Introduce new feature to dump memory statistics of each socket
and a total for all before and after the creation.

This will give two main advantage:
1- Check the memory consumption for large number of flows
"insertion rate scenario alone"

2- Check that no memory leackage after doing insertion then
deletion.

Signed-off-by: Suanming Mou <suanmi...@mellanox.com>
Signed-off-by: Wisam Jaddo <wis...@mellanox.com>
---
 app/test-flow-perf/main.c              | 72 +++++++++++++++++++++++++-
 doc/guides/rel_notes/release_20_05.rst |  1 +
 doc/guides/tools/flow-perf.rst         |  6 ++-
 3 files changed, 77 insertions(+), 2 deletions(-)

diff --git a/app/test-flow-perf/main.c b/app/test-flow-perf/main.c
index b177025fa..da54bbdef 100644
--- a/app/test-flow-perf/main.c
+++ b/app/test-flow-perf/main.c
@@ -49,7 +49,8 @@ static uint32_t flow_actions;
 static uint32_t flow_attrs;
 static volatile bool force_quit;
 static bool dump_iterations;
-static  bool delete_flag;
+static bool delete_flag;
+static bool dump_socket_mem_flag;
 static struct rte_mempool *mbuf_mp;
 static uint32_t nb_lcores;
 static uint32_t flows_count;
@@ -67,6 +68,7 @@ usage(char *progname)
                " iteration\n");
        printf("  --deletion-rate: Enable deletion rate"
                " calculations\n");
+       printf("  --dump-socket-mem: To dump all socket memory\n");
 
        printf("To set flow attributes:\n");
        printf("  --ingress: set ingress attribute in flows\n");
@@ -250,6 +252,7 @@ args_parse(int argc, char **argv)
                { "flows-count",                1, 0, 0 },
                { "dump-iterations",            0, 0, 0 },
                { "deletion-rate",              0, 0, 0 },
+               { "dump-socket-mem",            0, 0, 0 },
                /* Attributes */
                { "ingress",                    0, 0, 0 },
                { "egress",                     0, 0, 0 },
@@ -360,6 +363,9 @@ args_parse(int argc, char **argv)
                        if (strcmp(lgopts[opt_idx].name,
                                        "deletion-rate") == 0)
                                delete_flag = true;
+                       if (strcmp(lgopts[opt_idx].name,
+                                       "dump-socket-mem") == 0)
+                               dump_socket_mem_flag = true;
                        break;
                default:
                        fprintf(stderr, "Invalid option: %s\n", argv[optind]);
@@ -371,6 +377,62 @@ args_parse(int argc, char **argv)
        printf("end_flow\n");
 }
 
+/* Dump the socket memory statistics on console */
+static size_t
+dump_socket_mem(FILE *f)
+{
+       struct rte_malloc_socket_stats socket_stats;
+       unsigned int i = 0;
+       size_t total = 0;
+       size_t alloc = 0;
+       size_t free = 0;
+       unsigned int n_alloc = 0;
+       unsigned int n_free = 0;
+       bool active_nodes = false;
+
+
+       for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
+               if (rte_malloc_get_socket_stats(i, &socket_stats) ||
+                   !socket_stats.heap_totalsz_bytes)
+                       continue;
+               active_nodes = true;
+               total += socket_stats.heap_totalsz_bytes;
+               alloc += socket_stats.heap_allocsz_bytes;
+               free += socket_stats.heap_freesz_bytes;
+               n_alloc += socket_stats.alloc_count;
+               n_free += socket_stats.free_count;
+               if (dump_socket_mem_flag) {
+                       fprintf(f, "::::::::::::::::::::::::::::::::::::::::");
+                       fprintf(f,
+                               "\nSocket %u:\nsize(M) total: %.6lf\nalloc:"
+                               " %.6lf(%.3lf%%)\nfree: %.6lf"
+                               "\nmax: %.6lf"
+                               "\ncount alloc: %u\nfree: %u\n",
+                               i,
+                               socket_stats.heap_totalsz_bytes / 1.0e6,
+                               socket_stats.heap_allocsz_bytes / 1.0e6,
+                               (double)socket_stats.heap_allocsz_bytes * 100 /
+                               (double)socket_stats.heap_totalsz_bytes,
+                               socket_stats.heap_freesz_bytes / 1.0e6,
+                               socket_stats.greatest_free_size / 1.0e6,
+                               socket_stats.alloc_count,
+                               socket_stats.free_count);
+                               fprintf(f, 
"::::::::::::::::::::::::::::::::::::::::");
+               }
+       }
+       if (dump_socket_mem_flag && active_nodes) {
+               fprintf(f,
+                       "\nTotal: size(M)\ntotal: %.6lf"
+                       "\nalloc: %.6lf(%.3lf%%)\nfree: %.6lf"
+                       "\ncount alloc: %u\nfree: %u\n",
+                       total / 1.0e6, alloc / 1.0e6,
+                       (double)alloc * 100 / (double)total, free / 1.0e6,
+                       n_alloc, n_free);
+               fprintf(f, "::::::::::::::::::::::::::::::::::::::::\n");
+       }
+       return alloc;
+}
+
 static void
 print_flow_error(struct rte_flow_error error)
 {
@@ -708,6 +770,7 @@ main(int argc, char **argv)
        int ret;
        uint16_t port;
        struct rte_flow_error error;
+       int64_t alloc, last_alloc;
 
        ret = rte_eal_init(argc, argv);
        if (ret < 0)
@@ -718,6 +781,7 @@ main(int argc, char **argv)
        flows_count = DEFAULT_RULES_COUNT;
        iterations_number = DEFAULT_ITERATION;
        delete_flag = false;
+       dump_socket_mem_flag = false;
        flow_group = 0;
 
        signal(SIGINT, signal_handler);
@@ -734,7 +798,13 @@ main(int argc, char **argv)
        if (nb_lcores <= 1)
                rte_exit(EXIT_FAILURE, "This app needs at least two cores\n");
 
+       last_alloc = (int64_t)dump_socket_mem(stdout);
        flows_handler();
+       alloc = (int64_t)dump_socket_mem(stdout);
+
+       if (last_alloc)
+               fprintf(stdout, ":: Memory allocation change(M): %.6lf\n",
+               (alloc - last_alloc) / 1.0e6);
 
        RTE_ETH_FOREACH_DEV(port) {
                rte_flow_flush(port, &error);
diff --git a/doc/guides/rel_notes/release_20_05.rst 
b/doc/guides/rel_notes/release_20_05.rst
index e511e9c1a..aae1c5492 100644
--- a/doc/guides/rel_notes/release_20_05.rst
+++ b/doc/guides/rel_notes/release_20_05.rst
@@ -219,6 +219,7 @@ New Features
   Application features:
   * Measure rte_flow insertion rate.
   * Measure rte_flow deletion rate.
+  * Dump rte_flow memory consumption.
 
 
 Removed Items
diff --git a/doc/guides/tools/flow-perf.rst b/doc/guides/tools/flow-perf.rst
index 1f8b1fa15..c8cce187e 100644
--- a/doc/guides/tools/flow-perf.rst
+++ b/doc/guides/tools/flow-perf.rst
@@ -25,7 +25,8 @@ The current version has limitations which can be removed in 
future:
 * Support outer items up to tunnel layer only.
 * Single core insertion only.
 
-The application also provide the ability to measure rte flow deletion rate.
+The application also provide the ability to measure rte flow deletion rate,
+in addition to memory consumption before and after the flows creation.
 
 
 Compiling the Application
@@ -76,6 +77,9 @@ The command line options are:
 *      ``--deletion-rate``
        Enable deletion rate calculations.
 
+*      ``--dump-socket-mem``
+       Dump the memory stats for each socket before the insertion and after.
+
 Attributes:
 
 *      ``--ingress``
-- 
2.17.1

Reply via email to