Skip to contentSkip to conversation

perfcounter: sleep before refresh using poll in perf top

PATCH Applied Frederic Weisbecker 2 participants 3 messages Jun 4, 2009 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perfcounter: sleep before refresh using poll in perf top

perf top is refreshed every delay_secs the thread runs in such loop:

while (sleep(delay_secs)) {
	print_sym_table();
}

At the end of print_sym_table(), poll is used without sleep delay to check if we have something from stdin.

It means that this check is done only every delay_secs, which can be higher that 2 secs if the user defined a custom refresh rate.

We can drop sleep() here and directly use poll to wait between refresh periods, so that the reaction after the user stops perf top after typing "Enter" is immediate and doesn't suffer from the delay_secs latency.

Nb: poll doesn't add any overhead that can parasite perf top measures since it sleeps the entire timeout here.

---
 Documentation/perf_counter/builtin-top.c |   18 ++++++++----------
 1 files changed, 8 insertions(+), 10 deletions(-)
Documentation/perf_counter/builtin-top.c +8 -10
index 31c00ba..a31beb3 100644
@@ -278,23 +278,21 @@ static void print_sym_table(void)
 		color_fprintf(stdout, color, "%4.1f%%", pcnt);
 		printf(" - %016llx : %s\n", sym->start, sym->name);
 	}
-
-	{
-		struct pollfd stdin_poll = { .fd = 0, .events = POLLIN };
-
-		if (poll(&stdin_poll, 1, 0) == 1) {
-			printf("key pressed - exiting.\n");
-			exit(0);
-		}
-	}
 }
 
 static void *display_thread(void *arg)
 {
+	struct pollfd stdin_poll = { .fd = 0, .events = POLLIN };
+	int delay_msecs = delay_secs * 1000;
+
 	printf("PerfTop refresh period: %d seconds\n", delay_secs);
 
-	while (!sleep(delay_secs))
+	do {
 		print_sym_table();
+	} while (!poll(&stdin_poll, 1, delay_msecs) == 1);
+
+	printf("key pressed - exiting.\n");
+	exit(0);
 
 	return NULL;
 }
Signature · 1 line
1.6.2.3
Applied
#1 lore raw
Quoted 18 lines · Frederic Weisbecker

perf top is refreshed every delay_secs the thread runs in such loop:

while (sleep(delay_secs)) {
	print_sym_table();
}

At the end of print_sym_table(), poll is used without sleep delay to check if we have something from stdin.

It means that this check is done only every delay_secs, which can be higher that 2 secs if the user defined a custom refresh rate.

We can drop sleep() here and directly use poll to wait between refresh periods, so that the reaction after the user stops perf top after typing "Enter" is immediate and doesn't suffer from the delay_secs latency.

Quoted 7 lines

Nb: poll doesn't add any overhead that can parasite perf top measures since it sleeps the entire timeout here.

---
 Documentation/perf_counter/builtin-top.c |   18 ++++++++----------
 1 files changed, 8 insertions(+), 10 deletions(-)

Applied, thanks a lot Frederic!

Ingo

#2 lore raw

[tip:perfcounters/core] perf_counter: Sleep before refresh using poll in perf top

In reply to Frederic Weisbecker
Commit-ID:  0f5486b5c71a831a713ce356d8d06822e3c7c379
Gitweb:     http://git.kernel.org/tip/0f5486b5c71a831a713ce356d8d06822e3c7c379
Author:     Frederic Weisbecker <[email protected]>
AuthorDate: Thu, 4 Jun 2009 20:48:04 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Thu, 4 Jun 2009 21:44:53 +0200

perf_counter: Sleep before refresh using poll in perf top

perf top is refreshed every delay_secs the thread runs in such loop:

while (sleep(delay_secs)) {
	print_sym_table();
}

At the end of print_sym_table(), poll is used without sleep delay to check if we have something from stdin.

It means that this check is done only every delay_secs, which can be higher that 2 secs if the user defined a custom refresh rate.

We can drop sleep() here and directly use poll to wait between refresh periods, so that the reaction after the user stops perf top after typing "Enter" is immediate and doesn't suffer from the delay_secs latency.

Nb: poll doesn't add any overhead that can parasite perf top measures since it sleeps the entire timeout here.

Cc Peter Zijlstra <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Corey Ashford <[email protected]>
Cc Marcelo Tosatti <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Frederic Weisbecker <[email protected]>

LKML-Reference: <[email protected]>

---
 Documentation/perf_counter/builtin-top.c |   20 +++++++++-----------
 1 files changed, 9 insertions(+), 11 deletions(-)
Documentation/perf_counter/builtin-top.c +9 -11
index 31c00ba..28cbde4 100644
@@ -204,7 +204,7 @@ static void print_sym_table(void)
 			list_remove_active_sym(syme);
 	}
 
-	write(1, CONSOLE_CLEAR, strlen(CONSOLE_CLEAR));
+	puts(CONSOLE_CLEAR);
 
 	printf(
 "------------------------------------------------------------------------------\n");
@@ -278,23 +278,21 @@ static void print_sym_table(void)
 		color_fprintf(stdout, color, "%4.1f%%", pcnt);
 		printf(" - %016llx : %s\n", sym->start, sym->name);
 	}
-
-	{
-		struct pollfd stdin_poll = { .fd = 0, .events = POLLIN };
-
-		if (poll(&stdin_poll, 1, 0) == 1) {
-			printf("key pressed - exiting.\n");
-			exit(0);
-		}
-	}
 }
 
 static void *display_thread(void *arg)
 {
+	struct pollfd stdin_poll = { .fd = 0, .events = POLLIN };
+	int delay_msecs = delay_secs * 1000;
+
 	printf("PerfTop refresh period: %d seconds\n", delay_secs);
 
-	while (!sleep(delay_secs))
+	do {
 		print_sym_table();
+	} while (!poll(&stdin_poll, 1, delay_msecs) == 1);
+
+	printf("key pressed - exiting.\n");
+	exit(0);
 
 	return NULL;
 }