rpdfs-progs: ARM64 support and documentation
cover rpdfs-progs: ARM64 support and documentation
A couple of hacks to support ARM64 and some documentation updates.
The ARM64 patches should NOT be merged into main - I just wanted to share them here in case anyone else wanted to use them.
Valerie Aurora (3):
Initial support for ARM64, incompatible with x86_64 Workaround for short read from io_uring on aarch64 Update documentation
Makefile | 9 +++-- docs/development.md | 16 +++------ utask/net.c | 14 ++++++-- utask/utask.c | 17 ++++++++- utask/utask_asm.S | 84 +++++++++++++++++++++++++++++---------------- utask/utask_defs.h | 2 +- 6 files changed, 94 insertions(+), 48 deletions(-)
Signature · 1 line
2.49.0
PATCH 1/3 Initial support for ARM64, incompatible with x86_64
A quick hack to support task switching on ARM64 without any attempt to make it portable or compatible with x86_64. Will come back to it later if there is interest.
--- Makefile | 9 +++-- utask/utask.c | 17 +++++++++- utask/utask_asm.S | 84 ++++++++++++++++++++++++++++++---------------- utask/utask_defs.h | 2 +- 4 files changed, 79 insertions(+), 33 deletions(-)
Makefile +7 -2
@@ -3,7 +3,9 @@ # make every target depend on the makefile .EXTRA_PREREQS:= $(abspath $(lastword $(MAKEFILE_LIST))) -CFLAGS := -I. -O2 -ggdb -Wall -Werror -D_FILE_OFFSET_BITS=64 -msse4.2 -fno-strict-aliasing -fno-omit-frame-pointer +#CFLAGS := -I. -O2 -ggdb -Wall -Werror -D_FILE_OFFSET_BITS=64 -msse4.2 -fno-strict-aliasing -fno-omit-frame-pointer + +CFLAGS := -I. -I/usr/lib64/ -O2 -ggdb -Wall -Werror -D_FILE_OFFSET_BITS=64 -fno-strict-aliasing -fno-omit-frame-pointer # function entrance/exit profiling for uftrace CFLAGS += -pg
@@ -16,6 +18,9 @@ LDFLAGS := -Wl,--gc-sections -lxxhash -luring -luuid -lsystemd # provide dynamic symbol tables for backtrace() LDFLAGS += -rdynamic +# aarch64 needs this to find libraries +LDFLAGS += -L/usr/lib64/ + # build all c files in source directories DIR := cli devd shared shared/lk utask SRC := $(foreach d,$(DIR),$(wildcard $(d)/*.c))
@@ -73,7 +78,7 @@ $(OBJ_S): %.o: %.S utask/utask_defs.h utask/utask_gen_defs.h utask/utask.s: utask/utask.c gcc -I. -S -o ./utask/utask.s ./utask/utask.c -# extract defines from complied asm so we can include it from asm source +# extract defines from compiled asm so we can include it from asm source utask/utask_gen_defs.h: utask/utask.s grep '#define.*\<UTASK_ASM' utask/utask.s > utask/utask_gen_defs.h
utask/utask.c +16 -1
@@ -97,7 +97,7 @@ static struct utask *get_current_utask(void)struct utask *tsk;unsigned long sp; - asm("movq %%rsp, %0 \n\t" + asm("mov %0, sp \n\t" :"=rm" (sp) : : ); tsk = (void *)(round_up (sp,UTASK_STACK_SIZE ) -sizeof (struct utask ));
@@ -405,6 +405,7 @@ int utask_create_name_nowake(char *name, utask_fn_t fn, void *data, struct utaskstruct utask *tsk =NULL ;unsigned long after;void *stack; +void *fp;int ret; ret =posix_memalign (&stack,UTASK_STACK_SIZE ,UTASK_STACK_SIZE );
@@ -439,15 +440,29 @@ int utask_create_name_nowake(char *name, utask_fn_t fn, void *data, struct utaskif (!IS_ALIGNED (after,16 )) tsk->sp -=16 - (after &15 ); +/* for alignment (I think?) */ +push_stack (tsk,NULL ); +/* final null address to terminate backtracing unwinders */ push_stack (tsk,NULL ); +/* first switch_to jumps to _entry */ push_stack (tsk, utask_entry); +/* aarch64 wants the return address and the frame pointer on the stack */ + fp = tsk->sp; +push_stack (tsk, fp); +/* initial zeroed saved registers */ tsk->sp -=UTASK_SAVED_BYTES ;memset (tsk->sp,0 ,UTASK_SAVED_BYTES ); +/* aarch64 - write the frame pointer into the second to last register */ + *(void **)(tsk->sp) = fp; + +/* aarch64 - write the return address into the last register (link register) */ + *(void **)(tsk->sp +sizeof (void *)) = utask_entry; + ret =0 ; out:if (ret <0 )
utask/utask_asm.S +55 -29
128 lines not on this page · raw message
utask/utask_defs.h +1 -1
@@ -11,7 +11,7 @@#define UTASK_STACK_SIZE (8 * 1024)#define UTASK_STACK_BASE_MASK (~(UTASK_STACK_SIZE - 1)) -#define UTASK_SAVED_BYTES (6 * 8) +#define UTASK_SAVED_BYTES (12 * 8)#define UTASK_RET_SCHEDULED 0#define UTASK_RET_FINISHED 1
Signature · 1 line
2.49.0
PATCH 2/3 Workaround for short read from io_uring on aarch64
In reply to Valerie AuroraFor some reason, io_uring returns a short read even with MSG_WAITALL - but on aarch64 and not x86_64. Work around that with an outer loop
--- utask/net.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
utask/net.c +11 -3
@@ -265,11 +265,19 @@ static ssize_t recv_waiter(int fd, void *buf, size_t size, int flags) {struct utask_cqe_waiter waiter;struct io_uring_sqe *sqe; +size_t len =0 ;int ret; - sqe =utask_get_sqe_waiter (&waiter); -io_uring_prep_recv (sqe, fd, buf, size, flags |MSG_WAITALL ); - ret =utask_wait_event_task (waiter.completed); +/* TODO: Figure out why io_uring returns a short read on aarch64 */ +while (len < size) { + sqe =utask_get_sqe_waiter (&waiter); +io_uring_prep_recv (sqe, fd, buf + len, size - len, flags |MSG_WAITALL ); + ret =utask_wait_event_task (waiter.completed); + +if (waiter.res <0 ) +break ; + len += waiter.res; + }/* == 0 when fd is shutdown/disconnected */ BUG_ON (ret ==0 && waiter.res >0 && waiter.res != size);
Signature · 1 line
2.49.0
PATCH 3/3 Update documentation
In reply to Valerie Aurora--- docs/development.md | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)
docs/development.md +4 -12
@@ -25,9 +25,7 @@ Example invocation: In another terminal: ``` - $ ./cli/rpdfs-cli debugfs -d 127.0.0.1:8081 -t /tmp/trace_debugfs - <1> $ mkfs - <1> $ stat + # mount -t rpdfs -o mkfs 127.0.0.1:8081 /mnt ``` ## Code Layout
@@ -43,18 +41,12 @@ This is all the code that's shared by each utility. It's not a proper library in that it doesn't need to remain API compatible with external builds over time. -There's two kinds of shared code. There's code that can run in either -userspace or the kernel (block.c) and shared code that only runs in -userspace (options.c). It'd probably be worth making this distinction -more apparent. - **shared/lk/** -This is for userspace implementations of kernel interfaces. This both +This is for userspace implementations of kernel interfaces. This both lets us use reasonably stand-alone kernel interfaces (list.h) in -userspace as well as share rpdfs code with the kernel module by -providing implementations of more complicated runtime services (RCU hash -tables, work queues). +userspace by providing implementations of more complicated runtime +services (RCU hash tables, work queues). **shared/format-{block,msg,trace}.h**
Signature · 1 line
2.49.0
Re: [PATCH 1/3] Initial support for ARM64, incompatible with x86_64
In reply to Valerie AuroraQuoted 3 lines · Valerie Aurora
A quick hack to support task switching on ARM64 without any attempt to make it portable or compatible with
x86_64. Will come back to it later if there is interest.
Fun! I know of one ponential user that might want to experiment with rpdfs once its up and running and who would be using ARM. Maybe we'll be able to explore this with them when the time comes.
- z
Re: [PATCH 2/3] Workaround for short read from io_uring on aarch64
In reply to Valerie Aurorautask/net.c static ssize_t recv_waiter(int fd, void *buf, size_t size, int flags) · line 271
Quoted 1 line
utask/net.c +1
-0+/* TODO: Figure out why io_uring returns a short read on aarch64 */
That is certainly peculiar. I wouldn't be surprised if we're not using io_uring net correctly. What's there is very minimal.
- z
Re: [PATCH 3/3] Update documentation
In reply to Valerie AuroraQuoted 3 lines · Valerie Aurora
--- docs/development.md | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)
Hmm, can you add a Signed-off-by: so I can merge this? (And maybe clean up that edit of the last paragraph.. it's a little fractured. Don't sweat it though, I was going to take another editing pass on top of these cleanups either way.)
- z