Re: [PATCH v3 2/3] perf: xgene: Move PMU leaf functions into function pointer structure

2017-06-22 Thread Mark Rutland
On Tue, Jun 06, 2017 at 11:02:25AM -0700, Hoan Tran wrote:
> This patch moves PMU leaf functions into a function pointer structure.
> It helps code maintain and expasion easier.
> 
> Signed-off-by: Hoan Tran 
> ---
>  drivers/perf/xgene_pmu.c | 85 
> +---
>  1 file changed, 66 insertions(+), 19 deletions(-)

> -static inline u32 xgene_pmu_read_counter(struct xgene_pmu_dev *pmu_dev, int 
> idx)
> +static inline u64 xgene_pmu_read_counter32(struct xgene_pmu_dev *pmu_dev,
> +int idx)
>  {
> - return readl(pmu_dev->inf->csr + PMU_PMEVCNTR0 + (4 * idx));
> + return (u64)readl(pmu_dev->inf->csr + PMU_PMEVCNTR0 + (4 * idx));
>  }

Nit: the cast is redundant, and can go.

Otherwise:

Acked-by: Mark Rutland 

Thanks,
Mark.


[PATCH v3 2/3] perf: xgene: Move PMU leaf functions into function pointer structure

2017-06-06 Thread Hoan Tran
This patch moves PMU leaf functions into a function pointer structure.
It helps code maintain and expasion easier.

Signed-off-by: Hoan Tran 
---
 drivers/perf/xgene_pmu.c | 85 +---
 1 file changed, 66 insertions(+), 19 deletions(-)

diff --git a/drivers/perf/xgene_pmu.c b/drivers/perf/xgene_pmu.c
index 5ffd580..f34fc78 100644
--- a/drivers/perf/xgene_pmu.c
+++ b/drivers/perf/xgene_pmu.c
@@ -96,6 +96,23 @@ struct xgene_pmu_dev {
struct perf_event *pmu_counter_event[PMU_MAX_COUNTERS];
 };
 
+struct xgene_pmu_ops {
+   void (*mask_int)(struct xgene_pmu *pmu);
+   void (*unmask_int)(struct xgene_pmu *pmu);
+   u64 (*read_counter)(struct xgene_pmu_dev *pmu, int idx);
+   void (*write_counter)(struct xgene_pmu_dev *pmu, int idx, u64 val);
+   void (*write_evttype)(struct xgene_pmu_dev *pmu_dev, int idx, u32 val);
+   void (*write_agentmsk)(struct xgene_pmu_dev *pmu_dev, u32 val);
+   void (*write_agent1msk)(struct xgene_pmu_dev *pmu_dev, u32 val);
+   void (*enable_counter)(struct xgene_pmu_dev *pmu_dev, int idx);
+   void (*disable_counter)(struct xgene_pmu_dev *pmu_dev, int idx);
+   void (*enable_counter_int)(struct xgene_pmu_dev *pmu_dev, int idx);
+   void (*disable_counter_int)(struct xgene_pmu_dev *pmu_dev, int idx);
+   void (*reset_counters)(struct xgene_pmu_dev *pmu_dev);
+   void (*start_counters)(struct xgene_pmu_dev *pmu_dev);
+   void (*stop_counters)(struct xgene_pmu_dev *pmu_dev);
+};
+
 struct xgene_pmu {
struct device *dev;
int version;
@@ -104,6 +121,7 @@ struct xgene_pmu {
u32 mc_active_mask;
cpumask_t cpu;
raw_spinlock_t lock;
+   const struct xgene_pmu_ops *ops;
struct list_head l3cpmus;
struct list_head iobpmus;
struct list_head mcbpmus;
@@ -392,13 +410,14 @@ static inline void xgene_pmu_unmask_int(struct xgene_pmu 
*xgene_pmu)
writel(PCPPMU_INTCLRMASK, xgene_pmu->pcppmu_csr + PCPPMU_INTMASK_REG);
 }
 
-static inline u32 xgene_pmu_read_counter(struct xgene_pmu_dev *pmu_dev, int 
idx)
+static inline u64 xgene_pmu_read_counter32(struct xgene_pmu_dev *pmu_dev,
+  int idx)
 {
-   return readl(pmu_dev->inf->csr + PMU_PMEVCNTR0 + (4 * idx));
+   return (u64)readl(pmu_dev->inf->csr + PMU_PMEVCNTR0 + (4 * idx));
 }
 
 static inline void
-xgene_pmu_write_counter(struct xgene_pmu_dev *pmu_dev, int idx, u32 val)
+xgene_pmu_write_counter32(struct xgene_pmu_dev *pmu_dev, int idx, u64 val)
 {
writel(val, pmu_dev->inf->csr + PMU_PMEVCNTR0 + (4 * idx));
 }
@@ -491,20 +510,22 @@ static inline void xgene_pmu_stop_counters(struct 
xgene_pmu_dev *pmu_dev)
 static void xgene_perf_pmu_enable(struct pmu *pmu)
 {
struct xgene_pmu_dev *pmu_dev = to_pmu_dev(pmu);
+   struct xgene_pmu *xgene_pmu = pmu_dev->parent;
int enabled = bitmap_weight(pmu_dev->cntr_assign_mask,
pmu_dev->max_counters);
 
if (!enabled)
return;
 
-   xgene_pmu_start_counters(pmu_dev);
+   xgene_pmu->ops->start_counters(pmu_dev);
 }
 
 static void xgene_perf_pmu_disable(struct pmu *pmu)
 {
struct xgene_pmu_dev *pmu_dev = to_pmu_dev(pmu);
+   struct xgene_pmu *xgene_pmu = pmu_dev->parent;
 
-   xgene_pmu_stop_counters(pmu_dev);
+   xgene_pmu->ops->stop_counters(pmu_dev);
 }
 
 static int xgene_perf_event_init(struct perf_event *event)
@@ -572,27 +593,32 @@ static int xgene_perf_event_init(struct perf_event *event)
 static void xgene_perf_enable_event(struct perf_event *event)
 {
struct xgene_pmu_dev *pmu_dev = to_pmu_dev(event->pmu);
+   struct xgene_pmu *xgene_pmu = pmu_dev->parent;
 
-   xgene_pmu_write_evttype(pmu_dev, GET_CNTR(event), GET_EVENTID(event));
-   xgene_pmu_write_agentmsk(pmu_dev, ~((u32)GET_AGENTID(event)));
+   xgene_pmu->ops->write_evttype(pmu_dev, GET_CNTR(event),
+ GET_EVENTID(event));
+   xgene_pmu->ops->write_agentmsk(pmu_dev, ~((u32)GET_AGENTID(event)));
if (pmu_dev->inf->type == PMU_TYPE_IOB)
-   xgene_pmu_write_agent1msk(pmu_dev, ~((u32)GET_AGENT1ID(event)));
+   xgene_pmu->ops->write_agent1msk(pmu_dev,
+   ~((u32)GET_AGENT1ID(event)));
 
-   xgene_pmu_enable_counter(pmu_dev, GET_CNTR(event));
-   xgene_pmu_enable_counter_int(pmu_dev, GET_CNTR(event));
+   xgene_pmu->ops->enable_counter(pmu_dev, GET_CNTR(event));
+   xgene_pmu->ops->enable_counter_int(pmu_dev, GET_CNTR(event));
 }
 
 static void xgene_perf_disable_event(struct perf_event *event)
 {
struct xgene_pmu_dev *pmu_dev = to_pmu_dev(event->pmu);
+   struct xgene_pmu *xgene_pmu = pmu_dev->parent;
 
-   xgene_pmu_disable_counter(pmu_dev, GET_CNTR(event));
-   xgene_pmu_disable_counter_int(pmu_dev, GET_CNTR(event));
+   xgene_pmu->ops->disable_counter(pmu_dev,