Skip to content

Commit

Permalink
random32: add a tracepoint for prandom_u32()
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Eric Dumazet authored and davem330 committed Aug 13, 2020
1 parent 9643609 commit 94c7eb5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
17 changes: 17 additions & 0 deletions include/trace/events/random.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,23 @@ TRACE_EVENT(urandom_read,
__entry->pool_left, __entry->input_left)
);

TRACE_EVENT(prandom_u32,

TP_PROTO(unsigned int ret),

TP_ARGS(ret),

TP_STRUCT__entry(
__field( unsigned int, ret)
),

TP_fast_assign(
__entry->ret = ret;
),

TP_printk("ret=%u" , __entry->ret)
);

#endif /* _TRACE_RANDOM_H */

/* This part must be outside protection */
Expand Down
2 changes: 2 additions & 0 deletions lib/random32.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <linux/random.h>
#include <linux/sched.h>
#include <asm/unaligned.h>
#include <trace/events/random.h>

#ifdef CONFIG_RANDOM32_SELFTEST
static void __init prandom_state_selftest(void);
Expand Down Expand Up @@ -82,6 +83,7 @@ u32 prandom_u32(void)
u32 res;

res = prandom_u32_state(state);
trace_prandom_u32(res);
put_cpu_var(net_rand_state);

return res;
Expand Down

0 comments on commit 94c7eb5

Please sign in to comment.