git sha: [email protected]  
Author: Gaetan Rivet <[email protected]>
Subject: dpdk: Add helper to access hugepage memory statistics.

This commit adds a new function dpdk_get_hugepage_stats() to access DPDK
hugepage allocator utilization statistics, along with the corresponding
stub implementation and data structure.

> 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;
> +}

Could there be integer overflow when accumulating the bytes values?
The socket stats fields appear to be size_t, but repeatedly adding to
odhs->capacity_bytes, odhs->free_bytes, and odhs->allocated_bytes might
overflow if there are many NUMA nodes with large heap sizes.

[ ... ]

> 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 */
_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to