Exemplo n.º 1
0
static int dpdk_helper_stats_count_get(dpdk_helper_ctx_t *phc) {
  uint8_t ports = dpdk_helper_eth_dev_count();
  if (ports == 0)
    return -ENODEV;

  dpdk_stats_ctx_t *ctx = DPDK_STATS_CTX_GET(phc);
  ctx->ports_count = ports;

  int len = 0;
  int stats_count = 0;
  for (int i = 0; i < ports; i++) {
    if (!(ctx->config.enabled_port_mask & (1 << i)))
      continue;
#if RTE_VERSION >= RTE_VERSION_16_07
    len = rte_eth_xstats_get_names(i, NULL, 0);
#else
    len = rte_eth_xstats_get(i, NULL, 0);
#endif
    if (len < 0) {
      DPDK_CHILD_LOG("%s: Cannot get stats count\n", DPDK_STATS_PLUGIN);
      return -1;
    }
    ctx->port_stats_count[i] = len;
    stats_count += len;
  }

  DPDK_CHILD_LOG("%s:%s:%d stats_count=%d\n", DPDK_STATS_PLUGIN, __FUNCTION__,
                 __LINE__, stats_count);

  return stats_count;
}
Exemplo n.º 2
0
void
nic_xstats_display(struct cmdline *cl, portid_t port_id, int option)
{
	struct rte_eth_xstats *xstats;
	int len, ret, i;

	len = rte_eth_xstats_get(port_id, NULL, 0);
	if (len < 0) {
		cmdline_printf(cl, "Cannot get xstats count\n");
		return;
	}
	xstats = malloc(sizeof(xstats[0]) * len);
	if (xstats == NULL) {
		cmdline_printf(cl, "Cannot allocate memory for xstats\n");
		return;
	}
	ret = rte_eth_xstats_get(port_id, xstats, len);
	if (ret < 0 || ret > len) {
		cmdline_printf(cl, "Cannot get xstats\n");
		free(xstats);
		return;
	}

	if (option) {

		cmdline_printf(cl, "{\"portid\": %d, ", port_id);

		for (i = 0; i < len; i++)
			cmdline_printf(cl, "%s\"%s\": %" PRIu64,
				       (i != 0) ? ", " : "", xstats[i].name,
				       xstats[i].value);

		cmdline_printf(cl, "}\n");

	} else {
		cmdline_printf(cl,
			       "===== NIC extended statistics for port %-2d\n",
			       port_id);

		for (i = 0; i < len; i++)
			cmdline_printf(cl, "%s: %" PRIu64 "\n", xstats[i].name,
				       xstats[i].value);
	}

	free(xstats);
}
Exemplo n.º 3
0
int
rw_piot_get_extended_stats(rw_piot_api_handle_t api_handle,
                           struct rte_eth_xstats *xstats, unsigned n)
{
  rw_piot_device_t *rw_piot_dev = RWPIOT_GET_DEVICE(api_handle);
  ASSERT(RWPIOT_VALID_DEVICE(rw_piot_dev));
  if (NULL == rw_piot_dev) {
    RW_PIOT_LOG(RTE_LOG_ERR, "PIOT Could not find device by handle or invalid input param\n");
    return -1;
  }
  return rte_eth_xstats_get(rw_piot_dev->rte_port_id,
                            xstats, n);
}
Exemplo n.º 4
0
static int dpdk_helper_stats_get(dpdk_helper_ctx_t *phc) {
  int len = 0;
  int ret = 0;
  int stats = 0;
  dpdk_stats_ctx_t *ctx = DPDK_STATS_CTX_GET(phc);

  /* get stats from DPDK */
  for (uint8_t i = 0; i < ctx->ports_count; i++) {
    if (!(ctx->config.enabled_port_mask & (1 << i)))
      continue;

    ctx->port_read_time[i] = cdtime();
    /* Store available stats array length for port */
    len = ctx->port_stats_count[i];

    ret = rte_eth_xstats_get(i, &ctx->xstats[stats], len);
    if (ret < 0 || ret > len) {
      DPDK_CHILD_LOG(DPDK_STATS_PLUGIN
                     ": Error reading stats (port=%d; len=%d, ret=%d)\n",
                     i, len, ret);
      ctx->port_stats_count[i] = 0;
      return -1;
    }
#if RTE_VERSION >= RTE_VERSION_16_07
    ret = rte_eth_xstats_get_names(i, &ctx->xnames[stats], len);
    if (ret < 0 || ret > len) {
      DPDK_CHILD_LOG(DPDK_STATS_PLUGIN
                     ": Error reading stat names (port=%d; len=%d ret=%d)\n",
                     i, len, ret);
      ctx->port_stats_count[i] = 0;
      return -1;
    }
#endif
    ctx->port_stats_count[i] = ret;
    stats += ctx->port_stats_count[i];
  }

  assert(stats <= ctx->stats_count);
  return 0;
}