: SMP-safe freezer
Subsystems (4)
cover : SMP-safe freezer
Hi,
The following two patches are designed to make the task freezer SMP-safe.
The first patch is a controversial one, as Pavel doesn't like it, but I have no other idea how the freezing of stopped tasks could be handled to avoid the problems that it has now. I did my best to explain everything in the changelog.
The second patch is basically needed to make the freezer avoid races with other tasks when modifying the other tasks' flags.
Greetings,
Rafael
Signature · 9 lines
You never change things by fighting the existing reality. R. Buckminster Fuller ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
PATCH 1/2 : PM: Fix handling of stopped tasks
Currently, if a task is stopped (ie. it's in the TASK_STOPPED state), it is considered by the freezer as unfreezeable. However, there may be a race between the freezer and the delivery of the continuation signal to the task resulting in the task running after we have finished freezing other tasks. This, in turn, may lead to undesirable effects up to and including a corruption of data.
To prevent this from happening we first need to make the freezer consider stopped tasks as freezeable. For this purpose we need to make freezeable() stop returning 0 for these tasks. We must remember, however, that the stopped tasks need not receive the continuation signal before thaw_processes() is called, so as soon as PF_FREEZE is set for them try_to_freeze_tasks() should stop counting them as the ones to wait for. Additionally, if there's a traced task (ie. a task in the TASK_TRACED state) the parent of which has PF_FREEZE set and is stopped, try_to_freeze_tasks() should not wait for it. Moreover, if there are some stopped tasks that haven't received the continuation signal before thaw_processes() is called, we must clear PF_FREEZE for them so that they don't go to the refrigerator when it's no longer desirable.
Still if a stopped tasks receives the continuation signal after the freezer has returned, it should immediately go to the refrigerator. For this reason we need to place the call to try_to_freeze() in get_signal_to_deliver() right after the relock label.
It is also reasonable to change the error paths so that the names of stopped or traced tasks which have not frozen are not reported to the user, because in the majority of cases they would be false positives.
--- kernel/power/process.c | 36 ++++++++++++++++++++++++++++++------ kernel/signal.c | 2 +- 2 files changed, 31 insertions(+), 7 deletions(-)
kernel/power/process.c +30 -6
@@ -28,8 +28,7 @@ static inline int freezeable(struct taskif ((p == current) || (p->flags &PF_NOFREEZE ) || (p->exit_state ==EXIT_ZOMBIE ) || - (p->exit_state ==EXIT_DEAD ) || - (p->state ==TASK_STOPPED )) + (p->exit_state ==EXIT_DEAD ))return 0 ;return 1 ; }
@@ -81,6 +80,11 @@ static void cancel_freezing(struct task_ } } +static inline int stopped_and_freezing (struct task_struct *p) +{ +return p->state ==TASK_STOPPED &&freezing (p); +} +static inline int is_user_space (struct task_struct *p) {return p->mm && !(p->flags &PF_BORROWED_MM );
@@ -103,9 +107,11 @@ static unsigned int try_to_freeze_tasks(if (frozen (p))continue ; -if (p->state ==TASK_TRACED && - (frozen (p->parent) || - p->parent->state ==TASK_STOPPED )) { +if (stopped_and_freezing (p)) +continue ; + +if (p->state ==TASK_TRACED && (frozen (p->parent) || +stopped_and_freezing (p->parent))) {cancel_freezing (p);continue ; }
@@ -149,7 +155,8 @@ static unsigned int try_to_freeze_tasks(if (is_user_space (p) == !freeze_user_space)continue ; -if (freezeable (p) && !frozen (p)) +if (freezeable (p) && !frozen (p) && + p->state !=TASK_STOPPED && p->state !=TASK_TRACED )printk (KERN_ERR " %s\n" , p->comm);cancel_freezing (p);
@@ -185,6 +192,18 @@ int freeze_processes(void)return 0 ; } +static void release_stopped_tasks (void ) +{ +struct task_struct *g, *p; + +read_lock (&tasklist_lock); + do_each_thread(g, p) { +if (stopped_and_freezing (p)) +cancel_freezing (p); + }while_each_thread (g, p); +read_unlock (&tasklist_lock); +} +static void thaw_tasks (int thaw_user_space) {struct task_struct *g, *p;
@@ -197,6 +216,10 @@ static void thaw_tasks(int thaw_user_spaif (is_user_space (p) == !thaw_user_space)continue ; +if (!frozen (p) && + (p->state ==TASK_STOPPED || p->state ==TASK_TRACED )) +continue ; +if (!thaw_process (p))printk (KERN_WARNING " Strange, %s not stopped\n" , p->comm );
@@ -207,6 +230,7 @@ static void thaw_tasks(int thaw_user_spavoid thaw_processes (void ) {printk ("Restarting tasks ... " ); +release_stopped_tasks ();thaw_tasks (FREEZER_KERNEL_THREADS );thaw_tasks (FREEZER_USER_SPACE );schedule ();
kernel/signal.c +1 -1
@@ -1937,9 +1937,9 @@ int get_signal_to_deliver(siginfo_t *infsigset_t *mask = ¤t->blocked;int signr =0 ; +relock:try_to_freeze (); -relock:spin_lock_irq (¤t->sighand->siglock);for (;;) {struct k_sigaction *ka;
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Re: [PATCH -mm 1/2]: PM: Fix handling of stopped tasks
Hi!
Quoted 24 lines
Currently, if a task is stopped (ie. it's in the
TASK_STOPPEDstate), it is considered by the freezer as unfreezeable. However, there may be a race between the freezer and the delivery of the continuation signal to the task resulting in the task running after we have finished freezing other tasks. This, in turn, may lead to undesirable effects up to and including a corruption of data.To prevent this from happening we first need to make the freezer consider stopped tasks as freezeable. For this purpose we need to make
freezeable()stop returning 0 for these tasks. We must remember, however, that the stopped tasks need not receive the continuation signal beforethaw_processes()is called, so as soon asPF_FREEZEis set for themtry_to_freeze_tasks()should stop counting them as the ones to wait for. Additionally, if there's a traced task (ie. a task in theTASK_TRACEDstate) the parent of which hasPF_FREEZEset and is stopped,try_to_freeze_tasks()should not wait for it. Moreover, if there are some stopped tasks that haven't received the continuation signal beforethaw_processes()is called, we must clearPF_FREEZEfor them so that they don't go to the refrigerator when it's no longer desirable.Still if a stopped tasks receives the continuation signal after the freezer has returned, it should immediately go to the refrigerator. For this reason we need to place the call to
try_to_freeze()inget_signal_to_deliver()right after the relock label.
Quoted 5 lines
It is also reasonable to change the error paths so that the names of stopped or traced tasks which have not frozen are not reported to the user, because in the majority of cases they would be false positives.
Signed-off-by Rafael J. Wysocki <[email protected]>
Okay, lets go ahead with this one. (ACK) I still think we should be able to find some simpler solution, I'll take a look.
Pavel
Signature · 8 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Re: [PATCH -mm 1/2]: PM: Fix handling of stopped tasks
In reply to Rafael J. WysockiHi!
Quoted 7 lines
Currently, if a task is stopped (ie. it's in the
TASK_STOPPEDstate), it is considered by the freezer as unfreezeable. However, there may be a race between the freezer and the delivery of the continuation signal to the task resulting in the task running after we have finished freezing other tasks. This, in turn, may lead to undesirable effects up to and including a corruption of data.
Quoted 11 lines
To prevent this from happening we first need to make the freezer consider stopped tasks as freezeable. For this purpose we need to make
freezeable()stop returning 0 for these tasks. We must remember, however, that the stopped tasks need not receive the continuation signal beforethaw_processes()is called, so as soon asPF_FREEZEis set for themtry_to_freeze_tasks()should stop counting them as the ones to wait for. Additionally, if there's a traced task (ie. a task in theTASK_TRACEDstate) the parent of which hasPF_FREEZEset and is stopped,try_to_freeze_tasks()should not wait for it. Moreover, if there are some stopped tasks that haven't received the continuation signal beforethaw_processes()is called, we must clearPF_FREEZEfor them so that they don't go to the refrigerator when it's no longer desirable.
Actually, what do you think about this patch? It removes special handling of TASK_TRACED, and should do the trick, too...
Pavel
kernel/power/process.c +1 -2
@@ -26,8 +26,7 @@ static inline int freezeable(struct task (p->flags &PF_NOFREEZE ) || (p->exit_state ==EXIT_ZOMBIE ) || (p->exit_state ==EXIT_DEAD ) || - ((p->exit_state ==TASK_TRACED ) &&frozen (p->parent)) || - (p->state == TASK_STOPPED)) + ((p->exit_state == TASK_TRACED) && frozen(p->parent))) return 0;return 1 ; }
kernel/signal.c +3 -1
@@ -1702,7 +1702,9 @@ finish_stop(int stop_count)read_unlock (&tasklist_lock); } -schedule (); +do { +schedule (); + }while (try_to_freeze ());/* * Now we don't run again until continued. */
Signature · 8 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Re: [PATCH -mm 1/2]: PM: Fix handling of stopped tasks
Hi,
Quoted 21 lines · Pavel Machek
Hi!
Quoted 7 lines
Currently, if a task is stopped (ie. it's in the
TASK_STOPPEDstate), it is considered by the freezer as unfreezeable. However, there may be a race between the freezer and the delivery of the continuation signal to the task resulting in the task running after we have finished freezing other tasks. This, in turn, may lead to undesirable effects up to and including a corruption of data.Quoted 11 lines
To prevent this from happening we first need to make the freezer consider stopped tasks as freezeable. For this purpose we need to make
freezeable()stop returning 0 for these tasks. We must remember, however, that the stopped tasks need not receive the continuation signal beforethaw_processes()is called, so as soon asPF_FREEZEis set for themtry_to_freeze_tasks()should stop counting them as the ones to wait for. Additionally, if there's a traced task (ie. a task in theTASK_TRACEDstate) the parent of which hasPF_FREEZEset and is stopped,try_to_freeze_tasks()should not wait for it. Moreover, if there are some stopped tasks that haven't received the continuation signal beforethaw_processes()is called, we must clearPF_FREEZEfor them so that they don't go to the refrigerator when it's no longer desirable.
Quoted 2 lines
Actually, what do you think about this patch? It removes special handling of
TASK_TRACED, and should do the trick, too...
Well, I don't think so, ....
Quoted 21 lines
Pavel
kernel/power/process.c +1
-2@@ -26,8 +26,7 @@ static inline int freezeable(struct task (p->flags &PF_NOFREEZE ) || (p->exit_state ==EXIT_ZOMBIE ) || (p->exit_state ==EXIT_DEAD ) || - ((p->exit_state ==TASK_TRACED ) &&frozen (p->parent)) || - (p->state == TASK_STOPPED)) + ((p->exit_state == TASK_TRACED) && frozen(p->parent))) return 0;return 1 ; }kernel/signal.c +0
-0
kernel/signal.c finish_stop(int stop_count) · line 1710
Quoted 10 lines
kernel/signal.c +3
-1@@ -1702,7 +1702,9 @@ finish_stop(int stop_count)read_unlock (&tasklist_lock); } -schedule (); +do { +schedule (); + }while (try_to_freeze ());/* * Now we don't run again until continued. */
... because if you want try_to_freeze() here to trigger, then the task in question should have PF_FREEZE set, but we don't set it anywhere. [Actually I think this particular change is equivalent to moving the try_to_freeze() in get_signal_to_deliver() to after the relock label. :-)]
And the special handling of traced tasks is needed to clear TIF_SIGPENDING for a task that had been told to freeze before it's parent froze.
Greetings,
Rafael
Signature · 9 lines
If you don't have the time to read, you don't have the time or the tools to write. - Stephen King ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Re: [PATCH -mm 1/2]: PM: Fix handling of stopped tasks
Hi!
Quoted 9 lines
Quoted 2 lines
Actually, what do you think about this patch? It removes special handling of
TASK_TRACED, and should do the trick, too...Well, I don't think so, ....
Quoted 4 lines
kernel/signal.c +0
-0@@ -1702,7 +1702,9 @@ finish_stop(int stop_count)read_unlock (&tasklist_lock); }
Quoted 10 lines
kernel/signal.c finish_stop(int stop_count) · line 1710
Quoted 7 lines
kernel/signal.c +3
-1-schedule (); +do { +schedule (); + }while (try_to_freeze ());/* * Now we don't run again until continued. */ ... because if you want
try_to_freeze()here to trigger, then the task in question should havePF_FREEZEset, but we don't set it anywhere.
?? We set it to all the processes, so stopped processes get it, too...??
Pavel
Signature · 7 lines
Thanks for all the (sleeping) penguins. ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Re: [PATCH -mm 1/2]: PM: Fix handling of stopped tasks
Hi,
Quoted 22 lines · Pavel Machek
Hi!
Quoted 9 lines
Quoted 2 lines
Actually, what do you think about this patch? It removes special handling of
TASK_TRACED, and should do the trick, too...Well, I don't think so, ....
Quoted 4 lines
kernel/signal.c +0
-0@@ -1702,7 +1702,9 @@ finish_stop(int stop_count)read_unlock (&tasklist_lock); }Quoted 10 lines
kernel/signal.c finish_stop(int stop_count) · line 1710
Quoted 7 lines
kernel/signal.c +3
-1-schedule (); +do { +schedule (); + }while (try_to_freeze ());/* * Now we don't run again until continued. */ ... because if you want
try_to_freeze()here to trigger, then the task in question should havePF_FREEZEset, but we don't set it anywhere.
Quoted 2 lines
?? We set it to all the processes, so stopped processes get it, too...??
No, we don't. We only set it for the processes for which freezeable() returns 1.
Greetings,
Rafael
Signature · 9 lines
If you don't have the time to read, you don't have the time or the tools to write. - Stephen King ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Re: [PATCH -mm 1/2]: PM: Fix handling of stopped tasks
In reply to Pavel MachekHi!
Quoted 19 lines
Quoted 7 lines
Currently, if a task is stopped (ie. it's in the
TASK_STOPPEDstate), it is considered by the freezer as unfreezeable. However, there may be a race between the freezer and the delivery of the continuation signal to the task resulting in the task running after we have finished freezing other tasks. This, in turn, may lead to undesirable effects up to and including a corruption of data.Quoted 11 lines
To prevent this from happening we first need to make the freezer consider stopped tasks as freezeable. For this purpose we need to make
freezeable()stop returning 0 for these tasks. We must remember, however, that the stopped tasks need not receive the continuation signal beforethaw_processes()is called, so as soon asPF_FREEZEis set for themtry_to_freeze_tasks()should stop counting them as the ones to wait for. Additionally, if there's a traced task (ie. a task in theTASK_TRACEDstate) the parent of which hasPF_FREEZEset and is stopped,try_to_freeze_tasks()should not wait for it. Moreover, if there are some stopped tasks that haven't received the continuation signal beforethaw_processes()is called, we must clearPF_FREEZEfor them so that they don't go to the refrigerator when it's no longer desirable.
Quoted 2 lines
Actually, what do you think about this patch? It removes special handling of
TASK_TRACED, and should do the trick, too...
I was surprised, but the patch seems to work okay. Can you replace your 1/2 with this one, and see what breaks?
Pavel
Quoted 31 lines
kernel/power/process.c +1
-2@@ -26,8 +26,7 @@ static inline int freezeable(struct task (p->flags &PF_NOFREEZE ) || (p->exit_state ==EXIT_ZOMBIE ) || (p->exit_state ==EXIT_DEAD ) || - ((p->exit_state ==TASK_TRACED ) &&frozen (p->parent)) || - (p->state == TASK_STOPPED)) + ((p->exit_state == TASK_TRACED) && frozen(p->parent))) return 0;return 1 ; }kernel/signal.c +3
-1@@ -1702,7 +1702,9 @@ finish_stop(int stop_count)read_unlock (&tasklist_lock); } -schedule (); +do { +schedule (); + }while (try_to_freeze ());/* * Now we don't run again until continued. */
Signature · 8 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Re: [PATCH -mm 1/2]: PM: Fix handling of stopped tasks
Hi,
Quoted 21 lines · Pavel Machek
Hi!
Quoted 19 lines
Quoted 18 lines
Currently, if a task is stopped (ie. it's in the
TASK_STOPPEDstate), it is considered by the freezer as unfreezeable. However, there may be a race between the freezer and the delivery of the continuation signal to the task resulting in the task running after we have finished freezing other tasks. This, in turn, may lead to undesirable effects up to and including a corruption of data.To prevent this from happening we first need to make the freezer consider stopped tasks as freezeable. For this purpose we need to make
freezeable()stop returning 0 for these tasks. We must remember, however, that the stopped tasks need not receive the continuation signal beforethaw_processes()is called, so as soon asPF_FREEZEis set for themtry_to_freeze_tasks()should stop counting them as the ones to wait for. Additionally, if there's a traced task (ie. a task in theTASK_TRACEDstate) the parent of which hasPF_FREEZEset and is stopped,try_to_freeze_tasks()should not wait for it. Moreover, if there are some stopped tasks that haven't received the continuation signal beforethaw_processes()is called, we must clearPF_FREEZEfor them so that they don't go to the refrigerator when it's no longer desirable.
Quoted 5 lines
Quoted 2 lines
Actually, what do you think about this patch? It removes special handling of
TASK_TRACED, and should do the trick, too...I was surprised, but the patch seems to work okay. Can you replace your 1/2 with this one, and see what breaks?
I don't think anything will _visibly_ break, because (1) even if the traced task has TIF_SIGPENDING set unnecessarily, it will just notice there is no real signal to handle and continue and (2) the race between the delivery of the continuation signal and the freezer is damn hard to trigger (still I think I can wirte some artificial code that would trigger this, although it would involve a kernel thread sending SIGCONT to a user space process - provided it's permissible ;-)).
Greetings,
Rafael
Signature · 9 lines
If you don't have the time to read, you don't have the time or the tools to write. - Stephen King ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Re: [PATCH -mm 1/2]: PM: Fix handling of stopped tasks
Hi!
Quoted 9 lines
Quoted 5 lines
Quoted 2 lines
Actually, what do you think about this patch? It removes special handling of
TASK_TRACED, and should do the trick, too...I was surprised, but the patch seems to work okay. Can you replace your 1/2 with this one, and see what breaks?
I don't think anything will _visibly_ break, because (1) even if the traced task has
TIF_SIGPENDINGset unnecessarily, it will just notice there is no real signal to handle and continue and
We are generating spurious wakeups, but as you noticed, that should be okay.
Quoted 5 lines
(2) the race between the delivery of
the continuation signal and the freezer is damn hard to trigger (still I think I can wirte some artificial code that would trigger this, although it would involve a kernel thread sending SIGCONT to a user space process - provided it's permissible ;-)).
It is not really permissible, but I do not see how it would hurt...
With that patch, we put TASK_STOPPED tasks into refrigerator, along with everyone else. SIGCONT is *not* going to help them out of refrigerator.
We also ignore TASK_STOPPED now, so we'll not proceed until all stopped tasks are in refrigerator.
Now... I'm not 100% sure I got the ptrace() cases right (and did not test that)... but TASK_STOPPED cases look pretty trivial to me now.
Pavel
Signature · 7 lines
Thanks for all the (sleeping) penguins. ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Re: [PATCH -mm 1/2]: PM: Fix handling of stopped tasks
Hi,
Quoted 8 lines · Pavel Machek
Hi!
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines
Actually, what do you think about this patch? It removes special handling of
TASK_TRACED, and should do the trick, too...I was surprised, but the patch seems to work okay. Can you replace your 1/2 with this one, and see what breaks?
Quoted 6 lines
Quoted 3 lines
I don't think anything will _visibly_ break, because (1) even if the traced task has
TIF_SIGPENDINGset unnecessarily, it will just notice there is no real signal to handle and continue andWe are generating spurious wakeups, but as you noticed, that should be okay.
So we can move the check to freezeable(). Fine.
Quoted 12 lines
Quoted 5 lines
(2) the race between the delivery of
the continuation signal and the freezer is damn hard to trigger (still I think I can wirte some artificial code that would trigger this, although it would involve a kernel thread sending SIGCONT to a user space process - provided it's permissible ;-)).It is not really permissible, but I do not see how it would hurt...
With that patch, we put
TASK_STOPPEDtasks into refrigerator, along with everyone else. SIGCONT is *not* going to help them out of refrigerator.
Quoted 5 lines
We also ignore
TASK_STOPPEDnow, so we'll not proceed until all stopped tasks are in refrigerator.Now... I'm not 100% sure I got the
ptrace()cases right (and did not test that)... butTASK_STOPPEDcases look pretty trivial to me now.
Please note that currently (and with your patch) freezeable() returns 0 for TASK_STOPPED, so we don't set PF_FREEZE for them and my patch changes _exactly_ that and adds some minor (optional) modifications to the error paths.
Greetings,
Rafael
Signature · 9 lines
If you don't have the time to read, you don't have the time or the tools to write. - Stephen King ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Re: [PATCH -mm 1/2]: PM: Fix handling of stopped tasks
Hi,
Quoted 9 lines · Rafael J. Wysocki
Quoted 8 lines · Pavel Machek
Hi!
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines
Actually, what do you think about this patch? It removes special handling of
TASK_TRACED, and should do the trick, too...I was surprised, but the patch seems to work okay. Can you replace your 1/2 with this one, and see what breaks?
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
I don't think anything will _visibly_ break, because (1) even if the traced task has
TIF_SIGPENDINGset unnecessarily, it will just notice there is no real signal to handle and continue andWe are generating spurious wakeups, but as you noticed, that should be okay.
So we can move the check to
freezeable(). Fine.
Oops, not so. We have to reset PF_FREEZE for it too and freezeable() doesn't do that.
Greetings,
Rafael
Signature · 9 lines
If you don't have the time to read, you don't have the time or the tools to write. - Stephen King ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Re: [PATCH -mm 1/2]: PM: Fix handling of stopped tasks
In reply to Rafael J. WysockiHi!
Quoted 12 lines
Quoted 12 lines
Quoted 5 lines
(2) the race between the delivery of
the continuation signal and the freezer is damn hard to trigger (still I think I can wirte some artificial code that would trigger this, although it would involve a kernel thread sending SIGCONT to a user space process - provided it's permissible ;-)).It is not really permissible, but I do not see how it would hurt...
With that patch, we put
TASK_STOPPEDtasks into refrigerator, along with everyone else. SIGCONT is *not* going to help them out of refrigerator.
Quoted 7 lines
Quoted 5 lines
We also ignore
TASK_STOPPEDnow, so we'll not proceed until all stopped tasks are in refrigerator.Now... I'm not 100% sure I got the
ptrace()cases right (and did not test that)... butTASK_STOPPEDcases look pretty trivial to me now.Please note that currently (and with your patch)
freezeable()returns 0 for
I cerainly wanted freezable to return 1 for TASK_STOPPED... and I think this part of my patch should be doing it...?
kernel/power/process.c +1 -2
@@ -26,8 +26,7 @@ static inline int freezeable(struct task (p->flags &PF_NOFREEZE ) || (p->exit_state ==EXIT_ZOMBIE ) || (p->exit_state ==EXIT_DEAD ) || - ((p->exit_state ==TASK_TRACED ) &&frozen (p->parent)) || - (p->state == TASK_STOPPED)) + ((p->exit_state == TASK_TRACED) && frozen(p->parent))) return 0;return 1 ; }
Quoted 3 lines
TASK_STOPPED, so we don't setPF_FREEZEfor them and my patch changes _exactly_ that and adds some minor (optional) modifications to the error paths.
Signature · 7 lines
Thanks for all the (sleeping) penguins. ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Re: [PATCH -mm 1/2]: PM: Fix handling of stopped tasks
Hi,
Quoted 31 lines · Pavel Machek
Hi!
Quoted 12 lines
Quoted 12 lines
Quoted 5 lines
(2) the race between the delivery of
the continuation signal and the freezer is damn hard to trigger (still I think I can wirte some artificial code that would trigger this, although it would involve a kernel thread sending SIGCONT to a user space process - provided it's permissible ;-)).It is not really permissible, but I do not see how it would hurt...
With that patch, we put
TASK_STOPPEDtasks into refrigerator, along with everyone else. SIGCONT is *not* going to help them out of refrigerator.Quoted 7 lines
Quoted 5 lines
We also ignore
TASK_STOPPEDnow, so we'll not proceed until all stopped tasks are in refrigerator.Now... I'm not 100% sure I got the
ptrace()cases right (and did not test that)... butTASK_STOPPEDcases look pretty trivial to me now.Please note that currently (and with your patch)
freezeable()returns 0 forI cerainly wanted freezable to return 1 for
TASK_STOPPED... and I think this part of my patch should be doing it...?kernel/power/process.c +0
-0
kernel/power/process.c static inline int freezeable(struct task · line 32
Quoted 9 lines
kernel/power/process.c +1
-2@@ -26,8 +26,7 @@ static inline int freezeable(struct task (p->flags &PF_NOFREEZE ) || (p->exit_state ==EXIT_ZOMBIE ) || (p->exit_state ==EXIT_DEAD ) || - ((p->exit_state ==TASK_TRACED ) &&frozen (p->parent)) || - (p->state == TASK_STOPPED)) + ((p->exit_state == TASK_TRACED) && frozen(p->parent))) return 0;return 1 ; }
Ah, I didn't notice, sorry.
You should add
(p->exit_state == TASK_TRACED && p->parent->state == TASK_STOPPED) here too, I think.
Also, have you verified that stopped tasks don't go to the refrigerator after thaw_processes() is called?
Greetings,
Rafael
Signature · 9 lines
If you don't have the time to read, you don't have the time or the tools to write. - Stephen King ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Re: [PATCH -mm 1/2]: PM: Fix handling of stopped tasks
In reply to Pavel MachekHi,
Okay, I have replaced my [1/2] with the patch below ...
Quoted 30 lines · Pavel Machek
Hi!
Quoted 7 lines
Currently, if a task is stopped (ie. it's in the
TASK_STOPPEDstate), it is considered by the freezer as unfreezeable. However, there may be a race between the freezer and the delivery of the continuation signal to the task resulting in the task running after we have finished freezing other tasks. This, in turn, may lead to undesirable effects up to and including a corruption of data.Quoted 11 lines
To prevent this from happening we first need to make the freezer consider stopped tasks as freezeable. For this purpose we need to make
freezeable()stop returning 0 for these tasks. We must remember, however, that the stopped tasks need not receive the continuation signal beforethaw_processes()is called, so as soon asPF_FREEZEis set for themtry_to_freeze_tasks()should stop counting them as the ones to wait for. Additionally, if there's a traced task (ie. a task in theTASK_TRACEDstate) the parent of which hasPF_FREEZEset and is stopped,try_to_freeze_tasks()should not wait for it. Moreover, if there are some stopped tasks that haven't received the continuation signal beforethaw_processes()is called, we must clearPF_FREEZEfor them so that they don't go to the refrigerator when it's no longer desirable.Actually, what do you think about this patch? It removes special handling of
TASK_TRACED, and should do the trick, too...
Pavelkernel/power/process.c +0
-0
kernel/power/process.c static inline int freezeable(struct task · line 29
Quoted 6 lines
kernel/power/process.c +1
-2@@ -26,8 +26,7 @@ static inline int freezeable(struct task (p->flags &PF_NOFREEZE ) || (p->exit_state ==EXIT_ZOMBIE ) || (p->exit_state ==EXIT_DEAD ) || - ((p->exit_state ==TASK_TRACED ) &&frozen (p->parent)) || - (p->state == TASK_STOPPED)) + ((p->exit_state == TASK_TRACED) && frozen(p->parent)))
... with the exception that I haven't added the last line, since there's some code in try_to_freeze_tasks() that does the same and better ...
Quoted 10 lines
kernel/power/process.c +0
-0return 0 ;return 1 ; }kernel/signal.c +0
-0
kernel/signal.c finish_stop(int stop_count) · line 1710
Quoted 10 lines
kernel/signal.c +3
-1@@ -1702,7 +1702,9 @@ finish_stop(int stop_count)read_unlock (&tasklist_lock); } -schedule (); +do { +schedule (); + }while (try_to_freeze ());/* * Now we don't run again until continued. */
... and it fails to freeze processes if there's a stopped task (to verify, run vi, press ^Z, and try to suspend).
It happens because we shouldn't count the stopped task as freezeable any more after we've set PF_FREEZE for it and we can fix that by adding
if (p->state == TASK_STOPPED && freezing(p)) continue;
to the main loop in try_to_freeze_tasks(). Then we obtain the appended patch.
<tests again>
Now the stopped task doesn't prevent us from freezing processes. So far so good. [To be continued.]
Greetings,
Rafael
kernel/power/process.c +4 -2
@@ -28,8 +28,7 @@ static inline int freezeable(struct taskif ((p == current) || (p->flags &PF_NOFREEZE ) || (p->exit_state ==EXIT_ZOMBIE ) || - (p->exit_state ==EXIT_DEAD ) || - (p->state ==TASK_STOPPED )) + (p->exit_state ==EXIT_DEAD ))return 0 ;return 1 ; }
@@ -103,6 +102,9 @@ static unsigned int try_to_freeze_tasks(if (frozen (p))continue ; +if (p->state ==TASK_STOPPED &&freezing (p)) +continue ; +if (p->state ==TASK_TRACED && (frozen (p->parent) || p->parent->state ==TASK_STOPPED )) {
kernel/signal.c +3 -1
@@ -1829,7 +1829,9 @@ finish_stop(int stop_count)read_unlock (&tasklist_lock); } -schedule (); +do { +schedule (); + }while (try_to_freeze ());/* * Now we don't run again until continued. */
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Re: [PATCH -mm 1/2]: PM: Fix handling of stopped tasks
Quoted 3 lines · Rafael J. Wysocki
Okay, I have replaced my [1/2] with the patch below ...
On Tuesday, 5 December 2006 11:34, Pavel Machek wrote:
<--snip-->
Quoted 9 lines
... and it fails to freeze processes if there's a stopped task (to verify, run vi, press ^Z, and try to suspend).
It happens because we shouldn't count the stopped task as freezeable any more after we've set
PF_FREEZEfor it and we can fix that by addingif (p->state == TASK_STOPPED && freezing(p)) continue;
Quoted 6 lines
to the main loop in
try_to_freeze_tasks(). Then we obtain the appended patch.<tests again>
Now the stopped task doesn't prevent us from freezing processes. So far so good.
Unfortunately, after the resume the task that was stopped before the suspend goes to the refrigerator as soon as it receives the continuation signal (to verify, run vi, press ^Z, suspend, resume, type fg and look at the output of ps ax - on another terminal, becase this one will be unuseable ;-)).
Hm. It looks like we have to clear the freezing request for the stopped task before we thaw the other processes, but there may be more stopped tasks, so we need to add something like this:
read_lock(&tasklist_lock);
do_each_thread(g, p) {
if (p->state == TASK_STOPPED && freezing(p))
cancel_freezing(p);
} while_each_thread(g, p);
read_unlock(&tasklist_lock);to thaw_processes(). It's cleaner to add it as an inline function, though, and once we've done it, we get the appended patch.
<tests again>
Well, now the task that was stopped before the suspend doesn't go to the refrigerator when it's received the continuation signal after the resume. Good, but is it sufficient? [To be continued.]
kernel/power/process.c +17 -2
@@ -28,8 +28,7 @@ static inline int freezeable(struct taskif ((p == current) || (p->flags &PF_NOFREEZE ) || (p->exit_state ==EXIT_ZOMBIE ) || - (p->exit_state ==EXIT_DEAD ) || - (p->state ==TASK_STOPPED )) + (p->exit_state ==EXIT_DEAD ))return 0 ;return 1 ; }
@@ -103,6 +102,9 @@ static unsigned int try_to_freeze_tasks(if (frozen (p))continue ; +if (p->state ==TASK_STOPPED &&freezing (p)) +continue ; +if (p->state ==TASK_TRACED && (frozen (p->parent) || p->parent->state ==TASK_STOPPED )) {
@@ -185,6 +187,18 @@ int freeze_processes(void)return 0 ; } +static inline void release_stopped_tasks (void ) +{ +struct task_struct *g, *p; + +read_lock (&tasklist_lock); + do_each_thread(g, p) { +if (p->state ==TASK_STOPPED &&freezing (p)) +cancel_freezing (p); + }while_each_thread (g, p); +read_unlock (&tasklist_lock); +} +static void thaw_tasks (int thaw_user_space) {struct task_struct *g, *p;
@@ -207,6 +221,7 @@ static void thaw_tasks(int thaw_user_spavoid thaw_processes (void ) {printk ("Restarting tasks ... " ); +release_stopped_tasks ();thaw_tasks (FREEZER_KERNEL_THREADS );thaw_tasks (FREEZER_USER_SPACE );schedule ();
kernel/signal.c +3 -1
@@ -1829,7 +1829,9 @@ finish_stop(int stop_count)read_unlock (&tasklist_lock); } -schedule (); +do { +schedule (); + }while (try_to_freeze ());/* * Now we don't run again until continued. */
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Re: [Suspend-devel] [PATCH -mm 1/2]: PM: Fix handling of stopped tasks
Quoted 4 lines · Rafael J. Wysocki
Quoted 3 lines · Rafael J. Wysocki
Okay, I have replaced my [1/2] with the patch below ...
On Tuesday, 5 December 2006 11:34, Pavel Machek wrote:
<--snip-->
Quoted 4 lines
Well, now the task that was stopped before the suspend doesn't go to the refrigerator when it's received the continuation signal after the resume. Good, but is it sufficient?
Well, almost.
Namely, if you suspend with a stopped vi and you look at the dmesg output after the resume, there will be something like this:
Restarting tasks ... <4> Strange, vi not stopped
which means that thaw_tasks() is confused by the lurking stopped task. We can fix that by checking if the task in question is not stopped before printing the message in thaw_tasks() and we get this:
kernel/power/process.c | 21 ++++++++++++++++++--- kernel/signal.c | 4 +++- 2 files changed, 21 insertions(+), 4 deletions(-)
kernel/power/process.c +18 -3
@@ -28,8 +28,7 @@ static inline int freezeable(struct taskif ((p == current) || (p->flags &PF_NOFREEZE ) || (p->exit_state ==EXIT_ZOMBIE ) || - (p->exit_state ==EXIT_DEAD ) || - (p->state ==TASK_STOPPED )) + (p->exit_state ==EXIT_DEAD ))return 0 ;return 1 ; }
@@ -103,6 +102,9 @@ static unsigned int try_to_freeze_tasks(if (frozen (p))continue ; +if (p->state ==TASK_STOPPED &&freezing (p)) +continue ; +if (p->state ==TASK_TRACED && (frozen (p->parent) || p->parent->state ==TASK_STOPPED )) {
@@ -185,6 +187,18 @@ int freeze_processes(void)return 0 ; } +static inline void release_stopped_tasks (void ) +{ +struct task_struct *g, *p; + +read_lock (&tasklist_lock); + do_each_thread(g, p) { +if (p->state ==TASK_STOPPED &&freezing (p)) +cancel_freezing (p); + }while_each_thread (g, p); +read_unlock (&tasklist_lock); +} +static void thaw_tasks (int thaw_user_space) {struct task_struct *g, *p;
@@ -197,7 +211,7 @@ static void thaw_tasks(int thaw_user_spaif (is_user_space (p) == !thaw_user_space)continue ; -if (!thaw_process (p)) +if (!thaw_process (p) && p->state !=TASK_STOPPED )printk (KERN_WARNING " Strange, %s not stopped\n" , p->comm ); }while_each_thread (g, p);
@@ -207,6 +221,7 @@ static void thaw_tasks(int thaw_user_spavoid thaw_processes (void ) {printk ("Restarting tasks ... " ); +release_stopped_tasks ();thaw_tasks (FREEZER_KERNEL_THREADS );thaw_tasks (FREEZER_USER_SPACE );schedule ();
kernel/signal.c +3 -1
@@ -1829,7 +1829,9 @@ finish_stop(int stop_count)read_unlock (&tasklist_lock); } -schedule (); +do { +schedule (); + }while (try_to_freeze ());/* * Now we don't run again until continued. */
But now it looks almost like my [1/2], doesn't it? ;-)
Greetings,
Rafael
Signature · 3 lines
If you don't have the time to read, you don't have the time or the tools to write. - Stephen King
Re: [PATCH -mm 1/2]: PM: Fix handling of stopped tasks
In reply to Rafael J. WysockiHi!
Quoted 29 lines
Quoted 8 lines
Actually, what do you think about this patch? It removes special handling of
TASK_TRACED, and should do the trick, too...kernel/power/process.c +0
-0kernel/power/process.c static inline int freezeable(struct task · line 29
Quoted 6 lines
kernel/power/process.c +1
-2@@ -26,8 +26,7 @@ static inline int freezeable(struct task (p->flags &PF_NOFREEZE ) || (p->exit_state ==EXIT_ZOMBIE ) || (p->exit_state ==EXIT_DEAD ) || - ((p->exit_state ==TASK_TRACED ) &&frozen (p->parent)) || - (p->state == TASK_STOPPED)) + ((p->exit_state == TASK_TRACED) && frozen(p->parent)))... with the exception that I haven't added the last line, since there's some code in
try_to_freeze_tasks()that does the same and better ...Quoted 11 lines
kernel/power/process.c +0
-0return 0 ;return 1 ; }kernel/signal.c +0
-0@@ -1702,7 +1702,9 @@ finish_stop(int stop_count)read_unlock (&tasklist_lock); }
Quoted 12 lines
kernel/signal.c finish_stop(int stop_count) · line 1837
Quoted 9 lines
kernel/signal.c +3
-1-schedule (); +do { +schedule (); + }while (try_to_freeze ());/* * Now we don't run again until continued. */ ... and it fails to freeze processes if there's a stopped task (to verify, run vi, press ^Z, and try to suspend).
Huh, I thought I've tested that. Too bad, you are right.
Quoted 5 lines
It happens because we shouldn't count the stopped task as freezeable any more after we've set
PF_FREEZEfor it and we can fix that by addingif (p->state == TASK_STOPPED && freezing(p)) continue;
No, I'd actually like to force stopped task into refrigerator.
Pavel
Signature · 8 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Re: [PATCH -mm 1/2]: PM: Fix handling of stopped tasks
Quoted 46 lines · Pavel Machek
Hi!
Quoted 29 lines
Quoted 8 lines
Actually, what do you think about this patch? It removes special handling of
TASK_TRACED, and should do the trick, too...kernel/power/process.c +0
-0kernel/power/process.c static inline int freezeable(struct task · line 29
Quoted 6 lines
kernel/power/process.c +1
-2@@ -26,8 +26,7 @@ static inline int freezeable(struct task (p->flags &PF_NOFREEZE ) || (p->exit_state ==EXIT_ZOMBIE ) || (p->exit_state ==EXIT_DEAD ) || - ((p->exit_state ==TASK_TRACED ) &&frozen (p->parent)) || - (p->state == TASK_STOPPED)) + ((p->exit_state == TASK_TRACED) && frozen(p->parent)))... with the exception that I haven't added the last line, since there's some code in
try_to_freeze_tasks()that does the same and better ...Quoted 11 lines
kernel/power/process.c +0
-0return 0 ;return 1 ; }kernel/signal.c +0
-0@@ -1702,7 +1702,9 @@ finish_stop(int stop_count)read_unlock (&tasklist_lock); }Quoted 12 lines
kernel/signal.c finish_stop(int stop_count) · line 1837
Quoted 9 lines
kernel/signal.c +3
-1-schedule (); +do { +schedule (); + }while (try_to_freeze ());/* * Now we don't run again until continued. */ ... and it fails to freeze processes if there's a stopped task (to verify, run vi, press ^Z, and try to suspend).
Huh, I thought I've tested that. Too bad, you are right.
Quoted 7 lines
Quoted 5 lines
It happens because we shouldn't count the stopped task as freezeable any more after we've set
PF_FREEZEfor it and we can fix that by addingif (p->state == TASK_STOPPED && freezing(p)) continue;No, I'd actually like to force stopped task into refrigerator.
Well, we'd have to send SIGCONT to them for this purpose and then stop them back again during the resume. Doesn't sound nice ...
Greetings,
Rafael
Signature · 9 lines
If you don't have the time to read, you don't have the time or the tools to write. - Stephen King ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Re: [linux-pm] [PATCH -mm 1/2]: PM: Fix handling of stopped tasks
Hi.
Quoted 10 lines · Rafael J. Wysocki
Quoted 7 lines
Quoted 5 lines
It happens because we shouldn't count the stopped task as freezeable any more after we've set
PF_FREEZEfor it and we can fix that by addingif (p->state == TASK_STOPPED && freezing(p)) continue;No, I'd actually like to force stopped task into refrigerator.
Well, we'd have to send SIGCONT to them for this purpose and then stop them back again during the resume. Doesn't sound nice ...
I agree with Rafael. Contingencies for handling them being restarted by other means is one thing, but restarting tasks that were stopped is wrong. Who knows what work they might do between the SIGCONT and freezing that (and this is the key point) the user doesn't want them to do?
Regards,
Nigel
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Re: [PATCH -mm 1/2]: PM: Fix handling of stopped tasks
In reply to Rafael J. WysockiHi!
Quoted 2 lines
... and it fails to freeze processes if there's a stopped task (to verify, run vi, press ^Z, and try to suspend).
Ok, here's better version. (Notice it only differs by one bit ;-).
Ok, something is still weird. Bash reports spurious...
[2]+ Stopped vi
...after resume. But I think it is right approach. We want to store all the tasks in refrigerator.
Pavel
kernel/power/process.c +2 -3
@@ -26,8 +26,7 @@ static inline int freezeable(struct task (p->flags &PF_NOFREEZE ) || (p->exit_state ==EXIT_ZOMBIE ) || (p->exit_state ==EXIT_DEAD ) || - ((p->exit_state ==TASK_TRACED ) &&frozen (p->parent)) || - (p->state == TASK_STOPPED)) + ((p->exit_state == TASK_TRACED) && frozen(p->parent))) return 0;return 1 ; }
@@ -62,7 +61,7 @@ static inline void freeze_process(structif (!freezing (p)) {freeze (p);spin_lock_irqsave (&p->sighand->siglock, flags); -signal_wake_up (p,0 ); +signal_wake_up (p,1 );spin_unlock_irqrestore (&p->sighand->siglock, flags); } }
kernel/signal.c +3 -1
@@ -1702,7 +1702,9 @@ finish_stop(int stop_count)read_unlock (&tasklist_lock); } -schedule (); +do { +schedule (); + }while (try_to_freeze ());/* * Now we don't run again until continued. */
Pavel
Signature · 8 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Re: [PATCH -mm 1/2]: PM: Fix handling of stopped tasks
Hi,
Quoted 5 lines · Pavel Machek
Hi!
Quoted 2 lines
... and it fails to freeze processes if there's a stopped task (to verify, run vi, press ^Z, and try to suspend).
Quoted 7 lines
Ok, here's better version. (Notice it only differs by one bit ;-).
Ok, something is still weird. Bash reports spurious...
[2]+ Stopped vi
...after resume.
This is because of how signal_wake_up() works, I think..
Quoted 1 line
But I think it is right approach.
Fine by me with a couple of remarks below.
Quoted 9 lines
We want to store all the tasks in refrigerator.
Pavelkernel/power/process.c +0
-0
kernel/power/process.c static inline int freezeable(struct task · line 29
Quoted 6 lines
kernel/power/process.c +1
-2@@ -26,8 +26,7 @@ static inline int freezeable(struct task (p->flags &PF_NOFREEZE ) || (p->exit_state ==EXIT_ZOMBIE ) || (p->exit_state ==EXIT_DEAD ) || - ((p->exit_state ==TASK_TRACED ) &&frozen (p->parent)) || - (p->state == TASK_STOPPED)) + ((p->exit_state == TASK_TRACED) && frozen(p->parent)))
This doesn't apply to -mm as well as to -stable, -git, whatever. There's no
((p->exit_state == TASK_TRACED) && frozen(p->parent)) ||
line here in any of these kernels. Instead, there is a check in try_to_freeze_tasks() that does this.
kernel/power/process.c static inline void freeze_process(struct · line 64
Quoted 9 lines
kernel/power/process.c +1
-1return 0 ;return 1 ; }@@ -62,7 +61,7 @@ static inline void freeze_process(structif (!freezing (p)) {freeze (p);spin_lock_irqsave (&p->sighand->siglock, flags); -signal_wake_up (p,0 ); +signal_wake_up (p,1 );
Do we want traced tasks to get kicked here? If not, we'd have to write our own signal_wake_up() (no big deal, I think) or modify the existing one to be able to kick TASK_STOPPED without kicking TASK_TRACED.
Quoted 8 lines
kernel/power/process.c +0
-0spin_unlock_irqrestore (&p->sighand->siglock, flags); } }kernel/signal.c +0
-0
kernel/signal.c finish_stop(int stop_count) · line 1710
Quoted 10 lines
kernel/signal.c +3
-1@@ -1702,7 +1702,9 @@ finish_stop(int stop_count)read_unlock (&tasklist_lock); } -schedule (); +do { +schedule (); + }while (try_to_freeze ());/* * Now we don't run again until continued. */
Greetings,
Rafael
Signature · 9 lines
If you don't have the time to read, you don't have the time or the tools to write. - Stephen King ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Re: [PATCH -mm 1/2]: PM: Fix handling of stopped tasks
Hi,
Quoted 8 lines · Rafael J. Wysocki
Quoted 7 lines · Pavel Machek
Hi!
Quoted 2 lines
... and it fails to freeze processes if there's a stopped task (to verify, run vi, press ^Z, and try to suspend).
Ok, here's better version. (Notice it only differs by one bit ;-).
Quoted 9 lines
Quoted 5 lines
Ok, something is still weird. Bash reports spurious...
[2]+ Stopped vi
...after resume.
This is because of how
signal_wake_up()works, I think..Quoted 1 line
But I think it is right approach.
Okay, with the appended patch applied everything seems to work and I don't see any undesirable side-effects.
Greetings,
Rafael
kernel/power/process.c | 8 +++++--- kernel/signal.c | 4 +++- 2 files changed, 8 insertions(+), 4 deletions(-)
kernel/power/process.c +5 -3
@@ -28,8 +28,7 @@ static inline int freezeable(struct taskif ((p == current) || (p->flags &PF_NOFREEZE ) || (p->exit_state ==EXIT_ZOMBIE ) || - (p->exit_state ==EXIT_DEAD ) || - (p->state ==TASK_STOPPED )) + (p->exit_state ==EXIT_DEAD ))return 0 ;return 1 ; }
@@ -63,7 +62,10 @@ static inline void freeze_process(structif (!freezing (p)) {freeze (p);spin_lock_irqsave (&p->sighand->siglock, flags); -signal_wake_up (p,0 ); +set_tsk_thread_flag (p,TIF_SIGPENDING ); +if (!wake_up_state (p,TASK_INTERRUPTIBLE |TASK_STOPPED )) +kick_process (p); +spin_unlock_irqrestore (&p->sighand->siglock, flags); } }
kernel/signal.c +3 -1
@@ -1829,7 +1829,9 @@ finish_stop(int stop_count)read_unlock (&tasklist_lock); } -schedule (); +do { +schedule (); + }while (try_to_freeze ());/* * Now we don't run again until continued. */
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Re: [PATCH -mm 1/2]: PM: Fix handling of stopped tasks
Hi!
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
...after resume.
This is because of how
signal_wake_up()works, I think..Quoted 1 line
But I think it is right approach.
Okay, with the appended patch applied everything seems to work and I don't see any undesirable side-effects.
I promise to try it... tommorow. Looks very good to me.
Pavel
Signature · 8 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Re: [Suspend-devel] [PATCH -mm 1/2]: PM: Fix handling of stopped tasks
Hi guys.
Quoted 4 lines · Pavel Machek
Hi!
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
...after resume.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
This is because of how
signal_wake_up()works, I think..Quoted 1 line
But I think it is right approach.
Okay, with the appended patch applied everything seems to work and I don't see any undesirable side-effects.
I promise to try it... tommorow. Looks very good to me.
Just to say sorry for my lack of interaction / feedback. Too busy with other stuff at the moment, but I'm trying to keep track :)
Nigel
Re: [Suspend-devel] [PATCH -mm 1/2]: PM: Fix handling of stopped tasks
In reply to Pavel MachekQuoted 4 lines · Pavel Machek
Hi!
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
...after resume.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
This is because of how
signal_wake_up()works, I think..Quoted 1 line
But I think it is right approach.
Okay, with the appended patch applied everything seems to work and I don't see any undesirable side-effects.
I promise to try it... tommorow. Looks very good to me.
Unfortunately there's one problem with it.
To reproduce it I run "gdb /bin/cat", execute "run" in gdb and press ^Z twice to stop both processes. Next I suspend and resume and run "fg" to get the gdb back.and press "Enter" to get the prompt. Then, it turns out that the terminal echo doesn't work and "Enter" doesn't make it go to the next line. I can recover from this state by typing "fg+Enter" (with no echo) so that /bin/cat gets the continuation signal and it restores the terminal settings, apparently.
This means, however, that with this patch the behavior of a process (gdb) after the resume may be different to its normal behavior, which is wrong.
With my original [1/2] this problem doesn't appear (ie. after the resume gdb behaves normally). Thus I think that, although this patch is much more elegant, my original [1/2] is a safer solution, because we can say exactly what it does.
Greetings,
Rafael
Signature · 3 lines
If you don't have the time to read, you don't have the time or the tools to write. - Stephen King
Re: [PATCH -mm 1/2]: PM: Fix handling of stopped tasks
Hi!
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
...after resume.
This is because of how
signal_wake_up()works, I think..
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
But I think it is right approach.
Okay, with the appended patch applied everything seems to work and I don't see any undesirable side-effects.
I promise to try it... tommorow. Looks very good to me.
Unfortunately there's one problem with it.
Well, IIRC it still had the 'bash reports vi stopped twice' problem.
Quoted 7 lines
To reproduce it I run "gdb
/bin/cat", execute "run" in gdb and press ^Z twice to stop both processes. Next I suspend and resume and run "fg" to get the gdb back.and press "Enter" to get the prompt. Then, it turns out that the terminal echo doesn't work and "Enter" doesn't make it go to the next line. I can recover from this state by typing "fg+Enter" (with no echo) so that/bin/catgets the continuation signal and it restores the terminal settings, apparently.
I wonder if we should start a test suite ;-).
Quoted 2 lines
This means, however, that with this patch the behavior of a process (gdb) after the resume may be different to its normal behavior, which is wrong.
Yep.
Quoted 4 lines
With my original [1/2] this problem doesn't appear (ie. after the resume gdb behaves normally). Thus I think that, although this patch is much more elegant, my original [1/2] is a safer solution, because we can say exactly what it does.
Original 1/2 indeed is 'safer'... but it is also too ugly to live. Getting this to work should not be that hard, and I'd prefer not to add more tricky code to already-tricky process.c.
In the meantime, perhaps we want 2/2 merged? That one was safe&obvious.
Pavel
Signature · 7 lines
Thanks for all the (sleeping) penguins. ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Re: [PATCH -mm 1/2]: PM: Fix handling of stopped tasks
Hi,
Quoted 8 lines · Pavel Machek
Hi!
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 1 line
...after resume.
This is because of how
signal_wake_up()works, I think..Quoted 1 line
But I think it is right approach.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Okay, with the appended patch applied everything seems to work and I don't see any undesirable side-effects.
I promise to try it... tommorow. Looks very good to me.
Unfortunately there's one problem with it.
Well, IIRC it still had the 'bash reports vi stopped twice' problem.
It doesn't do that for me, but ...
Quoted 13 lines
Quoted 7 lines
To reproduce it I run "gdb
/bin/cat", execute "run" in gdb and press ^Z twice to stop both processes. Next I suspend and resume and run "fg" to get the gdb back.and press "Enter" to get the prompt. Then, it turns out that the terminal echo doesn't work and "Enter" doesn't make it go to the next line. I can recover from this state by typing "fg+Enter" (with no echo) so that/bin/catgets the continuation signal and it restores the terminal settings, apparently.I wonder if we should start a test suite ;-).
Quoted 2 lines
This means, however, that with this patch the behavior of a process (gdb) after the resume may be different to its normal behavior, which is wrong.
Quoted 8 lines
Yep.
Quoted 4 lines
With my original [1/2] this problem doesn't appear (ie. after the resume gdb behaves normally). Thus I think that, although this patch is much more elegant, my original [1/2] is a safer solution, because we can say exactly what it does.
Original 1/2 indeed is 'safer'... but it is also too ugly to live.
Well, I don't agree with that. :-)
Quoted 1 line
Getting this to work should not be that hard,
But it would involve messing up with the scheduler, no?
Quoted 4 lines
and I'd prefer not to add more tricky code to already-tricky
process.c.In the meantime, perhaps we want 2/2 merged? That one was safe&obvious.
Sort of. Except I still don't know which architectures are supposed to use the freezer ...
Greetings,
Rafael
Signature · 9 lines
If you don't have the time to read, you don't have the time or the tools to write. - Stephen King ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Re: [PATCH -mm 1/2]: PM: Fix handling of stopped tasks
Hi,
Quoted 40 lines · Rafael J. Wysocki
Quoted 8 lines · Pavel Machek
Hi!
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 1 line
...after resume.
This is because of how
signal_wake_up()works, I think..Quoted 1 line
But I think it is right approach.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Okay, with the appended patch applied everything seems to work and I don't see any undesirable side-effects.
I promise to try it... tommorow. Looks very good to me.
Unfortunately there's one problem with it.
Well, IIRC it still had the 'bash reports vi stopped twice' problem.
It doesn't do that for me, but ...
Quoted 20 lines
Quoted 7 lines
To reproduce it I run "gdb
/bin/cat", execute "run" in gdb and press ^Z twice to stop both processes. Next I suspend and resume and run "fg" to get the gdb back.and press "Enter" to get the prompt. Then, it turns out that the terminal echo doesn't work and "Enter" doesn't make it go to the next line. I can recover from this state by typing "fg+Enter" (with no echo) so that/bin/catgets the continuation signal and it restores the terminal settings, apparently.I wonder if we should start a test suite ;-).
Quoted 2 lines
This means, however, that with this patch the behavior of a process (gdb) after the resume may be different to its normal behavior, which is wrong.
Yep.
Quoted 4 lines
With my original [1/2] this problem doesn't appear (ie. after the resume gdb behaves normally). Thus I think that, although this patch is much more elegant, my original [1/2] is a safer solution, because we can say exactly what it does.
Quoted 9 lines
Quoted 1 line
Original 1/2 indeed is 'safer'... but it is also too ugly to live.
Well, I don't agree with that. :-)
Quoted 1 line
Getting this to work should not be that hard,
But it would involve messing up with the scheduler, no?
Quoted 1 line
and I'd prefer not to add more tricky code to already-tricky
process.c.
BTW, I think the alternative is even more tricky than [1/2] itself, although the trickiness is not clearly visible in this case.
Greetings,
Rafael
Signature · 9 lines
If you don't have the time to read, you don't have the time or the tools to write. - Stephen King ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Re: [PATCH -mm 1/2]: PM: Fix handling of stopped tasks
In reply to Rafael J. WysockiHi,
Quoted 12 lines · Rafael J. Wysocki
Quoted 11 lines · Pavel Machek
Hi!
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
...after resume.
This is because of how
signal_wake_up()works, I think..Quoted 1 line
But I think it is right approach.
Okay, with the appended patch applied everything seems to work and I don't see any undesirable side-effects.
Quoted 22 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
I promise to try it... tommorow. Looks very good to me.
Unfortunately there's one problem with it.
Well, IIRC it still had the 'bash reports vi stopped twice' problem.
It doesn't do that for me, but ...
Quoted 14 lines
Quoted 7 lines
To reproduce it I run "gdb
/bin/cat", execute "run" in gdb and press ^Z twice to stop both processes. Next I suspend and resume and run "fg" to get the gdb back.and press "Enter" to get the prompt. Then, it turns out that the terminal echo doesn't work and "Enter" doesn't make it go to the next line. I can recover from this state by typing "fg+Enter" (with no echo) so that/bin/catgets the continuation signal and it restores the terminal settings, apparently.I wonder if we should start a test suite ;-).
Quoted 2 lines
This means, however, that with this patch the behavior of a process (gdb) after the resume may be different to its normal behavior, which is wrong.
Yep.
Okay, I think I know what to do so that it works. The above symptoms are not present with the appended patch.
Greetings,
Rafael
--- kernel/power/process.c | 12 ++++++------ kernel/signal.c | 4 +++- 2 files changed, 9 insertions(+), 7 deletions(-)
kernel/power/process.c +6 -6
@@ -28,8 +28,7 @@ static inline int freezeable(struct taskif ((p == current) || (p->flags &PF_NOFREEZE ) || (p->exit_state ==EXIT_ZOMBIE ) || - (p->exit_state ==EXIT_DEAD ) || - (p->state ==TASK_STOPPED )) + (p->exit_state ==EXIT_DEAD ))return 0 ;return 1 ; }
@@ -61,9 +60,12 @@ static inline void freeze_process(structunsigned long flags;if (!freezing (p)) { +if (p->state ==TASK_STOPPED ) +force_sig_specific (SIGSTOP , p); +freeze (p);spin_lock_irqsave (&p->sighand->siglock, flags); -signal_wake_up (p,0 ); +signal_wake_up (p, p->state ==TASK_STOPPED );spin_unlock_irqrestore (&p->sighand->siglock, flags); } }
@@ -103,9 +105,7 @@ static unsigned int try_to_freeze_tasks(if (frozen (p))continue ; -if (p->state ==TASK_TRACED && - (frozen (p->parent) || - p->parent->state ==TASK_STOPPED )) { +if (p->state ==TASK_TRACED &&frozen (p->parent)) {cancel_freezing (p);continue ; }
kernel/signal.c +3 -1
@@ -1829,7 +1829,9 @@ finish_stop(int stop_count)read_unlock (&tasklist_lock); } -schedule (); +do { +schedule (); + }while (try_to_freeze ());/* * Now we don't run again until continued. */
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Re: [PATCH -mm 1/2]: PM: Fix handling of stopped tasks
Hi!
Quoted 9 lines
Quoted 6 lines
Quoted 6 lines
I wonder if we should start a test suite ;-).
Quoted 2 lines
This means, however, that with this patch the behavior of a process (gdb) after the resume may be different to its normal behavior, which is wrong.
Yep.
Okay, I think I know what to do so that it works. The above symptoms are not present with the appended patch.
Looks good to me. Thanks for you work!
Pavel
Signature · 8 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Re: [PATCH -mm 1/2]: PM: Fix handling of stopped tasks
Hi,
Quoted 7 lines · Pavel Machek
Hi!
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
I wonder if we should start a test suite ;-).
Quoted 2 lines
This means, however, that with this patch the behavior of a process (gdb) after the resume may be different to its normal behavior, which is wrong.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Yep.
Okay, I think I know what to do so that it works. The above symptoms are not present with the appended patch.
Looks good to me. Thanks for you work!
Well, there's still a race possible in there, if SIGCONT comes after we have forced the SIGSTOP and before we call signal_wake_up().
I think we should force the SIGSTOP and call signal_wake_up() without releasing the lock. I'll try to do something along these lines later today.
Greetings,
Rafael
Signature · 9 lines
If you don't have the time to read, you don't have the time or the tools to write. - Stephen King ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Re: [PATCH -mm 1/2]: PM: Fix handling of stopped tasks
Hi,
Quoted 13 lines · Rafael J. Wysocki
Quoted 12 lines · Pavel Machek
Hi!
Quoted 9 lines
Quoted 6 lines
Quoted 6 lines
I wonder if we should start a test suite ;-).
Quoted 2 lines
This means, however, that with this patch the behavior of a process (gdb) after the resume may be different to its normal behavior, which is wrong.
Yep.
Okay, I think I know what to do so that it works. The above symptoms are not present with the appended patch.
Quoted 7 lines
Quoted 1 line
Looks good to me. Thanks for you work!
Well, there's still a race possible in there, if SIGCONT comes after we have forced the SIGSTOP and before we call
signal_wake_up().I think we should force the SIGSTOP and call
signal_wake_up()without releasing the lock. I'll try to do something along these lines later today.
I think something like the appended patch will do.
Greetings,
Rafael
--- include/linux/sched.h | 1 + kernel/power/process.c | 15 ++++++++------- kernel/signal.c | 16 +++++++++++++++- 3 files changed, 24 insertions(+), 8 deletions(-)
kernel/power/process.c +8 -7
@@ -28,8 +28,7 @@ static inline int freezeable(struct taskif ((p == current) || (p->flags &PF_NOFREEZE ) || (p->exit_state ==EXIT_ZOMBIE ) || - (p->exit_state ==EXIT_DEAD ) || - (p->state ==TASK_STOPPED )) + (p->exit_state ==EXIT_DEAD ))return 0 ;return 1 ; }
@@ -61,9 +60,13 @@ static inline void freeze_process(structunsigned long flags;if (!freezing (p)) { -freeze (p);spin_lock_irqsave (&p->sighand->siglock, flags); -signal_wake_up (p,0 ); +freeze (p); +if (p->state ==TASK_STOPPED ) { +force_sigstop_and_wake_up (p); + }else { +signal_wake_up (p,0 ); + }spin_unlock_irqrestore (&p->sighand->siglock, flags); } }
@@ -103,9 +106,7 @@ static unsigned int try_to_freeze_tasks(if (frozen (p))continue ; -if (p->state ==TASK_TRACED && - (frozen (p->parent) || - p->parent->state ==TASK_STOPPED )) { +if (p->state ==TASK_TRACED &&frozen (p->parent)) {cancel_freezing (p);continue ; }
kernel/signal.c +15 -1
@@ -962,6 +962,18 @@ force_sig_specific(int sig, struct task_ }/* +* Force a SIGSTOP and make the task wake up. +* +* This is needed for the freezing of stopped tasks, because we want them to +* enter the refrigerator and be stopped again immediately after leaving it. +*/ +void force_sigstop_and_wake_up (struct task_struct *t) +{ +specific_send_sig_info (SIGSTOP ,SEND_SIG_FORCED , t); +signal_wake_up (t,1 ); +} + +/* * Test if P wants to take SIG. After we've checked all threads with this, * it's equivalent to finding no threads not blocking SIG. Any threads not * blocking SIG were ruled out because they are not running and already
@@ -1829,7 +1841,9 @@ finish_stop(int stop_count)read_unlock (&tasklist_lock); } -schedule (); +do { +schedule (); + }while (try_to_freeze ());/* * Now we don't run again until continued. */
include/linux/sched.h +1 -0
@@ -1350,6 +1350,7 @@ extern int kill_pg_info(int, struct sigiextern void do_notify_parent (struct task_struct *,int );extern void force_sig (int ,struct task_struct *);extern void force_sig_specific (int ,struct task_struct *); +extern void force_sigstop_and_wake_up (struct task_struct *t);extern int send_sig (int ,struct task_struct *,int );extern void zap_other_threads (struct task_struct *p);extern int kill_pg (pid_t ,int ,int );
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Re: [PATCH -mm 1/2]: PM: Fix handling of stopped tasks
Hi,
Quoted 55 lines · Rafael J. Wysocki
Quoted 13 lines · Rafael J. Wysocki
Quoted 12 lines · Pavel Machek
Hi!
Quoted 9 lines
Quoted 6 lines
Quoted 6 lines
I wonder if we should start a test suite ;-).
Quoted 2 lines
This means, however, that with this patch the behavior of a process (gdb) after the resume may be different to its normal behavior, which is wrong.
Yep.
Okay, I think I know what to do so that it works. The above symptoms are not present with the appended patch.
Quoted 7 lines
Quoted 1 line
Looks good to me. Thanks for you work!
Well, there's still a race possible in there, if SIGCONT comes after we have forced the SIGSTOP and before we call
signal_wake_up().I think we should force the SIGSTOP and call
signal_wake_up()without releasing the lock. I'll try to do something along these lines later today.I think something like the appended patch will do.
Greetings,
RafaelSigned-off-by Rafael J. Wysocki <[email protected]>--- include/linux/sched.h | 1 + kernel/power/process.c | 15 ++++++++------- kernel/signal.c | 16 +++++++++++++++- 3 files changed, 24 insertions(+), 8 deletions(-)Index:
linux-2.6.19-rc6-mm2/kernel/power/process.c
===================================================================kernel/power/process.c +1
-3@@ -28,8 +28,7 @@ static inline int freezeable(struct taskif ((p == current) || (p->flags &PF_NOFREEZE ) || (p->exit_state ==EXIT_ZOMBIE ) || - (p->exit_state ==EXIT_DEAD ) || - (p->state ==TASK_STOPPED )) + (p->exit_state ==EXIT_DEAD ))return 0 ;return 1 ; }@@ -61,9 +60,13 @@ static inline void freeze_process(structunsigned long flags;if (!freezing (p)) { -freeze (p);spin_lock_irqsave (&p->sighand->siglock, flags);
kernel/power/process.c static inline void freeze_process(struct · line 72
Quoted 10 lines
kernel/power/process.c +6
-1-signal_wake_up (p,0 ); +freeze (p); +if (p->state ==TASK_STOPPED ) { +force_sigstop_and_wake_up (p); + }else { +signal_wake_up (p,0 ); + }spin_unlock_irqrestore (&p->sighand->siglock, flags); } }
Ah, freeze(p) need not be under the lock.
Besides, I'm now thinking the previous version is also correct, because even if SIGCONT comes after we have forced SIGSTOP, it will remove the SIGSTOP from the queue and the task's state will change to TASK_RUNNING, so the next signal_wake_up() will do what it should.
I prefer that one, because it's shorter and doesn't affect sched.h. ;-)
Greetings,
Rafael
Signature · 9 lines
If you don't have the time to read, you don't have the time or the tools to write. - Stephen King ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Re: [PATCH -mm 1/2]: PM: Fix handling of stopped tasks
Hi!
Quoted 8 lines
Ah, freeze(p) need not be under the lock.
Besides, I'm now thinking the previous version is also correct, because even if SIGCONT comes after we have forced SIGSTOP, it will remove the SIGSTOP from the queue and the task's state will change to
TASK_RUNNING, so the nextsignal_wake_up()will do what it should.I prefer that one, because it's shorter and doesn't affect
sched.h. ;-)
Okay... consider your latest patches ACKed. (But it would be nice to make them wait in -mm to 2.6.21, I believe this needs testing).
Pavel
Signature · 8 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Re: [PATCH -mm 1/2]: PM: Fix handling of stopped tasks
In reply to Rafael J. WysockiHi,
Quoted 3 lines · Rafael J. Wysocki
Quoted 2 lines · Pavel Machek
Hi!
<--snip-->
Quoted 5 lines
Quoted 2 lines
In the meantime, perhaps we want 2/2 merged? That one was safe&obvious.
Sort of. Except I still don't know which architectures are supposed to use the freezer ...
I think it's reasonable to define TIF_FREEZE for the architectures that include kernel/power/Kconfig into their Kconfigs. :-)
The appended patch does this (applies on top of
http://lists.osdl.org/pipermail/linux-pm/2006-December/004307.html).
Greetings,
Rafael
--- include/asm-arm/thread_info.h | 2 ++ include/asm-frv/thread_info.h | 2 ++ include/asm-i386/thread_info.h | 2 ++ include/asm-ia64/thread_info.h | 2 ++ include/asm-powerpc/thread_info.h | 2 ++ include/asm-sh/thread_info.h | 2 ++ include/asm-x86_64/thread_info.h | 2 ++ include/linux/freezer.h | 11 ++++++----- include/linux/sched.h | 1 - kernel/power/process.c | 17 ++++++++++------- 10 files changed, 30 insertions(+), 13 deletions(-)
include/asm-arm/thread_info.h +2 -0
@@ -137,6 +137,7 @@ extern void iwmmxt_task_switch(struct th#define TIF_POLLING_NRFLAG 16#define TIF_USING_IWMMXT 17#define TIF_MEMDIE 18 +#define TIF_FREEZE 19#define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)#define _TIF_SIGPENDING (1 << TIF_SIGPENDING)
@@ -144,6 +145,7 @@ extern void iwmmxt_task_switch(struct th#define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)#define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG)#define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT) +#define _TIF_FREEZE (1 << TIF_FREEZE)/* * Change these and you break ASM code in entry-common.S
include/asm-ia64/thread_info.h +2 -0
@@ -88,6 +88,7 @@ struct thread_info {#define TIF_MEMDIE 17#define TIF_MCA_INIT 18/* this task is processing MCA or INIT */ #define TIF_DB_DISABLED 19/* debug trap disabled for fsyscall */ +#define TIF_FREEZE 20/* is freezing for suspend */ #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)#define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT)
@@ -98,6 +99,7 @@ struct thread_info {#define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG)#define _TIF_MCA_INIT (1 << TIF_MCA_INIT)#define _TIF_DB_DISABLED (1 << TIF_DB_DISABLED) +#define _TIF_FREEZE (1 << TIF_FREEZE)/* "work to do on user-return" bits */ #define TIF_ALLWORK_MASK (_TIF_NOTIFY_RESUME|_TIF_SIGPENDING|_TIF_NEED_RESCHED|_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT)
include/asm-sh/thread_info.h +2 -0
@@ -106,6 +106,7 @@ static inline struct thread_info *curren#define TIF_USEDFPU 16/* FPU was used by this task this quantum (SMP) */ #define TIF_POLLING_NRFLAG 17/* true if poll_idle() is polling TIF_NEED_RESCHED */ #define TIF_MEMDIE 18 +#define TIF_FREEZE 19#define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)#define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
@@ -114,6 +115,7 @@ static inline struct thread_info *curren#define _TIF_RESTORE_SIGMASK (1<<TIF_RESTORE_SIGMASK)#define _TIF_USEDFPU (1<<TIF_USEDFPU)#define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG) +#define _TIF_FREEZE (1<<TIF_FREEZE)#define _TIF_WORK_MASK 0x000000FE/* work to do on interrupt/exception return */ #define _TIF_ALLWORK_MASK 0x000000FF/* work to do on any return to u-space */
include/asm-frv/thread_info.h +2 -0
@@ -116,6 +116,7 @@ register struct thread_info *__current_t#define TIF_RESTORE_SIGMASK 6/* restore signal mask in do_signal() */ #define TIF_POLLING_NRFLAG 16/* true if poll_idle() is polling TIF_NEED_RESCHED */ #define TIF_MEMDIE 17/* OOM killer killed process */ +#define TIF_FREEZE 18/* freezing for suspend */ #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)#define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
@@ -125,6 +126,7 @@ register struct thread_info *__current_t#define _TIF_IRET (1 << TIF_IRET)#define _TIF_RESTORE_SIGMASK (1 << TIF_RESTORE_SIGMASK)#define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG) +#define _TIF_FREEZE (1 << TIF_FREEZE)#define _TIF_WORK_MASK 0x0000FFFE/* work to do on interrupt/exception return */ #define _TIF_ALLWORK_MASK 0x0000FFFF/* work to do on any return to u-space */
include/asm-i386/thread_info.h +2 -0
@@ -134,6 +134,7 @@ static inline struct thread_info *curren#define TIF_MEMDIE 16#define TIF_DEBUG 17/* uses debug registers */ #define TIF_IO_BITMAP 18/* uses I/O bitmap */ +#define TIF_FREEZE 19/* is freezing for suspend */ #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)#define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
@@ -147,6 +148,7 @@ static inline struct thread_info *curren#define _TIF_RESTORE_SIGMASK (1<<TIF_RESTORE_SIGMASK)#define _TIF_DEBUG (1<<TIF_DEBUG)#define _TIF_IO_BITMAP (1<<TIF_IO_BITMAP) +#define _TIF_FREEZE (1<<TIF_FREEZE)/* work to do on interrupt/exception return */ #define _TIF_WORK_MASK \
include/asm-powerpc/thread_info.h +2 -0
@@ -122,6 +122,7 @@ static inline struct thread_info *curren#define TIF_RESTOREALL 12/* Restore all regs (implies NOERROR) */ #define TIF_NOERROR 14/* Force successful syscall return */ #define TIF_RESTORE_SIGMASK 15/* Restore signal mask in do_signal */ +#define TIF_FREEZE 16/* Freezing for suspend */ /* as above, but as bit values */ #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
@@ -138,6 +139,7 @@ static inline struct thread_info *curren#define _TIF_RESTOREALL (1<<TIF_RESTOREALL)#define _TIF_NOERROR (1<<TIF_NOERROR)#define _TIF_RESTORE_SIGMASK (1<<TIF_RESTORE_SIGMASK) +#define _TIF_FREEZE (1<<TIF_FREEZE)#define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SECCOMP)#define _TIF_USER_WORK_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING | \
include/asm-x86_64/thread_info.h +2 -0
@@ -122,6 +122,7 @@ static inline struct thread_info *stack_#define TIF_MEMDIE 20#define TIF_DEBUG 21/* uses debug registers */ #define TIF_IO_BITMAP 22/* uses I/O bitmap */ +#define TIF_FREEZE 23/* is freezing for suspend */ #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)#define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
@@ -137,6 +138,7 @@ static inline struct thread_info *stack_#define _TIF_ABI_PENDING (1<<TIF_ABI_PENDING)#define _TIF_DEBUG (1<<TIF_DEBUG)#define _TIF_IO_BITMAP (1<<TIF_IO_BITMAP) +#define _TIF_FREEZE (1<<TIF_FREEZE)/* work to do on interrupt/exception return */ #define _TIF_WORK_MASK \
include/linux/freezer.h +6 -5
@@ -14,16 +14,15 @@ static inline int frozen(struct task_str*/ static inline int freezing (struct task_struct *p) { -return p->flags &PF_FREEZE ; +return test_tsk_thread_flag (p,TIF_FREEZE ); }/* * Request that a process be frozen -* FIXME: SMP problem. We may not modify other process' flags! */ static inline void freeze (struct task_struct *p) { - p->flags |=PF_FREEZE ; +set_tsk_thread_flag (p,TIF_FREEZE ); }/*
@@ -31,7 +30,7 @@ static inline void freeze(struct task_st*/ static inline void do_not_freeze (struct task_struct *p) { - p->flags &= ~PF_FREEZE ; +clear_tsk_thread_flag (p,TIF_FREEZE ); }/*
@@ -52,7 +51,9 @@ static inline int thaw_process(struct ta*/ static inline void frozen_process (struct task_struct *p) { - p->flags = (p->flags & ~PF_FREEZE ) |PF_FROZEN ; + p->flags |=PF_FROZEN ; +wmb (); +clear_tsk_thread_flag (p,TIF_FREEZE ); }extern void refrigerator (void );
include/linux/sched.h +0 -1
@@ -1161,7 +1161,6 @@ static inline void put_task_struct(struc#define PF_MEMALLOC 0x00000800/* Allocating memory */ #define PF_FLUSHER 0x00001000/* responsible for disk writeback */ #define PF_USED_MATH 0x00002000/* if unset the fpu must be initialized before use */ -#define PF_FREEZE 0x00004000/* this task is being frozen for suspend now */ #define PF_NOFREEZE 0x00008000/* this thread should not be frozen */ #define PF_FROZEN 0x00010000/* frozen for system suspend */ #define PF_FSTRANS 0x00020000/* inside a filesystem transaction */
kernel/power/process.c +10 -7
@@ -60,13 +60,16 @@ static inline void freeze_process(structunsigned long flags;if (!freezing (p)) { -if (p->state ==TASK_STOPPED ) -force_sig_specific (SIGSTOP , p); - -freeze (p); -spin_lock_irqsave (&p->sighand->siglock, flags); -signal_wake_up (p, p->state ==TASK_STOPPED ); -spin_unlock_irqrestore (&p->sighand->siglock, flags); +rmb (); +if (!frozen (p)) { +if (p->state ==TASK_STOPPED ) +force_sig_specific (SIGSTOP , p); + +freeze (p); +spin_lock_irqsave (&p->sighand->siglock, flags); +signal_wake_up (p, p->state ==TASK_STOPPED ); +spin_unlock_irqrestore (&p->sighand->siglock, flags); + } } }
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
PATCH 2/2 : PM: SMP-safe freezer
In reply to Rafael J. WysockiCurrently, to tell a task that it should go to the refrigerator, we set the PF_FREEZE flag for it and send a fake signal to it. Unfortunately there are two SMP-related problems with this approach. First, a task running on another CPU may be updating its flags while the freezer attempts to set PF_FREEZE for it and this may leave the task's flags in an inconsistent state. Second, there is a potential race between freeze_process() and refrigerator() in which freeze_process() running on one CPU is reading a task's PF_FREEZE flag while refrigerator() running on another CPU has just set PF_FROZEN for the same task and attempts to reset PF_FREEZE for it. If refrigerator wins the race, freeze_process() will state that PF_FREEZE hasn't been set for the task and will set it unnecessarily, so the task will go to the refrigerator once again after it's been thawed.
To solve first of these problems we need to stop using PF_FROZEN to tell tasks that they should go to the refrigerator. Instead, we can introduce a special TIF_*** flag and use it for this purpose, since it is allowed to change the other tasks' TIF_*** flags and there are special calls for it.
To avoid the freeze_process()-refrigerator() race we can make freeze_process() to always check the task's PF_FROZEN flag after it's read its "freeze" flag. We should also make sure that refrigerator() will always reset the task's "freeze" flag after it's set PF_FROZEN for it.
--- include/asm-frv/thread_info.h | 2 ++ include/asm-i386/thread_info.h | 2 ++ include/asm-powerpc/thread_info.h | 2 ++ include/asm-x86_64/thread_info.h | 2 ++ include/linux/freezer.h | 11 ++++++----- include/linux/sched.h | 1 - kernel/power/process.c | 11 +++++++---- 7 files changed, 21 insertions(+), 10 deletions(-)
include/asm-frv/thread_info.h +2 -0
@@ -116,6 +116,7 @@ register struct thread_info *__current_t#define TIF_RESTORE_SIGMASK 6/* restore signal mask in do_signal() */ #define TIF_POLLING_NRFLAG 16/* true if poll_idle() is polling TIF_NEED_RESCHED */ #define TIF_MEMDIE 17/* OOM killer killed process */ +#define TIF_FREEZE 18/* freezing for suspend */ #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)#define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
@@ -125,6 +126,7 @@ register struct thread_info *__current_t#define _TIF_IRET (1 << TIF_IRET)#define _TIF_RESTORE_SIGMASK (1 << TIF_RESTORE_SIGMASK)#define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG) +#define _TIF_FREEZE (1 << TIF_FREEZE)#define _TIF_WORK_MASK 0x0000FFFE/* work to do on interrupt/exception return */ #define _TIF_ALLWORK_MASK 0x0000FFFF/* work to do on any return to u-space */
include/asm-i386/thread_info.h +2 -0
@@ -134,6 +134,7 @@ static inline struct thread_info *curren#define TIF_MEMDIE 16#define TIF_DEBUG 17/* uses debug registers */ #define TIF_IO_BITMAP 18/* uses I/O bitmap */ +#define TIF_FREEZE 19/* is freezing for suspend */ #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)#define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
@@ -147,6 +148,7 @@ static inline struct thread_info *curren#define _TIF_RESTORE_SIGMASK (1<<TIF_RESTORE_SIGMASK)#define _TIF_DEBUG (1<<TIF_DEBUG)#define _TIF_IO_BITMAP (1<<TIF_IO_BITMAP) +#define _TIF_FREEZE (1<<TIF_FREEZE)/* work to do on interrupt/exception return */ #define _TIF_WORK_MASK \
include/asm-powerpc/thread_info.h +2 -0
@@ -122,6 +122,7 @@ static inline struct thread_info *curren#define TIF_RESTOREALL 12/* Restore all regs (implies NOERROR) */ #define TIF_NOERROR 14/* Force successful syscall return */ #define TIF_RESTORE_SIGMASK 15/* Restore signal mask in do_signal */ +#define TIF_FREEZE 16/* Freezing for suspend */ /* as above, but as bit values */ #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
@@ -138,6 +139,7 @@ static inline struct thread_info *curren#define _TIF_RESTOREALL (1<<TIF_RESTOREALL)#define _TIF_NOERROR (1<<TIF_NOERROR)#define _TIF_RESTORE_SIGMASK (1<<TIF_RESTORE_SIGMASK) +#define _TIF_FREEZE (1<<TIF_FREEZE)#define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SECCOMP)#define _TIF_USER_WORK_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING | \
include/asm-x86_64/thread_info.h +2 -0
@@ -122,6 +122,7 @@ static inline struct thread_info *stack_#define TIF_MEMDIE 20#define TIF_DEBUG 21/* uses debug registers */ #define TIF_IO_BITMAP 22/* uses I/O bitmap */ +#define TIF_FREEZE 23/* is freezing for suspend */ #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)#define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
@@ -137,6 +138,7 @@ static inline struct thread_info *stack_#define _TIF_ABI_PENDING (1<<TIF_ABI_PENDING)#define _TIF_DEBUG (1<<TIF_DEBUG)#define _TIF_IO_BITMAP (1<<TIF_IO_BITMAP) +#define _TIF_FREEZE (1<<TIF_FREEZE)/* work to do on interrupt/exception return */ #define _TIF_WORK_MASK \
include/linux/freezer.h +6 -5
@@ -14,16 +14,15 @@ static inline int frozen(struct task_str*/ static inline int freezing (struct task_struct *p) { -return p->flags &PF_FREEZE ; +return test_tsk_thread_flag (p,TIF_FREEZE ); }/* * Request that a process be frozen -* FIXME: SMP problem. We may not modify other process' flags! */ static inline void freeze (struct task_struct *p) { - p->flags |=PF_FREEZE ; +set_tsk_thread_flag (p,TIF_FREEZE ); }/*
@@ -31,7 +30,7 @@ static inline void freeze(struct task_st*/ static inline void do_not_freeze (struct task_struct *p) { - p->flags &= ~PF_FREEZE ; +clear_tsk_thread_flag (p,TIF_FREEZE ); }/*
@@ -52,7 +51,9 @@ static inline int thaw_process(struct ta*/ static inline void frozen_process (struct task_struct *p) { - p->flags = (p->flags & ~PF_FREEZE ) |PF_FROZEN ; + p->flags |=PF_FROZEN ; +wmb (); +clear_tsk_thread_flag (p,TIF_FREEZE ); }extern void refrigerator (void );
include/linux/sched.h +0 -1
@@ -1161,7 +1161,6 @@ static inline void put_task_struct(struc#define PF_MEMALLOC 0x00000800/* Allocating memory */ #define PF_FLUSHER 0x00001000/* responsible for disk writeback */ #define PF_USED_MATH 0x00002000/* if unset the fpu must be initialized before use */ -#define PF_FREEZE 0x00004000/* this task is being frozen for suspend now */ #define PF_NOFREEZE 0x00008000/* this thread should not be frozen */ #define PF_FROZEN 0x00010000/* frozen for system suspend */ #define PF_FSTRANS 0x00020000/* inside a filesystem transaction */
kernel/power/process.c +7 -4
@@ -60,10 +60,13 @@ static inline void freeze_process(structunsigned long flags;if (!freezing (p)) { -freeze (p); -spin_lock_irqsave (&p->sighand->siglock, flags); -signal_wake_up (p,0 ); -spin_unlock_irqrestore (&p->sighand->siglock, flags); +rmb (); +if (!frozen (p)) { +freeze (p); +spin_lock_irqsave (&p->sighand->siglock, flags); +signal_wake_up (p,0 ); +spin_unlock_irqrestore (&p->sighand->siglock, flags); + } } }
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Re: [PATCH -mm 2/2]: PM: SMP-safe freezer
Hi!
Quoted 11 lines
To solve first of these problems we need to stop using
PF_FROZENto tell tasks that they should go to the refrigerator. Instead, we can introduce a special TIF_*** flag and use it for this purpose, since it is allowed to change the other tasks' TIF_*** flags and there are special calls for it.To avoid the freeze_process()-refrigerator() race we can make
freeze_process()to always check the task'sPF_FROZENflag after it's read its "freeze" flag. We should also make sure thatrefrigerator()will always reset the task's "freeze" flag after it's setPF_FROZENfor it.Signed-off-by Rafael J. Wysocki <[email protected]>
ACK.
Pavel
Signature · 8 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Re: [PATCH -mm 2/2]: PM: SMP-safe freezer
Quoted 7 lines · Pavel Machek
Hi!
Quoted 5 lines
To solve first of these problems we need to stop using
PF_FROZENto tell tasks that they should go to the refrigerator. Instead, we can introduce a special TIF_*** flag and use it for this purpose, since it is allowed to change the other tasks' TIF_*** flags and there are special calls for it.
Quoted 8 lines
Quoted 6 lines
To avoid the freeze_process()-refrigerator() race we can make
freeze_process()to always check the task'sPF_FROZENflag after it's read its "freeze" flag. We should also make sure thatrefrigerator()will always reset the task's "freeze" flag after it's setPF_FROZENfor it.Signed-off-by Rafael J. Wysocki <[email protected]>ACK.
But I think I'll need to add TIF_FROZEN for all architectures, because suspend to RAM is supposed to work on all of them, isn't it?
Also, this patch is only sufficient with [1/2] or an alternative solution?
Greetings,
Rafael
Signature · 8 lines
You never change things by fighting the existing reality. R. Buckminster Fuller ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Re: [PATCH -mm 2/2]: PM: SMP-safe freezer
Hi!
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
To solve first of these problems we need to stop using
PF_FROZENto tell tasks that they should go to the refrigerator. Instead, we can introduce a special TIF_*** flag and use it for this purpose, since it is allowed to change the other tasks' TIF_*** flags and there are special calls for it.To avoid the freeze_process()-refrigerator() race we can make
freeze_process()to always check the task'sPF_FROZENflag after it's read its "freeze" flag. We should also make sure thatrefrigerator()will always reset the task's "freeze" flag after it's setPF_FROZENfor it.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Rafael J. Wysocki <[email protected]>ACK.
But I think I'll need to add
TIF_FROZENfor all architectures, because suspend to RAM is supposed to work on all of them, isn't it?
Well, yes, it should be added, but no, I do not think s2ram works on that many machines.
Quoted 1 line
Also, this patch is only sufficient with [1/2] or an alternative solution?
I haven't finished looking at that one. I suspect it is okay, but I'm not sure it is enough.
Pavel
Signature · 7 lines
Thanks for all the (sleeping) penguins. ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Re: [PATCH -mm 2/2]: PM: SMP-safe freezer
Hi,
Quoted 14 lines · Pavel Machek
Hi!
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
To solve first of these problems we need to stop using
PF_FROZENto tell tasks that they should go to the refrigerator. Instead, we can introduce a special TIF_*** flag and use it for this purpose, since it is allowed to change the other tasks' TIF_*** flags and there are special calls for it.To avoid the freeze_process()-refrigerator() race we can make
freeze_process()to always check the task'sPF_FROZENflag after it's read its "freeze" flag. We should also make sure thatrefrigerator()will always reset the task's "freeze" flag after it's setPF_FROZENfor it.Signed-off-by Rafael J. Wysocki <[email protected]>
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
ACK.
But I think I'll need to add
TIF_FROZENfor all architectures, because suspend to RAM is supposed to work on all of them, isn't it?Well, yes, it should be added, but no, I do not think s2ram works on that many machines.
So, do you think I should add any more architectures (which ones?) or leave it as is?
Quoted 4 lines
Quoted 1 line
Also, this patch is only sufficient with [1/2] or an alternative solution?
I haven't finished looking at that one. I suspect it is okay, but I'm not sure it is enough.
Well, I think I haven't overlooked anything, but of course that's always possible. ;-)
Greetings,
Rafael
Signature · 9 lines
If you don't have the time to read, you don't have the time or the tools to write. - Stephen King ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Re: [linux-pm] [PATCH -mm 2/2]: PM: SMP-safe freezer
In reply to Pavel Machek[ off $SUBJECT ]
Quoted 5 lines · Pavel Machek
Quoted 2 lines
But I think I'll need to add
TIF_FROZENfor all architectures, because suspend to RAM is supposed to work on all of them, isn't it?Well, yes, it should be added, but no, I do not think s2ram works on that many machines.
Userspace "s2ram" != PM_SUSPEND_MEM ("suspend-to-RAM") though.
I'm not even sure there's a globally acceptable definition of what PM_SUSPEND_MEM indicates, beyond the fact that one expects it saves more power than PM_SUSPEND_STANDBY.
Yes, the Documentation/power/states.txt regurgitates ACPI spec text. But lots of non-ACPI systems don't have any reason to do things like ACPI says. And in terms of latency, I've seen a lot of that be due to the PM framework taking so long to walk the device tree, with no substantial difference between "standby" and "str" costs.
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Re: [Suspend-devel] [PATCH -mm 2/2]: PM: SMP-safe freezer
Quoted 15 lines · David Brownell
[ off $SUBJECT ]
Quoted 5 lines · Pavel Machek
Quoted 2 lines
But I think I'll need to add
TIF_FROZENfor all architectures, because suspend to RAM is supposed to work on all of them, isn't it?Well, yes, it should be added, but no, I do not think s2ram works on that many machines.
Userspace "s2ram" !=
PM_SUSPEND_MEM("suspend-to-RAM") though.I'm not even sure there's a globally acceptable definition of what
PM_SUSPEND_MEMindicates, beyond the fact that one expects it saves more power thanPM_SUSPEND_STANDBY.
Quoted 5 lines
Yes, the
Documentation/power/states.txtregurgitates ACPI spec text. But lots of non-ACPI systems don't have any reason to do things like ACPI says. And in terms of latency, I've seen a lot of that be due to the PM framework taking so long to walk the device tree, with no substantial difference between "standby" and "str" costs.
Well, in this particular case the question is only which architectures will actually use the freezer. :-)
Greetings,
Rafael
Signature · 3 lines
If you don't have the time to read, you don't have the time or the tools to write. - Stephen King