41

The uname(1) command-line utility has a -m option which prints the "machine hardware name".

On Linux, this field comes from the machine member of struct utsname, as populated by the uname(2) system call.

Many other language APIs return this information:

What are the possible values for the "machine" field?

jww
  • 97,681
  • 90
  • 411
  • 885
Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328
  • 2
    Python's `os.uname()` has caused Jack Lloyd a fair amount of trouble in determining the OS and platform when configuring the [Botan library](https://github.com/randombit/botan). Linux and BSDs are OK, but others seem to provide inconsistent results, like MinGW, Cygwin, Solaris, Dragonfly, etc. You might want to have a look at [botan/configure.py](https://github.com/randombit/botan/blob/master/configure.py). If its any consolation, Cmake is even worse. – jww Jul 16 '17 at 12:10
  • @jww I'm curious if this is still true several years later. – Marcel Wilson May 25 '23 at 13:33

1 Answers1

57

Linux

(v4.12 - 2017-July)

Let's refer to the source of the newuname system call.

Tracking this down is complicated by the fact that Linux has UTS namespaces, but the init_uts_ns machine field is initialized by the UTS_MACHINE macro, which is defined per-architecture.

Further complicating matters, machine can be overridden via override_architecture(), if the process is running under a 32-bit "compat" personality, to COMPAT_UTS_MACHINE.

UTS_MACHINE defaults in Makefile to the same thing as ARCH. However, many platforms have separate sub-architectures under the same arch directory, so they set UTS_MACHINE themselves

With the list of directories in arch/ and a little grep-ing of the Linux kernel sources (git grep 'UTS_MACHINE\s*:=' and git grep COMPAT_UTS_MACHINE), we can arrive at this list:

  • alpha
  • arc

  • arm

  • aarch64_be (arm64)
  • aarch64 (arm64)
  • armv8b (arm64 compat)
  • armv8l (arm64 compat)

  • blackfin

  • c6x
  • cris
  • frv
  • h8300
  • hexagon
  • ia64
  • m32r
  • m68k
  • metag
  • microblaze
  • mips (native or compat)
  • mips64 (mips)
  • mn10300
  • nios2
  • openrisc
  • parisc (native or compat)
  • parisc64 (parisc)
  • ppc (powerpc native or compat)
  • ppc64 (powerpc)
  • ppcle (powerpc native or compat)
  • ppc64le (powerpc)
  • s390 (s390x compat)
  • s390x
  • score
  • sh
  • sh64 (sh)
  • sparc (native or compat)
  • sparc64 (sparc)
  • tile
  • unicore32
  • i386 (x86)
  • i686 (x86 compat)
  • x86_64 (x64)
  • xtensa
Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328
  • 8
    .... for the current generation of Linux. There have doubtless been other values in the past, and will doubtless be other values in the future. – Stephen C Jul 16 '17 at 06:21
  • @StephenC Absolutely. In my case, I had a few architectures in mind, and wanted to know how to best detect them. Specifically, I say `if platform.machine().startswith('ppc')`, then it's PowerPC, and `if platform.machine().startswith('arm')` then it's ARM. – Jonathon Reinhart Jul 16 '17 at 06:29
  • Actually, it is better to tabulate this by Linux kernel version than by date. – Stephen C Jul 16 '17 at 09:23
  • 2
    @JonathonReinhart - this is going to get like browser identification strings soon - for example, 'aarch64' is an ARM architecture, but doesn't start with or contain 'arm'. For x86-like CPUs, we have i386, i686 or x86_64 (though my windows install of python returns AMD64). – askvictor May 08 '19 at 00:32
  • 6
    This list is missing `armv7l`, reported f.ex. by Raspberry Pi 4 running in 32-bit mode – cfstras Dec 14 '20 at 10:27
  • 2
    Another list can be found at https://en.wikipedia.org/wiki/Uname – cfstras Dec 14 '20 at 10:27
  • That's a +40 well deserved. – djvg Feb 17 '22 at 13:46
  • Yes, missing `armv7l`, running on Raspberry Pi 3B+ as default. – Danijel Mar 30 '22 at 16:14