Skip to content

Commit 1e3bac7

Browse files
committed
tracing/histogram: Rename "cpu" to "common_cpu"
Currently the histogram logic allows the user to write "cpu" in as an event field, and it will record the CPU that the event happened on. The problem with this is that there's a lot of events that have "cpu" as a real field, and using "cpu" as the CPU it ran on, makes it impossible to run histograms on the "cpu" field of events. For example, if I want to have a histogram on the count of the workqueue_queue_work event on its cpu field, running: ># echo 'hist:keys=cpu' > events/workqueue/workqueue_queue_work/trigger Gives a misleading and wrong result. Change the command to "common_cpu" as no event should have "common_*" fields as that's a reserved name for fields used by all events. And this makes sense here as common_cpu would be a field used by all events. Now we can even do: ># echo 'hist:keys=common_cpu,cpu if cpu < 100' > events/workqueue/workqueue_queue_work/trigger ># cat events/workqueue/workqueue_queue_work/hist # event histogram # # trigger info: hist:keys=common_cpu,cpu:vals=hitcount:sort=hitcount:size=2048 if cpu < 100 [active] # { common_cpu: 0, cpu: 2 } hitcount: 1 { common_cpu: 0, cpu: 4 } hitcount: 1 { common_cpu: 7, cpu: 7 } hitcount: 1 { common_cpu: 0, cpu: 7 } hitcount: 1 { common_cpu: 0, cpu: 1 } hitcount: 1 { common_cpu: 0, cpu: 6 } hitcount: 2 { common_cpu: 0, cpu: 5 } hitcount: 2 { common_cpu: 1, cpu: 1 } hitcount: 4 { common_cpu: 6, cpu: 6 } hitcount: 4 { common_cpu: 5, cpu: 5 } hitcount: 14 { common_cpu: 4, cpu: 4 } hitcount: 26 { common_cpu: 0, cpu: 0 } hitcount: 39 { common_cpu: 2, cpu: 2 } hitcount: 184 Now for backward compatibility, I added a trick. If "cpu" is used, and the field is not found, it will fall back to "common_cpu" and work as it did before. This way, it will still work for old programs that use "cpu" to get the actual CPU, but if the event has a "cpu" as a field, it will get that event's "cpu" field, which is probably what it wants anyway. I updated the tracefs/README to include documentation about both the common_timestamp and the common_cpu. This way, if that text is present in the README, then an application can know that common_cpu is supported over just plain "cpu". Link: https://lkml.kernel.org/r/[email protected] Cc: Namhyung Kim <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Andrew Morton <[email protected]> Cc: [email protected] Fixes: 8b7622b ("tracing: Add cpu field for hist triggers") Reviewed-by: Tom Zanussi <[email protected]> Reviewed-by: Masami Hiramatsu <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 3b13911 commit 1e3bac7

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

Documentation/trace/histogram.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ Documentation written by Tom Zanussi
191191
with the event, in nanoseconds. May be
192192
modified by .usecs to have timestamps
193193
interpreted as microseconds.
194-
cpu int the cpu on which the event occurred.
194+
common_cpu int the cpu on which the event occurred.
195195
====================== ==== =======================================
196196

197197
Extended error information

kernel/trace/trace.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5609,6 +5609,10 @@ static const char readme_msg[] =
56095609
"\t [:name=histname1]\n"
56105610
"\t [:<handler>.<action>]\n"
56115611
"\t [if <filter>]\n\n"
5612+
"\t Note, special fields can be used as well:\n"
5613+
"\t common_timestamp - to record current timestamp\n"
5614+
"\t common_cpu - to record the CPU the event happened on\n"
5615+
"\n"
56125616
"\t When a matching event is hit, an entry is added to a hash\n"
56135617
"\t table using the key(s) and value(s) named, and the value of a\n"
56145618
"\t sum called 'hitcount' is incremented. Keys and values\n"

kernel/trace/trace_events_hist.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,7 @@ static const char *hist_field_name(struct hist_field *field,
11111111
field->flags & HIST_FIELD_FL_ALIAS)
11121112
field_name = hist_field_name(field->operands[0], ++level);
11131113
else if (field->flags & HIST_FIELD_FL_CPU)
1114-
field_name = "cpu";
1114+
field_name = "common_cpu";
11151115
else if (field->flags & HIST_FIELD_FL_EXPR ||
11161116
field->flags & HIST_FIELD_FL_VAR_REF) {
11171117
if (field->system) {
@@ -1991,14 +1991,24 @@ parse_field(struct hist_trigger_data *hist_data, struct trace_event_file *file,
19911991
hist_data->enable_timestamps = true;
19921992
if (*flags & HIST_FIELD_FL_TIMESTAMP_USECS)
19931993
hist_data->attrs->ts_in_usecs = true;
1994-
} else if (strcmp(field_name, "cpu") == 0)
1994+
} else if (strcmp(field_name, "common_cpu") == 0)
19951995
*flags |= HIST_FIELD_FL_CPU;
19961996
else {
19971997
field = trace_find_event_field(file->event_call, field_name);
19981998
if (!field || !field->size) {
1999-
hist_err(tr, HIST_ERR_FIELD_NOT_FOUND, errpos(field_name));
2000-
field = ERR_PTR(-EINVAL);
2001-
goto out;
1999+
/*
2000+
* For backward compatibility, if field_name
2001+
* was "cpu", then we treat this the same as
2002+
* common_cpu.
2003+
*/
2004+
if (strcmp(field_name, "cpu") == 0) {
2005+
*flags |= HIST_FIELD_FL_CPU;
2006+
} else {
2007+
hist_err(tr, HIST_ERR_FIELD_NOT_FOUND,
2008+
errpos(field_name));
2009+
field = ERR_PTR(-EINVAL);
2010+
goto out;
2011+
}
20022012
}
20032013
}
20042014
out:
@@ -5085,7 +5095,7 @@ static void hist_field_print(struct seq_file *m, struct hist_field *hist_field)
50855095
seq_printf(m, "%s=", hist_field->var.name);
50865096

50875097
if (hist_field->flags & HIST_FIELD_FL_CPU)
5088-
seq_puts(m, "cpu");
5098+
seq_puts(m, "common_cpu");
50895099
else if (field_name) {
50905100
if (hist_field->flags & HIST_FIELD_FL_VAR_REF ||
50915101
hist_field->flags & HIST_FIELD_FL_ALIAS)

0 commit comments

Comments
 (0)