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_TIMES_H
51 #include <sys/times.h>
54 #ifdef HAVE_SYS_RESOURCE_H
55 #include <sys/resource.h>
60 unsigned issue_count
[nr_itable_entries
];
63 unsigned unaligned_read_count
;
64 unsigned unaligned_write_count
;
65 unsigned event_count
[nr_mon_events
];
66 function_unit_print
*func_unit_print
;
71 cpu_mon cpu_monitor
[MAX_NR_PROCESSORS
];
78 mon
*monitor
= ZALLOC(mon
);
87 if (cpu_nr
< 0 || cpu_nr
>= MAX_NR_PROCESSORS
)
88 error("mon_cpu() - invalid cpu number\n");
89 return &monitor
->cpu_monitor
[cpu_nr
];
94 mon_init(mon
*monitor
,
97 memset(monitor
, 0, sizeof(*monitor
));
98 monitor
->nr_cpus
= nr_cpus
;
103 mon_issue(itable_index index
,
107 cpu_mon
*monitor
= cpu_monitor(processor
);
108 ASSERT(index
<= nr_itable_entries
);
109 monitor
->issue_count
[index
] += 1;
110 model_issue(index
, cpu_model(processor
), cia
);
115 mon_read(unsigned_word ea
,
121 cpu_mon
*monitor
= cpu_monitor(processor
);
122 monitor
->read_count
+= 1;
123 if ((nr_bytes
- 1) & ea
)
124 monitor
->unaligned_read_count
+= 1;
129 mon_write(unsigned_word ea
,
135 cpu_mon
*monitor
= cpu_monitor(processor
);
136 monitor
->write_count
+= 1;
137 if ((nr_bytes
- 1) & ea
)
138 monitor
->unaligned_write_count
+= 1;
142 mon_event(mon_events event
,
146 cpu_mon
*monitor
= cpu_monitor(processor
);
147 ASSERT(event
>= 0 && event
< nr_mon_events
);
148 monitor
->event_count
[event
] += 1;
151 STATIC_INLINE_MON
unsigned
152 mon_get_number_of_insns(cpu_mon
*monitor
)
155 unsigned total_insns
= 0;
156 for (index
= 0; index
< nr_itable_entries
; index
++)
157 total_insns
+= monitor
->issue_count
[index
];
161 STATIC_INLINE_MON
char *
162 mon_add_commas(char *buf
,
167 char *endbuf
= buf
+ sizeof_buf
- 1;
177 *--endbuf
= (value
% 10) + '0';
178 } while ((value
/= 10) != 0);
180 ASSERT(endbuf
>= buf
);
186 mon_print_info(psim
*system
,
195 long total_insns
= 0;
196 long cpu_insns_second
= 0;
197 double cpu_time
= 0.0;
199 for (cpu_nr
= 0; cpu_nr
< monitor
->nr_cpus
; cpu_nr
++) {
200 unsigned num_insns
= mon_get_number_of_insns(&monitor
->cpu_monitor
[cpu_nr
]);
202 total_insns
+= num_insns
;
203 len
= strlen (mon_add_commas(buffer
, sizeof(buffer
), num_insns
));
208 sprintf (buffer
, "%d", (int)monitor
->nr_cpus
+ 1);
209 len_cpu
= strlen (buffer
);
211 #ifdef HAVE_GETRUSAGE
212 if (total_insns
&& verbose
> 1)
214 struct rusage mytime
;
215 if (getrusage (RUSAGE_SELF
, &mytime
) == 0
216 && (mytime
.ru_utime
.tv_sec
> 0 || mytime
.ru_utime
.tv_usec
> 0)) {
218 cpu_time
= (double)mytime
.ru_utime
.tv_sec
+ (((double)mytime
.ru_utime
.tv_usec
) / 1000000.0);
219 cpu_insns_second
= (long)(((double)total_insns
/ cpu_time
) + 0.5);
224 for (cpu_nr
= 0; cpu_nr
< monitor
->nr_cpus
; cpu_nr
++) {
230 printf_filtered ("\n");
232 for (index
= 0; index
< nr_itable_entries
; index
++) {
233 if (monitor
->cpu_monitor
[cpu_nr
].issue_count
[index
])
234 printf_filtered("CPU #%*d executed %*s %s instruction%s.\n",
236 len_num
, mon_add_commas(buffer
,
238 monitor
->cpu_monitor
[cpu_nr
].issue_count
[index
]),
240 (monitor
->cpu_monitor
[cpu_nr
].issue_count
[index
] == 1) ? "" : "s");
243 printf_filtered ("\n");
248 model_data
*model_ptr
= cpu_model(psim_cpu(system
, cpu_nr
));
249 model_print
*ptr
= model_mon_info(model_ptr
);
250 model_print
*orig_ptr
= ptr
;
254 printf_filtered("CPU #%*d executed %*s %s%s.\n",
256 len_num
, mon_add_commas(buffer
,
261 ? ptr
->suffix_singular
262 : ptr
->suffix_plural
));
267 model_mon_info_free(model_ptr
, orig_ptr
);
270 if (monitor
->cpu_monitor
[cpu_nr
].read_count
)
271 printf_filtered ("CPU #%*d executed %*s data read%s.\n",
273 len_num
, mon_add_commas(buffer
,
275 monitor
->cpu_monitor
[cpu_nr
].read_count
),
276 (monitor
->cpu_monitor
[cpu_nr
].read_count
== 1) ? "" : "s");
278 if (monitor
->cpu_monitor
[cpu_nr
].write_count
)
279 printf_filtered ("CPU #%*d executed %*s data write%s.\n",
281 len_num
, mon_add_commas(buffer
,
283 monitor
->cpu_monitor
[cpu_nr
].write_count
),
284 (monitor
->cpu_monitor
[cpu_nr
].write_count
== 1) ? "" : "s");
286 if (monitor
->cpu_monitor
[cpu_nr
].unaligned_read_count
)
287 printf_filtered ("CPU #%*d executed %*s unaligned data read%s.\n",
289 len_num
, mon_add_commas(buffer
,
291 monitor
->cpu_monitor
[cpu_nr
].read_count
),
292 (monitor
->cpu_monitor
[cpu_nr
].read_count
== 1) ? "" : "s");
294 if (monitor
->cpu_monitor
[cpu_nr
].unaligned_write_count
)
295 printf_filtered ("CPU #%*d executed %*s unaligned data write%s.\n",
297 len_num
, mon_add_commas(buffer
,
299 monitor
->cpu_monitor
[cpu_nr
].write_count
),
300 (monitor
->cpu_monitor
[cpu_nr
].write_count
== 1) ? "" : "s");
302 if (monitor
->cpu_monitor
[cpu_nr
].event_count
[mon_event_icache_miss
])
303 printf_filtered ("CPU #%*d executed %*s icache miss%s.\n",
305 len_num
, mon_add_commas(buffer
,
307 monitor
->cpu_monitor
[cpu_nr
].event_count
[mon_event_icache_miss
]),
308 (monitor
->cpu_monitor
[cpu_nr
].event_count
[mon_event_icache_miss
] == 1) ? "" : "es");
310 printf_filtered("CPU #%*d executed %*s instructions in total.\n",
312 len_num
, mon_add_commas(buffer
,
314 mon_get_number_of_insns(&monitor
->cpu_monitor
[cpu_nr
])));
318 if (monitor
->nr_cpus
> 1)
319 printf_filtered("\nAll CPUs executed %s instructions in total.\n",
320 mon_add_commas(buffer
, sizeof(buffer
), total_insns
));
322 if (cpu_insns_second
)
323 printf_filtered ("%sSimulator speed was %s instructions/second\n",
324 (monitor
->nr_cpus
<= 1 && verbose
<= 1) ? "" : "\n",
325 mon_add_commas(buffer
, sizeof(buffer
), cpu_insns_second
));
This page took 0.036255 seconds and 5 git commands to generate.