source: rtems/testsuites/rhealstone/rhdeadlockbrk/deadlockbrk.c @ 893aac16

4.11
Last change on this file since 893aac16 was 893aac16, checked in by Joel Sherrill <joel.sherrill@…>, on Jan 8, 2014 at 12:31:32 AM

rhealstone: Add start end and messages

  • Property mode set to 100644
File size: 5.7 KB
Line 
1/*
2 * Copyright (c) 2014 Daniel Ramirez. (javamonn@gmail.com)
3 *
4 * This file's license is 2-clause BSD as in this distribution's LICENSE file.
5 */
6
7#include <rtems/timerdrv.h>
8#include <timesys.h>
9
10#define BENCHMARKS 20000
11
12rtems_task Task01( rtems_task_argument ignored );
13rtems_task Task02( rtems_task_argument ignored );
14rtems_task Task03( rtems_task_argument ignored );
15rtems_task Init( rtems_task_argument ignored );
16
17rtems_id           Task_id[3];
18rtems_name         Task_name[3];
19rtems_id           sem_id;
20rtems_name         sem_name;
21rtems_status_code  status;
22
23uint32_t count;
24uint32_t telapsed;
25uint32_t tswitch_overhead;
26uint32_t tobtain_overhead;
27uint32_t sem_exe;
28
29rtems_task Init( rtems_task_argument ignored )
30{
31  rtems_attribute      sem_attr;
32  rtems_task_priority  pri;
33  rtems_mode           prev_mode;
34
35  Print_Warning();
36
37  puts( "*** START OF RHDEADLOCKBRK ***" );
38
39  sem_attr = RTEMS_INHERIT_PRIORITY | RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY;
40
41  sem_name = rtems_build_name( 'S','0',' ',' ' );
42  status = rtems_semaphore_create(
43    sem_name,
44    1,
45    sem_attr,
46    0,
47    &sem_id
48  );
49  directive_failed( status, "rtems_semaphore_create of S0" );
50
51  Task_name[0] = rtems_build_name( 'T','A','0','1' );
52  status = rtems_task_create(
53    Task_name[0],
54    26,  /* High priority task */
55    RTEMS_MINIMUM_STACK_SIZE,
56    RTEMS_DEFAULT_MODES,
57    RTEMS_DEFAULT_ATTRIBUTES,
58    &Task_id[0]
59  );
60  directive_failed( status, "rtems_task_create of TA01" );
61
62  Task_name[1] = rtems_build_name( 'T','A','0','2' );
63  status = rtems_task_create(
64    Task_name[1],
65    28,  /* Mid priority task */
66    RTEMS_MINIMUM_STACK_SIZE,
67    RTEMS_DEFAULT_MODES,
68    RTEMS_DEFAULT_ATTRIBUTES,
69    &Task_id[1]
70  );
71  directive_failed( status, "rtems_task_create of TA02" );
72
73  Task_name[2] = rtems_build_name( 'T','A','0','3' );
74  status = rtems_task_create(
75    Task_name[2],
76    30,  /* Low priority task */
77    RTEMS_MINIMUM_STACK_SIZE,
78    RTEMS_DEFAULT_MODES,
79    RTEMS_DEFAULT_ATTRIBUTES,
80    &Task_id[2]
81  );
82  directive_failed( status, "rtems_task_create of TA03" );
83
84  /* find overhead of obtaining semaphore */
85  benchmark_timer_initialize();
86  rtems_semaphore_obtain( sem_id, RTEMS_WAIT, 0 );
87  tobtain_overhead = benchmark_timer_read();
88  rtems_semaphore_release( sem_id );
89
90  rtems_task_mode( RTEMS_PREEMPT, RTEMS_PREEMPT_MASK, &prev_mode );
91  /* Lower own priority so tasks can start up and run */
92  rtems_task_set_priority( RTEMS_SELF, 40, &pri );
93
94  /* Get time of benchmark with no semaphores involved, i.e. find overhead */
95  sem_exe = 0;
96  status = rtems_task_start( Task_id[2], Task03, 0 );
97  directive_failed( status, "rtems_task_start of TA03" );
98
99  /* Get time of benchmark with semaphores */
100  sem_exe = 1;
101  status = rtems_task_restart( Task_id[2], 0 );
102  directive_failed( status, "rtems_task_start of TA03" );
103
104  /* Should never reach here */
105  rtems_test_assert( false );
106}
107
108rtems_task Task01( rtems_task_argument ignored )
109{
110  /* All tasks have had time to start up once TA01 is running */
111
112  /* Benchmark code */
113  benchmark_timer_initialize();
114  for ( count = 0; count < BENCHMARKS; count++ ) {
115    if ( sem_exe == 1 ) {
116      /* Block on call */
117      rtems_semaphore_obtain( sem_id, RTEMS_WAIT, 0 );
118    }
119
120    if ( sem_exe == 1 ) {
121      /* Release semaphore immediately after obtaining it */
122      rtems_semaphore_release( sem_id );
123    }
124
125    /* Suspend self, go to TA02 */
126    rtems_task_suspend( RTEMS_SELF );
127  }
128  telapsed = benchmark_timer_read();
129
130  /* Check which run this was */
131  if (sem_exe == 0) {
132    tswitch_overhead = telapsed;
133    rtems_task_suspend( Task_id[1] );
134    rtems_task_suspend( Task_id[2] );
135    rtems_task_suspend( RTEMS_SELF );
136  } else {
137    put_time(
138       "Rhealstone: Deadlock Break",
139       telapsed,
140       BENCHMARKS,              /* Total number of times deadlock broken*/
141       tswitch_overhead,        /* Overhead of loop and task switches */
142       tobtain_overhead
143    );
144    puts( "*** END OF RHDEADLOCKBRK ***" );
145    rtems_test_exit( 0 );
146  }
147
148}
149
150rtems_task Task02( rtems_task_argument ignored )
151{
152  /* Start up TA01, get preempted */
153  if ( sem_exe == 1) {
154    status = rtems_task_restart( Task_id[0], 0);
155    directive_failed( status, "rtems_task_start of TA01");
156  } else {
157    status = rtems_task_start( Task_id[0], Task01, 0);
158    directive_failed( status, "rtems_task_start of TA01");
159  }
160
161  /* Benchmark code */
162  for ( ; count < BENCHMARKS ; ) {
163    /* Suspend self, go to TA01 */
164    rtems_task_suspend( RTEMS_SELF );
165
166    /* Wake up TA01, get preempted */
167    rtems_task_resume( Task_id[0] );
168  }
169}
170
171rtems_task Task03( rtems_task_argument ignored )
172{
173  if (sem_exe == 1) {
174    /* Low priority task holds mutex */
175    rtems_semaphore_obtain( sem_id, RTEMS_WAIT, 0 );
176  }
177
178  /* Start up TA02, get preempted */
179  if ( sem_exe == 1) {
180    status = rtems_task_restart( Task_id[1], 0);
181    directive_failed( status, "rtems_task_start of TA02");
182  } else {
183    status = rtems_task_start( Task_id[1], Task02, 0);
184    directive_failed( status, "rtems_task_start of TA02");
185  }
186
187  /* Benchmark code */
188  for ( ; count < BENCHMARKS ; ) {
189    if ( sem_exe == 1 ) {
190      /* Preempted by TA01 upon release */
191      rtems_semaphore_release( sem_id );
192    }
193
194    if ( sem_exe == 1 ) {
195      /* Prepare for next Benchmark */
196      rtems_semaphore_obtain( sem_id, RTEMS_WAIT, 0 );
197    }
198    /* Wake up TA02, get preempted */
199    rtems_task_resume( Task_id[1] );
200  }
201}
202
203/* configuration information */
204#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
205#define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
206
207#define CONFIGURE_TICKS_PER_TIMESLICE        0
208#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
209#define CONFIGURE_MAXIMUM_SEMAPHORES 1
210#define CONFIGURE_MAXIMUM_TASKS 4
211
212#define CONFIGURE_INIT
213#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.