1
votes

I like to know, in which file the value for the CPU architecture is stored on Linux e.g. x86_64.

I know several methods (shell commands) in order to access this value like lscpu or uname -a.

Furthermore I'm aware of the Qt-Method QSysInfo::currentCpuArchitecture(). And they all provide the required information.

But I like to create an OS-Interface which retrieves the information of the underlying operating system (in my case Linux) only by using "Linux-Tools" like information from files in /proc/....

I also know that I can run a shell command in my program by using popen() and access the results by the std streamer classes. That's no problem. But unfortunately we don't like run shell commands in our software.

I have looked in several files like /proc/version, /proc/cpuinfo, /proc/devices or in files in subfolders of /proc.

But unfortunately it seems to me as if I always overlooked this piece of information. I'm sure that it has to be in a file because the method QSysInfo::currentCpuArchitecture() access this information, too.

So if somebody knows where this information is placed on Linux I would be happy if he or she let me know.

With kind regards

1

1 Answers

0
votes

According man lscpu

lscpu gathers CPU architecture information from sysfs, /proc/cpuinfo ...

looking for the information under /proc and cpuinfo was the right idea, since the information is there, but not in the format you were expecting. It is somehow "hidden" in line flags. You like to look for lm (long mode).

cat /proc/cpuinfo | grep "flags\| lm "

If the flag for long mode is set you are on x86_64.

Thanks / Credits to

How the information is gathered and processed you can find in sys-utils/lscpu.c, in example from line 369-378.

Other CPU modes are

  • Real Mode, 16 bit CPU, Intel 8086 or 8080 emulation mode, all x86 CPU start in this mode after reset
  • Protected Mode, 32-bit CPU