* [PATCH] xen/spinlock: Use mnemonics for recursive spinlock sentinel values
@ 2016-01-09 14:33 Andrew Cooper
2016-01-11 14:19 ` Jan Beulich
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Cooper @ 2016-01-09 14:33 UTC (permalink / raw)
To: Xen-devel
Cc: Andrew Cooper, Tim Deegan, Ian Campbell, Jan Beulich, Doug Goldstein
Fix a fencepost error in the BUILD_BUG_ON() check. The sentinel must be
distinct from any legal cpu id.
No resulting change. The compiled binary is identical.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Tim Deegan <tim@xen.org>
CC: Ian Campbell <Ian.Campbell@citrix.com>
CC: Doug Goldstein <cardoe@cardoe.com>
Noticed while reviewing Doug's NR_CPUS patch.
---
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..22cf601 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;
--
2.1.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] xen/spinlock: Use mnemonics for recursive spinlock sentinel values
2016-01-09 14:33 [PATCH] xen/spinlock: Use mnemonics for recursive spinlock sentinel values Andrew Cooper
@ 2016-01-11 14:19 ` Jan Beulich
2016-01-11 15:35 ` Andrew Cooper
0 siblings, 1 reply; 3+ messages in thread
From: Jan Beulich @ 2016-01-11 14:19 UTC (permalink / raw)
To: Andrew Cooper; +Cc: Tim Deegan, Doug Goldstein, Ian Campbell, Xen-devel
>>> On 09.01.16 at 15:33, <andrew.cooper3@citrix.com> wrote:
> --- 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);
">" (see also the reply to Doug's patch 1/2)
Jan
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] xen/spinlock: Use mnemonics for recursive spinlock sentinel values
2016-01-11 14:19 ` Jan Beulich
@ 2016-01-11 15:35 ` Andrew Cooper
0 siblings, 0 replies; 3+ messages in thread
From: Andrew Cooper @ 2016-01-11 15:35 UTC (permalink / raw)
To: Jan Beulich; +Cc: Tim Deegan, Doug Goldstein, Ian Campbell, Xen-devel
On 11/01/16 14:19, Jan Beulich wrote:
>>>> On 09.01.16 at 15:33, <andrew.cooper3@citrix.com> wrote:
>> --- 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);
> ">" (see also the reply to Doug's patch 1/2)
So it is.
As there is no bug, I will resubmit the cleanup when the NR_CPUS series
is in to avoid causing patch conflicts.
~Andrew
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-01-11 15:35 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-09 14:33 [PATCH] xen/spinlock: Use mnemonics for recursive spinlock sentinel values Andrew Cooper
2016-01-11 14:19 ` Jan Beulich
2016-01-11 15:35 ` Andrew Cooper
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.