FreeBSD/sys/x86/x86/mp_x86.c
/*
 * Add a scheduling group, a group of logical processors sharing
 * a particular cache (and, thus having an affinity), to the scheduling
 * topology.
 * This function recursively works on lower level caches.
 */
Add a scheduling group, a group of logical processors sharing
a particular cache (and, thus having an affinity), to the scheduling
topology.
This function recursively works on lower level caches.
Add a scheduling group a group of logical processors sharing a particular cache ( and thus having an affinity ) to the scheduling topology . This function recursively works on lower level caches .
static void
x86topo_add_sched_group(struct topo_node *root, struct cpu_group *cg_root)
{
	struct topo_node *node;
	int nchildren;
	int ncores;
	int i;
	KASSERT(root->type == TOPO_TYPE_SYSTEM || root->type == TOPO_TYPE_CACHE,
	    ("x86topo_add_sched_group: bad type: %u", root->type));
	CPU_COPY(&root->cpuset, &cg_root->cg_mask);
	cg_root->cg_count = root->cpu_count;
	if (root->type == TOPO_TYPE_SYSTEM)
		cg_root->cg_level = CG_SHARE_NONE;
	else
		cg_root->cg_level = root->subtype;
	ncores = 0;
	node = root;
	while (node != NULL) {
		if (node->type != TOPO_TYPE_CORE) {
			node = topo_next_node(root, node);
			continue;
		}
		ncores++;
		node = topo_next_nonchild_node(root, node);
	}
	if (cg_root->cg_level != CG_SHARE_NONE &&
	    root->cpu_count > 1 && ncores < 2)
		cg_root->cg_flags = CG_FLAG_SMT;
	nchildren = 0;
	node = root;
	while (node != NULL) {
		if (node->type != TOPO_TYPE_CACHE ||
		    (root->type != TOPO_TYPE_SYSTEM &&
		    CPU_CMP(&node->cpuset, &root->cpuset) == 0)) {
			node = topo_next_node(root, node);
			continue;
		}
		nchildren++;
		node = topo_next_nonchild_node(root, node);
	}
	cg_root->cg_child = smp_topo_alloc(nchildren);
	cg_root->cg_children = nchildren;
	node = root;
	i = 0;
	while (node != NULL) {
		if (node->type != TOPO_TYPE_CACHE ||
		    (root->type != TOPO_TYPE_SYSTEM &&
		    CPU_CMP(&node->cpuset, &root->cpuset) == 0)) {
			node = topo_next_node(root, node);
			continue;
		}
		cg_root->cg_child[i].cg_parent = cg_root;
		x86topo_add_sched_group(node, &cg_root->cg_child[i]);
		i++;
		node = topo_next_nonchild_node(root, node);
	}
}
static void x86topo_add_sched_group ( struct topo_node * root , struct cpu_group * cg_root ) { struct topo_node * node ; int nchildren ; int ncores ; int i ; KASSERT ( root -> type == TOPO_TYPE_SYSTEM || root -> type == TOPO_TYPE_CACHE , ( " " , root -> type ) ) ; CPU_COPY ( & root -> cpuset , & cg_root -> cg_mask ) ; cg_root -> cg_count = root -> cpu_count ; if ( root -> type == TOPO_TYPE_SYSTEM ) cg_root -> cg_level = CG_SHARE_NONE ; else cg_root -> cg_level = root -> subtype ; ncores = 0 ; node = root ; while ( node != NULL ) { if ( node -> type != TOPO_TYPE_CORE ) { node = topo_next_node ( root , node ) ; continue ; } ncores ++ ; node = topo_next_nonchild_node ( root , node ) ; } if ( cg_root -> cg_level != CG_SHARE_NONE && root -> cpu_count > 1 && ncores < 2 ) cg_root -> cg_flags = CG_FLAG_SMT ; nchildren = 0 ; node = root ; while ( node != NULL ) { if ( node -> type != TOPO_TYPE_CACHE || ( root -> type != TOPO_TYPE_SYSTEM && CPU_CMP ( & node -> cpuset , & root -> cpuset ) == 0 ) ) { node = topo_next_node ( root , node ) ; continue ; } nchildren ++ ; node = topo_next_nonchild_node ( root , node ) ; } cg_root -> cg_child = smp_topo_alloc ( nchildren ) ; cg_root -> cg_children = nchildren ; node = root ; i = 0 ; while ( node != NULL ) { if ( node -> type != TOPO_TYPE_CACHE || ( root -> type != TOPO_TYPE_SYSTEM && CPU_CMP ( & node -> cpuset , & root -> cpuset ) == 0 ) ) { node = topo_next_node ( root , node ) ; continue ; } cg_root -> cg_child [ i ] . cg_parent = cg_root ; x86topo_add_sched_group ( node , & cg_root -> cg_child [ i ] ) ; i ++ ; node = topo_next_nonchild_node ( root , node ) ; } }
Add a scheduling group, a group of logical processors sharing
 a particular cache (and, thus having an affinity), to the scheduling
 topology.
Add a scheduling group a group of logical processors sharing a particular cache ( and thus having an affinity ) to the scheduling topology .
/*
	 * Check how many core nodes we have under the given root node.
	 * If we have multiple logical processors, but not multiple
	 * cores, then those processors must be hardware threads.
	 */ /*
	 * Find out how many cache nodes we have under the given root node.
	 * We ignore cache nodes that cover all the same processors as the
	 * root node.  Also, we do not descend below found cache nodes.
	 * That is, we count top-level "non-redundant" caches under the root
	 * node.
	 */ /*
	 * Now find again the same cache nodes as above and recursively
	 * build scheduling topologies for them.
	 */