source: rtems/testsuites/rhealstone/rhsemshuffle/semshuffle.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: 4.2 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 50000
11
12rtems_task Task01( rtems_task_argument ignored );
13rtems_task Task02( rtems_task_argument ignored );
14rtems_task Init( rtems_task_argument ignored );
15
16rtems_id   Task_id[2];
17rtems_name Task_name[2];
18rtems_id    sem_id;
19rtems_name  sem_name;
20
21uint32_t    telapsed;
22uint32_t    tswitch_overhead;
23uint32_t    count;
24uint32_t    sem_exe;
25
26rtems_task Init( rtems_task_argument ignored )
27{
28  rtems_status_code    status;
29  rtems_attribute      sem_attr;
30  rtems_task_priority  pri;
31  rtems_mode           prev_mode;
32
33  Print_Warning();
34
35  puts( "*** START OF RHSEMSHUFFLE ***" );
36
37  sem_attr =  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    30,
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    30,
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\n" );
70
71  rtems_task_mode( RTEMS_PREEMPT, RTEMS_PREEMPT_MASK, &prev_mode );
72  /* Lower own priority so TA01 can start up and run */
73  rtems_task_set_priority( RTEMS_SELF, 40, &pri);
74
75  /* Get time of benchmark with no semaphore shuffling */
76  sem_exe = 0;
77  status = rtems_task_start( Task_id[0], Task01, 0 );
78  directive_failed( status, "rtems_task_start of TA01" );
79
80  /* Get time of benchmark with semaphore shuffling */
81  sem_exe = 1;
82  status = rtems_task_restart( Task_id[0], 0 );
83  directive_failed( status, "rtems_task_restart of TA01" );
84
85  /* Should never reach here */
86  rtems_test_assert( false );
87}
88
89rtems_task Task01( rtems_task_argument ignored )
90{
91  rtems_status_code status;
92
93  /* Start up TA02, yield so it can run */
94  if ( sem_exe == 0 ) {
95    status = rtems_task_start( Task_id[1], Task02, 0 );
96    directive_failed( status, "rtems_task_start of TA02" );
97  } else {
98    status = rtems_task_restart( Task_id[1], 0 );
99    directive_failed( status, "rtems_task_restart of TA02" );
100  }
101  rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
102
103  /* Benchmark code */
104  for ( ; count < BENCHMARKS ; ) {
105    if ( sem_exe == 1 ) {
106      rtems_semaphore_obtain( sem_id, RTEMS_WAIT, 0 );
107    }
108    rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
109
110    if ( sem_exe == 1 ) {
111      rtems_semaphore_release( sem_id );
112    }
113    rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
114  }
115
116  /* Should never reach here */
117  rtems_test_assert( false );
118}
119
120rtems_task Task02( rtems_task_argument ignored )
121{
122
123  /* Benchmark code */
124  benchmark_timer_initialize();
125  for ( count = 0; count < BENCHMARKS; count++ ) {
126    if ( sem_exe == 1 ) {
127      rtems_semaphore_obtain( sem_id, RTEMS_WAIT, 0 );
128    }
129    rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
130
131    if ( sem_exe == 1 ) {
132      rtems_semaphore_release( sem_id );
133    }
134    rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
135  }
136  telapsed = benchmark_timer_read();
137
138  /* Check which run this was */
139  if (sem_exe == 0) {
140    tswitch_overhead = telapsed;
141    rtems_task_suspend( Task_id[0] );
142    rtems_task_suspend( RTEMS_SELF );
143  } else {
144    put_time(
145       "Rhealstone: Semaphore Shuffle",
146       telapsed,
147       (BENCHMARKS * 2),        /* Total number of semaphore-shuffles*/
148       tswitch_overhead,        /* Overhead of loop and task switches */
149       0
150    );
151    puts( "*** END OF RHSEMSHUFFLE ***" );
152    rtems_test_exit( 0 );
153  }
154}
155
156/* configuration information */
157#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
158#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
159#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
160#define CONFIGURE_MAXIMUM_TASKS 3
161#define CONFIGURE_MAXIMUM_SEMAPHORES 1
162#define CONFIGURE_INIT
163#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.