Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ring-buffer: Export buffer_data_page and macros

In preparation for allowing the writing of ring-buffer compliant pages
outside of ring_buffer.c, move buffer_data_page and timestamps encoding
macros into the publicly available ring_buffer_types.h.

Link: https://patch.msgid.link/20260309162516.2623589-13-vdonnefort@google.com
Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>

authored by

Vincent Donnefort and committed by
Steven Rostedt (Google)
93ae1b76 5f3efd1d

+42 -35
+41
include/linux/ring_buffer_types.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef _LINUX_RING_BUFFER_TYPES_H 3 + #define _LINUX_RING_BUFFER_TYPES_H 4 + 5 + #include <asm/local.h> 6 + 7 + #define TS_SHIFT 27 8 + #define TS_MASK ((1ULL << TS_SHIFT) - 1) 9 + #define TS_DELTA_TEST (~TS_MASK) 10 + 11 + /* 12 + * We need to fit the time_stamp delta into 27 bits. 13 + */ 14 + static inline bool test_time_stamp(u64 delta) 15 + { 16 + return !!(delta & TS_DELTA_TEST); 17 + } 18 + 19 + #define BUF_PAGE_HDR_SIZE offsetof(struct buffer_data_page, data) 20 + 21 + #define RB_EVNT_HDR_SIZE (offsetof(struct ring_buffer_event, array)) 22 + #define RB_ALIGNMENT 4U 23 + #define RB_MAX_SMALL_DATA (RB_ALIGNMENT * RINGBUF_TYPE_DATA_TYPE_LEN_MAX) 24 + #define RB_EVNT_MIN_SIZE 8U /* two 32bit words */ 25 + 26 + #ifndef CONFIG_HAVE_64BIT_ALIGNED_ACCESS 27 + # define RB_FORCE_8BYTE_ALIGNMENT 0 28 + # define RB_ARCH_ALIGNMENT RB_ALIGNMENT 29 + #else 30 + # define RB_FORCE_8BYTE_ALIGNMENT 1 31 + # define RB_ARCH_ALIGNMENT 8U 32 + #endif 33 + 34 + #define RB_ALIGN_DATA __aligned(RB_ARCH_ALIGNMENT) 35 + 36 + struct buffer_data_page { 37 + u64 time_stamp; /* page time stamp */ 38 + local_t commit; /* write committed index */ 39 + unsigned char data[] RB_ALIGN_DATA; /* data of buffer page */ 40 + }; 41 + #endif
+1 -35
kernel/trace/ring_buffer.c
··· 4 4 * 5 5 * Copyright (C) 2008 Steven Rostedt <srostedt@redhat.com> 6 6 */ 7 + #include <linux/ring_buffer_types.h> 7 8 #include <linux/sched/isolation.h> 8 9 #include <linux/trace_recursion.h> 9 10 #include <linux/trace_events.h> ··· 158 157 /* Used for individual buffers (after the counter) */ 159 158 #define RB_BUFFER_OFF (1 << 20) 160 159 161 - #define BUF_PAGE_HDR_SIZE offsetof(struct buffer_data_page, data) 162 - 163 - #define RB_EVNT_HDR_SIZE (offsetof(struct ring_buffer_event, array)) 164 - #define RB_ALIGNMENT 4U 165 - #define RB_MAX_SMALL_DATA (RB_ALIGNMENT * RINGBUF_TYPE_DATA_TYPE_LEN_MAX) 166 - #define RB_EVNT_MIN_SIZE 8U /* two 32bit words */ 167 - 168 - #ifndef CONFIG_HAVE_64BIT_ALIGNED_ACCESS 169 - # define RB_FORCE_8BYTE_ALIGNMENT 0 170 - # define RB_ARCH_ALIGNMENT RB_ALIGNMENT 171 - #else 172 - # define RB_FORCE_8BYTE_ALIGNMENT 1 173 - # define RB_ARCH_ALIGNMENT 8U 174 - #endif 175 - 176 - #define RB_ALIGN_DATA __aligned(RB_ARCH_ALIGNMENT) 177 - 178 160 /* define RINGBUF_TYPE_DATA for 'case RINGBUF_TYPE_DATA:' */ 179 161 #define RINGBUF_TYPE_DATA 0 ... RINGBUF_TYPE_DATA_TYPE_LEN_MAX 180 162 ··· 300 316 #define for_each_online_buffer_cpu(buffer, cpu) \ 301 317 for_each_cpu_and(cpu, buffer->cpumask, cpu_online_mask) 302 318 303 - #define TS_SHIFT 27 304 - #define TS_MASK ((1ULL << TS_SHIFT) - 1) 305 - #define TS_DELTA_TEST (~TS_MASK) 306 - 307 319 static u64 rb_event_time_stamp(struct ring_buffer_event *event) 308 320 { 309 321 u64 ts; ··· 317 337 #define RB_MISSED_STORED (1 << 30) 318 338 319 339 #define RB_MISSED_MASK (3 << 30) 320 - 321 - struct buffer_data_page { 322 - u64 time_stamp; /* page time stamp */ 323 - local_t commit; /* write committed index */ 324 - unsigned char data[] RB_ALIGN_DATA; /* data of buffer page */ 325 - }; 326 340 327 341 struct buffer_data_read_page { 328 342 unsigned order; /* order of the page */ ··· 409 435 rb_init_page(dpage); 410 436 411 437 return dpage; 412 - } 413 - 414 - /* 415 - * We need to fit the time_stamp delta into 27 bits. 416 - */ 417 - static inline bool test_time_stamp(u64 delta) 418 - { 419 - return !!(delta & TS_DELTA_TEST); 420 438 } 421 439 422 440 struct rb_irq_work {