LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 04-28-2017, 06:38 AM   #1
ayyasprings
Member
 
Registered: Aug 2014
Posts: 118

Rep: Reputation: Disabled
Is the scheduling policy shared for kernel process and user process?


Hi,

Kernel process and user process uses memory and other resources exclusively. ie) User process don't use memory or any other resources used by kernel to avoid crashes or any other serious faults in system.

I want to know does the scheduling policy is also like that? If it is so how the cpu usage was divided for scheduling policy for kernel process and scheduling policy for user process. ie) how was the time slicing done for both type of process by isolating the scheduling mechanism not affecting one another?

Or scheduling policy is shared for both kernel and user process?

Please reply!
 
Old 04-30-2017, 06:47 PM   #2
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,665
Blog Entries: 4

Rep: Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945
There's a good writeup in this LQ article.

Basically, "kernel threads" are a bit of a fiction. They are independently dispatchable – which makes it easy for them to, for instance, "wait for I/O" as the swapper does – but they are nevertheless part of the kernel.

If a kernel thread is ready to run, it is my understanding that it will run "at once," pre-empting user-land work if necessary. The kernel is not delayed from its work by user-land, although it can "delay a part of its work" through the kernel-thread mechanism.

Last edited by sundialsvcs; 05-09-2017 at 03:04 PM.
 
Old 05-22-2017, 06:32 AM   #3
ayyasprings
Member
 
Registered: Aug 2014
Posts: 118

Original Poster
Rep: Reputation: Disabled
Hi sundialsvcs,

The article you mentioned does not answer me for the following questions.

1)Will the kernel process share the same scheduling policy and/or priority as of the one used for user space processes in the OS( I did not get cleared with the your explanation )? What part of the kernel source code handles this so that I could look on that and try to clarify myself?

2) Can multiple scheduling policies be used in the same embedded target in the same image used, like some group of processes use Scheduling policy X and another group of process use Scheduling policy Y like so and so?

3) What is/are the api or system call that will be used to initiate a user space task that can invoked from User Application code?

4) how can I pass options like setting the type/name of Scheduling policy for that task, periodicity in which that task has to be invoked, time slice allocated for that task like so and so for user/kernel task ?

I could not get answers for these from google.

Please reply!

Last edited by ayyasprings; 05-22-2017 at 06:45 AM.
 
Old 05-22-2017, 08:36 AM   #4
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,665
Blog Entries: 4

Rep: Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945
Quote:
Originally Posted by ayyasprings View Post
Hi sundialsvcs,

The article you mentioned does not answer me for the following questions.

1)Will the kernel process share the same scheduling policy and/or priority as of the one used for user space processes in the OS( I did not get cleared with the your explanation )? What part of the kernel source code handles this so that I could look on that and try to clarify myself?
Kernel threads are "part of the kernel." As such, they aren't subject to "scheduling policies." If a kernel thread is ready to run, it will run at once, pre-empting any user thread or process as necessary.

The kernel is responsible for creating and for maintaining the "user-land environment." It therefore cannot "wait on" that environment, or be subject, itself, to the scheduling that it provides.

The "kernel thread" analogy only exists for the kernel's convenience: to allow portions of the kernel to, say, "start an I/O operation and wait for it to complete," without introducing a stinkin' wedge "special case" for kernel-initiated vs. user-initiated "operations that need to 'wait.'" (Full disclosure: I have worked on other operating systems that didn't have anything as truly-elegant as this ... and, ahhhhh, "it wasn't pretty." )

Quote:
2) Can multiple scheduling policies be used in the same embedded target in the same image used, like some group of processes use Scheduling policy X and another group of process use Scheduling policy Y like so and so?
You didn't Google very much, or you would have found articles like this one. Or, man 2 sched_setscheduler. (And related: man 7 sched.) Yes, Linux has several scheduling policies that can be applied to tasks individually.

Quote:
3) What is/are the api or system call that will be used to initiate a user space task that can invoked from User Application code?
Try man 2 fork

Quote:
4) how can I pass options like setting the type/name of Scheduling policy for that task, periodicity in which that task has to be invoked, time slice allocated for that task like so and so for user/kernel task ?
See e.g. man 2 sched_setscheduler as noted above.

Quote:
I could not get answers for these from google.
You didn't try very hard, did you?

Nevertheless, I am pleased to try to help you – and so, "hope this helps." But seriously, "you really do need to try harder get better at doing Internet research, because the Internet is fairly-stuffed with information related to these topics.

Last edited by sundialsvcs; 05-22-2017 at 02:31 PM.
 
Old 05-23-2017, 09:35 AM   #5
ayyasprings
Member
 
Registered: Aug 2014
Posts: 118

Original Poster
Rep: Reputation: Disabled
Hi sundialsvcs,

I have another couple of questions.

1) I see in the sched_param like that only sched_priority was implemented.
Code:
struct sched_param {
                 int sched_priority;
                   };
My question is, in Linux, for processes or in any threading library compatible with Linux do we have the option to pass time slice as an argument that a process/thread can execute, while creating a thread or while setting scheduler parameters for a given process, to preempt the current process or thread based on that time slice?
or do the context switching only happens in case of following?
a)waiting for event,
b)request for resources and waiting for that
c)sleep function execution started in the current process or thread
d)current process voluntarily giving control to other process or thread(in case of cooperative OS)
e) like so and so if I left something.

2) Or if we can fix the time quantum of thread or process to preempt, what will be the parameters that will be saved for current process or thread while context switching due to pre-emption?

Please reply!

Last edited by ayyasprings; 05-23-2017 at 09:37 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Help to find the process running by particular user and kill process one by one LittleMaster Linux - Newbie 1 02-09-2013 02:03 PM
Kernel with non-preemptive process scheduling... nik_nik Linux - Newbie 2 05-01-2010 04:06 PM
shared memory between user process and kernel roydcruz Linux - Kernel 9 01-22-2010 04:23 AM
IPC fails between user process and root process zaryab Linux - Newbie 1 09-22-2008 01:25 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 04:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration