Skip to content

Commit b61edd5

Browse files
committed
eprobes: Remove redundant event type information
Currently, the event probes save the type of the event they are attached to when recording the event. For example: # echo 'e:switch sched/sched_switch prev_state=$prev_state prev_prio=$prev_prio next_pid=$next_pid next_prio=$next_prio' > dynamic_events # cat events/eprobes/switch/format name: switch ID: 1717 format: field:unsigned short common_type; offset:0; size:2; signed:0; field:unsigned char common_flags; offset:2; size:1; signed:0; field:unsigned char common_preempt_count; offset:3; size:1; signed:0; field:int common_pid; offset:4; size:4; signed:1; field:unsigned int __probe_type; offset:8; size:4; signed:0; field:u64 prev_state; offset:12; size:8; signed:0; field:u64 prev_prio; offset:20; size:8; signed:0; field:u64 next_pid; offset:28; size:8; signed:0; field:u64 next_prio; offset:36; size:8; signed:0; print fmt: "(%u) prev_state=0x%Lx prev_prio=0x%Lx next_pid=0x%Lx next_prio=0x%Lx", REC->__probe_type, REC->prev_state, REC->prev_prio, REC->next_pid, REC->next_prio The __probe_type adds 4 bytes to every event. One of the reasons for creating eprobes is to limit what is traced in an event to be able to limit what is written into the ring buffer. Having this redundant 4 bytes to every event takes away from this. The event that is recorded can be retrieved from the event probe itself, that is available when the trace is happening. For user space tools, it could simply read the dynamic_event file to find the event they are for. So there is really no reason to write this information into the ring buffer for every event. Link: https://lkml.kernel.org/r/20220218190057.2f5a19a8@gandalf.local.home Acked-by: Masami Hiramatsu <mhiramat@kernel.org> Reviewed-by: Joel Fernandes <joel@joelfernandes.org> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent 302e9ed commit b61edd5

4 files changed

Lines changed: 12 additions & 16 deletions

File tree

kernel/trace/trace.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ struct kprobe_trace_entry_head {
136136

137137
struct eprobe_trace_entry_head {
138138
struct trace_entry ent;
139-
unsigned int type;
140139
};
141140

142141
struct kretprobe_trace_entry_head {

kernel/trace/trace_eprobe.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -242,16 +242,13 @@ static int trace_eprobe_tp_arg_update(struct trace_eprobe *ep, int i)
242242

243243
static int eprobe_event_define_fields(struct trace_event_call *event_call)
244244
{
245-
int ret;
246245
struct eprobe_trace_entry_head field;
247246
struct trace_probe *tp;
248247

249248
tp = trace_probe_primary_from_call(event_call);
250249
if (WARN_ON_ONCE(!tp))
251250
return -ENOENT;
252251

253-
DEFINE_FIELD(unsigned int, type, FIELD_STRING_TYPE, 0);
254-
255252
return traceprobe_define_arg_fields(event_call, sizeof(field), tp);
256253
}
257254

@@ -270,23 +267,28 @@ print_eprobe_event(struct trace_iterator *iter, int flags,
270267
struct trace_event_call *pevent;
271268
struct trace_event *probed_event;
272269
struct trace_seq *s = &iter->seq;
270+
struct trace_eprobe *ep;
273271
struct trace_probe *tp;
272+
unsigned int type;
274273

275274
field = (struct eprobe_trace_entry_head *)iter->ent;
276275
tp = trace_probe_primary_from_call(
277276
container_of(event, struct trace_event_call, event));
278277
if (WARN_ON_ONCE(!tp))
279278
goto out;
280279

280+
ep = container_of(tp, struct trace_eprobe, tp);
281+
type = ep->event->event.type;
282+
281283
trace_seq_printf(s, "%s: (", trace_probe_name(tp));
282284

283-
probed_event = ftrace_find_event(field->type);
285+
probed_event = ftrace_find_event(type);
284286
if (probed_event) {
285287
pevent = container_of(probed_event, struct trace_event_call, event);
286288
trace_seq_printf(s, "%s.%s", pevent->class->system,
287289
trace_event_name(pevent));
288290
} else {
289-
trace_seq_printf(s, "%u", field->type);
291+
trace_seq_printf(s, "%u", type);
290292
}
291293

292294
trace_seq_putc(s, ')');
@@ -498,10 +500,6 @@ __eprobe_trace_func(struct eprobe_data *edata, void *rec)
498500
return;
499501

500502
entry = fbuffer.entry = ring_buffer_event_data(fbuffer.event);
501-
if (edata->ep->event)
502-
entry->type = edata->ep->event->event.type;
503-
else
504-
entry->type = 0;
505503
store_trace_args(&entry[1], &edata->ep->tp, rec, sizeof(*entry), dsize);
506504

507505
trace_event_buffer_commit(&fbuffer);

kernel/trace/trace_probe.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -871,15 +871,15 @@ static int __set_print_fmt(struct trace_probe *tp, char *buf, int len,
871871
switch (ptype) {
872872
case PROBE_PRINT_NORMAL:
873873
fmt = "(%lx)";
874-
arg = "REC->" FIELD_STRING_IP;
874+
arg = ", REC->" FIELD_STRING_IP;
875875
break;
876876
case PROBE_PRINT_RETURN:
877877
fmt = "(%lx <- %lx)";
878-
arg = "REC->" FIELD_STRING_FUNC ", REC->" FIELD_STRING_RETIP;
878+
arg = ", REC->" FIELD_STRING_FUNC ", REC->" FIELD_STRING_RETIP;
879879
break;
880880
case PROBE_PRINT_EVENT:
881-
fmt = "(%u)";
882-
arg = "REC->" FIELD_STRING_TYPE;
881+
fmt = "";
882+
arg = "";
883883
break;
884884
default:
885885
WARN_ON_ONCE(1);
@@ -903,7 +903,7 @@ static int __set_print_fmt(struct trace_probe *tp, char *buf, int len,
903903
parg->type->fmt);
904904
}
905905

906-
pos += snprintf(buf + pos, LEN_OR_ZERO, "\", %s", arg);
906+
pos += snprintf(buf + pos, LEN_OR_ZERO, "\"%s", arg);
907907

908908
for (i = 0; i < tp->nr_args; i++) {
909909
parg = tp->args + i;

kernel/trace/trace_probe.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
#define FIELD_STRING_IP "__probe_ip"
3939
#define FIELD_STRING_RETIP "__probe_ret_ip"
4040
#define FIELD_STRING_FUNC "__probe_func"
41-
#define FIELD_STRING_TYPE "__probe_type"
4241

4342
#undef DEFINE_FIELD
4443
#define DEFINE_FIELD(type, item, name, is_signed) \

0 commit comments

Comments
 (0)