Few patches, backported from Arnaldo's kernel repo
cover Few patches, backported from Arnaldo's kernel repo
Few patches, backported from Arnaldo's kernel repo. The patch series was merged upstream on 8th of Januari.
Tzvetomir Stoyanov (6):
trace-cmd: Initialize host_bigendian at tep_handle allocation
trace_cmd: Rename struct cmdline to struct tep_cmdline
trace-cmd: Changed return logic of trace_seq_printf() and
trace_seq_vprintf() APIs
trace-cmd: Changed return logic of tep_register_event_handler() API
trace-cmd: Rename tep_is_file_bigendian() to tep_file_bigendian()
trace-cmd: Remove tep_data_event_from_type() API
include/traceevent/event-parse.h | 16 +++++--- kernel-shark/src/libkshark.c | 7 ++-- lib/trace-cmd/trace-input.c | 8 ++-- lib/traceevent/event-parse-api.c | 4 +- lib/traceevent/event-parse-local.h | 4 +- lib/traceevent/event-parse.c | 62 ++++++++++++++---------------- lib/traceevent/trace-seq.c | 17 +++++--- plugins/plugin_kvm.c | 2 +- python/tracecmd.py | 10 ++--- tracecmd/trace-hist.c | 4 +- tracecmd/trace-mem.c | 2 +- tracecmd/trace-output.c | 2 +- tracecmd/trace-read.c | 7 ++-- tracecmd/trace-record.c | 2 +- tracecmd/trace-split.c | 2 +- 15 files changed, 78 insertions(+), 71 deletions(-)
Signature · 1 line
2.20.1
PATCH 1/6 trace-cmd: Initialize host_bigendian at tep_handle allocation
This patch initializes the host_bigendian member of the tep_handle structure with the byte order of the current host, when this handler is created - in tep_alloc() API. We need this in order to remove the tep_set_host_bigendian() API.
--- lib/traceevent/event-parse.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
lib/traceevent/event-parse.c +3 -1
@@ -6829,8 +6829,10 @@ struct tep_handle *tep_alloc(void) {struct tep_handle *pevent =calloc (1 ,sizeof (*pevent)); -if (pevent) +if (pevent) { pevent->ref_count =1 ; + pevent->host_bigendian =tep_host_bigendian (); + }return pevent; }
Signature · 1 line
2.20.1
PATCH 2/6 trace_cmd: Rename struct cmdline to struct tep_cmdline
In reply to Tzvetomir StoyanovIn order to make libtraceevent a proper library, variables, data structures and functions should have a unique prefix to prevent name space conflicts. That prefix will be "tep_".
This patch renames 'struct cmdline' to 'struct tep_cmdline'.
--- include/traceevent/event-parse.h | 8 +++---- lib/traceevent/event-parse-local.h | 4 ++-- lib/traceevent/event-parse.c | 36 +++++++++++++++--------------- tracecmd/trace-read.c | 3 ++- 4 files changed, 26 insertions(+), 25 deletions(-)
include/traceevent/event-parse.h +4 -4
@@ -515,10 +515,10 @@ int tep_data_pid(struct tep_handle *pevent, struct tep_record *rec);int tep_data_preempt_count (struct tep_handle *pevent,struct tep_record *rec);int tep_data_flags (struct tep_handle *pevent,struct tep_record *rec);const char *tep_data_comm_from_pid (struct tep_handle *pevent,int pid); -struct cmdline ; -struct cmdline *tep_data_pid_from_comm (struct tep_handle *pevent,const char *comm, -struct cmdline *next); -int tep_cmdline_pid (struct tep_handle *pevent,struct cmdline *cmdline); +struct tep_cmdline ; +struct tep_cmdline *tep_data_pid_from_comm (struct tep_handle *pevent,const char *comm, +struct tep_cmdline *next); +int tep_cmdline_pid (struct tep_handle *pevent,struct tep_cmdline *cmdline);void tep_print_field (struct trace_seq *s,void *data,struct tep_format_field *field);
lib/traceevent/event-parse-local.h +2 -2
@@ -7,7 +7,7 @@#ifndef _PARSE_EVENTS_INT_H#define _PARSE_EVENTS_INT_H -struct cmdline ; +struct tep_cmdline ;struct cmdline_list ;struct func_map ;struct func_list ;
@@ -36,7 +36,7 @@ struct tep_handle {int long_size;int page_size; -struct cmdline *cmdlines; +struct tep_cmdline *cmdlines;struct cmdline_list *cmdlist;int cmdline_count;
lib/traceevent/event-parse.c +18 -18
@@ -124,15 +124,15 @@ struct tep_print_arg *alloc_arg(void)return calloc (1 ,sizeof (struct tep_print_arg )); } -struct cmdline { +struct tep_cmdline {char *comm;int pid; };static int cmdline_cmp (const void *a,const void *b) { -const struct cmdline *ca = a; -const struct cmdline *cb = b; +const struct tep_cmdline *ca = a; +const struct tep_cmdline *cb = b;if (ca->pid < cb->pid)return -1 ;
@@ -152,7 +152,7 @@ static int cmdline_init(struct tep_handle *pevent) {struct cmdline_list *cmdlist = pevent->cmdlist;struct cmdline_list *item; -struct cmdline *cmdlines; +struct tep_cmdline *cmdlines;int i; cmdlines =malloc (sizeof (*cmdlines) * pevent->cmdline_count);
@@ -179,8 +179,8 @@ static int cmdline_init(struct tep_handle *pevent)static const char *find_cmdline (struct tep_handle *pevent,int pid) { -const struct cmdline *comm; -struct cmdline key; +const struct tep_cmdline *comm; +struct tep_cmdline key;if (!pid)return "<idle>" ;
@@ -208,8 +208,8 @@ static const char *find_cmdline(struct tep_handle *pevent, int pid)*/ int tep_pid_is_registered (struct tep_handle *pevent,int pid) { -const struct cmdline *comm; -struct cmdline key; +const struct tep_cmdline *comm; +struct tep_cmdline key;if (!pid)return 1 ;
@@ -235,9 +235,9 @@ int tep_pid_is_registered(struct tep_handle *pevent, int pid)static int add_new_comm (struct tep_handle *pevent,const char *comm,int pid,bool override) { -struct cmdline *cmdlines = pevent->cmdlines; -struct cmdline *cmdline; -struct cmdline key; +struct tep_cmdline *cmdlines = pevent->cmdlines; +struct tep_cmdline *cmdline; +struct tep_cmdline key;char *new_comm;if (!pid)
@@ -5332,8 +5332,8 @@ const char *tep_data_comm_from_pid(struct tep_handle *pevent, int pid)return comm; } -static struct cmdline * -pid_from_cmdlist (struct tep_handle *pevent,const char *comm,struct cmdline *next) +static struct tep_cmdline * +pid_from_cmdlist (struct tep_handle *pevent,const char *comm,struct tep_cmdline *next) {struct cmdline_list *cmdlist = (struct cmdline_list *)next;
@@ -5345,7 +5345,7 @@ pid_from_cmdlist(struct tep_handle *pevent, const char *comm, struct cmdline *newhile (cmdlist &&strcmp (cmdlist->comm, comm) !=0 ) cmdlist = cmdlist->next; -return (struct cmdline *)cmdlist; +return (struct tep_cmdline *)cmdlist; }/**
@@ -5361,10 +5361,10 @@ pid_from_cmdlist(struct tep_handle *pevent, const char *comm, struct cmdline *ne* next pid. * Also, it does a linear search, so it may be slow. */ -struct cmdline *tep_data_pid_from_comm (struct tep_handle *pevent,const char *comm, -struct cmdline *next) +struct tep_cmdline *tep_data_pid_from_comm (struct tep_handle *pevent,const char *comm, +struct tep_cmdline *next) { -struct cmdline *cmdline; +struct tep_cmdline *cmdline;/* * If the cmdlines have not been converted yet, then use
@@ -5403,7 +5403,7 @@ struct cmdline *tep_data_pid_from_comm(struct tep_handle *pevent, const char *co* Returns the pid for a give cmdline. If @cmdline is NULL, then * -1 is returned. */ -int tep_cmdline_pid (struct tep_handle *pevent,struct cmdline *cmdline) +int tep_cmdline_pid (struct tep_handle *pevent,struct tep_cmdline *cmdline) {struct cmdline_list *cmdlist = (struct cmdline_list *)cmdline;
tracecmd/trace-read.c +2 -1
@@ -419,9 +419,10 @@ static char *append_pid_filter(char *curr_filter, char *pid)static void convert_comm_filter (struct tracecmd_input *handle) { +struct tep_cmdline *cmdline;struct tep_handle *pevent;struct pid_list *list; -struct cmdline *cmdline; +char pidstr[100 ];if (!comm_list)
Signature · 1 line
2.20.1
PATCH 3/6 trace-cmd: Changed return logic of trace_seq_printf() and trace_seq_vprintf() APIs
In reply to Tzvetomir StoyanovIn order to make libtraceevent into a proper library, its API should be straightforward.
The trace_seq_printf() and trace_seq_vprintf() APIs have inconsistent returned values with the other trace_seq_* APIs.
This path changes the return logic of trace_seq_printf() and trace_seq_vprintf() to return the number of printed characters, as the other trace_seq_* related APIs.
--- lib/traceevent/trace-seq.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
lib/traceevent/trace-seq.c +12 -5
@@ -100,7 +100,8 @@ static void expand_buffer(struct trace_seq *s)* @fmt: printf format string * * It returns 0 if the trace oversizes the buffer's free -* space, 1 otherwise. +* space, the number of characters printed, or a negative +* value in case of an error. * * The tracer may use either sequence operations or its own * copy to user routines. To simplify formating of a trace
@@ -129,9 +130,10 @@ trace_seq_printf(struct trace_seq *s, const char *fmt, ...) goto try_again; } - s->len += ret; +if (ret >0 ) + s->len += ret; -return 1 ; +return ret; }/**
@@ -139,6 +141,10 @@ trace_seq_printf(struct trace_seq *s, const char *fmt, ...)* @s: trace sequence descriptor * @fmt: printf format string * +* It returns 0 if the trace oversizes the buffer's free +* space, the number of characters printed, or a negative +* value in case of an error. +* * * The tracer may use either sequence operations or its own * copy to user routines. To simplify formating of a trace * trace_seq_printf is used to store strings into a special
@@ -163,9 +169,10 @@ trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args) goto try_again; } - s->len += ret; +if (ret >0 ) + s->len += ret; -return len; +return ret; }/**
Signature · 1 line
2.20.1
PATCH 4/6 trace-cmd: Changed return logic of tep_register_event_handler() API
In reply to Tzvetomir StoyanovIn order to make libtraceevent into a proper library, its API should be straightforward.
The tep_register_event_handler() functions returns -1 in case it successfully registers the new event handler. Such return code is used by the other library APIs in case of an error.
To unify the return logic of tep_register_event_handler() with the other APIs, this patch introduces enum tep_reg_handler, which is used by this function as return value, to handle all possible successful return cases.
--- include/traceevent/event-parse.h | 5 +++++ lib/traceevent/event-parse.c | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-)
include/traceevent/event-parse.h +5 -0
@@ -473,6 +473,11 @@ int tep_print_func_field(struct trace_seq *s, const char *fmt, struct tep_event *event, const char *name, struct tep_record *record, int err); +enum tep_reg_handler { +TEP_REGISTER_SUCCESS =0 , +TEP_REGISTER_SUCCESS_OVERWRITE , +}; +int tep_register_event_handler (struct tep_handle *pevent,int id,const char *sys_name,const char *event_name,tep_event_handler_func func,void *context);
lib/traceevent/event-parse.c +8 -2
@@ -6699,6 +6699,12 @@ static struct tep_event *search_event(struct tep_handle *pevent, int id,* * If @id is >= 0, then it is used to find the event. * else @sys_name and @event_name are used. +* +* Returns: +* TEP_REGISTER_SUCCESS_OVERWRITE if an existing handler is overwritten +* TEP_REGISTER_SUCCESS if a new handler is registered successfully +* negative TEP_ERRNO_... in case of an error +* */ int tep_register_event_handler(struct tep_handle *pevent, int id, const char *sys_name, const char *event_name,
@@ -6716,7 +6722,7 @@ int tep_register_event_handler(struct tep_handle *pevent, int id, event->handler = func; event->context = context; -return 0 ; +return TEP_REGISTER_SUCCESS_OVERWRITE ; not_found:/* Save for later use. */
@@ -6746,7 +6752,7 @@ int tep_register_event_handler(struct tep_handle *pevent, int id, pevent->handlers = handle; handle->context = context; -return -1 ; +return TEP_REGISTER_SUCCESS ; } static int handle_matches(struct event_handler *handler, int id,
Signature · 1 line
2.20.1
PATCH 5/6 trace-cmd: Rename tep_is_file_bigendian() to tep_file_bigendian()
In reply to Tzvetomir StoyanovIn order to make libtraceevent into a proper library, its API should be straightforward.
After a discussion with Steven Rostedt, we decided to rename a few APIs, to have more intuitive names.
This patch renames tep_is_file_bigendian() to tep_file_bigendian().
--- include/traceevent/event-parse.h | 2 +- lib/trace-cmd/trace-input.c | 8 ++++---- lib/traceevent/event-parse-api.c | 4 ++-- plugins/plugin_kvm.c | 2 +- python/tracecmd.py | 2 +- tracecmd/trace-output.c | 2 +- tracecmd/trace-read.c | 4 ++-- tracecmd/trace-split.c | 2 +- 8 files changed, 13 insertions(+), 13 deletions(-)
include/traceevent/event-parse.h +1 -1
@@ -551,7 +551,7 @@ int tep_get_long_size(struct tep_handle *pevent);void tep_set_long_size (struct tep_handle *pevent,int long_size);int tep_get_page_size (struct tep_handle *pevent);void tep_set_page_size (struct tep_handle *pevent,int _page_size); -int tep_is_file_bigendian (struct tep_handle *pevent); +int tep_file_bigendian (struct tep_handle *pevent);void tep_set_file_bigendian (struct tep_handle *pevent,enum tep_endian endian);int tep_is_host_bigendian (struct tep_handle *pevent);void tep_set_host_bigendian (struct tep_handle *pevent,enum tep_endian endian);
lib/trace-cmd/trace-input.c +4 -4
@@ -1619,7 +1619,7 @@ tracecmd_translate_data(struct tracecmd_input *handle,memset (record,0 ,sizeof (*record)); record->ref_count =1 ; -if (tep_is_host_bigendian (pevent) ==tep_is_file_bigendian (pevent)) +if (tep_is_host_bigendian (pevent) ==tep_file_bigendian (pevent)) swap =0 ; record->data =kbuffer_translate_data (swap, ptr, &length); record->size = length;
@@ -1661,7 +1661,7 @@ tracecmd_read_page_record(struct tep_handle *pevent, void *page, int size,enum kbuffer_endian endian;void *ptr; -if (tep_is_file_bigendian (pevent)) +if (tep_file_bigendian (pevent)) endian =KBUFFER_ENDIAN_BIG ;else endian =KBUFFER_ENDIAN_LITTLE ;
@@ -2266,7 +2266,7 @@ static int read_cpu_data(struct tracecmd_input *handle)else long_size =KBUFFER_LSIZE_4 ; -if (tep_is_file_bigendian (handle->pevent)) +if (tep_file_bigendian (handle->pevent)) endian =KBUFFER_ENDIAN_BIG ;else endian =KBUFFER_ENDIAN_LITTLE ;
@@ -2475,7 +2475,7 @@ int tracecmd_make_pipe(struct tracecmd_input *handle, int cpu, int fd, int cpus)else long_size =KBUFFER_LSIZE_4 ; -if (tep_is_file_bigendian (handle->pevent)) +if (tep_file_bigendian (handle->pevent)) endian =KBUFFER_ENDIAN_BIG ;else endian =KBUFFER_ENDIAN_LITTLE ;
lib/traceevent/event-parse-api.c +2 -2
@@ -250,13 +250,13 @@ void tep_set_page_size(struct tep_handle *pevent, int _page_size) }/** -* tep_is_file_bigendian - get if the file is in big endian order +* tep_file_bigendian - get if the file is in big endian order * @pevent: a handle to the tep_handle * * This returns if the file is in big endian order * If @pevent is NULL, 0 is returned. */ -int tep_is_file_bigendian (struct tep_handle *pevent) +int tep_file_bigendian (struct tep_handle *pevent) {if (pevent)return pevent->file_bigendian;
plugins/plugin_kvm.c +1 -1
@@ -386,7 +386,7 @@ static int kvm_mmu_print_role(struct trace_seq *s, struct tep_record *record,* We can only use the structure if file is of the same * endianness. */ -if (tep_is_file_bigendian (event->pevent) == +if (tep_file_bigendian (event->pevent) ==tep_is_host_bigendian (event->pevent)) { trace_seq_printf(s, "%u/%u q%u%s %s%s %spge %snxe",
python/tracecmd.py +1 -1
@@ -166,7 +166,7 @@ class PEvent(object): @cached_property def file_endian(self): - if tep_is_file_bigendian(self._pevent): + if tep_file_bigendian(self._pevent): return '>' return '<'
tracecmd/trace-output.c +1 -1
@@ -808,7 +808,7 @@ create_file_fd(int fd, struct tracecmd_input *ihandle,/* Use the pevent of the ihandle for later writes */ handle->pevent =tracecmd_get_pevent (ihandle);tep_ref (pevent); -if (tep_is_file_bigendian (pevent)) +if (tep_file_bigendian (pevent)) buf[0 ] =1 ;else buf[0 ] =0 ;
tracecmd/trace-read.c +2 -2
@@ -1700,8 +1700,8 @@ void trace_report (int argc, char **argv)if (show_endian) {printf ("file is %s endian and host is %s endian\n" , -tep_is_file_bigendian (pevent) ?"big" :"little" , -tep_is_host_bigendian (pevent) ?"big" :"little" ); +tep_file_bigendian (pevent) ?"big" :"little" , +tep_is_host_bigendian (pevent) ?"big" :"little" );return ; }
tracecmd/trace-split.c +1 -1
@@ -64,7 +64,7 @@ static int create_type_len(struct tep_handle *pevent, int time, int len) bigendian =1 ; } -if (tep_is_file_bigendian (pevent)) +if (tep_file_bigendian (pevent)) time |= (len <<27 );else time = (time <<5 ) | len;
Signature · 1 line
2.20.1
PATCH 6/6 trace-cmd: Remove tep_data_event_from_type() API
In reply to Tzvetomir StoyanovIn order to make libtraceevent into a proper library, its API should be straightforward.
After discussion with Steven Rostedt, we decided to remove the tep_data_event_from_type() API and to replace it with tep_find_event(), as it does the same.
--- include/traceevent/event-parse.h | 1 - kernel-shark/src/libkshark.c | 7 +++---- lib/traceevent/event-parse.c | 12 ------------ python/tracecmd.py | 8 ++++---- tracecmd/trace-hist.c | 4 ++-- tracecmd/trace-mem.c | 2 +- tracecmd/trace-record.c | 2 +- 7 files changed, 11 insertions(+), 25 deletions(-)
include/traceevent/event-parse.h +0 -1
@@ -515,7 +515,6 @@ tep_find_event_by_record(struct tep_handle *pevent, struct tep_record *record);void tep_data_lat_fmt (struct tep_handle *pevent,struct trace_seq *s,struct tep_record *record);int tep_data_type (struct tep_handle *pevent,struct tep_record *rec); -struct tep_event *tep_data_event_from_type (struct tep_handle *pevent,int type);int tep_data_pid (struct tep_handle *pevent,struct tep_record *rec);int tep_data_preempt_count (struct tep_handle *pevent,struct tep_record *rec);int tep_data_flags (struct tep_handle *pevent,struct tep_record *rec);
kernel-shark/src/libkshark.c +3 -4
@@ -1187,7 +1187,7 @@ const char *kshark_get_event_name_easy(struct kshark_entry *entry)* Use a mutex to protect the access. */ pthread_mutex_lock (&kshark_ctx->input_mutex); - event =tep_data_event_from_type (kshark_ctx->pevent, event_id); + event =tep_find_event (kshark_ctx->pevent, event_id);pthread_mutex_unlock (&kshark_ctx->input_mutex);if (event)
@@ -1236,7 +1236,7 @@ const char *kshark_get_info_easy(struct kshark_entry *entry) data =tracecmd_read_at (kshark_ctx->handle, entry->offset,NULL ); event_id =tep_data_type (kshark_ctx->pevent, data); - event =tep_data_event_from_type (kshark_ctx->pevent, event_id); + event =tep_find_event (kshark_ctx->pevent, event_id);if (event) info =kshark_get_info (kshark_ctx->pevent, data, event);
@@ -1330,8 +1330,7 @@ char* kshark_dump_entry(const struct kshark_entry *entry) data =tracecmd_read_at (kshark_ctx->handle, entry->offset,NULL ); - event =tep_data_event_from_type (kshark_ctx->pevent, - entry->event_id); + event =tep_find_event (kshark_ctx->pevent, entry->event_id); event_name = event? event->name :"[UNKNOWN EVENT]" ; lat =kshark_get_latency (kshark_ctx->pevent, data);
lib/traceevent/event-parse.c +0 -12
@@ -5266,18 +5266,6 @@ int tep_data_type(struct tep_handle *pevent, struct tep_record *rec)return trace_parse_common_type (pevent, rec->data); } -/** -* tep_data_event_from_type - find the event by a given type -* @pevent: a handle to the pevent -* @type: the type of the event. -* -* This returns the event form a given @type; -*/ -struct tep_event *tep_data_event_from_type (struct tep_handle *pevent,int type) -{ -return tep_find_event (pevent, type); -} -/** * tep_data_pid - parse the PID from record * @pevent: a handle to the pevent
python/tracecmd.py +4 -4
@@ -204,7 +204,7 @@ class Trace(object): rec = tracecmd_read_data(self._handle, cpu) if rec: type = tep_data_type(self._pevent, rec) - format = tep_data_event_from_type(self._pevent, type) + format = tep_find_event(self._pevent, type) # rec ownership goes over to Event instance return Event(self._pevent, rec, format) return None
@@ -216,7 +216,7 @@ class Trace(object): return None rec, cpu = res type = tep_data_type(self._pevent, rec) - format = tep_data_event_from_type(self._pevent, type) + format = tep_find_event(self._pevent, type) # rec ownership goes over to Event instance return Event(self._pevent, rec, format)
@@ -226,7 +226,7 @@ class Trace(object): return None rec, cpu = res type = tep_data_type(self._pevent, rec) - format = tep_data_event_from_type(self._pevent, type) + format = tep_find_event(self._pevent, type) return Event(self._pevent, rec, format) def peek_event(self, cpu):
@@ -234,7 +234,7 @@ class Trace(object): if rec is None: return None type = tep_data_type(self._pevent, rec) - format = tep_data_event_from_type(self._pevent, type) + format = tep_find_event(self._pevent, type) # rec ownership goes over to Event instance return Event(self._pevent, rec, format)
tracecmd/trace-hist.c +2 -2
@@ -541,7 +541,7 @@ process_event(struct tep_handle *pevent, struct tep_record *record, int type)reset_pending_stack (); } - event =tep_data_event_from_type (pevent, type); + event =tep_find_event (pevent, type); event_name = event->name; ret =tep_read_number_field (common_pid_field, record->data, &val);
@@ -952,7 +952,7 @@ static void do_trace_hist(struct tracecmd_input *handle)die ("No records found in file" ); ret =tep_data_type (pevent, record); - event =tep_data_event_from_type (pevent, ret); + event =tep_find_event (pevent, ret); long_size =tracecmd_long_size (handle);
tracecmd/trace-mem.c +1 -1
@@ -488,7 +488,7 @@ static void do_trace_mem(struct tracecmd_input *handle)die ("No records found in file" ); ret =tep_data_type (pevent, record); - event =tep_data_event_from_type (pevent, ret); + event =tep_find_event (pevent, ret); common_type_field =tep_find_common_field (event,"common_type" );if (!common_type_field)
tracecmd/trace-record.c +1 -1
@@ -3402,7 +3402,7 @@ find_ts_in_page(struct tep_handle *pevent, void *page, int size)break ;free_record (last_record); id =tep_data_type (pevent, record); - event =tep_data_event_from_type (pevent, id); + event =tep_find_event (pevent, id);if (event) {/* Make sure this is our event */ field =tep_find_field (event,"buf" );
Signature · 1 line
2.20.1