Patrick Williams | 2194f50 | 2022-10-16 14:26:09 -0500 | [diff] [blame^] | 1 | From 762ba0fb54d97c08c35fbe2745c19fd4a74ded0d Mon Sep 17 00:00:00 2001 |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 2 | From: Robin Murphy <robin.murphy@arm.com> |
| 3 | Date: Fri, 3 Dec 2021 11:44:53 +0000 |
Patrick Williams | 2194f50 | 2022-10-16 14:26:09 -0500 | [diff] [blame^] | 4 | Subject: [PATCH 18/40] perf/arm-cmn: Refactor node ID handling |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 5 | |
| 6 | Add a bit more abstraction for the places where we decompose node IDs. |
| 7 | This will help keep things nice and manageable when we come to add yet |
| 8 | more variables which affect the node ID format. Also use the opportunity |
| 9 | to move the rest of the low-level node management helpers back up to the |
| 10 | logical place they were meant to be - how they ended up buried right in |
| 11 | the middle of the event-related definitions is somewhat of a mystery... |
| 12 | |
| 13 | Signed-off-by: Robin Murphy <robin.murphy@arm.com> |
| 14 | Link: https://lore.kernel.org/r/a2242a8c3c96056c13a04ae87bf2047e5e64d2d9.1638530442.git.robin.murphy@arm.com |
| 15 | Signed-off-by: Will Deacon <will@kernel.org> |
| 16 | |
| 17 | Upstream-Status: Backport [https://lore.kernel.org/r/a2242a8c3c96056c13a04ae87bf2047e5e64d2d9.1638530442.git.robin.murphy@arm.com] |
| 18 | Signed-off-by: Rupinderjit Singh <rupinderjit.singh@arm.com> |
| 19 | --- |
| 20 | drivers/perf/arm-cmn.c | 94 +++++++++++++++++++++++++----------------- |
| 21 | 1 file changed, 56 insertions(+), 38 deletions(-) |
| 22 | |
| 23 | diff --git a/drivers/perf/arm-cmn.c b/drivers/perf/arm-cmn.c |
Patrick Williams | 2194f50 | 2022-10-16 14:26:09 -0500 | [diff] [blame^] | 24 | index 1d52fcfe3a0d..adf50d613734 100644 |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 25 | --- a/drivers/perf/arm-cmn.c |
| 26 | +++ b/drivers/perf/arm-cmn.c |
| 27 | @@ -255,6 +255,58 @@ struct arm_cmn { |
| 28 | |
| 29 | static int arm_cmn_hp_state; |
| 30 | |
| 31 | +struct arm_cmn_nodeid { |
| 32 | + u8 x; |
| 33 | + u8 y; |
| 34 | + u8 port; |
| 35 | + u8 dev; |
| 36 | +}; |
| 37 | + |
| 38 | +static int arm_cmn_xyidbits(const struct arm_cmn *cmn) |
| 39 | +{ |
| 40 | + int dim = max(cmn->mesh_x, cmn->mesh_y); |
| 41 | + |
| 42 | + return dim > 4 ? 3 : 2; |
| 43 | +} |
| 44 | + |
| 45 | +static struct arm_cmn_nodeid arm_cmn_nid(const struct arm_cmn *cmn, u16 id) |
| 46 | +{ |
| 47 | + struct arm_cmn_nodeid nid; |
| 48 | + int bits = arm_cmn_xyidbits(cmn); |
| 49 | + |
| 50 | + nid.x = CMN_NODEID_X(id, bits); |
| 51 | + nid.y = CMN_NODEID_Y(id, bits); |
| 52 | + nid.port = CMN_NODEID_PID(id); |
| 53 | + nid.dev = CMN_NODEID_DEVID(id); |
| 54 | + |
| 55 | + return nid; |
| 56 | +} |
| 57 | + |
| 58 | +static void arm_cmn_init_node_to_xp(const struct arm_cmn *cmn, |
| 59 | + struct arm_cmn_node *dn) |
| 60 | +{ |
| 61 | + struct arm_cmn_nodeid nid = arm_cmn_nid(cmn, dn->id); |
| 62 | + int xp_idx = cmn->mesh_x * nid.y + nid.x; |
| 63 | + |
| 64 | + dn->to_xp = (cmn->xps + xp_idx) - dn; |
| 65 | +} |
| 66 | + |
| 67 | +static struct arm_cmn_node *arm_cmn_node_to_xp(struct arm_cmn_node *dn) |
| 68 | +{ |
| 69 | + return dn->type == CMN_TYPE_XP ? dn : dn + dn->to_xp; |
| 70 | +} |
| 71 | + |
| 72 | +static struct arm_cmn_node *arm_cmn_node(const struct arm_cmn *cmn, |
| 73 | + enum cmn_node_type type) |
| 74 | +{ |
| 75 | + int i; |
| 76 | + |
| 77 | + for (i = 0; i < cmn->num_dns; i++) |
| 78 | + if (cmn->dns[i].type == type) |
| 79 | + return &cmn->dns[i]; |
| 80 | + return NULL; |
| 81 | +} |
| 82 | + |
| 83 | struct arm_cmn_hw_event { |
| 84 | struct arm_cmn_node *dn; |
| 85 | u64 dtm_idx[2]; |
| 86 | @@ -295,38 +347,6 @@ struct arm_cmn_format_attr { |
| 87 | int config; |
| 88 | }; |
| 89 | |
| 90 | -static int arm_cmn_xyidbits(const struct arm_cmn *cmn) |
| 91 | -{ |
| 92 | - return cmn->mesh_x > 4 || cmn->mesh_y > 4 ? 3 : 2; |
| 93 | -} |
| 94 | - |
| 95 | -static void arm_cmn_init_node_to_xp(const struct arm_cmn *cmn, |
| 96 | - struct arm_cmn_node *dn) |
| 97 | -{ |
| 98 | - int bits = arm_cmn_xyidbits(cmn); |
| 99 | - int x = CMN_NODEID_X(dn->id, bits); |
| 100 | - int y = CMN_NODEID_Y(dn->id, bits); |
| 101 | - int xp_idx = cmn->mesh_x * y + x; |
| 102 | - |
| 103 | - dn->to_xp = (cmn->xps + xp_idx) - dn; |
| 104 | -} |
| 105 | - |
| 106 | -static struct arm_cmn_node *arm_cmn_node_to_xp(struct arm_cmn_node *dn) |
| 107 | -{ |
| 108 | - return dn->type == CMN_TYPE_XP ? dn : dn + dn->to_xp; |
| 109 | -} |
| 110 | - |
| 111 | -static struct arm_cmn_node *arm_cmn_node(const struct arm_cmn *cmn, |
| 112 | - enum cmn_node_type type) |
| 113 | -{ |
| 114 | - int i; |
| 115 | - |
| 116 | - for (i = 0; i < cmn->num_dns; i++) |
| 117 | - if (cmn->dns[i].type == type) |
| 118 | - return &cmn->dns[i]; |
| 119 | - return NULL; |
| 120 | -} |
| 121 | - |
| 122 | #define CMN_EVENT_ATTR(_name, _type, _eventid, _occupid) \ |
| 123 | (&((struct arm_cmn_event_attr[]) {{ \ |
| 124 | .attr = __ATTR(_name, 0444, arm_cmn_event_show, NULL), \ |
| 125 | @@ -966,11 +986,10 @@ static int arm_cmn_event_init(struct perf_event *event) |
| 126 | } |
| 127 | |
| 128 | if (!hw->num_dns) { |
| 129 | - int bits = arm_cmn_xyidbits(cmn); |
| 130 | + struct arm_cmn_nodeid nid = arm_cmn_nid(cmn, nodeid); |
| 131 | |
| 132 | dev_dbg(cmn->dev, "invalid node 0x%x (%d,%d,%d,%d) type 0x%x\n", |
| 133 | - nodeid, CMN_NODEID_X(nodeid, bits), CMN_NODEID_Y(nodeid, bits), |
| 134 | - CMN_NODEID_PID(nodeid), CMN_NODEID_DEVID(nodeid), type); |
| 135 | + nodeid, nid.x, nid.y, nid.port, nid.dev, type); |
| 136 | return -EINVAL; |
| 137 | } |
| 138 | /* |
| 139 | @@ -1068,11 +1087,10 @@ static int arm_cmn_event_add(struct perf_event *event, int flags) |
| 140 | dn->wp_event[wp_idx] = dtc_idx; |
| 141 | writel_relaxed(cfg, dn->pmu_base + CMN_DTM_WPn_CONFIG(wp_idx)); |
| 142 | } else { |
| 143 | - unsigned int port = CMN_NODEID_PID(dn->id); |
| 144 | - unsigned int dev = CMN_NODEID_DEVID(dn->id); |
| 145 | + struct arm_cmn_nodeid nid = arm_cmn_nid(cmn, dn->id); |
| 146 | |
| 147 | input_sel = CMN__PMEVCNT0_INPUT_SEL_DEV + dtm_idx + |
| 148 | - (port << 4) + (dev << 2); |
| 149 | + (nid.port << 4) + (nid.dev << 2); |
| 150 | |
| 151 | if (arm_cmn_is_occup_event(type, CMN_EVENT_EVENTID(event))) { |
| 152 | int occupid = CMN_EVENT_OCCUPID(event); |
| 153 | -- |
Patrick Williams | 2194f50 | 2022-10-16 14:26:09 -0500 | [diff] [blame^] | 154 | 2.34.1 |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 155 | |