summaryrefslogtreecommitdiffstats
path: root/measure_startup_oh.c
diff options
context:
space:
mode:
Diffstat (limited to 'measure_startup_oh.c')
-rw-r--r--measure_startup_oh.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/measure_startup_oh.c b/measure_startup_oh.c
new file mode 100644
index 0000000..56f9ea7
--- /dev/null
+++ b/measure_startup_oh.c
@@ -0,0 +1,44 @@
1/* Copyright 2025 Joshua Bakita
2 * Simple kernel that uses measure_launch_oh to measure how long CUDA
3 * initialization takes.
4 * Prints status to stderr and nothing to stdout.
5 */
6#include <time.h> // clock_gettime()
7#include <stdio.h> // fprintf(), perror()
8#include <stdlib.h> // putenv()
9#include <string.h> // strcmp()
10#include <unistd.h> // execve()
11extern char **environ;
12
13#include "testbench.h"
14
15#define measure_launch_oh "./measure_launch_oh"
16
17int main(int argc, char **argv) {
18 int *__unused, i;
19 struct timespec start;
20
21 if (argc == 2 && (!strcmp(argv[1], "--help") || !strcmp(argv[1], "-h"))) {
22 fprintf(stderr, "Usage: %s [environment var to apply to child (optional)]\n", argv[0]);
23 return 1;
24 }
25
26 static char* child_argv[3];
27 child_argv[0] = measure_launch_oh;
28 child_argv[1] = "1";
29 child_argv[2] = NULL;
30
31 // Use this to apply LD_PRELOAD to the child only
32 if (argv[1])
33 putenv(argv[1]);
34
35 clock_gettime(CLOCK_MONOTONIC_RAW, &start);
36 fprintf(stderr, "(%d) Starting '"measure_launch_oh"' at CLOCK_MONOTONIC_RAW = %ld ns\n",
37 getpid(), time2ns(start));
38 if (execve(measure_launch_oh, child_argv, environ)) {
39 perror("Unable to start '"measure_launch_oh"'");
40 return 1;
41 }
42
43 return 0;
44}