net/sfc: rename array of SW stats descriptions
[dpdk.git] / app / test-flow-perf / main.c
index 0aef767..9be8edc 100644 (file)
@@ -61,6 +61,7 @@ static bool dump_iterations;
 static bool delete_flag;
 static bool dump_socket_mem_flag;
 static bool enable_fwd;
+static bool unique_data;
 
 static struct rte_mempool *mbuf_mp;
 static uint32_t nb_lcores;
@@ -104,8 +105,8 @@ struct used_cpu_time {
 struct multi_cores_pool {
        uint32_t cores_count;
        uint32_t rules_count;
-       struct used_cpu_time create_meter;
-       struct used_cpu_time create_flow;
+       struct used_cpu_time meters_record;
+       struct used_cpu_time flows_record;
        int64_t last_alloc[RTE_MAX_LCORE];
        int64_t current_alloc[RTE_MAX_LCORE];
 } __rte_cache_aligned;
@@ -131,6 +132,8 @@ usage(char *progname)
        printf("  --enable-fwd: To enable packets forwarding"
                " after insertion\n");
        printf("  --portmask=N: hexadecimal bitmask of ports used\n");
+       printf("  --unique-data: flag to set using unique data for all"
+               " actions that support data, such as header modify and encap actions\n");
 
        printf("To set flow attributes:\n");
        printf("  --ingress: set ingress attribute in flows\n");
@@ -567,6 +570,7 @@ args_parse(int argc, char **argv)
                { "deletion-rate",              0, 0, 0 },
                { "dump-socket-mem",            0, 0, 0 },
                { "enable-fwd",                 0, 0, 0 },
+               { "unique-data",                0, 0, 0 },
                { "portmask",                   1, 0, 0 },
                { "cores",                      1, 0, 0 },
                /* Attributes */
@@ -724,7 +728,7 @@ args_parse(int argc, char **argv)
                                        for (i = 0; i < RTE_DIM(flow_options); i++) {
                                                if (strcmp(flow_options[i].str, token) == 0) {
                                                        printf("%s,", token);
-                                                       encap_data |= flow_options[i].mask;
+                                                       decap_data |= flow_options[i].mask;
                                                        break;
                                                }
                                                /* Reached last item with no match */
@@ -762,6 +766,9 @@ args_parse(int argc, char **argv)
                        if (strcmp(lgopts[opt_idx].name,
                                        "dump-iterations") == 0)
                                dump_iterations = true;
+                       if (strcmp(lgopts[opt_idx].name,
+                                       "unique-data") == 0)
+                               unique_data = true;
                        if (strcmp(lgopts[opt_idx].name,
                                        "deletion-rate") == 0)
                                delete_flag = true;
@@ -921,13 +928,6 @@ create_meter_rule(int port_id, uint32_t counter)
 
        /*create meter*/
        params.meter_profile_id = default_prof_id;
-       params.action[RTE_COLOR_GREEN] =
-               MTR_POLICER_ACTION_COLOR_GREEN;
-       params.action[RTE_COLOR_YELLOW] =
-               MTR_POLICER_ACTION_COLOR_YELLOW;
-       params.action[RTE_COLOR_RED] =
-               MTR_POLICER_ACTION_DROP;
-
        ret = rte_mtr_create(port_id, counter, &params, 1, &error);
        if (ret != 0) {
                printf("Port %u create meter idx(%d) error(%d) message: %s\n",
@@ -966,7 +966,7 @@ meters_handler(int port_id, uint8_t core_id, uint8_t ops)
        end_counter = (core_id + 1) * rules_count_per_core;
 
        cpu_time_used = 0;
-       start_batch = rte_rdtsc();
+       start_batch = rte_get_timer_cycles();
        for (counter = start_counter; counter < end_counter; counter++) {
                if (ops == METER_CREATE)
                        create_meter_rule(port_id, counter);
@@ -981,10 +981,10 @@ meters_handler(int port_id, uint8_t core_id, uint8_t ops)
                if (!((counter + 1) % rules_batch)) {
                        rules_batch_idx = ((counter + 1) / rules_batch) - 1;
                        cpu_time_per_batch[rules_batch_idx] =
-                               ((double)(rte_rdtsc() - start_batch))
-                               / rte_get_tsc_hz();
+                               ((double)(rte_get_timer_cycles() - start_batch))
+                               / rte_get_timer_hz();
                        cpu_time_used += cpu_time_per_batch[rules_batch_idx];
-                       start_batch = rte_rdtsc();
+                       start_batch = rte_get_timer_cycles();
                }
        }
 
@@ -1003,10 +1003,10 @@ meters_handler(int port_id, uint8_t core_id, uint8_t ops)
                cpu_time_used, insertion_rate);
 
        if (ops == METER_CREATE)
-               mc_pool.create_meter.insertion[port_id][core_id]
+               mc_pool.meters_record.insertion[port_id][core_id]
                        = cpu_time_used;
        else
-               mc_pool.create_meter.deletion[port_id][core_id]
+               mc_pool.meters_record.deletion[port_id][core_id]
                        = cpu_time_used;
 }
 
@@ -1086,7 +1086,7 @@ destroy_flows(int port_id, uint8_t core_id, struct rte_flow **flows_list)
        if (flow_group > 0 && core_id == 0)
                rules_count_per_core++;
 
-       start_batch = rte_rdtsc();
+       start_batch = rte_get_timer_cycles();
        for (i = 0; i < (uint32_t) rules_count_per_core; i++) {
                if (flows_list[i] == 0)
                        break;
@@ -1104,12 +1104,12 @@ destroy_flows(int port_id, uint8_t core_id, struct rte_flow **flows_list)
                 * for this batch.
                 */
                if (!((i + 1) % rules_batch)) {
-                       end_batch = rte_rdtsc();
+                       end_batch = rte_get_timer_cycles();
                        delta = (double) (end_batch - start_batch);
                        rules_batch_idx = ((i + 1) / rules_batch) - 1;
-                       cpu_time_per_batch[rules_batch_idx] = delta / rte_get_tsc_hz();
+                       cpu_time_per_batch[rules_batch_idx] = delta / rte_get_timer_hz();
                        cpu_time_used += cpu_time_per_batch[rules_batch_idx];
-                       start_batch = rte_rdtsc();
+                       start_batch = rte_get_timer_cycles();
                }
        }
 
@@ -1124,7 +1124,7 @@ destroy_flows(int port_id, uint8_t core_id, struct rte_flow **flows_list)
        printf(":: Port %d :: Core %d :: The time for deleting %d rules is %f seconds\n",
                port_id, core_id, rules_count_per_core, cpu_time_used);
 
-       mc_pool.create_flow.deletion[port_id][core_id] = cpu_time_used;
+       mc_pool.flows_record.deletion[port_id][core_id] = cpu_time_used;
 }
 
 static struct rte_flow **
@@ -1133,6 +1133,7 @@ insert_flows(int port_id, uint8_t core_id)
        struct rte_flow **flows_list;
        struct rte_flow_error error;
        clock_t start_batch, end_batch;
+       double first_flow_latency;
        double cpu_time_used;
        double insertion_rate;
        double cpu_time_per_batch[MAX_BATCHES_COUNT] = { 0 };
@@ -1173,7 +1174,7 @@ insert_flows(int port_id, uint8_t core_id)
                 */
                flow = generate_flow(port_id, 0, flow_attrs,
                        global_items, global_actions,
-                       flow_group, 0, 0, 0, 0, core_id, &error);
+                       flow_group, 0, 0, 0, 0, core_id, unique_data, &error);
 
                if (flow == NULL) {
                        print_flow_error(error);
@@ -1182,14 +1183,24 @@ insert_flows(int port_id, uint8_t core_id)
                flows_list[flow_index++] = flow;
        }
 
-       start_batch = rte_rdtsc();
+       start_batch = rte_get_timer_cycles();
        for (counter = start_counter; counter < end_counter; counter++) {
                flow = generate_flow(port_id, flow_group,
                        flow_attrs, flow_items, flow_actions,
                        JUMP_ACTION_TABLE, counter,
                        hairpin_queues_num,
                        encap_data, decap_data,
-                       core_id, &error);
+                       core_id, unique_data, &error);
+
+               if (!counter) {
+                       first_flow_latency = (double) (rte_get_timer_cycles() - start_batch);
+                       first_flow_latency /= rte_get_timer_hz();
+                       /* In millisecond */
+                       first_flow_latency *= 1000;
+                       printf(":: First Flow Latency :: Port %d :: First flow "
+                               "installed in %f milliseconds\n",
+                               port_id, first_flow_latency);
+               }
 
                if (force_quit)
                        counter = end_counter;
@@ -1208,12 +1219,12 @@ insert_flows(int port_id, uint8_t core_id)
                 * for this batch.
                 */
                if (!((counter + 1) % rules_batch)) {
-                       end_batch = rte_rdtsc();
+                       end_batch = rte_get_timer_cycles();
                        delta = (double) (end_batch - start_batch);
                        rules_batch_idx = ((counter + 1) / rules_batch) - 1;
-                       cpu_time_per_batch[rules_batch_idx] = delta / rte_get_tsc_hz();
+                       cpu_time_per_batch[rules_batch_idx] = delta / rte_get_timer_hz();
                        cpu_time_used += cpu_time_per_batch[rules_batch_idx];
-                       start_batch = rte_rdtsc();
+                       start_batch = rte_get_timer_cycles();
                }
        }
 
@@ -1231,7 +1242,7 @@ insert_flows(int port_id, uint8_t core_id)
        printf(":: Port %d :: Core %d :: The time for creating %d in rules %f seconds\n",
                port_id, core_id, rules_count_per_core, cpu_time_used);
 
-       mc_pool.create_flow.insertion[port_id][core_id] = cpu_time_used;
+       mc_pool.flows_record.insertion[port_id][core_id] = cpu_time_used;
        return flows_list;
 }
 
@@ -1427,11 +1438,14 @@ run_rte_flow_handler_cores(void *data __rte_unused)
        rte_eal_mp_wait_lcore();
 
        RTE_ETH_FOREACH_DEV(port) {
+               /* If port outside portmask */
+               if (!((ports_mask >> port) & 0x1))
+                       continue;
                if (has_meter())
                        dump_used_cpu_time("Meters:",
-                               port, &mc_pool.create_meter);
+                               port, &mc_pool.meters_record);
                dump_used_cpu_time("Flows:",
-                       port, &mc_pool.create_flow);
+                       port, &mc_pool.flows_record);
                dump_used_mem(port);
        }
 
@@ -1860,6 +1874,7 @@ main(int argc, char **argv)
        delete_flag = false;
        dump_socket_mem_flag = false;
        flow_group = DEFAULT_GROUP;
+       unique_data = false;
 
        signal(SIGINT, signal_handler);
        signal(SIGTERM, signal_handler);
@@ -1875,7 +1890,6 @@ main(int argc, char **argv)
        if (nb_lcores <= 1)
                rte_exit(EXIT_FAILURE, "This app needs at least two cores\n");
 
-
        printf(":: Flows Count per port: %d\n\n", rules_count);
 
        if (has_meter())