A couple hist trigger patches
cover A couple hist trigger patches
From: Tom Zanussi <[email protected]>
Hi,
Here are a couple miscellaneous hist trigger patches which can be applied independently of the onchange/snapshot patches.
The first is just an additional use of str_has_prefix() that was apparently missed in the original str_has_prefix() conversion, with an update suggested by Joe Perches.
The second fixes a bug I noticed when testing the onchange/snapshot fixes.
I pulled these out into this separate patchset because they should be applied regardless of what happens with the onchange/snapshot patchset.
Thanks,
Tom
The following changes since commit 67748dbeaf2b1240c0b87588df4bb0fb9471a751:
sh: ftrace: Fix missing parenthesis in WARN_ON() (2019-01-08 10:19:02 -0600)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/zanussi/linux-trace.git ftrace/hist-fixes-v1
Tom Zanussi (2):
tracing: Use str_has_prefix() in synth_event_create()
tracing: Use strncpy instead of memcpy for string keys in hist
triggers
kernel/trace/trace_events_hist.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
Signature · 1 line
2.14.1
PATCH 1/2 tracing: Use str_has_prefix() in synth_event_create()
From: Tom Zanussi <[email protected]>
Since we now have a str_has_prefix() that returns the length, we can use that instead of explicitly calculating it.
--- kernel/trace/trace_events_hist.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/trace/trace_events_hist.c +2 -2
@@ -1200,8 +1200,8 @@ static int synth_event_create(int argc, const char **argv)/* This interface accepts group name prefix */ if (strchr (name,'/' )) { - len =sizeof (SYNTH_SYSTEM "/" ) -1 ; -if (strncmp (name,SYNTH_SYSTEM "/" , len)) + len =str_has_prefix (name,SYNTH_SYSTEM "/" ); +if (len ==0 )return -EINVAL ; name += len; }
Signature · 1 line
2.14.1
PATCH 2/2 tracing: Use strncpy instead of memcpy for string keys in hist triggers
In reply to Tom ZanussiFrom: Tom Zanussi <[email protected]>
Because there may be random garbage beyond a string's null terminator, it's not correct to copy the the complete character array for use as a hist trigger key. This results in multiple histogram entries for the 'same' string key.
So, in the case of a string key, use strncpy instead of memcpy to avoid copying in the extra bytes.
Before, using the gdbus entries in the following hist trigger as an example:
# echo 'hist:key=comm' > /sys/kernel/debug/tracing/events/sched/sched_waking/trigger # cat /sys/kernel/debug/tracing/events/sched/sched_waking/hist
...
{ comm: ImgDecoder #4 } hitcount: 203
{ comm: gmain } hitcount: 213
{ comm: gmain } hitcount: 216
{ comm: StreamTrans #73 } hitcount: 221
{ comm: mozStorage #3 } hitcount: 230
{ comm: gdbus } hitcount: 233
{ comm: StyleThread#5 } hitcount: 253
{ comm: gdbus } hitcount: 256
{ comm: gdbus } hitcount: 260
{ comm: StyleThread#4 } hitcount: 271...
# cat /sys/kernel/debug/tracing/events/sched/sched_waking/hist | egrep gdbus | wc -l 51
After:
# cat /sys/kernel/debug/tracing/events/sched/sched_waking/hist | egrep gdbus | wc -l 1
--- kernel/trace/trace_events_hist.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
kernel/trace/trace_events_hist.c +3 -2
@@ -4695,9 +4695,10 @@ static inline void add_to_key(char *compound_key, void *key,/* ensure NULL-termination */ if (size > key_field->size -1 ) size = key_field->size -1 ; - } -memcpy (compound_key + key_field->offset, key, size); +strncpy (compound_key + key_field->offset, (char *)key, size); + }else +memcpy (compound_key + key_field->offset, key, size); } static void
Signature · 1 line
2.14.1
Steven Rostedt
maintainerRe: [PATCH 2/2] tracing: Use strncpy instead of memcpy for string keys in hist triggers
Quoted 51 lines · On Mon, 4 Feb 2019 15:07:24 -0600 Tom Zanussi <[email protected]> wrote:
From: Tom Zanussi <[email protected]>
Because there may be random garbage beyond a string's null terminator, it's not correct to copy the the complete character array for use as a hist trigger key. This results in multiple histogram entries for the 'same' string key.
So, in the case of a string key, use strncpy instead of memcpy to avoid copying in the extra bytes.
Before, using the gdbus entries in the following hist trigger as an example:
# echo 'hist:key=comm' > /sys/kernel/debug/tracing/events/sched/sched_waking/trigger # cat /sys/kernel/debug/tracing/events/sched/sched_waking/hist...
{ comm: ImgDecoder #4 } hitcount: 203 { comm: gmain } hitcount: 213 { comm: gmain } hitcount: 216 { comm: StreamTrans #73 } hitcount: 221 { comm: mozStorage #3 } hitcount: 230 { comm: gdbus } hitcount: 233 { comm: StyleThread#5 } hitcount: 253 { comm: gdbus } hitcount: 256 { comm: gdbus } hitcount: 260 { comm: StyleThread#4 } hitcount: 271...
# cat /sys/kernel/debug/tracing/events/sched/sched_waking/hist | egrep gdbus | wc -l 51After:
# cat /sys/kernel/debug/tracing/events/sched/sched_waking/hist | egrep gdbus | wc -l 1Signed-off-by Tom Zanussi <[email protected]>Cc Namhyung Kim <[email protected]>--- kernel/trace/trace_events_hist.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)kernel/trace/trace_events_hist.c +0
-0@@ -4695,9 +4695,10 @@ static inline void add_to_key(char *compound_key, void *key,/* ensure NULL-termination */
kernel/trace/trace_events_hist.c static inline void add_to_key(char *compound_key, void *key, · line 4703
Quoted 10 lines
kernel/trace/trace_events_hist.c +3
-2if (size > key_field->size -1 ) size = key_field->size -1 ; - } -memcpy (compound_key + key_field->offset, key, size); +strncpy (compound_key + key_field->offset, (char *)key, size); + }else +memcpy (compound_key + key_field->offset, key, size); }
Shouldn't we use strncpy() in save_comm() too. Feels safer.
-- Steve
Steven Rostedt
maintainerRe: [PATCH 2/2] tracing: Use strncpy instead of memcpy for string keys in hist triggers
Quoted 7 lines · On Mon, 4 Mar 2019 16:50:00 -0500 Steven Rostedt <[email protected]> wrote:
Quoted 7 lines
+++
b/kernel/trace/trace_events_hist.ckernel/trace/trace_events_hist.c +0
-1@@ -4695,9 +4695,10 @@ static inline void add_to_key(char *compound_key, void *key,/* ensure NULL-termination */ if (size > key_field->size -1 ) size = key_field->size -1 ; - }
Quoted 8 lines
kernel/trace/trace_events_hist.c static inline void add_to_key(char *compound_key, void *key, · line 4703
Quoted 6 lines
kernel/trace/trace_events_hist.c +3
-1-memcpy (compound_key + key_field->offset, key, size); +strncpy (compound_key + key_field->offset, (char *)key, size); + }else +memcpy (compound_key + key_field->offset, key, size); }Shouldn't we use
strncpy()insave_comm()too. Feels safer.
Note, if that is changed, it can be another patch. This one is fine as is. I just was looking at other use cases of memcpy() in that file.
-- Steve
Re: [PATCH 2/2] tracing: Use strncpy instead of memcpy for string keys in hist triggers
Hi Steve,
Quoted 21 lines · Steven Rostedt
Quoted 8 lines · On Mon, 4 Mar 2019 16:50:00 -0500 Steven Rostedt <[email protected]> wrote:
Quoted 8 lines
+++
b/kernel/trace/trace_events_hist.ckernel/trace/trace_events_hist.c +0
-1@@ -4695,9 +4695,10 @@ static inline void add_to_key(char *compound_key, void *key,/* ensure NULL-termination */ if (size > key_field->size - 1) size = key_field->size - 1; - }Quoted 9 lines
kernel/trace/trace_events_hist.c static inline void add_to_key(char *compound_key, void *key, · line 4702
Quoted 7 lines
kernel/trace/trace_events_hist.c +3
-1-memcpy (compound_key + key_field->offset, key, size); +strncpy (compound_key + key_field->offset, (char *)key, size); + }else +memcpy (compound_key + key_field->offset, key, size); }Shouldn't we use
strncpy()insave_comm()too. Feels safer.
Quoted 4 lines
Note, if that is changed, it can be another patch. This one is fine as
is. I just was looking at other use cases ofmemcpy()in that file.
Hmm, I don't think it's really necessary - it's not used in a key so don't care about anything after the null, and TASK_COMM_LEN is used in the memcpy.
Tom
Quoted 1 line
-- Steve
Re: [PATCH 2/2] tracing: Use strncpy instead of memcpy for string keys in hist triggers
Hi Steve,
Quoted 31 lines · Tom Zanussi
Hi Steve,
Quoted 23 lines · Steven Rostedt
Quoted 8 lines · On Mon, 4 Mar 2019 16:50:00 -0500 Steven Rostedt <[email protected]> wrote:
Quoted 8 lines
+++
b/kernel/trace/trace_events_hist.ckernel/trace/trace_events_hist.c +0
-1@@ -4695,9 +4695,10 @@ static inline void add_to_key(char *compound_key, void *key,/* ensure NULL-termination */ if (size > key_field->size - 1) size = key_field->size - 1; - }Quoted 11 lines
Quoted 9 lines
(quoted diff) +3
-1- memcpy(compound_key + key_field->offset, key, size); + strncpy(compound_key + key_field->offset, (char *)key, size); + } else + memcpy(compound_key + key_field->offset, key,size);
}Shouldn't we use
strncpy()insave_comm()too. Feels safer.Quoted 4 lines
Note, if that is changed, it can be another patch. This one is fine as
is. I just was looking at other use cases ofmemcpy()in that file.
Quoted 4 lines
Hmm, I don't think it's really necessary - it's not used in a key so don't care about anything after the null, and
TASK_COMM_LENis used in
the memcpy.
Never mind, yeah, it would make sense to do this, will create another patch...
Tom
Quoted 4 lines
Tom
Quoted 1 line
-- Steve
Steven Rostedt
maintainerRe: [PATCH 2/2] tracing: Use strncpy instead of memcpy for string keys in hist triggers
Quoted 7 lines · On Mon, 04 Mar 2019 16:31:40 -0600 Tom Zanussi <[email protected]>…
Quoted 4 lines
Hmm, I don't think it's really necessary - it's not used in a key so don't care about anything after the null, and
TASK_COMM_LENis used in
the memcpy.Never mind, yeah, it would make sense to do this, will create another patch...
And probably should change the memcpy() of comm in kernel/trace/trace.c too. It could be that memcpy() is a little bit faster than strncpy(), and this is done on scheduling switches when tracing is active, but still, I'm starting to think that isn't a good choice.
-- Steve
Re: [PATCH 2/2] tracing: Use strncpy instead of memcpy for string keys in hist triggers
Quoted 14 lines · Steven Rostedt
Quoted 10 lines · On Mon, 04 Mar 2019 16:31:40 -0600 Tom Zanussi <[email protected]>…
Quoted 6 lines
Hmm, I don't think it's really necessary - it's not used in a key so
don't care about anything after the null, andTASK_COMM_LENis used
in
the memcpy.Never mind, yeah, it would make sense to do this, will create another
patch...
Quoted 6 lines
And probably should change the
memcpy()of comm inkernel/trace/trace.c
too. It could be thatmemcpy()is a little bit faster thanstrncpy(), and this is done on scheduling switches when tracing is active, but still, I'm starting to think that isn't a good choice.
OK, will add that too.
Tom
Quoted 1 line
-- Steve
Ping...
Quoted 43 lines · Tom Zanussi
From: Tom Zanussi <[email protected]>
Hi,
Here are a couple miscellaneous hist trigger patches which can be applied independently of the onchange/snapshot patches.
The first is just an additional use of
str_has_prefix()that was apparently missed in the originalstr_has_prefix()conversion, with an
update suggested by Joe Perches.The second fixes a bug I noticed when testing the onchange/snapshot fixes.
I pulled these out into this separate patchset because they should be applied regardless of what happens with the onchange/snapshot patchset.
Thanks,
Tom
The following changes since commit
67748dbeaf2b1240c0b87588df4bb0fb9471a751:sh: ftrace: Fix missing parenthesis in
WARN_ON()(2019-01-08
10:19:02 -0600)are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/zanussi/linux-
trace.git ftrace/hist-fixes-v1Tom Zanussi (2):
tracing: Usestr_has_prefix()insynth_event_create()
tracing: Use strncpy instead of memcpy for string keys in hist
triggerskernel/trace/trace_events_hist.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
Steven Rostedt
maintainerQuoted 3 lines · On Mon, 04 Mar 2019 14:11:03 -0600 Tom Zanussi <[email protected]> wrote:
Ping...
Thanks for the ping. It got buried.
-- Steve