py-cpuinfo icon indicating copy to clipboard operation
py-cpuinfo copied to clipboard

Add support for retrieving L3 cache size if possible

Open AkshatM opened this issue 8 years ago • 6 comments

This limitation has been referenced here. I would like to add this capability to py-cpuinfo.

It looks like the current technique in py-cpuinfo for retrieving L2 cache size info is to use the CPUID opcode with the extended L2 feature set. I've tried digging around for a way to use CPUID for L3 cache, as that would be the most compliant across different OSs, but no luck.

For certain operating systems, L3 cache size is easily retrievable e.g. /proc/cpuinfo/ on Linux directly references the L3 cache, while WMIC CPU can be used on Windows.

If permissible, I would like to try adding support for Linux and Windows specifically (by reading from /proc/cpuinfo for Linux and executing wmic cpu in a subprocess) while trying to find a processor-based solution (unless you are aware of one). Thoughts?

AkshatM avatar Jul 13 '17 19:07 AkshatM

This is a great idea. I have been meaning to beef up the cache size checking code, but have been too busy.

There could be one downside to this however. wmic is not installed by default on all versions of Windows. So it wont "Just work" on Windows.

If you want, give this a shot. I would love to have it get L3 cache info.

workhorsy avatar Jul 13 '17 21:07 workhorsy

I have found a bug. You're already reporting L3 cache size for Linux from /proc/cpuinfo, but erroneously misrepresenting it as L2.

   returncode, output = DataSource.cat_proc_cpuinfo()
   ...
   cache_size = _get_field(False, output, None, '', 'cache size')
   info = {
       ...
      'l2_cache_size': cache_size,
   }

From the man page for lscpu, which consults cpuinfo, the cache value returned there is shared across all processors, meaning it is L3.

I have verified this by comparing the results of dmidecode -t cache with the values contained in /proc/cpuinfo - the L3 cache reported there is the same as the cache size value reported there.

Should I commit a reporting change as part of this change? The other checks for this information should report it correctly.

AkshatM avatar Jul 14 '17 05:07 AkshatM

Any chance for a cross-platform solution using CPUID opcode to be implemented? I am in need of this feature as well for my project that needs to run on both Windows and Linux. Thanks!

vertangelx avatar Jul 14 '17 05:07 vertangelx

@AkshatM It looks like I have assumed that it is always L2 cache size when it says cache size. Ideally it should show the size of all the caches.

I'll make a new bug for fixing this issue: #77

workhorsy avatar Jul 14 '17 23:07 workhorsy

@vertangelx this is also a good idea. I will have to look if there is a way to get L3 cache size from the CPUID register.

workhorsy avatar Jul 14 '17 23:07 workhorsy

@workhorsy This may be of interest regarding obtaining L3 from CPUID.

Vol. 2A, pg. 3-197 of the Intel handbook also indicates that setting EAX = 0FH, ECX = 1 should be able to get us the L3 occupany monitoring size, whatever that means

AkshatM avatar Jul 19 '17 05:07 AkshatM