Topology
include/smp/topology.h View source View on GitHubStructs
Section titled “Structs”topology_contract
Section titled “topology_contract” struct topology_contract (2 fields) source
Contracts essentially state “I will not migrate outside of this scope”, with a set of named, verifiable reasons, so that “self topology” related functions can prove that they are in a safe state (specified), or in the edge case, have TOPOC_NONE contracts to uphold
enum topology_level scope enum topology_caller caller topology_cache_info
Section titled “topology_cache_info” struct topology_cache_info (5 fields) source
topology_package_info
Section titled “topology_package_info”topology_node
Section titled “topology_node” struct topology_node (11 fields) source
enum topology_level level uint64_t id Index in this node
uint64_t parent Parent node index, -1 for root
struct topology_node *parent_node int32_t first_child For cores this is in the cores array. For NUMA this is also in the cores array. For LLC this is in the numa array. For package this is LLC. For machine this is package.
int32_t nr_children union data struct topology_cache_info *cache struct topology_package_info *package topology
Section titled “topology” struct topology (2 fields) source
struct topology_node *level[TOPOLOGY_LEVEL_MAX] uint16_t count[TOPOLOGY_LEVEL_MAX] topology_level
Section titled “topology_level” enum topology_level (8 variants) source
TOPOLOGY_LEVEL_SMT Symmetric multiprocessing threads
TOPOLOGY_LEVEL_CORE SMTs under a core
TOPOLOGY_LEVEL_NUMA NUMA node
TOPOLOGY_LEVEL_LLC Last level cache (some processors have multiple L3 caches for a given physical processor)
TOPOLOGY_LEVEL_PACKAGE Physical processor in a socket
TOPOLOGY_LEVEL_MACHINE All processors in a machine
TOPOLOGY_LEVEL_MAX count
TOPOLOGY_LEVEL_EX_DOMAIN This exists solely because the topology_contract has a domain granularity that does not necessarily correspond to one of the others, thus, it is outside of MAX and is its own layer just for that API
topology_caller
Section titled “topology_caller” enum topology_caller (6 variants) source
This enum is used to verify topology contracts to guarantee a caller cannot be migrated out of a given scope of logical processors.
wrt. naming, we’ll suffix all instances of caller contracts with a C. e.g. SMPC, NODEC, PACKAGEC(specific bits go here)
we might need to come up with a naming document in docs/ because I’ve been doing this ad-hoc naming scheme stuff a few times
TOPC_NONE = 0 TOPC_IRQL = 1 << 0 TOPC_PINNED = 1 << 1 TOPC_IRQ = 1 << 2 TOPC_IFLAG = 1 << 3 TOPC_ANY = TOPC_IRQL | TOPC_PINNED | TOPC_IRQ | TOPC_IFLAG IRQ, IRQL and IFLAG: IRQ checks in_interrupt, IRQL that >= DISPATCH
Functions
Section titled “Functions”topology_mark_core_idle
Section titled “topology_mark_core_idle”topology_find_idle_core
Section titled “topology_find_idle_core”struct core * topology_find_idle_core(
struct core *local_core,
enum topology_level max_search
) source topology_get_smts_under_numa
Section titled “topology_get_smts_under_numa”struct core * * topology_get_smts_under_numa(
struct topology_node *numa,
size_t *count
) source topology_level_name
Section titled “topology_level_name”const char * topology_level_name(enum topology_level l) source topology_contract_verify
Section titled “topology_contract_verify”bool topology_contract_verify(struct topology_contract c) source Macros
Section titled “Macros”topology_for_each_id
Section titled “topology_for_each_id”#define topology_for_each_id(n_, l_) source Expansion
#define topology_for_each_id(n_, l_) \
for ((n_) = 0; (n_) < global.topology.count[l_]; (n_)++)