* [PATCH net] random32: add a tracepoint for prandom_u32()
@ 2020-08-13 17:06 Eric Dumazet
2020-08-13 17:53 ` Sedat Dilek
2020-08-13 22:16 ` David Miller
0 siblings, 2 replies; 3+ messages in thread
From: Eric Dumazet @ 2020-08-13 17:06 UTC (permalink / raw)
To: David S . Miller
Cc: netdev, Eric Dumazet, Eric Dumazet, Willy Tarreau, Sedat Dilek
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 <edumazet@google.com>
Cc: Willy Tarreau <w@1wt.eu>
Cc: Sedat Dilek <sedat.dilek@gmail.com>
---
According to MAINTAINERS, lib/random32.c is part of networking...
include/trace/events/random.h | 17 +++++++++++++++++
lib/random32.c | 2 ++
2 files changed, 19 insertions(+)
diff --git a/include/trace/events/random.h b/include/trace/events/random.h
index 32c10a515e2d5438e8d620a0c2313aab5f849b2b..9570a10cb949b5792c4290ba8e82a077ac655069 100644
--- a/include/trace/events/random.h
+++ b/include/trace/events/random.h
@@ -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 */
diff --git a/lib/random32.c b/lib/random32.c
index 3d749abb9e80d54d8e330e07fb8b773b7bec2b83..932345323af092a93fc2690b0ebbf4f7485ae4f3 100644
--- a/lib/random32.c
+++ b/lib/random32.c
@@ -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);
@@ -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;
--
2.28.0.220.ged08abb693-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net] random32: add a tracepoint for prandom_u32()
2020-08-13 17:06 [PATCH net] random32: add a tracepoint for prandom_u32() Eric Dumazet
@ 2020-08-13 17:53 ` Sedat Dilek
2020-08-13 22:16 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: Sedat Dilek @ 2020-08-13 17:53 UTC (permalink / raw)
To: Eric Dumazet; +Cc: David S . Miller, netdev, Eric Dumazet, Willy Tarreau
On Thu, Aug 13, 2020 at 7:06 PM Eric Dumazet <edumazet@google.com> wrote:
>
> 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 <edumazet@google.com>
> Cc: Willy Tarreau <w@1wt.eu>
> Cc: Sedat Dilek <sedat.dilek@gmail.com>
Thanks for the patch and embedding a list of instructions with linux-perf.
Tested-by: Sedat Dilek <sedat.dilek@gmail.com>
- Sedat -
> ---
> According to MAINTAINERS, lib/random32.c is part of networking...
>
> include/trace/events/random.h | 17 +++++++++++++++++
> lib/random32.c | 2 ++
> 2 files changed, 19 insertions(+)
>
> diff --git a/include/trace/events/random.h b/include/trace/events/random.h
> index 32c10a515e2d5438e8d620a0c2313aab5f849b2b..9570a10cb949b5792c4290ba8e82a077ac655069 100644
> --- a/include/trace/events/random.h
> +++ b/include/trace/events/random.h
> @@ -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 */
> diff --git a/lib/random32.c b/lib/random32.c
> index 3d749abb9e80d54d8e330e07fb8b773b7bec2b83..932345323af092a93fc2690b0ebbf4f7485ae4f3 100644
> --- a/lib/random32.c
> +++ b/lib/random32.c
> @@ -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);
> @@ -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;
> --
> 2.28.0.220.ged08abb693-goog
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net] random32: add a tracepoint for prandom_u32()
2020-08-13 17:06 [PATCH net] random32: add a tracepoint for prandom_u32() Eric Dumazet
2020-08-13 17:53 ` Sedat Dilek
@ 2020-08-13 22:16 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2020-08-13 22:16 UTC (permalink / raw)
To: edumazet; +Cc: netdev, eric.dumazet, w, sedat.dilek
From: Eric Dumazet <edumazet@google.com>
Date: Thu, 13 Aug 2020 10:06:43 -0700
> 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 <edumazet@google.com>
Applied, thanks Eric.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-08-13 22:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-13 17:06 [PATCH net] random32: add a tracepoint for prandom_u32() Eric Dumazet
2020-08-13 17:53 ` Sedat Dilek
2020-08-13 22:16 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).