FreeBSD/sys/kern/subr_smp.c
/*
 * Check if the topology is uniform, that is, each package has the same number
 * of cores in it and each core has the same number of threads (logical
 * processors) in it.  If so, calculate the number of package, the number of
 * cores per package and the number of logical processors per core.
 * 'all' parameter tells whether to include administratively disabled logical
 * processors into the analysis.
 */
Check if the topology is uniform, that is, each package has the same number
of cores in it and each core has the same number of threads (logical
processors) in it.  If so, calculate the number of package, the number of
cores per package and the number of logical processors per core.
'all' parameter tells whether to include administratively disabled logical
processors into the analysis.
Check if the topology is uniform that is each package has the same number of cores in it and each core has the same number of threads ( logical processors ) in it . If so calculate the number of package the number of cores per package and the number of logical processors per core . ' all ' parameter tells whether to include administratively disabled logical processors into the analysis .
int
topo_analyze(struct topo_node *topo_root, int all,
    int *pkg_count, int *cores_per_pkg, int *thrs_per_core)
{
	struct topo_node *pkg_node;
	struct topo_node *core_node;
	struct topo_node *pu_node;
	int thrs_per_pkg;
	int cpp_counter;
	int tpc_counter;
	int tpp_counter;
	*pkg_count = 0;
	*cores_per_pkg = -1;
	*thrs_per_core = -1;
	thrs_per_pkg = -1;
	pkg_node = topo_root;
	while (pkg_node != NULL) {
		if (pkg_node->type != TOPO_TYPE_PKG) {
			pkg_node = topo_next_node(topo_root, pkg_node);
			continue;
		}
		if (!all && CPU_EMPTY(&pkg_node->cpuset)) {
			pkg_node = topo_next_nonchild_node(topo_root, pkg_node);
			continue;
		}
		(*pkg_count)++;
		cpp_counter = 0;
		tpp_counter = 0;
		core_node = pkg_node;
		while (core_node != NULL) {
			if (core_node->type == TOPO_TYPE_CORE) {
				if (!all && CPU_EMPTY(&core_node->cpuset)) {
					core_node =
					    topo_next_nonchild_node(pkg_node,
					        core_node);
					continue;
				}
				cpp_counter++;
				tpc_counter = 0;
				pu_node = core_node;
				while (pu_node != NULL) {
					if (pu_node->type == TOPO_TYPE_PU &&
					    (all || !CPU_EMPTY(&pu_node->cpuset)))
						tpc_counter++;
					pu_node = topo_next_node(core_node,
					    pu_node);
				}
				if (*thrs_per_core == -1)
					*thrs_per_core = tpc_counter;
				else if (*thrs_per_core != tpc_counter)
					return (0);
				core_node = topo_next_nonchild_node(pkg_node,
				    core_node);
			} else {
				if (core_node->type == TOPO_TYPE_PU &&
			           (all || !CPU_EMPTY(&core_node->cpuset)))
					tpp_counter++;
				core_node = topo_next_node(pkg_node,
				    core_node);
			}
		}
		if (*cores_per_pkg == -1)
			*cores_per_pkg = cpp_counter;
		else if (*cores_per_pkg != cpp_counter)
			return (0);
		if (thrs_per_pkg == -1)
			thrs_per_pkg = tpp_counter;
		else if (thrs_per_pkg != tpp_counter)
			return (0);
		pkg_node = topo_next_nonchild_node(topo_root, pkg_node);
	}
	KASSERT(*pkg_count > 0,
		("bug in topology or analysis"));
	if (*cores_per_pkg == 0) {
		KASSERT(*thrs_per_core == -1 && thrs_per_pkg > 0,
			("bug in topology or analysis"));
		*thrs_per_core = thrs_per_pkg;
	}
	return (1);
}
int topo_analyze ( struct topo_node * topo_root , int all , int * pkg_count , int * cores_per_pkg , int * thrs_per_core ) { struct topo_node * pkg_node ; struct topo_node * core_node ; struct topo_node * pu_node ; int thrs_per_pkg ; int cpp_counter ; int tpc_counter ; int tpp_counter ; * pkg_count = 0 ; * cores_per_pkg = -1 ; * thrs_per_core = -1 ; thrs_per_pkg = -1 ; pkg_node = topo_root ; while ( pkg_node != NULL ) { if ( pkg_node -> type != TOPO_TYPE_PKG ) { pkg_node = topo_next_node ( topo_root , pkg_node ) ; continue ; } if ( ! all && CPU_EMPTY ( & pkg_node -> cpuset ) ) { pkg_node = topo_next_nonchild_node ( topo_root , pkg_node ) ; continue ; } ( * pkg_count ) ++ ; cpp_counter = 0 ; tpp_counter = 0 ; core_node = pkg_node ; while ( core_node != NULL ) { if ( core_node -> type == TOPO_TYPE_CORE ) { if ( ! all && CPU_EMPTY ( & core_node -> cpuset ) ) { core_node = topo_next_nonchild_node ( pkg_node , core_node ) ; continue ; } cpp_counter ++ ; tpc_counter = 0 ; pu_node = core_node ; while ( pu_node != NULL ) { if ( pu_node -> type == TOPO_TYPE_PU && ( all || ! CPU_EMPTY ( & pu_node -> cpuset ) ) ) tpc_counter ++ ; pu_node = topo_next_node ( core_node , pu_node ) ; } if ( * thrs_per_core == -1 ) * thrs_per_core = tpc_counter ; else if ( * thrs_per_core != tpc_counter ) return ( 0 ) ; core_node = topo_next_nonchild_node ( pkg_node , core_node ) ; } else { if ( core_node -> type == TOPO_TYPE_PU && ( all || ! CPU_EMPTY ( & core_node -> cpuset ) ) ) tpp_counter ++ ; core_node = topo_next_node ( pkg_node , core_node ) ; } } if ( * cores_per_pkg == -1 ) * cores_per_pkg = cpp_counter ; else if ( * cores_per_pkg != cpp_counter ) return ( 0 ) ; if ( thrs_per_pkg == -1 ) thrs_per_pkg = tpp_counter ; else if ( thrs_per_pkg != tpp_counter ) return ( 0 ) ; pkg_node = topo_next_nonchild_node ( topo_root , pkg_node ) ; } KASSERT ( * pkg_count > 0 , ( " " ) ) ; if ( * cores_per_pkg == 0 ) { KASSERT ( * thrs_per_core == -1 && thrs_per_pkg > 0 , ( " " ) ) ; * thrs_per_core = thrs_per_pkg ; } return ( 1 ) ; }
Check if the topology is uniform, that is, each package has the same number
 of cores in it and each core has the same number of threads (logical
 processors) in it.
Check if the topology is uniform that is each package has the same number of cores in it and each core has the same number of threads ( logical processors ) in it .
/* PU node directly under PKG. */