hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/kernel/trace/ring_buffer.c
....@@ -11,6 +11,7 @@
1111 #include <linux/trace_seq.h>
1212 #include <linux/spinlock.h>
1313 #include <linux/irq_work.h>
14
+#include <linux/security.h>
1415 #include <linux/uaccess.h>
1516 #include <linux/hardirq.h>
1617 #include <linux/kthread.h> /* for self test */
....@@ -201,7 +202,7 @@
201202 case RINGBUF_TYPE_DATA:
202203 return rb_event_data_length(event);
203204 default:
204
- BUG();
205
+ WARN_ON_ONCE(1);
205206 }
206207 /* not hit */
207208 return 0;
....@@ -257,7 +258,7 @@
257258 {
258259 if (extended_time(event))
259260 event = skip_time_extend(event);
260
- BUG_ON(event->type_len > RINGBUF_TYPE_DATA_TYPE_LEN_MAX);
261
+ WARN_ON_ONCE(event->type_len > RINGBUF_TYPE_DATA_TYPE_LEN_MAX);
261262 /* If length is in len field, then array[0] has the data */
262263 if (event->type_len)
263264 return (void *)&event->array[0];
....@@ -277,6 +278,9 @@
277278
278279 #define for_each_buffer_cpu(buffer, cpu) \
279280 for_each_cpu(cpu, buffer->cpumask)
281
+
282
+#define for_each_online_buffer_cpu(buffer, cpu) \
283
+ for_each_cpu_and(cpu, buffer->cpumask, cpu_online_mask)
280284
281285 #define TS_SHIFT 27
282286 #define TS_MASK ((1ULL << TS_SHIFT) - 1)
....@@ -307,8 +311,6 @@
307311 #define RB_MISSED_EVENTS (1 << 31)
308312 /* Missed count stored at end */
309313 #define RB_MISSED_STORED (1 << 30)
310
-
311
-#define RB_MISSED_FLAGS (RB_MISSED_EVENTS|RB_MISSED_STORED)
312314
313315 struct buffer_data_page {
314316 u64 time_stamp; /* page time stamp */
....@@ -351,20 +353,6 @@
351353 static void rb_init_page(struct buffer_data_page *bpage)
352354 {
353355 local_set(&bpage->commit, 0);
354
-}
355
-
356
-/**
357
- * ring_buffer_page_len - the size of data on the page.
358
- * @page: The page to read
359
- *
360
- * Returns the amount of data on the page, including buffer page header.
361
- */
362
-size_t ring_buffer_page_len(void *page)
363
-{
364
- struct buffer_data_page *bpage = page;
365
-
366
- return (local_read(&bpage->commit) & ~RB_MISSED_FLAGS)
367
- + BUF_PAGE_HDR_SIZE;
368356 }
369357
370358 /*
....@@ -426,6 +414,7 @@
426414 struct irq_work work;
427415 wait_queue_head_t waiters;
428416 wait_queue_head_t full_waiters;
417
+ long wait_index;
429418 bool waiters_pending;
430419 bool full_waiters_pending;
431420 bool wakeup_full;
....@@ -437,11 +426,26 @@
437426 struct rb_event_info {
438427 u64 ts;
439428 u64 delta;
429
+ u64 before;
430
+ u64 after;
440431 unsigned long length;
441432 struct buffer_page *tail_page;
442433 int add_timestamp;
443434 };
444435
436
+/*
437
+ * Used for the add_timestamp
438
+ * NONE
439
+ * EXTEND - wants a time extend
440
+ * ABSOLUTE - the buffer requests all events to have absolute time stamps
441
+ * FORCE - force a full time stamp.
442
+ */
443
+enum {
444
+ RB_ADD_STAMP_NONE = 0,
445
+ RB_ADD_STAMP_EXTEND = BIT(1),
446
+ RB_ADD_STAMP_ABSOLUTE = BIT(2),
447
+ RB_ADD_STAMP_FORCE = BIT(3)
448
+};
445449 /*
446450 * Used for which event context the event is in.
447451 * TRANSITION = 0
....@@ -461,13 +465,36 @@
461465 RB_CTX_MAX
462466 };
463467
468
+#if BITS_PER_LONG == 32
469
+#define RB_TIME_32
470
+#endif
471
+
472
+/* To test on 64 bit machines */
473
+//#define RB_TIME_32
474
+
475
+#ifdef RB_TIME_32
476
+
477
+struct rb_time_struct {
478
+ local_t cnt;
479
+ local_t top;
480
+ local_t bottom;
481
+};
482
+#else
483
+#include <asm/local64.h>
484
+struct rb_time_struct {
485
+ local64_t time;
486
+};
487
+#endif
488
+typedef struct rb_time_struct rb_time_t;
489
+
464490 /*
465491 * head_page == tail_page && head == tail then buffer is empty.
466492 */
467493 struct ring_buffer_per_cpu {
468494 int cpu;
469495 atomic_t record_disabled;
470
- struct ring_buffer *buffer;
496
+ atomic_t resize_disabled;
497
+ struct trace_buffer *buffer;
471498 raw_spinlock_t reader_lock; /* serialize readers */
472499 arch_spinlock_t lock;
473500 struct lock_class_key lock_key;
....@@ -489,9 +516,15 @@
489516 local_t dropped_events;
490517 local_t committing;
491518 local_t commits;
519
+ local_t pages_touched;
520
+ local_t pages_lost;
521
+ local_t pages_read;
522
+ long last_pages_touch;
523
+ size_t shortest_full;
492524 unsigned long read;
493525 unsigned long read_bytes;
494
- u64 write_stamp;
526
+ rb_time_t write_stamp;
527
+ rb_time_t before_stamp;
495528 u64 read_stamp;
496529 /* ring buffer pages to update, > 0 to add, < 0 to remove */
497530 long nr_pages_to_update;
....@@ -502,11 +535,10 @@
502535 struct rb_irq_work irq_work;
503536 };
504537
505
-struct ring_buffer {
538
+struct trace_buffer {
506539 unsigned flags;
507540 int cpus;
508541 atomic_t record_disabled;
509
- atomic_t resize_disabled;
510542 cpumask_var_t cpumask;
511543
512544 struct lock_class_key *reader_lock_key;
....@@ -525,11 +557,256 @@
525557 struct ring_buffer_iter {
526558 struct ring_buffer_per_cpu *cpu_buffer;
527559 unsigned long head;
560
+ unsigned long next_event;
528561 struct buffer_page *head_page;
529562 struct buffer_page *cache_reader_page;
530563 unsigned long cache_read;
531564 u64 read_stamp;
565
+ u64 page_stamp;
566
+ struct ring_buffer_event *event;
567
+ int missed_events;
532568 };
569
+
570
+#ifdef RB_TIME_32
571
+
572
+/*
573
+ * On 32 bit machines, local64_t is very expensive. As the ring
574
+ * buffer doesn't need all the features of a true 64 bit atomic,
575
+ * on 32 bit, it uses these functions (64 still uses local64_t).
576
+ *
577
+ * For the ring buffer, 64 bit required operations for the time is
578
+ * the following:
579
+ *
580
+ * - Only need 59 bits (uses 60 to make it even).
581
+ * - Reads may fail if it interrupted a modification of the time stamp.
582
+ * It will succeed if it did not interrupt another write even if
583
+ * the read itself is interrupted by a write.
584
+ * It returns whether it was successful or not.
585
+ *
586
+ * - Writes always succeed and will overwrite other writes and writes
587
+ * that were done by events interrupting the current write.
588
+ *
589
+ * - A write followed by a read of the same time stamp will always succeed,
590
+ * but may not contain the same value.
591
+ *
592
+ * - A cmpxchg will fail if it interrupted another write or cmpxchg.
593
+ * Other than that, it acts like a normal cmpxchg.
594
+ *
595
+ * The 60 bit time stamp is broken up by 30 bits in a top and bottom half
596
+ * (bottom being the least significant 30 bits of the 60 bit time stamp).
597
+ *
598
+ * The two most significant bits of each half holds a 2 bit counter (0-3).
599
+ * Each update will increment this counter by one.
600
+ * When reading the top and bottom, if the two counter bits match then the
601
+ * top and bottom together make a valid 60 bit number.
602
+ */
603
+#define RB_TIME_SHIFT 30
604
+#define RB_TIME_VAL_MASK ((1 << RB_TIME_SHIFT) - 1)
605
+
606
+static inline int rb_time_cnt(unsigned long val)
607
+{
608
+ return (val >> RB_TIME_SHIFT) & 3;
609
+}
610
+
611
+static inline u64 rb_time_val(unsigned long top, unsigned long bottom)
612
+{
613
+ u64 val;
614
+
615
+ val = top & RB_TIME_VAL_MASK;
616
+ val <<= RB_TIME_SHIFT;
617
+ val |= bottom & RB_TIME_VAL_MASK;
618
+
619
+ return val;
620
+}
621
+
622
+static inline bool __rb_time_read(rb_time_t *t, u64 *ret, unsigned long *cnt)
623
+{
624
+ unsigned long top, bottom;
625
+ unsigned long c;
626
+
627
+ /*
628
+ * If the read is interrupted by a write, then the cnt will
629
+ * be different. Loop until both top and bottom have been read
630
+ * without interruption.
631
+ */
632
+ do {
633
+ c = local_read(&t->cnt);
634
+ top = local_read(&t->top);
635
+ bottom = local_read(&t->bottom);
636
+ } while (c != local_read(&t->cnt));
637
+
638
+ *cnt = rb_time_cnt(top);
639
+
640
+ /* If top and bottom counts don't match, this interrupted a write */
641
+ if (*cnt != rb_time_cnt(bottom))
642
+ return false;
643
+
644
+ *ret = rb_time_val(top, bottom);
645
+ return true;
646
+}
647
+
648
+static bool rb_time_read(rb_time_t *t, u64 *ret)
649
+{
650
+ unsigned long cnt;
651
+
652
+ return __rb_time_read(t, ret, &cnt);
653
+}
654
+
655
+static inline unsigned long rb_time_val_cnt(unsigned long val, unsigned long cnt)
656
+{
657
+ return (val & RB_TIME_VAL_MASK) | ((cnt & 3) << RB_TIME_SHIFT);
658
+}
659
+
660
+static inline void rb_time_split(u64 val, unsigned long *top, unsigned long *bottom)
661
+{
662
+ *top = (unsigned long)((val >> RB_TIME_SHIFT) & RB_TIME_VAL_MASK);
663
+ *bottom = (unsigned long)(val & RB_TIME_VAL_MASK);
664
+}
665
+
666
+static inline void rb_time_val_set(local_t *t, unsigned long val, unsigned long cnt)
667
+{
668
+ val = rb_time_val_cnt(val, cnt);
669
+ local_set(t, val);
670
+}
671
+
672
+static void rb_time_set(rb_time_t *t, u64 val)
673
+{
674
+ unsigned long cnt, top, bottom;
675
+
676
+ rb_time_split(val, &top, &bottom);
677
+
678
+ /* Writes always succeed with a valid number even if it gets interrupted. */
679
+ do {
680
+ cnt = local_inc_return(&t->cnt);
681
+ rb_time_val_set(&t->top, top, cnt);
682
+ rb_time_val_set(&t->bottom, bottom, cnt);
683
+ } while (cnt != local_read(&t->cnt));
684
+}
685
+
686
+static inline bool
687
+rb_time_read_cmpxchg(local_t *l, unsigned long expect, unsigned long set)
688
+{
689
+ unsigned long ret;
690
+
691
+ ret = local_cmpxchg(l, expect, set);
692
+ return ret == expect;
693
+}
694
+
695
+static int rb_time_cmpxchg(rb_time_t *t, u64 expect, u64 set)
696
+{
697
+ unsigned long cnt, top, bottom;
698
+ unsigned long cnt2, top2, bottom2;
699
+ u64 val;
700
+
701
+ /* The cmpxchg always fails if it interrupted an update */
702
+ if (!__rb_time_read(t, &val, &cnt2))
703
+ return false;
704
+
705
+ if (val != expect)
706
+ return false;
707
+
708
+ cnt = local_read(&t->cnt);
709
+ if ((cnt & 3) != cnt2)
710
+ return false;
711
+
712
+ cnt2 = cnt + 1;
713
+
714
+ rb_time_split(val, &top, &bottom);
715
+ top = rb_time_val_cnt(top, cnt);
716
+ bottom = rb_time_val_cnt(bottom, cnt);
717
+
718
+ rb_time_split(set, &top2, &bottom2);
719
+ top2 = rb_time_val_cnt(top2, cnt2);
720
+ bottom2 = rb_time_val_cnt(bottom2, cnt2);
721
+
722
+ if (!rb_time_read_cmpxchg(&t->cnt, cnt, cnt2))
723
+ return false;
724
+ if (!rb_time_read_cmpxchg(&t->top, top, top2))
725
+ return false;
726
+ if (!rb_time_read_cmpxchg(&t->bottom, bottom, bottom2))
727
+ return false;
728
+ return true;
729
+}
730
+
731
+#else /* 64 bits */
732
+
733
+/* local64_t always succeeds */
734
+
735
+static inline bool rb_time_read(rb_time_t *t, u64 *ret)
736
+{
737
+ *ret = local64_read(&t->time);
738
+ return true;
739
+}
740
+static void rb_time_set(rb_time_t *t, u64 val)
741
+{
742
+ local64_set(&t->time, val);
743
+}
744
+
745
+static bool rb_time_cmpxchg(rb_time_t *t, u64 expect, u64 set)
746
+{
747
+ u64 val;
748
+ val = local64_cmpxchg(&t->time, expect, set);
749
+ return val == expect;
750
+}
751
+#endif
752
+
753
+/**
754
+ * ring_buffer_nr_pages - get the number of buffer pages in the ring buffer
755
+ * @buffer: The ring_buffer to get the number of pages from
756
+ * @cpu: The cpu of the ring_buffer to get the number of pages from
757
+ *
758
+ * Returns the number of pages used by a per_cpu buffer of the ring buffer.
759
+ */
760
+size_t ring_buffer_nr_pages(struct trace_buffer *buffer, int cpu)
761
+{
762
+ return buffer->buffers[cpu]->nr_pages;
763
+}
764
+
765
+/**
766
+ * ring_buffer_nr_pages_dirty - get the number of used pages in the ring buffer
767
+ * @buffer: The ring_buffer to get the number of pages from
768
+ * @cpu: The cpu of the ring_buffer to get the number of pages from
769
+ *
770
+ * Returns the number of pages that have content in the ring buffer.
771
+ */
772
+size_t ring_buffer_nr_dirty_pages(struct trace_buffer *buffer, int cpu)
773
+{
774
+ size_t read;
775
+ size_t lost;
776
+ size_t cnt;
777
+
778
+ read = local_read(&buffer->buffers[cpu]->pages_read);
779
+ lost = local_read(&buffer->buffers[cpu]->pages_lost);
780
+ cnt = local_read(&buffer->buffers[cpu]->pages_touched);
781
+
782
+ if (WARN_ON_ONCE(cnt < lost))
783
+ return 0;
784
+
785
+ cnt -= lost;
786
+
787
+ /* The reader can read an empty page, but not more than that */
788
+ if (cnt < read) {
789
+ WARN_ON_ONCE(read > cnt + 1);
790
+ return 0;
791
+ }
792
+
793
+ return cnt - read;
794
+}
795
+
796
+static __always_inline bool full_hit(struct trace_buffer *buffer, int cpu, int full)
797
+{
798
+ struct ring_buffer_per_cpu *cpu_buffer = buffer->buffers[cpu];
799
+ size_t nr_pages;
800
+ size_t dirty;
801
+
802
+ nr_pages = cpu_buffer->nr_pages;
803
+ if (!nr_pages || !full)
804
+ return true;
805
+
806
+ dirty = ring_buffer_nr_dirty_pages(buffer, cpu);
807
+
808
+ return (dirty * 100) > (full * nr_pages);
809
+}
533810
534811 /*
535812 * rb_wake_up_waiters - wake up tasks waiting for ring buffer input
....@@ -542,27 +819,60 @@
542819 struct rb_irq_work *rbwork = container_of(work, struct rb_irq_work, work);
543820
544821 wake_up_all(&rbwork->waiters);
545
- if (rbwork->wakeup_full) {
822
+ if (rbwork->full_waiters_pending || rbwork->wakeup_full) {
546823 rbwork->wakeup_full = false;
824
+ rbwork->full_waiters_pending = false;
547825 wake_up_all(&rbwork->full_waiters);
548826 }
827
+}
828
+
829
+/**
830
+ * ring_buffer_wake_waiters - wake up any waiters on this ring buffer
831
+ * @buffer: The ring buffer to wake waiters on
832
+ *
833
+ * In the case of a file that represents a ring buffer is closing,
834
+ * it is prudent to wake up any waiters that are on this.
835
+ */
836
+void ring_buffer_wake_waiters(struct trace_buffer *buffer, int cpu)
837
+{
838
+ struct ring_buffer_per_cpu *cpu_buffer;
839
+ struct rb_irq_work *rbwork;
840
+
841
+ if (cpu == RING_BUFFER_ALL_CPUS) {
842
+
843
+ /* Wake up individual ones too. One level recursion */
844
+ for_each_buffer_cpu(buffer, cpu)
845
+ ring_buffer_wake_waiters(buffer, cpu);
846
+
847
+ rbwork = &buffer->irq_work;
848
+ } else {
849
+ cpu_buffer = buffer->buffers[cpu];
850
+ rbwork = &cpu_buffer->irq_work;
851
+ }
852
+
853
+ rbwork->wait_index++;
854
+ /* make sure the waiters see the new index */
855
+ smp_wmb();
856
+
857
+ rb_wake_up_waiters(&rbwork->work);
549858 }
550859
551860 /**
552861 * ring_buffer_wait - wait for input to the ring buffer
553862 * @buffer: buffer to wait on
554863 * @cpu: the cpu buffer to wait on
555
- * @full: wait until a full page is available, if @cpu != RING_BUFFER_ALL_CPUS
864
+ * @full: wait until the percentage of pages are available, if @cpu != RING_BUFFER_ALL_CPUS
556865 *
557866 * If @cpu == RING_BUFFER_ALL_CPUS then the task will wake up as soon
558867 * as data is added to any of the @buffer's cpu buffers. Otherwise
559868 * it will wait for data to be added to a specific cpu buffer.
560869 */
561
-int ring_buffer_wait(struct ring_buffer *buffer, int cpu, bool full)
870
+int ring_buffer_wait(struct trace_buffer *buffer, int cpu, int full)
562871 {
563
- struct ring_buffer_per_cpu *uninitialized_var(cpu_buffer);
872
+ struct ring_buffer_per_cpu *cpu_buffer;
564873 DEFINE_WAIT(wait);
565874 struct rb_irq_work *work;
875
+ long wait_index;
566876 int ret = 0;
567877
568878 /*
....@@ -573,7 +883,7 @@
573883 if (cpu == RING_BUFFER_ALL_CPUS) {
574884 work = &buffer->irq_work;
575885 /* Full only makes sense on per cpu reads */
576
- full = false;
886
+ full = 0;
577887 } else {
578888 if (!cpumask_test_cpu(cpu, buffer->cpumask))
579889 return -ENODEV;
....@@ -581,6 +891,7 @@
581891 work = &cpu_buffer->irq_work;
582892 }
583893
894
+ wait_index = READ_ONCE(work->wait_index);
584895
585896 while (true) {
586897 if (full)
....@@ -625,19 +936,29 @@
625936 !ring_buffer_empty_cpu(buffer, cpu)) {
626937 unsigned long flags;
627938 bool pagebusy;
939
+ bool done;
628940
629941 if (!full)
630942 break;
631943
632944 raw_spin_lock_irqsave(&cpu_buffer->reader_lock, flags);
633945 pagebusy = cpu_buffer->reader_page == cpu_buffer->commit_page;
634
- raw_spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags);
946
+ done = !pagebusy && full_hit(buffer, cpu, full);
635947
636
- if (!pagebusy)
948
+ if (!cpu_buffer->shortest_full ||
949
+ cpu_buffer->shortest_full > full)
950
+ cpu_buffer->shortest_full = full;
951
+ raw_spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags);
952
+ if (done)
637953 break;
638954 }
639955
640956 schedule();
957
+
958
+ /* Make sure to see the new wait index */
959
+ smp_rmb();
960
+ if (wait_index != work->wait_index)
961
+ break;
641962 }
642963
643964 if (full)
....@@ -654,6 +975,7 @@
654975 * @cpu: the cpu buffer to wait on
655976 * @filp: the file descriptor
656977 * @poll_table: The poll descriptor
978
+ * @full: wait until the percentage of pages are available, if @cpu != RING_BUFFER_ALL_CPUS
657979 *
658980 * If @cpu == RING_BUFFER_ALL_CPUS then the task will wake up as soon
659981 * as data is added to any of the @buffer's cpu buffers. Otherwise
....@@ -662,15 +984,16 @@
662984 * Returns EPOLLIN | EPOLLRDNORM if data exists in the buffers,
663985 * zero otherwise.
664986 */
665
-__poll_t ring_buffer_poll_wait(struct ring_buffer *buffer, int cpu,
666
- struct file *filp, poll_table *poll_table)
987
+__poll_t ring_buffer_poll_wait(struct trace_buffer *buffer, int cpu,
988
+ struct file *filp, poll_table *poll_table, int full)
667989 {
668990 struct ring_buffer_per_cpu *cpu_buffer;
669991 struct rb_irq_work *work;
670992
671
- if (cpu == RING_BUFFER_ALL_CPUS)
993
+ if (cpu == RING_BUFFER_ALL_CPUS) {
672994 work = &buffer->irq_work;
673
- else {
995
+ full = 0;
996
+ } else {
674997 if (!cpumask_test_cpu(cpu, buffer->cpumask))
675998 return -EINVAL;
676999
....@@ -678,8 +1001,14 @@
6781001 work = &cpu_buffer->irq_work;
6791002 }
6801003
681
- poll_wait(filp, &work->waiters, poll_table);
682
- work->waiters_pending = true;
1004
+ if (full) {
1005
+ poll_wait(filp, &work->full_waiters, poll_table);
1006
+ work->full_waiters_pending = true;
1007
+ } else {
1008
+ poll_wait(filp, &work->waiters, poll_table);
1009
+ work->waiters_pending = true;
1010
+ }
1011
+
6831012 /*
6841013 * There's a tight race between setting the waiters_pending and
6851014 * checking if the ring buffer is empty. Once the waiters_pending bit
....@@ -694,6 +1023,9 @@
6941023 * will fix it later.
6951024 */
6961025 smp_mb();
1026
+
1027
+ if (full)
1028
+ return full_hit(buffer, cpu, full) ? EPOLLIN | EPOLLRDNORM : 0;
6971029
6981030 if ((cpu == RING_BUFFER_ALL_CPUS && !ring_buffer_empty(buffer)) ||
6991031 (cpu != RING_BUFFER_ALL_CPUS && !ring_buffer_empty_cpu(buffer, cpu)))
....@@ -720,13 +1052,21 @@
7201052 /* Up this if you want to test the TIME_EXTENTS and normalization */
7211053 #define DEBUG_SHIFT 0
7221054
723
-static inline u64 rb_time_stamp(struct ring_buffer *buffer)
1055
+static inline u64 rb_time_stamp(struct trace_buffer *buffer)
7241056 {
1057
+ u64 ts;
1058
+
1059
+ /* Skip retpolines :-( */
1060
+ if (IS_ENABLED(CONFIG_RETPOLINE) && likely(buffer->clock == trace_clock_local))
1061
+ ts = trace_clock_local();
1062
+ else
1063
+ ts = buffer->clock();
1064
+
7251065 /* shift to debug/test normalization and TIME_EXTENTS */
726
- return buffer->clock() << DEBUG_SHIFT;
1066
+ return ts << DEBUG_SHIFT;
7271067 }
7281068
729
-u64 ring_buffer_time_stamp(struct ring_buffer *buffer, int cpu)
1069
+u64 ring_buffer_time_stamp(struct trace_buffer *buffer, int cpu)
7301070 {
7311071 u64 time;
7321072
....@@ -738,7 +1078,7 @@
7381078 }
7391079 EXPORT_SYMBOL_GPL(ring_buffer_time_stamp);
7401080
741
-void ring_buffer_normalize_time_stamp(struct ring_buffer *buffer,
1081
+void ring_buffer_normalize_time_stamp(struct trace_buffer *buffer,
7421082 int cpu, u64 *ts)
7431083 {
7441084 /* Just stupid testing the normalize function and deltas */
....@@ -1056,6 +1396,7 @@
10561396 old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
10571397 old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
10581398
1399
+ local_inc(&cpu_buffer->pages_touched);
10591400 /*
10601401 * Just make sure we have seen our old_write and synchronize
10611402 * with any interrupts that come in.
....@@ -1260,7 +1601,7 @@
12601601 }
12611602
12621603 static struct ring_buffer_per_cpu *
1263
-rb_allocate_cpu_buffer(struct ring_buffer *buffer, long nr_pages, int cpu)
1604
+rb_allocate_cpu_buffer(struct trace_buffer *buffer, long nr_pages, int cpu)
12641605 {
12651606 struct ring_buffer_per_cpu *cpu_buffer;
12661607 struct buffer_page *bpage;
....@@ -1327,9 +1668,9 @@
13271668
13281669 free_buffer_page(cpu_buffer->reader_page);
13291670
1330
- rb_head_page_deactivate(cpu_buffer);
1331
-
13321671 if (head) {
1672
+ rb_head_page_deactivate(cpu_buffer);
1673
+
13331674 list_for_each_entry_safe(bpage, tmp, head, list) {
13341675 list_del_init(&bpage->list);
13351676 free_buffer_page(bpage);
....@@ -1345,16 +1686,17 @@
13451686 * __ring_buffer_alloc - allocate a new ring_buffer
13461687 * @size: the size in bytes per cpu that is needed.
13471688 * @flags: attributes to set for the ring buffer.
1689
+ * @key: ring buffer reader_lock_key.
13481690 *
13491691 * Currently the only flag that is available is the RB_FL_OVERWRITE
13501692 * flag. This flag means that the buffer will overwrite old data
13511693 * when the buffer wraps. If this flag is not set, the buffer will
13521694 * drop data when the tail hits the head.
13531695 */
1354
-struct ring_buffer *__ring_buffer_alloc(unsigned long size, unsigned flags,
1696
+struct trace_buffer *__ring_buffer_alloc(unsigned long size, unsigned flags,
13551697 struct lock_class_key *key)
13561698 {
1357
- struct ring_buffer *buffer;
1699
+ struct trace_buffer *buffer;
13581700 long nr_pages;
13591701 int bsize;
13601702 int cpu;
....@@ -1424,7 +1766,7 @@
14241766 * @buffer: the buffer to free.
14251767 */
14261768 void
1427
-ring_buffer_free(struct ring_buffer *buffer)
1769
+ring_buffer_free(struct trace_buffer *buffer)
14281770 {
14291771 int cpu;
14301772
....@@ -1440,18 +1782,18 @@
14401782 }
14411783 EXPORT_SYMBOL_GPL(ring_buffer_free);
14421784
1443
-void ring_buffer_set_clock(struct ring_buffer *buffer,
1785
+void ring_buffer_set_clock(struct trace_buffer *buffer,
14441786 u64 (*clock)(void))
14451787 {
14461788 buffer->clock = clock;
14471789 }
14481790
1449
-void ring_buffer_set_time_stamp_abs(struct ring_buffer *buffer, bool abs)
1791
+void ring_buffer_set_time_stamp_abs(struct trace_buffer *buffer, bool abs)
14501792 {
14511793 buffer->time_stamp_abs = abs;
14521794 }
14531795
1454
-bool ring_buffer_time_stamp_abs(struct ring_buffer *buffer)
1796
+bool ring_buffer_time_stamp_abs(struct trace_buffer *buffer)
14551797 {
14561798 return buffer->time_stamp_abs;
14571799 }
....@@ -1564,6 +1906,7 @@
15641906 */
15651907 local_add(page_entries, &cpu_buffer->overrun);
15661908 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
1909
+ local_inc(&cpu_buffer->pages_lost);
15671910 }
15681911
15691912 /*
....@@ -1689,7 +2032,7 @@
16892032 *
16902033 * Returns 0 on success and < 0 on failure.
16912034 */
1692
-int ring_buffer_resize(struct ring_buffer *buffer, unsigned long size,
2035
+int ring_buffer_resize(struct trace_buffer *buffer, unsigned long size,
16932036 int cpu_id)
16942037 {
16952038 struct ring_buffer_per_cpu *cpu_buffer;
....@@ -1715,18 +2058,24 @@
17152058
17162059 size = nr_pages * BUF_PAGE_SIZE;
17172060
1718
- /*
1719
- * Don't succeed if resizing is disabled, as a reader might be
1720
- * manipulating the ring buffer and is expecting a sane state while
1721
- * this is true.
1722
- */
1723
- if (atomic_read(&buffer->resize_disabled))
1724
- return -EBUSY;
1725
-
17262061 /* prevent another thread from changing buffer sizes */
17272062 mutex_lock(&buffer->mutex);
17282063
2064
+
17292065 if (cpu_id == RING_BUFFER_ALL_CPUS) {
2066
+ /*
2067
+ * Don't succeed if resizing is disabled, as a reader might be
2068
+ * manipulating the ring buffer and is expecting a sane state while
2069
+ * this is true.
2070
+ */
2071
+ for_each_buffer_cpu(buffer, cpu) {
2072
+ cpu_buffer = buffer->buffers[cpu];
2073
+ if (atomic_read(&cpu_buffer->resize_disabled)) {
2074
+ err = -EBUSY;
2075
+ goto out_err_unlock;
2076
+ }
2077
+ }
2078
+
17302079 /* calculate the pages to update */
17312080 for_each_buffer_cpu(buffer, cpu) {
17322081 cpu_buffer = buffer->buffers[cpu];
....@@ -1794,6 +2143,16 @@
17942143 if (nr_pages == cpu_buffer->nr_pages)
17952144 goto out;
17962145
2146
+ /*
2147
+ * Don't succeed if resizing is disabled, as a reader might be
2148
+ * manipulating the ring buffer and is expecting a sane state while
2149
+ * this is true.
2150
+ */
2151
+ if (atomic_read(&cpu_buffer->resize_disabled)) {
2152
+ err = -EBUSY;
2153
+ goto out_err_unlock;
2154
+ }
2155
+
17972156 cpu_buffer->nr_pages_to_update = nr_pages -
17982157 cpu_buffer->nr_pages;
17992158
....@@ -1836,7 +2195,7 @@
18362195 * There could have been a race between checking
18372196 * record_disable and incrementing it.
18382197 */
1839
- synchronize_sched();
2198
+ synchronize_rcu();
18402199 for_each_buffer_cpu(buffer, cpu) {
18412200 cpu_buffer = buffer->buffers[cpu];
18422201 rb_check_pages(cpu_buffer);
....@@ -1863,12 +2222,13 @@
18632222 free_buffer_page(bpage);
18642223 }
18652224 }
2225
+ out_err_unlock:
18662226 mutex_unlock(&buffer->mutex);
18672227 return err;
18682228 }
18692229 EXPORT_SYMBOL_GPL(ring_buffer_resize);
18702230
1871
-void ring_buffer_change_overwrite(struct ring_buffer *buffer, int val)
2231
+void ring_buffer_change_overwrite(struct trace_buffer *buffer, int val)
18722232 {
18732233 mutex_lock(&buffer->mutex);
18742234 if (val)
....@@ -1891,15 +2251,63 @@
18912251 cpu_buffer->reader_page->read);
18922252 }
18932253
1894
-static __always_inline struct ring_buffer_event *
1895
-rb_iter_head_event(struct ring_buffer_iter *iter)
1896
-{
1897
- return __rb_page_index(iter->head_page, iter->head);
1898
-}
1899
-
19002254 static __always_inline unsigned rb_page_commit(struct buffer_page *bpage)
19012255 {
19022256 return local_read(&bpage->page->commit);
2257
+}
2258
+
2259
+static struct ring_buffer_event *
2260
+rb_iter_head_event(struct ring_buffer_iter *iter)
2261
+{
2262
+ struct ring_buffer_event *event;
2263
+ struct buffer_page *iter_head_page = iter->head_page;
2264
+ unsigned long commit;
2265
+ unsigned length;
2266
+
2267
+ if (iter->head != iter->next_event)
2268
+ return iter->event;
2269
+
2270
+ /*
2271
+ * When the writer goes across pages, it issues a cmpxchg which
2272
+ * is a mb(), which will synchronize with the rmb here.
2273
+ * (see rb_tail_page_update() and __rb_reserve_next())
2274
+ */
2275
+ commit = rb_page_commit(iter_head_page);
2276
+ smp_rmb();
2277
+ event = __rb_page_index(iter_head_page, iter->head);
2278
+ length = rb_event_length(event);
2279
+
2280
+ /*
2281
+ * READ_ONCE() doesn't work on functions and we don't want the
2282
+ * compiler doing any crazy optimizations with length.
2283
+ */
2284
+ barrier();
2285
+
2286
+ if ((iter->head + length) > commit || length > BUF_MAX_DATA_SIZE)
2287
+ /* Writer corrupted the read? */
2288
+ goto reset;
2289
+
2290
+ memcpy(iter->event, event, length);
2291
+ /*
2292
+ * If the page stamp is still the same after this rmb() then the
2293
+ * event was safely copied without the writer entering the page.
2294
+ */
2295
+ smp_rmb();
2296
+
2297
+ /* Make sure the page didn't change since we read this */
2298
+ if (iter->page_stamp != iter_head_page->page->time_stamp ||
2299
+ commit > rb_page_commit(iter_head_page))
2300
+ goto reset;
2301
+
2302
+ iter->next_event = iter->head + length;
2303
+ return iter->event;
2304
+ reset:
2305
+ /* Reset to the beginning */
2306
+ iter->page_stamp = iter->read_stamp = iter->head_page->page->time_stamp;
2307
+ iter->head = 0;
2308
+ iter->next_event = 0;
2309
+ iter->missed_events = 1;
2310
+ return NULL;
19032311 }
19042312
19052313 /* Size is determined by what has been committed */
....@@ -1937,8 +2345,9 @@
19372345 else
19382346 rb_inc_page(cpu_buffer, &iter->head_page);
19392347
1940
- iter->read_stamp = iter->head_page->page->time_stamp;
2348
+ iter->page_stamp = iter->read_stamp = iter->head_page->page->time_stamp;
19412349 iter->head = 0;
2350
+ iter->next_event = 0;
19422351 }
19432352
19442353 /*
....@@ -1988,6 +2397,7 @@
19882397 */
19892398 local_add(entries, &cpu_buffer->overrun);
19902399 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
2400
+ local_inc(&cpu_buffer->pages_lost);
19912401
19922402 /*
19932403 * The entries will be zeroed out when we move the
....@@ -2156,6 +2566,9 @@
21562566 /* Mark the rest of the page with padding */
21572567 rb_event_set_padding(event);
21582568
2569
+ /* Make sure the padding is visible before the write update */
2570
+ smp_wmb();
2571
+
21592572 /* Set the write back to the previous setting */
21602573 local_sub(length, &tail_page->write);
21612574 return;
....@@ -2166,6 +2579,9 @@
21662579 event->type_len = RINGBUF_TYPE_PADDING;
21672580 /* time delta must be non zero */
21682581 event->time_delta = 1;
2582
+
2583
+ /* Make sure the padding is visible before the tail_page->write update */
2584
+ smp_wmb();
21692585
21702586 /* Set write to end of buffer */
21712587 length = (tail + length) - BUF_PAGE_SIZE;
....@@ -2183,7 +2599,7 @@
21832599 {
21842600 struct buffer_page *tail_page = info->tail_page;
21852601 struct buffer_page *commit_page = cpu_buffer->commit_page;
2186
- struct ring_buffer *buffer = cpu_buffer->buffer;
2602
+ struct trace_buffer *buffer = cpu_buffer->buffer;
21872603 struct buffer_page *next_page;
21882604 int ret;
21892605
....@@ -2280,8 +2696,8 @@
22802696 return NULL;
22812697 }
22822698
2283
-/* Slow path, do not inline */
2284
-static noinline struct ring_buffer_event *
2699
+/* Slow path */
2700
+static struct ring_buffer_event *
22852701 rb_add_time_stamp(struct ring_buffer_event *event, u64 delta, bool abs)
22862702 {
22872703 if (abs)
....@@ -2305,13 +2721,73 @@
23052721 static inline bool rb_event_is_commit(struct ring_buffer_per_cpu *cpu_buffer,
23062722 struct ring_buffer_event *event);
23072723
2724
+#ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
2725
+static inline bool sched_clock_stable(void)
2726
+{
2727
+ return true;
2728
+}
2729
+#endif
2730
+
2731
+static void
2732
+rb_check_timestamp(struct ring_buffer_per_cpu *cpu_buffer,
2733
+ struct rb_event_info *info)
2734
+{
2735
+ u64 write_stamp;
2736
+
2737
+ WARN_ONCE(1, "Delta way too big! %llu ts=%llu before=%llu after=%llu write stamp=%llu\n%s",
2738
+ (unsigned long long)info->delta,
2739
+ (unsigned long long)info->ts,
2740
+ (unsigned long long)info->before,
2741
+ (unsigned long long)info->after,
2742
+ (unsigned long long)(rb_time_read(&cpu_buffer->write_stamp, &write_stamp) ? write_stamp : 0),
2743
+ sched_clock_stable() ? "" :
2744
+ "If you just came from a suspend/resume,\n"
2745
+ "please switch to the trace global clock:\n"
2746
+ " echo global > /sys/kernel/debug/tracing/trace_clock\n"
2747
+ "or add trace_clock=global to the kernel command line\n");
2748
+}
2749
+
2750
+static void rb_add_timestamp(struct ring_buffer_per_cpu *cpu_buffer,
2751
+ struct ring_buffer_event **event,
2752
+ struct rb_event_info *info,
2753
+ u64 *delta,
2754
+ unsigned int *length)
2755
+{
2756
+ bool abs = info->add_timestamp &
2757
+ (RB_ADD_STAMP_FORCE | RB_ADD_STAMP_ABSOLUTE);
2758
+
2759
+ if (unlikely(info->delta > (1ULL << 59))) {
2760
+ /* did the clock go backwards */
2761
+ if (info->before == info->after && info->before > info->ts) {
2762
+ /* not interrupted */
2763
+ static int once;
2764
+
2765
+ /*
2766
+ * This is possible with a recalibrating of the TSC.
2767
+ * Do not produce a call stack, but just report it.
2768
+ */
2769
+ if (!once) {
2770
+ once++;
2771
+ pr_warn("Ring buffer clock went backwards: %llu -> %llu\n",
2772
+ info->before, info->ts);
2773
+ }
2774
+ } else
2775
+ rb_check_timestamp(cpu_buffer, info);
2776
+ if (!abs)
2777
+ info->delta = 0;
2778
+ }
2779
+ *event = rb_add_time_stamp(*event, info->delta, abs);
2780
+ *length -= RB_LEN_TIME_EXTEND;
2781
+ *delta = 0;
2782
+}
2783
+
23082784 /**
23092785 * rb_update_event - update event type and data
2786
+ * @cpu_buffer: The per cpu buffer of the @event
23102787 * @event: the event to update
2311
- * @type: the type of event
2312
- * @length: the size of the event field in the ring buffer
2788
+ * @info: The info to update the @event with (contains length and delta)
23132789 *
2314
- * Update the type and data fields of the event. The length
2790
+ * Update the type and data fields of the @event. The length
23152791 * is the actual size that is written to the ring buffer,
23162792 * and with this, we can determine what to place into the
23172793 * data field.
....@@ -2324,21 +2800,12 @@
23242800 unsigned length = info->length;
23252801 u64 delta = info->delta;
23262802
2327
- /* Only a commit updates the timestamp */
2328
- if (unlikely(!rb_event_is_commit(cpu_buffer, event)))
2329
- delta = 0;
2330
-
23312803 /*
23322804 * If we need to add a timestamp, then we
23332805 * add it to the start of the reserved space.
23342806 */
2335
- if (unlikely(info->add_timestamp)) {
2336
- bool abs = ring_buffer_time_stamp_abs(cpu_buffer->buffer);
2337
-
2338
- event = rb_add_time_stamp(event, abs ? info->delta : delta, abs);
2339
- length -= RB_LEN_TIME_EXTEND;
2340
- delta = 0;
2341
- }
2807
+ if (unlikely(info->add_timestamp))
2808
+ rb_add_timestamp(cpu_buffer, &event, info, &delta, &length);
23422809
23432810 event->time_delta = delta;
23442811 length -= RB_EVNT_HDR_SIZE;
....@@ -2381,12 +2848,38 @@
23812848 return length;
23822849 }
23832850
2384
-#ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
2385
-static inline bool sched_clock_stable(void)
2851
+static __always_inline bool
2852
+rb_event_is_commit(struct ring_buffer_per_cpu *cpu_buffer,
2853
+ struct ring_buffer_event *event)
23862854 {
2387
- return true;
2855
+ unsigned long addr = (unsigned long)event;
2856
+ unsigned long index;
2857
+
2858
+ index = rb_event_index(event);
2859
+ addr &= PAGE_MASK;
2860
+
2861
+ return cpu_buffer->commit_page->page == (void *)addr &&
2862
+ rb_commit_index(cpu_buffer) == index;
23882863 }
2389
-#endif
2864
+
2865
+static u64 rb_time_delta(struct ring_buffer_event *event)
2866
+{
2867
+ switch (event->type_len) {
2868
+ case RINGBUF_TYPE_PADDING:
2869
+ return 0;
2870
+
2871
+ case RINGBUF_TYPE_TIME_EXTEND:
2872
+ return ring_buffer_event_time_stamp(event);
2873
+
2874
+ case RINGBUF_TYPE_TIME_STAMP:
2875
+ return 0;
2876
+
2877
+ case RINGBUF_TYPE_DATA:
2878
+ return event->time_delta;
2879
+ default:
2880
+ return 0;
2881
+ }
2882
+}
23902883
23912884 static inline int
23922885 rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
....@@ -2396,6 +2889,8 @@
23962889 struct buffer_page *bpage;
23972890 unsigned long index;
23982891 unsigned long addr;
2892
+ u64 write_stamp;
2893
+ u64 delta;
23992894
24002895 new_index = rb_event_index(event);
24012896 old_index = new_index + rb_event_ts_length(event);
....@@ -2404,10 +2899,43 @@
24042899
24052900 bpage = READ_ONCE(cpu_buffer->tail_page);
24062901
2902
+ delta = rb_time_delta(event);
2903
+
2904
+ if (!rb_time_read(&cpu_buffer->write_stamp, &write_stamp))
2905
+ return 0;
2906
+
2907
+ /* Make sure the write stamp is read before testing the location */
2908
+ barrier();
2909
+
24072910 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
24082911 unsigned long write_mask =
24092912 local_read(&bpage->write) & ~RB_WRITE_MASK;
24102913 unsigned long event_length = rb_event_length(event);
2914
+
2915
+ /* Something came in, can't discard */
2916
+ if (!rb_time_cmpxchg(&cpu_buffer->write_stamp,
2917
+ write_stamp, write_stamp - delta))
2918
+ return 0;
2919
+
2920
+ /*
2921
+ * It's possible that the event time delta is zero
2922
+ * (has the same time stamp as the previous event)
2923
+ * in which case write_stamp and before_stamp could
2924
+ * be the same. In such a case, force before_stamp
2925
+ * to be different than write_stamp. It doesn't
2926
+ * matter what it is, as long as its different.
2927
+ */
2928
+ if (!delta)
2929
+ rb_time_set(&cpu_buffer->before_stamp, 0);
2930
+
2931
+ /*
2932
+ * If an event were to come in now, it would see that the
2933
+ * write_stamp and the before_stamp are different, and assume
2934
+ * that this event just added itself before updating
2935
+ * the write stamp. The interrupting event will fix the
2936
+ * write stamp for us, and use the before stamp as its delta.
2937
+ */
2938
+
24112939 /*
24122940 * This is on the tail page. It is possible that
24132941 * a write could come in and move the tail page
....@@ -2459,10 +2987,6 @@
24592987 local_set(&cpu_buffer->commit_page->page->commit,
24602988 rb_page_write(cpu_buffer->commit_page));
24612989 rb_inc_page(cpu_buffer, &cpu_buffer->commit_page);
2462
- /* Only update the write stamp if the page has an event */
2463
- if (rb_page_write(cpu_buffer->commit_page))
2464
- cpu_buffer->write_stamp =
2465
- cpu_buffer->commit_page->page->time_stamp;
24662990 /* add barrier to keep gcc from optimizing too much */
24672991 barrier();
24682992 }
....@@ -2534,62 +3058,16 @@
25343058 event->time_delta = 1;
25353059 }
25363060
2537
-static __always_inline bool
2538
-rb_event_is_commit(struct ring_buffer_per_cpu *cpu_buffer,
2539
- struct ring_buffer_event *event)
2540
-{
2541
- unsigned long addr = (unsigned long)event;
2542
- unsigned long index;
2543
-
2544
- index = rb_event_index(event);
2545
- addr &= PAGE_MASK;
2546
-
2547
- return cpu_buffer->commit_page->page == (void *)addr &&
2548
- rb_commit_index(cpu_buffer) == index;
2549
-}
2550
-
2551
-static __always_inline void
2552
-rb_update_write_stamp(struct ring_buffer_per_cpu *cpu_buffer,
2553
- struct ring_buffer_event *event)
2554
-{
2555
- u64 delta;
2556
-
2557
- /*
2558
- * The event first in the commit queue updates the
2559
- * time stamp.
2560
- */
2561
- if (rb_event_is_commit(cpu_buffer, event)) {
2562
- /*
2563
- * A commit event that is first on a page
2564
- * updates the write timestamp with the page stamp
2565
- */
2566
- if (!rb_event_index(event))
2567
- cpu_buffer->write_stamp =
2568
- cpu_buffer->commit_page->page->time_stamp;
2569
- else if (event->type_len == RINGBUF_TYPE_TIME_EXTEND) {
2570
- delta = ring_buffer_event_time_stamp(event);
2571
- cpu_buffer->write_stamp += delta;
2572
- } else if (event->type_len == RINGBUF_TYPE_TIME_STAMP) {
2573
- delta = ring_buffer_event_time_stamp(event);
2574
- cpu_buffer->write_stamp = delta;
2575
- } else
2576
- cpu_buffer->write_stamp += event->time_delta;
2577
- }
2578
-}
2579
-
25803061 static void rb_commit(struct ring_buffer_per_cpu *cpu_buffer,
25813062 struct ring_buffer_event *event)
25823063 {
25833064 local_inc(&cpu_buffer->entries);
2584
- rb_update_write_stamp(cpu_buffer, event);
25853065 rb_end_commit(cpu_buffer);
25863066 }
25873067
25883068 static __always_inline void
2589
-rb_wakeups(struct ring_buffer *buffer, struct ring_buffer_per_cpu *cpu_buffer)
3069
+rb_wakeups(struct trace_buffer *buffer, struct ring_buffer_per_cpu *cpu_buffer)
25903070 {
2591
- bool pagebusy;
2592
-
25933071 if (buffer->irq_work.waiters_pending) {
25943072 buffer->irq_work.waiters_pending = false;
25953073 /* irq_work_queue() supplies it's own memory barriers */
....@@ -2602,14 +3080,24 @@
26023080 irq_work_queue(&cpu_buffer->irq_work.work);
26033081 }
26043082
2605
- pagebusy = cpu_buffer->reader_page == cpu_buffer->commit_page;
3083
+ if (cpu_buffer->last_pages_touch == local_read(&cpu_buffer->pages_touched))
3084
+ return;
26063085
2607
- if (!pagebusy && cpu_buffer->irq_work.full_waiters_pending) {
2608
- cpu_buffer->irq_work.wakeup_full = true;
2609
- cpu_buffer->irq_work.full_waiters_pending = false;
2610
- /* irq_work_queue() supplies it's own memory barriers */
2611
- irq_work_queue(&cpu_buffer->irq_work.work);
2612
- }
3086
+ if (cpu_buffer->reader_page == cpu_buffer->commit_page)
3087
+ return;
3088
+
3089
+ if (!cpu_buffer->irq_work.full_waiters_pending)
3090
+ return;
3091
+
3092
+ cpu_buffer->last_pages_touch = local_read(&cpu_buffer->pages_touched);
3093
+
3094
+ if (!full_hit(buffer, cpu_buffer->cpu, cpu_buffer->shortest_full))
3095
+ return;
3096
+
3097
+ cpu_buffer->irq_work.wakeup_full = true;
3098
+ cpu_buffer->irq_work.full_waiters_pending = false;
3099
+ /* irq_work_queue() supplies it's own memory barriers */
3100
+ irq_work_queue(&cpu_buffer->irq_work.work);
26133101 }
26143102
26153103 /*
....@@ -2727,7 +3215,7 @@
27273215 * Call this function before calling another ring_buffer_lock_reserve() and
27283216 * call ring_buffer_nest_end() after the nested ring_buffer_unlock_commit().
27293217 */
2730
-void ring_buffer_nest_start(struct ring_buffer *buffer)
3218
+void ring_buffer_nest_start(struct trace_buffer *buffer)
27313219 {
27323220 struct ring_buffer_per_cpu *cpu_buffer;
27333221 int cpu;
....@@ -2747,7 +3235,7 @@
27473235 * Must be called after ring_buffer_nest_start() and after the
27483236 * ring_buffer_unlock_commit().
27493237 */
2750
-void ring_buffer_nest_end(struct ring_buffer *buffer)
3238
+void ring_buffer_nest_end(struct trace_buffer *buffer)
27513239 {
27523240 struct ring_buffer_per_cpu *cpu_buffer;
27533241 int cpu;
....@@ -2769,7 +3257,7 @@
27693257 *
27703258 * Must be paired with ring_buffer_lock_reserve.
27713259 */
2772
-int ring_buffer_unlock_commit(struct ring_buffer *buffer,
3260
+int ring_buffer_unlock_commit(struct trace_buffer *buffer,
27733261 struct ring_buffer_event *event)
27743262 {
27753263 struct ring_buffer_per_cpu *cpu_buffer;
....@@ -2789,57 +3277,135 @@
27893277 }
27903278 EXPORT_SYMBOL_GPL(ring_buffer_unlock_commit);
27913279
2792
-static noinline void
2793
-rb_handle_timestamp(struct ring_buffer_per_cpu *cpu_buffer,
2794
- struct rb_event_info *info)
2795
-{
2796
- WARN_ONCE(info->delta > (1ULL << 59),
2797
- KERN_WARNING "Delta way too big! %llu ts=%llu write stamp = %llu\n%s",
2798
- (unsigned long long)info->delta,
2799
- (unsigned long long)info->ts,
2800
- (unsigned long long)cpu_buffer->write_stamp,
2801
- sched_clock_stable() ? "" :
2802
- "If you just came from a suspend/resume,\n"
2803
- "please switch to the trace global clock:\n"
2804
- " echo global > /sys/kernel/debug/tracing/trace_clock\n"
2805
- "or add trace_clock=global to the kernel command line\n");
2806
- info->add_timestamp = 1;
2807
-}
2808
-
28093280 static struct ring_buffer_event *
28103281 __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
28113282 struct rb_event_info *info)
28123283 {
28133284 struct ring_buffer_event *event;
28143285 struct buffer_page *tail_page;
2815
- unsigned long tail, write;
2816
-
2817
- /*
2818
- * If the time delta since the last event is too big to
2819
- * hold in the time field of the event, then we append a
2820
- * TIME EXTEND event ahead of the data event.
2821
- */
2822
- if (unlikely(info->add_timestamp))
2823
- info->length += RB_LEN_TIME_EXTEND;
3286
+ unsigned long tail, write, w;
3287
+ bool a_ok;
3288
+ bool b_ok;
28243289
28253290 /* Don't let the compiler play games with cpu_buffer->tail_page */
28263291 tail_page = info->tail_page = READ_ONCE(cpu_buffer->tail_page);
2827
- write = local_add_return(info->length, &tail_page->write);
3292
+
3293
+ /*A*/ w = local_read(&tail_page->write) & RB_WRITE_MASK;
3294
+ barrier();
3295
+ b_ok = rb_time_read(&cpu_buffer->before_stamp, &info->before);
3296
+ a_ok = rb_time_read(&cpu_buffer->write_stamp, &info->after);
3297
+ barrier();
3298
+ info->ts = rb_time_stamp(cpu_buffer->buffer);
3299
+
3300
+ if ((info->add_timestamp & RB_ADD_STAMP_ABSOLUTE)) {
3301
+ info->delta = info->ts;
3302
+ } else {
3303
+ /*
3304
+ * If interrupting an event time update, we may need an
3305
+ * absolute timestamp.
3306
+ * Don't bother if this is the start of a new page (w == 0).
3307
+ */
3308
+ if (unlikely(!a_ok || !b_ok || (info->before != info->after && w))) {
3309
+ info->add_timestamp |= RB_ADD_STAMP_FORCE | RB_ADD_STAMP_EXTEND;
3310
+ info->length += RB_LEN_TIME_EXTEND;
3311
+ } else {
3312
+ info->delta = info->ts - info->after;
3313
+ if (unlikely(test_time_stamp(info->delta))) {
3314
+ info->add_timestamp |= RB_ADD_STAMP_EXTEND;
3315
+ info->length += RB_LEN_TIME_EXTEND;
3316
+ }
3317
+ }
3318
+ }
3319
+
3320
+ /*B*/ rb_time_set(&cpu_buffer->before_stamp, info->ts);
3321
+
3322
+ /*C*/ write = local_add_return(info->length, &tail_page->write);
28283323
28293324 /* set write to only the index of the write */
28303325 write &= RB_WRITE_MASK;
3326
+
28313327 tail = write - info->length;
3328
+
3329
+ /* See if we shot pass the end of this buffer page */
3330
+ if (unlikely(write > BUF_PAGE_SIZE)) {
3331
+ /* before and after may now different, fix it up*/
3332
+ b_ok = rb_time_read(&cpu_buffer->before_stamp, &info->before);
3333
+ a_ok = rb_time_read(&cpu_buffer->write_stamp, &info->after);
3334
+ if (a_ok && b_ok && info->before != info->after)
3335
+ (void)rb_time_cmpxchg(&cpu_buffer->before_stamp,
3336
+ info->before, info->after);
3337
+ return rb_move_tail(cpu_buffer, tail, info);
3338
+ }
3339
+
3340
+ if (likely(tail == w)) {
3341
+ u64 save_before;
3342
+ bool s_ok;
3343
+
3344
+ /* Nothing interrupted us between A and C */
3345
+ /*D*/ rb_time_set(&cpu_buffer->write_stamp, info->ts);
3346
+ barrier();
3347
+ /*E*/ s_ok = rb_time_read(&cpu_buffer->before_stamp, &save_before);
3348
+ RB_WARN_ON(cpu_buffer, !s_ok);
3349
+ if (likely(!(info->add_timestamp &
3350
+ (RB_ADD_STAMP_FORCE | RB_ADD_STAMP_ABSOLUTE))))
3351
+ /* This did not interrupt any time update */
3352
+ info->delta = info->ts - info->after;
3353
+ else
3354
+ /* Just use full timestamp for inerrupting event */
3355
+ info->delta = info->ts;
3356
+ barrier();
3357
+ if (unlikely(info->ts != save_before)) {
3358
+ /* SLOW PATH - Interrupted between C and E */
3359
+
3360
+ a_ok = rb_time_read(&cpu_buffer->write_stamp, &info->after);
3361
+ RB_WARN_ON(cpu_buffer, !a_ok);
3362
+
3363
+ /* Write stamp must only go forward */
3364
+ if (save_before > info->after) {
3365
+ /*
3366
+ * We do not care about the result, only that
3367
+ * it gets updated atomically.
3368
+ */
3369
+ (void)rb_time_cmpxchg(&cpu_buffer->write_stamp,
3370
+ info->after, save_before);
3371
+ }
3372
+ }
3373
+ } else {
3374
+ u64 ts;
3375
+ /* SLOW PATH - Interrupted between A and C */
3376
+ a_ok = rb_time_read(&cpu_buffer->write_stamp, &info->after);
3377
+ /* Was interrupted before here, write_stamp must be valid */
3378
+ RB_WARN_ON(cpu_buffer, !a_ok);
3379
+ ts = rb_time_stamp(cpu_buffer->buffer);
3380
+ barrier();
3381
+ /*E*/ if (write == (local_read(&tail_page->write) & RB_WRITE_MASK) &&
3382
+ info->after < ts &&
3383
+ rb_time_cmpxchg(&cpu_buffer->write_stamp,
3384
+ info->after, ts)) {
3385
+ /* Nothing came after this event between C and E */
3386
+ info->delta = ts - info->after;
3387
+ info->ts = ts;
3388
+ } else {
3389
+ /*
3390
+ * Interrupted beween C and E:
3391
+ * Lost the previous events time stamp. Just set the
3392
+ * delta to zero, and this will be the same time as
3393
+ * the event this event interrupted. And the events that
3394
+ * came after this will still be correct (as they would
3395
+ * have built their delta on the previous event.
3396
+ */
3397
+ info->delta = 0;
3398
+ }
3399
+ info->add_timestamp &= ~RB_ADD_STAMP_FORCE;
3400
+ }
28323401
28333402 /*
28343403 * If this is the first commit on the page, then it has the same
28353404 * timestamp as the page itself.
28363405 */
2837
- if (!tail && !ring_buffer_time_stamp_abs(cpu_buffer->buffer))
3406
+ if (unlikely(!tail && !(info->add_timestamp &
3407
+ (RB_ADD_STAMP_FORCE | RB_ADD_STAMP_ABSOLUTE))))
28383408 info->delta = 0;
2839
-
2840
- /* See if we shot pass the end of this buffer page */
2841
- if (unlikely(write > BUF_PAGE_SIZE))
2842
- return rb_move_tail(cpu_buffer, tail, info);
28433409
28443410 /* We reserved something on the buffer */
28453411
....@@ -2852,7 +3418,7 @@
28523418 * If this is the first commit on the page, then update
28533419 * its timestamp.
28543420 */
2855
- if (!tail)
3421
+ if (unlikely(!tail))
28563422 tail_page->page->time_stamp = info->ts;
28573423
28583424 /* account for these added bytes */
....@@ -2862,16 +3428,17 @@
28623428 }
28633429
28643430 static __always_inline struct ring_buffer_event *
2865
-rb_reserve_next_event(struct ring_buffer *buffer,
3431
+rb_reserve_next_event(struct trace_buffer *buffer,
28663432 struct ring_buffer_per_cpu *cpu_buffer,
28673433 unsigned long length)
28683434 {
28693435 struct ring_buffer_event *event;
28703436 struct rb_event_info info;
28713437 int nr_loops = 0;
2872
- u64 diff;
3438
+ int add_ts_default;
28733439
28743440 rb_start_commit(cpu_buffer);
3441
+ /* The commit page can not change after this */
28753442
28763443 #ifdef CONFIG_RING_BUFFER_ALLOW_SWAP
28773444 /*
....@@ -2889,8 +3456,16 @@
28893456 #endif
28903457
28913458 info.length = rb_calculate_event_length(length);
3459
+
3460
+ if (ring_buffer_time_stamp_abs(cpu_buffer->buffer)) {
3461
+ add_ts_default = RB_ADD_STAMP_ABSOLUTE;
3462
+ info.length += RB_LEN_TIME_EXTEND;
3463
+ } else {
3464
+ add_ts_default = RB_ADD_STAMP_NONE;
3465
+ }
3466
+
28923467 again:
2893
- info.add_timestamp = 0;
3468
+ info.add_timestamp = add_ts_default;
28943469 info.delta = 0;
28953470
28963471 /*
....@@ -2905,35 +3480,16 @@
29053480 if (RB_WARN_ON(cpu_buffer, ++nr_loops > 1000))
29063481 goto out_fail;
29073482
2908
- info.ts = rb_time_stamp(cpu_buffer->buffer);
2909
- diff = info.ts - cpu_buffer->write_stamp;
2910
-
2911
- /* make sure this diff is calculated here */
2912
- barrier();
2913
-
2914
- if (ring_buffer_time_stamp_abs(buffer)) {
2915
- info.delta = info.ts;
2916
- rb_handle_timestamp(cpu_buffer, &info);
2917
- } else /* Did the write stamp get updated already? */
2918
- if (likely(info.ts >= cpu_buffer->write_stamp)) {
2919
- info.delta = diff;
2920
- if (unlikely(test_time_stamp(info.delta)))
2921
- rb_handle_timestamp(cpu_buffer, &info);
2922
- }
2923
-
29243483 event = __rb_reserve_next(cpu_buffer, &info);
29253484
29263485 if (unlikely(PTR_ERR(event) == -EAGAIN)) {
2927
- if (info.add_timestamp)
3486
+ if (info.add_timestamp & (RB_ADD_STAMP_FORCE | RB_ADD_STAMP_EXTEND))
29283487 info.length -= RB_LEN_TIME_EXTEND;
29293488 goto again;
29303489 }
29313490
2932
- if (!event)
2933
- goto out_fail;
2934
-
2935
- return event;
2936
-
3491
+ if (likely(event))
3492
+ return event;
29373493 out_fail:
29383494 rb_end_commit(cpu_buffer);
29393495 return NULL;
....@@ -2955,7 +3511,7 @@
29553511 * If NULL is returned, then nothing has been allocated or locked.
29563512 */
29573513 struct ring_buffer_event *
2958
-ring_buffer_lock_reserve(struct ring_buffer *buffer, unsigned long length)
3514
+ring_buffer_lock_reserve(struct trace_buffer *buffer, unsigned long length)
29593515 {
29603516 struct ring_buffer_per_cpu *cpu_buffer;
29613517 struct ring_buffer_event *event;
....@@ -3056,7 +3612,7 @@
30563612 * If this function is called, do not call ring_buffer_unlock_commit on
30573613 * the event.
30583614 */
3059
-void ring_buffer_discard_commit(struct ring_buffer *buffer,
3615
+void ring_buffer_discard_commit(struct trace_buffer *buffer,
30603616 struct ring_buffer_event *event)
30613617 {
30623618 struct ring_buffer_per_cpu *cpu_buffer;
....@@ -3079,11 +3635,6 @@
30793635 if (rb_try_to_discard(cpu_buffer, event))
30803636 goto out;
30813637
3082
- /*
3083
- * The commit is still visible by the reader, so we
3084
- * must still update the timestamp.
3085
- */
3086
- rb_update_write_stamp(cpu_buffer, event);
30873638 out:
30883639 rb_end_commit(cpu_buffer);
30893640
....@@ -3107,7 +3658,7 @@
31073658 * Note, like ring_buffer_lock_reserve, the length is the length of the data
31083659 * and not the length of the event which would hold the header.
31093660 */
3110
-int ring_buffer_write(struct ring_buffer *buffer,
3661
+int ring_buffer_write(struct trace_buffer *buffer,
31113662 unsigned long length,
31123663 void *data)
31133664 {
....@@ -3205,9 +3756,9 @@
32053756 * This prevents all writes to the buffer. Any attempt to write
32063757 * to the buffer after this will fail and return NULL.
32073758 *
3208
- * The caller should call synchronize_sched() after this.
3759
+ * The caller should call synchronize_rcu() after this.
32093760 */
3210
-void ring_buffer_record_disable(struct ring_buffer *buffer)
3761
+void ring_buffer_record_disable(struct trace_buffer *buffer)
32113762 {
32123763 atomic_inc(&buffer->record_disabled);
32133764 }
....@@ -3220,7 +3771,7 @@
32203771 * Note, multiple disables will need the same number of enables
32213772 * to truly enable the writing (much like preempt_disable).
32223773 */
3223
-void ring_buffer_record_enable(struct ring_buffer *buffer)
3774
+void ring_buffer_record_enable(struct trace_buffer *buffer)
32243775 {
32253776 atomic_dec(&buffer->record_disabled);
32263777 }
....@@ -3237,7 +3788,7 @@
32373788 * it works like an on/off switch, where as the disable() version
32383789 * must be paired with a enable().
32393790 */
3240
-void ring_buffer_record_off(struct ring_buffer *buffer)
3791
+void ring_buffer_record_off(struct trace_buffer *buffer)
32413792 {
32423793 unsigned int rd;
32433794 unsigned int new_rd;
....@@ -3260,7 +3811,7 @@
32603811 * it works like an on/off switch, where as the enable() version
32613812 * must be paired with a disable().
32623813 */
3263
-void ring_buffer_record_on(struct ring_buffer *buffer)
3814
+void ring_buffer_record_on(struct trace_buffer *buffer)
32643815 {
32653816 unsigned int rd;
32663817 unsigned int new_rd;
....@@ -3278,7 +3829,7 @@
32783829 *
32793830 * Returns true if the ring buffer is in a state that it accepts writes.
32803831 */
3281
-bool ring_buffer_record_is_on(struct ring_buffer *buffer)
3832
+bool ring_buffer_record_is_on(struct trace_buffer *buffer)
32823833 {
32833834 return !atomic_read(&buffer->record_disabled);
32843835 }
....@@ -3294,7 +3845,7 @@
32943845 * ring_buffer_record_disable(), as that is a temporary disabling of
32953846 * the ring buffer.
32963847 */
3297
-bool ring_buffer_record_is_set_on(struct ring_buffer *buffer)
3848
+bool ring_buffer_record_is_set_on(struct trace_buffer *buffer)
32983849 {
32993850 return !(atomic_read(&buffer->record_disabled) & RB_BUFFER_OFF);
33003851 }
....@@ -3307,9 +3858,9 @@
33073858 * This prevents all writes to the buffer. Any attempt to write
33083859 * to the buffer after this will fail and return NULL.
33093860 *
3310
- * The caller should call synchronize_sched() after this.
3861
+ * The caller should call synchronize_rcu() after this.
33113862 */
3312
-void ring_buffer_record_disable_cpu(struct ring_buffer *buffer, int cpu)
3863
+void ring_buffer_record_disable_cpu(struct trace_buffer *buffer, int cpu)
33133864 {
33143865 struct ring_buffer_per_cpu *cpu_buffer;
33153866
....@@ -3329,7 +3880,7 @@
33293880 * Note, multiple disables will need the same number of enables
33303881 * to truly enable the writing (much like preempt_disable).
33313882 */
3332
-void ring_buffer_record_enable_cpu(struct ring_buffer *buffer, int cpu)
3883
+void ring_buffer_record_enable_cpu(struct trace_buffer *buffer, int cpu)
33333884 {
33343885 struct ring_buffer_per_cpu *cpu_buffer;
33353886
....@@ -3359,7 +3910,7 @@
33593910 * @buffer: The ring buffer
33603911 * @cpu: The per CPU buffer to read from.
33613912 */
3362
-u64 ring_buffer_oldest_event_ts(struct ring_buffer *buffer, int cpu)
3913
+u64 ring_buffer_oldest_event_ts(struct trace_buffer *buffer, int cpu)
33633914 {
33643915 unsigned long flags;
33653916 struct ring_buffer_per_cpu *cpu_buffer;
....@@ -3392,7 +3943,7 @@
33923943 * @buffer: The ring buffer
33933944 * @cpu: The per CPU buffer to read from.
33943945 */
3395
-unsigned long ring_buffer_bytes_cpu(struct ring_buffer *buffer, int cpu)
3946
+unsigned long ring_buffer_bytes_cpu(struct trace_buffer *buffer, int cpu)
33963947 {
33973948 struct ring_buffer_per_cpu *cpu_buffer;
33983949 unsigned long ret;
....@@ -3412,7 +3963,7 @@
34123963 * @buffer: The ring buffer
34133964 * @cpu: The per CPU buffer to get the entries from.
34143965 */
3415
-unsigned long ring_buffer_entries_cpu(struct ring_buffer *buffer, int cpu)
3966
+unsigned long ring_buffer_entries_cpu(struct trace_buffer *buffer, int cpu)
34163967 {
34173968 struct ring_buffer_per_cpu *cpu_buffer;
34183969
....@@ -3431,7 +3982,7 @@
34313982 * @buffer: The ring buffer
34323983 * @cpu: The per CPU buffer to get the number of overruns from
34333984 */
3434
-unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
3985
+unsigned long ring_buffer_overrun_cpu(struct trace_buffer *buffer, int cpu)
34353986 {
34363987 struct ring_buffer_per_cpu *cpu_buffer;
34373988 unsigned long ret;
....@@ -3454,7 +4005,7 @@
34544005 * @cpu: The per CPU buffer to get the number of overruns from
34554006 */
34564007 unsigned long
3457
-ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
4008
+ring_buffer_commit_overrun_cpu(struct trace_buffer *buffer, int cpu)
34584009 {
34594010 struct ring_buffer_per_cpu *cpu_buffer;
34604011 unsigned long ret;
....@@ -3476,7 +4027,7 @@
34764027 * @cpu: The per CPU buffer to get the number of overruns from
34774028 */
34784029 unsigned long
3479
-ring_buffer_dropped_events_cpu(struct ring_buffer *buffer, int cpu)
4030
+ring_buffer_dropped_events_cpu(struct trace_buffer *buffer, int cpu)
34804031 {
34814032 struct ring_buffer_per_cpu *cpu_buffer;
34824033 unsigned long ret;
....@@ -3497,7 +4048,7 @@
34974048 * @cpu: The per CPU buffer to get the number of events read
34984049 */
34994050 unsigned long
3500
-ring_buffer_read_events_cpu(struct ring_buffer *buffer, int cpu)
4051
+ring_buffer_read_events_cpu(struct trace_buffer *buffer, int cpu)
35014052 {
35024053 struct ring_buffer_per_cpu *cpu_buffer;
35034054
....@@ -3516,7 +4067,7 @@
35164067 * Returns the total number of entries in the ring buffer
35174068 * (all CPU entries)
35184069 */
3519
-unsigned long ring_buffer_entries(struct ring_buffer *buffer)
4070
+unsigned long ring_buffer_entries(struct trace_buffer *buffer)
35204071 {
35214072 struct ring_buffer_per_cpu *cpu_buffer;
35224073 unsigned long entries = 0;
....@@ -3539,7 +4090,7 @@
35394090 * Returns the total number of overruns in the ring buffer
35404091 * (all CPU entries)
35414092 */
3542
-unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
4093
+unsigned long ring_buffer_overruns(struct trace_buffer *buffer)
35434094 {
35444095 struct ring_buffer_per_cpu *cpu_buffer;
35454096 unsigned long overruns = 0;
....@@ -3562,14 +4113,18 @@
35624113 /* Iterator usage is expected to have record disabled */
35634114 iter->head_page = cpu_buffer->reader_page;
35644115 iter->head = cpu_buffer->reader_page->read;
4116
+ iter->next_event = iter->head;
35654117
35664118 iter->cache_reader_page = iter->head_page;
35674119 iter->cache_read = cpu_buffer->read;
35684120
3569
- if (iter->head)
4121
+ if (iter->head) {
35704122 iter->read_stamp = cpu_buffer->read_stamp;
3571
- else
4123
+ iter->page_stamp = cpu_buffer->reader_page->page->time_stamp;
4124
+ } else {
35724125 iter->read_stamp = iter->head_page->page->time_stamp;
4126
+ iter->page_stamp = iter->read_stamp;
4127
+ }
35734128 }
35744129
35754130 /**
....@@ -3605,17 +4160,38 @@
36054160 struct buffer_page *reader;
36064161 struct buffer_page *head_page;
36074162 struct buffer_page *commit_page;
4163
+ struct buffer_page *curr_commit_page;
36084164 unsigned commit;
4165
+ u64 curr_commit_ts;
4166
+ u64 commit_ts;
36094167
36104168 cpu_buffer = iter->cpu_buffer;
3611
-
3612
- /* Remember, trace recording is off when iterator is in use */
36134169 reader = cpu_buffer->reader_page;
36144170 head_page = cpu_buffer->head_page;
36154171 commit_page = cpu_buffer->commit_page;
3616
- commit = rb_page_commit(commit_page);
4172
+ commit_ts = commit_page->page->time_stamp;
36174173
3618
- return ((iter->head_page == commit_page && iter->head == commit) ||
4174
+ /*
4175
+ * When the writer goes across pages, it issues a cmpxchg which
4176
+ * is a mb(), which will synchronize with the rmb here.
4177
+ * (see rb_tail_page_update())
4178
+ */
4179
+ smp_rmb();
4180
+ commit = rb_page_commit(commit_page);
4181
+ /* We want to make sure that the commit page doesn't change */
4182
+ smp_rmb();
4183
+
4184
+ /* Make sure commit page didn't change */
4185
+ curr_commit_page = READ_ONCE(cpu_buffer->commit_page);
4186
+ curr_commit_ts = READ_ONCE(curr_commit_page->page->time_stamp);
4187
+
4188
+ /* If the commit page changed, then there's more data */
4189
+ if (curr_commit_page != commit_page ||
4190
+ curr_commit_ts != commit_ts)
4191
+ return 0;
4192
+
4193
+ /* Still racy, as it may return a false positive, but that's OK */
4194
+ return ((iter->head_page == commit_page && iter->head >= commit) ||
36194195 (iter->head_page == reader && commit_page == head_page &&
36204196 head_page->read == commit &&
36214197 iter->head == rb_page_commit(cpu_buffer->reader_page)));
....@@ -3647,7 +4223,7 @@
36474223 return;
36484224
36494225 default:
3650
- BUG();
4226
+ RB_WARN_ON(cpu_buffer, 1);
36514227 }
36524228 return;
36534229 }
....@@ -3677,7 +4253,7 @@
36774253 return;
36784254
36794255 default:
3680
- BUG();
4256
+ RB_WARN_ON(iter->cpu_buffer, 1);
36814257 }
36824258 return;
36834259 }
....@@ -3786,12 +4362,14 @@
37864362 goto spin;
37874363
37884364 /*
3789
- * Yeah! We succeeded in replacing the page.
4365
+ * Yay! We succeeded in replacing the page.
37904366 *
37914367 * Now make the new head point back to the reader page.
37924368 */
37934369 rb_list_head(reader->list.next)->prev = &cpu_buffer->reader_page->list;
37944370 rb_inc_page(cpu_buffer, &cpu_buffer->head_page);
4371
+
4372
+ local_inc(&cpu_buffer->pages_read);
37954373
37964374 /* Finally update the reader page to the new head */
37974375 cpu_buffer->reader_page = reader;
....@@ -3811,6 +4389,33 @@
38114389
38124390 arch_spin_unlock(&cpu_buffer->lock);
38134391 local_irq_restore(flags);
4392
+
4393
+ /*
4394
+ * The writer has preempt disable, wait for it. But not forever
4395
+ * Although, 1 second is pretty much "forever"
4396
+ */
4397
+#define USECS_WAIT 1000000
4398
+ for (nr_loops = 0; nr_loops < USECS_WAIT; nr_loops++) {
4399
+ /* If the write is past the end of page, a writer is still updating it */
4400
+ if (likely(!reader || rb_page_write(reader) <= BUF_PAGE_SIZE))
4401
+ break;
4402
+
4403
+ udelay(1);
4404
+
4405
+ /* Get the latest version of the reader write value */
4406
+ smp_rmb();
4407
+ }
4408
+
4409
+ /* The writer is not moving forward? Something is wrong */
4410
+ if (RB_WARN_ON(cpu_buffer, nr_loops == USECS_WAIT))
4411
+ reader = NULL;
4412
+
4413
+ /*
4414
+ * Make sure we see any padding after the write update
4415
+ * (see rb_reset_tail())
4416
+ */
4417
+ smp_rmb();
4418
+
38144419
38154420 return reader;
38164421 }
....@@ -3841,15 +4446,22 @@
38414446 static void rb_advance_iter(struct ring_buffer_iter *iter)
38424447 {
38434448 struct ring_buffer_per_cpu *cpu_buffer;
3844
- struct ring_buffer_event *event;
3845
- unsigned length;
38464449
38474450 cpu_buffer = iter->cpu_buffer;
4451
+
4452
+ /* If head == next_event then we need to jump to the next event */
4453
+ if (iter->head == iter->next_event) {
4454
+ /* If the event gets overwritten again, there's nothing to do */
4455
+ if (rb_iter_head_event(iter) == NULL)
4456
+ return;
4457
+ }
4458
+
4459
+ iter->head = iter->next_event;
38484460
38494461 /*
38504462 * Check if we are at the end of the buffer.
38514463 */
3852
- if (iter->head >= rb_page_size(iter->head_page)) {
4464
+ if (iter->next_event >= rb_page_size(iter->head_page)) {
38534465 /* discarded commits can make the page empty */
38544466 if (iter->head_page == cpu_buffer->commit_page)
38554467 return;
....@@ -3857,27 +4469,7 @@
38574469 return;
38584470 }
38594471
3860
- event = rb_iter_head_event(iter);
3861
-
3862
- length = rb_event_length(event);
3863
-
3864
- /*
3865
- * This should not be called to advance the header if we are
3866
- * at the tail of the buffer.
3867
- */
3868
- if (RB_WARN_ON(cpu_buffer,
3869
- (iter->head_page == cpu_buffer->commit_page) &&
3870
- (iter->head + length > rb_commit_index(cpu_buffer))))
3871
- return;
3872
-
3873
- rb_update_iter_read_stamp(iter, event);
3874
-
3875
- iter->head += length;
3876
-
3877
- /* check for end of page padding */
3878
- if ((iter->head >= rb_page_size(iter->head_page)) &&
3879
- (iter->head_page != cpu_buffer->commit_page))
3880
- rb_inc_iter(iter);
4472
+ rb_update_iter_read_stamp(iter, iter->event);
38814473 }
38824474
38834475 static int rb_lost_events(struct ring_buffer_per_cpu *cpu_buffer)
....@@ -3951,7 +4543,7 @@
39514543 return event;
39524544
39534545 default:
3954
- BUG();
4546
+ RB_WARN_ON(cpu_buffer, 1);
39554547 }
39564548
39574549 return NULL;
....@@ -3961,7 +4553,7 @@
39614553 static struct ring_buffer_event *
39624554 rb_iter_peek(struct ring_buffer_iter *iter, u64 *ts)
39634555 {
3964
- struct ring_buffer *buffer;
4556
+ struct trace_buffer *buffer;
39654557 struct ring_buffer_per_cpu *cpu_buffer;
39664558 struct ring_buffer_event *event;
39674559 int nr_loops = 0;
....@@ -3986,14 +4578,13 @@
39864578 return NULL;
39874579
39884580 /*
3989
- * We repeat when a time extend is encountered or we hit
3990
- * the end of the page. Since the time extend is always attached
3991
- * to a data event, we should never loop more than three times.
3992
- * Once for going to next page, once on time extend, and
3993
- * finally once to get the event.
3994
- * (We never hit the following condition more than thrice).
4581
+ * As the writer can mess with what the iterator is trying
4582
+ * to read, just give up if we fail to get an event after
4583
+ * three tries. The iterator is not as reliable when reading
4584
+ * the ring buffer with an active write as the consumer is.
4585
+ * Do not warn if the three failures is reached.
39954586 */
3996
- if (RB_WARN_ON(cpu_buffer, ++nr_loops > 3))
4587
+ if (++nr_loops > 3)
39974588 return NULL;
39984589
39994590 if (rb_per_cpu_empty(cpu_buffer))
....@@ -4005,6 +4596,8 @@
40054596 }
40064597
40074598 event = rb_iter_head_event(iter);
4599
+ if (!event)
4600
+ goto again;
40084601
40094602 switch (event->type_len) {
40104603 case RINGBUF_TYPE_PADDING:
....@@ -4039,7 +4632,7 @@
40394632 return event;
40404633
40414634 default:
4042
- BUG();
4635
+ RB_WARN_ON(cpu_buffer, 1);
40434636 }
40444637
40454638 return NULL;
....@@ -4089,7 +4682,7 @@
40894682 * not consume the data.
40904683 */
40914684 struct ring_buffer_event *
4092
-ring_buffer_peek(struct ring_buffer *buffer, int cpu, u64 *ts,
4685
+ring_buffer_peek(struct trace_buffer *buffer, int cpu, u64 *ts,
40934686 unsigned long *lost_events)
40944687 {
40954688 struct ring_buffer_per_cpu *cpu_buffer = buffer->buffers[cpu];
....@@ -4114,6 +4707,20 @@
41144707
41154708 return event;
41164709 }
4710
+
4711
+/** ring_buffer_iter_dropped - report if there are dropped events
4712
+ * @iter: The ring buffer iterator
4713
+ *
4714
+ * Returns true if there was dropped events since the last peek.
4715
+ */
4716
+bool ring_buffer_iter_dropped(struct ring_buffer_iter *iter)
4717
+{
4718
+ bool ret = iter->missed_events != 0;
4719
+
4720
+ iter->missed_events = 0;
4721
+ return ret;
4722
+}
4723
+EXPORT_SYMBOL_GPL(ring_buffer_iter_dropped);
41174724
41184725 /**
41194726 * ring_buffer_iter_peek - peek at the next event to be read
....@@ -4153,7 +4760,7 @@
41534760 * and eventually empty the ring buffer if the producer is slower.
41544761 */
41554762 struct ring_buffer_event *
4156
-ring_buffer_consume(struct ring_buffer *buffer, int cpu, u64 *ts,
4763
+ring_buffer_consume(struct trace_buffer *buffer, int cpu, u64 *ts,
41574764 unsigned long *lost_events)
41584765 {
41594766 struct ring_buffer_per_cpu *cpu_buffer;
....@@ -4213,7 +4820,7 @@
42134820 * This overall must be paired with ring_buffer_read_finish.
42144821 */
42154822 struct ring_buffer_iter *
4216
-ring_buffer_read_prepare(struct ring_buffer *buffer, int cpu, gfp_t flags)
4823
+ring_buffer_read_prepare(struct trace_buffer *buffer, int cpu, gfp_t flags)
42174824 {
42184825 struct ring_buffer_per_cpu *cpu_buffer;
42194826 struct ring_buffer_iter *iter;
....@@ -4221,16 +4828,21 @@
42214828 if (!cpumask_test_cpu(cpu, buffer->cpumask))
42224829 return NULL;
42234830
4224
- iter = kmalloc(sizeof(*iter), flags);
4831
+ iter = kzalloc(sizeof(*iter), flags);
42254832 if (!iter)
42264833 return NULL;
4834
+
4835
+ iter->event = kmalloc(BUF_MAX_DATA_SIZE, flags);
4836
+ if (!iter->event) {
4837
+ kfree(iter);
4838
+ return NULL;
4839
+ }
42274840
42284841 cpu_buffer = buffer->buffers[cpu];
42294842
42304843 iter->cpu_buffer = cpu_buffer;
42314844
4232
- atomic_inc(&buffer->resize_disabled);
4233
- atomic_inc(&cpu_buffer->record_disabled);
4845
+ atomic_inc(&cpu_buffer->resize_disabled);
42344846
42354847 return iter;
42364848 }
....@@ -4246,7 +4858,7 @@
42464858 void
42474859 ring_buffer_read_prepare_sync(void)
42484860 {
4249
- synchronize_sched();
4861
+ synchronize_rcu();
42504862 }
42514863 EXPORT_SYMBOL_GPL(ring_buffer_read_prepare_sync);
42524864
....@@ -4303,48 +4915,38 @@
43034915 rb_check_pages(cpu_buffer);
43044916 raw_spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags);
43054917
4306
- atomic_dec(&cpu_buffer->record_disabled);
4307
- atomic_dec(&cpu_buffer->buffer->resize_disabled);
4918
+ atomic_dec(&cpu_buffer->resize_disabled);
4919
+ kfree(iter->event);
43084920 kfree(iter);
43094921 }
43104922 EXPORT_SYMBOL_GPL(ring_buffer_read_finish);
43114923
43124924 /**
4313
- * ring_buffer_read - read the next item in the ring buffer by the iterator
4925
+ * ring_buffer_iter_advance - advance the iterator to the next location
43144926 * @iter: The ring buffer iterator
4315
- * @ts: The time stamp of the event read.
43164927 *
4317
- * This reads the next event in the ring buffer and increments the iterator.
4928
+ * Move the location of the iterator such that the next read will
4929
+ * be the next location of the iterator.
43184930 */
4319
-struct ring_buffer_event *
4320
-ring_buffer_read(struct ring_buffer_iter *iter, u64 *ts)
4931
+void ring_buffer_iter_advance(struct ring_buffer_iter *iter)
43214932 {
4322
- struct ring_buffer_event *event;
43234933 struct ring_buffer_per_cpu *cpu_buffer = iter->cpu_buffer;
43244934 unsigned long flags;
43254935
43264936 raw_spin_lock_irqsave(&cpu_buffer->reader_lock, flags);
4327
- again:
4328
- event = rb_iter_peek(iter, ts);
4329
- if (!event)
4330
- goto out;
4331
-
4332
- if (event->type_len == RINGBUF_TYPE_PADDING)
4333
- goto again;
43344937
43354938 rb_advance_iter(iter);
4336
- out:
4337
- raw_spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags);
43384939
4339
- return event;
4940
+ raw_spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags);
43404941 }
4341
-EXPORT_SYMBOL_GPL(ring_buffer_read);
4942
+EXPORT_SYMBOL_GPL(ring_buffer_iter_advance);
43424943
43434944 /**
43444945 * ring_buffer_size - return the size of the ring buffer (in bytes)
43454946 * @buffer: The ring buffer.
4947
+ * @cpu: The CPU to get ring buffer size from.
43464948 */
4347
-unsigned long ring_buffer_size(struct ring_buffer *buffer, int cpu)
4949
+unsigned long ring_buffer_size(struct trace_buffer *buffer, int cpu)
43484950 {
43494951 /*
43504952 * Earlier, this method returned
....@@ -4389,11 +4991,16 @@
43894991 local_set(&cpu_buffer->entries, 0);
43904992 local_set(&cpu_buffer->committing, 0);
43914993 local_set(&cpu_buffer->commits, 0);
4994
+ local_set(&cpu_buffer->pages_touched, 0);
4995
+ local_set(&cpu_buffer->pages_lost, 0);
4996
+ local_set(&cpu_buffer->pages_read, 0);
4997
+ cpu_buffer->last_pages_touch = 0;
4998
+ cpu_buffer->shortest_full = 0;
43924999 cpu_buffer->read = 0;
43935000 cpu_buffer->read_bytes = 0;
43945001
4395
- cpu_buffer->write_stamp = 0;
4396
- cpu_buffer->read_stamp = 0;
5002
+ rb_time_set(&cpu_buffer->write_stamp, 0);
5003
+ rb_time_set(&cpu_buffer->before_stamp, 0);
43975004
43985005 cpu_buffer->lost_events = 0;
43995006 cpu_buffer->last_overrun = 0;
....@@ -4401,26 +5008,10 @@
44015008 rb_head_page_activate(cpu_buffer);
44025009 }
44035010
4404
-/**
4405
- * ring_buffer_reset_cpu - reset a ring buffer per CPU buffer
4406
- * @buffer: The ring buffer to reset a per cpu buffer of
4407
- * @cpu: The CPU buffer to be reset
4408
- */
4409
-void ring_buffer_reset_cpu(struct ring_buffer *buffer, int cpu)
5011
+/* Must have disabled the cpu buffer then done a synchronize_rcu */
5012
+static void reset_disabled_cpu_buffer(struct ring_buffer_per_cpu *cpu_buffer)
44105013 {
4411
- struct ring_buffer_per_cpu *cpu_buffer = buffer->buffers[cpu];
44125014 unsigned long flags;
4413
-
4414
- if (!cpumask_test_cpu(cpu, buffer->cpumask))
4415
- return;
4416
- /* prevent another thread from changing buffer sizes */
4417
- mutex_lock(&buffer->mutex);
4418
-
4419
- atomic_inc(&buffer->resize_disabled);
4420
- atomic_inc(&cpu_buffer->record_disabled);
4421
-
4422
- /* Make sure all commits have finished */
4423
- synchronize_sched();
44245015
44255016 raw_spin_lock_irqsave(&cpu_buffer->reader_lock, flags);
44265017
....@@ -4435,24 +5026,105 @@
44355026
44365027 out:
44375028 raw_spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags);
5029
+}
5030
+
5031
+/**
5032
+ * ring_buffer_reset_cpu - reset a ring buffer per CPU buffer
5033
+ * @buffer: The ring buffer to reset a per cpu buffer of
5034
+ * @cpu: The CPU buffer to be reset
5035
+ */
5036
+void ring_buffer_reset_cpu(struct trace_buffer *buffer, int cpu)
5037
+{
5038
+ struct ring_buffer_per_cpu *cpu_buffer = buffer->buffers[cpu];
5039
+
5040
+ if (!cpumask_test_cpu(cpu, buffer->cpumask))
5041
+ return;
5042
+
5043
+ /* prevent another thread from changing buffer sizes */
5044
+ mutex_lock(&buffer->mutex);
5045
+
5046
+ atomic_inc(&cpu_buffer->resize_disabled);
5047
+ atomic_inc(&cpu_buffer->record_disabled);
5048
+
5049
+ /* Make sure all commits have finished */
5050
+ synchronize_rcu();
5051
+
5052
+ reset_disabled_cpu_buffer(cpu_buffer);
44385053
44395054 atomic_dec(&cpu_buffer->record_disabled);
4440
- atomic_dec(&buffer->resize_disabled);
5055
+ atomic_dec(&cpu_buffer->resize_disabled);
44415056
44425057 mutex_unlock(&buffer->mutex);
44435058 }
44445059 EXPORT_SYMBOL_GPL(ring_buffer_reset_cpu);
44455060
44465061 /**
5062
+ * ring_buffer_reset_cpu - reset a ring buffer per CPU buffer
5063
+ * @buffer: The ring buffer to reset a per cpu buffer of
5064
+ * @cpu: The CPU buffer to be reset
5065
+ */
5066
+void ring_buffer_reset_online_cpus(struct trace_buffer *buffer)
5067
+{
5068
+ struct ring_buffer_per_cpu *cpu_buffer;
5069
+ int cpu;
5070
+
5071
+ /* prevent another thread from changing buffer sizes */
5072
+ mutex_lock(&buffer->mutex);
5073
+
5074
+ for_each_online_buffer_cpu(buffer, cpu) {
5075
+ cpu_buffer = buffer->buffers[cpu];
5076
+
5077
+ atomic_inc(&cpu_buffer->resize_disabled);
5078
+ atomic_inc(&cpu_buffer->record_disabled);
5079
+ }
5080
+
5081
+ /* Make sure all commits have finished */
5082
+ synchronize_rcu();
5083
+
5084
+ for_each_online_buffer_cpu(buffer, cpu) {
5085
+ cpu_buffer = buffer->buffers[cpu];
5086
+
5087
+ reset_disabled_cpu_buffer(cpu_buffer);
5088
+
5089
+ atomic_dec(&cpu_buffer->record_disabled);
5090
+ atomic_dec(&cpu_buffer->resize_disabled);
5091
+ }
5092
+
5093
+ mutex_unlock(&buffer->mutex);
5094
+}
5095
+
5096
+/**
44475097 * ring_buffer_reset - reset a ring buffer
44485098 * @buffer: The ring buffer to reset all cpu buffers
44495099 */
4450
-void ring_buffer_reset(struct ring_buffer *buffer)
5100
+void ring_buffer_reset(struct trace_buffer *buffer)
44515101 {
5102
+ struct ring_buffer_per_cpu *cpu_buffer;
44525103 int cpu;
44535104
4454
- for_each_buffer_cpu(buffer, cpu)
4455
- ring_buffer_reset_cpu(buffer, cpu);
5105
+ /* prevent another thread from changing buffer sizes */
5106
+ mutex_lock(&buffer->mutex);
5107
+
5108
+ for_each_buffer_cpu(buffer, cpu) {
5109
+ cpu_buffer = buffer->buffers[cpu];
5110
+
5111
+ atomic_inc(&cpu_buffer->resize_disabled);
5112
+ atomic_inc(&cpu_buffer->record_disabled);
5113
+ }
5114
+
5115
+ /* Make sure all commits have finished */
5116
+ synchronize_rcu();
5117
+
5118
+ for_each_buffer_cpu(buffer, cpu) {
5119
+ cpu_buffer = buffer->buffers[cpu];
5120
+
5121
+ reset_disabled_cpu_buffer(cpu_buffer);
5122
+
5123
+ atomic_dec(&cpu_buffer->record_disabled);
5124
+ atomic_dec(&cpu_buffer->resize_disabled);
5125
+ }
5126
+
5127
+ mutex_unlock(&buffer->mutex);
44565128 }
44575129 EXPORT_SYMBOL_GPL(ring_buffer_reset);
44585130
....@@ -4460,7 +5132,7 @@
44605132 * rind_buffer_empty - is the ring buffer empty?
44615133 * @buffer: The ring buffer to test
44625134 */
4463
-bool ring_buffer_empty(struct ring_buffer *buffer)
5135
+bool ring_buffer_empty(struct trace_buffer *buffer)
44645136 {
44655137 struct ring_buffer_per_cpu *cpu_buffer;
44665138 unsigned long flags;
....@@ -4490,7 +5162,7 @@
44905162 * @buffer: The ring buffer
44915163 * @cpu: The CPU buffer to test
44925164 */
4493
-bool ring_buffer_empty_cpu(struct ring_buffer *buffer, int cpu)
5165
+bool ring_buffer_empty_cpu(struct trace_buffer *buffer, int cpu)
44945166 {
44955167 struct ring_buffer_per_cpu *cpu_buffer;
44965168 unsigned long flags;
....@@ -4516,14 +5188,15 @@
45165188 * ring_buffer_swap_cpu - swap a CPU buffer between two ring buffers
45175189 * @buffer_a: One buffer to swap with
45185190 * @buffer_b: The other buffer to swap with
5191
+ * @cpu: the CPU of the buffers to swap
45195192 *
45205193 * This function is useful for tracers that want to take a "snapshot"
45215194 * of a CPU buffer and has another back up buffer lying around.
45225195 * it is expected that the tracer handles the cpu buffer not being
45235196 * used at the moment.
45245197 */
4525
-int ring_buffer_swap_cpu(struct ring_buffer *buffer_a,
4526
- struct ring_buffer *buffer_b, int cpu)
5198
+int ring_buffer_swap_cpu(struct trace_buffer *buffer_a,
5199
+ struct trace_buffer *buffer_b, int cpu)
45275200 {
45285201 struct ring_buffer_per_cpu *cpu_buffer_a;
45295202 struct ring_buffer_per_cpu *cpu_buffer_b;
....@@ -4555,7 +5228,7 @@
45555228 goto out;
45565229
45575230 /*
4558
- * We can't do a synchronize_sched here because this
5231
+ * We can't do a synchronize_rcu here because this
45595232 * function can be called in atomic context.
45605233 * Normally this will be called from the same CPU as cpu.
45615234 * If not it's up to the caller to protect this.
....@@ -4602,7 +5275,7 @@
46025275 * Returns:
46035276 * The page allocated, or ERR_PTR
46045277 */
4605
-void *ring_buffer_alloc_read_page(struct ring_buffer *buffer, int cpu)
5278
+void *ring_buffer_alloc_read_page(struct trace_buffer *buffer, int cpu)
46065279 {
46075280 struct ring_buffer_per_cpu *cpu_buffer;
46085281 struct buffer_data_page *bpage = NULL;
....@@ -4649,7 +5322,7 @@
46495322 *
46505323 * Free a page allocated from ring_buffer_alloc_read_page.
46515324 */
4652
-void ring_buffer_free_read_page(struct ring_buffer *buffer, int cpu, void *data)
5325
+void ring_buffer_free_read_page(struct trace_buffer *buffer, int cpu, void *data)
46535326 {
46545327 struct ring_buffer_per_cpu *cpu_buffer = buffer->buffers[cpu];
46555328 struct buffer_data_page *bpage = data;
....@@ -4709,7 +5382,7 @@
47095382 * >=0 if data has been transferred, returns the offset of consumed data.
47105383 * <0 if no data has been transferred.
47115384 */
4712
-int ring_buffer_read_page(struct ring_buffer *buffer,
5385
+int ring_buffer_read_page(struct trace_buffer *buffer,
47135386 void **data_page, size_t len, int cpu, int full)
47145387 {
47155388 struct ring_buffer_per_cpu *cpu_buffer = buffer->buffers[cpu];
....@@ -4770,7 +5443,15 @@
47705443 unsigned int pos = 0;
47715444 unsigned int size;
47725445
4773
- if (full)
5446
+ /*
5447
+ * If a full page is expected, this can still be returned
5448
+ * if there's been a previous partial read and the
5449
+ * rest of the page can be read and the commit page is off
5450
+ * the reader page.
5451
+ */
5452
+ if (full &&
5453
+ (!read || (len < (commit - read)) ||
5454
+ cpu_buffer->reader_page == cpu_buffer->commit_page))
47745455 goto out_unlock;
47755456
47765457 if (len > (commit - read))
....@@ -4880,12 +5561,12 @@
48805561 */
48815562 int trace_rb_cpu_prepare(unsigned int cpu, struct hlist_node *node)
48825563 {
4883
- struct ring_buffer *buffer;
5564
+ struct trace_buffer *buffer;
48845565 long nr_pages_same;
48855566 int cpu_i;
48865567 unsigned long nr_pages;
48875568
4888
- buffer = container_of(node, struct ring_buffer, node);
5569
+ buffer = container_of(node, struct trace_buffer, node);
48895570 if (cpumask_test_cpu(cpu, buffer->cpumask))
48905571 return 0;
48915572
....@@ -4935,7 +5616,7 @@
49355616 static struct task_struct *rb_threads[NR_CPUS] __initdata;
49365617
49375618 struct rb_test_data {
4938
- struct ring_buffer *buffer;
5619
+ struct trace_buffer *buffer;
49395620 unsigned long events;
49405621 unsigned long bytes_written;
49415622 unsigned long bytes_alloc;
....@@ -4983,7 +5664,7 @@
49835664 cnt = data->cnt + (nested ? 27 : 0);
49845665
49855666 /* Multiply cnt by ~e, to make some unique increment */
4986
- size = (data->cnt * 68 / 25) % (sizeof(rb_string) - 1);
5667
+ size = (cnt * 68 / 25) % (sizeof(rb_string) - 1);
49875668
49885669 len = size + sizeof(struct rb_item);
49895670
....@@ -5077,10 +5758,15 @@
50775758 static __init int test_ringbuffer(void)
50785759 {
50795760 struct task_struct *rb_hammer;
5080
- struct ring_buffer *buffer;
5761
+ struct trace_buffer *buffer;
50815762 int cpu;
50825763 int ret = 0;
50835764
5765
+ if (security_locked_down(LOCKDOWN_TRACEFS)) {
5766
+ pr_warn("Lockdown is enabled, skipping ring buffer tests\n");
5767
+ return 0;
5768
+ }
5769
+
50845770 pr_info("Running ring buffer tests...\n");
50855771
50865772 buffer = ring_buffer_alloc(RB_TEST_BUFFER_SIZE, RB_FL_OVERWRITE);