summaryrefslogtreecommitdiffstats
path: root/testsuites/tmtests/tmcontext01/init.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--testsuites/tmtests/tmcontext01/init.c120
1 files changed, 63 insertions, 57 deletions
diff --git a/testsuites/tmtests/tmcontext01/init.c b/testsuites/tmtests/tmcontext01/init.c
index d1f88e045a..dc1da718c7 100644
--- a/testsuites/tmtests/tmcontext01/init.c
+++ b/testsuites/tmtests/tmcontext01/init.c
@@ -1,15 +1,28 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
/*
- * Copyright (c) 2014, 2017 embedded brains GmbH. All rights reserved.
+ * Copyright (C) 2014, 2017 embedded brains GmbH & Co. KG
*
- * embedded brains GmbH
- * Dornierstr. 4
- * 82178 Puchheim
- * Germany
- * <rtems@embedded-brains.de>
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
*
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rtems.org/license/LICENSE.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
@@ -36,8 +49,6 @@ const char rtems_test_name[] = "TMCONTEXT 1";
static rtems_counter_ticks t[SAMPLES];
-static volatile int prevent_optimization;
-
static size_t cache_line_size;
static size_t data_size;
@@ -59,43 +70,31 @@ static int dirty_data_cache(volatile int *data, size_t n, size_t clsz, int j)
return i + j;
}
-static int call_at_level(
+static __attribute__((__noipa__)) void call_at_level(
int start,
int fl,
- int s,
- bool dirty
+ int s
)
{
- int prevent_optimization;;
-
- prevent_optimization = start + fl;
-
+#if defined(__sparc__)
if (fl == start) {
- /*
- * Some architectures like the SPARC have register windows. A side-effect
- * of this context switch is that we start with a fresh window set. On
- * architectures like ARM or PowerPC this context switch has no effect.
- */
- _Context_Switch(&ctx, &ctx);
+ /* Flush register windows */
+ __asm__ volatile ("ta 3" : : : "memory");
}
+#endif
if (fl > 0) {
call_at_level(
start,
fl - 1,
- s,
- dirty
+ s
);
+ __asm__ volatile ("" : : : "memory");
} else {
char *volatile space;
rtems_counter_ticks a;
rtems_counter_ticks b;
- if (dirty) {
- dirty_data_cache(main_data, data_size, cache_line_size, fl);
- rtems_cache_invalidate_entire_instruction();
- }
-
a = rtems_counter_read();
/* Ensure that we use an untouched stack area */
@@ -107,8 +106,6 @@ static int call_at_level(
b = rtems_counter_read();
t[s] = rtems_counter_difference(b, a);
}
-
- return prevent_optimization;
}
static void load_task(rtems_task_argument arg)
@@ -136,7 +133,7 @@ static void sort_t(void)
qsort(&t[0], SAMPLES, sizeof(t[0]), cmp);
}
-static void test_by_function_level(int fl, bool dirty)
+static __attribute__((__noipa__)) void test_by_function_level(int fl, bool dirty)
{
RTEMS_INTERRUPT_LOCK_DECLARE(, lock)
rtems_interrupt_lock_context lock_context;
@@ -147,13 +144,16 @@ static void test_by_function_level(int fl, bool dirty)
uint64_t q3;
uint64_t max;
- fl += prevent_optimization;
-
rtems_interrupt_lock_initialize(&lock, "test");
rtems_interrupt_lock_acquire(&lock, &lock_context);
for (s = 0; s < SAMPLES; ++s) {
- call_at_level(fl, fl, s, dirty);
+ if (dirty) {
+ dirty_data_cache(main_data, data_size, cache_line_size, fl);
+ rtems_cache_invalidate_entire_instruction();
+ }
+
+ call_at_level(fl, fl, s);
}
rtems_interrupt_lock_release(&lock, &lock_context);
@@ -168,14 +168,8 @@ static void test_by_function_level(int fl, bool dirty)
max = t[SAMPLES - 1];
printf(
- " <Sample functionNestLevel=\"%i\">\n"
- " <Min unit=\"ns\">%" PRIu64 "</Min>"
- "<Q1 unit=\"ns\">%" PRIu64 "</Q1>"
- "<Q2 unit=\"ns\">%" PRIu64 "</Q2>"
- "<Q3 unit=\"ns\">%" PRIu64 "</Q3>"
- "<Max unit=\"ns\">%" PRIu64 "</Max>\n"
- " </Sample>\n",
- fl,
+ "%s\n [%" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 "]",
+ fl == 0 ? "" : ",",
rtems_counter_ticks_to_nanoseconds(min),
rtems_counter_ticks_to_nanoseconds(q1),
rtems_counter_ticks_to_nanoseconds(q2),
@@ -184,26 +178,38 @@ static void test_by_function_level(int fl, bool dirty)
);
}
-static void test(bool dirty, uint32_t load)
+static void test(bool first, bool dirty, uint32_t load)
{
int fl;
printf(
- " <ContextSwitchTest environment=\"%s\"",
- dirty ? "dirty" : "normal"
+ "\n %s{\n"
+ " \"environment\": \"",
+ first ? "" : "}, "
);
- if (load > 0) {
- printf(" load=\"%" PRIu32 "\"", load);
+ if (dirty) {
+ if (load > 0) {
+ printf("Load/%" PRIu32 "", load);
+ } else {
+ printf("DirtyCache");
+ }
+ } else {
+ printf("HotCache");
}
- printf(">\n");
+ printf(
+ "\",\n"
+ " \"stats-by-function-nest-level\": ["
+ );
for (fl = 0; fl < FUNCTION_LEVELS; ++fl) {
test_by_function_level(fl, dirty);
}
- printf(" </ContextSwitchTest>\n");
+ printf(
+ "\n ]"
+ );
}
static void Init(rtems_task_argument arg)
@@ -212,7 +218,7 @@ static void Init(rtems_task_argument arg)
TEST_BEGIN();
- printf("<Test>\n");
+ printf("*** BEGIN OF JSON DATA ***\n[");
cache_line_size = rtems_cache_get_data_line_size();
if (cache_line_size == 0) {
@@ -227,8 +233,8 @@ static void Init(rtems_task_argument arg)
main_data = malloc(data_size);
rtems_test_assert(main_data != NULL);
- test(false, load);
- test(true, load);
+ test(true, false, load);
+ test(false, true, load);
for (load = 1; load < rtems_scheduler_get_processor_maximum(); ++load) {
rtems_status_code sc;
@@ -253,10 +259,10 @@ static void Init(rtems_task_argument arg)
sc = rtems_task_start(id, load_task, (rtems_task_argument) load_data);
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
- test(true, load);
+ test(false, true, load);
}
- printf("</Test>\n");
+ printf("\n }\n]\n*** END OF JSON DATA ***\n");
TEST_END();
rtems_test_exit(0);