Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Ido Schimmel <idosch@idosch.org>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, kuba@kernel.org, jiri@nvidia.com,
amcohen@nvidia.com, danieller@nvidia.com, mlxsw@nvidia.com,
roopa@nvidia.com, dsahern@gmail.com, andrew@lunn.ch,
f.fainelli@gmail.com, vivien.didelot@gmail.com,
saeedm@nvidia.com, tariqt@nvidia.com, ayal@nvidia.com,
eranbe@nvidia.com, mkubecek@suse.cz,
Ido Schimmel <idosch@nvidia.com>
Subject: [RFC PATCH net-next 2/6] netdevsim: Add devlink metric support
Date: Mon, 17 Aug 2020 15:50:55 +0300 [thread overview]
Message-ID: <20200817125059.193242-3-idosch@idosch.org> (raw)
In-Reply-To: <20200817125059.193242-1-idosch@idosch.org>
From: Ido Schimmel <idosch@nvidia.com>
Register a dummy counter with devlink that is incremented by one
whenever queried.
Allow the query to fail by writing to a file in debugfs so that error
paths in the core infrastructure could be exercised.
Signed-off-by: Amit Cohen <amcohen@nvidia.com>
Signed-off-by: Danielle Ratson <danieller@nvidia.com>
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
---
drivers/net/netdevsim/dev.c | 92 ++++++++++++++++++++++++++++++-
drivers/net/netdevsim/netdevsim.h | 1 +
2 files changed, 91 insertions(+), 2 deletions(-)
diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c
index 32f339fedb21..075d2d4e22a5 100644
--- a/drivers/net/netdevsim/dev.c
+++ b/drivers/net/netdevsim/dev.c
@@ -692,6 +692,81 @@ static void nsim_dev_traps_exit(struct devlink *devlink)
kfree(nsim_dev->trap_data);
}
+struct nsim_metric_data {
+ struct devlink_metric *dummy_counter;
+ struct dentry *ddir;
+ u64 dummy_counter_value;
+ bool fail_counter_get;
+};
+
+static int nsim_dev_dummy_counter_get(struct devlink_metric *metric, u64 *p_val)
+{
+ struct nsim_dev *nsim_dev = devlink_metric_priv(metric);
+ u64 *cnt;
+
+ if (nsim_dev->metric_data->fail_counter_get)
+ return -EINVAL;
+
+ cnt = &nsim_dev->metric_data->dummy_counter_value;
+ *p_val = (*cnt)++;
+
+ return 0;
+}
+
+static const struct devlink_metric_ops nsim_dev_dummy_counter_ops = {
+ .counter_get = nsim_dev_dummy_counter_get,
+};
+
+static int nsim_dev_metric_init(struct nsim_dev *nsim_dev)
+{
+ struct devlink *devlink = priv_to_devlink(nsim_dev);
+ struct nsim_metric_data *nsim_metric_data;
+ struct devlink_metric *dummy_counter;
+ int err;
+
+ nsim_metric_data = kzalloc(sizeof(*nsim_metric_data), GFP_KERNEL);
+ if (!nsim_metric_data)
+ return -ENOMEM;
+ nsim_dev->metric_data = nsim_metric_data;
+
+ dummy_counter = devlink_metric_counter_create(devlink, "dummy_counter",
+ &nsim_dev_dummy_counter_ops,
+ nsim_dev);
+ if (IS_ERR(dummy_counter)) {
+ err = PTR_ERR(dummy_counter);
+ goto err_free_metric_data;
+ }
+ nsim_metric_data->dummy_counter = dummy_counter;
+
+ nsim_metric_data->ddir = debugfs_create_dir("metric", nsim_dev->ddir);
+ if (IS_ERR(nsim_metric_data->ddir)) {
+ err = PTR_ERR(nsim_metric_data->ddir);
+ goto err_dummy_counter_destroy;
+ }
+
+ nsim_metric_data->fail_counter_get = false;
+ debugfs_create_bool("fail_counter_get", 0600, nsim_metric_data->ddir,
+ &nsim_metric_data->fail_counter_get);
+
+ return 0;
+
+err_dummy_counter_destroy:
+ devlink_metric_destroy(devlink, dummy_counter);
+err_free_metric_data:
+ kfree(nsim_metric_data);
+ return err;
+}
+
+static void nsim_dev_metric_exit(struct nsim_dev *nsim_dev)
+{
+ struct nsim_metric_data *nsim_metric_data = nsim_dev->metric_data;
+ struct devlink *devlink = priv_to_devlink(nsim_dev);
+
+ debugfs_remove_recursive(nsim_metric_data->ddir);
+ devlink_metric_destroy(devlink, nsim_metric_data->dummy_counter);
+ kfree(nsim_metric_data);
+}
+
static int nsim_dev_reload_create(struct nsim_dev *nsim_dev,
struct netlink_ext_ack *extack);
static void nsim_dev_reload_destroy(struct nsim_dev *nsim_dev);
@@ -1008,10 +1083,14 @@ static int nsim_dev_reload_create(struct nsim_dev *nsim_dev,
if (err)
goto err_traps_exit;
- err = nsim_dev_port_add_all(nsim_dev, nsim_bus_dev->port_count);
+ err = nsim_dev_metric_init(nsim_dev);
if (err)
goto err_health_exit;
+ err = nsim_dev_port_add_all(nsim_dev, nsim_bus_dev->port_count);
+ if (err)
+ goto err_metric_exit;
+
nsim_dev->take_snapshot = debugfs_create_file("take_snapshot",
0200,
nsim_dev->ddir,
@@ -1019,6 +1098,8 @@ static int nsim_dev_reload_create(struct nsim_dev *nsim_dev,
&nsim_dev_take_snapshot_fops);
return 0;
+err_metric_exit:
+ nsim_dev_metric_exit(nsim_dev);
err_health_exit:
nsim_dev_health_exit(nsim_dev);
err_traps_exit:
@@ -1089,10 +1170,14 @@ int nsim_dev_probe(struct nsim_bus_dev *nsim_bus_dev)
if (err)
goto err_debugfs_exit;
- err = nsim_bpf_dev_init(nsim_dev);
+ err = nsim_dev_metric_init(nsim_dev);
if (err)
goto err_health_exit;
+ err = nsim_bpf_dev_init(nsim_dev);
+ if (err)
+ goto err_metric_exit;
+
err = nsim_dev_port_add_all(nsim_dev, nsim_bus_dev->port_count);
if (err)
goto err_bpf_dev_exit;
@@ -1103,6 +1188,8 @@ int nsim_dev_probe(struct nsim_bus_dev *nsim_bus_dev)
err_bpf_dev_exit:
nsim_bpf_dev_exit(nsim_dev);
+err_metric_exit:
+ nsim_dev_metric_exit(nsim_dev);
err_health_exit:
nsim_dev_health_exit(nsim_dev);
err_debugfs_exit:
@@ -1133,6 +1220,7 @@ static void nsim_dev_reload_destroy(struct nsim_dev *nsim_dev)
return;
debugfs_remove(nsim_dev->take_snapshot);
nsim_dev_port_del_all(nsim_dev);
+ nsim_dev_metric_exit(nsim_dev);
nsim_dev_health_exit(nsim_dev);
nsim_dev_traps_exit(devlink);
nsim_dev_dummy_region_exit(nsim_dev);
diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h
index 284f7092241d..5f9a99bc4022 100644
--- a/drivers/net/netdevsim/netdevsim.h
+++ b/drivers/net/netdevsim/netdevsim.h
@@ -171,6 +171,7 @@ struct nsim_dev {
struct nsim_bus_dev *nsim_bus_dev;
struct nsim_fib_data *fib_data;
struct nsim_trap_data *trap_data;
+ struct nsim_metric_data *metric_data;
struct dentry *ddir;
struct dentry *ports_ddir;
struct dentry *take_snapshot;
--
2.26.2
next prev parent reply other threads:[~2020-08-17 12:52 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-17 12:50 [RFC PATCH net-next 0/6] devlink: Add device " Ido Schimmel
2020-08-17 12:50 ` [RFC PATCH net-next 1/6] devlink: Add device metric infrastructure Ido Schimmel
2020-08-17 14:12 ` Andrew Lunn
2020-08-17 12:50 ` Ido Schimmel [this message]
2020-08-17 12:50 ` [RFC PATCH net-next 3/6] selftests: netdevsim: Add devlink metric tests Ido Schimmel
2020-08-17 12:50 ` [RFC PATCH net-next 4/6] mlxsw: reg: Add Tunneling NVE Counters Register Ido Schimmel
2020-08-17 12:50 ` [RFC PATCH net-next 5/6] mlxsw: reg: Add Tunneling NVE Counters Register Version 2 Ido Schimmel
2020-08-17 12:50 ` [RFC PATCH net-next 6/6] mlxsw: spectrum_nve: Expose VXLAN counters via devlink-metric Ido Schimmel
2020-08-17 14:29 ` Andrew Lunn
2020-08-18 6:59 ` Ido Schimmel
2020-08-19 0:24 ` [RFC PATCH net-next 0/6] devlink: Add device metric support Jakub Kicinski
2020-08-19 2:43 ` David Ahern
2020-08-19 3:35 ` Jakub Kicinski
2020-08-19 4:30 ` Florian Fainelli
2020-08-19 16:18 ` Jakub Kicinski
2020-08-19 17:20 ` Florian Fainelli
2020-08-19 18:07 ` Jakub Kicinski
2020-08-20 14:35 ` David Ahern
2020-08-20 16:09 ` Jakub Kicinski
2020-08-21 10:30 ` Ido Schimmel
2020-08-21 16:53 ` Jakub Kicinski
2020-08-21 19:12 ` David Ahern
2020-08-21 23:50 ` Jakub Kicinski
2020-08-21 23:59 ` David Ahern
2020-08-22 0:37 ` Jakub Kicinski
2020-08-22 1:18 ` David Ahern
2020-08-22 16:27 ` Jakub Kicinski
2020-08-23 7:04 ` Ido Schimmel
2020-08-24 19:11 ` Jakub Kicinski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200817125059.193242-3-idosch@idosch.org \
--to=idosch@idosch.org \
--cc=amcohen@nvidia.com \
--cc=andrew@lunn.ch \
--cc=ayal@nvidia.com \
--cc=danieller@nvidia.com \
--cc=davem@davemloft.net \
--cc=dsahern@gmail.com \
--cc=eranbe@nvidia.com \
--cc=f.fainelli@gmail.com \
--cc=idosch@nvidia.com \
--cc=jiri@nvidia.com \
--cc=kuba@kernel.org \
--cc=mkubecek@suse.cz \
--cc=mlxsw@nvidia.com \
--cc=netdev@vger.kernel.org \
--cc=roopa@nvidia.com \
--cc=saeedm@nvidia.com \
--cc=tariqt@nvidia.com \
--cc=vivien.didelot@gmail.com \
--subject='Re: [RFC PATCH net-next 2/6] netdevsim: Add devlink metric support' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).