History

ring-buffer: Add event descriptor to simplify passing data

Add rb_event_info descriptor to pass event info to functions a bit easier than using a bunch of parameters. This will also allow for changing the code around a bit to find better fast paths.

Steven Rostedt (Red Hat) committed 11 years ago

Commit fcc742e1 parent 5e2d5ef1 file · +52 −39Browse files

Showing the changes to kernel/trace (1 of 1 file). Show all

Unified · Split

kernel/trace/ring_buffer.c+52−39
@@ -399,6 +399,17 @@ struct rb_irq_work { · 398 unmodified lines
399399 bool wakeup_full;
400400 };
401401
402+/*
403+ * Structure to hold event state and handle nested events.
404+ */
405+struct rb_event_info {
406+ u64 ts;
407+ u64 delta;
408+ unsigned long length;
409+ struct buffer_page *tail_page;
410+ int add_timestamp;
411+};
412+
402413 /*
403414 * Used for which event context the event is in.
404415 * NMI = 0
@@ -2000,9 +2011,12 @@ rb_add_time_stamp(struct ring_buffer_event *event, u64 delta) · 1595 unmodified lines
20002011 */
20012012 static void
20022013 rb_update_event(struct ring_buffer_per_cpu *cpu_buffer,
2003− struct ring_buffer_event *event, unsigned length,
2004− int add_timestamp, u64 delta)
2014+ struct ring_buffer_event *event,
2015+ struct rb_event_info *info)
20052016 {
2017+ unsigned length = info->length;
2018+ u64 delta = info->delta;
2019+
20062020 /* Only a commit updates the timestamp */
20072021 if (unlikely(!rb_event_is_commit(cpu_buffer, event)))
20082022 delta = 0;
@@ -2011,7 +2025,7 @@ rb_update_event(struct ring_buffer_per_cpu *cpu_buffer, · 2 unmodified lines
20112025 * If we need to add a timestamp, then we
20122026 * add it to the start of the resevered space.
20132027 */
2014− if (unlikely(add_timestamp)) {
2028+ if (unlikely(info->add_timestamp)) {
20152029 event = rb_add_time_stamp(event, delta);
20162030 length -= RB_LEN_TIME_EXTEND;
20172031 delta = 0;
@@ -2203,10 +2217,11 @@ static unsigned rb_calculate_event_length(unsigned length) · 185 unmodified lines
22032217
22042218 static inline void
22052219 rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
2206− struct buffer_page *tail_page,
2207− unsigned long tail, unsigned long length)
2220+ unsigned long tail, struct rb_event_info *info)
22082221 {
2222+ struct buffer_page *tail_page = info->tail_page;
22092223 struct ring_buffer_event *event;
2224+ unsigned long length = info->length;
22102225
22112226 /*
22122227 * Only the event that crossed the page boundary
@@ -2276,13 +2291,14 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer, · 63 unmodified lines
22762291 */
22772292 static noinline struct ring_buffer_event *
22782293 rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
2279− unsigned long length, unsigned long tail,
2280− struct buffer_page *tail_page, u64 ts)
2294+ unsigned long tail, struct rb_event_info *info)
22812295 {
2296+ struct buffer_page *tail_page = info->tail_page;
22822297 struct buffer_page *commit_page = cpu_buffer->commit_page;
22832298 struct ring_buffer *buffer = cpu_buffer->buffer;
22842299 struct buffer_page *next_page;
22852300 int ret;
2301+ u64 ts;
22862302
22872303 next_page = tail_page;
22882304
@@ -2368,25 +2384,24 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer, · 79 unmodified lines
23682384
23692385 out_again:
23702386
2371− rb_reset_tail(cpu_buffer, tail_page, tail, length);
2387+ rb_reset_tail(cpu_buffer, tail, info);
23722388
23732389 /* fail and let the caller try again */
23742390 return ERR_PTR(-EAGAIN);
23752391
23762392 out_reset:
23772393 /* reset write */
2378− rb_reset_tail(cpu_buffer, tail_page, tail, length);
2394+ rb_reset_tail(cpu_buffer, tail, info);
23792395
23802396 return NULL;
23812397 }
23822398
23832399 static struct ring_buffer_event *
23842400 __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
2385− unsigned long length, u64 ts,
2386− u64 delta, int add_timestamp)
2401+ struct rb_event_info *info)
23872402 {
2388− struct buffer_page *tail_page;
23892403 struct ring_buffer_event *event;
2404+ struct buffer_page *tail_page;
23902405 unsigned long tail, write;
23912406
23922407 /*
@@ -2394,33 +2409,32 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer, · 1 unmodified line
23942409 * hold in the time field of the event, then we append a
23952410 * TIME EXTEND event ahead of the data event.
23962411 */
2397− if (unlikely(add_timestamp))
2398− length += RB_LEN_TIME_EXTEND;
2412+ if (unlikely(info->add_timestamp))
2413+ info->length += RB_LEN_TIME_EXTEND;
23992414
2400− tail_page = cpu_buffer->tail_page;
2401− write = local_add_return(length, &tail_page->write);
2415+ tail_page = info->tail_page = cpu_buffer->tail_page;
2416+ write = local_add_return(info->length, &tail_page->write);
24022417
24032418 /* set write to only the index of the write */
24042419 write &= RB_WRITE_MASK;
2405− tail = write - length;
2420+ tail = write - info->length;
24062421
24072422 /*
24082423 * If this is the first commit on the page, then it has the same
24092424 * timestamp as the page itself.
24102425 */
24112426 if (!tail)
2412− delta = 0;
2427+ info->delta = 0;
24132428
24142429 /* See if we shot pass the end of this buffer page */
24152430 if (unlikely(write > BUF_PAGE_SIZE))
2416− return rb_move_tail(cpu_buffer, length, tail,
2417− tail_page, ts);
2431+ return rb_move_tail(cpu_buffer, tail, info);
24182432
24192433 /* We reserved something on the buffer */
24202434
24212435 event = __rb_page_index(tail_page, tail);
24222436 kmemcheck_annotate_bitfield(event, bitfield);
2423− rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
2437+ rb_update_event(cpu_buffer, event, info);
24242438
24252439 local_inc(&tail_page->entries);
24262440
@@ -2429,10 +2443,10 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer, · 2 unmodified lines
24292443 * its timestamp.
24302444 */
24312445 if (!tail)
2432− tail_page->page->time_stamp = ts;
2446+ tail_page->page->time_stamp = info->ts;
24332447
24342448 /* account for these added bytes */
2435− local_add(length, &cpu_buffer->entries_bytes);
2449+ local_add(info->length, &cpu_buffer->entries_bytes);
24362450
24372451 return event;
24382452 }
@@ -2521,9 +2535,8 @@ rb_reserve_next_event(struct ring_buffer *buffer, · 82 unmodified lines
25212535 unsigned long length)
25222536 {
25232537 struct ring_buffer_event *event;
2524− u64 ts, delta;
2538+ struct rb_event_info info;
25252539 int nr_loops = 0;
2526− int add_timestamp;
25272540 u64 diff;
25282541
25292542 rb_start_commit(cpu_buffer);
@@ -2543,10 +2556,10 @@ rb_reserve_next_event(struct ring_buffer *buffer, · 13 unmodified lines
25432556 }
25442557 #endif
25452558
2546− length = rb_calculate_event_length(length);
2559+ info.length = rb_calculate_event_length(length);
25472560 again:
2548− add_timestamp = 0;
2549− delta = 0;
2561+ info.add_timestamp = 0;
2562+ info.delta = 0;
25502563
25512564 /*
25522565 * We allow for interrupts to reenter here and do a trace.
@@ -2560,35 +2573,35 @@ rb_reserve_next_event(struct ring_buffer *buffer, · 7 unmodified lines
25602573 if (RB_WARN_ON(cpu_buffer, ++nr_loops > 1000))
25612574 goto out_fail;
25622575
2563− ts = rb_time_stamp(cpu_buffer->buffer);
2564− diff = ts - cpu_buffer->write_stamp;
2576+ info.ts = rb_time_stamp(cpu_buffer->buffer);
2577+ diff = info.ts - cpu_buffer->write_stamp;
25652578
25662579 /* make sure this diff is calculated here */
25672580 barrier();
25682581
25692582 /* Did the write stamp get updated already? */
2570− if (likely(ts >= cpu_buffer->write_stamp)) {
2571− delta = diff;
2572− if (unlikely(test_time_stamp(delta))) {
2583+ if (likely(info.ts >= cpu_buffer->write_stamp)) {
2584+ info.delta = diff;
2585+ if (unlikely(test_time_stamp(info.delta))) {
25732586 int local_clock_stable = 1;
25742587 #ifdef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
25752588 local_clock_stable = sched_clock_stable();
25762589 #endif
2577− WARN_ONCE(delta > (1ULL << 59),
2590+ WARN_ONCE(info.delta > (1ULL << 59),
25782591 KERN_WARNING "Delta way too big! %llu ts=%llu write stamp = %llu\n%s",
2579− (unsigned long long)delta,
2580− (unsigned long long)ts,
2592+ (unsigned long long)info.delta,
2593+ (unsigned long long)info.ts,
25812594 (unsigned long long)cpu_buffer->write_stamp,
25822595 local_clock_stable ? "" :
25832596 "If you just came from a suspend/resume,\n"
25842597 "please switch to the trace global clock:\n"
25852598 " echo global > /sys/kernel/debug/tracing/trace_clock\n");
2586− add_timestamp = 1;
2599+ info.add_timestamp = 1;
25872600 }
25882601 }
25892602
2590− event = __rb_reserve_next(cpu_buffer, length, ts,
2591− delta, add_timestamp);
2603+ event = __rb_reserve_next(cpu_buffer, &info);
2604+
25922605 if (unlikely(PTR_ERR(event) == -EAGAIN))
25932606 goto again;
25942607