linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf tests switch-tracking: Fix timestamp comparison
@ 2025-03-31 17:27 Leo Yan
  2025-03-31 20:18 ` Ian Rogers
  2025-05-23  1:55 ` Arnaldo Carvalho de Melo
  0 siblings, 2 replies; 16+ messages in thread
From: Leo Yan @ 2025-03-31 17:27 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Ian Rogers, Adrian Hunter,
	Liang, Kan, James Clark, linux-perf-users, linux-kernel
  Cc: Leo Yan

The test might fail on the Arm64 platform with the error:

  perf test -vvv "Track with sched_switch"
  Missing sched_switch events

The issue is caused by incorrect handling of timestamp comparisons. The
comparison result, a signed 64-bit value, was being directly cast to an
int, leading to incorrect sorting for sched events.

Fix this by explicitly returning 0, 1, or -1 based on whether the result
is zero, positive, or negative.

Fixes: d44bc5582972 ("perf tests: Add a test for tracking with sched_switch")
Signed-off-by: Leo Yan <leo.yan@arm.com>
---
 tools/perf/tests/switch-tracking.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/tests/switch-tracking.c b/tools/perf/tests/switch-tracking.c
index 8df3f9d9ffd2..6b3aac283c37 100644
--- a/tools/perf/tests/switch-tracking.c
+++ b/tools/perf/tests/switch-tracking.c
@@ -264,7 +264,7 @@ static int compar(const void *a, const void *b)
 	const struct event_node *nodeb = b;
 	s64 cmp = nodea->event_time - nodeb->event_time;
 
-	return cmp;
+	return cmp < 0 ? -1 : (cmp > 0 ? 1 : 0);
 }
 
 static int process_events(struct evlist *evlist,
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2025-05-28 13:08 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-31 17:27 [PATCH] perf tests switch-tracking: Fix timestamp comparison Leo Yan
2025-03-31 20:18 ` Ian Rogers
2025-04-01  9:14   ` Leo Yan
2025-04-01 19:54     ` Ian Rogers
2025-04-02  9:05       ` Leo Yan
2025-05-16 15:31         ` Leo Yan
2025-05-20  1:52           ` Namhyung Kim
2025-05-23  1:49             ` Arnaldo Carvalho de Melo
2025-05-23  1:51               ` Arnaldo Carvalho de Melo
2025-05-23  1:55 ` Arnaldo Carvalho de Melo
2025-05-23  1:57   ` Arnaldo Carvalho de Melo
2025-05-23  8:10     ` Leo Yan
2025-05-23 16:52       ` Ian Rogers
2025-05-23 17:12       ` Arnaldo Carvalho de Melo
2025-05-27  9:49         ` Leo Yan
2025-05-28 13:08           ` Arnaldo Carvalho de Melo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).