Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2828513pxb; Mon, 19 Apr 2021 15:19:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyga4f0pZO4BCRyizGSQIXeHlaBwYoSaU34vkg/zKKfBS0lBhFPJz53ivnSIlxUA8lTPkmq X-Received: by 2002:a17:90b:ed8:: with SMTP id gz24mr1355845pjb.98.1618870792660; Mon, 19 Apr 2021 15:19:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618870792; cv=none; d=google.com; s=arc-20160816; b=rXxW43zVlnY9PMvA1JIdN3rwj89XIKi2DwA6UgcZM7uZVPv7jD0Z5KhbXt/Hq8bn7U mpJgR+YJqJ6EgMctFzTgQEbiamPgvAWfvQm99GzEfx3HVXoR6ZjZhunP5BWvY0Uuk7gn q51FTvInIzPxS7YD0IvJhTzA9bG05EhbHe4sNM3wFPiegV9n1DXDj5cKiMaI2pu+OGMv dnxEwVWy96flzxZOZd/l7shwTN4O363pExQJoFvQbabtu+JnJlH6PPwEfJ7Tc4Ex8ix0 ZEJosdjbzRsjqb+vW31r8v0zknY2sMCPrNlFauP3KCDLWf/9Bj9ErEc1c1OwKMXJ9OoV 6rHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=R8pufiua8uceLPsBwd52nCJebMyY+jcuIfF1Zm/1a90=; b=qiljh/f2n1sWJetR7zfQ3K0tAraPy1zxe7+ngpY4rhQyhwv5/68gMT+yHUoooKu/ND FoU+5rs1LHbBH0pU0sDBwPs1e006kbHB8em2mVwVWFbJBsU2qYr+x6w9bFQmjn2g8xw3 cNbK7puTcreIiquJ9oDd90GZEjn5W4PY2m6QImnW1Y2w/gXcVFDlqImUk95mnwZvR/j6 O7dq+mP05VdTtDDbHETzmUbAsByn6tMV6xLd0qc94StnVA4Q0hHXoEiq/G2+UA+77LqV WnEYcAiZCGLG6YiKYSk4pTfEkvVfIyTnVJRHhus/ChHgE/CkMVFchRwKZ955c0gFYZUr tzYQ== 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j203si18812647pfd.133.2021.04.19.15.19.40; Mon, 19 Apr 2021 15:19:52 -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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242142AbhDSUhi convert rfc822-to-8bit (ORCPT + 99 others); Mon, 19 Apr 2021 16:37:38 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:11448 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234546AbhDSUhh (ORCPT ); Mon, 19 Apr 2021 16:37:37 -0400 Received: from pps.filterd (m0044012.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 13JKUZ5e031119 for ; Mon, 19 Apr 2021 13:37:07 -0700 Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com with ESMTP id 380fgxq6nj-6 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 19 Apr 2021 13:37:06 -0700 Received: from intmgw001.25.frc3.facebook.com (2620:10d:c085:208::f) by mail.thefacebook.com (2620:10d:c085:11d::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Mon, 19 Apr 2021 13:37:06 -0700 Received: by devbig006.ftw2.facebook.com (Postfix, from userid 4523) id 2AAAA62E1A1C; Mon, 19 Apr 2021 13:37:02 -0700 (PDT) From: Song Liu To: CC: , , , , , , Song Liu Subject: [PATCH v4 1/4] perf util: move bpf_perf definitions to a libperf header Date: Mon, 19 Apr 2021 13:36:46 -0700 Message-ID: <20210419203649.164121-2-song@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210419203649.164121-1-song@kernel.org> References: <20210419203649.164121-1-song@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8BIT X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-GUID: sMRXrW9nTtBJ8_S1Uk_ycDhVTHJBiGjj X-Proofpoint-ORIG-GUID: sMRXrW9nTtBJ8_S1Uk_ycDhVTHJBiGjj X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.761 definitions=2021-04-19_11:2021-04-19,2021-04-19 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 lowpriorityscore=0 impostorscore=0 suspectscore=0 adultscore=0 clxscore=1015 malwarescore=0 phishscore=0 mlxlogscore=999 bulkscore=0 priorityscore=1501 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104190141 X-FB-Internal: deliver Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org By following the same protocol, other tools can share hardware PMCs with perf. Move perf_event_attr_map_entry and BPF_PERF_DEFAULT_ATTR_MAP_PATH to bpf_perf.h for other tools to use. Signed-off-by: Song Liu --- tools/lib/perf/include/perf/bpf_perf.h | 31 ++++++++++++++++++++++++++ tools/perf/util/bpf_counter.c | 27 +++------------------- 2 files changed, 34 insertions(+), 24 deletions(-) create mode 100644 tools/lib/perf/include/perf/bpf_perf.h diff --git a/tools/lib/perf/include/perf/bpf_perf.h b/tools/lib/perf/include/perf/bpf_perf.h new file mode 100644 index 0000000000000..e7cf6ba7b674b --- /dev/null +++ b/tools/lib/perf/include/perf/bpf_perf.h @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ +#ifndef __LIBPERF_BPF_PERF_H +#define __LIBPERF_BPF_PERF_H + +#include /* for __u32 */ + +/* + * bpf_perf uses a hashmap, the attr_map, to track all the leader programs. + * The hashmap is pinned in bpffs. flock() on this file is used to ensure + * no concurrent access to the attr_map. The key of attr_map is struct + * perf_event_attr, and the value is struct perf_event_attr_map_entry. + * + * struct perf_event_attr_map_entry contains two __u32 IDs, bpf_link of the + * leader prog, and the diff_map. Each perf-stat session holds a reference + * to the bpf_link to make sure the leader prog is attached to sched_switch + * tracepoint. + * + * Since the hashmap only contains IDs of the bpf_link and diff_map, it + * does not hold any references to the leader program. Once all perf-stat + * sessions of these events exit, the leader prog, its maps, and the + * perf_events will be freed. + */ +struct perf_event_attr_map_entry { + __u32 link_id; + __u32 diff_map_id; +}; + +/* default attr_map name */ +#define BPF_PERF_DEFAULT_ATTR_MAP_PATH "perf_attr_map" + +#endif /* __LIBPERF_BPF_PERF_H */ diff --git a/tools/perf/util/bpf_counter.c b/tools/perf/util/bpf_counter.c index 81d1df3c4ec0e..be484ddbbd5be 100644 --- a/tools/perf/util/bpf_counter.c +++ b/tools/perf/util/bpf_counter.c @@ -14,6 +14,7 @@ #include #include #include +#include #include "bpf_counter.h" #include "counts.h" @@ -29,28 +30,6 @@ #include "bpf_skel/bperf_leader.skel.h" #include "bpf_skel/bperf_follower.skel.h" -/* - * bperf uses a hashmap, the attr_map, to track all the leader programs. - * The hashmap is pinned in bpffs. flock() on this file is used to ensure - * no concurrent access to the attr_map. The key of attr_map is struct - * perf_event_attr, and the value is struct perf_event_attr_map_entry. - * - * struct perf_event_attr_map_entry contains two __u32 IDs, bpf_link of the - * leader prog, and the diff_map. Each perf-stat session holds a reference - * to the bpf_link to make sure the leader prog is attached to sched_switch - * tracepoint. - * - * Since the hashmap only contains IDs of the bpf_link and diff_map, it - * does not hold any references to the leader program. Once all perf-stat - * sessions of these events exit, the leader prog, its maps, and the - * perf_events will be freed. - */ -struct perf_event_attr_map_entry { - __u32 link_id; - __u32 diff_map_id; -}; - -#define DEFAULT_ATTR_MAP_PATH "fs/bpf/perf_attr_map" #define ATTR_MAP_SIZE 16 static inline void *u64_to_ptr(__u64 ptr) @@ -341,8 +320,8 @@ static int bperf_lock_attr_map(struct target *target) if (target->attr_map) { scnprintf(path, PATH_MAX, "%s", target->attr_map); } else { - scnprintf(path, PATH_MAX, "%s/%s", sysfs__mountpoint(), - DEFAULT_ATTR_MAP_PATH); + scnprintf(path, PATH_MAX, "%s/fs/bpf/%s", sysfs__mountpoint(), + BPF_PERF_DEFAULT_ATTR_MAP_PATH); } if (access(path, F_OK)) { -- 2.30.2