调度线程有什么区别?

What is the difference in scheduling threads?

我目前正在学习同步多线程、多核和多处理器线程调度。查了一些资料,我的理解是:

如果有支持同时多线程的处理器,它会将一个物理核心变成两个逻辑核心。有两个进程,P1和P2。

  1. My understanding: In Linux, each process is composed of at least one thread? So scheduling is based on thread scheduling?

P1和P2分别被调度到两个逻辑核心。他们独立运作。这是第一种情况。如果有一个进程P3,它由两个线程t1和t2组成。将 t1 和 t2 分别调度到不同的逻辑核心。那么调度两个不同的进程分离逻辑核和将同一个进程中的不同线程调度到逻辑核有什么区别呢?

  1. My understanding: The process is the smallest unit of the system to allocate resources, and threads share the resources of the process. Threads in a process share virtual memory, PCB, and can access the same data. Therefore, when scheduling different threads in a process and scheduling threads in different processes, there is no difference for the processor. The difference lies in the address translation of the page table and whether the cache can be shared. For a multi-core processor, the processor does not care whether the threads belong to the same process. The consistency of the data is guaranteed by MESI. The physical location of the data is guaranteed by the page table.

我的理解正确吗?

对,没有区别。内核只是调度任务;每个用户任务都引用一个页面 table(无论是否与任何其他任务共享)。

每个逻辑 CPU 核心都有自己的页面-table 指针(例如 x86 CR3)。

是的,缓存一致性是由硬件维护的。 Linux 内核的手动原子(使用 volatile,以及用于 RMW 和屏障的内联 asm)depend on that.