diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-03-07 23:44:25 -0700 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-03-09 03:09:22 -0600 |
commit | ddb67e1d0c133cbb59ee3708edf3a2c1feefeec6 (patch) | |
tree | b89b5953fb0cb5ca6f10fa544fd0404fa1b18ff2 /build-aux | |
parent | 638317a18ce4562440fc3fba95c1cb9f33b5affa (diff) |
stack.c.gen: APP: Include a thread total and a kernel size
Diffstat (limited to 'build-aux')
-rwxr-xr-x | build-aux/stack.c.gen | 66 |
1 files changed, 52 insertions, 14 deletions
diff --git a/build-aux/stack.c.gen b/build-aux/stack.c.gen index 11c5854..d9d128a 100755 --- a/build-aux/stack.c.gen +++ b/build-aux/stack.c.gen @@ -1469,24 +1469,62 @@ def main( print_group("Threads") print_group("Interrupt handlers") print("*/") - overhead = max(v.nstatic for v in result.groups["Interrupt handlers"].rows.values()) + intrstack = max( + v.nstatic for v in result.groups["Interrupt handlers"].rows.values() + ) stack_guard_size = 16 * 2 - rows: list[tuple[str, int, int]] = [] + + class CrRow(typing.NamedTuple): + name: str + cnt: int + base: int + size: int + + rows: list[CrRow] = [] + main: CrRow | None = None for funcname, val in result.groups["Threads"].rows.items(): + name = str(funcname.base()) base = val.nstatic - size = next_power_of_2(base + overhead + stack_guard_size) - stack_guard_size - rows.append((str(funcname.base()), base, size)) - namelen = max(len(r[0]) for r in rows) - baselen = max(len(str(r[1])) for r in rows) - sizelen = max(len(str(r[2])) for r in rows) + size = base + intrstack + if name in ("main", "_reset_handler"): + main = CrRow(name=name, cnt=1, base=base, size=size) + else: + size = next_power_of_2(size + stack_guard_size) - stack_guard_size + rows.append(CrRow(name=name, cnt=val.cnt, base=base, size=size)) + namelen = max(len(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, main.size if main else 0))) + + def print_row(comment: bool, name: str, size: int, eqn: str | None = None) -> None: + prefix = "const size_t CONFIG_COROUTINE_STACK_SIZE_" + if comment: + print(f"/* {name}".ljust(len(prefix) + namelen), end="") + else: + print(f"{prefix}{name.ljust(namelen)}", end="") + print(f" = {str(size).rjust(sizelen)};", end="") + if comment: + print(" */", end="") + elif eqn: + print(" ", end="") + if eqn: + print(f" /* {eqn} */", end="") + print() + for row in sorted(rows): - if row[0] in ("main", "_reset_handler"): - continue - print("const size_t CONFIG_COROUTINE_STACK_SIZE_", end="") - print(f"{row[0].ljust(namelen)} =", end="") - print(f" {str(row[2]).rjust(sizelen)};", end="") - print( - f" /* LM_NEXT_POWER_OF_2({str(row[1]).rjust(baselen)}+{overhead}+{stack_guard_size})-{stack_guard_size} */" + print_row( + False, + row.name, + row.size, + f"LM_NEXT_POWER_OF_2({str(row.base).rjust(baselen)}+{intrstack}+{stack_guard_size})-{stack_guard_size}", + ) + print_row(True, "TOTAL (inc. stack guard)", sizesum) + if main: + print_row( + True, + "MAIN/KERNEL", + main.size, + f" {str(main.base).rjust(baselen)}+{intrstack}", ) print() print("/*") |