From: David Howells <dhowells@redhat.com>
To: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [patch] 2.4.4 alpha semaphores optimization
Date: Fri, 04 May 2001 10:22:53 +0100 [thread overview]
Message-ID: <14842.988968173@warthog.cambridge.redhat.com> (raw)
In-Reply-To: Your message of "Thu, 03 May 2001 19:47:47 +0400." <20010503194747.A552@jurassic.park.msu.ru>
Hello Ivan,
One reason I picked "signed long" as the count type in the lib/rwsem.c is that
this would be 64 bits on a 64-bit arch such as the alpha.
So I've taken your idea for include/asm-alpha/rwsem.h and modified it a
little. You'll find it attached at the bottom.
I don't know whether it will (a) compile, or (b) work... I don't have an alpha
to play with.
I also don't know the alpha function calling convention, so I can't put direct
calls to the fallback routines in lib/rwsem.c from the ".subsection 2"
bits. Can you do that, or can you tell me how the calling convention works?
Cheers,
David
===============================================================================
#ifndef _ALPHA_RWSEM_H
#define _ALPHA_RWSEM_H
/*
* Written by Ivan Kokshaysky <ink@jurassic.park.msu.ru>, 2001.
* Based on asm-alpha/semaphore.h and asm-i386/rwsem.h
*/
#ifndef _LINUX_RWSEM_H
#error please dont include asm/rwsem.h directly, use linux/rwsem.h instead
#endif
#ifdef __KERNEL__
#include <linux/list.h>
#include <linux/spinlock.h>
struct rwsem_waiter;
extern struct rw_semaphore *rwsem_down_read_failed(struct rw_semaphore *sem);
extern struct rw_semaphore *rwsem_down_write_failed(struct rw_semaphore *sem);
extern struct rw_semaphore *rwsem_wake(struct rw_semaphore *);
/*
* the semaphore definition
*/
struct rw_semaphore {
signed long count;
#define RWSEM_UNLOCKED_VALUE 0x0000000000000000
#define RWSEM_ACTIVE_BIAS 0x0000000000000001
#define RWSEM_ACTIVE_MASK 0x00000000ffffffff
#define RWSEM_WAITING_BIAS (-0x0000000100000000)
#define RWSEM_ACTIVE_READ_BIAS RWSEM_ACTIVE_BIAS
#define RWSEM_ACTIVE_WRITE_BIAS (RWSEM_WAITING_BIAS + RWSEM_ACTIVE_BIAS)
spinlock_t wait_lock;
struct list_head wait_list;
#if RWSEM_DEBUG
int debug;
#endif
};
#if RWSEM_DEBUG
#define __RWSEM_DEBUG_INIT , 0
#else
#define __RWSEM_DEBUG_INIT /* */
#endif
#define __RWSEM_INITIALIZER(name) \
{ ATOMIC_INIT(RWSEM_UNLOCKED_VALUE), SPIN_LOCK_UNLOCKED, \
LIST_HEAD_INIT((name).wait_list) __RWSEM_DEBUG_INIT }
#define DECLARE_RWSEM(name) \
struct rw_semaphore name = __RWSEM_INITIALIZER(name)
static inline void init_rwsem(struct rw_semaphore *sem)
{
sem->count = RWSEM_UNLOCKED_VALUE;
spin_lock_init(&sem->wait_lock);
INIT_LIST_HEAD(&sem->wait_list);
#if RWSEM_DEBUG
sem->debug = 0;
#endif
}
static inline void __down_read(struct rw_semaphore *sem)
{
signed long oldcount, temp;
__asm__ __volatile__(
"1: ldq_l %0,%1\n"
" addq %0,%3,%2\n"
" stq_c %2,%1\n"
" beq %2,2f\n"
#ifdef CONFIG_SMP
" mb\n"
#endif
".subsection 2\n"
"2: br 1b\n"
".previous"
:"=&r" (oldcount), "=m" (sem->count), "=&r" (temp)
:"Ir" (RWSEM_ACTIVE_READ_BIAS), "m" (sem->count) : "memory");
if (oldcount < 0)
rwsem_down_read_failed(sem);
}
static inline void __down_write(struct rw_semaphore *sem)
{
signed long granted, temp;
__asm__ __volatile__(
"1: ldq_l %0,%1\n"
" addq %0,%3,%2\n"
" stq_c %2,%1\n"
" beq %2,2f\n"
#ifdef CONFIG_SMP
" mb\n"
" cmpeq %0,0,%0\n"
#endif
".subsection 2\n"
"2: br 1b\n"
".previous"
:"=&r" (granted), "=m" (sem->count), "=&r" (temp)
:"Ir" (RWSEM_ACTIVE_WRITE_BIAS), "m" (sem->count) : "memory");
if (!granted)
rwsem_down_write_failed(sem);
}
static inline void __up_read(struct rw_semaphore *sem)
{
signed long oldcount, temp;
__asm__ __volatile__(
"1: ldq_l %0,%1\n"
" subq %0,%3,%2\n"
" stq_c %2,%1\n"
" beq %2,2f\n"
#ifdef CONFIG_SMP
" mb\n"
#endif
".subsection 2\n"
"2: br 1b\n"
".previous"
:"=&r" (oldcount), "=m" (sem->count), "=&r" (temp)
:"Ir" (RWSEM_ACTIVE_READ_BIAS), "m" (sem->count) : "memory");
if (oldcount < 0)
if ((count & RWSEM_ACTIVE_MASK) == 0)
rwsem_wake(sem);
}
static inline void __up_write(struct rw_semaphore *sem)
{
signed long count, cmp;
__asm__ __volatile__(
"1: ldq_l %0,%1\n"
" subq %0,%3,%2\n"
" stq_c %2,%1\n"
" beq %2,2f\n"
#ifdef CONFIG_SMP
" mb\n"
" cmpeq %0,%3,%2\n"
" subq %0,%3,%0\n"
#endif
".subsection 2\n"
"2: br 1b\n"
".previous"
:"=&r" (count), "=m" (sem->count), "=&r" (cmp)
:"Ir" (RWSEM_ACTIVE_WRITE_BIAS), "m" (sem->count) : "memory");
if (!cmp)
if ((count & RWSEM_ACTIVE_MASK) == 0)
rwsem_wake(sem);
}
#define rwsem_atomic_add(val, sem) atomic_add(val, &(sem)->count)
#define rwsem_atomic_update(val, sem) atomic_add_return(val, &(sem)->count)
#endif /* __KERNEL__ */
#endif /* _ALPHA_RWSEM_H */
next prev parent reply other threads:[~2001-05-04 9:23 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-05-03 15:47 [patch] 2.4.4 alpha semaphores optimization Ivan Kokshaysky
2001-05-03 17:28 ` Andrea Arcangeli
2001-05-04 9:15 ` Ivan Kokshaysky
2001-05-04 14:33 ` Andrea Arcangeli
2001-05-04 17:02 ` Ivan Kokshaysky
2001-05-04 17:16 ` Andrea Arcangeli
2001-05-04 9:22 ` David Howells [this message]
2001-05-04 9:54 ` Ivan Kokshaysky
2001-05-04 16:46 ` Ivan Kokshaysky
2001-05-04 21:12 ` Richard Henderson
2001-05-05 13:55 ` Ivan Kokshaysky
2001-05-06 6:55 ` Ivan Kokshaysky
2001-05-04 21:13 ` Richard Henderson
2001-05-05 14:17 ` Ivan Kokshaysky
2001-05-05 17:06 ` __builtin_expect vs inlining Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=14842.988968173@warthog.cambridge.redhat.com \
--to=dhowells@redhat.com \
--cc=ink@jurassic.park.msu.ru \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.