|
4 | 4 | #include <getopt.h> |
5 | 5 | #include <inttypes.h> |
6 | 6 | #include <poll.h> |
| 7 | +#include <signal.h> |
7 | 8 | #include <stdio.h> |
8 | 9 | #include <stdlib.h> |
9 | 10 | #include <string.h> |
@@ -1007,7 +1008,6 @@ static int semu_step(emu_state_t *emu) |
1007 | 1008 | } |
1008 | 1009 |
|
1009 | 1010 | #ifdef MMU_CACHE_STATS |
1010 | | -static vm_t *global_vm_for_signal = NULL; |
1011 | 1011 | static volatile sig_atomic_t signal_received = 0; |
1012 | 1012 |
|
1013 | 1013 | /* Forward declaration */ |
@@ -1152,11 +1152,11 @@ static int semu_run(emu_state_t *emu) |
1152 | 1152 |
|
1153 | 1153 | while (!emu->stopped) { |
1154 | 1154 | #ifdef MMU_CACHE_STATS |
1155 | | - /* Check if signal received (SIGINT/SIGTERM) */ |
1156 | | - if (signal_received) { |
1157 | | - print_mmu_cache_stats(&emu->vm); |
1158 | | - return 0; |
1159 | | - } |
| 1155 | + /* Check if signal received (SIGINT/SIGTERM). |
| 1156 | + * Break to cleanup resources, stats printed at end of main(). |
| 1157 | + */ |
| 1158 | + if (signal_received) |
| 1159 | + break; |
1160 | 1160 | #endif |
1161 | 1161 | /* Only need fds for timer and UART (no coroutine I/O) */ |
1162 | 1162 | size_t needed = 2; |
@@ -1345,6 +1345,13 @@ static int semu_run(emu_state_t *emu) |
1345 | 1345 |
|
1346 | 1346 | /* Single-hart mode: use original scheduling */ |
1347 | 1347 | while (!emu->stopped) { |
| 1348 | +#ifdef MMU_CACHE_STATS |
| 1349 | + /* Check if signal received (SIGINT/SIGTERM). |
| 1350 | + * Break to exit loop, stats printed at end of main(). |
| 1351 | + */ |
| 1352 | + if (signal_received) |
| 1353 | + break; |
| 1354 | +#endif |
1348 | 1355 | #if SEMU_HAS(VIRTIONET) |
1349 | 1356 | int i = 0; |
1350 | 1357 | if (emu->vnet.peer.type == NETDEV_IMPL_user && boot_complete) { |
@@ -1422,6 +1429,13 @@ static gdb_action_t semu_cont(void *args) |
1422 | 1429 | { |
1423 | 1430 | emu_state_t *emu = (emu_state_t *) args; |
1424 | 1431 | while (!semu_is_interrupt(emu)) { |
| 1432 | +#ifdef MMU_CACHE_STATS |
| 1433 | + /* Check if signal received (SIGINT/SIGTERM). |
| 1434 | + * Break to return control to gdbstub, stats printed at end of main(). |
| 1435 | + */ |
| 1436 | + if (signal_received) |
| 1437 | + break; |
| 1438 | +#endif |
1425 | 1439 | semu_step(emu); |
1426 | 1440 | } |
1427 | 1441 |
|
@@ -1507,7 +1521,6 @@ int main(int argc, char **argv) |
1507 | 1521 | return ret; |
1508 | 1522 |
|
1509 | 1523 | #ifdef MMU_CACHE_STATS |
1510 | | - global_vm_for_signal = &emu.vm; |
1511 | 1524 | signal(SIGINT, signal_handler_stats); |
1512 | 1525 | signal(SIGTERM, signal_handler_stats); |
1513 | 1526 | #endif |
|
0 commit comments