From: jca Date: Fri, 10 Jun 2022 21:34:15 +0000 (+0000) Subject: Implement CPU_BUSY_CYCLE() with the ZiHintPause extension X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=77bac82635a6a223167e30768154726352f3b2d8;p=openbsd Implement CPU_BUSY_CYCLE() with the ZiHintPause extension This may help save power but also improves performance in contended workloads. kettenis@ helped a lot: - pointing out the error in my newest diff - pointing out that the ZiHintPause had been ratified in early 2021 - testing this on his visionfive board ok kettenis@ libc make -j4 time before 17m39.06s real 22m13.85s user 34m27.88s system 17m35.60s real 22m15.01s user 34m28.51s system 17m40.78s real 22m14.89s user 34m42.91s system 17m40.61s real 22m06.99s user 34m29.58s system 17m42.79s real 22m08.04s user 34m33.19s system 17m39.21s real 22m11.27s user 34m23.18s system 17m32.81s real 22m13.84s user 34m09.67s system libc make -j4 time after 16m35.48s real 21m57.94s user 32m05.50s system 16m49.10s real 21m58.47s user 32m42.37s system 16m42.16s real 22m00.51s user 32m22.18s system 16m41.54s real 21m53.32s user 32m19.53s system 16m45.42s real 21m52.14s user 32m37.78s system 16m46.55s real 21m58.98s user 32m36.70s system --- diff --git a/sys/arch/riscv64/include/cpu.h b/sys/arch/riscv64/include/cpu.h index 20da2ccf689..4c32f35fdff 100644 --- a/sys/arch/riscv64/include/cpu.h +++ b/sys/arch/riscv64/include/cpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.h,v 1.11 2022/01/01 14:18:39 kettenis Exp $ */ +/* $OpenBSD: cpu.h,v 1.12 2022/06/10 21:34:15 jca Exp $ */ /* * Copyright (c) 2019 Mike Larkin @@ -175,7 +175,8 @@ void cpu_startclock(void); #endif /* !MULTIPROCESSOR */ -#define CPU_BUSY_CYCLE() do {} while (0) +/* Zihintpause ratified extension */ +#define CPU_BUSY_CYCLE() __asm volatile(".long 0x0100000f" ::: "memory") #define curpcb curcpu()->ci_curpcb