tracing: A few more patches for 5.6
Subsystems (3)
Steven Rostedt
maintainercover tracing: A few more patches for 5.6
Masami Hiramatsu (2):
bootconfig: Allocate xbc_nodes array dynamically tools/bootconfig: Suppress non-error messages
Tom Zanussi (3):
tracing: Add missing nest end to synth_event_trace_start() error case
tracing: Don't return -EINVAL when tracing soft disabled synth events
tracing: Consolidate trace() functions
----
include/linux/trace_events.h | 2 +- kernel/trace/trace_events_hist.c | 227 +++++++++++------------------- lib/bootconfig.c | 15 +- tools/bootconfig/include/linux/memblock.h | 12 ++ tools/bootconfig/main.c | 28 ++-- tools/bootconfig/test-bootconfig.sh | 9 ++ 6 files changed, 134 insertions(+), 159 deletions(-) create mode 100644 tools/bootconfig/include/linux/memblock.h
Steven Rostedt
maintainerPATCH 1/5 bootconfig: Allocate xbc_nodes array dynamically
From: Masami Hiramatsu <[email protected]>
To reduce the large static array from kernel data, allocate xbc_nodes array dynamically only if the kernel loads a bootconfig.
Note that this also add dummy memblock.h for user-spacae bootconfig tool.
--- lib/bootconfig.c | 15 ++++++++++++--- tools/bootconfig/include/linux/memblock.h | 12 ++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 tools/bootconfig/include/linux/memblock.h
lib/bootconfig.c +12 -3
@@ -6,12 +6,13 @@#define pr_fmt (fmt) "bootconfig: " fmt +#include <linux/bootconfig.h> #include <linux/bug.h> #include <linux/ctype.h> #include <linux/errno.h> #include <linux/kernel.h> +#include <linux/memblock.h> #include <linux/printk.h> -#include <linux/bootconfig.h> #include <linux/string.h> /*
@@ -23,7 +24,7 @@* node (for array). */ -static struct xbc_node xbc_nodes[XBC_NODE_MAX ]__initdata ; +static struct xbc_node *xbc_nodes__initdata ;static int xbc_node_num__initdata ;static char *xbc_data__initdata ;static size_t xbc_data_size__initdata ;
@@ -719,7 +720,8 @@ void __init xbc_destroy_all(void) xbc_data =NULL ; xbc_data_size =0 ; xbc_node_num =0 ; -memset (xbc_nodes,0 ,sizeof (xbc_nodes)); +memblock_free (__pa (xbc_nodes),sizeof (struct xbc_node ) *XBC_NODE_MAX ); + xbc_nodes =NULL ; }/**
@@ -748,6 +750,13 @@ int __init xbc_init(char *buf)return -ERANGE ; } + xbc_nodes =memblock_alloc (sizeof (struct xbc_node ) *XBC_NODE_MAX , +SMP_CACHE_BYTES ); +if (!xbc_nodes) { +pr_err ("Failed to allocate memory for bootconfig nodes.\n" ); +return -ENOMEM ; + } +memset (xbc_nodes,0 ,sizeof (struct xbc_node ) *XBC_NODE_MAX ); xbc_data = buf; xbc_data_size = ret +1 ; last_parent =NULL ;
tools/bootconfig/include/linux/memblock.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _XBC_LINUX_MEMBLOCK_H +#define _XBC_LINUX_MEMBLOCK_H + +#include <stdlib.h> + +#define __pa (addr) (addr) +#define SMP_CACHE_BYTES 0 +#define memblock_alloc (size, align) malloc(size) +#define memblock_free (paddr, size) free(paddr) + +#endif
Signature · 1 line
2.24.1
Steven Rostedt
maintainerPATCH 2/5 tools/bootconfig: Suppress non-error messages
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Suppress non-error messages when applying new bootconfig to initrd image. To enable it, replace printf for error message with pr_err() macro.
This also adds a testcase for this fix.
--- tools/bootconfig/main.c | 28 ++++++++++++++-------------- tools/bootconfig/test-bootconfig.sh | 9 +++++++++ 2 files changed, 23 insertions(+), 14 deletions(-)
tools/bootconfig/main.c +14 -14
@@ -140,7 +140,7 @@ int load_xbc_from_initrd(int fd, char **buf)return 0 ;if (lseek (fd,-8 ,SEEK_END ) <0 ) { -printf ("Failed to lseek: %d\n" , -errno); +pr_err ("Failed to lseek: %d\n" , -errno);return -errno; }
@@ -155,7 +155,7 @@ int load_xbc_from_initrd(int fd, char **buf)return 0 ;if (lseek (fd, stat.st_size -8 - size,SEEK_SET ) <0 ) { -printf ("Failed to lseek: %d\n" , -errno); +pr_err ("Failed to lseek: %d\n" , -errno);return -errno; }
@@ -166,7 +166,7 @@ int load_xbc_from_initrd(int fd, char **buf)/* Wrong Checksum, maybe no boot config here */ rcsum =checksum ((unsigned char *)*buf, size);if (csum != rcsum) { -printf ("checksum error: %d != %d\n" , csum, rcsum); +pr_err ("checksum error: %d != %d\n" , csum, rcsum);return 0 ; }
@@ -185,13 +185,13 @@ int show_xbc(const char *path) fd =open (path,O_RDONLY );if (fd <0 ) { -printf ("Failed to open initrd %s: %d\n" , path, fd); +pr_err ("Failed to open initrd %s: %d\n" , path, fd);return -errno; } ret =load_xbc_from_initrd (fd, &buf);if (ret <0 ) -printf ("Failed to load a boot config from initrd: %d\n" , ret); +pr_err ("Failed to load a boot config from initrd: %d\n" , ret);else xbc_show_compact_tree ();
@@ -209,7 +209,7 @@ int delete_xbc(const char *path) fd =open (path,O_RDWR );if (fd <0 ) { -printf ("Failed to open initrd %s: %d\n" , path, fd); +pr_err ("Failed to open initrd %s: %d\n" , path, fd);return -errno; }
@@ -222,7 +222,7 @@ int delete_xbc(const char *path) pr_output =1 ;if (size <0 ) { ret = size; -printf ("Failed to load a boot config from initrd: %d\n" , ret); +pr_err ("Failed to load a boot config from initrd: %d\n" , ret); }else if (size >0 ) { ret =fstat (fd, &stat);if (!ret)
@@ -245,7 +245,7 @@ int apply_xbc(const char *path, const char *xbc_path) ret =load_xbc_file (xbc_path, &buf);if (ret <0 ) { -printf ("Failed to load %s : %d\n" , xbc_path, ret); +pr_err ("Failed to load %s : %d\n" , xbc_path, ret);return ret; } size =strlen (buf) +1 ;
@@ -262,7 +262,7 @@ int apply_xbc(const char *path, const char *xbc_path)/* Check the data format */ ret =xbc_init (buf);if (ret <0 ) { -printf ("Failed to parse %s: %d\n" , xbc_path, ret); +pr_err ("Failed to parse %s: %d\n" , xbc_path, ret);free (data);free (buf);return ret;
@@ -279,20 +279,20 @@ int apply_xbc(const char *path, const char *xbc_path)/* Remove old boot config if exists */ ret =delete_xbc (path);if (ret <0 ) { -printf ("Failed to delete previous boot config: %d\n" , ret); +pr_err ("Failed to delete previous boot config: %d\n" , ret);return ret; }/* Apply new one */ fd =open (path,O_RDWR |O_APPEND );if (fd <0 ) { -printf ("Failed to open %s: %d\n" , path, fd); +pr_err ("Failed to open %s: %d\n" , path, fd);return fd; }/* TODO: Ensure the @path is initramfs/initrd image */ ret =write (fd, data, size +8 );if (ret <0 ) { -printf ("Failed to apply a boot config: %d\n" , ret); +pr_err ("Failed to apply a boot config: %d\n" , ret);return ret; }close (fd);
@@ -334,12 +334,12 @@ int main(int argc, char **argv) }if (apply && delete) { -printf ("Error: You can not specify both -a and -d at once.\n" ); +pr_err ("Error: You can not specify both -a and -d at once.\n" );return usage (); }if (optind >= argc) { -printf ("Error: No initrd is specified.\n" ); +pr_err ("Error: No initrd is specified.\n" );return usage (); }
tools/bootconfig/test-bootconfig.sh +9 -0
@@ -64,6 +64,15 @@ echo "File size check" new_size=$(stat -c %s $INITRD) xpass test $new_size -eq $initrd_size +echo "No error messge while applying" +OUTFILE=`mktemp tempout-XXXX` +dd if=/dev/zero of=$INITRD bs=4096 count=1 +printf " \0\0\0 \0\0\0" >> $INITRD +$BOOTCONF -a $TEMPCONF $INITRD > $OUTFILE 2>&1 +xfail grep -i "failed" $OUTFILE +xfail grep -i "error" $OUTFILE +rm $OUTFILE + echo "Max node number check" echo -n > $TEMPCONF
Signature · 1 line
2.24.1
Steven Rostedt
maintainerPATCH 3/5 tracing: Add missing nest end to synth_event_trace_start() error case
In reply to Steven RostedtFrom: Tom Zanussi <[email protected]>
If the ring_buffer reserve in synth_event_trace_start() fails, the matching ring_buffer_nest_end() should be called in the error code, since nothing else will ever call it in this case.
--- kernel/trace/trace_events_hist.c | 1 + 1 file changed, 1 insertion(+)
kernel/trace/trace_events_hist.c +1 -0
@@ -2043,6 +2043,7 @@ int synth_event_trace_start(struct trace_event_file *file, entry =trace_event_buffer_reserve (&trace_state->fbuffer, file,sizeof (*entry) + fields_size);if (!entry) { +ring_buffer_nest_end (trace_state->buffer); ret = -EINVAL ; goto out; }
Signature · 1 line
2.24.1
Steven Rostedt
maintainerPATCH 4/5 tracing: Dont return -EINVAL when tracing soft disabled synth events
In reply to Steven RostedtFrom: Tom Zanussi <[email protected]>
There's no reason to return -EINVAL when tracing a synthetic event if it's soft disabled - treat it the same as if it were hard disabled and return normally.
Have synth_event_trace() and synth_event_trace_array() just return normally, and have synth_event_trace_start set the trace state to disabled and return.
--- kernel/trace/trace_events_hist.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-)
kernel/trace/trace_events_hist.c +6 -14
@@ -1828,7 +1828,8 @@ int synth_event_trace(struct trace_event_file *file, unsigned int n_vals, ...)* called directly by the user, we don't have that but we * still need to honor not logging when disabled. */ -if (!(file->flags &EVENT_FILE_FL_ENABLED )) +if (!(file->flags &EVENT_FILE_FL_ENABLED ) || +trace_trigger_soft_disabled (file))return 0 ; event = file->event_call->data;
@@ -1836,9 +1837,6 @@ int synth_event_trace(struct trace_event_file *file, unsigned int n_vals, ...)if (n_vals != event->n_fields)return -EINVAL ; -if (trace_trigger_soft_disabled (file)) -return -EINVAL ; - fields_size = event->n_u64 *sizeof (u64);/*
@@ -1918,7 +1916,8 @@ int synth_event_trace_array(struct trace_event_file *file, u64 *vals,* called directly by the user, we don't have that but we * still need to honor not logging when disabled. */ -if (!(file->flags &EVENT_FILE_FL_ENABLED )) +if (!(file->flags &EVENT_FILE_FL_ENABLED ) || +trace_trigger_soft_disabled (file))return 0 ; event = file->event_call->data;
@@ -1926,9 +1925,6 @@ int synth_event_trace_array(struct trace_event_file *file, u64 *vals,if (n_vals != event->n_fields)return -EINVAL ; -if (trace_trigger_soft_disabled (file)) -return -EINVAL ; - fields_size = event->n_u64 *sizeof (u64);/*
@@ -2017,7 +2013,8 @@ int synth_event_trace_start(struct trace_event_file *file,* trace case, we save the enabed state upon start and just * ignore the following data calls. */ -if (!(file->flags &EVENT_FILE_FL_ENABLED )) { +if (!(file->flags &EVENT_FILE_FL_ENABLED ) || +trace_trigger_soft_disabled (file)) { trace_state->enabled = false; goto out; }
@@ -2026,11 +2023,6 @@ int synth_event_trace_start(struct trace_event_file *file, trace_state->event = file->event_call->data; -if (trace_trigger_soft_disabled (file)) { - ret = -EINVAL ; - goto out; - } - fields_size = trace_state->event->n_u64 *sizeof (u64);/*
Signature · 1 line
2.24.1
Steven Rostedt
maintainerPATCH 5/5 tracing: Consolidate trace() functions
In reply to Steven RostedtFrom: Tom Zanussi <[email protected]>
Move the checking, buffer reserve and buffer commit code in synth_event_trace_start/end() into inline functions __synth_event_trace_start/end() so they can also be used by synth_event_trace() and synth_event_trace_array(), and then have all those functions use them.
Also, change synth_event_trace_state.enabled to disabled so it only needs to be set if the event is disabled, which is not normally the case.
--- include/linux/trace_events.h | 2 +- kernel/trace/trace_events_hist.c | 220 ++++++++++++------------------- 2 files changed, 87 insertions(+), 135 deletions(-)
include/linux/trace_events.h +1 -1
@@ -424,7 +424,7 @@ struct synth_event_trace_state {struct synth_event *event;unsigned int cur_field;unsigned int n_u64; -bool enabled; +bool disabled;bool add_next;bool add_name; };
kernel/trace/trace_events_hist.c +86 -134
294 lines not on this page · raw message
Signature · 1 line
2.24.1