tracing/eprobe: Iterate trace_eprobe directly
PATCH 1/1 tracing/eprobe: Iterate trace_eprobe directly
Refer to the description in [1], we can skip "container_of()" following "list_for_each_entry()" by using "list_for_each_entry()" with "struct trace_eprobe" and "tp.list".
[1] https://lore.kernel.org/all/CAHk-=wjakjw6-rDzDDBsuMoDCqd+9ogifR_EE1F0K-jYek1CdA@mail.gmail.com/
--- kernel/trace/trace_eprobe.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
kernel/trace/trace_eprobe.c +5 -8
@@ -640,7 +640,7 @@ static int disable_eprobe(struct trace_eprobe *ep,static int enable_trace_eprobe (struct trace_event_call *call,struct trace_event_file *file) { -struct trace_probe *pos, *tp; +struct trace_probe *tp;struct trace_eprobe *ep;bool enabled;int ret =0 ;
@@ -662,8 +662,7 @@ static int enable_trace_eprobe(struct trace_event_call *call,if (enabled)return 0 ; -list_for_each_entry (pos,trace_probe_probe_list (tp), list) { - ep = container_of(pos, struct trace_eprobe, tp); +list_for_each_entry (ep,trace_probe_probe_list (tp), tp.list) { ret =enable_eprobe (ep, file);if (ret)break ;
@@ -680,8 +679,7 @@ static int enable_trace_eprobe(struct trace_event_call *call,*/ WARN_ON_ONCE (ret != -ENOMEM ); -list_for_each_entry (pos,trace_probe_probe_list (tp), list) { - ep = container_of(pos, struct trace_eprobe, tp); +list_for_each_entry (ep,trace_probe_probe_list (tp), tp.list) {disable_eprobe (ep, file->tr);if (!--cnt)break ;
@@ -699,7 +697,7 @@ static int enable_trace_eprobe(struct trace_event_call *call,static int disable_trace_eprobe (struct trace_event_call *call,struct trace_event_file *file) { -struct trace_probe *pos, *tp; +struct trace_probe *tp;struct trace_eprobe *ep; tp =trace_probe_primary_from_call (call);
@@ -716,8 +714,7 @@ static int disable_trace_eprobe(struct trace_event_call *call,trace_probe_clear_flag (tp,TP_FLAG_PROFILE );if (!trace_probe_is_enabled (tp)) { -list_for_each_entry (pos,trace_probe_probe_list (tp), list) { - ep = container_of(pos, struct trace_eprobe, tp); +list_for_each_entry (ep,trace_probe_probe_list (tp), tp.list) {disable_eprobe (ep, file->tr); } }
Signature · 1 line
2.39.2
Masami Hiramatsu (Google)
maintainerQuoted 6 lines · On Thu, 10 Aug 2023 16:25:23 +0800 Chuang Wang <[email protected]> wrote:
Refer to the description in [1], we can skip "
container_of()" following "list_for_each_entry()" by using "list_for_each_entry()" with "structtrace_eprobe" and "tp.list".[1] https://lore.kernel.org/all/CAHk-=wjakjw6-rDzDDBsuMoDCqd+9ogifR_EE1F0K-jYek1CdA@mail.gmail.com/
Good point. BTW, it is better to have 'for_each_eprobe(ep)' if it repeats 3 times.
Quoted 1 line
Fixes 7491e2c44278 ("tracing: Add a probe that attaches to trace events")
This is not a bug, so no need Fixes tag.
Thank you,
Quoted 60 lines
Signed-off-by Chuang Wang <[email protected]>--- kernel/trace/trace_eprobe.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)kernel/trace/trace_eprobe.c +5
-8@@ -640,7 +640,7 @@ static int disable_eprobe(struct trace_eprobe *ep,static int enable_trace_eprobe (struct trace_event_call *call,struct trace_event_file *file) { -struct trace_probe *pos, *tp; +struct trace_probe *tp;struct trace_eprobe *ep;bool enabled;int ret =0 ;@@ -662,8 +662,7 @@ static int enable_trace_eprobe(struct trace_event_call *call,if (enabled)return 0 ; -list_for_each_entry (pos,trace_probe_probe_list (tp), list) { - ep = container_of(pos, struct trace_eprobe, tp); +list_for_each_entry (ep,trace_probe_probe_list (tp), tp.list) { ret =enable_eprobe (ep, file);if (ret)break ;@@ -680,8 +679,7 @@ static int enable_trace_eprobe(struct trace_event_call *call,*/ WARN_ON_ONCE (ret != -ENOMEM ); -list_for_each_entry (pos,trace_probe_probe_list (tp), list) { - ep = container_of(pos, struct trace_eprobe, tp); +list_for_each_entry (ep,trace_probe_probe_list (tp), tp.list) {disable_eprobe (ep, file->tr);if (!--cnt)break ;@@ -699,7 +697,7 @@ static int enable_trace_eprobe(struct trace_event_call *call,static int disable_trace_eprobe (struct trace_event_call *call,struct trace_event_file *file) { -struct trace_probe *pos, *tp; +struct trace_probe *tp;struct trace_eprobe *ep; tp =trace_probe_primary_from_call (call);@@ -716,8 +714,7 @@ static int disable_trace_eprobe(struct trace_event_call *call,trace_probe_clear_flag (tp,TP_FLAG_PROFILE );if (!trace_probe_is_enabled (tp)) { -list_for_each_entry (pos,trace_probe_probe_list (tp), list) { - ep = container_of(pos, struct trace_eprobe, tp); +list_for_each_entry (ep,trace_probe_probe_list (tp), tp.list) {disable_eprobe (ep, file->tr); } }Signature · 1 line
2.39.2
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
Masami Hiramatsu (Google)
maintainerQuoted 11 lines · On Thu, 10 Aug 2023 19:32:04 +0900 Masami Hiramatsu (Google)…
Quoted 6 lines · On Thu, 10 Aug 2023 16:25:23 +0800 Chuang Wang <[email protected]> wrote:
Refer to the description in [1], we can skip "
container_of()" following "list_for_each_entry()" by using "list_for_each_entry()" with "structtrace_eprobe" and "tp.list".[1] https://lore.kernel.org/all/CAHk-=wjakjw6-rDzDDBsuMoDCqd+9ogifR_EE1F0K-jYek1CdA@mail.gmail.com/
Good point. BTW, it is better to have '
for_each_eprobe(ep)' if it repeats 3 times.
Wait, it is for each trace_eprobe on the trace_probe.
#define for_each_trace_eprobe_on_trace_probe(ep, _tp)
list_for_each_entry(ep, trace_probe_probe_list(_tp), tp.list)
Thank you,
Quoted 72 lines
Quoted 3 lines
Fixes 7491e2c44278 ("tracing: Add a probe that attaches to trace events")This is not a bug, so no need Fixes tag.
Thank you,
Quoted 60 lines
Signed-off-by Chuang Wang <[email protected]>--- kernel/trace/trace_eprobe.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)kernel/trace/trace_eprobe.c +5
-8@@ -640,7 +640,7 @@ static int disable_eprobe(struct trace_eprobe *ep,static int enable_trace_eprobe (struct trace_event_call *call,struct trace_event_file *file) { -struct trace_probe *pos, *tp; +struct trace_probe *tp;struct trace_eprobe *ep;bool enabled;int ret =0 ;@@ -662,8 +662,7 @@ static int enable_trace_eprobe(struct trace_event_call *call,if (enabled)return 0 ; -list_for_each_entry (pos,trace_probe_probe_list (tp), list) { - ep = container_of(pos, struct trace_eprobe, tp); +list_for_each_entry (ep,trace_probe_probe_list (tp), tp.list) { ret =enable_eprobe (ep, file);if (ret)break ;@@ -680,8 +679,7 @@ static int enable_trace_eprobe(struct trace_event_call *call,*/ WARN_ON_ONCE (ret != -ENOMEM ); -list_for_each_entry (pos,trace_probe_probe_list (tp), list) { - ep = container_of(pos, struct trace_eprobe, tp); +list_for_each_entry (ep,trace_probe_probe_list (tp), tp.list) {disable_eprobe (ep, file->tr);if (!--cnt)break ;@@ -699,7 +697,7 @@ static int enable_trace_eprobe(struct trace_event_call *call,static int disable_trace_eprobe (struct trace_event_call *call,struct trace_event_file *file) { -struct trace_probe *pos, *tp; +struct trace_probe *tp;struct trace_eprobe *ep; tp =trace_probe_primary_from_call (call);@@ -716,8 +714,7 @@ static int disable_trace_eprobe(struct trace_event_call *call,trace_probe_clear_flag (tp,TP_FLAG_PROFILE );if (!trace_probe_is_enabled (tp)) { -list_for_each_entry (pos,trace_probe_probe_list (tp), list) { - ep = container_of(pos, struct trace_eprobe, tp); +list_for_each_entry (ep,trace_probe_probe_list (tp), tp.list) {disable_eprobe (ep, file->tr); } }Signature · 1 line
2.39.2Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
Steven Rostedt
maintainerQuoted 13 lines · On Fri, 11 Aug 2023 10:51:02 +0900 Masami Hiramatsu (Google)…
Quoted 10 lines · On Thu, 10 Aug 2023 19:32:04 +0900 Masami Hiramatsu (Google)…
Quoted 6 lines · On Thu, 10 Aug 2023 16:25:23 +0800 Chuang Wang <[email protected]> wrote:
Refer to the description in [1], we can skip "
container_of()" following "list_for_each_entry()" by using "list_for_each_entry()" with "structtrace_eprobe" and "tp.list".[1] https://lore.kernel.org/all/CAHk-=wjakjw6-rDzDDBsuMoDCqd+9ogifR_EE1F0K-jYek1CdA@mail.gmail.com/
Quoted 7 lines
Quoted 1 line
Good point. BTW, it is better to have '
for_each_eprobe(ep)' if it repeats 3 times.Wait, it is for each
trace_eprobeon thetrace_probe.#define
for_each_trace_eprobe_on_trace_probe(ep, _tp)
list_for_each_entry(ep, trace_probe_probe_list(_tp), tp.list)
Do we need it so verbose? Why can't it just be:
#define for_each_trace_eprobe(ep, tp)
If you are worried about consistency with the for_each_trace_kprobe() then let's call it:
#define for_each_trace_point_eprobe(ep, tp);
-- Steve