[ovs-dev] [RFC PATCH 05/26] dpif: Add function to read hardware offload statistics
Gaetan Rivet
grive at u256.net
Sat Dec 5 14:22:00 UTC 2020
Expose a function to query datapath offload statistics.
Call the new API from dpctl.
Signed-off-by: Gaetan Rivet <grive at u256.net>
---
lib/dpctl.c | 36 ++++++++++++++++++++++++++++++++++++
lib/dpif-netdev.c | 1 +
lib/dpif-netlink.c | 1 +
lib/dpif-provider.h | 7 +++++++
lib/dpif.c | 8 ++++++++
lib/dpif.h | 9 +++++++++
6 files changed, 62 insertions(+)
diff --git a/lib/dpctl.c b/lib/dpctl.c
index 33202813b..7bd75ae1a 100644
--- a/lib/dpctl.c
+++ b/lib/dpctl.c
@@ -1387,6 +1387,40 @@ dpctl_del_flows(int argc, const char *argv[], struct dpctl_params *dpctl_p)
return error;
}
+static int
+dpctl_offload_stats_show(int argc, const char *argv[],
+ struct dpctl_params *dpctl_p)
+{
+ struct netdev_custom_stats stats;
+ struct dpif *dpif;
+ int error;
+ size_t i;
+
+ error = opt_dpif_open(argc, argv, dpctl_p, 2, &dpif);
+ if (error) {
+ return error;
+ }
+
+ memset(&stats, 0, sizeof(stats));
+ error = dpif_offload_stats_get(dpif, &stats);
+ if (error) {
+ dpctl_error(dpctl_p, error, "retrieving offload statistics");
+ goto close_dpif;
+ }
+
+ dpctl_print(dpctl_p, "HW Offload stats:\n");
+ for (i = 0; i < stats.size; i++) {
+ dpctl_print(dpctl_p, " %s: %6" PRIu64 "\n",
+ stats.counters[i].name, stats.counters[i].value);
+ }
+
+ netdev_free_custom_stats_counters(&stats);
+
+close_dpif:
+ dpif_close(dpif);
+ return error;
+}
+
static int
dpctl_help(int argc OVS_UNUSED, const char *argv[] OVS_UNUSED,
struct dpctl_params *dpctl_p)
@@ -2541,6 +2575,8 @@ static const struct dpctl_command all_commands[] = {
{ "get-flow", "[dp] ufid", 1, 2, dpctl_get_flow, DP_RO },
{ "del-flow", "[dp] flow", 1, 2, dpctl_del_flow, DP_RW },
{ "del-flows", "[dp]", 0, 1, dpctl_del_flows, DP_RW },
+ { "offload-stats-show", "[dp]",
+ 0, 1, dpctl_offload_stats_show, DP_RO },
{ "dump-conntrack", "[dp] [zone=N]", 0, 2, dpctl_dump_conntrack, DP_RO },
{ "flush-conntrack", "[dp] [zone=N] [ct-tuple]", 0, 3,
dpctl_flush_conntrack, DP_RW },
diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index 300861ca5..a97796f64 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -8415,6 +8415,7 @@ const struct dpif_class dpif_netdev_class = {
dpif_netdev_flow_dump_thread_destroy,
dpif_netdev_flow_dump_next,
dpif_netdev_operate,
+ NULL, /* offload_stats_get */
NULL, /* recv_set */
NULL, /* handlers_set */
dpif_netdev_set_config,
diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c
index 2f881e4fa..5b4cf6d09 100644
--- a/lib/dpif-netlink.c
+++ b/lib/dpif-netlink.c
@@ -3967,6 +3967,7 @@ const struct dpif_class dpif_netlink_class = {
dpif_netlink_flow_dump_thread_destroy,
dpif_netlink_flow_dump_next,
dpif_netlink_operate,
+ NULL, /* offload_stats_get */
dpif_netlink_recv_set,
dpif_netlink_handlers_set,
NULL, /* set_config */
diff --git a/lib/dpif-provider.h b/lib/dpif-provider.h
index b817fceac..36dfa8e71 100644
--- a/lib/dpif-provider.h
+++ b/lib/dpif-provider.h
@@ -330,6 +330,13 @@ struct dpif_class {
void (*operate)(struct dpif *dpif, struct dpif_op **ops, size_t n_ops,
enum dpif_offload_type offload_type);
+ /* Get hardware-offloads activity counters from a dataplane.
+ * Those counters are not offload statistics (which are accessible through
+ * netdev statistics), but a status of hardware offload management:
+ * how many offloads are currently waiting, inserted, etc. */
+ int (*offload_stats_get)(struct dpif *dpif,
+ struct netdev_custom_stats *stats);
+
/* Enables or disables receiving packets with dpif_recv() for 'dpif'.
* Turning packet receive off and then back on is allowed to change Netlink
* PID assignments (see ->port_get_pid()). The client is responsible for
diff --git a/lib/dpif.c b/lib/dpif.c
index ac2860764..7218357aa 100644
--- a/lib/dpif.c
+++ b/lib/dpif.c
@@ -1426,6 +1426,14 @@ dpif_operate(struct dpif *dpif, struct dpif_op **ops, size_t n_ops,
}
}
+int dpif_offload_stats_get(struct dpif *dpif,
+ struct netdev_custom_stats *stats)
+{
+ return (dpif->dpif_class->offload_stats_get
+ ? dpif->dpif_class->offload_stats_get(dpif, stats)
+ : EOPNOTSUPP);
+}
+
/* Returns a string that represents 'type', for use in log messages. */
const char *
dpif_upcall_type_to_string(enum dpif_upcall_type type)
diff --git a/lib/dpif.h b/lib/dpif.h
index cb047dbe2..7ad0fe604 100644
--- a/lib/dpif.h
+++ b/lib/dpif.h
@@ -785,6 +785,15 @@ struct dpif_op {
void dpif_operate(struct dpif *, struct dpif_op **ops, size_t n_ops,
enum dpif_offload_type);
+
+/* Queries the datapath for hardware offloads stats.
+ *
+ * Statistics are written in 'stats' following the 'netdev_custom_stats'
+ * format. They are allocated on the heap and must be freed by the caller,
+ * using 'netdev_free_custom_stats_counters'.
+ */
+int dpif_offload_stats_get(struct dpif *dpif,
+ struct netdev_custom_stats *stats);
/* Upcalls. */
--
2.29.2
More information about the dev
mailing list