Unlocking task_list read lock before performing a sleepy operation

Pranami Bhattacharya pranami.bhattacharya at gmail.com
Thu Mar 14 05:45:15 EDT 2013


Dear All,


I was trying the following and had a doubt.


>From my kernel module I want to iterate over task list and do some sleepy
operation for all the process for which my task->flag is set .I know by
holding read_lock(tasklist_lock)/rcu_read_lock I should not be performing
any sleepy operation. So I have coded like below :



1.  Take the read lock

2.  Iterate over task (for_each_process)

3.  If my flag is set I unlock the tasklist_lock and get_task_struct

4.  Perform the sleepy operation

5.  Then put_task_struct

6.  Again take read_lock(&tasklist_lock);

7.  Loop continues



The code snippet is as shown below :


read_lock(&tasklist_lock);



 for_each_process(c) {



  if (c->my_flag) {



          read_unlock(&tasklist_lock);



           get_task_struct(c);


                    ...


                    perform_sleepy_operation();


                     ...



            put_task_struct(c);



             read_lock(&tasklist_lock);

                 }



         }



Please let me know if this approach is correct.


Thanks and Regards,

Pranami
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130314/b66d1266/attachment.html 


More information about the Kernelnewbies mailing list