From: Will Deacon <will.deacon@arm.com>
To: Zhi Li <lznuaa@gmail.com>
Cc: "mark.rutland@arm.com" <mark.rutland@arm.com>,
Aisheng Dong <aisheng.dong@nxp.com>,
"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
"festevam@gmail.com" <festevam@gmail.com>,
"s.hauer@pengutronix.de" <s.hauer@pengutronix.de>,
Frank Li <frank.li@nxp.com>,
"robh+dt@kernel.org" <robh+dt@kernel.org>,
dl-linux-imx <linux-imx@nxp.com>,
"kernel@pengutronix.de" <kernel@pengutronix.de>,
"shawnguo@kernel.org" <shawnguo@kernel.org>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH V9 2/4] drivers/perf: imx_ddr: Add ddr performance counter support
Date: Wed, 1 May 2019 14:53:12 +0100 [thread overview]
Message-ID: <20190501135312.GA27353@fuggles.cambridge.arm.com> (raw)
In-Reply-To: <CAHrpEqTqf2TFjrgdbu8RpYY6RKeJdX2Sz7yj+0-k5hE1gUCJ8w@mail.gmail.com>
On Tue, Apr 30, 2019 at 11:30:17AM -0500, Zhi Li wrote:
> On Tue, Apr 30, 2019 at 5:51 AM Will Deacon <will.deacon@arm.com> wrote:
> >
> > On Mon, Apr 29, 2019 at 04:44:32PM +0000, Frank Li wrote:
> > > diff --git a/drivers/perf/fsl_imx8_ddr_perf.c b/drivers/perf/fsl_imx8_ddr_perf.c
> > > new file mode 100644
> > > index 0000000..087d75a
> > > --- /dev/null
> > > +++ b/drivers/perf/fsl_imx8_ddr_perf.c
> > > @@ -0,0 +1,589 @@
> > > +// SPDX-License-Identifier: GPL-2.0
> > > +/*
> > > + * Copyright 2017 NXP
> > > + * Copyright 2016 Freescale Semiconductor, Inc.
> > > + */
> > > +
> > > +#include <linux/init.h>
> > > +#include <linux/interrupt.h>
> > > +#include <linux/io.h>
> > > +#include <linux/module.h>
> > > +#include <linux/of.h>
> > > +#include <linux/of_address.h>
> > > +#include <linux/of_device.h>
> > > +#include <linux/of_irq.h>
> > > +#include <linux/perf_event.h>
> > > +#include <linux/slab.h>
> > > +
> > > +#define COUNTER_CNTL 0x0
> > > +#define COUNTER_READ 0x20
> > > +
> > > +#define COUNTER_DPCR1 0x30
> > > +
> > > +#define CNTL_OVER 0x1
> > > +#define CNTL_CLEAR 0x2
> > > +#define CNTL_EN 0x4
> > > +#define CNTL_EN_MASK 0xFFFFFFFB
> > > +#define CNTL_CLEAR_MASK 0xFFFFFFFD
> > > +#define CNTL_OVER_MASK 0xFFFFFFFE
> > > +
> > > +#define CNTL_CSV_SHIFT 24
> > > +#define CNTL_CSV_MASK (0xFF << CNTL_CSV_SHIFT)
> > > +
> > > +#define EVENT_CYCLES_ID 0
> > > +#define EVENT_CYCLES_COUNTER 0
> > > +#define NUM_COUNTERS 4
> > > +
> > > +#define to_ddr_pmu(p) container_of(p, struct ddr_pmu, pmu)
> > > +
> > > +#define DDR_PERF_DEV_NAME "ddr_perf"
> >
> > This is far too generic. Please make it something like "imx8_ddr_perf_pmu".
> >
> > > +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;
> > > + int irq;
> > > +
> > > + 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);
> > > +
> > > + platform_set_drvdata(pdev, pmu);
> > > +
> > > + 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->cpu = raw_smp_processor_id();
> > > + ret = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN, hpname, NULL,
> > > + ddr_perf_offline_cpu);
> >
> > This doesn't seem right to me. My understanding of the cpuhp mechanism
> > is that you register a single multi-instance state as part of driver
> > initialisation, and then add an instance for each device you probe.
> > That means you don't need to kasprintf the callback name as you are above --
> > you can just use DDR_PERF_DEV_NAME instead.
> >
> > Please see how other perf drivers manage this on my for-next/perf branch.
> >
> > > +
> > > + if (ret < 0) {
> > > + dev_err(&pdev->dev, "cpuhp_setup_state_multi failed\n");
> > > + goto ddr_perf_err;
> > > + }
> > > +
> > > + 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);
> >
> > Again, the string you're passing in here is too generic. I suggest taking
> > DDR_PERF_DEV_NAME and adding "_%d" to the end to paste in your 'num'
> > identifier.
> >
> > Sorry if this feels like pedantry, but this gets exposed to userspace
> > via sysfs, so we need to be careful with the namespace.
>
> imx8_ddr_perf_pmu is too long to use. how about imx_ddr%d?
Too long for what? Drop the "perf" bit if you want, but I think we need
"pmu" in there.
Will
next prev parent reply other threads:[~2019-05-01 13:53 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-29 16:44 [PATCH V9 1/4] dt-bindings: perf: imx8-ddr: add imx8qxp ddr performance monitor Frank Li
2019-04-29 16:44 ` [PATCH V9 2/4] drivers/perf: imx_ddr: Add ddr performance counter support Frank Li
2019-04-30 10:51 ` Will Deacon
2019-04-30 16:30 ` Zhi Li
2019-05-01 13:53 ` Will Deacon [this message]
2019-04-30 18:59 ` [PATCH V9 2/4] drivers/perf: imx_ddr: Add ddr performance counter Andrey Smirnov
2019-04-30 20:08 ` Zhi Li
2019-05-01 1:06 ` Andrey Smirnov
2019-05-01 14:16 ` Zhi Li
2019-05-07 19:27 ` Andrey Smirnov
2019-04-29 16:44 ` [PATCH V9 3/4] arm64: dts: imx8qxp: added ddr performance monitor nodes Frank Li
2019-04-29 16:44 ` [PATCH V9 4/4] MAINTAINERS: Added imx DDR performonitor driver maintainer information Frank Li
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190501135312.GA27353@fuggles.cambridge.arm.com \
--to=will.deacon@arm.com \
--cc=aisheng.dong@nxp.com \
--cc=devicetree@vger.kernel.org \
--cc=festevam@gmail.com \
--cc=frank.li@nxp.com \
--cc=kernel@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-imx@nxp.com \
--cc=lznuaa@gmail.com \
--cc=mark.rutland@arm.com \
--cc=robh+dt@kernel.org \
--cc=s.hauer@pengutronix.de \
--cc=shawnguo@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).