From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id EC9D442BE1; Tue, 30 May 2023 10:17:12 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6C9B040F18; Tue, 30 May 2023 10:17:12 +0200 (CEST) Received: from mail-qt1-f180.google.com (mail-qt1-f180.google.com [209.85.160.180]) by mails.dpdk.org (Postfix) with ESMTP id B7457406BC for ; Tue, 30 May 2023 10:17:10 +0200 (CEST) Received: by mail-qt1-f180.google.com with SMTP id d75a77b69052e-3f6ac005824so38398531cf.2 for ; Tue, 30 May 2023 01:17:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685434630; x=1688026630; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=T/kuJRdulEOP0lMW7cbLvqbrbP6p+Oo6LTwpl/g//Nw=; b=XAiVGcbdx3ZzDfTZBUF64H97gsv4v4PU2uACqbJYKEyDSwsABcbtACp+AbD3YmJDvE MsOVrOlT0XHurz1G8O2miwF0bw14VkSTrc6Gw8HXc0r6jt8hPA281VbTnAKdK2nGWpi0 DkxLY6UgKNkExzxztL4uraH449WhZcUoxO3liVnvcJ7DA5MnYl6rh8fvzngFT3LQaGSY QM32dTffqmJtY6/dNfGLiV+5s2CNeoflWNIFoGfj7VMxZ3Veg6Tt4H57pYyWhdVEPGre RltBL6pFHCAamn+FVFbcvOaaclXG++uBoOTvvKOxCMJnlNCwaZiRlThnTjDLrYtR90R3 j4dA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685434630; x=1688026630; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=T/kuJRdulEOP0lMW7cbLvqbrbP6p+Oo6LTwpl/g//Nw=; b=Hfps2sWpgS8sSsh/z2VPefj/ns2yQ/h11aLHmuS9J4fxRI3rcdXdIinaUD3urO9AmA zsIr2FF0kyjUdl021wB93AIPqkbOGqxf/Gsst3wrTlyth3bWBuH9wrx+52BU0aSSKvfg +PCRA8hRPL/JmYfmDgwjwxTHuBxeMdg96lmtYiDdeMPS3k23N4J8ihN/LOGSIP4o8wEo TEmFvEAzhZ6nmNM9vmr09wOfmnPEwAuMBTxDJqXY4PvsmhlIiKpmeBIJKj26QpBBYDWs UId39YdufBUuEiwokMAGenEZFrpBaTuO4F8c/qiTD+ZJA7Ptd+3BgXbGNB4RlPlbP4JN DFmQ== X-Gm-Message-State: AC+VfDwhsrj8ytIsPSMEstPTc+tkH49prJADrK/V6YPayBAnBlDyfE4+ 1gDTWH7sESnxTbv0ktMEQvFtq2cDypwjpObTrlcNw9BVzKE= X-Google-Smtp-Source: ACHHUZ6mkHLc21AMx26w+4JnffuHo+Ux1LCWel7agiZd4/Za6TadDtPb206iFhw4cQVgE6KLmvOq4hz5WQoz36dTaII= X-Received: by 2002:a05:622a:54e:b0:3f4:e3b1:8d36 with SMTP id m14-20020a05622a054e00b003f4e3b18d36mr1147107qtx.20.1685434629811; Tue, 30 May 2023 01:17:09 -0700 (PDT) MIME-Version: 1.0 References: <20230421060245.3136217-1-vattunuru@marvell.com> <20230425131516.3308612-1-vattunuru@marvell.com> <20230425131516.3308612-2-vattunuru@marvell.com> In-Reply-To: <20230425131516.3308612-2-vattunuru@marvell.com> From: Nithin Dabilpuram Date: Tue, 30 May 2023 13:46:57 +0530 Message-ID: Subject: Re: [PATCH v2 1/4] node: add pkt punt to kernel node To: Vamsi Attunuru Cc: dev@dpdk.org, thomas@monjalon.net, jerinj@marvell.com, ndabilpuram@marvell.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On Tue, Apr 25, 2023 at 6:45=E2=80=AFPM Vamsi Attunuru wrote: > > Patch adds a node to punt the packets to kernel over > a raw socket. > > Signed-off-by: Vamsi Attunuru > --- > doc/guides/prog_guide/graph_lib.rst | 10 +++ > lib/node/meson.build | 1 + > lib/node/punt_kernel.c | 125 ++++++++++++++++++++++++++++ > lib/node/punt_kernel_priv.h | 36 ++++++++ > 4 files changed, 172 insertions(+) > > diff --git a/doc/guides/prog_guide/graph_lib.rst b/doc/guides/prog_guide/= graph_lib.rst > index 1cfdc86433..b3b5b14827 100644 > --- a/doc/guides/prog_guide/graph_lib.rst > +++ b/doc/guides/prog_guide/graph_lib.rst > @@ -392,3 +392,13 @@ null > ~~~~ > This node ignores the set of objects passed to it and reports that all a= re > processed. > + > +punt_kernel > +~~~~~~~~~~~ > +This node punts the packets to kernel using a raw socket interface. For = sending > +the received packets, raw socket uses the packet's destination IP addres= s in > +sockaddr_in address structure and node uses ``sendto`` function to send = data > +on the raw socket. > + > +Aftering sending the burst of packets to kernel, this node redirects the= same > +objects to pkt_drop node to free up the packet buffers. > diff --git a/lib/node/meson.build b/lib/node/meson.build > index dbdf673c86..48c2da73f7 100644 > --- a/lib/node/meson.build > +++ b/lib/node/meson.build > @@ -17,6 +17,7 @@ sources =3D files( > 'null.c', > 'pkt_cls.c', > 'pkt_drop.c', > + 'punt_kernel.c', > ) > headers =3D files('rte_node_ip4_api.h', 'rte_node_eth_api.h') > # Strict-aliasing rules are violated by uint8_t[] to context size casts. > diff --git a/lib/node/punt_kernel.c b/lib/node/punt_kernel.c > new file mode 100644 > index 0000000000..e5dd15b759 > --- /dev/null > +++ b/lib/node/punt_kernel.c > @@ -0,0 +1,125 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright(C) 2023 Marvell International Ltd. > + */ > + > +#include > +#include > +#include > +#include > + > +#include > +#include > +#include > +#include > +#include > + > +#include "node_private.h" > +#include "punt_kernel_priv.h" > + > +static __rte_always_inline void > +punt_kernel_process_mbuf(struct rte_node *node, struct rte_mbuf **mbufs,= uint16_t cnt) > +{ > + punt_kernel_node_ctx_t *ctx =3D (punt_kernel_node_ctx_t *)node->c= tx; > + struct sockaddr_in sin =3D {0}; > + struct rte_ipv4_hdr *ip4; > + size_t len; > + char *buf; > + int i; > + > + for (i =3D 0; i < cnt; i++) { > + ip4 =3D rte_pktmbuf_mtod(mbufs[i], struct rte_ipv4_hdr *)= ; > + len =3D rte_pktmbuf_data_len(mbufs[i]); > + buf =3D (char *)ip4; > + > + sin.sin_family =3D AF_INET; > + sin.sin_port =3D 0; > + sin.sin_addr.s_addr =3D ip4->dst_addr; > + > + if (sendto(ctx->sock, buf, len, 0, (struct sockaddr *)&si= n, sizeof(sin)) < 0) > + node_err("punt_kernel", "Unable to send packets: = %s\n", strerror(errno)); > + } > +} > + > +static uint16_t > +punt_kernel_node_process(struct rte_graph *graph __rte_unused, struct rt= e_node *node, void **objs, > + uint16_t nb_objs) > +{ > + struct rte_mbuf **pkts =3D (struct rte_mbuf **)objs; > + uint16_t obj_left =3D nb_objs; > + > +#define PREFETCH_CNT 4 > + > + while (obj_left >=3D 12) { > + /* Prefetch next-next mbufs */ > + rte_prefetch0(pkts[8]); > + rte_prefetch0(pkts[9]); > + rte_prefetch0(pkts[10]); > + rte_prefetch0(pkts[11]); > + > + /* Prefetch next mbuf data */ > + rte_prefetch0(rte_pktmbuf_mtod_offset(pkts[4], void *, pk= ts[4]->l2_len)); > + rte_prefetch0(rte_pktmbuf_mtod_offset(pkts[5], void *, pk= ts[5]->l2_len)); > + rte_prefetch0(rte_pktmbuf_mtod_offset(pkts[6], void *, pk= ts[6]->l2_len)); > + rte_prefetch0(rte_pktmbuf_mtod_offset(pkts[7], void *, pk= ts[7]->l2_len)); > + > + punt_kernel_process_mbuf(node, pkts, PREFETCH_CNT); > + > + obj_left -=3D PREFETCH_CNT; > + pkts +=3D PREFETCH_CNT; > + } > + > + while (obj_left > 0) { > + punt_kernel_process_mbuf(node, pkts, 1); > + > + obj_left--; > + pkts++; > + } > + > + rte_node_next_stream_move(graph, node, PUNT_KERNEL_NEXT_PKT_DROP)= ; Packet drop node signifies that packet is dropped due to some reason and not consumed. Since here the packet is really not dropped but consumed by Kernel, can we avoid using pkt drop node and instead free pkts directly ? > + > + return nb_objs; > +} > + > +static int > +punt_kernel_node_init(const struct rte_graph *graph __rte_unused, struct= rte_node *node) > +{ > + punt_kernel_node_ctx_t *ctx =3D (punt_kernel_node_ctx_t *)node->c= tx; > + > + ctx->sock =3D socket(AF_INET, SOCK_RAW, IPPROTO_RAW); > + if (ctx->sock < 0) > + node_err("punt_kernel", "Unable to open RAW socket\n"); > + > + return 0; > +} > + > +static void > +punt_kernel_node_fini(const struct rte_graph *graph __rte_unused, struct= rte_node *node) > +{ > + punt_kernel_node_ctx_t *ctx =3D (punt_kernel_node_ctx_t *)node->c= tx; > + > + if (ctx->sock >=3D 0) { > + close(ctx->sock); > + ctx->sock =3D -1; > + } > +} > + > +static struct rte_node_register punt_kernel_node_base =3D { > + .process =3D punt_kernel_node_process, > + .name =3D "punt_kernel", > + > + .init =3D punt_kernel_node_init, > + .fini =3D punt_kernel_node_fini, > + > + .nb_edges =3D PUNT_KERNEL_NEXT_MAX, > + .next_nodes =3D { > + [PUNT_KERNEL_NEXT_PKT_DROP] =3D "pkt_drop", > + }, > +}; > + > +struct rte_node_register * > +punt_kernel_node_get(void) > +{ > + return &punt_kernel_node_base; > +} > + > +RTE_NODE_REGISTER(punt_kernel_node_base); > diff --git a/lib/node/punt_kernel_priv.h b/lib/node/punt_kernel_priv.h > new file mode 100644 > index 0000000000..25ba2072e7 > --- /dev/null > +++ b/lib/node/punt_kernel_priv.h > @@ -0,0 +1,36 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright(C) 2023 Marvell International Ltd. > + */ > + > +#ifndef __INCLUDE_PUNT_KERNEL_PRIV_H__ > +#define __INCLUDE_PUNT_KERNEL_PRIV_H__ > + > +struct punt_kernel_node_elem; > +struct punt_kernel_node_ctx; > +typedef struct punt_kernel_node_elem punt_kernel_node_elem_t; > + > +/** > + * @internal > + * > + * PUNT Kernel node context structure. > + */ > +typedef struct punt_kernel_node_ctx { > + int sock; > +} punt_kernel_node_ctx_t; > + > +enum punt_kernel_next_nodes { > + PUNT_KERNEL_NEXT_PKT_DROP, > + PUNT_KERNEL_NEXT_MAX, > +}; > + > +/** > + * @internal > + * > + * Get the PUNT Kernel node. > + * > + * @return > + * Pointer to the PUNT Kernel node. > + */ > +struct rte_node_register *punt_kernel_node_get(void); > + > +#endif /* __INCLUDE_PUNT_KERNEL_PRIV_H__ */ > -- > 2.25.1 >