From ba8b2dc9ec4860e2e541215576e676216fee3666 Mon Sep 17 00:00:00 2001 From: Thomas Roehl Date: Thu, 12 Sep 2024 17:37:55 +0200 Subject: [PATCH] Fix for perfmon_init_maps if already initialized. Proper error checks --- src/luawid.c | 6 +++++- src/perfmon.c | 5 ++++- src/power.c | 6 +++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/luawid.c b/src/luawid.c index 59c8aed4..cfaebd18 100644 --- a/src/luawid.c +++ b/src/luawid.c @@ -882,7 +882,11 @@ lua_likwid_getEventsAndCounters(lua_State* L) affinity_init(); affinity_isInitialized = 1; } - perfmon_init_maps(); + int err = perfmon_init_maps(); + if (err != 0) + { + return 0; + } perfmon_check_counter_map(0); char** archTypeNames = getArchRegisterTypeNames(); lua_newtable(L); diff --git a/src/perfmon.c b/src/perfmon.c index 757be7fa..9daf14ec 100644 --- a/src/perfmon.c +++ b/src/perfmon.c @@ -876,7 +876,10 @@ perfmon_init_maps(void) { int err = 0; if (eventHash != NULL && counter_map != NULL && box_map != NULL && perfmon_numCounters > 0 && perfmon_numArchEvents > 0) - return -EINVAL; + { + // Already initialized + return 0; + } switch ( cpuid_info.family ) { case P6_FAMILY: diff --git a/src/power.c b/src/power.c index 134e00ae..b223925f 100644 --- a/src/power.c +++ b/src/power.c @@ -238,7 +238,11 @@ power_init(int cpuId) break; } - perfmon_init_maps(); + err = perfmon_init_maps(); + if (err != 0) + { + return err; + } if (!HPMinitialized()) { HPMinit();