All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/1] perf util: Do not reuse target->per_thread flag
@ 2018-01-12 23:12 Mathieu Poirier
  2018-01-12 23:12 ` [PATCH 1/1] " Mathieu Poirier
  0 siblings, 1 reply; 3+ messages in thread
From: Mathieu Poirier @ 2018-01-12 23:12 UTC (permalink / raw)
  To: acme
  Cc: peterz, mingo, alexander.shishkin, jolsa, namhyung, yao.jin,
	linux-kernel

Hi Arnaldo,

Here is another stab at addressing the side effect introduced by commit
("73c0ca1eee3d perf thread_map: Enumerate all threads from /proc").

I have decided to add another variable to struct target, which keep
things simple and doesn't touch the core.  Another solution could have
been to make target->per_thread an enumaration with values PER_THREAD
and ALL_THREAD, something that could be switched on in function
thread_map__new_str().

I opted for the first option as it makes the code easier to understand.
Let me know what you prefer or get back to me with a better solution if
you see one.

Thanks,
Mathieu

Mathieu Poirier (1):
  perf util: Do not reuse target->per_thread flag

 tools/perf/builtin-stat.c    | 2 +-
 tools/perf/util/evlist.c     | 2 +-
 tools/perf/util/target.h     | 1 +
 tools/perf/util/thread_map.c | 4 ++--
 tools/perf/util/thread_map.h | 2 +-
 5 files changed, 6 insertions(+), 5 deletions(-)

-- 
2.7.4

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

* [PATCH 1/1] perf util: Do not reuse target->per_thread flag
  2018-01-12 23:12 [PATCH 0/1] perf util: Do not reuse target->per_thread flag Mathieu Poirier
@ 2018-01-12 23:12 ` Mathieu Poirier
  2018-01-22 13:05   ` Jin, Yao
  0 siblings, 1 reply; 3+ messages in thread
From: Mathieu Poirier @ 2018-01-12 23:12 UTC (permalink / raw)
  To: acme
  Cc: peterz, mingo, alexander.shishkin, jolsa, namhyung, yao.jin,
	linux-kernel

Commit ("73c0ca1eee3d perf thread_map: Enumerate all threads from /proc")
is using the target->per_thread flag to specify that all threads in a
system should be taken into account.  That is then used in function
thread_map__new_str() where all threads are added to evlist->threads.

Variable target->per_thread is also used by 'perf record' when handling
trace sessions using the --per-thread command line option.  Since the
target->per_thread flag is set all threads will be added to
evlist->threads, which has the effect of creating a kernel event for each
thread in the system.

This patch address the issue by creating a new target->all_threads flag
that gets set from the 'stat' utility, avoiding any conflict with other
utilities using target->per_thread.

Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
---
 tools/perf/builtin-stat.c    | 2 +-
 tools/perf/util/evlist.c     | 2 +-
 tools/perf/util/target.h     | 1 +
 tools/perf/util/thread_map.c | 4 ++--
 tools/perf/util/thread_map.h | 2 +-
 5 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 98bf9d32f222..87e156bfb45e 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -2831,7 +2831,7 @@ int cmd_stat(int argc, const char **argv)
 	target__validate(&target);
 
 	if ((stat_config.aggr_mode == AGGR_THREAD) && (target.system_wide))
-		target.per_thread = true;
+		target.per_thread = target.all_threads = true;
 
 	if (perf_evlist__create_maps(evsel_list, &target) < 0) {
 		if (target__has_task(&target)) {
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index f0a5e09c4071..c239eb895612 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -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->all_threads);
 
 	if (!threads)
 		return -1;
diff --git a/tools/perf/util/target.h b/tools/perf/util/target.h
index 6ef01a83b24e..0da8ea2b6801 100644
--- a/tools/perf/util/target.h
+++ b/tools/perf/util/target.h
@@ -15,6 +15,7 @@ struct target {
 	bool	     uses_mmap;
 	bool	     default_per_cpu;
 	bool	     per_thread;
+	bool	     all_threads;
 };
 
 enum target_errno {
diff --git a/tools/perf/util/thread_map.c b/tools/perf/util/thread_map.c
index 3e1038f6491c..729dad8f412d 100644
--- a/tools/perf/util/thread_map.c
+++ b/tools/perf/util/thread_map.c
@@ -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);
diff --git a/tools/perf/util/thread_map.h b/tools/perf/util/thread_map.h
index 0a806b99e73c..5ec91cfd1869 100644
--- a/tools/perf/util/thread_map.h
+++ b/tools/perf/util/thread_map.h
@@ -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

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

* Re: [PATCH 1/1] perf util: Do not reuse target->per_thread flag
  2018-01-12 23:12 ` [PATCH 1/1] " Mathieu Poirier
@ 2018-01-22 13:05   ` Jin, Yao
  0 siblings, 0 replies; 3+ messages in thread
From: Jin, Yao @ 2018-01-22 13:05 UTC (permalink / raw)
  To: Mathieu Poirier, acme
  Cc: peterz, mingo, alexander.shishkin, jolsa, namhyung, linux-kernel

Hi Mathieu,

Sorry, I just see this patch today.

I have tested this patch and it works.

Another idea from me is it doesn't need to add a new target->all_threads 
flag.

We just use target->per-thread && target->system_wide as a condition to 
check for all per-thread case.

I just think for your perf record case, the target->system_wide will not 
be set. Instead, if target->per-thread and target->system_wide are both 
set, that means we needs to trace on all threads, right?

Thanks
Jin Yao

On 1/13/2018 7:12 AM, Mathieu Poirier wrote:
> Commit ("73c0ca1eee3d perf thread_map: Enumerate all threads from /proc")
> is using the target->per_thread flag to specify that all threads in a
> system should be taken into account.  That is then used in function
> thread_map__new_str() where all threads are added to evlist->threads.
> 
> Variable target->per_thread is also used by 'perf record' when handling
> trace sessions using the --per-thread command line option.  Since the
> target->per_thread flag is set all threads will be added to
> evlist->threads, which has the effect of creating a kernel event for each
> thread in the system.
> 
> This patch address the issue by creating a new target->all_threads flag
> that gets set from the 'stat' utility, avoiding any conflict with other
> utilities using target->per_thread.
> 
> Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
> ---
>   tools/perf/builtin-stat.c    | 2 +-
>   tools/perf/util/evlist.c     | 2 +-
>   tools/perf/util/target.h     | 1 +
>   tools/perf/util/thread_map.c | 4 ++--
>   tools/perf/util/thread_map.h | 2 +-
>   5 files changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
> index 98bf9d32f222..87e156bfb45e 100644
> --- a/tools/perf/builtin-stat.c
> +++ b/tools/perf/builtin-stat.c
> @@ -2831,7 +2831,7 @@ int cmd_stat(int argc, const char **argv)
>   	target__validate(&target);
>   
>   	if ((stat_config.aggr_mode == AGGR_THREAD) && (target.system_wide))
> -		target.per_thread = true;
> +		target.per_thread = target.all_threads = true;
>   
>   	if (perf_evlist__create_maps(evsel_list, &target) < 0) {
>   		if (target__has_task(&target)) {
> diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
> index f0a5e09c4071..c239eb895612 100644
> --- a/tools/perf/util/evlist.c
> +++ b/tools/perf/util/evlist.c
> @@ -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->all_threads);
>   
>   	if (!threads)
>   		return -1;
> diff --git a/tools/perf/util/target.h b/tools/perf/util/target.h
> index 6ef01a83b24e..0da8ea2b6801 100644
> --- a/tools/perf/util/target.h
> +++ b/tools/perf/util/target.h
> @@ -15,6 +15,7 @@ struct target {
>   	bool	     uses_mmap;
>   	bool	     default_per_cpu;
>   	bool	     per_thread;
> +	bool	     all_threads;
>   };
>   
>   enum target_errno {
> diff --git a/tools/perf/util/thread_map.c b/tools/perf/util/thread_map.c
> index 3e1038f6491c..729dad8f412d 100644
> --- a/tools/perf/util/thread_map.c
> +++ b/tools/perf/util/thread_map.c
> @@ -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);
> diff --git a/tools/perf/util/thread_map.h b/tools/perf/util/thread_map.h
> index 0a806b99e73c..5ec91cfd1869 100644
> --- a/tools/perf/util/thread_map.h
> +++ b/tools/perf/util/thread_map.h
> @@ -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);
>   
> 

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

end of thread, other threads:[~2018-01-22 13:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-12 23:12 [PATCH 0/1] perf util: Do not reuse target->per_thread flag Mathieu Poirier
2018-01-12 23:12 ` [PATCH 1/1] " Mathieu Poirier
2018-01-22 13:05   ` Jin, Yao

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.