Skip to contentSkip to conversation

ARM CoreSight: Enhance ETM tracing control

PATCH In review Adrien Vergé 3 participants 13 messages Jan 24, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover ARM CoreSight: Enhance ETM tracing control

Hi,

Different ARM users have shown their interest in this patch, so I made a second version that corrects the first mistakes.

Mainly, it extends current support of CoreSight ETM, that is currently very limited. ETM provides hardware-assisted program tracing, a cycle-precise and low-overhead solution that software tools such as 'perf record' cannot provide.

Usage of ETM tracing facility is presently limited to start and stop tracing. This set of patches enables management of address combinations and PIDs that trigger tracing, thus allowing to trace specific functions and processes.

ETM management was done via sysfs entries (trace_info, trace_running...), this code adds trace_addrrange and trace_pid to let the user read/write custom values.

Changes in V2:
- Use device attributes rather than raw kobjects
- Make PID_IN_CONTEXTIDR incompatible with PID_NS in Kconfig
- Use int for pid type (not long)
- During trace fetching, call vmalloc() only if really needed

This series of patches applies to v3.13.

Adrien Verg? (6):
ARM CoreSight: ETM: Use device attributes
ARM CoreSight: ETM: Rename 'comparator' to 'address comparator' ARM CoreSight: ETM: Add address control support
ARM: Make PID_IN_CONTEXTIDR incompatible with PID_NS ARM CoreSight: ETM: Add PID control support
ARM CoreSight: ETM: Allocate a trace buffer only when necessary

 arch/arm/Kconfig.debug                    |   2 +-
 arch/arm/include/asm/hardware/coresight.h |   9 +-
 arch/arm/kernel/etm.c                     | 208 +++++++++++++++++++++++-------
 arch/arm64/Kconfig.debug                  |   1 +
 4 files changed, 169 insertions(+), 51 deletions(-)
Signature · 1 line
1.8.5.2
#1 lore raw

PATCH v2 1/6 ARM CoreSight: ETM: Use device attributes

Replace all kobjects attributes with device attributes.
User experience isn't changed since the same files are created in sysfs.

---
 arch/arm/kernel/etm.c | 48 +++++++++++++++++++++---------------------------
 1 file changed, 21 insertions(+), 27 deletions(-)
arch/arm/kernel/etm.c +21 -27
index 8ff0ecd..2b1a307 100644
@@ -430,15 +430,14 @@ static struct amba_driver etb_driver = {
 };
 
 /* use a sysfs file "trace_running" to start/stop tracing */
-static ssize_t trace_running_show(struct kobject *kobj,
-				  struct kobj_attribute *attr,
-				  char *buf)
+static ssize_t trace_running_show(struct device *dev,
+				  struct device_attribute *attr, char *buf)
 {
 	return sprintf(buf, "%x\n", trace_isrunning(&tracer));
 }
 
-static ssize_t trace_running_store(struct kobject *kobj,
-				   struct kobj_attribute *attr,
+static ssize_t trace_running_store(struct device *dev,
+				   struct device_attribute *attr,
 				   const char *buf, size_t n)
 {
 	unsigned int value;
@@ -454,12 +453,11 @@ static ssize_t trace_running_store(struct kobject *kobj,
 	return ret ? : n;
 }
 
-static struct kobj_attribute trace_running_attr =
-	__ATTR(trace_running, 0644, trace_running_show, trace_running_store);
+DEVICE_ATTR(trace_running, S_IRUGO|S_IWUSR,
+	    trace_running_show, trace_running_store);
 
-static ssize_t trace_info_show(struct kobject *kobj,
-				  struct kobj_attribute *attr,
-				  char *buf)
+static ssize_t trace_info_show(struct device *dev,
+			       struct device_attribute *attr, char *buf)
 {
 	u32 etb_wa, etb_ra, etb_st, etb_fc, etm_ctrl, etm_st;
 	int datalen;
@@ -495,21 +493,19 @@ static ssize_t trace_info_show(struct kobject *kobj,
 			);
 }
 
-static struct kobj_attribute trace_info_attr =
-	__ATTR(trace_info, 0444, trace_info_show, NULL);
+DEVICE_ATTR(trace_info, S_IRUGO, trace_info_show, NULL);
 
-static ssize_t trace_mode_show(struct kobject *kobj,
-				  struct kobj_attribute *attr,
-				  char *buf)
+static ssize_t trace_mode_show(struct device *dev,
+			       struct device_attribute *attr, char *buf)
 {
 	return sprintf(buf, "%d %d\n",
 			!!(tracer.flags & TRACER_CYCLE_ACC),
 			tracer.etm_portsz);
 }
 
-static ssize_t trace_mode_store(struct kobject *kobj,
-				   struct kobj_attribute *attr,
-				   const char *buf, size_t n)
+static ssize_t trace_mode_store(struct device *dev,
+				struct device_attribute *attr,
+				const char *buf, size_t n)
 {
 	unsigned int cycacc, portsz;
 
@@ -528,8 +524,7 @@ static ssize_t trace_mode_store(struct kobject *kobj,
 	return n;
 }
 
-static struct kobj_attribute trace_mode_attr =
-	__ATTR(trace_mode, 0644, trace_mode_show, trace_mode_store);
+DEVICE_ATTR(trace_mode, S_IRUGO|S_IWUSR, trace_mode_show, trace_mode_store);
 
 static int etm_probe(struct amba_device *dev, const struct amba_id *id)
 {
@@ -568,17 +563,16 @@ static int etm_probe(struct amba_device *dev, const struct amba_id *id)
 	etm_writel(t, 0x440, ETMR_CTRL);
 	etm_lock(t);
 
-	ret = sysfs_create_file(&dev->dev.kobj,
-			&trace_running_attr.attr);
+	ret = device_create_file(&dev->dev, &dev_attr_trace_running);
 	if (ret)
 		goto out_unmap;
 
 	/* failing to create any of these two is not fatal */
-	ret = sysfs_create_file(&dev->dev.kobj, &trace_info_attr.attr);
+	ret = device_create_file(&dev->dev, &dev_attr_trace_info);
 	if (ret)
 		dev_dbg(&dev->dev, "Failed to create trace_info in sysfs\n");
 
-	ret = sysfs_create_file(&dev->dev.kobj, &trace_mode_attr.attr);
+	ret = device_create_file(&dev->dev, &dev_attr_trace_mode);
 	if (ret)
 		dev_dbg(&dev->dev, "Failed to create trace_mode in sysfs\n");
 
@@ -608,9 +602,9 @@ static int etm_remove(struct amba_device *dev)
 
 	amba_release_regions(dev);
 
-	sysfs_remove_file(&dev->dev.kobj, &trace_running_attr.attr);
-	sysfs_remove_file(&dev->dev.kobj, &trace_info_attr.attr);
-	sysfs_remove_file(&dev->dev.kobj, &trace_mode_attr.attr);
+	device_remove_file(&dev->dev, &dev_attr_trace_running);
+	device_remove_file(&dev->dev, &dev_attr_trace_info);
+	device_remove_file(&dev->dev, &dev_attr_trace_mode);
 
 	return 0;
 }
Signature · 1 line
1.8.5.2
#2 lore raw

PATCH v2 2/6 ARM CoreSight: ETM: Rename 'comparator' to 'address comparator'

In reply to Adrien Vergé

Since there are different types of comparators, and other kinds will be used (such as Context ID comparators), rename them properly.

---
 arch/arm/include/asm/hardware/coresight.h |  4 ++--
 arch/arm/kernel/etm.c                     | 19 ++++++++++---------
 2 files changed, 12 insertions(+), 11 deletions(-)
arch/arm/include/asm/hardware/coresight.h +2 -2
index ad774f3..8c50cf6 100644
@@ -95,8 +95,8 @@
 #define ETMAAT_NSONLY		(1 << 10)
 #define ETMAAT_SONLY		(2 << 10)
 
-#define ETMR_COMP_VAL(x)	(0x40 + (x) * 4)
-#define ETMR_COMP_ACC_TYPE(x)	(0x80 + (x) * 4)
+#define ETMR_ADDRCOMP_VAL(x)	(0x40 + (x) * 4)
+#define ETMR_ADDRCOMP_ACC_TYPE(x)	(0x80 + (x) * 4)
 
 /* ETM status register, "ETM Architecture", 3.3.2 */
 #define ETMR_STATUS		(0x10)
arch/arm/kernel/etm.c +10 -9
index 2b1a307..7f7a0ee 100644
@@ -39,7 +39,7 @@ struct tracectx {
 	void __iomem	*etb_regs;
 	void __iomem	*etm_regs;
 	unsigned long	flags;
-	int		ncmppairs;
+	int		naddrcmppairs;
 	int		etm_portsz;
 	struct device	*dev;
 	struct clk	*emu_clk;
@@ -59,7 +59,7 @@ static int etm_setup_address_range(struct tracectx *t, int n,
 	u32 flags = ETMAAT_ARM | ETMAAT_IGNCONTEXTID | ETMAAT_NSONLY | \
 		    ETMAAT_NOVALCMP;
 
-	if (n < 1 || n > t->ncmppairs)
+	if (n < 1 || n > t->naddrcmppairs)
 		return -EINVAL;
 
 	/* comparators and ranges are numbered starting with 1 as opposed
@@ -72,12 +72,12 @@ static int etm_setup_address_range(struct tracectx *t, int n,
 		flags |= ETMAAT_IEXEC;
 
 	/* first comparator for the range */
-	etm_writel(t, flags, ETMR_COMP_ACC_TYPE(n * 2));
-	etm_writel(t, start, ETMR_COMP_VAL(n * 2));
+	etm_writel(t, flags, ETMR_ADDRCOMP_ACC_TYPE(n * 2));
+	etm_writel(t, start, ETMR_ADDRCOMP_VAL(n * 2));
 
 	/* second comparator is right next to it */
-	etm_writel(t, flags, ETMR_COMP_ACC_TYPE(n * 2 + 1));
-	etm_writel(t, end, ETMR_COMP_VAL(n * 2 + 1));
+	etm_writel(t, flags, ETMR_ADDRCOMP_ACC_TYPE(n * 2 + 1));
+	etm_writel(t, end, ETMR_ADDRCOMP_VAL(n * 2 + 1));
 
 	flags = exclude ? ETMTE_INCLEXCL : 0;
 	etm_writel(t, flags | (1 << n), ETMR_TRACEENCTRL);
@@ -475,7 +475,8 @@ static ssize_t trace_info_show(struct device *dev,
 	etm_st = etm_readl(&tracer, ETMR_STATUS);
 	etm_lock(&tracer);
 
-	return sprintf(buf, "Trace buffer len: %d\nComparator pairs: %d\n"
+	return sprintf(buf, "Trace buffer len: %d\n"
+			"Addr comparator pairs: %d\n"
 			"ETBR_WRITEADDR:\t%08x\n"
 			"ETBR_READADDR:\t%08x\n"
 			"ETBR_STATUS:\t%08x\n"
@@ -483,7 +484,7 @@ static ssize_t trace_info_show(struct device *dev,
 			"ETMR_CTRL:\t%08x\n"
 			"ETMR_STATUS:\t%08x\n",
 			datalen,
-			tracer.ncmppairs,
+			tracer.naddrcmppairs,
 			etb_wa,
 			etb_ra,
 			etb_st,
@@ -559,7 +560,7 @@ static int etm_probe(struct amba_device *dev, const struct amba_id *id)
 	/* dummy first read */
 	(void)etm_readl(&tracer, ETMMR_OSSRR);
 
-	t->ncmppairs = etm_readl(t, ETMR_CONFCODE) & 0xf;
+	t->naddrcmppairs = etm_readl(t, ETMR_CONFCODE) & 0xf;
 	etm_writel(t, 0x440, ETMR_CTRL);
 	etm_lock(t);
 
Signature · 1 line
1.8.5.2
#3 lore raw

PATCH v2 3/6 ARM CoreSight: ETM: Add address control support

In reply to Adrien Vergé

In the same manner as for enabling tracing, an entry is created in sysfs to set the address range that triggers tracing.

---
 arch/arm/kernel/etm.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 49 insertions(+), 3 deletions(-)
arch/arm/kernel/etm.c +49 -3
index 7f7a0ee..4442e5c 100644
@@ -44,6 +44,8 @@ struct tracectx {
 	struct device	*dev;
 	struct clk	*emu_clk;
 	struct mutex	mutex;
+	unsigned long	addrrange_start;
+	unsigned long	addrrange_end;
 };
 
 static struct tracectx tracer;
@@ -53,6 +55,13 @@ static inline bool trace_isrunning(struct tracectx *t)
 	return !!(t->flags & TRACER_RUNNING);
 }
 
+/*
+ * Setups ETM to trace only when:
+ *   - address between start and end
+ *     or address not between start and end (if exclude)
+ *   - trace executed instructions
+ *     or trace loads and stores (if data)
+ */
 static int etm_setup_address_range(struct tracectx *t, int n,
 		unsigned long start, unsigned long end, int exclude, int data)
 {
@@ -115,8 +124,8 @@ static int trace_start(struct tracectx *t)
 		return -EFAULT;
 	}
 
-	etm_setup_address_range(t, 1, (unsigned long)_stext,
-			(unsigned long)_etext, 0, 0);
+	etm_setup_address_range(t, 1, t->addrrange_start, t->addrrange_end,
+				0, 0);
 	etm_writel(t, 0, ETMR_TRACEENCTRL2);
 	etm_writel(t, 0, ETMR_TRACESSCTRL);
 	etm_writel(t, 0x6f, ETMR_TRACEENEVT);
@@ -527,6 +536,36 @@ static ssize_t trace_mode_store(struct device *dev,
 
 DEVICE_ATTR(trace_mode, S_IRUGO|S_IWUSR, trace_mode_show, trace_mode_store);
 
+static ssize_t trace_addrrange_show(struct device *dev,
+				    struct device_attribute *attr, char *buf)
+{
+	return sprintf(buf, "%08lx - %08lx\n", tracer.addrrange_start,
+		       tracer.addrrange_end);
+}
+
+static ssize_t trace_addrrange_store(struct device *dev,
+				     struct device_attribute *attr,
+				     const char *buf, size_t n)
+{
+	unsigned long start, end;
+
+	if (tracer.flags & TRACER_RUNNING)
+		return -EBUSY;
+
+	if (sscanf(buf, "%08lx - %08lx", &start, &end) != 2)
+		return -EINVAL;
+
+	mutex_lock(&tracer.mutex);
+	tracer.addrrange_start = start;
+	tracer.addrrange_end = end;
+	mutex_unlock(&tracer.mutex);
+
+	return n;
+}
+
+DEVICE_ATTR(trace_addrrange, S_IRUGO|S_IWUSR,
+	    trace_addrrange_show, trace_addrrange_store);
+
 static int etm_probe(struct amba_device *dev, const struct amba_id *id)
 {
 	struct tracectx *t = &tracer;
@@ -554,6 +593,8 @@ static int etm_probe(struct amba_device *dev, const struct amba_id *id)
 	t->dev = &dev->dev;
 	t->flags = TRACER_CYCLE_ACC;
 	t->etm_portsz = 1;
+	t->addrrange_start = (unsigned long) _stext;
+	t->addrrange_end = (unsigned long) _etext;
 
 	etm_unlock(t);
 	(void)etm_readl(t, ETMMR_PDSR);
@@ -568,7 +609,7 @@ static int etm_probe(struct amba_device *dev, const struct amba_id *id)
 	if (ret)
 		goto out_unmap;
 
-	/* failing to create any of these two is not fatal */
+	/* failing to create any of these three is not fatal */
 	ret = device_create_file(&dev->dev, &dev_attr_trace_info);
 	if (ret)
 		dev_dbg(&dev->dev, "Failed to create trace_info in sysfs\n");
@@ -577,6 +618,10 @@ static int etm_probe(struct amba_device *dev, const struct amba_id *id)
 	if (ret)
 		dev_dbg(&dev->dev, "Failed to create trace_mode in sysfs\n");
 
+	ret = device_create_file(&dev->dev, &dev_attr_trace_addrrange);
+	if (ret)
+		dev_dbg(&dev->dev, "Failed to create trace_addrrange in sysfs\n");
+
 	dev_dbg(t->dev, "ETM AMBA driver initialized.\n");
 
 out:
@@ -606,6 +651,7 @@ static int etm_remove(struct amba_device *dev)
 	device_remove_file(&dev->dev, &dev_attr_trace_running);
 	device_remove_file(&dev->dev, &dev_attr_trace_info);
 	device_remove_file(&dev->dev, &dev_attr_trace_mode);
+	device_remove_file(&dev->dev, &dev_attr_trace_addrrange);
 
 	return 0;
 }
Signature · 1 line
1.8.5.2
#4 lore raw

PATCH v2 4/6 ARM: Make PID_IN_CONTEXTIDR incompatible with PID_NS

In reply to Adrien Vergé

When using namespaces, different processes can have the same PID. It makes no sense to store a PID value in the Context ID register to track a specific process, when others share the same value.

Consequently, PID_IN_CONTEXTIDR (which is used for tracing and debugging processes) should not be compatible with PID_NS.

---
 arch/arm/Kconfig.debug   | 2 +-
 arch/arm64/Kconfig.debug | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
arch/arm/Kconfig.debug +1 -1
index 5765abf..ed46748 100644
@@ -1143,7 +1143,7 @@ config ARM_KPROBES_TEST
 
 config PID_IN_CONTEXTIDR
 	bool "Write the current PID to the CONTEXTIDR register"
-	depends on CPU_COPY_V6
+	depends on CPU_COPY_V6 && !PID_NS
 	help
 	  Enabling this option causes the kernel to write the current PID to
 	  the PROCID field of the CONTEXTIDR register, at the expense of some
arch/arm64/Kconfig.debug +1 -0
index 835c559..06b2633b 100644
@@ -17,6 +17,7 @@ config EARLY_PRINTK
 
 config PID_IN_CONTEXTIDR
 	bool "Write the current PID to the CONTEXTIDR register"
+	depends on !PID_NS
 	help
 	  Enabling this option causes the kernel to write the current PID to
 	  the CONTEXTIDR register, at the expense of some additional
Signature · 1 line
1.8.5.2
#5 lore raw

Re: [PATCH V2 4/6] ARM: Make PID_IN_CONTEXTIDR incompatible with PID_NS

Quoted 31 lines · Adrien Verg?

When using namespaces, different processes can have the same PID. It makes no sense to store a PID value in the Context ID register to track a specific process, when others share the same value.

Consequently, PID_IN_CONTEXTIDR (which is used for tracing and debugging processes) should not be compatible with PID_NS.

---
 arch/arm/Kconfig.debug   | 2 +-
 arch/arm64/Kconfig.debug | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
arch/arm/Kconfig.debug +1 -1
index 5765abf..ed46748 100644
@@ -1143,7 +1143,7 @@ config ARM_KPROBES_TEST
 
 config PID_IN_CONTEXTIDR
 	bool "Write the current PID to the CONTEXTIDR register"
-	depends on CPU_COPY_V6
+	depends on CPU_COPY_V6 && !PID_NS
 	help
 	  Enabling this option causes the kernel to write the current PID to
 	  the PROCID field of the CONTEXTIDR register, at the expense of some
arch/arm64/Kconfig.debug +0 -0
index 835c559..06b2633b 100644

arch/arm64/Kconfig.debug config EARLY_PRINTK · line 23

Quoted 7 lines
arch/arm64/Kconfig.debug +1 -0
@@ -17,6 +17,7 @@ config EARLY_PRINTK
 
 config PID_IN_CONTEXTIDR
 	bool "Write the current PID to the CONTEXTIDR register"
+	depends on !PID_NS
 	help
 	  Enabling this option causes the kernel to write the current PID to
 	  the CONTEXTIDR register, at the expense of some additional

Are you sure about this? The value we write is actually task_pid_nr, which I believe to be globally unique.

Will

#6 lore raw

Re: [PATCH V2 4/6] ARM: Make PID_IN_CONTEXTIDR incompatible with PID_NS

2014/1/24 Will Deacon <[email protected]>:

Quoted 2 lines

Are you sure about this? The value we write is actually task_pid_nr, which I believe to be globally unique.

You are right: the task_pid_nr is unique in the system. However when using namespaces, the so called "PID" is the virtual number that processes in different namespaces can share.

This PID is the one visible by user-space tasks, in particular user-space tracers and debuggers. These programs would expect to find the PID of the traced process in the Context ID reg, while it is not. I think it is better to remove confusion by making PID_IN_CONTEXTIDR and PID_NS incompatible.

What do you think?

#7 lore raw

Re: [PATCH V2 4/6] ARM: Make PID_IN_CONTEXTIDR incompatible with PID_NS

Quoted 8 lines · Adrien Verg?

2014/1/24 Will Deacon <[email protected]>:

Quoted 2 lines

Are you sure about this? The value we write is actually task_pid_nr, which I believe to be globally unique.

You are right: the task_pid_nr is unique in the system. However when using namespaces, the so called "PID" is the virtual number that processes in different namespaces can share.

Quoted 7 lines

This PID is the one visible by user-space tasks, in particular user-space tracers and debuggers. These programs would expect to find the PID of the traced process in the Context ID reg, while it is not. I think it is better to remove confusion by making PID_IN_CONTEXTIDR and PID_NS incompatible.

What do you think?

I think I'd rather have the global ID than disable a potentially useful feature, especially since this is likely to be consumed by external trace tools as opposed to user-space tasks.

Will

#8 lore raw

Re: [PATCH V2 4/6] ARM: Make PID_IN_CONTEXTIDR incompatible with PID_NS

Quoted 15 lines · Will Deacon
Quoted 14 lines · Adrien Verg?

2014/1/24 Will Deacon <[email protected]>:

Quoted 2 lines

Are you sure about this? The value we write is actually task_pid_nr, which I believe to be globally unique.

You are right: the task_pid_nr is unique in the system. However when using namespaces, the so called "PID" is the virtual number that processes in different namespaces can share.

This PID is the one visible by user-space tasks, in particular user-space tracers and debuggers. These programs would expect to find the PID of the traced process in the Context ID reg, while it is not. I think it is better to remove confusion by making PID_IN_CONTEXTIDR and PID_NS incompatible.

Quoted 5 lines
Quoted 1 line

What do you think?

I think I'd rather have the global ID than disable a potentially useful feature, especially since this is likely to be consumed by external trace tools as opposed to user-space tasks.

We've discussed before that the ARM architecture doesn't say what should be written to the CONTEXTIDR, so it's up to us to decide. Will has a use case where the global PID is useful. Adrien's patches present a use case where I think the virtual PID would be useful. I've done work in the past where writing the process group ID was useful. Would it be reasonable to make what's written to the CONTEXTIDR run-time configurable? If so, what would be the best interface for configuring it?

Thanks,
Christopher

Signature · 3 lines
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by the Linux Foundation.
#9 lore raw

Re: [PATCH V2 4/6] ARM: Make PID_IN_CONTEXTIDR incompatible with PID_NS

Quoted 22 lines · Christopher Covington
Quoted 15 lines · Will Deacon
Quoted 14 lines · Adrien Verg?

2014/1/24 Will Deacon <[email protected]>:

Quoted 2 lines

Are you sure about this? The value we write is actually task_pid_nr, which I believe to be globally unique.

You are right: the task_pid_nr is unique in the system. However when using namespaces, the so called "PID" is the virtual number that processes in different namespaces can share.

This PID is the one visible by user-space tasks, in particular user-space tracers and debuggers. These programs would expect to find the PID of the traced process in the Context ID reg, while it is not. I think it is better to remove confusion by making PID_IN_CONTEXTIDR and PID_NS incompatible.

Quoted 5 lines
Quoted 1 line

What do you think?

I think I'd rather have the global ID than disable a potentially useful feature, especially since this is likely to be consumed by external trace tools as opposed to user-space tasks.

Quoted 7 lines

We've discussed before that the ARM architecture doesn't say what should be written to the CONTEXTIDR, so it's up to us to decide. Will has a use case where the global PID is useful. Adrien's patches present a use case where I think the virtual PID would be useful. I've done work in the past where writing the process group ID was useful. Would it be reasonable to make what's written to the CONTEXTIDR run-time configurable? If so, what would be the best interface for configuring it?

D'oh, I mixed things up. For ETM to work it can only use global PID's in the CONTEXTIDR.

Christopher

Signature · 3 lines
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by the Linux Foundation.
#10 lore raw

Re: [PATCH V2 4/6] ARM: Make PID_IN_CONTEXTIDR incompatible with PID_NS

In reply to Christopher Covington

2014/1/24 Will Deacon <[email protected]>:

Quoted 3 lines

I think I'd rather have the global ID than disable a potentially useful feature, especially since this is likely to be consumed by external trace tools as opposed to user-space tasks.

I understand.

2014/1/24 Christopher Covington <[email protected]>:

Quoted 3 lines

Would it be reasonable to make what's
written to the CONTEXTIDR run-time configurable? If so, what would be the best interface for configuring it?

This is an interesting option.

An other option would be to keep the global PID in the Context ID register, and rely on kernel support to translate virtual PID to global PID when needed. Then, it would be possible to select a task to trace via its PID, by asking the kernel to write its global ID to the Context ID comparator.

#11 lore raw

PATCH v2 5/6 ARM CoreSight: ETM: Add PID control support

In reply to Adrien Vergé

In the same manner as for enabling tracing, an entry is created in sysfs to set the PID that triggers tracing. This change is effective only if CONFIG_PID_IN_CONTEXTIDR is set, and thus is not compatible with PID namespaces.

---
 arch/arm/include/asm/hardware/coresight.h |  5 ++
 arch/arm/kernel/etm.c                     | 82 ++++++++++++++++++++++++++++---
 2 files changed, 80 insertions(+), 7 deletions(-)
arch/arm/include/asm/hardware/coresight.h +5 -0
index 8c50cf6..2051af0 100644
@@ -98,6 +98,11 @@
 #define ETMR_ADDRCOMP_VAL(x)	(0x40 + (x) * 4)
 #define ETMR_ADDRCOMP_ACC_TYPE(x)	(0x80 + (x) * 4)
 
+#ifdef CONFIG_PID_IN_CONTEXTIDR
+#define ETMR_CTXIDCOMP_VAL(x)	(0x1b0 + (x) * 4)
+#define ETMR_CTXIDCOMP_MASK	(0x1bc)
+#endif
+
 /* ETM status register, "ETM Architecture", 3.3.2 */
 #define ETMR_STATUS		(0x10)
 #define ETMST_OVERFLOW		BIT(0)
arch/arm/kernel/etm.c +75 -7

164 lines not on this page · raw message

Signature · 1 line
1.8.5.2
#12 lore raw

PATCH v2 6/6 ARM CoreSight: ETM: Allocate a trace buffer only when necessary

In reply to Adrien Vergé

Some user applications try to retrieve trace data often, there is no need to call vmalloc() when there is 0 byte to fetch.

---
 arch/arm/kernel/etm.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
arch/arm/kernel/etm.c +8 -5
index 54b5128..bc97240 100644
@@ -309,7 +309,7 @@ static ssize_t etb_read(struct file *file, char __user *data,
 	long length;
 	struct tracectx *t = file->private_data;
 	u32 first = 0;
-	u32 *buf;
+	u32 *buf = NULL;
 
 	mutex_lock(&t->mutex);
 
@@ -327,12 +327,14 @@ static ssize_t etb_read(struct file *file, char __user *data,
 	etb_writel(t, first, ETBR_READADDR);
 
 	length = min(total * 4, (int)len);
-	buf = vmalloc(length);
+	if (length != 0)
+		buf = vmalloc(length);
 
 	dev_dbg(t->dev, "ETB buffer length: %d\n", total);
 	dev_dbg(t->dev, "ETB status reg: %x\n", etb_readl(t, ETBR_STATUS));
-	for (i = 0; i < length / 4; i++)
-		buf[i] = etb_readl(t, ETBR_READMEM);
+	if (buf)
+		for (i = 0; i < length / 4; i++)
+			buf[i] = etb_readl(t, ETBR_READMEM);
 
 	/* the only way to deassert overflow bit in ETB status is this */
 	etb_writel(t, 1, ETBR_CTRL);
@@ -345,7 +347,8 @@ static ssize_t etb_read(struct file *file, char __user *data,
 	etb_lock(t);
 
 	length -= copy_to_user(data, buf, length);
-	vfree(buf);
+	if (buf)
+		vfree(buf);
 
 out:
 	mutex_unlock(&t->mutex);
Signature · 1 line
1.8.5.2