perf util: Use target->per_thread and target->system_wide flags
PATCH 1/1 perf util: Use target->per_thread and target->system_wide flags
Mathieu Poirier reports issue in commit ("73c0ca1eee3d perf thread_map:
Enumerate all threads from /proc") that it has negative impact on 'perf record --per-thread'. It has the effect of creating a kernel event for each thread in the system for 'perf record --per-thread'.
Mathieu Poirier's patch ("perf util: Do not reuse target->per_thread flag") can fix this issue by creating a new target->all_threads flag.
This patch is based on Mathieu Poirier's patch but it doesn't use a new target->all_threads flag. This patch just uses 'target->per_thread && target->system_wide' as a condition to check for all threads case.
--- tools/perf/util/evlist.c | 2 +- tools/perf/util/thread_map.c | 4 ++-- tools/perf/util/thread_map.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
tools/perf/util/evlist.c +1 -1
@@ -1106,7 +1106,7 @@ int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target)struct thread_map *threads; threads =thread_map__new_str (target->pid, target->tid, target->uid, - target->per_thread); + target->per_thread && target->system_wide);if (!threads)return -1 ;
tools/perf/util/thread_map.c +2 -2
@@ -323,7 +323,7 @@ struct thread_map *thread_map__new_by_tid_str(const char *tid_str) }struct thread_map *thread_map__new_str (const char *pid,const char *tid, -uid_t uid,bool per_thread) +uid_t uid,bool all_threads) {if (pid)return thread_map__new_by_pid_str (pid);
@@ -331,7 +331,7 @@ struct thread_map *thread_map__new_str(const char *pid, const char *tid,if (!tid && uid !=UINT_MAX )return thread_map__new_by_uid (uid); -if (per_thread) +if (all_threads)return thread_map__new_all_cpus ();return thread_map__new_by_tid_str (tid);
tools/perf/util/thread_map.h +1 -1
@@ -31,7 +31,7 @@ struct thread_map *thread_map__get(struct thread_map *map);void thread_map__put (struct thread_map *map);struct thread_map *thread_map__new_str (const char *pid, -const char *tid,uid_t uid,bool per_thread); +const char *tid,uid_t uid,bool all_threads);struct thread_map *thread_map__new_by_tid_str (const char *tid_str);
Signature · 1 line
2.7.4
Quoted 24 lines · Jin Yao
Mathieu Poirier reports issue in commit ("
73c0ca1eee3dperfthread_map:
Enumerate all threads from /proc") that it has negative impact on 'perf record --per-thread'. It has the effect of creating a kernel event for each thread in the system for 'perf record --per-thread'.Mathieu Poirier's patch ("perf util: Do not reuse
target->per_threadflag") can fix this issue by creating a newtarget->all_threadsflag.This patch is based on Mathieu Poirier's patch but it doesn't use a new
target->all_threadsflag. This patch just uses 'target->per_thread&&target->system_wide' as a condition to check for all threads case.Signed-off-by Jin Yao <[email protected]>--- tools/perf/util/evlist.c | 2 +- tools/perf/util/thread_map.c | 4 ++-- tools/perf/util/thread_map.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)tools/perf/util/evlist.c +0
-0
tools/perf/util/evlist.c int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target) · line 1109
Quoted 5 lines
tools/perf/util/evlist.c +1
-1@@ -1106,7 +1106,7 @@ int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target)struct thread_map *threads; threads =thread_map__new_str (target->pid, target->tid, target->uid, - target->per_thread); + target->per_thread && target->system_wide);
At first glance I thought your solution would do the trick but perf record does use target->system_wide when the '-a' switch is used. Moreover specifying the '-a' switch doesn't prevent the '--per-thread' option from being used as well, making both target->perf_thread and target_system_wide equal to true (and that is not good).
Although not a fan of adding more to struct target, the advantage of having target->all_threads is that we are guaranteed that it isn't used anywhere else.
Let me know what you think,
Mathieu
Quoted 41 lines
tools/perf/util/evlist.c +0
-0if (!threads)return -1 ;tools/perf/util/thread_map.c +2
-2@@ -323,7 +323,7 @@ struct thread_map *thread_map__new_by_tid_str(const char *tid_str) }struct thread_map *thread_map__new_str (const char *pid,const char *tid, -uid_t uid,bool per_thread) +uid_t uid,bool all_threads) {if (pid)return thread_map__new_by_pid_str (pid);@@ -331,7 +331,7 @@ struct thread_map *thread_map__new_str(const char *pid, const char *tid,if (!tid && uid !=UINT_MAX )return thread_map__new_by_uid (uid); -if (per_thread) +if (all_threads)return thread_map__new_all_cpus ();return thread_map__new_by_tid_str (tid);tools/perf/util/thread_map.h +1
-2@@ -31,7 +31,7 @@ struct thread_map *thread_map__get(struct thread_map *map);void thread_map__put (struct thread_map *map);struct thread_map *thread_map__new_str (const char *pid, -const char *tid,uid_t uid,bool per_thread); +const char *tid,uid_t uid,bool all_threads);struct thread_map *thread_map__new_by_tid_str (const char *tid_str); --2.7.4
Quoted 37 lines · Mathieu Poirier
Quoted 24 lines · Jin Yao
Mathieu Poirier reports issue in commit ("
73c0ca1eee3dperfthread_map:
Enumerate all threads from /proc") that it has negative impact on 'perf record --per-thread'. It has the effect of creating a kernel event for each thread in the system for 'perf record --per-thread'.Mathieu Poirier's patch ("perf util: Do not reuse
target->per_threadflag") can fix this issue by creating a newtarget->all_threadsflag.This patch is based on Mathieu Poirier's patch but it doesn't use a new
target->all_threadsflag. This patch just uses 'target->per_thread&&target->system_wide' as a condition to check for all threads case.Signed-off-by Jin Yao <[email protected]>--- tools/perf/util/evlist.c | 2 +- tools/perf/util/thread_map.c | 4 ++-- tools/perf/util/thread_map.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)tools/perf/util/evlist.c +0
-0tools/perf/util/evlist.c int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target) · line 1109
Quoted 5 lines
tools/perf/util/evlist.c +1
-1@@ -1106,7 +1106,7 @@ int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target)struct thread_map *threads; threads =thread_map__new_str (target->pid, target->tid, target->uid, - target->per_thread); + target->per_thread && target->system_wide);At first glance I thought your solution would do the trick but perf record does use
target->system_widewhen the '-a' switch is used. Moreover specifying the '-a' switch doesn't prevent the '--per-thread' option from being used as well, making bothtarget->perf_threadandtarget_system_wideequal to true (and that is not good).
Quoted 7 lines
Although not a fan of adding more to struct target, the advantage of having
target->all_threadsis that we are guaranteed that it isn't used anywhere else.Let me know what you think,
Mathieu
If we specify both '-a' and '--per-thread' to perf record, perf record will override'--per-thread'. So now target->per_thread = false, and target->system_wide = true.
If we specify '--per-thread' only to perf record, target->per_thread = true, and target->system_wide = false.
So whatever for any case, target->per_thread && target->system_wide is false.
Since the parameter is false, in thread_map__new_str(), it will not execute the thread_map__new_all_cpus(). So that will not change perf record previous behavior.
In perf stat, it allows the case that target->per_thread and target->system_wide are all true. That means we want to collect system-wide per-thread metrics.
That's my current thinking.
Thanks
Jin Yao
Quoted 51 lines · Yao
Quoted 48 lines · Mathieu Poirier
Quoted 26 lines · Jin Yao
Mathieu Poirier reports issue in commit ("
73c0ca1eee3dperfthread_map:
Enumerate all threads from /proc") that it has negative impact on 'perf record --per-thread'. It has the effect of creating a kernel event for each thread in the system for 'perf record --per-thread'.Mathieu Poirier's patch ("perf util: Do not reuse
target->per_threadflag")
can fix this issue by creating a newtarget->all_threadsflag.This patch is based on Mathieu Poirier's patch but it doesn't use a new
target->all_threadsflag. This patch just uses 'target->per_thread&&target->system_wide' as a condition to check for all threads case.Signed-off-by Jin Yao <[email protected]>--- tools/perf/util/evlist.c | 2 +- tools/perf/util/thread_map.c | 4 ++-- tools/perf/util/thread_map.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)tools/perf/util/evlist.c +0
-0tools/perf/util/evlist.c int perf_evlist__create_maps(struct perf_evlist · line 1112
Quoted 8 lines
tools/perf/util/evlist.c +1
-1@@ -1106,7 +1106,7 @@ int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target)struct thread_map *threads; threads =thread_map__new_str (target->pid, target->tid, target->uid, - target->per_thread); + target->per_thread && target->system_wide);At first glance I thought your solution would do the trick but perf record does use
target->system_widewhen the '-a' switch is used. Moreover specifying the '-a' switch doesn't prevent the '--per-thread' option from being used as well, making bothtarget->perf_threadandtarget_system_wideequal to true (and that is not good).Although not a fan of adding more to struct target, the advantage of having
target->all_threadsis that we are guaranteed that it isn't used anywhere else.
Quoted 7 lines
Quoted 3 lines
Let me know what you think,
MathieuIf we specify both '-a' and '--per-thread' to perf record, perf record will override'--per-thread'. So now
target->per_thread= false, andtarget->system_wide= true.
Just spent time looking at it further and target__validate() will make sure per thread and cpu wide options are mutually exclusive. I like your approach better so let's go with that.
Thanks,
Mathieu
Quoted 19 lines
If we specify '--per-thread' only to perf record,
target->per_thread= true, andtarget->system_wide= false.So whatever for any case,
target->per_thread&&target->system_wideis false.Since the parameter is false, in
thread_map__new_str(), it will not execute thethread_map__new_all_cpus(). So that will not change perf record previous behavior.In perf stat, it allows the case that
target->per_threadandtarget->system_wideare all true. That means we want to collect system-wide per-thread metrics.That's my current thinking.
Thanks
Jin Yao
On Tue, Jan 23, 2018 at 07:02:44AM +0800, Jin, Yao wrote:
SNIP
Quoted 28 lines
Quoted 10 lines
tools/perf/util/evlist.c int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target) · line 1109
Quoted 3 lines
threads = thread_map__new_str(target->pid, target->tid, target->uid,tools/perf/util/evlist.c +1
-1- target->per_thread); + target->per_thread && target->system_wide);At first glance I thought your solution would do the trick but perf record does use
target->system_widewhen the '-a' switch is used. Moreover specifying the '-a' switch doesn't prevent the '--per-thread' option from being used as well, making bothtarget->perf_threadandtarget_system_wideequal to true (and that is not good).Quoted 7 lines
Although not a fan of adding more to struct target, the advantage of having
target->all_threadsis that we are guaranteed that it isn't used anywhere else.Let me know what you think,
MathieuIf we specify both '-a' and '--per-thread' to perf record, perf record will override'--per-thread'. So now
target->per_thread= false, andtarget->system_wide= true.If we specify '--per-thread' only to perf record,
target->per_thread= true, andtarget->system_wide= false.So whatever for any case,
target->per_thread&&target->system_wideis false.
Quoted 7 lines
Since the parameter is false, in
thread_map__new_str(), it will not execute thethread_map__new_all_cpus(). So that will not change perf record previous behavior.In perf stat, it allows the case that
target->per_threadandtarget->system_wideare all true. That means we want to collect system-wide per-thread metrics.
could you please put this description into comment before the thread_map__new_str is called?
thanks,
jirka
Quoted 40 lines · Jiri Olsa
On Tue, Jan 23, 2018 at 07:02:44AM +0800, Jin, Yao wrote:
SNIP
Quoted 28 lines
Quoted 10 lines
tools/perf/util/evlist.c int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target) · line 1109
Quoted 3 lines
threads = thread_map__new_str(target->pid, target->tid, target->uid,tools/perf/util/evlist.c +1
-1- target->per_thread); + target->per_thread && target->system_wide);At first glance I thought your solution would do the trick but perf record does use
target->system_widewhen the '-a' switch is used. Moreover specifying the '-a' switch doesn't prevent the '--per-thread' option from being used as well, making bothtarget->perf_threadandtarget_system_wideequal to true (and that is not good).Quoted 7 lines
Although not a fan of adding more to struct target, the advantage of having
target->all_threadsis that we are guaranteed that it isn't used anywhere else.Let me know what you think,
MathieuIf we specify both '-a' and '--per-thread' to perf record, perf record will override'--per-thread'. So now
target->per_thread= false, andtarget->system_wide= true.If we specify '--per-thread' only to perf record,
target->per_thread= true, andtarget->system_wide= false.So whatever for any case,
target->per_thread&&target->system_wideis false.Quoted 7 lines
Since the parameter is false, in
thread_map__new_str(), it will not execute thethread_map__new_all_cpus(). So that will not change perf record previous behavior.In perf stat, it allows the case that
target->per_threadandtarget->system_wideare all true. That means we want to collect system-wide per-thread metrics.
Quoted 6 lines
could you please put this description into comment before the
thread_map__new_stris called?thanks,
jirka
OK, I will put this comment in v2. I will send v2 soon.
Thanks
Jin Yao
Quoted 59 lines · Jin Yao
Mathieu Poirier reports issue in commit ("
73c0ca1eee3dperfthread_map:
Enumerate all threads from /proc") that it has negative impact on 'perf record --per-thread'. It has the effect of creating a kernel event for each thread in the system for 'perf record --per-thread'.Mathieu Poirier's patch ("perf util: Do not reuse
target->per_threadflag") can fix this issue by creating a newtarget->all_threadsflag.This patch is based on Mathieu Poirier's patch but it doesn't use a new
target->all_threadsflag. This patch just uses 'target->per_thread&&target->system_wide' as a condition to check for all threads case.Signed-off-by Jin Yao <[email protected]>--- tools/perf/util/evlist.c | 2 +- tools/perf/util/thread_map.c | 4 ++-- tools/perf/util/thread_map.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)tools/perf/util/evlist.c +1
-1@@ -1106,7 +1106,7 @@ int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target)struct thread_map *threads; threads =thread_map__new_str (target->pid, target->tid, target->uid, - target->per_thread); + target->per_thread && target->system_wide);if (!threads)return -1 ;tools/perf/util/thread_map.c +2
-2@@ -323,7 +323,7 @@ struct thread_map *thread_map__new_by_tid_str(const char *tid_str) }struct thread_map *thread_map__new_str (const char *pid,const char *tid, -uid_t uid,bool per_thread) +uid_t uid,bool all_threads) {if (pid)return thread_map__new_by_pid_str (pid);@@ -331,7 +331,7 @@ struct thread_map *thread_map__new_str(const char *pid, const char *tid,if (!tid && uid !=UINT_MAX )return thread_map__new_by_uid (uid); -if (per_thread) +if (all_threads)return thread_map__new_all_cpus ();return thread_map__new_by_tid_str (tid);tools/perf/util/thread_map.h +0
-0
tools/perf/util/thread_map.h struct thread_map *thread_map__get(struct thread_map *map); · line 36
Quoted 7 lines
tools/perf/util/thread_map.h +1
-1@@ -31,7 +31,7 @@ struct thread_map *thread_map__get(struct thread_map *map);void thread_map__put (struct thread_map *map);struct thread_map *thread_map__new_str (const char *pid, -const char *tid,uid_t uid,bool per_thread); +const char *tid,uid_t uid,bool all_threads);struct thread_map *thread_map__new_by_tid_str (const char *tid_str);
Quoted 4 lines
tools/perf/util/thread_map.h +0
-1--2.7.4
Quoted 62 lines · Mathieu Poirier
Quoted 61 lines · Jin Yao
Mathieu Poirier reports issue in commit ("
73c0ca1eee3dperfthread_map:
Enumerate all threads from /proc") that it has negative impact on 'perf record --per-thread'. It has the effect of creating a kernel event for each thread in the system for 'perf record --per-thread'.Mathieu Poirier's patch ("perf util: Do not reuse
target->per_threadflag") can fix this issue by creating a newtarget->all_threadsflag.This patch is based on Mathieu Poirier's patch but it doesn't use a new
target->all_threadsflag. This patch just uses 'target->per_thread&&target->system_wide' as a condition to check for all threads case.Signed-off-by Jin Yao <[email protected]>--- tools/perf/util/evlist.c | 2 +- tools/perf/util/thread_map.c | 4 ++-- tools/perf/util/thread_map.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)tools/perf/util/evlist.c +1
-1@@ -1106,7 +1106,7 @@ int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target)struct thread_map *threads; threads =thread_map__new_str (target->pid, target->tid, target->uid, - target->per_thread); + target->per_thread && target->system_wide);if (!threads)return -1 ;tools/perf/util/thread_map.c +2
-2@@ -323,7 +323,7 @@ struct thread_map *thread_map__new_by_tid_str(const char *tid_str) }struct thread_map *thread_map__new_str (const char *pid,const char *tid, -uid_t uid,bool per_thread) +uid_t uid,bool all_threads) {if (pid)return thread_map__new_by_pid_str (pid);@@ -331,7 +331,7 @@ struct thread_map *thread_map__new_str(const char *pid, const char *tid,if (!tid && uid !=UINT_MAX )return thread_map__new_by_uid (uid); -if (per_thread) +if (all_threads)return thread_map__new_all_cpus ();return thread_map__new_by_tid_str (tid);tools/perf/util/thread_map.h +0
-0@@ -31,7 +31,7 @@ struct thread_map *thread_map__get(struct thread_map *map);void thread_map__put (struct thread_map *map);
Quoted 8 lines
tools/perf/util/thread_map.h struct thread_map *thread_map__get(struct thread_map *map); · line 36
Quoted 5 lines
tools/perf/util/thread_map.h +1
-1struct thread_map *thread_map__new_str (const char *pid, -const char *tid,uid_t uid,bool per_thread); +const char *tid,uid_t uid,bool all_threads);struct thread_map *thread_map__new_by_tid_str (const char *tid_str);Reviewed-and-tested-by Mathieu Poirier "[email protected]"
Thanks a lot for reviewing the patch.
Thanks
Jin Yao