Module Name: src Committed By: maxv Date: Wed Aug 26 16:28:17 UTC 2020
Modified Files: src/sys/dev/nvmm: nvmm.c Log Message: nvmm: misc improvements - use mach->ncpus to get the number of vcpus, now that we have it - don't forget to decrement mach->ncpus when a machine gets killed - add more __predict_false() To generate a diff of this commit: cvs rdiff -u -r1.35 -r1.36 src/sys/dev/nvmm/nvmm.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/nvmm/nvmm.c diff -u src/sys/dev/nvmm/nvmm.c:1.35 src/sys/dev/nvmm/nvmm.c:1.36 --- src/sys/dev/nvmm/nvmm.c:1.35 Tue Aug 18 17:04:37 2020 +++ src/sys/dev/nvmm/nvmm.c Wed Aug 26 16:28:17 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: nvmm.c,v 1.35 2020/08/18 17:04:37 maxv Exp $ */ +/* $NetBSD: nvmm.c,v 1.36 2020/08/26 16:28:17 maxv Exp $ */ /* * Copyright (c) 2018-2020 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: nvmm.c,v 1.35 2020/08/18 17:04:37 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: nvmm.c,v 1.36 2020/08/26 16:28:17 maxv Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -112,17 +112,17 @@ nvmm_machine_get(struct nvmm_owner *owne struct nvmm_machine *mach; krw_t op = writer ? RW_WRITER : RW_READER; - if (machid >= NVMM_MAX_MACHINES) { + if (__predict_false(machid >= NVMM_MAX_MACHINES)) { return EINVAL; } mach = &machines[machid]; rw_enter(&mach->lock, op); - if (!mach->present) { + if (__predict_false(!mach->present)) { rw_exit(&mach->lock); return ENOENT; } - if (owner != &root_owner && mach->owner != owner) { + if (__predict_false(mach->owner != owner && owner != &root_owner)) { rw_exit(&mach->lock); return EPERM; } @@ -179,13 +179,13 @@ nvmm_vcpu_get(struct nvmm_machine *mach, { struct nvmm_cpu *vcpu; - if (cpuid >= NVMM_MAX_VCPUS) { + if (__predict_false(cpuid >= NVMM_MAX_VCPUS)) { return EINVAL; } vcpu = &mach->cpus[cpuid]; mutex_enter(&vcpu->lock); - if (!vcpu->present) { + if (__predict_false(!vcpu->present)) { mutex_exit(&vcpu->lock); return ENOENT; } @@ -227,6 +227,7 @@ nvmm_kill_machines(struct nvmm_owner *ow (*nvmm_impl->vcpu_destroy)(mach, vcpu); nvmm_vcpu_free(mach, vcpu); nvmm_vcpu_put(vcpu); + atomic_dec_uint(&mach->ncpus); } (*nvmm_impl->machine_destroy)(mach); uvmspace_free(mach->vm); @@ -314,6 +315,7 @@ nvmm_machine_destroy(struct nvmm_owner * (*nvmm_impl->vcpu_destroy)(mach, vcpu); nvmm_vcpu_free(mach, vcpu); nvmm_vcpu_put(vcpu); + atomic_dec_uint(&mach->ncpus); } (*nvmm_impl->machine_destroy)(mach); @@ -414,7 +416,6 @@ nvmm_vcpu_create(struct nvmm_owner *owne } nvmm_vcpu_put(vcpu); - atomic_inc_uint(&mach->ncpus); out: @@ -440,7 +441,6 @@ nvmm_vcpu_destroy(struct nvmm_owner *own (*nvmm_impl->vcpu_destroy)(mach, vcpu); nvmm_vcpu_free(mach, vcpu); nvmm_vcpu_put(vcpu); - atomic_dec_uint(&mach->ncpus); out: @@ -907,7 +907,6 @@ nvmm_ctl_mach_info(struct nvmm_owner *ow { struct nvmm_ctl_mach_info ctl; struct nvmm_machine *mach; - struct nvmm_cpu *vcpu; int error; size_t i; @@ -921,14 +920,7 @@ nvmm_ctl_mach_info(struct nvmm_owner *ow if (error) return error; - ctl.nvcpus = 0; - for (i = 0; i < NVMM_MAX_VCPUS; i++) { - error = nvmm_vcpu_get(mach, i, &vcpu); - if (error) - continue; - ctl.nvcpus++; - nvmm_vcpu_put(vcpu); - } + ctl.nvcpus = mach->ncpus; ctl.nram = 0; for (i = 0; i < NVMM_MAX_HMAPPINGS; i++) {