Skip to content

[RISC-V] Read isa line in /proc/cpuinfo when hwprobe not available #114958

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

Closed
wants to merge 1 commit into from

Conversation

fuad1502
Copy link
Contributor

hwprobe was introduced in Linux kernel version 6.4 https://www.kernel.org/doc/html/v6.4/riscv/hwprobe.html (although on version 6.5, it only started supporting Zba, Zbb, and Zbs detection)

isa line in /proc/cpuinfo is available from Linux kernel version 6.3 upwards https://www.kernel.org/doc/html/v6.3/riscv/uabi.html (CMIIW)

hwprobe also exports less extensions than /proc/cpuinfo when first introduced. Should we prioritize /proc/cpuinfo on kernel version 6.11 and lower (on version 6.11, the extension supported in hwprobe looks complete https://www.kernel.org/doc/html/v6.11/arch/riscv/hwprobe.html)?

TODO:

  • Study further on hwprobe and /proc/cpuinfo isa line support on Linux.

Part of #84834, cc @dotnet/samsung

@ghost ghost added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Apr 23, 2025
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Apr 23, 2025
@risc-vv
Copy link

risc-vv commented Apr 23, 2025

RISC-V Release-CLR-VF2: 9702 / 9750 (99.51%)

=======================
      passed: 9702
      failed: 28
     skipped: 70
      killed: 20
------------------------
  TOTAL libs: 9820
 TOTAL tests: 9820
   REAL time: 1h 59min 38s 839ms
=======================

Release-CLR-VF2.md, Release-CLR-VF2.xml, testclr_output.tar.gz

Build information and commands

GIT: 5c23311a4c98fb62130781025f5aafc02c34fe41
CI: 2d916d20de463f9bba05ae71b3d1f37d439a8cb1
REPO: fuad1502/runtime
BRANCH: riscv-ext-cpuinfo
CONFIG: Release
LIB_CONFIG: Release

RISC-V Release-CLR-QEMU: 9701 / 9750 (99.50%)

=======================
      passed: 9701
      failed: 29
     skipped: 70
      killed: 20
------------------------
  TOTAL libs: 9820
 TOTAL tests: 9820
   REAL time: 3h 28min 15s 56ms
=======================

Release-CLR-QEMU.md, Release-CLR-QEMU.xml, testclr_output.tar.gz

Build information and commands

GIT: 5c23311a4c98fb62130781025f5aafc02c34fe41
CI: 2d916d20de463f9bba05ae71b3d1f37d439a8cb1
REPO: fuad1502/runtime
BRANCH: riscv-ext-cpuinfo
CONFIG: Release
LIB_CONFIG: Release

RISC-V Release-FX-QEMU: 706582 / 721531 (97.93%)

=======================
      passed: 706582
      failed: 1623
     skipped: 1537
      killed: 13326
------------------------
  TOTAL libs: 259
 TOTAL tests: 723068
   REAL time: 2h 28min 12s 448ms
=======================

Release-FX-QEMU.md, Release-FX-QEMU.xml, testfx_output.tar.gz

Build information and commands

GIT: 5c23311a4c98fb62130781025f5aafc02c34fe41
CI: 2d916d20de463f9bba05ae71b3d1f37d439a8cb1
REPO: fuad1502/runtime
BRANCH: riscv-ext-cpuinfo
CONFIG: Release
LIB_CONFIG: Release

size_t n = 0;
char* buf = NULL;

assert(cpuInfo != NULL);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linux procfs is considered optional for number of reasons.

Suggested change
assert(cpuInfo != NULL);
if (cpuInfo == NULL) return result;

(or wrap the handling under != NULL)

@am11
Copy link
Member

am11 commented Apr 23, 2025

hwprobe was introduced in Linux kernel version 6.4 kernel.org/doc/html/v6.4/riscv/hwprobe.html (although on version 6.5, it only started supporting Zba, Zbb, and Zbs detection)

Have we decided what is the .NET baseline kernel version for riscv64? If it is higher than 6.5 for other reasons, we can ignore the #else branch. https://lf-rise.atlassian.net/wiki/spaces/HOME/pages/8587962/RVA23+Profile

@am11 am11 added area-PAL-coreclr arch-riscv Related to the RISC-V architecture and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Apr 23, 2025
@fuad1502
Copy link
Contributor Author

Have we decided what is the .NET baseline kernel version for riscv64? If it is higher than 6.5 for other reasons, we can ignore the #else branch. https://lf-rise.atlassian.net/wiki/spaces/HOME/pages/8587962/RVA23+Profile

Hmm not sure, but you're right. And thanks for the reference BTW 👍

So actually, I added this detection through /proc/cpuinfo since the extensions are not detected on a platform I am testing on, despite the extensions are clearly available (exists in /proc/cpuinfo and run fine if I force the flag). But it turns out it's running kernel 6.6, so it should be fine. So, there might be some other issue that I'm not aware of.

I'll investigate further and closing this PR for now. I'll reopen it if it's clearly needed.

Thank you for your time reviewing it! 🙏 @am11

@fuad1502 fuad1502 closed this Apr 23, 2025
@am11
Copy link
Member

am11 commented Apr 23, 2025

@fuad1502, I am also on the same kernel and getting:

$ neofetch
        #####           am11@k1 
       #######          ------- 
       ##O#O##          OS: Bianbu 2.1 riscv64 
       #######          Host: M1-MUSE-BOOK 
     ###########        Kernel: 6.6.63 
    #############       Uptime: 4 days, 1 hour, 13 mins 
   ###############      Packages: 2325 (dpkg) 
   ################     Shell: bash 5.2.21 
  #################     Resolution: 1920x1080 
#####################   Terminal: /dev/pts/1 
#####################   CPU: Spacemit X60 (8) @ 1.600GHz 
  #################     Memory: 723MiB / 15904MiB 

$ cc -xc - <<EOF
#include <stdio.h>
#include <assert.h>
#include <asm/hwprobe.h>
#include <asm/unistd.h>
#include <unistd.h>

enum RiscV64IntrinsicConstants
{
    RiscV64IntrinsicConstants_Zba = 0x0001,
    RiscV64IntrinsicConstants_Zbb = 0x0002,
};

int main(void){
int result;
    struct riscv_hwprobe pairs[1] = {{RISCV_HWPROBE_KEY_IMA_EXT_0, 0}};

    if (syscall(__NR_riscv_hwprobe, pairs, 1, 0, NULL, 0) == 0)
    {
        // Our baseline support is for RV64GC (see #73437)
        assert(pairs[0].value & RISCV_HWPROBE_IMA_FD);
        assert(pairs[0].value & RISCV_HWPROBE_IMA_C);

        if (pairs[0].value & RISCV_HWPROBE_EXT_ZBA)
        {
            result |= RiscV64IntrinsicConstants_Zba;
        }

        if (pairs[0].value & RISCV_HWPROBE_EXT_ZBB)
        {
            result |= RiscV64IntrinsicConstants_Zbb;
        }
    }

    printf("result: %d\n", result);
    return 0;
}
EOF


$ ./a.out
result: 3

Please double check the build logs; cmake logs should be showing lines like:

  -- Looking for include files windows.h, bcrypt.h - not found
  -- Looking for include file asm/hwprobe.h
  -- Looking for include file asm/hwprobe.h - found
  -- Looking for arc4random_buf

https://github.com/am11/CrossRepoCITesting/actions/runs/14564508979/job/40851797145

@fuad1502
Copy link
Contributor Author

fuad1502 commented Apr 24, 2025

Thanks for looking into it! I found that the issue was indeed with our internal build, it turns out we're compiling with Linux 5.4 kernel headers 😅

I think we can safely assume hwprobe is available here for now 👍

@github-actions github-actions bot locked and limited conversation to collaborators May 24, 2025
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 community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants