Re: [PATCH 02/16] perf pmu: Let pmu's with no events show up on perf list

2014-10-24 Thread Arnaldo Carvalho de Melo
Em Fri, Oct 24, 2014 at 11:45:00AM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Fri, Oct 24, 2014 at 05:36:46PM +0300, Adrian Hunter escreveu:
> > >+  aliases = zalloc(sizeof(char *) * len);
> > >   if (!aliases)
> > >-  return;
> > >+  goto out_enomem;
> > 
> > That path tries to free aliases[j] but aliases is null.  You could set len 
> > to 0 in that case.

You got me confused, yeah, it ended up a bit confusing, but the idea was
to share the error message, i.e. have just one printf("FATAL:
enomem"...) for both alloc failures, the later will have to free the
array elements, and it is ok to call free(NULL), thus the change from
malloc to zalloc(aliases), so that all its entries were zeroed, yadda,
yadda.

- Arnaldo
 
> 
> Oops, yeah, my bad, it should not have the !, fixing...
>  
> > >   pmu = NULL;
> > >   j = 0;
> > >   while ((pmu = perf_pmu__scan(pmu)) != NULL) {
> > >@@ -768,16 +768,20 @@ void print_pmu_events(const char *event_glob, bool 
> > >name_only)
> > > (!is_cpu && strglobmatch(alias->name,
> > >  event_glob
> > >   continue;
> > >-  aliases[j] = name;
> > >+
> > >   if (is_cpu && !name_only)
> > >-  aliases[j] = format_alias_or(buf, sizeof(buf),
> > >-pmu, alias);
> > >-  aliases[j] = strdup(aliases[j]);
> > >+  name = format_alias_or(buf, sizeof(buf), pmu, 
> > >alias);
> > >+
> > >+  aliases[j] = strdup(name);
> > >+  if (aliases[j] == NULL)
> > >+  goto out_enomem;
> > >   j++;
> > >   }
> > >   if (pmu->selectable) {
> > >-  scnprintf(buf, sizeof(buf), "%s//", pmu->name);
> > >-  aliases[j] = strdup(buf);
> > >+  char *s;
> > >+  if (asprintf(, "%s//", pmu->name) < 0)
> > >+  goto out_enomem;
> > >+  aliases[j] = s;
> > >   j++;
> > >   }
> > >   }
> > >@@ -789,12 +793,20 @@ void print_pmu_events(const char *event_glob, bool 
> > >name_only)
> > >   continue;
> > >   }
> > >   printf("  %-50s [Kernel PMU event]\n", aliases[j]);
> > >-  zfree([j]);
> > >   printed++;
> > >   }
> > >   if (printed)
> > >   printf("\n");
> > >-  free(aliases);
> > >+out_free:
> > >+  for (j = 0; j < len; j++)
> > >+  zfree([j]);
> > >+  zfree();
> > >+  return;
> > >+
> > >+out_enomem:
> > >+  printf("FATAL: not enough memory to print PMU events\n");
> > >+  if (aliases)
> > >+  goto out_free;
> > >  }
> > >
> > >  bool pmu_have_event(const char *pname, const char *name)
> > >
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 02/16] perf pmu: Let pmu's with no events show up on perf list

2014-10-24 Thread Arnaldo Carvalho de Melo
Em Fri, Oct 24, 2014 at 05:36:46PM +0300, Adrian Hunter escreveu:
> On 24/10/2014 4:21 p.m., Arnaldo Carvalho de Melo wrote:
> >Em Fri, Oct 24, 2014 at 10:03:20AM -0300, Arnaldo Carvalho de Melo escreveu:
> >>Em Fri, Oct 24, 2014 at 09:57:02AM -0300, Arnaldo Carvalho de Melo escreveu:
> >>>Em Fri, Oct 24, 2014 at 02:15:52PM +0900, Namhyung Kim escreveu:
> On Thu, 23 Oct 2014 13:45:10 +0300, Adrian Hunter wrote:
> >+if (pmu->selectable) {
> >+scnprintf(buf, sizeof(buf), "%s//", pmu->name);
> >+aliases[j] = strdup(buf);
> 
> You need to check the return value here (and above too).
> >>>
> >>>Well spotted, fixing this up.
> >>
> >>Oh well, this print_pmu_events() function needs some care, it starts by
> >>trying to alloc the array, if it fails, it silently returns, does that
> >>mean that there are no pmu events? Or that memory allocation failed?
> >>
> >>Ok, will do the fixes in a separate patch...
> >>
> >>- Arnaldo
> >
> >The patch below should check everything and warn the user, even
> >maintaining that void return...
> >
> >Acked-by tags welcome as always :-)
> >
> >- Arnaldo
> >
> >
> >diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
> >index 91dca60..881b754 100644
> >--- a/tools/perf/util/pmu.c
> >+++ b/tools/perf/util/pmu.c
> >@@ -753,9 +753,9 @@ void print_pmu_events(const char *event_glob, bool 
> >name_only)
> > if (pmu->selectable)
> > len++;
> > }
> >-aliases = malloc(sizeof(char *) * len);
> >+aliases = zalloc(sizeof(char *) * len);
> > if (!aliases)
> >-return;
> >+goto out_enomem;
> 
> That path tries to free aliases[j] but aliases is null.  You could set len to 
> 0 in that case.


Oops, yeah, my bad, it should not have the !, fixing...
 
> > pmu = NULL;
> > j = 0;
> > while ((pmu = perf_pmu__scan(pmu)) != NULL) {
> >@@ -768,16 +768,20 @@ void print_pmu_events(const char *event_glob, bool 
> >name_only)
> >   (!is_cpu && strglobmatch(alias->name,
> >event_glob
> > continue;
> >-aliases[j] = name;
> >+
> > if (is_cpu && !name_only)
> >-aliases[j] = format_alias_or(buf, sizeof(buf),
> >-  pmu, alias);
> >-aliases[j] = strdup(aliases[j]);
> >+name = format_alias_or(buf, sizeof(buf), pmu, 
> >alias);
> >+
> >+aliases[j] = strdup(name);
> >+if (aliases[j] == NULL)
> >+goto out_enomem;
> > j++;
> > }
> > if (pmu->selectable) {
> >-scnprintf(buf, sizeof(buf), "%s//", pmu->name);
> >-aliases[j] = strdup(buf);
> >+char *s;
> >+if (asprintf(, "%s//", pmu->name) < 0)
> >+goto out_enomem;
> >+aliases[j] = s;
> > j++;
> > }
> > }
> >@@ -789,12 +793,20 @@ void print_pmu_events(const char *event_glob, bool 
> >name_only)
> > continue;
> > }
> > printf("  %-50s [Kernel PMU event]\n", aliases[j]);
> >-zfree([j]);
> > printed++;
> > }
> > if (printed)
> > printf("\n");
> >-free(aliases);
> >+out_free:
> >+for (j = 0; j < len; j++)
> >+zfree([j]);
> >+zfree();
> >+return;
> >+
> >+out_enomem:
> >+printf("FATAL: not enough memory to print PMU events\n");
> >+if (aliases)
> >+goto out_free;
> >  }
> >
> >  bool pmu_have_event(const char *pname, const char *name)
> >
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 02/16] perf pmu: Let pmu's with no events show up on perf list

2014-10-24 Thread Adrian Hunter

On 24/10/2014 5:36 p.m., Adrian Hunter wrote:

On 24/10/2014 4:21 p.m., Arnaldo Carvalho de Melo wrote:

Em Fri, Oct 24, 2014 at 10:03:20AM -0300, Arnaldo Carvalho de Melo escreveu:

Em Fri, Oct 24, 2014 at 09:57:02AM -0300, Arnaldo Carvalho de Melo escreveu:

Em Fri, Oct 24, 2014 at 02:15:52PM +0900, Namhyung Kim escreveu:

On Thu, 23 Oct 2014 13:45:10 +0300, Adrian Hunter wrote:

+if (pmu->selectable) {
+scnprintf(buf, sizeof(buf), "%s//", pmu->name);
+aliases[j] = strdup(buf);


You need to check the return value here (and above too).


Well spotted, fixing this up.


Oh well, this print_pmu_events() function needs some care, it starts by
trying to alloc the array, if it fails, it silently returns, does that
mean that there are no pmu events? Or that memory allocation failed?

Ok, will do the fixes in a separate patch...

- Arnaldo


The patch below should check everything and warn the user, even
maintaining that void return...

Acked-by tags welcome as always :-)

- Arnaldo


diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 91dca60..881b754 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -753,9 +753,9 @@ void print_pmu_events(const char *event_glob, bool 
name_only)
  if (pmu->selectable)
  len++;
  }
-aliases = malloc(sizeof(char *) * len);
+aliases = zalloc(sizeof(char *) * len);
  if (!aliases)
-return;
+goto out_enomem;


That path tries to free aliases[j] but aliases is null.  You could set len to 0 
in that case.


Than again, no it doesn't sorry for the noise.




  pmu = NULL;
  j = 0;
  while ((pmu = perf_pmu__scan(pmu)) != NULL) {
@@ -768,16 +768,20 @@ void print_pmu_events(const char *event_glob, bool 
name_only)
(!is_cpu && strglobmatch(alias->name,
 event_glob
  continue;
-aliases[j] = name;
+
  if (is_cpu && !name_only)
-aliases[j] = format_alias_or(buf, sizeof(buf),
-  pmu, alias);
-aliases[j] = strdup(aliases[j]);
+name = format_alias_or(buf, sizeof(buf), pmu, alias);
+
+aliases[j] = strdup(name);
+if (aliases[j] == NULL)
+goto out_enomem;
  j++;
  }
  if (pmu->selectable) {
-scnprintf(buf, sizeof(buf), "%s//", pmu->name);
-aliases[j] = strdup(buf);
+char *s;
+if (asprintf(, "%s//", pmu->name) < 0)
+goto out_enomem;
+aliases[j] = s;
  j++;
  }
  }
@@ -789,12 +793,20 @@ void print_pmu_events(const char *event_glob, bool 
name_only)
  continue;
  }
  printf("  %-50s [Kernel PMU event]\n", aliases[j]);
-zfree([j]);
  printed++;
  }
  if (printed)
  printf("\n");
-free(aliases);
+out_free:
+for (j = 0; j < len; j++)
+zfree([j]);
+zfree();
+return;
+
+out_enomem:
+printf("FATAL: not enough memory to print PMU events\n");
+if (aliases)
+goto out_free;
  }

  bool pmu_have_event(const char *pname, const char *name)


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 02/16] perf pmu: Let pmu's with no events show up on perf list

2014-10-24 Thread Adrian Hunter

On 24/10/2014 4:21 p.m., Arnaldo Carvalho de Melo wrote:

Em Fri, Oct 24, 2014 at 10:03:20AM -0300, Arnaldo Carvalho de Melo escreveu:

Em Fri, Oct 24, 2014 at 09:57:02AM -0300, Arnaldo Carvalho de Melo escreveu:

Em Fri, Oct 24, 2014 at 02:15:52PM +0900, Namhyung Kim escreveu:

On Thu, 23 Oct 2014 13:45:10 +0300, Adrian Hunter wrote:

+   if (pmu->selectable) {
+   scnprintf(buf, sizeof(buf), "%s//", pmu->name);
+   aliases[j] = strdup(buf);


You need to check the return value here (and above too).


Well spotted, fixing this up.


Oh well, this print_pmu_events() function needs some care, it starts by
trying to alloc the array, if it fails, it silently returns, does that
mean that there are no pmu events? Or that memory allocation failed?

Ok, will do the fixes in a separate patch...

- Arnaldo


The patch below should check everything and warn the user, even
maintaining that void return...

Acked-by tags welcome as always :-)

- Arnaldo


diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 91dca60..881b754 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -753,9 +753,9 @@ void print_pmu_events(const char *event_glob, bool 
name_only)
if (pmu->selectable)
len++;
}
-   aliases = malloc(sizeof(char *) * len);
+   aliases = zalloc(sizeof(char *) * len);
if (!aliases)
-   return;
+   goto out_enomem;


That path tries to free aliases[j] but aliases is null.  You could set len to 0 
in that case.


pmu = NULL;
j = 0;
while ((pmu = perf_pmu__scan(pmu)) != NULL) {
@@ -768,16 +768,20 @@ void print_pmu_events(const char *event_glob, bool 
name_only)
  (!is_cpu && strglobmatch(alias->name,
   event_glob
continue;
-   aliases[j] = name;
+
if (is_cpu && !name_only)
-   aliases[j] = format_alias_or(buf, sizeof(buf),
- pmu, alias);
-   aliases[j] = strdup(aliases[j]);
+   name = format_alias_or(buf, sizeof(buf), pmu, 
alias);
+
+   aliases[j] = strdup(name);
+   if (aliases[j] == NULL)
+   goto out_enomem;
j++;
}
if (pmu->selectable) {
-   scnprintf(buf, sizeof(buf), "%s//", pmu->name);
-   aliases[j] = strdup(buf);
+   char *s;
+   if (asprintf(, "%s//", pmu->name) < 0)
+   goto out_enomem;
+   aliases[j] = s;
j++;
}
}
@@ -789,12 +793,20 @@ void print_pmu_events(const char *event_glob, bool 
name_only)
continue;
}
printf("  %-50s [Kernel PMU event]\n", aliases[j]);
-   zfree([j]);
printed++;
}
if (printed)
printf("\n");
-   free(aliases);
+out_free:
+   for (j = 0; j < len; j++)
+   zfree([j]);
+   zfree();
+   return;
+
+out_enomem:
+   printf("FATAL: not enough memory to print PMU events\n");
+   if (aliases)
+   goto out_free;
  }

  bool pmu_have_event(const char *pname, const char *name)


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 02/16] perf pmu: Let pmu's with no events show up on perf list

2014-10-24 Thread Arnaldo Carvalho de Melo
Em Fri, Oct 24, 2014 at 10:03:20AM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Fri, Oct 24, 2014 at 09:57:02AM -0300, Arnaldo Carvalho de Melo escreveu:
> > Em Fri, Oct 24, 2014 at 02:15:52PM +0900, Namhyung Kim escreveu:
> > > On Thu, 23 Oct 2014 13:45:10 +0300, Adrian Hunter wrote:
> > > > +   if (pmu->selectable) {
> > > > +   scnprintf(buf, sizeof(buf), "%s//", pmu->name);
> > > > +   aliases[j] = strdup(buf);
> > > 
> > > You need to check the return value here (and above too).
> > 
> > Well spotted, fixing this up.
> 
> Oh well, this print_pmu_events() function needs some care, it starts by
> trying to alloc the array, if it fails, it silently returns, does that
> mean that there are no pmu events? Or that memory allocation failed?
> 
> Ok, will do the fixes in a separate patch...
> 
> - Arnaldo

The patch below should check everything and warn the user, even
maintaining that void return...

Acked-by tags welcome as always :-)

- Arnaldo


diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 91dca60..881b754 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -753,9 +753,9 @@ void print_pmu_events(const char *event_glob, bool 
name_only)
if (pmu->selectable)
len++;
}
-   aliases = malloc(sizeof(char *) * len);
+   aliases = zalloc(sizeof(char *) * len);
if (!aliases)
-   return;
+   goto out_enomem;
pmu = NULL;
j = 0;
while ((pmu = perf_pmu__scan(pmu)) != NULL) {
@@ -768,16 +768,20 @@ void print_pmu_events(const char *event_glob, bool 
name_only)
  (!is_cpu && strglobmatch(alias->name,
   event_glob
continue;
-   aliases[j] = name;
+
if (is_cpu && !name_only)
-   aliases[j] = format_alias_or(buf, sizeof(buf),
- pmu, alias);
-   aliases[j] = strdup(aliases[j]);
+   name = format_alias_or(buf, sizeof(buf), pmu, 
alias);
+
+   aliases[j] = strdup(name);
+   if (aliases[j] == NULL)
+   goto out_enomem;
j++;
}
if (pmu->selectable) {
-   scnprintf(buf, sizeof(buf), "%s//", pmu->name);
-   aliases[j] = strdup(buf);
+   char *s;
+   if (asprintf(, "%s//", pmu->name) < 0)
+   goto out_enomem;
+   aliases[j] = s;
j++;
}
}
@@ -789,12 +793,20 @@ void print_pmu_events(const char *event_glob, bool 
name_only)
continue;
}
printf("  %-50s [Kernel PMU event]\n", aliases[j]);
-   zfree([j]);
printed++;
}
if (printed)
printf("\n");
-   free(aliases);
+out_free:
+   for (j = 0; j < len; j++)
+   zfree([j]);
+   zfree();
+   return;
+
+out_enomem:
+   printf("FATAL: not enough memory to print PMU events\n");
+   if (aliases)
+   goto out_free;
 }
 
 bool pmu_have_event(const char *pname, const char *name)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 02/16] perf pmu: Let pmu's with no events show up on perf list

2014-10-24 Thread Arnaldo Carvalho de Melo
Em Fri, Oct 24, 2014 at 09:57:02AM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Fri, Oct 24, 2014 at 02:15:52PM +0900, Namhyung Kim escreveu:
> > On Thu, 23 Oct 2014 13:45:10 +0300, Adrian Hunter wrote:
> > > + if (pmu->selectable) {
> > > + scnprintf(buf, sizeof(buf), "%s//", pmu->name);
> > > + aliases[j] = strdup(buf);
> > 
> > You need to check the return value here (and above too).
> 
> Well spotted, fixing this up.

Oh well, this print_pmu_events() function needs some care, it starts by
trying to alloc the array, if it fails, it silently returns, does that
mean that there are no pmu events? Or that memory allocation failed?

Ok, will do the fixes in a separate patch...

- Arnaldo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 02/16] perf pmu: Let pmu's with no events show up on perf list

2014-10-24 Thread Arnaldo Carvalho de Melo
Em Fri, Oct 24, 2014 at 02:15:52PM +0900, Namhyung Kim escreveu:
> On Thu, 23 Oct 2014 13:45:10 +0300, Adrian Hunter wrote:
> > +   if (pmu->selectable) {
> > +   scnprintf(buf, sizeof(buf), "%s//", pmu->name);
> > +   aliases[j] = strdup(buf);
> 
> You need to check the return value here (and above too).

Well spotted, fixing this up.
 
- Arnado
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 02/16] perf pmu: Let pmu's with no events show up on perf list

2014-10-24 Thread Arnaldo Carvalho de Melo
Em Fri, Oct 24, 2014 at 02:15:52PM +0900, Namhyung Kim escreveu:
 On Thu, 23 Oct 2014 13:45:10 +0300, Adrian Hunter wrote:
  +   if (pmu-selectable) {
  +   scnprintf(buf, sizeof(buf), %s//, pmu-name);
  +   aliases[j] = strdup(buf);
 
 You need to check the return value here (and above too).

Well spotted, fixing this up.
 
- Arnado
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 02/16] perf pmu: Let pmu's with no events show up on perf list

2014-10-24 Thread Arnaldo Carvalho de Melo
Em Fri, Oct 24, 2014 at 09:57:02AM -0300, Arnaldo Carvalho de Melo escreveu:
 Em Fri, Oct 24, 2014 at 02:15:52PM +0900, Namhyung Kim escreveu:
  On Thu, 23 Oct 2014 13:45:10 +0300, Adrian Hunter wrote:
   + if (pmu-selectable) {
   + scnprintf(buf, sizeof(buf), %s//, pmu-name);
   + aliases[j] = strdup(buf);
  
  You need to check the return value here (and above too).
 
 Well spotted, fixing this up.

Oh well, this print_pmu_events() function needs some care, it starts by
trying to alloc the array, if it fails, it silently returns, does that
mean that there are no pmu events? Or that memory allocation failed?

Ok, will do the fixes in a separate patch...

- Arnaldo
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 02/16] perf pmu: Let pmu's with no events show up on perf list

2014-10-24 Thread Arnaldo Carvalho de Melo
Em Fri, Oct 24, 2014 at 10:03:20AM -0300, Arnaldo Carvalho de Melo escreveu:
 Em Fri, Oct 24, 2014 at 09:57:02AM -0300, Arnaldo Carvalho de Melo escreveu:
  Em Fri, Oct 24, 2014 at 02:15:52PM +0900, Namhyung Kim escreveu:
   On Thu, 23 Oct 2014 13:45:10 +0300, Adrian Hunter wrote:
+   if (pmu-selectable) {
+   scnprintf(buf, sizeof(buf), %s//, pmu-name);
+   aliases[j] = strdup(buf);
   
   You need to check the return value here (and above too).
  
  Well spotted, fixing this up.
 
 Oh well, this print_pmu_events() function needs some care, it starts by
 trying to alloc the array, if it fails, it silently returns, does that
 mean that there are no pmu events? Or that memory allocation failed?
 
 Ok, will do the fixes in a separate patch...
 
 - Arnaldo

The patch below should check everything and warn the user, even
maintaining that void return...

Acked-by tags welcome as always :-)

- Arnaldo


diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 91dca60..881b754 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -753,9 +753,9 @@ void print_pmu_events(const char *event_glob, bool 
name_only)
if (pmu-selectable)
len++;
}
-   aliases = malloc(sizeof(char *) * len);
+   aliases = zalloc(sizeof(char *) * len);
if (!aliases)
-   return;
+   goto out_enomem;
pmu = NULL;
j = 0;
while ((pmu = perf_pmu__scan(pmu)) != NULL) {
@@ -768,16 +768,20 @@ void print_pmu_events(const char *event_glob, bool 
name_only)
  (!is_cpu  strglobmatch(alias-name,
   event_glob
continue;
-   aliases[j] = name;
+
if (is_cpu  !name_only)
-   aliases[j] = format_alias_or(buf, sizeof(buf),
- pmu, alias);
-   aliases[j] = strdup(aliases[j]);
+   name = format_alias_or(buf, sizeof(buf), pmu, 
alias);
+
+   aliases[j] = strdup(name);
+   if (aliases[j] == NULL)
+   goto out_enomem;
j++;
}
if (pmu-selectable) {
-   scnprintf(buf, sizeof(buf), %s//, pmu-name);
-   aliases[j] = strdup(buf);
+   char *s;
+   if (asprintf(s, %s//, pmu-name)  0)
+   goto out_enomem;
+   aliases[j] = s;
j++;
}
}
@@ -789,12 +793,20 @@ void print_pmu_events(const char *event_glob, bool 
name_only)
continue;
}
printf(  %-50s [Kernel PMU event]\n, aliases[j]);
-   zfree(aliases[j]);
printed++;
}
if (printed)
printf(\n);
-   free(aliases);
+out_free:
+   for (j = 0; j  len; j++)
+   zfree(aliases[j]);
+   zfree(aliases);
+   return;
+
+out_enomem:
+   printf(FATAL: not enough memory to print PMU events\n);
+   if (aliases)
+   goto out_free;
 }
 
 bool pmu_have_event(const char *pname, const char *name)
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 02/16] perf pmu: Let pmu's with no events show up on perf list

2014-10-24 Thread Adrian Hunter

On 24/10/2014 4:21 p.m., Arnaldo Carvalho de Melo wrote:

Em Fri, Oct 24, 2014 at 10:03:20AM -0300, Arnaldo Carvalho de Melo escreveu:

Em Fri, Oct 24, 2014 at 09:57:02AM -0300, Arnaldo Carvalho de Melo escreveu:

Em Fri, Oct 24, 2014 at 02:15:52PM +0900, Namhyung Kim escreveu:

On Thu, 23 Oct 2014 13:45:10 +0300, Adrian Hunter wrote:

+   if (pmu-selectable) {
+   scnprintf(buf, sizeof(buf), %s//, pmu-name);
+   aliases[j] = strdup(buf);


You need to check the return value here (and above too).


Well spotted, fixing this up.


Oh well, this print_pmu_events() function needs some care, it starts by
trying to alloc the array, if it fails, it silently returns, does that
mean that there are no pmu events? Or that memory allocation failed?

Ok, will do the fixes in a separate patch...

- Arnaldo


The patch below should check everything and warn the user, even
maintaining that void return...

Acked-by tags welcome as always :-)

- Arnaldo


diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 91dca60..881b754 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -753,9 +753,9 @@ void print_pmu_events(const char *event_glob, bool 
name_only)
if (pmu-selectable)
len++;
}
-   aliases = malloc(sizeof(char *) * len);
+   aliases = zalloc(sizeof(char *) * len);
if (!aliases)
-   return;
+   goto out_enomem;


That path tries to free aliases[j] but aliases is null.  You could set len to 0 
in that case.


pmu = NULL;
j = 0;
while ((pmu = perf_pmu__scan(pmu)) != NULL) {
@@ -768,16 +768,20 @@ void print_pmu_events(const char *event_glob, bool 
name_only)
  (!is_cpu  strglobmatch(alias-name,
   event_glob
continue;
-   aliases[j] = name;
+
if (is_cpu  !name_only)
-   aliases[j] = format_alias_or(buf, sizeof(buf),
- pmu, alias);
-   aliases[j] = strdup(aliases[j]);
+   name = format_alias_or(buf, sizeof(buf), pmu, 
alias);
+
+   aliases[j] = strdup(name);
+   if (aliases[j] == NULL)
+   goto out_enomem;
j++;
}
if (pmu-selectable) {
-   scnprintf(buf, sizeof(buf), %s//, pmu-name);
-   aliases[j] = strdup(buf);
+   char *s;
+   if (asprintf(s, %s//, pmu-name)  0)
+   goto out_enomem;
+   aliases[j] = s;
j++;
}
}
@@ -789,12 +793,20 @@ void print_pmu_events(const char *event_glob, bool 
name_only)
continue;
}
printf(  %-50s [Kernel PMU event]\n, aliases[j]);
-   zfree(aliases[j]);
printed++;
}
if (printed)
printf(\n);
-   free(aliases);
+out_free:
+   for (j = 0; j  len; j++)
+   zfree(aliases[j]);
+   zfree(aliases);
+   return;
+
+out_enomem:
+   printf(FATAL: not enough memory to print PMU events\n);
+   if (aliases)
+   goto out_free;
  }

  bool pmu_have_event(const char *pname, const char *name)


--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 02/16] perf pmu: Let pmu's with no events show up on perf list

2014-10-24 Thread Adrian Hunter

On 24/10/2014 5:36 p.m., Adrian Hunter wrote:

On 24/10/2014 4:21 p.m., Arnaldo Carvalho de Melo wrote:

Em Fri, Oct 24, 2014 at 10:03:20AM -0300, Arnaldo Carvalho de Melo escreveu:

Em Fri, Oct 24, 2014 at 09:57:02AM -0300, Arnaldo Carvalho de Melo escreveu:

Em Fri, Oct 24, 2014 at 02:15:52PM +0900, Namhyung Kim escreveu:

On Thu, 23 Oct 2014 13:45:10 +0300, Adrian Hunter wrote:

+if (pmu-selectable) {
+scnprintf(buf, sizeof(buf), %s//, pmu-name);
+aliases[j] = strdup(buf);


You need to check the return value here (and above too).


Well spotted, fixing this up.


Oh well, this print_pmu_events() function needs some care, it starts by
trying to alloc the array, if it fails, it silently returns, does that
mean that there are no pmu events? Or that memory allocation failed?

Ok, will do the fixes in a separate patch...

- Arnaldo


The patch below should check everything and warn the user, even
maintaining that void return...

Acked-by tags welcome as always :-)

- Arnaldo


diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 91dca60..881b754 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -753,9 +753,9 @@ void print_pmu_events(const char *event_glob, bool 
name_only)
  if (pmu-selectable)
  len++;
  }
-aliases = malloc(sizeof(char *) * len);
+aliases = zalloc(sizeof(char *) * len);
  if (!aliases)
-return;
+goto out_enomem;


That path tries to free aliases[j] but aliases is null.  You could set len to 0 
in that case.


Than again, no it doesn't sorry for the noise.




  pmu = NULL;
  j = 0;
  while ((pmu = perf_pmu__scan(pmu)) != NULL) {
@@ -768,16 +768,20 @@ void print_pmu_events(const char *event_glob, bool 
name_only)
(!is_cpu  strglobmatch(alias-name,
 event_glob
  continue;
-aliases[j] = name;
+
  if (is_cpu  !name_only)
-aliases[j] = format_alias_or(buf, sizeof(buf),
-  pmu, alias);
-aliases[j] = strdup(aliases[j]);
+name = format_alias_or(buf, sizeof(buf), pmu, alias);
+
+aliases[j] = strdup(name);
+if (aliases[j] == NULL)
+goto out_enomem;
  j++;
  }
  if (pmu-selectable) {
-scnprintf(buf, sizeof(buf), %s//, pmu-name);
-aliases[j] = strdup(buf);
+char *s;
+if (asprintf(s, %s//, pmu-name)  0)
+goto out_enomem;
+aliases[j] = s;
  j++;
  }
  }
@@ -789,12 +793,20 @@ void print_pmu_events(const char *event_glob, bool 
name_only)
  continue;
  }
  printf(  %-50s [Kernel PMU event]\n, aliases[j]);
-zfree(aliases[j]);
  printed++;
  }
  if (printed)
  printf(\n);
-free(aliases);
+out_free:
+for (j = 0; j  len; j++)
+zfree(aliases[j]);
+zfree(aliases);
+return;
+
+out_enomem:
+printf(FATAL: not enough memory to print PMU events\n);
+if (aliases)
+goto out_free;
  }

  bool pmu_have_event(const char *pname, const char *name)


--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 02/16] perf pmu: Let pmu's with no events show up on perf list

2014-10-24 Thread Arnaldo Carvalho de Melo
Em Fri, Oct 24, 2014 at 05:36:46PM +0300, Adrian Hunter escreveu:
 On 24/10/2014 4:21 p.m., Arnaldo Carvalho de Melo wrote:
 Em Fri, Oct 24, 2014 at 10:03:20AM -0300, Arnaldo Carvalho de Melo escreveu:
 Em Fri, Oct 24, 2014 at 09:57:02AM -0300, Arnaldo Carvalho de Melo escreveu:
 Em Fri, Oct 24, 2014 at 02:15:52PM +0900, Namhyung Kim escreveu:
 On Thu, 23 Oct 2014 13:45:10 +0300, Adrian Hunter wrote:
 +if (pmu-selectable) {
 +scnprintf(buf, sizeof(buf), %s//, pmu-name);
 +aliases[j] = strdup(buf);
 
 You need to check the return value here (and above too).
 
 Well spotted, fixing this up.
 
 Oh well, this print_pmu_events() function needs some care, it starts by
 trying to alloc the array, if it fails, it silently returns, does that
 mean that there are no pmu events? Or that memory allocation failed?
 
 Ok, will do the fixes in a separate patch...
 
 - Arnaldo
 
 The patch below should check everything and warn the user, even
 maintaining that void return...
 
 Acked-by tags welcome as always :-)
 
 - Arnaldo
 
 
 diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
 index 91dca60..881b754 100644
 --- a/tools/perf/util/pmu.c
 +++ b/tools/perf/util/pmu.c
 @@ -753,9 +753,9 @@ void print_pmu_events(const char *event_glob, bool 
 name_only)
  if (pmu-selectable)
  len++;
  }
 -aliases = malloc(sizeof(char *) * len);
 +aliases = zalloc(sizeof(char *) * len);
  if (!aliases)
 -return;
 +goto out_enomem;
 
 That path tries to free aliases[j] but aliases is null.  You could set len to 
 0 in that case.


Oops, yeah, my bad, it should not have the !, fixing...
 
  pmu = NULL;
  j = 0;
  while ((pmu = perf_pmu__scan(pmu)) != NULL) {
 @@ -768,16 +768,20 @@ void print_pmu_events(const char *event_glob, bool 
 name_only)
(!is_cpu  strglobmatch(alias-name,
 event_glob
  continue;
 -aliases[j] = name;
 +
  if (is_cpu  !name_only)
 -aliases[j] = format_alias_or(buf, sizeof(buf),
 -  pmu, alias);
 -aliases[j] = strdup(aliases[j]);
 +name = format_alias_or(buf, sizeof(buf), pmu, 
 alias);
 +
 +aliases[j] = strdup(name);
 +if (aliases[j] == NULL)
 +goto out_enomem;
  j++;
  }
  if (pmu-selectable) {
 -scnprintf(buf, sizeof(buf), %s//, pmu-name);
 -aliases[j] = strdup(buf);
 +char *s;
 +if (asprintf(s, %s//, pmu-name)  0)
 +goto out_enomem;
 +aliases[j] = s;
  j++;
  }
  }
 @@ -789,12 +793,20 @@ void print_pmu_events(const char *event_glob, bool 
 name_only)
  continue;
  }
  printf(  %-50s [Kernel PMU event]\n, aliases[j]);
 -zfree(aliases[j]);
  printed++;
  }
  if (printed)
  printf(\n);
 -free(aliases);
 +out_free:
 +for (j = 0; j  len; j++)
 +zfree(aliases[j]);
 +zfree(aliases);
 +return;
 +
 +out_enomem:
 +printf(FATAL: not enough memory to print PMU events\n);
 +if (aliases)
 +goto out_free;
   }
 
   bool pmu_have_event(const char *pname, const char *name)
 
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 02/16] perf pmu: Let pmu's with no events show up on perf list

2014-10-24 Thread Arnaldo Carvalho de Melo
Em Fri, Oct 24, 2014 at 11:45:00AM -0300, Arnaldo Carvalho de Melo escreveu:
 Em Fri, Oct 24, 2014 at 05:36:46PM +0300, Adrian Hunter escreveu:
  +  aliases = zalloc(sizeof(char *) * len);
 if (!aliases)
  -  return;
  +  goto out_enomem;
  
  That path tries to free aliases[j] but aliases is null.  You could set len 
  to 0 in that case.

You got me confused, yeah, it ended up a bit confusing, but the idea was
to share the error message, i.e. have just one printf(FATAL:
enomem...) for both alloc failures, the later will have to free the
array elements, and it is ok to call free(NULL), thus the change from
malloc to zalloc(aliases), so that all its entries were zeroed, yadda,
yadda.

- Arnaldo
 
 
 Oops, yeah, my bad, it should not have the !, fixing...
  
 pmu = NULL;
 j = 0;
 while ((pmu = perf_pmu__scan(pmu)) != NULL) {
  @@ -768,16 +768,20 @@ void print_pmu_events(const char *event_glob, bool 
  name_only)
   (!is_cpu  strglobmatch(alias-name,
event_glob
 continue;
  -  aliases[j] = name;
  +
 if (is_cpu  !name_only)
  -  aliases[j] = format_alias_or(buf, sizeof(buf),
  -pmu, alias);
  -  aliases[j] = strdup(aliases[j]);
  +  name = format_alias_or(buf, sizeof(buf), pmu, 
  alias);
  +
  +  aliases[j] = strdup(name);
  +  if (aliases[j] == NULL)
  +  goto out_enomem;
 j++;
 }
 if (pmu-selectable) {
  -  scnprintf(buf, sizeof(buf), %s//, pmu-name);
  -  aliases[j] = strdup(buf);
  +  char *s;
  +  if (asprintf(s, %s//, pmu-name)  0)
  +  goto out_enomem;
  +  aliases[j] = s;
 j++;
 }
 }
  @@ -789,12 +793,20 @@ void print_pmu_events(const char *event_glob, bool 
  name_only)
 continue;
 }
 printf(  %-50s [Kernel PMU event]\n, aliases[j]);
  -  zfree(aliases[j]);
 printed++;
 }
 if (printed)
 printf(\n);
  -  free(aliases);
  +out_free:
  +  for (j = 0; j  len; j++)
  +  zfree(aliases[j]);
  +  zfree(aliases);
  +  return;
  +
  +out_enomem:
  +  printf(FATAL: not enough memory to print PMU events\n);
  +  if (aliases)
  +  goto out_free;
}
  
bool pmu_have_event(const char *pname, const char *name)
  
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 02/16] perf pmu: Let pmu's with no events show up on perf list

2014-10-23 Thread Namhyung Kim
On Thu, 23 Oct 2014 13:45:10 +0300, Adrian Hunter wrote:
> perf list only lists PMUs with events.  Add a
> flag to cause a PMU to be also listed separately.
>
> Signed-off-by: Adrian Hunter 
> ---
>  tools/perf/util/pmu.c | 13 +++--
>  tools/perf/util/pmu.h |  1 +
>  2 files changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
> index e243ad9..91dca60 100644
> --- a/tools/perf/util/pmu.c
> +++ b/tools/perf/util/pmu.c
> @@ -747,15 +747,18 @@ void print_pmu_events(const char *event_glob, bool 
> name_only)
>  
>   pmu = NULL;
>   len = 0;
> - while ((pmu = perf_pmu__scan(pmu)) != NULL)
> + while ((pmu = perf_pmu__scan(pmu)) != NULL) {
>   list_for_each_entry(alias, >aliases, list)
>   len++;
> + if (pmu->selectable)
> + len++;
> + }
>   aliases = malloc(sizeof(char *) * len);
>   if (!aliases)
>   return;
>   pmu = NULL;
>   j = 0;
> - while ((pmu = perf_pmu__scan(pmu)) != NULL)
> + while ((pmu = perf_pmu__scan(pmu)) != NULL) {
>   list_for_each_entry(alias, >aliases, list) {
>   char *name = format_alias(buf, sizeof(buf), pmu, alias);
>   bool is_cpu = !strcmp(pmu->name, "cpu");
> @@ -772,6 +775,12 @@ void print_pmu_events(const char *event_glob, bool 
> name_only)
>   aliases[j] = strdup(aliases[j]);
>   j++;
>   }
> + if (pmu->selectable) {
> + scnprintf(buf, sizeof(buf), "%s//", pmu->name);
> + aliases[j] = strdup(buf);

You need to check the return value here (and above too).


> + j++;
> + }
> + }
>   len = j;
>   qsort(aliases, len, sizeof(char *), cmp_string);
>   for (j = 0; j < len; j++) {
> diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h
> index fe9dfbe..8092de7 100644
> --- a/tools/perf/util/pmu.h
> +++ b/tools/perf/util/pmu.h
> @@ -18,6 +18,7 @@ struct perf_event_attr;
>  struct perf_pmu {
>   char *name;
>   __u32 type;
> + bool selectable;

I think it's a bit confusing.  IIUC this 'selectable' means that this
PMU doesn't contain any events but wants to be listed.  So the normal
PMUs which contain events are not selectable, right?

Thanks,
Namhyung


>   struct perf_event_attr *default_config;
>   struct cpu_map *cpus;
>   struct list_head format;  /* HEAD struct perf_pmu_format -> list */
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 02/16] perf pmu: Let pmu's with no events show up on perf list

2014-10-23 Thread Adrian Hunter
perf list only lists PMUs with events.  Add a
flag to cause a PMU to be also listed separately.

Signed-off-by: Adrian Hunter 
---
 tools/perf/util/pmu.c | 13 +++--
 tools/perf/util/pmu.h |  1 +
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index e243ad9..91dca60 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -747,15 +747,18 @@ void print_pmu_events(const char *event_glob, bool 
name_only)
 
pmu = NULL;
len = 0;
-   while ((pmu = perf_pmu__scan(pmu)) != NULL)
+   while ((pmu = perf_pmu__scan(pmu)) != NULL) {
list_for_each_entry(alias, >aliases, list)
len++;
+   if (pmu->selectable)
+   len++;
+   }
aliases = malloc(sizeof(char *) * len);
if (!aliases)
return;
pmu = NULL;
j = 0;
-   while ((pmu = perf_pmu__scan(pmu)) != NULL)
+   while ((pmu = perf_pmu__scan(pmu)) != NULL) {
list_for_each_entry(alias, >aliases, list) {
char *name = format_alias(buf, sizeof(buf), pmu, alias);
bool is_cpu = !strcmp(pmu->name, "cpu");
@@ -772,6 +775,12 @@ void print_pmu_events(const char *event_glob, bool 
name_only)
aliases[j] = strdup(aliases[j]);
j++;
}
+   if (pmu->selectable) {
+   scnprintf(buf, sizeof(buf), "%s//", pmu->name);
+   aliases[j] = strdup(buf);
+   j++;
+   }
+   }
len = j;
qsort(aliases, len, sizeof(char *), cmp_string);
for (j = 0; j < len; j++) {
diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h
index fe9dfbe..8092de7 100644
--- a/tools/perf/util/pmu.h
+++ b/tools/perf/util/pmu.h
@@ -18,6 +18,7 @@ struct perf_event_attr;
 struct perf_pmu {
char *name;
__u32 type;
+   bool selectable;
struct perf_event_attr *default_config;
struct cpu_map *cpus;
struct list_head format;  /* HEAD struct perf_pmu_format -> list */
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 02/16] perf pmu: Let pmu's with no events show up on perf list

2014-10-23 Thread Adrian Hunter
perf list only lists PMUs with events.  Add a
flag to cause a PMU to be also listed separately.

Signed-off-by: Adrian Hunter adrian.hun...@intel.com
---
 tools/perf/util/pmu.c | 13 +++--
 tools/perf/util/pmu.h |  1 +
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index e243ad9..91dca60 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -747,15 +747,18 @@ void print_pmu_events(const char *event_glob, bool 
name_only)
 
pmu = NULL;
len = 0;
-   while ((pmu = perf_pmu__scan(pmu)) != NULL)
+   while ((pmu = perf_pmu__scan(pmu)) != NULL) {
list_for_each_entry(alias, pmu-aliases, list)
len++;
+   if (pmu-selectable)
+   len++;
+   }
aliases = malloc(sizeof(char *) * len);
if (!aliases)
return;
pmu = NULL;
j = 0;
-   while ((pmu = perf_pmu__scan(pmu)) != NULL)
+   while ((pmu = perf_pmu__scan(pmu)) != NULL) {
list_for_each_entry(alias, pmu-aliases, list) {
char *name = format_alias(buf, sizeof(buf), pmu, alias);
bool is_cpu = !strcmp(pmu-name, cpu);
@@ -772,6 +775,12 @@ void print_pmu_events(const char *event_glob, bool 
name_only)
aliases[j] = strdup(aliases[j]);
j++;
}
+   if (pmu-selectable) {
+   scnprintf(buf, sizeof(buf), %s//, pmu-name);
+   aliases[j] = strdup(buf);
+   j++;
+   }
+   }
len = j;
qsort(aliases, len, sizeof(char *), cmp_string);
for (j = 0; j  len; j++) {
diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h
index fe9dfbe..8092de7 100644
--- a/tools/perf/util/pmu.h
+++ b/tools/perf/util/pmu.h
@@ -18,6 +18,7 @@ struct perf_event_attr;
 struct perf_pmu {
char *name;
__u32 type;
+   bool selectable;
struct perf_event_attr *default_config;
struct cpu_map *cpus;
struct list_head format;  /* HEAD struct perf_pmu_format - list */
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 02/16] perf pmu: Let pmu's with no events show up on perf list

2014-10-23 Thread Namhyung Kim
On Thu, 23 Oct 2014 13:45:10 +0300, Adrian Hunter wrote:
 perf list only lists PMUs with events.  Add a
 flag to cause a PMU to be also listed separately.

 Signed-off-by: Adrian Hunter adrian.hun...@intel.com
 ---
  tools/perf/util/pmu.c | 13 +++--
  tools/perf/util/pmu.h |  1 +
  2 files changed, 12 insertions(+), 2 deletions(-)

 diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
 index e243ad9..91dca60 100644
 --- a/tools/perf/util/pmu.c
 +++ b/tools/perf/util/pmu.c
 @@ -747,15 +747,18 @@ void print_pmu_events(const char *event_glob, bool 
 name_only)
  
   pmu = NULL;
   len = 0;
 - while ((pmu = perf_pmu__scan(pmu)) != NULL)
 + while ((pmu = perf_pmu__scan(pmu)) != NULL) {
   list_for_each_entry(alias, pmu-aliases, list)
   len++;
 + if (pmu-selectable)
 + len++;
 + }
   aliases = malloc(sizeof(char *) * len);
   if (!aliases)
   return;
   pmu = NULL;
   j = 0;
 - while ((pmu = perf_pmu__scan(pmu)) != NULL)
 + while ((pmu = perf_pmu__scan(pmu)) != NULL) {
   list_for_each_entry(alias, pmu-aliases, list) {
   char *name = format_alias(buf, sizeof(buf), pmu, alias);
   bool is_cpu = !strcmp(pmu-name, cpu);
 @@ -772,6 +775,12 @@ void print_pmu_events(const char *event_glob, bool 
 name_only)
   aliases[j] = strdup(aliases[j]);
   j++;
   }
 + if (pmu-selectable) {
 + scnprintf(buf, sizeof(buf), %s//, pmu-name);
 + aliases[j] = strdup(buf);

You need to check the return value here (and above too).


 + j++;
 + }
 + }
   len = j;
   qsort(aliases, len, sizeof(char *), cmp_string);
   for (j = 0; j  len; j++) {
 diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h
 index fe9dfbe..8092de7 100644
 --- a/tools/perf/util/pmu.h
 +++ b/tools/perf/util/pmu.h
 @@ -18,6 +18,7 @@ struct perf_event_attr;
  struct perf_pmu {
   char *name;
   __u32 type;
 + bool selectable;

I think it's a bit confusing.  IIUC this 'selectable' means that this
PMU doesn't contain any events but wants to be listed.  So the normal
PMUs which contain events are not selectable, right?

Thanks,
Namhyung


   struct perf_event_attr *default_config;
   struct cpu_map *cpus;
   struct list_head format;  /* HEAD struct perf_pmu_format - list */
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/