Pass arguments for context size computation
A message that is not in the archive (sent off-list or not yet received): [email protected]
RFC PATCH 1/10 Pass arguments for context size computation
From: Francis Giraldeau <[email protected]>
Pass same arguments to get_size_arg() than to record(). This new operation has the same effect than get_size(), and the client code can implement either one.
--- lttng-events.h | 3 +++ lttng-ring-buffer-client.h | 17 ++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-)
lttng-events.h +3 -0
@@ -204,6 +204,9 @@ struct lttng_probe_ctx {struct lttng_ctx_field {struct lttng_event_field event_field;size_t (*get_size)(size_t offset); +size_t (*get_size_arg)(size_t offset,struct lttng_ctx_field *field, +struct lib_ring_buffer_ctx *ctx, +struct lttng_channel *chan);void (*record)(struct lttng_ctx_field *field,struct lib_ring_buffer_ctx *ctx,struct lttng_channel *chan);
lttng-ring-buffer-client.h +12 -5
@@ -83,7 +83,9 @@ static inline notrace u64 lib_ring_buffer_clock_read(struct channel *chan) }static inline -size_t ctx_get_size (size_t offset,struct lttng_ctx *ctx) +size_t ctx_get_size (size_t offset,struct lib_ring_buffer_ctx *bufctx, +struct lttng_channel *chan, +struct lttng_ctx *ctx) {int i;size_t orig_offset = offset;
@@ -91,8 +93,13 @@ size_t ctx_get_size(size_t offset, struct lttng_ctx *ctx)if (likely (!ctx))return 0 ; offset +=lib_ring_buffer_align (offset, ctx->largest_align); -for (i =0 ; i < ctx->nr_fields; i++) - offset += ctx->fields[i].get_size (offset); +for (i =0 ; i < ctx->nr_fields; i++) { +if (ctx->fields[i].get_size) + offset += ctx->fields[i].get_size (offset); +if (ctx->fields[i].get_size_arg) + offset += ctx->fields[i].get_size_arg (offset, + &ctx->fields[i], bufctx, chan); + }return offset - orig_offset; }
@@ -170,8 +177,8 @@ size_t record_header_size(const struct lib_ring_buffer_config *config, padding =0 ;WARN_ON_ONCE (1 ); } - offset +=ctx_get_size (offset, lttng_chan->ctx); - offset +=ctx_get_size (offset, event->ctx); + offset +=ctx_get_size (offset, ctx, lttng_chan, event->ctx); + offset +=ctx_get_size (offset, ctx, lttng_chan, lttng_chan->ctx); *pre_header_padding = padding;return offset - orig_offset;
Signature · 6 lines
2.1.4 _______________________________________________ lttng-dev mailing list [email protected] https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
RFC PATCH 2/10 Define max nesting count constant
In reply to a message not in the archiveFrom: Francis Giraldeau <[email protected]>
Extract the constant within the code as #define. The define is added to frontend.h in order to be included in other source files.
--- lib/ringbuffer/frontend.h | 3 +++ lib/ringbuffer/frontend_api.h | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-)
lib/ringbuffer/frontend.h +3 -0
@@ -51,6 +51,9 @@/* Internal helpers */ #include <wrapper/ringbuffer/frontend_internal.h> +/* Max ring buffer nesting count, see lib_ring_buffer_get_cpu(). */ +#define RING_BUFFER_MAX_NESTING 4 +/* Buffer creation/removal and setup operations */ /*
lib/ringbuffer/frontend_api.h +1 -1
@@ -58,7 +58,7 @@ int lib_ring_buffer_get_cpu(const struct lib_ring_buffer_config *config) nesting = ++per_cpu (lib_ring_buffer_nesting, cpu);barrier (); -if (unlikely (nesting >4 )) { +if (unlikely (nesting >RING_BUFFER_MAX_NESTING )) {WARN_ON_ONCE (1 );per_cpu (lib_ring_buffer_nesting, cpu)--;rcu_read_unlock_sched_notrace ();
Signature · 6 lines
2.1.4 _______________________________________________ lttng-dev mailing list [email protected] https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
RFC PATCH 3/10 Add kernel and user callstack contexts
In reply to a message not in the archiveFrom: Francis Giraldeau <[email protected]>
--- Makefile | 3 +- lttng-abi.c | 3 + lttng-abi.h | 2 + lttng-context-callstack.c | 334 ++++++++++++++++++++++++++++++++++++++++++++++ lttng-events.h | 5 + 5 files changed, 346 insertions(+), 1 deletion(-) create mode 100644 lttng-context-callstack.c
Makefile +2 -1
@@ -51,7 +51,8 @@ ifneq ($(KERNELRELEASE),) lttng-context-vtid.o lttng-context-ppid.o \ lttng-context-vppid.o lttng-context-cpu-id.o \ lttng-context-interruptible.o \ - lttng-context-need-reschedule.o lttng-calibrate.o \ + lttng-context-need-reschedule.o \ + lttng-context-callstack.o lttng-calibrate.o \ lttng-context-hostname.o wrapper/random.o \ probes/lttng.o wrapper/trace-clock.o \ wrapper/page_alloc.o \
lttng-abi.c +3 -0
@@ -246,6 +246,9 @@ long lttng_abi_add_context(struct file *file,return lttng_add_preemptible_to_ctx (ctx);case LTTNG_KERNEL_CONTEXT_MIGRATABLE :return lttng_add_migratable_to_ctx (ctx); +case LTTNG_KERNEL_CONTEXT_CALLSTACK_KERNEL : +case LTTNG_KERNEL_CONTEXT_CALLSTACK_USER : +return lttng_add_callstack_to_ctx (ctx, context_param->ctx);default :return -EINVAL ; }
lttng-abi.h +2 -0
@@ -146,6 +146,8 @@ enum lttng_kernel_context_type {LTTNG_KERNEL_CONTEXT_PREEMPTIBLE =13 ,LTTNG_KERNEL_CONTEXT_NEED_RESCHEDULE =14 ,LTTNG_KERNEL_CONTEXT_MIGRATABLE =15 , +LTTNG_KERNEL_CONTEXT_CALLSTACK_KERNEL =16 , + LTTNG_KERNEL_CONTEXT_CALLSTACK_USER = 17, }; struct lttng_kernel_perf_counter_ctx {
lttng-context-callstack.c new file +334 -0
334 lines not on this page · raw message
lttng-events.h +5 -0
@@ -217,6 +217,8 @@ struct lttng_ctx_field {struct lttng_perf_counter_field *perf_counter; } u;void (*destroy)(struct lttng_ctx_field *field); +/* private data to keep state between get_size and record */ +void *private; };struct lttng_ctx {
@@ -705,6 +707,9 @@ int lttng_add_migratable_to_ctx(struct lttng_ctx **ctx)return -ENOSYS ; }#endif + +int lttng_add_callstack_to_ctx (struct lttng_ctx **ctx,int type); +#if defined(CONFIG_PERF_EVENTS ) && (LINUX_VERSION_CODE >=KERNEL_VERSION (2 ,6 ,33 )) int lttng_add_perf_counter_to_ctx(uint32_t type, uint64_t config,
Signature · 6 lines
2.1.4 _______________________________________________ lttng-dev mailing list [email protected] https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
RFC PATCH 4/10 Cleanup callstack context
In reply to a message not in the archive--- lttng-context-callstack.c | 10 ++++------ lttng-events.h | 8 ++++++-- 2 files changed, 10 insertions(+), 8 deletions(-)
lttng-context-callstack.c +4 -6
@@ -119,7 +119,7 @@ struct stack_trace *stack_trace_context(struct lttng_ctx_field *field, {int nesting;struct lttng_cs *cs; -struct field_data *fdata = field->private; +struct field_data *fdata = field->priv;/* * get_cpu() is not required, preemption is already
@@ -147,7 +147,7 @@ size_t lttng_callstack_get_size(size_t offset, struct lttng_ctx_field *field, {size_t size =0 ;struct stack_trace *trace; -struct field_data *fdata = field->private; +struct field_data *fdata = field->priv;/* do not write data if no space is available */ trace =stack_trace_context (field, ctx);
@@ -239,7 +239,7 @@ error_alloc:static void lttng_callstack_destroy (struct lttng_ctx_field *field) { -struct field_data *fdata = field->private; +struct field_data *fdata = field->priv;field_data_free (fdata); }
@@ -259,7 +259,6 @@ int __lttng_add_callstack_generic(struct lttng_ctx **ctx, int mode)if (!field)return -ENOMEM ;if (lttng_find_context (*ctx, ctx_name)) { -printk ("%s lttng_find_context failed\n" , ctx_name); ret = -EEXIST ; goto error_find; }
@@ -289,10 +288,9 @@ int __lttng_add_callstack_generic(struct lttng_ctx **ctx, int mode) field->get_size_arg = lttng_callstack_get_size; field->record = lttng_callstack_record; - field->private = fdata; + field->priv = fdata; field->destroy = lttng_callstack_destroy;wrapper_vmalloc_sync_all (); -printk ("lttng add-context %s\n" , ctx_name);return 0 ; error_create:
lttng-events.h +6 -2
@@ -217,8 +217,12 @@ struct lttng_ctx_field {struct lttng_perf_counter_field *perf_counter; } u;void (*destroy)(struct lttng_ctx_field *field); -/* private data to keep state between get_size and record */ -void *private; +/* +* Private data to keep state between get_size and record. +* User must perform its own synchronization to protect against +* concurrent and reentrant contexts. +*/ +void *priv; };struct lttng_ctx {
Signature · 6 lines
2.1.4 _______________________________________________ lttng-dev mailing list [email protected] https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
RFC PATCH 5/10 callstack context: use delimiter when stack is incomplete
In reply to a message not in the archiveReverse the delimiter logic so we only consume trace space and pollute the user output when the stack is incomplete.
--- lttng-context-callstack.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-)
lttng-context-callstack.c +23 -1
@@ -159,10 +159,22 @@ size_t lttng_callstack_get_size(size_t offset, struct lttng_ctx_field *field,/* do the real work and reserve space */ cs_types[fdata->mode].save_func (trace); +/* +* Remove final ULONG_MAX delimiter. If we cannot find it, add +* our own marker to show that the stack is incomplete. This is +* more compact for a trace. +*/ +if (trace->nr_entries >0 + && trace->entries[trace->nr_entries -1 ] ==ULONG_MAX ) { + trace->nr_entries--; + } size += lib_ring_buffer_align(offset, lttng_alignof(unsigned int)); size +=sizeof (unsigned int ); size += lib_ring_buffer_align(offset, lttng_alignof(unsigned long)); size +=sizeof (unsigned long ) * trace->nr_entries; +/* Add our own ULONG_MAX delimiter to show incomplete stack. */ +if (trace->nr_entries == trace->max_entries) + size +=sizeof (unsigned long );return size; }
@@ -172,14 +184,24 @@ void lttng_callstack_record(struct lttng_ctx_field *field, struct lttng_channel *chan) {struct stack_trace *trace =stack_trace_context (field, ctx); +unsigned int nr_seq_entries;if (!trace)return ; lib_ring_buffer_align_ctx(ctx, lttng_alignof(unsigned int)); - chan->ops->event_write (ctx, &trace->nr_entries,sizeof (unsigned int )); + nr_seq_entries = trace->nr_entries; +if (trace->nr_entries == trace->max_entries) + nr_seq_entries++; + chan->ops->event_write (ctx, &nr_seq_entries,sizeof (unsigned int )); lib_ring_buffer_align_ctx(ctx, lttng_alignof(unsigned long)); chan->ops->event_write (ctx, trace->entries,sizeof (unsigned long ) * trace->nr_entries); +/* Add our own ULONG_MAX delimiter to show incomplete stack. */ +if (trace->nr_entries == trace->max_entries) { +unsigned long delim =ULONG_MAX ; + + chan->ops->event_write (ctx, &delim,sizeof (unsigned long )); + } } static
Signature · 6 lines
2.1.4 _______________________________________________ lttng-dev mailing list [email protected] https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
RFC PATCH 6/10 Fix: callstack context: false-sharing, bad memory size allocation
In reply to a message not in the archive--- lttng-context-callstack.c | 61 ++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 33 deletions(-)
lttng-context-callstack.c +28 -33
@@ -61,15 +61,20 @@#include "wrapper/vmalloc.h" #include "lttng-tracer.h" -#define MAX_ENTRIES 25/* BUG: saving more than 30 entries causes trace corruption */ +#define MAX_ENTRIES 25 + +struct lttng_cs_nesting { +struct stack_trace stack_trace; +unsigned long entries[MAX_ENTRIES ]; +};struct lttng_cs { -struct stack_trace items[RING_BUFFER_MAX_NESTING ]; +struct lttng_cs_nesting level[RING_BUFFER_MAX_NESTING ]; };struct field_data { -int mode;struct lttng_cs __percpu *cs_percpu; +int mode; };struct lttng_cs_type {
@@ -85,14 +90,14 @@ enum lttng_cs_ctx_modes {static struct lttng_cs_type cs_types[] = { { - .name ="callstack_kernel" , - .save_func_name ="save_stack_trace" , - .save_func =NULL , + .name ="callstack_kernel" , + .save_func_name ="save_stack_trace" , + .save_func =NULL , }, { - .name ="callstack_user" , - .save_func_name ="save_stack_trace_user" , - .save_func =NULL , + .name ="callstack_user" , + .save_func_name ="save_stack_trace_user" , + .save_func =NULL , }, };
@@ -133,7 +138,7 @@ struct stack_trace *stack_trace_context(struct lttng_ctx_field *field,if (nesting >=RING_BUFFER_MAX_NESTING ) {return NULL ; } -return &cs->items[nesting]; +return &cs->level[nesting].stack_trace; }/*
@@ -180,8 +185,8 @@ size_t lttng_callstack_get_size(size_t offset, struct lttng_ctx_field *field,static void lttng_callstack_record (struct lttng_ctx_field *field, -struct lib_ring_buffer_ctx *ctx, -struct lttng_channel *chan) +struct lib_ring_buffer_ctx *ctx, +struct lttng_channel *chan) {struct stack_trace *trace =stack_trace_context (field, ctx);unsigned int nr_seq_entries;
@@ -207,31 +212,20 @@ void lttng_callstack_record(struct lttng_ctx_field *field,static void field_data_free (struct field_data *fdata) { -int cpu, i; -struct lttng_cs *cs; -if (!fdata)return ; -for_each_possible_cpu (cpu) { - cs =per_cpu_ptr (fdata->cs_percpu, cpu); -for (i =0 ; i <RING_BUFFER_MAX_NESTING ; i++) { -kfree (cs->items[i].entries); - } - }free_percpu (fdata->cs_percpu);kfree (fdata); }static -struct field_data __percpu *field_data_create (unsigned int entries,int type) +struct field_data __percpu *field_data_create (int type) {int cpu, i; -struct stack_trace *item; -struct lttng_cs *cs;struct lttng_cs __percpu *cs_set; -struct field_data * fdata; +struct field_data *fdata; - fdata =kzalloc (sizeof (unsigned long ) * entries,GFP_KERNEL ); + fdata =kzalloc (sizeof (*fdata),GFP_KERNEL );if (!fdata)return NULL ; cs_set = alloc_percpu(struct lttng_cs);
@@ -240,14 +234,15 @@ struct field_data __percpu *field_data_create(unsigned int entries, int type) fdata->cs_percpu = cs_set;for_each_possible_cpu (cpu) { +struct lttng_cs *cs; + cs =per_cpu_ptr (cs_set, cpu);for (i =0 ; i <RING_BUFFER_MAX_NESTING ; i++) { - item = &cs->items[i]; - item->entries =kzalloc (sizeof (unsigned long ) * entries,GFP_KERNEL ); -if (!item->entries) { - goto error_alloc; - } - item->max_entries = entries; +struct lttng_cs_nesting *level; + + level = &cs->level[i]; + level->stack_trace.entries = level->entries; + level->stack_trace.max_entries =MAX_ENTRIES ; } } fdata->mode = type;
@@ -284,7 +279,7 @@ int __lttng_add_callstack_generic(struct lttng_ctx **ctx, int mode) ret = -EEXIST ; goto error_find; } - fdata =field_data_create (MAX_ENTRIES , mode); + fdata =field_data_create (mode);if (!fdata) { ret = -ENOMEM ; goto error_create;
Signature · 6 lines
2.1.4 _______________________________________________ lttng-dev mailing list [email protected] https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
RFC PATCH 7/10 Fix callstack context: write empty sequence if no stack trace
In reply to a message not in the archiveThe trace content needs to match the metadata, else the trace will be corrupted.
--- lttng-context-callstack.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
lttng-context-callstack.c +12 -3
@@ -156,8 +156,12 @@ size_t lttng_callstack_get_size(size_t offset, struct lttng_ctx_field *field,/* do not write data if no space is available */ trace =stack_trace_context (field, ctx); -if (!trace) -return 0 ; +if (unlikely (!trace)) { + size += lib_ring_buffer_align(offset, lttng_alignof(unsigned int)); + size +=sizeof (unsigned int ); + size += lib_ring_buffer_align(offset, lttng_alignof(unsigned long)); +return size; + }/* reset stack trace, no need to clear memory */ trace->nr_entries =0 ;
@@ -191,8 +195,13 @@ void lttng_callstack_record(struct lttng_ctx_field *field,struct stack_trace *trace =stack_trace_context (field, ctx);unsigned int nr_seq_entries; -if (!trace) +if (unlikely (!trace)) { + nr_seq_entries =0 ; + lib_ring_buffer_align_ctx(ctx, lttng_alignof(unsigned int)); + chan->ops->event_write (ctx, &nr_seq_entries,sizeof (unsigned int )); + lib_ring_buffer_align_ctx(ctx, lttng_alignof(unsigned long));return ; + } lib_ring_buffer_align_ctx(ctx, lttng_alignof(unsigned int)); nr_seq_entries = trace->nr_entries;if (trace->nr_entries == trace->max_entries)
Signature · 6 lines
2.1.4 _______________________________________________ lttng-dev mailing list [email protected] https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
RFC PATCH 8/10 Cleanup callstack context
In reply to a message not in the archive--- lttng-context-callstack.c | 73 ++++++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 35 deletions(-)
lttng-context-callstack.c +38 -35
@@ -20,31 +20,32 @@* License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * -* The callstack context can be added to any kernel -* event. It records either the kernel or the userspace callstack, up to a -* max depth. The context is a CTF sequence, such that it uses only the space -* required for the number of callstack entries. +* The callstack context can be added to any kernel event. It records +* either the kernel or the userspace callstack, up to a max depth. The +* context is a CTF sequence, such that it uses only the space required +* for the number of callstack entries. * -* It allocates callstack buffers per-CPU up to 4 interrupt nesting. This -* nesting limit is the same as defined in the ring buffer. It therefore uses a -* fixed amount of memory, proportional to the number of CPUs: +* It allocates callstack buffers per-CPU up to 4 interrupt nesting. +* This nesting limit is the same as defined in the ring buffer. It +* therefore uses a fixed amount of memory, proportional to the number +* of CPUs: * * size = cpus * nest * depth * sizeof(unsigned long) * -* Which is about 800 bytes per-CPUs on 64-bit host and a depth of 25. The -* allocation is done at the initialization to avoid memory allocation -* overhead while tracing, using a shallow stack. +* Which is about 800 bytes per CPU on 64-bit host and a depth of 25. +* The allocation is done at the initialization to avoid memory +* allocation overhead while tracing, using a shallow stack. * * The kernel callstack is recovered using save_stack_trace(), and the * userspace callstack uses save_stack_trace_user(). They rely on frame -* pointers. These are usually available for the kernel, but the compiler -* option -fomit-frame-pointer frequently used in popular Linux distributions -* may cause the userspace callstack to be unreliable, and is a known -* limitation of this approach. If frame pointers are not available, it -* produces no error, but the callstack will be empty. We still provide the -* feature, because it works well for runtime environments having frame -* pointers. In the future, unwind support and/or last branch record may -* provide a solution to this problem. +* pointers. These are usually available for the kernel, but the +* compiler option -fomit-frame-pointer frequently used in popular Linux +* distributions may cause the userspace callstack to be unreliable, and +* is a known limitation of this approach. If frame pointers are not +* available, it produces no error, but the callstack will be empty. We +* still provide the feature, because it works well for runtime +* environments having frame pointers. In the future, unwind support +* and/or last branch record may provide a solution to this problem. * * The symbol name resolution is left to the trace reader. */
@@ -63,18 +64,24 @@#define MAX_ENTRIES 25 -struct lttng_cs_nesting { +enum lttng_cs_ctx_modes { +CALLSTACK_KERNEL =0 , +CALLSTACK_USER =1 , +NR_CALLSTACK_MODES , +}; + +struct lttng_cs_dispatch {struct stack_trace stack_trace;unsigned long entries[MAX_ENTRIES ]; };struct lttng_cs { -struct lttng_cs_nesting level[RING_BUFFER_MAX_NESTING ]; +struct lttng_cs_dispatch dispatch[RING_BUFFER_MAX_NESTING ]; };struct field_data {struct lttng_cs __percpu *cs_percpu; -int mode; +enum lttng_cs_ctx_modes mode; };struct lttng_cs_type {
@@ -83,11 +90,6 @@ struct lttng_cs_type {void (*save_func)(struct stack_trace *trace); }; -enum lttng_cs_ctx_modes { -CALLSTACK_KERNEL =0 , -CALLSTACK_USER =1 , -}; -static struct lttng_cs_type cs_types[] = { { .name ="callstack_kernel" ,
@@ -102,7 +104,7 @@ static struct lttng_cs_type cs_types[] = { };static -int init_type (int mode) +int init_type (enum lttng_cs_ctx_modes mode) {unsigned long func;
@@ -138,7 +140,7 @@ struct stack_trace *stack_trace_context(struct lttng_ctx_field *field,if (nesting >=RING_BUFFER_MAX_NESTING ) {return NULL ; } -return &cs->level[nesting].stack_trace; +return &cs->dispatch[nesting].stack_trace; }/*
@@ -228,7 +230,7 @@ void field_data_free(struct field_data *fdata) }static -struct field_data __percpu *field_data_create (int type) +struct field_data __percpu *field_data_create (enum lttng_cs_ctx_modes mode) {int cpu, i;struct lttng_cs __percpu *cs_set;
@@ -247,14 +249,14 @@ struct field_data __percpu *field_data_create(int type) cs =per_cpu_ptr (cs_set, cpu);for (i =0 ; i <RING_BUFFER_MAX_NESTING ; i++) { -struct lttng_cs_nesting *level; +struct lttng_cs_dispatch *dispatch; - level = &cs->level[i]; - level->stack_trace.entries = level->entries; - level->stack_trace.max_entries =MAX_ENTRIES ; + dispatch = &cs->dispatch[i]; + dispatch->stack_trace.entries = dispatch->entries; + dispatch->stack_trace.max_entries =MAX_ENTRIES ; } } - fdata->mode = type; + fdata->mode = mode;return fdata; error_alloc:
@@ -271,7 +273,8 @@ void lttng_callstack_destroy(struct lttng_ctx_field *field) }static -int __lttng_add_callstack_generic (struct lttng_ctx **ctx,int mode) +int __lttng_add_callstack_generic (struct lttng_ctx **ctx, +enum lttng_cs_ctx_modes mode) {const char *ctx_name = cs_types[mode].name;struct lttng_ctx_field *field;
Signature · 6 lines
2.1.4 _______________________________________________ lttng-dev mailing list [email protected] https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
RFC PATCH 9/10 Fix: callstack context alignment calculation
In reply to a message not in the archive--- lttng-context-callstack.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
lttng-context-callstack.c +11 -11
@@ -152,17 +152,17 @@ size_t lttng_callstack_get_size(size_t offset, struct lttng_ctx_field *field,struct lib_ring_buffer_ctx *ctx, struct lttng_channel *chan) { - size_t size = 0; struct stack_trace *trace;struct field_data *fdata = field->priv; +size_t orig_offset = offset;/* do not write data if no space is available */ trace =stack_trace_context (field, ctx);if (unlikely (!trace)) { - size += lib_ring_buffer_align(offset, lttng_alignof(unsigned int)); - size +=sizeof (unsigned int ); - size += lib_ring_buffer_align(offset, lttng_alignof(unsigned long)); -return size; + offset += lib_ring_buffer_align(offset, lttng_alignof(unsigned int)); + offset +=sizeof (unsigned int ); + offset += lib_ring_buffer_align(offset, lttng_alignof(unsigned long)); +return offset - orig_offset; }/* reset stack trace, no need to clear memory */
@@ -179,14 +179,14 @@ size_t lttng_callstack_get_size(size_t offset, struct lttng_ctx_field *field, && trace->entries[trace->nr_entries - 1] == ULONG_MAX) { trace->nr_entries--; } - size += lib_ring_buffer_align(offset, lttng_alignof(unsigned int)); - size +=sizeof (unsigned int ); - size += lib_ring_buffer_align(offset, lttng_alignof(unsigned long)); - size +=sizeof (unsigned long ) * trace->nr_entries; + offset += lib_ring_buffer_align(offset, lttng_alignof(unsigned int)); + offset +=sizeof (unsigned int ); + offset += lib_ring_buffer_align(offset, lttng_alignof(unsigned long)); + offset +=sizeof (unsigned long ) * trace->nr_entries;/* Add our own ULONG_MAX delimiter to show incomplete stack. */ if (trace->nr_entries == trace->max_entries) - size +=sizeof (unsigned long ); -return size; + offset +=sizeof (unsigned long ); +return offset - orig_offset; } static
Signature · 6 lines
2.1.4 _______________________________________________ lttng-dev mailing list [email protected] https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
RFC PATCH 10/10 callstack context: bump number of entries to 128
In reply to a message not in the archiveUse a limit that fits in a 4096 bytes page on a 64-bit system. The only reason for the prior 25 entries limitation was a bug in the header size calculation (now fixed).
--- lttng-context-callstack.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
lttng-context-callstack.c +2 -2
@@ -32,7 +32,7 @@* * size = cpus * nest * depth * sizeof(unsigned long) * -* Which is about 800 bytes per CPU on 64-bit host and a depth of 25. +* Which is 4096 bytes per CPU on 64-bit host and a depth of 128. * The allocation is done at the initialization to avoid memory * allocation overhead while tracing, using a shallow stack. *
@@ -62,7 +62,7 @@#include "wrapper/vmalloc.h" #include "lttng-tracer.h" -#define MAX_ENTRIES 25 +#define MAX_ENTRIES 128enum lttng_cs_ctx_modes {CALLSTACK_KERNEL =0 ,
Signature · 6 lines
2.1.4 _______________________________________________ lttng-dev mailing list [email protected] https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
Re: [RFC PATCH lttng-modules 00/10] Callstack context for kernel tracer
In reply to a message not in the archiveThanks for posting this. I'll definitely try it out (already did actually).
The 'callstack' branches are available on Mathieu's github: https://github.com/compudj/lttng-modules-dev and https://github.com/compudj/lttng-tools-dev
The contexts to add are:
* callstack-kernel
* callstack-user
lttng add-context -k -t callstack-kernel -t callstack-user
Geneviève
Quoted 42 lines · Mathieu Desnoyers
This patchset has been sitting in my dev branches for a while. I think it's time I post it for RFC.
Add callstack contexts for lttng-modules kernel tracer (callstack-user for user-space callstack, and callstack-kernel for kernel callstack). It currently rely on frame pointers for user-space callstacks, so it's normal that we cannot get stack trace for all applications for now. We may want to investigate using unwind information in those situations.
This is a RFC patchset. There are currently no tests for this feature in lttng-tools.
Feedback is welcome!
Thanks,
Mathieu
Francis Giraldeau (3):
Pass arguments for context size computation
Define max nesting count constant
Add kernel and user callstack contextsMathieu Desnoyers (7):
Cleanup callstack context
callstack context: use delimiter when stack is incomplete
Fix: callstack context: false-sharing, bad memory size allocation Fix callstack context: write empty sequence if no stack trace Cleanup callstack context
Fix: callstack context alignment calculation
callstack context: bump number of entries to 128Makefile | 3 +- lib/ringbuffer/frontend.h | 3 + lib/ringbuffer/frontend_api.h | 2 +- lttng-abi.c | 3 + lttng-abi.h | 2 + lttng-context-callstack.c | 361 ++++++++++++++++++++++++++++++++++++++++++ lttng-events.h | 12 ++ lttng-ring-buffer-client.h | 17 +- 8 files changed, 396 insertions(+), 7 deletions(-)
Quoted 2 lines
create mode 100644
lttng-context-callstack.c
_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev