diff options
Diffstat (limited to 'drivers/vhost/net.c')
| -rw-r--r-- | drivers/vhost/net.c | 44 | 
1 files changed, 15 insertions, 29 deletions
diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c index df51a35cf537..d57ebdd616d9 100644 --- a/drivers/vhost/net.c +++ b/drivers/vhost/net.c @@ -1,8 +1,7 @@ +// SPDX-License-Identifier: GPL-2.0-only  /* Copyright (C) 2009 Red Hat, Inc.   * Author: Michael S. Tsirkin <[email protected]>   * - * This work is licensed under the terms of the GNU GPL, version 2. - *   * virtio-net server in host kernel.   */ @@ -604,12 +603,6 @@ static size_t init_iov_iter(struct vhost_virtqueue *vq, struct iov_iter *iter,  	return iov_iter_count(iter);  } -static bool vhost_exceeds_weight(int pkts, int total_len) -{ -	return total_len >= VHOST_NET_WEIGHT || -	       pkts >= VHOST_NET_PKT_WEIGHT; -} -  static int get_tx_bufs(struct vhost_net *net,  		       struct vhost_net_virtqueue *nvq,  		       struct msghdr *msg, @@ -779,7 +772,7 @@ static void handle_tx_copy(struct vhost_net *net, struct socket *sock)  	int sent_pkts = 0;  	bool sock_can_batch = (sock->sk->sk_sndbuf == INT_MAX); -	for (;;) { +	do {  		bool busyloop_intr = false;  		if (nvq->done_idx == VHOST_NET_BATCH) @@ -845,11 +838,7 @@ done:  		vq->heads[nvq->done_idx].id = cpu_to_vhost32(vq, head);  		vq->heads[nvq->done_idx].len = 0;  		++nvq->done_idx; -		if (vhost_exceeds_weight(++sent_pkts, total_len)) { -			vhost_poll_queue(&vq->poll); -			break; -		} -	} +	} while (likely(!vhost_exceeds_weight(vq, ++sent_pkts, total_len)));  	vhost_tx_batch(net, nvq, sock, &msg);  } @@ -874,7 +863,7 @@ static void handle_tx_zerocopy(struct vhost_net *net, struct socket *sock)  	bool zcopy_used;  	int sent_pkts = 0; -	for (;;) { +	do {  		bool busyloop_intr;  		/* Release DMAs done buffers first */ @@ -951,11 +940,7 @@ static void handle_tx_zerocopy(struct vhost_net *net, struct socket *sock)  		else  			vhost_zerocopy_signal_used(net, vq);  		vhost_net_tx_packet(net); -		if (unlikely(vhost_exceeds_weight(++sent_pkts, total_len))) { -			vhost_poll_queue(&vq->poll); -			break; -		} -	} +	} while (likely(!vhost_exceeds_weight(vq, ++sent_pkts, total_len)));  }  /* Expects to be always run from workqueue - which acts as @@ -1153,8 +1138,11 @@ static void handle_rx(struct vhost_net *net)  		vq->log : NULL;  	mergeable = vhost_has_feature(vq, VIRTIO_NET_F_MRG_RXBUF); -	while ((sock_len = vhost_net_rx_peek_head_len(net, sock->sk, -						      &busyloop_intr))) { +	do { +		sock_len = vhost_net_rx_peek_head_len(net, sock->sk, +						      &busyloop_intr); +		if (!sock_len) +			break;  		sock_len += sock_hlen;  		vhost_len = sock_len + vhost_hlen;  		headcount = get_rx_bufs(vq, vq->heads + nvq->done_idx, @@ -1239,14 +1227,11 @@ static void handle_rx(struct vhost_net *net)  			vhost_log_write(vq, vq_log, log, vhost_len,  					vq->iov, in);  		total_len += vhost_len; -		if (unlikely(vhost_exceeds_weight(++recv_pkts, total_len))) { -			vhost_poll_queue(&vq->poll); -			goto out; -		} -	} +	} while (likely(!vhost_exceeds_weight(vq, ++recv_pkts, total_len))); +  	if (unlikely(busyloop_intr))  		vhost_poll_queue(&vq->poll); -	else +	else if (!sock_len)  		vhost_net_enable_vq(net, vq);  out:  	vhost_net_signal_used(nvq); @@ -1338,7 +1323,8 @@ static int vhost_net_open(struct inode *inode, struct file *f)  		vhost_net_buf_init(&n->vqs[i].rxq);  	}  	vhost_dev_init(dev, vqs, VHOST_NET_VQ_MAX, -		       UIO_MAXIOV + VHOST_NET_BATCH); +		       UIO_MAXIOV + VHOST_NET_BATCH, +		       VHOST_NET_PKT_WEIGHT, VHOST_NET_WEIGHT);  	vhost_poll_init(n->poll + VHOST_NET_VQ_TX, handle_tx_net, EPOLLOUT, dev);  	vhost_poll_init(n->poll + VHOST_NET_VQ_RX, handle_rx_net, EPOLLIN, dev);  |