mbuf: dump outer VLAN
[dpdk.git] / lib / mempool / rte_mempool.c
index 2eab38f..de59009 100644 (file)
@@ -7,7 +7,6 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdint.h>
-#include <stdarg.h>
 #include <unistd.h>
 #include <inttypes.h>
 #include <errno.h>
 #include <rte_memory.h>
 #include <rte_memzone.h>
 #include <rte_malloc.h>
-#include <rte_atomic.h>
-#include <rte_launch.h>
 #include <rte_eal.h>
 #include <rte_eal_memconfig.h>
-#include <rte_per_lcore.h>
-#include <rte_lcore.h>
-#include <rte_branch_prediction.h>
 #include <rte_errno.h>
 #include <rte_string_fns.h>
-#include <rte_spinlock.h>
 #include <rte_tailq.h>
 #include <rte_eal_paging.h>
+#include <rte_telemetry.h>
 
 #include "rte_mempool.h"
 #include "rte_mempool_trace.h"
@@ -179,7 +173,7 @@ mempool_add_elem(struct rte_mempool *mp, __rte_unused void *opaque,
 
 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
        hdr->cookie = RTE_MEMPOOL_HEADER_COOKIE2;
-       tlr = __mempool_get_trailer(obj);
+       tlr = rte_mempool_get_trailer(obj);
        tlr->cookie = RTE_MEMPOOL_TRAILER_COOKIE;
 #endif
 }
@@ -372,8 +366,8 @@ rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr,
        STAILQ_INSERT_TAIL(&mp->mem_list, memhdr, next);
        mp->nb_mem_chunks++;
 
-       /* At least some objects in the pool can now be used for IO. */
-       if (iova != RTE_BAD_IOVA)
+       /* Check if at least some objects in the pool are now usable for IO. */
+       if (!(mp->flags & RTE_MEMPOOL_F_NO_IOVA_CONTIG) && iova != RTE_BAD_IOVA)
                mp->flags &= ~RTE_MEMPOOL_F_NON_IO;
 
        /* Report the mempool as ready only when fully populated. */
@@ -798,13 +792,6 @@ rte_mempool_cache_free(struct rte_mempool_cache *cache)
        rte_free(cache);
 }
 
-#define MEMPOOL_KNOWN_FLAGS (RTE_MEMPOOL_F_NO_SPREAD \
-       | RTE_MEMPOOL_F_NO_CACHE_ALIGN \
-       | RTE_MEMPOOL_F_SP_PUT \
-       | RTE_MEMPOOL_F_SC_GET \
-       | RTE_MEMPOOL_F_POOL_CREATED \
-       | RTE_MEMPOOL_F_NO_IOVA_CONTIG \
-       )
 /* create an empty mempool */
 struct rte_mempool *
 rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,
@@ -849,8 +836,8 @@ rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,
                return NULL;
        }
 
-       /* enforce no unknown flag is passed by the application */
-       if ((flags & ~MEMPOOL_KNOWN_FLAGS) != 0) {
+       /* enforce only user flags are passed by the application */
+       if ((flags & ~RTE_MEMPOOL_VALID_USER_FLAGS) != 0) {
                rte_errno = EINVAL;
                return NULL;
        }
@@ -888,7 +875,7 @@ rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,
                goto exit_unlock;
        }
 
-       mempool_size = MEMPOOL_HEADER_SIZE(mp, cache_size);
+       mempool_size = RTE_MEMPOOL_HEADER_SIZE(mp, cache_size);
        mempool_size += private_data_size;
        mempool_size = RTE_ALIGN_CEIL(mempool_size, RTE_MEMPOOL_ALIGN);
 
@@ -904,7 +891,7 @@ rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,
 
        /* init the mempool structure */
        mp = mz->addr;
-       memset(mp, 0, MEMPOOL_HEADER_SIZE(mp, cache_size));
+       memset(mp, 0, RTE_MEMPOOL_HEADER_SIZE(mp, cache_size));
        ret = strlcpy(mp->name, name, sizeof(mp->name));
        if (ret < 0 || ret >= (int)sizeof(mp->name)) {
                rte_errno = ENAMETOOLONG;
@@ -928,7 +915,7 @@ rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,
         * The local_cache points to just past the elt_pa[] array.
         */
        mp->local_cache = (struct rte_mempool_cache *)
-               RTE_PTR_ADD(mp, MEMPOOL_HEADER_SIZE(mp, 0));
+               RTE_PTR_ADD(mp, RTE_MEMPOOL_HEADER_SIZE(mp, 0));
 
        /* Init all default caches. */
        if (cache_size != 0) {
@@ -1091,7 +1078,7 @@ void rte_mempool_check_cookies(const struct rte_mempool *mp,
                        rte_panic("MEMPOOL: object is owned by another "
                                  "mempool\n");
 
-               hdr = __mempool_get_header(obj);
+               hdr = rte_mempool_get_header(obj);
                cookie = hdr->cookie;
 
                if (free == 0) {
@@ -1119,7 +1106,7 @@ void rte_mempool_check_cookies(const struct rte_mempool *mp,
                                rte_panic("MEMPOOL: bad header cookie (audit)\n");
                        }
                }
-               tlr = __mempool_get_trailer(obj);
+               tlr = rte_mempool_get_trailer(obj);
                cookie = tlr->cookie;
                if (cookie != RTE_MEMPOOL_TRAILER_COOKIE) {
                        RTE_LOG(CRIT, MEMPOOL,
@@ -1171,7 +1158,7 @@ static void
 mempool_obj_audit(struct rte_mempool *mp, __rte_unused void *opaque,
        void *obj, __rte_unused unsigned idx)
 {
-       __mempool_check_cookies(mp, &obj, 1, 2);
+       RTE_MEMPOOL_CHECK_COOKIES(mp, &obj, 1, 2);
 }
 
 static void
@@ -1490,3 +1477,86 @@ rte_mempool_event_callback_unregister(rte_mempool_event_callback *func,
        rte_errno = -ret;
        return ret;
 }
+
+static void
+mempool_list_cb(struct rte_mempool *mp, void *arg)
+{
+       struct rte_tel_data *d = (struct rte_tel_data *)arg;
+
+       rte_tel_data_add_array_string(d, mp->name);
+}
+
+static int
+mempool_handle_list(const char *cmd __rte_unused,
+                   const char *params __rte_unused, struct rte_tel_data *d)
+{
+       rte_tel_data_start_array(d, RTE_TEL_STRING_VAL);
+       rte_mempool_walk(mempool_list_cb, d);
+       return 0;
+}
+
+struct mempool_info_cb_arg {
+       char *pool_name;
+       struct rte_tel_data *d;
+};
+
+static void
+mempool_info_cb(struct rte_mempool *mp, void *arg)
+{
+       struct mempool_info_cb_arg *info = (struct mempool_info_cb_arg *)arg;
+       const struct rte_memzone *mz;
+
+       if (strncmp(mp->name, info->pool_name, RTE_MEMZONE_NAMESIZE))
+               return;
+
+       rte_tel_data_add_dict_string(info->d, "name", mp->name);
+       rte_tel_data_add_dict_int(info->d, "pool_id", mp->pool_id);
+       rte_tel_data_add_dict_int(info->d, "flags", mp->flags);
+       rte_tel_data_add_dict_int(info->d, "socket_id", mp->socket_id);
+       rte_tel_data_add_dict_int(info->d, "size", mp->size);
+       rte_tel_data_add_dict_int(info->d, "cache_size", mp->cache_size);
+       rte_tel_data_add_dict_int(info->d, "elt_size", mp->elt_size);
+       rte_tel_data_add_dict_int(info->d, "header_size", mp->header_size);
+       rte_tel_data_add_dict_int(info->d, "trailer_size", mp->trailer_size);
+       rte_tel_data_add_dict_int(info->d, "private_data_size",
+                                 mp->private_data_size);
+       rte_tel_data_add_dict_int(info->d, "ops_index", mp->ops_index);
+       rte_tel_data_add_dict_int(info->d, "populated_size",
+                                 mp->populated_size);
+
+       mz = mp->mz;
+       rte_tel_data_add_dict_string(info->d, "mz_name", mz->name);
+       rte_tel_data_add_dict_int(info->d, "mz_len", mz->len);
+       rte_tel_data_add_dict_int(info->d, "mz_hugepage_sz",
+                                 mz->hugepage_sz);
+       rte_tel_data_add_dict_int(info->d, "mz_socket_id", mz->socket_id);
+       rte_tel_data_add_dict_int(info->d, "mz_flags", mz->flags);
+}
+
+static int
+mempool_handle_info(const char *cmd __rte_unused, const char *params,
+                   struct rte_tel_data *d)
+{
+       struct mempool_info_cb_arg mp_arg;
+       char name[RTE_MEMZONE_NAMESIZE];
+
+       if (!params || strlen(params) == 0)
+               return -EINVAL;
+
+       rte_strlcpy(name, params, RTE_MEMZONE_NAMESIZE);
+
+       rte_tel_data_start_dict(d);
+       mp_arg.pool_name = name;
+       mp_arg.d = d;
+       rte_mempool_walk(mempool_info_cb, &mp_arg);
+
+       return 0;
+}
+
+RTE_INIT(mempool_init_telemetry)
+{
+       rte_telemetry_register_cmd("/mempool/list", mempool_handle_list,
+               "Returns list of available mempool. Takes no parameters");
+       rte_telemetry_register_cmd("/mempool/info", mempool_handle_info,
+               "Returns mempool info. Parameters: pool_name");
+}