Serene Runtime 1.0.0-dev
C runtime for the Serene programming language
Loading...
Searching...
No Matches
configuration.c File Reference
#include "serene/rt/configuration.h"
#include <stdint.h>
#include "serene/rt/mm/interface.h"
#include "serene/utils.h"
Include dependency graph for configuration.c:

Go to the source code of this file.

Functions

void srn_config_validate (const srn_configuration_t *config)
 A configuration with every field set to its default.

Function Documentation

◆ srn_config_validate()

void srn_config_validate ( const srn_configuration_t * config)

A configuration with every field set to its default.

Use as an initializer: srn_configuration_t cfg = SRN_CONFIG_DEFAULTS;. Panic unless every knob in config is usable. Called by srn_mm_init and srn_engine_make on the configuration they are given, so a bad value fails loudly at startup, naming the knob, instead of corrupting whatever is sized or bounded by it later.

Definition at line 26 of file configuration.c.

26 {
27 PANIC_IF_NULL(config);
28
29 // Pages are powers of two on every platform in practice, which makes a
30 // covering power of two a whole number of pages. The modulo still checks
31 // it, in case a platform reports an unusual page size. The upper bound
32 // keeps the shift defined and the block size sane.
34 config->mm.block_size_magnitude > 30 ||
35 ((size_t)1 << config->mm.block_size_magnitude) < srn_mm_get_os_page_size() ||
36 ((size_t)1 << config->mm.block_size_magnitude) % srn_mm_get_os_page_size() != 0,
37 "config: mm.block_size_magnitude must yield a whole number of OS pages, within 30"
38 );
39
41 config->fiber.stack_size < FALLBACK_PAGE_SIZE || config->fiber.stack_size > SIZE_MAX / 2,
42 "config: fiber.stack_size must be within one page..SIZE_MAX/2"
43 );
44
45 // At least one page, so the band always faults on an incremental overflow.
46 // The upper bound keeps guard_pages * page size within SIZE_MAX / 2, so the
47 // stack allocation cannot wrap.
49 config->fiber.guard_pages < 1 ||
50 config->fiber.guard_pages > (SIZE_MAX / 2) / srn_mm_get_os_page_size(),
51 "config: fiber.guard_pages must be within 1..(SIZE_MAX/2 / OS page size)"
52 );
53
54 // A workers count of zero is valid, it delegates to the CPU count at run
55 // time.
57 config->fiber.max_workers < 1 || config->fiber.max_workers > SRN_MAX_WORKERS,
58 "config: fiber.max_workers must be within 1..SRN_MAX_WORKERS"
59 );
60
62 config->fiber.workers > config->fiber.max_workers,
63 "config: fiber.workers must not exceed fiber.max_workers"
64 );
65
66 // The ring magnitude bounds every ring, the admission cap, and the backend
67 // op pool; the reap batch is a stack buffer size on the workers.
69 config->reactor.ring_magnitude < 1 || config->reactor.ring_magnitude > 16,
70 "config: reactor.ring_magnitude must be within 1..16"
71 );
73 config->reactor.reap_batch < 1 ||
74 config->reactor.reap_batch > ((size_t)1 << config->reactor.ring_magnitude),
75 "config: reactor.reap_batch must be within 1..ring capacity"
76 );
77
78 // A zero limit rejects everything, including the runtime's own interned
79 // names, which is never what a configuration means.
80 PANIC_IF(config->limits.string_max_len < 1, "config: limits.string_max_len must be at least 1");
81 PANIC_IF(config->limits.ns_name_max_len < 1, "config: limits.ns_name_max_len must be at least 1");
82}
#define SRN_MAX_WORKERS
The absolute worker ceiling.
size_t srn_mm_get_os_page_size(void)
Retutrns the OS page size.
Definition default.c:312
#define FALLBACK_PAGE_SIZE
Definition interface.h:45
srn_reactor_config_t reactor
srn_fiber_config_t fiber
srn_limits_config_t limits
srn_mm_config_t mm
size_t workers
Worker count used when a run does not specify one.
size_t guard_pages
Pages in the guard band below every fiber stack.
size_t max_workers
Hard ceiling a requested worker count is clamped to.
size_t stack_size
Size of every fiber stack, in bytes.
size_t ns_name_max_len
Longest namespace name accepted, in bytes.
size_t string_max_len
Largest string accepted, in bytes.
size_t block_size_magnitude
Magnitude of one block the arena hands out from.
size_t reap_batch
Most completions a worker drains from its channel in a single pass.
size_t ring_magnitude
Magnitude of each channel's SQ/CQ rings, capacity is 1 << magnitude.
#define PANIC_IF_NULL(ptr)
Definition utils.h:66
#define PANIC_IF(cond, msg)
Definition utils.h:59
Here is the call graph for this function:
Here is the caller graph for this function: