Skip to content

Commit

Permalink
adapt selfcheckpoint.c and diff_vm_snapshot.cpp
Browse files Browse the repository at this point in the history
Signed-off-by: Elazar Gershuni <[email protected]>
  • Loading branch information
elazarg committed Sep 30, 2024
1 parent 53cff8d commit 98889a3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 20 deletions.
14 changes: 9 additions & 5 deletions scripts/diff_vm_snapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,16 @@ int main(int argc, char *argv[]) {
}
remove = true;
}
const std::vector<char> buffer1 = read_file(argv[1], remove);
const std::vector<char> buffer2 = read_file(argv[2], remove);
std::vector<char> buffer1 = read_file(argv[1], remove);
std::vector<char> 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();

Expand All @@ -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;
}
41 changes: 26 additions & 15 deletions scripts/selfcheckpoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
#include <fcntl.h> // For open()
#include <sys/types.h>
#include <criu/criu.h>
#include <string.h> // For memset()
#include <time.h>
#include <sys/time.h>

#define CHECKPOINT_ITER 5
#define TOTAL_ITER 10
#define CHECKPOINT_ITER 3
#define TOTAL_ITER 5

int fd = -1;

Expand All @@ -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");
Expand Down

0 comments on commit 98889a3

Please sign in to comment.