fate#314663 hyper-v memory ballooning support
[opensuse:kernel-source.git] / patches.suse / suse-hv-fate314665-0004-Drivers-hv-Optimize-signaling-in-the-read-path.patch
1 Patch-mainline: submitted
2 From: <ohering@suse.de>
3 Date: Sat, 1 Dec 2012 06:46:35 -0800
4 Subject: [PATCH 04/28] Drivers: hv: Optimize signaling in the read path
5
6 Now that we have the infratructure for correctly determining when we
7 should signal the host; optimize the signaling on the read side -
8 signaling the guest from the host.
9
10 Signed-off-by: K. Y. Srinivasan <kys@microsoft.com>
11 Reviewed-by: Haiyang Zhang <haiyangz@microsoft.com>
12 ---
13  drivers/hv/connection.c | 28 +++++++++++++++++++++++++---
14  1 file changed, 25 insertions(+), 3 deletions(-)
15
16 diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c
17 index 650c9f0..d1019a7 100644
18 --- a/drivers/hv/connection.c
19 +++ b/drivers/hv/connection.c
20 @@ -212,6 +212,9 @@ static void process_chn_event(u32 relid)
21  {
22         struct vmbus_channel *channel;
23         unsigned long flags;
24 +       void *arg;
25 +       bool read_state;
26 +       u32 bytes_to_read;
27  
28         /*
29          * Find the channel based on this relid and invokes the
30 @@ -234,10 +237,29 @@ static void process_chn_event(u32 relid)
31          */
32  
33         spin_lock_irqsave(&channel->inbound_lock, flags);
34 -       if (channel->onchannel_callback != NULL)
35 -               channel->onchannel_callback(channel->channel_callback_context);
36 -       else
37 +       if (channel->onchannel_callback != NULL) {
38 +               arg = channel->channel_callback_context;
39 +               read_state = channel->batched_reading;
40 +               /*
41 +                * This callback reads the messages sent by the host.
42 +                * We can optimize host to guest signaling by ensuring:
43 +                * 1. While reading the channel, we disable interrupts from
44 +                *    host.
45 +                * 2. Ensure that we process all posted messages from the host
46 +                *    before returning from this callback.
47 +                * 3. Once we return, enable signaling from the host. Once this
48 +                *    state is set we check to see if additional packets are
49 +                *    available to read. In this case we repeat the process.
50 +                */
51 +
52 +               do {
53 +                       hv_begin_read(&channel->inbound);
54 +                       channel->onchannel_callback(arg);
55 +                       bytes_to_read = hv_end_read(&channel->inbound);
56 +               } while (read_state && (bytes_to_read != 0));
57 +       } else {
58                 pr_err("no channel callback for relid - %u\n", relid);
59 +       }
60  
61         spin_unlock_irqrestore(&channel->inbound_lock, flags);
62  }
63 -- 
64 1.8.0.1
65