How to find the processor / chip architecture on Linux - linux

What command should I use to find the processor / chip architecture on Linux?
linux-x86-32
linux-x86-64
linux-ppc-64

To display kernel architecture: uname -p
To display extended CPU details: cat /proc/cpuinfo

In the terminal, type
lscpu
which returns output like this:
Architecture: i686
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 2
On-line CPU(s) list: 0,1
Thread(s) per core: 1
Core(s) per socket: 2
Socket(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 23
Stepping: 6
CPU MHz: 2670.000
BogoMIPS: 5320.13
L1d cache: 32K
L1i cache: 32K
L2 cache: 3072K
To only get the architecture:
lscpu | grep Architecture
Which in this case is
Architecture: i686
See man lscpu for more.

I'm surprised no one suggested uname -m. On my laptop, this gives armv7l, while uname -a gives me a monstrous two lines of text.

see (man uname):
echo `uname -s`-`uname -p`

A concise command producing information about the current machine is hostnamectl. Example output:
Static hostname: xxxx
Icon name: computer-laptop
Chassis: laptop
Boot ID: b3a1f952c514411c8c4xxxxxxxxxxxx
Operating System: Ubuntu 14.04.3 LTS
Kernel: Linux 3.19.0-43-generic
Architecture: x86_64
It gives you the most basic information about your machine. Other commands like uname, lsb_release, or lscpu return more specific information.

Related

Different uname -a output

I am looking for different output of the uname -a command.
The one that I have is
Linux dogeserv.net 5.4.0-89-generic #100-Ubuntu SMP Fri Sep 24 14:50:10 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
I am looking for different outputs of Processor (other then x86_64 and aarch64), OS , -m output.
As per the time i am writing the answer, these options are available in uname command.
-a, --all print all information, in the following order, except omit -p and -i if unknown:
-s, --kernel-name print the kernel name
-n, --nodename print the network node hostname
-r, --kernel-release print the kernel release
-v, --kernel-version print the kernel version
-m, --machine print the machine hardware name
-p, --processor print the processor type (non-portable)
-i, --hardware-platform print the hardware platform (non-portable)
-o, --operating-system print the operating system
For some reason, it's not showing my processor, but you can use uname -p for processor information.
Incase you want detailed information about your processor, you can use cat /proc/cpuinfo, and this will show you information about the processor of your computer with information of every single core and this is what your output should look like
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 142
model name : Intel(R) Core(TM) i3-8130U CPU # 2.20GHz
stepping : 10
microcode : 0xea
cpu MHz : 1279.215
cache size : 4096 KB
physical id : 0
siblings : 4
core id : 0
cpu cores : 2
.....
TO be more specific you can use these commands for their respective outputs
cat /proc/cpuinfo | grep 'vendor' | uniq #view vendor name
cat /proc/cpuinfo | grep 'model name' | uniq #display model name
cat /proc/cpuinfo | grep processor | wc -l #count the number of processing units
cat /proc/cpuinfo | grep 'core id' #show individual cores
A alternative to cat /proc/cpuinfo is lscpu, it will also give you information about your processor, but it will be more about the whole processor instead of every single core.
this is what output should look like:
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Address sizes: 39 bits physical, 48 bits virtual
Byte Order: Little Endian
CPU(s): 4
On-line CPU(s) list: 0-3
Vendor ID: GenuineIntel
BIOS Vendor ID: Intel(R) Corporation
Model name: Intel(R) Core(TM) i3-8130U CPU # 2.20GHz
BIOS Model name: Intel(R) Core(TM) i3-8130U CPU # 2.20GHz
CPU family: 6
Model: 142
Thread(s) per core: 2
Core(s) per socket: 2
.....
Lastly stackoverflow is for mostly programming related questions, you can see all the sites Stack Exchange offers for different type of questions to be asked by clicking this Link

linux irq affinity set cannot take effctive

when i set irq for my Ethernet cannot be effective. (irq from 99-119)
$ sudo cat /proc/irq/109/smp_affinity
00,00000400
$ sudo sh -c "echo 0 > /proc/irq/109/smp_affinity"
$ sudo cat /proc/irq/109/smp_affinity
00,00000400
i want to set all ethernet irq to bind with cpu0. but no lucky for me to set it. i am not sure what kind of problems i met.
and i noticed affinity_hint has following value, and i cannot set it anyway.
$sudo cat /proc/irq/109/affinity_hint
00,00000400
$ sudo sh -c "echo 0 > /proc/irq/109/affinity_hint"
sh: line 0: echo: write error: Input/output error
this system i have 2 cpus with 6 cores. and enable hyper thread. totally has 24 cpu cores.
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 40
On-line CPU(s) list: 0-39
Thread(s) per core: 2
Core(s) per socket: 10
Socket(s): 2
NUMA node(s): 2
Vendor ID: GenuineIntel
CPU family: 6
Model: 62
Model name: Intel(R) Xeon(R) CPU E5-2660 v2 # 2.20GHz
Stepping: 4
CPU MHz: 1201.921
BogoMIPS: 4404.51
Virtualization: VT-x
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 25600K
NUMA node0 CPU(s): 0-9,20-29
NUMA node1 CPU(s): 10-19,30-39
please help advise how to resolve. thanks!
You need to specify a bit mask giving a set of CPUs that can handle the interrupt. For CPU0, the mask value is 1.
i have got the solution. i make a mistake here. it should be echo "1" for core 0, and echo "2" for core 1.

How can I programmatically know if I am in a VM?

I want to be able to do so from both Windows and from Linux. I know that there are ways by getting sysinfo and using thumb rules related to hardware identifiers.
I want to know if there is a more fundamental method, like looking at a memory address / issuing an interrupt etc.
BTW I am trying to do this on Intel hardware and the virtualization software I use are Vmware Workstation and Windows HyperV.
Here is one more useful command:
$ lscpu | grep -E 'Hypervisor vendor|Virtualization type'
Hypervisor vendor: KVM
Virtualization type: full
Example output of other commands:
$ sudo virt-what
kvm
$ dmesg | grep -i virtual
[ 0.000000] Booting paravirtualized kernel on KVM
[ 0.029160] CPU0: Intel QEMU Virtual CPU version 1.0 stepping 03
$ sudo dmidecode | egrep -i 'manufacturer|product|vendor|domU'
Vendor: Bochs
Manufacturer: Bochs
Product Name: Bochs
Manufacturer: Bochs
Manufacturer: Bochs
Manufacturer: Bochs
Manufacturer: Bochs
Manufacturer: Bochs
Manufacturer: Bochs
Manufacturer: Bochs
Manufacturer: Bochs
Manufacturer: Bochs
At least one of these should work to detect if you are running under VMware (or some other common virtual environment) on Linux:
Check for virtual devices detected by kernel when system boots.
dmesg | grep -i virtual
Another way to detect virtualized hardware devices, if dmesg doesn't say anything useful.
dmidecode | egrep -i 'manufacturer|product|vendor|domU'
You can also check for virtual disks:
cat /proc/ide/hd*/model
Virtuozzo can usually be detected by looking for /proc/vz or /dev/vzfs.
Most software check the hypervisor CPUID leaf -
Leaf 0x40000000, Hypervisor CPUID information
EAX: The maximum input value for hypervisor CPUID info (0x40000010).
EBX, ECX, EDX: Hypervisor vendor ID signature. E.g. "KVMKVMKVM"
Leaf 0x40000010, Timing information.
EAX: (Virtual) TSC frequency in kHz.
EBX: (Virtual) Bus (local apic timer) frequency in kHz.
ECX, EDX: RESERVED
Ofcourse, you are still relying on the hypervisor to give you this information. It may very well decide to not report 0x40000000 at all, in turn leading the guest to believe that it's actually running on real hardware

How do you get the set of available CPUs in a Linux kernel module?

I would like to start one kernel thread per CPU with kthread_create()/kthread_bind(). However, I can't for the life of me figure out how to query the number of available CPUs. I did find the CPU_SET man page but that didn't help either.
Any thoughts?
You can use num_online_cpus() to get the number of available cpus. This may be different from things like nr_cpu_ids if the system was booted using a maxcpus setting that is not the same as the number of cpus in the system.
See following link, cpuinfo.c, proc.c, may be help you. And
at line 143, you can use two functions for traversing cpus, cpumask_first, cpumask_next. I think, by try and error, you can find the solutions.
You can use x86info. It's not per default installed (sudo apt-get install x86info (ubuntu))
x86info | grep Found
Found 2 CPUs
another way is:
grep processor /proc/cpuinfo | wc -l
2
Is that you are looking for?
If you're using a system that is Fedora Linux / RHEL / CentOS v6+ / Debian Linux v6+ you can use lscpu:
michael#test:~$ lscpu
Architecture: i686
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 4
On-line CPU(s) list: 0-3
Thread(s) per core: 2
Core(s) per socket: 2
Socket(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 37
Stepping: 5
CPU MHz: 1199.000
BogoMIPS: 5319.88
Virtualization: VT-x
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 3072K
Particularly you might be interested in the -p option which gives you parseable output:
michael#test:~$ lscpu -p
# The following is the parsable format, which can be fed to other
# programs. Each different item in every column has an unique ID
# starting from zero.
# CPU,Core,Socket,Node,,L1d,L1i,L2,L3
0,0,0,,,0,0,0,0
1,0,0,,,0,0,0,0
2,1,0,,,1,1,1,0
3,1,0,,,1,1,1,0
$ nproc --all
4
--all print the number of installed processors

How to determine whether a given Linux is 32 bit or 64 bit?

When I type uname -a, it gives the following output.
Linux mars 2.6.9-67.0.15.ELsmp #1 SMP Tue Apr 22 13:50:33 EDT 2008 i686 i686 i386 GNU/Linux
How can I know from this that the given OS is 32 or 64 bit?
This is useful when writing configure scripts, for example: what architecture am I building for?
Try uname -m. Which is short of uname --machine and it outputs:
x86_64 ==> 64-bit kernel
i686 ==> 32-bit kernel
Otherwise, not for the Linux kernel, but for the CPU, you type:
cat /proc/cpuinfo
or:
grep flags /proc/cpuinfo
Under "flags" parameter, you will see various values: see "What do the flags in /proc/cpuinfo mean?"
Among them, one is named lm: Long Mode (x86-64: amd64, also known as Intel 64, i.e. 64-bit capable)
lm ==> 64-bit processor
Or using lshw (as mentioned below by Rolf of Saxony), without sudo (just for grepping the cpu width):
lshw -class cpu|grep "^ width"|uniq|awk '{print $2}'
Note: you can have a 64-bit CPU with a 32-bit kernel installed.
(as ysdx mentions in his/her own answer, "Nowadays, a system can be multiarch so it does not make sense anyway. You might want to find the default target of the compiler")
If you were running a 64 bit platform you would see x86_64 or something very similar in the output from uname -a
To get your specific machine hardware name run
uname -m
You can also call
getconf LONG_BIT
which returns either 32 or 64
lscpu will list out these among other information regarding your CPU:
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
...
Another useful command for easy determination is as below:
Command:
getconf LONG_BIT
Answer:
32, if OS is 32 bit
64, if OS is 64 bit
The command
$ arch
is equivalent to
$ uname -m
but is twice as fast to type
I was wondering about this specifically for building software in Debian (the installed Debian system can be a 32-bit version with a 32 bit kernel, libraries, etc., or it can be a 64-bit version with stuff compiled for the 64-bit rather than 32-bit compatibility mode).
Debian packages themselves need to know what architecture they are for (of course) when they actually create the package with all of its metadata, including platform architecture, so there is a packaging tool that outputs it for other packaging tools and scripts to use, called dpkg-architecture. It includes both what it's configured to build for, as well as the current host. (Normally these are the same though.) Example output on a 64-bit machine:
DEB_BUILD_ARCH=amd64
DEB_BUILD_ARCH_OS=linux
DEB_BUILD_ARCH_CPU=amd64
DEB_BUILD_GNU_CPU=x86_64
DEB_BUILD_GNU_SYSTEM=linux-gnu
DEB_BUILD_GNU_TYPE=x86_64-linux-gnu
DEB_HOST_ARCH=amd64
DEB_HOST_ARCH_OS=linux
DEB_HOST_ARCH_CPU=amd64
DEB_HOST_GNU_CPU=x86_64
DEB_HOST_GNU_SYSTEM=linux-gnu
DEB_HOST_GNU_TYPE=x86_64-linux-gnu
You can print just one of those variables or do a test against their values with command line options to dpkg-architecture.
I have no idea how dpkg-architecture deduces the architecture, but you could look at its documentation or source code (dpkg-architecture and much of the dpkg system in general are Perl).
#include <stdio.h>
int main(void)
{
printf("%d\n", __WORDSIZE);
return 0;
}
If you have a 64-bit OS, instead of i686, you have x86_64 or ia64 in the output of uname -a. In that you do not have any of these two strings; you have a 32-bit OS (note that this does not mean that your CPU is not 64-bit).
That system is 32bit. iX86 in uname means it is a 32-bit architecture. If it was 64 bit, it would return
Linux mars 2.6.9-67.0.15.ELsmp #1 SMP Tue Apr 22 13:50:33 EDT 2008 x86_64 i686 x86_64 x86_64 GNU/Linux
Nowadays, a system can be multiarch so it does not make sense anyway. You might want to find the default target of the compiler:
$ cc -v 2>&1 | grep ^Target
Target: x86_64-pc-linux-gn
You can try to compile a hello world:
$ echo 'int main() { return 0; }' | cc -x c - -o foo
$ file foo
foo: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=b114e029a08abfb3c98db93d3dcdb7435b5bba0c, not stripped
With respect to the answer "getconf LONG_BIT".
I wrote a simple function to do it in 'C':
/*
* check_os_64bit
*
* Returns integer:
* 1 = it is a 64-bit OS
* 0 = it is NOT a 64-bit OS (probably 32-bit)
* < 0 = failure
* -1 = popen failed
* -2 = fgets failed
*
* **WARNING**
* Be CAREFUL! Just testing for a boolean return may not cut it
* with this (trivial) implementation! (Think of when it fails,
* returning -ve; this could be seen as non-zero & therefore true!)
* Suggestions?
*/
static int check_os_64bit(void)
{
FILE *fp=NULL;
char cb64[3];
fp = popen ("getconf LONG_BIT", "r");
if (!fp)
return -1;
if (!fgets(cb64, 3, fp))
return -2;
if (!strncmp (cb64, "64", 3)) {
return 1;
}
else {
return 0;
}
}
Good idea, the 'getconf'!
You can also check using a environment variable:
echo $HOSTTYPE
Result:
i386 -> 32 bits
x86_64 -> 64 bits
Extracted from: http://www.sysadmit.com/2016/02/linux-como-saber-si-es-32-o-64-bits.html
In Bash, using integer overflow:
if ((1 == 1<<32)); then
echo 32bits
else
echo 64bits
fi
It's much more efficient than invoking another process or opening files.
getconf uses the fewest system calls:
$ strace getconf LONG_BIT | wc -l
253
$ strace arch | wc -l
280
$ strace uname -m | wc -l
281
$ strace grep -q lm /proc/cpuinfo | wc -l
301
If you shift 1 left by 32 and you get 1, your system is 32 bit.
If you shift 1 left by 64 and you get 1, your system is 64 bit.
In other words,
if echo $((1<<32)) gives 1 then your system is 32 bit.
if echo $((1<<64)) gives 1 then your system is 64 bit.
If one is severely limited in available binaries (e.g. in initramfs), my colleagues suggested:
$ ls -l /lib*/ld-linux*.so.2
On my ALT Linux systems, i586 has /lib/ld-linux.so.2 and x86_64 has /lib64/ld-linux-x86-64.so.2.
$ grep "CONFIG_64" /lib/modules/*/build/.config
# CONFIG_64BIT is not set
I can't believe that in all this time, no one has mentioned:
sudo lshw -class cpu
to get details about the speed, quantity, size and capabilities of the CPU hardware.
Simple script to get 64 bit or 32 bit
if $(getconf LONG_BIT | grep '64'); then
echo "64 bit system"
else
echo "32 bit system"
fi
[ -z `uname -m | grep 64` ] && echo "32-bit" || echo "64-bit"
Based on the fact that 64-bit is usually x86_64 and 32-bit is i686 etc.
First you have to download Virtual Box. Then select new and a 32-bit Linux. Then boot the linux using it. If it boots then it is 32 bit if it doesn't then it is a 64 bit.

Resources