- struct mlx5_vdpa_priv *priv = arg;
- int i;
- struct mlx5_vdpa_cq *cq;
- uint32_t max;
- uint64_t current_tic;
-
- pthread_mutex_lock(&priv->timer_lock);
- while (!priv->timer_on)
- pthread_cond_wait(&priv->timer_cond, &priv->timer_lock);
- pthread_mutex_unlock(&priv->timer_lock);
- priv->timer_delay_us = priv->event_mode ==
- MLX5_VDPA_EVENT_MODE_DYNAMIC_TIMER ?
- MLX5_VDPA_DEFAULT_TIMER_DELAY_US :
- priv->event_us;
- while (1) {
- max = 0;
- pthread_mutex_lock(&priv->vq_config_lock);
- for (i = 0; i < priv->nr_virtqs; i++) {
- cq = &priv->virtqs[i].eqp.cq;
- if (cq->cq && !cq->armed) {
- uint32_t comp = mlx5_vdpa_cq_poll(cq);
-
- if (comp) {
- /* Notify guest for descs consuming. */
- if (cq->callfd != -1)
- eventfd_write(cq->callfd,
- (eventfd_t)1);
- if (comp > max)
- max = comp;
- }
- }
- }
- current_tic = rte_rdtsc();
- if (!max) {
- /* No traffic ? stop timer and load interrupts. */
- if (current_tic - priv->last_traffic_tic >=
- rte_get_timer_hz() * priv->no_traffic_time_s) {
- DRV_LOG(DEBUG, "Device %s traffic was stopped.",
- priv->vdev->device->name);
- mlx5_vdpa_arm_all_cqs(priv);
- pthread_mutex_unlock(&priv->vq_config_lock);
- pthread_mutex_lock(&priv->timer_lock);
- priv->timer_on = 0;
- while (!priv->timer_on)
- pthread_cond_wait(&priv->timer_cond,
- &priv->timer_lock);
- pthread_mutex_unlock(&priv->timer_lock);
- priv->timer_delay_us = priv->event_mode ==
- MLX5_VDPA_EVENT_MODE_DYNAMIC_TIMER ?
- MLX5_VDPA_DEFAULT_TIMER_DELAY_US :
- priv->event_us;
- continue;
- }
- } else {
- priv->last_traffic_tic = current_tic;