All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf/sched: fix for getting task's execute time
@ 2009-12-06 10:57 Xiao Guangrong
  2009-12-06 11:05 ` Peter Zijlstra
  0 siblings, 1 reply; 13+ messages in thread
From: Xiao Guangrong @ 2009-12-06 10:57 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: Peter Zijlstra, Frederic Weisbecker, Paul Mackerras, LKML

In current code, we get task's execute time by reading
"/proc/<pid>/sched" file, it's wrong if the task is created
by pthread_create(), because every thread task has same pid.
So, the correct way is reading "/proc/<ppid>/task/<tid>/sched"
file.

This patch also remove redundant include files since <sys/types.h>
is included in "perf.h"

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
---
 tools/perf/builtin-sched.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 26b782f..b2e910e 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -13,7 +13,6 @@
 #include "util/debug.h"
 #include "util/data_map.h"
 
-#include <sys/types.h>
 #include <sys/prctl.h>
 
 #include <semaphore.h>
@@ -416,7 +415,7 @@ static u64 get_cpu_usage_nsec_parent(void)
 
 static u64 get_cpu_usage_nsec_self(void)
 {
-	char filename [] = "/proc/1234567890/sched";
+	char filename [] = "/proc/1234567890/task/1234567890/sched";
 	unsigned long msecs, nsecs;
 	char *line = NULL;
 	u64 total = 0;
@@ -425,7 +424,9 @@ static u64 get_cpu_usage_nsec_self(void)
 	FILE *file;
 	int ret;
 
-	sprintf(filename, "/proc/%d/sched", getpid());
+	sprintf(filename, "/proc/%d/task/%d/sched", getpid(),
+		(pid_t)syscall(SYS_gettid));
+
 	file = fopen(filename, "r");
 	BUG_ON(!file);
 
-- 
1.6.1.2



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

end of thread, other threads:[~2009-12-09 10:04 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-06 10:57 [PATCH] perf/sched: fix for getting task's execute time Xiao Guangrong
2009-12-06 11:05 ` Peter Zijlstra
2009-12-06 11:06   ` Peter Zijlstra
2009-12-06 11:50     ` Ingo Molnar
2009-12-06 17:10     ` Xiao Guangrong
2009-12-07  7:20       ` [PATCH v2] perf/sched: fix for getting task's execution time Xiao Guangrong
2009-12-07  7:30         ` Ingo Molnar
2009-12-09  9:51           ` [PATCH v3] " Xiao Guangrong
2009-12-09  9:54             ` Xiao Guangrong
2009-12-09  9:59               ` Ingo Molnar
2009-12-09  9:57             ` Xiao Guangrong
2009-12-09  9:57             ` Ingo Molnar
2009-12-09 10:03             ` [tip:perf/urgent] perf sched: Fix " tip-bot for Xiao Guangrong

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.