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 A3137A0547; Thu, 9 Sep 2021 13:18:32 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 404BF4013F; Thu, 9 Sep 2021 13:18:32 +0200 (CEST) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mails.dpdk.org (Postfix) with ESMTP id 5B47740041 for ; Thu, 9 Sep 2021 13:18:30 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6200,9189,10101"; a="281774714" X-IronPort-AV: E=Sophos;i="5.85,280,1624345200"; d="scan'208";a="281774714" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Sep 2021 04:18:29 -0700 X-IronPort-AV: E=Sophos;i="5.85,280,1624345200"; d="scan'208";a="694075488" Received: from bricha3-mobl.ger.corp.intel.com ([10.252.3.161]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-SHA; 09 Sep 2021 04:18:25 -0700 Date: Thu, 9 Sep 2021 12:18:22 +0100 From: Bruce Richardson To: Thomas Monjalon Cc: Chengwen Feng , ferruh.yigit@intel.com, jerinj@marvell.com, jerinjacobk@gmail.com, andrew.rybchenko@oktetlabs.ru, dev@dpdk.org, mb@smartsharesystems.com, nipun.gupta@nxp.com, hemant.agrawal@nxp.com, maxime.coquelin@redhat.com, honnappa.nagarahalli@arm.com, david.marchand@redhat.com, sburla@marvell.com, pkapoor@marvell.com, konstantin.ananyev@intel.com, conor.walsh@intel.com, kevin.laatz@intel.com Message-ID: References: <1625231891-2963-1-git-send-email-fengchengwen@huawei.com> <20210907125649.49794-1-fengchengwen@huawei.com> <20210907125649.49794-2-fengchengwen@huawei.com> <1855788.BnNMhiXu0z@thomas> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1855788.BnNMhiXu0z@thomas> Subject: Re: [dpdk-dev] [PATCH v21 1/7] dmadev: introduce DMA device library public APIs 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 Sender: "dev" On Thu, Sep 09, 2021 at 12:33:00PM +0200, Thomas Monjalon wrote: > Hi, > > I am having a surface look at the API. > I hope we can do better than previous libs. > A few bits of feedback on your comments and the API below. /Bruce > 07/09/2021 14:56, Chengwen Feng: > > --- a/MAINTAINERS > > +++ b/MAINTAINERS > > @@ -496,6 +496,10 @@ F: drivers/raw/skeleton/ > > F: app/test/test_rawdev.c > > F: doc/guides/prog_guide/rawdev.rst > > > > +DMA device API - EXPERIMENTAL > > +M: Chengwen Feng > > +F: lib/dmadev/ > > > I think it should before (preferably) or after eventdev, > but let's keep rawdev as the last one. > > Then please apply the same order in other non-alphabetical lists (doc, meson, etc). > > > +/* SPDX-License-Identifier: BSD-3-Clause > > + * Copyright(c) 2021 HiSilicon Limited. > > + * Copyright(c) 2021 Intel Corporation. > > + * Copyright(c) 2021 Marvell International Ltd. > > + * Copyright(c) 2021 SmartShare Systems. > > + */ > > No need for final dot in copyright lines. > > > +#ifndef _RTE_DMADEV_H_ > > +#define _RTE_DMADEV_H_ > > No need for surrounding underscores. > > > + > > +/** > > + * @file rte_dmadev.h > > + * > > + * RTE DMA (Direct Memory Access) device APIs. > > RTE has no meaning when used in a sentence. > And given it is a DPDK library, you don't really need to specify. > I would also remove the final "s" as the library is one interface. > > > + * > > + * The DMA framework is built on the following model: > > + * > > + * --------------- --------------- --------------- > > + * | virtual DMA | | virtual DMA | | virtual DMA | > > + * | channel | | channel | | channel | > > + * --------------- --------------- --------------- > > + * | | | > > + * ------------------ | > > + * | | > > + * ------------ ------------ > > + * | dmadev | | dmadev | > > + * ------------ ------------ > > + * | | > > + * ------------------ ------------------ > > + * | HW-DMA-channel | | HW-DMA-channel | > > + * ------------------ ------------------ > > + * | | > > + * -------------------------------- > > + * | > > + * --------------------- > > + * | HW-DMA-Controller | > > + * --------------------- > > You don't hyphens between the words I think. > > > + * > > + * The DMA controller could have multiple HW-DMA-channels (aka. HW-DMA-queues), > > + * each HW-DMA-channel should be represented by a dmadev. > > + * > > + * The dmadev could create multiple virtual DMA channels, each virtual DMA > > + * channel represents a different transfer context. The DMA operation request > > + * must be submitted to the virtual DMA channel. e.g. Application could create > > + * virtual DMA channel 0 for memory-to-memory transfer scenario, and create > > + * virtual DMA channel 1 for memory-to-device transfer scenario. > > What is the benefit of virtual channels compared to have separate dmadevs > for the same HW channel? > > > + * > > + * The dmadev are dynamically allocated by rte_dmadev_pmd_allocate() during the > > + * PCI/SoC device probing phase performed at EAL initialization time. And could > > Not clear what is this phase. Do you mean bus probing? > > > + * be released by rte_dmadev_pmd_release() during the PCI/SoC device removing > > + * phase. > > Again what is this phase? > I think freeing should be done only via the "close" function. > > > + * > > + * This framework uses 'uint16_t dev_id' as the device identifier of a dmadev, > > + * and 'uint16_t vchan' as the virtual DMA channel identifier in one dmadev. > > I think it is better to use signed int16_t so you can express "none" in the API, > which can simplify some functions and error management. > > > + * > > + * The functions exported by the dmadev API to setup a device designated by its > > + * device identifier must be invoked in the following order: > > + * - rte_dmadev_configure() > > + * - rte_dmadev_vchan_setup() > > + * - rte_dmadev_start() > > + * > > + * Then, the application can invoke dataplane APIs to process jobs. > > You mean "dataplane functions". > > > + * > > + * If the application wants to change the configuration (i.e. invoke > > + * rte_dmadev_configure() or rte_dmadev_vchan_setup()), it must invoke > > + * rte_dmadev_stop() first to stop the device and then do the reconfiguration > > + * before invoking rte_dmadev_start() again. The dataplane APIs should not be > > again, APIs -> functions > > > + * invoked when the device is stopped. > > + * > > + * Finally, an application can close a dmadev by invoking the > > + * rte_dmadev_close() function. > > + * > > + * The dataplane APIs include two parts: > > + * The first part is the submission of operation requests: > > + * - rte_dmadev_copy() > > + * - rte_dmadev_copy_sg() > > + * - rte_dmadev_fill() > > + * - rte_dmadev_submit() > > + * > > + * These APIs could work with different virtual DMA channels which have > > + * different contexts. > > + * > > + * The first three APIs are used to submit the operation request to the virtual > > + * DMA channel, if the submission is successful, an uint16_t ring_idx is > > + * returned, otherwise a negative number is returned. > > unsigned or negative? looks weird. > May be, but it works well. We could perhaps rephase to make it less weird though: "if the submission is successful, a positive ring_idx <= UINT16_MAX is returned, otherwise a negative number is returned." > > + * > > + * The last API was used to issue doorbell to hardware, and also there are flags > > + * (@see RTE_DMA_OP_FLAG_SUBMIT) parameter of the first three APIs could do the > > + * same work. > > I don't understand this sentence. > You mean rte_dmadev_submit function? > Why past tense "was"? > Why having a redundant function? > Just because there are two ways to do something does not mean that one of them is redundant, as both may be more suitable for different situations. When enqueuing a set of jobs to the device, having a separate submit outside a loop makes for clearer code than having a check for the last iteration inside the loop to set a special submit flag. However, for cases where one item alone is to be submitted or there is a small set of jobs to be submitted sequentially, having a submit flag provides a lower-overhead way of doing the submission while still keeping the code clean. > > + * > > + * The second part is to obtain the result of requests: > > + * - rte_dmadev_completed() > > + * - return the number of operation requests completed successfully. > > + * - rte_dmadev_completed_status() > > + * - return the number of operation requests completed. > > + * > > + * @note The two completed APIs also support return the last completed > > + * operation's ring_idx. > > Not sure why this note here. > > > + * @note If the dmadev works in silent mode (@see RTE_DMADEV_CAPA_SILENT), > > + * application does not invoke the above two completed APIs. > > + * > > + * About the ring_idx which enqueue APIs (e.g. rte_dmadev_copy() > > + * rte_dmadev_fill()) returned, the rules are as follows: > > I feel a word is missing above. > > > + * - ring_idx for each virtual DMA channel are independent. > > + * - For a virtual DMA channel, the ring_idx is monotonically incremented, > > + * when it reach UINT16_MAX, it wraps back to zero. > > + * - This ring_idx can be used by applications to track per-operation > > + * metadata in an application-defined circular ring. > > + * - The initial ring_idx of a virtual DMA channel is zero, after the > > + * device is stopped, the ring_idx needs to be reset to zero. > > + * > > + * One example: > > + * - step-1: start one dmadev > > + * - step-2: enqueue a copy operation, the ring_idx return is 0 > > + * - step-3: enqueue a copy operation again, the ring_idx return is 1 > > + * - ... > > + * - step-101: stop the dmadev > > + * - step-102: start the dmadev > > + * - step-103: enqueue a copy operation, the ring_idx return is 0 > > + * - ... > > + * - step-x+0: enqueue a fill operation, the ring_idx return is 65535 > > + * - step-x+1: enqueue a copy operation, the ring_idx return is 0 > > + * - ... > > + * > > + * The DMA operation address used in enqueue APIs (i.e. rte_dmadev_copy(), > > + * rte_dmadev_copy_sg(), rte_dmadev_fill()) defined as rte_iova_t type. The > > "is" defined > > > + * dmadev supports two types of address: memory address and device address. > > Please try to start new sentences on a new line. > > > + * > > + * - memory address: the source and destination address of the memory-to-memory > > + * transfer type, or the source address of the memory-to-device transfer type, > > + * or the destination address of the device-to-memory transfer type. > > + * @note If the device support SVA (@see RTE_DMADEV_CAPA_SVA), the memory > > + * address can be any VA address, otherwise it must be an IOVA address. > > + * > > + * - device address: the source and destination address of the device-to-device > > + * transfer type, or the source address of the device-to-memory transfer type, > > + * or the destination address of the memory-to-device transfer type. > > + * > > + * By default, all the functions of the dmadev API exported by a PMD are > > What do you mean "by default"? Is there some exceptions? > > > + * lock-free functions which assume to not be invoked in parallel on different > > + * logical cores to work on the same target dmadev object. > > + * @note Different virtual DMA channels on the same dmadev *DO NOT* support > > + * parallel invocation because these virtual DMA channels share the same > > + * HW-DMA-channel. > > + * > > + */ > [...] > > +#define RTE_DMADEV_NAME_MAX_LEN RTE_DEV_NAME_MAX_LEN > > Why not using RTE_DEV_NAME_MAX_LEN directly? > If you keep it, it should be commented, explaining whether it takes '\0' > into account or not. > > > +__rte_experimental > > +bool > > +rte_dmadev_is_valid_dev(uint16_t dev_id); > > I would suggest dropping the final "_dev" in the function name. > The alternative, which I would support, is replacing "rte_dmadev" with "rte_dma" across the API. This would then become "rte_dma_is_valid_dev" which is clearer, since the dev is not part of the standard prefix. It also would fit in with a possible future function of "rte_dma_is_valid_vchan" for instance. > > > +uint16_t > > +rte_dmadev_count(void); > > It would be safer to name it rte_dmadev_count_avail > in case we need new kind of device count later. > If we change "dmadev" to "dma" this could then be "rte_dma_count_avail_dev". > > + > > +/* Enumerates DMA device capabilities. */ > > You should group them with a doxygen group syntax. > See https://patches.dpdk.org/project/dpdk/patch/20210830104232.598703-1-thomas@monjalon.net/ > > > +#define RTE_DMADEV_CAPA_MEM_TO_MEM (1ull << 0) > > Please use RTE_BIT macro (32 or 64). > > > +/**< DMA device support memory-to-memory transfer. > > + * > > + * @see struct rte_dmadev_info::dev_capa > > + */ > > It is preferred to have documentation before the item. > > [...] > > > +/** > > + * A structure used to retrieve the information of a DMA device. > > + */ > > +struct rte_dmadev_info { > > + struct rte_device *device; /**< Generic Device information. */ > > Please do not expose this. > > > + uint64_t dev_capa; /**< Device capabilities (RTE_DMADEV_CAPA_*). */ > > + uint16_t max_vchans; > > + /**< Maximum number of virtual DMA channels supported. */ > > + uint16_t max_desc; > > + /**< Maximum allowed number of virtual DMA channel descriptors. */ > > + uint16_t min_desc; > > + /**< Minimum allowed number of virtual DMA channel descriptors. */ > > + uint16_t max_sges; > > + /**< Maximum number of source or destination scatter-gather entry > > + * supported. > > + * If the device does not support COPY_SG capability, this value can be > > + * zero. > > + * If the device supports COPY_SG capability, then rte_dmadev_copy_sg() > > + * parameter nb_src/nb_dst should not exceed this value. > > + */ > > + uint16_t nb_vchans; /**< Number of virtual DMA channel configured. */ > > What about adding NUMA node? > > /* Local NUMA memory ID. -1 if unknown. */ > int16_t numa_node; > That was omitted as it could be got through the device structure. If device is removed, we need to ensure all fields needed from device, such as numa node, are made available here. > > +}; > > > +int > > +rte_dmadev_info_get(uint16_t dev_id, struct rte_dmadev_info *dev_info); >