From patchwork Fri Jul 30 13:55:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Monjalon X-Patchwork-Id: 96463 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: 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]) by inbox.dpdk.org (Postfix) with ESMTP id EA94AA0A0C; Fri, 30 Jul 2021 15:56:16 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B19C54067A; Fri, 30 Jul 2021 15:56:14 +0200 (CEST) Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by mails.dpdk.org (Postfix) with ESMTP id 69ABA410FB for ; Fri, 30 Jul 2021 15:56:13 +0200 (CEST) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 203FA5C00C9; Fri, 30 Jul 2021 09:56:13 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Fri, 30 Jul 2021 09:56:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=hPce/qfuIG4LU gLU2qhBPlHU0uGEJzBN53FnbAns2ns=; b=wJelnuyNyVb0bW5/AYkPIjxlZzi6h nFmix5UIK3h9eJOj2/BflxfexMv2zEGmClpLDVBj3LC/WmR/7H+LxIm3b7Iqu4nb uHEvoil62qhY5f3nsQlblMmF+sICCGjeBRDREKVBS1AwfqMVsxoRUXey3bWKnSuH pp+p8cXohoBCDtZPEzZ9EiokIBTmGH/PIEXkZVrUJAl0mmNyDWcnq+2iLtoDXyxS JXFduFLbL3Dmm5WBihEUGgpl7In8LUaAzTV09tVlguDsLkeIWWuuiTKAwLvfUkt0 p2kcUuTfiDOx5Yrl9rAMJ75+KPvMtQLRzarQrugYCOh9kctPCMwQ722Fg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=hPce/qfuIG4LUgLU2qhBPlHU0uGEJzBN53FnbAns2ns=; b=SL0rJ4N5 D0BcbRMVeYndb+Juu8inNEAN0s+GoDBawqDr+pu6asiQ2M5SZm4LIrTHcgDYMx/e /R2ERY50chaEma8/96k1qGU7RVsyX70sP0DW7dSpVl863KYekkgKZn1Dj9PTffY7 1G2XD6S4ubornVyc9NHhEcizmKsilr0keGwAuKHH8dhEu1WXxtHjidNR0D4k9iR7 Jr14pB2eSwHZbB5s+7rYVB+iiE3t0TDUJ3G1qf705SCigJsAIRQ9ofTTF/Rrtpzt aFahECVeCvTtJVPaoomNlCu0vCY1m1dXYn+yfYwZi+wacRcaBYS7wf49n7H7Ktu9 2zYqz/c1n5cyog== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrheehgdeiiecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomhepvfhhohhmrghs ucfoohhnjhgrlhhonhcuoehthhhomhgrshesmhhonhhjrghlohhnrdhnvghtqeenucggtf frrghtthgvrhhnpedvhefgiedvjeegtdevheefhfetleefgfeivefgffevfeejgedtgfeu tdehtdegveenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpehthhhomhgrshesmhhonhhjrghlohhnrdhnvght X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 30 Jul 2021 09:56:11 -0400 (EDT) From: Thomas Monjalon To: dev@dpdk.org Cc: Stephen Hemminger , David Marchand , Andrew Rybchenko , Haiyue Wang , Honnappa Nagarahalli , Jerin Jacob , Ferruh Yigit , Elena Agostini , Ray Kinsella Date: Fri, 30 Jul 2021 15:55:29 +0200 Message-Id: <20210730135533.417611-4-thomas@monjalon.net> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210730135533.417611-1-thomas@monjalon.net> References: <20210602203531.2288645-1-thomas@monjalon.net> <20210730135533.417611-1-thomas@monjalon.net> MIME-Version: 1.0 Subject: [dpdk-dev] [RFC PATCH v2 3/7] hcdev: add child device representing a device context 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" The computing device may operate in some isolated contexts. Memory and processing are isolated in a silo represented by a child device. The context is provided as an opaque by the caller of rte_hcdev_add_child(). Signed-off-by: Thomas Monjalon --- lib/hcdev/hcdev.c | 45 ++++++++++++++++++++++++-- lib/hcdev/hcdev_driver.h | 2 +- lib/hcdev/rte_hcdev.h | 69 +++++++++++++++++++++++++++++++++++++--- lib/hcdev/version.map | 1 + 4 files changed, 110 insertions(+), 7 deletions(-) diff --git a/lib/hcdev/hcdev.c b/lib/hcdev/hcdev.c index 2a7ce1ccd8..d40010749a 100644 --- a/lib/hcdev/hcdev.c +++ b/lib/hcdev/hcdev.c @@ -79,13 +79,22 @@ rte_hcdev_is_valid(int16_t dev_id) return false; } +static bool +hcdev_match_parent(int16_t dev_id, int16_t parent) +{ + if (parent == RTE_HCDEV_ID_ANY) + return true; + return hcdevs[dev_id].info.parent == parent; +} + int16_t -rte_hcdev_find_next(int16_t dev_id) +rte_hcdev_find_next(int16_t dev_id, int16_t parent) { if (dev_id < 0) dev_id = 0; while (dev_id < hcdev_max && - hcdevs[dev_id].state == RTE_HCDEV_STATE_UNUSED) + (hcdevs[dev_id].state == RTE_HCDEV_STATE_UNUSED || + !hcdev_match_parent(dev_id, parent))) dev_id++; if (dev_id >= hcdev_max) @@ -176,6 +185,7 @@ rte_hcdev_allocate(const char *name) dev->info.name = dev->name; dev->info.dev_id = dev_id; dev->info.numa_node = -1; + dev->info.parent = RTE_HCDEV_ID_NONE; TAILQ_INIT(&dev->callbacks); hcdev_count++; @@ -184,6 +194,28 @@ rte_hcdev_allocate(const char *name) return dev; } +int16_t +rte_hcdev_add_child(const char *name, int16_t parent, uint64_t child_context) +{ + struct rte_hcdev *dev; + + if (!rte_hcdev_is_valid(parent)) { + HCDEV_LOG(ERR, "add child to invalid parent ID %d", parent); + rte_errno = ENODEV; + return -rte_errno; + } + + dev = rte_hcdev_allocate(name); + if (dev == NULL) + return -rte_errno; + + dev->info.parent = parent; + dev->info.context = child_context; + + rte_hcdev_complete_new(dev); + return dev->info.dev_id; +} + void rte_hcdev_complete_new(struct rte_hcdev *dev) { @@ -197,10 +229,19 @@ rte_hcdev_complete_new(struct rte_hcdev *dev) int rte_hcdev_release(struct rte_hcdev *dev) { + int16_t dev_id, child; + if (dev == NULL) { rte_errno = ENODEV; return -rte_errno; } + dev_id = dev->info.dev_id; + RTE_HCDEV_FOREACH_CHILD(child, dev_id) { + HCDEV_LOG(ERR, "cannot release device %d with child %d", + dev_id, child); + rte_errno = EBUSY; + return -rte_errno; + } HCDEV_LOG(DEBUG, "free device %s (id %d)", dev->info.name, dev->info.dev_id); diff --git a/lib/hcdev/hcdev_driver.h b/lib/hcdev/hcdev_driver.h index 80d11bd612..39f6fc57ab 100644 --- a/lib/hcdev/hcdev_driver.h +++ b/lib/hcdev/hcdev_driver.h @@ -31,7 +31,7 @@ typedef int (rte_hcdev_info_get_t)(struct rte_hcdev *dev, struct rte_hcdev_info struct rte_hcdev_ops { /* Get device info. If NULL, info is just copied. */ rte_hcdev_info_get_t *dev_info_get; - /* Close device. */ + /* Close device or child context. */ rte_hcdev_close_t *dev_close; }; diff --git a/lib/hcdev/rte_hcdev.h b/lib/hcdev/rte_hcdev.h index 8131e4045a..518020fd2f 100644 --- a/lib/hcdev/rte_hcdev.h +++ b/lib/hcdev/rte_hcdev.h @@ -42,8 +42,12 @@ extern "C" { struct rte_hcdev_info { /** Unique identifier name. */ const char *name; + /** Opaque handler of the device context. */ + uint64_t context; /** Device ID. */ int16_t dev_id; + /** ID of the parent device, RTE_HCDEV_ID_NONE if no parent */ + int16_t parent; /** Total processors available on device. */ uint32_t processor_count; /** Total memory available on device. */ @@ -112,6 +116,33 @@ uint16_t rte_hcdev_count_avail(void); __rte_experimental bool rte_hcdev_is_valid(int16_t dev_id); +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Create a virtual device representing a context in the parent device. + * + * @param name + * Unique string to identify the device. + * @param parent + * Device ID of the parent. + * @param child_context + * Opaque context handler. + * + * @return + * Device ID of the new created child, -rte_errno otherwise: + * - EINVAL if empty name + * - ENAMETOOLONG if long name + * - EEXIST if existing device name + * - ENODEV if invalid parent + * - EPERM if secondary process + * - ENOENT if too many devices + * - ENOMEM if out of space + */ +__rte_experimental +int16_t rte_hcdev_add_child(const char *name, + int16_t parent, uint64_t child_context); + /** * @warning * @b EXPERIMENTAL: this API may change without prior notice. @@ -120,13 +151,17 @@ bool rte_hcdev_is_valid(int16_t dev_id); * * @param dev_id * The initial device ID to start the research. + * @param parent + * The device ID of the parent. + * RTE_HCDEV_ID_NONE means no parent. + * RTE_HCDEV_ID_ANY means no or any parent. * * @return * Next device ID corresponding to a valid and initialized computing device, * RTE_HCDEV_ID_NONE if there is none. */ __rte_experimental -int16_t rte_hcdev_find_next(int16_t dev_id); +int16_t rte_hcdev_find_next(int16_t dev_id, int16_t parent); /** * @warning @@ -138,15 +173,41 @@ int16_t rte_hcdev_find_next(int16_t dev_id); * The ID of the next possible valid device, usually 0 to iterate all. */ #define RTE_HCDEV_FOREACH(dev_id) \ - for (dev_id = rte_hcdev_find_next(0); \ + RTE_HCDEV_FOREACH_CHILD(dev_id, RTE_HCDEV_ID_ANY) + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Macro to iterate over all valid computing devices having no parent. + * + * @param dev_id + * The ID of the next possible valid device, usually 0 to iterate all. + */ +#define RTE_HCDEV_FOREACH_PARENT(dev_id) \ + RTE_HCDEV_FOREACH_CHILD(dev_id, RTE_HCDEV_ID_NONE) + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Macro to iterate over all valid children of a computing device parent. + * + * @param dev_id + * The ID of the next possible valid device, usually 0 to iterate all. + * @param parent + * The device ID of the parent. + */ +#define RTE_HCDEV_FOREACH_CHILD(dev_id, parent) \ + for (dev_id = rte_hcdev_find_next(0, parent); \ dev_id > 0; \ - dev_id = rte_hcdev_find_next(dev_id + 1)) + dev_id = rte_hcdev_find_next(dev_id + 1, parent)) /** * @warning * @b EXPERIMENTAL: this API may change without prior notice. * - * Close device. + * Close device or child context. * All resources are released. * * @param dev_id diff --git a/lib/hcdev/version.map b/lib/hcdev/version.map index 24a5a5a7c4..6d1a1ab1c9 100644 --- a/lib/hcdev/version.map +++ b/lib/hcdev/version.map @@ -2,6 +2,7 @@ EXPERIMENTAL { global: # added in 21.11 + rte_hcdev_add_child; rte_hcdev_callback_register; rte_hcdev_callback_unregister; rte_hcdev_close;