]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/commitdiff
powerpc/perf: Factor out event_alternative function
authorMadhavan Srinivasan <maddy@linux.vnet.ibm.com>
Sun, 12 Feb 2017 17:03:10 +0000 (22:33 +0530)
committerSeth Forshee <seth.forshee@canonical.com>
Fri, 24 Feb 2017 13:26:19 +0000 (07:26 -0600)
BugLink: http://bugs.launchpad.net/bugs/1667413
Factor out the power8 event_alternative function to share
the code with power9.

Signed-off-by: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
(cherry picked from linux-next commit efe881afdd9996ccbcd2a09c93b724f4ffc25991)
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
arch/powerpc/perf/isa207-common.c
arch/powerpc/perf/isa207-common.h
arch/powerpc/perf/power8-pmu.c

index 2703a1e340e77154016580f7a8c88ba3e0feebd3..e79fb5fb817dbe21cd19f633d89ca3bbbf51ad0c 100644 (file)
@@ -358,3 +358,39 @@ void isa207_disable_pmc(unsigned int pmc, unsigned long mmcr[])
        if (pmc <= 3)
                mmcr[1] &= ~(0xffUL << MMCR1_PMCSEL_SHIFT(pmc + 1));
 }
+
+static int find_alternative(u64 event, const unsigned int ev_alt[][MAX_ALT], int size)
+{
+       int i, j;
+
+       for (i = 0; i < size; ++i) {
+               if (event < ev_alt[i][0])
+                       break;
+
+               for (j = 0; j < MAX_ALT && ev_alt[i][j]; ++j)
+                       if (event == ev_alt[i][j])
+                               return i;
+       }
+
+       return -1;
+}
+
+int isa207_get_alternatives(u64 event, u64 alt[],
+                               const unsigned int ev_alt[][MAX_ALT], int size)
+{
+       int i, j, num_alt = 0;
+       u64 alt_event;
+
+       alt[num_alt++] = event;
+       i = find_alternative(event, ev_alt, size);
+       if (i >= 0) {
+               /* Filter out the original event, it's already in alt[0] */
+               for (j = 0; j < MAX_ALT; ++j) {
+                       alt_event = ev_alt[i][j];
+                       if (alt_event && alt_event != event)
+                               alt[num_alt++] = alt_event;
+               }
+       }
+
+       return num_alt;
+}
index 82c93b6410229e8932166ae77f42a18ce7f01b4f..cf9bd89901595cc38b793bc916a2096d873054eb 100644 (file)
@@ -264,5 +264,8 @@ int isa207_compute_mmcr(u64 event[], int n_ev,
                                unsigned int hwc[], unsigned long mmcr[],
                                struct perf_event *pevents[]);
 void isa207_disable_pmc(unsigned int pmc, unsigned long mmcr[]);
+int isa207_get_alternatives(u64 event, u64 alt[],
+                               const unsigned int ev_alt[][MAX_ALT], int size);
+
 
 #endif
index d07186382f3a75b147bfe582563f98341f50ea7e..ce15b19a7962c1de92f2d32f1ef4626c90a804be 100644 (file)
@@ -48,43 +48,12 @@ static const unsigned int event_alternatives[][MAX_ALT] = {
        { PM_RUN_INST_CMPL_ALT,         PM_RUN_INST_CMPL },
 };
 
-/*
- * Scan the alternatives table for a match and return the
- * index into the alternatives table if found, else -1.
- */
-static int find_alternative(u64 event)
-{
-       int i, j;
-
-       for (i = 0; i < ARRAY_SIZE(event_alternatives); ++i) {
-               if (event < event_alternatives[i][0])
-                       break;
-
-               for (j = 0; j < MAX_ALT && event_alternatives[i][j]; ++j)
-                       if (event == event_alternatives[i][j])
-                               return i;
-       }
-
-       return -1;
-}
-
 static int power8_get_alternatives(u64 event, unsigned int flags, u64 alt[])
 {
        int i, j, num_alt = 0;
-       u64 alt_event;
-
-       alt[num_alt++] = event;
-
-       i = find_alternative(event);
-       if (i >= 0) {
-               /* Filter out the original event, it's already in alt[0] */
-               for (j = 0; j < MAX_ALT; ++j) {
-                       alt_event = event_alternatives[i][j];
-                       if (alt_event && alt_event != event)
-                               alt[num_alt++] = alt_event;
-               }
-       }
 
+       num_alt = isa207_get_alternatives(event, alt, event_alternatives,
+                                       (int)ARRAY_SIZE(event_alternatives));
        if (flags & PPMU_ONLY_COUNT_RUN) {
                /*
                 * We're only counting in RUN state, so PM_CYC is equivalent to