Dear All,<br><div class="gmail_quote"><p class="MsoNormal"><br></p><p class="MsoNormal">I was trying the following and had a doubt.</p><p class="MsoNormal"><br></p><p class="MsoNormal">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 :</p><p class="MsoNormal"></p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">1. Take the read lock</p>
<p class="MsoNormal">2. Iterate over
task (for_each_process)</p>
<p class="MsoNormal">3. If my flag is set I unlock
the tasklist_lock and get_task_struct</p>
<p class="MsoNormal">4. Perform the sleepy operation</p>
<p class="MsoNormal">5. Then put_task_struct</p>
<p class="MsoNormal">6. Again take
read_lock(&tasklist_lock);</p>
<p class="MsoNormal">7. Loop continues </p>
<p class="MsoNormal"> </p><p class="MsoNormal">The code snippet is as shown below :</p><p class="MsoNormal"><br></p>
<p class="MsoNormal">read_lock(&tasklist_lock);</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal"> for_each_process(c) {</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal"> if (c->my_flag) {</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal"> read_unlock(&tasklist_lock);</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal"> get_task_struct(c);</p><p class="MsoNormal"><br></p>
<p class="MsoNormal"> ...</p><p class="MsoNormal"><br></p><p class="MsoNormal"></p>
<p class="MsoNormal"> perform_sleepy_operation();</p><p class="MsoNormal"><br></p>
<p class="MsoNormal"> ...</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal"> put_task_struct(c);</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal"> read_lock(&tasklist_lock);</p>
<p class="MsoNormal"> }</p><p class="MsoNormal"></p>
<p class="MsoNormal"> </p>
<p class="MsoNormal"> }</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">Please let me know if this approach is correct.</p><p class="MsoNormal"><br></p><p class="MsoNormal">Thanks and Regards,</p><p class="MsoNormal">Pranami</p>
</div><br>