Skip to content

add riscv64 CPU compatibility#257

Merged
tzcnt merged 1 commit into
tzcnt:mainfrom
Xeonacid:fix-riscv64-cpu-compat
Jun 21, 2026
Merged

add riscv64 CPU compatibility#257
tzcnt merged 1 commit into
tzcnt:mainfrom
Xeonacid:fix-riscv64-cpu-compat

Conversation

@Xeonacid

Copy link
Copy Markdown
Contributor

Add a riscv64 branch that uses the Zihintpause pause instruction when the target enables it, otherwise falls back to a nop that is valid for the baseline ISA.

Read the Linux device-tree timebase-frequency value from procfs or sysfs as the counter frequency, and use rdtime for timestamps so both helpers use the RISC-V time counter units.

Comment thread include/tmc/detail/compat.hpp Outdated
Comment thread include/tmc/detail/compat.hpp Outdated
@Xeonacid Xeonacid force-pushed the fix-riscv64-cpu-compat branch from 82278f0 to 0a9a2bd Compare June 21, 2026 07:13
Add a riscv64 branch that uses the Zihintpause pause instruction when the target enables it, otherwise falls back to a nop that is valid for the baseline ISA.

Read the Linux device-tree timebase-frequency value from procfs or sysfs as the counter frequency, and use rdtime for timestamps so both helpers use the RISC-V time counter units. Keep the stdio include inside the riscv64 Linux branch so the common compatibility header stays slim on other targets. If Linux device-tree data is unavailable, return a 2GHz heuristic fallback based on the SG2042 clock frequency.

Validated by compiling and running a small riscv64 translation unit including tmc/ex_cpu.hpp and tmc/channel.hpp on real riscv64 hardware, where it reported the 50 MHz device-tree timebase. Also validated riscv64 header compilation in the Arch Linux riscv64 chroot and ran the non-Linux fallback preprocessor path, which reported 2GHz.
@Xeonacid Xeonacid force-pushed the fix-riscv64-cpu-compat branch from 0a9a2bd to 8618846 Compare June 21, 2026 07:44
@tzcnt

tzcnt commented Jun 21, 2026

Copy link
Copy Markdown
Owner

Thanks for your contribution!

@tzcnt tzcnt merged commit cf0c6b4 into tzcnt:main Jun 21, 2026
@tzcnt

tzcnt commented Jun 21, 2026

Copy link
Copy Markdown
Owner

@Xeonacid want to do me a favor and run the hwloc_topo example CMake target (source here) on your SG2042 and paste the output back here? I want to make sure that the CPU / cache topology is properly detected.

@Xeonacid

Copy link
Copy Markdown
Contributor Author

@Xeonacid want to do me a favor and run the hwloc_topo example CMake target (source here) on your SG2042 and paste the output back here? I want to make sure that the CPU / cache topology is properly detected.

Sure!

# of NUMA nodes         : 1
# of physical processors: 64
# of logical processors : 64

Hybrid architecture?    : false
# of CPU kinds          : 1
# of PERFORMANCE cores  : 64

# of core groups        : 16
Group 0:
  NUMA index            : 0
  CPU kind              : PERFORMANCE
  SMT level             : 1
  physical core indexes : 0 1 2 3
Group 1:
  NUMA index            : 0
  CPU kind              : PERFORMANCE
  SMT level             : 1
  physical core indexes : 4 5 6 7
Group 2:
  NUMA index            : 0
  CPU kind              : PERFORMANCE
  SMT level             : 1
  physical core indexes : 8 9 10 11
Group 3:
  NUMA index            : 0
  CPU kind              : PERFORMANCE
  SMT level             : 1
  physical core indexes : 12 13 14 15
Group 4:
  NUMA index            : 0
  CPU kind              : PERFORMANCE
  SMT level             : 1
  physical core indexes : 16 17 18 19
Group 5:
  NUMA index            : 0
  CPU kind              : PERFORMANCE
  SMT level             : 1
  physical core indexes : 20 21 22 23
Group 6:
  NUMA index            : 0
  CPU kind              : PERFORMANCE
  SMT level             : 1
  physical core indexes : 24 25 26 27
Group 7:
  NUMA index            : 0
  CPU kind              : PERFORMANCE
  SMT level             : 1
  physical core indexes : 28 29 30 31
Group 8:
  NUMA index            : 0
  CPU kind              : PERFORMANCE
  SMT level             : 1
  physical core indexes : 32 33 34 35
Group 9:
  NUMA index            : 0
  CPU kind              : PERFORMANCE
  SMT level             : 1
  physical core indexes : 36 37 38 39
Group 10:
  NUMA index            : 0
  CPU kind              : PERFORMANCE
  SMT level             : 1
  physical core indexes : 40 41 42 43
Group 11:
  NUMA index            : 0
  CPU kind              : PERFORMANCE
  SMT level             : 1
  physical core indexes : 44 45 46 47
Group 12:
  NUMA index            : 0
  CPU kind              : PERFORMANCE
  SMT level             : 1
  physical core indexes : 48 49 50 51
Group 13:
  NUMA index            : 0
  CPU kind              : PERFORMANCE
  SMT level             : 1
  physical core indexes : 52 53 54 55
Group 14:
  NUMA index            : 0
  CPU kind              : PERFORMANCE
  SMT level             : 1
  physical core indexes : 56 57 58 59
Group 15:
  NUMA index            : 0
  CPU kind              : PERFORMANCE
  SMT level             : 1
  physical core indexes : 60 61 62 63

It seems corrrect. SG2042 has 64 phsyical cores and 1MB * 16Cluster L2 cache, and aligns with the hwloc-info -p output:

depth 0:            1 Machine (type #0)
 depth 1:           1 Package (type #1)
  depth 2:          2 Group0 (type #12)
   depth 3:         4 Group1 (type #12)
    depth 4:        16 L2Cache (type #5)
     depth 5:       64 L1dCache (type #4)
      depth 6:      64 L1iCache (type #9)
       depth 7:     64 Core (type #2)
        depth 8:    64 PU (type #3)

Thanks for your effort in supporting RISC-V!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants