source: rtems/testsuites/rhealstone/rhtaskswitch/taskswitch.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: 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  puts( "*** END OF RTASKSWITCH ***" );
44  rtems_test_exit( 0 );
45}
46
47rtems_task Task01( rtems_task_argument ignored )
48{
49  status = rtems_task_start( Task_id[1], Task02, 0 );
50  directive_failed( status, "rtems_task_start of TA02" );
51
52  /* Yield processor so second task can startup and run */
53  rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
54
55  for ( count2 = 0; count2 < BENCHMARKS; count2++ ) {
56    rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
57  }
58
59  /* Should never reach here */
60  rtems_test_assert( false );
61
62}
63
64rtems_task Init( rtems_task_argument ignored )
65{
66  Print_Warning();
67
68  puts( "*** START OF RHTASKSWITCH ***" );
69
70  Task_name[0] = rtems_build_name( 'T','A','0','1' );
71  status = rtems_task_create(
72    Task_name[0],
73    30,
74    RTEMS_MINIMUM_STACK_SIZE,
75    RTEMS_DEFAULT_MODES,
76    RTEMS_DEFAULT_ATTRIBUTES,
77    &Task_id[0]
78  );
79  directive_failed( status, "rtems_task_create of TA01" );
80
81  Task_name[1] = rtems_build_name( 'T','A','0','2' );
82  status = rtems_task_create(
83    Task_name[1],
84    30,
85    RTEMS_MINIMUM_STACK_SIZE,
86    RTEMS_DEFAULT_MODES,
87    RTEMS_DEFAULT_ATTRIBUTES,
88    &Task_id[1]
89  );
90  directive_failed( status, "rtems_task_create of TA02" );
91
92  /* find overhead of routine (no task switches) */
93  benchmark_timer_initialize();
94  for ( count1 = 0; count1 < BENCHMARKS - 1; count1++ ) {
95    /* rtems_task_wake_after( RTEMS_YIELD_PROCESSOR ) */
96  }
97  for ( count2 = 0; count2 < BENCHMARKS; count2++ ) {
98    /* rtems_task_wake_after( RTEMS_YIELD_PROCESSOR ) */
99  }
100  loop_overhead = benchmark_timer_read();
101
102  /* find overhead of rtems_task_wake_after call (no task switches) */
103  benchmark_timer_initialize();
104  rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
105  dir_overhead = benchmark_timer_read();
106
107  status = rtems_task_start( Task_id[0], Task01, 0);
108  directive_failed( status, "rtems_task_start of TA01" );
109
110  status = rtems_task_delete( RTEMS_SELF);
111  directive_failed( status, "rtems_task_delete of INIT" );
112}
113
114/* configuration information */
115#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
116#define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
117#define CONFIGURE_TICKS_PER_TIMESLICE        0
118#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
119#define CONFIGURE_MAXIMUM_TASKS 3
120#define CONFIGURE_INIT
121#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.