From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by dpdk.org (Postfix) with ESMTP id 862F54C74 for ; Tue, 13 Mar 2018 19:07:55 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Mar 2018 11:07:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,465,1515484800"; d="scan'208";a="33519374" Received: from irsmsx101.ger.corp.intel.com ([163.33.3.153]) by FMSMGA003.fm.intel.com with ESMTP; 13 Mar 2018 11:07:52 -0700 Received: from irsmsx156.ger.corp.intel.com (10.108.20.68) by IRSMSX101.ger.corp.intel.com (163.33.3.153) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 13 Mar 2018 18:07:52 +0000 Received: from irsmsx105.ger.corp.intel.com ([169.254.7.221]) by IRSMSX156.ger.corp.intel.com ([169.254.3.24]) with mapi id 14.03.0319.002; Tue, 13 Mar 2018 18:07:51 +0000 From: "Ananyev, Konstantin" To: Jerin Jacob CC: "dev@dpdk.org" Thread-Topic: [dpdk-dev] [PATCH v1 3/5] bpf: introduce basic RX/TX BPF filters Thread-Index: AQHTt8W4fJ9oTmp55US9qLOJbqG7vaPOMe8AgABFRUA= Date: Tue, 13 Mar 2018 18:07:50 +0000 Message-ID: <2601191342CEEE43887BDE71AB9772589E28F56A@irsmsx105.ger.corp.intel.com> References: <1520613725-9176-1-git-send-email-konstantin.ananyev@intel.com> <1520613725-9176-4-git-send-email-konstantin.ananyev@intel.com> <20180313133941.GB564@jerin> In-Reply-To: <20180313133941.GB564@jerin> Accept-Language: en-IE, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiZjI4OGJkYTgtMmM1ZC00NDljLTliNWQtYzEzZjhlODM5ZGJmIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE2LjUuOS4zIiwiVHJ1c3RlZExhYmVsSGFzaCI6IjNRZmRmb0o4SEs5WU1iTVg2emdzaGR3UzdMTjZRbkFkeiswOFZOaENFSWs9In0= x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.0.0.116 dlp-reaction: no-action x-originating-ip: [163.33.239.181] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH v1 3/5] bpf: introduce basic RX/TX BPF filters X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Mar 2018 18:07:56 -0000 >=20 > -----Original Message----- > > Date: Fri, 9 Mar 2018 16:42:03 +0000 > > From: Konstantin Ananyev > > To: dev@dpdk.org > > CC: Konstantin Ananyev > > Subject: [dpdk-dev] [PATCH v1 3/5] bpf: introduce basic RX/TX BPF filte= rs > > X-Mailer: git-send-email 1.7.0.7 > > > > Introduce API to install BPF based filters on ethdev RX/TX path. > > Current implementation is pure SW one, based on ethdev RX/TX > > callback mechanism. > > > > Signed-off-by: Konstantin Ananyev > > --- > > lib/librte_bpf/Makefile | 2 + > > lib/librte_bpf/bpf_pkt.c | 524 +++++++++++++++++++++++++++++= ++++++++ > > lib/librte_bpf/rte_bpf_ethdev.h | 50 ++++ > > lib/librte_bpf/rte_bpf_version.map | 4 + > > 4 files changed, 580 insertions(+) > > create mode 100644 lib/librte_bpf/bpf_pkt.c > > create mode 100644 lib/librte_bpf/rte_bpf_ethdev.h > > > > diff --git a/lib/librte_bpf/Makefile b/lib/librte_bpf/Makefile > > + > > +/* > > + * information about all installed BPF rx/tx callbacks > > + */ > > + > > +struct bpf_eth_cbi { > > + uint32_t use; /*usage counter */ > > + void *cb; /* callback handle */ > > + struct rte_bpf *bpf; > > + struct rte_bpf_jit jit; > > +} __rte_cache_aligned; > > + > > +/* > > + * Odd number means that callback is used by datapath. > > + * Even number means that callback is not used by datapath. > > + */ > > +#define BPF_ETH_CBI_INUSE 1 > > + > > +static struct bpf_eth_cbi rx_cbi[RTE_MAX_ETHPORTS][RTE_MAX_QUEUES_PER_= PORT]; > > +static struct bpf_eth_cbi tx_cbi[RTE_MAX_ETHPORTS][RTE_MAX_QUEUES_PER_= PORT]; >=20 > How about allocating this memory from huge page? Yep, in v2 will switch to using rte_malloc() for cbi allocation. >=20 > > + > > +/* > > + * Marks given callback as used by datapath. > > + */ > > +static __rte_always_inline void > > +bpf_eth_cbi_inuse(struct bpf_eth_cbi *cbi) > > +{ > > + cbi->use++; > > + /* make sure no store/load reordering could happen */ > > + rte_smp_mb(); >=20 > This is an full barrier on non x86. This is a full barrier on x86 too. Unfortunately I think it is unavoidable, though open for suggestions. > How about a light version of this > logic? See below. >=20 > > +} > > + > > +/* > > + * Marks given callback list as not used by datapath. > > + */ > > +static __rte_always_inline void > > +bpf_eth_cbi_unuse(struct bpf_eth_cbi *cbi) > > +{ > > + /* make sure all previous loads are completed */ > > + rte_smp_rmb(); > > + cbi->use++; > > +} > > + > > +/* > > + * Waits till datapath finished using given callback. > > + */ > > +static void > > +bpf_eth_cbi_wait(const struct bpf_eth_cbi *cbi) > > +{ > > + uint32_t nuse, puse; > > + > > + /* make sure all previous loads and stores are completed */ > > + rte_smp_mb(); > > + >=20 > Read conjunction with below change >=20 > #if 0 > > + puse =3D cbi->use; > > + > > + /* in use, busy wait till current RX/TX iteration is finished */ > > + if ((puse & BPF_ETH_CBI_INUSE) !=3D 0) { > > + do { > > + rte_pause(); > > + rte_compiler_barrier(); > > + nuse =3D cbi->use; > > + } while (nuse =3D=3D puse); > > + } > #else > cbi->cb =3D NULL; > while (likely(cb->done !=3D 1)) { > rte_pause(); > rte_smb_rmb(); > } >=20 > or any other logic using flag to wait until callback completes. > #endif I thought about it, but such approach makes control-path function progress = dependent on simultaneous invocation of data-path functions. In some cases it would cause control-path to hang. Let say there is no traffic for that port/queue (i.e. tx_burst() wouldn't b= e called), or user invokes control-path and data-path function from the same thread, i= .e: rte_bpf_eth_rx_elf_load(port, queue, ...); .... rte_eth_rx_burst(port, queue, ...); ... rte_bpf_eth_rx_unload(port,queue); Konstantin >=20 > > +} > > + > > + > > +/* > > + * RX/TX callbacks for raw data bpf. > > + */ > > + > > +static uint16_t > > +bpf_rx_callback_vm(__rte_unused uint16_t port, __rte_unused uint16_t q= ueue, > > + struct rte_mbuf *pkt[], uint16_t nb_pkts, > > + __rte_unused uint16_t max_pkts, void *user_param) > > +{ > > + struct bpf_eth_cbi *cbi; > > + uint16_t rc; > > + > > + cbi =3D user_param; > > + >=20 > Read conjunction with above change >=20 > #if 0 > > + bpf_eth_cbi_inuse(cbi); > > + rc =3D (cbi->cb !=3D NULL) ? > > + pkt_filter_vm(cbi->bpf, pkt, nb_pkts, 1) : > > + nb_pkts; > > + bpf_eth_cbi_unuse(cbi); > #else > if (likely(cbi->cb !=3D NULL)) > return pkt_filter_vm(cbi->bpf, pkt, nb_pkts, 1) : > else { > cbi->done =3D 1; > rte_smb_wmb(); > return nb_pkts; > } > #endif >=20 > > + return rc; > > +} > > +