From patchwork Tue May 18 07:23:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "liuqi (BA)" X-Patchwork-Id: 12264001 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNWANTED_LANGUAGE_BODY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 52A93C433ED for ; Tue, 18 May 2021 07:28:20 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1C0CA6117A for ; Tue, 18 May 2021 07:28:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1C0CA6117A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=oPVVrKdOfOEzq+i+FZ6YoAzrSpV2w054Y/GO/QxI3bQ=; b=iCIe4PbLzU+0XABJss7sEM1Aq R9sTi+T0bKiDL3n4QhTr3ZdwDNxksNqG3vLevVjXfR0sDXCQlvtnukFsdicVa/o7+DJ603qu2bqXj K6eZ3LaUAx/FekF8pE+NQIjATTSWVu+fWuVCIvnMozOJIgHGisjlpeyMD3dY3dvvOqcG5GpACkYlq MpKNHA5FSwqxGUBFHYBM20jhsw1k6mLUCZAaUPXPxs8UaI4TbEN0ZioztlsozAWN9bUcytPB4e5hs CZHq+e5LlbnttGHASohIXE2+Bzc9p/qsuMCqsA188GVUBoizjA4pxa4tnWx/N7k21JmmXkv3Pj5Bs FGpYXcKmQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1liu7v-00HKtV-NH; Tue, 18 May 2021 07:26:52 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1liu5G-00HJlV-TV for linux-arm-kernel@desiato.infradead.org; Tue, 18 May 2021 07:24:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:CC:To:From:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=zYkvodCb3tOSCo42tQ4iMgJCv1nUE3oUUjz5ccG+5JI=; b=XadkYWYRthIcc38GZl45/pFReK t3WeUBYCskyIcAVch2s+4YlHv7tWbJmewhDiXG7jZ2/xTwCu0T82VxhSwI+yBzz0596PNjbzNfv3y Kn3bJcoh01QouuwlA0oiZYln32SzIPxbdcYr/Nuxr4iZEtzed2p21ssH3YPJew7oinWLBFtAnK6SK RysfugTVPvURNbSbtYo60+1VSQ3pZcn3tpoFum4f0C/NzWrTfAH+MYQb7jyP0qTDMN2oZ60AjBxNN LWREz0uRKas6TSBPvS3+XX6dHc7psgmLGTUTu4tRsfdsfeEc6AgTTPYgbai+3+AXFp7i7MZKE6ySr G3OH80Fg==; Received: from szxga07-in.huawei.com ([45.249.212.35]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1liu5C-00EPN7-93 for linux-arm-kernel@lists.infradead.org; Tue, 18 May 2021 07:24:05 +0000 Received: from dggems706-chm.china.huawei.com (unknown [172.30.72.59]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4FknVD3v7kzCtlw; Tue, 18 May 2021 15:21:08 +0800 (CST) Received: from dggema757-chm.china.huawei.com (10.1.198.199) by dggems706-chm.china.huawei.com (10.3.19.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2176.2; Tue, 18 May 2021 15:23:53 +0800 Received: from localhost.localdomain (10.69.192.56) by dggema757-chm.china.huawei.com (10.1.198.199) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Tue, 18 May 2021 15:23:53 +0800 From: Qi Liu To: , , CC: , , , Subject: [PATCH 1/9] perf: Add EVENT_ATTR_ID to simplify event attributes Date: Tue, 18 May 2021 15:23:40 +0800 Message-ID: <1621322628-9945-2-git-send-email-liuqi115@huawei.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1621322628-9945-1-git-send-email-liuqi115@huawei.com> References: <1621322628-9945-1-git-send-email-liuqi115@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggema757-chm.china.huawei.com (10.1.198.199) X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210518_002402_509821_B6FBC27E X-CRM114-Status: GOOD ( 10.10 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Similar EVENT_ATTR macros are defined in many PMU drivers, like HiSilicon PMU driver, Arm PMU driver, Arm SMMU PMU driver. So Add a generic macro to simplify code. Signed-off-by: Qi Liu --- include/linux/perf_event.h | 6 ++++++ kernel/events/core.c | 2 ++ 2 files changed, 8 insertions(+) diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index f5a6a2f..d0aa74e 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -1576,6 +1576,12 @@ static struct perf_pmu_events_attr _var = { \ .event_str = _str, \ }; +#define PMU_EVENT_ATTR_ID(_name, _id) \ + (&((struct perf_pmu_events_attr[]) { \ + { .attr = __ATTR(_name, 0444, perf_event_sysfs_show, NULL), \ + .id = _id, } \ + })[0].attr.attr) + #define PMU_FORMAT_ATTR(_name, _format) \ static ssize_t \ _name##_show(struct device *dev, \ diff --git a/kernel/events/core.c b/kernel/events/core.c index 0ac818b..330d9cc 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -13295,6 +13295,8 @@ ssize_t perf_event_sysfs_show(struct device *dev, struct device_attribute *attr, if (pmu_attr->event_str) return sprintf(page, "%s\n", pmu_attr->event_str); + else + return sprintf(page, "config=%#llx\n", pmu_attr->id); return 0; }