source: rtems/testsuites/rhealstone/rhmlatency/mlatency.c @ b6c1578

4.11
Last change on this file since b6c1578 was b6c1578, checked in by Joel Sherrill <joel.sherrill@…>, on Jan 5, 2014 at 5:17:08 PM

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.9 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#ifdef HAVE_CONFIG_H
8#include "config.h"
9#endif
10
11#include <timesys.h>
12#include <rtems/timerdrv.h>
13
14#define MESSAGE_SIZE (sizeof(long) * 4)
15#define BENCHMARKS 50000
16
17rtems_task Init( rtems_task_argument ignored );
18rtems_task Task01( rtems_task_argument ignored );
19rtems_task Task02( rtems_task_argument ignored );
20
21uint32_t    telapsed;
22uint32_t    tloop_overhead;
23uint32_t    treceive_overhead;
24uint32_t    count;
25rtems_id    Task_id[2];
26rtems_name  Task_name[2];
27rtems_id    Queue_id;
28long        Buffer[4];
29
30void Init(
31  rtems_task_argument argument
32)
33{
34  rtems_status_code status;
35
36  Print_Warning();
37
38  status = rtems_message_queue_create(
39    rtems_build_name( 'M', 'Q', '1', ' '  ),
40    1,
41    MESSAGE_SIZE,
42    RTEMS_DEFAULT_ATTRIBUTES,
43    &Queue_id
44  );
45  directive_failed( status, "rtems_message_queue_create" );
46
47  Task_name[0] = rtems_build_name( 'T','A','0','1' );
48  status = rtems_task_create(
49    Task_name[0],
50    30,               /* TA01 is low priority task */
51    RTEMS_MINIMUM_STACK_SIZE,
52    RTEMS_DEFAULT_MODES,
53    RTEMS_DEFAULT_ATTRIBUTES,
54    &Task_id[0]
55  );
56  directive_failed( status, "rtems_task_create of TA01");
57
58  Task_name[1] = rtems_build_name( 'T','A','0','2' );
59  status = rtems_task_create(
60    Task_name[1],
61    28,               /* High priority task */
62    RTEMS_MINIMUM_STACK_SIZE,
63    RTEMS_DEFAULT_MODES,
64    RTEMS_DEFAULT_ATTRIBUTES,
65    &Task_id[1]
66  );
67  directive_failed( status, "rtems_task_create of TA01" );
68
69  benchmark_timer_initialize();
70  for ( count = 0; count < BENCHMARKS - 1; count++ ) {
71    /* message send/recieve */
72  }
73  tloop_overhead = benchmark_timer_read();
74
75  status = rtems_task_start( Task_id[0], Task01, 0 );
76  directive_failed( status, "rtems_task_start of TA01" );
77
78  status = rtems_task_delete( RTEMS_SELF );
79  directive_failed( status, "rtems_task_delete of RTEMS_SELF" );
80}
81
82rtems_task Task01( rtems_task_argument ignored )
83{
84  rtems_status_code status;
85
86  /* Put a message in the queue so recieve overhead can be found. */
87  (void) rtems_message_queue_send( Queue_id, Buffer, MESSAGE_SIZE );
88
89  /* Start up second task, get preempted */
90  status = rtems_task_start( Task_id[1], Task02, 0 );
91  directive_failed( status, "rtems_task_start" );
92
93  for ( ; count < BENCHMARKS; count++ ) {
94    (void) rtems_message_queue_send( Queue_id, Buffer, MESSAGE_SIZE );
95  }
96
97  /* Should never reach here */
98  rtems_test_assert( false );
99
100}
101
102rtems_task Task02( rtems_task_argument ignored )
103{
104  size_t size;
105
106  /* find recieve overhead - no preempt or task switch */
107  benchmark_timer_initialize();
108  (void) rtems_message_queue_receive(
109             Queue_id,
110             (long (*)[4]) Buffer,
111             &size,
112             RTEMS_DEFAULT_OPTIONS,
113             RTEMS_NO_TIMEOUT
114           );
115  treceive_overhead = benchmark_timer_read();
116
117  /* Benchmark code */
118  benchmark_timer_initialize();
119  for ( count = 0; count < BENCHMARKS - 1; count++ ) {
120    (void) rtems_message_queue_receive(
121             Queue_id,
122             (long (*)[4]) Buffer,
123             &size,
124             RTEMS_DEFAULT_OPTIONS,
125             RTEMS_NO_TIMEOUT
126           );
127  }
128  telapsed = benchmark_timer_read();
129
130  put_time(
131   "Rhealstone: Intertask Message Latency",
132   telapsed,                     /* Total time of all benchmarks */
133   BENCHMARKS - 1,               /* Total benchmarks */
134   tloop_overhead,               /* Overhead of loops */
135   treceive_overhead             /* Overhead of recieve call and task switch */
136  );
137
138  rtems_test_exit( 0 );
139}
140
141/* configuration information */
142
143#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
144#define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
145
146#define CONFIGURE_MAXIMUM_TASKS              3
147#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES     1
148#define CONFIGURE_TICKS_PER_TIMESLICE        0
149#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
150
151#define CONFIGURE_INIT
152#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.