From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52915) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yabvf-0003VA-Ol for qemu-devel@nongnu.org; Tue, 24 Mar 2015 23:24:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yabvb-0002Da-4R for qemu-devel@nongnu.org; Tue, 24 Mar 2015 23:24:27 -0400 Date: Wed, 25 Mar 2015 14:23:29 +1100 From: David Gibson Message-ID: <20150325032329.GY25043@voom.fritz.box> References: <1427117764-23008-1-git-send-email-bharata@linux.vnet.ibm.com> <1427117764-23008-15-git-send-email-bharata@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="kKplKE35C9I8SQOF" Content-Disposition: inline In-Reply-To: <1427117764-23008-15-git-send-email-bharata@linux.vnet.ibm.com> Subject: Re: [Qemu-devel] [RFC PATCH v2 14/23] cpus: Convert cpu_index into a bitmap List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Bharata B Rao Cc: mdroth@linux.vnet.ibm.com, agraf@suse.de, qemu-devel@nongnu.org, qemu-ppc@nongnu.org, tyreld@linux.vnet.ibm.com, nfont@linux.vnet.ibm.com, imammedo@redhat.com, afaerber@suse.de --kKplKE35C9I8SQOF Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Mar 23, 2015 at 07:05:55PM +0530, Bharata B Rao wrote: > Currently CPUState.cpu_index is monotonically increasing and a newly > created CPU always gets the next higher index. The next available > index is calculated by counting the existing number of CPUs. This is > fine as long as we only add CPUs, but there are architectures which > are starting to support CPU removal too. For an architecture like PowerPC > which derives its CPU identifier (device tree ID) from cpu_index, the > existing logic of generating cpu_index values causes problems. >=20 > With the currently proposed method of handling vCPU removal by parking > the vCPU fd in QEMU > (Ref: http://lists.gnu.org/archive/html/qemu-devel/2015-02/msg02604.html), > generating cpu_index this way will not work for PowerPC. >=20 > This patch changes the way cpu_index is handed out by maintaining > a bit map of the CPUs that tracks both addition and removal of CPUs. >=20 > Signed-off-by: Bharata B Rao > --- > exec.c | 37 ++++++++++++++++++++++++++++++++++--- > include/qom/cpu.h | 8 ++++++++ > 2 files changed, 42 insertions(+), 3 deletions(-) >=20 > diff --git a/exec.c b/exec.c > index e1ff6b0..9bbab02 100644 > --- a/exec.c > +++ b/exec.c > @@ -527,21 +527,52 @@ void tcg_cpu_address_space_init(CPUState *cpu, Addr= essSpace *as) > } > #endif > =20 > +#ifndef CONFIG_USER_ONLY > +static DECLARE_BITMAP(cpu_index_map, MAX_CPUMASK_BITS); > + > +static int cpu_get_free_index(Error **errp) > +{ > + int cpu =3D find_first_zero_bit(cpu_index_map, max_cpus); > + > + if (cpu =3D=3D max_cpus) { > + error_setg(errp, "Trying to use more CPUs than allowed max of %d= \n", > + max_cpus); > + return max_cpus; > + } else { > + bitmap_set(cpu_index_map, cpu, 1); > + return cpu; > + } > +} > + > +void cpu_exec_exit(CPUState *cpu) > +{ > + bitmap_clear(cpu_index_map, cpu->cpu_index, 1); > +} AFAICT, this function is never called, which seems like a bug. > +#endif > + > void cpu_exec_init(CPUArchState *env, Error **errp) > { > CPUState *cpu =3D ENV_GET_CPU(env); > CPUClass *cc =3D CPU_GET_CLASS(cpu); > - CPUState *some_cpu; > int cpu_index; > - > #if defined(CONFIG_USER_ONLY) > + CPUState *some_cpu; > + > cpu_list_lock(); > -#endif > cpu_index =3D 0; > CPU_FOREACH(some_cpu) { > cpu_index++; > } > cpu->cpu_index =3D cpu_index; > +#else > + Error *local_err =3D NULL; > + > + cpu_index =3D cpu->cpu_index =3D cpu_get_free_index(&local_err); > + if (local_err) { > + error_propagate(errp, local_err); > + return; > + } > +#endif > cpu->numa_node =3D 0; > QTAILQ_INIT(&cpu->breakpoints); > QTAILQ_INIT(&cpu->watchpoints); > diff --git a/include/qom/cpu.h b/include/qom/cpu.h > index 48fd6fb..5241cf4 100644 > --- a/include/qom/cpu.h > +++ b/include/qom/cpu.h > @@ -659,6 +659,14 @@ void cpu_watchpoint_remove_all(CPUState *cpu, int ma= sk); > void QEMU_NORETURN cpu_abort(CPUState *cpu, const char *fmt, ...) > GCC_FMT_ATTR(2, 3); > =20 > +#ifndef CONFIG_USER_ONLY > +void cpu_exec_exit(CPUState *cpu); > +#else > +static inline void cpu_exec_exit(CPUState *cpu) > +{ > +} > +#endif > + > #ifdef CONFIG_SOFTMMU > extern const struct VMStateDescription vmstate_cpu_common; > #else --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --kKplKE35C9I8SQOF Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJVEioxAAoJEGw4ysog2bOSuvkP/0rNtkXHtu5PypT1um/cQ0h6 0bFzYYHGTAJjbrlZsoldJj3/YnLRxzu2ooKs0k4TimlIz+AaLlY//a/ezkAnLdb0 dnjK+JXxuIXRCCGR12wAgnFFoVXV0UWY5tW6LrK9aWabLRnW6mdPB0T9AwnT0gng 4X4ZnSbF1H6gpyHgnULsi77ykSO+wF8GXJgj15wONzE98vXLXiKttjiavMI2x4LO lO24D9BfG5qqcRIxW0DKQHLAtAWbXvmR6Gx9eEAHpV/RMmh85HmWLQgSgekNW65N N/13o4Pd7ro70rwo3Y6U+r7j03npV4lXPJNILM8UL3OEdva4WOIJJope7FWKhi7h hWdfg4HA4wVNF8/bw9+JNG7q0HVaLOkjlefF3EUlBFMD/+uXHnevu41pfOon6fT8 xCxdOaZdehJgMWeHpdSMWZL+OyBQrK7qclrG6b7u8Tcun7Gt6A+pCrV9qbpbn6yt VWVS/iUe8PI0sR1DgyUkTbJBqNvRe4x7DwA//ulpR7W2YiviWsdvP1fvNcDaZJSr NVYkoYVlN7p2a/8sGX4p41JC9+TMlHTUDIYX9jF1Gub7Fy9WWPD/9ENfI27T163S 8vVv08s3dWn3rLIlo0oxy7Mj9br1/pjFTkSr4OlqkuV25BjNdFQbCTV8pvBI0BmT m13HrptUj8jP+1RG7YRH =8FHD -----END PGP SIGNATURE----- --kKplKE35C9I8SQOF--