1. -1

Used the closest tag, C, since there was no tag for D.

  1.  

  2. 2

    I recently had a curious bug….

    I have a build system that sniffed /proc/cpuinfo to guess how many compiles to run simultaneously.

    On my own box it shows I have 8 processors… So I tried running 9 (8+1) compiles.

    I also note it says cpu cores: 4.

    So I benchmarked and found number of cores + 1 was the fastest for compiling. The CPU I have has “hyperthreading” which may help with threads sharing the same cached data within the same process, but doesn’t help with compiles.

    Then we ran it on a 40 CPU Monster Server.

    Alas, cpuinfo tells me “cpu cores: 1”, so my build system ran only two compiles on the monster server!

    The program lscpu solved the mystery for me…

    CPU(s):                40
    On-line CPU(s) list:   0-39
    Thread(s) per core:    1
    Core(s) per socket:    1
    Socket(s):             40
    

    The monster server had 1 core per socket and 40 sockets!

    Whereas my hyperthreading desk top had

    CPU(s):                8
    On-line CPU(s) list:   0-7
    Thread(s) per core:    2
    Core(s) per socket:    4
    Socket(s):             1
    

    So where does the utility lscpu get it’s information?

    Strace reveals it gets it from /proc/cpuinfo AND /sys/devices/system/cpu

    I think it is probably just easier to parse the output of lscpu.

    1. 1

      Interesting. I had only tested my program on Windows. Will run it on Linux too and compare with your results from the proc file system and so on. Using strace was a good idea.

    2. 1

      This post is really poor. You don’t even have the source code linked.

      1. 2

        Oh heck. That happened accidentally. I proof read my posts and code, before publishing. In fact I don’t write them directly in Blogger nowadays - I write them first in a text editor (vim), and check things before pasting into the Blogger new post window. Even then I preview first, a couple of times, before publishing, then again after publishing, check all the links, text, etc. (because sometimes links don’t show on hovering over them in the preview). Might have got distracted by something today and missed out one or two of those steps. Sorry for inconvenience / annoyance caused to readers.

        Thanks for mentioning this.

        Adding the source code to the post now, and will comment here again when done.

        1. 1

          Adding the source code to the post now, and will comment here again when done.

          Done. See the OP.