Skip to content

Commit

Permalink
Merge pull request #70 from mochi-hpc-experiments/snyder/thread-id-cost
Browse files Browse the repository at this point in the history
add node microbenchmark tests for `gettid()` & `pthread_self()`
  • Loading branch information
carns authored Mar 18, 2024
2 parents 91e467b + 8890626 commit 2572d9d
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions perf-regression/node-microbench.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <assert.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/types.h>
#include <time.h>
#include <pthread.h>
#include <stdatomic.h>
Expand All @@ -23,6 +24,7 @@
#ifdef HAVE_ABT_H
#include <abt.h>
#endif
#include <pthread.h>

#include <mpi.h>

Expand Down Expand Up @@ -63,6 +65,8 @@ static void test_abt_eventual_dynamic_allocation(long unsigned iters);
static void test_abt_eventual_static_allocation(long unsigned iters);
#endif
#endif
static void test_pthread_self(long unsigned iters);
static void test_gettid(long unsigned iters);

static struct options g_opts;
static struct test_case g_test_cases[] = {
Expand All @@ -88,6 +92,8 @@ static struct test_case g_test_cases[] = {
{"ABT_eventual static per fn", test_abt_eventual_static_allocation},
#endif
#endif
{"pthread_self", test_pthread_self},
{"gettid", test_gettid},
{NULL, NULL}};

int main(int argc, char** argv)
Expand Down Expand Up @@ -426,3 +432,23 @@ static void test_abt_eventual_static_allocation(long unsigned iters)
#endif /* ABT_EVENTUAL_INITIALIZER */

#endif /* HAVE_ABT_H */

/* how expensive is pthread_self()? */
static void test_pthread_self(long unsigned iters)
{
long unsigned i;

for (i = 0; i < iters; i++) { pthread_self(); }

return;
}

/* how expensive is gettid()? */
static void test_gettid(long unsigned iters)
{
long unsigned i;

for (i = 0; i < iters; i++) { gettid(); }

return;
}

0 comments on commit 2572d9d

Please sign in to comment.