Re: [PATCH v5 2/4] tracing: Add cpu as a key field in histogram

2016-09-04 Thread Daniel Wagner
Hi Binoy

On 09/02/2016 02:37 PM, Binoy Jayan wrote:
> The field 'cpu' although part of the set of generic fields, is not made
> part of the key fields when mentioned in the trigger command. This hack
> suggested by Daniel marks it as one of the key fields and make it appear
> in the histogram output.

While you are at it, why not adding the COMM as well? I know there is
already the common_pid.execname. With only a few extra lines we get COMM
as well and it allows to write something like

hist:key=cpu,comm:sort=cpu,comm

for example.

cheers,
daniel



>From cc2f610078ebe9ba8d850cbf602aa529df690cdb Mon Sep 17 00:00:00 2001
From: Daniel Wagner 
Date: Wed, 31 Aug 2016 09:37:38 +0200
Subject: [PATCH] tracing: Add hist trigger support for generic fields

Whenever a trace is printed the generic fields (CPU, COMM) are
reconstructed (see trace_print_context()). CPU is taken from the
trace_iterator and COMM is extracted from the savedcmd map (see
__trace_find_cmdline()).

We can't reconstruct this information for hist events. Therefore this
information needs to stored when a new event is added to the hist
buffer.

There is already support for extracting the COMM for the common_pid
field. For this the tracing_map_ops infrasture is used. Unfortantly, we
can't reuse it because it extends an existing hist_field. That means we
first need to add a hist_field before we are able to make reuse of
trace_map_ops.

Furthermore, it is quite easy to extend the current code to support
those two fields by adding hist_field_cpu() and hist_field_comm().

Signed-off-by: Daniel Wagner 
Cc: Steven Rostedt 
Cc: Tom Zanussi 
Cc: Binoy Jayan 
---
 kernel/trace/trace.h |  6 ++
 kernel/trace/trace_events.c  | 13 +++--
 kernel/trace/trace_events_hist.c | 31 ---
 3 files changed, 41 insertions(+), 9 deletions(-)

diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
index f783df4..2b8889b 100644
--- a/kernel/trace/trace.h
+++ b/kernel/trace/trace.h
@@ -1288,6 +1288,12 @@ static inline bool is_function_field(struct 
ftrace_event_field *field)
return field->filter_type == FILTER_TRACE_FN;
 }
 
+static inline bool is_generic_field(struct ftrace_event_field *field)
+{
+   return field->filter_type == FILTER_CPU ||
+  field->filter_type == FILTER_COMM;
+}
+
 extern enum regex_type
 filter_parse_regex(char *buff, int len, char **search, int *not);
 extern void print_event_filter(struct trace_event_file *file,
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 03c0a48..7d9154d 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -150,9 +150,10 @@ int trace_define_field(struct trace_event_call *call, 
const char *type,
 }
 EXPORT_SYMBOL_GPL(trace_define_field);
 
-#define __generic_field(type, item, filter_type)   \
+#define __generic_field(type, item, filter_type, size) \
ret = __trace_define_field(_generic_fields, #type,   \
-  #item, 0, 0, is_signed_type(type),   \
+  #item, 0, size,  \
+  is_signed_type(type),\
   filter_type);\
if (ret)\
return ret;
@@ -170,10 +171,10 @@ static int trace_define_generic_fields(void)
 {
int ret;
 
-   __generic_field(int, CPU, FILTER_CPU);
-   __generic_field(int, cpu, FILTER_CPU);
-   __generic_field(char *, COMM, FILTER_COMM);
-   __generic_field(char *, comm, FILTER_COMM);
+   __generic_field(int, CPU, FILTER_CPU, sizeof(int));
+   __generic_field(int, cpu, FILTER_CPU, sizeof(int));
+   __generic_field(char *, COMM, FILTER_COMM, TASK_COMM_LEN + 1);
+   __generic_field(char *, comm, FILTER_COMM, TASK_COMM_LEN + 1);
 
return ret;
 }
diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
index f3a960e..0b40f22 100644
--- a/kernel/trace/trace_events_hist.c
+++ b/kernel/trace/trace_events_hist.c
@@ -75,6 +75,16 @@ static u64 hist_field_log2(struct hist_field *hist_field, 
void *event)
return (u64) ilog2(roundup_pow_of_two(val));
 }
 
+static u64 hist_field_cpu(struct hist_field *hist_field, void *event)
+{
+   return (u64) smp_processor_id();
+}
+
+static u64 hist_field_comm(struct hist_field *hist_field, void *event)
+{
+   return (u64)(unsigned long)current->comm;
+}
+
 #define DEFINE_HIST_FIELD_FN(type) \
 static u64 hist_field_##type(struct hist_field *hist_field, void *event)\
 {  \
@@ -119,6 +129,7 @@ enum hist_field_flags {

Re: [PATCH v5 2/4] tracing: Add cpu as a key field in histogram

2016-09-04 Thread Daniel Wagner
Hi Binoy

On 09/02/2016 02:37 PM, Binoy Jayan wrote:
> The field 'cpu' although part of the set of generic fields, is not made
> part of the key fields when mentioned in the trigger command. This hack
> suggested by Daniel marks it as one of the key fields and make it appear
> in the histogram output.

While you are at it, why not adding the COMM as well? I know there is
already the common_pid.execname. With only a few extra lines we get COMM
as well and it allows to write something like

hist:key=cpu,comm:sort=cpu,comm

for example.

cheers,
daniel



>From cc2f610078ebe9ba8d850cbf602aa529df690cdb Mon Sep 17 00:00:00 2001
From: Daniel Wagner 
Date: Wed, 31 Aug 2016 09:37:38 +0200
Subject: [PATCH] tracing: Add hist trigger support for generic fields

Whenever a trace is printed the generic fields (CPU, COMM) are
reconstructed (see trace_print_context()). CPU is taken from the
trace_iterator and COMM is extracted from the savedcmd map (see
__trace_find_cmdline()).

We can't reconstruct this information for hist events. Therefore this
information needs to stored when a new event is added to the hist
buffer.

There is already support for extracting the COMM for the common_pid
field. For this the tracing_map_ops infrasture is used. Unfortantly, we
can't reuse it because it extends an existing hist_field. That means we
first need to add a hist_field before we are able to make reuse of
trace_map_ops.

Furthermore, it is quite easy to extend the current code to support
those two fields by adding hist_field_cpu() and hist_field_comm().

Signed-off-by: Daniel Wagner 
Cc: Steven Rostedt 
Cc: Tom Zanussi 
Cc: Binoy Jayan 
---
 kernel/trace/trace.h |  6 ++
 kernel/trace/trace_events.c  | 13 +++--
 kernel/trace/trace_events_hist.c | 31 ---
 3 files changed, 41 insertions(+), 9 deletions(-)

diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
index f783df4..2b8889b 100644
--- a/kernel/trace/trace.h
+++ b/kernel/trace/trace.h
@@ -1288,6 +1288,12 @@ static inline bool is_function_field(struct 
ftrace_event_field *field)
return field->filter_type == FILTER_TRACE_FN;
 }
 
+static inline bool is_generic_field(struct ftrace_event_field *field)
+{
+   return field->filter_type == FILTER_CPU ||
+  field->filter_type == FILTER_COMM;
+}
+
 extern enum regex_type
 filter_parse_regex(char *buff, int len, char **search, int *not);
 extern void print_event_filter(struct trace_event_file *file,
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 03c0a48..7d9154d 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -150,9 +150,10 @@ int trace_define_field(struct trace_event_call *call, 
const char *type,
 }
 EXPORT_SYMBOL_GPL(trace_define_field);
 
-#define __generic_field(type, item, filter_type)   \
+#define __generic_field(type, item, filter_type, size) \
ret = __trace_define_field(_generic_fields, #type,   \
-  #item, 0, 0, is_signed_type(type),   \
+  #item, 0, size,  \
+  is_signed_type(type),\
   filter_type);\
if (ret)\
return ret;
@@ -170,10 +171,10 @@ static int trace_define_generic_fields(void)
 {
int ret;
 
-   __generic_field(int, CPU, FILTER_CPU);
-   __generic_field(int, cpu, FILTER_CPU);
-   __generic_field(char *, COMM, FILTER_COMM);
-   __generic_field(char *, comm, FILTER_COMM);
+   __generic_field(int, CPU, FILTER_CPU, sizeof(int));
+   __generic_field(int, cpu, FILTER_CPU, sizeof(int));
+   __generic_field(char *, COMM, FILTER_COMM, TASK_COMM_LEN + 1);
+   __generic_field(char *, comm, FILTER_COMM, TASK_COMM_LEN + 1);
 
return ret;
 }
diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
index f3a960e..0b40f22 100644
--- a/kernel/trace/trace_events_hist.c
+++ b/kernel/trace/trace_events_hist.c
@@ -75,6 +75,16 @@ static u64 hist_field_log2(struct hist_field *hist_field, 
void *event)
return (u64) ilog2(roundup_pow_of_two(val));
 }
 
+static u64 hist_field_cpu(struct hist_field *hist_field, void *event)
+{
+   return (u64) smp_processor_id();
+}
+
+static u64 hist_field_comm(struct hist_field *hist_field, void *event)
+{
+   return (u64)(unsigned long)current->comm;
+}
+
 #define DEFINE_HIST_FIELD_FN(type) \
 static u64 hist_field_##type(struct hist_field *hist_field, void *event)\
 {  \
@@ -119,6 +129,7 @@ enum hist_field_flags {
HIST_FIELD_FL_SYSCALL   = 128,
HIST_FIELD_FL_STACKTRACE= 256,
HIST_FIELD_FL_LOG2  = 512,
+ 

Re: [PATCH v5 2/4] tracing: Add cpu as a key field in histogram

2016-09-02 Thread Steven Rostedt
On Fri,  2 Sep 2016 18:07:29 +0530
Binoy Jayan  wrote:

> The field 'cpu' although part of the set of generic fields, is not made
> part of the key fields when mentioned in the trigger command. This hack
> suggested by Daniel marks it as one of the key fields and make it appear
> in the histogram output.
> 
> Signed-off-by: Binoy Jayan 
> ---
>  kernel/trace/trace_events.c  |  3 ++-
>  kernel/trace/trace_events_hist.c | 15 +++
>  2 files changed, 17 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
> index 03c0a48..c395608 100644
> --- a/kernel/trace/trace_events.c
> +++ b/kernel/trace/trace_events.c
> @@ -152,7 +152,8 @@ EXPORT_SYMBOL_GPL(trace_define_field);
>  
>  #define __generic_field(type, item, filter_type) \
>   ret = __trace_define_field(_generic_fields, #type,   \
> -#item, 0, 0, is_signed_type(type),   \
> +#item, 0, sizeof(type),  \
> +is_signed_type(type),\
>  filter_type);\
>   if (ret)\
>   return ret;
> diff --git a/kernel/trace/trace_events_hist.c 
> b/kernel/trace/trace_events_hist.c
> index 0c05b8a..4e0a12e 100644
> --- a/kernel/trace/trace_events_hist.c
> +++ b/kernel/trace/trace_events_hist.c
> @@ -75,6 +75,11 @@ static u64 hist_field_log2(struct hist_field *hist_field, 
> void *event)
>   return (u64) ilog2(roundup_pow_of_two(val));
>  }
>  
> +static u64 hist_field_cpu(struct hist_field *hist_field, void *event)
> +{
> + return (u64) raw_smp_processor_id();

Does this really need to be raw? I'm guessing that this would be called
always in preempt disabled locations, but if it is not, wouldn't we
want to know about it?

> +}
> +
>  #define DEFINE_HIST_FIELD_FN(type)   \
>  static u64 hist_field_##type(struct hist_field *hist_field, void *event)\
>  {\
> @@ -119,6 +124,7 @@ enum hist_field_flags {
>   HIST_FIELD_FL_SYSCALL   = 128,
>   HIST_FIELD_FL_STACKTRACE= 256,
>   HIST_FIELD_FL_LOG2  = 512,
> + HIST_FIELD_FL_CPU   = 1024,
>  };
>  
>  struct hist_trigger_attrs {
> @@ -371,6 +377,11 @@ static struct hist_field *create_hist_field(struct 
> ftrace_event_field *field,
>   goto out;
>   }
>  
> + if (flags & HIST_FIELD_FL_CPU) {
> + hist_field->fn = hist_field_cpu;
> + goto out;
> + }
> +
>   if (WARN_ON_ONCE(!field))
>   goto out;
>  
> @@ -526,6 +537,9 @@ static int create_key_field(struct hist_trigger_data 
> *hist_data,
>   } else {
>   char *field_name = strsep(_str, ".");
>  
> + if (strcmp(field_name, "cpu") == 0)
> + flags |= HIST_FIELD_FL_CPU;
> +
>   if (field_str) {
>   if (strcmp(field_str, "hex") == 0)
>   flags |= HIST_FIELD_FL_HEX;
> @@ -556,6 +570,7 @@ static int create_key_field(struct hist_trigger_data 
> *hist_data,
>   key_size = MAX_FILTER_STR_VAL;
>   else
>   key_size = field->size;
> +

Unnecessary white space.

-- Steve

>   }
>  
>   hist_data->fields[key_idx] = create_hist_field(field, flags);



Re: [PATCH v5 2/4] tracing: Add cpu as a key field in histogram

2016-09-02 Thread Steven Rostedt
On Fri,  2 Sep 2016 18:07:29 +0530
Binoy Jayan  wrote:

> The field 'cpu' although part of the set of generic fields, is not made
> part of the key fields when mentioned in the trigger command. This hack
> suggested by Daniel marks it as one of the key fields and make it appear
> in the histogram output.
> 
> Signed-off-by: Binoy Jayan 
> ---
>  kernel/trace/trace_events.c  |  3 ++-
>  kernel/trace/trace_events_hist.c | 15 +++
>  2 files changed, 17 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
> index 03c0a48..c395608 100644
> --- a/kernel/trace/trace_events.c
> +++ b/kernel/trace/trace_events.c
> @@ -152,7 +152,8 @@ EXPORT_SYMBOL_GPL(trace_define_field);
>  
>  #define __generic_field(type, item, filter_type) \
>   ret = __trace_define_field(_generic_fields, #type,   \
> -#item, 0, 0, is_signed_type(type),   \
> +#item, 0, sizeof(type),  \
> +is_signed_type(type),\
>  filter_type);\
>   if (ret)\
>   return ret;
> diff --git a/kernel/trace/trace_events_hist.c 
> b/kernel/trace/trace_events_hist.c
> index 0c05b8a..4e0a12e 100644
> --- a/kernel/trace/trace_events_hist.c
> +++ b/kernel/trace/trace_events_hist.c
> @@ -75,6 +75,11 @@ static u64 hist_field_log2(struct hist_field *hist_field, 
> void *event)
>   return (u64) ilog2(roundup_pow_of_two(val));
>  }
>  
> +static u64 hist_field_cpu(struct hist_field *hist_field, void *event)
> +{
> + return (u64) raw_smp_processor_id();

Does this really need to be raw? I'm guessing that this would be called
always in preempt disabled locations, but if it is not, wouldn't we
want to know about it?

> +}
> +
>  #define DEFINE_HIST_FIELD_FN(type)   \
>  static u64 hist_field_##type(struct hist_field *hist_field, void *event)\
>  {\
> @@ -119,6 +124,7 @@ enum hist_field_flags {
>   HIST_FIELD_FL_SYSCALL   = 128,
>   HIST_FIELD_FL_STACKTRACE= 256,
>   HIST_FIELD_FL_LOG2  = 512,
> + HIST_FIELD_FL_CPU   = 1024,
>  };
>  
>  struct hist_trigger_attrs {
> @@ -371,6 +377,11 @@ static struct hist_field *create_hist_field(struct 
> ftrace_event_field *field,
>   goto out;
>   }
>  
> + if (flags & HIST_FIELD_FL_CPU) {
> + hist_field->fn = hist_field_cpu;
> + goto out;
> + }
> +
>   if (WARN_ON_ONCE(!field))
>   goto out;
>  
> @@ -526,6 +537,9 @@ static int create_key_field(struct hist_trigger_data 
> *hist_data,
>   } else {
>   char *field_name = strsep(_str, ".");
>  
> + if (strcmp(field_name, "cpu") == 0)
> + flags |= HIST_FIELD_FL_CPU;
> +
>   if (field_str) {
>   if (strcmp(field_str, "hex") == 0)
>   flags |= HIST_FIELD_FL_HEX;
> @@ -556,6 +570,7 @@ static int create_key_field(struct hist_trigger_data 
> *hist_data,
>   key_size = MAX_FILTER_STR_VAL;
>   else
>   key_size = field->size;
> +

Unnecessary white space.

-- Steve

>   }
>  
>   hist_data->fields[key_idx] = create_hist_field(field, flags);



[PATCH v5 2/4] tracing: Add cpu as a key field in histogram

2016-09-02 Thread Binoy Jayan
The field 'cpu' although part of the set of generic fields, is not made
part of the key fields when mentioned in the trigger command. This hack
suggested by Daniel marks it as one of the key fields and make it appear
in the histogram output.

Signed-off-by: Binoy Jayan 
---
 kernel/trace/trace_events.c  |  3 ++-
 kernel/trace/trace_events_hist.c | 15 +++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 03c0a48..c395608 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -152,7 +152,8 @@ EXPORT_SYMBOL_GPL(trace_define_field);
 
 #define __generic_field(type, item, filter_type)   \
ret = __trace_define_field(_generic_fields, #type,   \
-  #item, 0, 0, is_signed_type(type),   \
+  #item, 0, sizeof(type),  \
+  is_signed_type(type),\
   filter_type);\
if (ret)\
return ret;
diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
index 0c05b8a..4e0a12e 100644
--- a/kernel/trace/trace_events_hist.c
+++ b/kernel/trace/trace_events_hist.c
@@ -75,6 +75,11 @@ static u64 hist_field_log2(struct hist_field *hist_field, 
void *event)
return (u64) ilog2(roundup_pow_of_two(val));
 }
 
+static u64 hist_field_cpu(struct hist_field *hist_field, void *event)
+{
+   return (u64) raw_smp_processor_id();
+}
+
 #define DEFINE_HIST_FIELD_FN(type) \
 static u64 hist_field_##type(struct hist_field *hist_field, void *event)\
 {  \
@@ -119,6 +124,7 @@ enum hist_field_flags {
HIST_FIELD_FL_SYSCALL   = 128,
HIST_FIELD_FL_STACKTRACE= 256,
HIST_FIELD_FL_LOG2  = 512,
+   HIST_FIELD_FL_CPU   = 1024,
 };
 
 struct hist_trigger_attrs {
@@ -371,6 +377,11 @@ static struct hist_field *create_hist_field(struct 
ftrace_event_field *field,
goto out;
}
 
+   if (flags & HIST_FIELD_FL_CPU) {
+   hist_field->fn = hist_field_cpu;
+   goto out;
+   }
+
if (WARN_ON_ONCE(!field))
goto out;
 
@@ -526,6 +537,9 @@ static int create_key_field(struct hist_trigger_data 
*hist_data,
} else {
char *field_name = strsep(_str, ".");
 
+   if (strcmp(field_name, "cpu") == 0)
+   flags |= HIST_FIELD_FL_CPU;
+
if (field_str) {
if (strcmp(field_str, "hex") == 0)
flags |= HIST_FIELD_FL_HEX;
@@ -556,6 +570,7 @@ static int create_key_field(struct hist_trigger_data 
*hist_data,
key_size = MAX_FILTER_STR_VAL;
else
key_size = field->size;
+
}
 
hist_data->fields[key_idx] = create_hist_field(field, flags);
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v5 2/4] tracing: Add cpu as a key field in histogram

2016-09-02 Thread Binoy Jayan
The field 'cpu' although part of the set of generic fields, is not made
part of the key fields when mentioned in the trigger command. This hack
suggested by Daniel marks it as one of the key fields and make it appear
in the histogram output.

Signed-off-by: Binoy Jayan 
---
 kernel/trace/trace_events.c  |  3 ++-
 kernel/trace/trace_events_hist.c | 15 +++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 03c0a48..c395608 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -152,7 +152,8 @@ EXPORT_SYMBOL_GPL(trace_define_field);
 
 #define __generic_field(type, item, filter_type)   \
ret = __trace_define_field(_generic_fields, #type,   \
-  #item, 0, 0, is_signed_type(type),   \
+  #item, 0, sizeof(type),  \
+  is_signed_type(type),\
   filter_type);\
if (ret)\
return ret;
diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
index 0c05b8a..4e0a12e 100644
--- a/kernel/trace/trace_events_hist.c
+++ b/kernel/trace/trace_events_hist.c
@@ -75,6 +75,11 @@ static u64 hist_field_log2(struct hist_field *hist_field, 
void *event)
return (u64) ilog2(roundup_pow_of_two(val));
 }
 
+static u64 hist_field_cpu(struct hist_field *hist_field, void *event)
+{
+   return (u64) raw_smp_processor_id();
+}
+
 #define DEFINE_HIST_FIELD_FN(type) \
 static u64 hist_field_##type(struct hist_field *hist_field, void *event)\
 {  \
@@ -119,6 +124,7 @@ enum hist_field_flags {
HIST_FIELD_FL_SYSCALL   = 128,
HIST_FIELD_FL_STACKTRACE= 256,
HIST_FIELD_FL_LOG2  = 512,
+   HIST_FIELD_FL_CPU   = 1024,
 };
 
 struct hist_trigger_attrs {
@@ -371,6 +377,11 @@ static struct hist_field *create_hist_field(struct 
ftrace_event_field *field,
goto out;
}
 
+   if (flags & HIST_FIELD_FL_CPU) {
+   hist_field->fn = hist_field_cpu;
+   goto out;
+   }
+
if (WARN_ON_ONCE(!field))
goto out;
 
@@ -526,6 +537,9 @@ static int create_key_field(struct hist_trigger_data 
*hist_data,
} else {
char *field_name = strsep(_str, ".");
 
+   if (strcmp(field_name, "cpu") == 0)
+   flags |= HIST_FIELD_FL_CPU;
+
if (field_str) {
if (strcmp(field_str, "hex") == 0)
flags |= HIST_FIELD_FL_HEX;
@@ -556,6 +570,7 @@ static int create_key_field(struct hist_trigger_data 
*hist_data,
key_size = MAX_FILTER_STR_VAL;
else
key_size = field->size;
+
}
 
hist_data->fields[key_idx] = create_hist_field(field, flags);
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project