fix: completion queue alignment

master
Sean McBride 3 years ago
parent 10cf211007
commit 13c8452f23

@ -1,5 +1,6 @@
#pragma once
#include "ps_list.h"
#include "sandbox_types.h"
void local_completion_queue_add(struct sandbox *sandbox);

@ -26,7 +26,7 @@ INIT_POOL(wasm_stack, wasm_stack_free)
struct module_pool {
struct wasm_memory_pool memory;
struct wasm_stack_pool stack;
} __attribute__((aligned(CACHE_PAD)));
} CACHE_PAD_ALIGNED;
struct module {
char *path;
@ -39,7 +39,7 @@ struct module {
struct sledge_abi__wasm_table *indirect_table;
struct module_pool *pools;
} __attribute__((aligned(CACHE_PAD)));
} CACHE_PAD_ALIGNED;
/********************************
* Public Methods from module.c *

@ -6,7 +6,6 @@
#include "arch/context.h"
#include "current_sandbox.h"
#include "ps_list.h"
#include "sandbox_state_history.h"
#include "sandbox_state_transition.h"
#include "sandbox_types.h"

@ -6,7 +6,6 @@
#include "arch/context.h"
#include "current_sandbox.h"
#include "ps_list.h"
#include "sandbox_state_history.h"
#include "sandbox_state_transition.h"
#include "sandbox_types.h"

@ -32,11 +32,14 @@ struct sandbox_timestamps {
};
struct sandbox {
/* used by ps_list's default name-based MACROS for the scheduling runqueue */
/* Keep as first member of sandbox struct to ensure ps_list maintains alignment */
struct ps_list list;
uint64_t id;
sandbox_state_t state;
struct sandbox_state_history state_history;
struct ps_list list; /* used by ps_list's default name-based MACROS for the scheduling runqueue */
/* Accounting Info */
struct route *route;

@ -21,11 +21,13 @@
#define round_to_cache_pad(x) round_to_pow2((unsigned long)(x), CACHE_PAD)
#define round_up_to_cache_pad(x) round_up_to_pow2((unsigned long)(x), CACHE_PAD)
#define EXPORT __attribute__((visibility("default")))
#define IMPORT __attribute__((visibility("default")))
#define INLINE __attribute__((always_inline))
#define PAGE_ALIGNED __attribute__((aligned(PAGE_SIZE)))
#define WEAK __attribute__((weak))
#define PAGE_ALIGNED __attribute__((aligned(PAGE_SIZE)))
#define CACHE_PAD_ALIGNED __attribute__((aligned(CACHE_PAD)))
#define EXPORT __attribute__((visibility("default")))
#define IMPORT __attribute__((visibility("default")))
#define INLINE __attribute__((always_inline))
#define WEAK __attribute__((weak))
#ifndef unlikely

@ -56,7 +56,12 @@ static INLINE void wasm_memory_set_f64(struct wasm_memory *wasm_memory, uint3
static INLINE struct wasm_memory *
wasm_memory_alloc(uint64_t initial, uint64_t max)
{
struct wasm_memory *wasm_memory = aligned_alloc(4096, round_up_to_page(sizeof(struct wasm_memory)));
size_t alignment = (size_t)PAGE_SIZE;
size_t size_to_alloc = (size_t)round_up_to_page(sizeof(struct wasm_memory));
assert(size_to_alloc % alignment == 0);
struct wasm_memory *wasm_memory = aligned_alloc(alignment, size_to_alloc);
if (wasm_memory == NULL) return wasm_memory;
int rc = wasm_memory_init(wasm_memory, initial, max);

@ -5,6 +5,7 @@
#include <sys/mman.h>
#include <string.h>
#include "ps_list.h"
#include "types.h"
/**

@ -3,7 +3,8 @@
#include "local_completion_queue.h"
#include "sandbox_functions.h"
thread_local static struct ps_list_head local_completion_queue __attribute__((aligned(16)));
/* Must be the same alignment as sandbox structs because of how the ps_list macros work */
thread_local static struct ps_list_head local_completion_queue PAGE_ALIGNED;
void
@ -39,8 +40,6 @@ local_completion_queue_add(struct sandbox *sandbox)
void
local_completion_queue_free()
{
if (local_completion_queue_is_empty()) return;
struct sandbox *sandbox_iterator = NULL;
struct sandbox *buffer = NULL;

@ -111,6 +111,8 @@ module_alloc(char *path)
size_t alignment = (size_t)CACHE_PAD;
size_t size_to_alloc = (size_t)round_to_cache_pad(sizeof(struct module));
assert(size_to_alloc % alignment == 0);
struct module *module = aligned_alloc(alignment, size_to_alloc);
if (!module) {
fprintf(stderr, "Failed to allocate module: %s\n", strerror(errno));

@ -180,11 +180,16 @@ struct sandbox *
sandbox_alloc(struct module *module, struct http_session *session, struct route *route, struct tenant *tenant,
uint64_t admissions_estimate)
{
struct sandbox *sandbox = NULL;
size_t page_aligned_sandbox_size = round_up_to_page(sizeof(struct sandbox));
sandbox = aligned_alloc(PAGE_SIZE, page_aligned_sandbox_size);
memset(sandbox, 0, page_aligned_sandbox_size);
size_t alignment = (size_t)PAGE_SIZE;
size_t size_to_alloc = (size_t)round_up_to_page(sizeof(struct module));
assert(size_to_alloc % alignment == 0);
struct sandbox *sandbox = NULL;
sandbox = aligned_alloc(alignment, size_to_alloc);
if (unlikely(sandbox == NULL)) return NULL;
memset(sandbox, 0, size_to_alloc);
sandbox_set_as_allocated(sandbox);
sandbox_init(sandbox, module, session, route, tenant, admissions_estimate);

Loading…
Cancel
Save