[英]Why does one core execute more than its share of instructions?
I have a C program (graphics benchamrk) that runs on a MIPS processor simulator(I'm looking to graph some performance characteristics). 我有一个在MIPS处理器模拟器上运行的C程序(图形基准)(我正在寻找图形的一些性能特征)。 The processor has 8 cores but it seems like core 0 is executing more than its fair share of instructions.
该处理器有8个内核,但似乎内核0的执行能力超出其应有的指令份额。 The benchmark is multithreaded with the work exactly distributed between the threads.
基准测试是多线程的,工作完全在线程之间分配。 Why could it be that core 0 happens to run about between 1/4 and half the instructions even though it is multithreaded on a 8 core processor?
为什么即使在8核处理器上是多线程的,0内核也可能恰好运行大约1/4至一半的指令?
What are some possible reasons this could be happening? 发生这种情况的可能原因有哪些?
Most application workloads involve some number of system calls, which could block (eg for I/O). 大多数应用程序工作负载涉及一定数量的系统调用,这些调用可能会阻塞(例如,针对I / O)。 It's likely that your threads spend some amount of time blocked, and the scheduler simply runs them on the first available core.
您的线程可能花费了一些时间来阻塞,并且调度程序仅在第一个可用的内核上运行它们。 In an extreme case, if you have N threads but each is able to do work only 1/N of the time, a single core is sufficient to service the entire workload.
在极端情况下,如果您有N个线程,但每个线程只能在1 / N的时间内工作,则单个内核足以服务整个工作负载。
You could use pthread_setaffinity_np
to assign each thread to a specific core, then see what happens. 您可以使用
pthread_setaffinity_np
将每个线程分配给特定的内核,然后查看会发生什么。
You did not mention which OS you are using. 您没有提及正在使用的操作系统。
However, most of the code in most OSs is still written for a single core CPU. 但是,大多数操作系统中的大多数代码仍是为单核CPU编写的。
Therefore, the OS will not try to evenly distribute the processes over the array of cores. 因此,操作系统将不会尝试在内核阵列上平均分配进程。
When there are multiple cores available, most OSs start a process on the first core that is available (and a blocked process leaves the related core available.) 当有多个内核可用时,大多数操作系统会在第一个可用内核上启动一个进程(而阻塞的进程将使相关内核可用)。
As an example, on my system (a 4 core amd-64) running ubuntu linux 14.04, the CPUs are usually less than 1 percent busy, So everything could run on a single core. 例如,在运行ubuntu linux 14.04的系统(4核amd-64)上,CPU的忙碌率通常不到1%,因此所有内容都可以在单个核上运行。
There must be lots of applications running like videos and background long running applications, with several windows open to show much real activity on other than the first core. 必须有许多像视频一样运行的应用程序和长期运行的后台应用程序,并且打开多个窗口以显示第一个核心以外的更多实际活动。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.