source: rtems/testsuites/rhealstone/rhsemshuffle/semshuffle.c @ cdf30f05

4.115
Last change on this file since cdf30f05 was 8fbe2e6, checked in by Joel Sherrill <joel.sherrill@…>, on 09/04/14 at 13:59:49

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