It can otherwise be quite awkward to get at this --- riscv64 puts it all neatly in the ELF auxv, x86-64 has it all in /proc, arm64 only exposes L1 instruction/data line sizes.
Annoyingly, none of musl, the BSDs, or Apple implement these sysconf() queries. But they're useful (and otherwise inaccessible from the command line) for the systems that _do_ support them. --- toys/posix/getconf.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
From a54e826e1697b3868d0a922e96b6e86926623907 Mon Sep 17 00:00:00 2001 From: Elliott Hughes <[email protected]> Date: Wed, 25 Oct 2023 15:59:37 -0700 Subject: [PATCH] getconf: add cache size sysconf() queries. It can otherwise be quite awkward to get at this --- riscv64 puts it all neatly in the ELF auxv, x86-64 has it all in /proc, arm64 only exposes L1 instruction/data line sizes. Annoyingly, none of musl, the BSDs, or Apple implement these sysconf() queries. But they're useful (and otherwise inaccessible from the command line) for the systems that _do_ support them. --- toys/posix/getconf.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/toys/posix/getconf.c b/toys/posix/getconf.c index a8017b29..05833e2a 100644 --- a/toys/posix/getconf.c +++ b/toys/posix/getconf.c @@ -45,6 +45,24 @@ config GETCONF #define _SC_V7_LPBIG_OFFBIG -1 #define _CS_V7_ENV -1 #endif +// macOS and musl both don't have any of these; same argument as above. +#ifndef _SC_LEVEL1_ICACHE_SIZE +#define _SC_LEVEL1_ICACHE_SIZE -1 +#define _SC_LEVEL1_ICACHE_ASSOC -1 +#define _SC_LEVEL1_ICACHE_LINESIZE -1 +#define _SC_LEVEL1_DCACHE_SIZE -1 +#define _SC_LEVEL1_DCACHE_ASSOC -1 +#define _SC_LEVEL1_DCACHE_LINESIZE -1 +#define _SC_LEVEL2_CACHE_SIZE -1 +#define _SC_LEVEL2_CACHE_ASSOC -1 +#define _SC_LEVEL2_CACHE_LINESIZE -1 +#define _SC_LEVEL3_CACHE_SIZE -1 +#define _SC_LEVEL3_CACHE_ASSOC -1 +#define _SC_LEVEL3_CACHE_LINESIZE -1 +#define _SC_LEVEL4_CACHE_SIZE -1 +#define _SC_LEVEL4_CACHE_ASSOC -1 +#define _SC_LEVEL4_CACHE_LINESIZE -1 +#endif struct config { char *name; @@ -105,6 +123,14 @@ static struct config sysconfs[] = { CONF(STREAM_MAX), CONF(SYMLOOP_MAX), CONF(TIMER_MAX), CONF(TTY_NAME_MAX), CONF(TZNAME_MAX), CONF(UIO_MAXIOV), + /* bionic and glibc have these; macOS and musl don't. */ + CONF(LEVEL1_ICACHE_SIZE), CONF(LEVEL1_ICACHE_ASSOC), + CONF(LEVEL1_ICACHE_LINESIZE), CONF(LEVEL1_DCACHE_SIZE), + CONF(LEVEL1_DCACHE_ASSOC), CONF(LEVEL1_DCACHE_LINESIZE), + CONF(LEVEL2_CACHE_SIZE),CONF(LEVEL2_CACHE_ASSOC),CONF(LEVEL2_CACHE_LINESIZE), + CONF(LEVEL3_CACHE_SIZE),CONF(LEVEL3_CACHE_ASSOC),CONF(LEVEL3_CACHE_LINESIZE), + CONF(LEVEL4_CACHE_SIZE),CONF(LEVEL4_CACHE_ASSOC),CONF(LEVEL4_CACHE_LINESIZE), + /* Names that just don't match the symbol, do it by hand */ {"_AVPHYS_PAGES", _SC_AVPHYS_PAGES}, {"_PHYS_PAGES", _SC_PHYS_PAGES}, {"_NPROCESSORS_CONF", _SC_NPROCESSORS_CONF}, -- 2.42.0.758.gaed0368e0e-goog
_______________________________________________ Toybox mailing list [email protected] http://lists.landley.net/listinfo.cgi/toybox-landley.net
