source: rtems/testsuites/smptests/smpfatal01/init.c @ 03c9f24

5
Last change on this file since 03c9f24 was 03c9f24, checked in by Sebastian Huber <sebastian.huber@…>, on Apr 5, 2019 at 6:03:12 AM

rtems: Add rtems_scheduler_get_processor()

Add rtems_scheduler_get_processor() as a replacement for
rtems_get_current_processor(). The rtems_get_current_processor() is a
bit orphaned. Adopt it by the Scheduler Manager. This is in line with
the glibc sched_getcpu() function.

Deprecate rtems_get_current_processor().

Update #3731.

  • Property mode set to 100644
File size: 3.0 KB
Line 
1/*
2 * Copyright (c) 2014 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
6 *  82178 Puchheim
7 *  Germany
8 *  <rtems@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.org/license/LICENSE.
13 */
14
15#ifdef HAVE_CONFIG_H
16  #include "config.h"
17#endif
18
19#include "tmacros.h"
20
21#include <rtems.h>
22#include <rtems/score/percpu.h>
23#include <rtems/score/smpimpl.h>
24#include <rtems/score/smpbarrier.h>
25
26#include <assert.h>
27#include <stdlib.h>
28
29const char rtems_test_name[] = "SMPFATAL 1";
30
31#define MAX_CPUS 32
32
33static uint32_t main_cpu;
34
35static SMP_barrier_Control barrier = SMP_BARRIER_CONTROL_INITIALIZER;
36
37static void Init(rtems_task_argument arg)
38{
39  assert(0);
40}
41
42static void fatal_extension(
43  rtems_fatal_source source,
44  bool always_set_to_false,
45  rtems_fatal_code code
46)
47{
48  SMP_barrier_State barrier_state = SMP_BARRIER_STATE_INITIALIZER;
49
50  if (source == RTEMS_FATAL_SOURCE_SMP) {
51    uint32_t self = rtems_scheduler_get_processor();
52
53    assert(!always_set_to_false);
54    assert(code == SMP_FATAL_SHUTDOWN);
55
56    if (self == main_cpu) {
57      uint32_t cpu;
58
59      for (cpu = 0; cpu < MAX_CPUS; ++cpu) {
60        const Per_CPU_Control *per_cpu = _Per_CPU_Get_by_index( cpu );
61        Per_CPU_State state = per_cpu->state;
62
63        assert(state == PER_CPU_STATE_SHUTDOWN);
64      }
65
66      TEST_END();
67    }
68  }
69
70  _SMP_barrier_Wait(&barrier, &barrier_state, rtems_get_processor_count());
71}
72
73static rtems_status_code test_driver_init(
74  rtems_device_major_number major,
75  rtems_device_minor_number minor,
76  void *arg
77)
78{
79  uint32_t self = rtems_scheduler_get_processor();
80  uint32_t cpu_count = rtems_get_processor_count();
81  uint32_t cpu;
82
83  TEST_BEGIN();
84
85  assert(rtems_configuration_get_maximum_processors() == MAX_CPUS);
86
87  main_cpu = self;
88
89  for (cpu = 0; cpu < MAX_CPUS; ++cpu) {
90    const Per_CPU_Control *per_cpu = _Per_CPU_Get_by_index( cpu );
91    Per_CPU_State state = per_cpu->state;
92
93    if (cpu == self) {
94      assert(state == PER_CPU_STATE_INITIAL);
95    } else if (cpu < cpu_count) {
96      assert(
97        state == PER_CPU_STATE_INITIAL
98          || state == PER_CPU_STATE_READY_TO_START_MULTITASKING
99      );
100    } else {
101      assert(state == PER_CPU_STATE_INITIAL);
102    }
103  }
104
105  if (cpu_count > 1) {
106    uint32_t other = (self + 1) % cpu_count;
107    Per_CPU_Control *per_cpu = _Per_CPU_Get_by_index( other );
108
109    per_cpu->state = PER_CPU_STATE_SHUTDOWN;
110  } else {
111    TEST_END();
112    exit(0);
113  }
114
115  return RTEMS_SUCCESSFUL;
116}
117
118#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
119#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
120
121#define CONFIGURE_APPLICATION_EXTRA_DRIVERS \
122  { .initialization_entry = test_driver_init }
123
124#define CONFIGURE_INITIAL_EXTENSIONS \
125  { .fatal = fatal_extension }, \
126  RTEMS_TEST_INITIAL_EXTENSION
127
128#define CONFIGURE_MAXIMUM_PROCESSORS MAX_CPUS
129
130#define CONFIGURE_MAXIMUM_TASKS 1
131
132#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
133
134#define CONFIGURE_INIT
135
136#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.