4

How can the L3 cache size of a CPU be found using Python running on a Windows system?

Tried py-cpuinfo but it only outputs the L2 cache info, not L3.

import cpuinfo

print cpuinfo.get_cpu_info()

Output

{'count': 12, 'l2_cache_line_size': 6L, 'hz_advertised': '3.5000 GHz', 'bits': 64, 'brand': u'Intel(R) Core(TM) i7-5930K CPU @ 3.50GHz', 'vendor_id': u'GenuineIntel', 'cpuinfo_version': (3
, 3, 0), 'flags': ['3dnow', 'acpi', 'clflush', 'cmov', 'de', 'dts', 'fxsr', 'ia64', 'mca', 'mce', 'mmx', 'msr', 'mtrr', 'pse', 'sep', 'serial', 'ss', 'sse', 'sse2', 'tm', 'tsc'], 'raw_arch
_string': 'AMD64', 'l2_cache_size': 64L, 'l2_cache_associativity': '0x100L', 'hz_actual_raw': (3500000000L, 0), 'hz_actual': '3.5000 GHz', 'arch': 'X86_64', 'hz_advertised_raw': (350000000
0L, 0)}
2
  • I took a look at the source code for py-cpuinfo, and it appears the author gets L2 cache info himself by running assembly instructions using ctypes. Might be worth investing adding L3 cache retrieval as a patch to py-cpuinfo, building on top of its nifty classes? Commented Jul 13, 2017 at 18:53
  • I have filed a feature request for L3 cache sizes on py-cpuinfo. In the meantime, launching wmic cpu get L3CacheSize in a separate process and reading the result should work well on Windows. Commented Jul 13, 2017 at 19:18

1 Answer 1

2

On Windows specifically,

import subprocess
subprocess.Popen('wmic cpu get L3CacheSize')

is sufficient to retrieve information about the L3 cache size.

Sign up to request clarification or add additional context in comments.

4 Comments

Great solution, however running it gave me the error wmic get cpu L3CacheSize on Windows 10
Is it possible to include the wmic binary with the script, then let the script run the included copy of wmic instead of using the one that came with the system's Window installation? Is there a wmic version that works with older Windows installation as well, like Windows XP, 7, 8, 10.
wmic cpu get L3CacheSize returned 0 for the cache size on a AMD A8-6800K... Thats strange
@Nyxynyx That's because the AMD A8-6800K has no L3 cache. In Windows 10, wmic has been renamed to wbem. Unfortunately, I believe wmic is packaged with Windows and is not distributable - thus this solution does not work for every possible version of Windows. Perks of closed-source software! :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.