source: multiio/commands/main_multiio_benchmark.c @ 0ecf946

Last change on this file since 0ecf946 was e38d987, checked in by Joel Sherrill <joel.sherrill@…>, on 03/18/11 at 13:19:33

2011-03-18 Joel Sherrill <joel.sherrill@…>

  • ChangeLog?, Makefile, commands/Makefile, commands/main_multiio_adc.c, commands/main_multiio_benchmark.c, commands/main_multiio_dac.c, commands/main_multiio_din.c, commands/main_multiio_dout.c, commands/main_multiio_irq.c, commands/multiio_commands.h, include/multiio.h, stub/multio_stub.c: New files.
  • Property mode set to 100644
File size: 3.6 KB
Line 
1/*
2 *  multiio_irq command
3 *
4 *  COPYRIGHT (c) 1989-2009.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#include <stdio.h>
15#include <stdlib.h>
16#include <rtems.h>
17#include <rtems/shell.h>
18#include <rtems/stringto.h>
19#include "multiio.h"
20
21#define __need_getopt_newlib
22#include <getopt.h>
23
24char multiio_benchmark_usage[] =
25  "Usage: %s [-i interrupts] [-v]\n"
26  "Where: maximum interrupts must be >= 1\n";
27
28#define PRINT_USAGE() \
29   printf( multiio_benchmark_usage, argv[0] )
30
31static uint64_t to_usecs( struct timespec *time )
32{
33  uint64_t usecs;
34  usecs = _Timespec_Get_seconds( time ) * 1000000;
35  usecs += _Timespec_Get_nanoseconds( time ) / 1000;
36  return usecs;
37}
38
39int main_multiio_benchmark(int argc, char **argv)
40{
41  int                 milliseconds;
42  int                 maximum;
43  int                 sc;
44  char                ch;
45  bool                verbose;
46  struct getopt_data  getopt_reent;
47  const  char        *s;
48  int                 interrupts;
49  struct timespec     timestamp;
50  struct timespec     now;
51  struct timespec     min;
52  struct timespec     max;
53  struct timespec     total;
54  struct timespec     took;
55  struct timespec     average;
56
57  /*
58   * Parse arguments here
59   */
60  milliseconds = 1000;
61  maximum = 1;
62  verbose = false;
63
64  memset(&getopt_reent, 0, sizeof(getopt_data));
65  while ((ch = getopt_r(argc, argv, "i:v:", &getopt_reent)) != -1) {
66    switch (ch) {
67      case 'i': /* maximum interrupts */
68        s = getopt_reent.optarg;
69        if ( rtems_string_to_int( s, &maximum, NULL, 0 ) ) {
70          printf( "Maximum interrupts (%s) is not a number\n", s );
71          PRINT_USAGE();
72          return -1;
73        }
74        if ( maximum <= 0 ) {
75          printf( "Maximum interrupts (%d) is invalid\n", maximum );
76          PRINT_USAGE();
77          return -1;
78        }
79        break;
80      case 'v': /* verbose */
81        verbose = true;
82        break;
83      default:
84        printf( multiio_benchmark_usage, argv[0] );
85        return -1;
86    }
87  }
88
89  printf( "Benchmarking for DIN IRQ for %d interrupts\n", maximum );
90
91  /*
92   *  Now sample in the loop
93   */
94  interrupts   = 0;
95  _Timespec_Set( &min, 0xffffffff, 999999999 );
96  _Timespec_Set_to_zero( &max );
97  _Timespec_Set_to_zero( &total );
98
99  rtems_din_flush_buffered_interrupts();
100  while (1) {
101    sc = 0;
102   
103    sc = rtems_din_wait_interrupt_with_timestamp(0, &timestamp);
104
105    if ( sc == -1 )
106      continue;
107
108    rtems_clock_get_uptime( &now );
109
110    _Timespec_Subtract( &now, &timestamp, &took );
111    _Timespec_Add_to( &total, &took );
112
113    if ( _Timespec_Less_than(&took, &min) )    min = took;
114    if ( _Timespec_Greater_than(&took, &max) ) max = took;
115
116    interrupts++;
117
118    if (interrupts >= maximum )
119      break;
120  }
121
122  _Timespec_Divide_by_integer( &total, maximum, &average );
123
124  printf(
125    "Number of Interrupts:  %d\n"
126    "Total:                 %lld\n"
127    "min/max/avg:           %lld/%lld/%lld\n",
128    maximum,
129    to_usecs( &total ),
130    to_usecs( &min ),
131    to_usecs( &max ),
132    to_usecs( &average )
133  );
134  return 0;
135}
136
137rtems_shell_cmd_t Shell_MULTIIO_Benchmark_Command = {
138  "multiio_benchmark",                             /* name */
139  "Benchmark Multi IOInterrupts",                  /* usage */
140  "multiio",                                       /* topic */
141  main_multiio_benchmark,                          /* command */
142  NULL,                                            /* alias */
143  NULL                                             /* next */
144};
Note: See TracBrowser for help on using the repository browser.