score: Add local context to SMP lock API

Add a local context structure to the SMP lock API for acquire and
release pairs.  This context can be used to store the ISR level and
profiling information.  It may be later used to enable more
sophisticated lock algorithms, e.g. MCS locks.

There is only one lock that cannot be used with a local context.  This
is the per-CPU lock since here we would have to transfer the local
context through a context switch which is very complicated.
This commit is contained in:
Sebastian Huber
2014-03-10 08:25:32 +01:00
parent ae88aa7927
commit d50acdbb6c
33 changed files with 480 additions and 329 deletions

View File

@@ -97,10 +97,11 @@ static void test_0_body(
)
{
unsigned long counter = 0;
SMP_lock_Context lock_context;
while (assert_state(ctx, START_TEST)) {
_SMP_lock_Acquire(&ctx->lock);
_SMP_lock_Release(&ctx->lock);
_SMP_lock_Acquire(&ctx->lock, &lock_context);
_SMP_lock_Release(&ctx->lock, &lock_context);
++counter;
}
@@ -116,11 +117,12 @@ static void test_1_body(
)
{
unsigned long counter = 0;
SMP_lock_Context lock_context;
while (assert_state(ctx, START_TEST)) {
_SMP_lock_Acquire(&ctx->lock);
_SMP_lock_Acquire(&ctx->lock, &lock_context);
++ctx->counter[test];
_SMP_lock_Release(&ctx->lock);
_SMP_lock_Release(&ctx->lock, &lock_context);
++counter;
}
@@ -137,10 +139,11 @@ static void test_2_body(
{
unsigned long counter = 0;
SMP_lock_Control lock = SMP_LOCK_INITIALIZER;
SMP_lock_Context lock_context;
while (assert_state(ctx, START_TEST)) {
_SMP_lock_Acquire(&lock);
_SMP_lock_Release(&lock);
_SMP_lock_Acquire(&lock, &lock_context);
_SMP_lock_Release(&lock, &lock_context);
++counter;
}
@@ -157,14 +160,15 @@ static void test_3_body(
{
unsigned long counter = 0;
SMP_lock_Control lock = SMP_LOCK_INITIALIZER;
SMP_lock_Context lock_context;
while (assert_state(ctx, START_TEST)) {
_SMP_lock_Acquire(&lock);
_SMP_lock_Acquire(&lock, &lock_context);
/* The counter value is not interesting, only the access to it */
++ctx->counter[test];
_SMP_lock_Release(&lock);
_SMP_lock_Release(&lock, &lock_context);
++counter;
}
@@ -189,11 +193,12 @@ static void test_4_body(
)
{
unsigned long counter = 0;
SMP_lock_Context lock_context;
while (assert_state(ctx, START_TEST)) {
_SMP_lock_Acquire(&ctx->lock);
_SMP_lock_Acquire(&ctx->lock, &lock_context);
busy_section();
_SMP_lock_Release(&ctx->lock);
_SMP_lock_Release(&ctx->lock, &lock_context);
++counter;
}

View File

@@ -162,20 +162,20 @@ static void test_isr_locks( void )
ISR_Level normal_interrupt_level = _ISR_Get_level();
ISR_lock_Control initialized = ISR_LOCK_INITIALIZER;
ISR_lock_Control lock;
ISR_Level level;
ISR_lock_Context lock_context;
_ISR_lock_Initialize( &lock );
rtems_test_assert( memcmp( &lock, &initialized, sizeof( lock ) ) == 0 );
_ISR_lock_ISR_disable_and_acquire( &lock, level );
_ISR_lock_ISR_disable_and_acquire( &lock, &lock_context );
rtems_test_assert( normal_interrupt_level != _ISR_Get_level() );
_ISR_lock_Release_and_ISR_enable( &lock, level );
_ISR_lock_Release_and_ISR_enable( &lock, &lock_context );
rtems_test_assert( normal_interrupt_level == _ISR_Get_level() );
_ISR_lock_Acquire( &lock );
_ISR_lock_Acquire( &lock, &lock_context );
rtems_test_assert( normal_interrupt_level == _ISR_Get_level() );
_ISR_lock_Release( &lock );
_ISR_lock_Release( &lock, &lock_context );
rtems_test_assert( normal_interrupt_level == _ISR_Get_level() );
}
@@ -196,20 +196,20 @@ static void test_interrupt_locks( void )
rtems_mode normal_interrupt_level = get_interrupt_level();
rtems_interrupt_lock initialized = RTEMS_INTERRUPT_LOCK_INITIALIZER;
rtems_interrupt_lock lock;
rtems_interrupt_level level;
rtems_interrupt_lock_context lock_context;
rtems_interrupt_lock_initialize( &lock );
rtems_test_assert( memcmp( &lock, &initialized, sizeof( lock ) ) == 0 );
rtems_interrupt_lock_acquire( &lock, level );
rtems_interrupt_lock_acquire( &lock, &lock_context );
rtems_test_assert( normal_interrupt_level != get_interrupt_level() );
rtems_interrupt_lock_release( &lock, level );
rtems_interrupt_lock_release( &lock, &lock_context );
rtems_test_assert( normal_interrupt_level == get_interrupt_level() );
rtems_interrupt_lock_acquire_isr( &lock );
rtems_interrupt_lock_acquire_isr( &lock, &lock_context );
rtems_test_assert( normal_interrupt_level == get_interrupt_level() );
rtems_interrupt_lock_release_isr( &lock );
rtems_interrupt_lock_release_isr( &lock, &lock_context );
rtems_test_assert( normal_interrupt_level == get_interrupt_level() );
}

View File

@@ -38,8 +38,8 @@ CPU_STRUCTURE_ALIGNMENT static int data[1024];
static void test_data_flush_and_invalidate(void)
{
if (rtems_cache_get_data_line_size() > 0) {
rtems_interrupt_level level;
rtems_interrupt_lock lock = RTEMS_INTERRUPT_LOCK_INITIALIZER;
rtems_interrupt_lock lock;
rtems_interrupt_lock_context lock_context;
volatile int *vdata = &data[0];
int n = 32;
int i;
@@ -48,7 +48,8 @@ static void test_data_flush_and_invalidate(void)
printf("data cache flush and invalidate test\n");
rtems_interrupt_lock_acquire(&lock, level);
rtems_interrupt_lock_initialize(&lock);
rtems_interrupt_lock_acquire(&lock, &lock_context);
for (i = 0; i < n; ++i) {
vdata[i] = i;
@@ -88,7 +89,7 @@ static void test_data_flush_and_invalidate(void)
rtems_test_assert(vdata[i] == ~i);
}
rtems_interrupt_lock_release(&lock, level);
rtems_interrupt_lock_release(&lock, &lock_context);
printf(
"data cache operations by line passed the test (%s cache detected)\n",
@@ -159,13 +160,15 @@ static uint64_t store(void)
static void test_timing(void)
{
rtems_interrupt_level level;
rtems_interrupt_lock lock = RTEMS_INTERRUPT_LOCK_INITIALIZER;
rtems_interrupt_lock lock;
rtems_interrupt_lock_context lock_context;
size_t data_size = sizeof(data);
uint64_t d[3];
uint32_t cache_level;
size_t cache_size;
rtems_interrupt_lock_initialize(&lock);
printf(
"data cache line size %zi bytes\n"
"data cache size %zi bytes\n",
@@ -185,14 +188,14 @@ static void test_timing(void)
cache_size = rtems_cache_get_data_cache_size(cache_level);
}
rtems_interrupt_lock_acquire(&lock, level);
rtems_interrupt_lock_acquire(&lock, &lock_context);
d[0] = load();
d[1] = load();
rtems_cache_flush_entire_data();
d[2] = load();
rtems_interrupt_lock_release(&lock, level);
rtems_interrupt_lock_release(&lock, &lock_context);
printf(
"load %zi bytes with flush entire data\n"
@@ -205,14 +208,14 @@ static void test_timing(void)
d[2]
);
rtems_interrupt_lock_acquire(&lock, level);
rtems_interrupt_lock_acquire(&lock, &lock_context);
d[0] = load();
d[1] = load();
rtems_cache_flush_multiple_data_lines(&data[0], sizeof(data));
d[2] = load();
rtems_interrupt_lock_release(&lock, level);
rtems_interrupt_lock_release(&lock, &lock_context);
printf(
"load %zi bytes with flush multiple data\n"
@@ -225,14 +228,14 @@ static void test_timing(void)
d[2]
);
rtems_interrupt_lock_acquire(&lock, level);
rtems_interrupt_lock_acquire(&lock, &lock_context);
d[0] = load();
d[1] = load();
rtems_cache_invalidate_multiple_data_lines(&data[0], sizeof(data));
d[2] = load();
rtems_interrupt_lock_release(&lock, level);
rtems_interrupt_lock_release(&lock, &lock_context);
printf(
"load %zi bytes with invalidate multiple data\n"
@@ -245,14 +248,14 @@ static void test_timing(void)
d[2]
);
rtems_interrupt_lock_acquire(&lock, level);
rtems_interrupt_lock_acquire(&lock, &lock_context);
d[0] = store();
d[1] = store();
rtems_cache_flush_entire_data();
d[2] = store();
rtems_interrupt_lock_release(&lock, level);
rtems_interrupt_lock_release(&lock, &lock_context);
printf(
"store %zi bytes with flush entire data\n"
@@ -265,14 +268,14 @@ static void test_timing(void)
d[2]
);
rtems_interrupt_lock_acquire(&lock, level);
rtems_interrupt_lock_acquire(&lock, &lock_context);
d[0] = store();
d[1] = store();
rtems_cache_flush_multiple_data_lines(&data[0], sizeof(data));
d[2] = store();
rtems_interrupt_lock_release(&lock, level);
rtems_interrupt_lock_release(&lock, &lock_context);
printf(
"store %zi bytes with flush multiple data\n"
@@ -285,14 +288,14 @@ static void test_timing(void)
d[2]
);
rtems_interrupt_lock_acquire(&lock, level);
rtems_interrupt_lock_acquire(&lock, &lock_context);
d[0] = store();
d[1] = store();
rtems_cache_invalidate_multiple_data_lines(&data[0], sizeof(data));
d[2] = store();
rtems_interrupt_lock_release(&lock, level);
rtems_interrupt_lock_release(&lock, &lock_context);
printf(
"store %zi bytes with invalidate multiple data\n"
@@ -324,14 +327,14 @@ static void test_timing(void)
cache_size = rtems_cache_get_instruction_cache_size(cache_level);
}
rtems_interrupt_lock_acquire(&lock, level);
rtems_interrupt_lock_acquire(&lock, &lock_context);
d[0] = do_some_work();
d[1] = do_some_work();
rtems_cache_invalidate_entire_instruction();
d[2] = do_some_work();
rtems_interrupt_lock_release(&lock, level);
rtems_interrupt_lock_release(&lock, &lock_context);
printf(
"invalidate entire instruction\n"
@@ -343,14 +346,14 @@ static void test_timing(void)
d[2]
);
rtems_interrupt_lock_acquire(&lock, level);
rtems_interrupt_lock_acquire(&lock, &lock_context);
d[0] = do_some_work();
d[1] = do_some_work();
rtems_cache_invalidate_multiple_instruction_lines(do_some_work, 4096);
d[2] = do_some_work();
rtems_interrupt_lock_release(&lock, level);
rtems_interrupt_lock_release(&lock, &lock_context);
printf(
"invalidate multiple instruction\n"

View File

@@ -21,8 +21,8 @@
static rtems_task Init(rtems_task_argument argument)
{
rtems_status_code sc = RTEMS_SUCCESSFUL;
rtems_interrupt_lock lock = RTEMS_INTERRUPT_LOCK_INITIALIZER;
rtems_interrupt_level level;
rtems_interrupt_lock lock;
rtems_interrupt_lock_context lock_context;
rtems_interval t0 = 0;
rtems_interval t1 = 0;
int i = 0;
@@ -51,7 +51,8 @@ static rtems_task Init(rtems_task_argument argument)
n = (3 * n) / 2;
rtems_interrupt_lock_acquire(&lock, level);
rtems_interrupt_lock_initialize(&lock);
rtems_interrupt_lock_acquire(&lock, &lock_context);
sc = rtems_clock_get_uptime(&uptime);
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
for (i = 0; i < n; ++i) {
@@ -63,7 +64,7 @@ static rtems_task Init(rtems_task_argument argument)
rtems_test_assert(!_Timespec_Less_than(&new_uptime, &uptime));
uptime = new_uptime;
}
rtems_interrupt_lock_release(&lock, level);
rtems_interrupt_lock_release(&lock, &lock_context);
puts("*** END OF TEST NANO SECONDS EXTENSION 1 ***");

View File

@@ -129,8 +129,8 @@ static void sort_t(void)
static void test_by_function_level(int fl, bool dirty)
{
rtems_interrupt_level level;
rtems_interrupt_lock lock = RTEMS_INTERRUPT_LOCK_INITIALIZER;
rtems_interrupt_lock_context lock_context;
int s;
uint64_t min;
uint64_t q1;
@@ -138,13 +138,13 @@ static void test_by_function_level(int fl, bool dirty)
uint64_t q3;
uint64_t max;
rtems_interrupt_lock_acquire(&lock, level);
rtems_interrupt_lock_acquire(&lock, &lock_context);
for (s = 0; s < SAMPLES; ++s) {
call_at_level(fl, fl, s, dirty);
}
rtems_interrupt_lock_release(&lock, level);
rtems_interrupt_lock_release(&lock, &lock_context);
sort_t();