Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2992464AbbHHIQa (ORCPT ); Sat, 8 Aug 2015 04:16:30 -0400 Received: from terminus.zytor.com ([198.137.202.10]:53883 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2992446AbbHHIQX (ORCPT ); Sat, 8 Aug 2015 04:16:23 -0400 Date: Sat, 8 Aug 2015 01:15:44 -0700 From: tip-bot for Wang Nan Message-ID: Cc: mingo@kernel.org, namhyung@kernel.org, hpa@zytor.com, ast@plumgrid.com, masami.hiramatsu.pt@hitachi.com, a.p.zijlstra@chello.nl, wangnan0@huawei.com, daniel@iogearbox.net, acme@redhat.com, hekuang@huawei.com, tglx@linutronix.de, jolsa@kernel.org, linux-kernel@vger.kernel.org, xiakaixu@huawei.com, brendan.d.gregg@gmail.com, lizefan@huawei.com, dsahern@gmail.com Reply-To: acme@redhat.com, hekuang@huawei.com, a.p.zijlstra@chello.nl, wangnan0@huawei.com, daniel@iogearbox.net, mingo@kernel.org, masami.hiramatsu.pt@hitachi.com, ast@plumgrid.com, namhyung@kernel.org, hpa@zytor.com, dsahern@gmail.com, brendan.d.gregg@gmail.com, lizefan@huawei.com, xiakaixu@huawei.com, linux-kernel@vger.kernel.org, tglx@linutronix.de, jolsa@kernel.org In-Reply-To: <1435716878-189507-23-git-send-email-wangnan0@huawei.com> References: <1435716878-189507-23-git-send-email-wangnan0@huawei.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] bpf tools: Link all bpf objects onto a list Git-Commit-ID: 9a208effd1832e50e1f7ea002f400f8b9ca8b1ed X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3989 Lines: 130 Commit-ID: 9a208effd1832e50e1f7ea002f400f8b9ca8b1ed Gitweb: http://git.kernel.org/tip/9a208effd1832e50e1f7ea002f400f8b9ca8b1ed Author: Wang Nan AuthorDate: Wed, 1 Jul 2015 02:14:10 +0000 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 7 Aug 2015 10:16:59 -0300 bpf tools: Link all bpf objects onto a list To allow enumeration of all bpf_objects, keep them in a list (hidden to caller). bpf_object__for_each_safe() is introduced to do this iteration. It is safe even user close the object during iteration. Signed-off-by: Wang Nan Acked-by: Alexei Starovoitov Cc: Brendan Gregg Cc: Daniel Borkmann Cc: David Ahern Cc: He Kuang Cc: Jiri Olsa Cc: Kaixu Xia Cc: Masami Hiramatsu Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Zefan Li Cc: pi3orama@163.com Link: http://lkml.kernel.org/r/1435716878-189507-23-git-send-email-wangnan0@huawei.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/lib/bpf/libbpf.c | 32 ++++++++++++++++++++++++++++++++ tools/lib/bpf/libbpf.h | 7 +++++++ 2 files changed, 39 insertions(+) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index ae1c5cb..4fa4bc4 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -104,6 +105,8 @@ struct bpf_program { bpf_program_clear_priv_t clear_priv; }; +static LIST_HEAD(bpf_objects_list); + struct bpf_object { char license[64]; u32 kern_version; @@ -137,6 +140,12 @@ struct bpf_object { } *reloc; int nr_reloc; } efile; + /* + * All loaded bpf_object is linked in a list, which is + * hidden to caller. bpf_objects__ handlers deal with + * all objects. + */ + struct list_head list; char path[]; }; #define obj_elf_valid(o) ((o)->efile.elf) @@ -265,6 +274,9 @@ static struct bpf_object *bpf_object__new(const char *path, obj->efile.obj_buf_sz = obj_buf_sz; obj->loaded = false; + + INIT_LIST_HEAD(&obj->list); + list_add(&obj->list, &bpf_objects_list); return obj; } @@ -940,9 +952,29 @@ void bpf_object__close(struct bpf_object *obj) } zfree(&obj->programs); + list_del(&obj->list); free(obj); } +struct bpf_object * +bpf_object__next(struct bpf_object *prev) +{ + struct bpf_object *next; + + if (!prev) + next = list_first_entry(&bpf_objects_list, + struct bpf_object, + list); + else + next = list_next_entry(prev, list); + + /* Empty list is noticed here so don't need checking on entry. */ + if (&next->list == &bpf_objects_list) + return NULL; + + return next; +} + struct bpf_program * bpf_program__next(struct bpf_program *prev, struct bpf_object *obj) { diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index 657e497..ea8adc2 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h @@ -35,6 +35,13 @@ void bpf_object__close(struct bpf_object *object); int bpf_object__load(struct bpf_object *obj); int bpf_object__unload(struct bpf_object *obj); +struct bpf_object *bpf_object__next(struct bpf_object *prev); +#define bpf_object__for_each_safe(pos, tmp) \ + for ((pos) = bpf_object__next(NULL), \ + (tmp) = bpf_object__next(pos); \ + (pos) != NULL; \ + (pos) = (tmp), (tmp) = bpf_object__next(tmp)) + /* Accessors of bpf_program. */ struct bpf_program; struct bpf_program *bpf_program__next(struct bpf_program *prog, -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/