Reputation: 1
I'm on the 12th gen Intel CPUs with hyperthreading enabled. From my lscpu output, I can see that logical cores 0 and 1 both map to physical core 0. I understand that if I allocate processes P0 and P1 to 0 and 1, respectively, they'll essentially multiplex physical core 0's resources via SMT. If I allocate both P0 and P1 to logical core 0, however, how is this execution handled? Does the OS just continually context switch them?
I'm just seeing some interesting behavior where P0 and P1 run faster when they're allocated on the same logical core (note that P0 and P1 communicate), faster than if they're multithreaded on the same physical core, or allocated to two different physical cores altogether. I can't explain this.
Upvotes: 0
Views: 114
Reputation: 37232
If I allocate both P0 and P1 to logical core 0, however, how is this execution handled?
It depends on the scheduler and what the scheduler is told about P1 and P2. If one process has a higher priority or an earlier deadline, then it may be given 100% of CPU time (until it terminates or unless it blocks temporarily). Regularly switching between the processes is a generic option that's often used when the scheduler can't distinguish between the processes (e.g. they're equal priority).
Note that this regular switching is mostly bad - e.g. if both processes would take 1 hour of CPU time to complete, then after 1 hour you end up no completed processes (2 "not quite half-completed due to extra overhead of context switches" processes) instead of 1 completed process (and 1 process that's made no progress); and after 2 hours you end up with no completed processes (2 "almost completed due to extra overhead of context switches" processes) instead of 2 completed process.
I'm just seeing some interesting behavior where P0 and P1 run faster when they're allocated on the same logical core (note that P0 and P1 communicate), faster than if they're multithreaded on the same physical core, or allocated to two different physical cores altogether. I can't explain this.
I can't explain it either - it depends on how the processes communicate (in addition to depending on the scheduler and what the scheduler is told).
Upvotes: 1