Skip to content

Commit

Permalink
Patched ps that can report used memory
Browse files Browse the repository at this point in the history
  • Loading branch information
veremenko-y committed Apr 3, 2024
1 parent 1654d9d commit 9a18a29
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Kernel/platform/platform-rpipico/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 $@ $<
Expand Down
2 changes: 1 addition & 1 deletion Kernel/platform/platform-rpipico/update-flash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 33 additions & 0 deletions Kernel/platform/platform-rpipico/utils/Makefile
Original file line number Diff line number Diff line change
@@ -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

33 changes: 33 additions & 0 deletions Kernel/platform/platform-rpipico/utils/ps-rpipico.patch
Original file line number Diff line number Diff line change
@@ -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 <pwd.h>
#include <fcntl.h>
#include <time.h>
+#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);
19 changes: 19 additions & 0 deletions Kernel/tools/makeversion.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
#include <stdlib.h>
#include <string.h>

/* Not sure why utsname.h needs <types.h>
* 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)
{
Expand Down Expand Up @@ -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;
Expand All @@ -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");
Expand Down

0 comments on commit 9a18a29

Please sign in to comment.