From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:58716) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RB8lY-0002fi-18 for qemu-devel@nongnu.org; Tue, 04 Oct 2011 13:26:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RB8lW-0005gv-ON for qemu-devel@nongnu.org; Tue, 04 Oct 2011 13:26:52 -0400 Received: from fmmailgate03.web.de ([217.72.192.234]:52677) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RB8lW-0005gl-Di for qemu-devel@nongnu.org; Tue, 04 Oct 2011 13:26:50 -0400 Message-ID: <4E8B41D8.3050502@web.de> Date: Tue, 04 Oct 2011 19:26:48 +0200 From: Jan Kiszka MIME-Version: 1.0 References: <20111003163352.GA22822@davesworkthinkpad> <4E89F62E.1020804@web.de> <87lit0n66z.fsf@ginnungagap.bsc.es> In-Reply-To: <87lit0n66z.fsf@ginnungagap.bsc.es> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enigF17ABF63DEAB4ADFC7B07379" Sender: jan.kiszka@web.de Subject: Re: [Qemu-devel] [PATCH] Make cpu_single_env thread local (Linux only for now) List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Dr. David Alan Gilbert" , peter.maydell@linaro.org, patches@linaro.org, qemu-devel@nongnu.org, agraf@suse.de This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigF17ABF63DEAB4ADFC7B07379 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On 2011-10-04 17:10, Llu=EDs Vilanova wrote: > Jan Kiszka writes: >=20 >> On 2011-10-03 18:33, Dr. David Alan Gilbert wrote: >>> Make cpu_single_env thread local (Linux only for now) >>> * Fixes some user space threading issues (esp those triggered >>> by bug 823902) >>> >>> Against rev d11cf8cc..., tested on ARM user mode, and ARM Vexpress >>> system mode (with Blue Swirl's fix from yesterday) - only >>> tested on Linux host. Lets me run ARM userspace firefox. >>> >>> Signed-off-by: Dr. David Alan Gilbert >>> >>> diff --git a/cpu-all.h b/cpu-all.h >>> index 42a5fa0..d895ee6 100644 >>> --- a/cpu-all.h >>> +++ b/cpu-all.h >>> @@ -334,7 +334,13 @@ void cpu_dump_statistics(CPUState *env, FILE *f,= fprintf_function cpu_fprintf, >>> void QEMU_NORETURN cpu_abort(CPUState *env, const char *fmt, ...) >>> GCC_FMT_ATTR(2, 3); >>> extern CPUState *first_cpu; >>> + >>> +#ifdef __linux__ >>> +/* DAG: Only tested thread local on Linux, feel free to add others *= / >>> +extern __thread CPUState *cpu_single_env; >>> +#else >>> extern CPUState *cpu_single_env; >>> +#endif >=20 >> We need this for all platforms in order to skip qemu_global_mutex whil= e >> manipulating some CPUState. And leaving some platforms with non-TLS wi= ll >> eventually break them when code is added that assumes TLS. >=20 >> However, it's not unlikely that some weird platforms / ancient >> toolchains still have problems with __thread - even on Linux. We may >> want to play safe and use pthread_key on POSIX. >=20 > Why not make this kind of annotations available in qemu-commmon.h; or e= ven > better somewhere less... "generic". Yes, we will need some encapsulation for this. >=20 > #if defined(CONFIG_SUPPORTS_THREAD_KEYWORD) >=20 > // use __thread > #define QEMU_DECL_TLS(type, name) \ > extern __thread type name; > #define QEMU_DEF_TLS(type, name) \ > __thread type name; > #define QEMU_SET_TLS(name, value) \ > do { name =3D value; } while (0) > #define QEMU_GET_TLS(name) \ > name >=20 > #elif defined(CONFIG_SUPPORTS_PTHREAD_KEY) >=20 > // use pthread_key_t > #define QEMU_DECL_TLS(type, name) \ > extern type _type_##name; \ > extern pthread_key_t name; > #define QEMU_DEF_TLS(type, name) \ > pthread_key_t name; \ > void _init_##name (void) __attribute__((constructor)); \ > void _init_##name (void) { pthread_key_create(&name, NULL); } > #define QEMU_SET_TLS(name, value) \ > do { pthread_setspecific(name, (void*)value); } while (0) > #define QEMU_GET_TLS(name) \ > ((typeof(_type_##name))pthread_getspecific(name)) >=20 > #else > #error Go home > #endif Looks like a start. But I would avoid macros and go for (static inline) functions where possible. And initialization should be explicit (so that you can start using TLS already inside constructors). Jan --------------enigF17ABF63DEAB4ADFC7B07379 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.16 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk6LQdgACgkQitSsb3rl5xTiTQCgvYNra5xrbRsBW8IPtFTmjin1 vK0AnApESjI6t3eZxgL45LlcppP30Oq0 =YQlK -----END PGP SIGNATURE----- --------------enigF17ABF63DEAB4ADFC7B07379--