From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 4EB43C356 for ; Mon, 15 Jun 2015 09:57:14 +0200 (CEST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 15 Jun 2015 00:57:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,617,1427785200"; d="scan'208";a="743499623" Received: from shvmail01.sh.intel.com ([10.239.29.42]) by fmsmga002.fm.intel.com with ESMTP; 15 Jun 2015 00:57:13 -0700 Received: from shecgisg004.sh.intel.com (shecgisg004.sh.intel.com [10.239.29.89]) by shvmail01.sh.intel.com with ESMTP id t5F7vAQo005771; Mon, 15 Jun 2015 15:57:10 +0800 Received: from shecgisg004.sh.intel.com (localhost [127.0.0.1]) by shecgisg004.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id t5F7v6lF030674; Mon, 15 Jun 2015 15:57:09 +0800 Received: (from couyang@localhost) by shecgisg004.sh.intel.com (8.13.6/8.13.6/Submit) id t5F7v6nf030670; Mon, 15 Jun 2015 15:57:06 +0800 From: Ouyang Changchun To: dev@dpdk.org Date: Mon, 15 Jun 2015 15:56:45 +0800 Message-Id: <1434355006-30583-9-git-send-email-changchun.ouyang@intel.com> X-Mailer: git-send-email 1.7.12.2 In-Reply-To: <1434355006-30583-1-git-send-email-changchun.ouyang@intel.com> References: <1433915549-18571-1-git-send-email-changchun.ouyang@intel.com> <1434355006-30583-1-git-send-email-changchun.ouyang@intel.com> Subject: [dpdk-dev] [PATCH v3 8/9] vhost: Add per queue stats info X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 15 Jun 2015 07:57:15 -0000 Add per queue stats info Changes in v3 - fix coding style and displaying format - check stats_enable to alloc mem for queue pair Changes in v2 - fix the stats issue in tx_local - dynamically alloc mem for queue pair stats info - fix checkpatch errors Signed-off-by: Changchun Ouyang --- examples/vhost/main.c | 126 +++++++++++++++++++++++++++++++------------------- 1 file changed, 79 insertions(+), 47 deletions(-) diff --git a/examples/vhost/main.c b/examples/vhost/main.c index d40cb11..76f645f 100644 --- a/examples/vhost/main.c +++ b/examples/vhost/main.c @@ -314,7 +314,7 @@ struct ipv4_hdr { #define VLAN_ETH_HLEN 18 /* Per-device statistics struct */ -struct device_statistics { +struct qp_statistics { uint64_t tx_total; rte_atomic64_t rx_total_atomic; uint64_t rx_total; @@ -322,6 +322,10 @@ struct device_statistics { rte_atomic64_t rx_atomic; uint64_t rx; } __rte_cache_aligned; + +struct device_statistics { + struct qp_statistics *qp_stats; +}; struct device_statistics dev_statistics[MAX_DEVICES]; /* @@ -738,6 +742,17 @@ us_vhost_parse_args(int argc, char **argv) return -1; } else { enable_stats = ret; + if (enable_stats) + for (i = 0; i < MAX_DEVICES; i++) { + dev_statistics[i].qp_stats = + malloc(VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX * sizeof(struct qp_statistics)); + if (dev_statistics[i].qp_stats == NULL) { + RTE_LOG(ERR, VHOST_CONFIG, "Failed to allocate memory for qp stats.\n"); + return -1; + } + memset(dev_statistics[i].qp_stats, 0, + VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX * sizeof(struct qp_statistics)); + } } } @@ -1093,13 +1108,13 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m, uint32_t q_idx) &m, 1); if (enable_stats) { rte_atomic64_add( - &dev_statistics[tdev->device_fh].rx_total_atomic, + &dev_statistics[tdev->device_fh].qp_stats[q_idx].rx_total_atomic, 1); rte_atomic64_add( - &dev_statistics[tdev->device_fh].rx_atomic, + &dev_statistics[tdev->device_fh].qp_stats[q_idx].rx_atomic, ret); - dev_statistics[tdev->device_fh].tx_total++; - dev_statistics[tdev->device_fh].tx += ret; + dev_statistics[dev->device_fh].qp_stats[q_idx].tx_total++; + dev_statistics[dev->device_fh].qp_stats[q_idx].tx += ret; } } @@ -1233,8 +1248,8 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, tx_q->m_table[len] = m; len++; if (enable_stats) { - dev_statistics[dev->device_fh].tx_total++; - dev_statistics[dev->device_fh].tx++; + dev_statistics[dev->device_fh].qp_stats[q_idx].tx_total++; + dev_statistics[dev->device_fh].qp_stats[q_idx].tx++; } if (unlikely(len == MAX_PKT_BURST)) { @@ -1365,10 +1380,10 @@ switch_worker(__attribute__((unused)) void *arg) pkts_burst, rx_count); if (enable_stats) { rte_atomic64_add( - &dev_statistics[dev_ll->vdev->dev->device_fh].rx_total_atomic, + &dev_statistics[dev_ll->vdev->dev->device_fh].qp_stats[i].rx_total_atomic, rx_count); rte_atomic64_add( - &dev_statistics[dev_ll->vdev->dev->device_fh].rx_atomic, ret_count); + &dev_statistics[dev_ll->vdev->dev->device_fh].qp_stats[i].rx_atomic, ret_count); } while (likely(rx_count)) { rx_count--; @@ -1918,8 +1933,8 @@ virtio_tx_route_zcp(struct virtio_net *dev, struct rte_mbuf *m, (mbuf->next == NULL) ? "null" : "non-null"); if (enable_stats) { - dev_statistics[dev->device_fh].tx_total++; - dev_statistics[dev->device_fh].tx++; + dev_statistics[dev->device_fh].qp_stats[0].tx_total++; + dev_statistics[dev->device_fh].qp_stats[0].tx++; } if (unlikely(len == MAX_PKT_BURST)) { @@ -2202,9 +2217,9 @@ switch_worker_zcp(__attribute__((unused)) void *arg) ret_count = virtio_dev_rx_zcp(dev, pkts_burst, rx_count); if (enable_stats) { - dev_statistics[dev->device_fh].rx_total + dev_statistics[dev->device_fh].qp_stats[0].rx_total += rx_count; - dev_statistics[dev->device_fh].rx + dev_statistics[dev->device_fh].qp_stats[0].rx += ret_count; } while (likely(rx_count)) { @@ -2824,7 +2839,9 @@ new_device (struct virtio_net *dev) add_data_ll_entry(&lcore_info[vdev->coreid].lcore_ll->ll_root_used, ll_dev); /* Initialize device stats */ - memset(&dev_statistics[dev->device_fh], 0, sizeof(struct device_statistics)); + if (enable_stats) + memset(dev_statistics[dev->device_fh].qp_stats, 0, + VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX * sizeof(struct qp_statistics)); /* Disable notifications. */ rte_vhost_enable_guest_notification(dev, VIRTIO_RXQ, 0); @@ -2857,7 +2874,7 @@ print_stats(void) struct virtio_net_data_ll *dev_ll; uint64_t tx_dropped, rx_dropped; uint64_t tx, tx_total, rx, rx_total; - uint32_t device_fh; + uint32_t device_fh, i; const char clr[] = { 27, '[', '2', 'J', '\0' }; const char top_left[] = { 27, '[', '1', ';', '1', 'H','\0' }; @@ -2872,35 +2889,53 @@ print_stats(void) dev_ll = ll_root_used; while (dev_ll != NULL) { device_fh = (uint32_t)dev_ll->vdev->dev->device_fh; - tx_total = dev_statistics[device_fh].tx_total; - tx = dev_statistics[device_fh].tx; - tx_dropped = tx_total - tx; - if (zero_copy == 0) { - rx_total = rte_atomic64_read( - &dev_statistics[device_fh].rx_total_atomic); - rx = rte_atomic64_read( - &dev_statistics[device_fh].rx_atomic); - } else { - rx_total = dev_statistics[device_fh].rx_total; - rx = dev_statistics[device_fh].rx; - } - rx_dropped = rx_total - rx; - - printf("\nStatistics for device %"PRIu32" ------------------------------" - "\nTX total: %"PRIu64"" - "\nTX dropped: %"PRIu64"" - "\nTX successful: %"PRIu64"" - "\nRX total: %"PRIu64"" - "\nRX dropped: %"PRIu64"" - "\nRX successful: %"PRIu64"", - device_fh, - tx_total, - tx_dropped, - tx, - rx_total, - rx_dropped, - rx); - + for (i = 0; i < rxq; i++) { + tx_total = dev_statistics[device_fh].qp_stats[i].tx_total; + tx = dev_statistics[device_fh].qp_stats[i].tx; + tx_dropped = tx_total - tx; + if (zero_copy == 0) { + rx_total = rte_atomic64_read( + &dev_statistics[device_fh].qp_stats[i].rx_total_atomic); + rx = rte_atomic64_read( + &dev_statistics[device_fh].qp_stats[i].rx_atomic); + } else { + rx_total = dev_statistics[device_fh].qp_stats[0].rx_total; + rx = dev_statistics[device_fh].qp_stats[0].rx; + } + rx_dropped = rx_total - rx; + + if (rxq > 1) + printf("\nStatistics for device %"PRIu32" queue id: %d------------------" + "\nTX total: %"PRIu64"" + "\nTX dropped: %"PRIu64"" + "\nTX success: %"PRIu64"" + "\nRX total: %"PRIu64"" + "\nRX dropped: %"PRIu64"" + "\nRX success: %"PRIu64"", + device_fh, + i, + tx_total, + tx_dropped, + tx, + rx_total, + rx_dropped, + rx); + else + printf("\nStatistics for device %"PRIu32" ------------------------------" + "\nTX total: %"PRIu64"" + "\nTX dropped: %"PRIu64"" + "\nTX success: %"PRIu64"" + "\nRX total: %"PRIu64"" + "\nRX dropped: %"PRIu64"" + "\nRX success: %"PRIu64"", + device_fh, + tx_total, + tx_dropped, + tx, + rx_total, + rx_dropped, + rx); + } dev_ll = dev_ll->next; } printf("\n======================================================\n"); @@ -3070,9 +3105,6 @@ main(int argc, char *argv[]) if (init_data_ll() == -1) rte_exit(EXIT_FAILURE, "Failed to initialize linked list\n"); - /* Initialize device stats */ - memset(&dev_statistics, 0, sizeof(dev_statistics)); - /* Enable stats if the user option is set. */ if (enable_stats) pthread_create(&tid, NULL, (void*)print_stats, NULL ); -- 1.8.4.2