* Create and initialize a new counter pool. * * @param[in] dev * Pointer to the Ethernet device structure. * @param[out] dcs * The devX counter handle. * @param[in] age * Whether the pool is for counter that was allocated for aging. * * @return * The pool container pointer on success, NULL otherwise and rte_errno is set. */
| 6500 | * The pool container pointer on success, NULL otherwise and rte_errno is set. |
| 6501 | */ |
| 6502 | static struct mlx5_flow_counter_pool * |
| 6503 | flow_dv_pool_create(struct rte_eth_dev *dev, struct mlx5_devx_obj *dcs, |
| 6504 | uint32_t age) |
| 6505 | { |
| 6506 | struct mlx5_priv *priv = dev->data->dev_private; |
| 6507 | struct mlx5_flow_counter_pool *pool; |
| 6508 | struct mlx5_flow_counter_mng *cmng = &priv->sh->sws_cmng; |
| 6509 | bool fallback = cmng->counter_fallback; |
| 6510 | uint32_t size = sizeof(*pool); |
| 6511 | |
| 6512 | if (cmng->n_valid == MLX5_COUNTER_POOLS_MAX_NUM) { |
| 6513 | DRV_LOG(ERR, "All counter is in used, try again later."); |
| 6514 | rte_errno = EAGAIN; |
| 6515 | return NULL; |
| 6516 | } |
| 6517 | size += MLX5_COUNTERS_PER_POOL * MLX5_CNT_SIZE; |
| 6518 | size += (!age ? 0 : MLX5_COUNTERS_PER_POOL * MLX5_AGE_SIZE); |
| 6519 | pool = mlx5_malloc(MLX5_MEM_ZERO, size, 0, SOCKET_ID_ANY); |
| 6520 | if (!pool) { |
| 6521 | rte_errno = ENOMEM; |
| 6522 | return NULL; |
| 6523 | } |
| 6524 | pool->raw = NULL; |
| 6525 | pool->is_aged = !!age; |
| 6526 | pool->query_gen = 0; |
| 6527 | pool->min_dcs = dcs; |
| 6528 | rte_spinlock_init(&pool->sl); |
| 6529 | rte_spinlock_init(&pool->csl); |
| 6530 | TAILQ_INIT(&pool->counters[0]); |
| 6531 | TAILQ_INIT(&pool->counters[1]); |
| 6532 | pool->time_of_last_age_check = MLX5_CURR_TIME_SEC; |
| 6533 | rte_spinlock_lock(&cmng->pool_update_sl); |
| 6534 | pool->index = cmng->n_valid; |
| 6535 | cmng->pools[pool->index] = pool; |
| 6536 | cmng->n_valid++; |
| 6537 | if (unlikely(fallback)) { |
| 6538 | int base = RTE_ALIGN_FLOOR(dcs->id, MLX5_COUNTERS_PER_POOL); |
| 6539 | |
| 6540 | if (base < cmng->min_id) |
| 6541 | cmng->min_id = base; |
| 6542 | if (base > cmng->max_id) |
| 6543 | cmng->max_id = base + MLX5_COUNTERS_PER_POOL - 1; |
| 6544 | cmng->last_pool_idx = pool->index; |
| 6545 | } |
| 6546 | rte_spinlock_unlock(&cmng->pool_update_sl); |
| 6547 | return pool; |
| 6548 | } |
| 6549 | |
| 6550 | /** |
| 6551 | * Prepare a new counter and/or a new counter pool. |
no test coverage detected