Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751619AbcDTTaM (ORCPT ); Wed, 20 Apr 2016 15:30:12 -0400 Received: from m12-14.163.com ([220.181.12.14]:38786 "EHLO m12-14.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750902AbcDTTaK convert rfc822-to-8bit (ORCPT ); Wed, 20 Apr 2016 15:30:10 -0400 Content-Type: text/plain; charset=gb2312 Mime-Version: 1.0 (1.0) Subject: Re: [RFC PATCH 05/13] bpf tools: Save engine type in bpf_program From: pi3orama X-Mailer: iPhone Mail (13E238) In-Reply-To: <20160420192315.GU3677@kernel.org> Date: Thu, 21 Apr 2016 03:29:43 +0800 Cc: Wang Nan , jolsa@redhat.com, brendan.d.gregg@gmail.com, linux-kernel@vger.kernel.org, Arnaldo Carvalho de Melo , Alexei Starovoitov , Jiri Olsa , Li Zefan Content-Transfer-Encoding: 8BIT Message-Id: References: <1461175313-38310-1-git-send-email-wangnan0@huawei.com> <1461175313-38310-6-git-send-email-wangnan0@huawei.com> <20160420192315.GU3677@kernel.org> To: Arnaldo Carvalho de Melo X-CM-TRANSID: DsCowABnf8un2BdX_y+KAg--.52802S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7uFy5XryUJr4UCFW5Jw4rAFb_yoW8Kw4fpF yUJa4UCr18JrW8WF1qqayFgwnxtF1DWFyjkFWUJ348CwsFvrZ7Gw1FkFsI9rya9F4DGF1v vw1jva4xu3s5ArDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UCg4DUUUUU= X-Originating-IP: [117.136.38.243] X-CM-SenderInfo: lslt02xdpdqiywtou0bp/xtbBaQlRQFXleJ5PbwAAsH Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2487 Lines: 94 ?????ҵ? iPhone > ?? 2016??4??21?գ?????3:23??Arnaldo Carvalho de Melo д???? > > Em Wed, Apr 20, 2016 at 06:01:45PM +0000, Wang Nan escreveu: >> [SNIP] >> >> + if (prog->engine == ENGINE_UNKNOWN) >> + prog->engine = ENGINE_KBPF; >> + if (prog->engine != ENGINE_KBPF) > > else if (prog->engine != ENGINE_KBPF) > > Nitpicking a bit :-) > We set it to ENGINE_KBPF in previous "if", so can't use "else". Do this because I want the engine is KBPF if not explicitly set to UNPF. Thank you. >> + return -EINVAL; >> + >> if (prog->instances.nr < 0 || !prog->instances.array) { >> if (prog->preprocessor) { >> pr_warning("Internal error: can't load program '%s'\n", >> @@ -1318,6 +1330,34 @@ int bpf_program__nth_fd(struct bpf_program *prog, int n) >> return fd; >> } >> >> +#ifdef HAVE_UBPF_SUPPORT >> +int bpf_program__set_ubpf(struct bpf_program *prog) >> +{ >> + if (prog->engine != ENGINE_UNKNOWN) { >> + pr_warning("Can't set program %s to ubpf\n", >> + prog->section_name); >> + return -EINVAL; >> + } >> + prog->engine = ENGINE_UBPF; >> + return 0; >> +} >> + >> +bool bpf_program__is_ubpf(struct bpf_program *prog) >> +{ >> + return prog->engine == ENGINE_UBPF; >> +} >> +#else >> +int bpf_program__set_ubpf(struct bpf_program *prog __maybe_unused) >> +{ >> + return -LIBBPF_ERRNO__NOUBPF; >> +} >> + >> +bool bpf_program__is_ubpf(struct bpf_program *prog __maybe_unused) >> +{ >> + return false; >> +} >> +#endif >> + >> int bpf_map__get_fd(struct bpf_map *map) >> { >> if (!map) >> diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h >> index a51594c..f6965ce 100644 >> --- a/tools/lib/bpf/libbpf.h >> +++ b/tools/lib/bpf/libbpf.h >> @@ -26,6 +26,7 @@ enum libbpf_errno { >> LIBBPF_ERRNO__VERIFY, /* Kernel verifier blocks program loading */ >> LIBBPF_ERRNO__PROG2BIG, /* Program too big */ >> LIBBPF_ERRNO__KVER, /* Incorrect kernel version */ >> + LIBBPF_ERRNO__NOUBPF, /* UBPF support is not compiled */ >> __LIBBPF_ERRNO__END, >> }; >> >> @@ -86,6 +87,9 @@ int bpf_program__get_private(struct bpf_program *prog, >> >> const char *bpf_program__title(struct bpf_program *prog, bool needs_copy); >> >> +int bpf_program__set_ubpf(struct bpf_program *prog); >> +bool bpf_program__is_ubpf(struct bpf_program *prog); >> + >> int bpf_program__fd(struct bpf_program *prog); >> >> struct bpf_insn; >> -- >> 1.8.3.4