(actually copying Lucas).
On 01/14/2010 03:11 PM, Avi Kivity wrote:
On 12/30/2009 06:25 PM, Avi Kivity wrote:
Defer fpu deactivation as much as possible - if the guest fpu is
loaded, keep
it loaded until the next heavyweight exit (where we are forced to
unload it).
This reduces unnecessary exits.
We also defer fpu activation on clts; while clts signals the intent
to use the
fpu, we can't be sure the guest will actually use it.
...
@@ -4988,6 +4988,10 @@ void kvm_put_guest_fpu(struct kvm_vcpu *vcpu)
return;
vcpu->guest_fpu_loaded = 0;
+ if (vcpu->fpu_active) {
+ vcpu->fpu_active = 0;
+ kvm_x86_ops->fpu_deactivate(vcpu);
+ }
kvm_fx_save(&vcpu->arch.guest_fx_image);
kvm_fx_restore(&vcpu->arch.host_fx_image);
++vcpu->stat.fpu_reload;
This is broken badly; kvm_put_guest_fpu() can be called from preempt
notifier context, that is during normal execution of vcpu processing.
Code which modifies the same variables as ->fpu_deactivate() or that
depends on ->fpu_active will break.
I fixed this by calling ->fpu_deactivate() from a synchronous context
using vcpu->requests, like we do everywhere else.
Strangely, autotest only caught this on AMD and even it took a while.
Lucas, can you integrate something like the following into autotest,
so we exercise the preemption code harder?
#!/usr/bin/python
import sys, os, re, random, ctypes, time
tasks = sys.argv[1:]
threads = [int(t)
for k in tasks
for t in os.listdir('/proc/%s/task' % (k,))]
cpus = [int(c[3:])
for c in os.listdir('/sys/devices/system/cpu')
if re.match(r'cpu[0-9]+', c)]
rand = random.Random()
sched_setaffinity = ctypes.CDLL('libc.so.6').sched_setaffinity
while True:
pid = rand.choice(threads)
cpu = rand.choice(cpus)
mask = 1 << cpu
sched_setaffinity(ctypes.c_int(pid), ctypes.c_size_t(4),
ctypes.byref(ctypes.c_int(mask)))
try:
time.sleep(0.01)
except:
break
--
error compiling committee.c: too many arguments to function
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html