Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MarkerAPI: Truncate region tag. Fixes #551 #552

Merged
merged 1 commit into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 40 additions & 26 deletions src/libperfctr.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ static int registered_cpus = 0;
static pthread_mutex_t globalLock = PTHREAD_MUTEX_INITIALIZER;
static int use_locks = 0;
static pthread_mutex_t threadLocks[MAX_NUM_THREADS] = { [ 0 ... (MAX_NUM_THREADS-1)] = PTHREAD_MUTEX_INITIALIZER};
static int maxRegionNameLength = 100;


/* ##### MACROS - LOCAL TO THIS SOURCE FILE ######################### */
Expand Down Expand Up @@ -511,13 +512,15 @@ likwid_markerRegisterRegion(const char* regionTag)
TimerData timer;
int ret = 0;
uint64_t tmp = 0x0ULL;
bstring tag = bfromcstralloc(100, regionTag);
LikwidThreadResults* results;
char groupSuffix[10];
sprintf(groupSuffix, "-%d", groupSet->activeGroup);
bcatcstr(tag, groupSuffix);
LikwidThreadResults* results = NULL;
bstring tag = bformat("%.*s-%d", 100, regionTag, groupSet->activeGroup);
int cpu_id = hashTable_get(tag, &results);
bdestroy(tag);
if (!results)
{
fprintf(stderr, "ERROR: Failed to get thread data for tag %s\n", regionTag);
return -EFAULT;
}

#ifndef LIKWID_USE_PERFEVENT
// Add CPU to access layer if ACCESSMODE is direct or accessdaemon
Expand All @@ -532,6 +535,7 @@ likwid_markerRegisterRegion(const char* regionTag)
int
likwid_markerStartRegion(const char* regionTag)
{
LikwidThreadResults* results = NULL;
if ( ! likwid_init )
{
return -EFAULT;
Expand All @@ -542,13 +546,13 @@ likwid_markerStartRegion(const char* regionTag)
return -EFAULT;
}

bstring tag = bfromcstralloc(100, regionTag);
LikwidThreadResults* results;
char groupSuffix[10];
sprintf(groupSuffix, "-%d", groupSet->activeGroup);
bcatcstr(tag, groupSuffix);

bstring tag = bformat("%.*s-%d", 100, regionTag, groupSet->activeGroup);
int cpu_id = hashTable_get(tag, &results);
if (!results)
{
fprintf(stderr, "ERROR: Failed to get thread data for tag %s\n", regionTag);
return -EFAULT;
}
int thread_id = getThreadID(cpu_id);
if (results->state == MARKER_STATE_START)
{
Expand Down Expand Up @@ -591,6 +595,7 @@ likwid_markerStopRegion(const char* regionTag)
}

TimerData timestamp;
LikwidThreadResults* results = NULL;
timer_stop(&timestamp);
double result = 0.0;
int cpu_id;
Expand All @@ -600,17 +605,22 @@ likwid_markerStopRegion(const char* regionTag)
return -EFAULT;
}
int thread_id;
bstring tag = bfromcstr(regionTag);
char groupSuffix[100];
LikwidThreadResults* results;
sprintf(groupSuffix, "-%d", groupSet->activeGroup);
bcatcstr(tag, groupSuffix);
bstring tag = bformat("%.*s-%d", 100, regionTag, groupSet->activeGroup);
if (use_locks == 1)
{
pthread_mutex_lock(&threadLocks[myCPU]);
}

cpu_id = hashTable_get(tag, &results);
if (!results)
{
fprintf(stderr, "ERROR: Failed to get thread data for tag %s\n", regionTag);
if (use_locks == 1)
{
pthread_mutex_unlock(&threadLocks[myCPU]);
}
return -EFAULT;
}
thread_id = getThreadID(cpu_id);
if (results->state != MARKER_STATE_START)
{
Expand Down Expand Up @@ -682,13 +692,15 @@ likwid_markerGetRegion(
int cpu_id;
int myCPU = likwid_getProcessorId();
int thread_id;
bstring tag = bfromcstr(regionTag);
char groupSuffix[100];
LikwidThreadResults* results;
sprintf(groupSuffix, "-%d", groupSet->activeGroup);
bcatcstr(tag, groupSuffix);
LikwidThreadResults* results = NULL;
bstring tag = bformat("%.*s-%d", 100, regionTag, groupSet->activeGroup);

cpu_id = hashTable_get(tag, &results);
if (!results)
{
fprintf(stderr, "ERROR: Failed to get thread data for tag %s\n", regionTag);
return;
}
thread_id = getThreadID(myCPU);
if (count != NULL)
{
Expand All @@ -715,6 +727,7 @@ likwid_markerGetRegion(
int
likwid_markerResetRegion(const char* regionTag)
{
LikwidThreadResults* results = NULL;
if (! likwid_init)
{
return -EFAULT;
Expand All @@ -725,13 +738,14 @@ likwid_markerResetRegion(const char* regionTag)
{
return -EFAULT;
}
bstring tag = bfromcstr(regionTag);
char groupSuffix[100];
LikwidThreadResults* results;
sprintf(groupSuffix, "-%d", groupSet->activeGroup);
bcatcstr(tag, groupSuffix);
bstring tag = bformat("%.*s-%d", 100, regionTag, groupSet->activeGroup);

cpu_id = hashTable_get(tag, &results);
if (!results)
{
fprintf(stderr, "ERROR: Failed to get thread data for tag %s\n", regionTag);
return -EFAULT;
}
if (results->state != MARKER_STATE_STOP)
{
fprintf(stderr, "ERROR: Can only reset stopped regions\n");
Expand Down
2 changes: 1 addition & 1 deletion src/perfmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -3903,7 +3903,7 @@ perfmon_readMarkerFile(const char* filename)
if (strchr(buf,':'))
{
int regionid = 0, groupid = -1;
char regiontag[100];
char regiontag[140];
char* ptr = NULL;
char* colonptr = NULL;
// zero out ALL of regiontag due to replacing %s with %Nc
Expand Down
Loading