source: multiio/pcmmio/original/main_pcmmio_benchmark.c @ 8660a76

Last change on this file since 8660a76 was 217770e, checked in by Joel Sherrill <joel.sherrill@…>, on 12/14/09 at 15:55:14

2009-12-14 Joel Sherrill <joel.sherrill@…>

  • Makefile, README, mio_io_rtems.c, pcmmio_commands.h: Add command to benchmark discrete input including message queue send and receive.
  • main_pcmmio_benchmark.c: New file.
  • Property mode set to 100644
File size: 3.5 KB
Line 
1/*
2 *  pcmmio_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 "pcmmio_commands.h"
15#include "mio_io.h"
16#include <stdint.h>
17#include <rtems/stringto.h>
18#include <libcpu/cpuModel.h> /* for rdtsc */
19
20#define __need_getopt_newlib
21#include <getopt.h>
22
23char pcmmio_benchmark_usage[] =
24  "Usage: %s [-i interrupts] [-v]\n"
25  "Where: maximum interrupts must be >= 1\n";
26
27#define PRINT_USAGE() \
28   printf( pcmmio_benchmark_usage, argv[0] )
29
30/*
31 *  Compute the number of TSC clicks per microsecond.
32 */
33extern uint64_t tsc_per_microsecond(void);
34int din_timestamp_subtract( uint64_t, uint64_t );
35
36uint64_t to_usecs( uint64_t cycles )
37{
38  return din_timestamp_subtract( 1, cycles + 1 );
39}
40
41int main_pcmmio_benchmark(int argc, char **argv)
42{
43  int                 milliseconds;
44  int                 maximum;
45  int                 sc;
46  char                ch;
47  bool                verbose;
48  struct getopt_data  getopt_reent;
49  const  char        *s;
50  int                 interrupts;
51  uint64_t            timestamp;
52  uint64_t            now;
53  uint32_t            min_cycles;
54  uint32_t            max_cycles;
55  uint64_t            total_cycles;
56  uint64_t            cycles;
57
58  /*
59   * Parse arguments here
60   */
61  milliseconds = 1000;
62  maximum = 1;
63  verbose = false;
64
65  memset(&getopt_reent, 0, sizeof(getopt_data));
66  while ((ch = getopt_r(argc, argv, "i:v:", &getopt_reent)) != -1) {
67    switch (ch) {
68      case 'i': /* maximum interrupts */
69        s = getopt_reent.optarg;
70        if ( rtems_string_to_int( s, &maximum, NULL, 0 ) ) {
71          printf( "Maximum interrupts (%s) is not a number\n", s );
72          PRINT_USAGE();
73          return -1;
74        }
75        if ( maximum <= 0 ) {
76          printf( "Maximum interrupts (%d) is invalid\n", maximum );
77          PRINT_USAGE();
78          return -1;
79        }
80        break;
81      case 'v': /* verbose */
82        verbose = true;
83        break;
84      default:
85        printf( pcmmio_benchmark_usage, argv[0] );
86        return -1;
87    }
88  }
89
90  printf( "Benchmarking for DIN IRQ for %d interrupts\n", maximum );
91
92  /*
93   *  Now sample in the loop
94   */
95  interrupts   = 0;
96  min_cycles   = 0xffffffff;
97  max_cycles   = 0;
98  total_cycles = 0;
99
100  flush_buffered_ints();
101  while (1) {
102    sc = 0;
103   
104    sc = wait_dio_int_with_timestamp(0, &timestamp);
105
106    if ( sc == -1 )
107      continue;
108
109    now = rdtsc();
110
111    cycles = now - timestamp;
112    total_cycles += cycles;
113
114    if ( cycles < min_cycles ) min_cycles = cycles;
115    if ( cycles > max_cycles ) max_cycles = cycles;
116
117    interrupts++;
118
119    if (interrupts >= maximum )
120      break;
121  }
122
123  printf(
124    "Number of Interrupts:     %d\n"
125    "Total Cycles:             %lld\n"
126    "min/max/avg cycles:       %ld/%ld/%lld\n"
127    "min/max/avg microseconds: %lld/%lld/%lld\n",
128    maximum,
129    total_cycles,
130    min_cycles, max_cycles, total_cycles / maximum,
131    to_usecs( min_cycles ),
132    to_usecs( max_cycles ),
133    to_usecs( total_cycles / maximum )
134  );
135  return 0;
136}
137
138rtems_shell_cmd_t Shell_PCMMIO_Benchmark_Command = {
139  "pcmmio_benchmark",                              /* name */
140  "Benchmark PCMMIO Interrupts",                   /* usage */
141  "pcmmio",                                        /* topic */
142  main_pcmmio_benchmark,                           /* command */
143  NULL,                                            /* alias */
144  NULL                                             /* next */
145};
Note: See TracBrowser for help on using the repository browser.