Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/nvmm Optimize: keep a per-VCPU buffer for the state, ...
details: https://anonhg.NetBSD.org/src/rev/32f4965a5962
branches: trunk
changeset: 838632:32f4965a5962
user: maxv <maxv%NetBSD.org@localhost>
date: Sat Jan 26 15:25:51 2019 +0000
description:
Optimize: keep a per-VCPU buffer for the state, and copy in and out
directly on it. The VCPUs are protected by mutexes, so nothing to worry
about.
This saves two kmem_allocs in {get,set}state.
diffstat:
sys/dev/nvmm/nvmm.c | 30 ++++++++++--------------------
sys/dev/nvmm/nvmm_internal.h | 5 ++++-
2 files changed, 14 insertions(+), 21 deletions(-)
diffs (122 lines):
diff -r ad58091ad92a -r 32f4965a5962 sys/dev/nvmm/nvmm.c
--- a/sys/dev/nvmm/nvmm.c Sat Jan 26 15:22:54 2019 +0000
+++ b/sys/dev/nvmm/nvmm.c Sat Jan 26 15:25:51 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: nvmm.c,v 1.5 2019/01/06 16:10:51 maxv Exp $ */
+/* $NetBSD: nvmm.c,v 1.6 2019/01/26 15:25:51 maxv Exp $ */
/*
* Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nvmm.c,v 1.5 2019/01/06 16:10:51 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvmm.c,v 1.6 2019/01/26 15:25:51 maxv Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -142,6 +142,7 @@
vcpu->present = true;
vcpu->cpuid = i;
+ vcpu->state = kmem_zalloc(nvmm_impl->state_size, KM_SLEEP);
*ret = vcpu;
return 0;
}
@@ -154,6 +155,7 @@
{
KASSERT(mutex_owned(&vcpu->lock));
vcpu->present = false;
+ kmem_free(vcpu->state, nvmm_impl->state_size);
vcpu->hcpu_last = -1;
}
@@ -404,33 +406,27 @@
{
struct nvmm_machine *mach;
struct nvmm_cpu *vcpu;
- void *data;
int error;
- data = kmem_alloc(nvmm_impl->state_size, KM_SLEEP);
-
error = nvmm_machine_get(args->machid, &mach, false);
- if (error) {
- kmem_free(data, nvmm_impl->state_size);
+ if (error)
return error;
- }
error = nvmm_vcpu_get(mach, args->cpuid, &vcpu);
if (error)
goto out;
- error = copyin(args->state, data, nvmm_impl->state_size);
+ error = copyin(args->state, vcpu->state, nvmm_impl->state_size);
if (error) {
nvmm_vcpu_put(vcpu);
goto out;
}
- (*nvmm_impl->vcpu_setstate)(vcpu, data, args->flags);
+ (*nvmm_impl->vcpu_setstate)(vcpu, vcpu->state, args->flags);
nvmm_vcpu_put(vcpu);
out:
nvmm_machine_put(mach);
- kmem_free(data, nvmm_impl->state_size);
return error;
}
@@ -439,28 +435,22 @@
{
struct nvmm_machine *mach;
struct nvmm_cpu *vcpu;
- void *data;
int error;
- data = kmem_alloc(nvmm_impl->state_size, KM_SLEEP);
-
error = nvmm_machine_get(args->machid, &mach, false);
- if (error) {
- kmem_free(data, nvmm_impl->state_size);
+ if (error)
return error;
- }
error = nvmm_vcpu_get(mach, args->cpuid, &vcpu);
if (error)
goto out;
- (*nvmm_impl->vcpu_getstate)(vcpu, data, args->flags);
+ (*nvmm_impl->vcpu_getstate)(vcpu, vcpu->state, args->flags);
nvmm_vcpu_put(vcpu);
- error = copyout(data, args->state, nvmm_impl->state_size);
+ error = copyout(vcpu->state, args->state, nvmm_impl->state_size);
out:
nvmm_machine_put(mach);
- kmem_free(data, nvmm_impl->state_size);
return error;
}
diff -r ad58091ad92a -r 32f4965a5962 sys/dev/nvmm/nvmm_internal.h
--- a/sys/dev/nvmm/nvmm_internal.h Sat Jan 26 15:22:54 2019 +0000
+++ b/sys/dev/nvmm/nvmm_internal.h Sat Jan 26 15:25:51 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: nvmm_internal.h,v 1.2 2018/12/15 13:39:43 maxv Exp $ */
+/* $NetBSD: nvmm_internal.h,v 1.3 2019/01/26 15:25:51 maxv Exp $ */
/*
* Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -43,6 +43,9 @@
nvmm_cpuid_t cpuid;
kmutex_t lock;
+ /* State buffer. */
+ void *state;
+
/* Last host CPU on which the VCPU ran. */
int hcpu_last;
Home |
Main Index |
Thread Index |
Old Index