qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Igor Mammedov <imammedo@redhat.com>, qemu-devel@nongnu.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Yanan Wang" <wangyanan55@huawei.com>,
	"Zhao Liu" <zhao1.liu@intel.com>
Subject: Re: [PATCH v2 08/10] cpus: expose only realized vCPUs to global &cpus_queue
Date: Wed, 26 Feb 2025 08:16:52 +0100	[thread overview]
Message-ID: <96b40129-072e-46c3-87c5-dd6a51dca1d6@linaro.org> (raw)
In-Reply-To: <20250207162048.1890669-9-imammedo@redhat.com>

On 7/2/25 17:20, Igor Mammedov wrote:
> cpu_list_add() was doing 2 distinct things:
> - assign some index to vCPU
> - add unrealized (thus in inconsistent state) vCPU to &cpus_queue
> 
> Code using CPU_FOREACH() macro would iterate over possibly
> unrealized vCPUs, often dealt with special casing.
> 
> Instead of working around of vCPU existence in cpus_queue,
> split out cpu_index assignment from cpu_list_add(),

Better split 2 distinct changes in 2 patches for clarity.

> and move the later to the end of realize stage,
> right before vCPU is let run.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
> CC: Yanan Wang <wangyanan55@huawei.com>
> CC: Zhao Liu <zhao1.liu@intel.com>
> ---
>   include/hw/core/cpu.h |  6 ++++++
>   cpu-common.c          | 23 ++++++++++++++---------
>   cpu-target.c          |  2 +-
>   hw/core/cpu-common.c  |  2 ++
>   4 files changed, 23 insertions(+), 10 deletions(-)
> 
> diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
> index fb397cdfc5..c338fd31bd 100644
> --- a/include/hw/core/cpu.h
> +++ b/include/hw/core/cpu.h
> @@ -750,6 +750,12 @@ bool cpu_virtio_is_big_endian(CPUState *cpu);
>   
>   #endif /* CONFIG_USER_ONLY */
>   
> +/**
> + * cpu_auto_assign_cpu_index:
> + * @cpu: The CPU to be assigned a cpu_index
> + */
> +void cpu_auto_assign_cpu_index(CPUState *cpu);
> +
>   /**
>    * cpu_list_add:
>    * @cpu: The CPU to be added to the list of CPUs.
> diff --git a/cpu-common.c b/cpu-common.c
> index 4248b2d727..92f3d00e56 100644
> --- a/cpu-common.c
> +++ b/cpu-common.c
> @@ -71,15 +71,7 @@ int cpu_get_free_index(void)
>       return max_cpu_index;
>   }
>   
> -CPUTailQ cpus_queue = QTAILQ_HEAD_INITIALIZER(cpus_queue);
> -static unsigned int cpu_list_generation_id;
> -
> -unsigned int cpu_list_generation_id_get(void)
> -{
> -    return cpu_list_generation_id;
> -}
> -
> -void cpu_list_add(CPUState *cpu)
> +void cpu_auto_assign_cpu_index(CPUState *cpu)
>   {
>       static bool cpu_index_auto_assigned;
>   
> @@ -91,6 +83,19 @@ void cpu_list_add(CPUState *cpu)
>       } else {
>           assert(!cpu_index_auto_assigned);
>       }
> +}
> +
> +CPUTailQ cpus_queue = QTAILQ_HEAD_INITIALIZER(cpus_queue);
> +static unsigned int cpu_list_generation_id;
> +
> +unsigned int cpu_list_generation_id_get(void)
> +{
> +    return cpu_list_generation_id;
> +}
> +
> +void cpu_list_add(CPUState *cpu)
> +{
> +    QEMU_LOCK_GUARD(&qemu_cpu_list_lock);
>       QTAILQ_INSERT_TAIL_RCU(&cpus_queue, cpu, node);
>       cpu_list_generation_id++;
>   }
> diff --git a/cpu-target.c b/cpu-target.c
> index 667688332c..0c86c18a50 100644
> --- a/cpu-target.c
> +++ b/cpu-target.c
> @@ -142,7 +142,7 @@ bool cpu_exec_realizefn(CPUState *cpu, Error **errp)
>       }
>   
>       /* Wait until cpu initialization complete before exposing cpu. */
> -    cpu_list_add(cpu);
> +    cpu_auto_assign_cpu_index(cpu);
>   
>   #ifdef CONFIG_USER_ONLY
>       assert(qdev_get_vmsd(DEVICE(cpu)) == NULL ||
> diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c
> index cb79566cc5..c29737e5e3 100644
> --- a/hw/core/cpu-common.c
> +++ b/hw/core/cpu-common.c
> @@ -211,6 +211,8 @@ static void cpu_common_realizefn(DeviceState *dev, Error **errp)
>           }
>       }
>   
> +    cpu_list_add(cpu);
> +
>       if (dev->hotplugged) {
>           cpu_synchronize_post_init(cpu);
>           cpu_resume(cpu);



  reply	other threads:[~2025-02-26  7:17 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-07 16:20 [PATCH v2 00/10] accel: Only include qdev-realized vCPUs in global &cpus_queue Igor Mammedov
2025-02-07 16:20 ` [PATCH v2 01/10] bsd-user: drop not longer used target_reset_cpu() Igor Mammedov
2025-02-25 11:27   ` Alex Bennée
2025-03-02  5:11   ` Warner Losh
2025-02-07 16:20 ` [PATCH v2 02/10] loongarch: reset vcpu after it's created Igor Mammedov
2025-02-25  7:50   ` bibo mao
2025-02-26  7:10   ` Philippe Mathieu-Daudé
2025-02-07 16:20 ` [PATCH v2 03/10] m68k: " Igor Mammedov
2025-02-25 11:27   ` Alex Bennée
2025-02-26  7:12   ` Philippe Mathieu-Daudé
2025-02-07 16:20 ` [PATCH v2 04/10] tcg:tlb: use tcg_debug_assert() in assert_cpu_is_self() Igor Mammedov
2025-02-25 11:47   ` Alex Bennée
2025-02-07 16:20 ` [PATCH v2 05/10] Revert "tcg/cputlb: remove other-cpu capability from TLB flushing" Igor Mammedov
2025-02-25 12:42   ` Alex Bennée
2025-02-25 17:19     ` Igor Mammedov
2025-02-25 17:26       ` Igor Mammedov
2025-02-07 16:20 ` [PATCH v2 06/10] tcg: drop cpu->created check Igor Mammedov
2025-02-07 16:20 ` [PATCH v2 07/10] accel/tcg: Simplify use of &first_cpu in rr_cpu_thread_fn() Igor Mammedov
2025-02-25 12:44   ` Alex Bennée
2025-02-07 16:20 ` [PATCH v2 08/10] cpus: expose only realized vCPUs to global &cpus_queue Igor Mammedov
2025-02-26  7:16   ` Philippe Mathieu-Daudé [this message]
2025-03-03 13:09     ` Igor Mammedov
2025-03-03 14:34       ` Philippe Mathieu-Daudé
2025-02-07 16:20 ` [PATCH v2 09/10] accel/kvm: Assert vCPU is created when calling kvm_dirty_ring_reap*() Igor Mammedov
2025-02-07 16:20 ` [PATCH v2 10/10] accel/kvm: Remove unreachable assertion in kvm_dirty_ring_reap*() Igor Mammedov
2025-02-25 10:31 ` [PATCH v2 00/10] accel: Only include qdev-realized vCPUs in global &cpus_queue Igor Mammedov

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=96b40129-072e-46c3-87c5-dd6a51dca1d6@linaro.org \
    --to=philmd@linaro.org \
    --cc=alex.bennee@linaro.org \
    --cc=imammedo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=wangyanan55@huawei.com \
    --cc=zhao1.liu@intel.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).