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 D1BD3A0093; Thu, 21 Apr 2022 16:09:26 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id ADA3440042; Thu, 21 Apr 2022 16:09:26 +0200 (CEST) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mails.dpdk.org (Postfix) with ESMTP id 9FB4B40040 for ; Thu, 21 Apr 2022 16:09:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1650550165; x=1682086165; h=from:to:subject:date:message-id:references:in-reply-to: content-transfer-encoding:mime-version; bh=lfAj/LT3KvXusUbbiwzAf6mPKHXGjyqu2fPUU9PMqII=; b=FeMBYLYvnLelEgUi9UMWLV2sZbPZLINrsSpQXusADPp54Ity8Fw986MG HCdZD4Q/4+1Sc0N95neLvGsPDVnsLNv+znRXHq4EbtcLS+OoD+Gl1DW1E 3+SjLmZOjW8qQysmiLn9JoZevSXDOTYmr7DgfCnTinsItPdj2PgI0bDJv ba8goQ4DUMSGl0UAiCGg8ZZjTsjSmwfYe4cccC+Z7Cq/XE1BVeDTS2JJY gAzBBguJKZFjP1aDvC/+cXNu/CTTw4OrSFZUNtOZRZu6bKE93t+msThgQ wpYOtilXgOVPHm/VJhgHpXcv5+Np9MWKNptir5KuROi8R25DhFnfw5xR/ Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10324"; a="263826463" X-IronPort-AV: E=Sophos;i="5.90,278,1643702400"; d="scan'208";a="263826463" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Apr 2022 07:09:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,278,1643702400"; d="scan'208";a="648145166" Received: from orsmsx601.amr.corp.intel.com ([10.22.229.14]) by FMSMGA003.fm.intel.com with ESMTP; 21 Apr 2022 07:09:23 -0700 Received: from orsmsx602.amr.corp.intel.com (10.22.229.15) by ORSMSX601.amr.corp.intel.com (10.22.229.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27; Thu, 21 Apr 2022 07:09:23 -0700 Received: from orsedg603.ED.cps.intel.com (10.7.248.4) by orsmsx602.amr.corp.intel.com (10.22.229.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27 via Frontend Transport; Thu, 21 Apr 2022 07:09:23 -0700 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (104.47.66.47) by edgegateway.intel.com (134.134.137.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.27; Thu, 21 Apr 2022 07:09:23 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=G/d3KjFBEn73aK1Xkx7h428Qt9o30QlKck8pM+tl+YZ4bYZuhz2P3VfXQ0vCuadIyYeEN2ITw/buJq95XEHE4izDCEtDLIuzlbBeLu4VQlLTEAg5tnyhDyBdEMR9i2+bwFn6KnCNNrMhdCzZFIezTsonp8ODKKZRQJ9q8OVDdVQAKoQZg26SaYGv5wuyDgvn0F0gInim5JprAC4rNjJJQYFlCPAptds2tGSHn0tS77QIKOpE0IU05N2pNuCgzPSLnGgFkK8TliKRCsIE3PW05ZWm1FQc7HWcWqL9ePeV6UZAkQH/WiyBXUn9288Ffy4QmkQFqMxX3y+DJ4TJmPTR7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=zBsOhcUaBvmct/rq1nwQXKSjnuHDN0Q1pCX2rlqQ/pc=; b=Yu70J5oQdWtfNYtwqm/q8Fe5wma4INA1t0HSg2gAAV4804D27JqHO9jwP7AA0vCFULuMAQNoQXo6ZtRICgX7vHbLyDnIjP8w4QGXhTck8wK3pixdCACdSXeQcjpI0tjj1vKx8CAXzSSmmcNjanBaQSQKzGrAj4be/AXvbe7yKN4bvdlQyPmW0vcVDbVndGpKgnOlNh+HGuJgWwo7ieWUQBxQ0ci7E7z62NAOwpkA52pjsPEFhBdISgsUL0mp3x9EaBWRxED5jLkpqUYpfURuKGNkURNB/S6qzstwEXNqU51E/ZijeFkMxZGyIGbxdB5xUe0oBCp965L6YysaJ6F/SQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from SN6PR11MB3504.namprd11.prod.outlook.com (2603:10b6:805:d0::17) by MW4PR11MB5892.namprd11.prod.outlook.com (2603:10b6:303:16a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.13; Thu, 21 Apr 2022 14:09:22 +0000 Received: from SN6PR11MB3504.namprd11.prod.outlook.com ([fe80::4d1d:6453:f00c:cf8a]) by SN6PR11MB3504.namprd11.prod.outlook.com ([fe80::4d1d:6453:f00c:cf8a%6]) with mapi id 15.20.5164.025; Thu, 21 Apr 2022 14:09:21 +0000 From: "Xia, Chenbo" To: Maxime Coquelin , "dev@dpdk.org" , "david.marchand@redhat.com" Subject: RE: [PATCH 2/5] vhost: add per-virtqueue statistics support Thread-Topic: [PATCH 2/5] vhost: add per-virtqueue statistics support Thread-Index: AQHYE45cBaS0e/t4OkWsNMA21yIEJaz66ATQ Date: Thu, 21 Apr 2022 14:09:21 +0000 Message-ID: References: <20220127145655.558029-1-maxime.coquelin@redhat.com> <20220127145655.558029-3-maxime.coquelin@redhat.com> In-Reply-To: <20220127145655.558029-3-maxime.coquelin@redhat.com> Accept-Language: en-US, zh-CN Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 61954400-11fc-430f-a6cd-08da23a08897 x-ms-traffictypediagnostic: MW4PR11MB5892:EE_ x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: J0qc1nw7w04lg9eYkoklaeKJKVS6tR4kOcK2Yw0mR+Lhqe0zOhFzJ9yve7W6JVRmDLxhA8OYLS7ihkVT5SLd9x7b4ZPWZzvFzSUwDujeX+Ba61rzKo22NwiYmqyaJS2F+2zdDFL8xO/4zUhh5iepEwhdoxN+zolRt7+LlKV2QuLYC4WYoWkfIzeO4ltywKNK2q5vNloSs75HQ79eE3dGscYMaPg7L7mGkdoYqYHl5QHxIvt2zw2iCa2haAcKhpgyfbfFBtXv8JCatkqPbZ7Qw1NhZurbeKkoA9raSYc4DL5VZMdrAsw7eKjr2/HBNsnLlezlqFqdhAme6JVX2hjfPEQZ3mFFkZuvTqS8Ood+lJkLsm3arWhYS4gSr5SYZNgp3h/yeNkcvM33st/xqrjkBtmK/Yb1gmyAgpLotPDZhn4btDzy3ATetU7cYfiBRMT/uOAHTcpT0/0POcQD6jwXk8HaD/78izOKfqfAm2Uhqc9iuGNnViduz1MeLq+fKB2ibyS0SOJyGtyookFF2+Y9IrsHspuSFOE63DZn46POCscqa5OMYvuuqqPQRSHksk9NHHlL/6k7BnkmFP9/dW7W5N2GTKMYjiX2IEnZWNKiykYFPZmnJsxeuZ09HJhLNj91TUyNhf7NE412sQk2QOgryzcBe6VSleO3Whe0QwFAiRbquqk3kqtttSJ8aKxrK/47w0/gEn1bDkOdlD+kTgkrPZqpEMaJLEQ4AmLTDjzqHnUdFtjaRPfRYygSxO9Lug6MrIXGF0ibQRDx4f0baTz33ATCA0+Ltsj2GpXB9T4gO2Q= x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SN6PR11MB3504.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(71200400001)(9686003)(26005)(5660300002)(6506007)(508600001)(52536014)(8936002)(966005)(186003)(53546011)(7696005)(55016003)(83380400001)(38070700005)(33656002)(66946007)(66446008)(66476007)(8676002)(66556008)(316002)(76116006)(38100700002)(2906002)(82960400001)(86362001)(64756008)(110136005)(30864003)(122000001); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?FzWJph3p2ODs6R8GCSRa+dS73ItT3FaE2mL/WGtGAbDGHkW2bxMMikJRFV4W?= =?us-ascii?Q?fOru1w+P9TxZAcdYBcDajhEGsTHha5nfLcS01XYu8g2TvJINLUQYb0BGppsY?= =?us-ascii?Q?PT0ih5AEFq9ip/wyKhnNOAPWGewcDS9TBFW6tO0o9C3jL2dJXBh64d0c/bSg?= =?us-ascii?Q?/3Ny0fIdbv2EmQBiB6u62EyJqu2E5HpOl2NaqRrdL+iZyx6LAP9sDWtew4MP?= =?us-ascii?Q?GJZkwRlBde5HIeUIQVZ2Aii5CDRdhygOcq3HXPZoVlqz7PJmJ2Ml3vlQeWcK?= =?us-ascii?Q?xOAReXmKZSymZ0BCOvbU6FEAPigFiGVc867wpNcaOr7KybEJ438rPsQTncBA?= =?us-ascii?Q?RYQtqshAbN6BLYI4rOg7OWKq5jJFlP7FqSx3cZLFOwVdJOy/AyBxCkxnAe6X?= =?us-ascii?Q?B+PyrPmmpGO7wEE13MyJvLwj3oRY/4oZAxytXD8tyIfYXRD0+6VX/JycUq9u?= =?us-ascii?Q?O7kD5cnvZJl3YI8ITvuGmvlb4n96HiQkn4GwCygH0I/wtt3WIsmlu0bMff95?= =?us-ascii?Q?KSWzMBWeu9bgvb0rXWj7RHpRkTHmB6lL77fUXvih1FBwWer3KiA74x5g33YA?= =?us-ascii?Q?Z3xjwplirgQOP++ThyzJ36DvQERuKsdjFXoQyqqJ0Pcq712Gyaco7dDenNpJ?= =?us-ascii?Q?Dip5pCFjbrcteLoYha7Y0D246qTuecHBpKz/rqd3slytmu3YvFy3iM9M0dC+?= =?us-ascii?Q?NTQaXQznyE/k2SsGA3ztmxM6MPaVL8yMXZy9rnuelM3AxYPCaN0OZyyNYcSy?= =?us-ascii?Q?uOxLYsGei7qr0KorzeQIc8JqUmMOS476CG4FJrWexFsIQu64U/zhOSLcjNgK?= =?us-ascii?Q?ebW5CXw/4wr9+w49IqcAjC5vTftTBBFTXpVRYlhb0EAY59CmAFuTFgMMCGVz?= =?us-ascii?Q?j0D1cgSsbRHGNF0ZwAo62sWNpstwwV58hTp7R5wiRAx70P1M4uCwrJPph8ru?= =?us-ascii?Q?a6TQcWQgKu2Aa1r4i3So/7JQk5V6Usrg3Qo5bcVPhjbOZNmapxtwZMmzQQgb?= =?us-ascii?Q?OluNq+CEceujS3umqG32CJuq0Z7SY9nAP5AqYjWTDUSL8313bd1h5MIv6Tuu?= =?us-ascii?Q?M1RtTPEPowBii43yQhAHKau85Msxe9TkOygiaMGGTJXc0xEunBkfoZ3zU2Rw?= =?us-ascii?Q?tllbb8Sf276k6qLqRRE+vOJE0N4yz/taHxGPmNoN83toSaBuDgx2oP3cUhEm?= =?us-ascii?Q?cqYLrjZddUkmFFOxypsRhvu0CcdxjVitCY2qNBuSxoYist86xzOKMCJ+Upjj?= =?us-ascii?Q?I9F0akD7ZjqPvK2ASFld4IQ3zaa4buqsKxufCO08/IAGDj6WgulMEMFzGvMZ?= =?us-ascii?Q?GGvUfaMEfEYMjhZDjoZjiPDSSykzM2QrejciFqSbN0DiupXs2oTIFg5W/fiz?= =?us-ascii?Q?rn9n791KDs9EdakNvxUrTwze6XNnmbHlWpBmmbm4TD6P6rAAz7+5+1SwEAXp?= =?us-ascii?Q?uxjyYv16SwZMOvmU44U0It1s738tM5cLcJbVC6GksKFIXFJU+nfbxtg3sPvl?= =?us-ascii?Q?MY8B7HzzgJUsM9HxbY7AoeB4G0+0mCUU3ut1LMTrJeZe3jP5HQcFz6N043/c?= =?us-ascii?Q?iLOiVTHSObH1Jt/SV8HWSn4SU3YjOY9SUOKUJ3SmuRIoazQpv1gBPGJRP3B1?= =?us-ascii?Q?HX6SErNsYyTJLzepo/KdV02S33ZbS/RE0v2K3o+Qq492QeFZ64ctt2SzGpET?= =?us-ascii?Q?NE26kssps5CmAsczqyaNM2OyYNPTZ/EtovoJLw7ccFHbLSutuY3NY7R5ybKX?= =?us-ascii?Q?pcvzO9IBGQ=3D=3D?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: SN6PR11MB3504.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 61954400-11fc-430f-a6cd-08da23a08897 X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Apr 2022 14:09:21.8788 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: eaQ6K49UHdggOiU6uct7yEq5eYlMp0EjCqGOYJCVL+KefszwWETK/DCXFDzlJ0edLdPKIkC9SMtL+7WyuRajJw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR11MB5892 X-OriginatorOrg: intel.com 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 Hi Maxime, > -----Original Message----- > From: Maxime Coquelin > Sent: Thursday, January 27, 2022 10:57 PM > To: dev@dpdk.org; Xia, Chenbo ; > david.marchand@redhat.com > Cc: Maxime Coquelin > Subject: [PATCH 2/5] vhost: add per-virtqueue statistics support >=20 > This patch introduces new APIs for the application > to query and reset per-virtqueue statistics. The > patch also introduces generic counters. >=20 > Signed-off-by: Maxime Coquelin > --- > lib/vhost/rte_vhost.h | 89 +++++++++++++++++++++++++++++++++ > lib/vhost/socket.c | 4 +- > lib/vhost/version.map | 5 ++ > lib/vhost/vhost.c | 109 ++++++++++++++++++++++++++++++++++++++++- > lib/vhost/vhost.h | 18 ++++++- > lib/vhost/virtio_net.c | 53 ++++++++++++++++++++ > 6 files changed, 274 insertions(+), 4 deletions(-) >=20 > diff --git a/lib/vhost/rte_vhost.h b/lib/vhost/rte_vhost.h > index b454c05868..e739091ca0 100644 > --- a/lib/vhost/rte_vhost.h > +++ b/lib/vhost/rte_vhost.h > @@ -37,6 +37,7 @@ extern "C" { > #define RTE_VHOST_USER_LINEARBUF_SUPPORT (1ULL << 6) > #define RTE_VHOST_USER_ASYNC_COPY (1ULL << 7) > #define RTE_VHOST_USER_NET_COMPLIANT_OL_FLAGS (1ULL << 8) > +#define RTE_VHOST_USER_NET_STATS_ENABLE (1ULL << 9) >=20 > /* Features. */ > #ifndef VIRTIO_NET_F_GUEST_ANNOUNCE > @@ -317,6 +318,32 @@ struct rte_vhost_power_monitor_cond { > uint8_t match; > }; >=20 > +/** Maximum name length for the statistics counters */ > +#define RTE_VHOST_STATS_NAME_SIZE 64 > + > +/** > + * Vhost virtqueue statistics structure > + * > + * This structure is used by rte_vhost_vring_stats_get() to provide > + * virtqueue statistics to the calling application. > + * It maps a name ID, corresponding to an index in the array returned > + * by rte_vhost_vring_stats_get_names(), to a statistic value. > + */ > +struct rte_vhost_stat { > + uint64_t id; /**< The index in xstats name array. */ > + uint64_t value; /**< The statistic counter value. */ > +}; > + > +/** > + * Vhost virtqueue statistic name element > + * > + * This structure is used by rte_vhost_vring_stats_get_anmes() to Anmes -> names > + * provide virtqueue statistics names to the calling application. > + */ > +struct rte_vhost_stat_name { > + char name[RTE_VHOST_STATS_NAME_SIZE]; /**< The statistic name. */ Should we consider using ethdev one? Since vhost lib already depends on eth= dev lib. > +}; > + > /** > * Convert guest physical address to host virtual address > * > @@ -1059,6 +1086,68 @@ __rte_experimental > int > rte_vhost_slave_config_change(int vid, bool need_reply); >=20 > +/** > + * Retrieve names of statistics of a Vhost virtqueue. > + * > + * There is an assumption that 'stat_names' and 'stats' arrays are > matched > + * by array index: stats_names[i].name =3D> stats[i].value > + * > + * @param vid > + * vhost device ID > + * @param queue_id > + * vhost queue index > + * @param stats_names > + * array of at least size elements to be filled. > + * If set to NULL, the function returns the required number of element= s. > + * @param size > + * The number of elements in stats_names array. > + * @return > + * A negative value on error, otherwise the number of entries filled i= n > the > + * stats name array. > + */ > +__rte_experimental > +int > +rte_vhost_vring_stats_get_names(int vid, uint16_t queue_id, > + struct rte_vhost_stat_name *name, unsigned int size); '@param stats_names' and 'struct rte_vhost_stat_name *name' do not align an= d reports error:=20 http://mails.dpdk.org/archives/test-report/2022-March/270275.html > + > +/** > + * Retrieve statistics of a Vhost virtqueue. > + * > + * There is an assumption that 'stat_names' and 'stats' arrays are > matched > + * by array index: stats_names[i].name =3D> stats[i].value > + * > + * @param vid > + * vhost device ID > + * @param queue_id > + * vhost queue index > + * @param stats > + * A pointer to a table of structure of type rte_vhost_stat to be > filled with > + * virtqueue statistics ids and values. > + * @param n > + * The number of elements in stats array. > + * @return > + * A negative value on error, otherwise the number of entries filled i= n > the > + * stats table. > + */ > +__rte_experimental > +int > +rte_vhost_vring_stats_get(int vid, uint16_t queue_id, > + struct rte_vhost_stat *stats, unsigned int n); > + > +/** > + * Reset statistics of a Vhost virtqueue. > + * > + * @param vid > + * vhost device ID > + * @param queue_id > + * vhost queue index > + * @return > + * 0 on success, a negative value on error. > + */ > +__rte_experimental > +int > +rte_vhost_vring_stats_reset(int vid, uint16_t queue_id); > + > #ifdef __cplusplus > } > #endif > diff --git a/lib/vhost/socket.c b/lib/vhost/socket.c > index c2f8013cd5..6020565fb6 100644 > --- a/lib/vhost/socket.c > +++ b/lib/vhost/socket.c > @@ -43,6 +43,7 @@ struct vhost_user_socket { > bool linearbuf; > bool async_copy; > bool net_compliant_ol_flags; > + bool stats_enabled; >=20 > /* > * The "supported_features" indicates the feature bits the > @@ -228,7 +229,7 @@ vhost_user_add_connection(int fd, struct > vhost_user_socket *vsocket) > vhost_set_ifname(vid, vsocket->path, size); >=20 > vhost_setup_virtio_net(vid, vsocket->use_builtin_virtio_net, > - vsocket->net_compliant_ol_flags); > + vsocket->net_compliant_ol_flags, vsocket->stats_enabled); >=20 > vhost_attach_vdpa_device(vid, vsocket->vdpa_dev); >=20 > @@ -864,6 +865,7 @@ rte_vhost_driver_register(const char *path, uint64_t > flags) > vsocket->linearbuf =3D flags & RTE_VHOST_USER_LINEARBUF_SUPPORT; > vsocket->async_copy =3D flags & RTE_VHOST_USER_ASYNC_COPY; > vsocket->net_compliant_ol_flags =3D flags & > RTE_VHOST_USER_NET_COMPLIANT_OL_FLAGS; > + vsocket->stats_enabled =3D flags & RTE_VHOST_USER_NET_STATS_ENABLE; >=20 > if (vsocket->async_copy && > (flags & (RTE_VHOST_USER_IOMMU_SUPPORT | > diff --git a/lib/vhost/version.map b/lib/vhost/version.map > index a7ef7f1976..b83f79c87f 100644 > --- a/lib/vhost/version.map > +++ b/lib/vhost/version.map > @@ -84,6 +84,11 @@ EXPERIMENTAL { >=20 > # added in 21.11 > rte_vhost_get_monitor_addr; > + > + # added in 22.03 > + rte_vhost_vring_stats_get_names; > + rte_vhost_vring_stats_get; > + rte_vhost_vring_stats_reset; > }; >=20 > INTERNAL { > diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c > index 42c01abf25..0c6a737aca 100644 > --- a/lib/vhost/vhost.c > +++ b/lib/vhost/vhost.c > @@ -28,6 +28,28 @@ > struct virtio_net *vhost_devices[MAX_VHOST_DEVICE]; > pthread_mutex_t vhost_dev_lock =3D PTHREAD_MUTEX_INITIALIZER; >=20 > +struct vhost_vq_stats_name_off { > + char name[RTE_VHOST_STATS_NAME_SIZE]; > + unsigned int offset; > +}; > + > +static const struct vhost_vq_stats_name_off vhost_vq_stat_strings[] =3D = { > + {"good_packets", offsetof(struct vhost_virtqueue, > stats.packets)}, > + {"good_bytes", offsetof(struct vhost_virtqueue, > stats.bytes)}, > + {"multicast_packets", offsetof(struct vhost_virtqueue, > stats.multicast)}, > + {"broadcast_packets", offsetof(struct vhost_virtqueue, > stats.broadcast)}, > + {"undersize_packets", offsetof(struct vhost_virtqueue, > stats.size_bins[0])}, > + {"size_64_packets", offsetof(struct vhost_virtqueue, > stats.size_bins[1])}, > + {"size_65_127_packets", offsetof(struct vhost_virtqueue, > stats.size_bins[2])}, > + {"size_128_255_packets", offsetof(struct vhost_virtqueue, > stats.size_bins[3])}, > + {"size_256_511_packets", offsetof(struct vhost_virtqueue, > stats.size_bins[4])}, > + {"size_512_1023_packets", offsetof(struct vhost_virtqueue, > stats.size_bins[5])}, > + {"size_1024_1518_packets", offsetof(struct vhost_virtqueue, > stats.size_bins[6])}, > + {"size_1519_max_packets", offsetof(struct vhost_virtqueue, > stats.size_bins[7])}, > +}; > + > +#define VHOST_NB_VQ_STATS RTE_DIM(vhost_vq_stat_strings) > + > /* Called with iotlb_lock read-locked */ > uint64_t > __vhost_iova_to_vva(struct virtio_net *dev, struct vhost_virtqueue *vq, > @@ -758,7 +780,7 @@ vhost_set_ifname(int vid, const char *if_name, > unsigned int if_len) > } >=20 > void > -vhost_setup_virtio_net(int vid, bool enable, bool compliant_ol_flags) > +vhost_setup_virtio_net(int vid, bool enable, bool compliant_ol_flags, > bool stats_enabled) > { > struct virtio_net *dev =3D get_device(vid); >=20 > @@ -773,6 +795,10 @@ vhost_setup_virtio_net(int vid, bool enable, bool > compliant_ol_flags) > dev->flags |=3D VIRTIO_DEV_LEGACY_OL_FLAGS; > else > dev->flags &=3D ~VIRTIO_DEV_LEGACY_OL_FLAGS; > + if (stats_enabled) > + dev->flags |=3D VIRTIO_DEV_STATS_ENABLED; > + else > + dev->flags &=3D ~VIRTIO_DEV_STATS_ENABLED; > } >=20 > void > @@ -1908,5 +1934,86 @@ rte_vhost_get_monitor_addr(int vid, uint16_t > queue_id, > return 0; > } >=20 > + > +int > +rte_vhost_vring_stats_get_names(int vid, uint16_t queue_id, > + struct rte_vhost_stat_name *name, unsigned int size) > +{ > + struct virtio_net *dev =3D get_device(vid); > + unsigned int i; > + > + if (dev =3D=3D NULL) > + return -1; > + > + if (queue_id >=3D dev->nr_vring) > + return -1; > + > + if (!(dev->flags & VIRTIO_DEV_STATS_ENABLED)) > + return -1; > + > + if (name =3D=3D NULL || size < VHOST_NB_VQ_STATS) > + return VHOST_NB_VQ_STATS; > + > + for (i =3D 0; i < VHOST_NB_VQ_STATS; i++) > + snprintf(name[i].name, sizeof(name[i].name), "%s_q%u_%s", > + (queue_id & 1) ? "rx" : "tx", > + queue_id / 2, vhost_vq_stat_strings[i].name); > + > + return VHOST_NB_VQ_STATS; > +} > + > +int > +rte_vhost_vring_stats_get(int vid, uint16_t queue_id, > + struct rte_vhost_stat *stats, unsigned int n) > +{ > + struct virtio_net *dev =3D get_device(vid); > + struct vhost_virtqueue *vq; > + unsigned int i; > + > + if (dev =3D=3D NULL) > + return -1; > + > + if (queue_id >=3D dev->nr_vring) > + return -1; > + > + if (!(dev->flags & VIRTIO_DEV_STATS_ENABLED)) > + return -1; > + > + if (stats =3D=3D NULL || n < VHOST_NB_VQ_STATS) > + return VHOST_NB_VQ_STATS; > + > + vq =3D dev->virtqueue[queue_id]; > + > + rte_spinlock_lock(&vq->access_lock); > + for (i =3D 0; i < VHOST_NB_VQ_STATS; i++) { > + stats[i].value =3D > + *(uint64_t *)(((char *)vq) + > vhost_vq_stat_strings[i].offset); > + stats[i].id =3D i; > + } > + rte_spinlock_unlock(&vq->access_lock); > + > + return VHOST_NB_VQ_STATS; > +} > + > +int rte_vhost_vring_stats_reset(int vid, uint16_t queue_id) > +{ > + struct virtio_net *dev =3D get_device(vid); > + struct vhost_virtqueue *vq; > + > + if (dev =3D=3D NULL) > + return -1; > + > + if (queue_id >=3D dev->nr_vring) > + return -1; > + Guess you forgot to check VIRTIO_DEV_STATS_ENABLED? > + vq =3D dev->virtqueue[queue_id]; > + > + rte_spinlock_lock(&vq->access_lock); > + memset(&vq->stats, 0, sizeof(vq->stats)); > + rte_spinlock_unlock(&vq->access_lock); > + > + return 0; > +} > + > RTE_LOG_REGISTER_SUFFIX(vhost_config_log_level, config, INFO); > RTE_LOG_REGISTER_SUFFIX(vhost_data_log_level, data, WARNING); > diff --git a/lib/vhost/vhost.h b/lib/vhost/vhost.h > index 7085e0885c..4c151244c7 100644 > --- a/lib/vhost/vhost.h > +++ b/lib/vhost/vhost.h > @@ -38,6 +38,8 @@ > #define VIRTIO_DEV_FEATURES_FAILED ((uint32_t)1 << 4) > /* Used to indicate that the virtio_net tx code should fill TX ol_flags > */ > #define VIRTIO_DEV_LEGACY_OL_FLAGS ((uint32_t)1 << 5) > +/* Used to indicate the application has requested statistics collection Should be only one space between '/*' and 'Used' :P Thanks, Chenbo