Reputation: 1702
We try to evaluate if it is better to make some hw related task in user or in kernel. The task have to respond to interrupt and do some task which shall copy data into physical (mapped) memory space.
According to my understanding the same task be done both in userspace or kernel.
The only open issue is if the kernel thread priority is higher then user threads priority.
We shall use pthread
for userspace or kthread
for kernel thread.
So, my question is:
When two threads are ready, does the kernel thread have higher priority over user thread ?
EDIT: If kthread_create was created with SCHED_FIFO and given priority x, and pthread_create was created with SCHED_FIFO and given priority y, and priority of pthread is higher than kthread, would still kthread get into scheduler before the user thread ?
Thank you!
Upvotes: 5
Views: 6951
Reputation: 484
Processes in a Linux system are represented by struct task_struct
structures.
Now for a kernel thread p->mm that is process' address space is NULL and its active address space is represented by p->active_mm. So when a kernel thread is scheduled-in, then its next->active_mm
will be set to the prev->active_mm
of the task that was scheduled-out. This helps minimize TLB flushes on switching address spaces.
The arch-specific constant PROC_CHANGE_PENALTY
which defines the cpu affinity giving advantage to processes in the same cpu also gives preference to kernel threads over user threads (which have their ->mm != NULL and require overheads).
Upvotes: 1
Reputation: 1836
User threads must always be pre-emptible by kernel-mode threads because kernel-mode threads need to respond to hardware-events. This happen because of operating system design.
Kernel Thread has higher priority than user thread because Kernel threads are used to provide privileged services to applications.
Apart from it they are also used by the kernel to keep track of what all is running on the system, how much of which resources are allocated to what process, and to schedule them.
See as you know for every thread that exists in user space there is a corresponding kernel thread so If the threads of a process in system scope (Kernel) have high enough priorities, they will be scheduled on multiple CPUs at the same time. Means other kernel threads will be preempted by this kernel thread that is running on the behalf of user space.
Upvotes: 4