Search code examples
linux-kernelcpucpu-architecturecpu-cores

Is having multiple cores in a CPU for running multiple threads/processes at once, or for instruction-level parallelism?


I was just trying to get a clearer understanding of what exactly multiple cores are being used for, and what the difference is between multiple cores and multiple CPUs.

I was trying to understand if having multiple cores is just to enable instruction-level parallelism within a given CPU, or if the multiple cores within a CPU all have their own struct rq that lets them independently call __schedule() and schedule processes/threads at will, and that instruction-level parallelism is then handled by additional modules within each core.

Any thoughts appreciated.


Solution

  • ILP is purely within each physical core separately.
    cross-site duplicate: How does a single thread run on multiple cores?
    (It doesn't - each core has multiple execution units and a wide front-end. Read my linked answer for details that I'm not going to duplicate. See also Modern Microprocessors A 90-Minute Guide!)

    Also, real CPU cores can pretend to be multiple "logical cores" (i.e. each having register context and can call __schedule() independently). Generically, this is SMT; the mostly widely-known brand-name implementation of that concept is Intel's HyperThreading. Letting multiple software threads share a CPU truly simultaneously (not via software context-switching) gives the core two instruction-streams to find parallelism between as well as within, generally increasing overall throughput (at the cost of single-thread performance to some degree, depending on how busy a single thread of your workload could keep a core).


    In some contexts, "CPU" is synonym for a single core. e.g. perf stat output saying "7.5 CPUs utilized".

    But more often, a CPU refers to the whole physical package, e.g. my CPU is a quad-core, an i7-6700k. Server motherboards are often dual-socket, allowing you to plug in two separate multi-core CPUs.

    Perhaps that's what created some terminology confusion?