Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp487504rwl; Wed, 29 Mar 2023 04:59:43 -0700 (PDT) X-Google-Smtp-Source: AKy350Ym4aM1F51AfGIjNzFCWE5D9WkW/GR94IV1E4apm/LroNlANLcAlkjbfolQUFLmn1DeUVpz X-Received: by 2002:a05:6a20:4925:b0:db:6d42:118b with SMTP id ft37-20020a056a20492500b000db6d42118bmr2154900pzb.0.1680091183472; Wed, 29 Mar 2023 04:59:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680091183; cv=none; d=google.com; s=arc-20160816; b=VqPdhczvBkXLAf4XKV8bfXUqD5VmiXZTY1rWLu2E1HbnvyUc5YZNqEHWPts3zNhRxk sE2zB5Dll6nPZgdjphbUjThnwGnpiJAVARTYeahuhbI8TBHGUupqeE9bVXnn2T9wkkwb xpxNKeBebhCvplYcqcjfzIbmvfrMhvgnJl/37nR/CW/oK7Z4vU+uwq+cVFLdKmN6eHBA AmcaP3IOUZxpl4iLitgtNdGNr527YzUppSu2wPA9QnhwqpkLU3Q4rCEGUTcOlVId8hdF p6e53UqcFz0LKdW241cJw60xNPcBi6clArWZo5Clpcs2kz7b7ulbyUkXSI8eAzs2teFH fo5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id; bh=G5bZbSUy6GiItVUQ7wE3ubcdE4R2AgRlQGapyMSNRts=; b=nluLcQB1c/cQWL1MPlPaewsvJMafcaZDxTOkxUgBZgjyIe6pKkZ9Yt1UNsIB99s/El ayJgUL6POSqgXZLxwRdIRpyj1JCMQ1sruFfWH+CjxDJIZisk9Q1NokuxZLghOzQd3q+r b8u6hBYxcduxkWEFJvz1Ln/adYb84FuAKSbnjSe+VkC1qSzHCczCsGctERBZ2dCKUVNq pkjhDxOIFhbrvlTyrFww4P0Z7CbzzBGAL9tF7X4EHSVmwgzhYtS/ocjMR4z8vAgwR43/ FncBafygsr1GKwMvT+lusI1Zepi8sMUXORiQKP0e/3bxBsu5GXlp+ufITdza6NVM90j6 LMaQ== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f188-20020a6238c5000000b0062ae46c1c06si12245683pfa.78.2023.03.29.04.59.31; Wed, 29 Mar 2023 04:59:43 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229957AbjC2LyP (ORCPT + 99 others); Wed, 29 Mar 2023 07:54:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229949AbjC2LyJ (ORCPT ); Wed, 29 Mar 2023 07:54:09 -0400 Received: from out30-99.freemail.mail.aliyun.com (out30-99.freemail.mail.aliyun.com [115.124.30.99]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B4A84203; Wed, 29 Mar 2023 04:54:03 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R421e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046059;MF=renyu.zj@linux.alibaba.com;NM=1;PH=DS;RN=18;SR=0;TI=SMTPD_---0VewpsNi_1680090837; Received: from 30.221.149.47(mailfrom:renyu.zj@linux.alibaba.com fp:SMTPD_---0VewpsNi_1680090837) by smtp.aliyun-inc.com; Wed, 29 Mar 2023 19:53:58 +0800 Message-ID: <8ba831ae-4568-32af-3fd1-fd51a7c13dcd@linux.alibaba.com> Date: Wed, 29 Mar 2023 19:53:56 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: Re: [PATCH RFC 1/4] driver/perf: Add identifier sysfs file for CMN To: John Garry , Ian Rogers , Will Deacon , James Clark , Mike Leach , Leo Yan , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Ilkka Koskinen , Robin Murphy Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, Shuai Xue , Zhuo Song References: <1679885172-95021-1-git-send-email-renyu.zj@linux.alibaba.com> <1679885172-95021-2-git-send-email-renyu.zj@linux.alibaba.com> <72246c5e-6ba5-098b-a979-e90738cc7509@oracle.com> From: Jing Zhang In-Reply-To: <72246c5e-6ba5-098b-a979-e90738cc7509@oracle.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.0 required=5.0 tests=ENV_AND_HDR_SPF_MATCH, NICE_REPLY_A,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=unavailable 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 在 2023/3/27 下午3:55, John Garry 写道: > On 27/03/2023 03:46, Jing Zhang wrote: >> To allow userspace to identify the specific implementation of the device, >> add an "identifier" sysfs file. >> >> The perf tool can match the arm CMN metric through the identifier. >> >> Signed-off-by: Jing Zhang >> --- >>   drivers/perf/arm-cmn.c | 43 +++++++++++++++++++++++++++++++++++++++++++ >>   1 file changed, 43 insertions(+) >> >> diff --git a/drivers/perf/arm-cmn.c b/drivers/perf/arm-cmn.c >> index c968986..0c138ad 100644 >> --- a/drivers/perf/arm-cmn.c >> +++ b/drivers/perf/arm-cmn.c >> @@ -1168,10 +1168,53 @@ static ssize_t arm_cmn_cpumask_show(struct device *dev, >>       .attrs = arm_cmn_cpumask_attrs, >>   }; >>   +static ssize_t arm_cmn_identifier_show(struct device *dev, >> +        struct device_attribute *attr, char *buf) >> +{ >> +    struct arm_cmn *cmn = to_cmn(dev_get_drvdata(dev)); >> +    if (cmn->model == CMN700) { >> +        return sysfs_emit(buf, "%s\n", "CMN700"); > > Is it possible to have a pointer to this string in struct arm_cmn, such that we don't have to do this model to identifier lookup here? If-else chains like this are not scalable. > Will do. > BTW, does this HW have some HW identifier register, like iidr? I think that using that may be preferable. > I didn't find the relevant identifier register. Do Illka and Robin know that there is such a register that can identify different CMN versions? Looking forward to your suggestions. >> +    } >> +    else if (cmn->model == CMN650) { >> +        return sysfs_emit(buf, "%s\n", "CMN650"); > > I'd use lowercase names > Ok. >> +    } >> +    else if (cmn->model == CMN600) { >> +        return sysfs_emit(buf, "%s\n", "CMN600"); >> +    } >> +    else if (cmn->model == CI700) { >> +        return sysfs_emit(buf, "%s\n", "CI700"); >> +    } >> +    return sysfs_emit(buf, "%s\n", "UNKNOWN"); > > can we have a "is_visble" attr to just no show this when unknown? > Ok. >> +} >> + >> +static umode_t arm_cmn_identifier_attr_visible(struct kobject *kobj, >> +        struct attribute *attr, int n) >> +{ >> +    struct device *dev = kobj_to_dev(kobj); >> +    struct arm_cmn *cmn = to_cmn(dev_get_drvdata(dev)); >> +    if (cmn->model <= 0) >> +        return 0; >> +    return attr->mode; >> +}; >> + >> +static struct device_attribute arm_cmn_identifier_attr = >> +__ATTR(identifier, 0444, arm_cmn_identifier_show, NULL); >> + >> +static struct attribute *arm_cmn_identifier_attrs[] = { >> +    &arm_cmn_identifier_attr.attr, >> +    NULL, > > nit: no need for trailing ',' on a sentinel > Ok, Will do. >> +}; >> + >> +static struct attribute_group arm_cmn_identifier_attr_group = { >> +    .attrs = arm_cmn_identifier_attrs, >> +    .is_visible = arm_cmn_identifier_attr_visible, >> +}; >> + >>   static const struct attribute_group *arm_cmn_attr_groups[] = { >>       &arm_cmn_event_attrs_group, >>       &arm_cmn_format_attrs_group, >>       &arm_cmn_cpumask_attr_group, >> +    &arm_cmn_identifier_attr_group, >>       NULL >>   }; >>