1 | /* |
---|
2 | * pcmmio_irq command |
---|
3 | * |
---|
4 | * COPYRIGHT (c) 1989-2011. |
---|
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 | |
---|
23 | char 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 | */ |
---|
33 | extern uint64_t tsc_per_microsecond(void); |
---|
34 | int din_timestamp_subtract( uint64_t, uint64_t ); |
---|
35 | |
---|
36 | uint64_t to_usecs( uint64_t cycles ) |
---|
37 | { |
---|
38 | return din_timestamp_subtract( 1, cycles + 1 ); |
---|
39 | } |
---|
40 | |
---|
41 | int main_pcmmio_benchmark(int argc, char **argv) |
---|
42 | { |
---|
43 | int maximum; |
---|
44 | int sc; |
---|
45 | char ch; |
---|
46 | bool verbose; |
---|
47 | struct getopt_data getopt_reent; |
---|
48 | const char *s; |
---|
49 | int interrupts; |
---|
50 | uint64_t timestamp; |
---|
51 | uint64_t now; |
---|
52 | uint32_t min_cycles; |
---|
53 | uint32_t max_cycles; |
---|
54 | uint64_t total_cycles; |
---|
55 | uint64_t cycles; |
---|
56 | |
---|
57 | /* |
---|
58 | * Parse arguments here |
---|
59 | */ |
---|
60 | maximum = 1; |
---|
61 | verbose = false; |
---|
62 | |
---|
63 | memset(&getopt_reent, 0, sizeof(getopt_data)); |
---|
64 | while ((ch = getopt_r(argc, argv, "i:v", &getopt_reent)) != -1) { |
---|
65 | switch (ch) { |
---|
66 | case 'i': /* maximum interrupts */ |
---|
67 | s = getopt_reent.optarg; |
---|
68 | if ( rtems_string_to_int( s, &maximum, NULL, 0 ) ) { |
---|
69 | printf( "Maximum interrupts (%s) is not a number\n", s ); |
---|
70 | PRINT_USAGE(); |
---|
71 | return -1; |
---|
72 | } |
---|
73 | if ( maximum <= 0 ) { |
---|
74 | printf( "Maximum interrupts (%d) is invalid\n", maximum ); |
---|
75 | PRINT_USAGE(); |
---|
76 | return -1; |
---|
77 | } |
---|
78 | break; |
---|
79 | case 'v': /* verbose */ |
---|
80 | verbose = true; |
---|
81 | break; |
---|
82 | default: |
---|
83 | printf( pcmmio_benchmark_usage, argv[0] ); |
---|
84 | return -1; |
---|
85 | } |
---|
86 | } |
---|
87 | |
---|
88 | printf( "Benchmarking for DIN IRQ for %d interrupts\n", maximum ); |
---|
89 | |
---|
90 | /* |
---|
91 | * Now catch interrupts in the loop |
---|
92 | */ |
---|
93 | interrupts = 0; |
---|
94 | min_cycles = 0xffffffff; |
---|
95 | max_cycles = 0; |
---|
96 | total_cycles = 0; |
---|
97 | |
---|
98 | flush_buffered_ints(); |
---|
99 | while (1) { |
---|
100 | sc = 0; |
---|
101 | |
---|
102 | sc = wait_dio_int_with_timestamp(0, ×tamp); |
---|
103 | |
---|
104 | if ( sc == -1 ) |
---|
105 | continue; |
---|
106 | |
---|
107 | now = rdtsc(); |
---|
108 | |
---|
109 | cycles = now - timestamp; |
---|
110 | total_cycles += cycles; |
---|
111 | |
---|
112 | if ( cycles < min_cycles ) min_cycles = cycles; |
---|
113 | if ( cycles > max_cycles ) max_cycles = cycles; |
---|
114 | |
---|
115 | interrupts++; |
---|
116 | |
---|
117 | if (interrupts >= maximum ) |
---|
118 | break; |
---|
119 | } |
---|
120 | |
---|
121 | printf( |
---|
122 | "Number of Interrupts: %d\n" |
---|
123 | "Total Cycles: %lld\n" |
---|
124 | "min/max/avg cycles: %ld/%ld/%lld\n" |
---|
125 | "min/max/avg microseconds: %lld/%lld/%lld\n", |
---|
126 | maximum, |
---|
127 | total_cycles, |
---|
128 | min_cycles, max_cycles, total_cycles / maximum, |
---|
129 | to_usecs( min_cycles ), |
---|
130 | to_usecs( max_cycles ), |
---|
131 | to_usecs( total_cycles / maximum ) |
---|
132 | ); |
---|
133 | return 0; |
---|
134 | } |
---|
135 | |
---|
136 | rtems_shell_cmd_t Shell_PCMMIO_Benchmark_Command = { |
---|
137 | "pcmmio_benchmark", /* name */ |
---|
138 | "Benchmark PCMMIO Interrupts", /* usage */ |
---|
139 | "pcmmio", /* topic */ |
---|
140 | main_pcmmio_benchmark, /* command */ |
---|
141 | NULL, /* alias */ |
---|
142 | NULL /* next */ |
---|
143 | }; |
---|