Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp3158298iog; Mon, 20 Jun 2022 12:44:18 -0700 (PDT) X-Google-Smtp-Source: AGRyM1umz0FQE22+WQIGZEwOaf/4aEB7I0Bcq2eebeYqmnYmUTJTELB4V8qiwh6jpcYorvQyMHvK X-Received: by 2002:a17:902:76c4:b0:16a:deb:c0ae with SMTP id j4-20020a17090276c400b0016a0debc0aemr15644954plt.22.1655754258667; Mon, 20 Jun 2022 12:44:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655754258; cv=none; d=google.com; s=arc-20160816; b=ApAvuVNYzY59VJ+NKXCfGso8AbC86F6X7opIeiCwmpsW1GZrfC5zR3BZpKtHxAKnCQ SxXgQbHY1Nz6SXiNJ/ibuyO7hv6gyy7Bnt9vE58dww1ztBSETef0UtZApIVdNg20ac8K TFEUHGkpiwqY0o/OkF6U7uxC3ccvo2hZqDX7Kft586sCFnBhVRD4YYMbRIqB3bw2ws8h tyGYsQOUbxEQhXniy3CPStYw71Bz/Cyn3IVhsE846/MWSzI1aA4TQFbTqqT+LU9RnNKI Qg1mTaT/RMTokhr30k+ixUZgjOmICi2ZoAxDx+95oEwZd0u4hkvmn/9QcGEenUsKSM2F WSAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=MF9w10rX2iwd2h9iSBKKxPfiedtUNAOz+4kVUvfb89E=; b=Lyjrm9LKd044pBO92TZwauYfgCWG/1z0iFgy7KwidYCVjdas3dh4t6YGTGQufD+l70 NfRiGJJQ6tYTV+ycS+z2Di7E/2Yt4ZyrG5LfyiM7sYtzrvCi6BEXb2H9deZh+e7+7XyV IeGGdG65+IcsZfP6X1mWEU9EFNRH1m57977xgSpiBUOlrFs+qLdufdvIOrQUuYY0pitd iNQ8T23WWAJbmXGm4iePpPxeyGTJ+RQA/PsmdZ1DssPnZ8WZZV+yi45c6JBVDlyGuBTJ 5UZ+Fb5gtNliUxgISL6+A4PLyrluMj6apBSo9NngPBMH6f9MI9zE426AC/pTVHxubHok 8rnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b=GG1JkTho; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z2-20020a170903018200b00163ddc0d459si5963003plg.320.2022.06.20.12.44.06; Mon, 20 Jun 2022 12:44:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b=GG1JkTho; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243547AbiFTTkf (ORCPT + 99 others); Mon, 20 Jun 2022 15:40:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233184AbiFTTke (ORCPT ); Mon, 20 Jun 2022 15:40:34 -0400 Received: from mail-yb1-xb29.google.com (mail-yb1-xb29.google.com [IPv6:2607:f8b0:4864:20::b29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC8D8764E for ; Mon, 20 Jun 2022 12:40:32 -0700 (PDT) Received: by mail-yb1-xb29.google.com with SMTP id t1so20745482ybd.2 for ; Mon, 20 Jun 2022 12:40:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=atishpatra.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=MF9w10rX2iwd2h9iSBKKxPfiedtUNAOz+4kVUvfb89E=; b=GG1JkThoq/+mdEhocGlISJpVEjHwAeMStlF2BWci9LDLNiYtOlkacsBNZIpZecrjsh fdXdX+wm2DII0sQ2l84LTw9a/+ECRVwrXXQMYmTPPX4YFQciutNx+K6WKcrFhhntyfrc nVkj0ns8Zakha5fZW91ck71QyOYRNYgY4qVg4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=MF9w10rX2iwd2h9iSBKKxPfiedtUNAOz+4kVUvfb89E=; b=Me9/g6fz1aSX6g0uB8nlS+gTviUghSJwZGmr1eoU4w4hTjTHvI9xCBGlG5anRw/Tlr UOit9s9cMNNXhtd96Qz5mxGKxOfbO9tP5Na6hVm+CrvHaMBHf0WEx718n7yuf3WK29T1 lE3+vW2wUhmoEIpezagpP7io1kD06yGD/E6ieeZ5HQeaNtBTPurJ2ui9mAY5yVbBGNrO UdpRxoJq3Zazc38exvQBhVeykdQHEwI1VviCz4x2JOdfELoOeiNrBCQfXXveYr+knFnb GqLq5+Kl2WIMa1QV1HsnrP8M4zQCeNLBqJp/8WgzYGQ0sYeixJpDS0lLlDc8ayJaXbx2 bAjA== X-Gm-Message-State: AJIora+usMDrmbzJ8HgXSAmcVZkn5xNYGUICP/s/x3O15MbcrWh8nTBR v38IMQXyTksXdS9C+v0Qjze8iToXyAq7xgsP7oQp X-Received: by 2002:a25:2612:0:b0:664:b1e1:3774 with SMTP id m18-20020a252612000000b00664b1e13774mr26937447ybm.228.1655754031926; Mon, 20 Jun 2022 12:40:31 -0700 (PDT) MIME-Version: 1.0 References: <20220619111115.6354-1-nikita.shubin@maquefel.me> <20220619111115.6354-2-nikita.shubin@maquefel.me> <20220620174006.1c86a456@redslave.neermore.group> In-Reply-To: <20220620174006.1c86a456@redslave.neermore.group> From: Atish Patra Date: Mon, 20 Jun 2022 12:40:20 -0700 Message-ID: Subject: Re: [PATCH v4 1/1] RISC-V: Create unique identification for SoC PMU To: Nikita Shubin Cc: Anup Patel , Will Deacon , Sunil V L , =?UTF-8?B?Sm/Do28gTcOhcmlvIERvbWluZ29z?= , 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 20, 2022 at 7:40 AM Nikita Shubin w= rote: > > On Mon, 20 Jun 2022 17:30:58 +0530 > Anup Patel wrote: > > > On Sun, Jun 19, 2022 at 4:41 PM Nikita Shubin > > wrote: > > > > > > From: Nikita Shubin > > > > > > 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=C3=A3o M=C3=A1rio Domingos > > > Signed-off-by: Nikita Shubin > > > > 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@ventanamicr= o.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/cpui= nfo). 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 =3D container_of(dev_get_drvdata(dev), > > > struct riscv_pmu, pmu); + > > > + len =3D sprintf(buf, "%s\n", pmu->pmuid); > > > + if (len <=3D 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[] =3D { > > > + &dev_attr_id.attr, > > > + NULL > > > +}; > > > + > > > +ATTRIBUTE_GROUPS(pmu_sbi); > > > + > > > static int pmu_sbi_device_probe(struct platform_device *pdev) > > > { > > > struct riscv_pmu *pmu =3D 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 =3D 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 =3D 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 =3D sysfs_create_group(&pdev->dev.kobj, &pmu_sbi_group); > > > + if (ret) { > > > + dev_err(&pdev->dev, "sysfs creation failed\n"); > > > + return ret; > > > + } > > > + > > > + pdev->dev.groups =3D 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 > > > > --=20 Regards, Atish