[LTP] [PATCH 6/6] sched_football: Add trace_marker messages if we're tracing

John Stultz jstultz@google.com
Wed Apr 24 00:58:03 CEST 2024


To further help with tracing, add trace_marker messages so we
can see exactly when the game starts and ends in the tracelog.

Cc: kernel-team@android.com
Cc: Darren Hart <darren@os.amperecomputing.com>
Signed-off-by: John Stultz <jstultz@google.com>
---
 .../realtime/func/sched_football/sched_football.c    | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/testcases/realtime/func/sched_football/sched_football.c b/testcases/realtime/func/sched_football/sched_football.c
index 45fbf6766..ca44584b0 100644
--- a/testcases/realtime/func/sched_football/sched_football.c
+++ b/testcases/realtime/func/sched_football/sched_football.c
@@ -67,6 +67,7 @@
 #include <pthread.h>
 #include <sched.h>
 #include <errno.h>
+#include <fcntl.h>
 #include <sys/syscall.h>
 #include <unistd.h>
 #include <sys/prctl.h>
@@ -167,10 +168,14 @@ void *thread_offense(void *arg)
 	return NULL;
 }
 
+#define BUF_LEN 256
 int referee(int game_length)
 {
 	struct timeval start, now;
+	char buf[BUF_LEN];
 	int final_ball;
+	int fd = open("/sys/kernel/tracing/trace_marker", O_RDWR, 0);
+	int ret;
 
 	prctl(PR_SET_NAME, "referee", 0, 0, 0);
 	printf("Game On (%d seconds)!\n", game_length);
@@ -178,14 +183,19 @@ int referee(int game_length)
 	gettimeofday(&start, NULL);
 	now = start;
 
+	sprintf(buf, "I|%i|Game_Started!\n", getpid());
 	/* Start the game! */
 	atomic_set(0, &the_ball);
-
+	if (fd > 0)
+		ret = write(fd, buf, strnlen(buf, BUF_LEN));
 	/* Watch the game */
 	while ((now.tv_sec - start.tv_sec) < game_length) {
 		sleep(1);
 		gettimeofday(&now, NULL);
 	}
+	sprintf(buf, "I|%i|Game_Over!\n", getpid());
+	if (fd > 0)
+		ret = write(fd, buf, strnlen(buf, BUF_LEN));
 	final_ball = atomic_get(&the_ball);
 	/* Blow the whistle */
 	printf("Game Over!\n");
-- 
2.44.0.769.g3c40516874-goog



More information about the ltp mailing list