- rte_atomic_thread_fence(__ATOMIC_RELEASE);
-
- while (likely((n_pkts_put < count) && n_inflight)) {
- uint16_t info_idx = (start_idx + n_pkts_put) & (vq_size - 1);
- if (n_pkts_cpl && pkts_info[info_idx].segs)
- n_pkts_cpl--;
- else if (!n_pkts_cpl && pkts_info[info_idx].segs)
- break;
- n_pkts_put++;
- n_inflight--;
- n_descs += pkts_info[info_idx].descs;
- }
-
- vq->async_last_pkts_n = n_pkts_cpl;
+ n_pkts_put = RTE_MIN(count, n_pkts_cpl);
+ if (unlikely(n_pkts_put == 0)) {
+ vq->async_last_pkts_n = n_pkts_cpl;
+ goto done;
+ }
+
+ for (i = 0; i < n_pkts_put; i++) {
+ from = (start_idx + i) & (vq_size - 1);
+ n_descs += pkts_info[from].descs;
+ pkts[i] = pkts_info[from].mbuf;
+ }
+ vq->async_last_pkts_n = n_pkts_cpl - n_pkts_put;
+ vq->async_pkts_inflight_n -= n_pkts_put;
+
+ if (likely(vq->enabled && vq->access_ok)) {
+ uint16_t nr_left = n_descs;
+ uint16_t nr_copy;
+ uint16_t to;
+
+ /* write back completed descriptors to used ring */
+ do {
+ from = vq->last_async_desc_idx & (vq->size - 1);
+ nr_copy = nr_left + from <= vq->size ? nr_left :
+ vq->size - from;
+ to = vq->last_used_idx & (vq->size - 1);
+
+ if (to + nr_copy <= vq->size) {
+ rte_memcpy(&vq->used->ring[to],
+ &vq->async_descs_split[from],
+ nr_copy *
+ sizeof(struct vring_used_elem));
+ } else {
+ uint16_t size = vq->size - to;
+
+ rte_memcpy(&vq->used->ring[to],
+ &vq->async_descs_split[from],
+ size *
+ sizeof(struct vring_used_elem));
+ rte_memcpy(vq->used->ring,
+ &vq->async_descs_split[from +
+ size], (nr_copy - size) *
+ sizeof(struct vring_used_elem));
+ }