Debian Codegraph @

src/queuelat/queuelat.c

raw symbols SCIP
1 // SPDX-License-Identifier: GPL-2.0-or-latercxx . . $ `<file>/src/queuelat/queuelat.c`/
2
3 /*
4 * Copyright (C) 2018 Marcelo Tosatti <[email protected]>
5 * Copyright (C) 2019 John Kacur <[email protected]>
6 * Copyright (C) 2019 Clark Williams <[email protected]>
7 */
8
9 #include <string.h>
10 #include <stdlib.h>
11 #include <sys/types.h>
12 #include <sys/stat.h>
13 #include <fcntl.h>
14 #include <ctype.h>
15 #include <stdio.h>
16 #include <unistd.h>
17 #include <signal.h>
18 #include <time.h>
19 #include <getopt.h>
20
21 #include "rt-utils.h"cxx . . $ `<file>/src/include/rt-utils.h`/
22
23 /* Program parameters:
24 * max_queue_len: maximum latency allowed, in nanoseconds (int).
25 * cycles_per_packet: number of cycles to process one packet (int).
26 * mpps(million-packet-per-sec): million packets per second (float).
27 * tsc_freq_mhz: TSC frequency in MHz, as measured by TSC PIT calibration
28 * (search for "Detected XXX MHz processor" in dmesg, and use the integer part).
29 *
30 * How it works
31 * ============
32 *
33 * The program in essence does:
34 *
35 * b = rdtsc();
36 * memmove(dest, src, n);
37 * a = rdtsc();
38 *
39 * delay = convert_to_ns(a - b);
40 *
41 * queue_size += packets_queued_in(delay);
42 * queue_size -= packets_processed;
43 *
44 * if (queue_size > max_queue_len)
45 * FAIL();
46 *
47 * packets_processed is fixed, and is estimated as follows:
48 * n is determined first, so that the stats bucket with highest count
49 * takes max_latency/2.
50 * for max_latency/2, we calculate how many packets can be drained
51 * in that time (using cycles_per_packet).
52 *
53 */
54
55 int maxlatencycxx . . $ maxlatency.;
56 int cycles_per_packetcxx . . $ cycles_per_packet.;
57 float mppscxx . . $ mpps.;
58 int timeout_secscxx . . $ timeout_secs.;
59 int min_queue_size_to_printcxx . . $ min_queue_size_to_print.;
60
61 /* Derived constants */
62
63 float cycles_to_nscxx . . $ cycles_to_ns.;
64 int max_queue_lencxx . . $ max_queue_len.;
65
66 int default_ncxx . . $ default_n.;
67 int nr_packets_drain_per_blockcxx . . $ nr_packets_drain_per_block.;
68
69 /*
70 * Parameters for the stats collection buckets
71 */
72
73 #define LAST_VALcxx . . $ `src/queuelat/queuelat.c:73:9`! 70000
74 #define VALS_PER_BUCKETcxx . . $ `src/queuelat/queuelat.c:74:9`! 100
75 #define NR_BUCKETScxx . . $ `src/queuelat/queuelat.c:75:9`! LAST_VALcxx . . $ `src/queuelat/queuelat.c:73:9`!/VALS_PER_BUCKETcxx . . $ `src/queuelat/queuelat.c:74:9`!
76
77 unsigned long long bucketscxx . . $ buckets.[NR_BUCKETScxx . . $ `src/queuelat/queuelat.c:75:9`!+1];
78 unsigned long long total_countcxx . . $ total_count.;
79
80 #define OUTLIER_BUCKETcxx . . $ `src/queuelat/queuelat.c:80:9`! NR_BUCKETScxx . . $ `src/queuelat/queuelat.c:75:9`!
81
82 static int val_to_bucketcxx . . $ val_to_bucket(642c2e9948c4ad2).(unsigned long long val)
83 {
84 int bucket_nr = val / VALS_PER_BUCKETcxx . . $ `src/queuelat/queuelat.c:74:9`!;
85 if (bucket_nr >= NR_BUCKETScxx . . $ `src/queuelat/queuelat.c:75:9`!)
86 return OUTLIER_BUCKETcxx . . $ `src/queuelat/queuelat.c:80:9`!;
87 return bucket_nr;
88 }
89
90 static void accountcxx . . $ account(891dc3055356b409).(unsigned long long val)
91 {
92 int bucket_nr = val_to_bucketcxx . . $ val_to_bucket(642c2e9948c4ad2).(val);
93 bucketscxx . . $ buckets.[bucket_nr]++;
94 total_countcxx . . $ total_count.++;
95 }
96
97 static unsigned long long total_samplescxx . . $ total_samples(73266883b0c7072b).(void)
98 {
99 int i;
100 unsigned long long total = 0;
101
102 for (i = 0; i <= OUTLIER_BUCKETcxx . . $ `src/queuelat/queuelat.c:80:9`!; i++)
103 total += bucketscxx . . $ buckets.[i];
104
105 return total;
106 }
107
108 static void print_all_bucketscxx . . $ print_all_buckets(49f6e7a06ebc5aa8).(void)
109 {
110 int i, print_dotdotdot = 0;
111
112 for (i = 0; i <= OUTLIER_BUCKETcxx . . $ `src/queuelat/queuelat.c:80:9`!; i++) {
113 int bucket_nr;
114 unsigned long long val = i*VALS_PER_BUCKETcxx . . $ `src/queuelat/queuelat.c:74:9`!;
115
116 bucket_nr = val_to_bucketcxx . . $ val_to_bucket(642c2e9948c4ad2).(val);
117
118 if (bucket_nr != OUTLIER_BUCKETcxx . . $ `src/queuelat/queuelat.c:80:9`!) {
119 int n_bucketnr = bucket_nr+1;
120 if (bucketscxx . . $ buckets.[bucket_nr] == bucketscxx . . $ buckets.[n_bucketnr]) {
121 print_dotdotdot = 1;
122 continue;
123 }
124 if (print_dotdotdot) {
125 printfcxx . . $ printf(581fddd72a8db8fc).("...\n");
126 print_dotdotdot = 0;
127 }
128 printfcxx . . $ printf(581fddd72a8db8fc).("[%lld - %lld] = %lld\n", val,
129 val + VALS_PER_BUCKETcxx . . $ `src/queuelat/queuelat.c:74:9`!-1,
130 bucketscxx . . $ buckets.[bucket_nr]);
131 } else {
132 if (print_dotdotdot) {
133 printfcxx . . $ printf(581fddd72a8db8fc).("...\n");
134 print_dotdotdot = 0;
135 }
136 printfcxx . . $ printf(581fddd72a8db8fc).("[%lld - END] = %lld\n", val,
137 bucketscxx . . $ buckets.[bucket_nr]);
138 }
139 }
140 }
141
142 static void print_max_bucketseccxx . . $ print_max_bucketsec(49f6e7a06ebc5aa8).(void)
143 {
144 int i, bucket_nr;
145 unsigned long long highest_val = 0;
146
147 for (i = 0; i <= OUTLIER_BUCKETcxx . . $ `src/queuelat/queuelat.c:80:9`!; i++) {
148 unsigned long long val = i*VALS_PER_BUCKETcxx . . $ `src/queuelat/queuelat.c:74:9`!;
149
150 bucket_nr = val_to_bucketcxx . . $ val_to_bucket(642c2e9948c4ad2).(val);
151
152 if (bucketscxx . . $ buckets.[bucket_nr] != 0)
153 highest_val = val;
154 }
155
156 bucket_nr = val_to_bucketcxx . . $ val_to_bucket(642c2e9948c4ad2).(highest_val);
157 printfcxx . . $ printf(581fddd72a8db8fc).("Max loop processing time: [%lld - %lld] = %lld\n", highest_val,
158 highest_val + VALS_PER_BUCKETcxx . . $ `src/queuelat/queuelat.c:74:9`!-1,
159 bucketscxx . . $ buckets.[bucket_nr]);
160
161 return;
162 }
163
164 static void print_min_bucketseccxx . . $ print_min_bucketsec(49f6e7a06ebc5aa8).(void)
165 {
166 int i, bucket_nr;
167 unsigned long long min_val = 0;
168
169 for (i = 0; i <= OUTLIER_BUCKETcxx . . $ `src/queuelat/queuelat.c:80:9`!; i++) {
170 unsigned long long val = i*VALS_PER_BUCKETcxx . . $ `src/queuelat/queuelat.c:74:9`!;
171
172 bucket_nr = val_to_bucketcxx . . $ val_to_bucket(642c2e9948c4ad2).(val);
173
174 if (bucketscxx . . $ buckets.[bucket_nr] != 0) {
175 min_val = val;
176 break;
177 }
178 }
179
180 bucket_nr = val_to_bucketcxx . . $ val_to_bucket(642c2e9948c4ad2).(min_val);
181 printfcxx . . $ printf(581fddd72a8db8fc).("Min loop processing time: [%lld - %lld] = %lld\n", min_val,
182 min_val + VALS_PER_BUCKETcxx . . $ `src/queuelat/queuelat.c:74:9`!-1,
183 bucketscxx . . $ buckets.[bucket_nr]);
184
185 return;
186 }
187
188 static void print_avg_bucketseccxx . . $ print_avg_bucketsec(49f6e7a06ebc5aa8).(void)
189 {
190 int i, bucket_nr;
191 unsigned long long total_sum = 0;
192 unsigned long long nr_hits = 0;
193
194 for (i = 0; i <= OUTLIER_BUCKETcxx . . $ `src/queuelat/queuelat.c:80:9`!; i++) {
195 unsigned long long val = i*VALS_PER_BUCKETcxx . . $ `src/queuelat/queuelat.c:74:9`!;
196 unsigned long long maxtime;
197
198 bucket_nr = val_to_bucketcxx . . $ val_to_bucket(642c2e9948c4ad2).(val);
199
200 maxtime = val + VALS_PER_BUCKETcxx . . $ `src/queuelat/queuelat.c:74:9`!-1;
201 total_sum = total_sum + maxtime*bucketscxx . . $ buckets.[bucket_nr];
202
203 nr_hits = nr_hits + bucketscxx . . $ buckets.[bucket_nr];
204 }
205
206 printfcxx . . $ printf(581fddd72a8db8fc).("Avg loop processing time: %lld\n", total_sum / nr_hits);
207 }
208
209 static void print_all_buckets_drainlengthcxx . . $ print_all_buckets_drainlength(49f6e7a06ebc5aa8).(void)
210 {
211 int i, print_dotdotdot = 0;
212
213 for (i = 0; i <= OUTLIER_BUCKETcxx . . $ `src/queuelat/queuelat.c:80:9`!; i++) {
214 int bucket_nr;
215 unsigned long long val = i*VALS_PER_BUCKETcxx . . $ `src/queuelat/queuelat.c:74:9`!;
216
217 bucket_nr = val_to_bucketcxx . . $ val_to_bucket(642c2e9948c4ad2).(val);
218
219 if (bucket_nr != OUTLIER_BUCKETcxx . . $ `src/queuelat/queuelat.c:80:9`!) {
220 unsigned long long mindelta, maxdelta;
221 int nr_packets_minfill, nr_packets_maxfill;
222 int n_bucketnr = bucket_nr+1;
223
224 if (bucketscxx . . $ buckets.[bucket_nr] == bucketscxx . . $ buckets.[n_bucketnr]) {
225 print_dotdotdot = 1;
226 continue;
227 }
228 if (print_dotdotdot) {
229 printfcxx . . $ printf(581fddd72a8db8fc).("...\n");
230 print_dotdotdot = 0;
231 }
232
233 mindelta = val;
234 maxdelta = val + VALS_PER_BUCKETcxx . . $ `src/queuelat/queuelat.c:74:9`!-1;
235
236 nr_packets_minfill = mindelta * mppscxx . . $ mpps. * 1000000 / NSEC_PER_SECcxx . . $ `src/include/rt-utils.h:39:9`!;
237 nr_packets_maxfill = maxdelta * mppscxx . . $ mpps. * 1000000 / NSEC_PER_SECcxx . . $ `src/include/rt-utils.h:39:9`!;
238
239 printfcxx . . $ printf(581fddd72a8db8fc).("[%lld - %lld] = %lld packetfillrates=[%d - %d]\n", val,
240 val + VALS_PER_BUCKETcxx . . $ `src/queuelat/queuelat.c:74:9`!-1,
241 bucketscxx . . $ buckets.[bucket_nr],
242 nr_packets_minfill,
243 nr_packets_maxfill);
244 } else {
245 if (print_dotdotdot) {
246 printfcxx . . $ printf(581fddd72a8db8fc).("...\n");
247 print_dotdotdot = 0;
248 }
249 printfcxx . . $ printf(581fddd72a8db8fc).("[%lld - END] = %lld\n", val,
250 bucketscxx . . $ buckets.[bucket_nr]);
251 }
252 }
253 }
254
255 typedef unsigned long long cycles_tcxx . . $ cycles_t#;
256 typedef unsigned long long usecs_tcxx . . $ usecs_t#;
257 typedef unsigned long long u64cxx . . $ u64#;
258
259 #if defined __x86_64__cxx . . $ `<built-in>:374:9`! || defined __i386__
260
261 #ifdef __x86_64__cxx . . $ `<built-in>:374:9`!
262 #define DECLARE_ARGScxx . . $ `src/queuelat/queuelat.c:262:9`!(val, low, high) unsigned low, high
263 #define EAX_EDX_VALcxx . . $ `src/queuelat/queuelat.c:263:9`!(val, low, high) ((low) | ((u64)(high) << 32))
264 #define EAX_EDX_ARGScxx . . $ `src/queuelat/queuelat.c:264:9`!(val, low, high) "a" (low), "d" (high)
265 #define EAX_EDX_RETcxx . . $ `src/queuelat/queuelat.c:265:9`!(val, low, high) "=a" (low), "=d" (high)
266 #else
267 #define DECLARE_ARGS(val, low, high) unsigned long long val
268 #define EAX_EDX_VAL(val, low, high) (val)
269 #define EAX_EDX_ARGS(val, low, high) "A" (val)
270 #define EAX_EDX_RET(val, low, high) "=A" (val)
271 #endif
272
273 static inline unsigned long long __rdtscllcxx . . $ __rdtscll(73266883b0c7072b).(void)
274 {
275 DECLARE_ARGScxx . . $ `src/queuelat/queuelat.c:262:9`!(val, low, high);
276
277 asm volatile("mfence; rdtsc" : EAX_EDX_RETcxx . . $ `src/queuelat/queuelat.c:265:9`!(val, low, high));
278
279 return EAX_EDX_VALcxx . . $ `src/queuelat/queuelat.c:263:9`!(val, low, high);
280 }
281
282 #define gettickcxx . . $ `src/queuelat/queuelat.c:282:9`!(val) do { (val) = __rdtscll(); } while (0)
283
284 #else
285
286 static inline unsigned long long __clock_gettime(void)
287 {
288 struct timespec now;
289 int ret;
290
291 ret = clock_gettime(CLOCK_MONOTONIC, &now);
292 if (ret < 0)
293 return 0;
294
295 // Combine seconds and nanoseconds into a single value in nanoseconds
296 return (unsigned long long)now.tv_sec * 1000000000ULL + now.tv_nsec;
297 }
298
299 #define gettick(val) do { (val) = __clock_gettime(); } while (0)
300
301 #endif
302
303 static void init_bucketscxx . . $ init_buckets(49f6e7a06ebc5aa8).(void)
304 {
305 int i;
306
307 for (i=0; i <= NR_BUCKETScxx . . $ `src/queuelat/queuelat.c:75:9`!; i++)
308 bucketscxx . . $ buckets.[i] = 0;
309
310 total_countcxx . . $ total_count. = 0;
311 }
312
313 static int find_highest_count_bucketcxx . . $ find_highest_count_bucket(b126dc7c1de90089).(void)
314 {
315 int i;
316 int max_bucket = 0;
317 unsigned long long max_val = 0;
318
319 for (i=0; i <= NR_BUCKETScxx . . $ `src/queuelat/queuelat.c:75:9`!; i++) {
320 if (bucketscxx . . $ buckets.[i] > max_val) {
321 max_bucket = i;
322 max_val = bucketscxx . . $ buckets.[i];
323 }
324 }
325
326 return max_bucket;
327 }
328
329 int tracing_mark_fdcxx . . $ tracing_mark_fd.;
330 static void trace_opencxx . . $ trace_open(49f6e7a06ebc5aa8).(void)
331 {
332 int fd;
333
334 fd = opencxx . . $ open(e156e3aa1e5c4ad1).("/sys/kernel/tracing/trace_marker", O_RDWRcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:45:9`!);
335
336 if (fd == -1) {
337 perrorcxx . . $ perror(85c52e162fed56f9).("open");
338 exitcxx . . $ exit(3ca292c338df9bb3).(0);
339 }
340 tracing_mark_fdcxx . . $ tracing_mark_fd. = fd;
341 }
342
343 static void trace_writecxx . . $ trace_write(a07d8cccb7673f5a).(char *buf, int len)
344 {
345 int ret;
346
347 ret = writecxx . . $ write(41184a59d38b4f65).(tracing_mark_fdcxx . . $ tracing_mark_fd., buf, len);
348 if (ret == -1) {
349 perrorcxx . . $ perror(85c52e162fed56f9).("write");
350 exitcxx . . $ exit(3ca292c338df9bb3).(0);
351 }
352 }
353
354 static void run_ncxx . . $ run_n(d4f767463ce0a6b3).(int n)
355 {
356 u64cxx . . $ u64# a, b, delta;
357 void *dest, *src;
358 int i, loops = 50000;
359
360 init_bucketscxx . . $ init_buckets(49f6e7a06ebc5aa8).();
361
362 dest = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(n);
363 if (dest == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
364 printfcxx . . $ printf(581fddd72a8db8fc).("failure to allocate %d bytes "
365 " for dest\n", n);
366 exitcxx . . $ exit(3ca292c338df9bb3).(0);
367 }
368 src = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(n);
369 if (src == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
370 printfcxx . . $ printf(581fddd72a8db8fc).("failure to allocate %d bytes "
371 " for src\n", n);
372 exitcxx . . $ exit(3ca292c338df9bb3).(0);
373 }
374
375 memsetcxx . . $ memset(d1de1e4fb215f1c6).(src, 0, n);
376
377 memmovecxx . . $ memmove(cc817cb175f282d).(dest, src, n);
378 for (i = 0; i < loops; i++) {
379 gettickcxx . . $ `src/queuelat/queuelat.c:282:9`!(b);
380 memmovecxx . . $ memmove(cc817cb175f282d).(dest, src, n);
381 gettickcxx . . $ `src/queuelat/queuelat.c:282:9`!(a);
382 delta = (a - b) * cycles_to_nscxx . . $ cycles_to_ns.;
383 accountcxx . . $ account(891dc3055356b409).(delta);
384 }
385
386 freecxx . . $ free(5d22bdacc48458e8).(dest);
387 freecxx . . $ free(5d22bdacc48458e8).(src);
388
389 return;
390 }
391
392 /*
393 * Find the size of n such that the stats for the
394 * function call
395 *
396 * memmove(dest, src, n).
397 *
398 * Takes MaximumLat/2 in the bucket that has most
399 * entries.
400 *
401 */
402 static int measure_ncxx . . $ measure_n(b126dc7c1de90089).(void)
403 {
404 int time, bucket_nr;
405 int n = 100000, delta = 0;
406
407 do {
408 if (delta > 0)
409 n = n+1000;
410 else if (delta < 0)
411 n = n-1000;
412
413 run_ncxx . . $ run_n(d4f767463ce0a6b3).(n);
414 bucket_nr = find_highest_count_bucketcxx . . $ find_highest_count_bucket(b126dc7c1de90089).();
415
416 time = bucket_nr * VALS_PER_BUCKETcxx . . $ `src/queuelat/queuelat.c:74:9`!;
417
418 delta = maxlatencycxx . . $ maxlatency./2 - time;
419 } while (abscxx . . $ abs(7864480464b09eea).(delta) > VALS_PER_BUCKETcxx . . $ `src/queuelat/queuelat.c:74:9`!*2);
420
421 return n;
422 }
423
424 static void convert_to_ghzcxx . . $ convert_to_ghz(ba8836b59fb42830).(double tsc_freq_mhz)
425 {
426 float tsc_freq_ghz = tsc_freq_mhz/1000;
427
428 cycles_to_nscxx . . $ cycles_to_ns. = 1/tsc_freq_ghz;
429
430 printfcxx . . $ printf(581fddd72a8db8fc).("tsc_freq_ghz = %f, cycles_to_ns = %f\n", tsc_freq_ghz,
431 cycles_to_nscxx . . $ cycles_to_ns.);
432 }
433
434
435 static void print_exit_infocxx . . $ print_exit_info(49f6e7a06ebc5aa8).(void)
436 {
437 print_all_bucketscxx . . $ print_all_buckets(49f6e7a06ebc5aa8).();
438 printfcxx . . $ printf(581fddd72a8db8fc).("\n ---------------- \n");
439 print_min_bucketseccxx . . $ print_min_bucketsec(49f6e7a06ebc5aa8).();
440 print_max_bucketseccxx . . $ print_max_bucketsec(49f6e7a06ebc5aa8).();
441 print_avg_bucketseccxx . . $ print_avg_bucketsec(49f6e7a06ebc5aa8).();
442
443 }
444
445 void main_loopcxx . . $ main_loop(49f6e7a06ebc5aa8).(void)
446 {
447 u64cxx . . $ u64# a, b, delta;
448 void *dest, *src;
449 int queue_size = 0;
450
451 trace_opencxx . . $ trace_open(49f6e7a06ebc5aa8).();
452
453 init_bucketscxx . . $ init_buckets(49f6e7a06ebc5aa8).();
454
455 dest = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(default_ncxx . . $ default_n.);
456 if (dest == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
457 printfcxx . . $ printf(581fddd72a8db8fc).("failure to allocate %d bytes "
458 " for dest\n", default_ncxx . . $ default_n.);
459 exitcxx . . $ exit(3ca292c338df9bb3).(0);
460 }
461 src = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(default_ncxx . . $ default_n.);
462 if (src == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
463 printfcxx . . $ printf(581fddd72a8db8fc).("failure to allocate %d bytes "
464 " for src\n", default_ncxx . . $ default_n.);
465 exitcxx . . $ exit(3ca292c338df9bb3).(0);
466 }
467
468 memsetcxx . . $ memset(d1de1e4fb215f1c6).(src, 0, default_ncxx . . $ default_n.);
469 memmovecxx . . $ memmove(cc817cb175f282d).(dest, src, default_ncxx . . $ default_n.);
470
471 while (1) {
472 char buf[500];
473 int ret;
474 int nr_packets_fill;
475
476 gettickcxx . . $ `src/queuelat/queuelat.c:282:9`!(b);
477 memmovecxx . . $ memmove(cc817cb175f282d).(dest, src, default_ncxx . . $ default_n.);
478 gettickcxx . . $ `src/queuelat/queuelat.c:282:9`!(a);
479 delta = (a - b) * cycles_to_nscxx . . $ cycles_to_ns.;
480 accountcxx . . $ account(891dc3055356b409).(delta);
481
482 /* fill up the queue by the amount of
483 * time that passed */
484 nr_packets_fill = delta * mppscxx . . $ mpps. * 1000000 / NSEC_PER_SECcxx . . $ `src/include/rt-utils.h:39:9`!;
485 queue_size += nr_packets_fill;
486
487 /* decrease the queue by the amount of packets
488 * processed in maxlatency/2 nanoseconds of
489 * full processing.
490 */
491
492 queue_size -= nr_packets_drain_per_blockcxx . . $ nr_packets_drain_per_block.;
493
494 if (queue_size < 0)
495 queue_size = 0;
496
497 if (queue_size <= min_queue_size_to_printcxx . . $ min_queue_size_to_print.)
498 continue;
499
500 ret = sprintfcxx . . $ sprintf(26c8642d26409d6d).(buf, "memmove block queue_size=%d queue_dec=%d"
501 " queue_inc=%d delta=%llu ns\n", queue_size,
502 nr_packets_drain_per_blockcxx . . $ nr_packets_drain_per_block.,
503 nr_packets_fill, delta);
504 trace_writecxx . . $ trace_write(a07d8cccb7673f5a).(buf, ret);
505
506 if (queue_size > max_queue_lencxx . . $ max_queue_len.) {
507 printfcxx . . $ printf(581fddd72a8db8fc).("queue length exceeded: "
508 " queue_size=%d max_queue_len=%d\n",
509 queue_size, max_queue_lencxx . . $ max_queue_len.);
510 ret = sprintfcxx . . $ sprintf(26c8642d26409d6d).(buf, "queue length exceeded: "
511 "queue_size=%d max_queue_len=%d\n",
512 queue_size, max_queue_lencxx . . $ max_queue_len.);
513 trace_writecxx . . $ trace_write(a07d8cccb7673f5a).(buf, ret);
514 print_exit_infocxx . . $ print_exit_info(49f6e7a06ebc5aa8).();
515 exitcxx . . $ exit(3ca292c338df9bb3).(0);
516 }
517 }
518
519 freecxx . . $ free(5d22bdacc48458e8).(dest);
520 freecxx . . $ free(5d22bdacc48458e8).(src);
521 }
522
523 void sig_handlercxx . . $ sig_handler(d4f767463ce0a6b3).(int sig)
524 {
525 print_exit_infocxx . . $ print_exit_info(49f6e7a06ebc5aa8).();
526 exitcxx . . $ exit(3ca292c338df9bb3).(0);
527 }
528
529 static void install_signalscxx . . $ install_signals(49f6e7a06ebc5aa8).(void)
530 {
531 signalcxx . . $ signal(c2d516773f91faf8).(SIGALRMcxx . . $ `<external>/11773118241360591791/signum-generic.h:61:9`!, sig_handlercxx . . $ sig_handler(d4f767463ce0a6b3).);
532 signalcxx . . $ signal(c2d516773f91faf8).(SIGINTcxx . . $ `<external>/11773118241360591791/signum-generic.h:48:9`!, sig_handlercxx . . $ sig_handler(d4f767463ce0a6b3).);
533 }
534
535 int calculate_nr_packets_drain_per_blockcxx . . $ calculate_nr_packets_drain_per_block(b126dc7c1de90089).(void)
536 {
537 unsigned long long maxcount;
538 int i, time;
539 int found = 0;
540 int bucket_nr = find_highest_count_bucketcxx . . $ find_highest_count_bucket(b126dc7c1de90089).();
541
542 maxcount = total_samplescxx . . $ total_samples(73266883b0c7072b).() / 40;
543
544 for (i = bucket_nr+1; i <= NR_BUCKETScxx . . $ `src/queuelat/queuelat.c:75:9`!; i++) {
545 if (bucketscxx . . $ buckets.[i] < maxcount) {
546 found = 1;
547 break;
548 }
549 }
550
551 if (found == 0) {
552 printfcxx . . $ printf(581fddd72a8db8fc).("error, did not find right bucket with < 10%% of total\n");
553 exitcxx . . $ exit(3ca292c338df9bb3).(0);
554 }
555
556 time = i*VALS_PER_BUCKETcxx . . $ `src/queuelat/queuelat.c:74:9`! + VALS_PER_BUCKETcxx . . $ `src/queuelat/queuelat.c:74:9`!-1;
557 nr_packets_drain_per_blockcxx . . $ nr_packets_drain_per_block. = time / (cycles_per_packetcxx . . $ cycles_per_packet.*cycles_to_nscxx . . $ cycles_to_ns.);
558
559 return nr_packets_drain_per_blockcxx . . $ nr_packets_drain_per_block.;
560 }
561
562 static void print_helpcxx . . $ print_help(d4f767463ce0a6b3).(int error)
563 {
564 printfcxx . . $ printf(581fddd72a8db8fc).("queuelat V %1.2f\n", VERSIONcxx . . $ `<built-in>:412:9`!);
565 printfcxx . . $ printf(581fddd72a8db8fc).("Usage:\n"
566 "queuelat <options>\n\n"
567 "-c N --cycles N number of cycles to process one packet (int)\n"
568 "-f F --freq F TSC frequency in MHz (float)\n"
569 "-h --help show this help menu\n"
570 "-m LEN --max-len LEN maximum latency allowed, in nanoseconds (int)\n"
571 "-p F --packets F million packets per second (float)\n"
572 "-q N --queue-len N minimum queue len to print trace (int)\n"
573 "-t TIME --timeout TIME timeout, in seconds (int)\n"
574 );
575 exitcxx . . $ exit(3ca292c338df9bb3).(error);
576 }
577
578 int maincxx . . $ main(afcd3168fc1188a4).(int argc, char **argv)
579 {
580 double tsc_freq_mhz;
581 float max_queue_len_f;
582 char *mvalue = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
583 char *cvalue = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
584 char *pvalue = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
585 char *fvalue = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
586 char *tvalue = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
587 char *qvalue = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
588
589 opterrcxx . . $ opterr. = 0;
590
591 for (;;) {
592 static struct optioncxx . . $ option# options[] = {
593 {"cycles", required_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:63:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 'c'},
594 {"freq", required_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:63:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 'f'},
595 {"help", no_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:62:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 'h'},
596 {"max-len", required_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:63:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 'm'},
597 {"packets", required_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:63:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 'p'},
598 {"queue-len", required_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:63:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 'q'},
599 {"timeout", required_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:63:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 't'},
600 {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}
601 };
602 int c = getopt_longcxx . . $ getopt_long(41f665c090816971).(argc, argv, "c:f:hm:p:q:t:", options, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
603 if (c == -1)
604 break;
605 switch (c) {
606 case 'c':
607 cvalue = optargcxx . . $ optarg.;
608 break;
609 case 'f':
610 fvalue = optargcxx . . $ optarg.;
611 break;
612 case '?':
613 case 'h':
614 print_helpcxx . . $ print_help(d4f767463ce0a6b3).(0);
615 break;
616 case 'm':
617 mvalue = optargcxx . . $ optarg.;
618 break;
619 case 'p':
620 pvalue = optargcxx . . $ optarg.;
621 break;
622 case 'q':
623 qvalue = optargcxx . . $ optarg.;
624 break;
625 case 't':
626 tvalue = optargcxx . . $ optarg.;
627 break;
628 default:
629 print_helpcxx . . $ print_help(d4f767463ce0a6b3).(1);
630 break;
631 }
632 }
633
634 if (mvalue == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! || cvalue == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! || pvalue == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! || fvalue == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
635 printfcxx . . $ printf(581fddd72a8db8fc).("options -m, -c, -p and -f are required\n");
636 exitcxx . . $ exit(3ca292c338df9bb3).(1);
637 }
638
639 install_signalscxx . . $ install_signals(49f6e7a06ebc5aa8).();
640
641 maxlatencycxx . . $ maxlatency. = atoicxx . . $ atoi(5c4306d8553b3696).(mvalue);
642 cycles_per_packetcxx . . $ cycles_per_packet. = atoicxx . . $ atoi(5c4306d8553b3696).(cvalue);
643 mppscxx . . $ mpps. = atofcxx . . $ atof(9a18bdb0e56c1bc2).(pvalue);
644 tsc_freq_mhz = atofcxx . . $ atof(9a18bdb0e56c1bc2).(fvalue);
645
646 if (tvalue) {
647 int alarm_secs;
648 alarm_secs = atoicxx . . $ atoi(5c4306d8553b3696).(tvalue);
649 alarmcxx . . $ alarm(2141b656ce2cc063).(alarm_secs);
650 }
651
652 if (qvalue)
653 min_queue_size_to_printcxx . . $ min_queue_size_to_print. = atoicxx . . $ atoi(5c4306d8553b3696).(qvalue);
654
655 convert_to_ghzcxx . . $ convert_to_ghz(ba8836b59fb42830).(tsc_freq_mhz);
656
657 max_queue_len_f = maxlatencycxx . . $ maxlatency. / (cycles_per_packetcxx . . $ cycles_per_packet.*cycles_to_nscxx . . $ cycles_to_ns.);
658 max_queue_lencxx . . $ max_queue_len. = max_queue_len_f;
659
660 printfcxx . . $ printf(581fddd72a8db8fc).("max_queue_len = %d\n", max_queue_lencxx . . $ max_queue_len.);
661 default_ncxx . . $ default_n. = measure_ncxx . . $ measure_n(b126dc7c1de90089).();
662
663 nr_packets_drain_per_blockcxx . . $ nr_packets_drain_per_block. = calculate_nr_packets_drain_per_blockcxx . . $ calculate_nr_packets_drain_per_block(b126dc7c1de90089).();
664 print_all_buckets_drainlengthcxx . . $ print_all_buckets_drainlength(49f6e7a06ebc5aa8).();
665
666 printfcxx . . $ printf(581fddd72a8db8fc).("default_n=%d nr_packets_drain_per_block=%d\n", default_ncxx . . $ default_n.,
667 nr_packets_drain_per_blockcxx . . $ nr_packets_drain_per_block.);
668
669 main_loopcxx . . $ main_loop(49f6e7a06ebc5aa8).();
670
671 return 0;
672 }
673