Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a32a8813 authored by Rusty Russell's avatar Rusty Russell
Browse files

lguest: improve interrupt handling, speed up stream networking



lguest never checked for pending interrupts when enabling interrupts, and
things still worked.  However, it makes a significant difference to TCP
performance, so it's time we fixed it by introducing a pending_irq flag
and checking it on irq_restore and irq_enable.

These two routines are now too big to patch into the 8/10 bytes
patch space, so we drop that code.

Note: The high latency on interrupt delivery had a very curious
effect: once everything else was optimized, networking without GSO was
faster than networking with GSO, since more interrupts were sent and
hence a greater chance of one getting through to the Guest!

Note2: (Almost) Closing the same loophole for iret doesn't have any
measurable effect, so I'm leaving that patch for the moment.

Before:
	1GB tcpblast Guest->Host:		30.7 seconds
	1GB tcpblast Guest->Host (no GSO):	76.0 seconds

After:
	1GB tcpblast Guest->Host:		6.8 seconds
	1GB tcpblast Guest->Host (no GSO):	27.8 seconds

Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
parent abd41f03
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#define LHCALL_LOAD_TLS		16
#define LHCALL_NOTIFY		17
#define LHCALL_LOAD_GDT_ENTRY	18
#define LHCALL_SEND_INTERRUPTS	19

#define LGUEST_TRAP_ENTRY 0x1F

+15 −6
Original line number Diff line number Diff line
@@ -205,6 +205,12 @@ PV_CALLEE_SAVE_REGS_THUNK(save_fl);
static void restore_fl(unsigned long flags)
{
	lguest_data.irq_enabled = flags;
	mb();
	/* Null hcall forces interrupt delivery now, if irq_pending is
	 * set to X86_EFLAGS_IF (ie. an interrupt is pending, and flags
	 * enables interrupts. */
	if (flags & lguest_data.irq_pending)
		kvm_hypercall0(LHCALL_SEND_INTERRUPTS);
}
PV_CALLEE_SAVE_REGS_THUNK(restore_fl);

@@ -219,6 +225,11 @@ PV_CALLEE_SAVE_REGS_THUNK(irq_disable);
static void irq_enable(void)
{
	lguest_data.irq_enabled = X86_EFLAGS_IF;
	mb();
	/* Null hcall forces interrupt delivery now. */
	if (lguest_data.irq_pending)
		kvm_hypercall0(LHCALL_SEND_INTERRUPTS);

}
PV_CALLEE_SAVE_REGS_THUNK(irq_enable);

@@ -972,10 +983,10 @@ static void lguest_restart(char *reason)
 *
 * Our current solution is to allow the paravirt back end to optionally patch
 * over the indirect calls to replace them with something more efficient.  We
 * patch the four most commonly called functions: disable interrupts, enable
 * interrupts, restore interrupts and save interrupts.  We usually have 6 or 10
 * bytes to patch into: the Guest versions of these operations are small enough
 * that we can fit comfortably.
 * patch two of the simplest of the most commonly called functions: disable
 * interrupts and save interrupts.  We usually have 6 or 10 bytes to patch
 * into: the Guest versions of these operations are small enough that we can
 * fit comfortably.
 *
 * First we need assembly templates of each of the patchable Guest operations,
 * and these are in i386_head.S. */
@@ -986,8 +997,6 @@ static const struct lguest_insns
	const char *start, *end;
} lguest_insns[] = {
	[PARAVIRT_PATCH(pv_irq_ops.irq_disable)] = { lgstart_cli, lgend_cli },
	[PARAVIRT_PATCH(pv_irq_ops.irq_enable)] = { lgstart_sti, lgend_sti },
	[PARAVIRT_PATCH(pv_irq_ops.restore_fl)] = { lgstart_popf, lgend_popf },
	[PARAVIRT_PATCH(pv_irq_ops.save_fl)] = { lgstart_pushf, lgend_pushf },
};

+0 −2
Original line number Diff line number Diff line
@@ -46,8 +46,6 @@ ENTRY(lguest_entry)
	.globl lgstart_##name; .globl lgend_##name

LGUEST_PATCH(cli, movl $0, lguest_data+LGUEST_DATA_irq_enabled)
LGUEST_PATCH(sti, movl $X86_EFLAGS_IF, lguest_data+LGUEST_DATA_irq_enabled)
LGUEST_PATCH(popf, movl %eax, lguest_data+LGUEST_DATA_irq_enabled)
LGUEST_PATCH(pushf, movl lguest_data+LGUEST_DATA_irq_enabled, %eax)
/*:*/

+4 −3
Original line number Diff line number Diff line
@@ -189,6 +189,7 @@ int run_guest(struct lg_cpu *cpu, unsigned long __user *user)
	/* We stop running once the Guest is dead. */
	while (!cpu->lg->dead) {
		unsigned int irq;
		bool more;

		/* First we run any hypercalls the Guest wants done. */
		if (cpu->hcall)
@@ -213,9 +214,9 @@ int run_guest(struct lg_cpu *cpu, unsigned long __user *user)
		/* Check if there are any interrupts which can be delivered now:
		 * if so, this sets up the hander to be executed when we next
		 * run the Guest. */
		irq = interrupt_pending(cpu);
		irq = interrupt_pending(cpu, &more);
		if (irq < LGUEST_IRQS)
			try_deliver_interrupt(cpu, irq);
			try_deliver_interrupt(cpu, irq, more);

		/* All long-lived kernel loops need to check with this horrible
		 * thing called the freezer.  If the Host is trying to suspend,
@@ -233,7 +234,7 @@ int run_guest(struct lg_cpu *cpu, unsigned long __user *user)
			set_current_state(TASK_INTERRUPTIBLE);
			/* Just before we sleep, make sure nothing snuck in
			 * which we should be doing. */
			if (interrupt_pending(cpu) < LGUEST_IRQS
			if (interrupt_pending(cpu, &more) < LGUEST_IRQS
			    || cpu->break_out)
				set_current_state(TASK_RUNNING);
			else
+4 −0
Original line number Diff line number Diff line
@@ -37,6 +37,10 @@ static void do_hcall(struct lg_cpu *cpu, struct hcall_args *args)
		/* This call does nothing, except by breaking out of the Guest
		 * it makes us process all the asynchronous hypercalls. */
		break;
	case LHCALL_SEND_INTERRUPTS:
		/* This call does nothing too, but by breaking out of the Guest
		 * it makes us process any pending interrupts. */
		break;
	case LHCALL_LGUEST_INIT:
		/* You can't get here unless you're already initialized.  Don't
		 * do that. */
Loading