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 319E843F63; Thu, 2 May 2024 04:53:05 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2EAE3406B4; Thu, 2 May 2024 04:52:26 +0200 (CEST) Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by mails.dpdk.org (Postfix) with ESMTP id 99E06402E8 for ; Thu, 2 May 2024 04:52:18 +0200 (CEST) Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-6f4302187c0so344646b3a.1 for ; Wed, 01 May 2024 19:52:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1714618338; x=1715223138; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qMJk0/wUyC+YkUBTmkm9rHnDdJr/2BD43yaivOSfRfU=; b=AcvqrkZlJh+FkHNEko3IF/+FUkL1d0CKPFh8+UbibdiQzQCoDyG9+xP17Jb5CrDsYc ag5kkAGmd4+c/BIE04r6Oc2kJsSuqnNznv4pwP5woNYmtYc0/F0T6TCe7rPfnjJ9HdI0 wc1Vx6l6/K7Rpcj3wmqHi0rJYzMKzv8oj9RS0lgr3MmA5Rw3MXTX8uo3xOpf9o7a2fXu Uz4JKSMPfMJeKwlbuhpLUHjBGlnpG/twgxYXBc9S8bQQxs3P0NDR2B/Wth2O2wWJAkV6 DEaPuA4xYGyvUzIuB7bU0WUei12er80amdSVf9BJGt2Brnj1ve2kyIe+q479CNpxkd9F 7Buw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714618338; x=1715223138; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qMJk0/wUyC+YkUBTmkm9rHnDdJr/2BD43yaivOSfRfU=; b=ArgfGBJVN0KttlGPWpAqwbd5ogl/e33SWENOlwbIhWyjc9IWduADNXPMB6iWlV1K/g rnE7CZFksXHMPFAKj3NofIl+SyA51mypTW47vZnxqG9MBBKcdcJyMNmBZbNd/+32qAle ZC64MO/ANrPpIcr/SQXPnfHNjRDyqIAH4qXW7xIK8if2xtVNHJqmem7EflgTwWvgSnZ+ mRAqvPau37RmrKqJRzwdDwdQop7azWU+crl2Q2M1MmwMCFCDhb7r/ZJb18AhUE/CL4vw 04+FFnseTtzoDnYdtCaFLE6degd45pkJ7Cz0EF576buNUXtmC6/3EEQ7wfSFqsb6Kwp5 OI+Q== X-Gm-Message-State: AOJu0YxmQtlEaNIhFFLgfoI9hsVMNqOvGX4SVPiP1CKbx4r0iAb2m+7J zzZP//zz0vaB8YY363yQMgKPLiHe/FeXjEIcX+BakKJWhlLnFqWA+zruTlXPvPDp/dlWWfmQo1M KQ64= X-Google-Smtp-Source: AGHT+IHjPExGKZDjl/C366cNJRktiOnGN05OpmFZ9wLVd96ee9tmkneh3ClB2RjSTuzwLSYjqUIdXw== X-Received: by 2002:a05:6a21:594:b0:1af:6088:10fc with SMTP id lw20-20020a056a21059400b001af608810fcmr2293984pzb.13.1714618337694; Wed, 01 May 2024 19:52:17 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id z19-20020aa78893000000b006ecfc3a8d6csm104818pfe.124.2024.05.01.19.52.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 May 2024 19:52:17 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v11 8/9] net/tap: simplify internals Date: Wed, 1 May 2024 19:49:27 -0700 Message-ID: <20240502025201.28322-9-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240502025201.28322-1-stephen@networkplumber.org> References: <20240130034925.44869-1-stephen@networkplumber.org> <20240502025201.28322-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 The names of Linux network devices are IFNAMSIZ(16) not the same as DPDK which has up to 64 characters. Don't need to hold onto the whole ifreq to save the remote interface flags. Make sure packet and byte counters are read once, so that global and per-queue values add up. No need for separate rx_nombuf counter since there is an alloc_failed value in ethdev. Signed-off-by: Stephen Hemminger --- drivers/net/tap/rte_eth_tap.c | 114 +++++++++++++++++++--------------- drivers/net/tap/rte_eth_tap.h | 12 ++-- 2 files changed, 71 insertions(+), 55 deletions(-) diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c index d847565073..2af6b763e6 100644 --- a/drivers/net/tap/rte_eth_tap.c +++ b/drivers/net/tap/rte_eth_tap.c @@ -46,6 +46,11 @@ #include #include +/* Used to snapshot statistics */ +#ifndef READ_ONCE +#define READ_ONCE(var) (*((volatile typeof(var) *)(&(var)))) +#endif + /* Linux based path to the TUN device */ #define TUN_TAP_DEV_PATH "/dev/net/tun" #define DEFAULT_TAP_NAME "dtap" @@ -212,7 +217,7 @@ tun_alloc(struct pmd_internals *pmd, int is_keepalive, int persistent) * and need to find the resulting device. */ TAP_LOG(DEBUG, "Device name is '%s'", ifr.ifr_name); - strlcpy(pmd->name, ifr.ifr_name, RTE_ETH_NAME_MAX_LEN); + strlcpy(pmd->name, ifr.ifr_name, IFNAMSIZ); if (is_keepalive) { /* @@ -466,7 +471,8 @@ pmd_rx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) struct rte_mbuf *buf = rte_pktmbuf_alloc(rxq->mp); if (unlikely(!buf)) { - rxq->stats.rx_nombuf++; + rte_eth_devices[rxq->in_port].data->rx_mbuf_alloc_failed++; + /* No new buf has been allocated: do nothing */ if (!new_tail || !seg) goto end; @@ -1047,43 +1053,44 @@ tap_dev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info) static int tap_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *tap_stats) { - unsigned int i, imax; - unsigned long rx_total = 0, tx_total = 0, tx_err_total = 0; - unsigned long rx_bytes_total = 0, tx_bytes_total = 0; - unsigned long rx_nombuf = 0, ierrors = 0; + unsigned int i; const struct pmd_internals *pmd = dev->data->dev_private; + uint64_t bytes, packets; /* rx queue statistics */ - imax = (dev->data->nb_rx_queues < RTE_ETHDEV_QUEUE_STAT_CNTRS) ? - dev->data->nb_rx_queues : RTE_ETHDEV_QUEUE_STAT_CNTRS; - for (i = 0; i < imax; i++) { - tap_stats->q_ipackets[i] = pmd->rxq[i].stats.ipackets; - tap_stats->q_ibytes[i] = pmd->rxq[i].stats.ibytes; - rx_total += tap_stats->q_ipackets[i]; - rx_bytes_total += tap_stats->q_ibytes[i]; - rx_nombuf += pmd->rxq[i].stats.rx_nombuf; - ierrors += pmd->rxq[i].stats.ierrors; + for (i = 0; i < dev->data->nb_rx_queues; i++) { + const struct rx_queue *rxq = &pmd->rxq[i]; + + packets = READ_ONCE(rxq->stats.ipackets); + bytes = READ_ONCE(rxq->stats.ibytes); + + tap_stats->ipackets += packets; + tap_stats->ibytes += bytes; + tap_stats->ierrors += rxq->stats.ierrors; + + if (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) { + tap_stats->q_ipackets[i] = packets; + tap_stats->q_ibytes[i] = bytes; + } } /* tx queue statistics */ - imax = (dev->data->nb_tx_queues < RTE_ETHDEV_QUEUE_STAT_CNTRS) ? - dev->data->nb_tx_queues : RTE_ETHDEV_QUEUE_STAT_CNTRS; - - for (i = 0; i < imax; i++) { - tap_stats->q_opackets[i] = pmd->txq[i].stats.opackets; - tap_stats->q_obytes[i] = pmd->txq[i].stats.obytes; - tx_total += tap_stats->q_opackets[i]; - tx_err_total += pmd->txq[i].stats.errs; - tx_bytes_total += tap_stats->q_obytes[i]; - } - - tap_stats->ipackets = rx_total; - tap_stats->ibytes = rx_bytes_total; - tap_stats->ierrors = ierrors; - tap_stats->rx_nombuf = rx_nombuf; - tap_stats->opackets = tx_total; - tap_stats->oerrors = tx_err_total; - tap_stats->obytes = tx_bytes_total; + for (i = 0; i < dev->data->nb_tx_queues; i++) { + const struct tx_queue *txq = &pmd->txq[i]; + + packets = READ_ONCE(txq->stats.opackets); + bytes = READ_ONCE(txq->stats.obytes); + + tap_stats->opackets += packets; + tap_stats->obytes += bytes; + tap_stats->oerrors += txq->stats.errs; + + if (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) { + tap_stats->q_opackets[i] = packets; + tap_stats->q_obytes[i] = bytes; + } + } + return 0; } @@ -1097,7 +1104,6 @@ tap_stats_reset(struct rte_eth_dev *dev) pmd->rxq[i].stats.ipackets = 0; pmd->rxq[i].stats.ibytes = 0; pmd->rxq[i].stats.ierrors = 0; - pmd->rxq[i].stats.rx_nombuf = 0; pmd->txq[i].stats.opackets = 0; pmd->txq[i].stats.errs = 0; @@ -1156,9 +1162,13 @@ tap_dev_close(struct rte_eth_dev *dev) } if (internals->remote_if_index) { + struct ifreq remote_ifr; + + strlcpy(remote_ifr.ifr_name, internals->remote_iface, IFNAMSIZ); + remote_ifr.ifr_flags = internals->remote_flags; + /* Restore initial remote state */ - int ret = ioctl(internals->ioctl_sock, SIOCSIFFLAGS, - &internals->remote_initial_flags); + int ret = ioctl(internals->ioctl_sock, SIOCSIFFLAGS, &remote_ifr); if (ret) TAP_LOG(ERR, "restore remote state failed: %d", ret); @@ -2067,16 +2077,22 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name, LIST_INIT(&pmd->flows); if (strlen(remote_iface)) { + struct ifreq remote_ifr; + pmd->remote_if_index = if_nametoindex(remote_iface); if (!pmd->remote_if_index) { TAP_LOG(ERR, "%s: failed to get %s if_index.", pmd->name, remote_iface); goto error_remote; } - strlcpy(pmd->remote_iface, remote_iface, RTE_ETH_NAME_MAX_LEN); + strlcpy(pmd->remote_iface, remote_iface, IFNAMSIZ); + + memset(&remote_ifr, 0, sizeof(ifr)); + strlcpy(remote_ifr.ifr_name, remote_iface, IFNAMSIZ); /* Save state of remote device */ - tap_ioctl(pmd, SIOCGIFFLAGS, &pmd->remote_initial_flags, 0, REMOTE_ONLY); + tap_ioctl(pmd, SIOCGIFFLAGS, &remote_ifr, 0, REMOTE_ONLY); + pmd->remote_flags = remote_ifr.ifr_flags; /* Replicate remote MAC address */ if (tap_ioctl(pmd, SIOCGIFHWADDR, &ifr, 0, REMOTE_ONLY) < 0) { @@ -2190,10 +2206,10 @@ set_interface_name(const char *key __rte_unused, value); return -1; } - strlcpy(name, value, RTE_ETH_NAME_MAX_LEN); + strlcpy(name, value, IFNAMSIZ); } else { /* use tap%d which causes kernel to choose next available */ - strlcpy(name, DEFAULT_TAP_NAME "%d", RTE_ETH_NAME_MAX_LEN); + strlcpy(name, DEFAULT_TAP_NAME "%d", IFNAMSIZ); } return 0; } @@ -2211,7 +2227,7 @@ set_remote_iface(const char *key __rte_unused, value); return -1; } - strlcpy(name, value, RTE_ETH_NAME_MAX_LEN); + strlcpy(name, value, IFNAMSIZ); } return 0; @@ -2262,13 +2278,13 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev) const char *name, *params; int ret; struct rte_kvargs *kvlist = NULL; - char tun_name[RTE_ETH_NAME_MAX_LEN]; - char remote_iface[RTE_ETH_NAME_MAX_LEN]; + char tun_name[IFNAMSIZ]; + char remote_iface[IFNAMSIZ]; struct rte_eth_dev *eth_dev; name = rte_vdev_device_name(dev); params = rte_vdev_device_args(dev); - memset(remote_iface, 0, RTE_ETH_NAME_MAX_LEN); + memset(remote_iface, 0, IFNAMSIZ); if (rte_eal_process_type() == RTE_PROC_SECONDARY && strlen(params) == 0) { @@ -2284,7 +2300,7 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev) } /* use tun%d which causes kernel to choose next available */ - strlcpy(tun_name, DEFAULT_TUN_NAME "%d", RTE_ETH_NAME_MAX_LEN); + strlcpy(tun_name, DEFAULT_TUN_NAME "%d", IFNAMSIZ); if (params && (params[0] != '\0')) { TAP_LOG(DEBUG, "parameters (%s)", params); @@ -2424,8 +2440,8 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev) int ret; struct rte_kvargs *kvlist = NULL; int speed; - char tap_name[RTE_ETH_NAME_MAX_LEN]; - char remote_iface[RTE_ETH_NAME_MAX_LEN]; + char tap_name[IFNAMSIZ]; + char remote_iface[IFNAMSIZ]; struct rte_ether_addr user_mac = { .addr_bytes = {0} }; struct rte_eth_dev *eth_dev; int tap_devices_count_increased = 0; @@ -2479,8 +2495,8 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev) speed = RTE_ETH_SPEED_NUM_10G; /* use tap%d which causes kernel to choose next available */ - strlcpy(tap_name, DEFAULT_TAP_NAME "%d", RTE_ETH_NAME_MAX_LEN); - memset(remote_iface, 0, RTE_ETH_NAME_MAX_LEN); + strlcpy(tap_name, DEFAULT_TAP_NAME "%d", IFNAMSIZ); + memset(remote_iface, 0, IFNAMSIZ); if (params && (params[0] != '\0')) { TAP_LOG(DEBUG, "parameters (%s)", params); diff --git a/drivers/net/tap/rte_eth_tap.h b/drivers/net/tap/rte_eth_tap.h index ce4322ad04..ca510e2c6b 100644 --- a/drivers/net/tap/rte_eth_tap.h +++ b/drivers/net/tap/rte_eth_tap.h @@ -68,15 +68,16 @@ struct tx_queue { struct pmd_internals { struct rte_eth_dev *dev; /* Ethernet device. */ - char remote_iface[RTE_ETH_NAME_MAX_LEN]; /* Remote netdevice name */ - char name[RTE_ETH_NAME_MAX_LEN]; /* Internal Tap device name */ + char remote_iface[IFNAMSIZ]; /* Remote netdevice name */ + char name[IFNAMSIZ]; /* Internal Tap device name */ int type; /* Type field - TUN|TAP */ int persist; /* 1 if keep link up, else 0 */ struct rte_ether_addr eth_addr; /* Mac address of the device port */ - struct ifreq remote_initial_flags;/* Remote netdevice flags on init */ + uint16_t remote_flags; /* Remote netdevice flags on init */ int remote_if_index; /* remote netdevice IF_INDEX */ int if_index; /* IF_INDEX for the port */ int ioctl_sock; /* socket for ioctl calls */ + int ka_fd; /* keep-alive file descriptor */ #ifdef HAVE_TCA_FLOWER int nlsk_fd; /* Netlink socket fd */ @@ -88,12 +89,11 @@ struct pmd_internals { /* implicit rte_flow rules set when a remote device is active */ LIST_HEAD(tap_implicit_flows, rte_flow) implicit_flows; #endif + struct rte_intr_handle *intr_handle; /* LSC interrupt handle. */ + struct rte_mempool *gso_ctx_mp; /* Mempool for GSO packets */ struct rx_queue rxq[RTE_PMD_TAP_MAX_QUEUES]; /* List of RX queues */ struct tx_queue txq[RTE_PMD_TAP_MAX_QUEUES]; /* List of TX queues */ - struct rte_intr_handle *intr_handle; /* LSC interrupt handle. */ - int ka_fd; /* keep-alive file descriptor */ - struct rte_mempool *gso_ctx_mp; /* Mempool for GSO packets */ }; struct pmd_process_private { -- 2.43.0