summaryrefslogtreecommitdiffstats
path: root/measure_startup_oh.c
blob: 56f9ea78f22fde4f891d71f4cfc2172aee658b2d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* Copyright 2025 Joshua Bakita
 * Simple kernel that uses measure_launch_oh to measure how long CUDA
 * initialization takes.
 * Prints status to stderr and nothing to stdout.
 */
#include <time.h>   // clock_gettime()
#include <stdio.h>  // fprintf(), perror()
#include <stdlib.h> // putenv()
#include <string.h> // strcmp()
#include <unistd.h> // execve()
extern char **environ;

#include "testbench.h"

#define measure_launch_oh "./measure_launch_oh"

int main(int argc, char **argv) {
	int *__unused, i;
	struct timespec start;

	if (argc == 2 && (!strcmp(argv[1], "--help") || !strcmp(argv[1], "-h"))) {
		fprintf(stderr, "Usage: %s [environment var to apply to child (optional)]\n", argv[0]);
		return 1;
	}

	static char* child_argv[3];
	child_argv[0] = measure_launch_oh;
	child_argv[1] = "1";
	child_argv[2] = NULL;

	// Use this to apply LD_PRELOAD to the child only
	if (argv[1])
		putenv(argv[1]);

	clock_gettime(CLOCK_MONOTONIC_RAW, &start);
	fprintf(stderr, "(%d) Starting '"measure_launch_oh"' at CLOCK_MONOTONIC_RAW = %ld ns\n",
			getpid(), time2ns(start));
	if (execve(measure_launch_oh, child_argv, environ)) {
		perror("Unable to start '"measure_launch_oh"'");
		return 1;
	}

	return 0;
}