Trivial: devtmpfsd: Setting task running/interruptible states
PATCH 1/1 Trivial: devtmpfsd: Setting task running/interruptible states
This trivial patch makes the following changes in devtmpfsd() :
- Set the state to TASK_INTERRUPTIBLE using __set_current_state instead of set_current_state as the spin_unlock is an implicit memory barrier.
- After return from schedule(), there is no need to set the current state to TASK_RUNNING as the wake_up_process() function call will do this for us.
--- drivers/base/devtmpfs.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
drivers/base/devtmpfs.c +1 -2
@@ -413,10 +413,9 @@ static int devtmpfsd(void *p) }spin_lock (&req_lock); } -set_current_state (TASK_INTERRUPTIBLE ); +__set_current_state (TASK_INTERRUPTIBLE );spin_unlock (&req_lock);schedule (); -__set_current_state (TASK_RUNNING ); }return 0 ; out:
Signature · 1 line
1.7.4.1
Quoted 1 line · Kautuk Consul
This trivial patch makes the following changes in
devtmpfsd():
This is not the definition of "trivial" in that you are changing the logic of the code, not just doing spelling changes.
Quoted 3 lines
- Set the state to
TASK_INTERRUPTIBLEusing__set_current_stateinstead ofset_current_stateas thespin_unlockis an implicit memory barrier.
Why? What is this hurting with the original code?
Quoted 3 lines
- After return from
schedule(), there is no need to set the current state toTASK_RUNNINGas thewake_up_process()function call will do this for us.
Are you sure?
Have you tested this patch and everything works properly?
greg k-h
Hi Greg,
Quoted 5 lines · Greg KH
Quoted 1 line · Kautuk Consul
This trivial patch makes the following changes in
devtmpfsd():This is not the definition of "trivial" in that you are changing the logic of the code, not just doing spelling changes.
Well, I didn't really change the performance/functionality so I called it trivial.
Quoted 6 lines
Quoted 4 lines
- Set the state to
TASK_INTERRUPTIBLEusing__set_current_stateinstead ofset_current_stateas thespin_unlockis an implicit memory barrier.Why? What is this hurting with the original code?
Nothing really hurting, that's why I called this patch trivial. There is an extra memory barrier we have to go through by way of set_current_state, which is mb().
That would lead to more overhead on the parallel pipelines of the processor as they will have to cease being parallel for instructions before and after the memory barrier despite the fact that the spin_unlock already covers this. We can do without this because as per the Documentation/memory-barriers.txt, atomic operations and unlocks give reliable ordering to instructions.
Quoted 6 lines
Quoted 4 lines
- After return from
schedule(), there is no need to set the current state toTASK_RUNNINGas thewake_up_process()function call will do this for us.Are you sure?
Yes. wake_up_process()->ttwu_queue()->ttwu_do_activate()->ttwu_do_wakeup() will set the task state to TASK_RUNNING. Before that, ttwu_activate()->activate_task()->enqueue_task() will have put the task struct onto the run-queue.
Of course, the rq->lock is held during this which does not allow there to be any race
conditions between the above process and the task actually waking up on a CPU and then proceeding to execute without its task state set to TASK_RUNNING.
Quoted 2 lines
Have you tested this patch and everything works properly?
Yes. It does so on my system. But I did not try any stress tests. If you want me to try out any stress test cases I can do so, but I was convinced after reading the code, documentation and creating a separate kernel module
with a thread and this kind of state setting behavior and things seemed fine then in the sense
that the thread did not sleep due to the task state being continued to be set toTASK_INTERRUPTIBLE after returning from the schedule() function.
Please correct me if I am wrong in any technical assumptions or any point which I might have overlooked.
Quoted 3 lines
greg k-h
Quoted 11 lines · On Wed, Sep 21, 2011 at 09:54:01PM +0530, kautuk.c @samsung.com wrote:
Hi Greg,
Quoted 5 lines · Greg KH
Quoted 1 line · Kautuk Consul
This trivial patch makes the following changes in
devtmpfsd():This is not the definition of "trivial" in that you are changing the logic of the code, not just doing spelling changes.
Well, I didn't really change the performance/functionality so I called it trivial.
You changed the code logic, which is not trivial at all in this area.
And actually unneeded from what I can tell, right?
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines
- Set the state to
TASK_INTERRUPTIBLEusing__set_current_stateinstead ofset_current_stateas thespin_unlockis an implicit memory barrier.Why? What is this hurting with the original code?
Quoted 8 lines
Nothing really hurting, that's why I called this patch trivial. There is an extra memory barrier we have to go through by way of
set_current_state, which ismb().
That would lead to more overhead on the parallel pipelines of the processor as they will have to cease being parallel for instructions before and after the memory barrier despite the fact that thespin_unlockalready covers this. We can do without this because as per theDocumentation/memory-barriers.txt, atomic operations and unlocks give reliable ordering to instructions.
But the current code is correct, and not hurting anything, and it's not on a "fast path" at all, so I'd prefer to keep it as-is and not change it for the sake of changing it, so I'm not going to accept this patch, sorry.
greg k-h
Quoted 7 lines · Greg KH
Quoted 6 lines · On Wed, Sep 21, 2011 at 09:54:01PM +0530, kautuk.c @samsung.com wrote:
Hi Greg,
Quoted 3 lines · Greg KH
Quoted 1 line · Kautuk Consul
This trivial patch makes the following changes in
devtmpfsd():
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
This is not the definition of "trivial" in that you are changing the logic of the code, not just doing spelling changes.
Well, I didn't really change the performance/functionality so I called it trivial.
You changed the code logic,
Hmm. Not the code logic of devtmpfsd as such but of the loop involved.
Quoted 1 line
which is not trivial at all in this area.
Ok.
If you want, maybe I could send another patch for this without marking it "trivial".
Quoted 2 lines
And actually unneeded from what I can tell, right?
Well, there *are* 2 overheads.
As I mentioned, the overheads which I tried to remove by this patch is an extra memory barrier as well as setting of the task state to TASK_RUNNING. Of course, they are very minimal and that's why I called this change "trivial".
Quoted 17 lines
Quoted 8 lines
Quoted 7 lines
Quoted 5 lines
- Set the state to
TASK_INTERRUPTIBLEusing__set_current_stateinstead ofset_current_stateas thespin_unlockis an implicit memory barrier.Why? What is this hurting with the original code?
Quoted 8 lines
Nothing really hurting, that's why I called this patch trivial. There is an extra memory barrier we have to go through by way of
set_current_state, which ismb().
That would lead to more overhead on the parallel pipelines of the processor as they will have to cease being parallel for instructions before and after the memory barrier despite the fact that thespin_unlockalready covers this. We can do without this because as per theDocumentation/memory-barriers.txt, atomic operations and unlocks give reliable ordering to instructions.
Quoted 4 lines
But the current code is correct, and not hurting anything, and it's not on a "fast path" at all, so I'd prefer to keep it as-is and not change it for the sake of changing it, so I'm not going to accept this patch, sorry.
Ok.
However, I see many changes going in which are purely cosmetic like restructuring or clean-up of a function, etc.
So this is a category of change that lies (in importance) between a cosmetic/trivial
change and a minor logic change.
Since this patch is still technically correct, do you mean to say that this cannot even
be looked as some sort of a "technical" cleanup ?
Also, I see you did not include my comment about the removal of the setting of TASK_RUNNING. Do you at least accept that ?
If that is so, maybe you could accept the first patch I sent.
Anyway, thanks for the info.
Quoted 3 lines
greg k-h