Received: by 2002:a05:6520:4211:b029:f4:110d:56bc with SMTP id o17csp1547338lkv; Wed, 19 May 2021 12:29:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxmcwPmNeanwM0lpjYE+QLdTFLf4hlGHUT41M1by7uffPh3a/bWbuFoI4Geuk2Y0+aj13vq X-Received: by 2002:a05:6402:4389:: with SMTP id o9mr664936edc.368.1621452540384; Wed, 19 May 2021 12:29:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621452540; cv=none; d=google.com; s=arc-20160816; b=aKxuElp8fgsu4q3iKapUB3tmv9OVTYCAxQs6St+26+x7TzRdtzpmY4nwU1fv206NIa aONtfPKQPECtNzNQ6oz1CCjDb18G+YZXGELR0QAGq/x9kA3C2tpyrl0Vk80l12gRuSws C07Fvfx01mvXBf7ajwRO+oNAPwkKoUz4cYZ+aCCQYSOxibp1BmltLuGKnT74MeQE+X6I LRWOwUNrq1NfOcOzJiUbMwXA5i7xTm6arWCvp2zWruiWpRVf3LFECCmttJkndwbM6XNi +PfDg4PAkA7/lD9Eg5FLARQozaGDqxoWygCjXDecme/rUCHqZC8Ia52n6sJOKBLZz2Xm gs6A== 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=zt72zUO9LaRM+7GKYK70dhMdtOqHHRpoCzSQFnRTXDw=; b=z4qPWmt50vfZnUbIZqj35Xs9jAfHMCo5K2Oqekk/VGQe+6WELbODeMBCR/2KpOfvpx OGbjBWv36X0yfnzjPF7YosiwzsIet7H7PPTE1A790KblRFti1nx9YoQlswPgqcu7cSfu +nJhVfFL60ayduV9CYztX5aSkr9ybrCchwJQgAJ3VMNefPzw0ypjxU7aEV4VMOy5Rq04 yduyQhb9wzML/1BBpwicneScDGo3FJ60dA+CKBuhUFcKh0D1WBvsq8QCYkQifmZXuG0C xwlXthCbWgHXmXx03TNjW5Ze0QObGatIA8fGpVzD8kbhrpXEDIwg1prMo2hZLFmKYMHg yvqA== 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 q26si97721edr.164.2021.05.19.12.28.35; Wed, 19 May 2021 12:29:00 -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 S1346901AbhESJxl (ORCPT + 99 others); Wed, 19 May 2021 05:53:41 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:4529 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346596AbhESJxg (ORCPT ); Wed, 19 May 2021 05:53:36 -0400 Received: from dggems704-chm.china.huawei.com (unknown [172.30.72.60]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4FlSkw1ntTzsRCG; Wed, 19 May 2021 17:49:28 +0800 (CST) Received: from dggema757-chm.china.huawei.com (10.1.198.199) by dggems704-chm.china.huawei.com (10.3.19.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2176.2; Wed, 19 May 2021 17:52:14 +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; Wed, 19 May 2021 17:52:13 +0800 From: Qi Liu To: , CC: , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin Subject: [PATCH v2 1/9] perf: Add EVENT_ATTR_ID to simplify event attributes Date: Wed, 19 May 2021 17:51:51 +0800 Message-ID: <1621417919-6632-2-git-send-email-liuqi115@huawei.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1621417919-6632-1-git-send-email-liuqi115@huawei.com> References: <1621417919-6632-1-git-send-email-liuqi115@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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. Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Arnaldo Carvalho de Melo Cc: Mark Rutland Cc: Alexander Shishkin 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