Skip to content

Commit edbaaa1

Browse files
author
Sebastian Andrzej Siewior
committed
tracing: Merge irqflags + preemt counter, add RT bits
This is the patch as posted upstream plus - fixed issues which were reported by kernel test robot - added the migrate-disable and lazy-preempt counter which are RT only. PREEMPT_RT never reported "serving softirq". I took a look to see if it could be changed. The tracing infrastructure examinates the preemtion counter for that. PREEMPT_RT does not change the preemption counter while disabling the bottom half or serving the softirqs in order to remain preemptible. The in_serving_softirq() macro and the SOFTIRQ_OFFSET define are still working but not on the preempt-counter. I started to look how to integrate the RT bits regarding softirq. The state of the interrupts (irqflags) and the preemption counter are passed down to tracing_generic_entry_update(). However only one bit of irqflags is actually required: The on/off state. 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 16bit as the preemption counter (considering that 1 must be substracted from the counter in some cases). Whith this change the preemption counter is read in one place and the relevant RT bits for softirq can be set there. The actual preemption value is not used except for the tracing record. The `irqflags' is also not used except for the _irqsave() locking in a few spots. As part of the patch I added __ to trace_event_buffer_commit() while evaluating trace_event_buffer() for the struct trace_event_buffer usage regarding the `pc' and `flags' members. It appears that those two can also be merged into the `trace_ctx' integer. With this change the callchain passes one argument less and evaluates the flags early. A build with all tracers enabled on x86-64 with and without the patch: text data bss dec hex filename 24301717 22148594 13996284 60446595 39a5783 vmlinux.old 24301248 22148850 13996284 60446382 39a56ae vmlinux.new data increased by 256 bytes, text shrank by 469 bytes. Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
1 parent fe22cfc commit edbaaa1

18 files changed

Lines changed: 301 additions & 284 deletions

include/linux/trace_events.h

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,17 +150,31 @@ enum print_line_t {
150150

151151
enum print_line_t trace_handle_return(struct trace_seq *s);
152152

153-
void tracing_generic_entry_update(struct trace_entry *entry,
154-
unsigned short type,
155-
unsigned long flags,
156-
int pc);
153+
static inline void tracing_generic_entry_update(struct trace_entry *entry,
154+
unsigned short type,
155+
unsigned int trace_ctx)
156+
{
157+
struct task_struct *tsk = current;
158+
159+
entry->preempt_count = trace_ctx & 0xff;
160+
entry->migrate_disable = (trace_ctx >> 8) & 0xff;
161+
entry->preempt_lazy_count = (trace_ctx >> 16) & 0xff;
162+
entry->pid = (tsk) ? tsk->pid : 0;
163+
entry->type = type;
164+
entry->flags = trace_ctx >> 24;
165+
}
166+
167+
unsigned int _tracing_gen_ctx_flags(unsigned long irqflags);
168+
unsigned int tracing_gen_ctx_flags(void);
169+
unsigned int tracing_gen_ctx_flags_dect(void);
170+
157171
struct trace_event_file;
158172

159173
struct ring_buffer_event *
160174
trace_event_buffer_lock_reserve(struct trace_buffer **current_buffer,
161175
struct trace_event_file *trace_file,
162176
int type, unsigned long len,
163-
unsigned long flags, int pc);
177+
unsigned int trace_ctx);
164178

165179
#define TRACE_RECORD_CMDLINE BIT(0)
166180
#define TRACE_RECORD_TGID BIT(1)
@@ -234,16 +248,15 @@ struct trace_event_buffer {
234248
struct ring_buffer_event *event;
235249
struct trace_event_file *trace_file;
236250
void *entry;
237-
unsigned long flags;
238-
int pc;
251+
unsigned int trace_ctx;
239252
struct pt_regs *regs;
240253
};
241254

242255
void *trace_event_buffer_reserve(struct trace_event_buffer *fbuffer,
243256
struct trace_event_file *trace_file,
244257
unsigned long len);
245258

246-
void trace_event_buffer_commit(struct trace_event_buffer *fbuffer);
259+
void trace_event_buffer_commit__(struct trace_event_buffer *fbuffer);
247260

248261
enum {
249262
TRACE_EVENT_FL_FILTERED_BIT,

include/trace/trace_events.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ trace_event_raw_event_##call(void *__data, proto) \
694694
\
695695
{ assign; } \
696696
\
697-
trace_event_buffer_commit(&fbuffer); \
697+
trace_event_buffer_commit__(&fbuffer); \
698698
}
699699
/*
700700
* The ftrace_test_probe is compiled out, it is only here as a build time check

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)