Holds cache sharing topology for the current system.
Declared in <folly/concurrency/CacheLocality.h>
struct CacheLocality;
Reads cache sharing information from procfs or sysfs to determine how CPUs should be grouped to minimize contention between cache levels.
| Name | Description |
|---|---|
readFromProcCpuinfo | Returns an estimate of the CacheLocality information by reading /proc/cpuinfo. This isn't as accurate as readFromSysfs(), but is a lot faster because the info isn't scattered across hundreds of files. Throws an exception if no cache information can be loaded. |
readFromProcCpuinfoLines | readFromProcCpuinfo(), except input is taken from memory rather than the file system. |
readFromSysfs | Reads CacheLocality information from the real sysfs filesystem. Throws an exception if no cache information can be loaded. |
readFromSysfsTree | Reads CacheLocality information from a tree structured like the sysfs filesystem. The provided function will be evaluated for each sysfs file that needs to be queried. The function should return a string containing the first line of the file (not including the newline), or an empty string if the file does not exist. The function will be called with paths of the form /sys/devices/system/cpu/cpu*/cache/index*/{type,shared_cpu_list} . Throws an exception if no caches can be parsed at all. |
readSystemLocalityInfo | Returns the best CacheLocality information available for the current system. This will be loaded from procfs or sysfs if possible, otherwise it will be correct in the number of CPUs but not in their sharing structure. |
system | Returns the best CacheLocality information available for the current system, cached for fast access. This will be loaded from procfs or sysfs if possible, otherwise it will be correct in the number of CPUs but not in their sharing structure. |
uniform | Returns a usable (but probably not reflective of reality) CacheLocality structure with the specified number of cpus and a single cache level that associates one cpu per cache. |
| Name | Description |
|---|---|
equivClassesByCpu | For each cpu, a list of cache identifiers following the same layout as numCachesByLevel. The identifier itself is an arbitrary number: it only signifies that cpus with the same identifier share a cache at that level. |
localityIndexByCpu | A map from cpu (from sched_getcpu or getcpu) to an index in the range 0..numCpus-1, where neighboring locality indices are more likely to share caches then indices far away. All of the members of a particular cache level be contiguous in their locality index. For example, if numCpus is 32 and numCachesByLevel.back() is 2, then cpus with a locality index < 16 will share one last-level cache and cpus with a locality index >= 16 will share the other. |
numCachesByLevel | Holds the number of caches present at each cache level (0 is the closest to the cpu). This is the number of AccessSpreader stripes needed to avoid cross-cache communication at the specified layer. numCachesByLevel.front() is the number of L1 caches and numCachesByLevel.back() is the number of last-level caches. |
numCpus | 1 more than the maximum value that can be returned from sched_getcpu or getcpu. This is the number of hardware thread contexts provided by the processors. |