diff mbox

[v6,1/7] perf: provide sysfs_show for struct perf_pmu_events_attr

Message ID 1419234532-22657-2-git-send-email-sukadev@linux.vnet.ibm.com (mailing list archive)
State Superseded
Delegated to: Michael Ellerman
Headers show

Commit Message

Sukadev Bhattiprolu Dec. 22, 2014, 7:48 a.m. UTC
From: Cody P Schafer <cody@linux.vnet.ibm.com>

(struct perf_pmu_events_attr) is defined in include/linux/perf_event.h,
but the only "show" for it is in x86 and contains x86 specific stuff.

Make a generic one for those of us who are just using the event_str.

CC: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
CC: Haren Myneni <hbabu@us.ibm.com>
CC: Cody P Schafer <dev@codyps.com>
Signed-off-by: Cody P Schafer <cody@linux.vnet.ibm.com>
---
 include/linux/perf_event.h | 3 +++
 kernel/events/core.c       | 8 ++++++++
 2 files changed, 11 insertions(+)

Comments

Sukadev Bhattiprolu Jan. 23, 2015, 6:09 a.m. UTC | #1
Jiri, Arnaldo,

Can you please review/ack this and the next (i.e patches 1 and 2)
of this set ? Since other patches in this set depend on these two,
it maybe easier to have them all go through the ppc tree ?

Thanks,

Sukadev

Sukadev Bhattiprolu [sukadev@linux.vnet.ibm.com] wrote:
| From: Cody P Schafer <cody@linux.vnet.ibm.com>
| 
| (struct perf_pmu_events_attr) is defined in include/linux/perf_event.h,
| but the only "show" for it is in x86 and contains x86 specific stuff.
| 
| Make a generic one for those of us who are just using the event_str.
| 
| CC: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
| CC: Haren Myneni <hbabu@us.ibm.com>
| CC: Cody P Schafer <dev@codyps.com>
| Signed-off-by: Cody P Schafer <cody@linux.vnet.ibm.com>
| ---
|  include/linux/perf_event.h | 3 +++
|  kernel/events/core.c       | 8 ++++++++
|  2 files changed, 11 insertions(+)
| 
| diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
| index 486e84c..58f59bd 100644
| --- a/include/linux/perf_event.h
| +++ b/include/linux/perf_event.h
| @@ -897,6 +897,9 @@ struct perf_pmu_events_attr {
|  	const char *event_str;
|  };
|  
| +ssize_t perf_event_sysfs_show(struct device *dev, struct device_attribute *attr,
| +			      char *page);
| +
|  #define PMU_EVENT_ATTR(_name, _var, _id, _show)				\
|  static struct perf_pmu_events_attr _var = {				\
|  	.attr = __ATTR(_name, 0444, _show, NULL),			\
| diff --git a/kernel/events/core.c b/kernel/events/core.c
| index af0a5ba..1808d0e 100644
| --- a/kernel/events/core.c
| +++ b/kernel/events/core.c
| @@ -8276,6 +8276,14 @@ void __init perf_event_init(void)
|  		     != 1024);
|  }
|  
| +ssize_t perf_event_sysfs_show(struct device *dev, struct device_attribute *attr,
| +			      char *page)
| +{
| +	struct perf_pmu_events_attr *pmu_attr =
| +		container_of(attr, struct perf_pmu_events_attr, attr);
| +	return sprintf(page, "%s\n", pmu_attr->event_str);
| +}
| +
|  static int __init perf_event_sysfs_init(void)
|  {
|  	struct pmu *pmu;
| -- 
| 1.8.3.1
| 
| _______________________________________________
| Linuxppc-dev mailing list
| Linuxppc-dev@lists.ozlabs.org
| https://lists.ozlabs.org/listinfo/linuxppc-dev
Jiri Olsa Jan. 23, 2015, 9:46 a.m. UTC | #2
On Sun, Dec 21, 2014 at 11:48:46PM -0800, Sukadev Bhattiprolu wrote:
> From: Cody P Schafer <cody@linux.vnet.ibm.com>
> 
> (struct perf_pmu_events_attr) is defined in include/linux/perf_event.h,
> but the only "show" for it is in x86 and contains x86 specific stuff.
> 
> Make a generic one for those of us who are just using the event_str.
> 
> CC: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
> CC: Haren Myneni <hbabu@us.ibm.com>
> CC: Cody P Schafer <dev@codyps.com>
> Signed-off-by: Cody P Schafer <cody@linux.vnet.ibm.com>
> ---
>  include/linux/perf_event.h | 3 +++
>  kernel/events/core.c       | 8 ++++++++
>  2 files changed, 11 insertions(+)
> 
> diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
> index 486e84c..58f59bd 100644
> --- a/include/linux/perf_event.h
> +++ b/include/linux/perf_event.h
> @@ -897,6 +897,9 @@ struct perf_pmu_events_attr {
>  	const char *event_str;
>  };
>  
> +ssize_t perf_event_sysfs_show(struct device *dev, struct device_attribute *attr,
> +			      char *page);
> +
>  #define PMU_EVENT_ATTR(_name, _var, _id, _show)				\
>  static struct perf_pmu_events_attr _var = {				\
>  	.attr = __ATTR(_name, 0444, _show, NULL),			\
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index af0a5ba..1808d0e 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -8276,6 +8276,14 @@ void __init perf_event_init(void)
>  		     != 1024);
>  }
>  
> +ssize_t perf_event_sysfs_show(struct device *dev, struct device_attribute *attr,
> +			      char *page)
> +{
> +	struct perf_pmu_events_attr *pmu_attr =
> +		container_of(attr, struct perf_pmu_events_attr, attr);
> +	return sprintf(page, "%s\n", pmu_attr->event_str);
> +}
> +

Stephane just added same local one for RAPL pmu:
  433678bdc6ed perf/rapl: Fix sysfs_show() initialization for RAPL PMU

with additional pmu_attr->event_str check

same for PMU_EVENT_ATTR_STRING macro

if you could add this additional check plus the id initialization
in the PMU_EVENT_ATTR_STRING macro, we could use the generic
version in RAPL object as well

thanks,
jirka
diff mbox

Patch

diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index 486e84c..58f59bd 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -897,6 +897,9 @@  struct perf_pmu_events_attr {
 	const char *event_str;
 };
 
+ssize_t perf_event_sysfs_show(struct device *dev, struct device_attribute *attr,
+			      char *page);
+
 #define PMU_EVENT_ATTR(_name, _var, _id, _show)				\
 static struct perf_pmu_events_attr _var = {				\
 	.attr = __ATTR(_name, 0444, _show, NULL),			\
diff --git a/kernel/events/core.c b/kernel/events/core.c
index af0a5ba..1808d0e 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -8276,6 +8276,14 @@  void __init perf_event_init(void)
 		     != 1024);
 }
 
+ssize_t perf_event_sysfs_show(struct device *dev, struct device_attribute *attr,
+			      char *page)
+{
+	struct perf_pmu_events_attr *pmu_attr =
+		container_of(attr, struct perf_pmu_events_attr, attr);
+	return sprintf(page, "%s\n", pmu_attr->event_str);
+}
+
 static int __init perf_event_sysfs_init(void)
 {
 	struct pmu *pmu;