From 4182c29476ed51170e676befcff2c37f8235da92 Mon Sep 17 00:00:00 2001 From: Isaku Yamahata Date: Thu, 6 Feb 2020 17:02:27 -0800 Subject: [PATCH] [LibOS] Eliminate unnecessary nested functions BEGIN_MIGRATION_DEF() is used to define nested functions unnecessarily. Make them normal (non-nested) functions. --- LibOS/shim/include/shim_checkpoint.h | 8 ++++---- LibOS/shim/src/sys/shim_exec.c | 28 ++++++++++---------------- LibOS/shim/src/sys/shim_fork.c | 30 ++++++++++++++-------------- LibOS/shim/src/sys/shim_migrate.c | 28 +++++++++++++------------- 4 files changed, 44 insertions(+), 50 deletions(-) diff --git a/LibOS/shim/include/shim_checkpoint.h b/LibOS/shim/include/shim_checkpoint.h index 9a320a82..7a9cc0f3 100644 --- a/LibOS/shim/include/shim_checkpoint.h +++ b/LibOS/shim/include/shim_checkpoint.h @@ -326,9 +326,9 @@ struct shim_cp_map_entry* get_cp_map_entry(void* map, void* addr, bool create); e->off = (off); \ } while (0) -#define BEGIN_MIGRATION_DEF(name, ...) \ - int migrate_##name(struct shim_cp_store* store, ##__VA_ARGS__) { \ - int ret = 0; \ +#define BEGIN_MIGRATION_DEF(name, ...) \ + int migrate_cp_##name(struct shim_cp_store* store, ##__VA_ARGS__) { \ + int ret = 0; \ ptr_t base = store->base; #define END_MIGRATION_DEF(name) \ @@ -367,7 +367,7 @@ struct shim_cp_map_entry* get_cp_map_entry(void* map, void* addr, bool create); } \ SAVE_PROFILE_INTERVAL(checkpoint_create_map); \ \ - ret = migrate_##name(store, ##__VA_ARGS__); \ + ret = migrate_cp_##name(store, ##__VA_ARGS__); \ if (ret < 0) \ goto out; \ \ diff --git a/LibOS/shim/src/sys/shim_exec.c b/LibOS/shim/src/sys/shim_exec.c index dc838060..889c4494 100644 --- a/LibOS/shim/src/sys/shim_exec.c +++ b/LibOS/shim/src/sys/shim_exec.c @@ -252,6 +252,17 @@ DEFINE_PROFILE_INTERVAL(search_and_check_file_for_exec, exec); DEFINE_PROFILE_INTERVAL(open_file_for_exec, exec); DEFINE_PROFILE_INTERVAL(close_CLOEXEC_files_for_exec, exec); +static BEGIN_MIGRATION_DEF(execve, struct shim_thread* thread, struct shim_process* proc, + const char** envp) { + DEFINE_MIGRATE(process, proc, sizeof(struct shim_process)); + DEFINE_MIGRATE(all_mounts, NULL, 0); + DEFINE_MIGRATE(running_thread, thread, sizeof(struct shim_thread)); + DEFINE_MIGRATE(handle_map, thread->handle_map, sizeof(struct shim_handle_map)); + DEFINE_MIGRATE(migratable, NULL, 0); + DEFINE_MIGRATE(environ, envp, 0); +} +END_MIGRATION_DEF(execve) + /* thread is cur_thread stripped off stack & tcb (see below func); * process is new process which is forked and waits for checkpoint. */ static int migrate_execve(struct shim_cp_store* cpstore, struct shim_thread* thread, @@ -272,23 +283,6 @@ static int migrate_execve(struct shim_cp_store* cpstore, struct shim_thread* thr SAVE_PROFILE_INTERVAL(close_CLOEXEC_files_for_exec); - /* Now we start to migrate bookkeeping for exec. - The data we need to migrate are: - 1. cur_threadrent thread - 2. cur_threadrent filesystem - 3. handle mapping - 4. each handle */ - BEGIN_MIGRATION_DEF(execve, struct shim_thread* thread, struct shim_process* proc, - const char** envp) { - DEFINE_MIGRATE(process, proc, sizeof(struct shim_process)); - DEFINE_MIGRATE(all_mounts, NULL, 0); - DEFINE_MIGRATE(running_thread, thread, sizeof(struct shim_thread)); - DEFINE_MIGRATE(handle_map, thread->handle_map, sizeof(struct shim_handle_map)); - DEFINE_MIGRATE(migratable, NULL, 0); - DEFINE_MIGRATE(environ, envp, 0); - } - END_MIGRATION_DEF(execve) - return START_MIGRATE(cpstore, execve, thread, process, envp); } diff --git a/LibOS/shim/src/sys/shim_fork.c b/LibOS/shim/src/sys/shim_fork.c index eaff607c..d3522144 100644 --- a/LibOS/shim/src/sys/shim_fork.c +++ b/LibOS/shim/src/sys/shim_fork.c @@ -35,24 +35,24 @@ #include #include +static BEGIN_MIGRATION_DEF(fork, struct shim_thread* thread, struct shim_process* process) { + DEFINE_MIGRATE(process, process, sizeof(struct shim_process)); + DEFINE_MIGRATE(all_mounts, NULL, 0); + DEFINE_MIGRATE(all_vmas, NULL, 0); + DEFINE_MIGRATE(running_thread, thread, sizeof(struct shim_thread)); + DEFINE_MIGRATE(handle_map, thread->handle_map, sizeof(struct shim_handle_map)); + DEFINE_MIGRATE(migratable, NULL, 0); + DEFINE_MIGRATE(brk, NULL, 0); + DEFINE_MIGRATE(loaded_libraries, NULL, 0); +#ifdef DEBUG + DEFINE_MIGRATE(gdb_map, NULL, 0); +#endif +} +END_MIGRATION_DEF(fork) + int migrate_fork(struct shim_cp_store* store, struct shim_thread* thread, struct shim_process* process, va_list ap) { __UNUSED(ap); - BEGIN_MIGRATION_DEF(fork, struct shim_thread* thread, struct shim_process* process) { - DEFINE_MIGRATE(process, process, sizeof(struct shim_process)); - DEFINE_MIGRATE(all_mounts, NULL, 0); - DEFINE_MIGRATE(all_vmas, NULL, 0); - DEFINE_MIGRATE(running_thread, thread, sizeof(struct shim_thread)); - DEFINE_MIGRATE(handle_map, thread->handle_map, sizeof(struct shim_handle_map)); - DEFINE_MIGRATE(migratable, NULL, 0); - DEFINE_MIGRATE(brk, NULL, 0); - DEFINE_MIGRATE(loaded_libraries, NULL, 0); -#ifdef DEBUG - DEFINE_MIGRATE(gdb_map, NULL, 0); -#endif - } - END_MIGRATION_DEF(fork) - int ret = START_MIGRATE(store, fork, thread, process); thread->in_vm = false; diff --git a/LibOS/shim/src/sys/shim_migrate.c b/LibOS/shim/src/sys/shim_migrate.c index aee6dcd0..c3abe597 100644 --- a/LibOS/shim/src/sys/shim_migrate.c +++ b/LibOS/shim/src/sys/shim_migrate.c @@ -220,26 +220,26 @@ static void* file_alloc(struct shim_cp_store* store, void* addr, size_t size) { return addr; } +static BEGIN_MIGRATION_DEF(checkpoint) { + DEFINE_MIGRATE(process, &cur_process, sizeof(struct shim_process)); + DEFINE_MIGRATE(all_mounts, NULL, 0); + DEFINE_MIGRATE(all_vmas, NULL, 0); + DEFINE_MIGRATE(all_running_threads, NULL, 0); + DEFINE_MIGRATE(brk, NULL, 0); + DEFINE_MIGRATE(loaded_libraries, NULL, 0); +#ifdef DEBUG + DEFINE_MIGRATE(gdb_map, NULL, 0); +#endif + DEFINE_MIGRATE(migratable, NULL, 0); +} +END_MIGRATION_DEF(checkpoint) + static int finish_checkpoint(struct cp_session* cpsession) { struct shim_cp_store* cpstore = &cpsession->cpstore; int ret; cpstore->alloc = file_alloc; - BEGIN_MIGRATION_DEF(checkpoint) { - DEFINE_MIGRATE(process, &cur_process, sizeof(struct shim_process)); - DEFINE_MIGRATE(all_mounts, NULL, 0); - DEFINE_MIGRATE(all_vmas, NULL, 0); - DEFINE_MIGRATE(all_running_threads, NULL, 0); - DEFINE_MIGRATE(brk, NULL, 0); - DEFINE_MIGRATE(loaded_libraries, NULL, 0); -#ifdef DEBUG - DEFINE_MIGRATE(gdb_map, NULL, 0); -#endif - DEFINE_MIGRATE(migratable, NULL, 0); - } - END_MIGRATION_DEF(checkpoint) - if ((ret = START_MIGRATE(cpstore, checkpoint)) < 0) return ret;