[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250219164410.35665-3-przemyslaw.kitszel@intel.com>
Date: Wed, 19 Feb 2025 17:32:55 +0100
From: Przemek Kitszel <przemyslaw.kitszel@...el.com>
To: intel-wired-lan@...ts.osuosl.org,
Tony Nguyen <anthony.l.nguyen@...el.com>,
Jiri Pirko <jiri@...nulli.us>,
Jakub Kicinski <kuba@...nel.org>,
Cosmin Ratiu <cratiu@...dia.com>,
Tariq Toukan <tariqt@...dia.com>
Cc: netdev@...r.kernel.org,
Konrad Knitter <konrad.knitter@...el.com>,
Jacob Keller <jacob.e.keller@...el.com>,
davem@...emloft.net,
Eric Dumazet <edumazet@...gle.com>,
Paolo Abeni <pabeni@...hat.com>,
Andrew Lunn <andrew@...n.ch>,
linux-kernel@...r.kernel.org,
ITP Upstream <nxne.cnse.osdt.itp.upstreaming@...el.com>,
Carolina Jubran <cjubran@...dia.com>,
Przemek Kitszel <przemyslaw.kitszel@...el.com>
Subject: [RFC net-next v2 2/2] devlink: give user option to allocate resources
Current devlink resources are designed as a thing that user could limit,
but there is not much otherwise that could be done with them.
Perhaps that's the reason there is no much adoption despite API being
there for multiple years.
Add new mode of operation, where user could allocate/assign resources
(from a common pool) to specific devices.
That requires "occ set" support, triggered by user.
To support that mode, "occ get" is (only then) turned into a simple
"get/show" operation, as opposed to "ask driver about current occupation"
in the "legacy" mode.
Naming advice welcomed, for now the modes are reffered as:
legacy/static-occ/mlx vs new/ice/dynamic-occ
Perhaps "user-settable" for the new mode and "driver-only" for the legacy?
Does not matter much, as this will be only embedded in the
net/devlink/resource.c file as names/comments for clarity.
Signed-off-by: Przemek Kitszel <przemyslaw.kitszel@...el.com>
---
net/devlink/resource.c | 94 +++++++++++++++++++++++++++++++++---------
1 file changed, 74 insertions(+), 20 deletions(-)
diff --git a/net/devlink/resource.c b/net/devlink/resource.c
index 2d6324f3d91f..c81d05427e12 100644
--- a/net/devlink/resource.c
+++ b/net/devlink/resource.c
@@ -14,25 +14,30 @@
* @size_new: updated size of the resource, reload is needed
* @size_valid: valid in case the total size of the resource is valid
* including its children
+ * @occ_mode: false for static occ mode == legacy mlx like
+ * true for dynamic occ mode == new one for intel
* @parent: parent resource
* @size_params: size parameters
* @list: parent list
* @resource_list: list of child resources
* @occ_get: occupancy getter callback
- * @occ_get_priv: occupancy getter callback priv
+ * @occ_set: occupancy setter callback
+ * @occ_priv: occupancy callbacks priv
*/
struct devlink_resource {
const char *name;
u64 id;
u64 size;
u64 size_new;
bool size_valid;
+ bool occ_mode;
struct devlink_resource *parent;
struct devlink_resource_size_params size_params;
struct list_head list;
struct list_head resource_list;
devlink_resource_occ_get_t *occ_get;
- void *occ_get_priv;
+ devlink_resource_occ_set_t *occ_set;
+ void *occ_priv;
};
static struct devlink_resource *
@@ -127,6 +132,9 @@ int devlink_nl_resource_set_doit(struct sk_buff *skb, struct genl_info *info)
if (err)
return err;
+ if (resource->occ_set)
+ return resource->occ_set(size, info->extack, resource->occ_priv);
+
resource->size_new = size;
devlink_resource_validate_children(resource);
if (resource->parent)
@@ -152,13 +160,46 @@ devlink_resource_size_params_put(struct devlink_resource *resource,
return 0;
}
-static int devlink_resource_occ_put(struct devlink_resource *resource,
- struct sk_buff *skb)
+static
+int devlink_resource_occ_size_put_legacy(struct devlink_resource *resource,
+ struct sk_buff *skb)
+{
+ int err;
+
+ if (resource->occ_get) {
+ err = devlink_nl_put_u64(skb, DEVLINK_ATTR_RESOURCE_OCC,
+ resource->occ_get(resource->occ_priv));
+ if (err)
+ return err;
+ }
+
+ if (resource->size != resource->size_new) {
+ err = devlink_nl_put_u64(skb, DEVLINK_ATTR_RESOURCE_SIZE_NEW,
+ resource->size_new);
+ if (err)
+ return err;
+ }
+
+ err = nla_put_u8(skb, DEVLINK_ATTR_RESOURCE_SIZE_VALID,
+ resource->size_valid);
+ if (err)
+ return err;
+
+
+ return devlink_nl_put_u64(skb, DEVLINK_ATTR_RESOURCE_SIZE,
+ resource->size);
+}
+
+static int devlink_resource_occ_size_put(struct devlink_resource *resource,
+ struct sk_buff *skb)
{
- if (!resource->occ_get)
- return 0;
- return devlink_nl_put_u64(skb, DEVLINK_ATTR_RESOURCE_OCC,
- resource->occ_get(resource->occ_get_priv));
+ if (!resource->occ_get || !resource->occ_set)
+ return devlink_resource_occ_size_put_legacy(resource, skb);
+
+ nla_put_u8(skb, DEVLINK_ATTR_RESOURCE_SIZE_VALID, true);
+
+ return devlink_nl_put_u64(skb, DEVLINK_ATTR_RESOURCE_SIZE,
+ resource->occ_get(resource->occ_priv));
}
static int devlink_resource_put(struct devlink *devlink, struct sk_buff *skb,
@@ -173,23 +214,16 @@ static int devlink_resource_put(struct devlink *devlink, struct sk_buff *skb,
return -EMSGSIZE;
if (nla_put_string(skb, DEVLINK_ATTR_RESOURCE_NAME, resource->name) ||
- devlink_nl_put_u64(skb, DEVLINK_ATTR_RESOURCE_SIZE, resource->size) ||
devlink_nl_put_u64(skb, DEVLINK_ATTR_RESOURCE_ID, resource->id))
goto nla_put_failure;
- if (resource->size != resource->size_new &&
- devlink_nl_put_u64(skb, DEVLINK_ATTR_RESOURCE_SIZE_NEW,
- resource->size_new))
- goto nla_put_failure;
- if (devlink_resource_occ_put(resource, skb))
- goto nla_put_failure;
if (devlink_resource_size_params_put(resource, skb))
goto nla_put_failure;
+ if (devlink_resource_occ_size_put(resource, skb))
+ goto nla_put_failure;
+
if (list_empty(&resource->resource_list))
goto out;
- if (nla_put_u8(skb, DEVLINK_ATTR_RESOURCE_SIZE_VALID,
- resource->size_valid))
- goto nla_put_failure;
child_resource_attr = nla_nest_start_noflag(skb,
DEVLINK_ATTR_RESOURCE_LIST);
@@ -476,7 +510,7 @@ void devl_resource_occ_get_register(struct devlink *devlink,
WARN_ON(resource->occ_get);
resource->occ_get = occ_get;
- resource->occ_get_priv = occ_get_priv;
+ resource->occ_priv = occ_get_priv;
}
EXPORT_SYMBOL_GPL(devl_resource_occ_get_register);
@@ -499,6 +533,26 @@ void devl_resource_occ_get_unregister(struct devlink *devlink,
WARN_ON(!resource->occ_get);
resource->occ_get = NULL;
- resource->occ_get_priv = NULL;
}
EXPORT_SYMBOL_GPL(devl_resource_occ_get_unregister);
+
+void devl_resource_occ_set_get_register(struct devlink *devlink,
+ u64 resource_id,
+ devlink_resource_occ_set_t *occ_set,
+ devlink_resource_occ_get_t *occ_get,
+ void *occ_priv)
+{
+ struct devlink_resource *resource;
+
+ lockdep_assert_held(&devlink->lock);
+
+ resource = devlink_resource_find(devlink, NULL, resource_id);
+ if (WARN_ON(!resource))
+ return;
+ WARN_ON(resource->occ_get || resource->occ_set);
+
+ resource->occ_set = occ_set;
+ resource->occ_get = occ_get;
+ resource->occ_priv = occ_priv;
+}
+EXPORT_SYMBOL_GPL(devl_resource_occ_set_get_register);
--
2.46.0
Powered by blists - more mailing lists