perf env: Conditionally compile BPF support code on having HAVE_LIBBPF_SUPPORT

If libbpf isn't selected, no need for a bunch of related code, that were
not even being used, as code using these perf_env methods was also
enclosed in HAVE_LIBBPF_SUPPORT.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 20e88c60
...@@ -11,8 +11,10 @@ ...@@ -11,8 +11,10 @@
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <stdlib.h> #include <stdlib.h>
#ifdef HAVE_LIBBPF_SUPPORT
#include <bpf/libbpf.h> #include <bpf/libbpf.h>
#include "bpf-event.h" #include "bpf-event.h"
#endif
#include "compress.h" #include "compress.h"
#include "env.h" #include "env.h"
#include "namespaces.h" #include "namespaces.h"
...@@ -728,6 +730,7 @@ bool dso__data_status_seen(struct dso *dso, enum dso_data_status_seen by) ...@@ -728,6 +730,7 @@ bool dso__data_status_seen(struct dso *dso, enum dso_data_status_seen by)
return false; return false;
} }
#ifdef HAVE_LIBBPF_SUPPORT
static ssize_t bpf_read(struct dso *dso, u64 offset, char *data) static ssize_t bpf_read(struct dso *dso, u64 offset, char *data)
{ {
struct bpf_prog_info_node *node; struct bpf_prog_info_node *node;
...@@ -765,6 +768,7 @@ static int bpf_size(struct dso *dso) ...@@ -765,6 +768,7 @@ static int bpf_size(struct dso *dso)
dso->data.file_size = node->info_linear->info.jited_prog_len; dso->data.file_size = node->info_linear->info.jited_prog_len;
return 0; return 0;
} }
#endif // HAVE_LIBBPF_SUPPORT
static void static void
dso_cache__free(struct dso *dso) dso_cache__free(struct dso *dso)
...@@ -894,10 +898,12 @@ static struct dso_cache *dso_cache__populate(struct dso *dso, ...@@ -894,10 +898,12 @@ static struct dso_cache *dso_cache__populate(struct dso *dso,
*ret = -ENOMEM; *ret = -ENOMEM;
return NULL; return NULL;
} }
#ifdef HAVE_LIBBPF_SUPPORT
if (dso->binary_type == DSO_BINARY_TYPE__BPF_PROG_INFO) if (dso->binary_type == DSO_BINARY_TYPE__BPF_PROG_INFO)
*ret = bpf_read(dso, cache_offset, cache->data); *ret = bpf_read(dso, cache_offset, cache->data);
else if (dso->binary_type == DSO_BINARY_TYPE__OOL) else
#endif
if (dso->binary_type == DSO_BINARY_TYPE__OOL)
*ret = DSO__DATA_CACHE_SIZE; *ret = DSO__DATA_CACHE_SIZE;
else else
*ret = file_read(dso, machine, cache_offset, cache->data); *ret = file_read(dso, machine, cache_offset, cache->data);
...@@ -1018,10 +1024,10 @@ int dso__data_file_size(struct dso *dso, struct machine *machine) ...@@ -1018,10 +1024,10 @@ int dso__data_file_size(struct dso *dso, struct machine *machine)
if (dso->data.status == DSO_DATA_STATUS_ERROR) if (dso->data.status == DSO_DATA_STATUS_ERROR)
return -1; return -1;
#ifdef HAVE_LIBBPF_SUPPORT
if (dso->binary_type == DSO_BINARY_TYPE__BPF_PROG_INFO) if (dso->binary_type == DSO_BINARY_TYPE__BPF_PROG_INFO)
return bpf_size(dso); return bpf_size(dso);
#endif
return file_size(dso, machine); return file_size(dso, machine);
} }
......
...@@ -5,16 +5,18 @@ ...@@ -5,16 +5,18 @@
#include "util/header.h" #include "util/header.h"
#include <linux/ctype.h> #include <linux/ctype.h>
#include <linux/zalloc.h> #include <linux/zalloc.h>
#include "bpf-event.h"
#include "cgroup.h" #include "cgroup.h"
#include <errno.h> #include <errno.h>
#include <sys/utsname.h> #include <sys/utsname.h>
#include <bpf/libbpf.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
struct perf_env perf_env; struct perf_env perf_env;
#ifdef HAVE_LIBBPF_SUPPORT
#include "bpf-event.h"
#include <bpf/libbpf.h>
void perf_env__insert_bpf_prog_info(struct perf_env *env, void perf_env__insert_bpf_prog_info(struct perf_env *env,
struct bpf_prog_info_node *info_node) struct bpf_prog_info_node *info_node)
{ {
...@@ -163,6 +165,11 @@ static void perf_env__purge_bpf(struct perf_env *env) ...@@ -163,6 +165,11 @@ static void perf_env__purge_bpf(struct perf_env *env)
up_write(&env->bpf_progs.lock); up_write(&env->bpf_progs.lock);
} }
#else // HAVE_LIBBPF_SUPPORT
static void perf_env__purge_bpf(struct perf_env *env __maybe_unused)
{
}
#endif // HAVE_LIBBPF_SUPPORT
void perf_env__exit(struct perf_env *env) void perf_env__exit(struct perf_env *env)
{ {
...@@ -197,11 +204,13 @@ void perf_env__exit(struct perf_env *env) ...@@ -197,11 +204,13 @@ void perf_env__exit(struct perf_env *env)
zfree(&env->memory_nodes); zfree(&env->memory_nodes);
} }
void perf_env__init(struct perf_env *env) void perf_env__init(struct perf_env *env __maybe_unused)
{ {
#ifdef HAVE_LIBBPF_SUPPORT
env->bpf_progs.infos = RB_ROOT; env->bpf_progs.infos = RB_ROOT;
env->bpf_progs.btfs = RB_ROOT; env->bpf_progs.btfs = RB_ROOT;
init_rwsem(&env->bpf_progs.lock); init_rwsem(&env->bpf_progs.lock);
#endif
} }
int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv[]) int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv[])
......
...@@ -77,7 +77,7 @@ struct perf_env { ...@@ -77,7 +77,7 @@ struct perf_env {
struct numa_node *numa_nodes; struct numa_node *numa_nodes;
struct memory_node *memory_nodes; struct memory_node *memory_nodes;
unsigned long long memory_bsize; unsigned long long memory_bsize;
#ifdef HAVE_LIBBPF_SUPPORT
/* /*
* bpf_info_lock protects bpf rbtrees. This is needed because the * bpf_info_lock protects bpf rbtrees. This is needed because the
* trees are accessed by different threads in perf-top * trees are accessed by different threads in perf-top
...@@ -89,7 +89,7 @@ struct perf_env { ...@@ -89,7 +89,7 @@ struct perf_env {
struct rb_root btfs; struct rb_root btfs;
u32 btfs_cnt; u32 btfs_cnt;
} bpf_progs; } bpf_progs;
#endif // HAVE_LIBBPF_SUPPORT
/* same reason as above (for perf-top) */ /* same reason as above (for perf-top) */
struct { struct {
struct rw_semaphore lock; struct rw_semaphore lock;
......
...@@ -19,7 +19,9 @@ ...@@ -19,7 +19,9 @@
#include <sys/utsname.h> #include <sys/utsname.h>
#include <linux/time64.h> #include <linux/time64.h>
#include <dirent.h> #include <dirent.h>
#ifdef HAVE_LIBBPF_SUPPORT
#include <bpf/libbpf.h> #include <bpf/libbpf.h>
#endif
#include <perf/cpumap.h> #include <perf/cpumap.h>
#include "dso.h" #include "dso.h"
...@@ -987,13 +989,6 @@ static int write_bpf_prog_info(struct feat_fd *ff, ...@@ -987,13 +989,6 @@ static int write_bpf_prog_info(struct feat_fd *ff,
up_read(&env->bpf_progs.lock); up_read(&env->bpf_progs.lock);
return ret; return ret;
} }
#else // HAVE_LIBBPF_SUPPORT
static int write_bpf_prog_info(struct feat_fd *ff __maybe_unused,
struct evlist *evlist __maybe_unused)
{
return 0;
}
#endif // HAVE_LIBBPF_SUPPORT
static int write_bpf_btf(struct feat_fd *ff, static int write_bpf_btf(struct feat_fd *ff,
struct evlist *evlist __maybe_unused) struct evlist *evlist __maybe_unused)
...@@ -1027,6 +1022,7 @@ static int write_bpf_btf(struct feat_fd *ff, ...@@ -1027,6 +1022,7 @@ static int write_bpf_btf(struct feat_fd *ff,
up_read(&env->bpf_progs.lock); up_read(&env->bpf_progs.lock);
return ret; return ret;
} }
#endif // HAVE_LIBBPF_SUPPORT
static int cpu_cache_level__sort(const void *a, const void *b) static int cpu_cache_level__sort(const void *a, const void *b)
{ {
...@@ -1638,6 +1634,7 @@ static void print_dir_format(struct feat_fd *ff, FILE *fp) ...@@ -1638,6 +1634,7 @@ static void print_dir_format(struct feat_fd *ff, FILE *fp)
fprintf(fp, "# directory data version : %"PRIu64"\n", data->dir.version); fprintf(fp, "# directory data version : %"PRIu64"\n", data->dir.version);
} }
#ifdef HAVE_LIBBPF_SUPPORT
static void print_bpf_prog_info(struct feat_fd *ff, FILE *fp) static void print_bpf_prog_info(struct feat_fd *ff, FILE *fp)
{ {
struct perf_env *env = &ff->ph->env; struct perf_env *env = &ff->ph->env;
...@@ -1683,6 +1680,7 @@ static void print_bpf_btf(struct feat_fd *ff, FILE *fp) ...@@ -1683,6 +1680,7 @@ static void print_bpf_btf(struct feat_fd *ff, FILE *fp)
up_read(&env->bpf_progs.lock); up_read(&env->bpf_progs.lock);
} }
#endif // HAVE_LIBBPF_SUPPORT
static void free_event_desc(struct evsel *events) static void free_event_desc(struct evsel *events)
{ {
...@@ -2938,12 +2936,6 @@ static int process_bpf_prog_info(struct feat_fd *ff, void *data __maybe_unused) ...@@ -2938,12 +2936,6 @@ static int process_bpf_prog_info(struct feat_fd *ff, void *data __maybe_unused)
up_write(&env->bpf_progs.lock); up_write(&env->bpf_progs.lock);
return err; return err;
} }
#else // HAVE_LIBBPF_SUPPORT
static int process_bpf_prog_info(struct feat_fd *ff __maybe_unused, void *data __maybe_unused)
{
return 0;
}
#endif // HAVE_LIBBPF_SUPPORT
static int process_bpf_btf(struct feat_fd *ff, void *data __maybe_unused) static int process_bpf_btf(struct feat_fd *ff, void *data __maybe_unused)
{ {
...@@ -2990,6 +2982,7 @@ static int process_bpf_btf(struct feat_fd *ff, void *data __maybe_unused) ...@@ -2990,6 +2982,7 @@ static int process_bpf_btf(struct feat_fd *ff, void *data __maybe_unused)
free(node); free(node);
return err; return err;
} }
#endif // HAVE_LIBBPF_SUPPORT
static int process_compressed(struct feat_fd *ff, static int process_compressed(struct feat_fd *ff,
void *data __maybe_unused) void *data __maybe_unused)
...@@ -3120,8 +3113,10 @@ const struct perf_header_feature_ops feat_ops[HEADER_LAST_FEATURE] = { ...@@ -3120,8 +3113,10 @@ const struct perf_header_feature_ops feat_ops[HEADER_LAST_FEATURE] = {
FEAT_OPR(MEM_TOPOLOGY, mem_topology, true), FEAT_OPR(MEM_TOPOLOGY, mem_topology, true),
FEAT_OPR(CLOCKID, clockid, false), FEAT_OPR(CLOCKID, clockid, false),
FEAT_OPN(DIR_FORMAT, dir_format, false), FEAT_OPN(DIR_FORMAT, dir_format, false),
#ifdef HAVE_LIBBPF_SUPPORT
FEAT_OPR(BPF_PROG_INFO, bpf_prog_info, false), FEAT_OPR(BPF_PROG_INFO, bpf_prog_info, false),
FEAT_OPR(BPF_BTF, bpf_btf, false), FEAT_OPR(BPF_BTF, bpf_btf, false),
#endif
FEAT_OPR(COMPRESSED, compressed, false), FEAT_OPR(COMPRESSED, compressed, false),
FEAT_OPR(CPU_PMU_CAPS, cpu_pmu_caps, false), FEAT_OPR(CPU_PMU_CAPS, cpu_pmu_caps, false),
FEAT_OPR(CLOCK_DATA, clock_data, false), FEAT_OPR(CLOCK_DATA, clock_data, false),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment