Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port CoreCLR PAL to linux-riscv64 #75749

Closed
am11 opened this issue Sep 16, 2022 · 10 comments
Closed

Port CoreCLR PAL to linux-riscv64 #75749

am11 opened this issue Sep 16, 2022 · 10 comments
Labels
arch-riscv Related to the RISC-V architecture area-PAL-coreclr
Milestone

Comments

@am11
Copy link
Member

am11 commented Sep 16, 2022

The first component in coreclr port is the abstraction layer located at src/coreclr/pal. That enables us to port other components of coreclr such as src/coreclr/vm, src/coreclr/unwinder and ultimately src/coreclr/jit.

We have riscv64 cross-toolchain with prerequisites set up for building the runtime. Some initial strokes to port coreclr are checked into the main branch (cmake configurations, libunwind, a few definitions in pal.h etc.).

Here is a gist for cross compilation:

#!/bin/sh

# on Ubuntu amd64 - with curl, jq and docker installed

tag="$(curl -sSL "https://raw.githubusercontent.com/dotnet/versions/main/build-info/docker/image-info.dotnet-dotnet-buildtools-prereqs-docker-main.json" |\
  jq -r '.repos[] | .images[] | .platforms [] | select(.dockerfile | contains("riscv64")).simpleTags[0]')"

URN="mcr.microsoft.com/dotnet-buildtools/prereqs:$tag"

cd runtime  # current main branch of dotnet/runtime

# Only build coreclr PAL and its tests:
docker run --rm -e ROOTFS_DIR=/crossrootfs/riscv64 -v"$(pwd)":/runtime "$URN" \
  /runtime/src/coreclr/build-runtime.sh -cross -a riscv64 -component paltests

# note: /crossrootfs/riscv64 has Debian sid bootstrap environment with llvm 14 and few other dependencies
# and the host has llvm 15 toolchain, which will be used by cmake for compilation with
# -sysroot=/crossrootfs/riscv64
#
# the relevant code to build this prerequisites docker image are:
#   * https://github.com/dotnet/arcade/blob/2e7521a/eng/common/cross/build-rootfs.sh#L155
#   * https://github.com/dotnet/arcade/blob/2e7521a/eng/common/cross/toolchain.cmake#L64
#   * https://github.com/dotnet/dotnet-buildtools-prereqs-docker/tree/main/src/ubuntu/22.04/cross/riscv64

The missing parts are architecture-specific assembly code under src/coreclr/pal/src/arch/riscv64, src/coreclr/pal/inc/unixasmmacrosriscv64.inc among other things. We added placeholder assembly files with #error TODO-RISCV64​ which can be reviewed and deleted as part of the port.

Once PAL port is completed, we can copy artifacts/bin​ to riscv64 machine (or virtual machine) and run its tests to verify the state of port:

$ artifacts/bin/coreclr/Linux.riscv64.Debug/paltests/runpaltests.sh \
    $(pwd)/artifacts/bin/coreclr/Linux.riscv64.Debug/paltests
@am11 am11 added help wanted [up-for-grabs] Good issue for external contributors area-PAL-coreclr arch-riscv Related to the RISC-V architecture labels Sep 16, 2022
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Sep 16, 2022
@am11 am11 removed the untriaged New issue has not been triaged by the area owner label Sep 16, 2022
@alexrp
Copy link
Contributor

alexrp commented Sep 16, 2022

Once PAL port is completed, we can copy artifacts/bin​ to riscv64 machine (or virtual machine)

For porting of this nature, qemu-riscv64 is your best friend. You can write code on an x86-based Linux system, build with a RISC-V cross toolchain, and then just run the resulting binary with QEMU's user mode emulation. I wrote a bit about this here for Mono a few years back.

@am11
Copy link
Member Author

am11 commented Sep 16, 2022

Yup, I am using debian sid riscv64 virtual machine. They also have good documentation in their wiki: https://wiki.debian.org/RISC-V#Qemu

RISC-V laptops are rumored to be available in coming weeks. :)

@archanox
Copy link

Fantastic work @am11! Looking forward to seeing how far dotnet support on RISC-V goes!

@am11
Copy link
Member Author

am11 commented Sep 17, 2022

I will defer to someone with experience to take the lead. I am new to RISC-V assembly but can lend hand wherever possible. :)

@jkotas
Copy link
Member

jkotas commented Sep 20, 2023

Anything left to do here?

@jkotas jkotas added backlog-cleanup-candidate An inactive issue that has been marked for automated closure. and removed help wanted [up-for-grabs] Good issue for external contributors labels Sep 20, 2023
@ghost
Copy link

ghost commented Sep 20, 2023

Due to lack of recent activity, this issue has been marked as a candidate for backlog cleanup. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process.

This process is part of our issue cleanup automation.

@ghost ghost added the no-recent-activity label Sep 20, 2023
@gbalykov
Copy link
Member

Anything left to do here?

@jkotas I think all is done. I'll share current pal tests status here soon.

@ghost ghost removed no-recent-activity backlog-cleanup-candidate An inactive issue that has been marked for automated closure. labels Sep 20, 2023
@am11
Copy link
Member Author

am11 commented Sep 20, 2023

@gbalykov we can continue at #84834 and close this one?

@gbalykov
Copy link
Member

Current pal tests results on main

1) x64

PAL Test Results:
  Passed: 435
  Failed: 0

2) riscv visionfive2 with HAVE_FUNCTIONAL_PTHREAD_ROBUST_MUTEXES_EXITCODE 1

PAL Test Results:
  Passed: 436
  Failed: 0

3) riscv visionfive2 with HAVE_FUNCTIONAL_PTHREAD_ROBUST_MUTEXES_EXITCODE 0

PAL Test Results:
  Passed: 436
  Failed: 0

So, all is done.

@am11
Copy link
Member Author

am11 commented Sep 21, 2023

Amazing progress! Lets continue monitoring the status of overall runtime tests at #84834. Closing.

@am11 am11 closed this as completed Sep 21, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Oct 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-riscv Related to the RISC-V architecture area-PAL-coreclr
Projects
None yet
Development

No branches or pull requests

6 participants