diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-10-07 17:24:18 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-10-07 17:24:36 -0600 |
commit | 62e8081e0ac4a4c170bc536303f7a9bd3e91fd7b (patch) | |
tree | 2c40e8297ff0d423bf5e811fa7212345af6141de | |
parent | b1b07aea8841d78e935e7de13d693a267709e711 (diff) |
tidy config
-rw-r--r-- | cmd/sbc_harness/config/config.h | 97 | ||||
-rw-r--r--[l---------] | cmd/srv9p/config/config.h | 47 | ||||
-rw-r--r-- | cmd/srv9p/main.c | 9 | ||||
-rw-r--r-- | lib9p/include/lib9p/9p.h | 9 | ||||
-rw-r--r-- | lib9p/internal.h | 22 | ||||
-rw-r--r-- | libcr/coroutine.c | 1 | ||||
-rw-r--r-- | libnetio/netio_posix.c | 9 |
7 files changed, 131 insertions, 63 deletions
diff --git a/cmd/sbc_harness/config/config.h b/cmd/sbc_harness/config/config.h index ff18b88..f12d4e5 100644 --- a/cmd/sbc_harness/config/config.h +++ b/cmd/sbc_harness/config/config.h @@ -4,59 +4,48 @@ * SPDX-Licence-Identifier: AGPL-3.0-or-later */ -#if (defined(USE_CONFIG_NETIO_POSIX) || defined(USE_CONFIG_COROUTINE)) && !defined(CONFIG_NETIO_NUM_CONNS) -# define CONFIG_NETIO_NUM_CONNS 8 -#endif -#if defined(USE_CONFIG_NETIO_POSIX) && !defined(_CONFIG_H_NETIO_POSIX_) -#define _CONFIG_H_NETIO_POSIX_ -# define CONFIG_NETIO_NUM_PORTS 1 -#endif +#ifndef _CONFIG_H_ +#define _CONFIG_H_ -#if defined(USE_CONFIG_9P) && !defined(_CONFIG_H_9P_) -#define _CONFIG_H_9P_ -# define CONFIG_9P_PORT 564 - /** - * This max-msg-size is sized so that a Twrite message can return - * 8KiB of data. - * - * This is the same as the default in Plan 9 4e's lib9p; it has the - * comment that "24" is "ample room for Twrite/Rread header - * (iounit)". In fact, the Twrite header is only 23 bytes - * ("size[4] Twrite[1] tag[2] fid[4] offset[8] count[4]") and the - * Rread header is even shorter at 11 bytes ("size[4] Rread[1] - * tag[2] count[4]"), so "24" appears to be the size of the Twrite - * header rounded up to a nice round number. - * - * In older versions of 9P ("9P1"), the max message size was - * defined as part of the protocol specification rather than - * negotiated. In Plan 9 1e it was (8*1024)+128, and was bumped to - * (8*1024)+160 in 2e and 3e. - */ -# define CONFIG_9P_MAX_MSG_SIZE ((4*1024)+24) - /** - * Maximum host-data-structure size. A message may be larger in - * unmarshaled-host-structures than marshaled-net-bytes due to (1) - * struct padding, (2) nul-terminator byes for strings. - */ -# define CONFIG_9P_MAX_HOSTMSG_SIZE CONFIG_9P_MAX_MSG_SIZE+16 -# define CONFIG_9P_MAX_FIDS 16 -#endif -#if (defined(USE_CONFIG_9P) || defined(USE_CONFIG_COROUTINE)) && !defined(CONFIG_9P_MAX_REQS) -# define CONFIG_9P_MAX_REQS 2 -#endif -#if (defined(USE_CONFIG_9P) || defined(_USE_CONFIG_9P_ERR)) && !defined(CONFIG_9P_MAX_ERR_SIZE) -# define CONFIG_9P_MAX_ERR_SIZE 128 /* 128 is what Plan 9 4e uses */ -#endif +#define CONFIG_NETIO_NUM_CONNS 8 -#if defined(USE_CONFIG_COROUTINE) && !defined(_CONFIG_H_COROUTINE_) -#define _CONFIG_H_COROUTINE_ -# define CONFIG_COROUTINE_DEFAULT_STACK_SIZE (32*1024) -# define CONFIG_COROUTINE_MEASURE_STACK 1 /* bool */ -# define CONFIG_COROUTINE_PROTECT_STACK 1 /* bool */ -# define CONFIG_COROUTINE_DEBUG 0 /* bool */ -# define CONFIG_COROUTINE_VALGRIND 1 /* bool */ -# define CONFIG_COROUTINE_NUM (1 /* usb_common */ +\ - 1 /* usb_keyboard */ +\ - CONFIG_NETIO_NUM_CONNS /* accept+read */ +\ - (CONFIG_9P_MAX_REQS*CONFIG_NETIO_NUM_CONNS) /* work+write */ ) -#endif +#define CONFIG_9P_PORT 564 +/** + * This max-msg-size is sized so that a Twrite message can return + * 8KiB of data. + * + * This is the same as the default in Plan 9 4e's lib9p; it has the + * comment that "24" is "ample room for Twrite/Rread header + * (iounit)". In fact, the Twrite header is only 23 bytes + * ("size[4] Twrite[1] tag[2] fid[4] offset[8] count[4]") and the + * Rread header is even shorter at 11 bytes ("size[4] Rread[1] + * tag[2] count[4]"), so "24" appears to be the size of the Twrite + * header rounded up to a nice round number. + * + * In older versions of 9P ("9P1"), the max message size was + * defined as part of the protocol specification rather than + * negotiated. In Plan 9 1e it was (8*1024)+128, and was bumped to + * (8*1024)+160 in 2e and 3e. + */ +#define CONFIG_9P_MAX_MSG_SIZE ((4*1024)+24) +/** + * Maximum host-data-structure size. A message may be larger in + * unmarshaled-host-structures than marshaled-net-bytes due to (1) + * struct padding, (2) nul-terminator byes for strings. + */ +#define CONFIG_9P_MAX_HOSTMSG_SIZE CONFIG_9P_MAX_MSG_SIZE+16 +#define CONFIG_9P_MAX_FIDS 16 +#define CONFIG_9P_MAX_REQS 2 +#define CONFIG_9P_MAX_ERR_SIZE 128 /* 128 is what Plan 9 4e uses */ + +#define CONFIG_COROUTINE_DEFAULT_STACK_SIZE (32*1024) +#define CONFIG_COROUTINE_MEASURE_STACK 1 /* bool */ +#define CONFIG_COROUTINE_PROTECT_STACK 1 /* bool */ +#define CONFIG_COROUTINE_DEBUG 0 /* bool */ +#define CONFIG_COROUTINE_VALGRIND 0 /* bool */ +#define CONFIG_COROUTINE_NUM (1 /* usb_common */ +\ + 1 /* usb_keyboard */ +\ + CONFIG_NETIO_NUM_CONNS /* accept+read */ +\ + (CONFIG_9P_MAX_REQS*CONFIG_NETIO_NUM_CONNS) /* work+write */ ) + +#endif /* _CONFIG_H_ */ diff --git a/cmd/srv9p/config/config.h b/cmd/srv9p/config/config.h index 2edbd7b..ead97e0 120000..100644 --- a/cmd/srv9p/config/config.h +++ b/cmd/srv9p/config/config.h @@ -1 +1,46 @@ -../../sbc_harness/config/config.h
\ No newline at end of file +/* config.h - Compile-time configuration for srv9p + * + * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> + * SPDX-Licence-Identifier: AGPL-3.0-or-later + */ + +#define CONFIG_NETIO_NUM_CONNS 8 + +# define CONFIG_9P_PORT 564 +/** + * This max-msg-size is sized so that a Twrite message can return + * 8KiB of data. + * + * This is the same as the default in Plan 9 4e's lib9p; it has the + * comment that "24" is "ample room for Twrite/Rread header + * (iounit)". In fact, the Twrite header is only 23 bytes + * ("size[4] Twrite[1] tag[2] fid[4] offset[8] count[4]") and the + * Rread header is even shorter at 11 bytes ("size[4] Rread[1] + * tag[2] count[4]"), so "24" appears to be the size of the Twrite + * header rounded up to a nice round number. + * + * In older versions of 9P ("9P1"), the max message size was + * defined as part of the protocol specification rather than + * negotiated. In Plan 9 1e it was (8*1024)+128, and was bumped to + * (8*1024)+160 in 2e and 3e. + */ +#define CONFIG_9P_MAX_MSG_SIZE ((4*1024)+24) +/** + * Maximum host-data-structure size. A message may be larger in + * unmarshaled-host-structures than marshaled-net-bytes due to (1) + * struct padding, (2) nul-terminator byes for strings. + */ +#define CONFIG_9P_MAX_HOSTMSG_SIZE CONFIG_9P_MAX_MSG_SIZE+16 +#define CONFIG_9P_MAX_FIDS 16 +#define CONFIG_9P_MAX_REQS 2 +#define CONFIG_9P_MAX_ERR_SIZE 128 /* 128 is what Plan 9 4e uses */ + +#define CONFIG_COROUTINE_DEFAULT_STACK_SIZE (32*1024) +#define CONFIG_COROUTINE_MEASURE_STACK 1 /* bool */ +#define CONFIG_COROUTINE_PROTECT_STACK 1 /* bool */ +#define CONFIG_COROUTINE_DEBUG 0 /* bool */ +#define CONFIG_COROUTINE_VALGRIND 1 /* bool */ +#define CONFIG_COROUTINE_NUM (1 /* usb_common */ +\ + 1 /* usb_keyboard */ +\ + CONFIG_NETIO_NUM_CONNS /* accept+read */ +\ + (CONFIG_9P_MAX_REQS*CONFIG_NETIO_NUM_CONNS) /* work+write */ ) diff --git a/cmd/srv9p/main.c b/cmd/srv9p/main.c index f62617d..6ed4b79 100644 --- a/cmd/srv9p/main.c +++ b/cmd/srv9p/main.c @@ -7,9 +7,16 @@ #include "static.h" -#define USE_CONFIG_COROUTINE +/* configuration **************************************************************/ + #include "config.h" +#ifndef CONFIG_NETIO_NUM_CONNS +# error config.h must define CONFIG_NETIO_NUM_CONNS +#endif + +/* implementation *************************************************************/ + #define UNUSED(name) /* name __attribute__((unused)) */ static struct static_dir_data root = { diff --git a/lib9p/include/lib9p/9p.h b/lib9p/include/lib9p/9p.h index 66f7542..616a0e1 100644 --- a/lib9p/include/lib9p/9p.h +++ b/lib9p/include/lib9p/9p.h @@ -14,9 +14,16 @@ #include <lib9p/9p.generated.h> #include <lib9p/linux-errno.h> -#define _USE_CONFIG_9P_ERR +/* configuration **************************************************************/ + #include "config.h" +#ifndef CONFIG_9P_MAX_ERR_SIZE +# error config.h must define CONFIG_9P_MAX_ERR_SIZE +#endif + +/******************************************************************************/ + #define LIB9P_NOTAG ((uint16_t)~0U) #define LIB9P_NOFID ((uint32_t)~0U) diff --git a/lib9p/internal.h b/lib9p/internal.h index 36a2647..2b5f8f3 100644 --- a/lib9p/internal.h +++ b/lib9p/internal.h @@ -12,13 +12,29 @@ #include <lib9p/9p.h> -#define USE_CONFIG_9P -#define USE_CONFIG_COROUTINE +/* configuration **************************************************************/ + #include "config.h" + +#ifndef CONFIG_9P_MAX_MSG_SIZE +# error config.h must define CONFIG_9P_MAX_MSG_SIZE +#endif +#ifndef CONFIG_9P_MAX_HOSTMSG_SIZE +# error config.h must define CONFIG_9P_MAX_HOSTMSG_SIZE +#endif +#ifndef CONFIG_9P_MAX_FIDS +# error config.h must define CONFIG_9P_MAX_FIDS +#endif +#ifndef CONFIG_9P_MAX_REQS +# error config.h must define CONFIG_9P_MAX_REQS +#endif +#ifndef CONFIG_9P_MAX_ERR_SIZE +# error config.h must define CONFIG_9P_MAX_ERR_SIZE +#endif + static_assert(CONFIG_9P_MAX_ERR_SIZE <= UINT16_MAX); static_assert(CONFIG_9P_MAX_MSG_SIZE <= CONFIG_9P_MAX_HOSTMSG_SIZE); static_assert(CONFIG_9P_MAX_HOSTMSG_SIZE <= SSIZE_MAX); -static_assert(CONFIG_9P_MAX_ERR_SIZE + CONFIG_9P_MAX_MSG_SIZE + 2*CONFIG_9P_MAX_HOSTMSG_SIZE < CONFIG_COROUTINE_DEFAULT_STACK_SIZE); /* C language *****************************************************************/ diff --git a/libcr/coroutine.c b/libcr/coroutine.c index 1891b61..e01d44c 100644 --- a/libcr/coroutine.c +++ b/libcr/coroutine.c @@ -14,7 +14,6 @@ /* Configuration **************************************************************/ -#define USE_CONFIG_COROUTINE #include "config.h" #ifndef CONFIG_COROUTINE_DEFAULT_STACK_SIZE diff --git a/libnetio/netio_posix.c b/libnetio/netio_posix.c index 62320f2..f3e9fe0 100644 --- a/libnetio/netio_posix.c +++ b/libnetio/netio_posix.c @@ -24,11 +24,16 @@ #include <libnetio/netio.h> -/* common *********************************************************************/ +/* configuration **************************************************************/ -#define USE_CONFIG_NETIO_POSIX #include "config.h" +#ifndef CONFIG_NETIO_NUM_CONNS +# error config.h must define CONFIG_NETIO_NUM_CONNS +#endif + +/* common *********************************************************************/ + #define UNUSED(name) /* name __attribute__ ((unused)) */ static int sig_io = 0; |