summaryrefslogtreecommitdiff
path: root/build-aux/measurestack
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2025-06-27 08:58:41 -0600
committerLuke T. Shumaker <lukeshu@lukeshu.com>2025-06-27 08:58:41 -0600
commit5a16ac6589817d20749103f45c8d3b4f1eccf784 (patch)
tree59148ec2255d14c184c7920baaae9766dc2c5ade /build-aux/measurestack
parent90f0c59f227b92a046f296865763dc77351782ed (diff)
parent112b4940c76e22606033acf437b00ad3edbd3c9c (diff)
Merge branch 'lukeshu/stack-sizes'HEADmain
Diffstat (limited to 'build-aux/measurestack')
-rw-r--r--build-aux/measurestack/app_output.py44
1 files changed, 31 insertions, 13 deletions
diff --git a/build-aux/measurestack/app_output.py b/build-aux/measurestack/app_output.py
index 7f14f9c..5cf7d17 100644
--- a/build-aux/measurestack/app_output.py
+++ b/build-aux/measurestack/app_output.py
@@ -51,14 +51,14 @@ def print_group(
print(sep1)
-def next_power_of_2(x: int) -> int:
- return 1 << (x.bit_length())
+def lm_round_up(n: int, d: int) -> int:
+ return ((n + d - 1) // d) * d
def print_c(
result: analyze.AnalyzeResult, location_xform: typing.Callable[[QName], str]
) -> None:
- print("#include <stddef.h> /* for size_t */")
+ print('#include "config.h" /* for COROUTINE_STACK_* extern declarations */')
print()
print("/*")
print_group(result, location_xform, "Threads")
@@ -75,6 +75,9 @@ def print_c(
base: int
size: int
+ print("[[gnu::aligned]] void _bogus_aligned_fn(void) {};")
+ print("#define STACK_ALIGNED [[gnu::aligned(__alignof__(_bogus_aligned_fn))]]")
+
rows: list[CrRow] = []
mainrow: CrRow | None = None
for funcname, val in result.groups["Threads"].rows.items():
@@ -84,20 +87,20 @@ def print_c(
if name in ["main", "_entry_point"]:
mainrow = CrRow(name=name, cnt=1, base=base, size=size)
else:
- size = next_power_of_2(size + stack_guard_size) - stack_guard_size
+ size = lm_round_up(size + stack_guard_size, 512)
rows.append(CrRow(name=name, cnt=val.cnt, base=base, size=size))
- namelen = max(len(r.name) for r in rows)
+ namelen = max(len(f"{r.name}{r.cnt}" if r.cnt > 1 else r.name) for r in rows)
baselen = max(len(str(r.base)) for r in rows)
sizesum = sum(r.cnt * (r.size + stack_guard_size) for r in rows)
sizelen = len(str(max(sizesum, mainrow.size if mainrow else 0)))
def print_row(comment: bool, name: str, size: int, eqn: str | None = None) -> None:
- prefix = "const size_t CONFIG_COROUTINE_STACK_SIZE_"
+ prefix = "STACK_ALIGNED char COROUTINE_STACK_"
if comment:
print(f"/* {name}".ljust(len(prefix) + namelen), end="")
else:
print(f"{prefix}{name:<{namelen}}", end="")
- print(f" = {size:>{sizelen}};", end="")
+ print(f"[{size:>{sizelen}}];", end="")
if comment:
print(" */", end="")
elif eqn:
@@ -107,13 +110,15 @@ def print_c(
print()
for row in sorted(rows):
- print_row(
- False,
- row.name,
- row.size,
- f"LM_NEXT_POWER_OF_2({row.base:>{baselen}}+{intrstack}+{stack_guard_size})-{stack_guard_size}",
+ comment = (
+ f"LM_ROUND_UP({row.base:>{baselen}}+{intrstack}+{stack_guard_size}, 512)"
)
- print_row(True, "TOTAL (inc. stack guard)", sizesum)
+ if row.cnt > 1:
+ for i in range(row.cnt):
+ print_row(False, f"{row.name}{i}", row.size, comment)
+ else:
+ print_row(False, row.name, row.size, comment)
+ print_row(True, "TOTAL", sizesum)
if mainrow:
print_row(
True,
@@ -122,6 +127,19 @@ def print_c(
f" {mainrow.base:>{baselen}}+{intrstack}",
)
print()
+ for row in sorted(rows):
+ name = row.name
+ if row.cnt > 1:
+ name += "0"
+ print(f"char *const COROUTINE_STACK_{row.name}[{row.cnt}] = {{")
+ for i in range(row.cnt):
+ print(f"\tCOROUTINE_STACK_{row.name}{i},")
+ print("};")
+ print(
+ f"const size_t COROUTINE_STACK_{row.name}_len = sizeof(COROUTINE_STACK_{name});"
+ )
+
+ print()
print("/*")
print_group(result, location_xform, "Misc")