Skip to content
Advertisement

linux c: what’s the common use case of “sched_setaffinity” function? I don’t find it useful

The operating system is able to determine how to arrange difference processes/threads onto different cpu cores, the os scheduler does the work well. So when do we really need to call functions like sched_setafficity() for a process, or pthread_setaffinity_np() for a pthread?

It doesn’t seem to be able to raise any performance dramatically, if it can, then I suppose we need to re-write linux process scheduler right?

Just wish to know when do we need to call these functions, in my applications? Thanks.

Advertisement

Answer

It’s very helpful in some computationally intensive real time processes related to DSP(Digital Signal Processing). Let’s say One real time DSP related process PROCESS0 is running on core CPU0. Because of some scheduling algorithms CPU0 pre-emption need to happen such that process0 has to run on another CPU. This switching of realtime process is a overhead. Hence affinity. We direct to kernel that the process0 should run on CPU0.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement