Commit e161c6bf authored by Jiri Olsa's avatar Jiri Olsa Committed by Steven Rostedt (VMware)

tracing: Iterate trace_[ku]probe objects directly

As suggested by Linus [1] using list_for_each_entry to iterate
directly trace_[ku]probe objects so we can skip another call to
container_of in these loops.

[1] https://lore.kernel.org/r/CAHk-=wjakjw6-rDzDDBsuMoDCqd+9ogifR_EE1F0K-jYek1CdA@mail.gmail.com

Link: https://lkml.kernel.org/r/20211125202852.406405-1-jolsa@kernel.orgSuggested-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
Acked-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
parent ee34c52c
...@@ -327,11 +327,9 @@ static inline int __enable_trace_kprobe(struct trace_kprobe *tk) ...@@ -327,11 +327,9 @@ static inline int __enable_trace_kprobe(struct trace_kprobe *tk)
static void __disable_trace_kprobe(struct trace_probe *tp) static void __disable_trace_kprobe(struct trace_probe *tp)
{ {
struct trace_probe *pos;
struct trace_kprobe *tk; struct trace_kprobe *tk;
list_for_each_entry(pos, trace_probe_probe_list(tp), list) { list_for_each_entry(tk, trace_probe_probe_list(tp), tp.list) {
tk = container_of(pos, struct trace_kprobe, tp);
if (!trace_kprobe_is_registered(tk)) if (!trace_kprobe_is_registered(tk))
continue; continue;
if (trace_kprobe_is_return(tk)) if (trace_kprobe_is_return(tk))
...@@ -348,7 +346,7 @@ static void __disable_trace_kprobe(struct trace_probe *tp) ...@@ -348,7 +346,7 @@ static void __disable_trace_kprobe(struct trace_probe *tp)
static int enable_trace_kprobe(struct trace_event_call *call, static int enable_trace_kprobe(struct trace_event_call *call,
struct trace_event_file *file) struct trace_event_file *file)
{ {
struct trace_probe *pos, *tp; struct trace_probe *tp;
struct trace_kprobe *tk; struct trace_kprobe *tk;
bool enabled; bool enabled;
int ret = 0; int ret = 0;
...@@ -369,8 +367,7 @@ static int enable_trace_kprobe(struct trace_event_call *call, ...@@ -369,8 +367,7 @@ static int enable_trace_kprobe(struct trace_event_call *call,
if (enabled) if (enabled)
return 0; return 0;
list_for_each_entry(pos, trace_probe_probe_list(tp), list) { list_for_each_entry(tk, trace_probe_probe_list(tp), tp.list) {
tk = container_of(pos, struct trace_kprobe, tp);
if (trace_kprobe_has_gone(tk)) if (trace_kprobe_has_gone(tk))
continue; continue;
ret = __enable_trace_kprobe(tk); ret = __enable_trace_kprobe(tk);
...@@ -559,11 +556,9 @@ static bool trace_kprobe_has_same_kprobe(struct trace_kprobe *orig, ...@@ -559,11 +556,9 @@ static bool trace_kprobe_has_same_kprobe(struct trace_kprobe *orig,
struct trace_kprobe *comp) struct trace_kprobe *comp)
{ {
struct trace_probe_event *tpe = orig->tp.event; struct trace_probe_event *tpe = orig->tp.event;
struct trace_probe *pos;
int i; int i;
list_for_each_entry(pos, &tpe->probes, list) { list_for_each_entry(orig, &tpe->probes, tp.list) {
orig = container_of(pos, struct trace_kprobe, tp);
if (strcmp(trace_kprobe_symbol(orig), if (strcmp(trace_kprobe_symbol(orig),
trace_kprobe_symbol(comp)) || trace_kprobe_symbol(comp)) ||
trace_kprobe_offset(orig) != trace_kprobe_offset(comp)) trace_kprobe_offset(orig) != trace_kprobe_offset(comp))
......
...@@ -409,12 +409,10 @@ static bool trace_uprobe_has_same_uprobe(struct trace_uprobe *orig, ...@@ -409,12 +409,10 @@ static bool trace_uprobe_has_same_uprobe(struct trace_uprobe *orig,
struct trace_uprobe *comp) struct trace_uprobe *comp)
{ {
struct trace_probe_event *tpe = orig->tp.event; struct trace_probe_event *tpe = orig->tp.event;
struct trace_probe *pos;
struct inode *comp_inode = d_real_inode(comp->path.dentry); struct inode *comp_inode = d_real_inode(comp->path.dentry);
int i; int i;
list_for_each_entry(pos, &tpe->probes, list) { list_for_each_entry(orig, &tpe->probes, tp.list) {
orig = container_of(pos, struct trace_uprobe, tp);
if (comp_inode != d_real_inode(orig->path.dentry) || if (comp_inode != d_real_inode(orig->path.dentry) ||
comp->offset != orig->offset) comp->offset != orig->offset)
continue; continue;
...@@ -1072,14 +1070,12 @@ static int trace_uprobe_enable(struct trace_uprobe *tu, filter_func_t filter) ...@@ -1072,14 +1070,12 @@ static int trace_uprobe_enable(struct trace_uprobe *tu, filter_func_t filter)
static void __probe_event_disable(struct trace_probe *tp) static void __probe_event_disable(struct trace_probe *tp)
{ {
struct trace_probe *pos;
struct trace_uprobe *tu; struct trace_uprobe *tu;
tu = container_of(tp, struct trace_uprobe, tp); tu = container_of(tp, struct trace_uprobe, tp);
WARN_ON(!uprobe_filter_is_empty(tu->tp.event->filter)); WARN_ON(!uprobe_filter_is_empty(tu->tp.event->filter));
list_for_each_entry(pos, trace_probe_probe_list(tp), list) { list_for_each_entry(tu, trace_probe_probe_list(tp), tp.list) {
tu = container_of(pos, struct trace_uprobe, tp);
if (!tu->inode) if (!tu->inode)
continue; continue;
...@@ -1091,7 +1087,7 @@ static void __probe_event_disable(struct trace_probe *tp) ...@@ -1091,7 +1087,7 @@ static void __probe_event_disable(struct trace_probe *tp)
static int probe_event_enable(struct trace_event_call *call, static int probe_event_enable(struct trace_event_call *call,
struct trace_event_file *file, filter_func_t filter) struct trace_event_file *file, filter_func_t filter)
{ {
struct trace_probe *pos, *tp; struct trace_probe *tp;
struct trace_uprobe *tu; struct trace_uprobe *tu;
bool enabled; bool enabled;
int ret; int ret;
...@@ -1126,8 +1122,7 @@ static int probe_event_enable(struct trace_event_call *call, ...@@ -1126,8 +1122,7 @@ static int probe_event_enable(struct trace_event_call *call,
if (ret) if (ret)
goto err_flags; goto err_flags;
list_for_each_entry(pos, trace_probe_probe_list(tp), list) { list_for_each_entry(tu, trace_probe_probe_list(tp), tp.list) {
tu = container_of(pos, struct trace_uprobe, tp);
ret = trace_uprobe_enable(tu, filter); ret = trace_uprobe_enable(tu, filter);
if (ret) { if (ret) {
__probe_event_disable(tp); __probe_event_disable(tp);
...@@ -1272,7 +1267,7 @@ static bool trace_uprobe_filter_add(struct trace_uprobe_filter *filter, ...@@ -1272,7 +1267,7 @@ static bool trace_uprobe_filter_add(struct trace_uprobe_filter *filter,
static int uprobe_perf_close(struct trace_event_call *call, static int uprobe_perf_close(struct trace_event_call *call,
struct perf_event *event) struct perf_event *event)
{ {
struct trace_probe *pos, *tp; struct trace_probe *tp;
struct trace_uprobe *tu; struct trace_uprobe *tu;
int ret = 0; int ret = 0;
...@@ -1284,8 +1279,7 @@ static int uprobe_perf_close(struct trace_event_call *call, ...@@ -1284,8 +1279,7 @@ static int uprobe_perf_close(struct trace_event_call *call,
if (trace_uprobe_filter_remove(tu->tp.event->filter, event)) if (trace_uprobe_filter_remove(tu->tp.event->filter, event))
return 0; return 0;
list_for_each_entry(pos, trace_probe_probe_list(tp), list) { list_for_each_entry(tu, trace_probe_probe_list(tp), tp.list) {
tu = container_of(pos, struct trace_uprobe, tp);
ret = uprobe_apply(tu->inode, tu->offset, &tu->consumer, false); ret = uprobe_apply(tu->inode, tu->offset, &tu->consumer, false);
if (ret) if (ret)
break; break;
...@@ -1297,7 +1291,7 @@ static int uprobe_perf_close(struct trace_event_call *call, ...@@ -1297,7 +1291,7 @@ static int uprobe_perf_close(struct trace_event_call *call,
static int uprobe_perf_open(struct trace_event_call *call, static int uprobe_perf_open(struct trace_event_call *call,
struct perf_event *event) struct perf_event *event)
{ {
struct trace_probe *pos, *tp; struct trace_probe *tp;
struct trace_uprobe *tu; struct trace_uprobe *tu;
int err = 0; int err = 0;
...@@ -1309,8 +1303,7 @@ static int uprobe_perf_open(struct trace_event_call *call, ...@@ -1309,8 +1303,7 @@ static int uprobe_perf_open(struct trace_event_call *call,
if (trace_uprobe_filter_add(tu->tp.event->filter, event)) if (trace_uprobe_filter_add(tu->tp.event->filter, event))
return 0; return 0;
list_for_each_entry(pos, trace_probe_probe_list(tp), list) { list_for_each_entry(tu, trace_probe_probe_list(tp), tp.list) {
tu = container_of(pos, struct trace_uprobe, tp);
err = uprobe_apply(tu->inode, tu->offset, &tu->consumer, true); err = uprobe_apply(tu->inode, tu->offset, &tu->consumer, true);
if (err) { if (err) {
uprobe_perf_close(call, event); uprobe_perf_close(call, event);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment