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> |
035d7688 | 15 | #include <urcu/compiler.h> |
e6af533d | 16 | |
a44af49d ZT |
17 | #ifdef TRACING |
18 | #define TRACEPOINT_DEFINE | |
19 | #include "ust_tests_benchmark.h" | |
20 | #endif | |
21 | ||
e6af533d DS |
22 | static int nr_cpus; |
23 | static unsigned long nr_events; | |
e6af533d DS |
24 | |
25 | void do_stuff(void) | |
26 | { | |
035d7688 MD |
27 | int i; |
28 | #ifdef TRACING | |
29 | int v = 50; | |
30 | #endif | |
e6af533d | 31 | |
035d7688 MD |
32 | for (i = 0; i < 100; i++) |
33 | cmm_barrier(); | |
a44af49d ZT |
34 | #ifdef TRACING |
35 | tracepoint(ust_tests_benchmark, tpbench, v); | |
e6af533d | 36 | #endif |
e6af533d DS |
37 | } |
38 | ||
e6af533d DS |
39 | void *function(void *arg) |
40 | { | |
41 | unsigned long i; | |
42 | ||
035d7688 | 43 | for (i = 0; i < nr_events; i++) { |
e6af533d DS |
44 | do_stuff(); |
45 | } | |
46 | return NULL; | |
47 | } | |
48 | ||
e6af533d DS |
49 | void usage(char **argv) { |
50 | printf("Usage: %s nr_cpus nr_events\n", argv[0]); | |
51 | } | |
52 | ||
53 | ||
54 | int main(int argc, char **argv) | |
55 | { | |
56 | void *retval; | |
57 | int i; | |
58 | ||
59 | if (argc < 3) { | |
60 | usage(argv); | |
61 | exit(1); | |
62 | } | |
63 | ||
64 | nr_cpus = atoi(argv[1]); | |
65 | printf("using %d processor(s)\n", nr_cpus); | |
66 | ||
67 | nr_events = atol(argv[2]); | |
68 | printf("using %ld events per cpu\n", nr_events); | |
69 | ||
70 | pthread_t thread[nr_cpus]; | |
71 | for (i = 0; i < nr_cpus; i++) { | |
72 | if (pthread_create(&thread[i], NULL, function, NULL)) { | |
73 | fprintf(stderr, "thread create %d failed\n", i); | |
74 | exit(1); | |
75 | } | |
76 | } | |
77 | ||
78 | for (i = 0; i < nr_cpus; i++) { | |
79 | if (pthread_join(thread[i], &retval)) { | |
80 | fprintf(stderr, "thread join %d failed\n", i); | |
81 | exit(1); | |
82 | } | |
83 | } | |
84 | return 0; | |
85 | } |