162306a36Sopenharmony_ci/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ 262306a36Sopenharmony_ci#ifndef __LIBPERF_BPF_PERF_H 362306a36Sopenharmony_ci#define __LIBPERF_BPF_PERF_H 462306a36Sopenharmony_ci 562306a36Sopenharmony_ci#include <linux/types.h> /* for __u32 */ 662306a36Sopenharmony_ci 762306a36Sopenharmony_ci/* 862306a36Sopenharmony_ci * bpf_perf uses a hashmap, the attr_map, to track all the leader programs. 962306a36Sopenharmony_ci * The hashmap is pinned in bpffs. flock() on this file is used to ensure 1062306a36Sopenharmony_ci * no concurrent access to the attr_map. The key of attr_map is struct 1162306a36Sopenharmony_ci * perf_event_attr, and the value is struct perf_event_attr_map_entry. 1262306a36Sopenharmony_ci * 1362306a36Sopenharmony_ci * struct perf_event_attr_map_entry contains two __u32 IDs, bpf_link of the 1462306a36Sopenharmony_ci * leader prog, and the diff_map. Each perf-stat session holds a reference 1562306a36Sopenharmony_ci * to the bpf_link to make sure the leader prog is attached to sched_switch 1662306a36Sopenharmony_ci * tracepoint. 1762306a36Sopenharmony_ci * 1862306a36Sopenharmony_ci * Since the hashmap only contains IDs of the bpf_link and diff_map, it 1962306a36Sopenharmony_ci * does not hold any references to the leader program. Once all perf-stat 2062306a36Sopenharmony_ci * sessions of these events exit, the leader prog, its maps, and the 2162306a36Sopenharmony_ci * perf_events will be freed. 2262306a36Sopenharmony_ci */ 2362306a36Sopenharmony_cistruct perf_event_attr_map_entry { 2462306a36Sopenharmony_ci __u32 link_id; 2562306a36Sopenharmony_ci __u32 diff_map_id; 2662306a36Sopenharmony_ci}; 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_ci/* default attr_map name */ 2962306a36Sopenharmony_ci#define BPF_PERF_DEFAULT_ATTR_MAP_PATH "perf_attr_map" 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ci#endif /* __LIBPERF_BPF_PERF_H */ 32