From 407a20d22a79901bce6dcea386b267d2218328a9 Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Fri, 10 Jul 2020 12:49:29 -0400 Subject: [PATCH] chore: refactor out u64 --- runtime/compiletime/instr.c | 24 ++++++++++++------------ runtime/include/module.h | 2 +- runtime/include/priority_queue.h | 2 +- runtime/include/sandbox.h | 12 ++++++------ runtime/include/sandbox_request.h | 6 +++--- runtime/include/types.h | 1 - runtime/src/env.c | 4 ++-- runtime/src/libc/uvio.c | 28 ++++++++++++++-------------- runtime/src/module.c | 2 +- runtime/src/runtime.c | 2 +- 10 files changed, 41 insertions(+), 42 deletions(-) diff --git a/runtime/compiletime/instr.c b/runtime/compiletime/instr.c index aa86702..881522c 100644 --- a/runtime/compiletime/instr.c +++ b/runtime/compiletime/instr.c @@ -29,8 +29,8 @@ rotr_u32(u32 n, u32 c_u32) return (n >> c) | (n << ((-c) & mask)); } -INLINE u64 -rotl_u64(u64 n, u64 c_u64) +INLINE uint64_t +rotl_u64(uint64_t n, uint64_t c_u64) { // WASM requires a modulus here (usually a single bitwise op, but it means we need no assert) unsigned int c = c_u64 % (CHAR_BIT * sizeof(n)); @@ -40,8 +40,8 @@ rotl_u64(u64 n, u64 c_u64) return (n << c) | (n >> ((-c) & mask)); } -INLINE u64 -rotr_u64(u64 n, u64 c_u64) +INLINE uint64_t +rotr_u64(uint64_t n, uint64_t c_u64) { // WASM requires a modulus here (usually a single bitwise op, but it means we need no assert) unsigned int c = c_u64 % (CHAR_BIT * sizeof(n)); @@ -80,15 +80,15 @@ i32_rem(i32 a, i32 b) return a % b; } -INLINE u64 -u64_div(u64 a, u64 b) +INLINE uint64_t +u64_div(uint64_t a, uint64_t b) { assert(b); return a / b; } -INLINE u64 -u64_rem(u64 a, u64 b) +INLINE uint64_t +u64_rem(uint64_t a, uint64_t b) { assert(b); return a % b; @@ -139,11 +139,11 @@ i32_trunc_f64(double f) return (i32)f; } -u64 +uint64_t u64_trunc_f32(float f) { assert(0 <= f && f <= UINT64_MAX); - return (u64)f; + return (uint64_t)f; } i64 @@ -153,11 +153,11 @@ i64_trunc_f32(float f) return (i64)f; } -u64 +uint64_t u64_trunc_f64(double f) { assert(0 <= f && f <= UINT64_MAX); - return (u64)f; + return (uint64_t)f; } i64 diff --git a/runtime/include/module.h b/runtime/include/module.h index a617338..bbb0a6a 100644 --- a/runtime/include/module.h +++ b/runtime/include/module.h @@ -10,7 +10,7 @@ struct module { void * dynamic_library_handle; /* Handle to the *.so of the serverless function */ i32 argument_count; u32 stack_size; /* a specification? */ - u64 max_memory; /* perhaps a specification of the module. (max 4GB) */ + uint64_t max_memory; /* perhaps a specification of the module. (max 4GB) */ u32 relative_deadline_us; u32 reference_count; /* ref count how many instances exist here. */ struct indirect_table_entry indirect_table[INDIRECT_TABLE_SIZE]; diff --git a/runtime/include/priority_queue.h b/runtime/include/priority_queue.h index e49569a..2cc4ef2 100644 --- a/runtime/include/priority_queue.h +++ b/runtime/include/priority_queue.h @@ -11,7 +11,7 @@ * UNIX time in ms). This is used to maintain a read replica of the highest * priority element that can be used to maintain a read replica * @param element - * @returns priority (a u64) + * @returns priority (a uint64_t) */ typedef uint64_t (*priority_queue_get_priority_fn_t)(void *element); diff --git a/runtime/include/sandbox.h b/runtime/include/sandbox.h index 1269618..34fef5f 100644 --- a/runtime/include/sandbox.h +++ b/runtime/include/sandbox.h @@ -35,18 +35,18 @@ struct sandbox { u32 sandbox_size; /* The struct plus enough buffer to hold the request or response (sized off largest) */ - void *linear_memory_start; /* after sandbox struct */ - u32 linear_memory_size; /* from after sandbox struct */ - u64 linear_memory_max_size; + void * linear_memory_start; /* after sandbox struct */ + u32 linear_memory_size; /* from after sandbox struct */ + uint64_t linear_memory_max_size; void *stack_start; u32 stack_size; arch_context_t ctxt; /* register context for context switch. */ - u64 total_time; - u64 start_time; - u64 absolute_deadline; + uint64_t total_time; + uint64_t start_time; + uint64_t absolute_deadline; struct module *module; /* the module this is an instance of */ diff --git a/runtime/include/sandbox_request.h b/runtime/include/sandbox_request.h index 96d877f..d44bea2 100644 --- a/runtime/include/sandbox_request.h +++ b/runtime/include/sandbox_request.h @@ -14,8 +14,8 @@ struct sandbox_request { char * arguments; int socket_descriptor; struct sockaddr *socket_address; - u64 start_time; /* cycles */ - u64 absolute_deadline; /* cycles */ + uint64_t start_time; /* cycles */ + uint64_t absolute_deadline; /* cycles */ }; typedef struct sandbox_request sandbox_request_t; @@ -33,7 +33,7 @@ DEQUE_PROTOTYPE(sandbox, sandbox_request_t *); */ static inline sandbox_request_t * sandbox_request_allocate(struct module *module, char *arguments, int socket_descriptor, - const struct sockaddr *socket_address, u64 start_time) + const struct sockaddr *socket_address, uint64_t start_time) { sandbox_request_t *sandbox_request = (sandbox_request_t *)malloc(sizeof(sandbox_request_t)); assert(sandbox_request); diff --git a/runtime/include/types.h b/runtime/include/types.h index 94bae94..0688d3b 100644 --- a/runtime/include/types.h +++ b/runtime/include/types.h @@ -43,7 +43,6 @@ typedef uint16_t u16; typedef int32_t i32; typedef uint32_t u32; typedef int64_t i64; -typedef uint64_t u64; /* FIXME: per-module configuration? */ #define WASM_PAGE_SIZE (1024 * 64) /* 64KB */ diff --git a/runtime/src/env.c b/runtime/src/env.c index 5b970e5..414cc13 100644 --- a/runtime/src/env.c +++ b/runtime/src/env.c @@ -27,13 +27,13 @@ env___unmapself(u32 base, u32 size) } i32 -env_a_ctz_64(u64 x) +env_a_ctz_64(uint64_t x) { return __builtin_ctzll(x); } INLINE void -env_a_and_64(i32 p_off, u64 v) +env_a_and_64(i32 p_off, uint64_t v) { uint64_t *p = worker_thread_get_memory_ptr_void(p_off, sizeof(uint64_t)); ck_pr_and_64(p, v); diff --git a/runtime/src/libc/uvio.c b/runtime/src/libc/uvio.c index 5fd5ae0..b3558ec 100644 --- a/runtime/src/libc/uvio.c +++ b/runtime/src/libc/uvio.c @@ -249,18 +249,18 @@ wasm_close(i32 file_descriptor) // What the wasm stat structure looks like struct wasm_stat { - i64 st_dev; - u64 st_ino; - u32 st_nlink; - - u32 st_mode; - u32 st_uid; - u32 st_gid; - u32 __pad0; - u64 st_rdev; - u64 st_size; - i32 st_blksize; - i64 st_blocks; + i64 st_dev; + uint64_t st_ino; + u32 st_nlink; + + u32 st_mode; + u32 st_uid; + u32 st_gid; + u32 __pad0; + uint64_t st_rdev; + uint64_t st_size; + i32 st_blksize; + i64 st_blocks; struct { i32 tv_sec; @@ -689,8 +689,8 @@ wasm_geteuid() #define SYS_GET_TIME 228 struct wasm_time_spec { - u64 sec; - u32 nanosec; + uint64_t sec; + u32 nanosec; }; i32 diff --git a/runtime/src/module.c b/runtime/src/module.c index eeef835..753ed08 100644 --- a/runtime/src/module.c +++ b/runtime/src/module.c @@ -159,7 +159,7 @@ module_new(char *name, char *path, i32 argument_count, u32 stack_size, u32 max_m module->argument_count = argument_count; module->stack_size = round_up_to_page(stack_size == 0 ? WASM_STACK_SIZE : stack_size); - module->max_memory = max_memory == 0 ? ((u64)WASM_PAGE_SIZE * WASM_MAX_PAGES) : max_memory; + module->max_memory = max_memory == 0 ? ((uint64_t)WASM_PAGE_SIZE * WASM_MAX_PAGES) : max_memory; module->relative_deadline_us = relative_deadline_us; module->socket_descriptor = -1; module->port = port; diff --git a/runtime/src/runtime.c b/runtime/src/runtime.c index 64fb5f4..5968a85 100644 --- a/runtime/src/runtime.c +++ b/runtime/src/runtime.c @@ -74,7 +74,7 @@ listener_thread_main(void *dummy) LISTENER_THREAD_MAX_EPOLL_EVENTS, -1); /* Capture Start Time to calculate absolute deadline */ - u64 start_time = __getcycles(); + uint64_t start_time = __getcycles(); for (int i = 0; i < request_count; i++) { if (epoll_events[i].events & EPOLLERR) { perror("epoll_wait");