proxygen
folly::CacheLocality Struct Reference

#include <CacheLocality.h>

Public Member Functions

template<>
const CacheLocalitysystem ()
 
template<>
const CacheLocalitysystem ()
 

Static Public Member Functions

template<template< typename > class Atom = std::atomic>
static const CacheLocalitysystem ()
 
cache index *static CacheLocality readFromSysfs ()
 
static CacheLocality uniform (size_t numCpus)
 

Public Attributes

size_t numCpus
 
std::vector< size_t > numCachesByLevel
 
std::vector< size_t > localityIndexByCpu
 

Detailed Description

Definition at line 60 of file CacheLocality.h.

Member Function Documentation

CacheLocality folly::CacheLocality::readFromSysfs ( )
static

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 Reads CacheLocality information from the real sysfs filesystem. Throws an exception if no cache information can be loaded.

Definition at line 181 of file CacheLocality.cpp.

References getline(), name, and string.

Referenced by folly::getSystemLocalityInfo().

181  {
182  return readFromSysfsTree([](std::string name) {
183  std::ifstream xi(name.c_str());
184  std::string rv;
185  std::getline(xi, rv);
186  return rv;
187  });
188 }
void BENCHFUN() getline(size_t iters, size_t arg)
const char * name
Definition: http_parser.c:437
const char * string
Definition: Conv.cpp:212
template<>
const CacheLocality& folly::CacheLocality::system ( )

Definition at line 50 of file CacheLocalityBenchmark.cpp.

template<>
const CacheLocality& folly::CacheLocality::system ( )

Definition at line 54 of file CacheLocalityBenchmark.cpp.

57 {
template<template< typename > class Atom = std::atomic>
static const CacheLocality& folly::CacheLocality::system ( )
static

Returns the best CacheLocality information available for the current system, cached for fast access. This will be loaded from sysfs if possible, otherwise it will be correct in the number of CPUs but not in their sharing structure.

If you are into yo dawgs, this is a shared cache of the local locality of the shared caches.

The template parameter here is used to allow injection of a repeatable CacheLocality structure during testing. Rather than inject the type of the CacheLocality provider into every data type that transitively uses it, all components select between the default sysfs implementation and a deterministic implementation by keying off the type of the underlying atomic. See DeterministicScheduler.

Referenced by folly::detail::DigestBuilder< DigestT >::DigestBuilder(), and folly::detail::MemoryIdler::flushLocalMallocCaches().

CacheLocality folly::CacheLocality::uniform ( size_t  numCpus)
static

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.

Definition at line 190 of file CacheLocality.cpp.

References localityIndexByCpu, numCachesByLevel, and numCpus.

Referenced by folly::CacheLocality::system< test::DeterministicAtomic >(), folly::getSystemLocalityInfo(), and TEST().

190  {
191  CacheLocality rv;
192 
193  rv.numCpus = numCpus;
194 
195  // one cache shared by all cpus
196  rv.numCachesByLevel.push_back(numCpus);
197 
198  // no permutations in locality index mapping
199  for (size_t cpu = 0; cpu < numCpus; ++cpu) {
200  rv.localityIndexByCpu.push_back(cpu);
201  }
202 
203  return rv;
204 }

Member Data Documentation

std::vector<size_t> folly::CacheLocality::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.

Definition at line 80 of file CacheLocality.h.

Referenced by uniform().

std::vector<size_t> folly::CacheLocality::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.

Definition at line 71 of file CacheLocality.h.

Referenced by folly::parseLeadingNumber(), and uniform().

size_t folly::CacheLocality::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

Definition at line 64 of file CacheLocality.h.

Referenced by uniform().


The documentation for this struct was generated from the following files: