source: rtems/testsuites/rhealstone/rhmlatency/mlatency.c @ 1d799ad

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