diff --git a/Makefile b/Makefile index 99efe3d30..e2924eedd 100644 --- a/Makefile +++ b/Makefile @@ -610,7 +610,6 @@ install: install_daemon install_freq install_appdaemon install_container_helper @install -m 644 $(SRC_DIR)/includes/likwid.h $(PREFIX)/include/ @sed -i -e "s##$(VERSION)#g" -e "s##$(DATE)#g" -e "s##$(GITCOMMIT)#g" -e "s##$(MINOR)#g" $(PREFIX)/include/likwid.h @install -m 644 $(SRC_DIR)/includes/likwid-marker.h $(PREFIX)/include/ - @install -m 644 $(SRC_DIR)/includes/bstrlib.h $(PREFIX)/include/ $(FORTRAN_INSTALL) @echo "===> INSTALL groups to $(PREFIX)/share/likwid/perfgroups" @mkdir -p $(PREFIX)/share/likwid/perfgroups @@ -622,7 +621,6 @@ install: install_daemon install_freq install_appdaemon install_container_helper @echo "===> INSTALL docs and examples to $(PREFIX)/share/likwid/docs" @mkdir -p $(PREFIX)/share/likwid/docs @chmod 755 $(PREFIX)/share/likwid/docs - @install -m 644 $(DOC_DIR)/bstrlib.txt $(PREFIX)/share/likwid/docs @mkdir -p $(PREFIX)/share/likwid/examples @chmod 755 $(PREFIX)/share/likwid/examples @install -m 644 $(EXAMPLES_DIR)/* $(PREFIX)/share/likwid/examples @@ -679,7 +677,6 @@ move: move_daemon move_freq move_appdaemon move_container_helper @chmod 755 $(INSTALLED_PREFIX)/include @install -m 644 $(PREFIX)/include/likwid.h $(INSTALLED_PREFIX)/include/likwid.h @install -m 644 $(PREFIX)/include/likwid-marker.h $(INSTALLED_PREFIX)/include/likwid-marker.h - @install -m 644 $(PREFIX)/include/bstrlib.h $(INSTALLED_PREFIX)/include/bstrlib.h @if [ -e $(PREFIX)/include/likwid.mod ]; then install $(PREFIX)/include/likwid.mod $(INSTALLED_PREFIX)/include/likwid.mod; fi @echo "===> MOVE groups from $(PREFIX)/share/likwid/perfgroups to $(INSTALLED_PREFIX)/share/likwid/perfgroups" @mkdir -p $(INSTALLED_PREFIX)/share/likwid/perfgroups @@ -690,7 +687,6 @@ move: move_daemon move_freq move_appdaemon move_container_helper @find $(INSTALLED_PREFIX)/share/likwid/perfgroups -name "*.txt" -exec chmod 644 {} \; @mkdir -p $(INSTALLED_PREFIX)/share/likwid/docs @chmod 755 $(INSTALLED_PREFIX)/share/likwid/docs - @install -m 644 $(PREFIX)/share/likwid/docs/bstrlib.txt $(INSTALLED_PREFIX)/share/likwid/docs @mkdir -p $(INSTALLED_PREFIX)/share/likwid/examples @chmod 755 $(INSTALLED_PREFIX)/share/likwid/examples @install -m 644 $(EXAMPLES_DIR)/* $(INSTALLED_PREFIX)/share/likwid/examples @@ -733,7 +729,6 @@ uninstall: uninstall_daemon uninstall_freq uninstall_appdaemon uninstall_contain @echo "===> REMOVING header from $(PREFIX)/include" @rm -f $(PREFIX)/include/likwid.h @rm -f $(PREFIX)/include/likwid-marker.h - @rm -f $(PREFIX)/include/bstrlib.h $(FORTRAN_REMOVE) @echo "===> REMOVING filter, groups and default configs from $(PREFIX)/share/likwid" @rm -rf $(abspath $(PREFIX)/share/likwid/filter) @@ -770,7 +765,6 @@ uninstall_moved: uninstall_daemon_moved uninstall_freq_moved uninstall_appdaemon @echo "===> REMOVING header from $(INSTALLED_PREFIX)/include" @rm -f $(INSTALLED_PREFIX)/include/likwid.h @rm -f $(PREFIX)/include/likwid-marker.h - @rm -f $(INSTALLED_PREFIX)/include/bstrlib.h $(FORTRAN_REMOVE) @echo "===> REMOVING filter, groups and default configs from $(INSTALLED_PREFIX)/share/likwid" @rm -rf $(LIKWIDFILTERPATH) diff --git a/bench/likwid-bench.c b/bench/likwid-bench.c index 0105a9c3b..9cf5097b0 100644 --- a/bench/likwid-bench.c +++ b/bench/likwid-bench.c @@ -442,7 +442,7 @@ int main(int argc, char** argv) for (i=0; i < affinity->numberOfAffinityDomains; i++ ) { ownprintf("Domain %d:\n",i); - ownprintf("\tTag %s:",bdata(affinity->domains[i].tag)); + ownprintf("\tTag %s:",affinity->domains[i].tag); for ( uint32_t j=0; j < affinity->domains[i].numberOfProcessors; j++ ) { diff --git a/bench/src/allocator.c b/bench/src/allocator.c index 4771f3ccc..e11fbd358 100644 --- a/bench/src/allocator.c +++ b/bench/src/allocator.c @@ -112,7 +112,7 @@ allocator_allocateVector( for (i=0;inumberOfAffinityDomains;i++) { - if (biseq(domainString, domains->domains[i].tag)) + if (strncmp(domains->domains[i].tag, bdata(domainString), strlen(domains->domains[i].tag)) == 0) { domain = domains->domains + i; } @@ -157,7 +157,7 @@ allocator_allocateVector( affinity_pinProcess(domain->processorList[0]); printf("Allocate: Process running on hwthread %d (Domain %s) - Vector length %llu/%llu Offset %d Alignment %llu\n", affinity_processGetProcessorId(), - bdata(domain->tag), + domain->tag, LLU_CAST size, LLU_CAST bytesize, offset, diff --git a/src/affinity.c b/src/affinity.c index 56b7c155f..ff5350e68 100644 --- a/src/affinity.c +++ b/src/affinity.c @@ -523,6 +523,12 @@ static int affinity_addNodeDomain(AffinityDomain* domain, int* help) { return -ENOMEM; } + domain->tag = malloc(2); + if (!domain->tag) + { + free(domain->processorList); + return -ENOMEM; + } int offset = 0; int cores = 0; for (int i = 0; i < MAX(cputopo->numSockets, 1); i++) @@ -537,7 +543,8 @@ static int affinity_addNodeDomain(AffinityDomain* domain, int* help) } domain->numberOfProcessors = offset; domain->numberOfCores = cores; - domain->tag = bformat("N"); + domain->tag[0] = 'N'; + domain->tag[1] = '\0'; DEBUG_PRINT(DEBUGLEV_DEVELOP, Affinity domain N: %d HW threads on %d cores, domain->numberOfProcessors, domain->numberOfCores); return 0; } @@ -559,6 +566,12 @@ static int affinity_addSocketDomain(int socket, AffinityDomain* domain, int* hel { return -ENOMEM; } + domain->tag = malloc(10); + if (!domain->tag) + { + free(domain->processorList); + return -ENOMEM; + } int tmp = treeFillNextEntries(cputopo->topologyTree, domain->processorList, 0, @@ -568,7 +581,7 @@ static int affinity_addSocketDomain(int socket, AffinityDomain* domain, int* hel tmp = MIN(tmp, domain->numberOfProcessors); domain->numberOfProcessors = tmp; domain->numberOfCores = affinity_countSocketCores(domain->numberOfProcessors, domain->processorList, help); - domain->tag = bformat("S%d", socket); + snprintf(domain->tag, 9, "S%d", socket); DEBUG_PRINT(DEBUGLEV_DEVELOP, Affinity domain S%d: %d HW threads on %d cores, socket, domain->numberOfProcessors, domain->numberOfCores); return 0; } @@ -594,6 +607,12 @@ static int affinity_addDieDomain(int socket, int die, AffinityDomain* domain, in { return -ENOMEM; } + domain->tag = malloc(10); + if (!domain->tag) + { + free(domain->processorList); + return -ENOMEM; + } domain->numberOfProcessors = numThreadsPerDie; domain->numberOfCores = numCoresPerDie; int tmp = treeFillNextEntries(cputopo->topologyTree, @@ -605,7 +624,7 @@ static int affinity_addDieDomain(int socket, int die, AffinityDomain* domain, in domain->numberOfProcessors); domain->numberOfProcessors = tmp; domain->numberOfCores = affinity_countSocketCores(domain->numberOfProcessors, domain->processorList, help); - domain->tag = bformat("D%d", dieId); + snprintf(domain->tag, 9, "D%d", dieId); DEBUG_PRINT(DEBUGLEV_DEVELOP, Affinity domain D%d: %d HW threads on %d cores, dieId, domain->numberOfProcessors, domain->numberOfCores); return 0; } @@ -630,6 +649,12 @@ static int affinity_addCacheDomain(int socket, int cacheId, AffinityDomain* doma { return -ENOMEM; } + domain->tag = malloc(10); + if (!domain->tag) + { + free(domain->processorList); + return -ENOMEM; + } domain->numberOfProcessors = numThreadsPerCache; domain->numberOfCores = numCoresPerCache; int tmp = treeFillNextEntries(cputopo->topologyTree, @@ -641,7 +666,7 @@ static int affinity_addCacheDomain(int socket, int cacheId, AffinityDomain* doma domain->numberOfProcessors); domain->numberOfProcessors = tmp; domain->numberOfCores = affinity_countSocketCores(domain->numberOfProcessors, domain->processorList, help); - domain->tag = bformat("C%d", cid); + snprintf(domain->tag, 9, "C%d", cid); DEBUG_PRINT(DEBUGLEV_DEVELOP, Affinity domain C%d: %d HW threads on %d cores, cid, domain->numberOfProcessors, domain->numberOfCores); return 0; } @@ -666,6 +691,12 @@ static int _affinity_addMemoryDomain(int nodeId, AffinityDomain* domain, int* he { return -ENOMEM; } + domain->tag = malloc(10); + if (!domain->tag) + { + free(domain->processorList); + return -ENOMEM; + } for (int i = 0; i < numatopo->nodes[nodeId].numberOfProcessors; i++) { for (int j = 0; j < cputopo->numHWThreads; j++) @@ -678,8 +709,7 @@ static int _affinity_addMemoryDomain(int nodeId, AffinityDomain* domain, int* he } domain->numberOfProcessors = num_hwthreads; domain->numberOfCores = affinity_countSocketCores(domain->numberOfProcessors, domain->processorList, help); - domain->tag = bformat("M%d", nodeId); - + snprintf(domain->tag, 9, "M%d", nodeId); return 0; } } @@ -718,9 +748,8 @@ static int affinity_addCudaDomain(int nodeId, AffinityDomain* domain, int offset err = _affinity_addMemoryDomain(cudadev->numaNode, domain, help); if (err == 0) { - bdestroy(domain->tag); - domain->tag = bformat("G%d", nodeId+offset); - DEBUG_PRINT(DEBUGLEV_DEVELOP, Affinity domain %s: %d HW threads on %d cores, bdata(domain->tag), domain->numberOfProcessors, domain->numberOfCores); + snprintf(domain->tag, 9, "G%d", nodeId+offset); + DEBUG_PRINT(DEBUGLEV_DEVELOP, Affinity domain %s: %d HW threads on %d cores, domain->tag, domain->numberOfProcessors, domain->numberOfCores); return 0; } } @@ -752,9 +781,8 @@ static int affinity_addRocmDomain(int nodeId, AffinityDomain* domain, int offset err = _affinity_addMemoryDomain(rocmdev->numaNode, domain, help); if (err == 0) { - bdestroy(domain->tag); - domain->tag = bformat("G%d", nodeId+offset); - DEBUG_PRINT(DEBUGLEV_DEVELOP, Affinity domain %s: %d HW threads on %d cores, bdata(domain->tag), domain->numberOfProcessors, domain->numberOfCores); + snprintf(domain->tag, 9, "G%d", nodeId+offset); + DEBUG_PRINT(DEBUGLEV_DEVELOP, Affinity domain %s: %d HW threads on %d cores, domain->tag, domain->numberOfProcessors, domain->numberOfCores); return 0; } } @@ -1022,8 +1050,10 @@ affinity_finalize() } for ( int i=0; i < affinityDomains.numberOfAffinityDomains; i++ ) { - if (affinityDomains.domains[i].tag) - bdestroy(affinityDomains.domains[i].tag); + if (affinityDomains.domains[i].tag != NULL) + { + free(affinityDomains.domains[i].tag); + } if (affinityDomains.domains[i].processorList != NULL) { free(affinityDomains.domains[i].processorList); @@ -1179,12 +1209,12 @@ affinity_pinProcesses(int cpu_count, const int* processorIds) } const AffinityDomain* -affinity_getDomain(bstring domain) +affinity_getDomain(char* domain) { for ( int i=0; i < affinity_numberOfDomains; i++ ) { - if ( biseq(domain, domains[i].tag) ) + if ( strncmp(domains[i].tag, domain, strlen(domains[i].tag)) == 0 ) { return domains+i; } @@ -1199,7 +1229,7 @@ affinity_printDomains() for ( int i=0; i < affinity_numberOfDomains; i++ ) { printf("Domain %d:\n",i); - printf("\tTag %s:",bdata(domains[i].tag)); + printf("\tTag %s:", domains[i].tag); for ( uint32_t j=0; j < domains[i].numberOfProcessors; j++ ) { diff --git a/src/cpustring.c b/src/cpustring.c index 63ca736e8..65082b20a 100644 --- a/src/cpustring.c +++ b/src/cpustring.c @@ -122,13 +122,13 @@ cpu_in_domain(int domainidx, int cpu) } static int -get_domain_idx(bstring bdomain) +get_domain_idx(char* bdomain) { affinity_init(); AffinityDomains_t affinity = get_affinityDomains(); for (int i=0;inumberOfAffinityDomains; i++) { - if (bstrcmp(affinity->domains[i].tag, bdomain) == BSTR_OK) + if (strncmp(affinity->domains[i].tag, bdomain, strlen(affinity->domains[i].tag)) == BSTR_OK) { return i; } @@ -155,7 +155,7 @@ cpuexpr_to_list(bstring bcpustr, bstring prefix, int* list, int length) oldinsert = insert; for (int j = 0; j < affinity->numberOfAffinityDomains; j++) { - if (bstrcmp(affinity->domains[j].tag, newstr) == 0) + if (strncmp(affinity->domains[j].tag, bdata(newstr), strlen(affinity->domains[j].tag)) == 0) { tmp = check_and_atoi(bdata(strlist->entry[i])); if (tmp >= 0) @@ -213,7 +213,7 @@ cpustr_to_cpulist_method(bstring bcpustr, int* cpulist, int length) } for (int i=0; inumberOfAffinityDomains; i++) { - if (binstr(affinity->domains[i].tag, 0, parts->entry[0]) != BSTR_ERR && + if (strstr(affinity->domains[i].tag, bdata(parts->entry[0])) != NULL && affinity->domains[i].numberOfProcessors > 0) { suitable[suitidx] = i; @@ -387,12 +387,12 @@ cpustr_to_cpulist_expression(bstring bcpustr, int* cpulist, int length) CpuTopology_t cpuid_topology = get_cpuTopology(); affinity_init(); AffinityDomains_t affinity = get_affinityDomains(); - bstring bdomain; int domainidx = -1; int count = 0; int stride = 0; int chunk = 0; int off = 0; + bstring bdomain; if (bstrchrp(bcpustr, 'E', 0) != 0) { fprintf(stderr, "Not a valid CPU expression\n"); @@ -436,7 +436,7 @@ cpustr_to_cpulist_expression(bstring bcpustr, int* cpulist, int length) bstrListDestroy(strlist); return 0; } - domainidx = get_domain_idx(bdomain); + domainidx = get_domain_idx(bdata(bdomain)); if (domainidx < 0) { fprintf(stderr, "Cannot find domain %s\n", bdata(bdomain)); @@ -505,7 +505,7 @@ cpustr_to_cpulist_logical(bstring bcpustr, int* cpulist, int length) bdomain = bstrcpy(strlist->entry[1]); blist = bstrcpy(strlist->entry[2]); bstrListDestroy(strlist); - domainidx = get_domain_idx(bdomain); + domainidx = get_domain_idx(bdata(bdomain)); if (domainidx < 0) { fprintf(stderr, "ERROR: Cannot find domain %s\n", bdata(bdomain)); @@ -565,7 +565,7 @@ cpustr_to_cpulist_logical(bstring bcpustr, int* cpulist, int length) { fprintf(stderr, "WARN: Selected affinity domain %s has only %d hardware threads, but selection string evaluates to %d threads.\n", - bdata(affinity->domains[domainidx].tag), ret, require); + affinity->domains[domainidx].tag, ret, require); fprintf(stderr, " This results in multiple threads on the same hardware thread.\n"); return 0; } @@ -680,7 +680,7 @@ cpustr_to_cpulist_physical(bstring bcpustr, int* cpulist, int length) bdomain = bformat("N"); blist = bstrcpy(bcpustr); } - domainidx = get_domain_idx(bdomain); + domainidx = get_domain_idx(bdata(bdomain)); if (domainidx < 0) { fprintf(stderr, "Cannot find domain %s\n", bdata(bdomain)); @@ -688,7 +688,7 @@ cpustr_to_cpulist_physical(bstring bcpustr, int* cpulist, int length) bdestroy(blist); return 0; } - bstring domtag = affinity->domains[domainidx].tag; + char* domtag = affinity->domains[domainidx].tag; strlist = bsplit(blist, ','); int insert = 0; @@ -731,7 +731,7 @@ cpustr_to_cpulist_physical(bstring bcpustr, int* cpulist, int length) notInCpuSet = 1; } } - fprintf(stderr, "CPU %d not in domain %s.", j, bdata(domtag)); + fprintf(stderr, "CPU %d not in domain %s.", j, domtag); if (notInCpuSet) { fprintf(stderr, " It is not in the given cpuset\n"); @@ -767,7 +767,7 @@ cpustr_to_cpulist_physical(bstring bcpustr, int* cpulist, int length) notInCpuSet = 1; } } - fprintf(stderr, "CPU %d not in domain %s.", j, bdata(domtag)); + fprintf(stderr, "CPU %d not in domain %s.", j, domtag); if (notInCpuSet) { fprintf(stderr, " It is not in the given cpuset\n"); @@ -808,7 +808,7 @@ cpustr_to_cpulist_physical(bstring bcpustr, int* cpulist, int length) notInCpuSet = 1; } } - fprintf(stderr, "CPU %d not in domain %s.", cpu, bdata(domtag)); + fprintf(stderr, "CPU %d not in domain %s.", cpu, domtag); if (notInCpuSet) { fprintf(stderr, " It is not in the given cpuset\n"); @@ -889,7 +889,7 @@ cpustr_to_cpulist(const char* cpustring, int* cpulist, int length) } else { - int dom = get_domain_idx(strlist->entry[i]); + int dom = get_domain_idx(bdata(strlist->entry[i])); if (dom >= 0) { AffinityDomains_t affinity = get_affinityDomains(); diff --git a/src/includes/affinity.h b/src/includes/affinity.h index 14efa190d..c515afed3 100644 --- a/src/includes/affinity.h +++ b/src/includes/affinity.h @@ -51,6 +51,6 @@ extern int *affinity_thread2die_lookup; extern int *affinity_thread2sharedl3_lookup; extern int affinity_processGetProcessorId(); extern int affinity_threadGetProcessorId(); -extern const AffinityDomain* affinity_getDomain(bstring domain); +extern const AffinityDomain* affinity_getDomain(char* domain); #endif /*AFFINITY_H*/ diff --git a/src/includes/likwid.h b/src/includes/likwid.h index 65386fb14..bcfd50f57 100644 --- a/src/includes/likwid.h +++ b/src/includes/likwid.h @@ -677,7 +677,7 @@ system. Example domains are NUMA nodes, CPU sockets/packages or LLC (Last Level Cache) cache domains. \extends AffinityDomains */ typedef struct { - bstring tag; /*!< \brief Bstring with the ID for the affinity domain. + char* tag; /*!< \brief Bstring with the ID for the affinity domain. Currently possible values: N (node), SX (socket/package X), CX (LLC cache domain X) and MX (memory domain X) */ uint32_t numberOfProcessors; /*!< \brief Number of HW threads in the domain diff --git a/src/luawid.c b/src/luawid.c index 0225ff804..993d653d8 100644 --- a/src/luawid.c +++ b/src/luawid.c @@ -1222,7 +1222,7 @@ static int lua_likwid_getAffinityInfo(lua_State *L) { lua_pushinteger(L, (lua_Integer)(i + 1)); lua_newtable(L); lua_pushstring(L, "tag"); - lua_pushstring(L, bdata(affinity->domains[i].tag)); + lua_pushstring(L, affinity->domains[i].tag); lua_settable(L, -3); lua_pushstring(L, "numberOfProcessors"); lua_pushinteger(L, (lua_Integer)(affinity->domains[i].numberOfProcessors));