From: Dor Laor <dor.laor-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: kvm-devel
<kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>,
virtualization
<virtualization-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org>,
Anthony Liguori
<aliguori-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>,
Rusty Russell <rusty-8n+1lVoiYb80n/F98K4Iww@public.gmane.org>,
Subject: [Virtio-for-kvm] [PATCH 6/13] [Mostly resend] virtio additions
Date: Fri, 21 Dec 2007 17:23:40 +0200 [thread overview]
Message-ID: <476BDA7C.6080809@qumranet.com> (raw)
From c1e1126c39fe107f68adec196d4e558a14540939 Mon Sep 17 00:00:00 2001
From: Anthony Liguori <aliguori-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
Date: Mon, 12 Nov 2007 21:30:26 -0600
Subject: [PATCH] virtio: use an hrtimer for tx coalescing.
Not sure why hrtimer's cb_mode only exists with CONFIG_HIGH_RES_TIMERS; that
seems like a bug to me.
Signed-off-by: Rusty Russell <rusty-8n+1lVoiYb80n/F98K4Iww@public.gmane.org>
---
drivers/net/virtio_net.c | 41 ++++++++++++++++++++++++++++++++++++++++-
1 files changed, 40 insertions(+), 1 deletions(-)
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index aff25b0..6526e0b 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -23,6 +23,7 @@
#include <linux/virtio.h>
#include <linux/virtio_net.h>
#include <linux/scatterlist.h>
+#include <linux/hrtimer.h>
/* FIXME: MTU in config. */
#define MAX_PACKET_LEN (ETH_HLEN+ETH_DATA_LEN)
@@ -34,9 +35,15 @@ struct virtnet_info
struct net_device *dev;
struct napi_struct napi;
+ /* TX coalescing. */
+ struct hrtimer tx_timer;
+
/* Number of input buffers, and max we've ever had. */
unsigned int num, max;
+ /* Number of queued output buffers, and max we've ever had. */
+ unsigned int out_num, out_max;
+
/* Receive & send queues. */
struct sk_buff_head recv;
struct sk_buff_head send;
@@ -223,6 +230,20 @@ static void free_old_xmit_skbs(struct virtnet_info *vi)
}
}
+static enum hrtimer_restart kick_xmit(struct hrtimer *t)
+{
+ struct virtnet_info *vi = container_of(t,struct virtnet_info,tx_timer);
+
+ BUG_ON(!in_softirq());
+ BUG_ON(in_irq());
+ netif_tx_lock(vi->dev);
+ vi->svq->vq_ops->kick(vi->svq);
+ vi->out_num = 0;
+ netif_tx_unlock(vi->dev);
+
+ return HRTIMER_NORESTART;
+}
+
static int start_xmit(struct sk_buff *skb, struct net_device *dev)
{
struct virtnet_info *vi = netdev_priv(dev);
@@ -273,11 +294,25 @@ static int start_xmit(struct sk_buff *skb, struct
net_device *dev)
if (err) {
pr_debug("%s: virtio not prepared to send\n", dev->name);
skb_unlink(skb, &vi->send);
+ if (vi->out_max != vi->out_num)
+ printk("%s: out_max changed from %u to %u\n",
+ dev->name, vi->out_max, vi->out_num);
+ vi->out_max = vi->out_num;
+ vi->out_num = 0;
+ /* Kick off send immediately. */
+ hrtimer_cancel(&vi->tx_timer);
+ vi->svq->vq_ops->kick(vi->svq);
netif_stop_queue(dev);
return NETDEV_TX_BUSY;
}
- vi->svq->vq_ops->kick(vi->svq);
+ if (++vi->out_num == vi->out_max) {
+ hrtimer_cancel(&vi->tx_timer);
+ vi->svq->vq_ops->kick(vi->svq);
+ vi->out_num = 0;
+ } else
+ hrtimer_start(&vi->tx_timer, ktime_set(0,500000),
+ HRTIMER_MODE_REL);
return 0;
}
@@ -363,6 +398,10 @@ static int virtnet_probe(struct virtio_device *vdev)
netif_napi_add(dev, &vi->napi, virtnet_poll, 16);
vi->dev = dev;
vi->vdev = vdev;
+ hrtimer_init(&vi->tx_timer, CLOCK_REALTIME, HRTIMER_MODE_REL);
+ vi->tx_timer.function = kick_xmit;
+ vi->tx_timer.cb_mode = HRTIMER_CB_SOFTIRQ;
+ vi->out_max = -1U;
/* We expect two virtqueues, receive then send. */
vi->rvq = vdev->config->find_vq(vdev, 0, skb_recv_done);
--
1.5.3.3
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
reply other threads:[~2007-12-21 15:23 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=476BDA7C.6080809@qumranet.com \
--to=dor.laor-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=aliguori-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org \
--cc=dor.laor-atKUWr5tajBWk0Htik3J/w@public.gmane.org \
--cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
--cc=rusty-8n+1lVoiYb80n/F98K4Iww@public.gmane.org \
--cc=virtualization-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.