source: rtems/testsuites/smptests/smpfatal01/init.c @ f9219db

5
Last change on this file since f9219db was f9219db, checked in by Sebastian Huber <sebastian.huber@…>, on 04/05/19 at 06:16:05

rtems: Add rtems_scheduler_get_processor_maximum()

Add rtems_scheduler_get_processor_maximum() as a replacement for
rtems_get_processor_count(). The rtems_get_processor_count() is a bit
orphaned. Adopt it by the Scheduler Manager. The count is also
misleading, since the processor set may have gaps and the actual count
of online processors may be less than the value returned by
rtems_get_processor_count().

Update #3732.

  • 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(
71    &barrier,
72    &barrier_state,
73    rtems_scheduler_get_processor_maximum()
74  );
75}
76
77static rtems_status_code test_driver_init(
78  rtems_device_major_number major,
79  rtems_device_minor_number minor,
80  void *arg
81)
82{
83  uint32_t self = rtems_scheduler_get_processor();
84  uint32_t cpu_count = rtems_scheduler_get_processor_maximum();
85  uint32_t cpu;
86
87  TEST_BEGIN();
88
89  assert(rtems_configuration_get_maximum_processors() == MAX_CPUS);
90
91  main_cpu = self;
92
93  for (cpu = 0; cpu < MAX_CPUS; ++cpu) {
94    const Per_CPU_Control *per_cpu = _Per_CPU_Get_by_index( cpu );
95    Per_CPU_State state = per_cpu->state;
96
97    if (cpu == self) {
98      assert(state == PER_CPU_STATE_INITIAL);
99    } else if (cpu < cpu_count) {
100      assert(
101        state == PER_CPU_STATE_INITIAL
102          || state == PER_CPU_STATE_READY_TO_START_MULTITASKING
103      );
104    } else {
105      assert(state == PER_CPU_STATE_INITIAL);
106    }
107  }
108
109  if (cpu_count > 1) {
110    uint32_t other = (self + 1) % cpu_count;
111    Per_CPU_Control *per_cpu = _Per_CPU_Get_by_index( other );
112
113    per_cpu->state = PER_CPU_STATE_SHUTDOWN;
114  } else {
115    TEST_END();
116    exit(0);
117  }
118
119  return RTEMS_SUCCESSFUL;
120}
121
122#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
123#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
124
125#define CONFIGURE_APPLICATION_EXTRA_DRIVERS \
126  { .initialization_entry = test_driver_init }
127
128#define CONFIGURE_INITIAL_EXTENSIONS \
129  { .fatal = fatal_extension }, \
130  RTEMS_TEST_INITIAL_EXTENSION
131
132#define CONFIGURE_MAXIMUM_PROCESSORS MAX_CPUS
133
134#define CONFIGURE_MAXIMUM_TASKS 1
135
136#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
137
138#define CONFIGURE_INIT
139
140#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.