Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp3121862pxy; Sun, 25 Apr 2021 14:44:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw50CN4FKSR43LpoRDyPpbxEHS/l2PXOOaS8tFn3ywYZbSjnRo+c7KG4QvdMVI0Anj5ywTl X-Received: by 2002:a17:90a:5885:: with SMTP id j5mr17342591pji.102.1619387071017; Sun, 25 Apr 2021 14:44:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619387071; cv=none; d=google.com; s=arc-20160816; b=jWdZNUXbECF+Xu2ne8SwHfnFkEkd2vrkLjpCMY4DbffH5fds7C4fmgpmMiagyzLYDt aNg2W28jOeIC691uqhnkTxUpKzv/wn0zdj7z/52E/uPQLLSqTqyiJEOBjAfWqLACC4MA VdrgZq+ZwyZUEpmYv7zx5IXdzChP4w99eAdKCZ7L03H5YYtyul2hdWdJmMHcYkNQRJsz k9xKWeK1jpanlVPoqynXSSG0VTXMUkCtwVt0KcFsL1KPjtFjaYvZVbgnQqQJTVIMG9JD A4X9WOPRYuww/jtiUzlIBPDGov9e2mOn3DV070HjcML0gzXRjhkR+auCim60VZ7FjKs4 PlRg== 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=iOePZAhFlMoloP84zaqZvTiKWh/Io7z/w2NS93ZuS/Q25ihSsuR6A79l0ZCJKFyjXv MqaNJzyqdfYSv3GUgoLkLpO7IZ227BnEPxiWCc8VltPw7chBRyhM9oEey4To7jDvPHf5 02QCHazjSA1dFtLuLoK6Vn5Quct9179ZyjYfMbF9gRjNdBTc8Hw6y9cs2v8hxvdYTTo1 1a35JIP5Yqcxtr45DFngRKNQG8rKLueC1PkNWjIi/eUVJdzKephCMsLMdAR20Z7B9mka Swnn3xF5APJf8TQ8GyibsmubMLvv5+9/n2AEKHldA64TAeuEFf4r283ttY7uPd3JkOoo JvtA== 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 e28si14882816pge.292.2021.04.25.14.44.19; Sun, 25 Apr 2021 14:44:31 -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 S231388AbhDYVo1 convert rfc822-to-8bit (ORCPT + 99 others); Sun, 25 Apr 2021 17:44:27 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:57786 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231365AbhDYVoY (ORCPT ); Sun, 25 Apr 2021 17:44:24 -0400 Received: from pps.filterd (m0109333.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 13PLUpEY004820 for ; Sun, 25 Apr 2021 14:43:44 -0700 Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com with ESMTP id 38530baa3g-7 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Sun, 25 Apr 2021 14:43:43 -0700 Received: from intmgw001.05.ash7.facebook.com (2620:10d:c085:208::f) by mail.thefacebook.com (2620:10d:c085:21d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Sun, 25 Apr 2021 14:43:43 -0700 Received: by devbig006.ftw2.facebook.com (Postfix, from userid 4523) id 076DB62E2330; Sun, 25 Apr 2021 14:43:40 -0700 (PDT) From: Song Liu To: CC: , , , , , , Song Liu Subject: [PATCH v5 1/5] perf util: move bpf_perf definitions to a libperf header Date: Sun, 25 Apr 2021 14:43:29 -0700 Message-ID: <20210425214333.1090950-2-song@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210425214333.1090950-1-song@kernel.org> References: <20210425214333.1090950-1-song@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8BIT X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-GUID: tqeEmG3rcB7m2c3LguhbubiSN6B2KSDH X-Proofpoint-ORIG-GUID: tqeEmG3rcB7m2c3LguhbubiSN6B2KSDH X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.761 definitions=2021-04-25_09:2021-04-23,2021-04-25 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 impostorscore=0 bulkscore=0 suspectscore=0 phishscore=0 clxscore=1015 adultscore=0 mlxscore=0 malwarescore=0 lowpriorityscore=0 spamscore=0 priorityscore=1501 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104250162 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