From 98889a3a43d5361ca028a144e19ed703a7d5bee1 Mon Sep 17 00:00:00 2001 From: Elazar Gershuni Date: Mon, 30 Sep 2024 13:53:39 +0300 Subject: [PATCH] adapt selfcheckpoint.c and diff_vm_snapshot.cpp Signed-off-by: Elazar Gershuni --- scripts/diff_vm_snapshot.cpp | 14 +++++++----- scripts/selfcheckpoint.c | 41 +++++++++++++++++++++++------------- 2 files changed, 35 insertions(+), 20 deletions(-) diff --git a/scripts/diff_vm_snapshot.cpp b/scripts/diff_vm_snapshot.cpp index 260a643..8362ef7 100644 --- a/scripts/diff_vm_snapshot.cpp +++ b/scripts/diff_vm_snapshot.cpp @@ -36,12 +36,16 @@ int main(int argc, char *argv[]) { } remove = true; } - const std::vector buffer1 = read_file(argv[1], remove); - const std::vector buffer2 = read_file(argv[2], remove); + std::vector buffer1 = read_file(argv[1], remove); + std::vector buffer2 = read_file(argv[2], remove); + size_t diff = 0; if (buffer1.size() != buffer2.size()) { - std::cerr << "Error: file sizes differ\n"; - return 1; + size_t m = std::min(buffer1.size(), buffer2.size()); + diff = std::max(buffer1.size(), buffer2.size()) - m; + std::cerr << "Error: file sizes differ, comparing first " << m << " bytes\n"; + buffer1.resize(m); + buffer2.resize(m); } std::size_t size = buffer1.size(); @@ -57,6 +61,6 @@ int main(int argc, char *argv[]) { } } - std::cout << count * chunk_size << "\n"; + std::cout << count * chunk_size + diff << "\n"; return 0; } diff --git a/scripts/selfcheckpoint.c b/scripts/selfcheckpoint.c index 2833805..41f9373 100644 --- a/scripts/selfcheckpoint.c +++ b/scripts/selfcheckpoint.c @@ -4,9 +4,12 @@ #include // For open() #include #include +#include // For memset() +#include +#include -#define CHECKPOINT_ITER 5 -#define TOTAL_ITER 10 +#define CHECKPOINT_ITER 3 +#define TOTAL_ITER 5 int fd = -1; @@ -28,35 +31,43 @@ void set_criu() { criu_set_pid(getpid()); // Set PID of the process to checkpoint criu_set_leave_running(1); // Keep the process running after dump criu_set_service_address("/tmp/criu_service.socket"); + criu_set_track_mem(0); // Track memory pages } int main() { set_criu(); - if (access("./criu_images", F_OK) == 0) { - printf("Restoring from checkpoint...\n"); - criu_restore(); - perror("CRIU restore failed"); - exit(EXIT_FAILURE); - } + // if (access("./criu_images", F_OK) == 0) { + // printf("Restoring from checkpoint...\n"); + // criu_restore(); + // perror("CRIU restore failed"); + // exit(EXIT_FAILURE); + // } + for (int i = 1; i <= TOTAL_ITER; i++) { + struct timeval start; + gettimeofday(&start, NULL); printf("Iteration: %d\n", i); sleep(1); // Simulate long-running work - + void* x = malloc(1025 * 1024 * 1024); // Allocate 1MB memory + memset(x, 1, 1024 * 1024 * 1024); // Write to the memory + printf("address: %p\n", x); // Create a checkpoint after a certain number of iterations if (i == CHECKPOINT_ITER) { printf("Creating checkpoint...\n"); // Perform the checkpoint - if (criu_dump() < 0) { - perror("CRIU checkpoint failed"); - exit(EXIT_FAILURE); - } + criu_dump(); printf("Checkpoint created successfully!\n"); - printf("Exiting after creating a checkpoint, run again to restore from it.\n"); - exit(EXIT_SUCCESS); + // printf("Exiting after creating a checkpoint, run again to restore from it.\n"); + // exit(EXIT_SUCCESS); } + free(x); + + struct timeval end; + gettimeofday(&end, NULL); + printf("took %lu us\n", (end.tv_sec - start.tv_sec) * 1000000 + end.tv_usec - start.tv_usec); } printf("Loop finished.\n");