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