Use autoconf correctly; provide more stats with -I
[deliverable/binutils-gdb.git] / sim / ppc / mon.c
1 /* This file is part of the program psim.
2
3 Copyright (C) 1994-1995, Andrew Cagney <cagney@highland.com.au>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 */
20
21
22 #ifndef _MON_C_
23 #define _MON_C_
24
25 #ifndef STATIC_INLINE_MON
26 #define STATIC_INLINE_MON STATIC_INLINE
27 #endif
28
29 #include "basics.h"
30 #include "cpu.h"
31 #include "mon.h"
32
33 #ifdef HAVE_STRING_H
34 #include <string.h>
35 #else
36 #ifdef HAVE_STRINGS_H
37 #include <strings.h>
38 #endif
39 #endif
40
41 #ifdef HAVE_UNISTD_H
42 #include <unistd.h>
43 #endif
44
45 #ifdef HAVE_TIME_H
46 #include <time.h>
47 #endif
48
49 #ifdef HAVE_SYS_TIMES_H
50 #include <sys/times.h>
51 #endif
52
53 #ifdef HAVE_SYS_RESOURCE_H
54 #include <sys/resource.h>
55 #endif
56
57 struct _cpu_mon {
58 unsigned issue_count[nr_itable_entries];
59 unsigned read_count;
60 unsigned write_count;
61 };
62
63 struct _mon {
64 int nr_cpus;
65 cpu_mon cpu_monitor[MAX_NR_PROCESSORS];
66 };
67
68
69 INLINE_MON mon *
70 mon_create(void)
71 {
72 mon *monitor = ZALLOC(mon);
73 return monitor;
74 }
75
76
77 INLINE_MON cpu_mon *
78 mon_cpu(mon *monitor,
79 int cpu_nr)
80 {
81 if (cpu_nr < 0 || cpu_nr >= MAX_NR_PROCESSORS)
82 error("mon_cpu() - invalid cpu number\n");
83 return &monitor->cpu_monitor[cpu_nr];
84 }
85
86
87 INLINE_MON void
88 mon_init(mon *monitor,
89 int nr_cpus)
90 {
91 bzero(monitor, sizeof(*monitor));
92 monitor->nr_cpus = nr_cpus;
93 }
94
95
96 INLINE_MON void
97 mon_issue(itable_index index,
98 cpu *processor,
99 unsigned_word cia)
100 {
101 cpu_mon *monitor = cpu_monitor(processor);
102 ASSERT(index <= nr_itable_entries);
103 monitor->issue_count[index] += 1;
104 }
105
106
107 INLINE_MON void
108 mon_read(unsigned_word ea,
109 unsigned_word ra,
110 unsigned nr_bytes,
111 cpu *processor,
112 unsigned_word cia)
113 {
114 cpu_mon *monitor = cpu_monitor(processor);
115 monitor->read_count += 1;
116 }
117
118
119 INLINE_MON void
120 mon_write(unsigned_word ea,
121 unsigned_word ra,
122 unsigned nr_bytes,
123 cpu *processor,
124 unsigned_word cia)
125 {
126 cpu_mon *monitor = cpu_monitor(processor);
127 monitor->write_count += 1;
128 }
129
130
131 STATIC_INLINE_MON unsigned
132 mon_get_number_of_insns(cpu_mon *monitor)
133 {
134 itable_index index;
135 unsigned total_insns = 0;
136 for (index = 0; index < nr_itable_entries; index++)
137 total_insns += monitor->issue_count[index];
138 return total_insns;
139 }
140
141 STATIC_INLINE_MON char *
142 mon_add_commas(char *buf,
143 int sizeof_buf,
144 long value)
145 {
146 int comma = 3;
147 char *endbuf = buf + sizeof_buf - 1;
148
149 *--endbuf = '\0';
150 do {
151 if (comma-- == 0)
152 {
153 *--endbuf = ',';
154 comma = 2;
155 }
156
157 *--endbuf = (value % 10) + '0';
158 } while ((value /= 10) != 0);
159
160 ASSERT(endbuf >= buf);
161 return endbuf;
162 }
163
164
165 INLINE_MON void
166 mon_print_info(mon *monitor,
167 int verbose)
168 {
169 char buffer[20];
170 int cpu_nr;
171 int len_cpu;
172 int len_num = 0;
173 int len;
174 long total_insns = 0;
175 long cpu_insns_second;
176 double cpu_time = 0.0;
177
178 for (cpu_nr = 0; cpu_nr < monitor->nr_cpus; cpu_nr++) {
179 unsigned num_insns = mon_get_number_of_insns(&monitor->cpu_monitor[cpu_nr]);
180
181 total_insns += num_insns;
182 len = strlen (mon_add_commas(buffer, sizeof(buffer), num_insns));
183 if (len_num < len)
184 len_num = len;
185 }
186
187 sprintf (buffer, "%d", (int)monitor->nr_cpus + 1);
188 len_cpu = strlen (buffer);
189
190 #ifdef HAVE_GETRUSAGE
191 if (total_insns && verbose > 1)
192 {
193 struct rusage mytime;
194 if (getrusage (RUSAGE_SELF, &mytime) == 0
195 && (mytime.ru_utime.tv_sec > 0 || mytime.ru_utime.tv_usec > 0)) {
196
197 cpu_time = (double)mytime.ru_utime.tv_sec + (((double)mytime.ru_utime.tv_usec) / 1000000.0);
198 cpu_insns_second = (long)(((double)total_insns / cpu_time) + 0.5);
199 }
200 }
201 #endif
202
203 for (cpu_nr = 0; cpu_nr < monitor->nr_cpus; cpu_nr++) {
204
205 if (verbose > 1) {
206 itable_index index;
207
208 if (cpu_nr)
209 printf_filtered ("\n");
210
211 for (index = 0; index < nr_itable_entries; index++) {
212 if (monitor->cpu_monitor[cpu_nr].issue_count[index])
213 printf_filtered("CPU #%*d executed %*s %s instruction%s.\n",
214 len_cpu, cpu_nr+1,
215 len_num, mon_add_commas(buffer,
216 sizeof(buffer),
217 monitor->cpu_monitor[cpu_nr].issue_count[index]),
218 itable[index].name,
219 (monitor->cpu_monitor[cpu_nr].issue_count[index] == 1) ? "" : "s");
220 }
221
222 if (monitor->cpu_monitor[cpu_nr].read_count)
223 printf_filtered ("CPU #%*d executed %*s data reads.\n",
224 len_cpu, cpu_nr+1,
225 len_num, mon_add_commas(buffer,
226 sizeof(buffer),
227 monitor->cpu_monitor[cpu_nr].read_count));
228
229 if (monitor->cpu_monitor[cpu_nr].write_count)
230 printf_filtered ("CPU #%*d executed %*s data writes.\n",
231 len_cpu, cpu_nr+1,
232 len_num, mon_add_commas(buffer,
233 sizeof(buffer),
234 monitor->cpu_monitor[cpu_nr].write_count));
235 }
236
237 printf_filtered("CPU #%*d executed %*s instructions in total.\n",
238 len_cpu, cpu_nr+1,
239 len_num, mon_add_commas(buffer,
240 sizeof(buffer),
241 mon_get_number_of_insns(&monitor->cpu_monitor[cpu_nr])));
242 }
243
244 if (monitor->nr_cpus > 1)
245 printf_filtered("\nAll CPUs executed %s instructions in total.\n",
246 mon_add_commas(buffer, sizeof(buffer), total_insns));
247
248 if (cpu_insns_second)
249 printf_filtered ("\nSimulator speed was %s instructions/second\n",
250 mon_add_commas(buffer, sizeof(buffer), cpu_insns_second));
251 }
252
253 #endif /* _MON_C_ */
This page took 0.038894 seconds and 5 git commands to generate.