1
0
forked from 0ad/0ad
0ad/source/lib/sysdep/x86_x64/topology.h
janwas 04127c7af3 fixes/improvements to lib code from work
- topology.cpp: modify interface due to thread-safety issue. caller is
now responsible for ensuring the first _Detect call isn't reentered;
everything else is safe.
- fix thread-safety issue in wnuma; use winit mechanism to ensure it's
ready before use
- VFS now takes a cacheSize parameter (required for being able to
disable read-only file caches for the image loader at work)
- allow dynarray that isn't actually holding memory
- debug_stl: VC9 fix (disable this code except on the exact STL version
on which it was tested)
- zlib, lib_api: changes to macro used to toggle between static and
dynamic linking
- add boost filesystem header in external_libraries
- amd64: cpu_ topology functions are now provided by x86_x64
- cpu: remove cpu_ClockFrequency (dangerous, may be tempting to use
during WHRT init which would cause a crash). use x86_x64_ClockFrequency
or os_cpu_ClockFrequency instead.
- werrno: cope with newer boost versions
- wmman: follow SUSv3 in rejecting zero-length mappings

This was SVN commit r5954.
2008-05-13 19:43:02 +00:00

102 lines
3.2 KiB
C

/**
* =========================================================================
* File : topology.cpp
* Project : 0 A.D.
* Description : detection of CPU and cache topology
* =========================================================================
*/
// license: GPL; see lib/license.txt
#ifndef INCLUDED_TOPOLOGY
#define INCLUDED_TOPOLOGY
// interface rationale:
// - explicit initialization avoids the difficulty and overhead of
// thread-safe lazy initialization checks.
// - requiring an opaque struct to be passed in ensures users call the
// init function before using the accessors.
// - delegating responsibility for thread-safety to the caller of the
// first *_Detect invocation avoids overhead and keeps us independent of
// the various threading packages (Boost, OpenMP, POSIX, Win32, ..)
//-----------------------------------------------------------------------------
// cpu
/**
* stores CPU topology, i.e. how many packages, cores and SMT units are
* actually present and enabled. this is useful for detecting SMP systems,
* predicting performance and dimensioning thread pools.
*
* note: OS abstractions usually only mention "processors", which could be
* any mix of the above.
**/
struct CpuTopology;
/**
* initialize static storage from which topology can be retrieved by
* means of the following functions.
* @return const pointer to a shared instance.
*
* WARNING: this function must not be reentered before it has returned once.
**/
LIB_API const CpuTopology* cpu_topology_Detect();
/**
* @return number of *enabled* CPU packages / sockets.
**/
LIB_API size_t cpu_topology_NumPackages(const CpuTopology*);
/**
* @return number of *enabled* CPU cores per package.
* (2 on dual-core systems)
**/
LIB_API size_t cpu_topology_CoresPerPackage(const CpuTopology*);
/**
* @return number of *enabled* hyperthreading units per core.
* (2 on P4 EE)
**/
LIB_API size_t cpu_topology_LogicalPerCore(const CpuTopology*);
//-----------------------------------------------------------------------------
// L2 cache
/**
* stores L2 cache topology, i.e. the mapping between processor and caches.
* this allows cores sharing a cache to work together on the same dataset,
* which may reduce contention and increase effective capacity.
*
* example: Intel Core2 micro-architectures (e.g. Intel Core2) feature
* partitioned L2 caches shared by two cores.
**/
struct CacheTopology;
/**
* initialize static storage from which topology can be retrieved by
* means of the following functions.
* @return const pointer to a shared instance.
*
* WARNING: this function must not be reentered before it has returned once.
**/
LIB_API const CacheTopology* cache_topology_Detect();
/**
* @return number of distinct L2 caches
**/
LIB_API size_t cache_topology_NumCaches(const CacheTopology*);
/**
* @return L2 cache number (zero-based) to which <processor> belongs.
**/
LIB_API size_t cache_topology_CacheFromProcessor(const CacheTopology*, size_t processor);
/**
* @return bit-mask of all processors sharing <cache>.
**/
LIB_API uintptr_t cache_topology_ProcessorMaskFromCache(const CacheTopology*, size_t cache);
#endif // #ifndef INCLUDED_TOPOLOGY