Skip to content

Commit

Permalink
vhost: packed ring support
Browse files Browse the repository at this point in the history
This patch introduces basic support for packed ring. The idea behinds
packed ring is to use a single descriptor ring instead of three
different rings (avail, used and descriptor). This could help to
reduce the cache contention and PCI transactions. So it was designed
to help for the performance for both software implementation and
hardware implementation.

The implementation was straightforward, packed version of vhost core
(whose name has a packed suffix) helpers were introduced and previous
helpers were renamed with a split suffix. Then the exported helpers
can just do a switch to go to the correct internal helpers.

The event suppression (device area and driver area) were not
implemented. It will be done on top with another patch.

For more information of packed ring, please refer Virtio spec.

Signed-off-by: Jason Wang <jasowang@redhat.com>
  • Loading branch information
jasowang committed Aug 7, 2018
1 parent bbdf97c commit 9b7b0d7
Show file tree
Hide file tree
Showing 4 changed files with 640 additions and 45 deletions.
12 changes: 7 additions & 5 deletions drivers/vhost/net.c
Expand Up @@ -591,7 +591,7 @@ static void handle_tx(struct vhost_net *net)
nvq->upend_idx = ((unsigned)nvq->upend_idx - 1)
% UIO_MAXIOV;
}
vhost_discard_vq_desc(vq, 1);
vhost_discard_vq_desc(vq, &used, 1);
vhost_net_enable_vq(net, vq);
break;
}
Expand Down Expand Up @@ -755,10 +755,12 @@ static void handle_rx(struct vhost_net *net)

while ((sock_len = vhost_net_rx_peek_head_len(net, sock->sk,
&busyloop_intr))) {
struct vhost_used_elem *used = vq->heads + nvq->done_idx;

sock_len += sock_hlen;
vhost_len = sock_len + vhost_hlen;
err = vhost_get_bufs(vq, vq->heads + nvq->done_idx,
vhost_len, &in, vq_log, &log,
err = vhost_get_bufs(vq, used, vhost_len,
&in, vq_log, &log,
likely(mergeable) ? UIO_MAXIOV : 1,
&headcount);
/* OK, now we need to know about added descriptors. */
Expand Down Expand Up @@ -806,7 +808,7 @@ static void handle_rx(struct vhost_net *net)
if (unlikely(err != sock_len)) {
pr_debug("Discarded rx packet: "
" len %d, expected %zd\n", err, sock_len);
vhost_discard_vq_desc(vq, headcount);
vhost_discard_vq_desc(vq, used, 1);
continue;
}
/* Supply virtio_net_hdr if VHOST_NET_F_VIRTIO_NET_HDR */
Expand All @@ -830,7 +832,7 @@ static void handle_rx(struct vhost_net *net)
copy_to_iter(&num_buffers, sizeof num_buffers,
&fixup) != sizeof num_buffers) {
vq_err(vq, "Failed num_buffers write");
vhost_discard_vq_desc(vq, headcount);
vhost_discard_vq_desc(vq, used, 1);
goto out;
}
nvq->done_idx += headcount;
Expand Down

0 comments on commit 9b7b0d7

Please sign in to comment.