guix/cpu should parse /sys/devices/system/cpu/modalias

  • Open
  • quality assurance status badge
Details
2 participants
  • Efraim Flashner
  • Ludovic Courtès
Owner
unassigned
Submitted by
Efraim Flashner
Severity
normal
E
E
Efraim Flashner wrote on 8 Dec 08:25 +0100
(address . bug-guix@gnu.org)
Z1VKB38Jsaw-RKtG@3900XT
I saw a post by Marcan¹ of Asahi Linux the other day about not parsing
/proc/cpuinfo and remembered that's what we're doing in (guix cpu).

I've included a couple of dumps below and some notes regarding future
implementation:

// My machine
(ins)efraim@3900XT ~$ cat /sys/devices/system/cpu/modalias
cpu:type:x86,ven0002fam0017mod0071:feature:,0000,0001,0002,0003,0004,0005,0006,0007,0008,0009,000B,000C,000D,000E,000F,0010,0011,0013,0017,0018,0019,001A,001C,0020,0021,0022,0023,0024,0025,0026,0027,0028,0029,002B,002C,002D,002E,002F,0030,0031,0034,0036,0037,0038,0039,003A,003B,003D,0064,0068,006E,0070,0074,0075,0076,0078,0079,007A,007C,007D,0080,0081,0083,0089,008C,008D,0093,0094,0095,0096,0097,0099,009A,009B,009C,009D,009E,00C0,00C1,00C3,00C4,00C5,00C6,00C7,00C8,00C9,00CA,00CC,00CD,00D1,00D6,00D7,00D8,00DA,00DC,00DD,00DE,00E2,00E4,00E6,00E8,00EA,00ED,00F0,00F1,00F2,00F3,00F5,00FA,00FB,00FC,010F,0120,0123,0125,0127,0128,012C,012F,0132,0133,0134,0137,0138,013D,0140,0141,0142,0160,0161,0162,0163,0165,016C,016E,016F,0170,0178,017C,01A0,01A1,01A2,01A4,01A6,01A9,01AA,01AC,01AD,01AF,01B2,01B3,01B8,01C2,01E0,01E1,01E2,01E3,01E4,01E5,01E6,01E7,01EA,01EB,01EC,01ED,01EF,01F0,01F1,01F4,0202,0216,0220,0221,0223,0224,0261,0262,0263,0270,0282,029C

// Berlin, aka ci.guix.gnu.org
(ins)efraim@berlin ~$ cat /sys/devices/system/cpu/modalias
cpu:type:x86,ven0002fam0017mod0001:feature:,0000,0001,0002,0003,0004,0005,0006,0007,0008,0009,000B,000C,000D,000E,000F,0010,0011,0013,0017,0018,0019,001A,001C,0020,0021,0022,0023,0024,0025,0026,0027,0028,0029,002B,002C,002D,002E,002F,0030,0031,0034,0036,0037,0038,0039,003A,003B,003D,0064,0068,006E,0070,0074,0075,0078,0079,007A,007B,007C,007D,0080,0081,0083,0089,008C,008D,0093,0094,0096,0097,0099,009A,009B,009C,009D,009E,00C0,00C1,00C2,00C3,00C4,00C5,00C6,00C7,00C8,00C9,00CC,00CD,00D1,00D6,00D7,00D8,00DA,00DC,00DD,00E2,00E8,00EA,00ED,00F1,00F3,00F5,00F8,00FA,00FC,010F,0120,0123,0125,0127,0128,0132,0133,0134,0137,013D,0140,0141,0142,0143,0165,016C,016E,016F,0170,0178,017F,01A0,01A1,01A2,01AC,01C2,01E0,01E1,01E2,01E3,01E4,01E5,01E6,01E7,01EA,01EB,01EC,01ED,01EF,01F0,0220,0221,0223,0224,0261,0262,0263,0282,029C

// pine64, kickstarter addition
(ins)efraim@3900XT ~$ ssh pine64 cat /sys/devices/system/cpu/modalias
cpu:type:aarch64:feature:,0000,0001,0002,0003,0004,0005,0006,0007,000B

// rock64
(ins)efraim@3900XT ~$ ssh rock64 cat /sys/devices/system/cpu/modalias
cpu:type:aarch64:feature:,0000,0001,0002,0003,0004,0005,0006,0007,000B

// raspberry pi 5b
(ins)efraim@3900XT ~$ ssh ubuntu.unicorn-typhon.ts.net cat /sys/devices/system/cpu/modalias
efraim@ubuntu.unicorn-typhon.ts.net: Permission denied (publickey).
(ins)efraim@3900XT ~$ ssh ubuntu@ubuntu.unicorn-typhon.ts.net cat /sys/devices/system/cpu/modalias
cpu:type:aarch64:feature:,0000,0001,0002,0003,0004,0005,0006,0007,0008,0009,000A,000B,000C,000F,0010,0014

// power9 machine from OSU for ci.guix.gnu.org
(ins)efraim@3900XT ~$ ssh guixp9 cat /sys/devices/system/cpu/modalias
cpu:type:power9:feature:,0001,0006,0007,0008,000A,000D,000E,001A,001B,001C,001E,001F,0034,0035,0036,0037,0039,003A,003B,003C,003D,003F

// rpi 1b
(ins)efraim@3900XT ~$ ssh 192.168.68.50 cat /sys/devices/system/cpu/modalias
cpu:type:v6l:feature:,0001,0002,0004,0006,0007,0008,000F

// hifive unmatched, riscv64
(ins)efraim@3900XT ~$ ssh 192.168.68.51 cat /sys/devices/system/cpu/modalias
cat: /sys/devices/system/cpu/modalias: No such file or directory

// macbook 4,1 I think
(ins)efraim@3900XT ~$ ssh israel.unicorn-typhon.ts.net cat /sys/devices/system/cpu/modalias
cpu:type:x86,ven0000fam0006mod0017:feature:,0000,0001,0002,0003,0004,0005,0006,0007,0008,0009,000B,000C,000D,000E,000F,0010,0011,0013,0015,0016,0017,0018,0019,001A,001C,001D,001F,002B,0034,003D,0068,006B,006C,006D,006F,0070,0072,0074,0075,0079,007C,0080,0082,0083,0084,0085,0087,0088,0089,008D,008E,008F,0093,00C0,00EB,00ED,00F3,00FD,00FF,0100,0101,0102,0104,0165,016C,0172,01C0

arch/x86/include/asm/cpufeatures.h
list of CPU features for x86 and x86_64

I haven't been able to find the table for other architectures yet.


--
Efraim Flashner <efraim@flashner.co.il> ????? ?????
GPG key = A28B F40C 3E55 1372 662D 14F7 41AA E7DC CA3D 8351
Confidentiality cannot be guaranteed on emails sent or received unencrypted
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEoov0DD5VE3JmLRT3Qarn3Mo9g1EFAmdVSgMACgkQQarn3Mo9
g1F0DxAAr0NcsqlfxewgCVd0TsOaPOkT5YPAHDVxZU7SRRoUi/G8dWVnYW3njh5a
FGyxfUwKElpDgfz9xUOfP1J/dw3iaktW7Bzd/pY7vL8ZpaIeaft0HzVBLX2dHF3q
lwExnBcDq08S53k6RuJyNr7GvOTw7jfN+Ss7AWOGEOWBOJ6Fa41wmnEdiHth1v5X
PuTlWeeRVWU5WKE/OgNMmuoqSrKXzu6ImOl6S3mjXf4MkEFdd2f2KXv1xiJpuikb
7VdnGeRvxCnqvrDxKaxf+gxhzNLN4uM9ZrjFxRpcFpVx6oighUmavIB+AgmLhi1c
PGGPB0NJRuP7qVHf7/wssQEsVzTjBoHIKmZf15E1T7EVxBoXvnJAwN1x0ZGRqzFK
ODIMoGUpu2/TqU+M37kWOfxkWABwN1ioylRas1duL5L/wwVnN/5JCu04PdHq+K5Z
zxpUiqCIOjNeu2U/Hma3rmAZ3hp3N1kXcrqtPAiYFHE2y7mgnT5vfjnmpeHYsjWM
RCcgpoKThbLHgDACDIPxUfEzKqiZl7tvft5T5W9HRA26AOKleiPTYSry8EmlfH1M
A/ByfX1SWvYPvdqN7Zrzn4tndDU3i3wpnKIXIMBbs7Dlts1TANPQm5vfSy1+OOAc
ywSYg7/Q2jm6OWqPfdgokfs9mQcUs8CJ5GnZS0M60Du7cqjw4cQ=
=zBN/
-----END PGP SIGNATURE-----


L
L
Ludovic Courtès wrote on 9 Dec 18:37 +0100
(name . Efraim Flashner)(address . efraim@flashner.co.il)(address . bug-guix@gnu.org)
87jzc8lpv1.fsf@gnu.org
Hello,

Efraim Flashner <efraim@flashner.co.il> skribis:

Toggle quote (3 lines)
> I saw a post by Marcan¹ of Asahi Linux the other day about not parsing
> /proc/cpuinfo and remembered that's what we're doing in (guix cpu).

I believe it initially mimicked what GCC does for ‘-march=native’, but
it does seem to be less exhaustive than /sys/devices/cpu/modalias.

I wonder if there are version/portability issues with the latter.

Ludo’.
E
E
Efraim Flashner wrote on 10 Dec 09:16 +0100
(name . Ludovic Courtès)(address . ludo@gnu.org)(address . 74731@debbugs.gnu.org)
Z1f47NtnZ1zFZZ0m@3900XT
On Mon, Dec 09, 2024 at 06:37:22PM +0100, Ludovic Courtès wrote:
Toggle quote (12 lines)
> Hello,
>
> Efraim Flashner <efraim@flashner.co.il> skribis:
>
> > I saw a post by Marcan¹ of Asahi Linux the other day about not parsing
> > /proc/cpuinfo and remembered that's what we're doing in (guix cpu).
>
> I believe it initially mimicked what GCC does for ‘-march=native’, but
> it does seem to be less exhaustive than /sys/devices/cpu/modalias.
>
> I wonder if there are version/portability issues with the latter.

I've been thinking more about it over the past few days.

I think ultimately we need to match both parts; the kernel interfaces
with the hardware and knows (or at least should know) exactly what the
hardware can support, and gcc (or the other compilers) need to support
optimizing for those hardware bits specifically.

Also, parsing /proc/cpuinfo is already reading what the kernel says it
supports, except in an incomplete manner.

Starting with x86_64 (and i686), I think we keep GCC's definition of
what each sub-architecture is but parse the modalias file instead of
parsing cpuinfo.

I already have some code to parse modalias and some ideas for just
reusing the math bits from the kernel (it looks like ((11*32)+28) for
zen2) to adjust the if-flags to match the numerical equivalent of the
feature.

For x86_64 the kernel does have a policy of reusing flags if they've
been deprecated and unused long enough, but hopefully that won't be a
problem, even with some of our older LTS kernels.

I think for the start it would make most sense to read modalias in
addition to cpuinfo, sort based on the data in modialis, and then
fallback to cpuinfo if it doesn't match. This helps for architectures
without the modalias file (like riscv64), and I don't know what the Hurd
provides, but I'd be surprised if it had the same modalias file for
parsing.

I'll try to work on it a bit over the coming days.

--
Efraim Flashner <efraim@flashner.co.il> ????? ?????
GPG key = A28B F40C 3E55 1372 662D 14F7 41AA E7DC CA3D 8351
Confidentiality cannot be guaranteed on emails sent or received unencrypted
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEoov0DD5VE3JmLRT3Qarn3Mo9g1EFAmdX+OgACgkQQarn3Mo9
g1G2jRAAnYuWeGCFeYgO+WL1sNmFesRh+LiBqSHxeV4bftENKPBtD0VqR4VX3FtE
hoUdgHl44b0hs8wpK6EW+ISQCMOSNyCooyviEUVA0KM7VAJ3ysuOb4YbbfZ+EYx0
TaCg0xFd+op2tpKzi7M/zmV4LHgmNi4G6ak+W1eLKe/mmj4Sv/BhbsRJy+z6h3Ai
eA79OJYGWoYBZ0YvH0oZkTlUl/Hfp2ovEArLBYvCF6jhujcjgBi9opxG62iscMDV
r5NCGMsW8cDTNhFSeNMgT6hG09CK84/4w1NI+b13lWTcKwwAP1RNntCH8Xp5pR8o
ZVX4jkjdDh4xAmQBj07Cv2BYP+PHaazWUe6QVKMqO5SAnADA5v1KDFaKmkzuy0pu
3AvT77jwgC6LgVaLjgVrlnuyzSyYYB0hVsoW0NFzntU8l/jza+DXBGM+r6aKVUeU
U4xnRYJ3NMhGVcIf2TbtjPfWa11IukptJxRkgrqMqpTLK3vuE4w5PRvVDkIX98I4
PdM/hZW0GQsxscIQCZMiFY1UJurG5WySHZS/GtI5Ec3tofyKJZhtA7eseogM/cwh
pcowalrsjlLWenS69/UuYobfGCwgt6jPNhpRmXIM6LZ1Z728L9Ok3RJc7CCuNuM9
oFRTYcLt7Oh66Y7sm2u35llz37uSclnURBWb8HDVjo69vtHSmdA=
=34Y0
-----END PGP SIGNATURE-----


?
Your comment

Commenting via the web interface is currently disabled.

To comment on this conversation send an email to 74731@debbugs.gnu.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 74731
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch