Re: [PATCH] kvm: make vcpu life cycle separated from kvm instance

From: Liu ping fan
Date: Mon Dec 05 2011 - 00:29:19 EST


On Sun, Dec 4, 2011 at 6:23 PM, Avi Kivity <avi@xxxxxxxxxx> wrote:
> On 12/02/2011 08:26 AM, Liu Ping Fan wrote:
>> From: Liu Ping Fan <pingfank@xxxxxxxxxxxxxxxxxx>
>>
>> Currently, vcpu can be destructed only when kvm instance destroyed.
>> Change this to vcpu's destruction taken when its refcnt is zero,
>> and then vcpu MUST and CAN be destroyed before kvm's destroy.
>>
>>
>> @@ -315,9 +315,17 @@ static void pit_do_work(struct work_struct *work)
>> Â Â Â Â Â Â Â Â* LVT0 to NMI delivery. Other PIC interrupts are just sent to
>> Â Â Â Â Â Â Â Â* VCPU0, and only if its LVT0 is in EXTINT mode.
>> Â Â Â Â Â Â Â Â*/
>> - Â Â Â Â Â Â if (kvm->arch.vapics_in_nmi_mode > 0)
>> - Â Â Â Â Â Â Â Â Â Â kvm_for_each_vcpu(i, vcpu, kvm)
>> + Â Â Â Â Â Â if (kvm->arch.vapics_in_nmi_mode > 0) {
>> + Â Â Â Â Â Â Â Â Â Â rcu_read_lock();
>> + Â Â Â Â Â Â Â Â Â Â kvm_for_each_vcpu(i, cnt, vcpu, kvm) {
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â vcpu = kvm_get_vcpu(kvm, i);
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â if (vcpu == NULL)
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â continue;
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â cnt++;
>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â kvm_apic_nmi_wd_deliver(vcpu);
>> + Â Â Â Â Â Â Â Â Â Â }
>> + Â Â Â Â Â Â Â Â Â Â rcu_read_unlock();
>> + Â Â Â Â Â Â }
>> Â Â Â }
>> Â}
>
> This pattern keeps repeating, please fold it into kvm_for_each_vcpu().
>
What about folding
kvm_for_each_vcpu(i, cnt, vcpu, kvm) {
       vcpu = kvm_get_vcpu(kvm, i);
       if (vcpu == NULL)
            continue;
       cnt++;

like this,
#define kvm_for_each_vcpu(idx, cnt, vcpup, kvm) \
for (idx = 0, cnt = 0, vcpup = kvm_get_vcpu(kvm, idx); \
cnt < atomic_read(&kvm->online_vcpus) && \
idx < KVM_MAX_VCPUS; \
idx++, (vcpup == NULL)?:cnt++, vcpup = kvm_get_vcpu(kvm, idx)) \
if (vcpup == NULL) \
continue; \
else


A little ugly, but have not thought a better way out :-)

Thanks,
ping fan
> --
> error compiling committee.c: too many arguments to function
>
èº{.nÇ+‰·Ÿ®‰­†+%ŠËlzwm…ébëæìr¸›zX§»®w¥Š{ayºÊÚë,j­¢f£¢·hš‹àz¹®w¥¢¸ ¢·¦j:+v‰¨ŠwèjØm¶Ÿÿ¾«‘êçzZ+ƒùšŽŠÝj"ú!¶iO•æ¬z·švØ^¶m§ÿðà nÆàþY&—