Re: [PATCH v2 02/14] perf mem: Introduce weak function perf_mem_events__ptr()
From: Leo Yan
Date: Thu Sep 03 2020 - 20:35:01 EST
Hi Jiri,
On Thu, Sep 03, 2020 at 03:50:54PM +0200, Jiri Olsa wrote:
> On Tue, Sep 01, 2020 at 09:38:03AM +0100, Leo Yan wrote:
>
> SNIP
>
> > @@ -2941,30 +2942,38 @@ static int perf_c2c__record(int argc, const char **argv)
> > rec_argv[i++] = "record";
> >
> > if (!event_set) {
> > - perf_mem_events[PERF_MEM_EVENTS__LOAD].record = true;
> > - perf_mem_events[PERF_MEM_EVENTS__STORE].record = true;
> > + e = perf_mem_events__ptr(PERF_MEM_EVENTS__LOAD);
> > + e->record = true;
> > +
> > + e = perf_mem_events__ptr(PERF_MEM_EVENTS__STORE);
> > + e->record = true;
> > }
> >
> > - if (perf_mem_events[PERF_MEM_EVENTS__LOAD].record)
> > + e = perf_mem_events__ptr(PERF_MEM_EVENTS__LOAD);
> > + if (e->record)
> > rec_argv[i++] = "-W";
> >
> > rec_argv[i++] = "-d";
> > rec_argv[i++] = "--phys-data";
> > rec_argv[i++] = "--sample-cpu";
> >
> > - for (j = 0; j < PERF_MEM_EVENTS__MAX; j++) {
> > - if (!perf_mem_events[j].record)
> > + j = 0;
> > + while ((e = perf_mem_events__ptr(j)) != NULL) {
> > + if (!e->record) {
>
> you could keep the above 'for loop' in here, it seems better
> than taking care of j++
Actually in patch v1 I did this way :) I followed James' suggestion to
encapsulate PERF_MEM_EVENTS__MAX into perf_mem_events__ptr(), thus
builtin-mem.c and buildin-c2c.c are not necessary to use
PERF_MEM_EVENTS__MAX in the loop and only needs to detect if the
pointer is NULL or not when return from perf_mem_events__ptr().
How about change as below?
for (j = 0; (e = perf_mem_events__ptr(j)) != NULL; j++) {
[...]
}
If you still think this is not good, I will change back to the old
code style in next spin
Thanks for reviewing!
Leo
> > + j++;
> > continue;
> > + }
> >
> > - if (!perf_mem_events[j].supported) {
> > + if (!e->supported) {
> > pr_err("failed: event '%s' not supported\n",
> > - perf_mem_events[j].name);
> > + perf_mem_events__name(j));
> > free(rec_argv);
> > return -1;
> > }
> >
> > rec_argv[i++] = "-e";
> > rec_argv[i++] = perf_mem_events__name(j);
> > + j++;
> > }
> >
> > if (all_user)
>
> SNIP
>
> > @@ -100,11 +106,14 @@ static int __cmd_record(int argc, const char **argv, struct perf_mem *mem)
> > if (mem->phys_addr)
> > rec_argv[i++] = "--phys-data";
> >
> > - for (j = 0; j < PERF_MEM_EVENTS__MAX; j++) {
> > - if (!perf_mem_events[j].record)
> > + j = 0;
> > + while ((e = perf_mem_events__ptr(j)) != NULL) {
> > + if (!e->record) {
>
> same here
>
> thanks,
> jirka
>
> > + j++;
> > continue;
> > + }
> >
> > - if (!perf_mem_events[j].supported) {
> > + if (!e->supported) {
> > pr_err("failed: event '%s' not supported\n",
> > perf_mem_events__name(j));
> > free(rec_argv);
> > @@ -113,6 +122,7 @@ static int __cmd_record(int argc, const char **argv, struct perf_mem *mem)
> >
> > rec_argv[i++] = "-e";
> > rec_argv[i++] = perf_mem_events__name(j);
> > + j++;
>
> SNIP
>