From patchwork Fri Mar 28 13:12:13 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 27280 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 95CF620062 for ; Fri, 28 Mar 2014 13:12:21 +0000 (UTC) Received: by mail-la0-f71.google.com with SMTP id ec20sf8689230lab.6 for ; Fri, 28 Mar 2014 06:12:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:to:subject:date:message-id :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe:content-type; bh=HoHk/u6KD4jUGOOhvkh/rtc78mBncQkVZTui8ZQzCNk=; b=ikQbjDX1rsweBSWtVCQsPLTDVSnV/Bb5+hJPkSITL0Bgq3bYTCs9tJvQ96+Z6Zhv2g JBYR43gcY7egvFUgLcGHUl+ckSuz39XF0IpQFs1rE0JbbnLfG/+9CymI6FrWezpApca2 QidAYfUB/WeqqF2KKOxGhiL1hd9ye9XEhWwzuCvILi2sbuN7RisIps60x6d9XZDLIjvq b6pgX2qYcEzEwMwDhFlO4uBqvD+oGJIkDoC2LbA36rtDYG7/IpxBnbtloJAyhOe5DW7H JlNulCxXBliCT4YJEbqkDf2/dvcmv4t0zDpiQi7EBwHYv+hKRcfnA83cR8Cw/o82E3E8 SBww== X-Gm-Message-State: ALoCoQmY4Ak4GWkE5nNdQL27cGYbGeoEkpRG/dorgUIanXradlQpXUdxmZ21X5nM+cR69a1XYxzM X-Received: by 10.14.219.194 with SMTP id m42mr1410903eep.7.1396012339755; Fri, 28 Mar 2014 06:12:19 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: lng-odp@linaro.org Received: by 10.152.240.225 with SMTP id wd1ls222775lac.12.gmail; Fri, 28 Mar 2014 06:12:19 -0700 (PDT) X-Received: by 10.112.41.227 with SMTP id i3mr1086413lbl.41.1396012339330; Fri, 28 Mar 2014 06:12:19 -0700 (PDT) Received: from mail-lb0-f169.google.com (mail-lb0-f169.google.com [209.85.217.169]) by mx.google.com with ESMTPS id y6si3368487lal.5.2014.03.28.06.12.19 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 28 Mar 2014 06:12:19 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.217.169 is neither permitted nor denied by best guess record for domain of maxim.uvarov@linaro.org) client-ip=209.85.217.169; Received: by mail-lb0-f169.google.com with SMTP id q8so3768668lbi.28 for ; Fri, 28 Mar 2014 06:12:19 -0700 (PDT) X-Received: by 10.112.163.69 with SMTP id yg5mr5243770lbb.14.1396012339135; Fri, 28 Mar 2014 06:12:19 -0700 (PDT) Received: from maxim-lap.localhost.onion ([92.39.133.154]) by mx.google.com with ESMTPSA id v20sm3659736lbi.24.2014.03.28.06.12.17 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 28 Mar 2014 06:12:18 -0700 (PDT) From: Maxim Uvarov To: lng-odp@linaro.org Subject: [lng-odp] [ODP/PATCH] [REQUIRE TESTING] rework packet io selection Date: Fri, 28 Mar 2014 17:12:13 +0400 Message-Id: <1396012333-27985-1-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.8.5.1.163.gd7aced9 X-Original-Sender: maxim.uvarov@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.217.169 is neither permitted nor denied by best guess record for domain of maxim.uvarov@linaro.org) smtp.mail=maxim.uvarov@linaro.org Precedence: list Mailing-list: list lng-odp@linaro.org; contact lng-odp+owners@linaro.org List-ID: X-Google-Group-Id: 474323889996 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Dynamically select type of packet I/O sock_params->type = ODP_PKTIO_TYPE_SOCKET_BASIC ODP_PKTIO_TYPE_SOCKET_MMSG ODP_PKTIO_TYPE_SOCKET_MMAP ODP_PKTIO_TYPE_NETMAP sock_params->fanout = 1; pktio = odp_pktio_open(thr_args->pktio_dev, thr_args->pool, ¶ms); Signed-off-by: Maxim Uvarov --- .../linux-generic/include/api/odp_pktio_types.h | 6 +- .../linux-generic/include/odp_packet_io_internal.h | 1 + platform/linux-generic/include/odp_packet_socket.h | 56 +++++-------- platform/linux-generic/source/odp_packet_io.c | 61 +++++++++++--- platform/linux-generic/source/odp_packet_socket.c | 98 +++++++++------------- test/packet/odp_example_pktio.c | 4 +- 6 files changed, 119 insertions(+), 107 deletions(-) diff --git a/platform/linux-generic/include/api/odp_pktio_types.h b/platform/linux-generic/include/api/odp_pktio_types.h index e6b4cbf..c87bfc2 100644 --- a/platform/linux-generic/include/api/odp_pktio_types.h +++ b/platform/linux-generic/include/api/odp_pktio_types.h @@ -17,9 +17,11 @@ extern "C" { */ typedef enum { - ODP_PKTIO_TYPE_SOCKET = 0x01, + ODP_PKTIO_TYPE_SOCKET_BASIC = 0x1, + ODP_PKTIO_TYPE_SOCKET_MMSG = 0x2, + ODP_PKTIO_TYPE_SOCKET_MMAP = 0x3, #ifdef ODP_HAVE_NETMAP - ODP_PKTIO_TYPE_NETMAP = 0x02, + ODP_PKTIO_TYPE_NETMAP = 0x4, #endif } odp_pktio_type_t; diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h index ba1ee9b..3ab7fa0 100644 --- a/platform/linux-generic/include/odp_packet_io_internal.h +++ b/platform/linux-generic/include/odp_packet_io_internal.h @@ -31,6 +31,7 @@ struct pktio_entry { odp_queue_t outq_default; /**< default out queue */ odp_pktio_params_t params; /**< pktio parameters */ pkt_sock_t pkt_sock; /**< using socket API for IO */ + pkt_sock_mmap_t pkt_sock_mmap; /**< using socket mmap API for IO */ #ifdef ODP_HAVE_NETMAP pkt_netmap_t pkt_nm; /**< using netmap API for IO */ #endif diff --git a/platform/linux-generic/include/odp_packet_socket.h b/platform/linux-generic/include/odp_packet_socket.h index fe216bb..98ceb98 100644 --- a/platform/linux-generic/include/odp_packet_socket.h +++ b/platform/linux-generic/include/odp_packet_socket.h @@ -20,37 +20,15 @@ #include - /* * Packet socket config: */ -#define ODP_PACKET_SOCKET_BASIC 0 /** use recv()/send() */ -#define ODP_PACKET_SOCKET_MMSG 1 /** use recvmmsg()/sendmmsg() */ -#define ODP_PACKET_SOCKET_MMAP 2 /** use PACKET_MMAP */ - - -#if LINUX_VERSION_CODE <= KERNEL_VERSION(3, 1, 0) -/* PACKET_FANOUT feature not supported */ -#define ODP_PACKET_SOCKET_FANOUT 0 -#define ODP_PACKET_SOCKET_MODE (ODP_PACKET_SOCKET_BASIC) -#else -/** PACKET_FANOUT mode spreads incoming packets over multiple sockets*/ -#define ODP_PACKET_SOCKET_FANOUT 1 /* 0=Off, 1=On */ -/** Choose one from the alternatives above */ -#define ODP_PACKET_SOCKET_MODE (ODP_PACKET_SOCKET_MMAP) -#endif - /** Max receive (Rx) burst size*/ #define ODP_PACKET_SOCKET_MAX_BURST_RX 32 /** Max transmit (Tx) burst size*/ #define ODP_PACKET_SOCKET_MAX_BURST_TX 32 - - -#if (ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_BASIC) || \ - (ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_MMSG) - typedef struct { int sockfd; /**< socket descriptor */ odp_buffer_pool_t pool; /**< buffer pool to alloc packets from */ @@ -60,12 +38,6 @@ typedef struct { unsigned char if_mac[ETH_ALEN]; /**< IF eth mac addr */ } pkt_sock_t; -#elif ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_MMAP - -#if ODP_PACKET_SOCKET_FANOUT == 0 -#error "ODP_PACKET_SOCKET_MMAP requires ODP_PACKET_SOCKET_FANOUT=1" -#endif - /** packet mmap ring */ struct ring { struct iovec *rd; @@ -99,31 +71,45 @@ typedef struct { unsigned mmap_len; unsigned char if_mac[ETH_ALEN]; struct sockaddr_ll ll; -} pkt_sock_t; - -#else -#error "Unsupported ODP_PACKET_SOCKET_MODE!" -#endif + int fanout; /**< 0: off 1: on */ +} pkt_sock_mmap_t; /** * Open & configure a raw packet socket */ int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev, odp_buffer_pool_t pool); + +int setup_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock, char *netdev, + odp_buffer_pool_t pool); + /** * Close a packet socket */ int close_pkt_sock(pkt_sock_t * const pkt_sock); +int close_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock); + /** * Receive packets from the packet socket */ -int recv_pkt_sock(pkt_sock_t * const pkt_sock, odp_packet_t pkt_table[], +int recv_pkt_sock_basic(pkt_sock_t * const pkt_sock, odp_packet_t pkt_table[], unsigned len); + +int recv_pkt_sock_mmsg(pkt_sock_t * const pkt_sock, odp_packet_t pkt_table[], + unsigned len); + +int recv_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock, + odp_packet_t pkt_table[], unsigned len); /** * Send packets through the packet socket */ -int send_pkt_sock(pkt_sock_t * const pkt_sock, odp_packet_t pkt_table[], +int send_pkt_sock_basic(pkt_sock_t * const pkt_sock, odp_packet_t pkt_table[], + unsigned len); + +int send_pkt_sock_mmsg(pkt_sock_t * const pkt_sock, odp_packet_t pkt_table[], unsigned len); +int send_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock, + odp_packet_t pkt_table[], unsigned len); #endif diff --git a/platform/linux-generic/source/odp_packet_io.c b/platform/linux-generic/source/odp_packet_io.c index 92aed34..ab80aef 100644 --- a/platform/linux-generic/source/odp_packet_io.c +++ b/platform/linux-generic/source/odp_packet_io.c @@ -117,8 +117,12 @@ static void init_pktio_entry(pktio_entry_t *entry, odp_pktio_params_t *params) set_taken(entry); entry->s.inq_default = ODP_QUEUE_INVALID; switch (params->type) { - case ODP_PKTIO_TYPE_SOCKET: + case ODP_PKTIO_TYPE_SOCKET_BASIC: + case ODP_PKTIO_TYPE_SOCKET_MMSG: + case ODP_PKTIO_TYPE_SOCKET_MMAP: memset(&entry->s.pkt_sock, 0, sizeof(entry->s.pkt_sock)); + memset(&entry->s.pkt_sock_mmap, 0, + sizeof(entry->s.pkt_sock_mmap)); break; #ifdef ODP_HAVE_NETMAP case ODP_PKTIO_TYPE_NETMAP: @@ -177,7 +181,9 @@ odp_pktio_t odp_pktio_open(char *dev, odp_buffer_pool_t pool, } switch (params->type) { - case ODP_PKTIO_TYPE_SOCKET: + case ODP_PKTIO_TYPE_SOCKET_BASIC: + case ODP_PKTIO_TYPE_SOCKET_MMSG: + case ODP_PKTIO_TYPE_SOCKET_MMAP: ODP_DBG("Allocating socket pktio\n"); break; #ifdef ODP_HAVE_NETMAP @@ -200,7 +206,8 @@ odp_pktio_t odp_pktio_open(char *dev, odp_buffer_pool_t pool, pktio_entry = get_entry(id); switch (params->type) { - case ODP_PKTIO_TYPE_SOCKET: + case ODP_PKTIO_TYPE_SOCKET_BASIC: + case ODP_PKTIO_TYPE_SOCKET_MMSG: res = setup_pkt_sock(&pktio_entry->s.pkt_sock, dev, pool); if (res == -1) { close_pkt_sock(&pktio_entry->s.pkt_sock); @@ -208,10 +215,19 @@ odp_pktio_t odp_pktio_open(char *dev, odp_buffer_pool_t pool, id = ODP_PKTIO_INVALID; } break; + case ODP_PKTIO_TYPE_SOCKET_MMAP: + res = setup_pkt_sock_mmap(&pktio_entry->s.pkt_sock_mmap, dev, + pool); + if (res == -1) { + close_pkt_sock_mmap(&pktio_entry->s.pkt_sock_mmap); + free_pktio_entry(id); + id = ODP_PKTIO_INVALID; + } + break; #ifdef ODP_HAVE_NETMAP case ODP_PKTIO_TYPE_NETMAP: res = setup_pkt_netmap(&pktio_entry->s.pkt_nm, dev, - pool, ¶ms->nm_params); + pool, ¶ms->nm_params); if (res == -1) { close_pkt_netmap(&pktio_entry->s.pkt_nm); free_pktio_entry(id); @@ -237,9 +253,13 @@ int odp_pktio_close(odp_pktio_t id) lock_entry(entry); if (!is_free(entry)) { switch (entry->s.params.type) { - case ODP_PKTIO_TYPE_SOCKET: + case ODP_PKTIO_TYPE_SOCKET_BASIC: + case ODP_PKTIO_TYPE_SOCKET_MMSG: res = close_pkt_sock(&entry->s.pkt_sock); break; + case ODP_PKTIO_TYPE_SOCKET_MMAP: + res = close_pkt_sock_mmap(&entry->s.pkt_sock_mmap); + break; #ifdef ODP_HAVE_NETMAP case ODP_PKTIO_TYPE_NETMAP: res = close_pkt_netmap(&entry->s.pkt_nm); @@ -247,7 +267,7 @@ int odp_pktio_close(odp_pktio_t id) #endif default: break; - res |= free_pktio_entry(id); + res |= free_pktio_entry(id); } } unlock_entry(entry); @@ -279,8 +299,17 @@ int odp_pktio_recv(odp_pktio_t id, odp_packet_t pkt_table[], unsigned len) lock_entry(pktio_entry); switch (pktio_entry->s.params.type) { - case ODP_PKTIO_TYPE_SOCKET: - pkts = recv_pkt_sock(&pktio_entry->s.pkt_sock, pkt_table, len); + case ODP_PKTIO_TYPE_SOCKET_BASIC: + pkts = recv_pkt_sock_basic(&pktio_entry->s.pkt_sock, + pkt_table, len); + break; + case ODP_PKTIO_TYPE_SOCKET_MMSG: + pkts = recv_pkt_sock_mmsg(&pktio_entry->s.pkt_sock, + pkt_table, len); + break; + case ODP_PKTIO_TYPE_SOCKET_MMAP: + pkts = recv_pkt_sock_mmap(&pktio_entry->s.pkt_sock_mmap, + pkt_table, len); break; #ifdef ODP_HAVE_NETMAP case ODP_PKTIO_TYPE_NETMAP: @@ -312,12 +341,22 @@ int odp_pktio_send(odp_pktio_t id, odp_packet_t pkt_table[], unsigned len) lock_entry(pktio_entry); switch (pktio_entry->s.params.type) { - case ODP_PKTIO_TYPE_SOCKET: - pkts = send_pkt_sock(&pktio_entry->s.pkt_sock, pkt_table, len); + case ODP_PKTIO_TYPE_SOCKET_BASIC: + pkts = send_pkt_sock_basic(&pktio_entry->s.pkt_sock, + pkt_table, len); + break; + case ODP_PKTIO_TYPE_SOCKET_MMSG: + pkts = send_pkt_sock_mmsg(&pktio_entry->s.pkt_sock, + pkt_table, len); + break; + case ODP_PKTIO_TYPE_SOCKET_MMAP: + pkts = send_pkt_sock_mmap(&pktio_entry->s.pkt_sock_mmap, + pkt_table, len); break; #ifdef ODP_HAVE_NETMAP case ODP_PKTIO_TYPE_NETMAP: - pkts = send_pkt_netmap(&pktio_entry->s.pkt_nm, pkt_table, len); + pkts = send_pkt_netmap(&pktio_entry->s.pkt_nm, + pkt_table, len); break; #endif default: diff --git a/platform/linux-generic/source/odp_packet_socket.c b/platform/linux-generic/source/odp_packet_socket.c index aaf2605..5f942dd 100644 --- a/platform/linux-generic/source/odp_packet_socket.c +++ b/platform/linux-generic/source/odp_packet_socket.c @@ -63,15 +63,17 @@ static inline int ethaddrs_equal(unsigned char mac_a[], unsigned char mac_b[]) return !memcmp(mac_a, mac_b, ETH_ALEN); } -static int set_pkt_sock_fanout(pkt_sock_t * const pkt_sock, int sock_group_idx) +static int set_pkt_sock_fanout_mmap(pkt_sock_mmap_t * const pkt_sock, + int sock_group_idx) { -#if ODP_PACKET_SOCKET_FANOUT == 1 - /* Use FANOUT-mode for socket */ int sockfd = pkt_sock->sockfd; int val; int err; uint16_t fanout_group; + if (!pkt_sock->fanout) + return 0; + fanout_group = (uint16_t) (sock_group_idx & 0xffff); val = (PACKET_FANOUT_HASH << 16) | fanout_group; @@ -80,16 +82,9 @@ static int set_pkt_sock_fanout(pkt_sock_t * const pkt_sock, int sock_group_idx) perror("set_pkt_sock_fanout() - setsockopt(PACKET_FANOUT)"); return -1; } -#else - (void)pkt_sock; - (void)sock_group_idx; -#endif - return 0; } -#if (ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_BASIC) || \ - (ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_MMSG) /* * ODP_PACKET_SOCKET_BASIC: * ODP_PACKET_SOCKET_MMSG: @@ -163,11 +158,6 @@ int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev, return -1; } - /* configure PACKET_FANOUT mode for socket (if mode enabled) */ - err = set_pkt_sock_fanout(pkt_sock, if_idx); - if (err != 0) - return -1; - return sockfd; } @@ -184,13 +174,11 @@ int close_pkt_sock(pkt_sock_t * const pkt_sock) return 0; } -#endif -#if ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_BASIC /* * ODP_PACKET_SOCKET_BASIC: */ -int recv_pkt_sock(pkt_sock_t *const pkt_sock, +int recv_pkt_sock_basic(pkt_sock_t *const pkt_sock, odp_packet_t pkt_table[], unsigned len) { ssize_t recv_bytes; @@ -240,7 +228,7 @@ int recv_pkt_sock(pkt_sock_t *const pkt_sock, /* * ODP_PACKET_SOCKET_BASIC: */ -int send_pkt_sock(pkt_sock_t * const pkt_sock, +int send_pkt_sock_basic(pkt_sock_t * const pkt_sock, odp_packet_t pkt_table[], unsigned len) { odp_packet_t pkt; @@ -281,11 +269,10 @@ int send_pkt_sock(pkt_sock_t * const pkt_sock, return nb_tx; } -#elif ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_MMSG /* * ODP_PACKET_SOCKET_MMSG: */ -int recv_pkt_sock(pkt_sock_t * const pkt_sock, +int recv_pkt_sock_mmsg(pkt_sock_t * const pkt_sock, odp_packet_t pkt_table[], unsigned len) { const int sockfd = pkt_sock->sockfd; @@ -348,7 +335,7 @@ int recv_pkt_sock(pkt_sock_t * const pkt_sock, /* * ODP_PACKET_SOCKET_MMSG: */ -int send_pkt_sock(pkt_sock_t * const pkt_sock, +int send_pkt_sock_mmsg(pkt_sock_t * const pkt_sock, odp_packet_t pkt_table[], unsigned len) { struct mmsghdr msgvec[ODP_PACKET_SOCKET_MAX_BURST_TX]; @@ -387,7 +374,6 @@ int send_pkt_sock(pkt_sock_t * const pkt_sock, return len; } -#elif ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_MMAP /* * ODP_PACKET_SOCKET_MMAP: */ @@ -402,7 +388,7 @@ union frame_map { void *raw; }; -static int pkt_socket(void) +static int mmap_pkt_socket(void) { int ver = TPACKET_V2; @@ -421,23 +407,23 @@ static int pkt_socket(void) return sock; } -static inline int rx_kernel_ready(struct tpacket2_hdr *hdr) +static inline int mmap_rx_kernel_ready(struct tpacket2_hdr *hdr) { return ((hdr->tp_status & TP_STATUS_USER) == TP_STATUS_USER); } -static inline void rx_user_ready(struct tpacket2_hdr *hdr) +static inline void mmap_rx_user_ready(struct tpacket2_hdr *hdr) { hdr->tp_status = TP_STATUS_KERNEL; __sync_synchronize(); } -static inline int tx_kernel_ready(struct tpacket2_hdr *hdr) +static inline int mmap_tx_kernel_ready(struct tpacket2_hdr *hdr) { return !(hdr->tp_status & (TP_STATUS_SEND_REQUEST | TP_STATUS_SENDING)); } -static inline void tx_user_ready(struct tpacket2_hdr *hdr) +static inline void mmap_tx_user_ready(struct tpacket2_hdr *hdr) { hdr->tp_status = TP_STATUS_SEND_REQUEST; __sync_synchronize(); @@ -462,7 +448,7 @@ static inline unsigned pkt_mmap_v2_rx(int sock, struct ring *ring, frame_num = ring->frame_num; while (i < len) { - if (rx_kernel_ready(ring->rd[frame_num].iov_base)) { + if (mmap_rx_kernel_ready(ring->rd[frame_num].iov_base)) { ppd.raw = ring->rd[frame_num].iov_base; next_frame_num = (frame_num + 1) % ring->rd_num; @@ -474,7 +460,7 @@ static inline unsigned pkt_mmap_v2_rx(int sock, struct ring *ring, eth_hdr = (struct ethhdr *)pkt_buf; if (odp_unlikely(ethaddrs_equal(if_mac, eth_hdr->h_source))) { - rx_user_ready(ppd.raw); /* drop */ + mmap_rx_user_ready(ppd.raw); /* drop */ continue; } @@ -486,7 +472,7 @@ static inline unsigned pkt_mmap_v2_rx(int sock, struct ring *ring, + frame_offset; memcpy(l2_hdr, pkt_buf, pkt_len); - rx_user_ready(ppd.raw); + mmap_rx_user_ready(ppd.raw); /* Parse and set packet header data */ odp_packet_parse(pkt_table[i], pkt_len, frame_offset); @@ -516,7 +502,7 @@ static inline unsigned pkt_mmap_v2_tx(int sock, struct ring *ring, frame_num = ring->frame_num; while (i < len) { - if (tx_kernel_ready(ring->rd[frame_num].iov_base)) { + if (mmap_tx_kernel_ready(ring->rd[frame_num].iov_base)) { ppd.raw = ring->rd[frame_num].iov_base; next_frame_num = (frame_num + 1) % ring->rd_num; @@ -530,7 +516,7 @@ static inline unsigned pkt_mmap_v2_tx(int sock, struct ring *ring, memcpy((uint8_t *)ppd.raw + TPACKET2_HDRLEN - sizeof(struct sockaddr_ll), pkt_buf, pkt_len); - tx_user_ready(ppd.raw); + mmap_tx_user_ready(ppd.raw); odp_packet_free(pkt_table[i]); frame_num = next_frame_num; @@ -553,7 +539,7 @@ static inline unsigned pkt_mmap_v2_tx(int sock, struct ring *ring, return i; } -static void fill_ring(struct ring *ring, unsigned blocks) +static void mmap_fill_ring(struct ring *ring, unsigned blocks) { ring->req.tp_block_size = getpagesize() << 2; ring->req.tp_frame_size = TPACKET_ALIGNMENT << 7; @@ -567,7 +553,7 @@ static void fill_ring(struct ring *ring, unsigned blocks) ring->flen = ring->req.tp_frame_size; } -static int set_packet_loss_discard(int sock) +static int mmap_set_packet_loss_discard(int sock) { int ret, discard = 1; @@ -581,7 +567,7 @@ static int set_packet_loss_discard(int sock) return 0; } -static int setup_ring(int sock, struct ring *ring, int type) +static int mmap_setup_ring(int sock, struct ring *ring, int type) { int ret = 0; unsigned blocks = 256; @@ -591,12 +577,12 @@ static int setup_ring(int sock, struct ring *ring, int type) ring->version = TPACKET_V2; if (type == PACKET_TX_RING) { - ret = set_packet_loss_discard(sock); + ret = mmap_set_packet_loss_discard(sock); if (ret != 0) return -1; } - fill_ring(ring, blocks); + mmap_fill_ring(ring, blocks); ret = setsockopt(sock, SOL_PACKET, type, &ring->req, sizeof(ring->req)); if (ret == -1) { @@ -614,7 +600,7 @@ static int setup_ring(int sock, struct ring *ring, int type) return 0; } -static int mmap_sock(pkt_sock_t *pkt_sock) +static int mmap_sock(pkt_sock_mmap_t *pkt_sock) { int i; int sock = pkt_sock->sockfd; @@ -655,14 +641,14 @@ static int mmap_sock(pkt_sock_t *pkt_sock) return 0; } -static void unmap_sock(pkt_sock_t *pkt_sock) +static void mmap_unmap_sock(pkt_sock_mmap_t *pkt_sock) { munmap(pkt_sock->mmap_base, pkt_sock->mmap_len); free(pkt_sock->rx_ring.rd); free(pkt_sock->tx_ring.rd); } -static int bind_sock(pkt_sock_t *pkt_sock, char *netdev) +static int mmap_bind_sock(pkt_sock_mmap_t *pkt_sock, char *netdev) { int ret; @@ -684,7 +670,7 @@ static int bind_sock(pkt_sock_t *pkt_sock, char *netdev) return 0; } -static int store_hw_addr(pkt_sock_t * const pkt_sock, char *netdev) +static int mmap_store_hw_addr(pkt_sock_mmap_t * const pkt_sock, char *netdev) { struct ifreq ethreq; int ret; @@ -707,7 +693,7 @@ static int store_hw_addr(pkt_sock_t * const pkt_sock, char *netdev) /* * ODP_PACKET_SOCKET_MMAP: */ -int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev, +int setup_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock, char *netdev, odp_buffer_pool_t pool) { odp_packet_t pkt; @@ -733,17 +719,19 @@ int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev, odp_packet_free(pkt); pkt_sock->pool = pool; - pkt_sock->sockfd = pkt_socket(); + pkt_sock->sockfd = mmap_pkt_socket(); - ret = bind_sock(pkt_sock, netdev); + ret = mmap_bind_sock(pkt_sock, netdev); if (ret != 0) return -1; - ret = setup_ring(pkt_sock->sockfd, &pkt_sock->tx_ring, PACKET_TX_RING); + ret = mmap_setup_ring(pkt_sock->sockfd, &pkt_sock->tx_ring, + PACKET_TX_RING); if (ret != 0) return -1; - ret = setup_ring(pkt_sock->sockfd, &pkt_sock->rx_ring, PACKET_RX_RING); + ret = mmap_setup_ring(pkt_sock->sockfd, &pkt_sock->rx_ring, + PACKET_RX_RING); if (ret != 0) return -1; @@ -751,7 +739,7 @@ int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev, if (ret != 0) return -1; - ret = store_hw_addr(pkt_sock, netdev); + ret = mmap_store_hw_addr(pkt_sock, netdev); if (ret != 0) return -1; @@ -761,7 +749,7 @@ int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev, return -1; } - ret = set_pkt_sock_fanout(pkt_sock, if_idx); + ret = set_pkt_sock_fanout_mmap(pkt_sock, if_idx); if (ret != 0) return -1; @@ -771,9 +759,9 @@ int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev, /* * ODP_PACKET_SOCKET_MMAP: */ -int close_pkt_sock(pkt_sock_t * const pkt_sock) +int close_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock) { - unmap_sock(pkt_sock); + mmap_unmap_sock(pkt_sock); if (close(pkt_sock->sockfd) != 0) { perror("close_pkt_sock() - close(sockfd)"); return -1; @@ -785,7 +773,7 @@ int close_pkt_sock(pkt_sock_t * const pkt_sock) /* * ODP_PACKET_SOCKET_MMAP: */ -int recv_pkt_sock(pkt_sock_t * const pkt_sock, +int recv_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock, odp_packet_t pkt_table[], unsigned len) { return pkt_mmap_v2_rx(pkt_sock->rx_ring.sock, &pkt_sock->rx_ring, @@ -796,13 +784,9 @@ int recv_pkt_sock(pkt_sock_t * const pkt_sock, /* * ODP_PACKET_SOCKET_MMAP: */ -int send_pkt_sock(pkt_sock_t * const pkt_sock, +int send_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock, odp_packet_t pkt_table[], unsigned len) { return pkt_mmap_v2_tx(pkt_sock->tx_ring.sock, &pkt_sock->tx_ring, pkt_table, len); } - -#else -#error "Unsupported ODP_PACKET_SOCKET_MODE!" -#endif diff --git a/test/packet/odp_example_pktio.c b/test/packet/odp_example_pktio.c index 85bbdd7..d6c9cd4 100644 --- a/test/packet/odp_example_pktio.c +++ b/test/packet/odp_example_pktio.c @@ -111,7 +111,7 @@ static void *pktio_queue_thread(void *arg) } /* Open a packet IO instance for this thread */ - sock_params->type = ODP_PKTIO_TYPE_SOCKET; + sock_params->type = ODP_PKTIO_TYPE_SOCKET_BASIC; pktio = odp_pktio_open(thr_args->pktio_dev, thr_args->pool, ¶ms); if (pktio == ODP_PKTIO_INVALID) { ODP_ERR(" [%02i] Error: pktio create failed\n", thr); @@ -223,7 +223,7 @@ static void *pktio_ifburst_thread(void *arg) } /* Open a packet IO instance for this thread */ - sock_params->type = ODP_PKTIO_TYPE_SOCKET; + sock_params->type = ODP_PKTIO_TYPE_SOCKET_BASIC; pktio = odp_pktio_open(thr_args->pktio_dev, thr_args->pool, ¶ms); if (pktio == ODP_PKTIO_INVALID) { ODP_ERR(" [%02i] Error: pktio create failed.\n", thr);