All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 0/1] RISC-V: Create unique identification for SoC PMU
@ 2022-06-19 11:11 ` Nikita Shubin
  0 siblings, 0 replies; 30+ messages in thread
From: Nikita Shubin @ 2022-06-19 11:11 UTC (permalink / raw)
  To: Atish Patra, Will Deacon, Sunil V L
  Cc: João Mário Domingos, linux, Nikita Shubin,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Anup Patel,
	Mark Rutland, Geert Uytterhoeven, linux-riscv, linux-kernel,
	linux-arm-kernel

From: Nikita Shubin <n.shubin@yadro.com>

Provide RISC-V SBI PMU id to distinguish different cores or SoCs via
"devices/platform/riscv-pmu/id" sysfs entry.

As per Will Deacon recomendation i am splitting the original series in parts,
first one is to provide a reasonable id for RISC-V SBI PMU. Events for Unmatched,
general RISCV and SBI Firmware bindings will be added later.

We can provide the PMU id as is marchid, mimpid, mvendorid as string, separated by a coma:

cat /sys/devices/platform/riscv-pmu/id 
0x70032,0x70032,0x0

In this case we are providing them as is as given by SBI extension.

Also i've added a string allocated on probe with pmuid, to avoid excess ecalls.

Atish would do you think about this ?

Sunil, thank you for reporting issue with 32-bit, i decided to make another approuch to problem.

Link: https://patchwork.kernel.org/project/linux-riscv/list/?series=648017
---
v3->v4:
- split series
- fix DEVICE_ATTR to use octal permissions
- use string for pmuid, instead of incoding some magical numbers
---
Nikita Shubin (1):
  RISC-V: Create unique identification for SoC PMU

 drivers/perf/riscv_pmu_sbi.c   | 41 ++++++++++++++++++++++++++++++++++
 include/linux/perf/riscv_pmu.h |  1 +
 2 files changed, 42 insertions(+)

-- 
2.35.1


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH v4 0/1] RISC-V: Create unique identification for SoC PMU
@ 2022-06-19 11:11 ` Nikita Shubin
  0 siblings, 0 replies; 30+ messages in thread
From: Nikita Shubin @ 2022-06-19 11:11 UTC (permalink / raw)
  To: Atish Patra, Will Deacon, Sunil V L
  Cc: João Mário Domingos, linux, Nikita Shubin,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Anup Patel,
	Mark Rutland, Geert Uytterhoeven, linux-riscv, linux-kernel,
	linux-arm-kernel

From: Nikita Shubin <n.shubin@yadro.com>

Provide RISC-V SBI PMU id to distinguish different cores or SoCs via
"devices/platform/riscv-pmu/id" sysfs entry.

As per Will Deacon recomendation i am splitting the original series in parts,
first one is to provide a reasonable id for RISC-V SBI PMU. Events for Unmatched,
general RISCV and SBI Firmware bindings will be added later.

We can provide the PMU id as is marchid, mimpid, mvendorid as string, separated by a coma:

cat /sys/devices/platform/riscv-pmu/id 
0x70032,0x70032,0x0

In this case we are providing them as is as given by SBI extension.

Also i've added a string allocated on probe with pmuid, to avoid excess ecalls.

Atish would do you think about this ?

Sunil, thank you for reporting issue with 32-bit, i decided to make another approuch to problem.

Link: https://patchwork.kernel.org/project/linux-riscv/list/?series=648017
---
v3->v4:
- split series
- fix DEVICE_ATTR to use octal permissions
- use string for pmuid, instead of incoding some magical numbers
---
Nikita Shubin (1):
  RISC-V: Create unique identification for SoC PMU

 drivers/perf/riscv_pmu_sbi.c   | 41 ++++++++++++++++++++++++++++++++++
 include/linux/perf/riscv_pmu.h |  1 +
 2 files changed, 42 insertions(+)

-- 
2.35.1


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH v4 0/1] RISC-V: Create unique identification for SoC PMU
@ 2022-06-19 11:11 ` Nikita Shubin
  0 siblings, 0 replies; 30+ messages in thread
From: Nikita Shubin @ 2022-06-19 11:11 UTC (permalink / raw)
  To: Atish Patra, Will Deacon, Sunil V L
  Cc: João Mário Domingos, linux, Nikita Shubin,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Anup Patel,
	Mark Rutland, Geert Uytterhoeven, linux-riscv, linux-kernel,
	linux-arm-kernel

From: Nikita Shubin <n.shubin@yadro.com>

Provide RISC-V SBI PMU id to distinguish different cores or SoCs via
"devices/platform/riscv-pmu/id" sysfs entry.

As per Will Deacon recomendation i am splitting the original series in parts,
first one is to provide a reasonable id for RISC-V SBI PMU. Events for Unmatched,
general RISCV and SBI Firmware bindings will be added later.

We can provide the PMU id as is marchid, mimpid, mvendorid as string, separated by a coma:

cat /sys/devices/platform/riscv-pmu/id 
0x70032,0x70032,0x0

In this case we are providing them as is as given by SBI extension.

Also i've added a string allocated on probe with pmuid, to avoid excess ecalls.

Atish would do you think about this ?

Sunil, thank you for reporting issue with 32-bit, i decided to make another approuch to problem.

Link: https://patchwork.kernel.org/project/linux-riscv/list/?series=648017
---
v3->v4:
- split series
- fix DEVICE_ATTR to use octal permissions
- use string for pmuid, instead of incoding some magical numbers
---
Nikita Shubin (1):
  RISC-V: Create unique identification for SoC PMU

 drivers/perf/riscv_pmu_sbi.c   | 41 ++++++++++++++++++++++++++++++++++
 include/linux/perf/riscv_pmu.h |  1 +
 2 files changed, 42 insertions(+)

-- 
2.35.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH v4 1/1] RISC-V: Create unique identification for SoC PMU
  2022-06-19 11:11 ` Nikita Shubin
  (?)
@ 2022-06-19 11:11   ` Nikita Shubin
  -1 siblings, 0 replies; 30+ messages in thread
From: Nikita Shubin @ 2022-06-19 11:11 UTC (permalink / raw)
  To: Atish Patra, Will Deacon, Sunil V L
  Cc: João Mário Domingos, linux, Nikita Shubin,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Anup Patel,
	Mark Rutland, Geert Uytterhoeven, linux-riscv, linux-kernel,
	linux-arm-kernel

From: Nikita Shubin <n.shubin@yadro.com>

Provide RISC-V SBI PMU id to distinguish different cores or SoCs via
"devices/platform/riscv-pmu/id" sysfs entry.

The identification is generated as string of marchid, mimpid, mvendorid
in hex format separated by coma - "0x70032,0x70032,0x0".

The CSRs are detailed in the RISC-V privileged spec [1].
[1] https://github.com/riscv/riscv-isa-manual

Inspired-by: João Mário Domingos <joao.mario@tecnico.ulisboa.pt>
Signed-off-by: Nikita Shubin <n.shubin@yadro.com>
---
v3->v4:
- use string for pmuid
- rename pmu_sbi_id_show to id_show
- fix error print message in id_show
- fix DEVICE_ATTR to use octal permissions
---
 arch/riscv/kernel/sbi.c        |  3 +++
 drivers/perf/riscv_pmu_sbi.c   | 41 ++++++++++++++++++++++++++++++++++
 include/linux/perf/riscv_pmu.h |  1 +
 3 files changed, 45 insertions(+)

diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c
index 775d3322b422..50dd9b6ecc9e 100644
--- a/arch/riscv/kernel/sbi.c
+++ b/arch/riscv/kernel/sbi.c
@@ -627,16 +627,19 @@ long sbi_get_mvendorid(void)
 {
 	return __sbi_base_ecall(SBI_EXT_BASE_GET_MVENDORID);
 }
+EXPORT_SYMBOL(sbi_get_mvendorid);
 
 long sbi_get_marchid(void)
 {
 	return __sbi_base_ecall(SBI_EXT_BASE_GET_MARCHID);
 }
+EXPORT_SYMBOL(sbi_get_marchid);
 
 long sbi_get_mimpid(void)
 {
 	return __sbi_base_ecall(SBI_EXT_BASE_GET_MIMPID);
 }
+EXPORT_SYMBOL(sbi_get_mimpid);
 
 static void sbi_send_cpumask_ipi(const struct cpumask *target)
 {
diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c
index dca3537a8dcc..be812f855617 100644
--- a/drivers/perf/riscv_pmu_sbi.c
+++ b/drivers/perf/riscv_pmu_sbi.c
@@ -693,6 +693,28 @@ static int pmu_sbi_setup_irqs(struct riscv_pmu *pmu, struct platform_device *pde
 	return 0;
 }
 
+static ssize_t id_show(struct device *dev,
+				struct device_attribute *attr, char *buf)
+{
+	int len;
+	struct riscv_pmu *pmu = container_of(dev_get_drvdata(dev), struct riscv_pmu, pmu);
+
+	len = sprintf(buf, "%s\n", pmu->pmuid);
+	if (len <= 0)
+		dev_err(dev, "invalid sprintf len: %d\n", len);
+
+	return len;
+}
+
+static DEVICE_ATTR(id, 0644, id_show, NULL);
+
+static struct attribute *pmu_sbi_attrs[] = {
+	&dev_attr_id.attr,
+	NULL
+};
+
+ATTRIBUTE_GROUPS(pmu_sbi);
+
 static int pmu_sbi_device_probe(struct platform_device *pdev)
 {
 	struct riscv_pmu *pmu = NULL;
@@ -714,6 +736,14 @@ static int pmu_sbi_device_probe(struct platform_device *pdev)
 	if (pmu_sbi_get_ctrinfo(num_counters))
 		goto out_free;
 
+	/* fill pmuid */
+	pmu->pmuid = kasprintf(GFP_KERNEL, "0x%lx,0x%lx,0x%lx",
+			       sbi_get_marchid(),
+			       sbi_get_mimpid(),
+			       sbi_get_mvendorid());
+	if (!pmu->pmuid)
+		goto out_free_pmuid;
+
 	ret = pmu_sbi_setup_irqs(pmu, pdev);
 	if (ret < 0) {
 		pr_info("Perf sampling/filtering is not supported as sscof extension is not available\n");
@@ -739,8 +769,19 @@ static int pmu_sbi_device_probe(struct platform_device *pdev)
 		return ret;
 	}
 
+	ret = sysfs_create_group(&pdev->dev.kobj, &pmu_sbi_group);
+	if (ret) {
+		dev_err(&pdev->dev, "sysfs creation failed\n");
+		return ret;
+	}
+
+	pdev->dev.groups = pmu_sbi_groups;
+	dev_set_drvdata(&pdev->dev, pmu);
+
 	return 0;
 
+out_free_pmuid:
+	kfree(pmu->pmuid);
 out_free:
 	kfree(pmu);
 	return ret;
diff --git a/include/linux/perf/riscv_pmu.h b/include/linux/perf/riscv_pmu.h
index 46f9b6fe306e..cf3557b77fb8 100644
--- a/include/linux/perf/riscv_pmu.h
+++ b/include/linux/perf/riscv_pmu.h
@@ -42,6 +42,7 @@ struct cpu_hw_events {
 struct riscv_pmu {
 	struct pmu	pmu;
 	char		*name;
+	char		*pmuid;
 
 	irqreturn_t	(*handle_irq)(int irq_num, void *dev);
 
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH v4 1/1] RISC-V: Create unique identification for SoC PMU
@ 2022-06-19 11:11   ` Nikita Shubin
  0 siblings, 0 replies; 30+ messages in thread
From: Nikita Shubin @ 2022-06-19 11:11 UTC (permalink / raw)
  To: Atish Patra, Will Deacon, Sunil V L
  Cc: João Mário Domingos, linux, Nikita Shubin,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Anup Patel,
	Mark Rutland, Geert Uytterhoeven, linux-riscv, linux-kernel,
	linux-arm-kernel

From: Nikita Shubin <n.shubin@yadro.com>

Provide RISC-V SBI PMU id to distinguish different cores or SoCs via
"devices/platform/riscv-pmu/id" sysfs entry.

The identification is generated as string of marchid, mimpid, mvendorid
in hex format separated by coma - "0x70032,0x70032,0x0".

The CSRs are detailed in the RISC-V privileged spec [1].
[1] https://github.com/riscv/riscv-isa-manual

Inspired-by: João Mário Domingos <joao.mario@tecnico.ulisboa.pt>
Signed-off-by: Nikita Shubin <n.shubin@yadro.com>
---
v3->v4:
- use string for pmuid
- rename pmu_sbi_id_show to id_show
- fix error print message in id_show
- fix DEVICE_ATTR to use octal permissions
---
 arch/riscv/kernel/sbi.c        |  3 +++
 drivers/perf/riscv_pmu_sbi.c   | 41 ++++++++++++++++++++++++++++++++++
 include/linux/perf/riscv_pmu.h |  1 +
 3 files changed, 45 insertions(+)

diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c
index 775d3322b422..50dd9b6ecc9e 100644
--- a/arch/riscv/kernel/sbi.c
+++ b/arch/riscv/kernel/sbi.c
@@ -627,16 +627,19 @@ long sbi_get_mvendorid(void)
 {
 	return __sbi_base_ecall(SBI_EXT_BASE_GET_MVENDORID);
 }
+EXPORT_SYMBOL(sbi_get_mvendorid);
 
 long sbi_get_marchid(void)
 {
 	return __sbi_base_ecall(SBI_EXT_BASE_GET_MARCHID);
 }
+EXPORT_SYMBOL(sbi_get_marchid);
 
 long sbi_get_mimpid(void)
 {
 	return __sbi_base_ecall(SBI_EXT_BASE_GET_MIMPID);
 }
+EXPORT_SYMBOL(sbi_get_mimpid);
 
 static void sbi_send_cpumask_ipi(const struct cpumask *target)
 {
diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c
index dca3537a8dcc..be812f855617 100644
--- a/drivers/perf/riscv_pmu_sbi.c
+++ b/drivers/perf/riscv_pmu_sbi.c
@@ -693,6 +693,28 @@ static int pmu_sbi_setup_irqs(struct riscv_pmu *pmu, struct platform_device *pde
 	return 0;
 }
 
+static ssize_t id_show(struct device *dev,
+				struct device_attribute *attr, char *buf)
+{
+	int len;
+	struct riscv_pmu *pmu = container_of(dev_get_drvdata(dev), struct riscv_pmu, pmu);
+
+	len = sprintf(buf, "%s\n", pmu->pmuid);
+	if (len <= 0)
+		dev_err(dev, "invalid sprintf len: %d\n", len);
+
+	return len;
+}
+
+static DEVICE_ATTR(id, 0644, id_show, NULL);
+
+static struct attribute *pmu_sbi_attrs[] = {
+	&dev_attr_id.attr,
+	NULL
+};
+
+ATTRIBUTE_GROUPS(pmu_sbi);
+
 static int pmu_sbi_device_probe(struct platform_device *pdev)
 {
 	struct riscv_pmu *pmu = NULL;
@@ -714,6 +736,14 @@ static int pmu_sbi_device_probe(struct platform_device *pdev)
 	if (pmu_sbi_get_ctrinfo(num_counters))
 		goto out_free;
 
+	/* fill pmuid */
+	pmu->pmuid = kasprintf(GFP_KERNEL, "0x%lx,0x%lx,0x%lx",
+			       sbi_get_marchid(),
+			       sbi_get_mimpid(),
+			       sbi_get_mvendorid());
+	if (!pmu->pmuid)
+		goto out_free_pmuid;
+
 	ret = pmu_sbi_setup_irqs(pmu, pdev);
 	if (ret < 0) {
 		pr_info("Perf sampling/filtering is not supported as sscof extension is not available\n");
@@ -739,8 +769,19 @@ static int pmu_sbi_device_probe(struct platform_device *pdev)
 		return ret;
 	}
 
+	ret = sysfs_create_group(&pdev->dev.kobj, &pmu_sbi_group);
+	if (ret) {
+		dev_err(&pdev->dev, "sysfs creation failed\n");
+		return ret;
+	}
+
+	pdev->dev.groups = pmu_sbi_groups;
+	dev_set_drvdata(&pdev->dev, pmu);
+
 	return 0;
 
+out_free_pmuid:
+	kfree(pmu->pmuid);
 out_free:
 	kfree(pmu);
 	return ret;
diff --git a/include/linux/perf/riscv_pmu.h b/include/linux/perf/riscv_pmu.h
index 46f9b6fe306e..cf3557b77fb8 100644
--- a/include/linux/perf/riscv_pmu.h
+++ b/include/linux/perf/riscv_pmu.h
@@ -42,6 +42,7 @@ struct cpu_hw_events {
 struct riscv_pmu {
 	struct pmu	pmu;
 	char		*name;
+	char		*pmuid;
 
 	irqreturn_t	(*handle_irq)(int irq_num, void *dev);
 
-- 
2.35.1


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH v4 1/1] RISC-V: Create unique identification for SoC PMU
@ 2022-06-19 11:11   ` Nikita Shubin
  0 siblings, 0 replies; 30+ messages in thread
From: Nikita Shubin @ 2022-06-19 11:11 UTC (permalink / raw)
  To: Atish Patra, Will Deacon, Sunil V L
  Cc: João Mário Domingos, linux, Nikita Shubin,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Anup Patel,
	Mark Rutland, Geert Uytterhoeven, linux-riscv, linux-kernel,
	linux-arm-kernel

From: Nikita Shubin <n.shubin@yadro.com>

Provide RISC-V SBI PMU id to distinguish different cores or SoCs via
"devices/platform/riscv-pmu/id" sysfs entry.

The identification is generated as string of marchid, mimpid, mvendorid
in hex format separated by coma - "0x70032,0x70032,0x0".

The CSRs are detailed in the RISC-V privileged spec [1].
[1] https://github.com/riscv/riscv-isa-manual

Inspired-by: João Mário Domingos <joao.mario@tecnico.ulisboa.pt>
Signed-off-by: Nikita Shubin <n.shubin@yadro.com>
---
v3->v4:
- use string for pmuid
- rename pmu_sbi_id_show to id_show
- fix error print message in id_show
- fix DEVICE_ATTR to use octal permissions
---
 arch/riscv/kernel/sbi.c        |  3 +++
 drivers/perf/riscv_pmu_sbi.c   | 41 ++++++++++++++++++++++++++++++++++
 include/linux/perf/riscv_pmu.h |  1 +
 3 files changed, 45 insertions(+)

diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c
index 775d3322b422..50dd9b6ecc9e 100644
--- a/arch/riscv/kernel/sbi.c
+++ b/arch/riscv/kernel/sbi.c
@@ -627,16 +627,19 @@ long sbi_get_mvendorid(void)
 {
 	return __sbi_base_ecall(SBI_EXT_BASE_GET_MVENDORID);
 }
+EXPORT_SYMBOL(sbi_get_mvendorid);
 
 long sbi_get_marchid(void)
 {
 	return __sbi_base_ecall(SBI_EXT_BASE_GET_MARCHID);
 }
+EXPORT_SYMBOL(sbi_get_marchid);
 
 long sbi_get_mimpid(void)
 {
 	return __sbi_base_ecall(SBI_EXT_BASE_GET_MIMPID);
 }
+EXPORT_SYMBOL(sbi_get_mimpid);
 
 static void sbi_send_cpumask_ipi(const struct cpumask *target)
 {
diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c
index dca3537a8dcc..be812f855617 100644
--- a/drivers/perf/riscv_pmu_sbi.c
+++ b/drivers/perf/riscv_pmu_sbi.c
@@ -693,6 +693,28 @@ static int pmu_sbi_setup_irqs(struct riscv_pmu *pmu, struct platform_device *pde
 	return 0;
 }
 
+static ssize_t id_show(struct device *dev,
+				struct device_attribute *attr, char *buf)
+{
+	int len;
+	struct riscv_pmu *pmu = container_of(dev_get_drvdata(dev), struct riscv_pmu, pmu);
+
+	len = sprintf(buf, "%s\n", pmu->pmuid);
+	if (len <= 0)
+		dev_err(dev, "invalid sprintf len: %d\n", len);
+
+	return len;
+}
+
+static DEVICE_ATTR(id, 0644, id_show, NULL);
+
+static struct attribute *pmu_sbi_attrs[] = {
+	&dev_attr_id.attr,
+	NULL
+};
+
+ATTRIBUTE_GROUPS(pmu_sbi);
+
 static int pmu_sbi_device_probe(struct platform_device *pdev)
 {
 	struct riscv_pmu *pmu = NULL;
@@ -714,6 +736,14 @@ static int pmu_sbi_device_probe(struct platform_device *pdev)
 	if (pmu_sbi_get_ctrinfo(num_counters))
 		goto out_free;
 
+	/* fill pmuid */
+	pmu->pmuid = kasprintf(GFP_KERNEL, "0x%lx,0x%lx,0x%lx",
+			       sbi_get_marchid(),
+			       sbi_get_mimpid(),
+			       sbi_get_mvendorid());
+	if (!pmu->pmuid)
+		goto out_free_pmuid;
+
 	ret = pmu_sbi_setup_irqs(pmu, pdev);
 	if (ret < 0) {
 		pr_info("Perf sampling/filtering is not supported as sscof extension is not available\n");
@@ -739,8 +769,19 @@ static int pmu_sbi_device_probe(struct platform_device *pdev)
 		return ret;
 	}
 
+	ret = sysfs_create_group(&pdev->dev.kobj, &pmu_sbi_group);
+	if (ret) {
+		dev_err(&pdev->dev, "sysfs creation failed\n");
+		return ret;
+	}
+
+	pdev->dev.groups = pmu_sbi_groups;
+	dev_set_drvdata(&pdev->dev, pmu);
+
 	return 0;
 
+out_free_pmuid:
+	kfree(pmu->pmuid);
 out_free:
 	kfree(pmu);
 	return ret;
diff --git a/include/linux/perf/riscv_pmu.h b/include/linux/perf/riscv_pmu.h
index 46f9b6fe306e..cf3557b77fb8 100644
--- a/include/linux/perf/riscv_pmu.h
+++ b/include/linux/perf/riscv_pmu.h
@@ -42,6 +42,7 @@ struct cpu_hw_events {
 struct riscv_pmu {
 	struct pmu	pmu;
 	char		*name;
+	char		*pmuid;
 
 	irqreturn_t	(*handle_irq)(int irq_num, void *dev);
 
-- 
2.35.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 30+ messages in thread

* Re: [PATCH v4 1/1] RISC-V: Create unique identification for SoC PMU
  2022-06-19 11:11   ` Nikita Shubin
  (?)
@ 2022-06-20  7:50     ` Geert Uytterhoeven
  -1 siblings, 0 replies; 30+ messages in thread
From: Geert Uytterhoeven @ 2022-06-20  7:50 UTC (permalink / raw)
  To: Nikita Shubin
  Cc: Atish Patra, Will Deacon, Sunil V L,
	João Mário Domingos, linux, Nikita Shubin,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Anup Patel,
	Mark Rutland, linux-riscv, Linux Kernel Mailing List, Linux ARM

Hi Nikita,

On Sun, Jun 19, 2022 at 1:11 PM Nikita Shubin <nikita.shubin@maquefel.me> wrote:
> From: Nikita Shubin <n.shubin@yadro.com>
>
> Provide RISC-V SBI PMU id to distinguish different cores or SoCs via
> "devices/platform/riscv-pmu/id" sysfs entry.
>
> The identification is generated as string of marchid, mimpid, mvendorid
> in hex format separated by coma - "0x70032,0x70032,0x0".
>
> The CSRs are detailed in the RISC-V privileged spec [1].
> [1] https://github.com/riscv/riscv-isa-manual
>
> Inspired-by: João Mário Domingos <joao.mario@tecnico.ulisboa.pt>
> Signed-off-by: Nikita Shubin <n.shubin@yadro.com>

Thanks for your patch!

> --- a/arch/riscv/kernel/sbi.c
> +++ b/arch/riscv/kernel/sbi.c

> --- a/drivers/perf/riscv_pmu_sbi.c
> +++ b/drivers/perf/riscv_pmu_sbi.c
> @@ -693,6 +693,28 @@ static int pmu_sbi_setup_irqs(struct riscv_pmu *pmu, struct platform_device *pde
>         return 0;
>  }
>
> +static ssize_t id_show(struct device *dev,
> +                               struct device_attribute *attr, char *buf)
> +{
> +       int len;
> +       struct riscv_pmu *pmu = container_of(dev_get_drvdata(dev), struct riscv_pmu, pmu);
> +
> +       len = sprintf(buf, "%s\n", pmu->pmuid);
> +       if (len <= 0)
> +               dev_err(dev, "invalid sprintf len: %d\n", len);

How can this fail?

Please use sysfs_emit() instead of sprintf(), and drop the error
message.

> +
> +       return len;
> +}

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v4 1/1] RISC-V: Create unique identification for SoC PMU
@ 2022-06-20  7:50     ` Geert Uytterhoeven
  0 siblings, 0 replies; 30+ messages in thread
From: Geert Uytterhoeven @ 2022-06-20  7:50 UTC (permalink / raw)
  To: Nikita Shubin
  Cc: Atish Patra, Will Deacon, Sunil V L,
	João Mário Domingos, linux, Nikita Shubin,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Anup Patel,
	Mark Rutland, linux-riscv, Linux Kernel Mailing List, Linux ARM

Hi Nikita,

On Sun, Jun 19, 2022 at 1:11 PM Nikita Shubin <nikita.shubin@maquefel.me> wrote:
> From: Nikita Shubin <n.shubin@yadro.com>
>
> Provide RISC-V SBI PMU id to distinguish different cores or SoCs via
> "devices/platform/riscv-pmu/id" sysfs entry.
>
> The identification is generated as string of marchid, mimpid, mvendorid
> in hex format separated by coma - "0x70032,0x70032,0x0".
>
> The CSRs are detailed in the RISC-V privileged spec [1].
> [1] https://github.com/riscv/riscv-isa-manual
>
> Inspired-by: João Mário Domingos <joao.mario@tecnico.ulisboa.pt>
> Signed-off-by: Nikita Shubin <n.shubin@yadro.com>

Thanks for your patch!

> --- a/arch/riscv/kernel/sbi.c
> +++ b/arch/riscv/kernel/sbi.c

> --- a/drivers/perf/riscv_pmu_sbi.c
> +++ b/drivers/perf/riscv_pmu_sbi.c
> @@ -693,6 +693,28 @@ static int pmu_sbi_setup_irqs(struct riscv_pmu *pmu, struct platform_device *pde
>         return 0;
>  }
>
> +static ssize_t id_show(struct device *dev,
> +                               struct device_attribute *attr, char *buf)
> +{
> +       int len;
> +       struct riscv_pmu *pmu = container_of(dev_get_drvdata(dev), struct riscv_pmu, pmu);
> +
> +       len = sprintf(buf, "%s\n", pmu->pmuid);
> +       if (len <= 0)
> +               dev_err(dev, "invalid sprintf len: %d\n", len);

How can this fail?

Please use sysfs_emit() instead of sprintf(), and drop the error
message.

> +
> +       return len;
> +}

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v4 1/1] RISC-V: Create unique identification for SoC PMU
@ 2022-06-20  7:50     ` Geert Uytterhoeven
  0 siblings, 0 replies; 30+ messages in thread
From: Geert Uytterhoeven @ 2022-06-20  7:50 UTC (permalink / raw)
  To: Nikita Shubin
  Cc: Atish Patra, Will Deacon, Sunil V L,
	João Mário Domingos, linux, Nikita Shubin,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Anup Patel,
	Mark Rutland, linux-riscv, Linux Kernel Mailing List, Linux ARM

Hi Nikita,

On Sun, Jun 19, 2022 at 1:11 PM Nikita Shubin <nikita.shubin@maquefel.me> wrote:
> From: Nikita Shubin <n.shubin@yadro.com>
>
> Provide RISC-V SBI PMU id to distinguish different cores or SoCs via
> "devices/platform/riscv-pmu/id" sysfs entry.
>
> The identification is generated as string of marchid, mimpid, mvendorid
> in hex format separated by coma - "0x70032,0x70032,0x0".
>
> The CSRs are detailed in the RISC-V privileged spec [1].
> [1] https://github.com/riscv/riscv-isa-manual
>
> Inspired-by: João Mário Domingos <joao.mario@tecnico.ulisboa.pt>
> Signed-off-by: Nikita Shubin <n.shubin@yadro.com>

Thanks for your patch!

> --- a/arch/riscv/kernel/sbi.c
> +++ b/arch/riscv/kernel/sbi.c

> --- a/drivers/perf/riscv_pmu_sbi.c
> +++ b/drivers/perf/riscv_pmu_sbi.c
> @@ -693,6 +693,28 @@ static int pmu_sbi_setup_irqs(struct riscv_pmu *pmu, struct platform_device *pde
>         return 0;
>  }
>
> +static ssize_t id_show(struct device *dev,
> +                               struct device_attribute *attr, char *buf)
> +{
> +       int len;
> +       struct riscv_pmu *pmu = container_of(dev_get_drvdata(dev), struct riscv_pmu, pmu);
> +
> +       len = sprintf(buf, "%s\n", pmu->pmuid);
> +       if (len <= 0)
> +               dev_err(dev, "invalid sprintf len: %d\n", len);

How can this fail?

Please use sysfs_emit() instead of sprintf(), and drop the error
message.

> +
> +       return len;
> +}

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v4 1/1] RISC-V: Create unique identification for SoC PMU
  2022-06-19 11:11   ` Nikita Shubin
  (?)
@ 2022-06-20 12:00     ` Anup Patel
  -1 siblings, 0 replies; 30+ messages in thread
From: Anup Patel @ 2022-06-20 12:00 UTC (permalink / raw)
  To: Nikita Shubin
  Cc: Atish Patra, Will Deacon, Sunil V L,
	João Mário Domingos, linux, Nikita Shubin,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Anup Patel,
	Mark Rutland, Geert Uytterhoeven, linux-riscv,
	linux-kernel@vger.kernel.org List, Linux ARM

On Sun, Jun 19, 2022 at 4:41 PM Nikita Shubin <nikita.shubin@maquefel.me> wrote:
>
> From: Nikita Shubin <n.shubin@yadro.com>
>
> Provide RISC-V SBI PMU id to distinguish different cores or SoCs via
> "devices/platform/riscv-pmu/id" sysfs entry.
>
> The identification is generated as string of marchid, mimpid, mvendorid
> in hex format separated by coma - "0x70032,0x70032,0x0".
>
> The CSRs are detailed in the RISC-V privileged spec [1].
> [1] https://github.com/riscv/riscv-isa-manual
>
> Inspired-by: João Mário Domingos <joao.mario@tecnico.ulisboa.pt>
> Signed-off-by: Nikita Shubin <n.shubin@yadro.com>

The mvendorid, marchid, and mimpid can be useful to apps other than
perf tool.

I have tried to extend /proc/cpuinfo with this information which can be
parsed by perf tool:
https://lore.kernel.org/all/20220620115549.1529597-1-apatel@ventanamicro.com/

Regards,
Anup

> ---
> v3->v4:
> - use string for pmuid
> - rename pmu_sbi_id_show to id_show
> - fix error print message in id_show
> - fix DEVICE_ATTR to use octal permissions
> ---
>  arch/riscv/kernel/sbi.c        |  3 +++
>  drivers/perf/riscv_pmu_sbi.c   | 41 ++++++++++++++++++++++++++++++++++
>  include/linux/perf/riscv_pmu.h |  1 +
>  3 files changed, 45 insertions(+)
>
> diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c
> index 775d3322b422..50dd9b6ecc9e 100644
> --- a/arch/riscv/kernel/sbi.c
> +++ b/arch/riscv/kernel/sbi.c
> @@ -627,16 +627,19 @@ long sbi_get_mvendorid(void)
>  {
>         return __sbi_base_ecall(SBI_EXT_BASE_GET_MVENDORID);
>  }
> +EXPORT_SYMBOL(sbi_get_mvendorid);
>
>  long sbi_get_marchid(void)
>  {
>         return __sbi_base_ecall(SBI_EXT_BASE_GET_MARCHID);
>  }
> +EXPORT_SYMBOL(sbi_get_marchid);
>
>  long sbi_get_mimpid(void)
>  {
>         return __sbi_base_ecall(SBI_EXT_BASE_GET_MIMPID);
>  }
> +EXPORT_SYMBOL(sbi_get_mimpid);
>
>  static void sbi_send_cpumask_ipi(const struct cpumask *target)
>  {
> diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c
> index dca3537a8dcc..be812f855617 100644
> --- a/drivers/perf/riscv_pmu_sbi.c
> +++ b/drivers/perf/riscv_pmu_sbi.c
> @@ -693,6 +693,28 @@ static int pmu_sbi_setup_irqs(struct riscv_pmu *pmu, struct platform_device *pde
>         return 0;
>  }
>
> +static ssize_t id_show(struct device *dev,
> +                               struct device_attribute *attr, char *buf)
> +{
> +       int len;
> +       struct riscv_pmu *pmu = container_of(dev_get_drvdata(dev), struct riscv_pmu, pmu);
> +
> +       len = sprintf(buf, "%s\n", pmu->pmuid);
> +       if (len <= 0)
> +               dev_err(dev, "invalid sprintf len: %d\n", len);
> +
> +       return len;
> +}
> +
> +static DEVICE_ATTR(id, 0644, id_show, NULL);
> +
> +static struct attribute *pmu_sbi_attrs[] = {
> +       &dev_attr_id.attr,
> +       NULL
> +};
> +
> +ATTRIBUTE_GROUPS(pmu_sbi);
> +
>  static int pmu_sbi_device_probe(struct platform_device *pdev)
>  {
>         struct riscv_pmu *pmu = NULL;
> @@ -714,6 +736,14 @@ static int pmu_sbi_device_probe(struct platform_device *pdev)
>         if (pmu_sbi_get_ctrinfo(num_counters))
>                 goto out_free;
>
> +       /* fill pmuid */
> +       pmu->pmuid = kasprintf(GFP_KERNEL, "0x%lx,0x%lx,0x%lx",
> +                              sbi_get_marchid(),
> +                              sbi_get_mimpid(),
> +                              sbi_get_mvendorid());
> +       if (!pmu->pmuid)
> +               goto out_free_pmuid;
> +
>         ret = pmu_sbi_setup_irqs(pmu, pdev);
>         if (ret < 0) {
>                 pr_info("Perf sampling/filtering is not supported as sscof extension is not available\n");
> @@ -739,8 +769,19 @@ static int pmu_sbi_device_probe(struct platform_device *pdev)
>                 return ret;
>         }
>
> +       ret = sysfs_create_group(&pdev->dev.kobj, &pmu_sbi_group);
> +       if (ret) {
> +               dev_err(&pdev->dev, "sysfs creation failed\n");
> +               return ret;
> +       }
> +
> +       pdev->dev.groups = pmu_sbi_groups;
> +       dev_set_drvdata(&pdev->dev, pmu);
> +
>         return 0;
>
> +out_free_pmuid:
> +       kfree(pmu->pmuid);
>  out_free:
>         kfree(pmu);
>         return ret;
> diff --git a/include/linux/perf/riscv_pmu.h b/include/linux/perf/riscv_pmu.h
> index 46f9b6fe306e..cf3557b77fb8 100644
> --- a/include/linux/perf/riscv_pmu.h
> +++ b/include/linux/perf/riscv_pmu.h
> @@ -42,6 +42,7 @@ struct cpu_hw_events {
>  struct riscv_pmu {
>         struct pmu      pmu;
>         char            *name;
> +       char            *pmuid;
>
>         irqreturn_t     (*handle_irq)(int irq_num, void *dev);
>
> --
> 2.35.1
>

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v4 1/1] RISC-V: Create unique identification for SoC PMU
@ 2022-06-20 12:00     ` Anup Patel
  0 siblings, 0 replies; 30+ messages in thread
From: Anup Patel @ 2022-06-20 12:00 UTC (permalink / raw)
  To: Nikita Shubin
  Cc: Atish Patra, Will Deacon, Sunil V L,
	João Mário Domingos, linux, Nikita Shubin,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Anup Patel,
	Mark Rutland, Geert Uytterhoeven, linux-riscv,
	linux-kernel@vger.kernel.org List, Linux ARM

On Sun, Jun 19, 2022 at 4:41 PM Nikita Shubin <nikita.shubin@maquefel.me> wrote:
>
> From: Nikita Shubin <n.shubin@yadro.com>
>
> Provide RISC-V SBI PMU id to distinguish different cores or SoCs via
> "devices/platform/riscv-pmu/id" sysfs entry.
>
> The identification is generated as string of marchid, mimpid, mvendorid
> in hex format separated by coma - "0x70032,0x70032,0x0".
>
> The CSRs are detailed in the RISC-V privileged spec [1].
> [1] https://github.com/riscv/riscv-isa-manual
>
> Inspired-by: João Mário Domingos <joao.mario@tecnico.ulisboa.pt>
> Signed-off-by: Nikita Shubin <n.shubin@yadro.com>

The mvendorid, marchid, and mimpid can be useful to apps other than
perf tool.

I have tried to extend /proc/cpuinfo with this information which can be
parsed by perf tool:
https://lore.kernel.org/all/20220620115549.1529597-1-apatel@ventanamicro.com/

Regards,
Anup

> ---
> v3->v4:
> - use string for pmuid
> - rename pmu_sbi_id_show to id_show
> - fix error print message in id_show
> - fix DEVICE_ATTR to use octal permissions
> ---
>  arch/riscv/kernel/sbi.c        |  3 +++
>  drivers/perf/riscv_pmu_sbi.c   | 41 ++++++++++++++++++++++++++++++++++
>  include/linux/perf/riscv_pmu.h |  1 +
>  3 files changed, 45 insertions(+)
>
> diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c
> index 775d3322b422..50dd9b6ecc9e 100644
> --- a/arch/riscv/kernel/sbi.c
> +++ b/arch/riscv/kernel/sbi.c
> @@ -627,16 +627,19 @@ long sbi_get_mvendorid(void)
>  {
>         return __sbi_base_ecall(SBI_EXT_BASE_GET_MVENDORID);
>  }
> +EXPORT_SYMBOL(sbi_get_mvendorid);
>
>  long sbi_get_marchid(void)
>  {
>         return __sbi_base_ecall(SBI_EXT_BASE_GET_MARCHID);
>  }
> +EXPORT_SYMBOL(sbi_get_marchid);
>
>  long sbi_get_mimpid(void)
>  {
>         return __sbi_base_ecall(SBI_EXT_BASE_GET_MIMPID);
>  }
> +EXPORT_SYMBOL(sbi_get_mimpid);
>
>  static void sbi_send_cpumask_ipi(const struct cpumask *target)
>  {
> diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c
> index dca3537a8dcc..be812f855617 100644
> --- a/drivers/perf/riscv_pmu_sbi.c
> +++ b/drivers/perf/riscv_pmu_sbi.c
> @@ -693,6 +693,28 @@ static int pmu_sbi_setup_irqs(struct riscv_pmu *pmu, struct platform_device *pde
>         return 0;
>  }
>
> +static ssize_t id_show(struct device *dev,
> +                               struct device_attribute *attr, char *buf)
> +{
> +       int len;
> +       struct riscv_pmu *pmu = container_of(dev_get_drvdata(dev), struct riscv_pmu, pmu);
> +
> +       len = sprintf(buf, "%s\n", pmu->pmuid);
> +       if (len <= 0)
> +               dev_err(dev, "invalid sprintf len: %d\n", len);
> +
> +       return len;
> +}
> +
> +static DEVICE_ATTR(id, 0644, id_show, NULL);
> +
> +static struct attribute *pmu_sbi_attrs[] = {
> +       &dev_attr_id.attr,
> +       NULL
> +};
> +
> +ATTRIBUTE_GROUPS(pmu_sbi);
> +
>  static int pmu_sbi_device_probe(struct platform_device *pdev)
>  {
>         struct riscv_pmu *pmu = NULL;
> @@ -714,6 +736,14 @@ static int pmu_sbi_device_probe(struct platform_device *pdev)
>         if (pmu_sbi_get_ctrinfo(num_counters))
>                 goto out_free;
>
> +       /* fill pmuid */
> +       pmu->pmuid = kasprintf(GFP_KERNEL, "0x%lx,0x%lx,0x%lx",
> +                              sbi_get_marchid(),
> +                              sbi_get_mimpid(),
> +                              sbi_get_mvendorid());
> +       if (!pmu->pmuid)
> +               goto out_free_pmuid;
> +
>         ret = pmu_sbi_setup_irqs(pmu, pdev);
>         if (ret < 0) {
>                 pr_info("Perf sampling/filtering is not supported as sscof extension is not available\n");
> @@ -739,8 +769,19 @@ static int pmu_sbi_device_probe(struct platform_device *pdev)
>                 return ret;
>         }
>
> +       ret = sysfs_create_group(&pdev->dev.kobj, &pmu_sbi_group);
> +       if (ret) {
> +               dev_err(&pdev->dev, "sysfs creation failed\n");
> +               return ret;
> +       }
> +
> +       pdev->dev.groups = pmu_sbi_groups;
> +       dev_set_drvdata(&pdev->dev, pmu);
> +
>         return 0;
>
> +out_free_pmuid:
> +       kfree(pmu->pmuid);
>  out_free:
>         kfree(pmu);
>         return ret;
> diff --git a/include/linux/perf/riscv_pmu.h b/include/linux/perf/riscv_pmu.h
> index 46f9b6fe306e..cf3557b77fb8 100644
> --- a/include/linux/perf/riscv_pmu.h
> +++ b/include/linux/perf/riscv_pmu.h
> @@ -42,6 +42,7 @@ struct cpu_hw_events {
>  struct riscv_pmu {
>         struct pmu      pmu;
>         char            *name;
> +       char            *pmuid;
>
>         irqreturn_t     (*handle_irq)(int irq_num, void *dev);
>
> --
> 2.35.1
>

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v4 1/1] RISC-V: Create unique identification for SoC PMU
@ 2022-06-20 12:00     ` Anup Patel
  0 siblings, 0 replies; 30+ messages in thread
From: Anup Patel @ 2022-06-20 12:00 UTC (permalink / raw)
  To: Nikita Shubin
  Cc: Atish Patra, Will Deacon, Sunil V L,
	João Mário Domingos, linux, Nikita Shubin,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Anup Patel,
	Mark Rutland, Geert Uytterhoeven, linux-riscv,
	linux-kernel@vger.kernel.org List, Linux ARM

On Sun, Jun 19, 2022 at 4:41 PM Nikita Shubin <nikita.shubin@maquefel.me> wrote:
>
> From: Nikita Shubin <n.shubin@yadro.com>
>
> Provide RISC-V SBI PMU id to distinguish different cores or SoCs via
> "devices/platform/riscv-pmu/id" sysfs entry.
>
> The identification is generated as string of marchid, mimpid, mvendorid
> in hex format separated by coma - "0x70032,0x70032,0x0".
>
> The CSRs are detailed in the RISC-V privileged spec [1].
> [1] https://github.com/riscv/riscv-isa-manual
>
> Inspired-by: João Mário Domingos <joao.mario@tecnico.ulisboa.pt>
> Signed-off-by: Nikita Shubin <n.shubin@yadro.com>

The mvendorid, marchid, and mimpid can be useful to apps other than
perf tool.

I have tried to extend /proc/cpuinfo with this information which can be
parsed by perf tool:
https://lore.kernel.org/all/20220620115549.1529597-1-apatel@ventanamicro.com/

Regards,
Anup

> ---
> v3->v4:
> - use string for pmuid
> - rename pmu_sbi_id_show to id_show
> - fix error print message in id_show
> - fix DEVICE_ATTR to use octal permissions
> ---
>  arch/riscv/kernel/sbi.c        |  3 +++
>  drivers/perf/riscv_pmu_sbi.c   | 41 ++++++++++++++++++++++++++++++++++
>  include/linux/perf/riscv_pmu.h |  1 +
>  3 files changed, 45 insertions(+)
>
> diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c
> index 775d3322b422..50dd9b6ecc9e 100644
> --- a/arch/riscv/kernel/sbi.c
> +++ b/arch/riscv/kernel/sbi.c
> @@ -627,16 +627,19 @@ long sbi_get_mvendorid(void)
>  {
>         return __sbi_base_ecall(SBI_EXT_BASE_GET_MVENDORID);
>  }
> +EXPORT_SYMBOL(sbi_get_mvendorid);
>
>  long sbi_get_marchid(void)
>  {
>         return __sbi_base_ecall(SBI_EXT_BASE_GET_MARCHID);
>  }
> +EXPORT_SYMBOL(sbi_get_marchid);
>
>  long sbi_get_mimpid(void)
>  {
>         return __sbi_base_ecall(SBI_EXT_BASE_GET_MIMPID);
>  }
> +EXPORT_SYMBOL(sbi_get_mimpid);
>
>  static void sbi_send_cpumask_ipi(const struct cpumask *target)
>  {
> diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c
> index dca3537a8dcc..be812f855617 100644
> --- a/drivers/perf/riscv_pmu_sbi.c
> +++ b/drivers/perf/riscv_pmu_sbi.c
> @@ -693,6 +693,28 @@ static int pmu_sbi_setup_irqs(struct riscv_pmu *pmu, struct platform_device *pde
>         return 0;
>  }
>
> +static ssize_t id_show(struct device *dev,
> +                               struct device_attribute *attr, char *buf)
> +{
> +       int len;
> +       struct riscv_pmu *pmu = container_of(dev_get_drvdata(dev), struct riscv_pmu, pmu);
> +
> +       len = sprintf(buf, "%s\n", pmu->pmuid);
> +       if (len <= 0)
> +               dev_err(dev, "invalid sprintf len: %d\n", len);
> +
> +       return len;
> +}
> +
> +static DEVICE_ATTR(id, 0644, id_show, NULL);
> +
> +static struct attribute *pmu_sbi_attrs[] = {
> +       &dev_attr_id.attr,
> +       NULL
> +};
> +
> +ATTRIBUTE_GROUPS(pmu_sbi);
> +
>  static int pmu_sbi_device_probe(struct platform_device *pdev)
>  {
>         struct riscv_pmu *pmu = NULL;
> @@ -714,6 +736,14 @@ static int pmu_sbi_device_probe(struct platform_device *pdev)
>         if (pmu_sbi_get_ctrinfo(num_counters))
>                 goto out_free;
>
> +       /* fill pmuid */
> +       pmu->pmuid = kasprintf(GFP_KERNEL, "0x%lx,0x%lx,0x%lx",
> +                              sbi_get_marchid(),
> +                              sbi_get_mimpid(),
> +                              sbi_get_mvendorid());
> +       if (!pmu->pmuid)
> +               goto out_free_pmuid;
> +
>         ret = pmu_sbi_setup_irqs(pmu, pdev);
>         if (ret < 0) {
>                 pr_info("Perf sampling/filtering is not supported as sscof extension is not available\n");
> @@ -739,8 +769,19 @@ static int pmu_sbi_device_probe(struct platform_device *pdev)
>                 return ret;
>         }
>
> +       ret = sysfs_create_group(&pdev->dev.kobj, &pmu_sbi_group);
> +       if (ret) {
> +               dev_err(&pdev->dev, "sysfs creation failed\n");
> +               return ret;
> +       }
> +
> +       pdev->dev.groups = pmu_sbi_groups;
> +       dev_set_drvdata(&pdev->dev, pmu);
> +
>         return 0;
>
> +out_free_pmuid:
> +       kfree(pmu->pmuid);
>  out_free:
>         kfree(pmu);
>         return ret;
> diff --git a/include/linux/perf/riscv_pmu.h b/include/linux/perf/riscv_pmu.h
> index 46f9b6fe306e..cf3557b77fb8 100644
> --- a/include/linux/perf/riscv_pmu.h
> +++ b/include/linux/perf/riscv_pmu.h
> @@ -42,6 +42,7 @@ struct cpu_hw_events {
>  struct riscv_pmu {
>         struct pmu      pmu;
>         char            *name;
> +       char            *pmuid;
>
>         irqreturn_t     (*handle_irq)(int irq_num, void *dev);
>
> --
> 2.35.1
>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v4 1/1] RISC-V: Create unique identification for SoC PMU
  2022-06-20 12:00     ` Anup Patel
  (?)
@ 2022-06-20 14:40       ` Nikita Shubin
  -1 siblings, 0 replies; 30+ messages in thread
From: Nikita Shubin @ 2022-06-20 14:40 UTC (permalink / raw)
  To: Atish Patra
  Cc: Anup Patel, Will Deacon, Sunil V L,
	João Mário Domingos, linux, Nikita Shubin,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Anup Patel,
	Mark Rutland, Geert Uytterhoeven, linux-riscv,
	linux-kernel@vger.kernel.org List, Linux ARM

On Mon, 20 Jun 2022 17:30:58 +0530
Anup Patel <apatel@ventanamicro.com> wrote:

> On Sun, Jun 19, 2022 at 4:41 PM Nikita Shubin
> <nikita.shubin@maquefel.me> wrote:
> >
> > From: Nikita Shubin <n.shubin@yadro.com>
> >
> > Provide RISC-V SBI PMU id to distinguish different cores or SoCs via
> > "devices/platform/riscv-pmu/id" sysfs entry.
> >
> > The identification is generated as string of marchid, mimpid,
> > mvendorid in hex format separated by coma - "0x70032,0x70032,0x0".
> >
> > The CSRs are detailed in the RISC-V privileged spec [1].
> > [1] https://github.com/riscv/riscv-isa-manual
> >
> > Inspired-by: João Mário Domingos <joao.mario@tecnico.ulisboa.pt>
> > Signed-off-by: Nikita Shubin <n.shubin@yadro.com>  
> 
> The mvendorid, marchid, and mimpid can be useful to apps other than
> perf tool.
> 
> I have tried to extend /proc/cpuinfo with this information which can
> be parsed by perf tool:
> https://lore.kernel.org/all/20220620115549.1529597-1-apatel@ventanamicro.com/

Atish, what do you think about this ?

RISC-V perf can rely on "/proc/cpuinfo", in some similar manner like
"tools/perf/arch/s390/util/header.c" does.

Can it create problems with pmu identification in case of hetergenous
harts ?

> 
> Regards,
> Anup
> 
> > ---
> > v3->v4:
> > - use string for pmuid
> > - rename pmu_sbi_id_show to id_show
> > - fix error print message in id_show
> > - fix DEVICE_ATTR to use octal permissions
> > ---
> >  arch/riscv/kernel/sbi.c        |  3 +++
> >  drivers/perf/riscv_pmu_sbi.c   | 41
> > ++++++++++++++++++++++++++++++++++ include/linux/perf/riscv_pmu.h |
> >  1 + 3 files changed, 45 insertions(+)
> >
> > diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c
> > index 775d3322b422..50dd9b6ecc9e 100644
> > --- a/arch/riscv/kernel/sbi.c
> > +++ b/arch/riscv/kernel/sbi.c
> > @@ -627,16 +627,19 @@ long sbi_get_mvendorid(void)
> >  {
> >         return __sbi_base_ecall(SBI_EXT_BASE_GET_MVENDORID);
> >  }
> > +EXPORT_SYMBOL(sbi_get_mvendorid);
> >
> >  long sbi_get_marchid(void)
> >  {
> >         return __sbi_base_ecall(SBI_EXT_BASE_GET_MARCHID);
> >  }
> > +EXPORT_SYMBOL(sbi_get_marchid);
> >
> >  long sbi_get_mimpid(void)
> >  {
> >         return __sbi_base_ecall(SBI_EXT_BASE_GET_MIMPID);
> >  }
> > +EXPORT_SYMBOL(sbi_get_mimpid);
> >
> >  static void sbi_send_cpumask_ipi(const struct cpumask *target)
> >  {
> > diff --git a/drivers/perf/riscv_pmu_sbi.c
> > b/drivers/perf/riscv_pmu_sbi.c index dca3537a8dcc..be812f855617
> > 100644 --- a/drivers/perf/riscv_pmu_sbi.c
> > +++ b/drivers/perf/riscv_pmu_sbi.c
> > @@ -693,6 +693,28 @@ static int pmu_sbi_setup_irqs(struct riscv_pmu
> > *pmu, struct platform_device *pde return 0;
> >  }
> >
> > +static ssize_t id_show(struct device *dev,
> > +                               struct device_attribute *attr, char
> > *buf) +{
> > +       int len;
> > +       struct riscv_pmu *pmu = container_of(dev_get_drvdata(dev),
> > struct riscv_pmu, pmu); +
> > +       len = sprintf(buf, "%s\n", pmu->pmuid);
> > +       if (len <= 0)
> > +               dev_err(dev, "invalid sprintf len: %d\n", len);
> > +
> > +       return len;
> > +}
> > +
> > +static DEVICE_ATTR(id, 0644, id_show, NULL);
> > +
> > +static struct attribute *pmu_sbi_attrs[] = {
> > +       &dev_attr_id.attr,
> > +       NULL
> > +};
> > +
> > +ATTRIBUTE_GROUPS(pmu_sbi);
> > +
> >  static int pmu_sbi_device_probe(struct platform_device *pdev)
> >  {
> >         struct riscv_pmu *pmu = NULL;
> > @@ -714,6 +736,14 @@ static int pmu_sbi_device_probe(struct
> > platform_device *pdev) if (pmu_sbi_get_ctrinfo(num_counters))
> >                 goto out_free;
> >
> > +       /* fill pmuid */
> > +       pmu->pmuid = kasprintf(GFP_KERNEL, "0x%lx,0x%lx,0x%lx",
> > +                              sbi_get_marchid(),
> > +                              sbi_get_mimpid(),
> > +                              sbi_get_mvendorid());
> > +       if (!pmu->pmuid)
> > +               goto out_free_pmuid;
> > +
> >         ret = pmu_sbi_setup_irqs(pmu, pdev);
> >         if (ret < 0) {
> >                 pr_info("Perf sampling/filtering is not supported
> > as sscof extension is not available\n"); @@ -739,8 +769,19 @@
> > static int pmu_sbi_device_probe(struct platform_device *pdev)
> > return ret; }
> >
> > +       ret = sysfs_create_group(&pdev->dev.kobj, &pmu_sbi_group);
> > +       if (ret) {
> > +               dev_err(&pdev->dev, "sysfs creation failed\n");
> > +               return ret;
> > +       }
> > +
> > +       pdev->dev.groups = pmu_sbi_groups;
> > +       dev_set_drvdata(&pdev->dev, pmu);
> > +
> >         return 0;
> >
> > +out_free_pmuid:
> > +       kfree(pmu->pmuid);
> >  out_free:
> >         kfree(pmu);
> >         return ret;
> > diff --git a/include/linux/perf/riscv_pmu.h
> > b/include/linux/perf/riscv_pmu.h index 46f9b6fe306e..cf3557b77fb8
> > 100644 --- a/include/linux/perf/riscv_pmu.h
> > +++ b/include/linux/perf/riscv_pmu.h
> > @@ -42,6 +42,7 @@ struct cpu_hw_events {
> >  struct riscv_pmu {
> >         struct pmu      pmu;
> >         char            *name;
> > +       char            *pmuid;
> >
> >         irqreturn_t     (*handle_irq)(int irq_num, void *dev);
> >
> > --
> > 2.35.1
> >  


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v4 1/1] RISC-V: Create unique identification for SoC PMU
@ 2022-06-20 14:40       ` Nikita Shubin
  0 siblings, 0 replies; 30+ messages in thread
From: Nikita Shubin @ 2022-06-20 14:40 UTC (permalink / raw)
  To: Atish Patra
  Cc: Anup Patel, Will Deacon, Sunil V L,
	João Mário Domingos, linux, Nikita Shubin,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Anup Patel,
	Mark Rutland, Geert Uytterhoeven, linux-riscv,
	linux-kernel@vger.kernel.org List, Linux ARM

On Mon, 20 Jun 2022 17:30:58 +0530
Anup Patel <apatel@ventanamicro.com> wrote:

> On Sun, Jun 19, 2022 at 4:41 PM Nikita Shubin
> <nikita.shubin@maquefel.me> wrote:
> >
> > From: Nikita Shubin <n.shubin@yadro.com>
> >
> > Provide RISC-V SBI PMU id to distinguish different cores or SoCs via
> > "devices/platform/riscv-pmu/id" sysfs entry.
> >
> > The identification is generated as string of marchid, mimpid,
> > mvendorid in hex format separated by coma - "0x70032,0x70032,0x0".
> >
> > The CSRs are detailed in the RISC-V privileged spec [1].
> > [1] https://github.com/riscv/riscv-isa-manual
> >
> > Inspired-by: João Mário Domingos <joao.mario@tecnico.ulisboa.pt>
> > Signed-off-by: Nikita Shubin <n.shubin@yadro.com>  
> 
> The mvendorid, marchid, and mimpid can be useful to apps other than
> perf tool.
> 
> I have tried to extend /proc/cpuinfo with this information which can
> be parsed by perf tool:
> https://lore.kernel.org/all/20220620115549.1529597-1-apatel@ventanamicro.com/

Atish, what do you think about this ?

RISC-V perf can rely on "/proc/cpuinfo", in some similar manner like
"tools/perf/arch/s390/util/header.c" does.

Can it create problems with pmu identification in case of hetergenous
harts ?

> 
> Regards,
> Anup
> 
> > ---
> > v3->v4:
> > - use string for pmuid
> > - rename pmu_sbi_id_show to id_show
> > - fix error print message in id_show
> > - fix DEVICE_ATTR to use octal permissions
> > ---
> >  arch/riscv/kernel/sbi.c        |  3 +++
> >  drivers/perf/riscv_pmu_sbi.c   | 41
> > ++++++++++++++++++++++++++++++++++ include/linux/perf/riscv_pmu.h |
> >  1 + 3 files changed, 45 insertions(+)
> >
> > diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c
> > index 775d3322b422..50dd9b6ecc9e 100644
> > --- a/arch/riscv/kernel/sbi.c
> > +++ b/arch/riscv/kernel/sbi.c
> > @@ -627,16 +627,19 @@ long sbi_get_mvendorid(void)
> >  {
> >         return __sbi_base_ecall(SBI_EXT_BASE_GET_MVENDORID);
> >  }
> > +EXPORT_SYMBOL(sbi_get_mvendorid);
> >
> >  long sbi_get_marchid(void)
> >  {
> >         return __sbi_base_ecall(SBI_EXT_BASE_GET_MARCHID);
> >  }
> > +EXPORT_SYMBOL(sbi_get_marchid);
> >
> >  long sbi_get_mimpid(void)
> >  {
> >         return __sbi_base_ecall(SBI_EXT_BASE_GET_MIMPID);
> >  }
> > +EXPORT_SYMBOL(sbi_get_mimpid);
> >
> >  static void sbi_send_cpumask_ipi(const struct cpumask *target)
> >  {
> > diff --git a/drivers/perf/riscv_pmu_sbi.c
> > b/drivers/perf/riscv_pmu_sbi.c index dca3537a8dcc..be812f855617
> > 100644 --- a/drivers/perf/riscv_pmu_sbi.c
> > +++ b/drivers/perf/riscv_pmu_sbi.c
> > @@ -693,6 +693,28 @@ static int pmu_sbi_setup_irqs(struct riscv_pmu
> > *pmu, struct platform_device *pde return 0;
> >  }
> >
> > +static ssize_t id_show(struct device *dev,
> > +                               struct device_attribute *attr, char
> > *buf) +{
> > +       int len;
> > +       struct riscv_pmu *pmu = container_of(dev_get_drvdata(dev),
> > struct riscv_pmu, pmu); +
> > +       len = sprintf(buf, "%s\n", pmu->pmuid);
> > +       if (len <= 0)
> > +               dev_err(dev, "invalid sprintf len: %d\n", len);
> > +
> > +       return len;
> > +}
> > +
> > +static DEVICE_ATTR(id, 0644, id_show, NULL);
> > +
> > +static struct attribute *pmu_sbi_attrs[] = {
> > +       &dev_attr_id.attr,
> > +       NULL
> > +};
> > +
> > +ATTRIBUTE_GROUPS(pmu_sbi);
> > +
> >  static int pmu_sbi_device_probe(struct platform_device *pdev)
> >  {
> >         struct riscv_pmu *pmu = NULL;
> > @@ -714,6 +736,14 @@ static int pmu_sbi_device_probe(struct
> > platform_device *pdev) if (pmu_sbi_get_ctrinfo(num_counters))
> >                 goto out_free;
> >
> > +       /* fill pmuid */
> > +       pmu->pmuid = kasprintf(GFP_KERNEL, "0x%lx,0x%lx,0x%lx",
> > +                              sbi_get_marchid(),
> > +                              sbi_get_mimpid(),
> > +                              sbi_get_mvendorid());
> > +       if (!pmu->pmuid)
> > +               goto out_free_pmuid;
> > +
> >         ret = pmu_sbi_setup_irqs(pmu, pdev);
> >         if (ret < 0) {
> >                 pr_info("Perf sampling/filtering is not supported
> > as sscof extension is not available\n"); @@ -739,8 +769,19 @@
> > static int pmu_sbi_device_probe(struct platform_device *pdev)
> > return ret; }
> >
> > +       ret = sysfs_create_group(&pdev->dev.kobj, &pmu_sbi_group);
> > +       if (ret) {
> > +               dev_err(&pdev->dev, "sysfs creation failed\n");
> > +               return ret;
> > +       }
> > +
> > +       pdev->dev.groups = pmu_sbi_groups;
> > +       dev_set_drvdata(&pdev->dev, pmu);
> > +
> >         return 0;
> >
> > +out_free_pmuid:
> > +       kfree(pmu->pmuid);
> >  out_free:
> >         kfree(pmu);
> >         return ret;
> > diff --git a/include/linux/perf/riscv_pmu.h
> > b/include/linux/perf/riscv_pmu.h index 46f9b6fe306e..cf3557b77fb8
> > 100644 --- a/include/linux/perf/riscv_pmu.h
> > +++ b/include/linux/perf/riscv_pmu.h
> > @@ -42,6 +42,7 @@ struct cpu_hw_events {
> >  struct riscv_pmu {
> >         struct pmu      pmu;
> >         char            *name;
> > +       char            *pmuid;
> >
> >         irqreturn_t     (*handle_irq)(int irq_num, void *dev);
> >
> > --
> > 2.35.1
> >  


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v4 1/1] RISC-V: Create unique identification for SoC PMU
@ 2022-06-20 14:40       ` Nikita Shubin
  0 siblings, 0 replies; 30+ messages in thread
From: Nikita Shubin @ 2022-06-20 14:40 UTC (permalink / raw)
  To: Atish Patra
  Cc: Anup Patel, Will Deacon, Sunil V L,
	João Mário Domingos, linux, Nikita Shubin,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Anup Patel,
	Mark Rutland, Geert Uytterhoeven, linux-riscv,
	linux-kernel@vger.kernel.org List, Linux ARM

On Mon, 20 Jun 2022 17:30:58 +0530
Anup Patel <apatel@ventanamicro.com> wrote:

> On Sun, Jun 19, 2022 at 4:41 PM Nikita Shubin
> <nikita.shubin@maquefel.me> wrote:
> >
> > From: Nikita Shubin <n.shubin@yadro.com>
> >
> > Provide RISC-V SBI PMU id to distinguish different cores or SoCs via
> > "devices/platform/riscv-pmu/id" sysfs entry.
> >
> > The identification is generated as string of marchid, mimpid,
> > mvendorid in hex format separated by coma - "0x70032,0x70032,0x0".
> >
> > The CSRs are detailed in the RISC-V privileged spec [1].
> > [1] https://github.com/riscv/riscv-isa-manual
> >
> > Inspired-by: João Mário Domingos <joao.mario@tecnico.ulisboa.pt>
> > Signed-off-by: Nikita Shubin <n.shubin@yadro.com>  
> 
> The mvendorid, marchid, and mimpid can be useful to apps other than
> perf tool.
> 
> I have tried to extend /proc/cpuinfo with this information which can
> be parsed by perf tool:
> https://lore.kernel.org/all/20220620115549.1529597-1-apatel@ventanamicro.com/

Atish, what do you think about this ?

RISC-V perf can rely on "/proc/cpuinfo", in some similar manner like
"tools/perf/arch/s390/util/header.c" does.

Can it create problems with pmu identification in case of hetergenous
harts ?

> 
> Regards,
> Anup
> 
> > ---
> > v3->v4:
> > - use string for pmuid
> > - rename pmu_sbi_id_show to id_show
> > - fix error print message in id_show
> > - fix DEVICE_ATTR to use octal permissions
> > ---
> >  arch/riscv/kernel/sbi.c        |  3 +++
> >  drivers/perf/riscv_pmu_sbi.c   | 41
> > ++++++++++++++++++++++++++++++++++ include/linux/perf/riscv_pmu.h |
> >  1 + 3 files changed, 45 insertions(+)
> >
> > diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c
> > index 775d3322b422..50dd9b6ecc9e 100644
> > --- a/arch/riscv/kernel/sbi.c
> > +++ b/arch/riscv/kernel/sbi.c
> > @@ -627,16 +627,19 @@ long sbi_get_mvendorid(void)
> >  {
> >         return __sbi_base_ecall(SBI_EXT_BASE_GET_MVENDORID);
> >  }
> > +EXPORT_SYMBOL(sbi_get_mvendorid);
> >
> >  long sbi_get_marchid(void)
> >  {
> >         return __sbi_base_ecall(SBI_EXT_BASE_GET_MARCHID);
> >  }
> > +EXPORT_SYMBOL(sbi_get_marchid);
> >
> >  long sbi_get_mimpid(void)
> >  {
> >         return __sbi_base_ecall(SBI_EXT_BASE_GET_MIMPID);
> >  }
> > +EXPORT_SYMBOL(sbi_get_mimpid);
> >
> >  static void sbi_send_cpumask_ipi(const struct cpumask *target)
> >  {
> > diff --git a/drivers/perf/riscv_pmu_sbi.c
> > b/drivers/perf/riscv_pmu_sbi.c index dca3537a8dcc..be812f855617
> > 100644 --- a/drivers/perf/riscv_pmu_sbi.c
> > +++ b/drivers/perf/riscv_pmu_sbi.c
> > @@ -693,6 +693,28 @@ static int pmu_sbi_setup_irqs(struct riscv_pmu
> > *pmu, struct platform_device *pde return 0;
> >  }
> >
> > +static ssize_t id_show(struct device *dev,
> > +                               struct device_attribute *attr, char
> > *buf) +{
> > +       int len;
> > +       struct riscv_pmu *pmu = container_of(dev_get_drvdata(dev),
> > struct riscv_pmu, pmu); +
> > +       len = sprintf(buf, "%s\n", pmu->pmuid);
> > +       if (len <= 0)
> > +               dev_err(dev, "invalid sprintf len: %d\n", len);
> > +
> > +       return len;
> > +}
> > +
> > +static DEVICE_ATTR(id, 0644, id_show, NULL);
> > +
> > +static struct attribute *pmu_sbi_attrs[] = {
> > +       &dev_attr_id.attr,
> > +       NULL
> > +};
> > +
> > +ATTRIBUTE_GROUPS(pmu_sbi);
> > +
> >  static int pmu_sbi_device_probe(struct platform_device *pdev)
> >  {
> >         struct riscv_pmu *pmu = NULL;
> > @@ -714,6 +736,14 @@ static int pmu_sbi_device_probe(struct
> > platform_device *pdev) if (pmu_sbi_get_ctrinfo(num_counters))
> >                 goto out_free;
> >
> > +       /* fill pmuid */
> > +       pmu->pmuid = kasprintf(GFP_KERNEL, "0x%lx,0x%lx,0x%lx",
> > +                              sbi_get_marchid(),
> > +                              sbi_get_mimpid(),
> > +                              sbi_get_mvendorid());
> > +       if (!pmu->pmuid)
> > +               goto out_free_pmuid;
> > +
> >         ret = pmu_sbi_setup_irqs(pmu, pdev);
> >         if (ret < 0) {
> >                 pr_info("Perf sampling/filtering is not supported
> > as sscof extension is not available\n"); @@ -739,8 +769,19 @@
> > static int pmu_sbi_device_probe(struct platform_device *pdev)
> > return ret; }
> >
> > +       ret = sysfs_create_group(&pdev->dev.kobj, &pmu_sbi_group);
> > +       if (ret) {
> > +               dev_err(&pdev->dev, "sysfs creation failed\n");
> > +               return ret;
> > +       }
> > +
> > +       pdev->dev.groups = pmu_sbi_groups;
> > +       dev_set_drvdata(&pdev->dev, pmu);
> > +
> >         return 0;
> >
> > +out_free_pmuid:
> > +       kfree(pmu->pmuid);
> >  out_free:
> >         kfree(pmu);
> >         return ret;
> > diff --git a/include/linux/perf/riscv_pmu.h
> > b/include/linux/perf/riscv_pmu.h index 46f9b6fe306e..cf3557b77fb8
> > 100644 --- a/include/linux/perf/riscv_pmu.h
> > +++ b/include/linux/perf/riscv_pmu.h
> > @@ -42,6 +42,7 @@ struct cpu_hw_events {
> >  struct riscv_pmu {
> >         struct pmu      pmu;
> >         char            *name;
> > +       char            *pmuid;
> >
> >         irqreturn_t     (*handle_irq)(int irq_num, void *dev);
> >
> > --
> > 2.35.1
> >  


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v4 1/1] RISC-V: Create unique identification for SoC PMU
  2022-06-20  7:50     ` Geert Uytterhoeven
  (?)
@ 2022-06-20 14:44       ` Nikita Shubin
  -1 siblings, 0 replies; 30+ messages in thread
From: Nikita Shubin @ 2022-06-20 14:44 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Atish Patra, Will Deacon, Sunil V L,
	João Mário Domingos, linux, Nikita Shubin,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Anup Patel,
	Mark Rutland, linux-riscv, Linux Kernel Mailing List, Linux ARM

Hello Geert!

On Mon, 20 Jun 2022 09:50:14 +0200
Geert Uytterhoeven <geert@linux-m68k.org> wrote:

> Hi Nikita,
> 
> On Sun, Jun 19, 2022 at 1:11 PM Nikita Shubin
> <nikita.shubin@maquefel.me> wrote:
> > From: Nikita Shubin <n.shubin@yadro.com>
> >
> > Provide RISC-V SBI PMU id to distinguish different cores or SoCs via
> > "devices/platform/riscv-pmu/id" sysfs entry.
> >
> > The identification is generated as string of marchid, mimpid,
> > mvendorid in hex format separated by coma - "0x70032,0x70032,0x0".
> >
> > The CSRs are detailed in the RISC-V privileged spec [1].
> > [1] https://github.com/riscv/riscv-isa-manual
> >
> > Inspired-by: João Mário Domingos <joao.mario@tecnico.ulisboa.pt>
> > Signed-off-by: Nikita Shubin <n.shubin@yadro.com>  
> 
> Thanks for your patch!
> 
> > --- a/arch/riscv/kernel/sbi.c
> > +++ b/arch/riscv/kernel/sbi.c  
> 
> > --- a/drivers/perf/riscv_pmu_sbi.c
> > +++ b/drivers/perf/riscv_pmu_sbi.c
> > @@ -693,6 +693,28 @@ static int pmu_sbi_setup_irqs(struct riscv_pmu
> > *pmu, struct platform_device *pde return 0;
> >  }
> >
> > +static ssize_t id_show(struct device *dev,
> > +                               struct device_attribute *attr, char
> > *buf) +{
> > +       int len;
> > +       struct riscv_pmu *pmu = container_of(dev_get_drvdata(dev),
> > struct riscv_pmu, pmu); +
> > +       len = sprintf(buf, "%s\n", pmu->pmuid);
> > +       if (len <= 0)
> > +               dev_err(dev, "invalid sprintf len: %d\n", len);  
> 
> How can this fail?
> 
> Please use sysfs_emit() instead of sprintf(), and drop the error
> message.

Indeed, thank you for your comments.

Also i missed some explicit free:

> > +out_free_pmuid:
> > +       kfree(pmu->pmuid);

This is not needed.

> 
> > +
> > +       return len;
> > +}  
> 
> Gr{oetje,eeting}s,
> 
>                         Geert
> 
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 --
> geert@linux-m68k.org
> 
> In personal conversations with technical people, I call myself a
> hacker. But when I'm talking to journalists I just say "programmer"
> or something like that. -- Linus Torvalds

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v4 1/1] RISC-V: Create unique identification for SoC PMU
@ 2022-06-20 14:44       ` Nikita Shubin
  0 siblings, 0 replies; 30+ messages in thread
From: Nikita Shubin @ 2022-06-20 14:44 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Atish Patra, Will Deacon, Sunil V L,
	João Mário Domingos, linux, Nikita Shubin,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Anup Patel,
	Mark Rutland, linux-riscv, Linux Kernel Mailing List, Linux ARM

Hello Geert!

On Mon, 20 Jun 2022 09:50:14 +0200
Geert Uytterhoeven <geert@linux-m68k.org> wrote:

> Hi Nikita,
> 
> On Sun, Jun 19, 2022 at 1:11 PM Nikita Shubin
> <nikita.shubin@maquefel.me> wrote:
> > From: Nikita Shubin <n.shubin@yadro.com>
> >
> > Provide RISC-V SBI PMU id to distinguish different cores or SoCs via
> > "devices/platform/riscv-pmu/id" sysfs entry.
> >
> > The identification is generated as string of marchid, mimpid,
> > mvendorid in hex format separated by coma - "0x70032,0x70032,0x0".
> >
> > The CSRs are detailed in the RISC-V privileged spec [1].
> > [1] https://github.com/riscv/riscv-isa-manual
> >
> > Inspired-by: João Mário Domingos <joao.mario@tecnico.ulisboa.pt>
> > Signed-off-by: Nikita Shubin <n.shubin@yadro.com>  
> 
> Thanks for your patch!
> 
> > --- a/arch/riscv/kernel/sbi.c
> > +++ b/arch/riscv/kernel/sbi.c  
> 
> > --- a/drivers/perf/riscv_pmu_sbi.c
> > +++ b/drivers/perf/riscv_pmu_sbi.c
> > @@ -693,6 +693,28 @@ static int pmu_sbi_setup_irqs(struct riscv_pmu
> > *pmu, struct platform_device *pde return 0;
> >  }
> >
> > +static ssize_t id_show(struct device *dev,
> > +                               struct device_attribute *attr, char
> > *buf) +{
> > +       int len;
> > +       struct riscv_pmu *pmu = container_of(dev_get_drvdata(dev),
> > struct riscv_pmu, pmu); +
> > +       len = sprintf(buf, "%s\n", pmu->pmuid);
> > +       if (len <= 0)
> > +               dev_err(dev, "invalid sprintf len: %d\n", len);  
> 
> How can this fail?
> 
> Please use sysfs_emit() instead of sprintf(), and drop the error
> message.

Indeed, thank you for your comments.

Also i missed some explicit free:

> > +out_free_pmuid:
> > +       kfree(pmu->pmuid);

This is not needed.

> 
> > +
> > +       return len;
> > +}  
> 
> Gr{oetje,eeting}s,
> 
>                         Geert
> 
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 --
> geert@linux-m68k.org
> 
> In personal conversations with technical people, I call myself a
> hacker. But when I'm talking to journalists I just say "programmer"
> or something like that. -- Linus Torvalds

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v4 1/1] RISC-V: Create unique identification for SoC PMU
@ 2022-06-20 14:44       ` Nikita Shubin
  0 siblings, 0 replies; 30+ messages in thread
From: Nikita Shubin @ 2022-06-20 14:44 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Atish Patra, Will Deacon, Sunil V L,
	João Mário Domingos, linux, Nikita Shubin,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Anup Patel,
	Mark Rutland, linux-riscv, Linux Kernel Mailing List, Linux ARM

Hello Geert!

On Mon, 20 Jun 2022 09:50:14 +0200
Geert Uytterhoeven <geert@linux-m68k.org> wrote:

> Hi Nikita,
> 
> On Sun, Jun 19, 2022 at 1:11 PM Nikita Shubin
> <nikita.shubin@maquefel.me> wrote:
> > From: Nikita Shubin <n.shubin@yadro.com>
> >
> > Provide RISC-V SBI PMU id to distinguish different cores or SoCs via
> > "devices/platform/riscv-pmu/id" sysfs entry.
> >
> > The identification is generated as string of marchid, mimpid,
> > mvendorid in hex format separated by coma - "0x70032,0x70032,0x0".
> >
> > The CSRs are detailed in the RISC-V privileged spec [1].
> > [1] https://github.com/riscv/riscv-isa-manual
> >
> > Inspired-by: João Mário Domingos <joao.mario@tecnico.ulisboa.pt>
> > Signed-off-by: Nikita Shubin <n.shubin@yadro.com>  
> 
> Thanks for your patch!
> 
> > --- a/arch/riscv/kernel/sbi.c
> > +++ b/arch/riscv/kernel/sbi.c  
> 
> > --- a/drivers/perf/riscv_pmu_sbi.c
> > +++ b/drivers/perf/riscv_pmu_sbi.c
> > @@ -693,6 +693,28 @@ static int pmu_sbi_setup_irqs(struct riscv_pmu
> > *pmu, struct platform_device *pde return 0;
> >  }
> >
> > +static ssize_t id_show(struct device *dev,
> > +                               struct device_attribute *attr, char
> > *buf) +{
> > +       int len;
> > +       struct riscv_pmu *pmu = container_of(dev_get_drvdata(dev),
> > struct riscv_pmu, pmu); +
> > +       len = sprintf(buf, "%s\n", pmu->pmuid);
> > +       if (len <= 0)
> > +               dev_err(dev, "invalid sprintf len: %d\n", len);  
> 
> How can this fail?
> 
> Please use sysfs_emit() instead of sprintf(), and drop the error
> message.

Indeed, thank you for your comments.

Also i missed some explicit free:

> > +out_free_pmuid:
> > +       kfree(pmu->pmuid);

This is not needed.

> 
> > +
> > +       return len;
> > +}  
> 
> Gr{oetje,eeting}s,
> 
>                         Geert
> 
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 --
> geert@linux-m68k.org
> 
> In personal conversations with technical people, I call myself a
> hacker. But when I'm talking to journalists I just say "programmer"
> or something like that. -- Linus Torvalds

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v4 1/1] RISC-V: Create unique identification for SoC PMU
  2022-06-20 14:40       ` Nikita Shubin
  (?)
@ 2022-06-20 19:40         ` Atish Patra
  -1 siblings, 0 replies; 30+ messages in thread
From: Atish Patra @ 2022-06-20 19:40 UTC (permalink / raw)
  To: Nikita Shubin
  Cc: Anup Patel, Will Deacon, Sunil V L,
	João Mário Domingos, linux, Nikita Shubin,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Anup Patel,
	Mark Rutland, Geert Uytterhoeven, linux-riscv,
	linux-kernel@vger.kernel.org List, Linux ARM

On Mon, Jun 20, 2022 at 7:40 AM Nikita Shubin <nikita.shubin@maquefel.me> wrote:
>
> On Mon, 20 Jun 2022 17:30:58 +0530
> Anup Patel <apatel@ventanamicro.com> wrote:
>
> > On Sun, Jun 19, 2022 at 4:41 PM Nikita Shubin
> > <nikita.shubin@maquefel.me> wrote:
> > >
> > > From: Nikita Shubin <n.shubin@yadro.com>
> > >
> > > Provide RISC-V SBI PMU id to distinguish different cores or SoCs via
> > > "devices/platform/riscv-pmu/id" sysfs entry.
> > >
> > > The identification is generated as string of marchid, mimpid,
> > > mvendorid in hex format separated by coma - "0x70032,0x70032,0x0".
> > >
> > > The CSRs are detailed in the RISC-V privileged spec [1].
> > > [1] https://github.com/riscv/riscv-isa-manual
> > >
> > > Inspired-by: João Mário Domingos <joao.mario@tecnico.ulisboa.pt>
> > > Signed-off-by: Nikita Shubin <n.shubin@yadro.com>
> >
> > The mvendorid, marchid, and mimpid can be useful to apps other than
> > perf tool.
> >
> > I have tried to extend /proc/cpuinfo with this information which can
> > be parsed by perf tool:
> > https://lore.kernel.org/all/20220620115549.1529597-1-apatel@ventanamicro.com/
>
> Atish, what do you think about this ?
>
> RISC-V perf can rely on "/proc/cpuinfo", in some similar manner like
> "tools/perf/arch/s390/util/header.c" does.
>

Yes. We can expose these three values either in sysfs or procfs (/proc/cpuinfo).
For perf tool, it shouldn't matter as the header.c will need to
generate the unique cpuid
string from either.

I am not sure if any other userspace tool prefers to parse sysfs
instead of cpuinfo.

> Can it create problems with pmu identification in case of hetergenous
> harts ?
>

Does perf support hetergenous harts at all ? ARM64 code
(tool/perf/arch/arm64/util/header.c)
just breaks out of the loop after finding the first MIDR.

> >
> > Regards,
> > Anup
> >
> > > ---
> > > v3->v4:
> > > - use string for pmuid
> > > - rename pmu_sbi_id_show to id_show
> > > - fix error print message in id_show
> > > - fix DEVICE_ATTR to use octal permissions
> > > ---
> > >  arch/riscv/kernel/sbi.c        |  3 +++
> > >  drivers/perf/riscv_pmu_sbi.c   | 41
> > > ++++++++++++++++++++++++++++++++++ include/linux/perf/riscv_pmu.h |
> > >  1 + 3 files changed, 45 insertions(+)
> > >
> > > diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c
> > > index 775d3322b422..50dd9b6ecc9e 100644
> > > --- a/arch/riscv/kernel/sbi.c
> > > +++ b/arch/riscv/kernel/sbi.c
> > > @@ -627,16 +627,19 @@ long sbi_get_mvendorid(void)
> > >  {
> > >         return __sbi_base_ecall(SBI_EXT_BASE_GET_MVENDORID);
> > >  }
> > > +EXPORT_SYMBOL(sbi_get_mvendorid);
> > >
> > >  long sbi_get_marchid(void)
> > >  {
> > >         return __sbi_base_ecall(SBI_EXT_BASE_GET_MARCHID);
> > >  }
> > > +EXPORT_SYMBOL(sbi_get_marchid);
> > >
> > >  long sbi_get_mimpid(void)
> > >  {
> > >         return __sbi_base_ecall(SBI_EXT_BASE_GET_MIMPID);
> > >  }
> > > +EXPORT_SYMBOL(sbi_get_mimpid);
> > >
> > >  static void sbi_send_cpumask_ipi(const struct cpumask *target)
> > >  {
> > > diff --git a/drivers/perf/riscv_pmu_sbi.c
> > > b/drivers/perf/riscv_pmu_sbi.c index dca3537a8dcc..be812f855617
> > > 100644 --- a/drivers/perf/riscv_pmu_sbi.c
> > > +++ b/drivers/perf/riscv_pmu_sbi.c
> > > @@ -693,6 +693,28 @@ static int pmu_sbi_setup_irqs(struct riscv_pmu
> > > *pmu, struct platform_device *pde return 0;
> > >  }
> > >
> > > +static ssize_t id_show(struct device *dev,
> > > +                               struct device_attribute *attr, char
> > > *buf) +{
> > > +       int len;
> > > +       struct riscv_pmu *pmu = container_of(dev_get_drvdata(dev),
> > > struct riscv_pmu, pmu); +
> > > +       len = sprintf(buf, "%s\n", pmu->pmuid);
> > > +       if (len <= 0)
> > > +               dev_err(dev, "invalid sprintf len: %d\n", len);
> > > +
> > > +       return len;
> > > +}
> > > +
> > > +static DEVICE_ATTR(id, 0644, id_show, NULL);
> > > +
> > > +static struct attribute *pmu_sbi_attrs[] = {
> > > +       &dev_attr_id.attr,
> > > +       NULL
> > > +};
> > > +
> > > +ATTRIBUTE_GROUPS(pmu_sbi);
> > > +
> > >  static int pmu_sbi_device_probe(struct platform_device *pdev)
> > >  {
> > >         struct riscv_pmu *pmu = NULL;
> > > @@ -714,6 +736,14 @@ static int pmu_sbi_device_probe(struct
> > > platform_device *pdev) if (pmu_sbi_get_ctrinfo(num_counters))
> > >                 goto out_free;
> > >
> > > +       /* fill pmuid */
> > > +       pmu->pmuid = kasprintf(GFP_KERNEL, "0x%lx,0x%lx,0x%lx",
> > > +                              sbi_get_marchid(),
> > > +                              sbi_get_mimpid(),
> > > +                              sbi_get_mvendorid());
> > > +       if (!pmu->pmuid)
> > > +               goto out_free_pmuid;
> > > +
> > >         ret = pmu_sbi_setup_irqs(pmu, pdev);
> > >         if (ret < 0) {
> > >                 pr_info("Perf sampling/filtering is not supported
> > > as sscof extension is not available\n"); @@ -739,8 +769,19 @@
> > > static int pmu_sbi_device_probe(struct platform_device *pdev)
> > > return ret; }
> > >
> > > +       ret = sysfs_create_group(&pdev->dev.kobj, &pmu_sbi_group);
> > > +       if (ret) {
> > > +               dev_err(&pdev->dev, "sysfs creation failed\n");
> > > +               return ret;
> > > +       }
> > > +
> > > +       pdev->dev.groups = pmu_sbi_groups;
> > > +       dev_set_drvdata(&pdev->dev, pmu);
> > > +
> > >         return 0;
> > >
> > > +out_free_pmuid:
> > > +       kfree(pmu->pmuid);
> > >  out_free:
> > >         kfree(pmu);
> > >         return ret;
> > > diff --git a/include/linux/perf/riscv_pmu.h
> > > b/include/linux/perf/riscv_pmu.h index 46f9b6fe306e..cf3557b77fb8
> > > 100644 --- a/include/linux/perf/riscv_pmu.h
> > > +++ b/include/linux/perf/riscv_pmu.h
> > > @@ -42,6 +42,7 @@ struct cpu_hw_events {
> > >  struct riscv_pmu {
> > >         struct pmu      pmu;
> > >         char            *name;
> > > +       char            *pmuid;
> > >
> > >         irqreturn_t     (*handle_irq)(int irq_num, void *dev);
> > >
> > > --
> > > 2.35.1
> > >
>


-- 
Regards,
Atish

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v4 1/1] RISC-V: Create unique identification for SoC PMU
@ 2022-06-20 19:40         ` Atish Patra
  0 siblings, 0 replies; 30+ messages in thread
From: Atish Patra @ 2022-06-20 19:40 UTC (permalink / raw)
  To: Nikita Shubin
  Cc: Anup Patel, Will Deacon, Sunil V L,
	João Mário Domingos, linux, Nikita Shubin,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Anup Patel,
	Mark Rutland, Geert Uytterhoeven, linux-riscv,
	linux-kernel@vger.kernel.org List, Linux ARM

On Mon, Jun 20, 2022 at 7:40 AM Nikita Shubin <nikita.shubin@maquefel.me> wrote:
>
> On Mon, 20 Jun 2022 17:30:58 +0530
> Anup Patel <apatel@ventanamicro.com> wrote:
>
> > On Sun, Jun 19, 2022 at 4:41 PM Nikita Shubin
> > <nikita.shubin@maquefel.me> wrote:
> > >
> > > From: Nikita Shubin <n.shubin@yadro.com>
> > >
> > > Provide RISC-V SBI PMU id to distinguish different cores or SoCs via
> > > "devices/platform/riscv-pmu/id" sysfs entry.
> > >
> > > The identification is generated as string of marchid, mimpid,
> > > mvendorid in hex format separated by coma - "0x70032,0x70032,0x0".
> > >
> > > The CSRs are detailed in the RISC-V privileged spec [1].
> > > [1] https://github.com/riscv/riscv-isa-manual
> > >
> > > Inspired-by: João Mário Domingos <joao.mario@tecnico.ulisboa.pt>
> > > Signed-off-by: Nikita Shubin <n.shubin@yadro.com>
> >
> > The mvendorid, marchid, and mimpid can be useful to apps other than
> > perf tool.
> >
> > I have tried to extend /proc/cpuinfo with this information which can
> > be parsed by perf tool:
> > https://lore.kernel.org/all/20220620115549.1529597-1-apatel@ventanamicro.com/
>
> Atish, what do you think about this ?
>
> RISC-V perf can rely on "/proc/cpuinfo", in some similar manner like
> "tools/perf/arch/s390/util/header.c" does.
>

Yes. We can expose these three values either in sysfs or procfs (/proc/cpuinfo).
For perf tool, it shouldn't matter as the header.c will need to
generate the unique cpuid
string from either.

I am not sure if any other userspace tool prefers to parse sysfs
instead of cpuinfo.

> Can it create problems with pmu identification in case of hetergenous
> harts ?
>

Does perf support hetergenous harts at all ? ARM64 code
(tool/perf/arch/arm64/util/header.c)
just breaks out of the loop after finding the first MIDR.

> >
> > Regards,
> > Anup
> >
> > > ---
> > > v3->v4:
> > > - use string for pmuid
> > > - rename pmu_sbi_id_show to id_show
> > > - fix error print message in id_show
> > > - fix DEVICE_ATTR to use octal permissions
> > > ---
> > >  arch/riscv/kernel/sbi.c        |  3 +++
> > >  drivers/perf/riscv_pmu_sbi.c   | 41
> > > ++++++++++++++++++++++++++++++++++ include/linux/perf/riscv_pmu.h |
> > >  1 + 3 files changed, 45 insertions(+)
> > >
> > > diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c
> > > index 775d3322b422..50dd9b6ecc9e 100644
> > > --- a/arch/riscv/kernel/sbi.c
> > > +++ b/arch/riscv/kernel/sbi.c
> > > @@ -627,16 +627,19 @@ long sbi_get_mvendorid(void)
> > >  {
> > >         return __sbi_base_ecall(SBI_EXT_BASE_GET_MVENDORID);
> > >  }
> > > +EXPORT_SYMBOL(sbi_get_mvendorid);
> > >
> > >  long sbi_get_marchid(void)
> > >  {
> > >         return __sbi_base_ecall(SBI_EXT_BASE_GET_MARCHID);
> > >  }
> > > +EXPORT_SYMBOL(sbi_get_marchid);
> > >
> > >  long sbi_get_mimpid(void)
> > >  {
> > >         return __sbi_base_ecall(SBI_EXT_BASE_GET_MIMPID);
> > >  }
> > > +EXPORT_SYMBOL(sbi_get_mimpid);
> > >
> > >  static void sbi_send_cpumask_ipi(const struct cpumask *target)
> > >  {
> > > diff --git a/drivers/perf/riscv_pmu_sbi.c
> > > b/drivers/perf/riscv_pmu_sbi.c index dca3537a8dcc..be812f855617
> > > 100644 --- a/drivers/perf/riscv_pmu_sbi.c
> > > +++ b/drivers/perf/riscv_pmu_sbi.c
> > > @@ -693,6 +693,28 @@ static int pmu_sbi_setup_irqs(struct riscv_pmu
> > > *pmu, struct platform_device *pde return 0;
> > >  }
> > >
> > > +static ssize_t id_show(struct device *dev,
> > > +                               struct device_attribute *attr, char
> > > *buf) +{
> > > +       int len;
> > > +       struct riscv_pmu *pmu = container_of(dev_get_drvdata(dev),
> > > struct riscv_pmu, pmu); +
> > > +       len = sprintf(buf, "%s\n", pmu->pmuid);
> > > +       if (len <= 0)
> > > +               dev_err(dev, "invalid sprintf len: %d\n", len);
> > > +
> > > +       return len;
> > > +}
> > > +
> > > +static DEVICE_ATTR(id, 0644, id_show, NULL);
> > > +
> > > +static struct attribute *pmu_sbi_attrs[] = {
> > > +       &dev_attr_id.attr,
> > > +       NULL
> > > +};
> > > +
> > > +ATTRIBUTE_GROUPS(pmu_sbi);
> > > +
> > >  static int pmu_sbi_device_probe(struct platform_device *pdev)
> > >  {
> > >         struct riscv_pmu *pmu = NULL;
> > > @@ -714,6 +736,14 @@ static int pmu_sbi_device_probe(struct
> > > platform_device *pdev) if (pmu_sbi_get_ctrinfo(num_counters))
> > >                 goto out_free;
> > >
> > > +       /* fill pmuid */
> > > +       pmu->pmuid = kasprintf(GFP_KERNEL, "0x%lx,0x%lx,0x%lx",
> > > +                              sbi_get_marchid(),
> > > +                              sbi_get_mimpid(),
> > > +                              sbi_get_mvendorid());
> > > +       if (!pmu->pmuid)
> > > +               goto out_free_pmuid;
> > > +
> > >         ret = pmu_sbi_setup_irqs(pmu, pdev);
> > >         if (ret < 0) {
> > >                 pr_info("Perf sampling/filtering is not supported
> > > as sscof extension is not available\n"); @@ -739,8 +769,19 @@
> > > static int pmu_sbi_device_probe(struct platform_device *pdev)
> > > return ret; }
> > >
> > > +       ret = sysfs_create_group(&pdev->dev.kobj, &pmu_sbi_group);
> > > +       if (ret) {
> > > +               dev_err(&pdev->dev, "sysfs creation failed\n");
> > > +               return ret;
> > > +       }
> > > +
> > > +       pdev->dev.groups = pmu_sbi_groups;
> > > +       dev_set_drvdata(&pdev->dev, pmu);
> > > +
> > >         return 0;
> > >
> > > +out_free_pmuid:
> > > +       kfree(pmu->pmuid);
> > >  out_free:
> > >         kfree(pmu);
> > >         return ret;
> > > diff --git a/include/linux/perf/riscv_pmu.h
> > > b/include/linux/perf/riscv_pmu.h index 46f9b6fe306e..cf3557b77fb8
> > > 100644 --- a/include/linux/perf/riscv_pmu.h
> > > +++ b/include/linux/perf/riscv_pmu.h
> > > @@ -42,6 +42,7 @@ struct cpu_hw_events {
> > >  struct riscv_pmu {
> > >         struct pmu      pmu;
> > >         char            *name;
> > > +       char            *pmuid;
> > >
> > >         irqreturn_t     (*handle_irq)(int irq_num, void *dev);
> > >
> > > --
> > > 2.35.1
> > >
>


-- 
Regards,
Atish

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v4 1/1] RISC-V: Create unique identification for SoC PMU
@ 2022-06-20 19:40         ` Atish Patra
  0 siblings, 0 replies; 30+ messages in thread
From: Atish Patra @ 2022-06-20 19:40 UTC (permalink / raw)
  To: Nikita Shubin
  Cc: Anup Patel, Will Deacon, Sunil V L,
	João Mário Domingos, linux, Nikita Shubin,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Anup Patel,
	Mark Rutland, Geert Uytterhoeven, linux-riscv,
	linux-kernel@vger.kernel.org List, Linux ARM

On Mon, Jun 20, 2022 at 7:40 AM Nikita Shubin <nikita.shubin@maquefel.me> wrote:
>
> On Mon, 20 Jun 2022 17:30:58 +0530
> Anup Patel <apatel@ventanamicro.com> wrote:
>
> > On Sun, Jun 19, 2022 at 4:41 PM Nikita Shubin
> > <nikita.shubin@maquefel.me> wrote:
> > >
> > > From: Nikita Shubin <n.shubin@yadro.com>
> > >
> > > Provide RISC-V SBI PMU id to distinguish different cores or SoCs via
> > > "devices/platform/riscv-pmu/id" sysfs entry.
> > >
> > > The identification is generated as string of marchid, mimpid,
> > > mvendorid in hex format separated by coma - "0x70032,0x70032,0x0".
> > >
> > > The CSRs are detailed in the RISC-V privileged spec [1].
> > > [1] https://github.com/riscv/riscv-isa-manual
> > >
> > > Inspired-by: João Mário Domingos <joao.mario@tecnico.ulisboa.pt>
> > > Signed-off-by: Nikita Shubin <n.shubin@yadro.com>
> >
> > The mvendorid, marchid, and mimpid can be useful to apps other than
> > perf tool.
> >
> > I have tried to extend /proc/cpuinfo with this information which can
> > be parsed by perf tool:
> > https://lore.kernel.org/all/20220620115549.1529597-1-apatel@ventanamicro.com/
>
> Atish, what do you think about this ?
>
> RISC-V perf can rely on "/proc/cpuinfo", in some similar manner like
> "tools/perf/arch/s390/util/header.c" does.
>

Yes. We can expose these three values either in sysfs or procfs (/proc/cpuinfo).
For perf tool, it shouldn't matter as the header.c will need to
generate the unique cpuid
string from either.

I am not sure if any other userspace tool prefers to parse sysfs
instead of cpuinfo.

> Can it create problems with pmu identification in case of hetergenous
> harts ?
>

Does perf support hetergenous harts at all ? ARM64 code
(tool/perf/arch/arm64/util/header.c)
just breaks out of the loop after finding the first MIDR.

> >
> > Regards,
> > Anup
> >
> > > ---
> > > v3->v4:
> > > - use string for pmuid
> > > - rename pmu_sbi_id_show to id_show
> > > - fix error print message in id_show
> > > - fix DEVICE_ATTR to use octal permissions
> > > ---
> > >  arch/riscv/kernel/sbi.c        |  3 +++
> > >  drivers/perf/riscv_pmu_sbi.c   | 41
> > > ++++++++++++++++++++++++++++++++++ include/linux/perf/riscv_pmu.h |
> > >  1 + 3 files changed, 45 insertions(+)
> > >
> > > diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c
> > > index 775d3322b422..50dd9b6ecc9e 100644
> > > --- a/arch/riscv/kernel/sbi.c
> > > +++ b/arch/riscv/kernel/sbi.c
> > > @@ -627,16 +627,19 @@ long sbi_get_mvendorid(void)
> > >  {
> > >         return __sbi_base_ecall(SBI_EXT_BASE_GET_MVENDORID);
> > >  }
> > > +EXPORT_SYMBOL(sbi_get_mvendorid);
> > >
> > >  long sbi_get_marchid(void)
> > >  {
> > >         return __sbi_base_ecall(SBI_EXT_BASE_GET_MARCHID);
> > >  }
> > > +EXPORT_SYMBOL(sbi_get_marchid);
> > >
> > >  long sbi_get_mimpid(void)
> > >  {
> > >         return __sbi_base_ecall(SBI_EXT_BASE_GET_MIMPID);
> > >  }
> > > +EXPORT_SYMBOL(sbi_get_mimpid);
> > >
> > >  static void sbi_send_cpumask_ipi(const struct cpumask *target)
> > >  {
> > > diff --git a/drivers/perf/riscv_pmu_sbi.c
> > > b/drivers/perf/riscv_pmu_sbi.c index dca3537a8dcc..be812f855617
> > > 100644 --- a/drivers/perf/riscv_pmu_sbi.c
> > > +++ b/drivers/perf/riscv_pmu_sbi.c
> > > @@ -693,6 +693,28 @@ static int pmu_sbi_setup_irqs(struct riscv_pmu
> > > *pmu, struct platform_device *pde return 0;
> > >  }
> > >
> > > +static ssize_t id_show(struct device *dev,
> > > +                               struct device_attribute *attr, char
> > > *buf) +{
> > > +       int len;
> > > +       struct riscv_pmu *pmu = container_of(dev_get_drvdata(dev),
> > > struct riscv_pmu, pmu); +
> > > +       len = sprintf(buf, "%s\n", pmu->pmuid);
> > > +       if (len <= 0)
> > > +               dev_err(dev, "invalid sprintf len: %d\n", len);
> > > +
> > > +       return len;
> > > +}
> > > +
> > > +static DEVICE_ATTR(id, 0644, id_show, NULL);
> > > +
> > > +static struct attribute *pmu_sbi_attrs[] = {
> > > +       &dev_attr_id.attr,
> > > +       NULL
> > > +};
> > > +
> > > +ATTRIBUTE_GROUPS(pmu_sbi);
> > > +
> > >  static int pmu_sbi_device_probe(struct platform_device *pdev)
> > >  {
> > >         struct riscv_pmu *pmu = NULL;
> > > @@ -714,6 +736,14 @@ static int pmu_sbi_device_probe(struct
> > > platform_device *pdev) if (pmu_sbi_get_ctrinfo(num_counters))
> > >                 goto out_free;
> > >
> > > +       /* fill pmuid */
> > > +       pmu->pmuid = kasprintf(GFP_KERNEL, "0x%lx,0x%lx,0x%lx",
> > > +                              sbi_get_marchid(),
> > > +                              sbi_get_mimpid(),
> > > +                              sbi_get_mvendorid());
> > > +       if (!pmu->pmuid)
> > > +               goto out_free_pmuid;
> > > +
> > >         ret = pmu_sbi_setup_irqs(pmu, pdev);
> > >         if (ret < 0) {
> > >                 pr_info("Perf sampling/filtering is not supported
> > > as sscof extension is not available\n"); @@ -739,8 +769,19 @@
> > > static int pmu_sbi_device_probe(struct platform_device *pdev)
> > > return ret; }
> > >
> > > +       ret = sysfs_create_group(&pdev->dev.kobj, &pmu_sbi_group);
> > > +       if (ret) {
> > > +               dev_err(&pdev->dev, "sysfs creation failed\n");
> > > +               return ret;
> > > +       }
> > > +
> > > +       pdev->dev.groups = pmu_sbi_groups;
> > > +       dev_set_drvdata(&pdev->dev, pmu);
> > > +
> > >         return 0;
> > >
> > > +out_free_pmuid:
> > > +       kfree(pmu->pmuid);
> > >  out_free:
> > >         kfree(pmu);
> > >         return ret;
> > > diff --git a/include/linux/perf/riscv_pmu.h
> > > b/include/linux/perf/riscv_pmu.h index 46f9b6fe306e..cf3557b77fb8
> > > 100644 --- a/include/linux/perf/riscv_pmu.h
> > > +++ b/include/linux/perf/riscv_pmu.h
> > > @@ -42,6 +42,7 @@ struct cpu_hw_events {
> > >  struct riscv_pmu {
> > >         struct pmu      pmu;
> > >         char            *name;
> > > +       char            *pmuid;
> > >
> > >         irqreturn_t     (*handle_irq)(int irq_num, void *dev);
> > >
> > > --
> > > 2.35.1
> > >
>


-- 
Regards,
Atish

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v4 1/1] RISC-V: Create unique identification for SoC PMU
  2022-06-20 19:40         ` Atish Patra
  (?)
@ 2022-06-21  7:41           ` Nikita Shubin
  -1 siblings, 0 replies; 30+ messages in thread
From: Nikita Shubin @ 2022-06-21  7:41 UTC (permalink / raw)
  To: Atish Patra
  Cc: Anup Patel, Will Deacon, Sunil V L,
	João Mário Domingos, linux, Nikita Shubin,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Anup Patel,
	Mark Rutland, Geert Uytterhoeven, linux-riscv,
	linux-kernel@vger.kernel.org List, Linux ARM

Hello Anup!

On Mon, 20 Jun 2022 12:40:20 -0700
Atish Patra <atishp@atishpatra.org> wrote:

> On Mon, Jun 20, 2022 at 7:40 AM Nikita Shubin
> <nikita.shubin@maquefel.me> wrote:
> >
> > On Mon, 20 Jun 2022 17:30:58 +0530
> > Anup Patel <apatel@ventanamicro.com> wrote:
> >  
> > > On Sun, Jun 19, 2022 at 4:41 PM Nikita Shubin
> > > <nikita.shubin@maquefel.me> wrote:  
> > > >
> > > > From: Nikita Shubin <n.shubin@yadro.com>
> > > >
> > > > Provide RISC-V SBI PMU id to distinguish different cores or
> > > > SoCs via "devices/platform/riscv-pmu/id" sysfs entry.
> > > >
> > > > The identification is generated as string of marchid, mimpid,
> > > > mvendorid in hex format separated by coma -
> > > > "0x70032,0x70032,0x0".
> > > >
> > > > The CSRs are detailed in the RISC-V privileged spec [1].
> > > > [1] https://github.com/riscv/riscv-isa-manual
> > > >
> > > > Inspired-by: João Mário Domingos <joao.mario@tecnico.ulisboa.pt>
> > > > Signed-off-by: Nikita Shubin <n.shubin@yadro.com>  
> > >
> > > The mvendorid, marchid, and mimpid can be useful to apps other
> > > than perf tool.
> > >
> > > I have tried to extend /proc/cpuinfo with this information which
> > > can be parsed by perf tool:
> > > https://lore.kernel.org/all/20220620115549.1529597-1-apatel@ventanamicro.com/
> > >  
> >
> > Atish, what do you think about this ?
> >
> > RISC-V perf can rely on "/proc/cpuinfo", in some similar manner like
> > "tools/perf/arch/s390/util/header.c" does.
> >  
> 
> Yes. We can expose these three values either in sysfs or procfs
> (/proc/cpuinfo). For perf tool, it shouldn't matter as the header.c
> will need to generate the unique cpuid
> string from either.
> 
> I am not sure if any other userspace tool prefers to parse sysfs
> instead of cpuinfo.

Okay - let's stick to /proc/cpuinfo.

> 
> > Can it create problems with pmu identification in case of
> > hetergenous harts ?
> >  
> 
> Does perf support hetergenous harts at all ? ARM64 code
> (tool/perf/arch/arm64/util/header.c)
> just breaks out of the loop after finding the first MIDR.
> 
> > >
> > > Regards,
> > > Anup
> > >  
> > > > ---
> > > > v3->v4:
> > > > - use string for pmuid
> > > > - rename pmu_sbi_id_show to id_show
> > > > - fix error print message in id_show
> > > > - fix DEVICE_ATTR to use octal permissions
> > > > ---
> > > >  arch/riscv/kernel/sbi.c        |  3 +++
> > > >  drivers/perf/riscv_pmu_sbi.c   | 41
> > > > ++++++++++++++++++++++++++++++++++
> > > > include/linux/perf/riscv_pmu.h | 1 + 3 files changed, 45
> > > > insertions(+)
> > > >
> > > > diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c
> > > > index 775d3322b422..50dd9b6ecc9e 100644
> > > > --- a/arch/riscv/kernel/sbi.c
> > > > +++ b/arch/riscv/kernel/sbi.c
> > > > @@ -627,16 +627,19 @@ long sbi_get_mvendorid(void)
> > > >  {
> > > >         return __sbi_base_ecall(SBI_EXT_BASE_GET_MVENDORID);
> > > >  }
> > > > +EXPORT_SYMBOL(sbi_get_mvendorid);
> > > >
> > > >  long sbi_get_marchid(void)
> > > >  {
> > > >         return __sbi_base_ecall(SBI_EXT_BASE_GET_MARCHID);
> > > >  }
> > > > +EXPORT_SYMBOL(sbi_get_marchid);
> > > >
> > > >  long sbi_get_mimpid(void)
> > > >  {
> > > >         return __sbi_base_ecall(SBI_EXT_BASE_GET_MIMPID);
> > > >  }
> > > > +EXPORT_SYMBOL(sbi_get_mimpid);
> > > >
> > > >  static void sbi_send_cpumask_ipi(const struct cpumask *target)
> > > >  {
> > > > diff --git a/drivers/perf/riscv_pmu_sbi.c
> > > > b/drivers/perf/riscv_pmu_sbi.c index dca3537a8dcc..be812f855617
> > > > 100644 --- a/drivers/perf/riscv_pmu_sbi.c
> > > > +++ b/drivers/perf/riscv_pmu_sbi.c
> > > > @@ -693,6 +693,28 @@ static int pmu_sbi_setup_irqs(struct
> > > > riscv_pmu *pmu, struct platform_device *pde return 0;
> > > >  }
> > > >
> > > > +static ssize_t id_show(struct device *dev,
> > > > +                               struct device_attribute *attr,
> > > > char *buf) +{
> > > > +       int len;
> > > > +       struct riscv_pmu *pmu =
> > > > container_of(dev_get_drvdata(dev), struct riscv_pmu, pmu); +
> > > > +       len = sprintf(buf, "%s\n", pmu->pmuid);
> > > > +       if (len <= 0)
> > > > +               dev_err(dev, "invalid sprintf len: %d\n", len);
> > > > +
> > > > +       return len;
> > > > +}
> > > > +
> > > > +static DEVICE_ATTR(id, 0644, id_show, NULL);
> > > > +
> > > > +static struct attribute *pmu_sbi_attrs[] = {
> > > > +       &dev_attr_id.attr,
> > > > +       NULL
> > > > +};
> > > > +
> > > > +ATTRIBUTE_GROUPS(pmu_sbi);
> > > > +
> > > >  static int pmu_sbi_device_probe(struct platform_device *pdev)
> > > >  {
> > > >         struct riscv_pmu *pmu = NULL;
> > > > @@ -714,6 +736,14 @@ static int pmu_sbi_device_probe(struct
> > > > platform_device *pdev) if (pmu_sbi_get_ctrinfo(num_counters))
> > > >                 goto out_free;
> > > >
> > > > +       /* fill pmuid */
> > > > +       pmu->pmuid = kasprintf(GFP_KERNEL, "0x%lx,0x%lx,0x%lx",
> > > > +                              sbi_get_marchid(),
> > > > +                              sbi_get_mimpid(),
> > > > +                              sbi_get_mvendorid());
> > > > +       if (!pmu->pmuid)
> > > > +               goto out_free_pmuid;
> > > > +
> > > >         ret = pmu_sbi_setup_irqs(pmu, pdev);
> > > >         if (ret < 0) {
> > > >                 pr_info("Perf sampling/filtering is not
> > > > supported as sscof extension is not available\n"); @@ -739,8
> > > > +769,19 @@ static int pmu_sbi_device_probe(struct
> > > > platform_device *pdev) return ret; }
> > > >
> > > > +       ret = sysfs_create_group(&pdev->dev.kobj,
> > > > &pmu_sbi_group);
> > > > +       if (ret) {
> > > > +               dev_err(&pdev->dev, "sysfs creation failed\n");
> > > > +               return ret;
> > > > +       }
> > > > +
> > > > +       pdev->dev.groups = pmu_sbi_groups;
> > > > +       dev_set_drvdata(&pdev->dev, pmu);
> > > > +
> > > >         return 0;
> > > >
> > > > +out_free_pmuid:
> > > > +       kfree(pmu->pmuid);
> > > >  out_free:
> > > >         kfree(pmu);
> > > >         return ret;
> > > > diff --git a/include/linux/perf/riscv_pmu.h
> > > > b/include/linux/perf/riscv_pmu.h index
> > > > 46f9b6fe306e..cf3557b77fb8 100644 ---
> > > > a/include/linux/perf/riscv_pmu.h +++
> > > > b/include/linux/perf/riscv_pmu.h @@ -42,6 +42,7 @@ struct
> > > > cpu_hw_events { struct riscv_pmu {
> > > >         struct pmu      pmu;
> > > >         char            *name;
> > > > +       char            *pmuid;
> > > >
> > > >         irqreturn_t     (*handle_irq)(int irq_num, void *dev);
> > > >
> > > > --
> > > > 2.35.1
> > > >  
> >  
> 
> 


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v4 1/1] RISC-V: Create unique identification for SoC PMU
@ 2022-06-21  7:41           ` Nikita Shubin
  0 siblings, 0 replies; 30+ messages in thread
From: Nikita Shubin @ 2022-06-21  7:41 UTC (permalink / raw)
  To: Atish Patra
  Cc: Anup Patel, Will Deacon, Sunil V L,
	João Mário Domingos, linux, Nikita Shubin,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Anup Patel,
	Mark Rutland, Geert Uytterhoeven, linux-riscv,
	linux-kernel@vger.kernel.org List, Linux ARM

Hello Anup!

On Mon, 20 Jun 2022 12:40:20 -0700
Atish Patra <atishp@atishpatra.org> wrote:

> On Mon, Jun 20, 2022 at 7:40 AM Nikita Shubin
> <nikita.shubin@maquefel.me> wrote:
> >
> > On Mon, 20 Jun 2022 17:30:58 +0530
> > Anup Patel <apatel@ventanamicro.com> wrote:
> >  
> > > On Sun, Jun 19, 2022 at 4:41 PM Nikita Shubin
> > > <nikita.shubin@maquefel.me> wrote:  
> > > >
> > > > From: Nikita Shubin <n.shubin@yadro.com>
> > > >
> > > > Provide RISC-V SBI PMU id to distinguish different cores or
> > > > SoCs via "devices/platform/riscv-pmu/id" sysfs entry.
> > > >
> > > > The identification is generated as string of marchid, mimpid,
> > > > mvendorid in hex format separated by coma -
> > > > "0x70032,0x70032,0x0".
> > > >
> > > > The CSRs are detailed in the RISC-V privileged spec [1].
> > > > [1] https://github.com/riscv/riscv-isa-manual
> > > >
> > > > Inspired-by: João Mário Domingos <joao.mario@tecnico.ulisboa.pt>
> > > > Signed-off-by: Nikita Shubin <n.shubin@yadro.com>  
> > >
> > > The mvendorid, marchid, and mimpid can be useful to apps other
> > > than perf tool.
> > >
> > > I have tried to extend /proc/cpuinfo with this information which
> > > can be parsed by perf tool:
> > > https://lore.kernel.org/all/20220620115549.1529597-1-apatel@ventanamicro.com/
> > >  
> >
> > Atish, what do you think about this ?
> >
> > RISC-V perf can rely on "/proc/cpuinfo", in some similar manner like
> > "tools/perf/arch/s390/util/header.c" does.
> >  
> 
> Yes. We can expose these three values either in sysfs or procfs
> (/proc/cpuinfo). For perf tool, it shouldn't matter as the header.c
> will need to generate the unique cpuid
> string from either.
> 
> I am not sure if any other userspace tool prefers to parse sysfs
> instead of cpuinfo.

Okay - let's stick to /proc/cpuinfo.

> 
> > Can it create problems with pmu identification in case of
> > hetergenous harts ?
> >  
> 
> Does perf support hetergenous harts at all ? ARM64 code
> (tool/perf/arch/arm64/util/header.c)
> just breaks out of the loop after finding the first MIDR.
> 
> > >
> > > Regards,
> > > Anup
> > >  
> > > > ---
> > > > v3->v4:
> > > > - use string for pmuid
> > > > - rename pmu_sbi_id_show to id_show
> > > > - fix error print message in id_show
> > > > - fix DEVICE_ATTR to use octal permissions
> > > > ---
> > > >  arch/riscv/kernel/sbi.c        |  3 +++
> > > >  drivers/perf/riscv_pmu_sbi.c   | 41
> > > > ++++++++++++++++++++++++++++++++++
> > > > include/linux/perf/riscv_pmu.h | 1 + 3 files changed, 45
> > > > insertions(+)
> > > >
> > > > diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c
> > > > index 775d3322b422..50dd9b6ecc9e 100644
> > > > --- a/arch/riscv/kernel/sbi.c
> > > > +++ b/arch/riscv/kernel/sbi.c
> > > > @@ -627,16 +627,19 @@ long sbi_get_mvendorid(void)
> > > >  {
> > > >         return __sbi_base_ecall(SBI_EXT_BASE_GET_MVENDORID);
> > > >  }
> > > > +EXPORT_SYMBOL(sbi_get_mvendorid);
> > > >
> > > >  long sbi_get_marchid(void)
> > > >  {
> > > >         return __sbi_base_ecall(SBI_EXT_BASE_GET_MARCHID);
> > > >  }
> > > > +EXPORT_SYMBOL(sbi_get_marchid);
> > > >
> > > >  long sbi_get_mimpid(void)
> > > >  {
> > > >         return __sbi_base_ecall(SBI_EXT_BASE_GET_MIMPID);
> > > >  }
> > > > +EXPORT_SYMBOL(sbi_get_mimpid);
> > > >
> > > >  static void sbi_send_cpumask_ipi(const struct cpumask *target)
> > > >  {
> > > > diff --git a/drivers/perf/riscv_pmu_sbi.c
> > > > b/drivers/perf/riscv_pmu_sbi.c index dca3537a8dcc..be812f855617
> > > > 100644 --- a/drivers/perf/riscv_pmu_sbi.c
> > > > +++ b/drivers/perf/riscv_pmu_sbi.c
> > > > @@ -693,6 +693,28 @@ static int pmu_sbi_setup_irqs(struct
> > > > riscv_pmu *pmu, struct platform_device *pde return 0;
> > > >  }
> > > >
> > > > +static ssize_t id_show(struct device *dev,
> > > > +                               struct device_attribute *attr,
> > > > char *buf) +{
> > > > +       int len;
> > > > +       struct riscv_pmu *pmu =
> > > > container_of(dev_get_drvdata(dev), struct riscv_pmu, pmu); +
> > > > +       len = sprintf(buf, "%s\n", pmu->pmuid);
> > > > +       if (len <= 0)
> > > > +               dev_err(dev, "invalid sprintf len: %d\n", len);
> > > > +
> > > > +       return len;
> > > > +}
> > > > +
> > > > +static DEVICE_ATTR(id, 0644, id_show, NULL);
> > > > +
> > > > +static struct attribute *pmu_sbi_attrs[] = {
> > > > +       &dev_attr_id.attr,
> > > > +       NULL
> > > > +};
> > > > +
> > > > +ATTRIBUTE_GROUPS(pmu_sbi);
> > > > +
> > > >  static int pmu_sbi_device_probe(struct platform_device *pdev)
> > > >  {
> > > >         struct riscv_pmu *pmu = NULL;
> > > > @@ -714,6 +736,14 @@ static int pmu_sbi_device_probe(struct
> > > > platform_device *pdev) if (pmu_sbi_get_ctrinfo(num_counters))
> > > >                 goto out_free;
> > > >
> > > > +       /* fill pmuid */
> > > > +       pmu->pmuid = kasprintf(GFP_KERNEL, "0x%lx,0x%lx,0x%lx",
> > > > +                              sbi_get_marchid(),
> > > > +                              sbi_get_mimpid(),
> > > > +                              sbi_get_mvendorid());
> > > > +       if (!pmu->pmuid)
> > > > +               goto out_free_pmuid;
> > > > +
> > > >         ret = pmu_sbi_setup_irqs(pmu, pdev);
> > > >         if (ret < 0) {
> > > >                 pr_info("Perf sampling/filtering is not
> > > > supported as sscof extension is not available\n"); @@ -739,8
> > > > +769,19 @@ static int pmu_sbi_device_probe(struct
> > > > platform_device *pdev) return ret; }
> > > >
> > > > +       ret = sysfs_create_group(&pdev->dev.kobj,
> > > > &pmu_sbi_group);
> > > > +       if (ret) {
> > > > +               dev_err(&pdev->dev, "sysfs creation failed\n");
> > > > +               return ret;
> > > > +       }
> > > > +
> > > > +       pdev->dev.groups = pmu_sbi_groups;
> > > > +       dev_set_drvdata(&pdev->dev, pmu);
> > > > +
> > > >         return 0;
> > > >
> > > > +out_free_pmuid:
> > > > +       kfree(pmu->pmuid);
> > > >  out_free:
> > > >         kfree(pmu);
> > > >         return ret;
> > > > diff --git a/include/linux/perf/riscv_pmu.h
> > > > b/include/linux/perf/riscv_pmu.h index
> > > > 46f9b6fe306e..cf3557b77fb8 100644 ---
> > > > a/include/linux/perf/riscv_pmu.h +++
> > > > b/include/linux/perf/riscv_pmu.h @@ -42,6 +42,7 @@ struct
> > > > cpu_hw_events { struct riscv_pmu {
> > > >         struct pmu      pmu;
> > > >         char            *name;
> > > > +       char            *pmuid;
> > > >
> > > >         irqreturn_t     (*handle_irq)(int irq_num, void *dev);
> > > >
> > > > --
> > > > 2.35.1
> > > >  
> >  
> 
> 


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v4 1/1] RISC-V: Create unique identification for SoC PMU
@ 2022-06-21  7:41           ` Nikita Shubin
  0 siblings, 0 replies; 30+ messages in thread
From: Nikita Shubin @ 2022-06-21  7:41 UTC (permalink / raw)
  To: Atish Patra
  Cc: Anup Patel, Will Deacon, Sunil V L,
	João Mário Domingos, linux, Nikita Shubin,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Anup Patel,
	Mark Rutland, Geert Uytterhoeven, linux-riscv,
	linux-kernel@vger.kernel.org List, Linux ARM

Hello Anup!

On Mon, 20 Jun 2022 12:40:20 -0700
Atish Patra <atishp@atishpatra.org> wrote:

> On Mon, Jun 20, 2022 at 7:40 AM Nikita Shubin
> <nikita.shubin@maquefel.me> wrote:
> >
> > On Mon, 20 Jun 2022 17:30:58 +0530
> > Anup Patel <apatel@ventanamicro.com> wrote:
> >  
> > > On Sun, Jun 19, 2022 at 4:41 PM Nikita Shubin
> > > <nikita.shubin@maquefel.me> wrote:  
> > > >
> > > > From: Nikita Shubin <n.shubin@yadro.com>
> > > >
> > > > Provide RISC-V SBI PMU id to distinguish different cores or
> > > > SoCs via "devices/platform/riscv-pmu/id" sysfs entry.
> > > >
> > > > The identification is generated as string of marchid, mimpid,
> > > > mvendorid in hex format separated by coma -
> > > > "0x70032,0x70032,0x0".
> > > >
> > > > The CSRs are detailed in the RISC-V privileged spec [1].
> > > > [1] https://github.com/riscv/riscv-isa-manual
> > > >
> > > > Inspired-by: João Mário Domingos <joao.mario@tecnico.ulisboa.pt>
> > > > Signed-off-by: Nikita Shubin <n.shubin@yadro.com>  
> > >
> > > The mvendorid, marchid, and mimpid can be useful to apps other
> > > than perf tool.
> > >
> > > I have tried to extend /proc/cpuinfo with this information which
> > > can be parsed by perf tool:
> > > https://lore.kernel.org/all/20220620115549.1529597-1-apatel@ventanamicro.com/
> > >  
> >
> > Atish, what do you think about this ?
> >
> > RISC-V perf can rely on "/proc/cpuinfo", in some similar manner like
> > "tools/perf/arch/s390/util/header.c" does.
> >  
> 
> Yes. We can expose these three values either in sysfs or procfs
> (/proc/cpuinfo). For perf tool, it shouldn't matter as the header.c
> will need to generate the unique cpuid
> string from either.
> 
> I am not sure if any other userspace tool prefers to parse sysfs
> instead of cpuinfo.

Okay - let's stick to /proc/cpuinfo.

> 
> > Can it create problems with pmu identification in case of
> > hetergenous harts ?
> >  
> 
> Does perf support hetergenous harts at all ? ARM64 code
> (tool/perf/arch/arm64/util/header.c)
> just breaks out of the loop after finding the first MIDR.
> 
> > >
> > > Regards,
> > > Anup
> > >  
> > > > ---
> > > > v3->v4:
> > > > - use string for pmuid
> > > > - rename pmu_sbi_id_show to id_show
> > > > - fix error print message in id_show
> > > > - fix DEVICE_ATTR to use octal permissions
> > > > ---
> > > >  arch/riscv/kernel/sbi.c        |  3 +++
> > > >  drivers/perf/riscv_pmu_sbi.c   | 41
> > > > ++++++++++++++++++++++++++++++++++
> > > > include/linux/perf/riscv_pmu.h | 1 + 3 files changed, 45
> > > > insertions(+)
> > > >
> > > > diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c
> > > > index 775d3322b422..50dd9b6ecc9e 100644
> > > > --- a/arch/riscv/kernel/sbi.c
> > > > +++ b/arch/riscv/kernel/sbi.c
> > > > @@ -627,16 +627,19 @@ long sbi_get_mvendorid(void)
> > > >  {
> > > >         return __sbi_base_ecall(SBI_EXT_BASE_GET_MVENDORID);
> > > >  }
> > > > +EXPORT_SYMBOL(sbi_get_mvendorid);
> > > >
> > > >  long sbi_get_marchid(void)
> > > >  {
> > > >         return __sbi_base_ecall(SBI_EXT_BASE_GET_MARCHID);
> > > >  }
> > > > +EXPORT_SYMBOL(sbi_get_marchid);
> > > >
> > > >  long sbi_get_mimpid(void)
> > > >  {
> > > >         return __sbi_base_ecall(SBI_EXT_BASE_GET_MIMPID);
> > > >  }
> > > > +EXPORT_SYMBOL(sbi_get_mimpid);
> > > >
> > > >  static void sbi_send_cpumask_ipi(const struct cpumask *target)
> > > >  {
> > > > diff --git a/drivers/perf/riscv_pmu_sbi.c
> > > > b/drivers/perf/riscv_pmu_sbi.c index dca3537a8dcc..be812f855617
> > > > 100644 --- a/drivers/perf/riscv_pmu_sbi.c
> > > > +++ b/drivers/perf/riscv_pmu_sbi.c
> > > > @@ -693,6 +693,28 @@ static int pmu_sbi_setup_irqs(struct
> > > > riscv_pmu *pmu, struct platform_device *pde return 0;
> > > >  }
> > > >
> > > > +static ssize_t id_show(struct device *dev,
> > > > +                               struct device_attribute *attr,
> > > > char *buf) +{
> > > > +       int len;
> > > > +       struct riscv_pmu *pmu =
> > > > container_of(dev_get_drvdata(dev), struct riscv_pmu, pmu); +
> > > > +       len = sprintf(buf, "%s\n", pmu->pmuid);
> > > > +       if (len <= 0)
> > > > +               dev_err(dev, "invalid sprintf len: %d\n", len);
> > > > +
> > > > +       return len;
> > > > +}
> > > > +
> > > > +static DEVICE_ATTR(id, 0644, id_show, NULL);
> > > > +
> > > > +static struct attribute *pmu_sbi_attrs[] = {
> > > > +       &dev_attr_id.attr,
> > > > +       NULL
> > > > +};
> > > > +
> > > > +ATTRIBUTE_GROUPS(pmu_sbi);
> > > > +
> > > >  static int pmu_sbi_device_probe(struct platform_device *pdev)
> > > >  {
> > > >         struct riscv_pmu *pmu = NULL;
> > > > @@ -714,6 +736,14 @@ static int pmu_sbi_device_probe(struct
> > > > platform_device *pdev) if (pmu_sbi_get_ctrinfo(num_counters))
> > > >                 goto out_free;
> > > >
> > > > +       /* fill pmuid */
> > > > +       pmu->pmuid = kasprintf(GFP_KERNEL, "0x%lx,0x%lx,0x%lx",
> > > > +                              sbi_get_marchid(),
> > > > +                              sbi_get_mimpid(),
> > > > +                              sbi_get_mvendorid());
> > > > +       if (!pmu->pmuid)
> > > > +               goto out_free_pmuid;
> > > > +
> > > >         ret = pmu_sbi_setup_irqs(pmu, pdev);
> > > >         if (ret < 0) {
> > > >                 pr_info("Perf sampling/filtering is not
> > > > supported as sscof extension is not available\n"); @@ -739,8
> > > > +769,19 @@ static int pmu_sbi_device_probe(struct
> > > > platform_device *pdev) return ret; }
> > > >
> > > > +       ret = sysfs_create_group(&pdev->dev.kobj,
> > > > &pmu_sbi_group);
> > > > +       if (ret) {
> > > > +               dev_err(&pdev->dev, "sysfs creation failed\n");
> > > > +               return ret;
> > > > +       }
> > > > +
> > > > +       pdev->dev.groups = pmu_sbi_groups;
> > > > +       dev_set_drvdata(&pdev->dev, pmu);
> > > > +
> > > >         return 0;
> > > >
> > > > +out_free_pmuid:
> > > > +       kfree(pmu->pmuid);
> > > >  out_free:
> > > >         kfree(pmu);
> > > >         return ret;
> > > > diff --git a/include/linux/perf/riscv_pmu.h
> > > > b/include/linux/perf/riscv_pmu.h index
> > > > 46f9b6fe306e..cf3557b77fb8 100644 ---
> > > > a/include/linux/perf/riscv_pmu.h +++
> > > > b/include/linux/perf/riscv_pmu.h @@ -42,6 +42,7 @@ struct
> > > > cpu_hw_events { struct riscv_pmu {
> > > >         struct pmu      pmu;
> > > >         char            *name;
> > > > +       char            *pmuid;
> > > >
> > > >         irqreturn_t     (*handle_irq)(int irq_num, void *dev);
> > > >
> > > > --
> > > > 2.35.1
> > > >  
> >  
> 
> 


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v4 1/1] RISC-V: Create unique identification for SoC PMU
  2022-06-21  7:41           ` Nikita Shubin
  (?)
@ 2022-06-21  7:51             ` Anup Patel
  -1 siblings, 0 replies; 30+ messages in thread
From: Anup Patel @ 2022-06-21  7:51 UTC (permalink / raw)
  To: Nikita Shubin
  Cc: Atish Patra, Will Deacon, Sunil V L,
	João Mário Domingos, linux, Nikita Shubin,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Anup Patel,
	Mark Rutland, Geert Uytterhoeven, linux-riscv,
	linux-kernel@vger.kernel.org List, Linux ARM

On Tue, Jun 21, 2022 at 1:13 PM Nikita Shubin <nikita.shubin@maquefel.me> wrote:
>
> Hello Anup!
>
> On Mon, 20 Jun 2022 12:40:20 -0700
> Atish Patra <atishp@atishpatra.org> wrote:
>
> > On Mon, Jun 20, 2022 at 7:40 AM Nikita Shubin
> > <nikita.shubin@maquefel.me> wrote:
> > >
> > > On Mon, 20 Jun 2022 17:30:58 +0530
> > > Anup Patel <apatel@ventanamicro.com> wrote:
> > >
> > > > On Sun, Jun 19, 2022 at 4:41 PM Nikita Shubin
> > > > <nikita.shubin@maquefel.me> wrote:
> > > > >
> > > > > From: Nikita Shubin <n.shubin@yadro.com>
> > > > >
> > > > > Provide RISC-V SBI PMU id to distinguish different cores or
> > > > > SoCs via "devices/platform/riscv-pmu/id" sysfs entry.
> > > > >
> > > > > The identification is generated as string of marchid, mimpid,
> > > > > mvendorid in hex format separated by coma -
> > > > > "0x70032,0x70032,0x0".
> > > > >
> > > > > The CSRs are detailed in the RISC-V privileged spec [1].
> > > > > [1] https://github.com/riscv/riscv-isa-manual
> > > > >
> > > > > Inspired-by: João Mário Domingos <joao.mario@tecnico.ulisboa.pt>
> > > > > Signed-off-by: Nikita Shubin <n.shubin@yadro.com>
> > > >
> > > > The mvendorid, marchid, and mimpid can be useful to apps other
> > > > than perf tool.
> > > >
> > > > I have tried to extend /proc/cpuinfo with this information which
> > > > can be parsed by perf tool:
> > > > https://lore.kernel.org/all/20220620115549.1529597-1-apatel@ventanamicro.com/
> > > >
> > >
> > > Atish, what do you think about this ?
> > >
> > > RISC-V perf can rely on "/proc/cpuinfo", in some similar manner like
> > > "tools/perf/arch/s390/util/header.c" does.
> > >
> >
> > Yes. We can expose these three values either in sysfs or procfs
> > (/proc/cpuinfo). For perf tool, it shouldn't matter as the header.c
> > will need to generate the unique cpuid
> > string from either.
> >
> > I am not sure if any other userspace tool prefers to parse sysfs
> > instead of cpuinfo.
>
> Okay - let's stick to /proc/cpuinfo.

Sounds good.

You might have to write /proc/cpuinfo parsing code in perf tool
header.c. Do you plan to send v4 of perf tool patches ??

Regards,
Anup

>
> >
> > > Can it create problems with pmu identification in case of
> > > hetergenous harts ?
> > >
> >
> > Does perf support hetergenous harts at all ? ARM64 code
> > (tool/perf/arch/arm64/util/header.c)
> > just breaks out of the loop after finding the first MIDR.
> >
> > > >
> > > > Regards,
> > > > Anup
> > > >
> > > > > ---
> > > > > v3->v4:
> > > > > - use string for pmuid
> > > > > - rename pmu_sbi_id_show to id_show
> > > > > - fix error print message in id_show
> > > > > - fix DEVICE_ATTR to use octal permissions
> > > > > ---
> > > > >  arch/riscv/kernel/sbi.c        |  3 +++
> > > > >  drivers/perf/riscv_pmu_sbi.c   | 41
> > > > > ++++++++++++++++++++++++++++++++++
> > > > > include/linux/perf/riscv_pmu.h | 1 + 3 files changed, 45
> > > > > insertions(+)
> > > > >
> > > > > diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c
> > > > > index 775d3322b422..50dd9b6ecc9e 100644
> > > > > --- a/arch/riscv/kernel/sbi.c
> > > > > +++ b/arch/riscv/kernel/sbi.c
> > > > > @@ -627,16 +627,19 @@ long sbi_get_mvendorid(void)
> > > > >  {
> > > > >         return __sbi_base_ecall(SBI_EXT_BASE_GET_MVENDORID);
> > > > >  }
> > > > > +EXPORT_SYMBOL(sbi_get_mvendorid);
> > > > >
> > > > >  long sbi_get_marchid(void)
> > > > >  {
> > > > >         return __sbi_base_ecall(SBI_EXT_BASE_GET_MARCHID);
> > > > >  }
> > > > > +EXPORT_SYMBOL(sbi_get_marchid);
> > > > >
> > > > >  long sbi_get_mimpid(void)
> > > > >  {
> > > > >         return __sbi_base_ecall(SBI_EXT_BASE_GET_MIMPID);
> > > > >  }
> > > > > +EXPORT_SYMBOL(sbi_get_mimpid);
> > > > >
> > > > >  static void sbi_send_cpumask_ipi(const struct cpumask *target)
> > > > >  {
> > > > > diff --git a/drivers/perf/riscv_pmu_sbi.c
> > > > > b/drivers/perf/riscv_pmu_sbi.c index dca3537a8dcc..be812f855617
> > > > > 100644 --- a/drivers/perf/riscv_pmu_sbi.c
> > > > > +++ b/drivers/perf/riscv_pmu_sbi.c
> > > > > @@ -693,6 +693,28 @@ static int pmu_sbi_setup_irqs(struct
> > > > > riscv_pmu *pmu, struct platform_device *pde return 0;
> > > > >  }
> > > > >
> > > > > +static ssize_t id_show(struct device *dev,
> > > > > +                               struct device_attribute *attr,
> > > > > char *buf) +{
> > > > > +       int len;
> > > > > +       struct riscv_pmu *pmu =
> > > > > container_of(dev_get_drvdata(dev), struct riscv_pmu, pmu); +
> > > > > +       len = sprintf(buf, "%s\n", pmu->pmuid);
> > > > > +       if (len <= 0)
> > > > > +               dev_err(dev, "invalid sprintf len: %d\n", len);
> > > > > +
> > > > > +       return len;
> > > > > +}
> > > > > +
> > > > > +static DEVICE_ATTR(id, 0644, id_show, NULL);
> > > > > +
> > > > > +static struct attribute *pmu_sbi_attrs[] = {
> > > > > +       &dev_attr_id.attr,
> > > > > +       NULL
> > > > > +};
> > > > > +
> > > > > +ATTRIBUTE_GROUPS(pmu_sbi);
> > > > > +
> > > > >  static int pmu_sbi_device_probe(struct platform_device *pdev)
> > > > >  {
> > > > >         struct riscv_pmu *pmu = NULL;
> > > > > @@ -714,6 +736,14 @@ static int pmu_sbi_device_probe(struct
> > > > > platform_device *pdev) if (pmu_sbi_get_ctrinfo(num_counters))
> > > > >                 goto out_free;
> > > > >
> > > > > +       /* fill pmuid */
> > > > > +       pmu->pmuid = kasprintf(GFP_KERNEL, "0x%lx,0x%lx,0x%lx",
> > > > > +                              sbi_get_marchid(),
> > > > > +                              sbi_get_mimpid(),
> > > > > +                              sbi_get_mvendorid());
> > > > > +       if (!pmu->pmuid)
> > > > > +               goto out_free_pmuid;
> > > > > +
> > > > >         ret = pmu_sbi_setup_irqs(pmu, pdev);
> > > > >         if (ret < 0) {
> > > > >                 pr_info("Perf sampling/filtering is not
> > > > > supported as sscof extension is not available\n"); @@ -739,8
> > > > > +769,19 @@ static int pmu_sbi_device_probe(struct
> > > > > platform_device *pdev) return ret; }
> > > > >
> > > > > +       ret = sysfs_create_group(&pdev->dev.kobj,
> > > > > &pmu_sbi_group);
> > > > > +       if (ret) {
> > > > > +               dev_err(&pdev->dev, "sysfs creation failed\n");
> > > > > +               return ret;
> > > > > +       }
> > > > > +
> > > > > +       pdev->dev.groups = pmu_sbi_groups;
> > > > > +       dev_set_drvdata(&pdev->dev, pmu);
> > > > > +
> > > > >         return 0;
> > > > >
> > > > > +out_free_pmuid:
> > > > > +       kfree(pmu->pmuid);
> > > > >  out_free:
> > > > >         kfree(pmu);
> > > > >         return ret;
> > > > > diff --git a/include/linux/perf/riscv_pmu.h
> > > > > b/include/linux/perf/riscv_pmu.h index
> > > > > 46f9b6fe306e..cf3557b77fb8 100644 ---
> > > > > a/include/linux/perf/riscv_pmu.h +++
> > > > > b/include/linux/perf/riscv_pmu.h @@ -42,6 +42,7 @@ struct
> > > > > cpu_hw_events { struct riscv_pmu {
> > > > >         struct pmu      pmu;
> > > > >         char            *name;
> > > > > +       char            *pmuid;
> > > > >
> > > > >         irqreturn_t     (*handle_irq)(int irq_num, void *dev);
> > > > >
> > > > > --
> > > > > 2.35.1
> > > > >
> > >
> >
> >
>

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v4 1/1] RISC-V: Create unique identification for SoC PMU
@ 2022-06-21  7:51             ` Anup Patel
  0 siblings, 0 replies; 30+ messages in thread
From: Anup Patel @ 2022-06-21  7:51 UTC (permalink / raw)
  To: Nikita Shubin
  Cc: Atish Patra, Will Deacon, Sunil V L,
	João Mário Domingos, linux, Nikita Shubin,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Anup Patel,
	Mark Rutland, Geert Uytterhoeven, linux-riscv,
	linux-kernel@vger.kernel.org List, Linux ARM

On Tue, Jun 21, 2022 at 1:13 PM Nikita Shubin <nikita.shubin@maquefel.me> wrote:
>
> Hello Anup!
>
> On Mon, 20 Jun 2022 12:40:20 -0700
> Atish Patra <atishp@atishpatra.org> wrote:
>
> > On Mon, Jun 20, 2022 at 7:40 AM Nikita Shubin
> > <nikita.shubin@maquefel.me> wrote:
> > >
> > > On Mon, 20 Jun 2022 17:30:58 +0530
> > > Anup Patel <apatel@ventanamicro.com> wrote:
> > >
> > > > On Sun, Jun 19, 2022 at 4:41 PM Nikita Shubin
> > > > <nikita.shubin@maquefel.me> wrote:
> > > > >
> > > > > From: Nikita Shubin <n.shubin@yadro.com>
> > > > >
> > > > > Provide RISC-V SBI PMU id to distinguish different cores or
> > > > > SoCs via "devices/platform/riscv-pmu/id" sysfs entry.
> > > > >
> > > > > The identification is generated as string of marchid, mimpid,
> > > > > mvendorid in hex format separated by coma -
> > > > > "0x70032,0x70032,0x0".
> > > > >
> > > > > The CSRs are detailed in the RISC-V privileged spec [1].
> > > > > [1] https://github.com/riscv/riscv-isa-manual
> > > > >
> > > > > Inspired-by: João Mário Domingos <joao.mario@tecnico.ulisboa.pt>
> > > > > Signed-off-by: Nikita Shubin <n.shubin@yadro.com>
> > > >
> > > > The mvendorid, marchid, and mimpid can be useful to apps other
> > > > than perf tool.
> > > >
> > > > I have tried to extend /proc/cpuinfo with this information which
> > > > can be parsed by perf tool:
> > > > https://lore.kernel.org/all/20220620115549.1529597-1-apatel@ventanamicro.com/
> > > >
> > >
> > > Atish, what do you think about this ?
> > >
> > > RISC-V perf can rely on "/proc/cpuinfo", in some similar manner like
> > > "tools/perf/arch/s390/util/header.c" does.
> > >
> >
> > Yes. We can expose these three values either in sysfs or procfs
> > (/proc/cpuinfo). For perf tool, it shouldn't matter as the header.c
> > will need to generate the unique cpuid
> > string from either.
> >
> > I am not sure if any other userspace tool prefers to parse sysfs
> > instead of cpuinfo.
>
> Okay - let's stick to /proc/cpuinfo.

Sounds good.

You might have to write /proc/cpuinfo parsing code in perf tool
header.c. Do you plan to send v4 of perf tool patches ??

Regards,
Anup

>
> >
> > > Can it create problems with pmu identification in case of
> > > hetergenous harts ?
> > >
> >
> > Does perf support hetergenous harts at all ? ARM64 code
> > (tool/perf/arch/arm64/util/header.c)
> > just breaks out of the loop after finding the first MIDR.
> >
> > > >
> > > > Regards,
> > > > Anup
> > > >
> > > > > ---
> > > > > v3->v4:
> > > > > - use string for pmuid
> > > > > - rename pmu_sbi_id_show to id_show
> > > > > - fix error print message in id_show
> > > > > - fix DEVICE_ATTR to use octal permissions
> > > > > ---
> > > > >  arch/riscv/kernel/sbi.c        |  3 +++
> > > > >  drivers/perf/riscv_pmu_sbi.c   | 41
> > > > > ++++++++++++++++++++++++++++++++++
> > > > > include/linux/perf/riscv_pmu.h | 1 + 3 files changed, 45
> > > > > insertions(+)
> > > > >
> > > > > diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c
> > > > > index 775d3322b422..50dd9b6ecc9e 100644
> > > > > --- a/arch/riscv/kernel/sbi.c
> > > > > +++ b/arch/riscv/kernel/sbi.c
> > > > > @@ -627,16 +627,19 @@ long sbi_get_mvendorid(void)
> > > > >  {
> > > > >         return __sbi_base_ecall(SBI_EXT_BASE_GET_MVENDORID);
> > > > >  }
> > > > > +EXPORT_SYMBOL(sbi_get_mvendorid);
> > > > >
> > > > >  long sbi_get_marchid(void)
> > > > >  {
> > > > >         return __sbi_base_ecall(SBI_EXT_BASE_GET_MARCHID);
> > > > >  }
> > > > > +EXPORT_SYMBOL(sbi_get_marchid);
> > > > >
> > > > >  long sbi_get_mimpid(void)
> > > > >  {
> > > > >         return __sbi_base_ecall(SBI_EXT_BASE_GET_MIMPID);
> > > > >  }
> > > > > +EXPORT_SYMBOL(sbi_get_mimpid);
> > > > >
> > > > >  static void sbi_send_cpumask_ipi(const struct cpumask *target)
> > > > >  {
> > > > > diff --git a/drivers/perf/riscv_pmu_sbi.c
> > > > > b/drivers/perf/riscv_pmu_sbi.c index dca3537a8dcc..be812f855617
> > > > > 100644 --- a/drivers/perf/riscv_pmu_sbi.c
> > > > > +++ b/drivers/perf/riscv_pmu_sbi.c
> > > > > @@ -693,6 +693,28 @@ static int pmu_sbi_setup_irqs(struct
> > > > > riscv_pmu *pmu, struct platform_device *pde return 0;
> > > > >  }
> > > > >
> > > > > +static ssize_t id_show(struct device *dev,
> > > > > +                               struct device_attribute *attr,
> > > > > char *buf) +{
> > > > > +       int len;
> > > > > +       struct riscv_pmu *pmu =
> > > > > container_of(dev_get_drvdata(dev), struct riscv_pmu, pmu); +
> > > > > +       len = sprintf(buf, "%s\n", pmu->pmuid);
> > > > > +       if (len <= 0)
> > > > > +               dev_err(dev, "invalid sprintf len: %d\n", len);
> > > > > +
> > > > > +       return len;
> > > > > +}
> > > > > +
> > > > > +static DEVICE_ATTR(id, 0644, id_show, NULL);
> > > > > +
> > > > > +static struct attribute *pmu_sbi_attrs[] = {
> > > > > +       &dev_attr_id.attr,
> > > > > +       NULL
> > > > > +};
> > > > > +
> > > > > +ATTRIBUTE_GROUPS(pmu_sbi);
> > > > > +
> > > > >  static int pmu_sbi_device_probe(struct platform_device *pdev)
> > > > >  {
> > > > >         struct riscv_pmu *pmu = NULL;
> > > > > @@ -714,6 +736,14 @@ static int pmu_sbi_device_probe(struct
> > > > > platform_device *pdev) if (pmu_sbi_get_ctrinfo(num_counters))
> > > > >                 goto out_free;
> > > > >
> > > > > +       /* fill pmuid */
> > > > > +       pmu->pmuid = kasprintf(GFP_KERNEL, "0x%lx,0x%lx,0x%lx",
> > > > > +                              sbi_get_marchid(),
> > > > > +                              sbi_get_mimpid(),
> > > > > +                              sbi_get_mvendorid());
> > > > > +       if (!pmu->pmuid)
> > > > > +               goto out_free_pmuid;
> > > > > +
> > > > >         ret = pmu_sbi_setup_irqs(pmu, pdev);
> > > > >         if (ret < 0) {
> > > > >                 pr_info("Perf sampling/filtering is not
> > > > > supported as sscof extension is not available\n"); @@ -739,8
> > > > > +769,19 @@ static int pmu_sbi_device_probe(struct
> > > > > platform_device *pdev) return ret; }
> > > > >
> > > > > +       ret = sysfs_create_group(&pdev->dev.kobj,
> > > > > &pmu_sbi_group);
> > > > > +       if (ret) {
> > > > > +               dev_err(&pdev->dev, "sysfs creation failed\n");
> > > > > +               return ret;
> > > > > +       }
> > > > > +
> > > > > +       pdev->dev.groups = pmu_sbi_groups;
> > > > > +       dev_set_drvdata(&pdev->dev, pmu);
> > > > > +
> > > > >         return 0;
> > > > >
> > > > > +out_free_pmuid:
> > > > > +       kfree(pmu->pmuid);
> > > > >  out_free:
> > > > >         kfree(pmu);
> > > > >         return ret;
> > > > > diff --git a/include/linux/perf/riscv_pmu.h
> > > > > b/include/linux/perf/riscv_pmu.h index
> > > > > 46f9b6fe306e..cf3557b77fb8 100644 ---
> > > > > a/include/linux/perf/riscv_pmu.h +++
> > > > > b/include/linux/perf/riscv_pmu.h @@ -42,6 +42,7 @@ struct
> > > > > cpu_hw_events { struct riscv_pmu {
> > > > >         struct pmu      pmu;
> > > > >         char            *name;
> > > > > +       char            *pmuid;
> > > > >
> > > > >         irqreturn_t     (*handle_irq)(int irq_num, void *dev);
> > > > >
> > > > > --
> > > > > 2.35.1
> > > > >
> > >
> >
> >
>

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v4 1/1] RISC-V: Create unique identification for SoC PMU
@ 2022-06-21  7:51             ` Anup Patel
  0 siblings, 0 replies; 30+ messages in thread
From: Anup Patel @ 2022-06-21  7:51 UTC (permalink / raw)
  To: Nikita Shubin
  Cc: Atish Patra, Will Deacon, Sunil V L,
	João Mário Domingos, linux, Nikita Shubin,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Anup Patel,
	Mark Rutland, Geert Uytterhoeven, linux-riscv,
	linux-kernel@vger.kernel.org List, Linux ARM

On Tue, Jun 21, 2022 at 1:13 PM Nikita Shubin <nikita.shubin@maquefel.me> wrote:
>
> Hello Anup!
>
> On Mon, 20 Jun 2022 12:40:20 -0700
> Atish Patra <atishp@atishpatra.org> wrote:
>
> > On Mon, Jun 20, 2022 at 7:40 AM Nikita Shubin
> > <nikita.shubin@maquefel.me> wrote:
> > >
> > > On Mon, 20 Jun 2022 17:30:58 +0530
> > > Anup Patel <apatel@ventanamicro.com> wrote:
> > >
> > > > On Sun, Jun 19, 2022 at 4:41 PM Nikita Shubin
> > > > <nikita.shubin@maquefel.me> wrote:
> > > > >
> > > > > From: Nikita Shubin <n.shubin@yadro.com>
> > > > >
> > > > > Provide RISC-V SBI PMU id to distinguish different cores or
> > > > > SoCs via "devices/platform/riscv-pmu/id" sysfs entry.
> > > > >
> > > > > The identification is generated as string of marchid, mimpid,
> > > > > mvendorid in hex format separated by coma -
> > > > > "0x70032,0x70032,0x0".
> > > > >
> > > > > The CSRs are detailed in the RISC-V privileged spec [1].
> > > > > [1] https://github.com/riscv/riscv-isa-manual
> > > > >
> > > > > Inspired-by: João Mário Domingos <joao.mario@tecnico.ulisboa.pt>
> > > > > Signed-off-by: Nikita Shubin <n.shubin@yadro.com>
> > > >
> > > > The mvendorid, marchid, and mimpid can be useful to apps other
> > > > than perf tool.
> > > >
> > > > I have tried to extend /proc/cpuinfo with this information which
> > > > can be parsed by perf tool:
> > > > https://lore.kernel.org/all/20220620115549.1529597-1-apatel@ventanamicro.com/
> > > >
> > >
> > > Atish, what do you think about this ?
> > >
> > > RISC-V perf can rely on "/proc/cpuinfo", in some similar manner like
> > > "tools/perf/arch/s390/util/header.c" does.
> > >
> >
> > Yes. We can expose these three values either in sysfs or procfs
> > (/proc/cpuinfo). For perf tool, it shouldn't matter as the header.c
> > will need to generate the unique cpuid
> > string from either.
> >
> > I am not sure if any other userspace tool prefers to parse sysfs
> > instead of cpuinfo.
>
> Okay - let's stick to /proc/cpuinfo.

Sounds good.

You might have to write /proc/cpuinfo parsing code in perf tool
header.c. Do you plan to send v4 of perf tool patches ??

Regards,
Anup

>
> >
> > > Can it create problems with pmu identification in case of
> > > hetergenous harts ?
> > >
> >
> > Does perf support hetergenous harts at all ? ARM64 code
> > (tool/perf/arch/arm64/util/header.c)
> > just breaks out of the loop after finding the first MIDR.
> >
> > > >
> > > > Regards,
> > > > Anup
> > > >
> > > > > ---
> > > > > v3->v4:
> > > > > - use string for pmuid
> > > > > - rename pmu_sbi_id_show to id_show
> > > > > - fix error print message in id_show
> > > > > - fix DEVICE_ATTR to use octal permissions
> > > > > ---
> > > > >  arch/riscv/kernel/sbi.c        |  3 +++
> > > > >  drivers/perf/riscv_pmu_sbi.c   | 41
> > > > > ++++++++++++++++++++++++++++++++++
> > > > > include/linux/perf/riscv_pmu.h | 1 + 3 files changed, 45
> > > > > insertions(+)
> > > > >
> > > > > diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c
> > > > > index 775d3322b422..50dd9b6ecc9e 100644
> > > > > --- a/arch/riscv/kernel/sbi.c
> > > > > +++ b/arch/riscv/kernel/sbi.c
> > > > > @@ -627,16 +627,19 @@ long sbi_get_mvendorid(void)
> > > > >  {
> > > > >         return __sbi_base_ecall(SBI_EXT_BASE_GET_MVENDORID);
> > > > >  }
> > > > > +EXPORT_SYMBOL(sbi_get_mvendorid);
> > > > >
> > > > >  long sbi_get_marchid(void)
> > > > >  {
> > > > >         return __sbi_base_ecall(SBI_EXT_BASE_GET_MARCHID);
> > > > >  }
> > > > > +EXPORT_SYMBOL(sbi_get_marchid);
> > > > >
> > > > >  long sbi_get_mimpid(void)
> > > > >  {
> > > > >         return __sbi_base_ecall(SBI_EXT_BASE_GET_MIMPID);
> > > > >  }
> > > > > +EXPORT_SYMBOL(sbi_get_mimpid);
> > > > >
> > > > >  static void sbi_send_cpumask_ipi(const struct cpumask *target)
> > > > >  {
> > > > > diff --git a/drivers/perf/riscv_pmu_sbi.c
> > > > > b/drivers/perf/riscv_pmu_sbi.c index dca3537a8dcc..be812f855617
> > > > > 100644 --- a/drivers/perf/riscv_pmu_sbi.c
> > > > > +++ b/drivers/perf/riscv_pmu_sbi.c
> > > > > @@ -693,6 +693,28 @@ static int pmu_sbi_setup_irqs(struct
> > > > > riscv_pmu *pmu, struct platform_device *pde return 0;
> > > > >  }
> > > > >
> > > > > +static ssize_t id_show(struct device *dev,
> > > > > +                               struct device_attribute *attr,
> > > > > char *buf) +{
> > > > > +       int len;
> > > > > +       struct riscv_pmu *pmu =
> > > > > container_of(dev_get_drvdata(dev), struct riscv_pmu, pmu); +
> > > > > +       len = sprintf(buf, "%s\n", pmu->pmuid);
> > > > > +       if (len <= 0)
> > > > > +               dev_err(dev, "invalid sprintf len: %d\n", len);
> > > > > +
> > > > > +       return len;
> > > > > +}
> > > > > +
> > > > > +static DEVICE_ATTR(id, 0644, id_show, NULL);
> > > > > +
> > > > > +static struct attribute *pmu_sbi_attrs[] = {
> > > > > +       &dev_attr_id.attr,
> > > > > +       NULL
> > > > > +};
> > > > > +
> > > > > +ATTRIBUTE_GROUPS(pmu_sbi);
> > > > > +
> > > > >  static int pmu_sbi_device_probe(struct platform_device *pdev)
> > > > >  {
> > > > >         struct riscv_pmu *pmu = NULL;
> > > > > @@ -714,6 +736,14 @@ static int pmu_sbi_device_probe(struct
> > > > > platform_device *pdev) if (pmu_sbi_get_ctrinfo(num_counters))
> > > > >                 goto out_free;
> > > > >
> > > > > +       /* fill pmuid */
> > > > > +       pmu->pmuid = kasprintf(GFP_KERNEL, "0x%lx,0x%lx,0x%lx",
> > > > > +                              sbi_get_marchid(),
> > > > > +                              sbi_get_mimpid(),
> > > > > +                              sbi_get_mvendorid());
> > > > > +       if (!pmu->pmuid)
> > > > > +               goto out_free_pmuid;
> > > > > +
> > > > >         ret = pmu_sbi_setup_irqs(pmu, pdev);
> > > > >         if (ret < 0) {
> > > > >                 pr_info("Perf sampling/filtering is not
> > > > > supported as sscof extension is not available\n"); @@ -739,8
> > > > > +769,19 @@ static int pmu_sbi_device_probe(struct
> > > > > platform_device *pdev) return ret; }
> > > > >
> > > > > +       ret = sysfs_create_group(&pdev->dev.kobj,
> > > > > &pmu_sbi_group);
> > > > > +       if (ret) {
> > > > > +               dev_err(&pdev->dev, "sysfs creation failed\n");
> > > > > +               return ret;
> > > > > +       }
> > > > > +
> > > > > +       pdev->dev.groups = pmu_sbi_groups;
> > > > > +       dev_set_drvdata(&pdev->dev, pmu);
> > > > > +
> > > > >         return 0;
> > > > >
> > > > > +out_free_pmuid:
> > > > > +       kfree(pmu->pmuid);
> > > > >  out_free:
> > > > >         kfree(pmu);
> > > > >         return ret;
> > > > > diff --git a/include/linux/perf/riscv_pmu.h
> > > > > b/include/linux/perf/riscv_pmu.h index
> > > > > 46f9b6fe306e..cf3557b77fb8 100644 ---
> > > > > a/include/linux/perf/riscv_pmu.h +++
> > > > > b/include/linux/perf/riscv_pmu.h @@ -42,6 +42,7 @@ struct
> > > > > cpu_hw_events { struct riscv_pmu {
> > > > >         struct pmu      pmu;
> > > > >         char            *name;
> > > > > +       char            *pmuid;
> > > > >
> > > > >         irqreturn_t     (*handle_irq)(int irq_num, void *dev);
> > > > >
> > > > > --
> > > > > 2.35.1
> > > > >
> > >
> >
> >
>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v4 1/1] RISC-V: Create unique identification for SoC PMU
  2022-06-21  7:51             ` Anup Patel
  (?)
@ 2022-06-21  7:59               ` Nikita Shubin
  -1 siblings, 0 replies; 30+ messages in thread
From: Nikita Shubin @ 2022-06-21  7:59 UTC (permalink / raw)
  To: Anup Patel
  Cc: Atish Patra, Will Deacon, Sunil V L,
	João Mário Domingos, linux, Nikita Shubin,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Anup Patel,
	Mark Rutland, Geert Uytterhoeven, linux-riscv,
	linux-kernel@vger.kernel.org List, Linux ARM

Hello Anup!

On Tue, 21 Jun 2022 13:21:11 +0530
Anup Patel <apatel@ventanamicro.com> wrote:

> On Tue, Jun 21, 2022 at 1:13 PM Nikita Shubin
> <nikita.shubin@maquefel.me> wrote:
> >
> > Hello Anup!
> >
> > On Mon, 20 Jun 2022 12:40:20 -0700
> > Atish Patra <atishp@atishpatra.org> wrote:
> >  
> > > On Mon, Jun 20, 2022 at 7:40 AM Nikita Shubin
> > > <nikita.shubin@maquefel.me> wrote:  
> > > >
> > > > On Mon, 20 Jun 2022 17:30:58 +0530
> > > > Anup Patel <apatel@ventanamicro.com> wrote:
> > > >  
> > > > > On Sun, Jun 19, 2022 at 4:41 PM Nikita Shubin
> > > > > <nikita.shubin@maquefel.me> wrote:  
> > > > > >
> > > > > > From: Nikita Shubin <n.shubin@yadro.com>
> > > > > >
> > > > > > Provide RISC-V SBI PMU id to distinguish different cores or
> > > > > > SoCs via "devices/platform/riscv-pmu/id" sysfs entry.
> > > > > >
> > > > > > The identification is generated as string of marchid,
> > > > > > mimpid, mvendorid in hex format separated by coma -
> > > > > > "0x70032,0x70032,0x0".
> > > > > >
> > > > > > The CSRs are detailed in the RISC-V privileged spec [1].
> > > > > > [1] https://github.com/riscv/riscv-isa-manual
> > > > > >
> > > > > > Inspired-by: João Mário Domingos
> > > > > > <joao.mario@tecnico.ulisboa.pt> Signed-off-by: Nikita
> > > > > > Shubin <n.shubin@yadro.com>  
> > > > >
> > > > > The mvendorid, marchid, and mimpid can be useful to apps other
> > > > > than perf tool.
> > > > >
> > > > > I have tried to extend /proc/cpuinfo with this information
> > > > > which can be parsed by perf tool:
> > > > > https://lore.kernel.org/all/20220620115549.1529597-1-apatel@ventanamicro.com/
> > > > >  
> > > >
> > > > Atish, what do you think about this ?
> > > >
> > > > RISC-V perf can rely on "/proc/cpuinfo", in some similar manner
> > > > like "tools/perf/arch/s390/util/header.c" does.
> > > >  
> > >
> > > Yes. We can expose these three values either in sysfs or procfs
> > > (/proc/cpuinfo). For perf tool, it shouldn't matter as the
> > > header.c will need to generate the unique cpuid
> > > string from either.
> > >
> > > I am not sure if any other userspace tool prefers to parse sysfs
> > > instead of cpuinfo.  
> >
> > Okay - let's stick to /proc/cpuinfo.  
> 
> Sounds good.
> 
> You might have to write /proc/cpuinfo parsing code in perf tool
> header.c. Do you plan to send v4 of perf tool patches ??

Yes, but i might split it into separate series, not to mix perf headers
and U74 pmu-events bindings, i ll also add some SBI firmware event
bindings to make things easier.

> 
> Regards,
> Anup
> 
> >  
> > >  
> > > > Can it create problems with pmu identification in case of
> > > > hetergenous harts ?
> > > >  
> > >
> > > Does perf support hetergenous harts at all ? ARM64 code
> > > (tool/perf/arch/arm64/util/header.c)
> > > just breaks out of the loop after finding the first MIDR.
> > >  
> > > > >
> > > > > Regards,
> > > > > Anup
> > > > >  
> > > > > > ---
> > > > > > v3->v4:
> > > > > > - use string for pmuid
> > > > > > - rename pmu_sbi_id_show to id_show
> > > > > > - fix error print message in id_show
> > > > > > - fix DEVICE_ATTR to use octal permissions
> > > > > > ---
> > > > > >  arch/riscv/kernel/sbi.c        |  3 +++
> > > > > >  drivers/perf/riscv_pmu_sbi.c   | 41
> > > > > > ++++++++++++++++++++++++++++++++++
> > > > > > include/linux/perf/riscv_pmu.h | 1 + 3 files changed, 45
> > > > > > insertions(+)
> > > > > >
> > > > > > diff --git a/arch/riscv/kernel/sbi.c
> > > > > > b/arch/riscv/kernel/sbi.c index 775d3322b422..50dd9b6ecc9e
> > > > > > 100644 --- a/arch/riscv/kernel/sbi.c
> > > > > > +++ b/arch/riscv/kernel/sbi.c
> > > > > > @@ -627,16 +627,19 @@ long sbi_get_mvendorid(void)
> > > > > >  {
> > > > > >         return __sbi_base_ecall(SBI_EXT_BASE_GET_MVENDORID);
> > > > > >  }
> > > > > > +EXPORT_SYMBOL(sbi_get_mvendorid);
> > > > > >
> > > > > >  long sbi_get_marchid(void)
> > > > > >  {
> > > > > >         return __sbi_base_ecall(SBI_EXT_BASE_GET_MARCHID);
> > > > > >  }
> > > > > > +EXPORT_SYMBOL(sbi_get_marchid);
> > > > > >
> > > > > >  long sbi_get_mimpid(void)
> > > > > >  {
> > > > > >         return __sbi_base_ecall(SBI_EXT_BASE_GET_MIMPID);
> > > > > >  }
> > > > > > +EXPORT_SYMBOL(sbi_get_mimpid);
> > > > > >
> > > > > >  static void sbi_send_cpumask_ipi(const struct cpumask
> > > > > > *target) {
> > > > > > diff --git a/drivers/perf/riscv_pmu_sbi.c
> > > > > > b/drivers/perf/riscv_pmu_sbi.c index
> > > > > > dca3537a8dcc..be812f855617 100644 ---
> > > > > > a/drivers/perf/riscv_pmu_sbi.c +++
> > > > > > b/drivers/perf/riscv_pmu_sbi.c @@ -693,6 +693,28 @@ static
> > > > > > int pmu_sbi_setup_irqs(struct riscv_pmu *pmu, struct
> > > > > > platform_device *pde return 0; }
> > > > > >
> > > > > > +static ssize_t id_show(struct device *dev,
> > > > > > +                               struct device_attribute
> > > > > > *attr, char *buf) +{
> > > > > > +       int len;
> > > > > > +       struct riscv_pmu *pmu =
> > > > > > container_of(dev_get_drvdata(dev), struct riscv_pmu, pmu); +
> > > > > > +       len = sprintf(buf, "%s\n", pmu->pmuid);
> > > > > > +       if (len <= 0)
> > > > > > +               dev_err(dev, "invalid sprintf len: %d\n",
> > > > > > len); +
> > > > > > +       return len;
> > > > > > +}
> > > > > > +
> > > > > > +static DEVICE_ATTR(id, 0644, id_show, NULL);
> > > > > > +
> > > > > > +static struct attribute *pmu_sbi_attrs[] = {
> > > > > > +       &dev_attr_id.attr,
> > > > > > +       NULL
> > > > > > +};
> > > > > > +
> > > > > > +ATTRIBUTE_GROUPS(pmu_sbi);
> > > > > > +
> > > > > >  static int pmu_sbi_device_probe(struct platform_device
> > > > > > *pdev) {
> > > > > >         struct riscv_pmu *pmu = NULL;
> > > > > > @@ -714,6 +736,14 @@ static int pmu_sbi_device_probe(struct
> > > > > > platform_device *pdev) if
> > > > > > (pmu_sbi_get_ctrinfo(num_counters)) goto out_free;
> > > > > >
> > > > > > +       /* fill pmuid */
> > > > > > +       pmu->pmuid = kasprintf(GFP_KERNEL,
> > > > > > "0x%lx,0x%lx,0x%lx",
> > > > > > +                              sbi_get_marchid(),
> > > > > > +                              sbi_get_mimpid(),
> > > > > > +                              sbi_get_mvendorid());
> > > > > > +       if (!pmu->pmuid)
> > > > > > +               goto out_free_pmuid;
> > > > > > +
> > > > > >         ret = pmu_sbi_setup_irqs(pmu, pdev);
> > > > > >         if (ret < 0) {
> > > > > >                 pr_info("Perf sampling/filtering is not
> > > > > > supported as sscof extension is not available\n"); @@ -739,8
> > > > > > +769,19 @@ static int pmu_sbi_device_probe(struct
> > > > > > platform_device *pdev) return ret; }
> > > > > >
> > > > > > +       ret = sysfs_create_group(&pdev->dev.kobj,
> > > > > > &pmu_sbi_group);
> > > > > > +       if (ret) {
> > > > > > +               dev_err(&pdev->dev, "sysfs creation
> > > > > > failed\n");
> > > > > > +               return ret;
> > > > > > +       }
> > > > > > +
> > > > > > +       pdev->dev.groups = pmu_sbi_groups;
> > > > > > +       dev_set_drvdata(&pdev->dev, pmu);
> > > > > > +
> > > > > >         return 0;
> > > > > >
> > > > > > +out_free_pmuid:
> > > > > > +       kfree(pmu->pmuid);
> > > > > >  out_free:
> > > > > >         kfree(pmu);
> > > > > >         return ret;
> > > > > > diff --git a/include/linux/perf/riscv_pmu.h
> > > > > > b/include/linux/perf/riscv_pmu.h index
> > > > > > 46f9b6fe306e..cf3557b77fb8 100644 ---
> > > > > > a/include/linux/perf/riscv_pmu.h +++
> > > > > > b/include/linux/perf/riscv_pmu.h @@ -42,6 +42,7 @@ struct
> > > > > > cpu_hw_events { struct riscv_pmu {
> > > > > >         struct pmu      pmu;
> > > > > >         char            *name;
> > > > > > +       char            *pmuid;
> > > > > >
> > > > > >         irqreturn_t     (*handle_irq)(int irq_num, void
> > > > > > *dev);
> > > > > >
> > > > > > --
> > > > > > 2.35.1
> > > > > >  
> > > >  
> > >
> > >  
> >  


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v4 1/1] RISC-V: Create unique identification for SoC PMU
@ 2022-06-21  7:59               ` Nikita Shubin
  0 siblings, 0 replies; 30+ messages in thread
From: Nikita Shubin @ 2022-06-21  7:59 UTC (permalink / raw)
  To: Anup Patel
  Cc: Atish Patra, Will Deacon, Sunil V L,
	João Mário Domingos, linux, Nikita Shubin,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Anup Patel,
	Mark Rutland, Geert Uytterhoeven, linux-riscv,
	linux-kernel@vger.kernel.org List, Linux ARM

Hello Anup!

On Tue, 21 Jun 2022 13:21:11 +0530
Anup Patel <apatel@ventanamicro.com> wrote:

> On Tue, Jun 21, 2022 at 1:13 PM Nikita Shubin
> <nikita.shubin@maquefel.me> wrote:
> >
> > Hello Anup!
> >
> > On Mon, 20 Jun 2022 12:40:20 -0700
> > Atish Patra <atishp@atishpatra.org> wrote:
> >  
> > > On Mon, Jun 20, 2022 at 7:40 AM Nikita Shubin
> > > <nikita.shubin@maquefel.me> wrote:  
> > > >
> > > > On Mon, 20 Jun 2022 17:30:58 +0530
> > > > Anup Patel <apatel@ventanamicro.com> wrote:
> > > >  
> > > > > On Sun, Jun 19, 2022 at 4:41 PM Nikita Shubin
> > > > > <nikita.shubin@maquefel.me> wrote:  
> > > > > >
> > > > > > From: Nikita Shubin <n.shubin@yadro.com>
> > > > > >
> > > > > > Provide RISC-V SBI PMU id to distinguish different cores or
> > > > > > SoCs via "devices/platform/riscv-pmu/id" sysfs entry.
> > > > > >
> > > > > > The identification is generated as string of marchid,
> > > > > > mimpid, mvendorid in hex format separated by coma -
> > > > > > "0x70032,0x70032,0x0".
> > > > > >
> > > > > > The CSRs are detailed in the RISC-V privileged spec [1].
> > > > > > [1] https://github.com/riscv/riscv-isa-manual
> > > > > >
> > > > > > Inspired-by: João Mário Domingos
> > > > > > <joao.mario@tecnico.ulisboa.pt> Signed-off-by: Nikita
> > > > > > Shubin <n.shubin@yadro.com>  
> > > > >
> > > > > The mvendorid, marchid, and mimpid can be useful to apps other
> > > > > than perf tool.
> > > > >
> > > > > I have tried to extend /proc/cpuinfo with this information
> > > > > which can be parsed by perf tool:
> > > > > https://lore.kernel.org/all/20220620115549.1529597-1-apatel@ventanamicro.com/
> > > > >  
> > > >
> > > > Atish, what do you think about this ?
> > > >
> > > > RISC-V perf can rely on "/proc/cpuinfo", in some similar manner
> > > > like "tools/perf/arch/s390/util/header.c" does.
> > > >  
> > >
> > > Yes. We can expose these three values either in sysfs or procfs
> > > (/proc/cpuinfo). For perf tool, it shouldn't matter as the
> > > header.c will need to generate the unique cpuid
> > > string from either.
> > >
> > > I am not sure if any other userspace tool prefers to parse sysfs
> > > instead of cpuinfo.  
> >
> > Okay - let's stick to /proc/cpuinfo.  
> 
> Sounds good.
> 
> You might have to write /proc/cpuinfo parsing code in perf tool
> header.c. Do you plan to send v4 of perf tool patches ??

Yes, but i might split it into separate series, not to mix perf headers
and U74 pmu-events bindings, i ll also add some SBI firmware event
bindings to make things easier.

> 
> Regards,
> Anup
> 
> >  
> > >  
> > > > Can it create problems with pmu identification in case of
> > > > hetergenous harts ?
> > > >  
> > >
> > > Does perf support hetergenous harts at all ? ARM64 code
> > > (tool/perf/arch/arm64/util/header.c)
> > > just breaks out of the loop after finding the first MIDR.
> > >  
> > > > >
> > > > > Regards,
> > > > > Anup
> > > > >  
> > > > > > ---
> > > > > > v3->v4:
> > > > > > - use string for pmuid
> > > > > > - rename pmu_sbi_id_show to id_show
> > > > > > - fix error print message in id_show
> > > > > > - fix DEVICE_ATTR to use octal permissions
> > > > > > ---
> > > > > >  arch/riscv/kernel/sbi.c        |  3 +++
> > > > > >  drivers/perf/riscv_pmu_sbi.c   | 41
> > > > > > ++++++++++++++++++++++++++++++++++
> > > > > > include/linux/perf/riscv_pmu.h | 1 + 3 files changed, 45
> > > > > > insertions(+)
> > > > > >
> > > > > > diff --git a/arch/riscv/kernel/sbi.c
> > > > > > b/arch/riscv/kernel/sbi.c index 775d3322b422..50dd9b6ecc9e
> > > > > > 100644 --- a/arch/riscv/kernel/sbi.c
> > > > > > +++ b/arch/riscv/kernel/sbi.c
> > > > > > @@ -627,16 +627,19 @@ long sbi_get_mvendorid(void)
> > > > > >  {
> > > > > >         return __sbi_base_ecall(SBI_EXT_BASE_GET_MVENDORID);
> > > > > >  }
> > > > > > +EXPORT_SYMBOL(sbi_get_mvendorid);
> > > > > >
> > > > > >  long sbi_get_marchid(void)
> > > > > >  {
> > > > > >         return __sbi_base_ecall(SBI_EXT_BASE_GET_MARCHID);
> > > > > >  }
> > > > > > +EXPORT_SYMBOL(sbi_get_marchid);
> > > > > >
> > > > > >  long sbi_get_mimpid(void)
> > > > > >  {
> > > > > >         return __sbi_base_ecall(SBI_EXT_BASE_GET_MIMPID);
> > > > > >  }
> > > > > > +EXPORT_SYMBOL(sbi_get_mimpid);
> > > > > >
> > > > > >  static void sbi_send_cpumask_ipi(const struct cpumask
> > > > > > *target) {
> > > > > > diff --git a/drivers/perf/riscv_pmu_sbi.c
> > > > > > b/drivers/perf/riscv_pmu_sbi.c index
> > > > > > dca3537a8dcc..be812f855617 100644 ---
> > > > > > a/drivers/perf/riscv_pmu_sbi.c +++
> > > > > > b/drivers/perf/riscv_pmu_sbi.c @@ -693,6 +693,28 @@ static
> > > > > > int pmu_sbi_setup_irqs(struct riscv_pmu *pmu, struct
> > > > > > platform_device *pde return 0; }
> > > > > >
> > > > > > +static ssize_t id_show(struct device *dev,
> > > > > > +                               struct device_attribute
> > > > > > *attr, char *buf) +{
> > > > > > +       int len;
> > > > > > +       struct riscv_pmu *pmu =
> > > > > > container_of(dev_get_drvdata(dev), struct riscv_pmu, pmu); +
> > > > > > +       len = sprintf(buf, "%s\n", pmu->pmuid);
> > > > > > +       if (len <= 0)
> > > > > > +               dev_err(dev, "invalid sprintf len: %d\n",
> > > > > > len); +
> > > > > > +       return len;
> > > > > > +}
> > > > > > +
> > > > > > +static DEVICE_ATTR(id, 0644, id_show, NULL);
> > > > > > +
> > > > > > +static struct attribute *pmu_sbi_attrs[] = {
> > > > > > +       &dev_attr_id.attr,
> > > > > > +       NULL
> > > > > > +};
> > > > > > +
> > > > > > +ATTRIBUTE_GROUPS(pmu_sbi);
> > > > > > +
> > > > > >  static int pmu_sbi_device_probe(struct platform_device
> > > > > > *pdev) {
> > > > > >         struct riscv_pmu *pmu = NULL;
> > > > > > @@ -714,6 +736,14 @@ static int pmu_sbi_device_probe(struct
> > > > > > platform_device *pdev) if
> > > > > > (pmu_sbi_get_ctrinfo(num_counters)) goto out_free;
> > > > > >
> > > > > > +       /* fill pmuid */
> > > > > > +       pmu->pmuid = kasprintf(GFP_KERNEL,
> > > > > > "0x%lx,0x%lx,0x%lx",
> > > > > > +                              sbi_get_marchid(),
> > > > > > +                              sbi_get_mimpid(),
> > > > > > +                              sbi_get_mvendorid());
> > > > > > +       if (!pmu->pmuid)
> > > > > > +               goto out_free_pmuid;
> > > > > > +
> > > > > >         ret = pmu_sbi_setup_irqs(pmu, pdev);
> > > > > >         if (ret < 0) {
> > > > > >                 pr_info("Perf sampling/filtering is not
> > > > > > supported as sscof extension is not available\n"); @@ -739,8
> > > > > > +769,19 @@ static int pmu_sbi_device_probe(struct
> > > > > > platform_device *pdev) return ret; }
> > > > > >
> > > > > > +       ret = sysfs_create_group(&pdev->dev.kobj,
> > > > > > &pmu_sbi_group);
> > > > > > +       if (ret) {
> > > > > > +               dev_err(&pdev->dev, "sysfs creation
> > > > > > failed\n");
> > > > > > +               return ret;
> > > > > > +       }
> > > > > > +
> > > > > > +       pdev->dev.groups = pmu_sbi_groups;
> > > > > > +       dev_set_drvdata(&pdev->dev, pmu);
> > > > > > +
> > > > > >         return 0;
> > > > > >
> > > > > > +out_free_pmuid:
> > > > > > +       kfree(pmu->pmuid);
> > > > > >  out_free:
> > > > > >         kfree(pmu);
> > > > > >         return ret;
> > > > > > diff --git a/include/linux/perf/riscv_pmu.h
> > > > > > b/include/linux/perf/riscv_pmu.h index
> > > > > > 46f9b6fe306e..cf3557b77fb8 100644 ---
> > > > > > a/include/linux/perf/riscv_pmu.h +++
> > > > > > b/include/linux/perf/riscv_pmu.h @@ -42,6 +42,7 @@ struct
> > > > > > cpu_hw_events { struct riscv_pmu {
> > > > > >         struct pmu      pmu;
> > > > > >         char            *name;
> > > > > > +       char            *pmuid;
> > > > > >
> > > > > >         irqreturn_t     (*handle_irq)(int irq_num, void
> > > > > > *dev);
> > > > > >
> > > > > > --
> > > > > > 2.35.1
> > > > > >  
> > > >  
> > >
> > >  
> >  


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v4 1/1] RISC-V: Create unique identification for SoC PMU
@ 2022-06-21  7:59               ` Nikita Shubin
  0 siblings, 0 replies; 30+ messages in thread
From: Nikita Shubin @ 2022-06-21  7:59 UTC (permalink / raw)
  To: Anup Patel
  Cc: Atish Patra, Will Deacon, Sunil V L,
	João Mário Domingos, linux, Nikita Shubin,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Anup Patel,
	Mark Rutland, Geert Uytterhoeven, linux-riscv,
	linux-kernel@vger.kernel.org List, Linux ARM

Hello Anup!

On Tue, 21 Jun 2022 13:21:11 +0530
Anup Patel <apatel@ventanamicro.com> wrote:

> On Tue, Jun 21, 2022 at 1:13 PM Nikita Shubin
> <nikita.shubin@maquefel.me> wrote:
> >
> > Hello Anup!
> >
> > On Mon, 20 Jun 2022 12:40:20 -0700
> > Atish Patra <atishp@atishpatra.org> wrote:
> >  
> > > On Mon, Jun 20, 2022 at 7:40 AM Nikita Shubin
> > > <nikita.shubin@maquefel.me> wrote:  
> > > >
> > > > On Mon, 20 Jun 2022 17:30:58 +0530
> > > > Anup Patel <apatel@ventanamicro.com> wrote:
> > > >  
> > > > > On Sun, Jun 19, 2022 at 4:41 PM Nikita Shubin
> > > > > <nikita.shubin@maquefel.me> wrote:  
> > > > > >
> > > > > > From: Nikita Shubin <n.shubin@yadro.com>
> > > > > >
> > > > > > Provide RISC-V SBI PMU id to distinguish different cores or
> > > > > > SoCs via "devices/platform/riscv-pmu/id" sysfs entry.
> > > > > >
> > > > > > The identification is generated as string of marchid,
> > > > > > mimpid, mvendorid in hex format separated by coma -
> > > > > > "0x70032,0x70032,0x0".
> > > > > >
> > > > > > The CSRs are detailed in the RISC-V privileged spec [1].
> > > > > > [1] https://github.com/riscv/riscv-isa-manual
> > > > > >
> > > > > > Inspired-by: João Mário Domingos
> > > > > > <joao.mario@tecnico.ulisboa.pt> Signed-off-by: Nikita
> > > > > > Shubin <n.shubin@yadro.com>  
> > > > >
> > > > > The mvendorid, marchid, and mimpid can be useful to apps other
> > > > > than perf tool.
> > > > >
> > > > > I have tried to extend /proc/cpuinfo with this information
> > > > > which can be parsed by perf tool:
> > > > > https://lore.kernel.org/all/20220620115549.1529597-1-apatel@ventanamicro.com/
> > > > >  
> > > >
> > > > Atish, what do you think about this ?
> > > >
> > > > RISC-V perf can rely on "/proc/cpuinfo", in some similar manner
> > > > like "tools/perf/arch/s390/util/header.c" does.
> > > >  
> > >
> > > Yes. We can expose these three values either in sysfs or procfs
> > > (/proc/cpuinfo). For perf tool, it shouldn't matter as the
> > > header.c will need to generate the unique cpuid
> > > string from either.
> > >
> > > I am not sure if any other userspace tool prefers to parse sysfs
> > > instead of cpuinfo.  
> >
> > Okay - let's stick to /proc/cpuinfo.  
> 
> Sounds good.
> 
> You might have to write /proc/cpuinfo parsing code in perf tool
> header.c. Do you plan to send v4 of perf tool patches ??

Yes, but i might split it into separate series, not to mix perf headers
and U74 pmu-events bindings, i ll also add some SBI firmware event
bindings to make things easier.

> 
> Regards,
> Anup
> 
> >  
> > >  
> > > > Can it create problems with pmu identification in case of
> > > > hetergenous harts ?
> > > >  
> > >
> > > Does perf support hetergenous harts at all ? ARM64 code
> > > (tool/perf/arch/arm64/util/header.c)
> > > just breaks out of the loop after finding the first MIDR.
> > >  
> > > > >
> > > > > Regards,
> > > > > Anup
> > > > >  
> > > > > > ---
> > > > > > v3->v4:
> > > > > > - use string for pmuid
> > > > > > - rename pmu_sbi_id_show to id_show
> > > > > > - fix error print message in id_show
> > > > > > - fix DEVICE_ATTR to use octal permissions
> > > > > > ---
> > > > > >  arch/riscv/kernel/sbi.c        |  3 +++
> > > > > >  drivers/perf/riscv_pmu_sbi.c   | 41
> > > > > > ++++++++++++++++++++++++++++++++++
> > > > > > include/linux/perf/riscv_pmu.h | 1 + 3 files changed, 45
> > > > > > insertions(+)
> > > > > >
> > > > > > diff --git a/arch/riscv/kernel/sbi.c
> > > > > > b/arch/riscv/kernel/sbi.c index 775d3322b422..50dd9b6ecc9e
> > > > > > 100644 --- a/arch/riscv/kernel/sbi.c
> > > > > > +++ b/arch/riscv/kernel/sbi.c
> > > > > > @@ -627,16 +627,19 @@ long sbi_get_mvendorid(void)
> > > > > >  {
> > > > > >         return __sbi_base_ecall(SBI_EXT_BASE_GET_MVENDORID);
> > > > > >  }
> > > > > > +EXPORT_SYMBOL(sbi_get_mvendorid);
> > > > > >
> > > > > >  long sbi_get_marchid(void)
> > > > > >  {
> > > > > >         return __sbi_base_ecall(SBI_EXT_BASE_GET_MARCHID);
> > > > > >  }
> > > > > > +EXPORT_SYMBOL(sbi_get_marchid);
> > > > > >
> > > > > >  long sbi_get_mimpid(void)
> > > > > >  {
> > > > > >         return __sbi_base_ecall(SBI_EXT_BASE_GET_MIMPID);
> > > > > >  }
> > > > > > +EXPORT_SYMBOL(sbi_get_mimpid);
> > > > > >
> > > > > >  static void sbi_send_cpumask_ipi(const struct cpumask
> > > > > > *target) {
> > > > > > diff --git a/drivers/perf/riscv_pmu_sbi.c
> > > > > > b/drivers/perf/riscv_pmu_sbi.c index
> > > > > > dca3537a8dcc..be812f855617 100644 ---
> > > > > > a/drivers/perf/riscv_pmu_sbi.c +++
> > > > > > b/drivers/perf/riscv_pmu_sbi.c @@ -693,6 +693,28 @@ static
> > > > > > int pmu_sbi_setup_irqs(struct riscv_pmu *pmu, struct
> > > > > > platform_device *pde return 0; }
> > > > > >
> > > > > > +static ssize_t id_show(struct device *dev,
> > > > > > +                               struct device_attribute
> > > > > > *attr, char *buf) +{
> > > > > > +       int len;
> > > > > > +       struct riscv_pmu *pmu =
> > > > > > container_of(dev_get_drvdata(dev), struct riscv_pmu, pmu); +
> > > > > > +       len = sprintf(buf, "%s\n", pmu->pmuid);
> > > > > > +       if (len <= 0)
> > > > > > +               dev_err(dev, "invalid sprintf len: %d\n",
> > > > > > len); +
> > > > > > +       return len;
> > > > > > +}
> > > > > > +
> > > > > > +static DEVICE_ATTR(id, 0644, id_show, NULL);
> > > > > > +
> > > > > > +static struct attribute *pmu_sbi_attrs[] = {
> > > > > > +       &dev_attr_id.attr,
> > > > > > +       NULL
> > > > > > +};
> > > > > > +
> > > > > > +ATTRIBUTE_GROUPS(pmu_sbi);
> > > > > > +
> > > > > >  static int pmu_sbi_device_probe(struct platform_device
> > > > > > *pdev) {
> > > > > >         struct riscv_pmu *pmu = NULL;
> > > > > > @@ -714,6 +736,14 @@ static int pmu_sbi_device_probe(struct
> > > > > > platform_device *pdev) if
> > > > > > (pmu_sbi_get_ctrinfo(num_counters)) goto out_free;
> > > > > >
> > > > > > +       /* fill pmuid */
> > > > > > +       pmu->pmuid = kasprintf(GFP_KERNEL,
> > > > > > "0x%lx,0x%lx,0x%lx",
> > > > > > +                              sbi_get_marchid(),
> > > > > > +                              sbi_get_mimpid(),
> > > > > > +                              sbi_get_mvendorid());
> > > > > > +       if (!pmu->pmuid)
> > > > > > +               goto out_free_pmuid;
> > > > > > +
> > > > > >         ret = pmu_sbi_setup_irqs(pmu, pdev);
> > > > > >         if (ret < 0) {
> > > > > >                 pr_info("Perf sampling/filtering is not
> > > > > > supported as sscof extension is not available\n"); @@ -739,8
> > > > > > +769,19 @@ static int pmu_sbi_device_probe(struct
> > > > > > platform_device *pdev) return ret; }
> > > > > >
> > > > > > +       ret = sysfs_create_group(&pdev->dev.kobj,
> > > > > > &pmu_sbi_group);
> > > > > > +       if (ret) {
> > > > > > +               dev_err(&pdev->dev, "sysfs creation
> > > > > > failed\n");
> > > > > > +               return ret;
> > > > > > +       }
> > > > > > +
> > > > > > +       pdev->dev.groups = pmu_sbi_groups;
> > > > > > +       dev_set_drvdata(&pdev->dev, pmu);
> > > > > > +
> > > > > >         return 0;
> > > > > >
> > > > > > +out_free_pmuid:
> > > > > > +       kfree(pmu->pmuid);
> > > > > >  out_free:
> > > > > >         kfree(pmu);
> > > > > >         return ret;
> > > > > > diff --git a/include/linux/perf/riscv_pmu.h
> > > > > > b/include/linux/perf/riscv_pmu.h index
> > > > > > 46f9b6fe306e..cf3557b77fb8 100644 ---
> > > > > > a/include/linux/perf/riscv_pmu.h +++
> > > > > > b/include/linux/perf/riscv_pmu.h @@ -42,6 +42,7 @@ struct
> > > > > > cpu_hw_events { struct riscv_pmu {
> > > > > >         struct pmu      pmu;
> > > > > >         char            *name;
> > > > > > +       char            *pmuid;
> > > > > >
> > > > > >         irqreturn_t     (*handle_irq)(int irq_num, void
> > > > > > *dev);
> > > > > >
> > > > > > --
> > > > > > 2.35.1
> > > > > >  
> > > >  
> > >
> > >  
> >  


^ permalink raw reply	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2022-06-21  8:07 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-19 11:11 [PATCH v4 0/1] RISC-V: Create unique identification for SoC PMU Nikita Shubin
2022-06-19 11:11 ` Nikita Shubin
2022-06-19 11:11 ` Nikita Shubin
2022-06-19 11:11 ` [PATCH v4 1/1] " Nikita Shubin
2022-06-19 11:11   ` Nikita Shubin
2022-06-19 11:11   ` Nikita Shubin
2022-06-20  7:50   ` Geert Uytterhoeven
2022-06-20  7:50     ` Geert Uytterhoeven
2022-06-20  7:50     ` Geert Uytterhoeven
2022-06-20 14:44     ` Nikita Shubin
2022-06-20 14:44       ` Nikita Shubin
2022-06-20 14:44       ` Nikita Shubin
2022-06-20 12:00   ` Anup Patel
2022-06-20 12:00     ` Anup Patel
2022-06-20 12:00     ` Anup Patel
2022-06-20 14:40     ` Nikita Shubin
2022-06-20 14:40       ` Nikita Shubin
2022-06-20 14:40       ` Nikita Shubin
2022-06-20 19:40       ` Atish Patra
2022-06-20 19:40         ` Atish Patra
2022-06-20 19:40         ` Atish Patra
2022-06-21  7:41         ` Nikita Shubin
2022-06-21  7:41           ` Nikita Shubin
2022-06-21  7:41           ` Nikita Shubin
2022-06-21  7:51           ` Anup Patel
2022-06-21  7:51             ` Anup Patel
2022-06-21  7:51             ` Anup Patel
2022-06-21  7:59             ` Nikita Shubin
2022-06-21  7:59               ` Nikita Shubin
2022-06-21  7:59               ` Nikita Shubin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.