2024-05-25 02:41:44

by Steven Rostedt

[permalink] [raw]
Subject: [PATCH 19/20] function_graph: Use for_each_set_bit() in __ftrace_return_to_handler()

From: "Steven Rostedt (Google)" <[email protected]>

Instead of iterating through the entire fgraph_array[] and seeing if one
of the bitmap bits are set to know to call the array's retfunc() function,
use for_each_set_bit() on the bitmap itself. This will only iterate for
the number of set bits.

Signed-off-by: Steven Rostedt (Google) <[email protected]>
---
kernel/trace/fgraph.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c
index 4d503b3e45ad..5e8e13ffcfb6 100644
--- a/kernel/trace/fgraph.c
+++ b/kernel/trace/fgraph.c
@@ -827,11 +827,10 @@ static unsigned long __ftrace_return_to_handler(struct fgraph_ret_regs *ret_regs
#endif

bitmap = get_bitmap_bits(current, offset);
- for (i = 0; i < FGRAPH_ARRAY_SIZE; i++) {
+
+ for_each_set_bit(i, &bitmap, sizeof(bitmap) * BITS_PER_BYTE) {
struct fgraph_ops *gops = fgraph_array[i];

- if (!(bitmap & BIT(i)))
- continue;
if (gops == &fgraph_stub)
continue;

--
2.43.0




2024-05-26 23:58:59

by Masami Hiramatsu

[permalink] [raw]
Subject: Re: [PATCH 19/20] function_graph: Use for_each_set_bit() in __ftrace_return_to_handler()

On Fri, 24 May 2024 22:37:11 -0400
Steven Rostedt <[email protected]> wrote:

> From: "Steven Rostedt (Google)" <[email protected]>
>
> Instead of iterating through the entire fgraph_array[] and seeing if one
> of the bitmap bits are set to know to call the array's retfunc() function,
> use for_each_set_bit() on the bitmap itself. This will only iterate for
> the number of set bits.
>

Looks good to me.

Reviewed-by: Masami Hiramatsu (Google) <[email protected]>

Thanks,

> Signed-off-by: Steven Rostedt (Google) <[email protected]>
> ---
> kernel/trace/fgraph.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c
> index 4d503b3e45ad..5e8e13ffcfb6 100644
> --- a/kernel/trace/fgraph.c
> +++ b/kernel/trace/fgraph.c
> @@ -827,11 +827,10 @@ static unsigned long __ftrace_return_to_handler(struct fgraph_ret_regs *ret_regs
> #endif
>
> bitmap = get_bitmap_bits(current, offset);
> - for (i = 0; i < FGRAPH_ARRAY_SIZE; i++) {
> +
> + for_each_set_bit(i, &bitmap, sizeof(bitmap) * BITS_PER_BYTE) {
> struct fgraph_ops *gops = fgraph_array[i];
>
> - if (!(bitmap & BIT(i)))
> - continue;
> if (gops == &fgraph_stub)
> continue;
>
> --
> 2.43.0
>
>


--
Masami Hiramatsu (Google) <[email protected]>

2024-05-27 00:04:49

by Masami Hiramatsu

[permalink] [raw]
Subject: Re: [PATCH 19/20] function_graph: Use for_each_set_bit() in __ftrace_return_to_handler()

On Fri, 24 May 2024 22:37:11 -0400
Steven Rostedt <[email protected]> wrote:

> From: "Steven Rostedt (Google)" <[email protected]>
>
> Instead of iterating through the entire fgraph_array[] and seeing if one
> of the bitmap bits are set to know to call the array's retfunc() function,
> use for_each_set_bit() on the bitmap itself. This will only iterate for
> the number of set bits.
>
> Signed-off-by: Steven Rostedt (Google) <[email protected]>
> ---
> kernel/trace/fgraph.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c
> index 4d503b3e45ad..5e8e13ffcfb6 100644
> --- a/kernel/trace/fgraph.c
> +++ b/kernel/trace/fgraph.c
> @@ -827,11 +827,10 @@ static unsigned long __ftrace_return_to_handler(struct fgraph_ret_regs *ret_regs
> #endif
>
> bitmap = get_bitmap_bits(current, offset);
> - for (i = 0; i < FGRAPH_ARRAY_SIZE; i++) {
> +
> + for_each_set_bit(i, &bitmap, sizeof(bitmap) * BITS_PER_BYTE) {
> struct fgraph_ops *gops = fgraph_array[i];
>
> - if (!(bitmap & BIT(i)))
> - continue;
> if (gops == &fgraph_stub)

Ah, nit: maybe this is unlikely()?

Thank you,


--
Masami Hiramatsu (Google) <[email protected]>

2024-05-27 00:31:54

by Steven Rostedt

[permalink] [raw]
Subject: Re: [PATCH 19/20] function_graph: Use for_each_set_bit() in __ftrace_return_to_handler()

On Mon, 27 May 2024 09:04:34 +0900
Masami Hiramatsu (Google) <[email protected]> wrote:

> > bitmap = get_bitmap_bits(current, offset);
> > - for (i = 0; i < FGRAPH_ARRAY_SIZE; i++) {
> > +
> > + for_each_set_bit(i, &bitmap, sizeof(bitmap) * BITS_PER_BYTE) {
> > struct fgraph_ops *gops = fgraph_array[i];
> >
> > - if (!(bitmap & BIT(i)))
> > - continue;
> > if (gops == &fgraph_stub)
>
> Ah, nit: maybe this is unlikely()?

Ah probably. I'll update it.

Thanks,

-- Steve