source: rtems/testsuites/smptests/smp08/init.c @ ac2bb464

4.11
Last change on this file since ac2bb464 was ac2bb464, checked in by Sebastian Huber <sebastian.huber@…>, on May 31, 2013 at 11:56:56 AM

smptests: Use priority ceiling for locked print

In case the printf() blocks on a semaphore it was possible to end up in
a livelock.

  • Property mode set to 100644
File size: 2.2 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2011.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.com/license/LICENSE.
8 */
9
10#ifdef HAVE_CONFIG_H
11#include "config.h"
12#endif
13
14#define CONFIGURE_INIT
15#include "system.h"
16
17void PrintTaskInfo(
18  const char         *task_name,
19  rtems_time_of_day  *_tb
20)
21{
22  int               cpu_num;
23
24  cpu_num = bsp_smp_processor_id();
25
26  /* Print the cpu number and task name */
27  locked_printf(
28    "  CPU %d running task %s - rtems_clock_get_tod "
29    "%02" PRId32 ":%02" PRId32 ":%02" PRId32 "   %02" PRId32
30        "/%02" PRId32 "/%04" PRId32 "\n",
31    cpu_num,
32    task_name,
33    _tb->hour, _tb->minute, _tb->second, 
34    _tb->month, _tb->day, _tb->year
35  ); 
36}
37
38rtems_task Init(
39  rtems_task_argument argument
40)
41{
42  rtems_status_code status;
43  rtems_time_of_day time;
44  int               i;
45  char              ch[4];
46  rtems_id          id;
47 
48  locked_print_initialize();
49  locked_printf( "\n\n*** SMP08 TEST ***\n" );
50
51  time.year   = 1988;
52  time.month  = 12;
53  time.day    = 31;
54  time.hour   = 9;
55  time.minute = 0;
56  time.second = 0;
57  time.ticks  = 0;
58
59  status = rtems_clock_set( &time );
60
61  /* Create/verify synchronisation semaphore */
62  status = rtems_semaphore_create(
63    rtems_build_name ('S', 'E', 'M', '1'),
64    1,                                             
65    RTEMS_LOCAL                   |
66    RTEMS_SIMPLE_BINARY_SEMAPHORE |
67    RTEMS_PRIORITY,
68    1,
69    &Semaphore
70  );
71  directive_failed( status, "rtems_semaphore_create" );
72
73  /* Show that the init task is running on this cpu */
74  PrintTaskInfo( "Init", &time );
75
76  for ( i=1; i <= rtems_smp_get_number_of_processors() *3; i++ ) {
77
78    sprintf(ch, "%02" PRId32, i );
79    status = rtems_task_create(
80      rtems_build_name( 'T', 'A', ch[0], ch[1] ),
81      2,
82      RTEMS_MINIMUM_STACK_SIZE,
83      RTEMS_DEFAULT_MODES,
84      RTEMS_DEFAULT_ATTRIBUTES,
85      &id
86    );
87    directive_failed( status, "task create" );
88
89    status = rtems_task_start( id, Test_task, i+1 );
90    directive_failed( status, "task start" );
91  }
92
93  status = rtems_task_delete( RTEMS_SELF );
94}
Note: See TracBrowser for help on using the repository browser.