[erlang-questions] CPU affinity and enif_thread_create

Rickard Green <>
Mon Aug 22 18:08:32 CEST 2011


enif_thread_create() and erl_drv_thread_create() will set the affinity of the newly created thread to the same as the affinity of the main thread (or you have found a bug). Binding of scheduler threads does not effect the affinity of the main thread. However, if you create the thread any other way (e.g. by calling pthread_create() directly), the newly created thread will inherit the affinity of the scheduler thread it happens to execute on (and it may also inherit other unwanted stuff).

If you have changed the affinity of the emulator while it is running, you need to force a re-read of the cpu information by calling erlang:system_info(update_cpu_info) before it will fully take effect.

What is the affinity of the emulator (main thread)?

<emu-pid> = os:getpid().

taskset -p <emu-pid> (in os-shell)

What are the affinities of the other individual threads?

ps -Lp <emu-pid> (in os-shell) will give you pids of individual threads (LWP column I think).

taskset -p <LWP pid>

Which ERTS version do you use?


Regards,
Rickard Green, Erlang/OTP, Ericsson AB

On Aug 21, 2011, at 10:47 PM, Max Lapshin wrote:

> I've created libx264 encoder in nif and started new thread for it.
> libx264 was started with option threads 4 and it really created 4 threads.
> 
> Now I have problems. All created threads are bound to one CPU core and
> it is not enough. 100% busy and I have to drop frames.
> 
> I have installed linux kernel with BFS (brainfuck scheduler), but it
> didn't change anything.
> 
> So I have called sched_setaffinity by hands and libx264 threads spread
> across cores.
> 
> And I have questions: does erlang VM makes some calls, that bind
> future created threads to current core?
> 
> If no, that why doesn't erlang VM moved to other cores busy processes
> that had several hundred messages inbox?
> Maybe I should do some hinting like  "bump_reductions" to tell VM to
> switch process to another scheduler?
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions




More information about the erlang-questions mailing list