Page MenuHomeFreeBSD

x86: Add zen identifier helper function
ClosedPublic

Authored by aokblast on Thu, Apr 9, 1:30 PM.
Tags
None
Referenced Files
F152552159: D56330.diff
Wed, Apr 15, 3:38 PM
F152502130: D56330.diff
Wed, Apr 15, 9:03 AM
Unknown Object (File)
Tue, Apr 14, 7:35 PM
Unknown Object (File)
Tue, Apr 14, 12:53 PM
Unknown Object (File)
Tue, Apr 14, 12:53 PM
Unknown Object (File)
Mon, Apr 13, 9:01 PM
Unknown Object (File)
Mon, Apr 13, 9:00 PM
Unknown Object (File)
Sat, Apr 11, 5:42 PM

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 72101
Build 68984: arc lint + arc unit

Event Timeline

sys/x86/include/x86_var.h
135

Will fix it before commit

sys/x86/x86/identcpu.c
2729

Can this be a table of {family, model_min, model_max} ?

Use structure instead of ifdef.

sys/x86/include/specialreg.h
307

The constants are not from CPUID. Pleae use some different namespace for them. I think just CPU_AMD_ZENx is fine.

Also, specialreg.h is for the hardware registers definitions. Better to place them in some other place, might be machine/cpu.h.
Then it seems logical to move the function prototype there, as well.

sys/x86/x86/identcpu.c
2729

This requires the table to be sorted. At least, a comment is needed in the table herald.

Can we scan the whole table?

This was also a requirement for https://reviews.freebsd.org/D56332 and should be useless now. However, amdtemp driver now hardcode this zen detection logic in the amdtemp.c file, we can use ident_zen_cpu to refactor the amdtemp code.

sys/x86/include/specialreg.h
307

machine/cpu.h has i386 and amd64 variant. Can we put in x86/cputypes.h?

sys/x86/include/specialreg.h
307

Yes, and it looks even more appropriate than what I proposed.

Loop the whole array and put the macro to other file

sys/x86/include/x86_var.h
135

I still suggest to move the prototype to cputypes.h, perhaps under #ifdef _KERNEL.

This revision is now accepted and ready to land.Fri, Apr 10, 12:50 PM
sys/x86/include/cputypes.h
54 ↗(On Diff #175221)

Emm, It breaks again. I will fix it before merging.

This revision was automatically updated to reflect the committed changes.

As reported by https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=294468, cputypes.h is used in ASM code on i386 build so we cannot put the function declaration inside cputypes.h. machine/cpu.h also has this issue. @kib, is there any place you think that we can put?

This comment was removed by aokblast.

As reported by https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=294468, cputypes.h is used in ASM code on i386 build so we cannot put the function declaration inside cputypes.h. machine/cpu.h also has this issue. @kib, is there any place you think that we can put?

Put #ifndef _LOCORE around the proto.

Put #ifndef _LOCORE around the proto.

With _LOCORE I had the same build error. I was able to proceed by using LOCORE instead.

diff --git a/sys/x86/include/cputypes.h b/sys/x86/include/cputypes.h
index ed26304a89ac..0b6f0f3746a9 100644
--- a/sys/x86/include/cputypes.h
+++ b/sys/x86/include/cputypes.h
@@ -54,7 +54,9 @@
 #define CPU_AMD_UNKNOWN                0xffffffff
 
 #ifdef _KERNEL
+#ifndef LOCORE
 u_int  ident_zen_cpu(void);
 #endif
+#endif
 
 #endif /* !_X86_CPUTYPES_H_ */
--------------------------------------------------------------
>>> Kernel build for GENERIC completed on Mon Apr 13 16:27:27 UTC 2026
--------------------------------------------------------------
>>> Kernel(s)  GENERIC built in 144 seconds, ncpu: 32, make -j32
--------------------------------------------------------------

Put #ifndef _LOCORE around the proto.

With _LOCORE I had the same build error. I was able to proceed by using LOCORE instead.

diff --git a/sys/x86/include/cputypes.h b/sys/x86/include/cputypes.h
index ed26304a89ac..0b6f0f3746a9 100644
--- a/sys/x86/include/cputypes.h
+++ b/sys/x86/include/cputypes.h
@@ -54,7 +54,9 @@
 #define CPU_AMD_UNKNOWN                0xffffffff
 
 #ifdef _KERNEL
+#ifndef LOCORE
 u_int  ident_zen_cpu(void);
 #endif
+#endif
 
 #endif /* !_X86_CPUTYPES_H_ */
--------------------------------------------------------------
>>> Kernel build for GENERIC completed on Mon Apr 13 16:27:27 UTC 2026
--------------------------------------------------------------
>>> Kernel(s)  GENERIC built in 144 seconds, ncpu: 32, make -j32
--------------------------------------------------------------

Thanks:). I can commit this right now.