Skip to contentSkip to conversation

ARM CCN driver updates

PATCH New Pawel Moll 2 participants 7 messages May 1, 2015 – May 12, 2015 Documentation

lore
Share & tools
lore

Pawel Moll

author
#0 lore raw

cover ARM CCN driver updates

Arnd, Olof, Kevin,

Here's a short set of updates to the ARM CCN driver, aiming at 4.2.

No major functional changes, just a bunch of smaller and larger bug fixes and getting the driver in line with the latest perf tool features.

The series can be also pulled:

The following changes since commit b787f68c36d49bb1d9236f403813641efa74a031:

Linux 4.1-rc1 (2015-04-26 17:59:10 -0700)

are available in the git repository at:

git://git.linaro.org/people/pawel.moll/linux.git tags/ccn/updates-for-4.2

for you to fetch changes up to 57006d3e6f62def53c01ae3ffc338caebd866e89:

bus: arm-ccn: Allocate event when it is being added, not initialised (2015-05-01 17:51:05 +0100)

----------------------------------------------------------------
Set of ARM CCN PMU driver updates:
- fixed a nasty bitfield mangling bug
- added new hints to the perf userspace tool
- pinned events processing to a single PMU
- modified events initialisation so they can be rotated now

----------------------------------------------------------------

Pawel Moll (5):
bus: arm-ccn: Fix node->XP config conversion
bus: arm-ccn: cpumask attribute
bus: arm-ccn: Provide required event arguments
bus: arm-ccn: Do not group CCN events with other PMUs
bus: arm-ccn: Allocate event when it is being added, not initialised

 Documentation/arm/CCN.txt |  17 +--
 drivers/bus/arm-ccn.c     | 273 ++++++++++++++++++++++++++++++++++++----------
 2 files changed, 226 insertions(+), 64 deletions(-)
Signature · 1 line
2.1.0
author
#1 lore raw

PATCH 1/5 bus: arm-ccn: Fix node->XP config conversion

Events defined as watchpoints on nodes must have their config values converted so that they apply to the respective node's XP. The function setting new values was using wrong mask for the "port" field, resulting in corrupted value. Fixed now.

Cc stable at vger.kernel.org # 3.17+
---
 drivers/bus/arm-ccn.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/bus/arm-ccn.c +1 -1
index aaa0f2a..60397ec 100644
@@ -212,7 +212,7 @@ static int arm_ccn_node_to_xp_port(int node)
 
 static void arm_ccn_pmu_config_set(u64 *config, u32 node_xp, u32 type, u32 port)
 {
-	*config &= ~((0xff << 0) | (0xff << 8) | (0xff << 24));
+	*config &= ~((0xff << 0) | (0xff << 8) | (0x3 << 24));
 	*config |= (node_xp << 0) | (type << 8) | (port << 24);
 }
 
Signature · 1 line
2.1.0
author
#2 lore raw

PATCH 2/5 bus: arm-ccn: cpumask attribute

In reply to Pawel Moll

This patch adds a "cpumask" attribute to CCN's event_source class sysfs directory. Perf user tool uses it to restrict events to the processor(s) enumerated in this mask.

This patch provides a single CPU mask, making it possible to run "-a" perf session (previously it would request the same CCN event, for example cycle counter, on each available core and most likely fail). Initially the mask is set to the CPU that happened to probe the driver, but it will be changed when it is hot-un-plugged (active events are migrated to another CPU then).

Example:

Performance counter stats for 'system wide':

CPU0               2968148      cycles
CPU1               2236736      cycles
CPU2               1797968      cycles
CPU3               1831715      cycles
CPU1            1201850868      ccn/cycles/
       1.001241383 seconds time elapsed
---
 Documentation/arm/CCN.txt |  15 +++---
 drivers/bus/arm-ccn.c     | 128 ++++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 126 insertions(+), 17 deletions(-)
Documentation/arm/CCN.txt +9 -6
index 0632b3a..3a76048 100644
@@ -33,6 +33,13 @@ directory, with first 8 configurable by user and additional
 Cycle counter is described by a "type" value 0xff and does
 not require any other settings.
 
+The driver also provides a "cpumask" sysfs attribute, which contains
+a single CPU ID, of the processor which will be used to handle all
+the CCN PMU events. It is recommended that the user space tools
+request the events on this processor (if not, the perf_event->cpu value
+will be overwritten anyway). In case of this processor being offlined,
+the events are migrated to another one and the attribute is updated.
+
 Example of perf tool use:
 
 / # perf list | grep ccn
@@ -41,12 +48,8 @@ Example of perf tool use:
   ccn/xp_valid_flit/                                 [Kernel PMU event]
 <...>
 
-/ # perf stat -C 0 -e ccn/cycles/,ccn/xp_valid_flit,xp=1,port=0,vc=1,dir=1/ \
+/ # perf stat -a -e ccn/cycles/,ccn/xp_valid_flit,xp=1,port=0,vc=1,dir=1/ \
                                                                        sleep 1
 
 The driver does not support sampling, therefore "perf record" will
-not work. Also notice that only single cpu is being selected
-("-C 0") - this is because perf framework does not support
-"non-CPU related" counters (yet?) so system-wide session ("-a")
-would try (and in most cases fail) to set up the same event
-per each CPU.
+not work. Per-task (without "-a") perf sessions are not supported.
drivers/bus/arm-ccn.c +117 -11

221 lines not on this page · raw message

Signature · 1 line
2.1.0
author
#3 lore raw

PATCH 3/5 bus: arm-ccn: Provide required event arguments

In reply to Pawel Moll

Since 688d4dfcdd624192cbf03c08402e444d1d11f294 "perf tools: Support parsing parameterized events" the perf userspace tools understands "argument=?" syntax in the events file, making sure that required arguments are provided by the user and not defaulting to 0, causing confusion.

This patch adds the required arguments lists for CCN events.

---
 Documentation/arm/CCN.txt |  2 +-
 drivers/bus/arm-ccn.c     | 17 +++++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)
Documentation/arm/CCN.txt +1 -1
index 3a76048..ffca443 100644
@@ -45,7 +45,7 @@ Example of perf tool use:
 / # perf list | grep ccn
   ccn/cycles/                                        [Kernel PMU event]
 <...>
-  ccn/xp_valid_flit/                                 [Kernel PMU event]
+  ccn/xp_valid_flit,xp=?,port=?,vc=?,dir=?/          [Kernel PMU event]
 <...>
 
 / # perf stat -a -e ccn/cycles/,ccn/xp_valid_flit,xp=1,port=0,vc=1,dir=1/ \
drivers/bus/arm-ccn.c +17 -0
index 3374dcb..572360f 100644
@@ -340,6 +340,23 @@ static ssize_t arm_ccn_pmu_event_show(struct device *dev,
 	if (event->mask)
 		res += snprintf(buf + res, PAGE_SIZE - res, ",mask=0x%x",
 				event->mask);
+
+	/* Arguments required by an event */
+	switch (event->type) {
+	case CCN_TYPE_CYCLES:
+		break;
+	case CCN_TYPE_XP:
+		res += snprintf(buf + res, PAGE_SIZE - res,
+				",xp=?,port=?,vc=?,dir=?");
+		if (event->event == CCN_EVENT_WATCHPOINT)
+			res += snprintf(buf + res, PAGE_SIZE - res,
+					",cmp_l=?,cmp_h=?,mask=?");
+		break;
+	default:
+		res += snprintf(buf + res, PAGE_SIZE - res, ",node=?");
+		break;
+	}
+
 	res += snprintf(buf + res, PAGE_SIZE - res, "\n");
 
 	return res;
Signature · 1 line
2.1.0
author
#4 lore raw

PATCH 4/5 bus: arm-ccn: Do not group CCN events with other PMUs

In reply to Pawel Moll

Groups must not mix events from different PMUs (software events are allowed). Unfortunately the core does not ensures that, so it is necessary to validate the group at the PMU driver level.

---
 drivers/bus/arm-ccn.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
drivers/bus/arm-ccn.c +16 -0
index 572360f..fb589d4 100644
@@ -660,6 +660,7 @@ static int arm_ccn_pmu_event_init(struct perf_event *event)
 	int valid, bit;
 	struct arm_ccn_component *source;
 	int i;
+	struct perf_event *sibling;
 
 	if (event->attr.type != event->pmu->type)
 		return -ENOENT;
@@ -762,6 +763,21 @@ static int arm_ccn_pmu_event_init(struct perf_event *event)
 				node_xp, type, port);
 	}
 
+	/*
+	 * We must NOT create groups containing mixed PMUs, although software
+	 * events are acceptable (for example to create a CCN group
+	 * periodically read when a hrtimer aka cpu-clock leader triggers).
+	 */
+	if (event->group_leader->pmu != event->pmu &&
+			!is_software_event(event->group_leader))
+		return -EINVAL;
+
+	list_for_each_entry(sibling, &event->group_leader->sibling_list,
+			group_entry)
+		if (sibling->pmu != event->pmu &&
+				!is_software_event(sibling))
+			return -EINVAL;
+
 	/* Allocate the cycle counter */
 	if (type == CCN_TYPE_CYCLES) {
 		if (test_and_set_bit(CCN_IDX_PMU_CYCLE_COUNTER,
Signature · 1 line
2.1.0
author
#5 lore raw

PATCH 5/5 bus: arm-ccn: Allocate event when it is being added, not initialised

In reply to Pawel Moll

To make events rotation possible, they should be allocated when event is being ->added(), not during initialisation. This patch moves the respective code.

---
 drivers/bus/arm-ccn.c | 114 +++++++++++++++++++++++++++++---------------------
 1 file changed, 67 insertions(+), 47 deletions(-)
drivers/bus/arm-ccn.c +67 -47
index fb589d4..df5f307 100644
@@ -628,7 +628,65 @@ static int arm_ccn_pmu_type_eq(u32 a, u32 b)
 	return 0;
 }
 
-static void arm_ccn_pmu_event_destroy(struct perf_event *event)
+static int arm_ccn_pmu_event_alloc(struct perf_event *event)
+{
+	struct arm_ccn *ccn = pmu_to_arm_ccn(event->pmu);
+	struct hw_perf_event *hw = &event->hw;
+	u32 node_xp, type, event_id;
+	struct arm_ccn_component *source;
+	int bit;
+
+	node_xp = CCN_CONFIG_NODE(event->attr.config);
+	type = CCN_CONFIG_TYPE(event->attr.config);
+	event_id = CCN_CONFIG_EVENT(event->attr.config);
+
+	/* Allocate the cycle counter */
+	if (type == CCN_TYPE_CYCLES) {
+		if (test_and_set_bit(CCN_IDX_PMU_CYCLE_COUNTER,
+				ccn->dt.pmu_counters_mask))
+			return -EAGAIN;
+
+		hw->idx = CCN_IDX_PMU_CYCLE_COUNTER;
+		ccn->dt.pmu_counters[CCN_IDX_PMU_CYCLE_COUNTER].event = event;
+
+		return 0;
+	}
+
+	/* Allocate an event counter */
+	hw->idx = arm_ccn_pmu_alloc_bit(ccn->dt.pmu_counters_mask,
+			CCN_NUM_PMU_EVENT_COUNTERS);
+	if (hw->idx < 0) {
+		dev_dbg(ccn->dev, "No more counters available!\n");
+		return -EAGAIN;
+	}
+
+	if (type == CCN_TYPE_XP)
+		source = &ccn->xp[node_xp];
+	else
+		source = &ccn->node[node_xp];
+	ccn->dt.pmu_counters[hw->idx].source = source;
+
+	/* Allocate an event source or a watchpoint */
+	if (type == CCN_TYPE_XP && event_id == CCN_EVENT_WATCHPOINT)
+		bit = arm_ccn_pmu_alloc_bit(source->xp.dt_cmp_mask,
+				CCN_NUM_XP_WATCHPOINTS);
+	else
+		bit = arm_ccn_pmu_alloc_bit(source->pmu_events_mask,
+				CCN_NUM_PMU_EVENTS);
+	if (bit < 0) {
+		dev_dbg(ccn->dev, "No more event sources/watchpoints on node/XP %d!\n",
+				node_xp);
+		clear_bit(hw->idx, ccn->dt.pmu_counters_mask);
+		return -EAGAIN;
+	}
+	hw->config_base = bit;
+
+	ccn->dt.pmu_counters[hw->idx].event = event;
+
+	return 0;
+}
+
+static void arm_ccn_pmu_event_release(struct perf_event *event)
 {
 	struct arm_ccn *ccn = pmu_to_arm_ccn(event->pmu);
 	struct hw_perf_event *hw = &event->hw;
@@ -657,8 +715,7 @@ static int arm_ccn_pmu_event_init(struct perf_event *event)
 	struct arm_ccn *ccn;
 	struct hw_perf_event *hw = &event->hw;
 	u32 node_xp, type, event_id;
-	int valid, bit;
-	struct arm_ccn_component *source;
+	int valid;
 	int i;
 	struct perf_event *sibling;
 
@@ -666,7 +723,6 @@ static int arm_ccn_pmu_event_init(struct perf_event *event)
 		return -ENOENT;
 
 	ccn = pmu_to_arm_ccn(event->pmu);
-	event->destroy = arm_ccn_pmu_event_destroy;
 
 	if (hw->sample_period) {
 		dev_warn(ccn->dev, "Sampling not supported!\n");
@@ -778,49 +834,6 @@ static int arm_ccn_pmu_event_init(struct perf_event *event)
 				!is_software_event(sibling))
 			return -EINVAL;
 
-	/* Allocate the cycle counter */
-	if (type == CCN_TYPE_CYCLES) {
-		if (test_and_set_bit(CCN_IDX_PMU_CYCLE_COUNTER,
-				ccn->dt.pmu_counters_mask))
-			return -EAGAIN;
-
-		hw->idx = CCN_IDX_PMU_CYCLE_COUNTER;
-		ccn->dt.pmu_counters[CCN_IDX_PMU_CYCLE_COUNTER].event = event;
-
-		return 0;
-	}
-
-	/* Allocate an event counter */
-	hw->idx = arm_ccn_pmu_alloc_bit(ccn->dt.pmu_counters_mask,
-			CCN_NUM_PMU_EVENT_COUNTERS);
-	if (hw->idx < 0) {
-		dev_warn(ccn->dev, "No more counters available!\n");
-		return -EAGAIN;
-	}
-
-	if (type == CCN_TYPE_XP)
-		source = &ccn->xp[node_xp];
-	else
-		source = &ccn->node[node_xp];
-	ccn->dt.pmu_counters[hw->idx].source = source;
-
-	/* Allocate an event source or a watchpoint */
-	if (type == CCN_TYPE_XP && event_id == CCN_EVENT_WATCHPOINT)
-		bit = arm_ccn_pmu_alloc_bit(source->xp.dt_cmp_mask,
-				CCN_NUM_XP_WATCHPOINTS);
-	else
-		bit = arm_ccn_pmu_alloc_bit(source->pmu_events_mask,
-				CCN_NUM_PMU_EVENTS);
-	if (bit < 0) {
-		dev_warn(ccn->dev, "No more event sources/watchpoints on node/XP %d!\n",
-				node_xp);
-		clear_bit(hw->idx, ccn->dt.pmu_counters_mask);
-		return -EAGAIN;
-	}
-	hw->config_base = bit;
-
-	ccn->dt.pmu_counters[hw->idx].event = event;
-
 	return 0;
 }
 
@@ -1087,8 +1100,13 @@ static void arm_ccn_pmu_event_config(struct perf_event *event)
 
 static int arm_ccn_pmu_event_add(struct perf_event *event, int flags)
 {
+	int err;
 	struct hw_perf_event *hw = &event->hw;
 
+	err = arm_ccn_pmu_event_alloc(event);
+	if (err)
+		return err;
+
 	arm_ccn_pmu_event_config(event);
 
 	hw->state = PERF_HES_STOPPED;
@@ -1102,6 +1120,8 @@ static int arm_ccn_pmu_event_add(struct perf_event *event, int flags)
 static void arm_ccn_pmu_event_del(struct perf_event *event, int flags)
 {
 	arm_ccn_pmu_event_stop(event, PERF_EF_UPDATE);
+
+	arm_ccn_pmu_event_release(event);
 }
 
 static void arm_ccn_pmu_event_read(struct perf_event *event)
Signature · 1 line
2.1.0
#6 lore raw

cover ARM CCN driver updates

In reply to Pawel Moll
Quoted 18 lines · On Friday 01 May 2015 18:36:25 Pawel Moll wrote:

Here's a short set of updates to the ARM CCN driver, aiming at 4.2.

No major functional changes, just a bunch of smaller and larger bug fixes and getting the driver in line with the latest perf tool features.

The series can be also pulled:

The following changes since commit b787f68c36d49bb1d9236f403813641efa74a031:

Linux 4.1-rc1 (2015-04-26 17:59:10 -0700)

are available in the git repository at:

git://git.linaro.org/people/pawel.moll/linux.git tags/ccn/updates-for-4.2

for you to fetch changes up to 57006d3e6f62def53c01ae3ffc338caebd866e89:

Quoted 9 lines

bus: arm-ccn: Allocate event when it is being added, not initialised (2015-05-01 17:51:05 +0100)

----------------------------------------------------------------
Set of ARM CCN PMU driver updates:
- fixed a nasty bitfield mangling bug
- added new hints to the perf userspace tool
- pinned events processing to a single PMU
- modified events initialisation so they can be rotated now

Pulled into next/drivers, thanks!

Arnd