- int ret,nb_item,i;
- struct cmd_set_mirror_mask_result *res = parsed_result;
- struct rte_eth_mirror_conf mr_conf;
-
- memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
-
- unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
-
- mr_conf.dst_pool = res->dstpool_id;
-
- if (!strcmp(res->what, "pool-mirror-up")) {
- mr_conf.pool_mask = strtoull(res->value, NULL, 16);
- mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
- } else if (!strcmp(res->what, "pool-mirror-down")) {
- mr_conf.pool_mask = strtoull(res->value, NULL, 16);
- mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
- } else if (!strcmp(res->what, "vlan-mirror")) {
- mr_conf.rule_type = ETH_MIRROR_VLAN;
- nb_item = parse_item_list(res->value, "vlan",
- ETH_MIRROR_MAX_VLANS, vlan_list, 1);
- if (nb_item <= 0)
- return;
-
- for (i = 0; i < nb_item; i++) {
- if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
- printf("Invalid vlan_id: must be < 4096\n");
- return;
- }
-
- mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
- mr_conf.vlan.vlan_mask |= 1ULL << i;
- }
- }
-
- if (!strcmp(res->on, "on"))
- ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
- res->rule_id, 1);
- else
- ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
- res->rule_id, 0);
- if (ret < 0)
- printf("mirror rule add error: (%s)\n", strerror(-ret));
-}
-
-cmdline_parse_inst_t cmd_set_mirror_mask = {
- .f = cmd_set_mirror_mask_parsed,
- .data = NULL,
- .help_str = "set port <port_id> mirror-rule <rule_id> "
- "pool-mirror-up|pool-mirror-down|vlan-mirror "
- "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
- .tokens = {
- (void *)&cmd_mirror_mask_set,
- (void *)&cmd_mirror_mask_port,
- (void *)&cmd_mirror_mask_portid,
- (void *)&cmd_mirror_mask_mirror,
- (void *)&cmd_mirror_mask_ruleid,
- (void *)&cmd_mirror_mask_what,
- (void *)&cmd_mirror_mask_value,
- (void *)&cmd_mirror_mask_dstpool,
- (void *)&cmd_mirror_mask_poolid,
- (void *)&cmd_mirror_mask_on,
- NULL,
- },
-};
-
-/* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
-struct cmd_set_mirror_link_result {
- cmdline_fixed_string_t set;
- cmdline_fixed_string_t port;
- portid_t port_id;
- cmdline_fixed_string_t mirror;
- uint8_t rule_id;
- cmdline_fixed_string_t what;
- cmdline_fixed_string_t dstpool;
- uint8_t dstpool_id;
- cmdline_fixed_string_t on;
-};
-
-cmdline_parse_token_string_t cmd_mirror_link_set =
- TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
- set, "set");
-cmdline_parse_token_string_t cmd_mirror_link_port =
- TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
- port, "port");
-cmdline_parse_token_num_t cmd_mirror_link_portid =
- TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
- port_id, UINT16);
-cmdline_parse_token_string_t cmd_mirror_link_mirror =
- TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
- mirror, "mirror-rule");
-cmdline_parse_token_num_t cmd_mirror_link_ruleid =
- TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
- rule_id, UINT8);
-cmdline_parse_token_string_t cmd_mirror_link_what =
- TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
- what, "uplink-mirror#downlink-mirror");
-cmdline_parse_token_string_t cmd_mirror_link_dstpool =
- TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
- dstpool, "dst-pool");
-cmdline_parse_token_num_t cmd_mirror_link_poolid =
- TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
- dstpool_id, UINT8);
-cmdline_parse_token_string_t cmd_mirror_link_on =
- TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
- on, "on#off");
-
-static void
-cmd_set_mirror_link_parsed(void *parsed_result,
- __attribute__((unused)) struct cmdline *cl,
- __attribute__((unused)) void *data)
-{
- int ret;
- struct cmd_set_mirror_link_result *res = parsed_result;
- struct rte_eth_mirror_conf mr_conf;
-
- memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
- if (!strcmp(res->what, "uplink-mirror"))
- mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
- else
- mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
-
- mr_conf.dst_pool = res->dstpool_id;
-
- if (!strcmp(res->on, "on"))
- ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
- res->rule_id, 1);
- else
- ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
- res->rule_id, 0);
-
- /* check the return value and print it if is < 0 */
- if (ret < 0)
- printf("mirror rule add error: (%s)\n", strerror(-ret));
-
-}
-
-cmdline_parse_inst_t cmd_set_mirror_link = {
- .f = cmd_set_mirror_link_parsed,
- .data = NULL,
- .help_str = "set port <port_id> mirror-rule <rule_id> "
- "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
- .tokens = {
- (void *)&cmd_mirror_link_set,
- (void *)&cmd_mirror_link_port,
- (void *)&cmd_mirror_link_portid,
- (void *)&cmd_mirror_link_mirror,
- (void *)&cmd_mirror_link_ruleid,
- (void *)&cmd_mirror_link_what,
- (void *)&cmd_mirror_link_dstpool,
- (void *)&cmd_mirror_link_poolid,
- (void *)&cmd_mirror_link_on,
- NULL,
- },
-};
-
-/* *** RESET VM MIRROR RULE *** */
-struct cmd_rm_mirror_rule_result {
- cmdline_fixed_string_t reset;
- cmdline_fixed_string_t port;
- portid_t port_id;
- cmdline_fixed_string_t mirror;
- uint8_t rule_id;
-};
-
-cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
- TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
- reset, "reset");
-cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
- TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
- port, "port");
-cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
- TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
- port_id, UINT16);
-cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
- TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
- mirror, "mirror-rule");
-cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
- TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
- rule_id, UINT8);
-
-static void
-cmd_reset_mirror_rule_parsed(void *parsed_result,
- __attribute__((unused)) struct cmdline *cl,
- __attribute__((unused)) void *data)
-{
- int ret;
- struct cmd_set_mirror_link_result *res = parsed_result;
- /* check rule_id */
- ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
- if(ret < 0)
- printf("mirror rule remove error: (%s)\n", strerror(-ret));
-}
-
-cmdline_parse_inst_t cmd_reset_mirror_rule = {
- .f = cmd_reset_mirror_rule_parsed,
- .data = NULL,
- .help_str = "reset port <port_id> mirror-rule <rule_id>",
- .tokens = {
- (void *)&cmd_rm_mirror_rule_reset,
- (void *)&cmd_rm_mirror_rule_port,
- (void *)&cmd_rm_mirror_rule_portid,
- (void *)&cmd_rm_mirror_rule_mirror,
- (void *)&cmd_rm_mirror_rule_ruleid,
- NULL,
- },
-};
-
-/* ******************************************************************************** */
-
-struct cmd_dump_result {
- cmdline_fixed_string_t dump;
-};
-
-static void
-dump_struct_sizes(void)
-{
-#define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
- DUMP_SIZE(struct rte_mbuf);
- DUMP_SIZE(struct rte_mempool);
- DUMP_SIZE(struct rte_ring);
-#undef DUMP_SIZE
+ struct rte_malloc_socket_stats socket_stats;
+ unsigned int i;
+ size_t total = 0;
+ size_t alloc = 0;
+ size_t free = 0;
+ unsigned int n_alloc = 0;
+ unsigned int n_free = 0;
+ static size_t last_allocs;
+ static size_t last_total;
+
+
+ for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
+ if (rte_malloc_get_socket_stats(i, &socket_stats) ||
+ !socket_stats.heap_totalsz_bytes)
+ continue;
+ 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;
+ fprintf(f,
+ "Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
+ i,
+ (double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
+ (double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
+ (double)socket_stats.heap_allocsz_bytes * 100 /
+ (double)socket_stats.heap_totalsz_bytes,
+ (double)socket_stats.heap_freesz_bytes / (1024 * 1024),
+ socket_stats.alloc_count,
+ socket_stats.free_count);
+ }
+ fprintf(f,
+ "Total : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
+ (double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
+ total ? ((double)alloc * 100 / (double)total) : 0,
+ (double)free / (1024 * 1024),
+ n_alloc, n_free);
+ if (last_allocs)
+ fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
+ ((double)total - (double)last_total) / (1024 * 1024),
+ (double)(alloc - (double)last_allocs) / 1024 / 1024);
+ last_allocs = alloc;
+ last_total = total;