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
50 #ifdef HAVE_SYS_TYPES_H
51 #include <sys/types.h>
58 #ifdef HAVE_SYS_TIMES_H
59 #include <sys/times.h>
62 #ifdef HAVE_SYS_TIME_H
66 #ifdef HAVE_SYS_RESOURCE_H
67 #include <sys/resource.h>
72 count_type issue_count
[nr_itable_entries
];
73 count_type read_count
;
74 count_type write_count
;
75 count_type unaligned_read_count
;
76 count_type unaligned_write_count
;
77 count_type event_count
[nr_mon_events
];
82 cpu_mon cpu_monitor
[MAX_NR_PROCESSORS
];
89 mon
*monitor
= ZALLOC(mon
);
98 if (cpu_nr
< 0 || cpu_nr
>= MAX_NR_PROCESSORS
)
99 error("mon_cpu() - invalid cpu number\n");
100 return &monitor
->cpu_monitor
[cpu_nr
];
105 mon_init(mon
*monitor
,
108 memset(monitor
, 0, sizeof(*monitor
));
109 monitor
->nr_cpus
= nr_cpus
;
114 mon_issue(itable_index index
,
118 cpu_mon
*monitor
= cpu_monitor(processor
);
119 ASSERT(index
<= nr_itable_entries
);
120 monitor
->issue_count
[index
] += 1;
125 mon_read(unsigned_word ea
,
131 cpu_mon
*monitor
= cpu_monitor(processor
);
132 monitor
->read_count
+= 1;
133 if ((nr_bytes
- 1) & ea
)
134 monitor
->unaligned_read_count
+= 1;
139 mon_write(unsigned_word ea
,
145 cpu_mon
*monitor
= cpu_monitor(processor
);
146 monitor
->write_count
+= 1;
147 if ((nr_bytes
- 1) & ea
)
148 monitor
->unaligned_write_count
+= 1;
152 mon_event(mon_events event
,
156 cpu_mon
*monitor
= cpu_monitor(processor
);
157 ASSERT(event
>= 0 && event
< nr_mon_events
);
158 monitor
->event_count
[event
] += 1;
161 STATIC_INLINE_MON count_type
162 mon_get_number_of_insns(cpu_mon
*monitor
)
165 count_type total_insns
= 0;
166 for (index
= 0; index
< nr_itable_entries
; index
++)
167 total_insns
+= monitor
->issue_count
[index
];
172 mon_sort_instruction_names(const void *ptr_a
, const void *ptr_b
)
174 itable_index a
= *(const itable_index
*)ptr_a
;
175 itable_index b
= *(const itable_index
*)ptr_b
;
177 return strcmp (itable
[a
].name
, itable
[b
].name
);
180 STATIC_INLINE_MON
char *
181 mon_add_commas(char *buf
,
186 char *endbuf
= buf
+ sizeof_buf
- 1;
196 *--endbuf
= (value
% 10) + '0';
197 } while ((value
/= 10) != 0);
199 ASSERT(endbuf
>= buf
);
205 mon_print_info(psim
*system
,
214 long total_insns
= 0;
215 long cpu_insns_second
= 0;
216 double cpu_time
= 0.0;
218 for (cpu_nr
= 0; cpu_nr
< monitor
->nr_cpus
; cpu_nr
++) {
219 count_type num_insns
= mon_get_number_of_insns(&monitor
->cpu_monitor
[cpu_nr
]);
221 total_insns
+= num_insns
;
222 len
= strlen (mon_add_commas(buffer
, sizeof(buffer
), num_insns
));
227 sprintf (buffer
, "%d", (int)monitor
->nr_cpus
+ 1);
228 len_cpu
= strlen (buffer
);
230 #ifdef HAVE_GETRUSAGE
231 if (total_insns
&& verbose
)
233 struct rusage mytime
;
234 if (getrusage (RUSAGE_SELF
, &mytime
) == 0
235 && (mytime
.ru_utime
.tv_sec
> 0 || mytime
.ru_utime
.tv_usec
> 0)) {
237 cpu_time
= (double)mytime
.ru_utime
.tv_sec
+ (((double)mytime
.ru_utime
.tv_usec
) / 1000000.0);
238 cpu_insns_second
= (long)(((double)total_insns
/ cpu_time
) + 0.5);
243 for (cpu_nr
= 0; cpu_nr
< monitor
->nr_cpus
; cpu_nr
++) {
246 itable_index sort_insns
[nr_itable_entries
];
247 int nr_sort_insns
= 0;
252 printf_filtered ("\n");
254 for (index
= 0; index
< nr_itable_entries
; index
++) {
255 if (monitor
->cpu_monitor
[cpu_nr
].issue_count
[index
]) {
256 sort_insns
[nr_sort_insns
++] = index
;
260 qsort((void *)sort_insns
, nr_sort_insns
, sizeof(sort_insns
[0]), mon_sort_instruction_names
);
262 for (index2
= 0; index2
< nr_sort_insns
; index2
++) {
263 index
= sort_insns
[index2
];
264 printf_filtered("CPU #%*d executed %*s %s instruction%s.\n",
266 len_num
, mon_add_commas(buffer
,
268 monitor
->cpu_monitor
[cpu_nr
].issue_count
[index
]),
270 (monitor
->cpu_monitor
[cpu_nr
].issue_count
[index
] == 1) ? "" : "s");
273 printf_filtered ("\n");
276 if (CURRENT_MODEL_ISSUE
> 0)
278 model_data
*model_ptr
= cpu_model(psim_cpu(system
, cpu_nr
));
279 model_print
*ptr
= model_mon_info(model_ptr
);
280 model_print
*orig_ptr
= ptr
;
284 printf_filtered("CPU #%*d executed %*s %s%s.\n",
286 len_num
, mon_add_commas(buffer
,
291 ? ptr
->suffix_singular
292 : ptr
->suffix_plural
));
297 model_mon_info_free(model_ptr
, orig_ptr
);
300 if (monitor
->cpu_monitor
[cpu_nr
].read_count
)
301 printf_filtered ("CPU #%*d executed %*s data read%s.\n",
303 len_num
, mon_add_commas(buffer
,
305 monitor
->cpu_monitor
[cpu_nr
].read_count
),
306 (monitor
->cpu_monitor
[cpu_nr
].read_count
== 1) ? "" : "s");
308 if (monitor
->cpu_monitor
[cpu_nr
].write_count
)
309 printf_filtered ("CPU #%*d executed %*s data write%s.\n",
311 len_num
, mon_add_commas(buffer
,
313 monitor
->cpu_monitor
[cpu_nr
].write_count
),
314 (monitor
->cpu_monitor
[cpu_nr
].write_count
== 1) ? "" : "s");
316 if (monitor
->cpu_monitor
[cpu_nr
].unaligned_read_count
)
317 printf_filtered ("CPU #%*d executed %*s unaligned data read%s.\n",
319 len_num
, mon_add_commas(buffer
,
321 monitor
->cpu_monitor
[cpu_nr
].read_count
),
322 (monitor
->cpu_monitor
[cpu_nr
].read_count
== 1) ? "" : "s");
324 if (monitor
->cpu_monitor
[cpu_nr
].unaligned_write_count
)
325 printf_filtered ("CPU #%*d executed %*s unaligned data write%s.\n",
327 len_num
, mon_add_commas(buffer
,
329 monitor
->cpu_monitor
[cpu_nr
].write_count
),
330 (monitor
->cpu_monitor
[cpu_nr
].write_count
== 1) ? "" : "s");
332 if (monitor
->cpu_monitor
[cpu_nr
].event_count
[mon_event_icache_miss
])
333 printf_filtered ("CPU #%*d executed %*s icache miss%s.\n",
335 len_num
, mon_add_commas(buffer
,
337 monitor
->cpu_monitor
[cpu_nr
].event_count
[mon_event_icache_miss
]),
338 (monitor
->cpu_monitor
[cpu_nr
].event_count
[mon_event_icache_miss
] == 1) ? "" : "es");
340 printf_filtered("CPU #%*d executed %*s instructions in total.\n",
342 len_num
, mon_add_commas(buffer
,
344 mon_get_number_of_insns(&monitor
->cpu_monitor
[cpu_nr
])));
348 if (monitor
->nr_cpus
> 1)
349 printf_filtered("\nAll CPUs executed %s instructions in total.\n",
350 mon_add_commas(buffer
, sizeof(buffer
), total_insns
));
352 if (cpu_insns_second
)
353 printf_filtered ("%sSimulator speed was %s instructions/second\n",
354 (monitor
->nr_cpus
> 1) ? "" : "\n",
355 mon_add_commas(buffer
, sizeof(buffer
), cpu_insns_second
));