From patchwork Thu Jan 14 18:33:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 8034911 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 68B83BEEE5 for ; Thu, 14 Jan 2016 18:36:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 91C5420499 for ; Thu, 14 Jan 2016 18:36:57 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AAC1520458 for ; Thu, 14 Jan 2016 18:36:56 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aJmiJ-0007qy-VW; Thu, 14 Jan 2016 18:33:39 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aJmiJ-0007qt-3y for xen-devel@lists.xen.org; Thu, 14 Jan 2016 18:33:39 +0000 Received: from [193.109.254.147] by server-8.bemta-14.messagelabs.com id D4/65-24450-20AE7965; Thu, 14 Jan 2016 18:33:38 +0000 X-Env-Sender: prvs=8143030eb=Andrew.Cooper3@citrix.com X-Msg-Ref: server-15.tower-27.messagelabs.com!1452796416!16955463!1 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 8473 invoked from network); 14 Jan 2016 18:33:37 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-15.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 14 Jan 2016 18:33:37 -0000 X-IronPort-AV: E=Sophos;i="5.22,295,1449532800"; d="scan'208";a="325246546" From: Andrew Cooper To: Xen-devel Date: Thu, 14 Jan 2016 18:33:28 +0000 Message-ID: <1452796408-31882-1-git-send-email-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.1.4 MIME-Version: 1.0 X-DLP: MIA2 Cc: Andrew Cooper , Tim Deegan , Ian Campbell , Jan Beulich Subject: [Xen-devel] [PATCH v2] xen/spinlock: Use mnemonics for recursive spinlock sentinel values X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP No resulting change. The compiled binary is identical. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Tim Deegan CC: Ian Campbell v2: Remove the fencepost adjustment. All valid cpu ids are < NR_CPUS. --- xen/common/spinlock.c | 8 ++++---- xen/include/xen/spinlock.h | 6 ++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/xen/common/spinlock.c b/xen/common/spinlock.c index 7f89694..7b0cf6c 100644 --- a/xen/common/spinlock.c +++ b/xen/common/spinlock.c @@ -246,7 +246,7 @@ int _spin_trylock_recursive(spinlock_t *lock) unsigned int cpu = smp_processor_id(); /* Don't allow overflow of recurse_cpu field. */ - BUILD_BUG_ON(NR_CPUS > 0xfffu); + BUILD_BUG_ON(NR_CPUS > SPINLOCK_NO_CPU); check_lock(&lock->debug); @@ -258,7 +258,7 @@ int _spin_trylock_recursive(spinlock_t *lock) } /* We support only fairly shallow recursion, else the counter overflows. */ - ASSERT(lock->recurse_cnt < 0xfu); + ASSERT(lock->recurse_cnt < SPINLOCK_MAX_RECURSE); lock->recurse_cnt++; return 1; @@ -275,7 +275,7 @@ void _spin_lock_recursive(spinlock_t *lock) } /* We support only fairly shallow recursion, else the counter overflows. */ - ASSERT(lock->recurse_cnt < 0xfu); + ASSERT(lock->recurse_cnt < SPINLOCK_MAX_RECURSE); lock->recurse_cnt++; } @@ -283,7 +283,7 @@ void _spin_unlock_recursive(spinlock_t *lock) { if ( likely(--lock->recurse_cnt == 0) ) { - lock->recurse_cpu = 0xfffu; + lock->recurse_cpu = SPINLOCK_NO_CPU; spin_unlock(lock); } } diff --git a/xen/include/xen/spinlock.h b/xen/include/xen/spinlock.h index fb0438e..9555c53 100644 --- a/xen/include/xen/spinlock.h +++ b/xen/include/xen/spinlock.h @@ -80,7 +80,7 @@ struct lock_profile_qhead { static struct lock_profile *__lock_profile_##name \ __used_section(".lockprofile.data") = \ &__lock_profile_data_##name -#define _SPIN_LOCK_UNLOCKED(x) { { 0 }, 0xfffu, 0, _LOCK_DEBUG, x } +#define _SPIN_LOCK_UNLOCKED(x) { { 0 }, SPINLOCK_NO_CPU, 0, _LOCK_DEBUG, x } #define SPIN_LOCK_UNLOCKED _SPIN_LOCK_UNLOCKED(NULL) #define DEFINE_SPINLOCK(l) \ spinlock_t l = _SPIN_LOCK_UNLOCKED(NULL); \ @@ -116,7 +116,7 @@ extern void spinlock_profile_reset(unsigned char key); struct lock_profile_qhead { }; -#define SPIN_LOCK_UNLOCKED { { 0 }, 0xfffu, 0, _LOCK_DEBUG } +#define SPIN_LOCK_UNLOCKED { { 0 }, SPINLOCK_NO_CPU, 0, _LOCK_DEBUG } #define DEFINE_SPINLOCK(l) spinlock_t l = SPIN_LOCK_UNLOCKED #define spin_lock_init_prof(s, l) spin_lock_init(&((s)->l)) @@ -138,7 +138,9 @@ typedef union { typedef struct spinlock { spinlock_tickets_t tickets; u16 recurse_cpu:12; +#define SPINLOCK_NO_CPU 0xfffu u16 recurse_cnt:4; +#define SPINLOCK_MAX_RECURSE 0xfu struct lock_debug debug; #ifdef LOCK_PROFILE struct lock_profile *profile;