tracing: Rename to "capacity"
Subsystems (2)
Vincent Donnefort
maintainerv2 cover tracing: Rename to "capacity"
A few places in ring-buffer and tracing are using "size" or "entries" while it means "capacity", that is the amount of memory available for raw data in a ring buffer. Rename functions and member where appropriate.
v2:
- Fix "subbufer" typo
- Rename trace_array::entries (Masami)
- Rename tracing_entries_fops and tracing_total_entries_fops
v1 (https://lore.kernel.org/all/[email protected]/)
Vincent Donnefort (3):
ring-buffer: Rename ring_buffer_size() to ring_buffer_capacity()
tracing: Rename trace_array::entries to capacity
tracing: Rename tracing_entries_fops to tracing_capacity_fops
include/linux/ring_buffer.h | 2 +- kernel/trace/ring_buffer.c | 13 ++++++--- kernel/trace/trace.c | 51 +++++++++++++++++------------------ kernel/trace/trace.h | 4 +-- kernel/trace/trace_snapshot.c | 14 +++++----- 5 files changed, 43 insertions(+), 41 deletions(-)
base-commit: df2908090cda368b01ff43709f51890076c56157
Signature · 1 line
2.55.0.979.g7e5102b832-goog
Vincent Donnefort
maintainerPATCH v2 1/3 ring-buffer: Rename ring_buffer_size() to ring_buffer_capacity()
Since commit 8a5f63637890 ("ring-buffer: Fix subbuf resize race with ring buffer readers"), "capacity" refers to the memory available for events (excluding subbuffer headers) while "size" refers to the raw allocation. ring_buffer_size() actually calculates this event capacity. Rename it to ring_buffer_capacity() to align with this convention.
--- include/linux/ring_buffer.h | 2 +- kernel/trace/ring_buffer.c | 13 +++++++++---- kernel/trace/trace.c | 6 +++--- 3 files changed, 13 insertions(+), 8 deletions(-)
include/linux/ring_buffer.h +1 -1
@@ -165,7 +165,7 @@ void ring_buffer_iter_reset(struct ring_buffer_iter *iter);int ring_buffer_iter_empty (struct ring_buffer_iter *iter);bool ring_buffer_iter_dropped (struct ring_buffer_iter *iter); -unsigned long ring_buffer_size (struct trace_buffer *buffer,int cpu); +unsigned long ring_buffer_capacity (struct trace_buffer *buffer,int cpu);unsigned long ring_buffer_max_event_size (struct trace_buffer *buffer);void ring_buffer_reset_cpu (struct trace_buffer *buffer,int cpu);
kernel/trace/ring_buffer.c +9 -4
@@ -6547,18 +6547,23 @@ void ring_buffer_iter_advance(struct ring_buffer_iter *iter)EXPORT_SYMBOL_GPL (ring_buffer_iter_advance);/** -* ring_buffer_size - return the size of the ring buffer (in bytes) +* ring_buffer_capacity - return the capacity of the ring buffer (in bytes) * @buffer: The ring buffer. -* @cpu: The CPU to get ring buffer size from. +* @cpu: The CPU to get ring buffer capacity from. +* +* Capacity is the total memory available for recording event data in the +* ring buffer. It excludes subbuffer headers. +* +* Returns the capacity in bytes, or 0 if the CPU is not set in the buffer mask. */ -unsigned long ring_buffer_size (struct trace_buffer *buffer,int cpu) +unsigned long ring_buffer_capacity (struct trace_buffer *buffer,int cpu) {if (!cpumask_test_cpu (cpu, buffer->cpumask))return 0 ;return rb_subbuf_capacity (buffer) * buffer->buffers[cpu]->nr_pages; } -EXPORT_SYMBOL_GPL (ring_buffer_size); +EXPORT_SYMBOL_GPL (ring_buffer_capacity);/** * ring_buffer_max_event_size - return the max data size of an event
kernel/trace/trace.c +3 -3
@@ -4712,9 +4712,9 @@ void trace_set_buffer_entries(struct array_buffer *buf, unsigned long val)static void update_buffer_entries (struct array_buffer *buf,int cpu) {if (cpu ==RING_BUFFER_ALL_CPUS ) { -trace_set_buffer_entries (buf,ring_buffer_size (buf->buffer,0 )); +trace_set_buffer_entries (buf,ring_buffer_capacity (buf->buffer,0 )); }else { -per_cpu_ptr (buf->data, cpu)->entries =ring_buffer_size (buf->buffer, cpu); +per_cpu_ptr (buf->data, cpu)->entries =ring_buffer_capacity (buf->buffer, cpu); } }
@@ -8476,7 +8476,7 @@ int allocate_trace_buffer(struct trace_array *tr, struct array_buffer *buf, int/* Allocate the first page for all buffers */ trace_set_buffer_entries (&tr->array_buffer, -ring_buffer_size (tr->array_buffer.buffer,0 )); +ring_buffer_capacity (tr->array_buffer.buffer,0 ));return 0 ; }
Signature · 1 line
2.55.0.979.g7e5102b832-goog
Vincent Donnefort
maintainerPATCH v2 2/3 tracing: Rename trace_array::entries to capacity
In reply to Vincent DonnefortSince commit 8a5f63637890 ("ring-buffer: Fix subbuf resize race with ring buffer readers"), "capacity" refers to the memory available for events, while "entries" refers to the number of events in a ring buffer. As a consequence, rename trace_array::entries to capacity to align with this convention and avoid any confusion.
Rename also the helper functions trace_set_buffer_entries and update_buffer_entries.
--- kernel/trace/trace.c | 26 +++++++++++++------------- kernel/trace/trace.h | 4 ++-- kernel/trace/trace_snapshot.c | 14 +++++++------- 3 files changed, 22 insertions(+), 22 deletions(-)
kernel/trace/trace.c +13 -13
@@ -4701,20 +4701,20 @@ int tracer_init(struct tracer *t, struct trace_array *tr)return t->init (tr); } -void trace_set_buffer_entries (struct array_buffer *buf,unsigned long val) +void trace_set_buffer_capacity (struct array_buffer *buf,unsigned long val) {int cpu;for_each_tracing_cpu (cpu) -per_cpu_ptr (buf->data, cpu)->entries = val; +per_cpu_ptr (buf->data, cpu)->capacity = val; } -static void update_buffer_entries (struct array_buffer *buf,int cpu) +static void update_buffer_capacity (struct array_buffer *buf,int cpu) {if (cpu ==RING_BUFFER_ALL_CPUS ) { -trace_set_buffer_entries (buf,ring_buffer_capacity (buf->buffer,0 )); +trace_set_buffer_capacity (buf,ring_buffer_capacity (buf->buffer,0 )); }else { -per_cpu_ptr (buf->data, cpu)->entries =ring_buffer_capacity (buf->buffer, cpu); +per_cpu_ptr (buf->data, cpu)->capacity =ring_buffer_capacity (buf->buffer, cpu); } }
@@ -4770,12 +4770,12 @@ static int __tracing_resize_ring_buffer(struct trace_array *tr, goto out_start; } -update_buffer_entries (&tr->snapshot_buffer, cpu); +update_buffer_capacity (&tr->snapshot_buffer, cpu); out:#endif /* CONFIG_TRACER_SNAPSHOT */ -update_buffer_entries (&tr->array_buffer, cpu); +update_buffer_capacity (&tr->array_buffer, cpu); out_start:tracing_start_tr (tr);return ret;
@@ -5694,8 +5694,8 @@ tracing_entries_read(struct file *filp, char __user *ubuf,for_each_tracing_cpu (cpu) {/* fill in the size from first enabled cpu */ if (size ==0 ) - size =per_cpu_ptr (tr->array_buffer.data, cpu)->entries; -if (size !=per_cpu_ptr (tr->array_buffer.data, cpu)->entries) { + size =per_cpu_ptr (tr->array_buffer.data, cpu)->capacity; +if (size !=per_cpu_ptr (tr->array_buffer.data, cpu)->capacity) { buf_size_same =0 ;break ; }
@@ -5711,7 +5711,7 @@ tracing_entries_read(struct file *filp, char __user *ubuf, }else r =sprintf (buf,"X\n" ); }else - r =sprintf (buf,"%lu\n" ,per_cpu_ptr (tr->array_buffer.data, cpu)->entries >>10 ); + r =sprintf (buf,"%lu\n" ,per_cpu_ptr (tr->array_buffer.data, cpu)->capacity >>10 );mutex_unlock (&trace_types_lock);
@@ -5758,7 +5758,7 @@ tracing_total_entries_read(struct file *filp, char __user *ubuf,mutex_lock (&trace_types_lock);for_each_tracing_cpu (cpu) { - size +=per_cpu_ptr (tr->array_buffer.data, cpu)->entries >>10 ; + size +=per_cpu_ptr (tr->array_buffer.data, cpu)->capacity >>10 ;if (!tr->ring_buffer_expanded) expanded_size += trace_buf_size >>10 ; }
@@ -8475,8 +8475,8 @@ int allocate_trace_buffer(struct trace_array *tr, struct array_buffer *buf, int }/* Allocate the first page for all buffers */ -trace_set_buffer_entries (&tr->array_buffer, -ring_buffer_capacity (tr->array_buffer.buffer,0 )); +trace_set_buffer_capacity (&tr->array_buffer, +ring_buffer_capacity (tr->array_buffer.buffer,0 ));return 0 ; }
kernel/trace/trace.h +2 -2
@@ -191,7 +191,7 @@ struct trace_array;struct trace_array_cpu {local_t disabled; -unsigned long entries; +unsigned long capacity;unsigned long saved_latency;unsigned long critical_start;unsigned long critical_end;
@@ -730,7 +730,7 @@ ssize_t tracing_nsecs_read(unsigned long *ptr, char __user *ubuf,ssize_t tracing_nsecs_write (unsigned long *ptr,const char __user *ubuf,size_t cnt,loff_t *ppos); -void trace_set_buffer_entries (struct array_buffer *buf,unsigned long val); +void trace_set_buffer_capacity (struct array_buffer *buf,unsigned long val);/* * Should be used after trace_array_get(), trace_types_lock
kernel/trace/trace_snapshot.c +7 -7
@@ -142,18 +142,18 @@ int resize_buffer_duplicate_size(struct array_buffer *trace_buf,if (cpu_id ==RING_BUFFER_ALL_CPUS ) {for_each_tracing_cpu (cpu) { ret =ring_buffer_resize (trace_buf->buffer, -per_cpu_ptr (size_buf->data, cpu)->entries, cpu); +per_cpu_ptr (size_buf->data, cpu)->capacity, cpu);if (ret <0 )break ; -per_cpu_ptr (trace_buf->data, cpu)->entries = -per_cpu_ptr (size_buf->data, cpu)->entries; +per_cpu_ptr (trace_buf->data, cpu)->capacity = +per_cpu_ptr (size_buf->data, cpu)->capacity; } }else { ret =ring_buffer_resize (trace_buf->buffer, -per_cpu_ptr (size_buf->data, cpu_id)->entries, cpu_id); +per_cpu_ptr (size_buf->data, cpu_id)->capacity, cpu_id);if (ret ==0 ) -per_cpu_ptr (trace_buf->data, cpu_id)->entries = -per_cpu_ptr (size_buf->data, cpu_id)->entries; +per_cpu_ptr (trace_buf->data, cpu_id)->capacity = +per_cpu_ptr (size_buf->data, cpu_id)->capacity; }return ret;
@@ -193,7 +193,7 @@ void free_snapshot(struct trace_array *tr)*/ ring_buffer_subbuf_order_set (tr->snapshot_buffer.buffer,0 );ring_buffer_resize (tr->snapshot_buffer.buffer,1 ,RING_BUFFER_ALL_CPUS ); -trace_set_buffer_entries (&tr->snapshot_buffer,1 ); +trace_set_buffer_capacity (&tr->snapshot_buffer,1 );tracing_reset_online_cpus (&tr->snapshot_buffer); tr->allocated_snapshot = false; }
Signature · 1 line
2.55.0.979.g7e5102b832-goog
Vincent Donnefort
maintainerPATCH v2 3/3 tracing: Rename tracing_entries_fops to tracing_capacity_fops
In reply to Vincent DonnefortSince commit 8a5f63637890 ("ring-buffer: Fix subbuf resize race with ring buffer readers"), "capacity" refers to the memory available for events, while "entries" refers to the number of events in a ring buffer. As a consequence, rename trace_array::entries to capacity to align with this convention.
While at it, rename also tracing_total_entries_fops. It is the aggragate of all ring buffer capacities.
--- kernel/trace/trace.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-)
kernel/trace/trace.c +11 -14
@@ -5672,8 +5672,7 @@ tracing_syscall_buf_write(struct file *filp, const char __user *ubuf, }static ssize_t -tracing_entries_read (struct file *filp,char __user *ubuf, -size_t cnt,loff_t *ppos) +tracing_capacity_read (struct file *filp,char __user *ubuf,size_t cnt,loff_t *ppos) {struct inode *inode =file_inode (filp);struct trace_array *tr = inode->i_private;
@@ -5720,8 +5719,7 @@ tracing_entries_read(struct file *filp, char __user *ubuf, }static ssize_t -tracing_entries_write (struct file *filp,const char __user *ubuf, -size_t cnt,loff_t *ppos) +tracing_capacity_write (struct file *filp,const char __user *ubuf,size_t cnt,loff_t *ppos) {struct inode *inode =file_inode (filp);struct trace_array *tr = inode->i_private;
@@ -5748,8 +5746,7 @@ tracing_entries_write(struct file *filp, const char __user *ubuf, }static ssize_t -tracing_total_entries_read (struct file *filp,char __user *ubuf, -size_t cnt,loff_t *ppos) +tracing_total_capacity_read (struct file *filp,char __user *ubuf,size_t cnt,loff_t *ppos) {struct trace_array *tr = filp->private_data;char buf[64 ];
@@ -6600,10 +6597,10 @@ static const struct file_operations tracing_pipe_fops = { .release = tracing_release_pipe, }; -static const struct file_operations tracing_entries_fops = { +static const struct file_operations tracing_capacity_fops = { .open = tracing_open_generic_tr, - .read = tracing_entries_read, - .write = tracing_entries_write, + .read = tracing_capacity_read, + .write = tracing_capacity_write, .llseek = generic_file_llseek, .release = tracing_release_generic_tr, };
@@ -6623,9 +6620,9 @@ static const struct file_operations tracing_buffer_meta_fops = { .release = tracing_seq_release, }; -static const struct file_operations tracing_total_entries_fops = { +static const struct file_operations tracing_total_capacity_fops = { .open = tracing_open_generic_tr, - .read = tracing_total_entries_read, + .read = tracing_total_capacity_read, .llseek = generic_file_llseek, .release = tracing_release_generic_tr, };
@@ -7653,7 +7650,7 @@ tracing_init_tracefs_percpu(struct trace_array *tr, long cpu) tr, cpu, &tracing_stats_fops);trace_create_cpu_file ("buffer_size_kb" ,TRACE_MODE_WRITE , d_cpu, - tr, cpu, &tracing_entries_fops); + tr, cpu, &tracing_capacity_fops);if (tr->range_addr_start) trace_create_cpu_file("buffer_meta", TRACE_MODE_READ, d_cpu,
@@ -8954,10 +8951,10 @@ init_tracer_tracefs(struct trace_array *tr, struct dentry *d_tracer) tr, &tracing_pipe_fops);trace_create_file ("buffer_size_kb" , writable_mode, d_tracer, - tr, &tracing_entries_fops); + tr, &tracing_capacity_fops);trace_create_file ("buffer_total_size_kb" ,TRACE_MODE_READ , d_tracer, - tr, &tracing_total_entries_fops); + tr, &tracing_total_capacity_fops);trace_create_file ("trace_clock" , writable_mode, d_tracer, tr, &trace_clock_fops);
Signature · 1 line
2.55.0.979.g7e5102b832-goog