get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/106615/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 106615,
    "url": "http://patchwork.dpdk.org/api/patches/106615/?format=api",
    "web_url": "http://patchwork.dpdk.org/project/dpdk/patch/20220127145655.558029-3-maxime.coquelin@redhat.com/",
    "project": {
        "id": 1,
        "url": "http://patchwork.dpdk.org/api/projects/1/?format=api",
        "name": "DPDK",
        "link_name": "dpdk",
        "list_id": "dev.dpdk.org",
        "list_email": "dev@dpdk.org",
        "web_url": "http://core.dpdk.org",
        "scm_url": "git://dpdk.org/dpdk",
        "webscm_url": "http://git.dpdk.org/dpdk",
        "list_archive_url": "https://inbox.dpdk.org/dev",
        "list_archive_url_format": "https://inbox.dpdk.org/dev/{}",
        "commit_url_format": ""
    },
    "msgid": "<20220127145655.558029-3-maxime.coquelin@redhat.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20220127145655.558029-3-maxime.coquelin@redhat.com",
    "date": "2022-01-27T14:56:52",
    "name": "[2/5] vhost: add per-virtqueue statistics support",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "fc59955e4c87b7596a99626489f4dfae8e3ce587",
    "submitter": {
        "id": 512,
        "url": "http://patchwork.dpdk.org/api/people/512/?format=api",
        "name": "Maxime Coquelin",
        "email": "maxime.coquelin@redhat.com"
    },
    "delegate": {
        "id": 2642,
        "url": "http://patchwork.dpdk.org/api/users/2642/?format=api",
        "username": "mcoquelin",
        "first_name": "Maxime",
        "last_name": "Coquelin",
        "email": "maxime.coquelin@redhat.com"
    },
    "mbox": "http://patchwork.dpdk.org/project/dpdk/patch/20220127145655.558029-3-maxime.coquelin@redhat.com/mbox/",
    "series": [
        {
            "id": 21401,
            "url": "http://patchwork.dpdk.org/api/series/21401/?format=api",
            "web_url": "http://patchwork.dpdk.org/project/dpdk/list/?series=21401",
            "date": "2022-01-27T14:56:50",
            "name": "vhost: introduce per-virtqueue stats API",
            "version": 1,
            "mbox": "http://patchwork.dpdk.org/series/21401/mbox/"
        }
    ],
    "comments": "http://patchwork.dpdk.org/api/patches/106615/comments/",
    "check": "success",
    "checks": "http://patchwork.dpdk.org/api/patches/106615/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@inbox.dpdk.org",
        "Delivered-To": "patchwork@inbox.dpdk.org",
        "Received": [
            "from mails.dpdk.org (mails.dpdk.org [217.70.189.124])\n\tby inbox.dpdk.org (Postfix) with ESMTP id 84BC6A04A6;\n\tThu, 27 Jan 2022 15:57:54 +0100 (CET)",
            "from [217.70.189.124] (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id 5DA6642808;\n\tThu, 27 Jan 2022 15:57:49 +0100 (CET)",
            "from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [170.10.133.124])\n by mails.dpdk.org (Postfix) with ESMTP id 217EC427D2\n for <dev@dpdk.org>; Thu, 27 Jan 2022 15:57:47 +0100 (CET)",
            "from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com\n [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS\n (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id\n us-mta-318-75KVdZJwOy6V8oN9Cx-KPQ-1; Thu, 27 Jan 2022 09:57:44 -0500",
            "from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com\n [10.5.11.14])\n (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n (No client certificate requested)\n by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D8B8B640AA;\n Thu, 27 Jan 2022 14:57:35 +0000 (UTC)",
            "from max-t490s.redhat.com (unknown [10.39.208.34])\n by smtp.corp.redhat.com (Postfix) with ESMTP id 8EADB798B7;\n Thu, 27 Jan 2022 14:57:34 +0000 (UTC)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1643295466;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:cc:mime-version:mime-version:content-type:content-type:\n content-transfer-encoding:content-transfer-encoding:\n in-reply-to:in-reply-to:references:references;\n bh=FJ9r8HiBjj9XHpdK0Xe+axQb+rU9B7Xe76HteNIIg+Q=;\n b=WCAVATsAmF+JddTJpACjETwXp33DzuZEuSsGVv0qEtcA631e1r342imatV76ycx0L3B5JD\n aq7iD0eP96Bs9Ci4N6PO4M33uPdugYlEY1Sh/UB6e50ilDWTckMRA/bndZYL5d84TvKDAU\n Px3UdiaLWUA6rJvNOWjB7dpRtjt2YEs=",
        "X-MC-Unique": "75KVdZJwOy6V8oN9Cx-KPQ-1",
        "From": "Maxime Coquelin <maxime.coquelin@redhat.com>",
        "To": "dev@dpdk.org,\n\tchenbo.xia@intel.com,\n\tdavid.marchand@redhat.com",
        "Cc": "Maxime Coquelin <maxime.coquelin@redhat.com>",
        "Subject": "[PATCH 2/5] vhost: add per-virtqueue statistics support",
        "Date": "Thu, 27 Jan 2022 15:56:52 +0100",
        "Message-Id": "<20220127145655.558029-3-maxime.coquelin@redhat.com>",
        "In-Reply-To": "<20220127145655.558029-1-maxime.coquelin@redhat.com>",
        "References": "<20220127145655.558029-1-maxime.coquelin@redhat.com>",
        "MIME-Version": "1.0",
        "X-Scanned-By": "MIMEDefang 2.79 on 10.5.11.14",
        "Authentication-Results": "relay.mimecast.com;\n auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=maxime.coquelin@redhat.com",
        "X-Mimecast-Spam-Score": "0",
        "X-Mimecast-Originator": "redhat.com",
        "Content-Transfer-Encoding": "8bit",
        "Content-Type": "text/plain; charset=\"US-ASCII\"",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n <mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://mails.dpdk.org/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n <mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org"
    },
    "content": "This patch introduces new APIs for the application\nto query and reset per-virtqueue statistics. The\npatch also introduces generic counters.\n\nSigned-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>\n---\n lib/vhost/rte_vhost.h  |  89 +++++++++++++++++++++++++++++++++\n lib/vhost/socket.c     |   4 +-\n lib/vhost/version.map  |   5 ++\n lib/vhost/vhost.c      | 109 ++++++++++++++++++++++++++++++++++++++++-\n lib/vhost/vhost.h      |  18 ++++++-\n lib/vhost/virtio_net.c |  53 ++++++++++++++++++++\n 6 files changed, 274 insertions(+), 4 deletions(-)",
    "diff": "diff --git a/lib/vhost/rte_vhost.h b/lib/vhost/rte_vhost.h\nindex b454c05868..e739091ca0 100644\n--- a/lib/vhost/rte_vhost.h\n+++ b/lib/vhost/rte_vhost.h\n@@ -37,6 +37,7 @@ extern \"C\" {\n #define RTE_VHOST_USER_LINEARBUF_SUPPORT\t(1ULL << 6)\n #define RTE_VHOST_USER_ASYNC_COPY\t(1ULL << 7)\n #define RTE_VHOST_USER_NET_COMPLIANT_OL_FLAGS\t(1ULL << 8)\n+#define RTE_VHOST_USER_NET_STATS_ENABLE\t(1ULL << 9)\n \n /* Features. */\n #ifndef VIRTIO_NET_F_GUEST_ANNOUNCE\n@@ -317,6 +318,32 @@ struct rte_vhost_power_monitor_cond {\n \tuint8_t match;\n };\n \n+/** Maximum name length for the statistics counters */\n+#define RTE_VHOST_STATS_NAME_SIZE 64\n+\n+/**\n+ * Vhost virtqueue statistics structure\n+ *\n+ * This structure is used by rte_vhost_vring_stats_get() to provide\n+ * virtqueue statistics to the calling application.\n+ * It maps a name ID, corresponding to an index in the array returned\n+ * by rte_vhost_vring_stats_get_names(), to a statistic value.\n+ */\n+struct rte_vhost_stat {\n+\tuint64_t id;    /**< The index in xstats name array. */\n+\tuint64_t value; /**< The statistic counter value. */\n+};\n+\n+/**\n+ * Vhost virtqueue statistic name element\n+ *\n+ * This structure is used by rte_vhost_vring_stats_get_anmes() to\n+ * provide virtqueue statistics names to the calling application.\n+ */\n+struct rte_vhost_stat_name {\n+\tchar name[RTE_VHOST_STATS_NAME_SIZE]; /**< The statistic name. */\n+};\n+\n /**\n  * Convert guest physical address to host virtual address\n  *\n@@ -1059,6 +1086,68 @@ __rte_experimental\n int\n rte_vhost_slave_config_change(int vid, bool need_reply);\n \n+/**\n+ * Retrieve names of statistics of a Vhost virtqueue.\n+ *\n+ * There is an assumption that 'stat_names' and 'stats' arrays are matched\n+ * by array index: stats_names[i].name => stats[i].value\n+ *\n+ * @param vid\n+ *   vhost device ID\n+ * @param queue_id\n+ *   vhost queue index\n+ * @param stats_names\n+ *   array of at least size elements to be filled.\n+ *   If set to NULL, the function returns the required number of elements.\n+ * @param size\n+ *   The number of elements in stats_names array.\n+ * @return\n+ *   A negative value on error, otherwise the number of entries filled in the\n+ *   stats name array.\n+ */\n+__rte_experimental\n+int\n+rte_vhost_vring_stats_get_names(int vid, uint16_t queue_id,\n+\t\tstruct rte_vhost_stat_name *name, unsigned int size);\n+\n+/**\n+ * Retrieve statistics of a Vhost virtqueue.\n+ *\n+ * There is an assumption that 'stat_names' and 'stats' arrays are matched\n+ * by array index: stats_names[i].name => stats[i].value\n+ *\n+ * @param vid\n+ *   vhost device ID\n+ * @param queue_id\n+ *   vhost queue index\n+ * @param stats\n+ *   A pointer to a table of structure of type rte_vhost_stat to be filled with\n+ *   virtqueue statistics ids and values.\n+ * @param n\n+ *   The number of elements in stats array.\n+ * @return\n+ *   A negative value on error, otherwise the number of entries filled in the\n+ *   stats table.\n+ */\n+__rte_experimental\n+int\n+rte_vhost_vring_stats_get(int vid, uint16_t queue_id,\n+\t\tstruct rte_vhost_stat *stats, unsigned int n);\n+\n+/**\n+ * Reset statistics of a Vhost virtqueue.\n+ *\n+ * @param vid\n+ *   vhost device ID\n+ * @param queue_id\n+ *   vhost queue index\n+ * @return\n+ *   0 on success, a negative value on error.\n+ */\n+__rte_experimental\n+int\n+rte_vhost_vring_stats_reset(int vid, uint16_t queue_id);\n+\n #ifdef __cplusplus\n }\n #endif\ndiff --git a/lib/vhost/socket.c b/lib/vhost/socket.c\nindex c2f8013cd5..6020565fb6 100644\n--- a/lib/vhost/socket.c\n+++ b/lib/vhost/socket.c\n@@ -43,6 +43,7 @@ struct vhost_user_socket {\n \tbool linearbuf;\n \tbool async_copy;\n \tbool net_compliant_ol_flags;\n+\tbool stats_enabled;\n \n \t/*\n \t * The \"supported_features\" indicates the feature bits the\n@@ -228,7 +229,7 @@ vhost_user_add_connection(int fd, struct vhost_user_socket *vsocket)\n \tvhost_set_ifname(vid, vsocket->path, size);\n \n \tvhost_setup_virtio_net(vid, vsocket->use_builtin_virtio_net,\n-\t\tvsocket->net_compliant_ol_flags);\n+\t\tvsocket->net_compliant_ol_flags, vsocket->stats_enabled);\n \n \tvhost_attach_vdpa_device(vid, vsocket->vdpa_dev);\n \n@@ -864,6 +865,7 @@ rte_vhost_driver_register(const char *path, uint64_t flags)\n \tvsocket->linearbuf = flags & RTE_VHOST_USER_LINEARBUF_SUPPORT;\n \tvsocket->async_copy = flags & RTE_VHOST_USER_ASYNC_COPY;\n \tvsocket->net_compliant_ol_flags = flags & RTE_VHOST_USER_NET_COMPLIANT_OL_FLAGS;\n+\tvsocket->stats_enabled = flags & RTE_VHOST_USER_NET_STATS_ENABLE;\n \n \tif (vsocket->async_copy &&\n \t\t(flags & (RTE_VHOST_USER_IOMMU_SUPPORT |\ndiff --git a/lib/vhost/version.map b/lib/vhost/version.map\nindex a7ef7f1976..b83f79c87f 100644\n--- a/lib/vhost/version.map\n+++ b/lib/vhost/version.map\n@@ -84,6 +84,11 @@ EXPERIMENTAL {\n \n \t# added in 21.11\n \trte_vhost_get_monitor_addr;\n+\n+\t# added in 22.03\n+\trte_vhost_vring_stats_get_names;\n+\trte_vhost_vring_stats_get;\n+\trte_vhost_vring_stats_reset;\n };\n \n INTERNAL {\ndiff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c\nindex 42c01abf25..0c6a737aca 100644\n--- a/lib/vhost/vhost.c\n+++ b/lib/vhost/vhost.c\n@@ -28,6 +28,28 @@\n struct virtio_net *vhost_devices[MAX_VHOST_DEVICE];\n pthread_mutex_t vhost_dev_lock = PTHREAD_MUTEX_INITIALIZER;\n \n+struct vhost_vq_stats_name_off {\n+\tchar name[RTE_VHOST_STATS_NAME_SIZE];\n+\tunsigned int offset;\n+};\n+\n+static const struct vhost_vq_stats_name_off vhost_vq_stat_strings[] = {\n+\t{\"good_packets\",           offsetof(struct vhost_virtqueue, stats.packets)},\n+\t{\"good_bytes\",             offsetof(struct vhost_virtqueue, stats.bytes)},\n+\t{\"multicast_packets\",      offsetof(struct vhost_virtqueue, stats.multicast)},\n+\t{\"broadcast_packets\",      offsetof(struct vhost_virtqueue, stats.broadcast)},\n+\t{\"undersize_packets\",      offsetof(struct vhost_virtqueue, stats.size_bins[0])},\n+\t{\"size_64_packets\",        offsetof(struct vhost_virtqueue, stats.size_bins[1])},\n+\t{\"size_65_127_packets\",    offsetof(struct vhost_virtqueue, stats.size_bins[2])},\n+\t{\"size_128_255_packets\",   offsetof(struct vhost_virtqueue, stats.size_bins[3])},\n+\t{\"size_256_511_packets\",   offsetof(struct vhost_virtqueue, stats.size_bins[4])},\n+\t{\"size_512_1023_packets\",  offsetof(struct vhost_virtqueue, stats.size_bins[5])},\n+\t{\"size_1024_1518_packets\", offsetof(struct vhost_virtqueue, stats.size_bins[6])},\n+\t{\"size_1519_max_packets\",  offsetof(struct vhost_virtqueue, stats.size_bins[7])},\n+};\n+\n+#define VHOST_NB_VQ_STATS RTE_DIM(vhost_vq_stat_strings)\n+\n /* Called with iotlb_lock read-locked */\n uint64_t\n __vhost_iova_to_vva(struct virtio_net *dev, struct vhost_virtqueue *vq,\n@@ -758,7 +780,7 @@ vhost_set_ifname(int vid, const char *if_name, unsigned int if_len)\n }\n \n void\n-vhost_setup_virtio_net(int vid, bool enable, bool compliant_ol_flags)\n+vhost_setup_virtio_net(int vid, bool enable, bool compliant_ol_flags, bool stats_enabled)\n {\n \tstruct virtio_net *dev = get_device(vid);\n \n@@ -773,6 +795,10 @@ vhost_setup_virtio_net(int vid, bool enable, bool compliant_ol_flags)\n \t\tdev->flags |= VIRTIO_DEV_LEGACY_OL_FLAGS;\n \telse\n \t\tdev->flags &= ~VIRTIO_DEV_LEGACY_OL_FLAGS;\n+\tif (stats_enabled)\n+\t\tdev->flags |= VIRTIO_DEV_STATS_ENABLED;\n+\telse\n+\t\tdev->flags &= ~VIRTIO_DEV_STATS_ENABLED;\n }\n \n void\n@@ -1908,5 +1934,86 @@ rte_vhost_get_monitor_addr(int vid, uint16_t queue_id,\n \treturn 0;\n }\n \n+\n+int\n+rte_vhost_vring_stats_get_names(int vid, uint16_t queue_id,\n+\t\tstruct rte_vhost_stat_name *name, unsigned int size)\n+{\n+\tstruct virtio_net *dev = get_device(vid);\n+\tunsigned int i;\n+\n+\tif (dev == NULL)\n+\t\treturn -1;\n+\n+\tif (queue_id >= dev->nr_vring)\n+\t\treturn -1;\n+\n+\tif (!(dev->flags & VIRTIO_DEV_STATS_ENABLED))\n+\t\treturn -1;\n+\n+\tif (name == NULL || size < VHOST_NB_VQ_STATS)\n+\t\treturn VHOST_NB_VQ_STATS;\n+\n+\tfor (i = 0; i < VHOST_NB_VQ_STATS; i++)\n+\t\tsnprintf(name[i].name, sizeof(name[i].name), \"%s_q%u_%s\",\n+\t\t\t\t(queue_id & 1) ? \"rx\" : \"tx\",\n+\t\t\t\tqueue_id / 2, vhost_vq_stat_strings[i].name);\n+\n+\treturn VHOST_NB_VQ_STATS;\n+}\n+\n+int\n+rte_vhost_vring_stats_get(int vid, uint16_t queue_id,\n+\t\tstruct rte_vhost_stat *stats, unsigned int n)\n+{\n+\tstruct virtio_net *dev = get_device(vid);\n+\tstruct vhost_virtqueue *vq;\n+\tunsigned int i;\n+\n+\tif (dev == NULL)\n+\t\treturn -1;\n+\n+\tif (queue_id >= dev->nr_vring)\n+\t\treturn -1;\n+\n+\tif (!(dev->flags & VIRTIO_DEV_STATS_ENABLED))\n+\t\treturn -1;\n+\n+\tif (stats == NULL || n < VHOST_NB_VQ_STATS)\n+\t\treturn VHOST_NB_VQ_STATS;\n+\n+\tvq = dev->virtqueue[queue_id];\n+\n+\trte_spinlock_lock(&vq->access_lock);\n+\tfor (i = 0; i < VHOST_NB_VQ_STATS; i++) {\n+\t\tstats[i].value =\n+\t\t\t*(uint64_t *)(((char *)vq) + vhost_vq_stat_strings[i].offset);\n+\t\tstats[i].id = i;\n+\t}\n+\trte_spinlock_unlock(&vq->access_lock);\n+\n+\treturn VHOST_NB_VQ_STATS;\n+}\n+\n+int rte_vhost_vring_stats_reset(int vid, uint16_t queue_id)\n+{\n+\tstruct virtio_net *dev = get_device(vid);\n+\tstruct vhost_virtqueue *vq;\n+\n+\tif (dev == NULL)\n+\t\treturn -1;\n+\n+\tif (queue_id >= dev->nr_vring)\n+\t\treturn -1;\n+\n+\tvq = dev->virtqueue[queue_id];\n+\n+\trte_spinlock_lock(&vq->access_lock);\n+\tmemset(&vq->stats, 0, sizeof(vq->stats));\n+\trte_spinlock_unlock(&vq->access_lock);\n+\n+\treturn 0;\n+}\n+\n RTE_LOG_REGISTER_SUFFIX(vhost_config_log_level, config, INFO);\n RTE_LOG_REGISTER_SUFFIX(vhost_data_log_level, data, WARNING);\ndiff --git a/lib/vhost/vhost.h b/lib/vhost/vhost.h\nindex 7085e0885c..4c151244c7 100644\n--- a/lib/vhost/vhost.h\n+++ b/lib/vhost/vhost.h\n@@ -38,6 +38,8 @@\n #define VIRTIO_DEV_FEATURES_FAILED ((uint32_t)1 << 4)\n /* Used to indicate that the virtio_net tx code should fill TX ol_flags */\n #define VIRTIO_DEV_LEGACY_OL_FLAGS ((uint32_t)1 << 5)\n+/*  Used to indicate the application has requested statistics collection */\n+#define VIRTIO_DEV_STATS_ENABLED ((uint32_t)1 << 6)\n \n /* Backend value set by guest. */\n #define VIRTIO_DEV_STOPPED -1\n@@ -119,6 +121,18 @@ struct vring_used_elem_packed {\n \tuint32_t count;\n };\n \n+/**\n+ * Virtqueue statistics\n+ */\n+struct virtqueue_stats {\n+\tuint64_t packets;\n+\tuint64_t bytes;\n+\tuint64_t multicast;\n+\tuint64_t broadcast;\n+\t/* Size bins in array as RFC 2819, undersized [0], 64 [1], etc */\n+\tuint64_t size_bins[8];\n+};\n+\n /**\n  * inflight async packet information\n  */\n@@ -235,6 +249,7 @@ struct vhost_virtqueue {\n #define VIRTIO_UNINITIALIZED_NOTIF\t(-1)\n \n \tstruct vhost_vring_addr ring_addrs;\n+\tstruct virtqueue_stats\tstats;\n } __rte_cache_aligned;\n \n /* Virtio device status as per Virtio specification */\n@@ -696,7 +711,7 @@ int alloc_vring_queue(struct virtio_net *dev, uint32_t vring_idx);\n void vhost_attach_vdpa_device(int vid, struct rte_vdpa_device *dev);\n \n void vhost_set_ifname(int, const char *if_name, unsigned int if_len);\n-void vhost_setup_virtio_net(int vid, bool enable, bool legacy_ol_flags);\n+void vhost_setup_virtio_net(int vid, bool enable, bool legacy_ol_flags, bool stats_enabled);\n void vhost_enable_extbuf(int vid);\n void vhost_enable_linearbuf(int vid);\n int vhost_enable_guest_notification(struct virtio_net *dev,\n@@ -873,5 +888,4 @@ mbuf_is_consumed(struct rte_mbuf *m)\n \n \treturn true;\n }\n-\n #endif /* _VHOST_NET_CDEV_H_ */\ndiff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c\nindex f19713137c..550b239450 100644\n--- a/lib/vhost/virtio_net.c\n+++ b/lib/vhost/virtio_net.c\n@@ -43,6 +43,54 @@ is_valid_virt_queue_idx(uint32_t idx, int is_tx, uint32_t nr_vring)\n \treturn (is_tx ^ (idx & 1)) == 0 && idx < nr_vring;\n }\n \n+/*\n+ * This function must be called with virtqueue's access_lock taken.\n+ */\n+static inline void\n+vhost_queue_stats_update(struct virtio_net *dev, struct vhost_virtqueue *vq,\n+\t\tstruct rte_mbuf **pkts, uint16_t count)\n+{\n+\tstruct virtqueue_stats *stats = &vq->stats;\n+\tint i;\n+\n+\tif (!(dev->flags & VIRTIO_DEV_STATS_ENABLED))\n+\t\treturn;\n+\n+\tfor (i = 0; i < count; i++) {\n+\t\tstruct rte_ether_addr *ea;\n+\t\tstruct rte_mbuf *pkt = pkts[i];\n+\t\tuint32_t pkt_len = rte_pktmbuf_pkt_len(pkt);\n+\n+\t\tstats->packets++;\n+\t\tstats->bytes += pkt_len;\n+\n+\t\tif (pkt_len == 64) {\n+\t\t\tstats->size_bins[1]++;\n+\t\t} else if (pkt_len > 64 && pkt_len < 1024) {\n+\t\t\tuint32_t bin;\n+\n+\t\t\t/* count zeros, and offset into correct bin */\n+\t\t\tbin = (sizeof(pkt_len) * 8) - __builtin_clz(pkt_len) - 5;\n+\t\t\tstats->size_bins[bin]++;\n+\t\t} else {\n+\t\t\tif (pkt_len < 64)\n+\t\t\t\tstats->size_bins[0]++;\n+\t\t\telse if (pkt_len < 1519)\n+\t\t\t\tstats->size_bins[6]++;\n+\t\t\telse\n+\t\t\t\tstats->size_bins[7]++;\n+\t\t}\n+\n+\t\tea = rte_pktmbuf_mtod(pkt, struct rte_ether_addr *);\n+\t\tif (rte_is_multicast_ether_addr(ea)) {\n+\t\t\tif (rte_is_broadcast_ether_addr(ea))\n+\t\t\t\tstats->broadcast++;\n+\t\t\telse\n+\t\t\t\tstats->multicast++;\n+\t\t}\n+\t}\n+}\n+\n static inline void\n do_data_copy_enqueue(struct virtio_net *dev, struct vhost_virtqueue *vq)\n {\n@@ -1375,6 +1423,8 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,\n \telse\n \t\tnb_tx = virtio_dev_rx_split(dev, vq, pkts, count);\n \n+\tvhost_queue_stats_update(dev, vq, pkts, nb_tx);\n+\n out:\n \tif (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))\n \t\tvhost_user_iotlb_rd_unlock(vq);\n@@ -2941,6 +2991,7 @@ rte_vhost_dequeue_burst(int vid, uint16_t queue_id,\n \t\t * learning table will get updated first.\n \t\t */\n \t\tpkts[0] = rarp_mbuf;\n+\t\tvhost_queue_stats_update(dev, vq, pkts, 1);\n \t\tpkts++;\n \t\tcount -= 1;\n \t}\n@@ -2957,6 +3008,8 @@ rte_vhost_dequeue_burst(int vid, uint16_t queue_id,\n \t\t\tcount = virtio_dev_tx_split_compliant(dev, vq, mbuf_pool, pkts, count);\n \t}\n \n+\tvhost_queue_stats_update(dev, vq, pkts, count);\n+\n out:\n \tif (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))\n \t\tvhost_user_iotlb_rd_unlock(vq);\n",
    "prefixes": [
        "2/5"
    ]
}