Message ID | 1433260778-26497-5-git-send-email-maddy@linux.vnet.ibm.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
On Tue, 2015-06-02 at 21:29 +0530, Madhavan Srinivasan wrote: > Patch adds generic nest pmu functions and format attribute. > I'm not sure this commit message accurately reflects the content of the patch. At any rate, please could you: - say what the patch adds the functions and attributes to. - phrase your message as "Add generic ..." not "Patch adds generic ...": see https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/SubmittingPatches#n155 > > +PMU_FORMAT_ATTR(event, "config:0-20"); > +struct attribute *p8_nest_format_attrs[] = { > + &format_attr_event.attr, > + NULL, > +}; > + > +struct attribute_group p8_nest_format_group = { > + .name = "format", > + .attrs = p8_nest_format_attrs, > +}; Can these structs be constified? > + > +int p8_nest_event_init(struct perf_event *event) > +{ > + int chip_id; > + > + if (event->attr.type != event->pmu->type) > + return -ENOENT; > + > + /* Sampling not supported yet */ > + if (event->hw.sample_period) > + return -EINVAL; > + > + /* unsupported modes and filters */ > + if (event->attr.exclude_user || > + event->attr.exclude_kernel || > + event->attr.exclude_hv || > + event->attr.exclude_idle || > + event->attr.exclude_host || > + event->attr.exclude_guest || > + event->attr.sample_period) /* no sampling */ > + return -EINVAL; You test for sample period twice here. > + > + if (event->cpu < 0) > + return -EINVAL; > + > + chip_id = topology_physical_package_id(event->cpu); > + event->hw.event_base = event->attr.config + > + p8_perchip_nest_info[chip_id].vbase; > + > + return 0; > +} > + > +void p8_nest_read_counter(struct perf_event *event) > +{ > + u64 *addr; > + u64 data = 0; > + > + addr = (u64 *)event->hw.event_base; > + data = __be64_to_cpu((uint64_t)*addr); > + local64_set(&event->hw.prev_count, data); > +} > + > +void p8_nest_perf_event_update(struct perf_event *event) > +{ > + u64 counter_prev, counter_new, final_count; > + uint64_t *addr; > + > + addr = (u64 *)event->hw.event_base; > + counter_prev = local64_read(&event->hw.prev_count); > + counter_new = __be64_to_cpu((uint64_t)*addr); > + final_count = counter_new - counter_prev; > + > + local64_set(&event->hw.prev_count, counter_new); > + local64_add(final_count, &event->count); > +} > + > +void p8_nest_event_start(struct perf_event *event, int flags) > +{ > + event->hw.state = 0; > + p8_nest_read_counter(event); > +} > + > +void p8_nest_event_stop(struct perf_event *event, int flags) > +{ > + p8_nest_perf_event_update(event); > +} > + > +int p8_nest_event_add(struct perf_event *event, int flags) > +{ > + p8_nest_event_start(event, flags); > + return 0; > +} > + > +void p8_nest_event_del(struct perf_event *event, int flags) > +{ > + p8_nest_event_stop(event, flags); Is this necessary? Stop calls update, which I guess makes sense as it finalises the value. But if the event is being deleted anyway, why not just do nothing here? > +} > + Regards, Daniel Axtens
On Wednesday 03 June 2015 05:33 AM, Daniel Axtens wrote: > On Tue, 2015-06-02 at 21:29 +0530, Madhavan Srinivasan wrote: >> Patch adds generic nest pmu functions and format attribute. >> > I'm not sure this commit message accurately reflects the content of the > patch. At any rate, please could you: > - say what the patch adds the functions and attributes to. > - phrase your message as "Add generic ..." not "Patch adds > generic ...": see > https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/SubmittingPatches#n155 Sure. Will rephrase it. > >> >> +PMU_FORMAT_ATTR(event, "config:0-20"); >> +struct attribute *p8_nest_format_attrs[] = { >> + &format_attr_event.attr, >> + NULL, >> +}; >> + >> +struct attribute_group p8_nest_format_group = { >> + .name = "format", >> + .attrs = p8_nest_format_attrs, >> +}; > Can these structs be constified? I guess it can. Will check it out. >> + >> +int p8_nest_event_init(struct perf_event *event) >> +{ >> + int chip_id; >> + >> + if (event->attr.type != event->pmu->type) >> + return -ENOENT; >> + >> + /* Sampling not supported yet */ >> + if (event->hw.sample_period) >> + return -EINVAL; >> + >> + /* unsupported modes and filters */ >> + if (event->attr.exclude_user || >> + event->attr.exclude_kernel || >> + event->attr.exclude_hv || >> + event->attr.exclude_idle || >> + event->attr.exclude_host || >> + event->attr.exclude_guest || >> + event->attr.sample_period) /* no sampling */ >> + return -EINVAL; > You test for sample period twice here. Yes right. I will remove it. >> + >> + if (event->cpu < 0) >> + return -EINVAL; >> + >> + chip_id = topology_physical_package_id(event->cpu); >> + event->hw.event_base = event->attr.config + >> + p8_perchip_nest_info[chip_id].vbase; >> + >> + return 0; >> +} >> + >> +void p8_nest_read_counter(struct perf_event *event) >> +{ >> + u64 *addr; >> + u64 data = 0; >> + >> + addr = (u64 *)event->hw.event_base; >> + data = __be64_to_cpu((uint64_t)*addr); >> + local64_set(&event->hw.prev_count, data); >> +} >> + >> +void p8_nest_perf_event_update(struct perf_event *event) >> +{ >> + u64 counter_prev, counter_new, final_count; >> + uint64_t *addr; >> + >> + addr = (u64 *)event->hw.event_base; >> + counter_prev = local64_read(&event->hw.prev_count); >> + counter_new = __be64_to_cpu((uint64_t)*addr); >> + final_count = counter_new - counter_prev; >> + >> + local64_set(&event->hw.prev_count, counter_new); >> + local64_add(final_count, &event->count); >> +} >> + >> +void p8_nest_event_start(struct perf_event *event, int flags) >> +{ >> + event->hw.state = 0; >> + p8_nest_read_counter(event); >> +} >> + >> +void p8_nest_event_stop(struct perf_event *event, int flags) >> +{ >> + p8_nest_perf_event_update(event); >> +} >> + >> +int p8_nest_event_add(struct perf_event *event, int flags) >> +{ >> + p8_nest_event_start(event, flags); >> + return 0; >> +} >> + >> +void p8_nest_event_del(struct perf_event *event, int flags) >> +{ >> + p8_nest_event_stop(event, flags); > Is this necessary? > > Stop calls update, which I guess makes sense as it finalises the value. > But if the event is being deleted anyway, why not just do nothing here? Since these Nest PMUs does not support sampling. IIUC, "perf record" interface uses the event start/stop ops. Incase of perf stat interface event add/del interface are used to enable and disable the counters. Now, when we disable or delete, we update the event counter with the delta value. >> +} >> + > Regards, > Daniel Axtens Thanks for the review Maddy
On Wednesday 03 June 2015 05:33 AM, Daniel Axtens wrote: > On Tue, 2015-06-02 at 21:29 +0530, Madhavan Srinivasan wrote: >> Patch adds generic nest pmu functions and format attribute. >> > I'm not sure this commit message accurately reflects the content of the > patch. At any rate, please could you: > - say what the patch adds the functions and attributes to. > - phrase your message as "Add generic ..." not "Patch adds > generic ...": see > https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/SubmittingPatches#n155 > I will rephrase the commit message. >> >> +PMU_FORMAT_ATTR(event, "config:0-20"); >> +struct attribute *p8_nest_format_attrs[] = { >> + &format_attr_event.attr, >> + NULL, >> +}; >> + >> +struct attribute_group p8_nest_format_group = { >> + .name = "format", >> + .attrs = p8_nest_format_attrs, >> +}; > Can these structs be constified? I guess so. Will try it out. >> + >> +int p8_nest_event_init(struct perf_event *event) >> +{ >> + int chip_id; >> + >> + if (event->attr.type != event->pmu->type) >> + return -ENOENT; >> + >> + /* Sampling not supported yet */ >> + if (event->hw.sample_period) >> + return -EINVAL; >> + >> + /* unsupported modes and filters */ >> + if (event->attr.exclude_user || >> + event->attr.exclude_kernel || >> + event->attr.exclude_hv || >> + event->attr.exclude_idle || >> + event->attr.exclude_host || >> + event->attr.exclude_guest || >> + event->attr.sample_period) /* no sampling */ >> + return -EINVAL; > You test for sample period twice here. My bad. Will remove it. >> + >> + if (event->cpu < 0) >> + return -EINVAL; >> + >> + chip_id = topology_physical_package_id(event->cpu); >> + event->hw.event_base = event->attr.config + >> + p8_perchip_nest_info[chip_id].vbase; >> + >> + return 0; >> +} >> + >> +void p8_nest_read_counter(struct perf_event *event) >> +{ >> + u64 *addr; >> + u64 data = 0; >> + >> + addr = (u64 *)event->hw.event_base; >> + data = __be64_to_cpu((uint64_t)*addr); >> + local64_set(&event->hw.prev_count, data); >> +} >> + >> +void p8_nest_perf_event_update(struct perf_event *event) >> +{ >> + u64 counter_prev, counter_new, final_count; >> + uint64_t *addr; >> + >> + addr = (u64 *)event->hw.event_base; >> + counter_prev = local64_read(&event->hw.prev_count); >> + counter_new = __be64_to_cpu((uint64_t)*addr); >> + final_count = counter_new - counter_prev; >> + >> + local64_set(&event->hw.prev_count, counter_new); >> + local64_add(final_count, &event->count); >> +} >> + >> +void p8_nest_event_start(struct perf_event *event, int flags) >> +{ >> + event->hw.state = 0; >> + p8_nest_read_counter(event); >> +} >> + >> +void p8_nest_event_stop(struct perf_event *event, int flags) >> +{ >> + p8_nest_perf_event_update(event); >> +} >> + >> +int p8_nest_event_add(struct perf_event *event, int flags) >> +{ >> + p8_nest_event_start(event, flags); >> + return 0; >> +} >> + >> +void p8_nest_event_del(struct perf_event *event, int flags) >> +{ >> + p8_nest_event_stop(event, flags); > Is this necessary? > > Stop calls update, which I guess makes sense as it finalises the value. > But if the event is being deleted anyway, why not just do nothing here? IIUC, "perf record" will use the event start/stop interface. Incase of "perf stat" (for PMUs which does not support sampling), event add/del interface is used. Now when event is disable or deleted, event count should get updated with the delta value. >> +} >> + > Regards, > Daniel Axtens Thanks for the review Maddy
diff --git a/arch/powerpc/perf/nest-pmu.c b/arch/powerpc/perf/nest-pmu.c index 3e7010e..345707c 100644 --- a/arch/powerpc/perf/nest-pmu.c +++ b/arch/powerpc/perf/nest-pmu.c @@ -134,6 +134,113 @@ void cpumask_chip(void) cpu_notifier_register_done(); } +PMU_FORMAT_ATTR(event, "config:0-20"); +struct attribute *p8_nest_format_attrs[] = { + &format_attr_event.attr, + NULL, +}; + +struct attribute_group p8_nest_format_group = { + .name = "format", + .attrs = p8_nest_format_attrs, +}; + +int p8_nest_event_init(struct perf_event *event) +{ + int chip_id; + + if (event->attr.type != event->pmu->type) + return -ENOENT; + + /* Sampling not supported yet */ + if (event->hw.sample_period) + return -EINVAL; + + /* unsupported modes and filters */ + if (event->attr.exclude_user || + event->attr.exclude_kernel || + event->attr.exclude_hv || + event->attr.exclude_idle || + event->attr.exclude_host || + event->attr.exclude_guest || + event->attr.sample_period) /* no sampling */ + return -EINVAL; + + if (event->cpu < 0) + return -EINVAL; + + chip_id = topology_physical_package_id(event->cpu); + event->hw.event_base = event->attr.config + + p8_perchip_nest_info[chip_id].vbase; + + return 0; +} + +void p8_nest_read_counter(struct perf_event *event) +{ + u64 *addr; + u64 data = 0; + + addr = (u64 *)event->hw.event_base; + data = __be64_to_cpu((uint64_t)*addr); + local64_set(&event->hw.prev_count, data); +} + +void p8_nest_perf_event_update(struct perf_event *event) +{ + u64 counter_prev, counter_new, final_count; + uint64_t *addr; + + addr = (u64 *)event->hw.event_base; + counter_prev = local64_read(&event->hw.prev_count); + counter_new = __be64_to_cpu((uint64_t)*addr); + final_count = counter_new - counter_prev; + + local64_set(&event->hw.prev_count, counter_new); + local64_add(final_count, &event->count); +} + +void p8_nest_event_start(struct perf_event *event, int flags) +{ + event->hw.state = 0; + p8_nest_read_counter(event); +} + +void p8_nest_event_stop(struct perf_event *event, int flags) +{ + p8_nest_perf_event_update(event); +} + +int p8_nest_event_add(struct perf_event *event, int flags) +{ + p8_nest_event_start(event, flags); + return 0; +} + +void p8_nest_event_del(struct perf_event *event, int flags) +{ + p8_nest_event_stop(event, flags); +} + +/* + * Populate pmu ops in the structure + */ +static int update_pmu_ops(struct nest_pmu *pmu) +{ + if (!pmu) + return -EINVAL; + + pmu->pmu.task_ctx_nr = perf_invalid_context; + pmu->pmu.event_init = p8_nest_event_init; + pmu->pmu.add = p8_nest_event_add; + pmu->pmu.del = p8_nest_event_del; + pmu->pmu.start = p8_nest_event_start; + pmu->pmu.stop = p8_nest_event_stop; + pmu->pmu.read = p8_nest_perf_event_update; + pmu->pmu.attr_groups = pmu->attr_groups; + + return 0; +} static int __init nest_pmu_init(void) {
Patch adds generic nest pmu functions and format attribute. Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com> Cc: Anshuman Khandual <khandual@linux.vnet.ibm.com> Cc: Stephane Eranian <eranian@google.com> Signed-off-by: Madhavan Srinivasan <maddy@linux.vnet.ibm.com> --- arch/powerpc/perf/nest-pmu.c | 107 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+)