From: Zhenyu Ye <yezhenyu2@huawei.com>
To: Eduardo Habkost <ehabkost@redhat.com>
Cc: Zhanghailiang <zhang.zhanghailiang@huawei.com>,
"S. Tsirkin, Michael" <mst@redhat.com>,
richard.henderson@linaro.org, qemu-devel@nongnu.org,
Xiexiangyou <xiexiangyou@huawei.com>,
yebiaoxiang <yebiaoxiang@huawei.com>,
Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [RFC PATCH v2] x86/cpu: initialize the CPU concurrently
Date: Thu, 24 Dec 2020 21:41:10 +0800 [thread overview]
Message-ID: <e823060d-1a8a-a1d8-aa2f-1394c118bdae@huawei.com> (raw)
In-Reply-To: <20201221213620.GF6040@habkost.net>
Hi Eduardo,
Sorry for the delay.
On 2020/12/22 5:36, Eduardo Habkost wrote:
> On Mon, Dec 21, 2020 at 07:36:18PM +0800, Zhenyu Ye wrote:
>> Providing a optional mechanism to wait for all VCPU threads be
>> created out of qemu_init_vcpu(), then we can initialize the cpu
>> concurrently on the x86 architecture.
>>
>> This reduces the time of creating virtual machines. For example, when
>> the haxm is used as the accelerator, cpus_accel->create_vcpu_thread()
>> will cause at least 200ms for each cpu, extremely prolong the boot
>> time.
>>
>> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
>> Signed-off-by: eillon <yezhenyu2@huawei.com>
>
> The patch is easier to follow now, but I have a question that may
> be difficult to answer:
>
> What exactly is the meaning of cpu->created=true, and what
> exactly would break if we never wait for cpu->created==true at all?
>
> I'm asking that because we might be introducing subtle races
> here, if some of the remaining CPU initialization code in
> x86_cpu_realizefn() [1] expects the VCPU thread to be already
> initialized.
>
> The cpu_reset() call below is one such example (but probably not
> the only one). cpu_reset() ends up calling
> kvm_arch_reset_vcpu(), which seems to assume kvm_init_vcpu() was
> already called. With your patch, kvm_init_vcpu() might end up
> being called after kvm_arch_reset_vcpu().
>
There's a chance that this happens.
Could we move these (after qemu_init_vcpu()) out of x86_cpu_realizefn()
to the x86_cpus_init(), after qemu_wait_all_vcpu_threads_init()?
Such as:
void x86_cpus_init()
{
foreach (cpu) {
x86_cpu_new();
}
qemu_wait_all_vcpu_threads_init();
foreach (cpu) {
x86_cpu_new_post();
}
}
> Maybe a simpler alternative is to keep the existing thread
> creation logic, but changing hax_cpu_thread_fn() to do less work
> before calling cpu_thread_signal_created()?
>
> In my testing (without this patch), creation of 8 KVM VCPU
> threads in a 4 core machine takes less than 3 ms. Why is
> qemu_init_vcpu() taking so long on haxm? Which parts of haxm
> initialization can be moved after cpu_thread_signal_created(), to
> make this better?
>
The most time-consuming operation in haxm is ioctl(HAX_VM_IOCTL_VCPU_CREATE).
Saddly this can not be split.
Even if we fix the problem in haxm, other accelerators may also have
this problem. So I think if we can make the x86_cpu_new() concurrently,
we should try to do it.
Thanks,
Zhenyu
next prev parent reply other threads:[~2020-12-24 13:42 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-21 11:36 [RFC PATCH v2] x86/cpu: initialize the CPU concurrently Zhenyu Ye
2020-12-21 21:36 ` Eduardo Habkost
2020-12-24 13:41 ` Zhenyu Ye [this message]
2020-12-24 18:06 ` Eduardo Habkost
2020-12-31 9:34 ` Zhenyu Ye
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e823060d-1a8a-a1d8-aa2f-1394c118bdae@huawei.com \
--to=yezhenyu2@huawei.com \
--cc=ehabkost@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=xiexiangyou@huawei.com \
--cc=yebiaoxiang@huawei.com \
--cc=zhang.zhanghailiang@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).