From 9a18a298c7ff84cf7f93cda1711bcdc44b6c56a0 Mon Sep 17 00:00:00 2001 From: Yaroslav Veremenko Date: Wed, 3 Apr 2024 16:09:19 -0600 Subject: [PATCH] Patched ps that can report used memory --- Kernel/platform/platform-rpipico/Makefile | 2 ++ .../platform/platform-rpipico/update-flash.sh | 2 +- .../platform/platform-rpipico/utils/Makefile | 33 +++++++++++++++++++ .../platform-rpipico/utils/ps-rpipico.patch | 33 +++++++++++++++++++ Kernel/tools/makeversion.c | 19 +++++++++++ 5 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 Kernel/platform/platform-rpipico/utils/Makefile create mode 100644 Kernel/platform/platform-rpipico/utils/ps-rpipico.patch diff --git a/Kernel/platform/platform-rpipico/Makefile b/Kernel/platform/platform-rpipico/Makefile index 8d79785323..d704a20e01 100644 --- a/Kernel/platform/platform-rpipico/Makefile +++ b/Kernel/platform/platform-rpipico/Makefile @@ -31,6 +31,7 @@ clean: $(MAKE) -C ../../../Applications/cave -f Makefile.armm0 clean $(MAKE) -C ../../../Applications/cursesgames -f Makefile.armm0 clean $(MAKE) -C ../../../Standalone clean + $(MAKE) -C utils clean world: build/fuzix.elf $(MAKE) -C ../../../Library/libs -f Makefile.armm0 @@ -42,6 +43,7 @@ world: build/fuzix.elf $(MAKE) -C ../../../Applications/cave -f Makefile.armm0 $(MAKE) -C ../../../Applications/cursesgames -f Makefile.armm0 $(MAKE) -C ../../../Standalone + $(MAKE) -C utils uf2conv: tools/uf2conv.c cc -O -g -o $@ $< diff --git a/Kernel/platform/platform-rpipico/update-flash.sh b/Kernel/platform/platform-rpipico/update-flash.sh index d1107788b9..0afbed61d9 100755 --- a/Kernel/platform/platform-rpipico/update-flash.sh +++ b/Kernel/platform/platform-rpipico/update-flash.sh @@ -145,7 +145,7 @@ bget ../../../Applications/util/pagesize bget ../../../Applications/util/passwd bget ../../../Applications/util/printenv bget ../../../Applications/util/prtroot -bget ../../../Applications/util/ps +bget utils/ps bget ../../../Applications/util/pwd bget ../../../Applications/util/reboot bget ../../../Applications/util/remount diff --git a/Kernel/platform/platform-rpipico/utils/Makefile b/Kernel/platform/platform-rpipico/utils/Makefile new file mode 100644 index 0000000000..ba8f3ca615 --- /dev/null +++ b/Kernel/platform/platform-rpipico/utils/Makefile @@ -0,0 +1,33 @@ +ROOT=../../../.. +FUZIX_ROOT=$(ROOT) +USERCPU=armm0 +VERBOSE=1 +include $(FUZIX_ROOT)/Target/rules.$(USERCPU) + +UTILS = ps.c +UTILSO = $(UTILS:.c=.o) +UTILSBIN = $(UTILS:.c=) + +.PHONY: all clean + +all: $(UTILSBIN) + +clean: + rm -f *.o + rm -f $(UTILSBIN) + rm -f progbase.h + rm -f ps.c + +$(UTILSBIN): %: %.o + $(LINKER) $(CRT0) $^ -o $@ $(LINKER_OPT) $(LINKER_TAIL) + +ps.c: ps-rpipico.patch + cp ../../../../Applications/util/ps.c . + patch ps.c < ps-rpipico.patch + +%.o: %.c progbase.h + $(CC) $(CFLAGS) $(CCOPTS) -c $< + +progbase.h: ../build/fuzix.elf + nm ../build/fuzix.elf | grep progbase | awk '{print "#define PROGBASE 0x" $$1}' > progbase.h + diff --git a/Kernel/platform/platform-rpipico/utils/ps-rpipico.patch b/Kernel/platform/platform-rpipico/utils/ps-rpipico.patch new file mode 100644 index 0000000000..a57ee21128 --- /dev/null +++ b/Kernel/platform/platform-rpipico/utils/ps-rpipico.patch @@ -0,0 +1,33 @@ +--- ../../../../Applications/util/ps.c 2024-02-12 16:06:26.445511000 -0700 ++++ ps.c 2024-03-31 10:58:57.708871714 -0600 +@@ -35,6 +35,7 @@ + #include + #include + #include ++#include "progbase.h" + + #define TTY_MAJOR 2 /* Be nice if we didn't have to + just know this */ +@@ -66,6 +67,9 @@ + #define OF_TIME 8192 /* Cumulative execution time */ + #define OF_CMD 16384 /* Command line */ + ++#define BLOCKSIZE 4096 ++#define alignup(v,a) (uint8_t*)((intptr_t)((v) + (a)-1) & ~((a)-1)) ++ + static const char *month = "JanFebMarAprMayJunJulAugSepOctNovDec"; + + static char mapstat(char s) +@@ -348,7 +352,11 @@ + if (outflags & OF_ADDR) + fputs(" - ", stdout); + if (outflags & OF_SZ) +- fputs(" - ", stdout); ++ { ++ long size = pp->p_top - PROGBASE; ++ size = (long)alignup(size, BLOCKSIZE) / 1024; ++ printf("%5d ", size); ++ } + if (outflags & OF_WCHAN) { + if (pp->p_status > 2) + printf(" %4x ", (unsigned int)pp->p_wait); diff --git a/Kernel/tools/makeversion.c b/Kernel/tools/makeversion.c index 85c4a22ea4..bd2e99aafe 100644 --- a/Kernel/tools/makeversion.c +++ b/Kernel/tools/makeversion.c @@ -2,6 +2,11 @@ #include #include +/* Not sure why utsname.h needs + * I'm keeping it but disable it here */ +#define __TYPES_H +#include "../../Library/include/utsname.h" + void write_body(FILE *out, char *v, char *sv, char *p) { @@ -65,6 +70,15 @@ struct sysinfoblk {\n\ \n", (int)(strlen(v) + strlen(sv) + strlen(p) + 9)); } +void trimstr(char* str, int size) { + while(*str && size--) { + *str++; + } + *str = '\0'; +} + +#define member_size(type, member) (sizeof(((type*)0)->member)) + int main(int argc, char *argv[]) { FILE *f; @@ -77,6 +91,11 @@ int main(int argc, char *argv[]) perror("include/sysinfoblk.h"); exit(1); } + + trimstr(argv[1], member_size(struct utsname, release)); + trimstr(argv[2], member_size(struct utsname, version)); + trimstr(argv[3], member_size(struct utsname, machine)); + write_header(f, argv[1], argv[2], argv[3]); fclose(f); f = fopen("version.c", "w");