source: rtems/testsuites/rhealstone/rhdeadlockbrk/deadlockbrk.c @ 8fbe2e6

4.11
Last change on this file since 8fbe2e6 was 8fbe2e6, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 4, 2014 at 1:59:49 PM

Use correct prototype of benchmark_timer_read()

This change starts with removing the effectively empty file
timerdrv.h. The prototypes for benchmark_timer_XXX() were in
btimer.h which was not universally used. Thus every use of
timerdrv.h had to be changed to btimer.h. Then the prototypes
for benchmark_timer_read() had to be adjusted to return
benchmark_timer_t rather than int or uint32_t.

I took this opportunity to also correct the file headers to
separate the copyright from the file description comments which
is needed to ensure the copyright isn't propagated into Doxygen
output.

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