Debian Codegraph @

src/signaltest/signaltest.c

raw symbols SCIP
1 // SPDX-License-Identifier: GPL-2.0-onlycxx . . $ `<file>/src/signaltest/signaltest.c`/
2
3 /*
4 * RT signal roundtrip test software
5 *
6 * (C) 2007 Thomas Gleixner <[email protected]>
7 *
8 */
9
10 #include <fcntl.h>
11 #include <getopt.h>
12 #include <pthread.h>
13 #include <signal.h>
14 #include <stdlib.h>
15 #include <stdio.h>
16 #include <string.h>
17 #include <time.h>
18 #include <unistd.h>
19 #include <errno.h>
20 #include <sched.h>
21 #include <inttypes.h>
22
23 #include <linux/unistd.h>
24
25 #include <sys/prctl.h>
26 #include <sys/stat.h>
27 #include <sys/types.h>
28 #include <sys/time.h>
29 #include <sys/mman.h>
30
31 #include "rt-error.h"cxx . . $ `<file>/src/include/rt-error.h`/
32 #include "rt-utils.h"cxx . . $ `<file>/src/include/rt-utils.h`/
33 #include "rt-numa.h"cxx . . $ `<file>/src/include/rt-numa.h`/
34
35 /* Must be power of 2 ! */
36 #define VALBUF_SIZEcxx . . $ `src/signaltest/signaltest.c:36:9`! 16384
37
38 /* Struct to transfer parameters to the thread */
39 struct thread_paramcxx . . $ thread_param# {
40 int idcxx . . $ thread_param#id.;
41 int priocxx . . $ thread_param#prio.;
42 int signalcxx . . $ thread_param#signal.;
43 unsigned long max_cyclescxx . . $ thread_param#max_cycles.;
44 struct thread_statcxx . . $ thread_stat# *statscxx . . $ thread_param#stats.;
45 int bufmskcxx . . $ thread_param#bufmsk.;
46 int cpucxx . . $ thread_param#cpu.;
47 };
48
49 /* Struct for statistics */
50 struct thread_statcxx . . $ thread_stat# {
51 unsigned long cyclescxx . . $ thread_stat#cycles.;
52 unsigned long cyclesreadcxx . . $ thread_stat#cyclesread.;
53 long mincxx . . $ thread_stat#min.;
54 long maxcxx . . $ thread_stat#max.;
55 long actcxx . . $ thread_stat#act.;
56 double avgcxx . . $ thread_stat#avg.;
57 long *valuescxx . . $ thread_stat#values.;
58 pthread_tcxx . . $ pthread_t# threadcxx . . $ thread_stat#thread.;
59 pthread_tcxx . . $ pthread_t# tothreadcxx . . $ thread_stat#tothread.;
60 int threadstartedcxx . . $ thread_stat#threadstarted.;
61 int tidcxx . . $ thread_stat#tid.;
62 int interruptedcxx . . $ thread_stat#interrupted.;
63 };
64
65 static int shutdowncxx . . $ shutdown.;
66 static int tracelimitcxx . . $ tracelimit.;
67
68
69 /*
70 * signal thread
71 *
72 */
73 void *signalthreadcxx . . $ signalthread(9f162e79bfc6c74).(void *param)
74 {
75 struct thread_paramcxx . . $ thread_param# *par = param;
76 struct sched_paramcxx . . $ sched_param# schedp;
77 sigset_tcxx . . $ sigset_t# sigset;
78 struct timespeccxx . . $ timespec# before, after;
79 struct thread_statcxx . . $ thread_stat# *stat = par->statscxx . . $ thread_param#stats.;
80 int policy = par->priocxx . . $ thread_param#prio. ? SCHED_FIFOcxx . . $ `<external>/4872883757279652994/sched.h:29:9`! : SCHED_OTHERcxx . . $ `<external>/4872883757279652994/sched.h:28:9`!;
81 int stopped = 0;
82 int first = 1;
83 pthread_tcxx . . $ pthread_t# thread;
84 cpu_set_tcxx . . $ cpu_set_t# mask;
85
86 stat->tidcxx . . $ thread_stat#tid. = gettidcxx . . $ gettid(b126dc7c1de90089).();
87
88 if (par->cpucxx . . $ thread_param#cpu. != -1) {
89 CPU_ZEROcxx . . $ `<external>/17522079545615609418/sched.h:96:10`!(&mask);
90 CPU_SETcxx . . $ `<external>/17522079545615609418/sched.h:92:10`!(par->cpu, &mask);
91 thread = pthread_selfcxx . . $ pthread_self(f708dce9a8856c70).();
92 if (pthread_setaffinity_npcxx . . $ pthread_setaffinity_np(f5c5d8965c9d8dbc).(thread, sizeof(mask), &mask) != 0)
93 warncxx . . $ warn(d5d9ff45db7b5d36).("Could not set CPU affinity to CPU #%d\n",
94 par->cpucxx . . $ thread_param#cpu.);
95 }
96
97 sigemptysetcxx . . $ sigemptyset(f9c066a8ff75ee9d).(&sigset);
98 sigaddsetcxx . . $ sigaddset(4917c6e3ecb7dbd5).(&sigset, par->signalcxx . . $ thread_param#signal.);
99 sigprocmaskcxx . . $ sigprocmask(7504382baa173b1).(SIG_BLOCKcxx . . $ `<external>/16635209305659446502/sigaction.h:79:9`!, &sigset, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
100
101 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&schedp, 0, sizeof(schedp));
102 schedp.sched_prioritycxx . . $ `<external>/17522079545615609418/sched.h:47:9`! = par->priocxx . . $ thread_param#prio.;
103 sched_setschedulercxx . . $ sched_setscheduler(b99e0841b006542f).(0, policy, &schedp);
104
105 stat->threadstartedcxx . . $ thread_stat#threadstarted.++;
106
107 clock_gettimecxx . . $ clock_gettime(65aaefb2502b4987).(CLOCK_MONOTONICcxx . . $ `<external>/89459239771508533/time.h:48:10`!, &before);
108
109 while (!shutdowncxx . . $ shutdown.) {
110 struct timespeccxx . . $ timespec# now;
111 long diff;
112 int sigs;
113
114 if (sigwaitcxx . . $ sigwait(84466af2bbf90658).(&sigset, &sigs) < 0)
115 goto out;
116
117 clock_gettimecxx . . $ clock_gettime(65aaefb2502b4987).(CLOCK_MONOTONICcxx . . $ `<external>/89459239771508533/time.h:48:10`!, &after);
118
119 /*
120 * If it is the first thread, sleep after every 16
121 * round trips.
122 */
123 if (!par->idcxx . . $ thread_param#id. && !(stat->cyclescxx . . $ thread_stat#cycles. & 0x0F))
124 usleepcxx . . $ usleep(4c679297bf94b9eb).(10000);
125
126 /* Get current time */
127 clock_gettimecxx . . $ clock_gettime(65aaefb2502b4987).(CLOCK_MONOTONICcxx . . $ `<external>/89459239771508533/time.h:48:10`!, &now);
128 pthread_killcxx . . $ pthread_kill(4292610292d2867f).(stat->tothreadcxx . . $ thread_stat#tothread., SIGUSR1cxx . . $ `<external>/1457673850468744829/signum-arch.h:49:9`!);
129
130 /* Skip the first cycle */
131 if (first) {
132 first = 0;
133 before = now;
134 continue;
135 }
136
137 diff = calcdiffcxx . . $ calcdiff(a7174a6ca78cf3cd).(after, before);
138 before = now;
139
140 if (diff < stat->mincxx . . $ thread_stat#min.)
141 stat->mincxx . . $ thread_stat#min. = diff;
142 if (diff > stat->maxcxx . . $ thread_stat#max.)
143 stat->maxcxx . . $ thread_stat#max. = diff;
144 stat->avgcxx . . $ thread_stat#avg. += (double) diff;
145
146 if (!stopped && tracelimitcxx . . $ tracelimit. && !par->idcxx . . $ thread_param#id. && (diff > tracelimitcxx . . $ tracelimit.)) {
147 stat->actcxx . . $ thread_stat#act. = diff;
148 stat->interruptedcxx . . $ thread_stat#interrupted. = 1;
149 stopped++;
150 shutdowncxx . . $ shutdown.++;
151 }
152 stat->actcxx . . $ thread_stat#act. = diff;
153 stat->cyclescxx . . $ thread_stat#cycles.++;
154
155 if (par->bufmskcxx . . $ thread_param#bufmsk.)
156 stat->valuescxx . . $ thread_stat#values.[stat->cyclescxx . . $ thread_stat#cycles. & par->bufmskcxx . . $ thread_param#bufmsk.] = diff;
157
158 if (par->max_cyclescxx . . $ thread_param#max_cycles. && par->max_cyclescxx . . $ thread_param#max_cycles. == stat->cyclescxx . . $ thread_stat#cycles.)
159 break;
160 }
161
162 out:
163 /* switch to normal */
164 schedp.sched_prioritycxx . . $ `<external>/17522079545615609418/sched.h:47:9`! = 0;
165 sched_setschedulercxx . . $ sched_setscheduler(b99e0841b006542f).(0, SCHED_OTHERcxx . . $ `<external>/4872883757279652994/sched.h:28:9`!, &schedp);
166
167 stat->threadstartedcxx . . $ thread_stat#threadstarted. = -1;
168
169 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
170 }
171
172
173 /* Print usage information */
174 static void display_helpcxx . . $ display_help(d4f767463ce0a6b3).(int error)
175 {
176 printfcxx . . $ printf(581fddd72a8db8fc).("signaltest V %1.2f\n", VERSIONcxx . . $ `<built-in>:412:9`!);
177 printfcxx . . $ printf(581fddd72a8db8fc).("Usage:\n"
178 "signaltest <options>\n\n"
179 "-a [NUM] --affinity run thread #N on processor #N, if possible\n"
180 " with NUM pin all threads to the processor NUM\n"
181 "-b USEC --breaktrace=USEC send break trace command when latency > USEC\n"
182 "-D --duration=TIME specify a length for the test run.\n"
183 " Append 'm', 'h', or 'd' to specify minutes, hours or\n"
184 " days.\n"
185 "-h --help display usage information\n"
186 " --json=FILENAME write final results into FILENAME, JSON formatted\n"
187 "-l LOOPS --loops=LOOPS number of loops: default=0(endless)\n"
188 "-m --mlockall lock current and future memory allocations\n"
189 "-p PRIO --prio=PRIO priority of highest prio thread\n"
190 "-q --quiet print a summary only on exit\n"
191 "-t NUM --threads=NUM number of threads: default=2\n"
192 "-v --verbose output values on stdout for statistics\n"
193 " format: n:c:v n=tasknum c=count v=value in us\n"
194 );
195 exitcxx . . $ exit(3ca292c338df9bb3).(error);
196 }
197
198 static int prioritycxx . . $ priority.;
199 static int num_threadscxx . . $ num_threads. = 2;
200 static int max_cyclescxx . . $ max_cycles.;
201 static int durationcxx . . $ duration.;
202 static int verbosecxx . . $ verbose.;
203 static int quietcxx . . $ quiet.;
204 static int lockallcxx . . $ lockall.;
205 static struct bitmaskcxx . . $ bitmask# *affinity_maskcxx . . $ affinity_mask. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
206 static int smpcxx . . $ smp. = 0;
207 static int numacxx . . $ numa. = 0;
208 static int setaffinitycxx . . $ setaffinity. = AFFINITY_UNSPECIFIEDcxx . . $ AFFINITY_UNSPECIFIED.;
209 static char jsonfilecxx . . $ jsonfile.[MAX_PATHcxx . . $ `src/include/rt-utils.h:9:9`!];
210
211 enum option_valuescxx . . $ option_values# {
212 OPT_AFFINITYcxx . . $ OPT_AFFINITY.=1, OPT_BREAKTRACEcxx . . $ OPT_BREAKTRACE.,
213 OPT_DURATIONcxx . . $ OPT_DURATION., OPT_HELPcxx . . $ OPT_HELP., OPT_JSONcxx . . $ OPT_JSON.,
214 OPT_LOOPScxx . . $ OPT_LOOPS., OPT_MLOCKALLcxx . . $ OPT_MLOCKALL., OPT_PRIORITYcxx . . $ OPT_PRIORITY.,
215 OPT_QUIETcxx . . $ OPT_QUIET., OPT_SMPcxx . . $ OPT_SMP., OPT_THREADScxx . . $ OPT_THREADS., OPT_VERBOSEcxx . . $ OPT_VERBOSE.
216 };
217
218 /* Process commandline options */
219 static void process_optionscxx . . $ process_options(ddc4c40db40b0503).(int argc, char *argv[], unsigned int max_cpus)
220 {
221 int option_affinity = 0;
222 int error = 0;
223
224 for (;;) {
225 int option_index = 0;
226 /** Options for getopt */
227 static struct optioncxx . . $ option# long_options[] = {
228 {"affinity", optional_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:64:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, OPT_AFFINITYcxx . . $ OPT_AFFINITY.},
229 {"breaktrace", required_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:63:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, OPT_BREAKTRACEcxx . . $ OPT_BREAKTRACE.},
230 {"duration", required_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:63:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, OPT_DURATIONcxx . . $ OPT_DURATION.},
231 {"help", no_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:62:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, OPT_HELPcxx . . $ OPT_HELP.},
232 {"json", required_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:63:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, OPT_JSONcxx . . $ OPT_JSON.},
233 {"loops", required_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:63:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, OPT_LOOPScxx . . $ OPT_LOOPS.},
234 {"mlockall", no_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:62:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, OPT_MLOCKALLcxx . . $ OPT_MLOCKALL.},
235 {"priority", required_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:63:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, OPT_PRIORITYcxx . . $ OPT_PRIORITY.},
236 {"quiet", no_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:62:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, OPT_QUIETcxx . . $ OPT_QUIET.},
237 {"smp", no_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:62:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, OPT_SMPcxx . . $ OPT_SMP.},
238 {"threads", required_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:63:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, OPT_THREADScxx . . $ OPT_THREADS.},
239 {"verbose", no_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:62:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, OPT_VERBOSEcxx . . $ OPT_VERBOSE.},
240 {NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0}
241 };
242 int c = getopt_longcxx . . $ getopt_long(41f665c090816971).(argc, argv, "a::b:D:hl:mp:qSt:v",
243 long_options, &option_index);
244 if (c == -1)
245 break;
246 switch (c) {
247 case OPT_AFFINITYcxx . . $ OPT_AFFINITY.:
248 case 'a':
249 option_affinity = 1;
250 /* smp sets AFFINITY_USEALL in OPT_SMP */
251 if (smpcxx . . $ smp.)
252 break;
253 numacxx . . $ numa. = numa_initializecxx . . $ numa_initialize(b126dc7c1de90089).();
254 if (optargcxx . . $ optarg.) {
255 parse_cpumaskcxx . . $ parse_cpumask(3a199e04db700bfb).(optargcxx . . $ optarg., max_cpus, &affinity_maskcxx . . $ affinity_mask.);
256 setaffinitycxx . . $ setaffinity. = AFFINITY_SPECIFIEDcxx . . $ AFFINITY_SPECIFIED.;
257 } else if (optindcxx . . $ optind. < argc &&
258 (atoicxx . . $ atoi(5c4306d8553b3696).(argv[optindcxx . . $ optind.]) ||
259 argv[optindcxx . . $ optind.][0] == '0' ||
260 argv[optindcxx . . $ optind.][0] == '!' ||
261 argv[optindcxx . . $ optind.][0] == '+' ||
262 argv[optindcxx . . $ optind.][0] == 'a')) {
263 parse_cpumaskcxx . . $ parse_cpumask(3a199e04db700bfb).(argv[optindcxx . . $ optind.], max_cpus, &affinity_maskcxx . . $ affinity_mask.);
264 setaffinitycxx . . $ setaffinity. = AFFINITY_SPECIFIEDcxx . . $ AFFINITY_SPECIFIED.;
265 } else {
266 setaffinitycxx . . $ setaffinity. = AFFINITY_USEALLcxx . . $ AFFINITY_USEALL.;
267 }
268
269 if (setaffinitycxx . . $ setaffinity. == AFFINITY_SPECIFIEDcxx . . $ AFFINITY_SPECIFIED. && !affinity_maskcxx . . $ affinity_mask.)
270 display_helpcxx . . $ display_help(d4f767463ce0a6b3).(1);
271 if (verbosecxx . . $ verbose.)
272 printfcxx . . $ printf(581fddd72a8db8fc).("Using %u cpus.\n",
273 numa_bitmask_weightcxx . . $ numa_bitmask_weight(4b55de75830e9378).(affinity_maskcxx . . $ affinity_mask.));
274 break;
275 case OPT_BREAKTRACEcxx . . $ OPT_BREAKTRACE.:
276 case 'b':
277 tracelimitcxx . . $ tracelimit. = atoicxx . . $ atoi(5c4306d8553b3696).(optargcxx . . $ optarg.);
278 break;
279 case OPT_DURATIONcxx . . $ OPT_DURATION.:
280 case 'D':
281 durationcxx . . $ duration. = parse_time_stringcxx . . $ parse_time_string(1ef8e6ec083aabb9).(optargcxx . . $ optarg.);
282 break;
283 case OPT_HELPcxx . . $ OPT_HELP.:
284 case '?':
285 case 'h':
286 display_helpcxx . . $ display_help(d4f767463ce0a6b3).(0);
287 break;
288 case OPT_JSONcxx . . $ OPT_JSON.:
289 strncpycxx . . $ strncpy(255158a415b673b0).(jsonfilecxx . . $ jsonfile., optargcxx . . $ optarg., strnlencxx . . $ strnlen(ac5a385650b4bde5).(optargcxx . . $ optarg., MAX_PATHcxx . . $ `src/include/rt-utils.h:9:9`!-1));
290 break;
291 case OPT_LOOPScxx . . $ OPT_LOOPS.:
292 case 'l':
293 max_cyclescxx . . $ max_cycles. = atoicxx . . $ atoi(5c4306d8553b3696).(optargcxx . . $ optarg.);
294 break;
295 case OPT_MLOCKALLcxx . . $ OPT_MLOCKALL.:
296 case 'm':
297 lockallcxx . . $ lockall. = 1;
298 break;
299 case OPT_PRIORITYcxx . . $ OPT_PRIORITY.:
300 case 'p':
301 prioritycxx . . $ priority. = atoicxx . . $ atoi(5c4306d8553b3696).(optargcxx . . $ optarg.);
302 break;
303 case OPT_QUIETcxx . . $ OPT_QUIET.:
304 case 'q':
305 quietcxx . . $ quiet. = 1;
306 break;
307 case OPT_SMPcxx . . $ OPT_SMP.:
308 case 'S':
309 if (numacxx . . $ numa.)
310 fatalcxx . . $ fatal(5313ecf19fd40d4d).("numa and smp options are mutually exclusive\n");
311 smpcxx . . $ smp. = 1;
312 num_threadscxx . . $ num_threads. = -1; /* update after parsing */
313 setaffinitycxx . . $ setaffinity. = AFFINITY_USEALLcxx . . $ AFFINITY_USEALL.;
314 break;
315 case OPT_THREADScxx . . $ OPT_THREADS.:
316 case 't':
317 num_threadscxx . . $ num_threads. = atoicxx . . $ atoi(5c4306d8553b3696).(optargcxx . . $ optarg.);
318 break;
319 case OPT_VERBOSEcxx . . $ OPT_VERBOSE.:
320 case 'v': verbosecxx . . $ verbose. = 1;
321 break;
322 }
323 }
324
325 if (durationcxx . . $ duration. < 0)
326 error = 1;
327
328 if (prioritycxx . . $ priority. < 0 || prioritycxx . . $ priority. > 99)
329 error = 1;
330
331 if (num_threadscxx . . $ num_threads. == -1)
332 num_threadscxx . . $ num_threads. = get_available_cpuscxx . . $ get_available_cpus(e325be287bc55a3e).(affinity_maskcxx . . $ affinity_mask.);
333
334 if (num_threadscxx . . $ num_threads. < 2)
335 error = 1;
336
337 /* if smp wasn't requested, test for numa automatically */
338 if (!smpcxx . . $ smp.) {
339 numacxx . . $ numa. = numa_initializecxx . . $ numa_initialize(b126dc7c1de90089).();
340 if (setaffinitycxx . . $ setaffinity. == AFFINITY_UNSPECIFIEDcxx . . $ AFFINITY_UNSPECIFIED.)
341 setaffinitycxx . . $ setaffinity. = AFFINITY_USEALLcxx . . $ AFFINITY_USEALL.;
342 }
343
344 if (option_affinity) {
345 if (smpcxx . . $ smp.)
346 warncxx . . $ warn(d5d9ff45db7b5d36).("-a ignored due to smp mode\n");
347 }
348
349 if (error) {
350 if (affinity_maskcxx . . $ affinity_mask.)
351 numa_bitmask_freecxx . . $ numa_bitmask_free(d7c6455decaee94d).(affinity_maskcxx . . $ affinity_mask.);
352 display_helpcxx . . $ display_help(d4f767463ce0a6b3).(error);
353 }
354 }
355
356 static void sighandcxx . . $ sighand(d4f767463ce0a6b3).(int sig)
357 {
358 shutdowncxx . . $ shutdown. = 1;
359 }
360
361 static void print_statcxx . . $ print_stat(8b8d1384512980fd).(struct thread_paramcxx . . $ thread_param# *par, int index, int verbose)
362 {
363 struct thread_statcxx . . $ thread_stat# *stat = par->statscxx . . $ thread_param#stats.;
364
365 if (!verbose) {
366 if (quietcxx . . $ quiet. != 1) {
367 printfcxx . . $ printf(581fddd72a8db8fc).("T:%2d (%5d) P:%2d C:%7lu "
368 "Min:%7ld Act:%5ld Avg:%5ld Max:%8ld\n",
369 index, stat->tidcxx . . $ thread_stat#tid., par->priocxx . . $ thread_param#prio.,
370 stat->cyclescxx . . $ thread_stat#cycles., stat->mincxx . . $ thread_stat#min., stat->actcxx . . $ thread_stat#act.,
371 stat->cyclescxx . . $ thread_stat#cycles. ?
372 (long)(stat->avgcxx . . $ thread_stat#avg./stat->cyclescxx . . $ thread_stat#cycles.) : 0, stat->maxcxx . . $ thread_stat#max.);
373 }
374 } else {
375 while (stat->cyclescxx . . $ thread_stat#cycles. != stat->cyclesreadcxx . . $ thread_stat#cyclesread.) {
376 long diff = stat->valuescxx . . $ thread_stat#values.[stat->cyclesreadcxx . . $ thread_stat#cyclesread. & par->bufmskcxx . . $ thread_param#bufmsk.];
377 printfcxx . . $ printf(581fddd72a8db8fc).("%8d:%8lu:%8ld\n", index, stat->cyclesreadcxx . . $ thread_stat#cyclesread., diff);
378 stat->cyclesreadcxx . . $ thread_stat#cyclesread.++;
379 }
380 }
381 }
382
383 static void write_statscxx . . $ write_stats(2fd218767557b4b8).(FILEcxx . . $ FILE# *f, void *data)
384 {
385 struct thread_paramcxx . . $ thread_param# *par = data;
386 struct thread_statcxx . . $ thread_stat# *s;
387 int i;
388
389 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(f, " \"num_threads\": %d,\n", num_threadscxx . . $ num_threads.);
390 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(f, " \"thread\": {\n");
391 for (i = 0; i < num_threadscxx . . $ num_threads.; i++) {
392 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(f, " \"%u\": {\n", i);
393 s = &par->statscxx . . $ thread_param#stats.[i];
394 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(f, " \"cycles\": %ld,\n", s->cyclescxx . . $ thread_stat#cycles.);
395 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(f, " \"min\": %ld,\n", s->mincxx . . $ thread_stat#min.);
396 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(f, " \"max\": %ld,\n", s->maxcxx . . $ thread_stat#max.);
397 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(f, " \"avg\": %.2f,\n", s->avgcxx . . $ thread_stat#avg./s->cyclescxx . . $ thread_stat#cycles.);
398 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(f, " \"cpu\": %d\n", par->cpucxx . . $ thread_param#cpu.);
399 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(f, " }%s\n", i == num_threadscxx . . $ num_threads. - 1 ? "" : ",");
400
401 }
402 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(f, " }\n");
403 }
404
405 int maincxx . . $ main(afcd3168fc1188a4).(int argc, char **argv)
406 {
407 sigset_tcxx . . $ sigset_t# sigset;
408 int signum = SIGUSR1cxx . . $ `<external>/1457673850468744829/signum-arch.h:49:9`!;
409 struct thread_paramcxx . . $ thread_param# *par;
410 struct thread_statcxx . . $ thread_stat# *stat;
411 int i, ret = -1;
412 int status, cpu;
413 int max_cpus = sysconfcxx . . $ sysconf(dc1f09c09fbff20f).(_SC_NPROCESSORS_ONLNcxx . . $ `<external>/6393649343499073842/confname.h:253:9`!);
414
415 rt_initcxx . . $ rt_init(c759356ac01a31e7).(argc, argv);
416 process_optionscxx . . $ process_options(ddc4c40db40b0503).(argc, argv, max_cpus);
417
418 if (check_privscxx . . $ check_privs(b126dc7c1de90089).())
419 exitcxx . . $ exit(3ca292c338df9bb3).(1);
420
421 /* lock all memory (prevent paging) */
422 if (lockallcxx . . $ lockall.)
423 if (mlockallcxx . . $ mlockall(7864480464b09eea).(MCL_CURRENTcxx . . $ `<external>/17226767460805440860/mman-linux.h:131:10`!|MCL_FUTUREcxx . . $ `<external>/17226767460805440860/mman-linux.h:132:10`!) == -1) {
424 perrorcxx . . $ perror(85c52e162fed56f9).("mlockall");
425 goto out;
426 }
427
428 /* Restrict the main pid to the affinity specified by the user */
429 if (affinity_maskcxx . . $ affinity_mask. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
430 int res;
431
432 errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = 0;
433 res = numa_sched_setaffinitycxx . . $ numa_sched_setaffinity(cf9f0dd4c417177b).(getpidcxx . . $ getpid(b126dc7c1de90089).(), affinity_maskcxx . . $ affinity_mask.);
434 if (res != 0)
435 warncxx . . $ warn(d5d9ff45db7b5d36).("Couldn't setaffinity in main thread: %s\n", strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
436 }
437
438 sigemptysetcxx . . $ sigemptyset(f9c066a8ff75ee9d).(&sigset);
439 sigaddsetcxx . . $ sigaddset(4917c6e3ecb7dbd5).(&sigset, signum);
440 sigprocmaskcxx . . $ sigprocmask(7504382baa173b1).(SIG_BLOCKcxx . . $ `<external>/16635209305659446502/sigaction.h:79:9`!, &sigset, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
441
442 signalcxx . . $ signal(c2d516773f91faf8).(SIGINTcxx . . $ `<external>/11773118241360591791/signum-generic.h:48:9`!, sighandcxx . . $ sighand(d4f767463ce0a6b3).);
443 signalcxx . . $ signal(c2d516773f91faf8).(SIGTERMcxx . . $ `<external>/11773118241360591791/signum-generic.h:53:9`!, sighandcxx . . $ sighand(d4f767463ce0a6b3).);
444 signalcxx . . $ signal(c2d516773f91faf8).(SIGALRMcxx . . $ `<external>/11773118241360591791/signum-generic.h:61:9`!, sighandcxx . . $ sighand(d4f767463ce0a6b3).);
445
446 if (durationcxx . . $ duration.)
447 alarmcxx . . $ alarm(2141b656ce2cc063).(durationcxx . . $ duration.);
448
449 par = calloccxx . . $ calloc(63a7bf2941bfcd7a).(num_threadscxx . . $ num_threads., sizeof(struct thread_paramcxx . . $ thread_param#));
450 if (!par)
451 goto out;
452 stat = calloccxx . . $ calloc(63a7bf2941bfcd7a).(num_threadscxx . . $ num_threads., sizeof(struct thread_statcxx . . $ thread_stat#));
453 if (!stat)
454 goto outpar;
455
456 for (i = 0; i < num_threadscxx . . $ num_threads.; i++) {
457 if (verbosecxx . . $ verbose.) {
458 stat[i].valuescxx . . $ thread_stat#values. = calloccxx . . $ calloc(63a7bf2941bfcd7a).(VALBUF_SIZEcxx . . $ `src/signaltest/signaltest.c:36:9`!, sizeof(long));
459 if (!stat[i].valuescxx . . $ thread_stat#values.)
460 goto outall;
461 par[i].bufmskcxx . . $ thread_param#bufmsk. = VALBUF_SIZEcxx . . $ `src/signaltest/signaltest.c:36:9`! - 1;
462 }
463
464 switch (setaffinitycxx . . $ setaffinity.) {
465 case AFFINITY_UNSPECIFIEDcxx . . $ AFFINITY_UNSPECIFIED.:
466 cpu = -1;
467 break;
468 case AFFINITY_SPECIFIEDcxx . . $ AFFINITY_SPECIFIED.:
469 cpu = cpu_for_thread_spcxx . . $ cpu_for_thread_sp(5778b5fee399886d).(i, max_cpus, affinity_maskcxx . . $ affinity_mask.);
470 if (verbosecxx . . $ verbose.)
471 printfcxx . . $ printf(581fddd72a8db8fc).("Thread %d using cpu %d.\n", i, cpu);
472 break;
473 case AFFINITY_USEALLcxx . . $ AFFINITY_USEALL.:
474 cpu = cpu_for_thread_uacxx . . $ cpu_for_thread_ua(9b79fb6aee4c0440).(i, max_cpus);
475 break;
476 default:
477 cpu = -1;
478 }
479
480 par[i].idcxx . . $ thread_param#id. = i;
481 par[i].priocxx . . $ thread_param#prio. = prioritycxx . . $ priority.;
482 #if 0
483 if (priority)
484 priority--;
485 #endif
486 par[i].signalcxx . . $ thread_param#signal. = signum;
487 par[i].max_cyclescxx . . $ thread_param#max_cycles. = max_cyclescxx . . $ max_cycles.;
488 par[i].statscxx . . $ thread_param#stats. = &stat[i];
489 par[i].cpucxx . . $ thread_param#cpu. = cpu;
490 stat[i].mincxx . . $ thread_stat#min. = 1000000;
491 stat[i].maxcxx . . $ thread_stat#max. = -1000000;
492 stat[i].avgcxx . . $ thread_stat#avg. = 0.0;
493 stat[i].threadstartedcxx . . $ thread_stat#threadstarted. = 1;
494 status = pthread_createcxx . . $ pthread_create(2141a84bcac899e5).(&stat[i].threadcxx . . $ thread_stat#thread., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, signalthreadcxx . . $ signalthread(9f162e79bfc6c74).,
495 &par[i]);
496 if (status)
497 fatalcxx . . $ fatal(5313ecf19fd40d4d).("failed to create thread %d: %s\n", i,
498 strerrorcxx . . $ strerror(ff224f080444ee45).(status));
499 }
500
501 while (!shutdowncxx . . $ shutdown.) {
502 int allstarted = 1;
503
504 for (i = 0; i < num_threadscxx . . $ num_threads.; i++) {
505 if (stat[i].threadstartedcxx . . $ thread_stat#threadstarted. != 2)
506 allstarted = 0;
507 }
508 if (!allstarted)
509 continue;
510
511 for (i = 0; i < num_threadscxx . . $ num_threads. - 1; i++)
512 stat[i].tothreadcxx . . $ thread_stat#tothread. = stat[i+1].threadcxx . . $ thread_stat#thread.;
513 stat[i].tothreadcxx . . $ thread_stat#tothread. = stat[0].threadcxx . . $ thread_stat#thread.;
514 break;
515 }
516 pthread_killcxx . . $ pthread_kill(4292610292d2867f).(stat[0].threadcxx . . $ thread_stat#thread., signum);
517
518 while (!shutdowncxx . . $ shutdown.) {
519 char lavg[256];
520 int fd, len, allstopped = 0;
521
522 if (!verbosecxx . . $ verbose. && !quietcxx . . $ quiet.) {
523 fd = opencxx . . $ open(e156e3aa1e5c4ad1).("/proc/loadavg", O_RDONLYcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:43:9`!, 0666);
524 len = readcxx . . $ read(7e34d0a36f355389).(fd, &lavg, 255);
525 closecxx . . $ close(7864480464b09eea).(fd);
526 lavg[len-1] = 0x0;
527 printfcxx . . $ printf(581fddd72a8db8fc).("%s \n\n", lavg);
528 }
529
530 print_statcxx . . $ print_stat(8b8d1384512980fd).(&par[0], 0, verbosecxx . . $ verbose.);
531 if (max_cyclescxx . . $ max_cycles. && stat[0].cyclescxx . . $ thread_stat#cycles. >= max_cyclescxx . . $ max_cycles.)
532 allstopped++;
533
534 usleepcxx . . $ usleep(4c679297bf94b9eb).(10000);
535 if (shutdowncxx . . $ shutdown. || allstopped)
536 break;
537 if (!verbosecxx . . $ verbose. && !quietcxx . . $ quiet.)
538 printfcxx . . $ printf(581fddd72a8db8fc).("\033[%dA", 3);
539 }
540 ret = 0;
541 outall:
542 shutdowncxx . . $ shutdown. = 1;
543 usleepcxx . . $ usleep(4c679297bf94b9eb).(50000);
544 if (quietcxx . . $ quiet.)
545 quietcxx . . $ quiet. = 2;
546 for (i = 0; i < num_threadscxx . . $ num_threads.; i++) {
547 if (stat[i].threadstartedcxx . . $ thread_stat#threadstarted. > 0)
548 pthread_killcxx . . $ pthread_kill(4292610292d2867f).(stat[i].threadcxx . . $ thread_stat#thread., SIGUSR1cxx . . $ `<external>/1457673850468744829/signum-arch.h:49:9`!);
549 if (stat[i].interruptedcxx . . $ thread_stat#interrupted.)
550 printfcxx . . $ printf(581fddd72a8db8fc).("Thread %d exceeded trace limit.\n", i);
551 if (stat[i].threadstartedcxx . . $ thread_stat#threadstarted.) {
552 pthread_joincxx . . $ pthread_join(269902cf949f12c5).(stat[i].threadcxx . . $ thread_stat#thread., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
553 print_statcxx . . $ print_stat(8b8d1384512980fd).(&par[i], i, 0);
554 }
555 if (stat[i].valuescxx . . $ thread_stat#values.)
556 freecxx . . $ free(5d22bdacc48458e8).(stat[i].valuescxx . . $ thread_stat#values.);
557 }
558 if (strlencxx . . $ strlen(751346f8406fd082).(jsonfilecxx . . $ jsonfile.) != 0)
559 rt_write_jsoncxx . . $ rt_write_json(969c696bbc9a09ad).(jsonfilecxx . . $ jsonfile., ret, write_statscxx . . $ write_stats(2fd218767557b4b8)., par);
560
561 freecxx . . $ free(5d22bdacc48458e8).(stat);
562 outpar:
563 freecxx . . $ free(5d22bdacc48458e8).(par);
564 out:
565 if (lockallcxx . . $ lockall.)
566 munlockallcxx . . $ munlockall(b126dc7c1de90089).();
567
568 exitcxx . . $ exit(3ca292c338df9bb3).(ret);
569 }