source: rtems/testsuites/rhealstone/deadlockbrk/deadlockbrk.c @ e8c7dbe7

4.115
Last change on this file since e8c7dbe7 was e8c7dbe7, checked in by Joel Sherrill <joel.sherrill@…>, on 01/05/14 at 16:39:34

rhealstone/*.c: Add Print_Warning() call to indicate debug enabled

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