Skip to content

Commit 94c7eb5

Browse files
edumazetdavem330
authored andcommitted
random32: add a tracepoint for prandom_u32()
There has been some heat around prandom_u32() lately, and some people were wondering if there was a simple way to determine how often it was used, before considering making it maybe 10 times more expensive. This tracepoint exports the generated pseudo random value. Tested: perf list | grep prandom_u32 random:prandom_u32 [Tracepoint event] perf record -a [-g] [-C1] -e random:prandom_u32 sleep 1 [ perf record: Woken up 0 times to write data ] [ perf record: Captured and wrote 259.748 MB perf.data (924087 samples) ] perf report --nochildren ... 97.67% ksoftirqd/1 [kernel.vmlinux] [k] prandom_u32 | ---prandom_u32 prandom_u32 | |--48.86%--tcp_v4_syn_recv_sock | tcp_check_req | tcp_v4_rcv | ... --48.81%--tcp_conn_request tcp_v4_conn_request tcp_rcv_state_process ... perf script Signed-off-by: Eric Dumazet <[email protected]> Cc: Willy Tarreau <[email protected]> Cc: Sedat Dilek <[email protected]> Tested-by: Sedat Dilek <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 9643609 commit 94c7eb5

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

include/trace/events/random.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,23 @@ TRACE_EVENT(urandom_read,
307307
__entry->pool_left, __entry->input_left)
308308
);
309309

310+
TRACE_EVENT(prandom_u32,
311+
312+
TP_PROTO(unsigned int ret),
313+
314+
TP_ARGS(ret),
315+
316+
TP_STRUCT__entry(
317+
__field( unsigned int, ret)
318+
),
319+
320+
TP_fast_assign(
321+
__entry->ret = ret;
322+
),
323+
324+
TP_printk("ret=%u" , __entry->ret)
325+
);
326+
310327
#endif /* _TRACE_RANDOM_H */
311328

312329
/* This part must be outside protection */

lib/random32.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include <linux/random.h>
4040
#include <linux/sched.h>
4141
#include <asm/unaligned.h>
42+
#include <trace/events/random.h>
4243

4344
#ifdef CONFIG_RANDOM32_SELFTEST
4445
static void __init prandom_state_selftest(void);
@@ -82,6 +83,7 @@ u32 prandom_u32(void)
8283
u32 res;
8384

8485
res = prandom_u32_state(state);
86+
trace_prandom_u32(res);
8587
put_cpu_var(net_rand_state);
8688

8789
return res;

0 commit comments

Comments
 (0)