1 /* This file is part of the program psim.
3 Copyright (C) 1994-1995, Andrew Cagney <cagney@highland.com.au>
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.
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.
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.
25 #ifndef STATIC_INLINE_MON
26 #define STATIC_INLINE_MON STATIC_INLINE
54 #ifdef HAVE_SYS_TIMES_H
55 #include <sys/times.h>
58 #ifdef HAVE_SYS_RESOURCE_H
59 #include <sys/resource.h>
64 count_type issue_count
[nr_itable_entries
];
65 count_type read_count
;
66 count_type write_count
;
67 count_type unaligned_read_count
;
68 count_type unaligned_write_count
;
69 count_type event_count
[nr_mon_events
];
74 cpu_mon cpu_monitor
[MAX_NR_PROCESSORS
];
81 mon
*monitor
= ZALLOC(mon
);
90 if (cpu_nr
< 0 || cpu_nr
>= MAX_NR_PROCESSORS
)
91 error("mon_cpu() - invalid cpu number\n");
92 return &monitor
->cpu_monitor
[cpu_nr
];
97 mon_init(mon
*monitor
,
100 memset(monitor
, 0, sizeof(*monitor
));
101 monitor
->nr_cpus
= nr_cpus
;
106 mon_issue(itable_index index
,
110 cpu_mon
*monitor
= cpu_monitor(processor
);
111 ASSERT(index
<= nr_itable_entries
);
112 monitor
->issue_count
[index
] += 1;
117 mon_read(unsigned_word ea
,
123 cpu_mon
*monitor
= cpu_monitor(processor
);
124 monitor
->read_count
+= 1;
125 if ((nr_bytes
- 1) & ea
)
126 monitor
->unaligned_read_count
+= 1;
131 mon_write(unsigned_word ea
,
137 cpu_mon
*monitor
= cpu_monitor(processor
);
138 monitor
->write_count
+= 1;
139 if ((nr_bytes
- 1) & ea
)
140 monitor
->unaligned_write_count
+= 1;
144 mon_event(mon_events event
,
148 cpu_mon
*monitor
= cpu_monitor(processor
);
149 ASSERT(event
>= 0 && event
< nr_mon_events
);
150 monitor
->event_count
[event
] += 1;
153 STATIC_INLINE_MON count_type
154 mon_get_number_of_insns(cpu_mon
*monitor
)
157 count_type total_insns
= 0;
158 for (index
= 0; index
< nr_itable_entries
; index
++)
159 total_insns
+= monitor
->issue_count
[index
];
164 mon_sort_instruction_names(const void *ptr_a
, const void *ptr_b
)
166 itable_index a
= *(const itable_index
*)ptr_a
;
167 itable_index b
= *(const itable_index
*)ptr_b
;
169 return strcmp (itable
[a
].name
, itable
[b
].name
);
172 STATIC_INLINE_MON
char *
173 mon_add_commas(char *buf
,
178 char *endbuf
= buf
+ sizeof_buf
- 1;
188 *--endbuf
= (value
% 10) + '0';
189 } while ((value
/= 10) != 0);
191 ASSERT(endbuf
>= buf
);
197 mon_print_info(psim
*system
,
206 long total_insns
= 0;
207 long cpu_insns_second
= 0;
208 double cpu_time
= 0.0;
210 for (cpu_nr
= 0; cpu_nr
< monitor
->nr_cpus
; cpu_nr
++) {
211 count_type num_insns
= mon_get_number_of_insns(&monitor
->cpu_monitor
[cpu_nr
]);
213 total_insns
+= num_insns
;
214 len
= strlen (mon_add_commas(buffer
, sizeof(buffer
), num_insns
));
219 sprintf (buffer
, "%d", (int)monitor
->nr_cpus
+ 1);
220 len_cpu
= strlen (buffer
);
222 #ifdef HAVE_GETRUSAGE
223 if (total_insns
&& verbose
> 1)
225 struct rusage mytime
;
226 if (getrusage (RUSAGE_SELF
, &mytime
) == 0
227 && (mytime
.ru_utime
.tv_sec
> 0 || mytime
.ru_utime
.tv_usec
> 0)) {
229 cpu_time
= (double)mytime
.ru_utime
.tv_sec
+ (((double)mytime
.ru_utime
.tv_usec
) / 1000000.0);
230 cpu_insns_second
= (long)(((double)total_insns
/ cpu_time
) + 0.5);
235 for (cpu_nr
= 0; cpu_nr
< monitor
->nr_cpus
; cpu_nr
++) {
238 itable_index sort_insns
[nr_itable_entries
];
239 int nr_sort_insns
= 0;
244 printf_filtered ("\n");
246 for (index
= 0; index
< nr_itable_entries
; index
++) {
247 if (monitor
->cpu_monitor
[cpu_nr
].issue_count
[index
]) {
248 sort_insns
[nr_sort_insns
++] = index
;
252 qsort((void *)sort_insns
, nr_sort_insns
, sizeof(sort_insns
[0]), mon_sort_instruction_names
);
254 for (index2
= 0; index2
< nr_sort_insns
; index2
++) {
255 index
= sort_insns
[index2
];
256 printf_filtered("CPU #%*d executed %*s %s instruction%s.\n",
258 len_num
, mon_add_commas(buffer
,
260 monitor
->cpu_monitor
[cpu_nr
].issue_count
[index
]),
262 (monitor
->cpu_monitor
[cpu_nr
].issue_count
[index
] == 1) ? "" : "s");
265 printf_filtered ("\n");
268 if (WITH_MODEL_ISSUE
)
270 model_data
*model_ptr
= cpu_model(psim_cpu(system
, cpu_nr
));
271 model_print
*ptr
= model_mon_info(model_ptr
);
272 model_print
*orig_ptr
= ptr
;
276 printf_filtered("CPU #%*d executed %*s %s%s.\n",
278 len_num
, mon_add_commas(buffer
,
283 ? ptr
->suffix_singular
284 : ptr
->suffix_plural
));
289 model_mon_info_free(model_ptr
, orig_ptr
);
292 if (monitor
->cpu_monitor
[cpu_nr
].read_count
)
293 printf_filtered ("CPU #%*d executed %*s data read%s.\n",
295 len_num
, mon_add_commas(buffer
,
297 monitor
->cpu_monitor
[cpu_nr
].read_count
),
298 (monitor
->cpu_monitor
[cpu_nr
].read_count
== 1) ? "" : "s");
300 if (monitor
->cpu_monitor
[cpu_nr
].write_count
)
301 printf_filtered ("CPU #%*d executed %*s data write%s.\n",
303 len_num
, mon_add_commas(buffer
,
305 monitor
->cpu_monitor
[cpu_nr
].write_count
),
306 (monitor
->cpu_monitor
[cpu_nr
].write_count
== 1) ? "" : "s");
308 if (monitor
->cpu_monitor
[cpu_nr
].unaligned_read_count
)
309 printf_filtered ("CPU #%*d executed %*s unaligned data read%s.\n",
311 len_num
, mon_add_commas(buffer
,
313 monitor
->cpu_monitor
[cpu_nr
].read_count
),
314 (monitor
->cpu_monitor
[cpu_nr
].read_count
== 1) ? "" : "s");
316 if (monitor
->cpu_monitor
[cpu_nr
].unaligned_write_count
)
317 printf_filtered ("CPU #%*d executed %*s unaligned data write%s.\n",
319 len_num
, mon_add_commas(buffer
,
321 monitor
->cpu_monitor
[cpu_nr
].write_count
),
322 (monitor
->cpu_monitor
[cpu_nr
].write_count
== 1) ? "" : "s");
324 if (monitor
->cpu_monitor
[cpu_nr
].event_count
[mon_event_icache_miss
])
325 printf_filtered ("CPU #%*d executed %*s icache miss%s.\n",
327 len_num
, mon_add_commas(buffer
,
329 monitor
->cpu_monitor
[cpu_nr
].event_count
[mon_event_icache_miss
]),
330 (monitor
->cpu_monitor
[cpu_nr
].event_count
[mon_event_icache_miss
] == 1) ? "" : "es");
332 printf_filtered("CPU #%*d executed %*s instructions in total.\n",
334 len_num
, mon_add_commas(buffer
,
336 mon_get_number_of_insns(&monitor
->cpu_monitor
[cpu_nr
])));
340 if (monitor
->nr_cpus
> 1)
341 printf_filtered("\nAll CPUs executed %s instructions in total.\n",
342 mon_add_commas(buffer
, sizeof(buffer
), total_insns
));
344 if (cpu_insns_second
)
345 printf_filtered ("%sSimulator speed was %s instructions/second\n",
346 (monitor
->nr_cpus
<= 1 && verbose
<= 1) ? "" : "\n",
347 mon_add_commas(buffer
, sizeof(buffer
), cpu_insns_second
));