Skip to content

Commit 36590c5

Browse files
Sebastian Andrzej Siewiorrostedt
authored andcommitted
tracing: Merge irqflags + preempt counter.
The state of the interrupts (irqflags) and the preemption counter are both passed down to tracing_generic_entry_update(). Only one bit of irqflags is actually required: The on/off state. The complete 32bit of the preemption counter isn't needed. Just whether of the upper bits (softirq, hardirq and NMI) are set and the preemption depth is needed. The irqflags and the preemption counter could be evaluated early and the information stored in an integer `trace_ctx'. tracing_generic_entry_update() would use the upper bits as the TRACE_FLAG_* and the lower 8bit as the disabled-preemption depth (considering that one must be substracted from the counter in one special cases). The actual preemption value is not used except for the tracing record. The `irqflags' variable is mostly used only for the tracing record. An exception here is for instance wakeup_tracer_call() or probe_wakeup_sched_switch() which explicilty disable interrupts and use that `irqflags' to save (and restore) the IRQ state and to record the state. Struct trace_event_buffer has also the `pc' and flags' members which can be replaced with `trace_ctx' since their actual value is not used outside of trace recording. This will reduce tracing_generic_entry_update() to simply assign values to struct trace_entry. The evaluation of the TRACE_FLAG_* bits is moved to _tracing_gen_ctx_flags() which replaces preempt_count() and local_save_flags() invocations. As an example, ftrace_syscall_enter() may invoke: - trace_buffer_lock_reserve() -> … -> tracing_generic_entry_update() - event_trigger_unlock_commit() -> ftrace_trace_stack() -> … -> tracing_generic_entry_update() -> ftrace_trace_userstack() -> … -> tracing_generic_entry_update() In this case the TRACE_FLAG_* bits were evaluated three times. By using the `trace_ctx' they are evaluated once and assigned three times. A build with all tracers enabled on x86-64 with and without the patch: text data bss dec hex filename 21970669 17084168 7639260 46694097 2c87ed1 vmlinux.old 21970293 17084168 7639260 46693721 2c87d59 vmlinux.new text shrank by 379 bytes, data remained constant. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent c6358ba commit 36590c5

17 files changed

+287
-308
lines changed

include/linux/trace_events.h

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,29 @@ enum print_line_t {
148148

149149
enum print_line_t trace_handle_return(struct trace_seq *s);
150150

151-
void tracing_generic_entry_update(struct trace_entry *entry,
152-
unsigned short type,
153-
unsigned long flags,
154-
int pc);
151+
static inline void tracing_generic_entry_update(struct trace_entry *entry,
152+
unsigned short type,
153+
unsigned int trace_ctx)
154+
{
155+
struct task_struct *tsk = current;
156+
157+
entry->preempt_count = trace_ctx & 0xff;
158+
entry->pid = (tsk) ? tsk->pid : 0;
159+
entry->type = type;
160+
entry->flags = trace_ctx >> 16;
161+
}
162+
163+
unsigned int tracing_gen_ctx_flags(unsigned long irqflags);
164+
unsigned int tracing_gen_ctx(void);
165+
unsigned int tracing_gen_ctx_dec(void);
166+
155167
struct trace_event_file;
156168

157169
struct ring_buffer_event *
158170
trace_event_buffer_lock_reserve(struct trace_buffer **current_buffer,
159171
struct trace_event_file *trace_file,
160172
int type, unsigned long len,
161-
unsigned long flags, int pc);
173+
unsigned int trace_ctx);
162174

163175
#define TRACE_RECORD_CMDLINE BIT(0)
164176
#define TRACE_RECORD_TGID BIT(1)
@@ -232,8 +244,7 @@ struct trace_event_buffer {
232244
struct ring_buffer_event *event;
233245
struct trace_event_file *trace_file;
234246
void *entry;
235-
unsigned long flags;
236-
int pc;
247+
unsigned int trace_ctx;
237248
struct pt_regs *regs;
238249
};
239250

kernel/trace/blktrace.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,17 @@ static void trace_note(struct blk_trace *bt, pid_t pid, int action,
7272
struct blk_io_trace *t;
7373
struct ring_buffer_event *event = NULL;
7474
struct trace_buffer *buffer = NULL;
75-
int pc = 0;
75+
unsigned int trace_ctx = 0;
7676
int cpu = smp_processor_id();
7777
bool blk_tracer = blk_tracer_enabled;
7878
ssize_t cgid_len = cgid ? sizeof(cgid) : 0;
7979

8080
if (blk_tracer) {
8181
buffer = blk_tr->array_buffer.buffer;
82-
pc = preempt_count();
82+
trace_ctx = tracing_gen_ctx_flags(0);
8383
event = trace_buffer_lock_reserve(buffer, TRACE_BLK,
8484
sizeof(*t) + len + cgid_len,
85-
0, pc);
85+
trace_ctx);
8686
if (!event)
8787
return;
8888
t = ring_buffer_event_data(event);
@@ -107,7 +107,7 @@ static void trace_note(struct blk_trace *bt, pid_t pid, int action,
107107
memcpy((void *) t + sizeof(*t) + cgid_len, data, len);
108108

109109
if (blk_tracer)
110-
trace_buffer_unlock_commit(blk_tr, buffer, event, 0, pc);
110+
trace_buffer_unlock_commit(blk_tr, buffer, event, trace_ctx);
111111
}
112112
}
113113

@@ -222,8 +222,9 @@ static void __blk_add_trace(struct blk_trace *bt, sector_t sector, int bytes,
222222
struct blk_io_trace *t;
223223
unsigned long flags = 0;
224224
unsigned long *sequence;
225+
unsigned int trace_ctx = 0;
225226
pid_t pid;
226-
int cpu, pc = 0;
227+
int cpu;
227228
bool blk_tracer = blk_tracer_enabled;
228229
ssize_t cgid_len = cgid ? sizeof(cgid) : 0;
229230

@@ -252,10 +253,10 @@ static void __blk_add_trace(struct blk_trace *bt, sector_t sector, int bytes,
252253
tracing_record_cmdline(current);
253254

254255
buffer = blk_tr->array_buffer.buffer;
255-
pc = preempt_count();
256+
trace_ctx = tracing_gen_ctx_flags(0);
256257
event = trace_buffer_lock_reserve(buffer, TRACE_BLK,
257258
sizeof(*t) + pdu_len + cgid_len,
258-
0, pc);
259+
trace_ctx);
259260
if (!event)
260261
return;
261262
t = ring_buffer_event_data(event);
@@ -301,7 +302,7 @@ static void __blk_add_trace(struct blk_trace *bt, sector_t sector, int bytes,
301302
memcpy((void *)t + sizeof(*t) + cgid_len, pdu_data, pdu_len);
302303

303304
if (blk_tracer) {
304-
trace_buffer_unlock_commit(blk_tr, buffer, event, 0, pc);
305+
trace_buffer_unlock_commit(blk_tr, buffer, event, trace_ctx);
305306
return;
306307
}
307308
}

0 commit comments

Comments
 (0)