Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1574912pxj; Wed, 19 May 2021 08:58:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz0jnl/pITu3lczBpkHT9NT7RLDdYqd1fI8ljyu/tvCv1fiAQOozulEDcdUPQdw8ETUiZJg X-Received: by 2002:a05:6402:22fa:: with SMTP id dn26mr15072990edb.5.1621439926766; Wed, 19 May 2021 08:58:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621439926; cv=none; d=google.com; s=arc-20160816; b=JjOBxi0UCVGGZ5pRg+n36RKbPqZLGHIdQBabjDvH69mq9AqkgRJC1Ez7AM9F4H2+RG kuk+8/9JVUZcTgiRXkHnHzhBBq9u5EBacAjXY6GMJOiGix/TYUyNVYfWsAppftKGh541 EaDP+lyI+PLva8BAGi89OBd14eg6owuRhzUu26JI9vG5Hm9YVFHIM84xmkXIv7e4cUAf N/oQ3HrzE9g8XCgMnnPwJR91rHf+klA+cqZIxduhi9DaBDJ0V9G8ZQjdEvSSVKdNYf1C zjaNL089cPvflXPTl8mHPub51W2J6DG2JchOt95mudgOfRsxLJMRHnUU7EGlNR5HCSZE 4LQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=zYkvodCb3tOSCo42tQ4iMgJCv1nUE3oUUjz5ccG+5JI=; b=DRJKUZLiol5pwBUP0jadAHzx8b2k6r6qCChZwBMVHrUYrum9MvfFLlR6yKCYhnCM9+ W6CKZrAbqtM30dzMwbcj2PWqg7axCoEOYy30sB0jhHk4KDNLrsp55Yc9rZHTIt/r7exE 8meKK7Q0jyeDrW0n1tSElBkaQhpc3B5TE7Fni+jJDZYZPncuJhCAdGaZ3rn1o65cbE47 RjMiN9ce9be8Tu+3nyyJvkfpfuLgUT4PxQflihR+eZd9sFyelEuCtPq9uTVbQvxTqikG gRGBKHhvCZMLgWwmX27gu6QIWdreXiHyHLhXNHztXfpUkVPlkCaya7BMgf7mEQnGNSzX PXCA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ce5si340662edb.102.2021.05.19.08.58.23; Wed, 19 May 2021 08:58:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242375AbhERHZc (ORCPT + 99 others); Tue, 18 May 2021 03:25:32 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:2962 "EHLO szxga07-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240235AbhERHZO (ORCPT ); Tue, 18 May 2021 03:25:14 -0400 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 Content-Type: text/plain 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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; } -- 2.7.4