[fpc-pascal] CPU affinity of TThread descendants
JeLlyFish.software at gmx.net
Tue Jan 20 11:34:44 CET 2009
-------- Original-Nachricht --------
> Datum: Tue, 20 Jan 2009 09:07:54 +0100 (CET)
> Von: Michael Van Canneyt <michael at freepascal.org>
> An: FPC-Pascal users discussions <fpc-pascal at lists.freepascal.org>
> Betreff: Re: [fpc-pascal] CPU affinity of TThread descendants
> On Mon, 19 Jan 2009, David W Noon wrote:
> > Hi,
> > I am running FPC 2.3.1 under Linux 2.6.26 on a twin CPU AMD Athlon MP
> > system.
> > Whenever I instantiate multiple descendants of the TThread class, they
> > all seem to run on the same CPU, which is the same CPU as the parent
> > thread is running on. With 21 threads in the program, the system monitor
> > shows one CPU at 100% busy and the other CPU idle.
> > Does this class, by default, impose CPU affinity, in the manner of the
> > Windows NT/2K/XP CreateThread() API? If so, how can I disable this?
> > [I.e., I want all my threads to be runnable by any CPU inside the box.]
> No CPU affinity is imposed as far as I know;
> Under Linux, this is not possible, at least I've never heard of such a
(Now you've heard. ;)
The default for the CPU masks should be all 1s though, so the scheduler should distribute the threads evenly to all available CPUs. But... AFAIR the affinity mask is inherited by child processes, so maybe the main thread already has some affinity mask set (well, I don't see no reason why it should, but you never know).
So for the original poster I'd suggest inserting a sched_get_affinity() call and check the resulting bit mask. If that's not all 1s, one should investigate the reason... if it is, then maybe the scheduler detects too many dependencies between the threads, so it doesn't distribute the thread on both CPUs, or maybe there's one totally different reason for the behaviour...
Psssst! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger
More information about the fpc-pascal