static int treeFillNextEntries( TreeNode* tree, int* processorIds, int socketId, int offset, int numberOfEntries ) { int counter = numberOfEntries; TreeNode* node = tree; TreeNode* thread; node = tree_getChildNode(node); /* get socket node */ for (int i=0; i<socketId; i++) { node = tree_getNextNode(node); if ( node == NULL ) { DEBUG_PRINT(DEBUGLEV_DEVELOP, Cannot find socket %d in topology tree, i); } } node = tree_getChildNode(node); /* skip offset cores */ for (int i=0; i<offset; i++) { node = tree_getNextNode(node); if ( node == NULL ) { DEBUG_PRINT(DEBUGLEV_DEVELOP, Cannot find core %d in topology tree, i); } } /* Traverse horizontal */ while ( node != NULL ) { if ( !counter ) break; thread = tree_getChildNode(node); while ( thread != NULL ) { if (cpuid_topology.threadPool[thread->id].inCpuSet) { processorIds[numberOfEntries-counter] = thread->id; thread = tree_getNextNode(thread); counter--; } else { thread = tree_getNextNode(thread); } } node = tree_getNextNode(node); } return numberOfEntries-counter; }
void topology_setupTree(void) { uint32_t i; TreeNode* currentNode; HWThread* hwThreadPool = cpuid_topology.threadPool; tree_init(&cpuid_topology.topologyTree, 0); for (i=0; i< cpuid_topology.numHWThreads; i++) { /* Add node to Topology tree */ if (!tree_nodeExists(cpuid_topology.topologyTree, hwThreadPool[i].packageId)) { //printf("Insert Socket %d\n", hwThreadPool[i].packageId); tree_insertNode(cpuid_topology.topologyTree, hwThreadPool[i].packageId); } currentNode = tree_getNode(cpuid_topology.topologyTree, hwThreadPool[i].packageId); if (!tree_nodeExists(currentNode, hwThreadPool[i].coreId)) { //printf("Insert Core %d at Socket %d\n", hwThreadPool[i].coreId, hwThreadPool[i].packageId); tree_insertNode(currentNode, hwThreadPool[i].coreId); } currentNode = tree_getNode(currentNode, hwThreadPool[i].coreId); if (!tree_nodeExists(currentNode, hwThreadPool[i].apicId)) { /* printf("WARNING: Thread already exists!\n"); */ //printf("Insert HWThread %d from Core %d at Socket %d\n", hwThreadPool[i].apicId, hwThreadPool[i].coreId, hwThreadPool[i].packageId); tree_insertNode(currentNode, hwThreadPool[i].apicId); affinity_thread2tile_lookup[hwThreadPool[i].apicId] = hwThreadPool[i].coreId; } } cpuid_topology.numSockets = tree_countChildren(cpuid_topology.topologyTree); currentNode = tree_getChildNode(cpuid_topology.topologyTree); cpuid_topology.numCoresPerSocket = tree_countChildren(currentNode); currentNode = tree_getChildNode(currentNode); cpuid_topology.numThreadsPerCore = tree_countChildren(currentNode); return; }
static int lua_likwid_getCpuTopology(lua_State* L) { int i; TreeNode* socketNode; int socketCount = 0; TreeNode* coreNode; int coreCount = 0; TreeNode* threadNode; int threadCount = 0; if (topology_isInitialized == 0) { topology_init(); topology_isInitialized = 1; cputopo = get_cpuTopology(); } if ((topology_isInitialized) && (cputopo == NULL)) { cputopo = get_cpuTopology(); } if (numa_isInitialized == 0) { if (numa_init() == 0) { numa_isInitialized = 1; numainfo = get_numaTopology(); } } if ((numa_isInitialized) && (numainfo == NULL)) { numainfo = get_numaTopology(); } lua_newtable(L); lua_pushstring(L,"numHWThreads"); lua_pushunsigned(L,cputopo->numHWThreads); lua_settable(L,-3); lua_pushstring(L,"activeHWThreads"); lua_pushunsigned(L,cputopo->activeHWThreads); lua_settable(L,-3); lua_pushstring(L,"numSockets"); lua_pushunsigned(L,cputopo->numSockets); lua_settable(L,-3); lua_pushstring(L,"numCoresPerSocket"); lua_pushunsigned(L,cputopo->numCoresPerSocket); lua_settable(L,-3); lua_pushstring(L,"numThreadsPerCore"); lua_pushunsigned(L,cputopo->numThreadsPerCore); lua_settable(L,-3); lua_pushstring(L,"numCacheLevels"); lua_pushinteger(L,cputopo->numCacheLevels); lua_settable(L,-3); lua_pushstring(L,"threadPool"); lua_newtable(L); for(i=0;i<cputopo->numHWThreads;i++) { lua_pushnumber(L,i); lua_newtable(L); lua_pushstring(L,"threadId"); lua_pushunsigned(L,cputopo->threadPool[i].threadId); lua_settable(L,-3); lua_pushstring(L,"coreId"); lua_pushunsigned(L,cputopo->threadPool[i].coreId); lua_settable(L,-3); lua_pushstring(L,"packageId"); lua_pushunsigned(L,cputopo->threadPool[i].packageId); lua_settable(L,-3); lua_pushstring(L,"apicId"); lua_pushunsigned(L,cputopo->threadPool[i].apicId); lua_settable(L,-3); lua_pushstring(L,"inCpuSet"); lua_pushunsigned(L,cputopo->threadPool[i].inCpuSet); lua_settable(L,-3); lua_settable(L,-3); } lua_settable(L,-3); lua_pushstring(L,"cacheLevels"); lua_newtable(L); for(i=0;i<cputopo->numCacheLevels;i++) { lua_pushnumber(L,i+1); lua_newtable(L); lua_pushstring(L,"level"); lua_pushunsigned(L,cputopo->cacheLevels[i].level); lua_settable(L,-3); lua_pushstring(L,"associativity"); lua_pushunsigned(L,cputopo->cacheLevels[i].associativity); lua_settable(L,-3); lua_pushstring(L,"sets"); lua_pushunsigned(L,cputopo->cacheLevels[i].sets); lua_settable(L,-3); lua_pushstring(L,"lineSize"); lua_pushunsigned(L,cputopo->cacheLevels[i].lineSize); lua_settable(L,-3); lua_pushstring(L,"size"); lua_pushunsigned(L,cputopo->cacheLevels[i].size); lua_settable(L,-3); lua_pushstring(L,"threads"); lua_pushunsigned(L,cputopo->cacheLevels[i].threads); lua_settable(L,-3); lua_pushstring(L,"inclusive"); lua_pushunsigned(L,cputopo->cacheLevels[i].inclusive); lua_settable(L,-3); lua_pushstring(L,"type"); switch (cputopo->cacheLevels[i].type) { case DATACACHE: lua_pushstring(L,"DATACACHE"); break; case INSTRUCTIONCACHE: lua_pushstring(L,"INSTRUCTIONCACHE"); break; case UNIFIEDCACHE: lua_pushstring(L,"UNIFIEDCACHE"); break; case ITLB: lua_pushstring(L,"ITLB"); break; case DTLB: lua_pushstring(L,"DTLB"); break; case NOCACHE: default: lua_pushstring(L,"NOCACHE"); break; } lua_settable(L,-3); lua_settable(L,-3); } lua_settable(L,-3); lua_pushstring(L,"topologyTree"); lua_newtable(L); socketNode = tree_getChildNode(cputopo->topologyTree); while (socketNode != NULL) { lua_pushinteger(L, socketCount); lua_newtable(L); lua_pushstring(L, "ID"); lua_pushunsigned(L,socketNode->id); lua_settable(L, -3); lua_pushstring(L, "Childs"); lua_newtable(L); coreCount = 0; coreNode = tree_getChildNode(socketNode); while (coreNode != NULL) { lua_pushinteger(L, coreCount); lua_newtable(L); lua_pushstring(L, "ID"); lua_pushunsigned(L,coreNode->id); lua_settable(L,-3); lua_pushstring(L, "Childs"); lua_newtable(L); threadNode = tree_getChildNode(coreNode); threadCount = 0; while (threadNode != NULL) { lua_pushunsigned(L,threadCount); lua_pushunsigned(L,threadNode->id); lua_settable(L,-3); threadNode = tree_getNextNode(threadNode); threadCount++; } lua_settable(L,-3); coreNode = tree_getNextNode(coreNode); coreCount++; lua_settable(L,-3); } lua_settable(L,-3); socketNode = tree_getNextNode(socketNode); socketCount++; lua_settable(L,-3); } lua_settable(L,-3); return 1; }