History

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

Eric Dumazet committed 6 years ago

Commit 94c7eb51 parent 96436092 files · +19 −0Browse files

Unified · Split

2 files
  1. include/trace/events/random.h +17 −0
  2. lib/random32.c +2 −0
include/trace/events/random.h+17−0
@@ -307,6 +307,23 @@ TRACE_EVENT(urandom_read, · 306 unmodified lines
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+2−0
@@ -39,6 +39,7 @@ · 38 unmodified lines
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) · 37 unmodified lines
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;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t