From 5a5fb3b9d6d99d6751d129458217f1a3b5b85ff8 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Fri, 18 Mar 2016 14:03:01 +0100 Subject: score: Avoid Giant lock for CORE spinlock Use an ISR lock to protect the spinlock state. Remove empty attributes. Update #2555. --- cpukit/posix/include/rtems/posix/spinlockimpl.h | 27 ++++------- cpukit/posix/src/pspindestroy.c | 63 ++++++++----------------- cpukit/posix/src/pspininit.c | 5 +- cpukit/posix/src/pspinlock.c | 50 ++++++-------------- cpukit/posix/src/pspintrylock.c | 52 ++++++-------------- cpukit/posix/src/pspinunlock.c | 47 ++++-------------- 6 files changed, 69 insertions(+), 175 deletions(-) (limited to 'cpukit/posix') diff --git a/cpukit/posix/include/rtems/posix/spinlockimpl.h b/cpukit/posix/include/rtems/posix/spinlockimpl.h index 01fe372aca..0904050288 100644 --- a/cpukit/posix/include/rtems/posix/spinlockimpl.h +++ b/cpukit/posix/include/rtems/posix/spinlockimpl.h @@ -75,26 +75,19 @@ RTEMS_INLINE_ROUTINE void _POSIX_Spinlock_Free ( _Objects_Free( &_POSIX_Spinlock_Information, &the_spinlock->Object ); } -/** - * @brief Get a spinlock control block. - * - * This function maps spinlock IDs to spinlock control blocks. - * If ID corresponds to a local spinlock, then it returns - * the_spinlock control pointer which maps to ID and location - * is set to OBJECTS_LOCAL. if the spinlock ID is global and - * resides on a remote node, then location is set to OBJECTS_REMOTE, - * and the_spinlock is undefined. Otherwise, location is set - * to OBJECTS_ERROR and the_spinlock is undefined. - */ -RTEMS_INLINE_ROUTINE POSIX_Spinlock_Control *_POSIX_Spinlock_Get ( +RTEMS_INLINE_ROUTINE POSIX_Spinlock_Control *_POSIX_Spinlock_Get( pthread_spinlock_t *spinlock, - Objects_Locations *location + ISR_lock_Context *lock_context ) { - return (POSIX_Spinlock_Control *) _Objects_Get( - &_POSIX_Spinlock_Information, - (Objects_Id) *spinlock, - location + if ( spinlock == NULL ) { + return NULL; + } + + return (POSIX_Spinlock_Control *) _Objects_Get_local( + &_POSIX_Spinlock_Information, + *spinlock, + lock_context ); } diff --git a/cpukit/posix/src/pspindestroy.c b/cpukit/posix/src/pspindestroy.c index ab45ad1e92..42a6e76806 100644 --- a/cpukit/posix/src/pspindestroy.c +++ b/cpukit/posix/src/pspindestroy.c @@ -18,58 +18,35 @@ #include "config.h" #endif -#include -#include - -#include #include -/** - * This directive allows a thread to delete a spinlock specified by - * the spinlock id. The spinlock is freed back to the inactive - * spinlock chain. - * - * @param[in] spinlock is the spinlock id - * - * @return This method returns 0 if there was not an - * error. Otherwise, a status code is returned indicating the - * source of the error. - */ -int pthread_spin_destroy( - pthread_spinlock_t *spinlock -) -{ - POSIX_Spinlock_Control *the_spinlock = NULL; - Objects_Locations location; +#include - if ( !spinlock ) - return EINVAL; +int pthread_spin_destroy( pthread_spinlock_t *spinlock ) +{ + POSIX_Spinlock_Control *the_spinlock; + ISR_lock_Context lock_context; _Objects_Allocator_lock(); - the_spinlock = _POSIX_Spinlock_Get( spinlock, &location ); - switch ( location ) { - case OBJECTS_LOCAL: - if ( _CORE_spinlock_Is_busy( &the_spinlock->Spinlock ) ) { - _Objects_Put( &the_spinlock->Object ); - return EBUSY; - } - - _Objects_Close( &_POSIX_Spinlock_Information, &the_spinlock->Object ); - _Objects_Put( &the_spinlock->Object ); - _POSIX_Spinlock_Free( the_spinlock ); - _Objects_Allocator_unlock(); + the_spinlock = _POSIX_Spinlock_Get( spinlock, &lock_context ); + if ( the_spinlock == NULL ) { + _Objects_Allocator_unlock(); + return EINVAL; + } - return 0; + _CORE_spinlock_Acquire_critical( &the_spinlock->Spinlock, &lock_context ); -#if defined(RTEMS_MULTIPROCESSING) - case OBJECTS_REMOTE: -#endif - case OBJECTS_ERROR: - break; + if ( _CORE_spinlock_Is_busy( &the_spinlock->Spinlock ) ) { + _CORE_spinlock_Release( &the_spinlock->Spinlock, &lock_context ); + _Objects_Allocator_unlock(); + return EBUSY; } - _Objects_Allocator_unlock(); + _CORE_spinlock_Release( &the_spinlock->Spinlock, &lock_context ); - return EINVAL; + _Objects_Close( &_POSIX_Spinlock_Information, &the_spinlock->Object ); + _POSIX_Spinlock_Free( the_spinlock ); + _Objects_Allocator_unlock(); + return 0; } diff --git a/cpukit/posix/src/pspininit.c b/cpukit/posix/src/pspininit.c index 02b07c8468..bc131e2e81 100644 --- a/cpukit/posix/src/pspininit.c +++ b/cpukit/posix/src/pspininit.c @@ -47,7 +47,6 @@ int pthread_spin_init( ) { POSIX_Spinlock_Control *the_spinlock; - CORE_spinlock_Attributes attributes; if ( !spinlock ) return EINVAL; @@ -67,9 +66,7 @@ int pthread_spin_init( return EAGAIN; } - _CORE_spinlock_Initialize_attributes( &attributes ); - - _CORE_spinlock_Initialize( &the_spinlock->Spinlock, &attributes ); + _CORE_spinlock_Initialize( &the_spinlock->Spinlock ); _Objects_Open_u32( &_POSIX_Spinlock_Information, &the_spinlock->Object, 0 ); diff --git a/cpukit/posix/src/pspinlock.c b/cpukit/posix/src/pspinlock.c index d13ffe6b5c..502177c50e 100644 --- a/cpukit/posix/src/pspinlock.c +++ b/cpukit/posix/src/pspinlock.c @@ -18,46 +18,26 @@ #include "config.h" #endif -#include -#include - -#include #include -/** - * This directive allows a thread to wait at a spinlock. - * - * @param[in] spinlock is spinlock id - * - * @return This method returns 0 if there was not an - * error. Otherwise, a status code is returned indicating the - * source of the error. - */ -int pthread_spin_lock( - pthread_spinlock_t *spinlock -) +#include + +int pthread_spin_lock( pthread_spinlock_t *spinlock ) { - POSIX_Spinlock_Control *the_spinlock = NULL; - Objects_Locations location; - CORE_spinlock_Status status; + POSIX_Spinlock_Control *the_spinlock; + ISR_lock_Context lock_context; + CORE_spinlock_Status status; - if ( !spinlock ) + the_spinlock = _POSIX_Spinlock_Get( spinlock, &lock_context ); + if ( the_spinlock == NULL ) { return EINVAL; - - the_spinlock = _POSIX_Spinlock_Get( spinlock, &location ); - switch ( location ) { - - case OBJECTS_LOCAL: - status = _CORE_spinlock_Wait( &the_spinlock->Spinlock, true, 0 ); - _Objects_Put( &the_spinlock->Object ); - return _POSIX_Spinlock_Translate_core_spinlock_return_code( status ); - -#if defined(RTEMS_MULTIPROCESSING) - case OBJECTS_REMOTE: -#endif - case OBJECTS_ERROR: - break; } - return EINVAL; + status = _CORE_spinlock_Seize( + &the_spinlock->Spinlock, + true, + 0, + &lock_context + ); + return _POSIX_Spinlock_Translate_core_spinlock_return_code( status ); } diff --git a/cpukit/posix/src/pspintrylock.c b/cpukit/posix/src/pspintrylock.c index d304908559..5f132a3193 100644 --- a/cpukit/posix/src/pspintrylock.c +++ b/cpukit/posix/src/pspintrylock.c @@ -18,50 +18,26 @@ #include "config.h" #endif -#include -#include - -#include #include -/* - * pthread_spin_trylock - * - * This directive allows a thread to poll an attempt at locking a spinlock. - * - * Input parameters: - * spinlock - spinlock id - * - * Output parameters: - * 0 - if successful - * error code - if unsuccessful - */ +#include -int pthread_spin_trylock( - pthread_spinlock_t *spinlock -) +int pthread_spin_trylock( pthread_spinlock_t *spinlock ) { - POSIX_Spinlock_Control *the_spinlock = NULL; - Objects_Locations location; - CORE_spinlock_Status status; + POSIX_Spinlock_Control *the_spinlock; + ISR_lock_Context lock_context; + CORE_spinlock_Status status; - if ( !spinlock ) + the_spinlock = _POSIX_Spinlock_Get( spinlock, &lock_context ); + if ( the_spinlock == NULL ) { return EINVAL; - - the_spinlock = _POSIX_Spinlock_Get( spinlock, &location ); - switch ( location ) { - - case OBJECTS_LOCAL: - status = _CORE_spinlock_Wait( &the_spinlock->Spinlock, false, 0 ); - _Objects_Put( &the_spinlock->Object ); - return _POSIX_Spinlock_Translate_core_spinlock_return_code( status ); - -#if defined(RTEMS_MULTIPROCESSING) - case OBJECTS_REMOTE: -#endif - case OBJECTS_ERROR: - break; } - return EINVAL; + status = _CORE_spinlock_Seize( + &the_spinlock->Spinlock, + false, + 0, + &lock_context + ); + return _POSIX_Spinlock_Translate_core_spinlock_return_code( status ); } diff --git a/cpukit/posix/src/pspinunlock.c b/cpukit/posix/src/pspinunlock.c index 3a483adab0..35dbcb977f 100644 --- a/cpukit/posix/src/pspinunlock.c +++ b/cpukit/posix/src/pspinunlock.c @@ -20,50 +20,21 @@ #include "config.h" #endif -#include -#include - -#include #include -/* - * pthread_spin_unlock - * - * This directive allows a thread to wait at a spinlock. - * - * Input parameters: - * spinlock - spinlock id - * - * Output parameters: - * 0 - if successful - * error code - if unsuccessful - */ +#include -int pthread_spin_unlock( - pthread_spinlock_t *spinlock -) +int pthread_spin_unlock( pthread_spinlock_t *spinlock ) { - POSIX_Spinlock_Control *the_spinlock = NULL; - Objects_Locations location; - CORE_spinlock_Status status; + POSIX_Spinlock_Control *the_spinlock; + ISR_lock_Context lock_context; + CORE_spinlock_Status status; - if ( !spinlock ) + the_spinlock = _POSIX_Spinlock_Get( spinlock, &lock_context ); + if ( the_spinlock == NULL ) { return EINVAL; - - the_spinlock = _POSIX_Spinlock_Get( spinlock, &location ); - switch ( location ) { - - case OBJECTS_LOCAL: - status = _CORE_spinlock_Release( &the_spinlock->Spinlock ); - _Objects_Put( &the_spinlock->Object ); - return _POSIX_Spinlock_Translate_core_spinlock_return_code( status ); - -#if defined(RTEMS_MULTIPROCESSING) - case OBJECTS_REMOTE: -#endif - case OBJECTS_ERROR: - break; } - return EINVAL; + status = _CORE_spinlock_Surrender( &the_spinlock->Spinlock, &lock_context ); + return _POSIX_Spinlock_Translate_core_spinlock_return_code( status ); } -- cgit v1.2.3