Skip to content

Commit 98889a3

Browse files
committed
adapt selfcheckpoint.c and diff_vm_snapshot.cpp
Signed-off-by: Elazar Gershuni <elazarg@gmail.com>
1 parent 53cff8d commit 98889a3

File tree

2 files changed

+35
-20
lines changed

2 files changed

+35
-20
lines changed

scripts/diff_vm_snapshot.cpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,16 @@ int main(int argc, char *argv[]) {
3636
}
3737
remove = true;
3838
}
39-
const std::vector<char> buffer1 = read_file(argv[1], remove);
40-
const std::vector<char> buffer2 = read_file(argv[2], remove);
39+
std::vector<char> buffer1 = read_file(argv[1], remove);
40+
std::vector<char> buffer2 = read_file(argv[2], remove);
4141

42+
size_t diff = 0;
4243
if (buffer1.size() != buffer2.size()) {
43-
std::cerr << "Error: file sizes differ\n";
44-
return 1;
44+
size_t m = std::min(buffer1.size(), buffer2.size());
45+
diff = std::max(buffer1.size(), buffer2.size()) - m;
46+
std::cerr << "Error: file sizes differ, comparing first " << m << " bytes\n";
47+
buffer1.resize(m);
48+
buffer2.resize(m);
4549
}
4650
std::size_t size = buffer1.size();
4751

@@ -57,6 +61,6 @@ int main(int argc, char *argv[]) {
5761
}
5862
}
5963

60-
std::cout << count * chunk_size << "\n";
64+
std::cout << count * chunk_size + diff << "\n";
6165
return 0;
6266
}

scripts/selfcheckpoint.c

+26-15
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
#include <fcntl.h> // For open()
55
#include <sys/types.h>
66
#include <criu/criu.h>
7+
#include <string.h> // For memset()
8+
#include <time.h>
9+
#include <sys/time.h>
710

8-
#define CHECKPOINT_ITER 5
9-
#define TOTAL_ITER 10
11+
#define CHECKPOINT_ITER 3
12+
#define TOTAL_ITER 5
1013

1114
int fd = -1;
1215

@@ -28,35 +31,43 @@ void set_criu() {
2831
criu_set_pid(getpid()); // Set PID of the process to checkpoint
2932
criu_set_leave_running(1); // Keep the process running after dump
3033
criu_set_service_address("/tmp/criu_service.socket");
34+
criu_set_track_mem(0); // Track memory pages
3135
}
3236

3337
int main() {
3438
set_criu();
3539

36-
if (access("./criu_images", F_OK) == 0) {
37-
printf("Restoring from checkpoint...\n");
38-
criu_restore();
39-
perror("CRIU restore failed");
40-
exit(EXIT_FAILURE);
41-
}
40+
// if (access("./criu_images", F_OK) == 0) {
41+
// printf("Restoring from checkpoint...\n");
42+
// criu_restore();
43+
// perror("CRIU restore failed");
44+
// exit(EXIT_FAILURE);
45+
// }
46+
4247
for (int i = 1; i <= TOTAL_ITER; i++) {
48+
struct timeval start;
49+
gettimeofday(&start, NULL);
4350
printf("Iteration: %d\n", i);
4451
sleep(1); // Simulate long-running work
45-
52+
void* x = malloc(1025 * 1024 * 1024); // Allocate 1MB memory
53+
memset(x, 1, 1024 * 1024 * 1024); // Write to the memory
54+
printf("address: %p\n", x);
4655
// Create a checkpoint after a certain number of iterations
4756
if (i == CHECKPOINT_ITER) {
4857
printf("Creating checkpoint...\n");
4958

5059
// Perform the checkpoint
51-
if (criu_dump() < 0) {
52-
perror("CRIU checkpoint failed");
53-
exit(EXIT_FAILURE);
54-
}
60+
criu_dump();
5561

5662
printf("Checkpoint created successfully!\n");
57-
printf("Exiting after creating a checkpoint, run again to restore from it.\n");
58-
exit(EXIT_SUCCESS);
63+
// printf("Exiting after creating a checkpoint, run again to restore from it.\n");
64+
// exit(EXIT_SUCCESS);
5965
}
66+
free(x);
67+
68+
struct timeval end;
69+
gettimeofday(&end, NULL);
70+
printf("took %lu us\n", (end.tv_sec - start.tv_sec) * 1000000 + end.tv_usec - start.tv_usec);
6071
}
6172

6273
printf("Loop finished.\n");

0 commit comments

Comments
 (0)