examples/ip_pipeline: add stats read commands
authorJasvinder Singh <jasvinder.singh@intel.com>
Thu, 29 Mar 2018 18:31:53 +0000 (19:31 +0100)
committerCristian Dumitrescu <cristian.dumitrescu@intel.com>
Thu, 5 Apr 2018 17:00:18 +0000 (19:00 +0200)
Add commands to read the pipeline  port in, port out
and table stats.

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
Signed-off-by: Jasvinder Singh <jasvinder.singh@intel.com>
Signed-off-by: Fan Zhang <roy.fan.zhang@intel.com>
examples/ip_pipeline/cli.c
examples/ip_pipeline/pipeline.h
examples/ip_pipeline/thread.c

index c3adc17..33babb5 100644 (file)
@@ -1937,6 +1937,83 @@ cmd_pipeline_port_in_table(char **tokens,
        }
 }
 
+/**
+ * pipeline <pipeline_name> port in <port_id> stats read [clear]
+ */
+
+#define MSG_PIPELINE_PORT_IN_STATS                         \
+       "Pkts in: %" PRIu64 "\n"                           \
+       "Pkts dropped by AH: %" PRIu64 "\n"                \
+       "Pkts dropped by other: %" PRIu64 "\n"
+
+static void
+cmd_pipeline_port_in_stats(char **tokens,
+       uint32_t n_tokens,
+       char *out,
+       size_t out_size)
+{
+       struct rte_pipeline_port_in_stats stats;
+       char *pipeline_name;
+       uint32_t port_id;
+       int clear, status;
+
+       if ((n_tokens != 7) && (n_tokens != 8)) {
+               snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+               return;
+       }
+
+       pipeline_name = tokens[1];
+
+       if (strcmp(tokens[2], "port") != 0) {
+               snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
+               return;
+       }
+
+       if (strcmp(tokens[3], "in") != 0) {
+               snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
+               return;
+       }
+
+       if (parser_read_uint32(&port_id, tokens[4]) != 0) {
+               snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
+               return;
+       }
+
+       if (strcmp(tokens[5], "stats") != 0) {
+               snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
+               return;
+       }
+
+       if (strcmp(tokens[6], "read") != 0) {
+               snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
+               return;
+       }
+
+       clear = 0;
+       if (n_tokens == 8) {
+               if (strcmp(tokens[7], "clear") != 0) {
+                       snprintf(out, out_size, MSG_ARG_INVALID, "clear");
+                       return;
+               }
+
+               clear = 1;
+       }
+
+       status = pipeline_port_in_stats_read(pipeline_name,
+               port_id,
+               &stats,
+               clear);
+       if (status) {
+               snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
+               return;
+       }
+
+       snprintf(out, out_size, MSG_PIPELINE_PORT_IN_STATS,
+               stats.stats.n_pkts_in,
+               stats.n_pkts_dropped_by_ah,
+               stats.stats.n_pkts_drop);
+}
+
 /**
  * pipeline <pipeline_name> port in <port_id> enable
  */
@@ -2031,6 +2108,159 @@ cmd_pipeline_port_in_disable(char **tokens,
        }
 }
 
+/**
+ * pipeline <pipeline_name> port out <port_id> stats read [clear]
+ */
+#define MSG_PIPELINE_PORT_OUT_STATS                        \
+       "Pkts in: %" PRIu64 "\n"                           \
+       "Pkts dropped by AH: %" PRIu64 "\n"                \
+       "Pkts dropped by other: %" PRIu64 "\n"
+
+static void
+cmd_pipeline_port_out_stats(char **tokens,
+       uint32_t n_tokens,
+       char *out,
+       size_t out_size)
+{
+       struct rte_pipeline_port_out_stats stats;
+       char *pipeline_name;
+       uint32_t port_id;
+       int clear, status;
+
+       if ((n_tokens != 7) && (n_tokens != 8)) {
+               snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+               return;
+       }
+
+       pipeline_name = tokens[1];
+
+       if (strcmp(tokens[2], "port") != 0) {
+               snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
+               return;
+       }
+
+       if (strcmp(tokens[3], "out") != 0) {
+               snprintf(out, out_size, MSG_ARG_NOT_FOUND, "out");
+               return;
+       }
+
+       if (parser_read_uint32(&port_id, tokens[4]) != 0) {
+               snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
+               return;
+       }
+
+       if (strcmp(tokens[5], "stats") != 0) {
+               snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
+               return;
+       }
+
+       if (strcmp(tokens[6], "read") != 0) {
+               snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
+               return;
+       }
+
+       clear = 0;
+       if (n_tokens == 8) {
+               if (strcmp(tokens[7], "clear") != 0) {
+                       snprintf(out, out_size, MSG_ARG_INVALID, "clear");
+                       return;
+               }
+
+               clear = 1;
+       }
+
+       status = pipeline_port_out_stats_read(pipeline_name,
+               port_id,
+               &stats,
+               clear);
+       if (status) {
+               snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
+               return;
+       }
+
+       snprintf(out, out_size, MSG_PIPELINE_PORT_OUT_STATS,
+               stats.stats.n_pkts_in,
+               stats.n_pkts_dropped_by_ah,
+               stats.stats.n_pkts_drop);
+}
+
+/**
+ * pipeline <pipeline_name> table <table_id> stats read [clear]
+ */
+#define MSG_PIPELINE_TABLE_STATS                                     \
+       "Pkts in: %" PRIu64 "\n"                                     \
+       "Pkts in with lookup miss: %" PRIu64 "\n"                    \
+       "Pkts in with lookup hit dropped by AH: %" PRIu64 "\n"       \
+       "Pkts in with lookup hit dropped by others: %" PRIu64 "\n"   \
+       "Pkts in with lookup miss dropped by AH: %" PRIu64 "\n"      \
+       "Pkts in with lookup miss dropped by others: %" PRIu64 "\n"
+
+static void
+cmd_pipeline_table_stats(char **tokens,
+       uint32_t n_tokens,
+       char *out,
+       size_t out_size)
+{
+       struct rte_pipeline_table_stats stats;
+       char *pipeline_name;
+       uint32_t table_id;
+       int clear, status;
+
+       if ((n_tokens != 6) && (n_tokens != 7)) {
+               snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+               return;
+       }
+
+       pipeline_name = tokens[1];
+
+       if (strcmp(tokens[2], "table") != 0) {
+               snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
+               return;
+       }
+
+       if (parser_read_uint32(&table_id, tokens[3]) != 0) {
+               snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
+               return;
+       }
+
+       if (strcmp(tokens[4], "stats") != 0) {
+               snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
+               return;
+       }
+
+       if (strcmp(tokens[5], "read") != 0) {
+               snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
+               return;
+       }
+
+       clear = 0;
+       if (n_tokens == 7) {
+               if (strcmp(tokens[6], "clear") != 0) {
+                       snprintf(out, out_size, MSG_ARG_INVALID, "clear");
+                       return;
+               }
+
+               clear = 1;
+       }
+
+       status = pipeline_table_stats_read(pipeline_name,
+               table_id,
+               &stats,
+               clear);
+       if (status) {
+               snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
+               return;
+       }
+
+       snprintf(out, out_size, MSG_PIPELINE_TABLE_STATS,
+               stats.stats.n_pkts_in,
+               stats.stats.n_pkts_lookup_miss,
+               stats.n_pkts_dropped_by_lkp_hit_ah,
+               stats.n_pkts_dropped_lkp_hit,
+               stats.n_pkts_dropped_by_lkp_miss_ah,
+               stats.n_pkts_dropped_lkp_miss);
+}
+
 /**
  * thread <thread_id> pipeline <pipeline_name> enable
  */
@@ -2243,6 +2473,15 @@ cli_process(char *in, char *out, size_t out_size)
                        return;
                }
 
+               if ((n_tokens >= 6) &&
+                       (strcmp(tokens[2], "port") == 0) &&
+                       (strcmp(tokens[3], "in") == 0) &&
+                       (strcmp(tokens[5], "stats") == 0)) {
+                       cmd_pipeline_port_in_stats(tokens, n_tokens,
+                               out, out_size);
+                       return;
+               }
+
                if ((n_tokens >= 6) &&
                        (strcmp(tokens[2], "port") == 0) &&
                        (strcmp(tokens[3], "in") == 0) &&
@@ -2260,6 +2499,23 @@ cli_process(char *in, char *out, size_t out_size)
                                out, out_size);
                        return;
                }
+
+               if ((n_tokens >= 6) &&
+                       (strcmp(tokens[2], "port") == 0) &&
+                       (strcmp(tokens[3], "out") == 0) &&
+                       (strcmp(tokens[5], "stats") == 0)) {
+                       cmd_pipeline_port_out_stats(tokens, n_tokens,
+                               out, out_size);
+                       return;
+               }
+
+               if ((n_tokens >= 5) &&
+                       (strcmp(tokens[2], "table") == 0) &&
+                       (strcmp(tokens[4], "stats") == 0)) {
+                       cmd_pipeline_table_stats(tokens, n_tokens,
+                               out, out_size);
+                       return;
+               }
        }
 
        if (strcmp(tokens[0], "thread") == 0) {
index 08b2555..5757eb5 100644 (file)
@@ -269,6 +269,12 @@ struct table_rule_action {
        struct rte_table_action_time_params time;
 };
 
+int
+pipeline_port_in_stats_read(const char *pipeline_name,
+       uint32_t port_id,
+       struct rte_pipeline_port_in_stats *stats,
+       int clear);
+
 int
 pipeline_port_in_enable(const char *pipeline_name,
        uint32_t port_id);
@@ -277,4 +283,16 @@ int
 pipeline_port_in_disable(const char *pipeline_name,
        uint32_t port_id);
 
+int
+pipeline_port_out_stats_read(const char *pipeline_name,
+       uint32_t port_id,
+       struct rte_pipeline_port_out_stats *stats,
+       int clear);
+
+int
+pipeline_table_stats_read(const char *pipeline_name,
+       uint32_t table_id,
+       struct rte_pipeline_table_stats *stats,
+       int clear);
+
 #endif /* _INCLUDE_PIPELINE_H_ */
index 35c4de3..b1a2926 100644 (file)
@@ -479,19 +479,64 @@ thread_msg_handle(struct thread_data *t)
  */
 enum pipeline_req_type {
        /* Port IN */
+       PIPELINE_REQ_PORT_IN_STATS_READ,
        PIPELINE_REQ_PORT_IN_ENABLE,
        PIPELINE_REQ_PORT_IN_DISABLE,
 
+       /* Port OUT */
+       PIPELINE_REQ_PORT_OUT_STATS_READ,
+
+       /* Table */
+       PIPELINE_REQ_TABLE_STATS_READ,
+
        PIPELINE_REQ_MAX
 };
 
+struct pipeline_msg_req_port_in_stats_read {
+       int clear;
+};
+
+struct pipeline_msg_req_port_out_stats_read {
+       int clear;
+};
+
+struct pipeline_msg_req_table_stats_read {
+       int clear;
+};
+
 struct pipeline_msg_req {
        enum pipeline_req_type type;
        uint32_t id; /* Port IN, port OUT or table ID */
+
+       RTE_STD_C11
+       union {
+               struct pipeline_msg_req_port_in_stats_read port_in_stats_read;
+               struct pipeline_msg_req_port_out_stats_read port_out_stats_read;
+               struct pipeline_msg_req_table_stats_read table_stats_read;
+       };
+};
+
+struct pipeline_msg_rsp_port_in_stats_read {
+       struct rte_pipeline_port_in_stats stats;
+};
+
+struct pipeline_msg_rsp_port_out_stats_read {
+       struct rte_pipeline_port_out_stats stats;
+};
+
+struct pipeline_msg_rsp_table_stats_read {
+       struct rte_pipeline_table_stats stats;
 };
 
 struct pipeline_msg_rsp {
        int status;
+
+       RTE_STD_C11
+       union {
+               struct pipeline_msg_rsp_port_in_stats_read port_in_stats_read;
+               struct pipeline_msg_rsp_port_out_stats_read port_out_stats_read;
+               struct pipeline_msg_rsp_table_stats_read table_stats_read;
+       };
 };
 
 /**
@@ -534,6 +579,54 @@ pipeline_msg_send_recv(struct pipeline *p,
        return rsp;
 }
 
+int
+pipeline_port_in_stats_read(const char *pipeline_name,
+       uint32_t port_id,
+       struct rte_pipeline_port_in_stats *stats,
+       int clear)
+{
+       struct pipeline *p;
+       struct pipeline_msg_req *req;
+       struct pipeline_msg_rsp *rsp;
+       int status;
+
+       /* Check input params */
+       if ((pipeline_name == NULL) ||
+               (stats == NULL))
+               return -1;
+
+       p = pipeline_find(pipeline_name);
+       if ((p == NULL) ||
+               (p->enabled == 0) ||
+               (port_id >= p->n_ports_in))
+               return -1;
+
+       /* Allocate request */
+       req = pipeline_msg_alloc();
+       if (req == NULL)
+               return -1;
+
+       /* Write request */
+       req->type = PIPELINE_REQ_PORT_IN_STATS_READ;
+       req->id = port_id;
+       req->port_in_stats_read.clear = clear;
+
+       /* Send request and wait for response */
+       rsp = pipeline_msg_send_recv(p, req);
+       if (rsp == NULL)
+               return -1;
+
+       /* Read response */
+       status = rsp->status;
+       if (status)
+               memcpy(stats, &rsp->port_in_stats_read.stats, sizeof(*stats));
+
+       /* Free response */
+       pipeline_msg_free(rsp);
+
+       return status;
+}
+
 int
 pipeline_port_in_enable(const char *pipeline_name,
        uint32_t port_id)
@@ -618,6 +711,101 @@ pipeline_port_in_disable(const char *pipeline_name,
        return status;
 }
 
+int
+pipeline_port_out_stats_read(const char *pipeline_name,
+       uint32_t port_id,
+       struct rte_pipeline_port_out_stats *stats,
+       int clear)
+{
+       struct pipeline *p;
+       struct pipeline_msg_req *req;
+       struct pipeline_msg_rsp *rsp;
+       int status;
+
+       /* Check input params */
+       if ((pipeline_name == NULL) ||
+               (stats == NULL))
+               return -1;
+
+       p = pipeline_find(pipeline_name);
+       if ((p == NULL) ||
+               (p->enabled == 0) ||
+               (port_id >= p->n_ports_out))
+               return -1;
+
+       /* Allocate request */
+       req = pipeline_msg_alloc();
+       if (req == NULL)
+               return -1;
+
+       /* Write request */
+       req->type = PIPELINE_REQ_PORT_OUT_STATS_READ;
+       req->id = port_id;
+       req->port_out_stats_read.clear = clear;
+
+       /* Send request and wait for response */
+       rsp = pipeline_msg_send_recv(p, req);
+       if (rsp == NULL)
+               return -1;
+
+       /* Read response */
+       status = rsp->status;
+       if (status)
+               memcpy(stats, &rsp->port_out_stats_read.stats, sizeof(*stats));
+
+       /* Free response */
+       pipeline_msg_free(rsp);
+
+       return status;
+}
+
+int
+pipeline_table_stats_read(const char *pipeline_name,
+       uint32_t table_id,
+       struct rte_pipeline_table_stats *stats,
+       int clear)
+{
+       struct pipeline *p;
+       struct pipeline_msg_req *req;
+       struct pipeline_msg_rsp *rsp;
+       int status;
+
+       /* Check input params */
+       if ((pipeline_name == NULL) ||
+               (stats == NULL))
+               return -1;
+
+       p = pipeline_find(pipeline_name);
+       if ((p == NULL) ||
+               (p->enabled == 0) ||
+               (table_id >= p->n_tables))
+               return -1;
+
+       /* Allocate request */
+       req = pipeline_msg_alloc();
+       if (req == NULL)
+               return -1;
+
+       /* Write request */
+       req->type = PIPELINE_REQ_TABLE_STATS_READ;
+       req->id = table_id;
+       req->table_stats_read.clear = clear;
+
+       /* Send request and wait for response */
+       rsp = pipeline_msg_send_recv(p, req);
+       if (rsp == NULL)
+               return -1;
+
+       /* Read response */
+       status = rsp->status;
+       if (status)
+               memcpy(stats, &rsp->table_stats_read.stats, sizeof(*stats));
+
+       /* Free response */
+       pipeline_msg_free(rsp);
+
+       return status;
+}
 
 /**
  * Data plane threads: message handling
@@ -646,6 +834,22 @@ pipeline_msg_send(struct rte_ring *msgq_rsp,
        } while (status == -ENOBUFS);
 }
 
+static struct pipeline_msg_rsp *
+pipeline_msg_handle_port_in_stats_read(struct pipeline_data *p,
+       struct pipeline_msg_req *req)
+{
+       struct pipeline_msg_rsp *rsp = (struct pipeline_msg_rsp *) req;
+       uint32_t port_id = req->id;
+       int clear = req->port_in_stats_read.clear;
+
+       rsp->status = rte_pipeline_port_in_stats_read(p->p,
+               port_id,
+               &rsp->port_in_stats_read.stats,
+               clear);
+
+       return rsp;
+}
+
 static struct pipeline_msg_rsp *
 pipeline_msg_handle_port_in_enable(struct pipeline_data *p,
        struct pipeline_msg_req *req)
@@ -672,6 +876,38 @@ pipeline_msg_handle_port_in_disable(struct pipeline_data *p,
        return rsp;
 }
 
+static struct pipeline_msg_rsp *
+pipeline_msg_handle_port_out_stats_read(struct pipeline_data *p,
+       struct pipeline_msg_req *req)
+{
+       struct pipeline_msg_rsp *rsp = (struct pipeline_msg_rsp *) req;
+       uint32_t port_id = req->id;
+       int clear = req->port_out_stats_read.clear;
+
+       rsp->status = rte_pipeline_port_out_stats_read(p->p,
+               port_id,
+               &rsp->port_out_stats_read.stats,
+               clear);
+
+       return rsp;
+}
+
+static struct pipeline_msg_rsp *
+pipeline_msg_handle_table_stats_read(struct pipeline_data *p,
+       struct pipeline_msg_req *req)
+{
+       struct pipeline_msg_rsp *rsp = (struct pipeline_msg_rsp *) req;
+       uint32_t port_id = req->id;
+       int clear = req->table_stats_read.clear;
+
+       rsp->status = rte_pipeline_table_stats_read(p->p,
+               port_id,
+               &rsp->table_stats_read.stats,
+               clear);
+
+       return rsp;
+}
+
 static void
 pipeline_msg_handle(struct pipeline_data *p)
 {
@@ -684,6 +920,10 @@ pipeline_msg_handle(struct pipeline_data *p)
                        break;
 
                switch (req->type) {
+               case PIPELINE_REQ_PORT_IN_STATS_READ:
+                       rsp = pipeline_msg_handle_port_in_stats_read(p, req);
+                       break;
+
                case PIPELINE_REQ_PORT_IN_ENABLE:
                        rsp = pipeline_msg_handle_port_in_enable(p, req);
                        break;
@@ -692,6 +932,15 @@ pipeline_msg_handle(struct pipeline_data *p)
                        rsp = pipeline_msg_handle_port_in_disable(p, req);
                        break;
 
+               case PIPELINE_REQ_PORT_OUT_STATS_READ:
+                       rsp = pipeline_msg_handle_port_out_stats_read(p, req);
+                       break;
+
+               case PIPELINE_REQ_TABLE_STATS_READ:
+                       rsp = pipeline_msg_handle_table_stats_read(p, req);
+                       break;
+
+
                default:
                        rsp = (struct pipeline_msg_rsp *) req;
                        rsp->status = -1;