[PATCH 5/5] signaltest: Add tracing bits

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This isn't intended for merging.
This is just for Daniel to help him with tracing.

The intention:
- TH0 waits for a signal
- TH1 waits for a signal
- main thread sends a signal to TH1
- TH0 wakes up, sends a signal to TH1, waits for SIGNAL
- TH1 wakes up, sends a signal to TH0, waits for SIGNAL
- loop begin.
  - TH0 wakes up, measures the delay between sending a signal and
    receiving a signal. Sends a signal to TH1.
  - TH1 wakes up, sends a signal to TH0, waits for SIGNAL
  - loop end.

There is nothing that pins the two threads. So the scheduler might be
busy to move them from CPU to another. Pinning everything to one CPU
might make a difference.

  taskset -c 1 ~/signaltest -m -p 98 -b 400

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx>
---
 src/signaltest/signaltest.c | 47 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 46 insertions(+), 1 deletion(-)

diff --git a/src/signaltest/signaltest.c b/src/signaltest/signaltest.c
index dacaa63673c48..b504eef149cd9 100644
--- a/src/signaltest/signaltest.c
+++ b/src/signaltest/signaltest.c
@@ -65,6 +65,25 @@ static int shutdown;
 static int tracelimit;
 
 
+static int trace_marker = -1;
+
+static void trace_log(const char *s)
+{
+	write(trace_marker, s, strlen(s));
+}
+
+
+static int trace_switch = -1;
+
+static void trace_on(void)
+{
+	write(trace_switch, "1", 1);
+}
+
+static void trace_off(void)
+{
+	write(trace_switch, "0", 1);
+}
 /*
  * signal thread
  *
@@ -99,8 +118,10 @@ void *signalthread(void *param)
 		long diff;
 		int sigs;
 
+		trace_log("Before sigwait\n");
 		if (sigwait(&sigset, &sigs) < 0)
 			goto out;
+		trace_log("After sigwait\n");
 
 		clock_gettime(CLOCK_MONOTONIC, &after);
 
@@ -108,12 +129,17 @@ void *signalthread(void *param)
 		 * If it is the first thread, sleep after every 16
 		 * round trips.
 		 */
-		if (!par->id && !(stat->cycles & 0x0F))
+		if (!par->id && !(stat->cycles & 0x0F)) {
+			trace_log("Before sleep\n");
 			usleep(10000);
+			trace_log("After sleep\n");
+		}
 
 		/* Get current time */
 		clock_gettime(CLOCK_MONOTONIC, &now);
+		trace_log("Before phtread_kill\n");
 		pthread_kill(stat->tothread, SIGUSR1);
+		trace_log("After phtread_kill\n");
 
 		/* Skip the first cycle */
 		if (first) {
@@ -136,6 +162,7 @@ void *signalthread(void *param)
 			stat->interrupted = 1;
 			stopped++;
 			shutdown++;
+			trace_log("trace_limit\n");
 		}
 		stat->act = diff;
 		stat->cycles++;
@@ -154,6 +181,7 @@ void *signalthread(void *param)
 
 	stat->threadstarted = -1;
 
+	trace_off();
 	return NULL;
 }
 
@@ -242,6 +270,7 @@ static void process_options(int argc, char *argv[])
 static void sighand(int sig)
 {
 	shutdown = 1;
+	trace_off();
 }
 
 static void print_stat(struct thread_param *par, int index, int verbose)
@@ -287,6 +316,18 @@ int main(int argc, char **argv)
 			goto out;
 		}
 
+	trace_marker = open("/sys/kernel/debug/tracing/trace_marker", O_WRONLY);
+	if (trace_marker < 0) {
+		printf("Failed to open trace_marker: %m\n");
+		exit(1);
+	}
+
+	trace_switch = open("/sys/kernel/debug/tracing/tracing_on", O_WRONLY);
+	if (trace_switch < 0) {
+		printf("Failed to open trace_marker: %m\n");
+		exit(1);
+	}
+
 	sigemptyset(&sigset);
 	sigaddset(&sigset, signum);
 	sigprocmask(SIG_BLOCK, &sigset, NULL);
@@ -305,6 +346,7 @@ int main(int argc, char **argv)
 	if (!stat)
 		goto outpar;
 
+	trace_on();
 	for (i = 0; i < num_threads; i++) {
 		if (verbose) {
 			stat[i].values = calloc(VALBUF_SIZE, sizeof(long));
@@ -348,7 +390,9 @@ int main(int argc, char **argv)
 		stat[i].tothread = stat[0].thread;
 		break;
 	}
+	trace_log("Main phtread_kill\n");
 	pthread_kill(stat[0].thread, signum);
+	trace_log("Main phtread_kill post\n");
 
 	while (!shutdown) {
 		char lavg[256];
@@ -374,6 +418,7 @@ int main(int argc, char **argv)
 	}
 	ret = 0;
  outall:
+	trace_off();
 	shutdown = 1;
 	usleep(50000);
 	if (quiet)
-- 
2.29.2




[Index of Archives]     [RT Stable]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux