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
Unified · Split
| @@ -307,6 +307,23 @@ TRACE_EVENT(urandom_read, · 306 unmodified lines | ||
| 307 | 307 | __entry->pool_left, __entry->input_left) |
| 308 | 308 | ); |
| 309 | 309 | |
| 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 | + | |
| 310 | 327 | #endif /* _TRACE_RANDOM_H */ |
| 311 | 328 | |
| 312 | 329 | /* This part must be outside protection */ |
| @@ -39,6 +39,7 @@ · 38 unmodified lines | ||
| 39 | 39 | #include <linux/random.h> |
| 40 | 40 | #include <linux/sched.h> |
| 41 | 41 | #include <asm/unaligned.h> |
| 42 | +#include <trace/events/random.h> | |
| 42 | 43 | |
| 43 | 44 | #ifdef CONFIG_RANDOM32_SELFTEST |
| 44 | 45 | static void __init prandom_state_selftest(void); |
| @@ -82,6 +83,7 @@ u32 prandom_u32(void) · 37 unmodified lines | ||
| 82 | 83 | u32 res; |
| 83 | 84 | |
| 84 | 85 | res = prandom_u32_state(state); |
| 86 | + trace_prandom_u32(res); | |
| 85 | 87 | put_cpu_var(net_rand_state); |
| 86 | 88 | |
| 87 | 89 | return res; |