freeze_processes questions
Subsystems (2)
Hi,
I have two questions regarding freeze_processes():
1) Shouldn't we take the TASK_UNINTERRUPTIBLE state into consideration? Now we will fail if a process is sleeping when we try to freeze it.
2) Is it necessary to check p->state == TASK_STOPPED and p->state == TASK_TRACED twice in a row (once in freezable() and then again in the next if ())?
Greets,
Rafael
Signature · 3 lines
- Would you tell me, please, which way I ought to go from here? - That depends a good deal on where you want to get to. -- Lewis Carroll "Alice's Adventures in Wonderland"
Hi!
Quoted 5 lines
I have two questions regarding
freeze_processes():1) Shouldn't we take the
TASK_UNINTERRUPTIBLEstate into consideration? Now we will fail if a process is sleeping when we try to freeze it.
We can't allow processes to sleep at arbitrary places. Therefore we send UNINTERRUPTIBLE task a signal, and hope it can get into refrigerator in time.
Quoted 3 lines
2) Is it necessary to check
p->state==TASK_STOPPEDandp->state==TASK_TRACEDtwice in a row (once infreezable()and then again in the next if ())?
Those tests should probably be killed from if() below. As far as I can see, they can not trigger there.
Pavel
Signature · 2 lines
People were complaining that M$ turns users into beta-testers... ...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!
Hi,
Quoted 10 lines · Pavel Machek
Hi!
Quoted 5 lines
I have two questions regarding
freeze_processes():1) Shouldn't we take the
TASK_UNINTERRUPTIBLEstate into consideration? Now we will fail if a process is sleeping when we try to freeze it.We can't allow processes to sleep at arbitrary places. Therefore we send UNINTERRUPTIBLE task a signal, and hope it can get into refrigerator in time.
Hm, AFAIK we can't kill an UNINTERRUPTIBLE process, can we? Which means that we can't deliver a signal to it too ...
Quoted 6 lines
Quoted 3 lines
2) Is it necessary to check
p->state==TASK_STOPPEDandp->state==TASK_TRACEDtwice in a row (once infreezable()and then again in the next if ())?Those tests should probably be killed from
if()below. As far as I can see, they can not trigger there.
OK, patch follows. :-)
Greets,
Rafael
kernel/power/process.c +1 -3
@@ -70,9 +70,7 @@ int freeze_processes(void)unsigned long flags;if (!freezeable (p))continue ; -if ((p->flags &PF_FROZEN ) || - (p->state ==TASK_TRACED ) || - (p->state ==TASK_STOPPED )) +if (p->flags &PF_FROZEN )continue ;/* FIXME: smp problem here: we may not access other process' flags
Signature · 3 lines
- Would you tell me, please, which way I ought to go from here? - That depends a good deal on where you want to get to. -- Lewis Carroll "Alice's Adventures in Wonderland"
Hi,
Quoted 8 lines · Rafael J. Wysocki
Quoted 7 lines · Pavel Machek
Hi!
Quoted 5 lines
I have two questions regarding
freeze_processes():1) Shouldn't we take the
TASK_UNINTERRUPTIBLEstate into consideration? Now we will fail if a process is sleeping when we try to freeze it.
Quoted 6 lines
Quoted 3 lines
We can't allow processes to sleep at arbitrary places. Therefore we send UNINTERRUPTIBLE task a signal, and hope it can get into refrigerator in time.
Hm, AFAIK we can't kill an UNINTERRUPTIBLE process, can we? Which means that we can't deliver a signal to it too ...
Well, the problem is that signal_wake_up() is not sufficient to make an uninterruptible task get the signal. It only sets TIF_SIGPENDING for the task, which is not quite good, IMHO (when the task finally wakes up, it gets the "signal" and enters refrigerator(), because it has PF_FREEZE set, and stays there forever, as there's nothing that could clear PF_FROZEN for it).
I think it may be fixed in one of the two ways:
1) We can treat uninterruptible tasks as non-freezable (in analogy to stopped tasks) - if all of the other tasks are frozen, nothing can wake up an uninterruptible task, so this seems to be a safe approach.
2) We can try to force uninterruptible tasks to get their "signals" anyway using wake_up_state() directly on them (which I don't like as much).
Greets,
Rafael
Signature · 3 lines
- Would you tell me, please, which way I ought to go from here? - That depends a good deal on where you want to get to. -- Lewis Carroll "Alice's Adventures in Wonderland"
Quoted 3 lines · Rafael J. Wysocki
1) We can treat uninterruptible tasks as non-freezable (in analogy to stopped tasks) - if all of the other tasks are frozen, nothing can wake up an uninterruptible task, so this seems to be a safe approach.
Not true at all. An uninterruptible task can be woken up by an interrupt handler.
Alan Stern
Quoted 8 lines · Alan Stern
Quoted 3 lines · Rafael J. Wysocki
1) We can treat uninterruptible tasks as non-freezable (in analogy to stopped tasks) - if all of the other tasks are frozen, nothing can wake up an uninterruptible task, so this seems to be a safe approach.
Not true at all. An uninterruptible task can be woken up by an interrupt handler.
Right. So it seems we'll have to force uninterruptible tasks to go to the refrigerator().
Greets,
Rafael
Signature · 3 lines
- Would you tell me, please, which way I ought to go from here? - That depends a good deal on where you want to get to. -- Lewis Carroll "Alice's Adventures in Wonderland"
Hi!
Quoted 12 lines
Quoted 11 lines
Quoted 8 lines
Quoted 4 lines
I have two questions regarding
freeze_processes():1) Shouldn't we take the
TASK_UNINTERRUPTIBLEstate into consideration? Now we will fail if a process is sleeping when we try to freeze it.We can't allow processes to sleep at arbitrary places. Therefore we send UNINTERRUPTIBLE task a signal, and hope it can get into refrigerator in time.
Hm, AFAIK we can't kill an UNINTERRUPTIBLE process, can we? Which means that we can't deliver a signal to it too ...
Quoted 6 lines
Well, the problem is that
signal_wake_up()is not sufficient to make an uninterruptible task get the signal. It only setsTIF_SIGPENDINGfor the task, which is not quite good, IMHO (when the task finally wakes up, it gets the "signal" and entersrefrigerator(), because it hasPF_FREEZEset, and stays there forever, as there's nothing that could clearPF_FROZENfor it).
Do you see any problem with UNINTERRUPTIBLE processess? THey should not stay in UNINTERRUPTIBLE state for too long.. If they get back into something normal within timeout, we freeze them just okay.
Quoted 5 lines
I think it may be fixed in one of the two ways:
1) We can treat uninterruptible tasks as non-freezable (in analogy to stopped tasks) - if all of the other tasks are frozen, nothing can wake up an uninterruptible task, so this seems to be a safe approach.
HW event can wake that task up.
Quoted 2 lines
2) We can try to force uninterruptible tasks to get their "signals" anyway using
wake_up_state()directly on them (which I don't like as much).
They are probably uninterruptible for a reason...
If something is staying in UNINTERRUPTIBLE for more than 1 second, it is going to cause problems elsewhere, anyway. Do you see that happening?
Pavel
Signature · 2 lines
People were complaining that M$ turns users into beta-testers... ...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!
Hi,
On Tuesday, 5 of April 2005 22:37, Pavel Machek wrote:
]--snip--[
Quoted 7 lines
Quoted 2 lines
2) We can try to force uninterruptible tasks to get their "signals" anyway using
wake_up_state()directly on them (which I don't like as much).They are probably uninterruptible for a reason...
If something is staying in UNINTERRUPTIBLE for more than 1 second, it is going to cause problems elsewhere, anyway. Do you see that happening?
Probably. Please see, for example, this message sent to l-k:
http://marc.theaimsgroup.com/?l=linux-kernel&m=111268969510393&w=2
I can easily trigger a similar behavior with an uninterruptible task and I have some problems with freezing tasks on SMP that smell like this too.
If we are going to ignore uninterruptible tasks, I'd propose to set PF_FREEZE and TIF_SIGPENDING for them without counting them as "todo" in freeze_processes() (if such a task is woken up afterwards by an interrupt handler, it'll get the "signal" and it'll go to the refrigerator() immediately, because of the PF_FREEZE). At least, I'd do this on resume, as we don't care for these tasks then anyway and IMHO it's not a good idea to fail because of them.
I think we should also clear PF_FREEZE for uninterruptible tasks in thaw_processes(), just in case. :-)
Greets,
Rafael
Signature · 3 lines
- Would you tell me, please, which way I ought to go from here? - That depends a good deal on where you want to get to. -- Lewis Carroll "Alice's Adventures in Wonderland"
Hi!
Quoted 11 lines
Quoted 7 lines
Quoted 2 lines
2) We can try to force uninterruptible tasks to get their "signals" anyway using
wake_up_state()directly on them (which I don't like as much).They are probably uninterruptible for a reason...
If something is staying in UNINTERRUPTIBLE for more than 1 second, it is going to cause problems elsewhere, anyway. Do you see that happening?
Probably. Please see, for example, this message sent to l-k:
http://marc.theaimsgroup.com/?l=linux-kernel&m=111268969510393&w=2
...hmm, perhaps kseriod needs suspend/resume support, or something; but that does not mean we should handle *all* uninterruptible tasks that way.
Quoted 5 lines
I can easily trigger a similar behavior with an uninterruptible task and I have some problems with freezing tasks on SMP that smell like this too.
If we are going to ignore uninterruptible tasks, I'd propose to set
PF_FREEZEandTIF_SIGPENDINGfor them without counting them as "todo" in
You can't just ignore uninterruptible tasks, sorry.
OTOH, if you want working refrigerator, Nigel has one ;-). We were talking about merging it to mainline few times already...
Pavel
Signature · 2 lines
People were complaining that M$ turns users into beta-testers... ...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!
Hi.
Quoted 18 lines · Pavel Machek
Hi!
Quoted 11 lines
Quoted 7 lines
Quoted 2 lines
2) We can try to force uninterruptible tasks to get their "signals" anyway using
wake_up_state()directly on them (which I don't like as much).They are probably uninterruptible for a reason...
If something is staying in UNINTERRUPTIBLE for more than 1 second, it is going to cause problems elsewhere, anyway. Do you see that happening?
Probably. Please see, for example, this message sent to l-k:
http://marc.theaimsgroup.com/?l=linux-kernel&m=111268969510393&w=2
...hmm, perhaps kseriod needs suspend/resume support, or something; but that does not mean we should handle *all* uninterruptible tasks that way.
Quoted 7 lines
Quoted 5 lines
I can easily trigger a similar behavior with an uninterruptible task and I have some problems with freezing tasks on SMP that smell like this too.
If we are going to ignore uninterruptible tasks, I'd propose to set
PF_FREEZEandTIF_SIGPENDINGfor them without counting them as "todo" inYou can't just ignore uninterruptible tasks, sorry.
I don't think Rafael is suggesting ignoring them. He's suggesting what I'm already doing:
- Signal so they enter the freezer if they leave the state;
- Don't count them when deciding whether freezing failed;
- Handle the case where they don't leave the state until post resume (I let them enter the refrigerator, but have code in there to check whether the freezer is still on).
In this way, I handle kseriod and anything else uninterruptible without any problems.
Quoted 2 lines
OTOH, if you want working refrigerator, Nigel has one ;-). We were talking about merging it to mainline few times already...
Sorry. I keep getting preoccupied with other things. I'll get my act together :>
Nigel
Signature · 6 lines
Nigel Cunningham Software Engineer, Canberra, Australia http://www.cyclades.com Bus: +61 (2) 6291 9554; Hme: +61 (2) 6292 8028; Mob: +61 (417) 100 574 Maintainer of Suspend2 Kernel Patches http://suspend2.net
Hi,
Quoted 18 lines · Nigel Cunningham
Hi.
Quoted 15 lines · Pavel Machek
Hi!
Quoted 11 lines
Quoted 7 lines
Quoted 2 lines
2) We can try to force uninterruptible tasks to get their "signals" anyway using
wake_up_state()directly on them (which I don't like as much).They are probably uninterruptible for a reason...
If something is staying in UNINTERRUPTIBLE for more than 1 second, it is going to cause problems elsewhere, anyway. Do you see that happening?
Probably. Please see, for example, this message sent to l-k:
http://marc.theaimsgroup.com/?l=linux-kernel&m=111268969510393&w=2
...hmm, perhaps kseriod needs suspend/resume support, or something;
It seems that anything compiled in (ie not as a module) which ends up in call_usermodehelper() during boot is likely to need this kind of handling.
Quoted 6 lines
Quoted 6 lines
but that does not mean we should handle *all* uninterruptible tasks that way.
Quoted 3 lines
I can easily trigger a similar behavior with an uninterruptible task and I have some problems with freezing tasks on SMP that smell like this too.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
If we are going to ignore uninterruptible tasks, I'd propose to set
PF_FREEZEandTIF_SIGPENDINGfor them without counting them as "todo" inYou can't just ignore uninterruptible tasks, sorry.
I don't think Rafael is suggesting ignoring them.
Words, words ... ;-)
Quoted 6 lines
He's suggesting what I'm already doing:
- Signal so they enter the freezer if they leave the state;
- Don't count them when deciding whether freezing failed;
- Handle the case where they don't leave the state until post resume (I let them enter the refrigerator, but have code in there to check whether the freezer is still on).
Yup. Actaully, I think of something like this (tested once):
kernel/power/process.c +12 -3
@@ -18,6 +18,7 @@*/ #define TIMEOUT (6 * HZ) +static int refrigerator_disabled;static inline int freezeable (struct task_struct * p) {
@@ -47,9 +48,12 @@ void refrigerator(unsigned long flag)recalc_sigpending ();/* We sent fake signal, clean it up */ spin_unlock_irq (¤t->sighand->siglock); - current->flags |=PF_FROZEN ; -while (current->flags &PF_FROZEN ) -schedule (); +if (!refrigerator_disabled) { + current->flags |=PF_FROZEN ; +while (current->flags &PF_FROZEN ) +schedule (); + } +pr_debug ("%s left refrigerator\n" , current->comm); current->state = save; }
@@ -62,6 +66,7 @@ int freeze_processes(void)struct task_struct *g, *p;printk ("Stopping tasks: " ); + refrigerator_disabled =0 ; start_time = jiffies; do { todo = 0;
@@ -72,6 +77,9 @@ int freeze_processes(void)continue ;if (p->flags &PF_FROZEN )continue ; +if ((p->flags &PF_FREEZE ) && + (p->state ==TASK_UNINTERRUPTIBLE )) +continue ;/* FIXME: smp problem here: we may not access other process' flags without locking */
@@ -100,6 +108,7 @@ void thaw_processes(void)struct task_struct *g, *p;printk ("Restarting tasks..." ); + refrigerator_disabled =1 ;read_lock (&tasklist_lock); do_each_thread(g, p) {if (!freezeable (p))
Quoted 3 lines
In this way, I handle kseriod and anything else uninterruptible without any problems.
Exactly. :-)
Greets,
Rafael
Signature · 3 lines
- Would you tell me, please, which way I ought to go from here? - That depends a good deal on where you want to get to. -- Lewis Carroll "Alice's Adventures in Wonderland"
Quoted 10 lines · Nigel Cunningham
I don't think Rafael is suggesting ignoring them. He's suggesting what I'm already doing:
- Signal so they enter the freezer if they leave the state;
- Don't count them when deciding whether freezing failed;
- Handle the case where they don't leave the state until post resume (I let them enter the refrigerator, but have code in there to check whether the freezer is still on).In this way, I handle kseriod and anything else uninterruptible without any problems.
What happens if a process owns a lock needed to suspend a device and it is waiting in TASK_UNINTERRUPTIBLE?
Alan Stern
Hi,
Quoted 10 lines · Alan Stern
Quoted 8 lines · Nigel Cunningham
I don't think Rafael is suggesting ignoring them. He's suggesting what I'm already doing:
- Signal so they enter the freezer if they leave the state;
- Don't count them when deciding whether freezing failed;
- Handle the case where they don't leave the state until post resume (I let them enter the refrigerator, but have code in there to check whether the freezer is still on).
Quoted 5 lines
Quoted 2 lines
In this way, I handle kseriod and anything else uninterruptible without any problems.
What happens if a process owns a lock needed to suspend a device and it is waiting in
TASK_UNINTERRUPTIBLE?
Well, we're in trouble. :-)
However, if any process that we have frozen owns such a lock, we're in trouble too. Thus it won't help if we forcibly freeze the uninterruptible process. Worse yet, there won't be any way to wake it up afterwards. OTOH, if we leave it in TASK_UNINTERRUPTIBLE, it may (potentially) be woken up by an interrupt handler (as you pointed out previously :-)) and release the lock.
Frankly, I can't see any probable scenario leading to this kind of trouble. Seemingly, it would require someone to take a lock and (knowingly) do something that could end up in uninterruptible sleep, which IMHO is not a good idea.
Greets,
Rafael
Signature · 3 lines
- Would you tell me, please, which way I ought to go from here? - That depends a good deal on where you want to get to. -- Lewis Carroll "Alice's Adventures in Wonderland"
Quoted 11 lines · Rafael J. Wysocki
Quoted 2 lines
What happens if a process owns a lock needed to suspend a device and it is waiting in
TASK_UNINTERRUPTIBLE?Well, we're in trouble. :-)
However, if any process that we have frozen owns such a lock, we're in trouble too. Thus it won't help if we forcibly freeze the uninterruptible process. Worse yet, there won't be any way to wake it up afterwards. OTOH, if we leave it in
TASK_UNINTERRUPTIBLE, it may (potentially) be woken up by an interrupt handler (as you pointed out previously :-)) and release the lock.
Quoted 4 lines
Frankly, I can't see any probable scenario leading to this kind of trouble. Seemingly, it would require someone to take a lock and (knowingly) do something that could end up in uninterruptible sleep, which IMHO is not a good idea.
It happens all the time in the USB core, when dealing with a newly-connected device.
Alan Stern
Hi!
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
I don't think Rafael is suggesting ignoring them. He's suggesting what I'm already doing:
- Signal so they enter the freezer if they leave the state;
- Don't count them when deciding whether freezing failed;
- Handle the case where they don't leave the state until post resume (I let them enter the refrigerator, but have code in there to check whether the freezer is still on).In this way, I handle kseriod and anything else uninterruptible without any problems.
Quoted 7 lines
Quoted 2 lines
What happens if a process owns a lock needed to suspend a device and it is waiting in
TASK_UNINTERRUPTIBLE?Well, we're in trouble. :-)
However, if any process that we have frozen owns such a lock, we're in trouble too.
No, we are not. Processes can't own any locks when they are in refrigerator... It is not ok to call refrigerator from any context where you own a lock.
OTOH it is okay to enter TASK_UNINTERRUPTIBLE with locks held.
Pavel
Signature · 1 line
Boycott Kodak -- for their patent abuse against Java.
Quoted 9 lines · Alan Stern
Quoted 4 lines · Rafael J. Wysocki
Frankly, I can't see any probable scenario leading to this kind of trouble. Seemingly, it would require someone to take a lock and (knowingly) do something that could end up in uninterruptible sleep, which IMHO is not a good idea.
It happens all the time in the USB core, when dealing with a newly-connected device.
True, it does happen then. One of many examples of where the USB team must regularly deal with issues that some simpler driver stacks are able to avoid ... or at least think they're able to avoid. (Hotplugging and hot-unplugging tend to complicate things.)
That said, why wouldn't that be a good idea? The locking infrastructure in Linux was certainly designed to make that work properly. And it's common in other operating systems too. Tasks block each other all the time; it's simpler to adopt that model than the alternatives, and hence a lot easier to maintain.
- Dave
Quoted 3 lines · Nigel Cunningham
In this way, I handle kseriod and anything else uninterruptible without any problems.
This may be off-topic for this thread ... but does anyone have system wakeup from PS/2 keyboard/mouse working?
Last time I tried to use it, it didn't work. Not clear where the problem was, but I suspect it was a case of ACPI support not having anything to hook up to in the driver.
Hence the (potential) relevance on this thread: the current approach to suspend/resume in serio drivers needing updating, which may interact with how kseriod is used.
- Dave
Hi,
Quoted 16 lines · Pavel Machek
Hi!
Quoted 14 lines
Quoted 13 lines
Quoted 10 lines
I don't think Rafael is suggesting ignoring them. He's suggesting what I'm already doing:
- Signal so they enter the freezer if they leave the state;
- Don't count them when deciding whether freezing failed;
- Handle the case where they don't leave the state until post resume (I let them enter the refrigerator, but have code in there to check whether the freezer is still on).In this way, I handle kseriod and anything else uninterruptible without any problems.
What happens if a process owns a lock needed to suspend a device and it is waiting in
TASK_UNINTERRUPTIBLE?
Quoted 8 lines
Quoted 4 lines
Well, we're in trouble. :-)
However, if any process that we have frozen owns such a lock, we're in trouble too.
No, we are not. Processes can't own any locks when they are in refrigerator... It is not ok to call refrigerator from any context where you own a lock.
I didn't mean a lock in general, but a lock that is needed to suspend a device. If a process holding that lock is frozen, the _suspend() routine for the device won't complete, because it won't be able to get the lock. IOW it will go to sleep and we are single-threaded at that time ... Or am I missing anything?
Rafael
Signature · 3 lines
- Would you tell me, please, which way I ought to go from here? - That depends a good deal on where you want to get to. -- Lewis Carroll "Alice's Adventures in Wonderland"
Hi David.
Quoted 7 lines · David Brownell
Quoted 3 lines · Nigel Cunningham
In this way, I handle kseriod and anything else uninterruptible without any problems.
This may be off-topic for this thread ... but does anyone have system wakeup from PS/2 keyboard/mouse working?
Never tried it, I'm afraid. My keyboard has 'Power', 'Sleep' and 'Wake' buttons, but they seem to be directly connected to /dev/null.
There's a /proc/acpi entry that controls the enabling wake events. Have you tried fiddling with it?
Regards,
Nigel
Quoted 11 lines
Last time I tried to use it, it didn't work. Not clear where the problem was, but I suspect it was a case of ACPI support not having anything to hook up to in the driver.
Hence the (potential) relevance on this thread: the current approach to suspend/resume in serio drivers needing updating, which may interact with how kseriod is used.
- Dave
Signature · 6 lines
Nigel Cunningham Software Engineer, Canberra, Australia http://www.cyclades.com Bus: +61 (2) 6291 9554; Hme: +61 (2) 6292 8028; Mob: +61 (417) 100 574 Maintainer of Suspend2 Kernel Patches http://suspend2.net
Hi.
Quoted 20 lines · Rafael J. Wysocki
Quoted 19 lines · Pavel Machek
Quoted 18 lines
Quoted 8 lines
Quoted 8 lines
I don't think Rafael is suggesting ignoring them. He's suggesting what I'm already doing:
- Signal so they enter the freezer if they leave the state;
- Don't count them when deciding whether freezing failed;
- Handle the case where they don't leave the state until post resume (I let them enter the refrigerator, but have code in there to check whether the freezer is still on).Quoted 5 lines
Quoted 2 lines
In this way, I handle kseriod and anything else uninterruptible without any problems.
What happens if a process owns a lock needed to suspend a device and it is waiting in
TASK_UNINTERRUPTIBLE?Well, we're in trouble. :-)
However, if any process that we have frozen owns such a lock, we're in trouble too.
Quoted 8 lines
Quoted 3 lines
No, we are not. Processes can't own any locks when they are in refrigerator... It is not ok to call refrigerator from any context where you own a lock.
I didn't mean a lock in general, but a lock that is needed to suspend a device. If a process holding that lock is frozen, the
_suspend()routine for the device won't complete, because it won't be able to get the lock. IOW it will go to sleep and we are single-threaded at that time ... Or am I missing anything?
Whenever this topic comes up, the discussion is always abstract. If someone could think of a lock that might actually deadlock suspending, we look seriously at the issue. In the meantime, all I can say, from roughly three years of developing and testing, is that it never seems to happen. And yes, I know that doesn't necessarily mean it can't.
Perhaps it helps to remember that we're using bdev_io routines. All of the filesystem locking is completely out of the picture. Furthermore, we flush (well Suspend2 does) all pending I/O before freezing kernel threads.
Regards,
Nigel
Signature · 6 lines
Nigel Cunningham Software Engineer, Canberra, Australia http://www.cyclades.com Bus: +61 (2) 6291 9554; Hme: +61 (2) 6292 8028; Mob: +61 (417) 100 574 Maintainer of Suspend2 Kernel Patches http://suspend2.net
Quoted 8 lines · Nigel Cunningham
Hi David.
Quoted 5 lines · David Brownell
Quoted 3 lines · Nigel Cunningham
In this way, I handle kseriod and anything else uninterruptible without any problems.
Quoted 8 lines
Quoted 2 lines
This may be off-topic for this thread ... but does anyone have system wakeup from PS/2 keyboard/mouse working?
Never tried it, I'm afraid. My keyboard has 'Power', 'Sleep' and 'Wake' buttons, but they seem to be directly connected to
/dev/null.There's a
/proc/acpientry that controls the enabling wake events. Have you tried fiddling with it?
That's what didn't work. (Combined with entering S1 then trying to use the relevant buttons ... or for that matter, any buttons.)
- Dave
Quoted 24 lines
Regards,
Nigel
Quoted 11 lines
Last time I tried to use it, it didn't work. Not clear where the problem was, but I suspect it was a case of ACPI support not having anything to hook up to in the driver.
Hence the (potential) relevance on this thread: the current approach to suspend/resume in serio drivers needing updating, which may interact with how kseriod is used.
- Dave
Signature · 6 lines
Nigel Cunningham Software Engineer, Canberra, Australia http://www.cyclades.com Bus: +61 (2) 6291 9554; Hme: +61 (2) 6292 8028; Mob: +61 (417) 100 574 Maintainer of Suspend2 Kernel Patches http://suspend2.net
Hi,
Quoted 27 lines · Nigel Cunningham
Hi.
Quoted 24 lines · Rafael J. Wysocki
Quoted 22 lines · Pavel Machek
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
I don't think Rafael is suggesting ignoring them. He's suggesting what I'm already doing:
- Signal so they enter the freezer if they leave the state;
- Don't count them when deciding whether freezing failed;
- Handle the case where they don't leave the state until post resume (I let them enter the refrigerator, but have code in there to check whether the freezer is still on).In this way, I handle kseriod and anything else uninterruptible without any problems.
Quoted 7 lines
Quoted 2 lines
What happens if a process owns a lock needed to suspend a device and it is waiting in
TASK_UNINTERRUPTIBLE?Well, we're in trouble. :-)
However, if any process that we have frozen owns such a lock, we're in trouble too.
No, we are not. Processes can't own any locks when they are in refrigerator... It is not ok to call refrigerator from any context where you own a lock.
Quoted 8 lines
Quoted 4 lines
I didn't mean a lock in general, but a lock that is needed to suspend a device. If a process holding that lock is frozen, the
_suspend()routine for the device won't complete, because it won't be able to get the lock. IOW it will go to sleep and we are single-threaded at that time ... Or am I missing anything?Whenever this topic comes up, the discussion is always abstract. If someone could think of a lock that might actually deadlock suspending, we look seriously at the issue.
Well, (having thought about it for a while) why, actually, a device's _suspend() routine would need such a lock? Devices are suspended on one CPU in a single thread which can only (potentially) race with interrupt handlers ...
Quoted 2 lines
In the meantime, all I can say, from roughly three years of developing and testing, is that it never seems to happen.
Well, I have much less experience, but I don't think it's likely to happen, too. :-)
Greets,
Rafael
Signature · 3 lines
- Would you tell me, please, which way I ought to go from here? - That depends a good deal on where you want to get to. -- Lewis Carroll "Alice's Adventures in Wonderland"
Hi!
Quoted 5 lines
Quoted 2 lines
In this way, I handle kseriod and anything else uninterruptible without any problems.
This may be off-topic for this thread ... but does anyone have system wakeup from PS/2 keyboard/mouse working?
It worked for me from PS/2 keyboard... I did not set up anything on linux side, I just enabled it with bios. It worked okay with both ACPI/S3 and swsusp...
Pavel
Signature · 1 line
Boycott Kodak -- for their patent abuse against Java.
Hi!
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 2 lines
What happens if a process owns a lock needed to suspend a device and it is waiting in
TASK_UNINTERRUPTIBLE?Well, we're in trouble. :-)
However, if any process that we have frozen owns such a lock, we're in trouble too.
Quoted 6 lines
Quoted 3 lines
No, we are not. Processes can't own any locks when they are in refrigerator... It is not ok to call refrigerator from any context where you own a lock.
I didn't mean a lock in general, but a lock that is needed to suspend a device.
Processes in refrigerator are not allowed to own any locks. That means they may not own a lock that is needed to suspend a device ;-).
OTOH... we may want to move completely away from refrigerator. Its quite a hack, and it device support is okay, we'll not really need it.
Pavel
Signature · 1 line
Boycott Kodak -- for their patent abuse against Java.
Hi,
Quoted 14 lines · Pavel Machek
Hi!
Quoted 12 lines
Quoted 11 lines
Quoted 7 lines
Quoted 2 lines
What happens if a process owns a lock needed to suspend a device and it is waiting in
TASK_UNINTERRUPTIBLE?Well, we're in trouble. :-)
However, if any process that we have frozen owns such a lock, we're in trouble too.
No, we are not. Processes can't own any locks when they are in refrigerator... It is not ok to call refrigerator from any context where you own a lock.
Quoted 5 lines
Quoted 2 lines
I didn't mean a lock in general, but a lock that is needed to suspend a device.
Processes in refrigerator are not allowed to own any locks. That means they may not own a lock that is needed to suspend a device ;-).
I am confused now. AFAICS, we don't check anywhere if a process we are going to freeze holds any locks. If we have a task in TASK_INTERRUPTIBLE, we just send it a fake signal which causes it to go to the refrigerator(). Could you please tell me how we prevent such a task from holding any locks? [It probably doesn't matter, at least practically, but ...? :-)]
Quoted 2 lines
OTOH... we may want to move completely away from refrigerator. Its quite a hack, and it device support is okay, we'll not really need it.
Still, it won't happen soon, I guess. :-) As of today, we have the refrigerator and the processes in TASK_UNINTERRUPTIBLE are mishandled. I think we should do something about it, at least for now, until we drop the refrigerator altogether (if we are going to drop it). That's why I started the discussion and sent the patch.
Greets,
Rafael
Signature · 3 lines
- Would you tell me, please, which way I ought to go from here? - That depends a good deal on where you want to get to. -- Lewis Carroll "Alice's Adventures in Wonderland"
Hi.
Quoted 6 lines · Rafael J. Wysocki
I am confused now. AFAICS, we don't check anywhere if a process we are going to freeze holds any locks. If we have a task in
TASK_INTERRUPTIBLE, we just send it a fake signal which causes it to go to therefrigerator(). Could you please tell me how we prevent such a task from holding any locks? [It probably doesn't matter, at least practically, but ...? :-)]
Checking that no locks aren't held is impossible at the moment afaik. There's no 'I'm holding n locks counter'. And even if there were, if you get rid of the refrigerator, you still can't guarantee that you won't deadlock against processes grabbing locks after your atomic copy.
Dropping the freezer also means you're forever limiting suspend to writing a maximum of one half of memory - unless you're going to do non-atomic images.
Quoted 8 lines
Quoted 2 lines
OTOH... we may want to move completely away from refrigerator. Its quite a hack, and it device support is okay, we'll not really need it.
Still, it won't happen soon, I guess. :-) As of today, we have the refrigerator and the processes in
TASK_UNINTERRUPTIBLEare mishandled. I think we should do something about it, at least for now, until we drop the refrigerator altogether (if we are going to drop it). That's why I started the discussion and sent the patch.
I believe dropping the refrigerator is a fundamentally broken idea. You have to (at least) stop processes doing disk I/O (otherwise the snapshot you just took won't match the on-disk state). At the same time, though, you still need I/O to work for your suspend implementation. You're then talking about putting nous in the drivers which says "Hold this I/O, it's not suspend but process this - it's suspend."
Regards,
Nigel
Signature · 6 lines
Nigel Cunningham Software Engineer, Canberra, Australia http://www.cyclades.com Bus: +61 (2) 6291 9554; Hme: +61 (2) 6292 8028; Mob: +61 (417) 100 574 Maintainer of Suspend2 Kernel Patches http://suspend2.net
Quoted 2 lines · Rafael J. Wysocki
I am confused now. AFAICS, we don't check anywhere if a process we are going to freeze holds any locks.
You're not supposed to check. If the process is running in userspace then it can't be holding any locks, by definition. If it's running in the kernel then it's supposed to do its own checking. It won't call refrigerator() unless it knows that no locks are held.
Quoted 5 lines
If we have a task in
TASK_INTERRUPTIBLE, we just send it a fake signal which causes it to go to therefrigerator(). Could you please tell me how we prevent such a task from holding any locks? [It probably doesn't matter, at least practically, but ...? :-)]
You can't prevent it, and what you're doing is a mistake.
Quoted 8 lines
Quoted 2 lines
OTOH... we may want to move completely away from refrigerator. Its quite a hack, and it device support is okay, we'll not really need it.
Still, it won't happen soon, I guess. :-) As of today, we have the refrigerator and the processes in
TASK_UNINTERRUPTIBLEare mishandled. I think we should do something about it, at least for now, until we drop the refrigerator altogether (if we are going to drop it). That's why I started the discussion and sent the patch.
It's very simple. Processes in TASK_UNINTERRUPTIBLE can't be put in the refrigerator, so you have to wait until they can be put there. If that means waiting more than 10 seconds or so, you should just give up. Return an error and put a message in the log saying something like "Can't suspend because process XXX is busy".
Alan Stern
Quoted 3 lines · Rafael J. Wysocki
Well, (having thought about it for a while) why, actually, a device's
_suspend()routine would need such a lock? Devices are suspended on one CPU in a single thread which can only (potentially) race with interrupt handlers ...
You're blinded by thinking that suspend() can be called only during a system sleep transition. Don't forget about runtime power management!
Alan Stern
Quoted 5 lines · Nigel Cunningham
Whenever this topic comes up, the discussion is always abstract. If someone could think of a lock that might actually deadlock suspending, we look seriously at the issue. In the meantime, all I can say, from roughly three years of developing and testing, is that it never seems to happen. And yes, I know that doesn't necessarily mean it can't.
I agree with Nigel. Certainly in the USB part of the kernel the uninterruptible sleeps all have rather short, bounded durations. Furthermore they correspond to specific events -- a new device is plugged in -- which are unlikely to occur just as the system is going to sleep.
Alan Stern
Hi,
Quoted 8 lines · Alan Stern
Quoted 3 lines · Rafael J. Wysocki
Well, (having thought about it for a while) why, actually, a device's
_suspend()routine would need such a lock? Devices are suspended on one CPU in a single thread which can only (potentially) race with interrupt handlers ...You're blinded by thinking that
suspend()can be called only during a system sleep transition.
Well, yes. :-)
Quoted 1 line
Don't forget about runtime power management!
Of course you're right. Thanks for pointing this out.
Greets,
Rafael
Signature · 3 lines
- Would you tell me, please, which way I ought to go from here? - That depends a good deal on where you want to get to. -- Lewis Carroll "Alice's Adventures in Wonderland"
Hi,
Quoted 8 lines · Alan Stern
Quoted 5 lines · Nigel Cunningham
Whenever this topic comes up, the discussion is always abstract. If someone could think of a lock that might actually deadlock suspending, we look seriously at the issue. In the meantime, all I can say, from roughly three years of developing and testing, is that it never seems to happen. And yes, I know that doesn't necessarily mean it can't.
Quoted 4 lines
I agree with Nigel. Certainly in the USB part of the kernel the uninterruptible sleeps all have rather short, bounded durations. Furthermore they correspond to specific events -- a new device is plugged in -- which are unlikely to occur just as the system is going to sleep.
Strangely enough, I agree with him too. :-) Still, Nigel says he is handling uninterruptible tasks in the way that I was thinking of (as far as I understand it), which you say is a mistake ...
Greets,
Rafael
Signature · 3 lines
- Would you tell me, please, which way I ought to go from here? - That depends a good deal on where you want to get to. -- Lewis Carroll "Alice's Adventures in Wonderland"
Hi,
Quoted 9 lines · Alan Stern
Quoted 2 lines · Rafael J. Wysocki
I am confused now. AFAICS, we don't check anywhere if a process we are going to freeze holds any locks.
You're not supposed to check. If the process is running in userspace then it can't be holding any locks, by definition. If it's running in the kernel then it's supposed to do its own checking. It won't call
refrigerator()unless it knows that no locks are held.
Oh, well. The processes that are running in the kernel always enter the refrigerator voluntarily ...
]--snip--[
Quoted 11 lines
Quoted 8 lines
Quoted 2 lines
OTOH... we may want to move completely away from refrigerator. Its quite a hack, and it device support is okay, we'll not really need it.
Still, it won't happen soon, I guess. :-) As of today, we have the refrigerator and the processes in
TASK_UNINTERRUPTIBLEare mishandled. I think we should do something about it, at least for now, until we drop the refrigerator altogether (if we are going to drop it). That's why I started the discussion and sent the patch.It's very simple. Processes in
TASK_UNINTERRUPTIBLEcan't be put in the refrigerator, so you have to wait until they can be put there.
It seems that if a process calls wait_for_completion() right before suspend, the other task supposed to complete its completion may be accidentally frozen before it's able to do this. It looks like this happens to kseroid sometimes on suspend-during-resume.
Quoted 3 lines
If that means waiting more than 10 seconds or so, you should just give up. Return an error and put a message in the log saying something like "Can't suspend because process XXX is busy".
OK, that's what we do now. Except that IMO we should clear the PF_FREEZE flag for this process and do recalc_sigpending() for it after we give up, because otherwise it will enter the refrigerator sooner or later and it will stay there. Alternatively, we can disable the "freezing loop" in refrigerator() as soon as thaw_processes() is started. Also, we can avoid setting PF_FREEZE for processes in TASK_UNINTERRUPTIBLE, but count them as "freezable". Etc.
Greets,
Rafael
Signature · 3 lines
- Would you tell me, please, which way I ought to go from here? - That depends a good deal on where you want to get to. -- Lewis Carroll "Alice's Adventures in Wonderland"
Quoted 7 lines · Rafael J. Wysocki
Quoted 2 lines
It's very simple. Processes in
TASK_UNINTERRUPTIBLEcan't be put in the refrigerator, so you have to wait until they can be put there.It seems that if a process calls
wait_for_completion()right before suspend, the other task supposed to complete its completion may be accidentally frozen before it's able to do this. It looks like this happens to kseroid sometimes on suspend-during-resume.
You mean, when a suspend occurs so soon after a resume that the resume has fully completed yet? Aren't there interlocks to prevent that sort of thing from happening?
Anyway, if a process is waiting for something that's not going to happen because some other process is frozen, then the suspend should fail. I don't see any other choice. However, it might help in some situations to send a FREEZE message to some device drivers before putting processes in the refrigerator -- especially drivers that use a kernel thread.
Quoted 10 lines
Quoted 3 lines
If that means waiting more than 10 seconds or so, you should just give up. Return an error and put a message in the log saying something like "Can't suspend because process XXX is busy".
OK, that's what we do now. Except that IMO we should clear the
PF_FREEZEflag for this process and dorecalc_sigpending()for it after we give up, because otherwise it will enter the refrigerator sooner or later and it will stay there. Alternatively, we can disable the "freezing loop" inrefrigerator()as soon asthaw_processes()is started. Also, we can avoid settingPF_FREEZEfor processes inTASK_UNINTERRUPTIBLE, but count them as "freezable". Etc.
Yes, all the necessary cleanup steps should be taken.
Alan Stern
Hi,
Quoted 5 lines · Alan Stern
Quoted 3 lines · Rafael J. Wysocki
Quoted 2 lines
It's very simple. Processes in
TASK_UNINTERRUPTIBLEcan't be put in the refrigerator, so you have to wait until they can be put there.
Quoted 7 lines
Quoted 4 lines
It seems that if a process calls
wait_for_completion()right before suspend, the other task supposed to complete its completion may be accidentally frozen before it's able to do this. It looks like this happens to kseroid sometimes on suspend-during-resume.You mean, when a suspend occurs so soon after a resume that the resume has fully completed yet?
No.
During resume, we boot the kernel, check if there's an image to read and (if there's one) we freeze processes using the refrigerator (we need to get rid of them so that we can restore the image safely). Then, it seems, on some systems, freeze_processes() may be called before all of the compiled-in drivers complete their initialization. In particular, kseriod calls usermodehelper at that time, which makes it wait uninterruptibly for a helper process to complete. If that helper process is frozen, we end up with the uninterruptible kseriod that we can't freeze and _resume_ fails, which is not nice, especially that we don't need to care for this kseriod, as we are going to restore the image in a while ...
Perhaps we should not use the refrigerator during resume, or we could use a slightly modified version? I don't know.
Greets,
Rafael
Signature · 3 lines
- Would you tell me, please, which way I ought to go from here? - That depends a good deal on where you want to get to. -- Lewis Carroll "Alice's Adventures in Wonderland"
Hi,
Quoted 1 line · Alan Stern
On Thu, 7 Apr 2005, Rafael J. Wysocki wrote:
]--snip--[
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
If that means waiting more than 10 seconds or so, you should just give up. Return an error and put a message in the log saying something like "Can't suspend because process XXX is busy".
Quoted 8 lines
Quoted 6 lines
OK, that's what we do now. Except that IMO we should clear the
PF_FREEZEflag for this process and dorecalc_sigpending()for it after we give up, because otherwise it will enter the refrigerator sooner or later and it will stay there. Alternatively, we can disable the "freezing loop" inrefrigerator()as soon asthaw_processes()is started. Also, we can avoid settingPF_FREEZEfor processes inTASK_UNINTERRUPTIBLE, but count them as "freezable". Etc.Yes, all the necessary cleanup steps should be taken.
Pavel, which approach do you like most?
Rafael
Signature · 3 lines
- Would you tell me, please, which way I ought to go from here? - That depends a good deal on where you want to get to. -- Lewis Carroll "Alice's Adventures in Wonderland"
Quoted 11 lines · Rafael J. Wysocki
During resume, we boot the kernel, check if there's an image to read and (if there's one) we freeze processes using the refrigerator (we need to get rid of them so that we can restore the image safely). Then, it seems, on some systems,
freeze_processes()may be called before all of the compiled-in drivers complete their initialization. In particular, kseriod calls usermodehelper at that time, which makes it wait uninterruptibly for a helper process to complete. If that helper process is frozen, we end up with the uninterruptible kseriod that we can't freeze and _resume_ fails, which is not nice, especially that we don't need to care for this kseriod, as we are going to restore the image in a while ...
Quoted 2 lines
Perhaps we should not use the refrigerator during resume, or we could use a slightly modified version? I don't know.
Kernel threads calling (and waiting for!) userspace processes is a very difficult problem for suspend. It comes up in several different places, and it doesn't seem to have any easy solution.
It might be best to require that kernel threads should always be freeze-able when they do this, which in particular implies that they must not hold any locks. While that should work, it would create problems for a number of drivers that use the firmware loader during their probe() routine. There will probably be other similar problems I'm not aware of.
Alan Stern
Hi!
Quoted 21 lines
Quoted 7 lines
Quoted 4 lines
It seems that if a process calls
wait_for_completion()right before suspend, the other task supposed to complete its completion may be accidentally frozen before it's able to do this. It looks like this happens to kseroid sometimes on suspend-during-resume.You mean, when a suspend occurs so soon after a resume that the resume has fully completed yet?
No.
During resume, we boot the kernel, check if there's an image to read and (if there's one) we freeze processes using the refrigerator (we need to get rid of them so that we can restore the image safely). Then, it seems, on some systems,
freeze_processes()may be called before all of the compiled-in drivers complete their initialization. In particular, kseriod calls usermodehelper at that time, which makes it wait uninterruptibly for a helper process to complete. If that helper process is frozen, we end up with the uninterruptible kseriod that we can't freeze and _resume_ fails, which is not nice, especially that we don't need to care for this kseriod, as we are going to restore the image in a while ...
Quoted 2 lines
Perhaps we should not use the refrigerator during resume, or we could use a slightly modified version? I don't know.
As we allow resume to be called from userland, other refrigerator is not really an option. We could insert mdelay before resume, or some equivalent trick...
Pavel
Signature · 1 line
Boycott Kodak -- for their patent abuse against Java.
Quoted 16 lines · Rafael J. Wysocki
Hi,
Quoted 1 line · Alan Stern
On Thu, 7 Apr 2005, Rafael J. Wysocki wrote:
]--snip--[
Quoted 11 lines
Quoted 10 lines
Quoted 3 lines
If that means waiting more than 10 seconds or so, you should just give up. Return an error and put a message in the log saying something like "Can't suspend because process XXX is busy".
OK, that's what we do now. Except that IMO we should clear the
PF_FREEZEflag for this process and dorecalc_sigpending()for it after we give up, because otherwise it will enter the refrigerator sooner or later and it will stay there. Alternatively, we can disable the "freezing loop" inrefrigerator()as soon asthaw_processes()is started. Also, we can avoid settingPF_FREEZEfor processes inTASK_UNINTERRUPTIBLE, but count them as "freezable". Etc.
Quoted 3 lines
Quoted 1 line
Yes, all the necessary cleanup steps should be taken.
Pavel, which approach do you like most?
Clearing PF_FREEZE when we fail to stop some process sounds okay to me. It would be nice if the patch was actually tested ;-).
I do not think you can deal with TASK_UNINTERRUPTIBLE in some reasonable way... If you do something with them be sure to make it separate patch :-).
Pavel
Signature · 1 line
Boycott Kodak -- for their patent abuse against Java.
Hi!
Quoted 5 lines
Quoted 2 lines
OTOH, if you want working refrigerator, Nigel has one ;-). We were talking about merging it to mainline few times already...
Sorry. I keep getting preoccupied with other things. I'll get my act together :>
I thought "Rafael seems to have enough motivation to merge that one" :-).
Pavel
Signature · 1 line
Boycott Kodak -- for their patent abuse against Java.
Hi.
Quoted 10 lines · Pavel Machek
Hi!
Quoted 5 lines
Quoted 2 lines
OTOH, if you want working refrigerator, Nigel has one ;-). We were talking about merging it to mainline few times already...
Sorry. I keep getting preoccupied with other things. I'll get my act together :>
I thought "Rafael seems to have enough motivation to merge that one" :-).
We've only been discussing part of the problem. I'll pick up the ball and submit the whole workthreads/SYNCTHREAD/process.c-upgrade solution.
Regards,
Nigel
Signature · 6 lines
Nigel Cunningham Software Engineer, Canberra, Australia http://www.cyclades.com Bus: +61 (2) 6291 9554; Hme: +61 (2) 6292 8028; Mob: +61 (417) 100 574 Maintainer of Suspend2 Kernel Patches http://suspend2.net
Hi!
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 2 lines
OTOH... we may want to move completely away from refrigerator. Its quite a hack, and it device support is okay, we'll not really need it.
Still, it won't happen soon, I guess. :-) As of today, we have the refrigerator and the processes in
TASK_UNINTERRUPTIBLEare mishandled. I think we should do something about it, at least for now, until we drop the refrigerator altogether (if we are going to drop it). That's why I started the discussion and sent the patch.
Quoted 7 lines
Quoted 2 lines
It's very simple. Processes in
TASK_UNINTERRUPTIBLEcan't be put in the refrigerator, so you have to wait until they can be put there.It seems that if a process calls
wait_for_completion()right before suspend, the other task supposed to complete its completion may be accidentally frozen before it's able to do this. It looks like this happens to kseroid sometimes on suspend-during-resume.
Hmm, so maybe rule needs to be "other tasks may not be waiting on you using wait_for_completion when you enter refrigerator?
Pavel
Signature · 1 line
Boycott Kodak -- for their patent abuse against Java.
Hi,
Quoted 2 lines · Pavel Machek
Hi!
]--snip--[
Quoted 4 lines
As we allow resume to be called from userland, other refrigerator is not really an option. We could insert mdelay before resume, or some equivalent trick...
I have an idea (provided we can disable/enable usermodehelper as in the Dmitry's patch):
kernel/power/process.c +21 -0
@@ -62,6 +62,26 @@ int freeze_processes(void)struct task_struct *g, *p;printk ("Stopping tasks: " ); +usermodehelper_disable (); +yield (); + start_time = jiffies; +do { + todo =0 ; +read_lock (&tasklist_lock); + do_each_thread(g, p) +if (!(p->flags &PF_NOFREEZE ) && + (p->state ==TASK_UNINTERRUPTIBLE )) + todo++; +while_each_thread (g, p); +read_unlock (&tasklist_lock); +yield (); +if (time_after (jiffies, start_time +TIMEOUT )) { +printk ("\n" ); +printk (KERN_ERR " stopping tasks faliled (%d unstoppable tasks)\n" , + todo); +return todo; + } + }while (todo); start_time = jiffies; do { todo = 0;
@@ -100,6 +120,7 @@ void thaw_processes(void)struct task_struct *g, *p;printk ("Restarting tasks..." ); +usermodehelper_enable ();read_lock (&tasklist_lock); do_each_thread(g, p) {if (!freezeable (p))
It's not bullet-proof, but should be enough to handle the "freeze-during-resume" case ...
Greets,
Rafael
Signature · 3 lines
- Would you tell me, please, which way I ought to go from here? - That depends a good deal on where you want to get to. -- Lewis Carroll "Alice's Adventures in Wonderland"
Hi,
Quoted 17 lines · Pavel Machek
Quoted 16 lines · Rafael J. Wysocki
Hi,
Quoted 1 line · Alan Stern
On Thu, 7 Apr 2005, Rafael J. Wysocki wrote:
]--snip--[
Quoted 11 lines
Quoted 10 lines
Quoted 3 lines
If that means waiting more than 10 seconds or so, you should just give up. Return an error and put a message in the log saying something like "Can't suspend because process XXX is busy".
OK, that's what we do now. Except that IMO we should clear the
PF_FREEZEflag for this process and dorecalc_sigpending()for it after we give up, because otherwise it will enter the refrigerator sooner or later and it will stay there. Alternatively, we can disable the "freezing loop" inrefrigerator()as soon asthaw_processes()is started. Also, we can avoid settingPF_FREEZEfor processes inTASK_UNINTERRUPTIBLE, but count them as "freezable". Etc.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Yes, all the necessary cleanup steps should be taken.
Pavel, which approach do you like most?
Clearing
PF_FREEZEwhen we fail to stop some process sounds okay to me. It would be nice if the patch was actually tested ;-).
The patch (against 2.6.12-rc2) follows. It has been tested, but of course it's difficult to recreate every possible scenario. :-)
Greets,
Rafael
kernel/power/process.c +18 -3
@@ -60,6 +60,7 @@ int freeze_processes(void)int todo;unsigned long start_time;struct task_struct *g, *p; +unsigned long flags;printk ("Stopping tasks: " ); start_time = jiffies;
@@ -67,7 +68,6 @@ int freeze_processes(void) todo =0 ;read_lock (&tasklist_lock); do_each_thread(g, p) { -unsigned long flags;if (!freezeable (p))continue ; if ((p->flags & PF_FROZEN) ||
@@ -85,13 +85,28 @@ int freeze_processes(void) }while_each_thread (g, p);read_unlock (&tasklist_lock);yield ();/* Yield is okay here */ -if (time_after (jiffies, start_time +TIMEOUT )) { +if (todo &&time_after (jiffies, start_time +TIMEOUT )) {printk ("\n" );printk (KERN_ERR " stopping tasks failed (%d tasks remaining)\n" , todo ); -return todo; +break ; } }while (todo); +if (todo) { +read_lock (&tasklist_lock); + do_each_thread(g, p) +if (p->flags &PF_FREEZE ) { +pr_debug (" clean up: %s\n" , p->comm); + p->flags &= ~PF_FREEZE ; +spin_lock_irqsave (&p->sighand->siglock, flags); +recalc_sigpending_tsk (p); +spin_unlock_irqrestore (&p->sighand->siglock, flags); + } +while_each_thread (g, p); +read_unlock (&tasklist_lock); +return todo; + } +printk ("|\n" );BUG_ON (in_atomic ());return 0 ;
Signature · 3 lines
- Would you tell me, please, which way I ought to go from here? - That depends a good deal on where you want to get to. -- Lewis Carroll "Alice's Adventures in Wonderland"
Pavel Machek
AppliedHi!
Quoted 5 lines
Quoted 2 lines
Clearing
PF_FREEZEwhen we fail to stop some process sounds okay to me. It would be nice if the patch was actually tested ;-).The patch (against 2.6.12-rc2) follows. It has been tested, but of course it's difficult to recreate every possible scenario. :-)
Applied, modulo some whitespace.
Pavel
Signature · 1 line
Boycott Kodak -- for their patent abuse against Java.
Hi,
Sorry for raising the problem again after a long time. I got some reports about ' xxx not stopped' at suspend time. The general cause is one task is waiting for another task which has been into refrigerator first. Report an error and stop suspend can't solve the problem. After the task's dependent task is released from refrigerator, the task itself will soon go into refrigerator and will never be waked up. Nigel's refrigerator patch half solves the problem. It distinct kernel tasks and user tasks, so can solve the dependence between kernel tasks and user tasks, but can't solve the user tasks dependence. Right, Nigel? Below is a proposal method to solve the issue. Assume task A depends on task B. Task B is frozen first. When we find task A can't be frozen after a long time, we thaw all tasks and let task A continue (task A has gotten a freeze signal so it will soon go into refrigerator) and then we freeze other tasks again. In theory, this can solve all task dependence (sure can't solve the circled dependence) if the retry times are enough big, but cost maybe too high. Looks it help my case (syslogd can't be stopped because it's waitting for kjournald). Any idea?
Thanks,
Shaohua
---
linux-2.6.11-root/kernel/power/process.c | 36 +++++++++++++++++++++++++++---- 1 files changed, 32 insertions(+), 4 deletions(-)
kernel/power/process.c renamed from kernel/power/process.c~freeze_process_order +32 -4
@@ -16,7 +16,8 @@/* * Timeout for stopping processes */ -#define TIMEOUT (6 * HZ) +#define TIMEOUT (3 * HZ) +#define RETRY (2)static inline int freezeable (struct task_struct * p)
@@ -54,12 +55,34 @@ void refrigerator(unsigned long flag) current->state = save; } +static void freeze_processes_failure (void ) +{ +struct task_struct *g, *p; + +/* thaw frozen processes and let process which received a frozen signal +* but was waitting for other process go. +*/ +read_lock (&tasklist_lock); + do_each_thread(g, p) { +if (!freezeable (p)) +continue ; +if (p->flags &PF_FROZEN ) { + p->flags &= ~PF_FROZEN ; +wake_up_process (p); + } + }while_each_thread (g, p); +read_unlock (&tasklist_lock); + +yield (); +} +/* 0 = success, else # of processes that we failed to stop */ int freeze_processes (void ) {int todo;unsigned long start_time;struct task_struct *g, *p; +int retry_times =1 ;printk ("Stopping tasks: " ); start_time = jiffies;
@@ -86,9 +109,14 @@ int freeze_processes(void)read_unlock (&tasklist_lock);yield ();/* Yield is okay here */ if (time_after (jiffies, start_time +TIMEOUT )) { -printk ("\n" ); -printk (KERN_ERR " stopping tasks failed (%d tasks remaining)\n" , todo ); -return todo; +if (retry_times >=RETRY ) { +printk ("\n" ); +printk (KERN_ERR " stopping tasks failed (%d tasks remaining)\n" , todo ); +return todo; + } + retry_times ++; + start_time = jiffies; +freeze_processes_failure (); } }while (todo);
_
Hi.
Quoted 10 lines · Li Shaohua
Hi,
Sorry for raising the problem again after a long time. I got some reports about ' xxx not stopped' at suspend time. The general cause is one task is waiting for another task which has been into refrigerator first. Report an error and stop suspend can't solve the problem. After the task's dependent task is released from refrigerator, the task itself will soon go into refrigerator and will never be waked up. Nigel's refrigerator patch half solves the problem. It distinct kernel tasks and user tasks, so can solve the dependence between kernel tasks and user tasks, but can't solve the user tasks dependence. Right, Nigel?
That's right, but the example you give below is userspace (syslogd) vs kernel space (kjournald), so I wonder if something could be wrong with your implementation.
Quoted 8 lines
Below is a proposal method to solve the issue. Assume task A depends on task B. Task B is frozen first. When we find task A can't be frozen after a long time, we thaw all tasks and let task A continue (task A has gotten a freeze signal so it will soon go into refrigerator) and then we freeze other tasks again. In theory, this can solve all task dependence (sure can't solve the circled dependence) if the retry times are enough big, but cost maybe too high. Looks it help my case (syslogd can't be stopped because it's waitting for kjournald). Any idea?
Perhaps what is needful is the other component of my refrigerator implementation. I also mark threads like kjournald with the new flag PF_SYNCTHREAD, and temporarily give it to threads that enter sys_sync and siblings. That ensures that processes submitting I/O are frozen, then the I/O is flushed, then kernel threads such as kjournald are frozen.
Regards,
Nigel
Signature · 6 lines
Nigel Cunningham Software Engineer, Canberra, Australia http://www.cyclades.com Bus: +61 (2) 6291 9554; Hme: +61 (2) 6292 8028; Mob: +61 (417) 100 574 Maintainer of Suspend2 Kernel Patches http://suspend2.net
Hi,
Quoted 12 lines · Nigel Cunningham
Quoted 2 lines
Sorry for raising the problem again after a long time. I got some reports about ' xxx not stopped' at suspend time. The general cause
is
Quoted 1 line
one task is waiting for another task which has been into
refrigerator
Quoted 1 line
first. Report an error and stop suspend can't solve the problem.
After
Quoted 1 line
the task's dependent task is released from refrigerator, the task
itself
Quoted 2 lines
will soon go into refrigerator and will never be waked up. Nigel's refrigerator patch half solves the problem. It distinct
kernel
Quoted 8 lines
Quoted 1 line
tasks and user tasks, so can solve the dependence between kernel
tasks
Quoted 1 line
and user tasks, but can't solve the user tasks dependence. Right,
Nigel?
That's right, but the example you give below is userspace (syslogd) vs kernel space (kjournald), so I wonder if something could be wrong with your implementation.
Right, my example can be solved with your patch. But I'd like a more generic solution to solve all the dependences, like user space tasks dependencies.
Thanks,
Shaohua
Hi.
Quoted 17 lines · Li Shaohua
Hi,
Quoted 15 lines · Nigel Cunningham
Quoted 2 lines
Sorry for raising the problem again after a long time. I got some reports about ' xxx not stopped' at suspend time. The general cause
is
Quoted 1 line
one task is waiting for another task which has been into
refrigerator
Quoted 1 line
first. Report an error and stop suspend can't solve the problem.
After
Quoted 1 line
the task's dependent task is released from refrigerator, the task
itself
Quoted 2 lines
will soon go into refrigerator and will never be waked up. Nigel's refrigerator patch half solves the problem. It distinct
kernel
Quoted 1 line
tasks and user tasks, so can solve the dependence between kernel
tasks
Quoted 1 line
and user tasks, but can't solve the user tasks dependence. Right,
Quoted 8 lines
Quoted 5 lines
Nigel?
That's right, but the example you give below is userspace (syslogd) vs kernel space (kjournald), so I wonder if something could be wrong with your implementation.
Right, my example can be solved with your patch. But I'd like a more generic solution to solve all the dependences, like user space tasks dependencies.
Do you have a particular example in mind? I haven't seen or heard of any freezing failures in Suspend2 for ages, so I'm struggling to see what is lacking.
Regards,
Nigel
Signature · 6 lines
Nigel Cunningham Software Engineer, Canberra, Australia http://www.cyclades.com Bus: +61 (2) 6291 9554; Hme: +61 (2) 6292 8028; Mob: +61 (417) 100 574 Maintainer of Suspend2 Kernel Patches http://suspend2.net
Quoted 31 lines · Nigel Cunningham
Quoted 2 lines · Nigel Cunningham
Quoted 1 line
Quoted 1 line
Sorry for raising the problem again after a long time. I got
some
Quoted 1 line
Quoted 1 line
Quoted 1 line
reports about ' xxx not stopped' at suspend time. The general
cause
Quoted 6 lines
Quoted 6 lines
is
Quoted 1 line
one task is waiting for another task which has been into
refrigerator
Quoted 1 line
first. Report an error and stop suspend can't solve the problem.
After
Quoted 1 line
the task's dependent task is released from refrigerator, the
task
Quoted 7 lines
Quoted 7 lines
itself
Quoted 2 lines
will soon go into refrigerator and will never be waked up. Nigel's refrigerator patch half solves the problem. It distinct
kernel
Quoted 1 line
tasks and user tasks, so can solve the dependence between kernel
tasks
Quoted 1 line
and user tasks, but can't solve the user tasks dependence.
Right,
Quoted 3 lines
Quoted 3 lines
Nigel?
That's right, but the example you give below is userspace
(syslogd) vs
Quoted 1 line
Quoted 1 line
kernel space (kjournald), so I wonder if something could be wrong
with
Quoted 4 lines
Quoted 1 line
your implementation.
Right, my example can be solved with your patch. But I'd like a more generic solution to solve all the dependences, like user space tasks dependencies.
Quoted 5 lines
Do you have a particular example in mind? I haven't seen or heard of any
freezing failures in Suspend2 for ages, so I'm struggling to see what is
lacking.
No, actually. Maybe I should send the proposal till I really find a case :). I only noticed the syslogd case. Somebody reported the 'mdnsresponder' process case, but didn't look at it yet.
http://bugme.osdl.org/show_bug.cgi?id=3964
Thanks,
Shaohua
Hi.
Quoted 9 lines · Li Shaohua
Quoted 5 lines
Do you have a particular example in mind? I haven't seen or heard of any
freezing failures in Suspend2 for ages, so I'm struggling to see what is
lacking.No, actually. Maybe I should send the proposal till I really find a case :). I only noticed the syslogd case. Somebody reported the 'mdnsresponder' process case, but didn't look at it yet.
http://bugme.osdl.org/show_bug.cgi?id=3964
Ah. Ok. The ipw2100 driver starts a workqueue. Since I also have patches to make kthreads freezable, we sometimes have to tell people to add an extra parameter to the create_workqueue call. Once that's done, I believe it all works fine.
I keep saying I must seek to merge these patches. I've gotten caught up on trying to get everything ready to merge at once, and confused by what Pavel is and isn't changing :> Pavel, since you're cc'd I might as well ask, am I still right to submit those patches again? If so, I'll try to do it this evening.
On a related topic, I've tried to get hotplug cpu support working with suspending, but it looks like more is needed. In particular, the 'dead' cpu still needs state saved and restored, so we're not really gaining anything with the current implementation. If hotplug really killed the CPU and rebooted it, the story might be different.
Regards,
Nigel
Signature · 6 lines
Nigel Cunningham Software Engineer, Canberra, Australia http://www.cyclades.com Bus: +61 (2) 6291 9554; Hme: +61 (2) 6292 8028; Mob: +61 (417) 100 574 Maintainer of Suspend2 Kernel Patches http://suspend2.net
Quoted 29 lines · Nigel Cunningham
Quoted 1 line
Quoted 1 line
Do you have a particular example in mind? I haven't seen or heard
of
Quoted 2 lines
Quoted 2 lines
any
freezing failures in Suspend2 for ages, so I'm struggling to seewhat
Quoted 3 lines
Quoted 2 lines
is
lacking.No, actually. Maybe I should send the proposal till I really find a
case
Quoted 3 lines
:). I only noticed the syslogd case. Somebody reported the 'mdnsresponder' process case, but didn't look at it yet.
http://bugme.osdl.org/show_bug.cgi?id=3964Ah. Ok. The ipw2100 driver starts a workqueue. Since I also have patches
to make kthreads freezable, we sometimes have to tell people to add an extra parameter to thecreate_workqueuecall. Once that's done, I believe it all works fine.I keep saying I must seek to merge these patches. I've gotten caught up
on trying to get everything ready to merge at once, and confused by what
Pavel is and isn't changing :> Pavel, since you're cc'd I might as well
ask, am I still right to submit those patches again? If so, I'll try to
do it this evening.
Quoted 6 lines
On a related topic, I've tried to get hotplug cpu support working with suspending, but it looks like more is needed. In particular, the 'dead'
cpu still needs state saved and restored, so we're not really gaining anything with the current implementation. If hotplug really killed the CPU and rebooted it, the story might be different.
What states should be saved/restored for the dead CPU? The dead CPU is in idle thread before becoming dead, so ingoring save/restore general registers doesn't matter. Sure there are something which must be saved/restored, like the MTRR registers and possible Local APIC registers if their value are different with the boot time. But there are no much such cases, I think.
Thanks,
Shaohua
Hi.
Quoted 6 lines · Li Shaohua
What states should be saved/restored for the dead CPU? The dead CPU is in idle thread before becoming dead, so ingoring save/restore general registers doesn't matter. Sure there are something which must be saved/restored, like the MTRR registers and possible Local APIC registers if their value are different with the boot time. But there are no much such cases, I think.
Well, I don't have it working perfectly yet, but saving and restoring MTRRs definitely did make a difference. Prior to that I added the same save and restore of CPU registers we use at the moment (suspend2 style) and shifted the irq disable call above the wait loop (so the comment is true). Given what you say, I'll try reversing the other changes and just leaving in the MTRR save/restore, then see if it's as reliable as it is now.
For the record, without anything added, I was getting spontaneous reboots in the copy back with just hotplug. With everything I have now added, I'm always making it to the end of the resume, but then getting seg faults when I try to start apps. Should be simple to fix, but I won't be trying this evening as I'm going to my last LUG meeting here in Canberra. We move to Brisbane May 9.
Regards,
Nigel
Signature · 6 lines
Nigel Cunningham Software Engineer, Canberra, Australia http://www.cyclades.com Bus: +61 (2) 6291 9554; Hme: +61 (2) 6292 8028; Mob: +61 (417) 100 574 Maintainer of Suspend2 Kernel Patches http://suspend2.net
Hi!
Quoted 6 lines
Quoted 3 lines
That's right, but the example you give below is userspace (syslogd) vs kernel space (kjournald), so I wonder if something could be wrong with your implementation.
Right, my example can be solved with your patch. But I'd like a more generic solution to solve all the dependences, like user space tasks dependencies.
How can usespace processes depend on each other? By definition user task sleeps in place where it holds no locks... it can't block anyone.
Pavel
Signature · 1 line
Boycott Kodak -- for their patent abuse against Java.
Hi!
Quoted 15 lines
Quoted 9 lines
Quoted 5 lines
Do you have a particular example in mind? I haven't seen or heard of any
freezing failures in Suspend2 for ages, so I'm struggling to see what is
lacking.No, actually. Maybe I should send the proposal till I really find a case :). I only noticed the syslogd case. Somebody reported the 'mdnsresponder' process case, but didn't look at it yet.
http://bugme.osdl.org/show_bug.cgi?id=3964Ah. Ok. The ipw2100 driver starts a workqueue. Since I also have patches to make kthreads freezable, we sometimes have to tell people to add an extra parameter to the
create_workqueuecall. Once that's done, I believe it all works fine.
Quoted 5 lines
I keep saying I must seek to merge these patches. I've gotten caught up on trying to get everything ready to merge at once, and confused by what Pavel is and isn't changing :> Pavel, since you're cc'd I might as well ask, am I still right to submit those patches again? If so, I'll try to do it this evening.
Yes, I'd like those patches...
Quoted 5 lines
On a related topic, I've tried to get hotplug cpu support working with suspending, but it looks like more is needed. In particular, the 'dead' cpu still needs state saved and restored, so we're not really gaining anything with the current implementation. If hotplug really killed the CPU and rebooted it, the story might be different.
It works for me, but you need to play with -mm kernel where neccessary support is implemented...
Pavel
Signature · 1 line
Boycott Kodak -- for their patent abuse against Java.
Quoted 4 lines · Pavel Machek
Hi!
How can usespace processes depend on each other? By definition user task sleeps in place where it holds no locks... it can't block anyone.
what was the problem with mysql some months back? I never fully understood it, but wasn't it 2 mysql processes communicating via a pipe or something like that and the "wrong end" frozen first?
Signature · 4 lines
Stefan Seyfried, QA / R&D Team Mobile Devices, SUSE LINUX Nürnberg. "Any ideas, John?" "Well, surrounding them's out."
Hi!
Quoted 6 lines
Quoted 2 lines
How can usespace processes depend on each other? By definition user task sleeps in place where it holds no locks... it can't block anyone.
what was the problem with mysql some months back? I never fully understood it, but wasn't it 2 mysql processes communicating via a pipe or something like that and the "wrong end" frozen first?
I never fully understood it, either (it still exists in mainline, IIRC), but it apparently was process calling signal functions in too tight loop. It was reproducible with just one process.
Pavel
Signature · 1 line
Boycott Kodak -- for their patent abuse against Java.