public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* sched.c  function
@ 2005-03-24  4:43 sounak chakraborty
  2005-03-24  7:00 ` Jan Engelhardt
  0 siblings, 1 reply; 7+ messages in thread
From: sounak chakraborty @ 2005-03-24  4:43 UTC (permalink / raw)
  To: linux kernel


Dear sir,

 I am new to kernel. I want to know which function in
the file sched.c or procedure is called to bring a
process for processing in the CPU after context
switching. 

Thanks in advance,
Sounak

________________________________________________________________________
Yahoo! India Matrimony: Find your partner online. http://yahoo.shaadi.com/india-matrimony/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: sched.c  function
  2005-03-24  4:43 sounak chakraborty
@ 2005-03-24  7:00 ` Jan Engelhardt
  0 siblings, 0 replies; 7+ messages in thread
From: Jan Engelhardt @ 2005-03-24  7:00 UTC (permalink / raw)
  To: sounak chakraborty; +Cc: linux kernel

>Dear sir,
>
> I am new to kernel. I want to know which function in
>the file sched.c or procedure is called to bring a
>process for processing in the CPU after context
>switching. 

In schedule(), context_switch() is called -- there is not any processing 
needed, the task state is just copied from memory back into CPU
and.. +finished.
There's a finish_task_switch(), though.


Jan Engelhardt
-- 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: sched.c  function
@ 2005-03-24  9:33 sounak chakraborty
  2005-03-24  9:42 ` Jan Engelhardt
  0 siblings, 1 reply; 7+ messages in thread
From: sounak chakraborty @ 2005-03-24  9:33 UTC (permalink / raw)
  To: Oliver Neukum, linux kernel



> What exactly do you want to know about the
> scheduler?
> 
I had a wild idea  to process one function that
repeatedly checks the task list and find out which
process is in which state 

At first i retrieve the information from fork.c in
do_fork() and exit.x in do_exit()
but the problem it showed me is that the information
of the task at the beginnig and at the
end(termination)

but the process may be in different states at
different moment in between these two extremes(start
-- end)

So how to know that .

I can  run for_each process after certain interval of
time , but rather than using timer i thought to set a
value or call the function (for_each_process) whenever
sheduling occurs(that is some process is going to
sleep and some are awakening) that is i am getting
some changes in the task list after that..

is my approch is correct ?
or should i implement timer ?
plz help me 

i am sorry if some of my concepts are wrong as i am
new to kernel and would be obliged if you correct me
thank for your help 
sounak  

________________________________________________________________________
Yahoo! India Matrimony: Find your partner online. http://yahoo.shaadi.com/india-matrimony/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: sched.c  function
  2005-03-24  9:33 sounak chakraborty
@ 2005-03-24  9:42 ` Jan Engelhardt
  0 siblings, 0 replies; 7+ messages in thread
From: Jan Engelhardt @ 2005-03-24  9:42 UTC (permalink / raw)
  To: sounak chakraborty; +Cc: linux kernel


>I had a wild idea to process one function that repeatedly checks the task list
>and find out which process is in which state

Why do not you do so, then? Note that on uniprocessors, all other tasks are
suspended, so their state does not change in between.

Tasks do not change their state without holding a lock. (There is an exception,
but it is justified.)

>I can run for_each process after certain interval of time, but rather than
>using timer i thought to set a value or call the function (for_each_process)
>whenever sheduling occurs(that is some process is going to sleep and some are
>awakening) that is i am getting some changes in the task list after that..

So you want to record task state changes? That is better done at the right
places in the kernel rather than traversing the task list repeatedly (the
latter is not that performant).

>i am sorry if some of my concepts are wrong as i am new to kernel and would be
>obliged if you correct me thank for your help sounak

I would be interested in the background: what do you need to know the task
states for?



Jan Engelhardt
-- 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: sched.c  function
@ 2005-03-24 11:03 sounak chakraborty
  2005-03-24 12:06 ` Jan Engelhardt
  0 siblings, 1 reply; 7+ messages in thread
From: sounak chakraborty @ 2005-03-24 11:03 UTC (permalink / raw)
  To: Jan Engelhardt, linux kernel



> Tasks do not change their state without holding a
> lock. (There is an exception,
> but it is justified.)
list after that..
> 
> So you want to record task state changes? That is
> better done at the right
> places in the kernel rather than traversing the task
> list repeatedly (the
> latter is not that performant).

So you want to say that only one task could be running
at a single time 

but how to know which one 
is there any way without traversing the task list
previously i thought of for_each_process(p)
                        if(p->state==running)

but without this how to find which process is
currently running and other are sleeping 
may it is through "current"

since the current->pid is only running
but i have to run this repeatedly to get the
information of currently running process(since this
may be for a fraction of a second and i can miss that
process if my loop is longer) 
how to do that 
fast timer 
or any other way 
i am little bit confused
                        

> I would be interested in the background: what do you
> need to know the task
> states for?


i want to develop a task manager for threads.
the application reads properly the process information
and the thread information but not able to refresh the
thread information as i am building my own proc file
where only threads are there 
i am distinguishing between process and thread at
fork.c
with clone_vm set..

therefore i need to know which thread is currently
running or not 


there is another problem i am discusing with you 

i want to distinguish between thread and process and
after distinguishing between user thread and kernel
thread 
but i am unable to find any condition which will be
true for kernel level thread during creation and false
for user level thread 
can you help me in this also
thanks 
sounak

________________________________________________________________________
Yahoo! India Matrimony: Find your partner online. http://yahoo.shaadi.com/india-matrimony/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: sched.c  function
  2005-03-24 11:03 sched.c function sounak chakraborty
@ 2005-03-24 12:06 ` Jan Engelhardt
  2005-03-24 16:40   ` Lee Revell
  0 siblings, 1 reply; 7+ messages in thread
From: Jan Engelhardt @ 2005-03-24 12:06 UTC (permalink / raw)
  To: sounak chakraborty; +Cc: linux kernel

>So you want to say that only one task could be running
>at a single time 

per processor, yes.

>but how to know which one 

The kernel is not a separate task. If you call read() for example, you change 
from user to kernel space, so there can be multiple threads being in kernel 
space at the same time (on SMP+) -- there is no process that is _always_ in 
kernelspace.

task_t *current;
is a pointer to the, well, current process (remember that the kernel is not a 
separate proc!)

>is there any way without traversing the task list
>previously i thought of for_each_process(p)
>                        if(p->state==running)

Good idea.

>but without this how to find which process is
>currently running and other are sleeping 
>may it is through "current"

p->state == TASK_RUNNING is (AFAI understand) something different than the 
process that _is_ actually running at this very moment.

>since the current->pid is only running

Usually yes. You probably mix 'running' up with "running in the sense of a 
user, not a kernel developer".

>i want to develop a task manager for threads.
>the application reads properly the process information
>and the thread information but not able to refresh the
>thread information as i am building my own proc file
>where only threads are there 
>i am distinguishing between process and thread at
>fork.c
>with clone_vm set..

A process is the set of all threads with the same
TGID (thread group identifier).

>therefore i need to know which thread is currently
>running or not 

task_t *current;
That one is running.
For SMP, you need a little different variables.

>i want to distinguish between thread and process and
>after distinguishing between user thread and kernel
>thread 

I think there are only kernel threads.

>but i am unable to find any condition which will be
>true for kernel level thread during creation and false
>for user level thread 
>can you help me in this also
>thanks 
>sounak


Jan Engelhardt
-- 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: sched.c  function
  2005-03-24 12:06 ` Jan Engelhardt
@ 2005-03-24 16:40   ` Lee Revell
  0 siblings, 0 replies; 7+ messages in thread
From: Lee Revell @ 2005-03-24 16:40 UTC (permalink / raw)
  To: Jan Engelhardt; +Cc: sounak chakraborty, linux kernel

On Thu, 2005-03-24 at 13:06 +0100, Jan Engelhardt wrote:
> >i want to distinguish between thread and process and
> >after distinguishing between user thread and kernel
> >thread 
> 
> I think there are only kernel threads.
> 

Um... what?  I don't know about you but I run lots of multithreaded user
space apps.

Lee


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2005-03-24 16:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-03-24 11:03 sched.c function sounak chakraborty
2005-03-24 12:06 ` Jan Engelhardt
2005-03-24 16:40   ` Lee Revell
  -- strict thread matches above, loose matches on Subject: below --
2005-03-24  9:33 sounak chakraborty
2005-03-24  9:42 ` Jan Engelhardt
2005-03-24  4:43 sounak chakraborty
2005-03-24  7:00 ` Jan Engelhardt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox