From: Steven Rostedt <rostedt@kernel.org>
To: linux-kernel@vger.kernel.org
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Andrew Morton <akpm@linux-foundation.org>,
Donggeun Yoo <donggeunyoo.kernel@gmail.com>
Subject: [for-next][PATCH 18/18] tracing: Print a signed histogram key as signed
Date: Fri, 16 Oct 2026 10:31:33 -0400 [thread overview]
Message-ID: <20261016143137.762707137@kernel.org> (raw)
In-Reply-To: <20261016143115.392980228@kernel.org>
From: Donggeun Yoo <donggeunyoo.kernel@gmail.com>
A histogram sorts its rows by the key named in sort=, and for a key over a
signed event field it sorts them signed: create_tracing_map_fields() picks
the comparison function with
else
cmp_fn = tracing_map_cmp_num(field->size,
field->is_signed);
hist_trigger_print_key() does not look at is_signed at all. Every numeric
key is printed with %llu, so a sorted histogram over a signed field comes
out looking unsorted. syscalls/sys_exit_lseek carries "long ret", which
SYSCALL_FIELD() marks signed and which is negative on every error:
# echo 'hist:keys=ret:sort=ret' > events/syscalls/sys_exit_lseek/trigger
# echo 1 > events/syscalls/sys_exit_lseek/enable
# (five lseek(2) calls returning -ESPIPE, -EINVAL, -EBADF, 0 and 100)
# cat events/syscalls/sys_exit_lseek/hist
{ ret: 18446744073709551587 } hitcount: 1
{ ret: 18446744073709551594 } hitcount: 1
{ ret: 18446744073709551607 } hitcount: 1
{ ret: 0 } hitcount: 1
{ ret: 100 } hitcount: 1
The rows are in ascending order and the numbers are not, because the three
leading ones are -29, -22 and -9 rendered as their two's complement.
Take the rendering from the same place the sort order comes from: the event
field when the key has one, and the hist_field itself when it does not. The
same histogram then reads
{ ret: -29 } hitcount: 1
{ ret: -22 } hitcount: 1
{ ret: -9 } hitcount: 1
{ ret: 0 } hitcount: 1
{ ret: 100 } hitcount: 1
A ".buckets" key stays unsigned here, and not because it is right.
hist_field_bucket() divides as unsigned, so the group holding S64_MAX also
holds S64_MIN, reported at
https://lore.kernel.org/all/20260914054614.82A9B1F000FF@smtp.kernel.org/
Printing that group signed would name a range that does not contain
S64_MIN, so the grouping has to be fixed with it, in a patch of its own.
Link: https://patch.msgid.link/20260917045918.370993-1-donggeunyoo.kernel@gmail.com
Fixes: 7ef224d1d0e3 ("tracing: Add 'hist' event trigger command")
Signed-off-by: Donggeun Yoo <donggeunyoo.kernel@gmail.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
kernel/trace/trace_events_hist.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
index 7d3bb7da4dd1..5527605758cb 100644
--- a/kernel/trace/trace_events_hist.c
+++ b/kernel/trace/trace_events_hist.c
@@ -279,6 +279,14 @@ static u64 hist_field_pstring(struct hist_field *hist_field,
return (u64)(unsigned long)*addr;
}
+static bool hist_field_is_signed(struct hist_field *hist_field)
+{
+ if (hist_field->field)
+ return hist_field->field->is_signed;
+
+ return hist_field->is_signed;
+}
+
static u64 hist_field_log2(struct hist_field *hist_field,
struct tracing_map_elt *elt,
struct trace_buffer *buffer,
@@ -5574,7 +5582,11 @@ static void hist_trigger_print_key(struct seq_file *m,
(char *)(key + key_field->offset));
} else {
uval = *(u64 *)(key + key_field->offset);
- seq_printf(m, "%s: %10llu", field_name, uval);
+ if (hist_field_is_signed(key_field))
+ seq_printf(m, "%s: %10lld", field_name,
+ (s64)uval);
+ else
+ seq_printf(m, "%s: %10llu", field_name, uval);
}
}
--
2.53.0
prev parent reply other threads:[~2026-10-16 14:31 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-16 14:31 [for-next][PATCH 00/18] tracing: Updates for 7.4 Steven Rostedt
2026-10-16 14:31 ` [for-next][PATCH 01/18] tracing: Add "within" filter for call-stack-based event filtering Steven Rostedt
2026-10-16 14:31 ` [for-next][PATCH 02/18] tracnig: Add proper error message for glob use with "within" filter Steven Rostedt
2026-10-16 14:31 ` [for-next][PATCH 03/18] tracing: Remove duplicate declaration of ftrace_set_clr_event() Steven Rostedt
2026-10-16 14:31 ` [for-next][PATCH 04/18] tracing: Stop modifying the input buffer in ftrace_set_clr_event() Steven Rostedt
2026-10-16 14:31 ` [for-next][PATCH 05/18] tracing: Split the event string parsing logic into a dedicated function Steven Rostedt
2026-10-16 14:31 ` [for-next][PATCH 06/18] tracing: Add a test for ftrace_parse_event_string() Steven Rostedt
2026-10-16 14:31 ` [for-next][PATCH 07/18] tracing: Add a filter argument to __ftrace_set_clr_event() Steven Rostedt
2026-10-16 14:31 ` [for-next][PATCH 08/18] tracing: Parse filter from boot event string Steven Rostedt
2026-10-16 14:31 ` [for-next][PATCH 09/18] ring-buffer: Rename ring_buffer_size() to ring_buffer_capacity() Steven Rostedt
2026-10-16 14:31 ` [for-next][PATCH 10/18] tracing: Rename trace_array::entries to capacity Steven Rostedt
2026-10-16 14:31 ` [for-next][PATCH 11/18] tracing: Rename tracing_entries_fops to tracing_capacity_fops Steven Rostedt
2026-10-16 14:31 ` [for-next][PATCH 12/18] tracing: Print the bucket size as unsigned Steven Rostedt
2026-10-16 14:31 ` [for-next][PATCH 13/18] tracing: Add the bucket size to expr_field_str() Steven Rostedt
2026-10-16 14:31 ` [for-next][PATCH 14/18] tracing: Only report the stacktrace modifier on a real field Steven Rostedt
2026-10-16 14:31 ` [for-next][PATCH 15/18] tracing: Unregister field variable histograms when the command fails Steven Rostedt
2026-10-16 14:31 ` [for-next][PATCH 16/18] tracing: Clamp the printed end of a histogram bucket at U64_MAX Steven Rostedt
2026-10-16 14:31 ` [for-next][PATCH 17/18] tracing: Fix 64-bit and signed histogram fields on 32-bit kernels Steven Rostedt
2026-10-16 14:31 ` Steven Rostedt [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261016143137.762707137@kernel.org \
--to=rostedt@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=donggeunyoo.kernel@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®