From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jes Sorensen Date: Tue, 13 Jan 2009 10:25:02 +0000 Subject: [patch] dynamic nr online cpus Message-Id: <496C6BFE.6020900@sgi.com> MIME-Version: 1 Content-Type: multipart/mixed; boundary="------------080904010000090901010206" List-Id: To: kvm-ia64@vger.kernel.org This is a multi-part message in MIME format. --------------080904010000090901010206 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hi, Working on allowing larger max vcpus I'd like to put in this patch that calculates the number of online cpus. It's a building block for allowing the larger number of max vcpus without crippling performance for the smaller cases. Cheers, Jes --------------080904010000090901010206 Content-Type: text/plain; name="5000-kvm-ia64-nr-online-vcpu.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="5000-kvm-ia64-nr-online-vcpu.patch" Account for number of online cpus and use that in loops iterating over the list of vpus. This patch is a building block, in the work to allow for larger max number of vcpus. A copy of the number of online cpus is stored in vcpu 0's private data area to allow the number to be visible from the KVM module. Signed-off-by: Jes Sorensen --- arch/ia64/include/asm/kvm_host.h | 3 +++ arch/ia64/kvm/kvm-ia64.c | 20 ++++++++++++++++---- arch/ia64/kvm/vcpu.c | 2 +- 3 files changed, 20 insertions(+), 5 deletions(-) Index: linux-2.6.git/arch/ia64/include/asm/kvm_host.h =================================================================== --- linux-2.6.git.orig/arch/ia64/include/asm/kvm_host.h +++ linux-2.6.git/arch/ia64/include/asm/kvm_host.h @@ -377,6 +377,7 @@ int last_run_cpu; int vmm_tr_slot; int vm_tr_slot; + int online_cpus; #define KVM_MP_STATE_RUNNABLE 0 #define KVM_MP_STATE_UNINITIALIZED 1 @@ -470,6 +471,8 @@ unsigned long metaphysical_rr4; unsigned long vmm_init_rr; + int online_cpus; + struct kvm_ioapic *vioapic; struct kvm_vm_stat stat; struct kvm_sal_data rdv_sal_data; Index: linux-2.6.git/arch/ia64/kvm/kvm-ia64.c =================================================================== --- linux-2.6.git.orig/arch/ia64/kvm/kvm-ia64.c +++ linux-2.6.git/arch/ia64/kvm/kvm-ia64.c @@ -316,7 +316,7 @@ union ia64_lid lid; int i; - for (i = 0; i < KVM_MAX_VCPUS; i++) { + for (i = 0; i < kvm->arch.online_cpus; i++) { if (kvm->vcpus[i]) { lid.val = VCPU_LID(kvm->vcpus[i]); if (lid.id == id && lid.eid == eid) @@ -390,7 +390,7 @@ call_data.ptc_g_data = p->u.ptc_g_data; - for (i = 0; i < KVM_MAX_VCPUS; i++) { + for (i = 0; i < kvm->arch.online_cpus; i++) { if (!kvm->vcpus[i] || kvm->vcpus[i]->arch.mp_state == KVM_MP_STATE_UNINITIALIZED || vcpu == kvm->vcpus[i]) @@ -825,6 +825,8 @@ return ERR_PTR(-ENOMEM); kvm_init_vm(kvm); + kvm->arch.online_cpus = 0; /* xxx hack me harder xxx */ + return kvm; } @@ -1186,7 +1188,7 @@ /*Initialize itc offset for vcpus*/ itc_offset = 0UL - ia64_getreg(_IA64_REG_AR_ITC); - for (i = 0; i < KVM_MAX_VCPUS; i++) { + for (i = 0; i < kvm->arch.online_cpus; i++) { v = (struct kvm_vcpu *)((char *)vcpu + sizeof(struct kvm_vcpu_data) * i); v->arch.itc_offset = itc_offset; @@ -1320,6 +1322,16 @@ goto fail; } + kvm->arch.online_cpus++; + /* + * For vcpu 0, kvm->vcpus hasn't been assigned yet, special case it + */ + if (!id) + vcpu->arch.online_cpus = kvm->arch.online_cpus; + else + kvm->vcpus[0]->arch.online_cpus = kvm->arch.online_cpus; + + printk(KERN_INFO "arch.online_cpus %i\n", kvm->arch.online_cpus); return vcpu; fail: return ERR_PTR(r); @@ -1766,7 +1778,7 @@ struct kvm_vcpu *lvcpu = kvm->vcpus[0]; int i; - for (i = 1; i < KVM_MAX_VCPUS; i++) { + for (i = 1; i < kvm->arch.online_cpus; i++) { if (!kvm->vcpus[i]) continue; if (lvcpu->arch.xtp > kvm->vcpus[i]->arch.xtp) Index: linux-2.6.git/arch/ia64/kvm/vcpu.c =================================================================== --- linux-2.6.git.orig/arch/ia64/kvm/vcpu.c +++ linux-2.6.git/arch/ia64/kvm/vcpu.c @@ -816,7 +816,7 @@ unsigned long vitv = VCPU(vcpu, itv); if (vcpu->vcpu_id == 0) { - for (i = 0; i < KVM_MAX_VCPUS; i++) { + for (i = 0; i < vcpu->arch.online_cpus; i++) { v = (struct kvm_vcpu *)((char *)vcpu + sizeof(struct kvm_vcpu_data) * i); VMX(v, itc_offset) = itc_offset; --------------080904010000090901010206--