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

4.11
Last change on this file since b6c1578 was b6c1578, checked in by Joel Sherrill <joel.sherrill@…>, on Jan 5, 2014 at 5:17:08 PM

rhealstone: Add rh prefix to all test names

This makes them easier to spot as a group in wildcard searches.

  • Property mode set to 100644
File size: 4.1 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  sem_attr =  RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY;
36
37  sem_name = rtems_build_name( 'S','0',' ',' ' );
38  status = rtems_semaphore_create(
39    sem_name,
40    1,
41    sem_attr,
42    0,
43    &sem_id
44  );
45  directive_failed( status, "rtems_semaphore_create of S0" );
46
47  Task_name[0] = rtems_build_name( 'T','A','0','1' );
48  status = rtems_task_create(
49    Task_name[0],
50    30,
51    RTEMS_MINIMUM_STACK_SIZE,
52    RTEMS_DEFAULT_MODES,
53    RTEMS_DEFAULT_ATTRIBUTES,
54    &Task_id[0]
55  );
56  directive_failed( status, "rtems_task_create of TA01" );
57
58  Task_name[1] = rtems_build_name( 'T','A','0','2' );
59  status = rtems_task_create(
60    Task_name[1],
61    30,
62    RTEMS_MINIMUM_STACK_SIZE,
63    RTEMS_DEFAULT_MODES,
64    RTEMS_DEFAULT_ATTRIBUTES,
65    &Task_id[1]
66  );
67  directive_failed( status , "rtems_task_create of TA02\n" );
68
69  rtems_task_mode( RTEMS_PREEMPT, RTEMS_PREEMPT_MASK, &prev_mode );
70  /* Lower own priority so TA01 can start up and run */
71  rtems_task_set_priority( RTEMS_SELF, 40, &pri);
72
73  /* Get time of benchmark with no semaphore shuffling */
74  sem_exe = 0;
75  status = rtems_task_start( Task_id[0], Task01, 0 );
76  directive_failed( status, "rtems_task_start of TA01" );
77
78  /* Get time of benchmark with semaphore shuffling */
79  sem_exe = 1;
80  status = rtems_task_restart( Task_id[0], 0 );
81  directive_failed( status, "rtems_task_restart of TA01" );
82
83  /* Should never reach here */
84  rtems_test_assert( false );
85}
86
87rtems_task Task01( rtems_task_argument ignored )
88{
89  rtems_status_code status;
90
91  /* Start up TA02, yield so it can run */
92  if ( sem_exe == 0 ) {
93    status = rtems_task_start( Task_id[1], Task02, 0 );
94    directive_failed( status, "rtems_task_start of TA02" );
95  } else {
96    status = rtems_task_restart( Task_id[1], 0 );
97    directive_failed( status, "rtems_task_restart of TA02" );
98  }
99  rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
100
101  /* Benchmark code */
102  for ( ; count < BENCHMARKS ; ) {
103    if ( sem_exe == 1 ) {
104      rtems_semaphore_obtain( sem_id, RTEMS_WAIT, 0 );
105    }
106    rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
107
108    if ( sem_exe == 1 ) {
109      rtems_semaphore_release( sem_id );
110    }
111    rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
112  }
113
114  /* Should never reach here */
115  rtems_test_assert( false );
116}
117
118rtems_task Task02( rtems_task_argument ignored )
119{
120
121  /* Benchmark code */
122  benchmark_timer_initialize();
123  for ( count = 0; count < BENCHMARKS; count++ ) {
124    if ( sem_exe == 1 ) {
125      rtems_semaphore_obtain( sem_id, RTEMS_WAIT, 0 );
126    }
127    rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
128
129    if ( sem_exe == 1 ) {
130      rtems_semaphore_release( sem_id );
131    }
132    rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
133  }
134  telapsed = benchmark_timer_read();
135
136  /* Check which run this was */
137  if (sem_exe == 0) {
138    tswitch_overhead = telapsed;
139    rtems_task_suspend( Task_id[0] );
140    rtems_task_suspend( RTEMS_SELF );
141  } else {
142    put_time(
143       "Rhealstone: Semaphore Shuffle",
144       telapsed,
145       (BENCHMARKS * 2),        /* Total number of semaphore-shuffles*/
146       tswitch_overhead,        /* Overhead of loop and task switches */
147       0
148    );
149    rtems_test_exit( 0 );
150  }
151}
152
153/* configuration information */
154#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
155#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
156#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
157#define CONFIGURE_MAXIMUM_TASKS 3
158#define CONFIGURE_MAXIMUM_SEMAPHORES 1
159#define CONFIGURE_INIT
160#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.