def test_mat(): cpupaths = acpi.get_cpupaths() procid_apicid, uid_x2apicid = acpi.parse_apic() for cpupath in cpupaths: # Find the ProcId defined by the processor object processor = acpi.evaluate(cpupath) # Find the UID defined by the processor object's _UID method uid = acpi.evaluate(cpupath + "._UID") mat_buffer = acpi.evaluate(cpupath + "._MAT") if mat_buffer is None: continue # Process each _MAT subtable mat = acpi._MAT(mat_buffer) for index, subtable in enumerate(mat.subtables): if subtable.type == acpi.MADT_TYPE_LOCAL_APIC: if subtable.enabled: testsuite.test("{} Processor declaration ProcId = _MAT ProcId".format(cpupath), processor.ProcId == subtable.proc_id) testsuite.print_detail("{} ProcId ({:#02x}) != _MAT ProcId ({:#02x})".format(cpupath, processor.ProcId, subtable.proc_id)) testsuite.print_detail("Processor Declaration: {}".format(processor)) testsuite.print_detail("_MAT entry[{}]: {}".format(index, subtable)) if testsuite.test("{} with local APIC in _MAT has local APIC in MADT".format(cpupath), processor.ProcId in procid_apicid): testsuite.test("{} ApicId derived using Processor declaration ProcId = _MAT ApicId".format(cpupath), procid_apicid[processor.ProcId] == subtable.apic_id) testsuite.print_detail("{} ApicId derived from MADT ({:#02x}) != _MAT ApicId ({:#02x})".format(cpupath, procid_apicid[processor.ProcId], subtable.apic_id)) testsuite.print_detail("Processor Declaration: {}".format(processor)) testsuite.print_detail("_MAT entry[{}]: {}".format(index, subtable)) if subtable.type == acpi.MADT_TYPE_LOCAL_X2APIC: if subtable.enabled: if testsuite.test("{} with x2Apic in _MAT has _UID".format(cpupath), uid is not None): testsuite.test("{}._UID = _MAT UID".format(cpupath), uid == subtable.uid) testsuite.print_detail("{}._UID ({:#x}) != _MAT UID ({:#x})".format(cpupath, uid, subtable.uid)) testsuite.print_detail("_MAT entry[{}]: {}".format(index, subtable)) if testsuite.test("{} with _MAT x2Apic has x2Apic in MADT".format(cpupath), subtable.uid in uid_x2apicid): testsuite.test("{} x2ApicId derived from MADT using UID = _MAT x2ApicId".format(cpupath), uid_x2apicid[subtable.uid] == subtable.x2apicid) testsuite.print_detail("{} x2ApicId derived from MADT ({:#02x}) != _MAT x2ApicId ({:#02x})".format(cpupath, uid_x2apicid[subtable.uid], subtable.x2apicid)) testsuite.print_detail("_MAT entry[{}]: {}".format(index, x2Apic))
def test_mat(): cpupaths = acpi.get_cpupaths() apic = acpi.parse_apic() procid_apicid = apic.procid_apicid uid_x2apicid = apic.uid_x2apicid for cpupath in cpupaths: # Find the ProcId defined by the processor object processor = acpi.evaluate(cpupath) # Find the UID defined by the processor object's _UID method uid = acpi.evaluate(cpupath + "._UID") mat_buffer = acpi.evaluate(cpupath + "._MAT") if mat_buffer is None: continue # Process each _MAT subtable mat = acpi._MAT(mat_buffer) for index, subtable in enumerate(mat): if subtable.subtype == acpi.MADT_TYPE_LOCAL_APIC: if subtable.flags.bits.enabled: testsuite.test("{} Processor declaration ProcId = _MAT ProcId".format(cpupath), processor.ProcId == subtable.proc_id) testsuite.print_detail("{} ProcId ({:#02x}) != _MAT ProcId ({:#02x})".format(cpupath, processor.ProcId, subtable.proc_id)) testsuite.print_detail("Processor Declaration: {}".format(processor)) testsuite.print_detail("_MAT entry[{}]: {}".format(index, subtable)) if testsuite.test("{} with local APIC in _MAT has local APIC in MADT".format(cpupath), processor.ProcId in procid_apicid): testsuite.test("{} ApicId derived using Processor declaration ProcId = _MAT ApicId".format(cpupath), procid_apicid[processor.ProcId] == subtable.apic_id) testsuite.print_detail("{} ApicId derived from MADT ({:#02x}) != _MAT ApicId ({:#02x})".format(cpupath, procid_apicid[processor.ProcId], subtable.apic_id)) testsuite.print_detail("Processor Declaration: {}".format(processor)) testsuite.print_detail("_MAT entry[{}]: {}".format(index, subtable)) if subtable.subtype == acpi.MADT_TYPE_LOCAL_X2APIC: if subtable.flags.bits.enabled: if testsuite.test("{} with x2Apic in _MAT has _UID".format(cpupath), uid is not None): testsuite.test("{}._UID = _MAT UID".format(cpupath), uid == subtable.uid) testsuite.print_detail("{}._UID ({:#x}) != _MAT UID ({:#x})".format(cpupath, uid, subtable.uid)) testsuite.print_detail("_MAT entry[{}]: {}".format(index, subtable)) if testsuite.test("{} with _MAT x2Apic has x2Apic in MADT".format(cpupath), subtable.uid in uid_x2apicid): testsuite.test("{} x2ApicId derived from MADT using UID = _MAT x2ApicId".format(cpupath), uid_x2apicid[subtable.uid] == subtable.x2apicid) testsuite.print_detail("{} x2ApicId derived from MADT ({:#02x}) != _MAT x2ApicId ({:#02x})".format(cpupath, uid_x2apicid[subtable.uid], subtable.x2apicid)) testsuite.print_detail("_MAT entry[{}]: {}".format(index, subtable))
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)
def test_apic(): data = acpi.get_table("APIC") if data is None: return test_table_checksum(data) apic = acpi.parse_apic()
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)