From patchwork Thu Oct 13 20:35:01 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harsh Prateek Bora X-Patchwork-Id: 119607 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 32907B70F5 for ; Fri, 14 Oct 2011 07:35:26 +1100 (EST) Received: from localhost ([::1]:53869 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RERzr-0006cV-QR for incoming@patchwork.ozlabs.org; Thu, 13 Oct 2011 16:35:19 -0400 Received: from eggs.gnu.org ([140.186.70.92]:41036) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RERzl-0006c5-PX for qemu-devel@nongnu.org; Thu, 13 Oct 2011 16:35:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RERzj-0007Z8-QZ for qemu-devel@nongnu.org; Thu, 13 Oct 2011 16:35:13 -0400 Received: from e28smtp06.in.ibm.com ([122.248.162.6]:35960) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RERzj-0007YL-8c for qemu-devel@nongnu.org; Thu, 13 Oct 2011 16:35:11 -0400 Received: from d28relay05.in.ibm.com (d28relay05.in.ibm.com [9.184.220.62]) by e28smtp06.in.ibm.com (8.14.4/8.13.1) with ESMTP id p9DKZ7gZ027054 for ; Fri, 14 Oct 2011 02:05:07 +0530 Received: from d28av01.in.ibm.com (d28av01.in.ibm.com [9.184.220.63]) by d28relay05.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p9DKZ6pB3305664 for ; Fri, 14 Oct 2011 02:05:06 +0530 Received: from d28av01.in.ibm.com (loopback [127.0.0.1]) by d28av01.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p9DKZ6nW023078 for ; Fri, 14 Oct 2011 02:05:06 +0530 Received: from harshbora.in.ibm.com ([9.77.195.160]) by d28av01.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p9DKZ50P022942; Fri, 14 Oct 2011 02:05:06 +0530 From: Harsh Prateek Bora To: qemu-devel@nongnu.org Date: Fri, 14 Oct 2011 02:05:01 +0530 Message-Id: <1318538102-6982-1-git-send-email-harsh@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Received-From: 122.248.162.6 Cc: pbonzini@redhat.com, jan.kiszka@web.de, aneesh.kumar@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH v2 1/2] Introduce QLIST_INSERT_HEAD_RCU and dummy RCU wrappers. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org SynthFS needs a QLIST_INSERT_HEAD_RCU to make sure list instructions are not re-ordered and therefore avoiding a crash. There may be parallel readers which should be allowed for lock-free access and this variant allows us to get rid of rwlocks used by readers. SynthFS is a special case where we dont really need full RCU capabilities as it doesnt allow list entry deletion but concurrent readers/writers and instruction re-ordering should not result in a crash. Also, once the real rcu is available, dummy rcu macro definitions will go away and the code will still work as expected. This patchwork is based on inputs from Paolo Bonzini. Signed-off-by: Harsh Prateek Bora --- qemu-queue.h | 12 ++++++++++++ qemu-thread.h | 3 +++ 2 files changed, 15 insertions(+), 0 deletions(-) diff --git a/qemu-queue.h b/qemu-queue.h index 1d07745..57234f8 100644 --- a/qemu-queue.h +++ b/qemu-queue.h @@ -76,6 +76,8 @@ * For details on the use of these macros, see the queue(3) manual page. */ +#include "qemu-barrier.h" /* for smp_wmb() */ + /* * List definitions. */ @@ -122,6 +124,16 @@ struct { \ (elm)->field.le_prev = &(head)->lh_first; \ } while (/*CONSTCOND*/0) +#define QLIST_INSERT_HEAD_RCU(head, elm, field) do { \ + (elm)->field.le_prev = &(head)->lh_first; \ + smp_wmb(); \ + if (((elm)->field.le_next = (head)->lh_first) != NULL) \ + (head)->lh_first->field.le_prev = &(elm)->field.le_next;\ + smp_wmb(); \ + (head)->lh_first = (elm); \ + smp_wmb(); \ +} while (/* CONSTCOND*/0) + #define QLIST_REMOVE(elm, field) do { \ if ((elm)->field.le_next != NULL) \ (elm)->field.le_next->field.le_prev = \ diff --git a/qemu-thread.h b/qemu-thread.h index 0a73d50..e008b60 100644 --- a/qemu-thread.h +++ b/qemu-thread.h @@ -19,6 +19,9 @@ void qemu_mutex_lock(QemuMutex *mutex); int qemu_mutex_trylock(QemuMutex *mutex); void qemu_mutex_unlock(QemuMutex *mutex); +#define rcu_read_lock() do { } while (0) +#define rcu_read_unlock() do { } while (0) + void qemu_cond_init(QemuCond *cond); void qemu_cond_destroy(QemuCond *cond);