Add a function to access the DPDK hugepage allocator utilization statistics.
Signed-off-by: Gaetan Rivet <[email protected]> --- lib/dpdk-stub.c | 8 ++++++++ lib/dpdk.c | 38 ++++++++++++++++++++++++++++++++++++++ lib/dpdk.h | 9 +++++++++ 3 files changed, 55 insertions(+) diff --git a/lib/dpdk-stub.c b/lib/dpdk-stub.c index 58ebf6cb62..95a28f25d9 100644 --- a/lib/dpdk-stub.c +++ b/lib/dpdk-stub.c @@ -18,6 +18,8 @@ #include <config.h> #include "dpdk.h" +#include <errno.h> + #include "smap.h" #include "ovs-thread.h" #include "openvswitch/vlog.h" @@ -68,3 +70,9 @@ dpdk_status(const struct ovsrec_open_vswitch *cfg) ovsrec_open_vswitch_set_dpdk_version(cfg, "none"); } } + +int +dpdk_get_hugepage_stats(struct ovs_dpdk_hugepage_stats *odhs OVS_UNUSED) +{ + return EOPNOTSUPP; +} diff --git a/lib/dpdk.c b/lib/dpdk.c index 077bdfc098..e93f9fab42 100644 --- a/lib/dpdk.c +++ b/lib/dpdk.c @@ -600,3 +600,41 @@ dpdk_status(const struct ovsrec_open_vswitch *cfg) ovsrec_open_vswitch_set_dpdk_version(cfg, rte_version()); } } + +int +dpdk_get_hugepage_stats(struct ovs_dpdk_hugepage_stats *odhs) +{ + struct rte_malloc_socket_stats sock_stats; + struct ovs_numa_info_numa *numa; + struct ovs_numa_dump *affinity; + int ret = 0; + + if (odhs == NULL) { + return EINVAL; + } + + if (dpdk_initialized == false) { + return EOPNOTSUPP; + } + + affinity = ovs_numa_thread_getaffinity_dump(); + if (affinity == NULL) { + return ENODEV; + } + + memset(odhs, 0, sizeof *odhs); + + FOR_EACH_NUMA_ON_DUMP(numa, affinity) { + ret = rte_malloc_get_socket_stats(numa->numa_id, &sock_stats); + if (ret) { + goto free_affinity; + } + odhs->capacity_bytes += sock_stats.heap_totalsz_bytes; + odhs->free_bytes += sock_stats.heap_freesz_bytes; + odhs->allocated_bytes += sock_stats.heap_allocsz_bytes; + } + +free_affinity: + ovs_numa_dump_destroy(affinity); + return ret; +} diff --git a/lib/dpdk.h b/lib/dpdk.h index 1b790e682e..a79b1509a1 100644 --- a/lib/dpdk.h +++ b/lib/dpdk.h @@ -18,6 +18,7 @@ #define DPDK_H #include <stdbool.h> +#include <stdlib.h> #ifdef DPDK_NETDEV @@ -42,4 +43,12 @@ bool dpdk_available(void); void print_dpdk_version(void); void dpdk_status(const struct ovsrec_open_vswitch *); +struct ovs_dpdk_hugepage_stats { + size_t capacity_bytes; /* Total bytes reserved by DPDK from hugepages. */ + size_t free_bytes; /* Non-allocated bytes from reserved pages in bytes. */ + size_t allocated_bytes; /* Allocated bytes from reserved pages in bytes. */ +}; + +int dpdk_get_hugepage_stats(struct ovs_dpdk_hugepage_stats *odhs); + #endif /* dpdk.h */ -- 2.34.1 _______________________________________________ dev mailing list [email protected] https://mail.openvswitch.org/mailman/listinfo/ovs-dev
