Re: Kernel Thread and Kernel Module

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

 



Hi Manish,

It is just a macro that expands to  a for loop. It is
deffined in 
sched.h

#define for_each_process(p) \
     for (p = &init_task ; (p = next_task(p)) !=
&init_task ; )

Right this is a macro. On further investigation, I
found that init_task access init_task_union.task
{defined in include/asm-i386/processor.h} and
next_task is again a macro defined as 
#define next_task(p)    list_entry((p)->tasks.next,
struct task_struct, tasks)

list_entry is again a macro defined in
{include/linux/list.h} as
#define list_entry(ptr, type, member) \
        ((type *)((char *)(ptr)-(unsigned
long)(&((type *)0)->member)))

In this case, macro uses a init_task_union which is
exported by kernel and that should be sufficient for
module to iterate over list. But if macro is using an
kernel symbol i.e function or a global variable, then
these symbols should be exported otherwise use of
macro will give unresolved symbols. Please verfiy my
understanding.

I am trying to use read lock before iterating a task
list.

         read_lock(&tasklist_lock);
         for_each_process(p) {
                        printk ("<1> Iterating Task
List" );
         }
         read_unlock(&tasklist_lock);

But getting following error:
 unresolved symbol __read_lock_failed

I could see that tasklist_lock is being exported from
kernel but how to get a lock on that. I could not see
any exported symbol read_lock/read_unlock.


Please advise.

Regards
Dinesh

--- Manish Regmi <regmi.manish@xxxxxxxxx> wrote:

> On 8/13/06, Dinesh Ahuja <mdlinux7@xxxxxxxxxxx>
> wrote:
> > Hi Rahul/Daniel,
> >
> > I fully agree with you. I am able to iterate task
> > list.
> >
> > But I am little bit confused about one thing. When
> I
> > wrote module and used for_each_process, I was
> > expecting a unresolved error during loading of
> module.
> > This is because for_each_process is not exported
> from
> > static kernel which I can verify from /proc/ksysms
> > output.
> 
> It is just a macro that expands to  a for loop. It
> is deffined in sched.h
> 
> #define for_each_process(p) \
>      for (p = &init_task ; (p = next_task(p)) !=
> &init_task ; )
> 
> regards
> Manish Regmi
> 



		
__________________________________________________________
Yahoo! India Answers: Share what you know. Learn something new
http://in.answers.yahoo.com/

--
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