Re: Access to kernel routine (find_task_by_pid)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Friday 19 August 2005 15:35, canon wrote:
> Even if I am root, I cannot make my program entering the kernel space ?
> I was thinking to write a special scheduler that can be configured to 
> reduce the load of the process, but I have neither the skills nor the 
> time. I suppose that I will keep the current solution if there is no 
> other way.

You have to just create a kernel module as all the user space processes you 
create, also as root, act only on user space functions and not with the 
kernel functions.
Modules run in kernel mode and access to the task_struct you've tried to 
access.
You can take the load value of the processes from the task_struct. 
The counter field, for example, indicates the number of ticks of CPU time left 
to the process before its quantum expires. 
The priority field, instead, indicates the base time quantum (r base priority) 
of the process.

But there are some system calls by which you can modify the desired feature.
These are:
1. sched_getscheduler(): queries the scheduling policy currently applied to 
the process identified by the pid parameter.

2. sched_getparam(): retrieves the scheduling parameters for the process 
identified by pid.

3. sched_yield(): allows a process to relinquish the CPU voluntarily without 
being suspended.

4. sched_rr_get_interval(): should get the round robin time quantum for the 
named real -time process.

I don't know anymore about these system calls, but I think you haven't to 
worry about your skill. 
I suggest you to implement via kernel module as you have better control on 
monitoring process. It's a little more difficult than in user space.
If you can have the book "Understanding Linux Kernel", you can just read the 
chapter named "Process Scheduling" (till the section regarding system calls) 
and, for the timer,  the chapter "timer measuring".
I also suggest you this strategies.

Create a kernel module that have one function set and one function get fro 
each of the field you want to modify.
Then you create a function that initialize a timer and one by which you can 
modify it. 
Finally, a function that make the whole works. First, initializes the timer, 
then call the modifiers of process descriptor fields of monitoring processes.
You can also provide an interface by means the ioctl/read mechanism in order 
to call all these functions by user space. For this, I suggest you to read 
"Linux Device Driver".

For sake of completeness, I lists the chapter you have to study to better 
understand in which way you can implement your project:
- Chapter "Building and Running Modules" from "Linux Device Drivers" (to learn 
building modules)

- Chapter  "Process Scheduling"  from "Understanding Linux Kernel" (Only the 
sections "Scheduling Policy" and "The Scheduling Algorithm" - to better 
understand the mechanism of get/relinquish CPU)

- Chapter "Timing Measurements" from "Understanding Linux Kernel" (Only parts 
of it regarding static and dynamic timers). 
In order to give you the possibilities to skip this chapter, I can provide you 
a brief description of the methods you've to use without the need for you to 
study an entire chapter.

- [optional] Chapter "Char Drivers" and "Advanced Char Driver Operations" to 
better understand the read/write/ioctl mechanism. This is necessary if you 
want to communicate between user space and kernel module.

Vincenzo Mallozzi.


	

	
		
___________________________________ 
Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB 
http://mail.yahoo.it


--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux