Commit | Line | Data |
---|---|---|
e6af533d | 1 | /* |
c0c0989a | 2 | * SPDX-License-Identifier: GPL-2.0-or-later |
e6af533d | 3 | * |
c0c0989a | 4 | * Copyright 2010 Douglas Santos <douglas.santos@polymtl.ca> |
046975d0 | 5 | * |
c0c0989a | 6 | * LTTng Userspace Tracer (UST) - benchmark tool |
e6af533d DS |
7 | */ |
8 | ||
e6af533d DS |
9 | #include <stdio.h> |
10 | #include <pthread.h> | |
11 | #include <stdlib.h> | |
12 | #include <unistd.h> | |
13 | #include <sched.h> | |
e6eed717 | 14 | #include <time.h> |
e6af533d | 15 | |
a44af49d ZT |
16 | #ifdef TRACING |
17 | #define TRACEPOINT_DEFINE | |
18 | #include "ust_tests_benchmark.h" | |
19 | #endif | |
20 | ||
e6af533d DS |
21 | static int nr_cpus; |
22 | static unsigned long nr_events; | |
e6af533d DS |
23 | |
24 | void do_stuff(void) | |
25 | { | |
26 | int v; | |
27 | FILE *file; | |
e6af533d DS |
28 | |
29 | v = 1; | |
30 | ||
e6eed717 | 31 | file = fopen("/dev/null", "a"); |
e6af533d DS |
32 | fprintf(file, "%d", v); |
33 | fclose(file); | |
e6eed717 | 34 | time(NULL); |
e6af533d | 35 | |
a44af49d ZT |
36 | #ifdef TRACING |
37 | tracepoint(ust_tests_benchmark, tpbench, v); | |
e6af533d DS |
38 | #endif |
39 | ||
40 | } | |
41 | ||
42 | ||
43 | void *function(void *arg) | |
44 | { | |
45 | unsigned long i; | |
46 | ||
47 | for(i = 0; i < nr_events; i++) { | |
48 | do_stuff(); | |
49 | } | |
50 | return NULL; | |
51 | } | |
52 | ||
e6af533d DS |
53 | void usage(char **argv) { |
54 | printf("Usage: %s nr_cpus nr_events\n", argv[0]); | |
55 | } | |
56 | ||
57 | ||
58 | int main(int argc, char **argv) | |
59 | { | |
60 | void *retval; | |
61 | int i; | |
62 | ||
63 | if (argc < 3) { | |
64 | usage(argv); | |
65 | exit(1); | |
66 | } | |
67 | ||
68 | nr_cpus = atoi(argv[1]); | |
69 | printf("using %d processor(s)\n", nr_cpus); | |
70 | ||
71 | nr_events = atol(argv[2]); | |
72 | printf("using %ld events per cpu\n", nr_events); | |
73 | ||
74 | pthread_t thread[nr_cpus]; | |
75 | for (i = 0; i < nr_cpus; i++) { | |
76 | if (pthread_create(&thread[i], NULL, function, NULL)) { | |
77 | fprintf(stderr, "thread create %d failed\n", i); | |
78 | exit(1); | |
79 | } | |
80 | } | |
81 | ||
82 | for (i = 0; i < nr_cpus; i++) { | |
83 | if (pthread_join(thread[i], &retval)) { | |
84 | fprintf(stderr, "thread join %d failed\n", i); | |
85 | exit(1); | |
86 | } | |
87 | } | |
88 | return 0; | |
89 | } |