How do OS's handle hyperthreading?

d4mo

Senior member
Jun 24, 2005
588
0
0
Like on an i7 for example is the OS smart enough to assign one thread per physical core before assign 2 to one?

For Example

Core 1
Logical core 1 - Thread
Logical core 2 - Nothing

Core 2
Logical core 1 - Thread
Logical core 2 - Nothing

Core 3
Logical core 1 - Thread
Logical core 2 - Nothing

Core 4
Logical core 1 - Thread
Logical core 2 - Nothing
 

Cogman

Lifer
Sep 19, 2000
10,277
125
106
Yes. Scheduling is pretty smart and pretty complex on the OS level. OSes do a lot of work to try to keep your CPU as busy as possible. The OS scheduler needs to take into account things like core affinity to make sure that you aren't getting a bunch of cache misses because your thread is leaping across cores (memory -> CPU is expensive).
 

Cogman

Lifer
Sep 19, 2000
10,277
125
106
Generally, no.

Scheduling is one of those core things that OSes do. They try to provide flexible schedulers that are very general purpose. Some OSes will allow you to change the scheduler that is being used to help optimize it for the system task (different scheduler for a database for example). But those are generally OSes geared towards servers and not end users.

It is best not to futz around with the scheduler. The guys that write these things put blood, sweat, and tears in them to make them work as fast and as efficiently as possible. Almost anything you would do will negatively impact your system's performance.

One way you can influence the scheduler is by bumping the priority of whatever it is you care about. In linux this is the "nice" value and in windows you can change it from the task manager. Be warned, though, if you do something like set a bunch of tasks to realtime which are CPU intensive, you can pretty much take down your OS. The scheduler will starve the OS in favor of running your app.
 

Borealis7

Platinum Member
Oct 19, 2006
2,914
205
106
in a pure CompSci theoretical sense, the OS shouldn't know the difference between logical and virtual cores, and it shouldn't matter to the OS. in reality - it knows.
 

Heatshiver

Member
Jun 9, 2013
39
1
71
If that interests you, you should also look into core parking. Some related info there which can be interesting to learn and try.