source: rtems/testsuites/rhealstone/rhtaskpreempt/taskpreempt.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.6 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 <timesys.h>
8#include <rtems/timerdrv.h>
9#define BENCHMARKS 50000   /* Number of benchmarks to run and average over */
10
11rtems_task Task02( rtems_task_argument ignored );
12rtems_task Task01( rtems_task_argument ignored );
13rtems_task Init( rtems_task_argument ignored );
14
15rtems_id           Task_id[2];
16rtems_name         Task_name[2];
17
18uint32_t           telapsed;          /* total time elapsed during benchmark */
19uint32_t           tloop_overhead;    /* overhead of loops */
20uint32_t           tswitch_overhead;  /* overhead of time it takes to switch
21                                       * from TA02 to TA01, includes rtems_suspend
22                                       * overhead
23                                       */
24unsigned long      count1;
25rtems_status_code  status;
26
27rtems_task Task01( rtems_task_argument ignored )
28{
29  /* Start up TA02, get preempted */
30  status = rtems_task_start( Task_id[1], Task02, 0);
31  directive_failed( status, "rtems_task_start of TA02");
32
33  tswitch_overhead = benchmark_timer_read();
34
35  benchmark_timer_initialize();
36  /* Benchmark code */
37  for ( count1 = 0; count1 < BENCHMARKS; count1++ ) {
38    rtems_task_resume( Task_id[1] );  /* Awaken TA02, preemption occurs */
39  }
40
41  /* Should never reach here */
42  rtems_test_assert( false );
43}
44
45rtems_task Task02( rtems_task_argument ignored )
46{
47  /* Find overhead of task switch back to TA01 (not a preemption) */
48  benchmark_timer_initialize();
49  rtems_task_suspend( RTEMS_SELF );
50
51  /* Benchmark code */
52  for ( ; count1 < BENCHMARKS - 1; ) {
53    rtems_task_suspend( RTEMS_SELF );
54  }
55
56  telapsed = benchmark_timer_read();
57  put_time(
58     "Rhealstone: Task Preempt",
59     telapsed,                     /* Total time of all benchmarks */
60     BENCHMARKS - 1,               /* BENCHMARKS - 1 total preemptions */
61     tloop_overhead,               /* Overhead of loops */
62     tswitch_overhead              /* Overhead of task switch back to TA01 */
63  );
64
65  puts( "*** END OF RHTASKPREEMPT ***" );
66  rtems_test_exit( 0 );
67}
68
69rtems_task Init( rtems_task_argument ignored )
70{
71  Print_Warning();
72
73  puts( "*** START OF RHTASKPREEMPT ***" );
74
75  Task_name[0] = rtems_build_name( 'T','A','0','1' );
76  status = rtems_task_create(
77    Task_name[0],
78    30,               /* TA01 is low priority task */
79    RTEMS_MINIMUM_STACK_SIZE,
80    RTEMS_DEFAULT_MODES,
81    RTEMS_DEFAULT_ATTRIBUTES,
82    &Task_id[0]
83  );
84  directive_failed( status, "rtems_task_create of TA01");
85
86  Task_name[1] = rtems_build_name( 'T','A','0','2' );
87  status = rtems_task_create(
88    Task_name[1],
89    28,               /* TA02 is high priority task */
90    RTEMS_MINIMUM_STACK_SIZE,
91    RTEMS_DEFAULT_MODES,
92    RTEMS_DEFAULT_ATTRIBUTES,
93    &Task_id[1]
94  );
95  directive_failed( status, "rtems_task_create of TA02");
96
97  /* Find loop overhead */
98  benchmark_timer_initialize();
99  for ( count1 = 0; count1 < ( BENCHMARKS * 2 ) - 1; count1++ ); {
100     /* rtems_task_resume( Task_id[1] ); */
101  }
102  tloop_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.