source: rtems/testsuites/rhealstone/rhtaskswitch/taskswitch.c @ 564ce0f

4.115
Last change on this file since 564ce0f was b6c1578, checked in by Joel Sherrill <joel.sherrill@…>, on 01/05/14 at 17:17:08

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: 3.3 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];
18uint32_t           loop_overhead;
19uint32_t           dir_overhead;
20unsigned long      count1, count2;
21rtems_status_code  status;
22
23rtems_task Task02( rtems_task_argument ignored )
24{
25  uint32_t telapsed;
26
27  /* All overhead accounted for now, we can begin benchmark */
28  benchmark_timer_initialize();
29
30  for ( count1 = 0; count1 < BENCHMARKS - 1; count1++ ) {
31    rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
32  }
33
34  telapsed = benchmark_timer_read();
35  put_time(
36     "Rhealstone: Task switch",
37     telapsed,
38     ( BENCHMARKS * 2 ) - 1,   /* ( BENCHMARKS * 2 ) - 1 total benchmarks */
39     loop_overhead,            /* Overhead of loop */
40     dir_overhead              /* Overhead of rtems_task_wake_after directive */
41  );
42
43  rtems_test_exit( 0 );
44}
45
46rtems_task Task01( rtems_task_argument ignored )
47{
48  status = rtems_task_start( Task_id[1], Task02, 0 );
49  directive_failed( status, "rtems_task_start of TA02" );
50
51  /* Yield processor so second task can startup and run */
52  rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
53
54  for ( count2 = 0; count2 < BENCHMARKS; count2++ ) {
55    rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
56  }
57
58  /* Should never reach here */
59  rtems_test_assert( false );
60
61}
62
63rtems_task Init( rtems_task_argument ignored )
64{
65  Print_Warning();
66
67  Task_name[0] = rtems_build_name( 'T','A','0','1' );
68  status = rtems_task_create(
69    Task_name[0],
70    30,
71    RTEMS_MINIMUM_STACK_SIZE,
72    RTEMS_DEFAULT_MODES,
73    RTEMS_DEFAULT_ATTRIBUTES,
74    &Task_id[0]
75  );
76  directive_failed( status, "rtems_task_create of TA01" );
77
78  Task_name[1] = rtems_build_name( 'T','A','0','2' );
79  status = rtems_task_create(
80    Task_name[1],
81    30,
82    RTEMS_MINIMUM_STACK_SIZE,
83    RTEMS_DEFAULT_MODES,
84    RTEMS_DEFAULT_ATTRIBUTES,
85    &Task_id[1]
86  );
87  directive_failed( status, "rtems_task_create of TA02" );
88
89  /* find overhead of routine (no task switches) */
90  benchmark_timer_initialize();
91  for ( count1 = 0; count1 < BENCHMARKS - 1; count1++ ) {
92    /* rtems_task_wake_after( RTEMS_YIELD_PROCESSOR ) */
93  }
94  for ( count2 = 0; count2 < BENCHMARKS; count2++ ) {
95    /* rtems_task_wake_after( RTEMS_YIELD_PROCESSOR ) */
96  }
97  loop_overhead = benchmark_timer_read();
98
99  /* find overhead of rtems_task_wake_after call (no task switches) */
100  benchmark_timer_initialize();
101  rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
102  dir_overhead = benchmark_timer_read();
103
104  status = rtems_task_start( Task_id[0], Task01, 0);
105  directive_failed( status, "rtems_task_start of TA01" );
106
107  status = rtems_task_delete( RTEMS_SELF);
108  directive_failed( status, "rtems_task_delete of INIT" );
109}
110
111/* configuration information */
112#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
113#define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
114#define CONFIGURE_TICKS_PER_TIMESLICE        0
115#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
116#define CONFIGURE_MAXIMUM_TASKS 3
117#define CONFIGURE_INIT
118#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.