Skip to contentSkip to conversation

dt-bindings: perf: imx8-ddr: add imx8qxp ddr performance monitor

PATCH Superseded Frank Li 5 participants 8 messages Apr 16, 2019 – Apr 25, 2019

Subsystems (4)

v5 of 12 Superseded Latest is v12 →

lore
Share & tools
lore

Frank Li

author maintainer
#0 lore raw

PATCH v5 1/4 dt-bindings: perf: imx8-ddr: add imx8qxp ddr performance monitor

Added binding doc for imx8qxp ddr performance monitor

---
No change from v4 to v5

Change from v4 to v4
* remove "standard xxx"

Change from v2 to v3
* ddr_pmu0 -> ddr-pmu

 .../devicetree/bindings/perf/fsl-imx-ddr.txt       | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/perf/fsl-imx-ddr.txt
Documentation/devicetree/bindings/perf/fsl-imx-ddr.txt new file +22 -0
new file mode 100644
index 0000000..c667b87
@@ -0,0 +1,22 @@
+* Freescale(NXP) IMX8 DDR performance monitor
+
+Required properties:
+
+- compatible: should be one of:
+	"fsl,imx8-ddr-pmu"
+	"fsl,imx8m-ddr-pmu"
+
+- reg: physical address and size
+
+- interrupts: single interrupt
+	generated by the control block
+
+Example:
+
+	ddr-pmu@5c020000 {
+		compatible = "fsl,imx8-ddr-pmu";
+		reg = <0x0 0x5c020000 0x0 0x10000>;
+		interrupt-parent = <&gic>;
+		interrupts = <GIC_SPI 131 IRQ_TYPE_LEVEL_HIGH>;
+	};
+
Signature · 1 line
2.5.2
author maintainer
#1 lore raw

PATCH v5 2/4 drivers/perf: imx_ddr: Add ddr performance counter support

Add ddr performance monitor support for iMX8QXP

There are 4 counters for ddr perfomance events.
counter 0 is dedicated for cycles.
you choose any up to 3 no cycles events.

for example:

perf stat -a -e ddr0/read-cycles/,ddr0/write-cycles/,ddr0/precharge/ ls perf stat -a -e ddr0/cycles/,ddr0/read-access/,ddr0/write-access/ ls

Support below events.

  ddr0/activate/                                     [Kernel PMU event]
  ddr0/cycles/                                       [Kernel PMU event]
  ddr0/hp-read-credit-cnt/                           [Kernel PMU event]
  ddr0/hp-read/                                      [Kernel PMU event]
  ddr0/hp-req-nodcredit/                             [Kernel PMU event]
  ddr0/hp-xact-credit/                               [Kernel PMU event]
  ddr0/load-mode/                                    [Kernel PMU event]
  ddr0/lp-read-credit-cnt/                           [Kernel PMU event]
  ddr0/lp-req-nocredit/                              [Kernel PMU event]
  ddr0/lp-xact-credit/                               [Kernel PMU event]
  ddr0/mwr/                                          [Kernel PMU event]
  ddr0/precharge/                                    [Kernel PMU event]
  ddr0/raw-hazard/                                   [Kernel PMU event]
  ddr0/read-access/                                  [Kernel PMU event]
  ddr0/read-activate/                                [Kernel PMU event]
  ddr0/read-command/                                 [Kernel PMU event]
  ddr0/read-cycles/                                  [Kernel PMU event]
  ddr0/read-modify-write-command/                    [Kernel PMU event]
  ddr0/read-queue-depth/                             [Kernel PMU event]
  ddr0/read-write-transition/                        [Kernel PMU event]
  ddr0/read/                                         [Kernel PMU event]
  ddr0/refresh/                                      [Kernel PMU event]
  ddr0/selfresh/                                     [Kernel PMU event]
  ddr0/wr-xact-credit/                               [Kernel PMU event]
  ddr0/write-access/                                 [Kernel PMU event]
  ddr0/write-command/                                [Kernel PMU event]
  ddr0/write-credit-cnt/                             [Kernel PMU event]
  ddr0/write-cycles/                                 [Kernel PMU event]
  ddr0/write-queue-depth/                            [Kernel PMU event]

ddr0/write/

---
Change from v4 to v5
* Remove AXI ID filter function

Change from v3 to v4
* Change FSL_IMX8_DDR_PERF to FSL_IMX8_DDR_PMU
* sort include
* remove struct fsl_ddr_devtype_data
* Added comment need disable control first
* Added comment about must enable cycle counter
* Added macro for EVENT_AXI_READ, remove hardcode 0x41 and 0x42
* Added comment about cycle counter is fastest one

Change from v2 to v3
* remove kfree

Change from V1 to V2
* update Kconfig by use i.MX8 instead of i.MX8 QXP
* remove gpl statememnt since SPDX tag
* use dev_kzalloc
* use dev_err
* commit message show axi_read 0x41\axi_write 0x42
* commit message show cycles must be enabled
* Irq only issue at cycles overflow
* use NUM_COUNTER
* use devm_request_irq
* add hotplug callback to handle context migration

 drivers/perf/Kconfig             |   7 +
 drivers/perf/Makefile            |   1 +
 drivers/perf/fsl_imx8_ddr_perf.c | 553 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 561 insertions(+)
 create mode 100644 drivers/perf/fsl_imx8_ddr_perf.c
drivers/perf/Kconfig +7 -0
index a94e586..9bc3785 100644
@@ -70,6 +70,13 @@ config ARM_DSU_PMU
 	  system, control logic. The PMU allows counting various events related
 	  to DSU.
 
+config FSL_IMX8_DDR_PMU
+	tristate "Freescale i.MX8 DDR perf monitor"
+	depends on ARCH_MXC
+	  help
+	  Provides support for ddr perfomance monitor in i.MX8. Provide memory
+	  througput information.
+
 config HISI_PMU
        bool "HiSilicon SoC PMU"
        depends on ARM64 && ACPI
drivers/perf/Makefile +1 -0
index 3048994..2ebb4de 100644
@@ -5,6 +5,7 @@ obj-$(CONFIG_ARM_DSU_PMU) += arm_dsu_pmu.o
 obj-$(CONFIG_ARM_PMU) += arm_pmu.o arm_pmu_platform.o
 obj-$(CONFIG_ARM_PMU_ACPI) += arm_pmu_acpi.o
 obj-$(CONFIG_ARM_SMMU_V3_PMU) += arm_smmuv3_pmu.o
+obj-$(CONFIG_FSL_IMX8_DDR_PMU) += fsl_imx8_ddr_perf.o
 obj-$(CONFIG_HISI_PMU) += hisilicon/
 obj-$(CONFIG_QCOM_L2_PMU)	+= qcom_l2_pmu.o
 obj-$(CONFIG_QCOM_L3_PMU) += qcom_l3_pmu.o
drivers/perf/fsl_imx8_ddr_perf.c new file +553 -0

553 lines not on this page · raw message

Signature · 1 line
2.5.2
#2 lore raw

Re: [PATCH V5 2/4] drivers/perf: imx_ddr: Add ddr performance counter support

Hi Frank,

Quoted 5 lines · Frank Li

Add ddr performance monitor support for iMX8QXP

There are 4 counters for ddr perfomance events.
counter 0 is dedicated for cycles.
you choose any up to 3 no cycles events.

I was about to pick this up, but I still have a few questions/comments on the code:

Quoted 15 lines
drivers/perf/fsl_imx8_ddr_perf.c new file +15 -0
+static irqreturn_t ddr_perf_irq_handler(int irq, void *p)
+{
+	int i;
+	u8 reg;
+	int val;
+	int counter;
+	struct ddr_pmu *pmu = (struct ddr_pmu *) p;
+	struct perf_event *event;
+
+	/* Only cycles counter overflowed can issue irq. all counters will
+	 * be stopped when cycles counter overflow. but other counter don't stop
+	 * when overflow happen. Update all of the local counter values,
+	 * then reset the cycles counter, so the others can continue
+	 * counting. cycles counter is fastest counter in all events. at last
+	 * 4 times than other counters.

drivers/perf/fsl_imx8_ddr_perf.c line 407

Quoted 10 lines
drivers/perf/fsl_imx8_ddr_perf.c new file +10 -0
+	 */
+	for (i = 0; i < NUM_COUNTER; i++) {
+
+		if (!pmu->active_events[i])
+			continue;
+
+		event = pmu->active_events[i];
+		counter = event->hw.idx;
+		reg = counter * 4 + COUNTER_CNTL;
+		val = readl(pmu->base + reg);

Does this read have a side-effect, or can it be removed given that you don't use val for anything else?

drivers/perf/fsl_imx8_ddr_perf.c line 421

Quoted 13 lines
drivers/perf/fsl_imx8_ddr_perf.c new file +13 -0
+		ddr_perf_event_update(event);
+
+		if (counter == EVENT_CYCLES_COUNTER) {
+			ddr_perf_event_enable(pmu,
+					      EVENT_CYCLES_ID,
+					      EVENT_CYCLES_COUNTER,
+					      true);
+			ddr_perf_event_update(event);
+		}
+	}
+
+	return IRQ_HANDLED;
+}

What stops the IRQ handler running concurrently with perf callbacks? I can't see any locking here, or is the IRQ supposed to be affine to the same CPU that's handling the perf context?

Quoted 67 lines
drivers/perf/fsl_imx8_ddr_perf.c new file +67 -0
+static int ddr_perf_offline_cpu(unsigned int cpu, struct hlist_node *node)
+{
+	struct ddr_pmu *pmu = hlist_entry_safe(node, struct ddr_pmu, node);
+	int target;
+
+	if (!cpumask_test_and_clear_cpu(cpu, &pmu->cpu))
+		return 0;
+
+	target = cpumask_any_but(cpu_online_mask, cpu);
+	if (target >= nr_cpu_ids)
+		return 0;
+
+	perf_pmu_migrate_context(&pmu->pmu, cpu, target);
+	cpumask_set_cpu(target, &pmu->cpu);
+
+	return 0;
+}
+
+static int ddr_perf_probe(struct platform_device *pdev)
+{
+	struct ddr_pmu *pmu;
+	struct device_node *np;
+	void __iomem *base;
+	struct resource *iomem;
+	char *name;
+	char *hpname;
+	int num;
+	int ret;
+	u32 irq;
+	const struct of_device_id *of_id =
+		of_match_device(imx_ddr_pmu_dt_ids, &pdev->dev);
+
+	iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	base = devm_ioremap_resource(&pdev->dev, iomem);
+	if (IS_ERR(base))
+		return PTR_ERR(base);
+
+	np = pdev->dev.of_node;
+
+	pmu = devm_kzalloc(&pdev->dev, sizeof(*pmu), GFP_KERNEL);
+	if (!pmu)
+		return -ENOMEM;
+
+	num = ddr_perf_init(pmu, base, &pdev->dev);
+
+	name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "ddr%d", num);
+	if (!name)
+		return -ENOMEM;
+
+	hpname = devm_kasprintf(&pdev->dev, GFP_KERNEL,
+				"perf/imx/ddr%d:online", num);
+	if (!hpname)
+		return -ENOMEM;
+
+	pmu->flags = (uintptr_t) of_id->data;
+
+	cpumask_set_cpu(raw_smp_processor_id(), &pmu->cpu);
+	ret = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN, hpname, NULL,
+					 ddr_perf_offline_cpu);
+
+	if (ret < 0) {
+		dev_err(&pdev->dev, "cpuhp_setup_state_multi failed\n");
+		goto ddr_perf_err;
+	}
+
+	pmu->cpuhp_state = ret;
+

drivers/perf/fsl_imx8_ddr_perf.c line 499

Quoted 10 lines
drivers/perf/fsl_imx8_ddr_perf.c new file +10 -0
+	/* Register the pmu instance for cpu hotplug */
+	cpuhp_state_add_instance_nocalls(pmu->cpuhp_state, &pmu->node);
+
+	ret = perf_pmu_register(&(pmu->pmu), name, -1);
+	if (ret)
+		goto ddr_perf_err;
+
+	/* Request irq */
+	irq = of_irq_get(np, 0);
+	if (irq < 0) {

irq is a u32 so this will never execute. You need to make it an int.

drivers/perf/fsl_imx8_ddr_perf.c line 507

Quoted 8 lines
drivers/perf/fsl_imx8_ddr_perf.c new file +8 -0
+		dev_err(&pdev->dev, "Failed to get irq: %d", irq);
+		ret = irq;
+		goto ddr_perf_irq_err;
+	}
+
+	ret = devm_request_irq(&pdev->dev, irq,
+					ddr_perf_irq_handler,
+					IRQF_TRIGGER_RISING | IRQF_ONESHOT,

Can you explain why you need to pass these specific IRQ flags, please? I'm struggling to see what the ONESHOT is buying you.

Will

#3 lore raw

Re: [PATCH V5 2/4] drivers/perf: imx_ddr: Add ddr performance counter support

Quoted 33 lines · Will Deacon

Hi Frank,

Quoted 5 lines · Frank Li

Add ddr performance monitor support for iMX8QXP

There are 4 counters for ddr perfomance events.
counter 0 is dedicated for cycles.
you choose any up to 3 no cycles events.

I was about to pick this up, but I still have a few questions/comments on the code:

Quoted 20 lines
drivers/perf/fsl_imx8_ddr_perf.c new file +20 -0
+static irqreturn_t ddr_perf_irq_handler(int irq, void *p)
+{
+     int i;
+     u8 reg;
+     int val;
+     int counter;
+     struct ddr_pmu *pmu = (struct ddr_pmu *) p;
+     struct perf_event *event;
+
+     /* Only cycles counter overflowed can issue irq. all counters will
+      * be stopped when cycles counter overflow. but other counter don't stop
+      * when overflow happen. Update all of the local counter values,
+      * then reset the cycles counter, so the others can continue
+      * counting. cycles counter is fastest counter in all events. at last
+      * 4 times than other counters.
+      */
+     for (i = 0; i < NUM_COUNTER; i++) {
+
+             if (!pmu->active_events[i])
+                     continue;
Quoted 8 lines

drivers/perf/fsl_imx8_ddr_perf.c line 407

Quoted 5 lines
drivers/perf/fsl_imx8_ddr_perf.c new file +5 -0
+
+             event = pmu->active_events[i];
+             counter = event->hw.idx;
+             reg = counter * 4 + COUNTER_CNTL;
+             val = readl(pmu->base + reg);

Does this read have a side-effect, or can it be removed given that you don't use val for anything else?

It can be removed.

Quoted 10 lines
Quoted 10 lines
drivers/perf/fsl_imx8_ddr_perf.c new file +9 -0
+             ddr_perf_event_update(event);
+
+             if (counter == EVENT_CYCLES_COUNTER) {
+                     ddr_perf_event_enable(pmu,
+                                           EVENT_CYCLES_ID,
+                                           EVENT_CYCLES_COUNTER,
+                                           true);
+                     ddr_perf_event_update(event);
+             }
Quoted 8 lines

drivers/perf/fsl_imx8_ddr_perf.c line 421

Quoted 4 lines
drivers/perf/fsl_imx8_ddr_perf.c new file +4 -0
+     }
+
+     return IRQ_HANDLED;
+}

What stops the IRQ handler running concurrently with perf callbacks? I can't see any locking here, or is the IRQ supposed to be affine to the same CPU that's handling the perf context?

I don't under your means here.
ddr_perf_event_update is lockless design.

I can't found problem if run ddr_perf_event_enable at both perf context and IRQ concurrently.

Quoted 90 lines
Quoted 68 lines
drivers/perf/fsl_imx8_ddr_perf.c new file +67 -0
+static int ddr_perf_offline_cpu(unsigned int cpu, struct hlist_node *node)
+{
+     struct ddr_pmu *pmu = hlist_entry_safe(node, struct ddr_pmu, node);
+     int target;
+
+     if (!cpumask_test_and_clear_cpu(cpu, &pmu->cpu))
+             return 0;
+
+     target = cpumask_any_but(cpu_online_mask, cpu);
+     if (target >= nr_cpu_ids)
+             return 0;
+
+     perf_pmu_migrate_context(&pmu->pmu, cpu, target);
+     cpumask_set_cpu(target, &pmu->cpu);
+
+     return 0;
+}
+
+static int ddr_perf_probe(struct platform_device *pdev)
+{
+     struct ddr_pmu *pmu;
+     struct device_node *np;
+     void __iomem *base;
+     struct resource *iomem;
+     char *name;
+     char *hpname;
+     int num;
+     int ret;
+     u32 irq;
+     const struct of_device_id *of_id =
+             of_match_device(imx_ddr_pmu_dt_ids, &pdev->dev);
+
+     iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+     base = devm_ioremap_resource(&pdev->dev, iomem);
+     if (IS_ERR(base))
+             return PTR_ERR(base);
+
+     np = pdev->dev.of_node;
+
+     pmu = devm_kzalloc(&pdev->dev, sizeof(*pmu), GFP_KERNEL);
+     if (!pmu)
+             return -ENOMEM;
+
+     num = ddr_perf_init(pmu, base, &pdev->dev);
+
+     name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "ddr%d", num);
+     if (!name)
+             return -ENOMEM;
+
+     hpname = devm_kasprintf(&pdev->dev, GFP_KERNEL,
+                             "perf/imx/ddr%d:online", num);
+     if (!hpname)
+             return -ENOMEM;
+
+     pmu->flags = (uintptr_t) of_id->data;
+
+     cpumask_set_cpu(raw_smp_processor_id(), &pmu->cpu);
+     ret = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN, hpname, NULL,
+                                      ddr_perf_offline_cpu);
+
+     if (ret < 0) {
+             dev_err(&pdev->dev, "cpuhp_setup_state_multi failed\n");
+             goto ddr_perf_err;
+     }
+
+     pmu->cpuhp_state = ret;
+

drivers/perf/fsl_imx8_ddr_perf.c line 499

Quoted 10 lines
drivers/perf/fsl_imx8_ddr_perf.c new file +10 -0
+     /* Register the pmu instance for cpu hotplug */
+     cpuhp_state_add_instance_nocalls(pmu->cpuhp_state, &pmu->node);
+
+     ret = perf_pmu_register(&(pmu->pmu), name, -1);
+     if (ret)
+             goto ddr_perf_err;
+
+     /* Request irq */
+     irq = of_irq_get(np, 0);
+     if (irq < 0) {

irq is a u32 so this will never execute. You need to make it an int.

drivers/perf/fsl_imx8_ddr_perf.c line 507

Quoted 8 lines
drivers/perf/fsl_imx8_ddr_perf.c new file +8 -0
+             dev_err(&pdev->dev, "Failed to get irq: %d", irq);
+             ret = irq;
+             goto ddr_perf_irq_err;
+     }
+
+     ret = devm_request_irq(&pdev->dev, irq,
+                                     ddr_perf_irq_handler,
+                                     IRQF_TRIGGER_RISING | IRQF_ONESHOT,
Quoted 2 lines

Can you explain why you need to pass these specific IRQ flags, please? I'm struggling to see what the ONESHOT is buying you.

I think default should be okay. I will update at next version

Quoted 2 lines

Will

maintainer
#4 lore raw

Re: [PATCH V5 2/4] drivers/perf: imx_ddr: Add ddr performance counter support

In reply to Will Deacon
Quoted 50 lines · Will Deacon

Hi Frank,

Quoted 5 lines · Frank Li

Add ddr performance monitor support for iMX8QXP

There are 4 counters for ddr perfomance events.
counter 0 is dedicated for cycles.
you choose any up to 3 no cycles events.

I was about to pick this up, but I still have a few questions/comments on the code:

Quoted 15 lines
drivers/perf/fsl_imx8_ddr_perf.c new file +15 -0
+static irqreturn_t ddr_perf_irq_handler(int irq, void *p)
+{
+	int i;
+	u8 reg;
+	int val;
+	int counter;
+	struct ddr_pmu *pmu = (struct ddr_pmu *) p;
+	struct perf_event *event;
+
+	/* Only cycles counter overflowed can issue irq. all counters will
+	 * be stopped when cycles counter overflow. but other counter don't stop
+	 * when overflow happen. Update all of the local counter values,
+	 * then reset the cycles counter, so the others can continue
+	 * counting. cycles counter is fastest counter in all events. at last
+	 * 4 times than other counters.

drivers/perf/fsl_imx8_ddr_perf.c line 407

Quoted 10 lines
drivers/perf/fsl_imx8_ddr_perf.c new file +10 -0
+	 */
+	for (i = 0; i < NUM_COUNTER; i++) {
+
+		if (!pmu->active_events[i])
+			continue;
+
+		event = pmu->active_events[i];
+		counter = event->hw.idx;
+		reg = counter * 4 + COUNTER_CNTL;
+		val = readl(pmu->base + reg);

Does this read have a side-effect, or can it be removed given that you don't use val for anything else?

Quoted 9 lines
drivers/perf/fsl_imx8_ddr_perf.c new file +9 -0
+		ddr_perf_event_update(event);
+
+		if (counter == EVENT_CYCLES_COUNTER) {
+			ddr_perf_event_enable(pmu,
+					      EVENT_CYCLES_ID,
+					      EVENT_CYCLES_COUNTER,
+					      true);
+			ddr_perf_event_update(event);
+		}
Quoted 8 lines

drivers/perf/fsl_imx8_ddr_perf.c line 421

Quoted 4 lines
drivers/perf/fsl_imx8_ddr_perf.c new file +4 -0
+	}
+
+	return IRQ_HANDLED;
+}

What stops the IRQ handler running concurrently with perf callbacks? I can't see any locking here, or is the IRQ supposed to be affine to the same CPU that's handling the perf context?

To be correct, the IRQ affinity should be set to match the logical affinity of the PMU, but it looks like that's not done at setup or migrate time.

Frank, please take a look at what drivers/perf/arm-ccn.c does with teh IRQ, including the use of IRQF_NOBALANCING | IRQF_NO_THREAD flags when requesting the IRQ to begin with.

Thanks,
Mark.

#5 lore raw

Re: [PATCH V5 2/4] drivers/perf: imx_ddr: Add ddr performance counter support

In reply to Frank Li

On 16/04/2019 21:39, Frank Li wrote:
[...]

Quoted 36 lines
drivers/perf/fsl_imx8_ddr_perf.c new file +36 -0
+static int ddr_perf_probe(struct platform_device *pdev)
+{
+	struct ddr_pmu *pmu;
+	struct device_node *np;
+	void __iomem *base;
+	struct resource *iomem;
+	char *name;
+	char *hpname;
+	int num;
+	int ret;
+	u32 irq;
+	const struct of_device_id *of_id =
+		of_match_device(imx_ddr_pmu_dt_ids, &pdev->dev);
+
+	iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	base = devm_ioremap_resource(&pdev->dev, iomem);
+	if (IS_ERR(base))
+		return PTR_ERR(base);
+
+	np = pdev->dev.of_node;
+
+	pmu = devm_kzalloc(&pdev->dev, sizeof(*pmu), GFP_KERNEL);
+	if (!pmu)
+		return -ENOMEM;
+
+	num = ddr_perf_init(pmu, base, &pdev->dev);
+
+	name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "ddr%d", num);
+	if (!name)
+		return -ENOMEM;
+
+	hpname = devm_kasprintf(&pdev->dev, GFP_KERNEL,
+				"perf/imx/ddr%d:online", num);
+	if (!hpname)
+		return -ENOMEM;
+

drivers/perf/fsl_imx8_ddr_perf.c line 486

Quoted 10 lines
drivers/perf/fsl_imx8_ddr_perf.c new file +10 -0
+	pmu->flags = (uintptr_t) of_id->data;
+
+	cpumask_set_cpu(raw_smp_processor_id(), &pmu->cpu);
+	ret = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN, hpname, NULL,
+					 ddr_perf_offline_cpu);
+
+	if (ret < 0) {
+		dev_err(&pdev->dev, "cpuhp_setup_state_multi failed\n");
+		goto ddr_perf_err;
+	}

Since you don't seem to ever remove this state again, this looks like it would make subsequent loads of the module always fail after it's been loaded and unloaded once - have you tried that?

Robin.

Quoted 68 lines
drivers/perf/fsl_imx8_ddr_perf.c new file +67 -0
+
+	pmu->cpuhp_state = ret;
+
+	/* Register the pmu instance for cpu hotplug */
+	cpuhp_state_add_instance_nocalls(pmu->cpuhp_state, &pmu->node);
+
+	ret = perf_pmu_register(&(pmu->pmu), name, -1);
+	if (ret)
+		goto ddr_perf_err;
+
+	/* Request irq */
+	irq = of_irq_get(np, 0);
+	if (irq < 0) {
+		dev_err(&pdev->dev, "Failed to get irq: %d", irq);
+		ret = irq;
+		goto ddr_perf_irq_err;
+	}
+
+	ret = devm_request_irq(&pdev->dev, irq,
+					ddr_perf_irq_handler,
+					IRQF_TRIGGER_RISING | IRQF_ONESHOT,
+					DDR_PERF_DEV_NAME,
+					pmu);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "Request irq failed: %d", ret);
+		goto ddr_perf_irq_err;
+	}
+
+	return 0;
+
+ddr_perf_irq_err:
+	perf_pmu_unregister(&(pmu->pmu));
+
+ddr_perf_err:
+	if (pmu->cpuhp_state)
+		cpuhp_state_remove_instance_nocalls(pmu->cpuhp_state, &pmu->node);
+
+	dev_warn(&pdev->dev, "i.MX8 DDR Perf PMU failed (%d), disabled\n", ret);
+	return ret;
+}
+
+static int ddr_perf_remove(struct platform_device *pdev)
+{
+	struct ddr_pmu *pmu = platform_get_drvdata(pdev);
+
+	cpuhp_state_remove_instance_nocalls(pmu->cpuhp_state, &pmu->node);
+	perf_pmu_unregister(&pmu->pmu);
+
+	return 0;
+}
+
+static struct platform_driver imx_ddr_pmu_driver = {
+	.driver         = {
+		.name   = "imx-ddr-pmu",
+		.of_match_table = imx_ddr_pmu_dt_ids,
+	},
+	.probe          = ddr_perf_probe,
+	.remove         = ddr_perf_remove,
+};
+
+static int __init imx_ddr_pmu_init(void)
+{
+	return platform_driver_register(&imx_ddr_pmu_driver);
+}
+
+module_init(imx_ddr_pmu_init);
+
author maintainer
#6 lore raw

PATCH v5 3/4 arm64: dts: imx8qxp: added ddr performance monitor nodes

In reply to Frank Li

Add ddr performance monitor

---
Change from v3 to v5
* none

Change from v2 to v3
* ddr_pmu0 -> ddr-pmu

 arch/arm64/boot/dts/freescale/imx8qxp.dtsi | 7 +++++++
 1 file changed, 7 insertions(+)
arch/arm64/boot/dts/freescale/imx8qxp.dtsi +7 -0
index 0683ee2..16f2588 100644
@@ -110,6 +110,13 @@
 		interrupts = <GIC_PPI 7 IRQ_TYPE_LEVEL_HIGH>;
 	};
 
+	ddr-pmu@5c020000 {
+		compatible = "fsl,imx8-ddr-pmu";
+		reg = <0x0 0x5c020000 0x0 0x10000>;
+		interrupt-parent = <&gic>;
+		interrupts = <GIC_SPI 131 IRQ_TYPE_LEVEL_HIGH>;
+	};
+
 	psci {
 		compatible = "arm,psci-1.0";
 		method = "smc";
Signature · 1 line
2.5.2
author maintainer
#7 lore raw

PATCH v5 4/4 MAINTAINERS: Added imx DDR performonitor driver maintainer information

In reply to Frank Li

Add DDR perf counter driver maintainer information

---
No change from v1 to v5

 MAINTAINERS | 7 +++++++
 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
index b4a972f..332faba 100644
@@ -6263,6 +6263,13 @@ L:	[email protected]
 S:	Maintained
 F:	drivers/i2c/busses/i2c-cpm.c
 
+FREESCALE IMX DDR Performance Monitor DRIVER
+M:	Frank Li <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/perf/fsl_imx8_ddr_perf.c
+F:	Documentation/devicetree/bindings/perf/fsl-imx-ddr.txt
+
 FREESCALE IMX LPI2C DRIVER
 M:	Dong Aisheng <[email protected]>
 L:	[email protected]
Signature · 1 line
2.5.2