Threaded RTS must use processor affinity and processor information
Threaded RTS must use processor affinity and processor information
I think current GHC's SMP parallelism support has 2 problems.
- We must specify -Nx option if we want to use multiple CPU or cores.
- Threaded RTS doesn't set processor affinity even if OS API support that.
1 is bad. Because this is complex for Application user and developper. If user want to take full advantage of multiple core processor, user must know how many his computer's cpu cores, and specify RTS option in runtime. Or application developper must guess how many users' computer use cpu cores, and set guessed good enough RTS option.
If OS doesn't provide CPU information, it's real solution. But we can get CPU information by OS's API, so it's just bad way.
We can get number of processors (cores) by sysconf(_SC_NPROCESSORS_CONF) under unix (includes Mac OS X) platform, and by GetSystemInfo function under Windows platform.
- http://developer.apple.com/documentation/Darwin/Reference/ManPages/man3/sysconf.3.html
- http://msdn2.microsoft.com/en-us/library/ms724381.aspx
So I think threaded RTS must specify -Nx's default x by using these API.
2 is related to good parallel program's behavior. Current mainstream OS scheduler assigns thread to CPU implicitly by default. And if two thread are assigned to same CPU, then a thead must wait when another thread is running, even if other CPU is idle. This is not good.
And RTS -Nx option specifies number of thread running simultaneously.
So I think threaded RTS must assigning thread to CPU instead of leaving work for OS scheduler.
This is not difficult work on Linux and Windows. Because we just need to set processor affinity by OS's API. Linux has sched_setaffinity, so we must just set bitmask on Linux.
- http://linux.die.net/man/2/sched_setaffinity
- http://www-128.ibm.com/developerworks/linux/library/l-affinity.html
Windows has many API, e.g. SetThreadAffinityMask and SetThreadIdealProcessor .... So we must just set bitmask by SetThreadAffinityMask, or set preferred processor by SetThreadIdealProcessor on Windows.
But I don't get other OS's API information soonly, and I think this is difficult point of this task.
Trac metadata
Trac field | Value |
---|---|
Version | 6.6.1 |
Type | Task |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | shelarcy@gmail.com |
Operating system | Multiple |
Architecture | Multiple |