1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-08-05 19:35:52 +03:00

* sysdeps/mips/pspinlock.c (__pthread_spin_lock): Implement for

R3K. 
* sysdeps/mips/pt-machine.h (testandset): Likewise.
2000-07-12  Maciej W. Rozycki  <macro@ds2.pg.gda.pl>

	* sysdeps/mips/pspinlock.c (__pthread_spin_lock): Implement for
	R3K.
	* sysdeps/mips/pt-machine.h (testandset): Likewise.
This commit is contained in:
Andreas Jaeger
2000-07-28 13:36:23 +00:00
parent f1e0984603
commit fdfb2eccca
3 changed files with 90 additions and 54 deletions

View File

@@ -1,3 +1,9 @@
2000-07-12 Maciej W. Rozycki <macro@ds2.pg.gda.pl>
* sysdeps/mips/pspinlock.c (__pthread_spin_lock): Implement for
R3K.
* sysdeps/mips/pt-machine.h (testandset): Likewise.
2000-07-26 Andreas Jaeger <aj@suse.de> 2000-07-26 Andreas Jaeger <aj@suse.de>
* pthread.c: Initialize p_sem_avail. * pthread.c: Initialize p_sem_avail.

View File

@@ -19,8 +19,12 @@
#include <errno.h> #include <errno.h>
#include <pthread.h> #include <pthread.h>
#include <sgidefs.h>
#include <sys/tas.h>
#if (_MIPS_ISA >= _MIPS_ISA_MIPS2)
/* This implementation is similar to the one used in the Linux kernel. */ /* This implementation is similar to the one used in the Linux kernel. */
int int
__pthread_spin_lock (pthread_spinlock_t *lock) __pthread_spin_lock (pthread_spinlock_t *lock)
@@ -28,22 +32,34 @@ __pthread_spin_lock (pthread_spinlock_t *lock)
unsigned int tmp; unsigned int tmp;
asm volatile asm volatile
(".set\tnoreorder\t\t\t# spin_lock\n" ("\t\t\t# spin_lock\n\t"
".set\tpush\n" "1:\n\t"
".set\tmips2\n" "ll %1,%2\n\t"
"1:\tll\t%1, %2\n\t" ".set push\n\t"
"bnez\t%1, 1b\n\t" ".set noreorder\n\t"
" li\t%1, 1\n\t" "bnez %1,1b\n\t"
"sc\t%1, %0\n\t" " li %1,1\n\t"
"beqz\t%1, 1b\n\t" ".set pop\n\t"
".set\tpop\n" "sc %1,%0\n\t"
".set\treorder" "beqz %1,1b"
: "=o" (*lock), "=&r" (tmp) : "=m" (*lock), "=&r" (tmp)
: "o" (*lock) : "m" (*lock)
: "memory"); : "memory");
return 0; return 0;
} }
#else /* !(_MIPS_ISA >= _MIPS_ISA_MIPS2) */
int
__pthread_spin_lock (pthread_spinlock_t *lock)
{
while (_test_and_set (lock, 1));
return 0;
}
#endif /* !(_MIPS_ISA >= _MIPS_ISA_MIPS2) */
weak_alias (__pthread_spin_lock, pthread_spin_lock) weak_alias (__pthread_spin_lock, pthread_spin_lock)
@@ -60,11 +76,10 @@ int
__pthread_spin_unlock (pthread_spinlock_t *lock) __pthread_spin_unlock (pthread_spinlock_t *lock)
{ {
asm volatile asm volatile
(".set\tnoreorder\t\t\t# spin_unlock\n\t" ("\t\t\t# spin_unlock\n\t"
"sw\t$0, %0\n\t" "sw $0,%0"
".set\treorder" : "=m" (*lock)
: "=o" (*lock) :
: "o" (*lock)
: "memory"); : "memory");
return 0; return 0;
} }

View File

@@ -18,13 +18,10 @@
You should have received a copy of the GNU Library General Public You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
TODO: This version makes use of MIPS ISA 2 features. It won't #include <sgidefs.h>
work on ISA 1. These machines will have to take the overhead of #include <sys/tas.h>
a sysmips(MIPS_ATOMIC_SET, ...) syscall which isn't implemented
yet correctly. There is however a better solution for R3000
uniprocessor machines possible. */
#ifndef PT_EI #ifndef PT_EI
# define PT_EI extern inline # define PT_EI extern inline
@@ -35,30 +32,43 @@
/* Spinlock implementation; required. */ /* Spinlock implementation; required. */
#if (_MIPS_ISA >= _MIPS_ISA_MIPS2)
PT_EI long int PT_EI long int
testandset (int *spinlock) testandset (int *spinlock)
{ {
long int ret, temp; long int ret, temp;
__asm__ __volatile__( __asm__ __volatile__
"# Inline spinlock test & set\n\t" ("/* Inline spinlock test & set */\n\t"
".set\tmips2\n" "1:\n\t"
"1:\tll\t%0,%3\n\t" "ll %0,%3\n\t"
"bnez\t%0,2f\n\t" ".set push\n\t"
".set\tnoreorder\n\t" ".set noreorder\n\t"
"li\t%1,1\n\t" "bnez %0,2f\n\t"
".set\treorder\n\t" " li %1,1\n\t"
"sc\t%1,%2\n\t" ".set pop\n\t"
"beqz\t%1,1b\n" "sc %1,%2\n\t"
"2:\t.set\tmips0\n\t" "beqz %1,1b\n"
"/* End spinlock test & set */" "2:\n\t"
: "=&r"(ret), "=&r" (temp), "=m"(*spinlock) "/* End spinlock test & set */"
: "m"(*spinlock) : "=&r" (ret), "=&r" (temp), "=m" (*spinlock)
: "memory"); : "m" (*spinlock)
: "memory");
return ret; return ret;
} }
#else /* !(_MIPS_ISA >= _MIPS_ISA_MIPS2) */
PT_EI long int
testandset (int *spinlock)
{
return _test_and_set (spinlock, 1);
}
#endif /* !(_MIPS_ISA >= _MIPS_ISA_MIPS2) */
/* Get some notion of the current stack. Need not be exactly the top /* Get some notion of the current stack. Need not be exactly the top
of the stack, just something somewhere in the current frame. */ of the stack, just something somewhere in the current frame. */
@@ -68,27 +78,32 @@ register char * stack_pointer __asm__ ("$29");
/* Compare-and-swap for semaphores. */ /* Compare-and-swap for semaphores. */
#if (_MIPS_ISA >= _MIPS_ISA_MIPS2)
#define HAS_COMPARE_AND_SWAP #define HAS_COMPARE_AND_SWAP
PT_EI int PT_EI int
__compare_and_swap (long int *p, long int oldval, long int newval) __compare_and_swap (long int *p, long int oldval, long int newval)
{ {
long ret; long int ret;
__asm__ __volatile__ ( __asm__ __volatile__
"/* Inline compare & swap */\n\t" ("/* Inline compare & swap */\n\t"
".set\tmips2\n" "1:\n\t"
"1:\tll\t%0,%4\n\t" "ll %0,%4\n\t"
".set\tnoreorder\n\t" ".set push\n"
"bne\t%0,%2,2f\n\t" ".set noreorder\n\t"
"move\t%0,%3\n\t" "bne %0,%2,2f\n\t"
".set\treorder\n\t" " move %0,%3\n\t"
"sc\t%0,%1\n\t" ".set pop\n\t"
"beqz\t%0,1b\n" "sc %0,%1\n\t"
"2:\t.set\tmips0\n\t" "beqz %0,1b\n"
"/* End compare & swap */" "2:\n\t"
: "=&r"(ret), "=m"(*p) "/* End compare & swap */"
: "r"(oldval), "r"(newval), "m"(*p) : "=&r" (ret), "=m" (*p)
: "memory"); : "r" (oldval), "r" (newval), "m" (*p)
: "memory");
return ret; return ret;
} }
#endif /* (_MIPS_ISA >= _MIPS_ISA_MIPS2) */