You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I don't think it's currently supported, (can't find it in CentralProcessor/PhysicalProcessor)
It could be added by parsing eg. lscpu (Linux) output eg. so you are welcome to provide a pull request
But with that solution i need to implement it for every os in an slightly other way, right?
At least at macOS there are sysctl's called hw.l1icachesize, hw.l1dcachesize, hw.l2cachesize and hw.l3cachesize. I don't know if the exist on OpenBSD also...
Yes, we'd need to find the information in other OS's, but I believe that should be available. The bigger question is what sort of data structure applies and how to model this. Are these caches common to all the processors? Can there be more than one of them?
I think the answer is yes. We currently fetch logical/physical processor info on Windows from GetLogicalProcessorInformationEx and in its returned objects it includes a RelationCache identifying processors which share a cache. That provides a CACHE_RELATIONSHIP structure with data... probably a good template for an OSHI object.
Results on Winodws, mac, and Linux are probably enough to add a cross-platform feature. We can add them from the BSDs, solaris, and AIX if they are reasonably easy to obtain there as well.
Can you get started with the new interface method (probably getCaches() on the CentralProcessor interface) and probably a new ProcessorCache class (similar to PhysicalProcessor) that contains the data in that CACHE_RELATIONSHIP structure? If you can implement on any OS the community can help with the other ones.
Yep, so different level caches associated with different groups of processors.... Windows handles that with the groupmasks.
Suggestion:
have a Cache object with fields for level, associativity, lineSize and cacheSize. Give them an index number based on the order they are found (for lack of any other numbering system)
in the LogicalProcessor class add a field with a list of cache index numbers it's associated with
Linux has the data stored in sysfs, e.g., /sys/devices/system/cpu/cpu0/cache/index2/size. I think this is the best source. It may be fetchable via udev.
For an example in OSHI, Check out readTopologyFromUdev() in the LinuxCentralProcessor class. It gets you as far as enumerating the CPUs (so up to cpu0 in the example above). You may need to do another layer of enumeration of CACHE below that to get the index #s, and then get the size property from them.
There's also a fallback non-UDEV option to just navigate the sysfs files in readTopologyFromSysfs(). You'll probably have to do both. :)
You can probably piggyback on these existing methods and insert your new code within them.
So it seems like there are many differences between each operating system and even different processors. Therefore, it is very likely that some information is only available on some operating systems or some processors.
I haven't had much time lately and I won't have much time in the near future either.
So it won't be possible for me to really work on this.
So it would make sense to add the "up for grabs" tag.
I created an API and implemented on Windows in #2198.
Originally mapped all the processors to cores which is accurate in Windows but duplicates data on Linux, and some platforms (macOS, AIX) only list summary values. So I decided to just list those summary values. Will probably just add a second line (per cache type) for the (unique) efficiency core data for hybrid cores.
I'm not sure where cache size of 56 bytes is coming from (I got 52 running in my local VM). I'm guessing that the hypervisors aren't populating the appropriate virtual CPUID bits.
The L3 associativity of 11 is also really strange, but that's what the data says...
Activity
mprins commentedon Sep 20, 2022
I don't think it's currently supported, (can't find it in CentralProcessor/PhysicalProcessor)
It could be added by parsing eg.
lscpu(Linux) output eg. so you are welcome to provide a pull requestor
I don't think there's a
sysctlfor OpenBSD@dbwiddis Might have better/other suggestions
lian-hsc commentedon Sep 20, 2022
But with that solution i need to implement it for every os in an slightly other way, right?
At least at macOS there are sysctl's called
hw.l1icachesize,hw.l1dcachesize,hw.l2cachesizeandhw.l3cachesize. I don't know if the exist on OpenBSD also...dbwiddis commentedon Sep 20, 2022
Yes, we'd need to find the information in other OS's, but I believe that should be available. The bigger question is what sort of data structure applies and how to model this. Are these caches common to all the processors? Can there be more than one of them?
I think the answer is yes. We currently fetch logical/physical processor info on Windows from
GetLogicalProcessorInformationExand in its returned objects it includes aRelationCacheidentifying processors which share a cache. That provides aCACHE_RELATIONSHIPstructure with data... probably a good template for an OSHI object.Results on Winodws, mac, and Linux are probably enough to add a cross-platform feature. We can add them from the BSDs, solaris, and AIX if they are reasonably easy to obtain there as well.
Can you get started with the new interface method (probably
getCaches()on the CentralProcessor interface) and probably a newProcessorCacheclass (similar to PhysicalProcessor) that contains the data in thatCACHE_RELATIONSHIPstructure? If you can implement on any OS the community can help with the other ones.dbwiddis commentedon Sep 20, 2022
Looks like on Solaris you can parse
prtpicloutput.lian-hsc commentedon Sep 20, 2022
I will start working and will try to implemnt windows, linux and macOS for the start, maby i will add some other OS later
mprins commentedon Sep 20, 2022
OpenBSD provides it in
dmesgI see, so it is probably available programmatically somewhere.afaik each cpu core can have these eg.
I bet that at some point there will/may be CPU's that have different values for different cores as well eg. big/little ARM...
dbwiddis commentedon Sep 20, 2022
@mprins it's in dmidecode -t cache (or 7) but that requires elevated permissions. But dmesg is a good backup.
dbwiddis commentedon Sep 20, 2022
Logical or physical core? And is that the same cache shared across multiple cores?
The Windows implementation will associate each cache with one or more logical processors, so that seems reasonable to do elsewhere, if possible.
mprins commentedon Sep 20, 2022
this has some pictures: https://superuser.com/questions/1073937/what-does-l4-cache-hold-on-some-cpus including L4 cache
dbwiddis commentedon Sep 20, 2022
Yep, so different level caches associated with different groups of processors.... Windows handles that with the groupmasks.
Suggestion:
dbwiddis commentedon Sep 20, 2022
Linux has the data stored in sysfs, e.g.,
/sys/devices/system/cpu/cpu0/cache/index2/size. I think this is the best source. It may be fetchable via udev.lian-hsc commentedon Sep 20, 2022
How can i use udev? Is there a documentation of it anywhere?
dbwiddis commentedon Sep 21, 2022
Docs for Udev are at JNA: http://java-native-access.github.io/jna/5.12.1/javadoc/com/sun/jna/platform/linux/Udev.html
For an example in OSHI, Check out
readTopologyFromUdev()in theLinuxCentralProcessorclass. It gets you as far as enumerating the CPUs (so up to cpu0 in the example above). You may need to do another layer of enumeration of CACHE below that to get the index #s, and then get the size property from them.There's also a fallback non-UDEV option to just navigate the sysfs files in
readTopologyFromSysfs(). You'll probably have to do both. :)You can probably piggyback on these existing methods and insert your new code within them.
1 remaining item
lian-hsc commentedon Sep 21, 2022
My MacBook (M2) has with
sysctlthe following output:system_profilerdoesn't include Cache at all.dbwiddis commentedon Sep 21, 2022
Glad you've got an M2. I'll buy one as soon as it's available in 16" size :)
Looks like plenty to go with here.
machdepisn't available, nor system profiler. Don't see anything about an L3 cache though.I looked in the IO Registry and didn't see anything there, either.
lian-hsc commentedon Sep 21, 2022
So it seems like there are many differences between each operating system and even different processors. Therefore, it is very likely that some information is only available on some operating systems or some processors.
dbwiddis commentedon Sep 21, 2022
That's generally true of most things on OSHI. :)
lian-hsc commentedon Sep 25, 2022
Hey @dbwiddis,
I haven't had much time lately and I won't have much time in the near future either.
So it won't be possible for me to really work on this.
So it would make sense to add the "up for grabs" tag.
dbwiddis commentedon Sep 28, 2022
I created an API and implemented on Windows in #2198.
Originally mapped all the processors to cores which is accurate in Windows but duplicates data on Linux, and some platforms (macOS, AIX) only list summary values. So I decided to just list those summary values. Will probably just add a second line (per cache type) for the (unique) efficiency core data for hybrid cores.
I'm not sure where cache size of 56 bytes is coming from (I got 52 running in my local VM). I'm guessing that the hypervisors aren't populating the appropriate virtual CPUID bits.
The L3 associativity of 11 is also really strange, but that's what the data says...
dbwiddis commentedon Oct 2, 2022
Linux is done.
dbwiddis commentedon Oct 2, 2022
AIX seems to only show L2 cache...
So I just hardcoded the values
dbwiddis commentedon Oct 3, 2022
Current status:
prtpicl -von x86 but I can't get any output on my VM. Nothing on SPARC.