source: rtems/testsuites/rhealstone/rhtaskpreempt/taskpreempt.c @ c080c343

4.11
Last change on this file since c080c343 was 1d799ad, checked in by Sebastian Huber <sebastian.huber@…>, on Jun 3, 2014 at 8:24:55 AM

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