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 162A2A0553; Fri, 10 Jun 2022 16:34:43 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AC8AA4069C; Fri, 10 Jun 2022 16:34:42 +0200 (CEST) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mails.dpdk.org (Postfix) with ESMTP id 9F44240689 for ; Fri, 10 Jun 2022 16:34:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1654871680; x=1686407680; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=Jz0wEa5ke3txeu+p9Jtdl1ZsJSjq3YA3Z1THQs5gbGo=; b=k3a2Yi8b+ePL04SuPLlaYA0jKU4aytBRiQRPSaTOTcQcllSY605WKRkK N6/roCeovcfurnw1bbCtTvoAWQud/cWdKODVCe+j1tCICgImONNcITS7w 7hDuymn31oz957l+/tt/LWC30Sxt64zsMhbwr7iDg/HkvwkHDoP/Xo6LY OmV+eWJ80Zmn0V0xuQGrPr0dL0DHfrDJgbw4pfG1t0uNMfsfqNENy8dxh MDMmZwAbsZsFdVWo+qWYqCq3MEYF5pW7nvTxiJWlrtnCnA7SDHfR1QfH8 x/ZkjOzr8D3cbjcVm0Y6BkNYSRKQ9cvHyjDwNrigZSo23lJKXWDla+r5H w==; X-IronPort-AV: E=McAfee;i="6400,9594,10373"; a="278445574" X-IronPort-AV: E=Sophos;i="5.91,290,1647327600"; d="scan'208";a="278445574" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2022 07:33:22 -0700 X-IronPort-AV: E=Sophos;i="5.91,290,1647327600"; d="scan'208";a="638163628" Received: from bricha3-mobl.ger.corp.intel.com ([10.55.133.106]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-SHA; 10 Jun 2022 07:33:21 -0700 Date: Fri, 10 Jun 2022 15:33:18 +0100 From: Bruce Richardson To: "Xia, Chenbo" Cc: "dev@dpdk.org" , Maxime Coquelin Subject: Re: [PATCH v2 2/2] doc/howto: add code example to virtio-user exception path doc Message-ID: References: <20220527162659.129022-1-bruce.richardson@intel.com> <20220527163643.130679-1-bruce.richardson@intel.com> <20220527163643.130679-2-bruce.richardson@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 On Mon, May 30, 2022 at 06:44:27AM +0100, Xia, Chenbo wrote: > > -----Original Message----- > > From: Richardson, Bruce > > Sent: Saturday, May 28, 2022 12:37 AM > > To: dev@dpdk.org > > Cc: Maxime Coquelin ; Xia, Chenbo > > ; Richardson, Bruce > > Subject: [PATCH v2 2/2] doc/howto: add code example to virtio-user > > exception path doc > > > > The HOWTO guide for using virtio-user as an exception path to the kernel > > only provided an example of how testpmd may be used for that purpose. > > However, a real application wanting to use virtio-user as exception path > > would likely want to create such devices from code within the app > > itself. Therefore, we update the doc with instructions and a code > > snippet showing how this may be done. > > > > Signed-off-by: Bruce Richardson > > > > --- > > > > v2: fix http link to https > > --- > > .../howto/virtio_user_as_exceptional_path.rst | 55 +++++++++++++++++++ > > 1 file changed, 55 insertions(+) > > > > diff --git a/doc/guides/howto/virtio_user_as_exceptional_path.rst > > b/doc/guides/howto/virtio_user_as_exceptional_path.rst > > index 100376c32d..45d4ebd284 100644 > > --- a/doc/guides/howto/virtio_user_as_exceptional_path.rst > > +++ b/doc/guides/howto/virtio_user_as_exceptional_path.rst > > @@ -157,3 +157,58 @@ For example: > > /path/to/dpdk-testpmd --vdev=virtio_user0,path=/dev/vhost- > > net,queues=2,queue_size=1024 -- \ > > -i --tx-offloads=0x002c --enable-lro --txq=2 --rxq=2 -- > > txd=1024 --rxd=1024 > > > > + > > +Creating Virtio-User Ports within an Application > > +------------------------------------------------ > > + > > +To use virtio-user ports within an application, > > +it is not necessary to explicitly initialize those ports using EAL > > arguments at startup. > > +Instead, one can use the generic EAL API > > +`rte_eal_hotplug_add > > > bb>`_ > > +function to create a new instance at startup. > > +For example, to create a basic virtio-user port, the following code could > > be used: > > + > > +.. code-block:: C > > + > > + rte_eal_hotplug_add("vdev", "virtio_user0", "path=/dev/vhost-net"); > > + > > +A fuller code example is shown below, where a virtio-user port, and hence > > kernel netdev, > > +is created for each NIC port discovered by DPDK. > > +Each virtio-user port is given the MAC address of its matching physical > > port > > +(assuming app was run without vdev args on commandline, so all ports > > auto-discovered are HW ones). > > +These new virtio-user netdevs will appear in the kernel port listings as > > ``virtio_user0``, > > You mean vhost_tap netdev here? Or? > Yes, I am referring to the vhost tap port. If you look at the code below, the parameters provide the name of the kernel netdev to be the same as the name of the vdev created, meaning any ports will appear as "vhost_user0", "vhost_user1" etc. in your ip-link/ifconfig listings. /Bruce > > > +``virtio_user1``, etc., > > +based on the names passed in as ``iface=`` via the ``portargs`` parameter. > > + > > +.. code-block:: C > > + > > + nb_ports = rte_eth_dev_count_avail(); > > + > > + /* Create a vhost_user port for each physical port */ > > + unsigned port_count = 0; > > + RTE_ETH_FOREACH_DEV(portid) { > > + char portname[32]; > > + char portargs[256]; > > + struct rte_ether_addr addr = {0}; > > + > > + /* don't create virtio_user ports for other virtio_user ports */ > > + if (++port_count > nb_ports) > > + break; > > + > > + /* get mac address of physical port to use as mac of virtio_user > > port */ > > + rte_eth_macaddr_get(portid, &addr); > > + > > + /* set the name and arguments */ > > + snprintf(portname, sizeof(portname), "virtio_user%u", portid); > > + snprintf(portargs, sizeof(portargs), > > + "path=/dev/vhost- > > net,queues=1,queue_size=%u,iface=%s,mac=" RTE_ETHER_ADDR_PRT_FMT, > > + RX_RING_SIZE, portname, RTE_ETHER_ADDR_BYTES(&addr)); > > + > > + /* add the vdev for virtio_user */ > > + if (rte_eal_hotplug_add("vdev", portname, portargs) < 0) > > + rte_exit(EXIT_FAILURE, "Cannot create paired port for > > port %u\n", portid); > > + > > + } > > + > > +Once these virtio-user ports have been created in the loop, all ports, > > both physical and virtual, > > +may be initialized and used as normal in the application. > > -- > > 2.34.1 >