From 47d6013417c63115356042695e7125ecfcfe4696 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Wed, 19 Feb 2014 13:52:41 +0100 Subject: score: _CPU_SMP_Get_current_processor() Remove RTEMS_COMPILER_PURE_ATTRIBUTE from _SMP_Get_current_processor() and all _CPU_SMP_Get_current_processor(). Make inline ASM statements volatile again. Test smptests/smpmigration01 showed that GCC optimizes too much otherwise. --- testsuites/smptests/smpmigration01/init.c | 50 +++++++++++++++++++--- .../smptests/smpmigration01/smpmigration01.scn | 32 ++++++++------ 2 files changed, 64 insertions(+), 18 deletions(-) (limited to 'testsuites/smptests/smpmigration01') diff --git a/testsuites/smptests/smpmigration01/init.c b/testsuites/smptests/smpmigration01/init.c index 1500dba3bc..2422466ee9 100644 --- a/testsuites/smptests/smpmigration01/init.c +++ b/testsuites/smptests/smpmigration01/init.c @@ -16,9 +16,11 @@ #include "config.h" #endif +#define TESTS_USE_PRINTF #include "tmacros.h" #include +#include #include #define CPU_COUNT 2 @@ -102,6 +104,11 @@ static void stopper(rtems_task_argument arg) } } +static uint32_t abs_delta(uint32_t a, uint32_t b) +{ + return a > b ? a - b : b - a; +} + static void test(void) { test_context *ctx = &ctx_instance; @@ -110,6 +117,8 @@ static void test(void) rtems_id stopper_id; uint32_t expected_tokens; uint32_t total_delta; + uint64_t total_cycles; + uint32_t average_cycles; sc = rtems_task_create( rtems_build_name('S', 'T', 'O', 'P'), @@ -144,21 +153,49 @@ static void test(void) sc = rtems_task_start(stopper_id, stopper, 0); rtems_test_assert(sc == RTEMS_SUCCESSFUL); + total_cycles = 0; for (runner_index = 0; runner_index < RUNNER_COUNT; ++runner_index) { - test_counters *counters = &ctx->counters[runner_index]; + const test_counters *counters = &ctx->counters[runner_index]; + size_t cpu; + + for (cpu = 0; cpu < CPU_COUNT; ++cpu) { + total_cycles += counters->cycles_per_cpu[cpu].counter; + } + } + average_cycles = (uint32_t) (total_cycles / (RUNNER_COUNT * CPU_COUNT)); + + printf( + "total cycles %" PRIu64 "\n" + "average cycles %" PRIu32 "\n", + total_cycles, + average_cycles + ); + + for (runner_index = 0; runner_index < RUNNER_COUNT; ++runner_index) { + const test_counters *counters = &ctx->counters[runner_index]; size_t cpu; printf("runner %" PRIuPTR "\n", runner_index); for (cpu = 0; cpu < CPU_COUNT; ++cpu) { + uint32_t tokens = counters->tokens_per_cpu[cpu].counter; + uint32_t cycles = counters->cycles_per_cpu[cpu].counter; + double cycle_deviation = ((double) cycles - average_cycles) + / average_cycles; + printf( "\tcpu %zu tokens %" PRIu32 "\n" - "\tcpu %zu cycles %" PRIu32 "\n", + "\tcpu %zu cycles %" PRIu32 "\n" + "\tcpu %zu cycle deviation %f\n", + cpu, + tokens, cpu, - counters->tokens_per_cpu[cpu].counter, + cycles, cpu, - counters->cycles_per_cpu[cpu].counter + cycle_deviation ); + + rtems_test_assert(fabs(cycle_deviation) < 0.5); } } @@ -170,8 +207,7 @@ static void test(void) for (cpu = 0; cpu < CPU_COUNT; ++cpu) { uint32_t tokens = counters->tokens_per_cpu[cpu].counter; - uint32_t delta = tokens > expected_tokens ? - tokens - expected_tokens : expected_tokens - tokens; + uint32_t delta = abs_delta(tokens, expected_tokens); rtems_test_assert(delta <= 1); @@ -204,6 +240,8 @@ static void Init(rtems_task_argument arg) #define CONFIGURE_MAXIMUM_TASKS (2 + RUNNER_COUNT) +#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT + #define CONFIGURE_RTEMS_INIT_TASKS_TABLE #define CONFIGURE_INIT diff --git a/testsuites/smptests/smpmigration01/smpmigration01.scn b/testsuites/smptests/smpmigration01/smpmigration01.scn index b2b56ffcb8..ba42cd4942 100644 --- a/testsuites/smptests/smpmigration01/smpmigration01.scn +++ b/testsuites/smptests/smpmigration01/smpmigration01.scn @@ -1,17 +1,25 @@ *** TEST SMPMIGRATION 1 *** +total cycles 94476101 +average cycles 15746016 runner 0 - cpu 0 tokens 453284 - cpu 0 cycles 14955317 - cpu 1 tokens 453283 - cpu 1 cycles 14978390 + cpu 0 tokens 456994 + cpu 0 cycles 16451659 + cpu 0 cycle deviation 0.044814 + cpu 1 tokens 456994 + cpu 1 cycles 16895680 + cpu 1 cycle deviation 0.073013 runner 1 - cpu 0 tokens 453283 - cpu 0 cycles 21302793 - cpu 1 tokens 453283 - cpu 1 cycles 21318817 + cpu 0 tokens 456993 + cpu 0 cycles 20561545 + cpu 0 cycle deviation 0.305825 + cpu 1 tokens 456994 + cpu 1 cycles 20548432 + cpu 1 cycle deviation 0.304992 runner 2 - cpu 0 tokens 453283 - cpu 0 cycles 19973312 - cpu 1 tokens 453283 - cpu 1 cycles 21315227 + cpu 0 tokens 456994 + cpu 0 cycles 10007206 + cpu 0 cycle deviation -0.364461 + cpu 1 tokens 456993 + cpu 1 cycles 10011579 + cpu 1 cycle deviation -0.364183 *** END OF TEST SMPMIGRATION 1 *** -- cgit v1.2.3