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 | |
---|
24 | char 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 | |
---|
31 | static 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 | |
---|
39 | int 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, ×tamp); |
---|
104 | |
---|
105 | if ( sc == -1 ) |
---|
106 | continue; |
---|
107 | |
---|
108 | rtems_clock_get_uptime( &now ); |
---|
109 | |
---|
110 | _Timespec_Subtract( &now, ×tamp, &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 | |
---|
137 | rtems_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 | }; |
---|