Serene Runtime 1.0.0-dev
C runtime for the Serene programming language
Loading...
Searching...
No Matches
configuration.c
Go to the documentation of this file.
1/* -*- C -*-
2 * Serene programming language
3 * Copyright (C) 2019-2026 Sameer Rahmani <[email protected]>
4 *
5 * This library is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this library. If not, see <https://www.gnu.org/licenses/>.
17 */
18
20
21#include <stdint.h>
22
24#include "serene/utils.h"
25
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 );
40 config->fiber.stack_size < FALLBACK_PAGE_SIZE || config->fiber.stack_size > SIZE_MAX / 2,
41 "config: fiber.stack_size must be within one page..SIZE_MAX/2"
42 );
43
44 PANIC_IF(config->fiber.workers < 1, "config: fiber.workers must be at least 1");
46 config->fiber.max_workers < config->fiber.workers ||
48 "config: fiber.max_workers must be within fiber.workers..SRN_MAX_WORKERS"
49 );
50
51 // The ring magnitude bounds every ring, the admission cap, and the backend
52 // op pool; the reap batch is a stack buffer size on the workers.
54 config->reactor.ring_magnitude < 1 || config->reactor.ring_magnitude > 16,
55 "config: reactor.ring_magnitude must be within 1..16"
56 );
58 config->reactor.reap_batch < 1 ||
59 config->reactor.reap_batch > ((size_t)1 << config->reactor.ring_magnitude),
60 "config: reactor.reap_batch must be within 1..ring capacity"
61 );
62
63 // A zero limit rejects everything, including the runtime's own interned
64 // names, which is never what a configuration means.
65 PANIC_IF(config->limits.string_max_len < 1, "config: limits.string_max_len must be at least 1");
66 PANIC_IF(config->limits.ns_name_max_len < 1, "config: limits.ns_name_max_len must be at least 1");
67}
void srn_config_validate(const srn_configuration_t *config)
A configuration with every field set to its default.
The single place that holds every runtime knob.
#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:303
#define FALLBACK_PAGE_SIZE
Definition interface.h:42
Every runtime knob, in one place.
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 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