From patchwork Fri Oct 28 09:52:40 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 4867 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 4AD1223DEF for ; Fri, 28 Oct 2011 09:52:50 +0000 (UTC) Received: from mail-fx0-f52.google.com (mail-fx0-f52.google.com [209.85.161.52]) by fiordland.canonical.com (Postfix) with ESMTP id 3F10FA18609 for ; Fri, 28 Oct 2011 09:52:50 +0000 (UTC) Received: by mail-fx0-f52.google.com with SMTP id n26so5172404faa.11 for ; Fri, 28 Oct 2011 02:52:50 -0700 (PDT) Received: by 10.223.91.73 with SMTP id l9mr638623fam.22.1319795570113; Fri, 28 Oct 2011 02:52:50 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.152.1.71 with SMTP id 7cs5322lak; Fri, 28 Oct 2011 02:52:49 -0700 (PDT) Received: by 10.14.4.167 with SMTP id 39mr171855eej.13.1319795567301; Fri, 28 Oct 2011 02:52:47 -0700 (PDT) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [81.2.115.146]) by mx.google.com with ESMTPS id o50si2694342eeh.104.2011.10.28.02.52.46 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 28 Oct 2011 02:52:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 81.2.115.146 as permitted sender) client-ip=81.2.115.146; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 81.2.115.146 as permitted sender) smtp.mail=pm215@archaic.org.uk Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.72) (envelope-from ) id 1RJj7C-0004iG-UU; Fri, 28 Oct 2011 10:52:42 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Paolo Bonzini , "Dr. David Alan Gilbert" , Jan Kiszka , =?UTF-8?q?Andreas=20F=C3=A4rber?= Subject: [PATCH v3 1/3] qemu-tls.h: Add abstraction layer for TLS variables Date: Fri, 28 Oct 2011 10:52:40 +0100 Message-Id: <1319795562-18091-2-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1319795562-18091-1-git-send-email-peter.maydell@linaro.org> References: <1319795562-18091-1-git-send-email-peter.maydell@linaro.org> Add an abstraction layer for defining and using thread-local variables. For the moment this is implemented only for Linux, which means they can only be used in restricted circumstances. The abstraction layer allows us to add POSIX and Win32 support later. Signed-off-by: Paolo Bonzini Signed-off-by: Peter Maydell --- qemu-tls.h | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 52 insertions(+), 0 deletions(-) create mode 100644 qemu-tls.h diff --git a/qemu-tls.h b/qemu-tls.h new file mode 100644 index 0000000..5b70f10 --- /dev/null +++ b/qemu-tls.h @@ -0,0 +1,52 @@ +/* + * Abstraction layer for defining and using TLS variables + * + * Copyright (c) 2011 Red Hat, Inc + * Copyright (c) 2011 Linaro Limited + * + * Authors: + * Paolo Bonzini + * Peter Maydell + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, see . + */ + +#ifndef QEMU_TLS_H +#define QEMU_TLS_H + +/* Per-thread variables. Note that we only have implementations + * which are really thread-local on Linux; the dummy implementations + * define plain global variables. + * + * This means that for the moment use should be restricted to + * per-VCPU variables, which are OK because: + * - the only -user mode supporting multiple VCPU threads is linux-user + * - TCG system mode is single-threaded regarding VCPUs + * - KVM system mode is multi-threaded but limited to Linux + * + * TODO: proper implementations via Win32 .tls sections and + * POSIX pthread_getspecific. + */ +#ifdef __linux__ +#define DECLARE_TLS(type, x) extern DEFINE_TLS(type, x) +#define DEFINE_TLS(type, x) __thread __typeof__(type) tls__##x +#define get_tls(x) tls__##x +#else +/* Dummy implementations which define plain global variables */ +#define DECLARE_TLS(type, x) extern DEFINE_TLS(type, x) +#define DEFINE_TLS(type, x) __typeof__(type) tls__##x +#define get_tls(x) tls__##x +#endif + +#endif