From 3cb6b6fabf20260d0a45e5c33e2152d391073dcb Mon Sep 17 00:00:00 2001 From: lidj Date: Sat, 9 Sep 2023 22:13:16 +0800 Subject: [PATCH] minor fix --- chbuild | 5 +- kernel/sls_config.cmake | 8 +- user/sample-apps/apps/treesls/CMakeLists.txt | 4 + .../apps/treesls/test_crash_counter.c | 94 +++++++++++++++++++ .../apps/treesls/test_crash_hello.c | 17 ++++ 5 files changed, 121 insertions(+), 7 deletions(-) create mode 100644 user/sample-apps/apps/treesls/test_crash_counter.c create mode 100644 user/sample-apps/apps/treesls/test_crash_hello.c diff --git a/chbuild b/chbuild index 9ab93ce..b8fa5cd 100755 --- a/chbuild +++ b/chbuild @@ -211,9 +211,8 @@ _docker_run() { $@ else test -t 1 && use_tty="-t" - # docker run -i $use_tty --rm \ - # -u $(id -u ${USER}):$(id -g ${USER}) \ - docker run -it \ + docker run -i $use_tty --rm \ + -u $(id -u ${USER}):$(id -g ${USER}) \ -v $(pwd):/chos -w /chos \ promisivia/treesls_chcore_builder:v2.2 \ $self $@ diff --git a/kernel/sls_config.cmake b/kernel/sls_config.cmake index 58ba1be..c022f71 100644 --- a/kernel/sls_config.cmake +++ b/kernel/sls_config.cmake @@ -4,11 +4,11 @@ set(SLS_EXT_SYNC OFF) set(SLS_HYBRID_MEM ON) # SLS Report Details -set(SLS_REPORT_CKPT ON) -set(SLS_REPORT_RESTORE ON) -set(SLS_REPORT_HYBRID ON) +set(SLS_REPORT_CKPT OFF) +set(SLS_REPORT_RESTORE OFF) +set(SLS_REPORT_HYBRID OFF) # SLS special tests: for tests of only-checkpoint, +pf, +memcpy set(SLS_SPECIAL_OMIT_PF OFF) set(SLS_SPECIAL_OMIT_MEMCPY OFF) -set(SLS_SPECIAL_OMIT_BENCHMARK ON) +set(SLS_SPECIAL_OMIT_BENCHMARK OFF) diff --git a/user/sample-apps/apps/treesls/CMakeLists.txt b/user/sample-apps/apps/treesls/CMakeLists.txt index 77a1908..cb6e98b 100644 --- a/user/sample-apps/apps/treesls/CMakeLists.txt +++ b/user/sample-apps/apps/treesls/CMakeLists.txt @@ -6,6 +6,10 @@ add_executable(idle.bin idle.c) # checkpoint add_executable(checkpoint.bin checkpoint.c) +# test applications +add_executable(test_crash_hello.bin test_crash_hello.c) +add_executable(test_crash_counter.bin test_crash_counter.c) + # adjust config add_executable(set_poll_loop_time.bin set_poll_loop_time.c) add_executable(set_dyn_hybrid_config.bin set_dyn_hybrid_config.c) diff --git a/user/sample-apps/apps/treesls/test_crash_counter.c b/user/sample-apps/apps/treesls/test_crash_counter.c new file mode 100644 index 0000000..db2574c --- /dev/null +++ b/user/sample-apps/apps/treesls/test_crash_counter.c @@ -0,0 +1,94 @@ +#include +#include +#include +#include +#include +#include + +#include +#include + +#define LEADER 0 +#define FOLLOWER 1 +#define TRUE 1 +#define FALSE 0 + +const int sleep_every_step = TRUE; + +struct shared_data { + int turn; + int counter; +}; + +volatile struct shared_data *region; + +void count(int myturn) { + for (;;) { + /* wait for my turn */ + while (region->turn != myturn); + + /* output and add 1 */ + printf("%d: [%d]\n", myturn, region->counter++); + + /* give it to the other process */ + region->turn ^= 1; + + if (sleep_every_step) { + sleep(1); + } + } +} + +void counter_leader(char *program) { + /* create shared memory */ + int shmid = shmget(-1, sizeof(struct shared_data), IPC_CREAT); + assert(shmid > 0); + printf("created shared memory with id = %d\n", shmid); + + /* map shared memory */ + region = (volatile struct shared_data *)shmat(shmid, 0, 0); + assert((s64)region != -EINVAL); + + /* initialize the shared structure */ + region->turn = 0; // leader + region->counter = 1; + + /* spawn the follower process */ + char *argv[] = { program, "follower" }; + chcore_new_process(sizeof(argv) / sizeof(*argv), argv, 0); + + /* spawn ckpt process */ + /* TODO: only for simulating */ + char *argv2[] = {"checkpoint.bin"}; + chcore_new_process(sizeof(argv2) / sizeof(*argv2), argv2, 0); + + /* start counting */ + count(LEADER); +} + +void counter_follower() { + /* map shared memory */ + int shmid = shmget(-1, sizeof(struct shared_data), IPC_CREAT); + region = (volatile struct shared_data *)shmat(shmid, 0, 0); + assert((s64)region != -EINVAL); + + /* start counting */ + count(FOLLOWER); +} + +int main(int argc, char *argv[]) { + switch (argc) { + case 1: + counter_leader(argv[0]); + break; + + case 2: + counter_follower(); + break; + + default: + printf("Please launch this program with 0 or 1 arguments!\n"); + return -1; + } + return 0; +} diff --git a/user/sample-apps/apps/treesls/test_crash_hello.c b/user/sample-apps/apps/treesls/test_crash_hello.c new file mode 100644 index 0000000..bb41492 --- /dev/null +++ b/user/sample-apps/apps/treesls/test_crash_hello.c @@ -0,0 +1,17 @@ +#include +#include +#include +#include +#include + +int main(int argc, char *argv[], char *envp[]) +{ + int cnt = 0; + + while (1) { + printf("[%d] hello world\n", cnt); + usys_whole_ckpt("test_crash_hello", 17); + cnt++; + sleep(1); + } +}