Reputation: 17345
Actually one of the concepts that I don't really understand is the 'kernel porocess' or kernel thread. Searching in the web and for similar questions in SOO I found the following: What is a Kernel thread? where the answer was:
A kernel thread is a kernel task running only in kernel mode
As far as I know a process to go into 'kernel mode' has to issue a system call. So I don't understand how these threads are running in this mode all the time. Can somebody help me to understand how this works?
Upvotes: 2
Views: 105
Reputation: 22157
Kernel threads are threads that can be created only by another kernel thread (already in "kernel mode" - maybe some driver could spawn them to do some cleanup or monitoring for them), so there's no user thread to start with (and to switch context with syscall), and these threads are started inside the kernel address space, so they don't need anything extra to go to kernel mode.
Created kernel thread runs with the normal priority and scheduler capatibilities as user thread. From kthread_create_on_node
(http://lxr.free-electrons.com/source/kernel/kthread.c#L269):
310 task = create->result;
311 if (!IS_ERR(task)) {
312 static const struct sched_param param = { .sched_priority = 0 };
313 va_list args;
314
315 va_start(args, namefmt);
316 vsnprintf(task->comm, sizeof(task->comm), namefmt, args);
317 va_end(args);
318 /*
319 * root may have changed our (kthreadd's) priority or CPU mask.
320 * The kernel thread should not inherit these properties.
321 */
322 sched_setscheduler_nocheck(task, SCHED_NORMAL, ¶m);
323 set_cpus_allowed_ptr(task, cpu_all_mask);
324 }
Upvotes: 2