Skip to content

Commit fe69562

Browse files
committed
Replace VTR_LOG with async-signal-safe writes in signal handler
and save block locs after each SA temprature update when signal handler enabled.
1 parent 6d48c27 commit fe69562

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

vpr/src/base/vpr_signal_handler.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
void vpr_signal_handler(int signal);
3030
void checkpoint();
3131

32+
static inline void safe_write(const char* msg) {
33+
(void)!write(STDERR_FILENO, msg, strlen(msg));
34+
}
35+
3236
#ifdef VPR_USE_SIGACTION
3337

3438
void vpr_install_signal_handler() {
@@ -44,14 +48,14 @@ void vpr_install_signal_handler() {
4448

4549
void vpr_signal_handler(int signal) {
4650
if (signal == SIGINT) {
47-
VTR_LOG("Recieved SIGINT: Attempting to checkpoint then exit...\n");
51+
safe_write("Received SIGINT: Attempting to checkpoint then exit...\n");
4852
checkpoint();
4953
std::quick_exit(INTERRUPTED_EXIT_CODE);
5054
} else if (signal == SIGHUP) {
51-
VTR_LOG("Recieved SIGHUP: Attempting to checkpoint...\n");
55+
safe_write("Received SIGHUP: Attempting to checkpoint...\n");
5256
checkpoint();
5357
} else if (signal == SIGTERM) {
54-
VTR_LOG("Recieved SIGTERM: Attempting to checkpoint then exit...\n");
58+
safe_write("Received SIGTERM: Attempting to checkpoint then exit...\n");
5559
checkpoint();
5660
std::quick_exit(INTERRUPTED_EXIT_CODE);
5761
}
@@ -74,14 +78,12 @@ void checkpoint() {
7478
//Dump the current placement and routing state
7579
vtr::ScopedStartFinishTimer timer("Checkpointing");
7680

77-
std::string placer_checkpoint_file = "placer_checkpoint.place";
78-
VTR_LOG("Attempting to checkpoint current placement to file: %s\n", placer_checkpoint_file.c_str());
79-
print_place(nullptr, nullptr, placer_checkpoint_file.c_str(), g_vpr_ctx.placement().block_locs());
81+
safe_write("Attempting to checkpoint current placement to file: placer_checkpoint.place\n");
82+
print_place(nullptr, nullptr, "placer_checkpoint.place", g_vpr_ctx.placement().block_locs());
8083

8184
bool is_flat = g_vpr_ctx.routing().is_flat;
8285
const Netlist<>& router_net_list = is_flat ? (const Netlist<>&)g_vpr_ctx.atom().netlist() : (const Netlist<>&)g_vpr_ctx.clustering().clb_nlist;
8386

84-
std::string router_checkpoint_file = "router_checkpoint.route";
85-
VTR_LOG("Attempting to checkpoint current routing to file: %s\n", router_checkpoint_file.c_str());
86-
print_route(router_net_list, nullptr, router_checkpoint_file.c_str(), is_flat);
87+
safe_write("Attempting to checkpoint current routing to file: router_checkpoint.route\n");
88+
print_route(router_net_list, nullptr, "router_checkpoint.route", is_flat);
8789
}

vpr/src/place/annealer.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,11 @@ void PlacementAnnealer::placement_inner_loop() {
898898
}
899899
}
900900

901+
#ifdef VPR_USE_SIGACTION
902+
// Save the block locations after each inner loop for checkpointing.
903+
g_vpr_ctx.mutable_placement().mutable_block_locs() = placer_state_.block_locs();
904+
#endif
905+
901906
// Calculate the success_rate and std_dev of the costs.
902907
placer_stats_.calc_iteration_stats(costs_, annealing_state_.move_lim);
903908

0 commit comments

Comments
 (0)