source: rtems/testsuites/tmtests/tm01/task1.c @ b331f40

Last change on this file since b331f40 was b331f40, checked in by Joel Sherrill <joel@…>, on 04/01/22 at 19:05:19

testsuites/tmtests/*: Change license to BSD-2

Updates #3053.

  • Property mode set to 100644
File size: 5.7 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/*
4 *  COPYRIGHT (c) 1989-2013.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#if !defined(OPERATION_COUNT)
30#define OPERATION_COUNT 100
31#endif
32
33#ifdef HAVE_CONFIG_H
34#include "config.h"
35#endif
36
37#include <rtems/btimer.h>
38
39#define CONFIGURE_INIT
40#include "system.h"
41
42const char rtems_test_name[] = "TIME TEST";
43
44rtems_task Test_task(
45  rtems_task_argument argument
46);
47
48rtems_task Init(
49  rtems_task_argument argument
50)
51{
52  rtems_status_code status;
53
54  Print_Warning();
55
56  TEST_BEGIN();
57
58  Task_name[ 1 ] = rtems_build_name( 'T', 'A', '1', ' ' );
59  Task_name[ 2 ] = rtems_build_name( 'T', 'A', '2', ' ' );
60  Task_name[ 3 ] = rtems_build_name( 'T', 'A', '3', ' ' );
61
62  status = rtems_task_create(
63    Task_name[ 1 ],
64    (RTEMS_MAXIMUM_PRIORITY / 2u) + 1u,
65    RTEMS_MINIMUM_STACK_SIZE,
66    RTEMS_DEFAULT_MODES,
67    RTEMS_DEFAULT_ATTRIBUTES,
68    &Task_id[ 1 ]
69  );
70  directive_failed( status, "rtems_task_create of TA1" );
71
72  status = rtems_task_start( Task_id[ 1 ], Test_task, 0 );
73  directive_failed( status, "rtems_task_start of TA1" );
74
75  rtems_task_exit();
76}
77
78rtems_task Test_task(
79  rtems_task_argument argument
80)
81{
82  uint32_t    semaphore_obtain_time;
83  uint32_t    semaphore_release_time;
84  uint32_t    semaphore_obtain_no_wait_time;
85  uint32_t    semaphore_obtain_loop_time;
86  uint32_t    semaphore_release_loop_time;
87  uint32_t    index;
88  uint32_t    iterations;
89  rtems_name        name;
90  rtems_id          smid;
91  rtems_status_code status;
92
93  name = rtems_build_name( 'S', 'M', '1', ' ' );
94
95  semaphore_obtain_time          = 0;
96  semaphore_release_time         = 0;
97  semaphore_obtain_no_wait_time  = 0;
98  semaphore_obtain_loop_time     = 0;
99  semaphore_release_loop_time    = 0;
100
101
102  /* Time one invocation of rtems_semaphore_create */
103
104  benchmark_timer_initialize();
105    (void) rtems_semaphore_create(
106      name,
107      OPERATION_COUNT,
108      RTEMS_DEFAULT_MODES,
109      RTEMS_NO_PRIORITY,
110      &smid
111    );
112  end_time = benchmark_timer_read();
113  put_time(
114    "rtems_semaphore_create: only case",
115    end_time,
116    1,
117    0,
118    0
119  );
120
121  /* Time one invocation of rtems_semaphore_delete */
122
123  benchmark_timer_initialize();
124    (void) rtems_semaphore_delete( smid );
125  end_time = benchmark_timer_read();
126  put_time(
127    "rtems_semaphore_delete: only case",
128    end_time,
129    1,
130    0,
131    0
132  );
133
134  status = rtems_semaphore_create(
135    name,
136    OPERATION_COUNT,
137    RTEMS_DEFAULT_ATTRIBUTES,
138    RTEMS_NO_PRIORITY,
139    &smid
140  );
141  directive_failed( status, "rtems_task_create of TA1" );
142
143  for ( iterations=OPERATION_COUNT ; iterations ; iterations-- ) {
144
145    benchmark_timer_initialize();
146      for ( index = 1 ; index<=OPERATION_COUNT ; index++ )
147        (void) benchmark_timer_empty_function();
148    end_time = benchmark_timer_read();
149
150    semaphore_obtain_loop_time  += end_time;
151    semaphore_release_loop_time += end_time;
152
153    /* rtems_semaphore_obtain (available) */
154
155    benchmark_timer_initialize();
156      for ( index = 1 ; index<=OPERATION_COUNT ; index++ )
157        (void) rtems_semaphore_obtain(
158          smid,
159          RTEMS_DEFAULT_OPTIONS,
160          RTEMS_NO_TIMEOUT
161        );
162    end_time = benchmark_timer_read();
163
164    semaphore_obtain_time += end_time;
165
166    /* rtems_semaphore_release */
167
168    benchmark_timer_initialize();
169      for ( index = 1 ; index<=OPERATION_COUNT ; index++ )
170        (void) rtems_semaphore_release( smid );
171    end_time = benchmark_timer_read();
172
173    semaphore_release_time += end_time;
174
175    /* semaphore obtain (RTEMS_NO_WAIT) */
176    benchmark_timer_initialize();
177      for ( index = 1 ; index<=OPERATION_COUNT ; index++ )
178        rtems_semaphore_obtain( smid, RTEMS_NO_WAIT, RTEMS_NO_TIMEOUT );
179    semaphore_obtain_no_wait_time += benchmark_timer_read();
180
181    benchmark_timer_initialize();
182      for ( index = 1 ; index<=OPERATION_COUNT ; index++ )
183        rtems_semaphore_release( smid );
184    end_time = benchmark_timer_read();
185
186    semaphore_release_time += end_time;
187  }
188
189  put_time(
190    "rtems_semaphore_obtain: available",
191    semaphore_obtain_time,
192    OPERATION_COUNT * OPERATION_COUNT,
193    semaphore_obtain_loop_time,
194    0
195  );
196
197  put_time(
198    "rtems_semaphore_obtain: not available NO_WAIT",
199    semaphore_obtain_no_wait_time,
200    OPERATION_COUNT * OPERATION_COUNT,
201    semaphore_obtain_loop_time,
202    0
203  );
204
205  put_time(
206    "rtems_semaphore_release: no waiting tasks",
207    semaphore_release_time,
208    OPERATION_COUNT * OPERATION_COUNT * 2,
209    semaphore_release_loop_time * 2,
210    0
211  );
212
213  TEST_END();
214  rtems_test_exit( 0 );
215}
Note: See TracBrowser for help on using the repository browser.