static int lua_likwid_getCpuInfo(lua_State* L) { if (topology_isInitialized == 0) { topology_init(); topology_isInitialized = 1; cpuinfo = get_cpuInfo(); } if ((topology_isInitialized) && (cpuinfo == NULL)) { cpuinfo = get_cpuInfo(); } lua_newtable(L); lua_pushstring(L,"family"); lua_pushunsigned(L,cpuinfo->family); lua_settable(L,-3); lua_pushstring(L,"model"); lua_pushunsigned(L,cpuinfo->model); lua_settable(L,-3); lua_pushstring(L,"stepping"); lua_pushunsigned(L,cpuinfo->stepping); lua_settable(L,-3); lua_pushstring(L,"clock"); lua_pushunsigned(L,cpuinfo->clock); lua_settable(L,-3); lua_pushstring(L,"turbo"); lua_pushinteger(L,cpuinfo->turbo); lua_settable(L,-3); lua_pushstring(L,"name"); lua_pushstring(L,cpuinfo->name); lua_settable(L,-3); lua_pushstring(L,"osname"); lua_pushstring(L,cpuinfo->osname); lua_settable(L,-3); lua_pushstring(L,"short_name"); lua_pushstring(L,cpuinfo->short_name); lua_settable(L,-3); lua_pushstring(L,"features"); lua_pushstring(L,cpuinfo->features); lua_settable(L,-3); lua_pushstring(L,"isIntel"); lua_pushinteger(L,cpuinfo->isIntel); lua_settable(L,-3); lua_pushstring(L,"featureFlags"); lua_pushunsigned(L,cpuinfo->featureFlags); lua_settable(L,-3); lua_pushstring(L,"perf_version"); lua_pushunsigned(L, cpuinfo->perf_version); lua_settable(L,-3); lua_pushstring(L,"perf_num_ctr"); lua_pushunsigned(L,cpuinfo->perf_num_ctr); lua_settable(L,-3); lua_pushstring(L,"perf_width_ctr"); lua_pushunsigned(L,cpuinfo->perf_width_ctr); lua_settable(L,-3); lua_pushstring(L,"perf_num_fixed_ctr"); lua_pushunsigned(L,cpuinfo->perf_num_fixed_ctr); lua_settable(L,-3); return 1; }
static int lua_likwid_init(lua_State* L) { int ret; int nrThreads = luaL_checknumber(L,1); luaL_argcheck(L, nrThreads > 0, 1, "CPU count must be greater than 0"); int cpus[nrThreads]; if (!lua_istable(L, -1)) { lua_pushstring(L,"No table given as second argument"); lua_error(L); } for (ret = 1; ret<=nrThreads; ret++) { lua_rawgeti(L,-1,ret); cpus[ret-1] = lua_tounsigned(L,-1); lua_pop(L,1); } if (topology_isInitialized == 0) { topology_init(); topology_isInitialized = 1; cpuinfo = get_cpuInfo(); cputopo = get_cpuTopology(); } if ((topology_isInitialized) && (cpuinfo == NULL)) { cpuinfo = get_cpuInfo(); } if ((topology_isInitialized) && (cputopo == NULL)) { cputopo = get_cpuTopology(); } if (numa_isInitialized == 0) { numa_init(); numa_isInitialized = 1; numainfo = get_numaTopology(); } if ((numa_isInitialized) && (numainfo == NULL)) { numainfo = get_numaTopology(); } if (perfmon_isInitialized == 0) { ret = perfmon_init(nrThreads, &(cpus[0])); if (ret != 0) { lua_pushstring(L,"Cannot initialize likwid perfmon"); lua_error(L); return 1; } perfmon_isInitialized = 1; timer_isInitialized = 1; lua_pushinteger(L,ret); } return 1; }
int test_perfmonstop_noadd() { CpuInfo_t cpuinfo; int cpu = 0; int group; topology_init(); cpuinfo = get_cpuInfo(); if (cpuinfo->isIntel == 0) { topology_finalize(); return 1; } int ret = perfmon_init(1, &cpu); if (ret != 0) goto fail; ret = perfmon_stopCounters(); if (ret == 0) goto fail; perfmon_finalize(); topology_finalize(); return 1; fail: perfmon_finalize(); topology_finalize(); return 0; }
int test_perfmonstart() { CpuInfo_t cpuinfo; int group1, group2; int cpu = 0; topology_init(); cpuinfo = get_cpuInfo(); if (cpuinfo->isIntel == 0) { topology_finalize(); return 1; } int ret = perfmon_init(1, &cpu); if (ret != 0) goto fail; ret = perfmon_addEventSet(eventset_ok); if (ret != 0) goto fail; group1 = ret; ret = perfmon_setupCounters(group1); if (ret != 0) goto fail; if (perfmon_getIdOfActiveGroup() != group1) goto fail; ret = perfmon_startCounters(); if (ret != 0) goto fail; perfmon_finalize(); topology_finalize(); return 1; fail: perfmon_finalize(); topology_finalize(); return 0; }
int test_perfmonstop_nostart() { CpuInfo_t cpuinfo; int cpu = 0; int group; topology_init(); cpuinfo = get_cpuInfo(); if (cpuinfo->isIntel == 0) { topology_finalize(); return 1; } int ret = perfmon_init(1, &cpu); if (ret != 0) goto fail; ret = perfmon_addEventSet(eventset_ok); if (ret != 0) goto fail; group = ret; ret = perfmon_setupCounters(group); if (ret != 0) goto fail; ret = perfmon_stopCounters(); if (ret == 0) goto fail; perfmon_finalize(); topology_finalize(); return 1; fail: perfmon_finalize(); topology_finalize(); return 0; }
int test_perfmonresult_noadd() { CpuInfo_t cpuinfo; int cpu = 0; int group; topology_init(); cpuinfo = get_cpuInfo(); if (cpuinfo->isIntel == 0) { topology_finalize(); return 1; } int ret = perfmon_init(1, &cpu); if (ret != 0) goto fail; double result = perfmon_getResult(0,0,0); if (result != 0) goto fail; perfmon_finalize(); topology_finalize(); return 1; fail: perfmon_finalize(); topology_finalize(); return 0; }
int main(int argc, char* argv[]) { int i; int* cpus; int gid; double result = 0.0; // Load the topology module and print some values. topology_init(); // CpuInfo_t contains global information like name, CPU family, ... CpuInfo_t info = get_cpuInfo(); // CpuTopology_t contains information about the topology of the CPUs. CpuTopology_t topo = get_cpuTopology(); printf("Likwid example on a %s with %d CPUs\n", info->name, topo->numHWThreads); cpus = malloc(topo->numHWThreads * sizeof(int)); if (!cpus) return 1; for (i=0;i<topo->numHWThreads;i++) { cpus[i] = topo->threadPool[i].apicId; } // Must be called before perfmon_init() but only if you want to use another // access mode as the pre-configured one. For direct access (0) you have to // be root. //accessClient_setaccessmode(0); // Initialize the perfmon module. perfmon_init(topo->numHWThreads, cpus); // Add eventset string to the perfmon module. gid = perfmon_addEventSet(EVENTSET); // Setup the eventset identified by group ID (gid). perfmon_setupCounters(gid); // Start all counters in the previously set up event set. perfmon_startCounters(); // Perform something sleep(2); // Stop all counters in the previously started event set. perfmon_stopCounters(); // Print the result of every thread/CPU. for (i = 0;i < topo->numHWThreads; i++) { result = perfmon_getResult(gid, 0, i); printf("Measurement result for event set %s at CPU %d: %f\n", EVENTSET, cpus[i], result); } // Uninitialize the perfmon module. perfmon_finalize(); // Uninitialize the topology module. topology_finalize(); return 0; }
int test_perfmonresult() { CpuInfo_t cpuinfo; int cpu = 0; int group; topology_init(); cpuinfo = get_cpuInfo(); if (cpuinfo->isIntel == 0) { topology_finalize(); return 1; } int ret = perfmon_init(1, &cpu); if (ret != 0) goto fail; ret = perfmon_addEventSet(eventset_ok); if (ret != 0) goto fail; group = ret; ret = perfmon_setupCounters(group); if (ret != 0) goto fail; ret = perfmon_startCounters(); if (ret != 0) goto fail; sleep(1); ret = perfmon_stopCounters(); if (ret != 0) goto fail; if ((perfmon_getResult(group,0,0) == 0)||(perfmon_getResult(group,1,0) == 0)) goto fail; if (perfmon_getTimeOfGroup(group) == 0) goto fail; perfmon_finalize(); topology_finalize(); return 1; fail: perfmon_finalize(); topology_finalize(); return 0; }
int test_perfmonperfgroup() { CpuInfo_t cpuinfo; int i; int cpu = 0; topology_init(); cpuinfo = get_cpuInfo(); int ret = perfmon_init(1, &cpu); if (ret != 0) { printf("Perfmon init failed\n"); goto fail; } char** glist = NULL; char** slist = NULL; char** llist = NULL; ret = perfmon_getGroups(&glist, &slist, &llist); if (ret <= 0) { goto fail; } ret = perfmon_addEventSet(glist[0]); if (ret != 0) { printf("Perfmon addEventSet(%s) failed\n", glist[0]); goto fail; } if (perfmon_getNumberOfEvents(ret) == 0) { printf("Perfmon number of events == 0\n"); goto fail; } if (perfmon_getNumberOfMetrics(ret) == 0) { printf("Perfmon number of metrics == 0\n"); goto fail; } for (i=0; i<perfmon_getNumberOfEvents(ret); i++) { if (strcmp(perfmon_getEventName(ret, i), "") == 0) goto fail; if (strcmp(perfmon_getCounterName(ret, i), "") == 0) goto fail; } if (strcmp(perfmon_getGroupName(ret), "Custom") == 0) { goto fail; } if (strcmp(perfmon_getGroupInfoShort(ret), "Custom") == 0) { goto fail; } if (strcmp(perfmon_getGroupInfoLong(ret), "Custom") == 0) { goto fail; } if (perfmon_getLastTimeOfGroup(ret) != 0) { goto fail; } if (perfmon_getTimeOfGroup(ret) != 0) { goto fail; } for (i=0; i<perfmon_getNumberOfMetrics(ret); i++) { if (strcmp(perfmon_getMetricName(ret, i), "") == 0) goto fail; if (perfmon_getMetric(ret, i, 0) != 0.0) goto fail; } free(glist); free(slist); free(llist); perfmon_finalize(); affinity_finalize(); topology_finalize(); return 1; fail: if (glist) free(glist); if (slist) free(slist); if (llist) free(llist); perfmon_finalize(); affinity_finalize(); topology_finalize(); return 0; }
int test_perfmoncustomgroup() { CpuInfo_t cpuinfo; int cpu = 0; topology_init(); cpuinfo = get_cpuInfo(); int ret = perfmon_init(1, &cpu); if (ret != 0) { printf("Perfmon init failed\n"); goto fail; } ret = perfmon_addEventSet(eventset_ok); if (ret != 0) { printf("Perfmon addEventSet(ok) failed\n"); goto fail; } if (perfmon_getNumberOfEvents(ret) != 3) { printf("Perfmon number of events != 3\n"); goto fail; } if (perfmon_getNumberOfMetrics(ret) != 0) { printf("Perfmon number of metrics != 0\n"); goto fail; } if (strcmp(perfmon_getEventName(ret, 0), event1_ok) != 0) { goto fail; } if (strcmp(perfmon_getEventName(ret, 1), event2_ok) != 0) { goto fail; } if (strcmp(perfmon_getEventName(ret, 2), event3_ok) != 0) { goto fail; } if (strcmp(perfmon_getCounterName(ret, 0), ctr1_ok) != 0) { goto fail; } if (strcmp(perfmon_getCounterName(ret, 1), ctr2_ok) != 0) { goto fail; } if (strcmp(perfmon_getCounterName(ret, 2), ctr3_ok) != 0) { goto fail; } if (strcmp(perfmon_getGroupName(ret), "Custom") != 0) { goto fail; } if (strcmp(perfmon_getGroupInfoShort(ret), "Custom") != 0) { goto fail; } if (strcmp(perfmon_getGroupInfoLong(ret), "Custom") != 0) { goto fail; } if (perfmon_getLastTimeOfGroup(ret) != 0) { goto fail; } perfmon_finalize(); affinity_finalize(); topology_finalize(); return 1; fail: perfmon_finalize(); affinity_finalize(); topology_finalize(); return 0; }
int test_perfmonaddeventset() { char eventset_fail1[] = "INSTR_RETIRED.ANY:FIXC0"; char eventset_fail2[] = "INSTR_RETIRED-ANY:FIXC0"; CpuInfo_t cpuinfo; int cpu = 0; topology_init(); cpuinfo = get_cpuInfo(); if (cpuinfo->isIntel == 0) { topology_finalize(); return 1; } int ret = perfmon_init(1, &cpu); if (ret != 0) { printf("Perfmon init failed\n"); goto fail; } if (perfmon_getNumberOfGroups() != 0) { printf("Perfmon number of groups != 0\n"); goto fail; } if (perfmon_getNumberOfThreads() != 1) { printf("Perfmon number of threads != 1\n"); goto fail; } if (perfmon_getIdOfActiveGroup() != -1) { printf("Perfmon id of active group != -1\n"); goto fail; } ret = perfmon_addEventSet(eventset_ok); if (ret != 0) { printf("Perfmon addEventSet(ok) failed\n"); goto fail; } if (perfmon_getNumberOfGroups() != 1) { printf("Perfmon number of groups != 1\n"); goto fail; } if (perfmon_getNumberOfEvents(ret) != 3) { printf("Perfmon number of events != 3\n"); goto fail; } if (perfmon_getIdOfActiveGroup() != -1) { printf("Perfmon id of active group != -1\n"); goto fail; } ret = perfmon_addEventSet(eventset_option); if (ret != 1) { printf("Perfmon addEventSet(options) failed\n"); goto fail; } if (perfmon_getNumberOfGroups() != 2) { printf("Perfmon number of groups != 2\n"); goto fail; } if (perfmon_getNumberOfEvents(ret) != 3) { printf("Perfmon number of events != 3\n"); goto fail; } if (perfmon_getIdOfActiveGroup() != -1) { printf("Perfmon id of active group != -1\n"); goto fail; } ret = perfmon_addEventSet(eventset_fail1); if (ret >= 0) { printf("Perfmon addEventSet(fail1) failed\n"); goto fail; } if (perfmon_getNumberOfGroups() != 2) { printf("Perfmon number of groups != 2\n"); goto fail; } ret = perfmon_addEventSet(eventset_fail2); if (ret >= 0) { printf("Perfmon addEventSet(fail2) failed\n"); goto fail; } if (perfmon_getNumberOfGroups() != 2) { printf("Perfmon number of groups != 2\n"); goto fail; } if (perfmon_getIdOfActiveGroup() != -1) { printf("Perfmon id of active group != -1\n"); goto fail; } perfmon_finalize(); affinity_finalize(); topology_finalize(); return 1; fail: perfmon_finalize(); affinity_finalize(); topology_finalize(); return 0; }
static int lua_likwid_getAffinityInfo(lua_State* L) { int i,j; if (topology_isInitialized == 0) { topology_init(); topology_isInitialized = 1; cpuinfo = get_cpuInfo(); cputopo = get_cpuTopology(); } if ((topology_isInitialized) && (cpuinfo == NULL)) { cpuinfo = get_cpuInfo(); } 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(); } if (affinity_isInitialized == 0) { affinity_init(); affinity_isInitialized = 1; affinity = get_affinityDomains(); } if ((affinity_isInitialized) && (affinity == NULL)) { affinity = get_affinityDomains(); } if (!affinity) { lua_pushstring(L,"Cannot initialize affinity groups"); lua_error(L); } lua_newtable(L); lua_pushstring(L,"numberOfAffinityDomains"); lua_pushunsigned(L,affinity->numberOfAffinityDomains); lua_settable(L,-3); lua_pushstring(L,"numberOfSocketDomains"); lua_pushunsigned(L,affinity->numberOfSocketDomains); lua_settable(L,-3); lua_pushstring(L,"numberOfNumaDomains"); lua_pushunsigned(L,affinity->numberOfNumaDomains); lua_settable(L,-3); lua_pushstring(L,"numberOfProcessorsPerSocket"); lua_pushunsigned(L,affinity->numberOfProcessorsPerSocket); lua_settable(L,-3); lua_pushstring(L,"numberOfCacheDomains"); lua_pushunsigned(L,affinity->numberOfCacheDomains); lua_settable(L,-3); lua_pushstring(L,"numberOfCoresPerCache"); lua_pushunsigned(L,affinity->numberOfCoresPerCache); lua_settable(L,-3); lua_pushstring(L,"numberOfProcessorsPerCache"); lua_pushunsigned(L,affinity->numberOfProcessorsPerCache); lua_settable(L,-3); lua_pushstring(L,"domains"); lua_newtable(L); for(i=0;i<affinity->numberOfAffinityDomains;i++) { lua_pushunsigned(L, i+1); lua_newtable(L); lua_pushstring(L,"tag"); lua_pushstring(L,bdata(affinity->domains[i].tag)); lua_settable(L,-3); lua_pushstring(L,"numberOfProcessors"); lua_pushunsigned(L,affinity->domains[i].numberOfProcessors); lua_settable(L,-3); lua_pushstring(L,"numberOfCores"); lua_pushunsigned(L,affinity->domains[i].numberOfCores); lua_settable(L,-3); lua_pushstring(L,"processorList"); lua_newtable(L); for(j=0;j<affinity->domains[i].numberOfProcessors;j++) { lua_pushunsigned(L,j+1); lua_pushunsigned(L,affinity->domains[i].processorList[j]); lua_settable(L,-3); } lua_settable(L,-3); lua_settable(L,-3); } lua_settable(L,-3); return 1; }
static int lua_likwid_getNumaInfo(lua_State* L) { uint32_t i,j; if (topology_isInitialized == 0) { topology_init(); topology_isInitialized = 1; cpuinfo = get_cpuInfo(); cputopo = get_cpuTopology(); } if ((topology_isInitialized) && (cpuinfo == NULL)) { cpuinfo = get_cpuInfo(); } if ((topology_isInitialized) && (cputopo == NULL)) { cputopo = get_cpuTopology(); } if (numa_isInitialized == 0) { if (numa_init() == 0) { numa_isInitialized = 1; numainfo = get_numaTopology(); } else { lua_newtable(L); lua_pushstring(L,"numberOfNodes"); lua_pushunsigned(L,0); lua_settable(L,-3); lua_pushstring(L,"nodes"); lua_newtable(L); lua_settable(L,-3); return 1; } } if ((numa_isInitialized) && (numainfo == NULL)) { numainfo = get_numaTopology(); } if (affinity_isInitialized == 0) { affinity_init(); affinity_isInitialized = 1; affinity = get_affinityDomains(); } if ((affinity_isInitialized) && (affinity == NULL)) { affinity = get_affinityDomains(); } lua_newtable(L); lua_pushstring(L,"numberOfNodes"); lua_pushunsigned(L,numainfo->numberOfNodes); lua_settable(L,-3); lua_pushstring(L,"nodes"); lua_newtable(L); for(i=0;i<numainfo->numberOfNodes;i++) { lua_pushinteger(L, i+1); lua_newtable(L); lua_pushstring(L,"id"); lua_pushunsigned(L,numainfo->nodes[i].id); lua_settable(L,-3); lua_pushstring(L,"totalMemory"); lua_pushunsigned(L,numainfo->nodes[i].totalMemory); lua_settable(L,-3); lua_pushstring(L,"freeMemory"); lua_pushunsigned(L,numainfo->nodes[i].freeMemory); lua_settable(L,-3); lua_pushstring(L,"numberOfProcessors"); lua_pushunsigned(L,numainfo->nodes[i].numberOfProcessors); lua_settable(L,-3); lua_pushstring(L,"numberOfDistances"); lua_pushunsigned(L,numainfo->nodes[i].numberOfDistances); lua_settable(L,-3); lua_pushstring(L,"processors"); lua_newtable(L); for(j=0;j<numainfo->nodes[i].numberOfProcessors;j++) { lua_pushunsigned(L,j+1); lua_pushunsigned(L,numainfo->nodes[i].processors[j]); lua_settable(L,-3); } lua_settable(L,-3); /*lua_pushstring(L,"processorsCompact"); lua_newtable(L); for(j=0;j<numa->nodes[i].numberOfProcessors;j++) { lua_pushunsigned(L,j); lua_pushunsigned(L,numa->nodes[i].processorsCompact[j]); lua_settable(L,-3); } lua_settable(L,-3);*/ lua_pushstring(L,"distances"); lua_newtable(L); for(j=0;j<numainfo->nodes[i].numberOfDistances;j++) { lua_pushinteger(L,j+1); lua_newtable(L); lua_pushinteger(L,j); lua_pushunsigned(L,numainfo->nodes[i].distances[j]); lua_settable(L,-3); lua_settable(L,-3); } lua_settable(L,-3); lua_settable(L,-3); } lua_settable(L,-3); return 1; }
static int lua_likwid_getEventsAndCounters(lua_State* L) { int i; char optString[1024]; int optStringIndex = 0; if (topology_isInitialized == 0) { topology_init(); topology_isInitialized = 1; cpuinfo = get_cpuInfo(); } if ((topology_isInitialized) && (cpuinfo == NULL)) { cpuinfo = get_cpuInfo(); } perfmon_init_maps(); lua_newtable(L); lua_pushstring(L,"Counters"); lua_newtable(L); for(i=1;i<=perfmon_numCounters;i++) { optStringIndex = 0; optString[0] = '\0'; lua_pushunsigned(L,i); lua_newtable(L); lua_pushstring(L,"Name"); lua_pushstring(L,counter_map[i-1].key); lua_settable(L,-3); lua_pushstring(L,"Options"); for(int j=1; j<NUM_EVENT_OPTIONS; j++) { if (counter_map[i-1].optionMask & REG_TYPE_MASK(j)) { optStringIndex += sprintf(&(optString[optStringIndex]), "%s|", eventOptionTypeName[j]); } } optString[optStringIndex-1] = '\0'; lua_pushstring(L,optString); lua_settable(L,-3); lua_pushstring(L,"Type"); lua_pushunsigned(L, counter_map[i-1].type); lua_settable(L,-3); lua_pushstring(L,"TypeName"); lua_pushstring(L, RegisterTypeNames[counter_map[i-1].type]); lua_settable(L,-3); lua_pushstring(L,"Index"); lua_pushunsigned(L,counter_map[i-1].index); lua_settable(L,-3); lua_settable(L,-3); } lua_settable(L,-3); lua_pushstring(L,"Events"); lua_newtable(L); for(i=1;i<=perfmon_numArchEvents;i++) { optStringIndex = 0; optString[0] = '\0'; lua_pushunsigned(L,i); lua_newtable(L); lua_pushstring(L,"Name"); lua_pushstring(L,eventHash[i-1].name); lua_settable(L,-3); lua_pushstring(L,"ID"); lua_pushunsigned(L,eventHash[i-1].eventId); lua_settable(L,-3); lua_pushstring(L,"UMask"); lua_pushunsigned(L,eventHash[i-1].umask); lua_settable(L,-3); lua_pushstring(L,"Limit"); lua_pushstring(L,eventHash[i-1].limit); lua_settable(L,-3); lua_pushstring(L,"Options"); for(int j=1; j<NUM_EVENT_OPTIONS; j++) { if (eventHash[i-1].optionMask & REG_TYPE_MASK(j)) { optStringIndex += sprintf(&(optString[optStringIndex]), "%s|", eventOptionTypeName[j]); } } optString[optStringIndex-1] = '\0'; lua_pushstring(L,optString); lua_settable(L,-3); lua_settable(L,-3); } lua_settable(L,-3); return 1; }
static int lua_likwid_getPowerInfo(lua_State* L) { int i; if (topology_isInitialized == 0) { topology_init(); topology_isInitialized = 1; cpuinfo = get_cpuInfo(); cputopo = get_cpuTopology(); } if ((topology_isInitialized) && (cpuinfo == NULL)) { cpuinfo = get_cpuInfo(); } if ((topology_isInitialized) && (cputopo == NULL)) { cputopo = get_cpuTopology(); } if (power_isInitialized == 0) { power_hasRAPL = power_init(0); if (power_hasRAPL) { power_isInitialized = 1; power = get_powerInfo(); } else { return 0; } } lua_newtable(L); lua_pushstring(L,"hasRAPL"); lua_pushboolean(L,power_hasRAPL); lua_settable(L,-3); lua_pushstring(L,"baseFrequency"); lua_pushnumber(L,power->baseFrequency); lua_settable(L,-3); lua_pushstring(L,"minFrequency"); lua_pushnumber(L,power->minFrequency); lua_settable(L,-3); lua_pushstring(L,"powerUnit"); lua_pushnumber(L,power->powerUnit); lua_settable(L,-3); lua_pushstring(L,"timeUnit"); lua_pushnumber(L,power->timeUnit); lua_settable(L,-3); lua_pushstring(L,"turbo"); lua_newtable(L); lua_pushstring(L,"numSteps"); lua_pushunsigned(L,power->turbo.numSteps); lua_settable(L,-3); lua_pushstring(L,"steps"); lua_newtable(L); for(i=0;i<power->turbo.numSteps;i++) { lua_pushunsigned(L,i+1); lua_pushnumber(L,power->turbo.steps[i]); lua_settable(L,-3); } lua_settable(L,-3); lua_settable(L,-3); lua_pushstring(L,"domains"); lua_newtable(L); for(i=0;i<NUM_POWER_DOMAINS;i++) { lua_pushstring(L,power_names[i]); lua_newtable(L); lua_pushstring(L, "ID"); lua_pushnumber(L, power->domains[i].type); lua_settable(L,-3); lua_pushstring(L, "energyUnit"); lua_pushnumber(L, power->domains[i].energyUnit); lua_settable(L,-3); lua_pushstring(L,"supportStatus"); if (power->domains[i].supportFlags & POWER_DOMAIN_SUPPORT_STATUS) { lua_pushboolean(L, 1); } else { lua_pushboolean(L, 0); } lua_settable(L,-3); lua_pushstring(L,"supportPerf"); if (power->domains[i].supportFlags & POWER_DOMAIN_SUPPORT_PERF) { lua_pushboolean(L, 1); } else { lua_pushboolean(L, 0); } lua_settable(L,-3); lua_pushstring(L,"supportPolicy"); if (power->domains[i].supportFlags & POWER_DOMAIN_SUPPORT_POLICY) { lua_pushboolean(L, 1); } else { lua_pushboolean(L, 0); } lua_settable(L,-3); lua_pushstring(L,"supportLimit"); if (power->domains[i].supportFlags & POWER_DOMAIN_SUPPORT_LIMIT) { lua_pushboolean(L, 1); } else { lua_pushboolean(L, 0); } lua_settable(L,-3); if (power->domains[i].supportFlags & POWER_DOMAIN_SUPPORT_INFO) { lua_pushstring(L,"supportInfo"); lua_pushboolean(L, 1); lua_settable(L,-3); lua_pushstring(L,"tdp"); lua_pushnumber(L, power->domains[i].tdp); lua_settable(L,-3); lua_pushstring(L,"minPower"); lua_pushnumber(L, power->domains[i].minPower); lua_settable(L,-3); lua_pushstring(L,"maxPower"); lua_pushnumber(L, power->domains[i].maxPower); lua_settable(L,-3); lua_pushstring(L,"maxTimeWindow"); lua_pushnumber(L, power->domains[i].maxTimeWindow); lua_settable(L,-3); } else { lua_pushstring(L,"supportInfo"); lua_pushboolean(L, 0); lua_settable(L,-3); } lua_settable(L,-3); } lua_settable(L,-3); return 1; }
int test_topologyinit() { int i, j; int ret = topology_init(); if (ret != 0) goto fail; CpuInfo_t cpuinfo = get_cpuInfo(); if (cpuinfo == NULL) goto fail; if (cpuinfo->family == 0) goto fail; if (cpuinfo->model == 0) goto fail; if (cpuinfo->osname == NULL) goto fail; if (cpuinfo->name == NULL) goto fail; if (cpuinfo->features == NULL) goto fail; CpuTopology_t cputopo = get_cpuTopology(); if (cputopo->threadPool == NULL) goto fail; if (cputopo->cacheLevels == NULL) goto fail; if (cputopo->numHWThreads == 0) goto fail; if (cputopo->activeHWThreads == 0) goto fail; if (cputopo->numSockets == 0) goto fail; if (cputopo->numCoresPerSocket < 1) goto fail; if (cputopo->numThreadsPerCore < 1) goto fail; if (cputopo->numHWThreads > 0) { for (i = 0; i < cputopo->numHWThreads; i++) { for (j=0;j< cputopo->numHWThreads; j++) { if ((i != j) && (cputopo->threadPool[i].apicId == cputopo->threadPool[j].apicId)) goto fail; } if (cputopo->threadPool[i].threadId >= cputopo->numThreadsPerCore) { goto fail; } if (cputopo->threadPool[i].packageId >= cputopo->numSockets) { goto fail; } } } if (cputopo->numCacheLevels > 0) { for (i=0;i<cputopo->numCacheLevels;i++) { if (cputopo->cacheLevels[i].level > cputopo->numCacheLevels) { goto fail; } } } isIntel = cpuinfo->isIntel; topology_finalize(); return 1; fail: topology_finalize(); return 0; }
int main(int argc, char* argv[]) { int i, j; int err; int* cpus; int gid; double result = 0.0; char estr[] = "INSTR_RETIRED_ANY:FIXC0,CPU_CLK_UNHALTED_CORE:FIXC1,CPU_CLK_UNHALTED_REF:FIXC2,TEMP_CORE:TMP0"; // Load the topology module and print some values. err = topology_init(); if (err < 0) { printf("Failed to initialize LIKWID's topology module\n"); return 1; } // CpuInfo_t contains global information like name, CPU family, ... CpuInfo_t info = get_cpuInfo(); // CpuTopology_t contains information about the topology of the CPUs. CpuTopology_t topo = get_cpuTopology(); // Create affinity domains. Commonly only needed when reading Uncore counters //affinity_init(); printf("Likwid example on a %s with %d CPUs\n", info->name, topo->numHWThreads); cpus = (int*)malloc(topo->numHWThreads * sizeof(int)); if (!cpus) return 1; for (i=0;i<topo->numHWThreads;i++) { cpus[i] = topo->threadPool[i].apicId; } // Must be called before perfmon_init() but only if you want to use another // access mode as the pre-configured one. For direct access (0) you have to // be root. //accessClient_setaccessmode(0); // Initialize the perfmon module. err = perfmon_init(topo->numHWThreads, cpus); if (err < 0) { printf("Failed to initialize LIKWID's performance monitoring module\n"); topology_finalize(); return 1; } // Add eventset string to the perfmon module. gid = perfmon_addEventSet(estr); if (gid < 0) { printf("Failed to add event string %s to LIKWID's performance monitoring module\n", estr); perfmon_finalize(); topology_finalize(); return 1; } // Setup the eventset identified by group ID (gid). err = perfmon_setupCounters(gid); if (err < 0) { printf("Failed to setup group %d in LIKWID's performance monitoring module\n", gid); perfmon_finalize(); topology_finalize(); return 1; } // Start all counters in the previously set up event set. err = perfmon_startCounters(); if (err < 0) { printf("Failed to start counters for group %d for thread %d\n",gid, (-1*err)-1); perfmon_finalize(); topology_finalize(); return 1; } // Perform something sleep(2); // Stop all counters in the previously started event set. err = perfmon_stopCounters(); if (err < 0) { printf("Failed to stop counters for group %d for thread %d\n",gid, (-1*err)-1); perfmon_finalize(); topology_finalize(); return 1; } // Print the result of every thread/CPU for all events in estr. char* ptr = strtok(estr,","); j = 0; while (ptr != NULL) { for (i = 0;i < topo->numHWThreads; i++) { result = perfmon_getResult(gid, j, cpus[i]); printf("Measurement result for event set %s at CPU %d: %f\n", ptr, cpus[i], result); } ptr = strtok(NULL,","); j++; } // Uninitialize the perfmon module. perfmon_finalize(); // Uninitialize the topology module. topology_finalize(); return 0; }