Ejemplo n.º 1
0
def test_hardware_pstates(ratio_to_control_value):
    IA32_PERF_CTL = 0x199
    with bits.mwait.use_hint(), bits.preserve_msr(IA32_PERF_CTL):
        MSR_PLATFORM_INFO = 0xce
        min_ratio = testmsr.MSR("maximum efficiency ratio",
                                bits.bsp_apicid(),
                                MSR_PLATFORM_INFO,
                                highbit=47,
                                lowbit=40)[0]
        max_ratio = testmsr.MSR("max non-turbo ratio",
                                bits.bsp_apicid(),
                                MSR_PLATFORM_INFO,
                                highbit=15,
                                lowbit=8)[0]

        # Get the Turbo Mode Availability flag
        turbo_mode_available = bits.cpuid(bits.bsp_apicid(), 0).eax >= 6 and (
            bits.cpuid(bits.bsp_apicid(), 6).eax & 0x2)
        last_ratio = max_ratio
        if turbo_mode_available:
            last_ratio += 1

        bclk = testutil.adjust_to_nearest(bits.bclk(), 100.0 / 12) * 1000000

        for ratio in range(min_ratio, last_ratio + 1):
            control_value = ratio_to_control_value(ratio, min_ratio, max_ratio)
            for apicid in bits.cpus():
                bits.wrmsr(apicid, IA32_PERF_CTL, control_value)

            turbo = (ratio == max_ratio + 1)
            if turbo:
                # Needs to busywait, not sleep
                start = time.time()
                while (time.time() - start < 2):
                    pass

            expected = int(ratio * bclk / 1000000)

            for duration in (0.1, 1.0):
                aperf = bits.cpu_frequency(duration)[1]
                aperf = testutil.adjust_to_nearest(aperf, bclk / 2)
                aperf = int(aperf / 1000000)
                if turbo:
                    if aperf >= expected:
                        break
                else:
                    if aperf == expected:
                        break

            if turbo:
                testsuite.test(
                    "Turbo measured frequency {} >= expected {} MHz".format(
                        aperf, expected), aperf >= expected)
            else:
                testsuite.test(
                    "Ratio {} measured frequency {} MHz == expected {} MHz".
                    format(ratio, aperf, expected), aperf == expected)
Ejemplo n.º 2
0
def toggle_autodemotion():
    value = bits.rdmsr(bits.bsp_apicid(), 0xe2)
    if bitfields.getbits(value, 26, 25) == 0x3:
        fieldvalue = 0
    else:
        fieldvalue = 0x3
    value = bitfields.setbits(value, fieldvalue, 26, 25)
    for cpu in bits.cpus():
        bits.wrmsr(cpu, 0xe2, value)
    show_autodemotion()
Ejemplo n.º 3
0
def toggle_autodemotion():
    value = bits.rdmsr(bits.bsp_apicid(), 0xe2)
    if bitfields.getbits(value, 26, 25) == 0x3:
        fieldvalue = 0
    else:
        fieldvalue = 0x3
    value = bitfields.setbits(value, fieldvalue, 26, 25)
    for cpu in bits.cpus():
        bits.wrmsr(cpu, 0xe2, value)
    show_autodemotion()
Ejemplo n.º 4
0
def test_hardware_pstates(ratio_to_control_value):
    old_mwait = {}
    try:
        MSR_PLATFORM_INFO = 0xce
        IA32_PERF_CTL = 0x199
        min_ratio = testmsr.MSR("maximum efficiency ratio", bits.bsp_apicid(), MSR_PLATFORM_INFO, highbit=47, lowbit=40)[0]
        max_ratio = testmsr.MSR("max non-turbo ratio", bits.bsp_apicid(), MSR_PLATFORM_INFO, highbit=15, lowbit=8)[0]

        # Get the Turbo Mode Availability flag
        turbo_mode_available = bits.cpuid(bits.bsp_apicid(),0).eax >= 6 and (bits.cpuid(bits.bsp_apicid(),6).eax & 0x2)
        last_ratio = max_ratio
        if turbo_mode_available:
            last_ratio += 1

        duration = last_ratio - min_ratio + 1
        if turbo_mode_available:
            duration += 2
        print "Test duration is ~{} seconds...".format(duration)

        # Force use of MWAIT C3
        hint = 0x20
        cpus = bits.cpus()
        for apicid in cpus:
            old_mwait[apicid] = bits.get_mwait(apicid)
            bits.set_mwait(apicid, True, hint)

        bclk = testutil.adjust_to_nearest(bits.bclk(), 100.0/12) * 1000000

        for ratio in range(min_ratio, last_ratio + 1):
            control_value = ratio_to_control_value(ratio, min_ratio, max_ratio)
            for apicid in cpus:
                bits.wrmsr(apicid, IA32_PERF_CTL, control_value)

            if ratio == max_ratio + 1:
                # Needs to busywait, not sleep
                start = time.time()
                while (time.time() - start < 2):
                    pass

            aperf = bits.cpu_frequency()[1]
            aperf = testutil.adjust_to_nearest(aperf, bclk/2)
            aperf = int(aperf / 1000000)

            expected = int(ratio * bclk / 1000000)

            if ratio == max_ratio + 1:
                testsuite.test("Turbo measured frequency {} >= expected {} MHz".format(aperf, expected), aperf >= expected)
            else:
                testsuite.test("Ratio {} measured frequency {} MHz == expected {} MHz".format(ratio, aperf, expected), aperf == expected)
    finally:
        for apicid, old_mwait_values in old_mwait.iteritems():
            bits.set_mwait(apicid, *old_mwait_values)
Ejemplo n.º 5
0
def test_hardware_pstates(ratio_to_control_value):
    IA32_PERF_CTL = 0x199
    with bits.mwait.use_hint(), bits.preserve_msr(IA32_PERF_CTL):
        MSR_PLATFORM_INFO = 0xce
        min_ratio = testmsr.MSR("maximum efficiency ratio", bits.bsp_apicid(), MSR_PLATFORM_INFO, highbit=47, lowbit=40)[0]
        max_ratio = testmsr.MSR("max non-turbo ratio", bits.bsp_apicid(), MSR_PLATFORM_INFO, highbit=15, lowbit=8)[0]

        # Get the Turbo Mode Availability flag
        turbo_mode_available = bits.cpuid(bits.bsp_apicid(),0).eax >= 6 and (bits.cpuid(bits.bsp_apicid(),6).eax & 0x2)
        last_ratio = max_ratio
        if turbo_mode_available:
            last_ratio += 1

        bclk = testutil.adjust_to_nearest(bits.bclk(), 100.0/12) * 1000000

        for ratio in range(min_ratio, last_ratio + 1):
            control_value = ratio_to_control_value(ratio, min_ratio, max_ratio)
            for apicid in bits.cpus():
                bits.wrmsr(apicid, IA32_PERF_CTL, control_value)

            turbo = (ratio == max_ratio + 1)
            if turbo:
                # Needs to busywait, not sleep
                start = time.time()
                while (time.time() - start < 2):
                    pass

            expected = int(ratio * bclk / 1000000)

            for duration in (0.1, 1.0):
                aperf = bits.cpu_frequency(duration)[1]
                aperf = testutil.adjust_to_nearest(aperf, bclk/2)
                aperf = int(aperf / 1000000)
                if turbo:
                    if aperf >= expected:
                        break
                else:
                    if aperf == expected:
                        break

            if turbo:
                testsuite.test("Turbo measured frequency {} >= expected {} MHz".format(aperf, expected), aperf >= expected)
            else:
                testsuite.test("Ratio {} measured frequency {} MHz == expected {} MHz".format(ratio, aperf, expected), aperf == expected)
Ejemplo n.º 6
0
 def process_wrmsr(apicid):
     wr_value = 0
     if args.rmw:
         rd_value = bits.rdmsr(apicid, args.msr)
         if rd_value is None:
             rd_fail.append(apicid)
             return
         wr_value = rd_value & ~(args.mask << args.shift)
     wr_value |= (args.value & args.mask) << args.shift
     if bits.wrmsr(apicid, args.msr, wr_value):
         success.append(apicid)
     else:
         wr_fail.append(apicid)
Ejemplo n.º 7
0
 def wrmsr(self, apicid=None):
     if apicid is None:
         apicid = self.apicid
     bits.wrmsr(apicid, self.addr, self.value)
Ejemplo n.º 8
0
 def wrmsr(self, apicid=None):
     if apicid is None:
         apicid = self.apicid
     bits.wrmsr(apicid, self.addr, self.value)
Ejemplo n.º 9
0
def test_pstates():
    """Execute and verify frequency for each Pstate in the _PSS"""
    old_mwait = {}
    try:
        IA32_PERF_CTL = 0x199

        # Force use of MWAIT C3
        hint = 0x20
        cpus = bits.cpus()
        for apicid in cpus:
            old_mwait[apicid] = bits.get_mwait(apicid)
            bits.set_mwait(apicid, True, hint)

        cpupath_procid = acpi.find_procid()
        cpupath_uid = acpi.find_uid()
        procid_apicid, uid_x2apicid = acpi.parse_apic()
        def cpupath_apicid(cpupath):
            if procid_apicid is not None:
                procid = cpupath_procid.get(cpupath, None)
                if procid is not None:
                    apicid = procid_apicid.get(procid, None)
                    if apicid is not None:
                        return apicid
            if uid_x2apicid is not None:
                uid = cpupath_uid.get(cpupath, None)
                if uid is not None:
                    apicid = uid_x2apicid.get(uid, None)
                    if apicid is not None:
                        return apicid
            return bits.cpus()[0]

        bclk = testutil.adjust_to_nearest(bits.bclk(), 100.0/12) * 1000000

        uniques = acpi.parse_cpu_method("_PSS")
        for pss, cpupaths in uniques.iteritems():
            if not testsuite.test("_PSS must exist", pss is not None):
                testsuite.print_detail(acpi.factor_commonprefix(cpupaths))
                testsuite.print_detail('No _PSS exists')
                continue

            print "Test duration is ~{} seconds...".format(len(pss.pstates) + 2)

            for n, pstate in enumerate(pss.pstates):
                for cpupath in cpupaths:
                    apicid = cpupath_apicid(cpupath)
                    if apicid is None:
                        print 'Failed to find apicid for cpupath {}'.format(cpupath)
                        continue
                    bits.wrmsr(apicid, IA32_PERF_CTL, pstate.control)

                # Detecting Turbo frequency requires at least 2 pstates
                # since turbo frequency = max non-turbo frequency + 1
                turbo = False
                if len(pss.pstates) >= 2:
                    turbo = (n == 0 and pstate.core_frequency == (pss.pstates[1].core_frequency + 1))
                    if turbo:
                        # Needs to busywait, not sleep
                        start = time.time()
                        while (time.time() - start < 2):
                            pass

                # Abort the test if no cpu frequency is not available
                if bits.cpu_frequency() is None:
                    continue
                aperf = bits.cpu_frequency()[1]

                aperf = testutil.adjust_to_nearest(aperf, bclk/2)
                aperf = int(aperf / 1000000)

                if turbo:
                    testsuite.test("P{}: Turbo measured frequency {} >= expected {} MHz".format(n, aperf, pstate.core_frequency), aperf >= pstate.core_frequency)
                else:
                    testsuite.test("P{}: measured frequency {} MHz == expected {} MHz".format(n, aperf, pstate.core_frequency), aperf == pstate.core_frequency)
    finally:
        for apicid, old_mwait_values in old_mwait.iteritems():
            bits.set_mwait(apicid, *old_mwait_values)
Ejemplo n.º 10
0
def test_pstates():
    """Execute and verify frequency for each Pstate in the _PSS"""
    IA32_PERF_CTL = 0x199
    with bits.mwait.use_hint(), bits.preserve_msr(IA32_PERF_CTL):
        cpupath_procid = acpi.find_procid()
        cpupath_uid = acpi.find_uid()
        apic = acpi.parse_apic()
        procid_apicid = apic.procid_apicid
        uid_x2apicid = apic.uid_x2apicid
        def cpupath_apicid(cpupath):
            if procid_apicid is not None:
                procid = cpupath_procid.get(cpupath, None)
                if procid is not None:
                    apicid = procid_apicid.get(procid, None)
                    if apicid is not None:
                        return apicid
            if uid_x2apicid is not None:
                uid = cpupath_uid.get(cpupath, None)
                if uid is not None:
                    apicid = uid_x2apicid.get(uid, None)
                    if apicid is not None:
                        return apicid
            return bits.cpus()[0]

        bclk = testutil.adjust_to_nearest(bits.bclk(), 100.0/12) * 1000000

        uniques = acpi.parse_cpu_method("_PSS")
        for pss, cpupaths in uniques.iteritems():
            if not testsuite.test("_PSS must exist", pss is not None):
                testsuite.print_detail(acpi.factor_commonprefix(cpupaths))
                testsuite.print_detail('No _PSS exists')
                continue

            for n, pstate in enumerate(pss.pstates):
                for cpupath in cpupaths:
                    apicid = cpupath_apicid(cpupath)
                    if apicid is None:
                        print 'Failed to find apicid for cpupath {}'.format(cpupath)
                        continue
                    bits.wrmsr(apicid, IA32_PERF_CTL, pstate.control)

                # Detecting Turbo frequency requires at least 2 pstates
                # since turbo frequency = max non-turbo frequency + 1
                turbo = False
                if len(pss.pstates) >= 2:
                    turbo = (n == 0 and pstate.core_frequency == (pss.pstates[1].core_frequency + 1))
                    if turbo:
                        # Needs to busywait, not sleep
                        start = time.time()
                        while (time.time() - start < 2):
                            pass

                for duration in (0.1, 1.0):
                    frequency_data = bits.cpu_frequency(duration)
                    # Abort the test if no cpu frequency is not available
                    if frequency_data is None:
                        continue
                    aperf = frequency_data[1]
                    aperf = testutil.adjust_to_nearest(aperf, bclk/2)
                    aperf = int(aperf / 1000000)
                    if turbo:
                        if aperf >= pstate.core_frequency:
                            break
                    else:
                        if aperf == pstate.core_frequency:
                            break

                if turbo:
                    testsuite.test("P{}: Turbo measured frequency {} >= expected {} MHz".format(n, aperf, pstate.core_frequency), aperf >= pstate.core_frequency)
                else:
                    testsuite.test("P{}: measured frequency {} MHz == expected {} MHz".format(n, aperf, pstate.core_frequency), aperf == pstate.core_frequency)