News for hackers. Stuff that matters.
Re:Cache Sizes with CPUID on Intel CPU's by tux1968 on Monday May 16, 2016 @07:59AM (#11705730)
I don't get it. The code doesn't even compile. Both code snippets have undefined variables.
Re:Cache Sizes with CPUID on Intel CPU's by svens_ on Monday May 16, 2016 @08:42AM (#11705891)
Just declare cpu_info as int[4] and it should run.

Basically on x86 CPUs you can use the cpuid instruction to get information about the CPU and the cache: http://www.sandpile.org/x86/cpuid.htm

The code in the first snippet uses a compiler intrinsic to execute this instruction and calculates the cache size from the result. In the second snippet the assembler code is written by hand instead.

Re:Cache Sizes with CPUID on Intel CPU's by tux1968 on Monday May 16, 2016 @08:50AM (#11705922)
Yes, that was pretty clear, but in the D version that's not enough to make it compile, there is also the missing functionID which apparently needs to be primed with the correct value to make things work. No idea what that value should be though.

It's not that I thought that this information was difficult to look up, rather it seemed very odd information to be missing from a link that was submitted as useful/interesting.

Re:Cache Sizes with CPUID on Intel CPU's by svens_ on Monday May 16, 2016 @09:29AM (#11706102)
functionID is what's called "standard level" in the link I posted. So it should be 4 (you can also see that in the C version btw.).

I agree that the example isn't very well tested - the author probably pulled it out of some existing code and wasn't very careful.

Re:Cache Sizes with CPUID on Intel CPU's by jepler on Monday May 16, 2016 @08:06AM (#11705755)
on Debian Linux, the commandline programs 'cpuid' and 'x86info' from packages of the same name show this information; their source might also be worth reading to understand how to obtain and interpret this information in practice.
Re:Cache Sizes with CPUID on Intel CPU's by frakturfreund on Monday May 16, 2016 @09:46AM (#11706193)
lscpu (from the preinstalled util-linux package) works too. And now that Windows comes with the Ubuntu Bash …
Re:Cache Sizes with CPUID on Intel CPU's by RandomBK on Monday May 16, 2016 @10:34PM (#11711040)
Might as well just read from /proc/cpuinfo