mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH -tip] perf stat: memcpy is only required if no event is selected and !null_run
@ 2009-06-27 18:19 Jaswinder Singh Rajput
  2009-06-28  5:31 ` Jaswinder Singh Rajput
  2009-06-28 13:42 ` [tip:perfcounters/urgent] perf stat: Micro-optimize the code: " tip-bot for Jaswinder Singh Rajput
  0 siblings, 2 replies; 3+ messages in thread
From: Jaswinder Singh Rajput @ 2009-06-27 18:19 UTC (permalink / raw)
  To: Ingo Molnar, Thomas Gleixner, Peter Zijlstra, LKML


Set attrs and nr_counters if no event is selected and !null_run

Setting of attrs should depend on number of counters,
so we need to memcpy only for sizeof(default_attrs)

and set nr_counters as ARRAY_SIZE(default_attrs) in place of hardcoded value

Signed-off-by: Jaswinder Singh Rajput <jaswinderrajput@gmail.com>
---
 tools/perf/builtin-stat.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 3840a70..3e5ea4e 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -46,7 +46,7 @@
 #include <sys/prctl.h>
 #include <math.h>
 
-static struct perf_counter_attr default_attrs[MAX_COUNTERS] = {
+static struct perf_counter_attr default_attrs[] = {
 
   { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_TASK_CLOCK	},
   { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_CONTEXT_SWITCHES},
@@ -477,16 +477,17 @@ int cmd_stat(int argc, const char **argv, const char *prefix)
 {
 	int status;
 
-	memcpy(attrs, default_attrs, sizeof(attrs));
-
 	argc = parse_options(argc, argv, options, stat_usage, 0);
 	if (!argc)
 		usage_with_options(stat_usage, options);
 	if (run_count <= 0 || run_count > MAX_RUN)
 		usage_with_options(stat_usage, options);
 
-	if (!null_run && !nr_counters)
-		nr_counters = 8;
+	/* Set attrs and nr_counters if no event is selected and !null_run */
+	if (!null_run && !nr_counters) {
+		memcpy(attrs, default_attrs, sizeof(default_attrs));
+		nr_counters = ARRAY_SIZE(default_attrs);
+	}
 
 	nr_cpus = sysconf(_SC_NPROCESSORS_ONLN);
 	assert(nr_cpus <= MAX_NR_CPUS);
-- 
1.6.0.6




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

* Re: [PATCH -tip] perf stat: memcpy is only required if no event is selected and !null_run
  2009-06-27 18:19 [PATCH -tip] perf stat: memcpy is only required if no event is selected and !null_run Jaswinder Singh Rajput
@ 2009-06-28  5:31 ` Jaswinder Singh Rajput
  2009-06-28 13:42 ` [tip:perfcounters/urgent] perf stat: Micro-optimize the code: " tip-bot for Jaswinder Singh Rajput
  1 sibling, 0 replies; 3+ messages in thread
From: Jaswinder Singh Rajput @ 2009-06-28  5:31 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: Thomas Gleixner, Peter Zijlstra, LKML

If You want can also add Impact Line.

Impact: Speedup, reduce binary size.


On Sat, 2009-06-27 at 23:49 +0530, Jaswinder Singh Rajput wrote:
> Set attrs and nr_counters if no event is selected and !null_run
> 
> Setting of attrs should depend on number of counters,
> so we need to memcpy only for sizeof(default_attrs)
> 
> and set nr_counters as ARRAY_SIZE(default_attrs) in place of hardcoded value
> 
> Signed-off-by: Jaswinder Singh Rajput <jaswinderrajput@gmail.com>
> ---
>  tools/perf/builtin-stat.c |   11 ++++++-----
>  1 files changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
> index 3840a70..3e5ea4e 100644
> --- a/tools/perf/builtin-stat.c
> +++ b/tools/perf/builtin-stat.c
> @@ -46,7 +46,7 @@
>  #include <sys/prctl.h>
>  #include <math.h>
>  
> -static struct perf_counter_attr default_attrs[MAX_COUNTERS] = {
> +static struct perf_counter_attr default_attrs[] = {
>  
>    { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_TASK_CLOCK	},
>    { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_CONTEXT_SWITCHES},
> @@ -477,16 +477,17 @@ int cmd_stat(int argc, const char **argv, const char *prefix)
>  {
>  	int status;
>  
> -	memcpy(attrs, default_attrs, sizeof(attrs));
> -
>  	argc = parse_options(argc, argv, options, stat_usage, 0);
>  	if (!argc)
>  		usage_with_options(stat_usage, options);
>  	if (run_count <= 0 || run_count > MAX_RUN)
>  		usage_with_options(stat_usage, options);
>  
> -	if (!null_run && !nr_counters)
> -		nr_counters = 8;
> +	/* Set attrs and nr_counters if no event is selected and !null_run */
> +	if (!null_run && !nr_counters) {
> +		memcpy(attrs, default_attrs, sizeof(default_attrs));
> +		nr_counters = ARRAY_SIZE(default_attrs);
> +	}
>  
>  	nr_cpus = sysconf(_SC_NPROCESSORS_ONLN);
>  	assert(nr_cpus <= MAX_NR_CPUS);


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

* [tip:perfcounters/urgent] perf stat: Micro-optimize the code: memcpy is only required if no event is selected and !null_run
  2009-06-27 18:19 [PATCH -tip] perf stat: memcpy is only required if no event is selected and !null_run Jaswinder Singh Rajput
  2009-06-28  5:31 ` Jaswinder Singh Rajput
@ 2009-06-28 13:42 ` tip-bot for Jaswinder Singh Rajput
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Jaswinder Singh Rajput @ 2009-06-28 13:42 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, peterz, jaswinder, jaswinderrajput,
	tglx, mingo

Commit-ID:  c3043569dc8fbe9228b76174f15d1a7152c48a20
Gitweb:     http://git.kernel.org/tip/c3043569dc8fbe9228b76174f15d1a7152c48a20
Author:     Jaswinder Singh Rajput <jaswinder@kernel.org>
AuthorDate: Sat, 27 Jun 2009 23:49:09 +0530
Committer:  Ingo Molnar <mingo@elte.hu>
CommitDate: Sun, 28 Jun 2009 15:22:47 +0200

perf stat: Micro-optimize the code: memcpy is only required if no event is selected and !null_run

Set attrs and nr_counters if no event is selected and !null_run.

Setting of attrs should depend on number of counters,
so we need to memcpy only for sizeof(default_attrs)

Also set nr_counters as ARRAY_SIZE(default_attrs) in place of
hardcoded value.

Signed-off-by: Jaswinder Singh Rajput <jaswinderrajput@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
LKML-Reference: <1246126749.32198.16.camel@hpdv5.satnam>
Signed-off-by: Ingo Molnar <mingo@elte.hu>


---
 tools/perf/builtin-stat.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 3840a70..3e5ea4e 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -46,7 +46,7 @@
 #include <sys/prctl.h>
 #include <math.h>
 
-static struct perf_counter_attr default_attrs[MAX_COUNTERS] = {
+static struct perf_counter_attr default_attrs[] = {
 
   { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_TASK_CLOCK	},
   { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_CONTEXT_SWITCHES},
@@ -477,16 +477,17 @@ int cmd_stat(int argc, const char **argv, const char *prefix)
 {
 	int status;
 
-	memcpy(attrs, default_attrs, sizeof(attrs));
-
 	argc = parse_options(argc, argv, options, stat_usage, 0);
 	if (!argc)
 		usage_with_options(stat_usage, options);
 	if (run_count <= 0 || run_count > MAX_RUN)
 		usage_with_options(stat_usage, options);
 
-	if (!null_run && !nr_counters)
-		nr_counters = 8;
+	/* Set attrs and nr_counters if no event is selected and !null_run */
+	if (!null_run && !nr_counters) {
+		memcpy(attrs, default_attrs, sizeof(default_attrs));
+		nr_counters = ARRAY_SIZE(default_attrs);
+	}
 
 	nr_cpus = sysconf(_SC_NPROCESSORS_ONLN);
 	assert(nr_cpus <= MAX_NR_CPUS);

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

end of thread, other threads:[~2009-06-28 13:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-27 18:19 [PATCH -tip] perf stat: memcpy is only required if no event is selected and !null_run Jaswinder Singh Rajput
2009-06-28  5:31 ` Jaswinder Singh Rajput
2009-06-28 13:42 ` [tip:perfcounters/urgent] perf stat: Micro-optimize the code: " tip-bot for Jaswinder Singh Rajput

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®