Remove process freezer from suspend to RAM pathway
Subsystems (3)
Quoted 32 lines · Benjamin Herrenschmidt
Quoted 11 lines
Quoted 2 lines
- For STR, don't do the freezer thing.
In the long run, I agree.
Still, can you please read this post from Alan Stern:
https://lists.linux-foundation.org/pipermail/linux-pm/2007-June/012847.html
? I don't think I'm able to repeat the arguments given in there in a convincing way.
That's the same crackpot I've been hearing for the past 3 years or so ...
Both Paulus and I think the freezer is just a way to try to put your head in the sand and ignore the problem. It causes as many problems as it solves on its own, and is just not a solution that will be of any use once you start implementing dynamic PM schemes etc...
In many cases, having proper support for "live" suspend of devices is just a matter of having a couple of helpers in whatever subsystem those drivers hookup with. In the case of network, for example, it's mostly trivial (stop the queue). For block, it's not terribly hard neither, though you want to have some orderign/atomicity between the blocking of the incoming request queue and the sending of things like spindown & flush commands to the disk. For old-style IDE, that was fairly easily solved by piping suspend/resume command down the request queue itself and have the queue block/unblbock itself after processing them. Some of that logic could maybe be moved to the block layer for all block drivers to benefit.
Quoted 3 lines
But yes, overall, there is work to do on drivers and I'm doing the ones I hit on the platforms I use. I don't think the freezer is any kind of remotely good solution, just a way to continue avoiding the problem.
Still, do you really think that we're ready to drop it _right_ _now_ (I'm referring to suspend only) and if so than on what basis (except that you don't like it, which falls short of being a techical argument)?
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Quoted 6 lines · Rafael J. Wysocki
Still, do you really think that we're ready to drop it _right_ _now_ (I'm
referring to suspend only) and if so than on what basis (except that you
don't like it, which falls short of being a techical argument)?
Works fine for me without it ;-)
Ben.
Quoted 6 lines · Rafael J. Wysocki
Still, do you really think that we're ready to drop it _right_ _now_ (I'm
referring to suspend only) and if so than on what basis (except that you
don't like it, which falls short of being a techical argument)?
Works fine for me without it ;-)
Ben.
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 6 lines · Rafael J. Wysocki
Still, do you really think that we're ready to drop it _right_ _now_ (I'm
referring to suspend only) and if so than on what basis (except that you
don't like it, which falls short of being a techical argument)?Works fine for me without it ;-)
Yeah, that makes sense. ;-)
Still, someone needs to take care of bug reports from unlucky people and I wouldn't like to increase the number of these by doing such a high-level change without any preparations ...
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 6 lines · Rafael J. Wysocki
Still, do you really think that we're ready to drop it _right_ _now_ (I'm
referring to suspend only) and if so than on what basis (except that you
don't like it, which falls short of being a techical argument)?Works fine for me without it ;-)
Yeah, that makes sense. ;-)
Still, someone needs to take care of bug reports from unlucky people and I wouldn't like to increase the number of these by doing such a high-level change without any preparations ...
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Quoted 3 lines · Rafael J. Wysocki
Still, do you really think that we're ready to drop it _right_ _now_ (I'm referring to suspend only) and if so than on what basis (except that you don't like it, which falls short of being a techical argument)?
The basis is that it (the freezer) causes more deadlocks and other problems than it avoids, so it's a net win to remove it.
Paul.
Quoted 3 lines · Rafael J. Wysocki
Still, do you really think that we're ready to drop it _right_ _now_ (I'm referring to suspend only) and if so than on what basis (except that you don't like it, which falls short of being a techical argument)?
The basis is that it (the freezer) causes more deadlocks and other problems than it avoids, so it's a net win to remove it.
Paul.
Quoted 8 lines · Paul Mackerras
Quoted 3 lines · Rafael J. Wysocki
Still, do you really think that we're ready to drop it _right_ _now_ (I'm referring to suspend only) and if so than on what basis (except that you don't like it, which falls short of being a techical argument)?
The basis is that it (the freezer) causes more deadlocks and other problems than it avoids, so it's a net win to remove it.
So, I gather, you're volunteering to handle suspend-related bug reports from the point in which we drop the freezer from the suspend code path?
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Quoted 2 lines · Rafael J. Wysocki
So, I gather, you're volunteering to handle suspend-related bug reports from the point in which we drop the freezer from the suspend code path?
Ben and I are happy to handle all the ones for the platform we maintain, which currently does suspend without freezing processes. :)
Paul.
Quoted 2 lines · Rafael J. Wysocki
So, I gather, you're volunteering to handle suspend-related bug reports from the point in which we drop the freezer from the suspend code path?
Ben and I are happy to handle all the ones for the platform we maintain, which currently does suspend without freezing processes. :)
Paul.
Quoted 7 lines · Paul Mackerras
Quoted 2 lines · Rafael J. Wysocki
So, I gather, you're volunteering to handle suspend-related bug reports from the point in which we drop the freezer from the suspend code path?
Ben and I are happy to handle all the ones for the platform we maintain, which currently does suspend without freezing processes. :)
I mean all platforms. After all, the $subject change won't affect yours.
BTW, does your platform's suspend work on SMP systems?
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Quoted 1 line · Rafael J. Wysocki
BTW, does your platform's suspend work on SMP systems?
Yes; currently we require userspace to offline all cpus other than the boot cpu before initiating the suspend.
The main difficulty is actually that SMP powermacs that can suspend tend to have video cards that get powered off in suspend. We know how to re-initialize one (the Radeon RV100 QW) but not others. That's an orthogonal issue to the issues we have been discussing, though.
Paul.
Quoted 6 lines · Paul Mackerras
Quoted 1 line · Rafael J. Wysocki
BTW, does your platform's suspend work on SMP systems?
Yes; currently we require userspace to offline all cpus other than the boot cpu before initiating the suspend.
This is incompatible with the code in kernel/power/main.c, since we only disable the nonboot CPUs after devices have been suspended. Do you think that your framework can be modified to work without disabling the nonboot CPUs by the user space?
Quoted 4 lines
The main difficulty is actually that SMP powermacs that can suspend tend to have video cards that get powered off in suspend. We know how to re-initialize one (the Radeon RV100 QW) but not others. That's an orthogonal issue to the issues we have been discussing, though.
Sure.
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Quoted 4 lines · Rafael J. Wysocki
This is incompatible with the code in
kernel/power/main.c, since we only disable the nonboot CPUs after devices have been suspended. Do you think that your framework can be modified to work without disabling the nonboot CPUs by the user space?
Sure. It was a "if it can be done in userspace, do it in userspace" kind of decision, but I'm not wedded to it.
I actually do want to converge to using the generic suspend-to-ram code on powerbooks. I just want to avoid causing regressions for powerbook users, including myself. :)
Paul.
Quoted 4 lines · Rafael J. Wysocki
This is incompatible with the code in
kernel/power/main.c, since we only disable the nonboot CPUs after devices have been suspended. Do you think that your framework can be modified to work without disabling the nonboot CPUs by the user space?
Sure. It was a "if it can be done in userspace, do it in userspace" kind of decision, but I'm not wedded to it.
I actually do want to converge to using the generic suspend-to-ram code on powerbooks. I just want to avoid causing regressions for powerbook users, including myself. :)
Paul.
Quoted 7 lines · Paul Mackerras
Quoted 4 lines · Rafael J. Wysocki
This is incompatible with the code in
kernel/power/main.c, since we only disable the nonboot CPUs after devices have been suspended. Do you think that your framework can be modified to work without disabling the nonboot CPUs by the user space?
Quoted 6 lines
Sure. It was a "if it can be done in userspace, do it in userspace" kind of decision, but I'm not wedded to it.
I actually do want to converge to using the generic suspend-to-ram code on powerbooks. I just want to avoid causing regressions for powerbook users, including myself. :)
Okay, but my question is this: Would that be possible, within your framework, to disable the nonboot CPUs _after_ suspending devices?
Can you please point me to your high-level suspend code?
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Quoted 7 lines · Paul Mackerras
Quoted 4 lines · Rafael J. Wysocki
This is incompatible with the code in
kernel/power/main.c, since we only disable the nonboot CPUs after devices have been suspended. Do you think that your framework can be modified to work without disabling the nonboot CPUs by the user space?
Quoted 6 lines
Sure. It was a "if it can be done in userspace, do it in userspace" kind of decision, but I'm not wedded to it.
I actually do want to converge to using the generic suspend-to-ram code on powerbooks. I just want to avoid causing regressions for powerbook users, including myself. :)
Okay, but my question is this: Would that be possible, within your framework, to disable the nonboot CPUs _after_ suspending devices?
Can you please point me to your high-level suspend code?
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Quoted 7 lines · Paul Mackerras
Quoted 4 lines · Rafael J. Wysocki
This is incompatible with the code in
kernel/power/main.c, since we only disable the nonboot CPUs after devices have been suspended. Do you think that your framework can be modified to work without disabling the nonboot CPUs by the user space?
Quoted 6 lines
Sure. It was a "if it can be done in userspace, do it in userspace" kind of decision, but I'm not wedded to it.
I actually do want to converge to using the generic suspend-to-ram code on powerbooks. I just want to avoid causing regressions for powerbook users, including myself. :)
Curious, do you actually use fuse? Can you try it _with_ freezer and produce sysrq-t trace of deadlock?
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 7 lines · Paul Mackerras
Quoted 4 lines · Rafael J. Wysocki
This is incompatible with the code in
kernel/power/main.c, since we only disable the nonboot CPUs after devices have been suspended. Do you think that your framework can be modified to work without disabling the nonboot CPUs by the user space?
Quoted 6 lines
Sure. It was a "if it can be done in userspace, do it in userspace" kind of decision, but I'm not wedded to it.
I actually do want to converge to using the generic suspend-to-ram code on powerbooks. I just want to avoid causing regressions for powerbook users, including myself. :)
Curious, do you actually use fuse? Can you try it _with_ freezer and produce sysrq-t trace of deadlock?
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 6 lines · Paul Mackerras
Quoted 1 line · Rafael J. Wysocki
BTW, does your platform's suspend work on SMP systems?
Yes; currently we require userspace to offline all cpus other than the boot cpu before initiating the suspend.
This is incompatible with the code in kernel/power/main.c, since we only disable the nonboot CPUs after devices have been suspended. Do you think that your framework can be modified to work without disabling the nonboot CPUs by the user space?
Quoted 4 lines
The main difficulty is actually that SMP powermacs that can suspend tend to have video cards that get powered off in suspend. We know how to re-initialize one (the Radeon RV100 QW) but not others. That's an orthogonal issue to the issues we have been discussing, though.
Sure.
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Quoted 7 lines · Rafael J. Wysocki
Quoted 5 lines
Quoted 2 lines
So, I gather, you're volunteering to handle suspend-related bug reports from the point in which we drop the freezer from the suspend code path?
Ben and I are happy to handle all the ones for the platform we maintain, which currently does suspend without freezing processes. :)
I mean all platforms. After all, the $subject change won't affect yours.
Well, I can't commit to handling all bug reports, but I am happy to help out where I can...
Paul.
Quoted 7 lines · Rafael J. Wysocki
Quoted 5 lines
Quoted 2 lines
So, I gather, you're volunteering to handle suspend-related bug reports from the point in which we drop the freezer from the suspend code path?
Ben and I are happy to handle all the ones for the platform we maintain, which currently does suspend without freezing processes. :)
I mean all platforms. After all, the $subject change won't affect yours.
Well, I can't commit to handling all bug reports, but I am happy to help out where I can...
Paul.
Quoted 7 lines · Paul Mackerras
Quoted 2 lines · Rafael J. Wysocki
So, I gather, you're volunteering to handle suspend-related bug reports from the point in which we drop the freezer from the suspend code path?
Ben and I are happy to handle all the ones for the platform we maintain, which currently does suspend without freezing processes. :)
I mean all platforms. After all, the $subject change won't affect yours.
BTW, does your platform's suspend work on SMP systems?
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
The big suspend mess
In reply to Paul MackerrasQuoted 8 lines · Paul Mackerras
Quoted 3 lines · Rafael J. Wysocki
Still, do you really think that we're ready to drop it _right_ _now_ (I'm referring to suspend only) and if so than on what basis (except that you don't like it, which falls short of being a techical argument)?
The basis is that it (the freezer) causes more deadlocks and other problems than it avoids, so it's a net win to remove it.
You forget one important point:
Regressions are much worse than normal bugs.
It's not about the question whether the driver was "correct" or "buggy" - for a user the important question is whether it worked in practice, and if yes, whether it continues to work.
And my impression is that every time someone touches some part of the suspend code some drivers break.
During 2.6.21-rc, it wasn't unusual for users to run with one kernel into up to three distinct suspend regressions on one machine.
And no, it wasn't always the same set of distinct regressions.
IMHO the suspend code is currently way too much of a moving target which results in this mess.
The correct order seems to be:
1. agree on what the suspend code as a whole should look like
2. implement this
3. fix ALL drivers to work at least as good as they do today
4. get it tested in -mm
5. fix all bugs people run into
6. submit it for inclusion in Linus' tree
7. quickly work on the most likely big amount of bug reports
Step 1 is the most important one - evolving code is often something good, but in this case with different people trying to evolve the suspend code in different directions it simply results in a big mess.
Quoted 1 line
Paul.
cu
Adrian
Signature · 4 lines
"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon SeedRe: The big suspend mess
Quoted 5 lines
IMHO the suspend code is currently way too much of a moving target which results in this mess.
The correct order seems to be:
0. Get someone to sign up as a maintainer for suspend, so we have someone to blame for the mess? :-)
Quoted 11 lines
1. agree on what the suspend code as a whole should look like
2. implement this
3. fix ALL drivers to work at least as good as they do today
4. get it tested in -mm
5. fix all bugs people run into
6. submit it for inclusion in Linus' tree
7. quickly work on the most likely big amount of bug reportsStep 1 is the most important one - evolving code is often something good, but in this case with different people trying to evolve the suspend code in different directions it simply results in a big mess.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: The big suspend mess
In reply to Adrian BunkQuoted 5 lines
IMHO the suspend code is currently way too much of a moving target which results in this mess.
The correct order seems to be:
0. Get someone to sign up as a maintainer for suspend, so we have someone to blame for the mess? :-)
Quoted 11 lines
1. agree on what the suspend code as a whole should look like
2. implement this
3. fix ALL drivers to work at least as good as they do today
4. get it tested in -mm
5. fix all bugs people run into
6. submit it for inclusion in Linus' tree
7. quickly work on the most likely big amount of bug reportsStep 1 is the most important one - evolving code is often something good, but in this case with different people trying to evolve the suspend code in different directions it simply results in a big mess.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: The big suspend mess
Quoted 2 lines · Pavel Machek
0. Get someone to sign up as a maintainer for suspend, so we have someone to blame for the mess? :-)
I thought that was Rafael?
Paul.
Re: The big suspend mess
In reply to Pavel MachekQuoted 2 lines · Pavel Machek
0. Get someone to sign up as a maintainer for suspend, so we have someone to blame for the mess? :-)
I thought that was Rafael?
Paul.
Re: The big suspend mess
Quoted 6 lines · Paul Mackerras
Quoted 2 lines · Pavel Machek
0. Get someone to sign up as a maintainer for suspend, so we have someone to blame for the mess? :-)
I thought that was Rafael?
Rafael is good job trying to fix suspend when he can, but we do not actually have "SUSPEND" entry in MAINTAINERS file.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: The big suspend mess
In reply to Paul MackerrasQuoted 6 lines · Paul Mackerras
Quoted 2 lines · Pavel Machek
0. Get someone to sign up as a maintainer for suspend, so we have someone to blame for the mess? :-)
I thought that was Rafael?
Rafael is good job trying to fix suspend when he can, but we do not actually have "SUSPEND" entry in MAINTAINERS file.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: The big suspend mess
Quoted 8 lines · Pavel Machek
Quoted 6 lines · Paul Mackerras
Quoted 3 lines · Pavel Machek
0. Get someone to sign up as a maintainer for suspend, so we have someone to blame for the mess? :-)
Quoted 7 lines
Quoted 2 lines
I thought that was Rafael?
Rafael is good job trying to fix suspend when he can, but we do not actually have "SUSPEND" entry in
MAINTAINERSfile.
Pavel
Huch ?;)
We do :p
...
SOFTWARE SUSPEND:
P: Pavel Machek
M: [email protected]
L: [email protected]
S: Maintained
...
Re: The big suspend mess
Hi.
Quoted 21 lines · Gabriel C
Quoted 8 lines · Pavel Machek
Quoted 6 lines · Paul Mackerras
Quoted 3 lines · Pavel Machek
0. Get someone to sign up as a maintainer for suspend, so we have someone to blame for the mess? :-)
Quoted 7 lines
Quoted 2 lines
I thought that was Rafael?
Rafael is good job trying to fix suspend when he can, but we do not actually have "SUSPEND" entry in
MAINTAINERSfile.
PavelHuch ?;)
We do :p
Quoted 8 lines
...
SOFTWARE SUSPEND:
P: Pavel Machek
M: [email protected]
L: [email protected]
S: Maintained
I think he means SUSPEND (aka suspend-to-ram) not "SOFTWARE SUSPEND" (aka suspend-to-disk)
Re: The big suspend mess
In reply to Gabriel CHi.
Quoted 21 lines · Gabriel C
Quoted 8 lines · Pavel Machek
Quoted 6 lines · Paul Mackerras
Quoted 3 lines · Pavel Machek
0. Get someone to sign up as a maintainer for suspend, so we have someone to blame for the mess? :-)
Quoted 7 lines
Quoted 2 lines
I thought that was Rafael?
Rafael is good job trying to fix suspend when he can, but we do not actually have "SUSPEND" entry in
MAINTAINERSfile.
PavelHuch ?;)
We do :p
Quoted 8 lines
...
SOFTWARE SUSPEND:
P: Pavel Machek
M: [email protected]
L: [email protected]
S: Maintained
I think he means SUSPEND (aka suspend-to-ram) not "SOFTWARE SUSPEND" (aka suspend-to-disk)
Re: The big suspend mess
In reply to Pavel MachekQuoted 8 lines · Pavel Machek
Quoted 5 lines
IMHO the suspend code is currently way too much of a moving target which results in this mess.
The correct order seems to be:
0. Get someone to sign up as a maintainer for suspend, so we have someone to blame for the mess? :-)
The "SOFTWARE SUSPEND" entry in MAINTAINERS already contains a victim... ;-)
My impression is that suspend is an area of the kernel that does not lack maintainers - you and Rafael are doing a good job, and there's e.g. also the maintained code formerly known as suspend2.
But some basic questions like e.g.
- What should be done in the kernel and what in userspace?
- How should this be implemented?
- What must subsystems and drivers do?
- What must subsystems and drivers not do?
seem to be in a constant flux because the big picture everyone agrees upon seems to be missing.
Quoted 8 lines
Quoted 8 lines
1. agree on what the suspend code as a whole should look like
2. implement this
3. fix ALL drivers to work at least as good as they do today
4. get it tested in -mm
5. fix all bugs people run into
6. submit it for inclusion in Linus' tree
7. quickly work on the most likely big amount of bug reports
Quoted 5 lines
Quoted 3 lines
Step 1 is the most important one - evolving code is often something good, but in this case with different people trying to evolve the suspend code in different directions it simply results in a big mess.
Pavel
cu
Adrian
Signature · 4 lines
"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon SeedRe: The big suspend mess
Quoted 16 lines · Adrian Bunk
Quoted 8 lines · Pavel Machek
Quoted 5 lines
IMHO the suspend code is currently way too much of a moving target which results in this mess.
The correct order seems to be:
0. Get someone to sign up as a maintainer for suspend, so we have someone to blame for the mess? :-)
The "SOFTWARE SUSPEND" entry in
MAINTAINERSalready contains a victim... ;-)My impression is that suspend is an area of the kernel that does not lack maintainers - you and Rafael are doing a good job, and there's e.g. also the maintained code formerly known as suspend2.
Quoted 7 lines
But some basic questions like e.g.
- What should be done in the kernel and what in userspace?
- How should this be implemented?
- What must subsystems and drivers do?
- What must subsystems and drivers not do?
seem to be in a constant flux because the big picture everyone agrees upon seems to be missing.
Well, to some extent I agree, but that's because it's difficult to reach such an agreement and if we have one, new poeple come with new ideas and we need to start all over again. :-)
In the meantime, problems are reported that need to be fixed and the fixes often break other systems and we learn about that too late ect.
As far as the big picture is concerned, we have already agreed, or at least this is my impression, that we need to separate the drivers' suspend callbacks (as they exist today) from their hibernation callbacks (not present yet).
This seems to be needed for a couple of reasons, the first of them being that the desired functionality of the hibernation code may be substantially different from the desired functionality of the suspend code. For instance, it generally is not necessary to put devices into low power states, or to power them off, in order to create the hibernation image, while it is necessary to do that for a suspend.
It will require us to redesign the core quite a bit and I've already started to prepare for that. I really would like to do that in the first place and _then_ to think of improving both the suspend and hibernation code paths _separately_. This way, we can do things more easily and in a much more clean way.
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Re: The big suspend mess
In reply to Adrian BunkQuoted 16 lines · Adrian Bunk
Quoted 8 lines · Pavel Machek
Quoted 5 lines
IMHO the suspend code is currently way too much of a moving target which results in this mess.
The correct order seems to be:
0. Get someone to sign up as a maintainer for suspend, so we have someone to blame for the mess? :-)
The "SOFTWARE SUSPEND" entry in
MAINTAINERSalready contains a victim... ;-)My impression is that suspend is an area of the kernel that does not lack maintainers - you and Rafael are doing a good job, and there's e.g. also the maintained code formerly known as suspend2.
Quoted 7 lines
But some basic questions like e.g.
- What should be done in the kernel and what in userspace?
- How should this be implemented?
- What must subsystems and drivers do?
- What must subsystems and drivers not do?
seem to be in a constant flux because the big picture everyone agrees upon seems to be missing.
Well, to some extent I agree, but that's because it's difficult to reach such an agreement and if we have one, new poeple come with new ideas and we need to start all over again. :-)
In the meantime, problems are reported that need to be fixed and the fixes often break other systems and we learn about that too late ect.
As far as the big picture is concerned, we have already agreed, or at least this is my impression, that we need to separate the drivers' suspend callbacks (as they exist today) from their hibernation callbacks (not present yet).
This seems to be needed for a couple of reasons, the first of them being that the desired functionality of the hibernation code may be substantially different from the desired functionality of the suspend code. For instance, it generally is not necessary to put devices into low power states, or to power them off, in order to create the hibernation image, while it is necessary to do that for a suspend.
It will require us to redesign the core quite a bit and I've already started to prepare for that. I really would like to do that in the first place and _then_ to think of improving both the suspend and hibernation code paths _separately_. This way, we can do things more easily and in a much more clean way.
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Re: The big suspend mess
In reply to Pavel MachekQuoted 8 lines · Pavel Machek
Quoted 5 lines
IMHO the suspend code is currently way too much of a moving target which results in this mess.
The correct order seems to be:
0. Get someone to sign up as a maintainer for suspend, so we have someone to blame for the mess? :-)
The "SOFTWARE SUSPEND" entry in MAINTAINERS already contains a victim... ;-)
My impression is that suspend is an area of the kernel that does not lack maintainers - you and Rafael are doing a good job, and there's e.g. also the maintained code formerly known as suspend2.
But some basic questions like e.g.
- What should be done in the kernel and what in userspace?
- How should this be implemented?
- What must subsystems and drivers do?
- What must subsystems and drivers not do?
seem to be in a constant flux because the big picture everyone agrees upon seems to be missing.
Quoted 8 lines
Quoted 8 lines
1. agree on what the suspend code as a whole should look like
2. implement this
3. fix ALL drivers to work at least as good as they do today
4. get it tested in -mm
5. fix all bugs people run into
6. submit it for inclusion in Linus' tree
7. quickly work on the most likely big amount of bug reports
Quoted 5 lines
Quoted 3 lines
Step 1 is the most important one - evolving code is often something good, but in this case with different people trying to evolve the suspend code in different directions it simply results in a big mess.
Pavel
cu
Adrian
Signature · 4 lines
"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon SeedRe: [linux-pm] The big suspend mess
In reply to Adrian BunkQuoted 12 lines · Adrian Bunk
IMHO the suspend code is currently way too much of a moving target which results in this mess.
The correct order seems to be:
1. agree on what the suspend code as a whole should look like
2. implement this
3. fix ALL drivers to work at least as good as they do today
4. get it tested in -mm
5. fix all bugs people run into
6. submit it for inclusion in Linus' tree
7. quickly work on the most likely big amount of bug reports
Quoted 3 lines
Step 1 is the most important one - evolving code is often something good, but in this case with different people trying to evolve the suspend code in different directions it simply results in a big mess.
Isn't Step 1 exactly what we are in the midst of right now?
Alan Stern
The big suspend mess
In reply to Paul MackerrasQuoted 8 lines · Paul Mackerras
Quoted 3 lines · Rafael J. Wysocki
Still, do you really think that we're ready to drop it _right_ _now_ (I'm referring to suspend only) and if so than on what basis (except that you don't like it, which falls short of being a techical argument)?
The basis is that it (the freezer) causes more deadlocks and other problems than it avoids, so it's a net win to remove it.
You forget one important point:
Regressions are much worse than normal bugs.
It's not about the question whether the driver was "correct" or "buggy" - for a user the important question is whether it worked in practice, and if yes, whether it continues to work.
And my impression is that every time someone touches some part of the suspend code some drivers break.
During 2.6.21-rc, it wasn't unusual for users to run with one kernel into up to three distinct suspend regressions on one machine.
And no, it wasn't always the same set of distinct regressions.
IMHO the suspend code is currently way too much of a moving target which results in this mess.
The correct order seems to be:
1. agree on what the suspend code as a whole should look like
2. implement this
3. fix ALL drivers to work at least as good as they do today
4. get it tested in -mm
5. fix all bugs people run into
6. submit it for inclusion in Linus' tree
7. quickly work on the most likely big amount of bug reports
Step 1 is the most important one - evolving code is often something good, but in this case with different people trying to evolve the suspend code in different directions it simply results in a big mess.
Quoted 1 line
Paul.
cu
Adrian
Signature · 4 lines
"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon SeedQuoted 32 lines · Benjamin Herrenschmidt
Quoted 11 lines
Quoted 2 lines
- For STR, don't do the freezer thing.
In the long run, I agree.
Still, can you please read this post from Alan Stern:
https://lists.linux-foundation.org/pipermail/linux-pm/2007-June/012847.html
? I don't think I'm able to repeat the arguments given in there in a convincing way.
That's the same crackpot I've been hearing for the past 3 years or so ...
Both Paulus and I think the freezer is just a way to try to put your head in the sand and ignore the problem. It causes as many problems as it solves on its own, and is just not a solution that will be of any use once you start implementing dynamic PM schemes etc...
In many cases, having proper support for "live" suspend of devices is just a matter of having a couple of helpers in whatever subsystem those drivers hookup with. In the case of network, for example, it's mostly trivial (stop the queue). For block, it's not terribly hard neither, though you want to have some orderign/atomicity between the blocking of the incoming request queue and the sending of things like spindown & flush commands to the disk. For old-style IDE, that was fairly easily solved by piping suspend/resume command down the request queue itself and have the queue block/unblbock itself after processing them. Some of that logic could maybe be moved to the block layer for all block drivers to benefit.
Quoted 3 lines
But yes, overall, there is work to do on drivers and I'm doing the ones I hit on the platforms I use. I don't think the freezer is any kind of remotely good solution, just a way to continue avoiding the problem.
Still, do you really think that we're ready to drop it _right_ _now_ (I'm referring to suspend only) and if so than on what basis (except that you don't like it, which falls short of being a techical argument)?
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Hi!
Quoted 11 lines
Quoted 10 lines
Quoted 1 line
- For STR, don't do the freezer thing.
In the long run, I agree.
Still, can you please read this post from Alan Stern:
https://lists.linux-foundation.org/pipermail/linux-pm/2007-June/012847.html
? I don't think I'm able to repeat the arguments given in there in a convincing way.
Quoted 7 lines
That's the same crackpot I've been hearing for the past 3 years or so ...
Both Paulus and I think the freezer is just a way to try to put your head in the sand and ignore the problem. It causes as many problems as it solves on its own, and is just not a solution that will be of any use once you start implementing dynamic PM schemes etc...
Well, yep, you can view freezer as a head in the sand...
Quoted 11 lines
In many cases, having proper support for "live" suspend of devices is just a matter of having a couple of helpers in whatever subsystem those drivers hookup with. In the case of network, for example, it's mostly trivial (stop the queue). For block, it's not terribly hard neither, though you want to have some orderign/atomicity between the blocking of the incoming request queue and the sending of things like spindown & flush commands to the disk. For old-style IDE, that was fairly easily solved by piping suspend/resume command down the request queue itself and have the queue block/unblbock itself after processing them. Some of that logic could maybe be moved to the block layer for all block drivers to benefit.
...but the moment you start blocking tasks that done driver request, you _do_ have mini-freezer of your own, with pretty much the same problems.
In another message I shown that removing freezer will not help with FUSE in general case.
It probably does not help with firmware, too; as soon as udev attempts to do something with your wireless card, it is blocked, and if the wireless card needs the firmware from udev, you are deadlocked.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Hi!
Quoted 11 lines
Quoted 10 lines
Quoted 1 line
- For STR, don't do the freezer thing.
In the long run, I agree.
Still, can you please read this post from Alan Stern:
https://lists.linux-foundation.org/pipermail/linux-pm/2007-June/012847.html
? I don't think I'm able to repeat the arguments given in there in a convincing way.
Quoted 7 lines
That's the same crackpot I've been hearing for the past 3 years or so ...
Both Paulus and I think the freezer is just a way to try to put your head in the sand and ignore the problem. It causes as many problems as it solves on its own, and is just not a solution that will be of any use once you start implementing dynamic PM schemes etc...
Well, yep, you can view freezer as a head in the sand...
Quoted 11 lines
In many cases, having proper support for "live" suspend of devices is just a matter of having a couple of helpers in whatever subsystem those drivers hookup with. In the case of network, for example, it's mostly trivial (stop the queue). For block, it's not terribly hard neither, though you want to have some orderign/atomicity between the blocking of the incoming request queue and the sending of things like spindown & flush commands to the disk. For old-style IDE, that was fairly easily solved by piping suspend/resume command down the request queue itself and have the queue block/unblbock itself after processing them. Some of that logic could maybe be moved to the block layer for all block drivers to benefit.
...but the moment you start blocking tasks that done driver request, you _do_ have mini-freezer of your own, with pretty much the same problems.
In another message I shown that removing freezer will not help with FUSE in general case.
It probably does not help with firmware, too; as soon as udev attempts to do something with your wireless card, it is blocked, and if the wireless card needs the firmware from udev, you are deadlocked.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 4 lines · Pavel Machek
...but the moment you start blocking tasks that done driver request, you _do_ have mini-freezer of your own, with pretty much the same problems.
No, not at all the same problems. Those tasks will block, but that will be harmless because we won't have some "freezer" things waiting for all tasks to reach a "stable" point (calling try_to_freeze()). We just let them block wherever we want, as long as it doesn't prevent a -driver- from suspending, which should be allright, we have no problem.
Quoted 2 lines
In another message I shown that removing freezer will not help with FUSE in general case.
I disagree.
Quoted 3 lines
It probably does not help with firmware, too; as soon as udev attempts to do something with your wireless card, it is blocked, and if the wireless card needs the firmware from udev, you are deadlocked.
Firmware load has been a problem since day 1, I've talked about it multiple times, it's broken with or without the freezer, and so far, the reaction of pretty much everybody has been to dig their head deeper in the mud and ignore the problem.
There are other issues (again, with or without freezer) that should be dealt with. For example, drivers that haven't yet got their suspend() callback or already have got their resume() may rely on services of the kernel that are still blocked, that's where things may go hairy. request_firmware() within resume() is a typical example of that.
There are a few things we should do in that area. For example, once we start to call driver suspend's, we should probably set a system wide flag that will do things such as:
- block usermode helpers (either make call_usermodehelper return
something like -EBUSY or have it queue up the calls and issue them later when thing are resuming, we need to look closely at what semantic we want here).
- Silently add GFP_NOIO to all allocations, to avoid having things
blocking in kmalloc() with a mutex held that will deadlock with suspend() in a driver for example. Or set some way to have all GFP waiters wakeup and fail rather than wait for IOs. It's hard/bizarre but necessary, again, with or without a freezer.
- Deal with the firmware problem. The best way is probably to have an
async request_firmware interface(). Another thing is, drivers may want to cache their firmware in main memory, that sort of thing...
And that's just a small list off the top of my mind, of known problems that will cause deadlocks or misbehaviours today, with or without the freezer, and that need to be addressed.
Ben.
Quoted 4 lines · Pavel Machek
...but the moment you start blocking tasks that done driver request, you _do_ have mini-freezer of your own, with pretty much the same problems.
No, not at all the same problems. Those tasks will block, but that will be harmless because we won't have some "freezer" things waiting for all tasks to reach a "stable" point (calling try_to_freeze()). We just let them block wherever we want, as long as it doesn't prevent a -driver- from suspending, which should be allright, we have no problem.
Quoted 2 lines
In another message I shown that removing freezer will not help with FUSE in general case.
I disagree.
Quoted 3 lines
It probably does not help with firmware, too; as soon as udev attempts to do something with your wireless card, it is blocked, and if the wireless card needs the firmware from udev, you are deadlocked.
Firmware load has been a problem since day 1, I've talked about it multiple times, it's broken with or without the freezer, and so far, the reaction of pretty much everybody has been to dig their head deeper in the mud and ignore the problem.
There are other issues (again, with or without freezer) that should be dealt with. For example, drivers that haven't yet got their suspend() callback or already have got their resume() may rely on services of the kernel that are still blocked, that's where things may go hairy. request_firmware() within resume() is a typical example of that.
There are a few things we should do in that area. For example, once we start to call driver suspend's, we should probably set a system wide flag that will do things such as:
- block usermode helpers (either make call_usermodehelper return
something like -EBUSY or have it queue up the calls and issue them later when thing are resuming, we need to look closely at what semantic we want here).
- Silently add GFP_NOIO to all allocations, to avoid having things
blocking in kmalloc() with a mutex held that will deadlock with suspend() in a driver for example. Or set some way to have all GFP waiters wakeup and fail rather than wait for IOs. It's hard/bizarre but necessary, again, with or without a freezer.
- Deal with the firmware problem. The best way is probably to have an
async request_firmware interface(). Another thing is, drivers may want to cache their firmware in main memory, that sort of thing...
And that's just a small list off the top of my mind, of known problems that will cause deadlocks or misbehaviours today, with or without the freezer, and that need to be addressed.
Ben.
Hi.
Quoted 11 lines · On Friday 06 July 2007 08:46:54 Benjamin Herrenschmidt wrote:
Quoted 4 lines · Pavel Machek
...but the moment you start blocking tasks that done driver request, you _do_ have mini-freezer of your own, with pretty much the same problems.
No, not at all the same problems. Those tasks will block, but that will be harmless because we won't have some "freezer" things waiting for all tasks to reach a "stable" point (calling
try_to_freeze()). We just let them block wherever we want, as long as it doesn't prevent a -driver- from suspending, which should be allright, we have no problem.
Will you be able to guarantee that every place where a task can/will block will be harmless place? If so, how will you guarantee that? How will you debug issues where a task occasionally doesn't block in the right place, particularly instances where it is some less than obvious interaction with other tasks?
This is the whole point to having the freezer. It makes things more predictable and testable. It shows us, clearly, when process X is the one that is causing problems.
Quoted 4 lines
Quoted 2 lines
In another message I shown that removing freezer will not help with FUSE in general case.
I disagree.
Why?
Quoted 24 lines
Quoted 3 lines
It probably does not help with firmware, too; as soon as udev attempts to do something with your wireless card, it is blocked, and if the wireless card needs the firmware from udev, you are deadlocked.
Firmware load has been a problem since day 1, I've talked about it multiple times, it's broken with or without the freezer, and so far, the reaction of pretty much everybody has been to dig their head deeper in the mud and ignore the problem.
There are other issues (again, with or without freezer) that should be dealt with. For example, drivers that haven't yet got their
suspend()callback or already have got theirresume()may rely on services of the kernel that are still blocked, that's where things may go hairy.request_firmware()withinresume()is a typical example of that.There are a few things we should do in that area. For example, once we start to call driver suspend's, we should probably set a system wide flag that will do things such as:
- block usermode helpers (either make
call_usermodehelperreturn
something like-EBUSYor have it queue up the calls and issue them later when thing are resuming, we need to look closely at what semantic we want here).
Quoted 5 lines
- Silently add
GFP_NOIOto all allocations, to avoid having things
blocking inkmalloc()with a mutex held that will deadlock withsuspend()in a driver for example. Or set some way to have all GFP waiters wakeup and fail rather than wait for IOs. It's hard/bizarre but necessary, again, with or without a freezer.
GFP_ATOMIC? (In driver suspend, they shouldn't be sleeping either, right?)
Quoted 7 lines
- Deal with the firmware problem. The best way is probably to have an
asyncrequest_firmwareinterface(). Another thing is, drivers may want to cache their firmware in main memory, that sort of thing...And that's just a small list off the top of my mind, of known problems that will cause deadlocks or misbehaviours today, with or without the freezer, and that need to be addressed.
Userspace device drivers too?
Regards,
Nigel
Hi.
Quoted 11 lines · On Friday 06 July 2007 08:46:54 Benjamin Herrenschmidt wrote:
Quoted 4 lines · Pavel Machek
...but the moment you start blocking tasks that done driver request, you _do_ have mini-freezer of your own, with pretty much the same problems.
No, not at all the same problems. Those tasks will block, but that will be harmless because we won't have some "freezer" things waiting for all tasks to reach a "stable" point (calling
try_to_freeze()). We just let them block wherever we want, as long as it doesn't prevent a -driver- from suspending, which should be allright, we have no problem.
Will you be able to guarantee that every place where a task can/will block will be harmless place? If so, how will you guarantee that? How will you debug issues where a task occasionally doesn't block in the right place, particularly instances where it is some less than obvious interaction with other tasks?
This is the whole point to having the freezer. It makes things more predictable and testable. It shows us, clearly, when process X is the one that is causing problems.
Quoted 4 lines
Quoted 2 lines
In another message I shown that removing freezer will not help with FUSE in general case.
I disagree.
Why?
Quoted 24 lines
Quoted 3 lines
It probably does not help with firmware, too; as soon as udev attempts to do something with your wireless card, it is blocked, and if the wireless card needs the firmware from udev, you are deadlocked.
Firmware load has been a problem since day 1, I've talked about it multiple times, it's broken with or without the freezer, and so far, the reaction of pretty much everybody has been to dig their head deeper in the mud and ignore the problem.
There are other issues (again, with or without freezer) that should be dealt with. For example, drivers that haven't yet got their
suspend()callback or already have got theirresume()may rely on services of the kernel that are still blocked, that's where things may go hairy.request_firmware()withinresume()is a typical example of that.There are a few things we should do in that area. For example, once we start to call driver suspend's, we should probably set a system wide flag that will do things such as:
- block usermode helpers (either make
call_usermodehelperreturn
something like-EBUSYor have it queue up the calls and issue them later when thing are resuming, we need to look closely at what semantic we want here).
Quoted 5 lines
- Silently add
GFP_NOIOto all allocations, to avoid having things
blocking inkmalloc()with a mutex held that will deadlock withsuspend()in a driver for example. Or set some way to have all GFP waiters wakeup and fail rather than wait for IOs. It's hard/bizarre but necessary, again, with or without a freezer.
GFP_ATOMIC? (In driver suspend, they shouldn't be sleeping either, right?)
Quoted 7 lines
- Deal with the firmware problem. The best way is probably to have an
asyncrequest_firmwareinterface(). Another thing is, drivers may want to cache their firmware in main memory, that sort of thing...And that's just a small list off the top of my mind, of known problems that will cause deadlocks or misbehaviours today, with or without the freezer, and that need to be addressed.
Userspace device drivers too?
Regards,
Nigel
Quoted 6 lines
Will you be able to guarantee that every place where a task can/will block will be harmless place? If so, how will you guarantee that? How will you debug issues where a task occasionally doesn't block in the right place, particularly instances where it is some less than obvious interaction with other tasks?
Which places aren't harmless if you don't have a freezer ?
Quoted 3 lines
This is the whole point to having the freezer. It makes things more predictable and testable. It shows us, clearly, when process X is the one that is causing problems.
No, the freezer creates all those places what are harmful for a task to block because they will break the freezer :-)
Quoted 7 lines
Quoted 5 lines
- Silently add
GFP_NOIOto all allocations, to avoid having things
blocking inkmalloc()with a mutex held that will deadlock withsuspend()in a driver for example. Or set some way to have all GFP waiters wakeup and fail rather than wait for IOs. It's hard/bizarre but necessary, again, with or without a freezer.
GFP_ATOMIC? (In driver suspend, they shouldn't be sleeping either, right?)
NOIO should be enough I think but ATOMIC would do).
That's one of the reason why I used to have the pre-suspend and post-resume hooks in my original powermac implementation, for those few drivers complicated enough to require some pre-allocations.
Quoted 4 lines
Quoted 4 lines
- Deal with the firmware problem. The best way is probably to have an
asyncrequest_firmwareinterface(). Another thing is, drivers may want to cache their firmware in main memory, that sort of thing...
Note that the above firmware problem could be dealt with also with the pre-suspend/post-resume. Allowing to pre-request firmware etc... and keep it around until after resume, because we know we will need it. Gives a chance to drivers to perform things while the system is still live, filesystems still working, etc... (big memory allocations for example).
Quoted 5 lines
Quoted 3 lines
And that's just a small list off the top of my mind, of known problems that will cause deadlocks or misbehaviours today, with or without the freezer, and that need to be addressed.
Userspace device drivers too?
Maybe but they are less of an issue, most of the time, they don't do DMA or whatever harmful things. If they are USB drivers, for example, they are an non-issues at that level.
Quoted 6 lines
Will you be able to guarantee that every place where a task can/will block will be harmless place? If so, how will you guarantee that? How will you debug issues where a task occasionally doesn't block in the right place, particularly instances where it is some less than obvious interaction with other tasks?
Which places aren't harmless if you don't have a freezer ?
Quoted 3 lines
This is the whole point to having the freezer. It makes things more predictable and testable. It shows us, clearly, when process X is the one that is causing problems.
No, the freezer creates all those places what are harmful for a task to block because they will break the freezer :-)
Quoted 7 lines
Quoted 5 lines
- Silently add
GFP_NOIOto all allocations, to avoid having things
blocking inkmalloc()with a mutex held that will deadlock withsuspend()in a driver for example. Or set some way to have all GFP waiters wakeup and fail rather than wait for IOs. It's hard/bizarre but necessary, again, with or without a freezer.
GFP_ATOMIC? (In driver suspend, they shouldn't be sleeping either, right?)
NOIO should be enough I think but ATOMIC would do).
That's one of the reason why I used to have the pre-suspend and post-resume hooks in my original powermac implementation, for those few drivers complicated enough to require some pre-allocations.
Quoted 4 lines
Quoted 4 lines
- Deal with the firmware problem. The best way is probably to have an
asyncrequest_firmwareinterface(). Another thing is, drivers may want to cache their firmware in main memory, that sort of thing...
Note that the above firmware problem could be dealt with also with the pre-suspend/post-resume. Allowing to pre-request firmware etc... and keep it around until after resume, because we know we will need it. Gives a chance to drivers to perform things while the system is still live, filesystems still working, etc... (big memory allocations for example).
Quoted 5 lines
Quoted 3 lines
And that's just a small list off the top of my mind, of known problems that will cause deadlocks or misbehaviours today, with or without the freezer, and that need to be addressed.
Userspace device drivers too?
Maybe but they are less of an issue, most of the time, they don't do DMA or whatever harmful things. If they are USB drivers, for example, they are an non-issues at that level.
Hi.
Quoted 8 lines · On Friday 06 July 2007 09:20:43 Benjamin Herrenschmidt wrote:
Quoted 6 lines
Will you be able to guarantee that every place where a task can/will block will be harmless place? If so, how will you guarantee that? How will you debug issues where a task occasionally doesn't block in the right place, particularly instances where it is some less than obvious interaction with other tasks?
Which places aren't harmless if you don't have a freezer ?
If I knew that, I wouldn't be asking the question.
Quoted 6 lines
Quoted 3 lines
This is the whole point to having the freezer. It makes things more predictable and testable. It shows us, clearly, when process X is the one that is causing problems.
No, the freezer creates all those places what are harmful for a task to block because they will break the freezer :-)
Nice try :) Okay then, you remove the freezer, try hibernating, then get back to me after you've fixed your filesystem because some process that wasn't frozen started writing things after the atomic copy (making the on disk filesystem inconsistent with the snapshot).
As Pavel rightly said, you can get rid of the freezer, but you're only going to have to implement another one that does the essentially the same thing, even if it is at some other level.
Quoted 30 lines
Quoted 7 lines
Quoted 5 lines
- Silently add
GFP_NOIOto all allocations, to avoid having things
blocking inkmalloc()with a mutex held that will deadlock withsuspend()in a driver for example. Or set some way to have all GFP waiters wakeup and fail rather than wait for IOs. It's hard/bizarre but necessary, again, with or without a freezer.
GFP_ATOMIC? (In driver suspend, they shouldn't be sleeping either, right?)NOIO should be enough I think but ATOMIC would do).
That's one of the reason why I used to have the pre-suspend and post-resume hooks in my original powermac implementation, for those few drivers complicated enough to require some pre-allocations.
Quoted 4 lines
Quoted 4 lines
- Deal with the firmware problem. The best way is probably to have an
asyncrequest_firmwareinterface(). Another thing is, drivers may want to cache their firmware in main memory, that sort of thing...Note that the above firmware problem could be dealt with also with the pre-suspend/post-resume. Allowing to pre-request firmware etc... and keep it around until after resume, because we know we will need it. Gives a chance to drivers to perform things while the system is still live, filesystems still working, etc... (big memory allocations for example).
Quoted 4 lines
Quoted 3 lines
And that's just a small list off the top of my mind, of known problems that will cause deadlocks or misbehaviours today, with or without the freezer, and that need to be addressed.
Quoted 5 lines
Quoted 1 line
Userspace device drivers too?
Maybe but they are less of an issue, most of the time, they don't do DMA or whatever harmful things. If they are USB drivers, for example, they are an non-issues at that level.
(Leaving the rest of the message intact so we don't have to fragment the discussion into a million subthreads).
Regards,
Nigel
Hi.
Quoted 8 lines · On Friday 06 July 2007 09:20:43 Benjamin Herrenschmidt wrote:
Quoted 6 lines
Will you be able to guarantee that every place where a task can/will block will be harmless place? If so, how will you guarantee that? How will you debug issues where a task occasionally doesn't block in the right place, particularly instances where it is some less than obvious interaction with other tasks?
Which places aren't harmless if you don't have a freezer ?
If I knew that, I wouldn't be asking the question.
Quoted 6 lines
Quoted 3 lines
This is the whole point to having the freezer. It makes things more predictable and testable. It shows us, clearly, when process X is the one that is causing problems.
No, the freezer creates all those places what are harmful for a task to block because they will break the freezer :-)
Nice try :) Okay then, you remove the freezer, try hibernating, then get back to me after you've fixed your filesystem because some process that wasn't frozen started writing things after the atomic copy (making the on disk filesystem inconsistent with the snapshot).
As Pavel rightly said, you can get rid of the freezer, but you're only going to have to implement another one that does the essentially the same thing, even if it is at some other level.
Quoted 30 lines
Quoted 7 lines
Quoted 5 lines
- Silently add
GFP_NOIOto all allocations, to avoid having things
blocking inkmalloc()with a mutex held that will deadlock withsuspend()in a driver for example. Or set some way to have all GFP waiters wakeup and fail rather than wait for IOs. It's hard/bizarre but necessary, again, with or without a freezer.
GFP_ATOMIC? (In driver suspend, they shouldn't be sleeping either, right?)NOIO should be enough I think but ATOMIC would do).
That's one of the reason why I used to have the pre-suspend and post-resume hooks in my original powermac implementation, for those few drivers complicated enough to require some pre-allocations.
Quoted 4 lines
Quoted 4 lines
- Deal with the firmware problem. The best way is probably to have an
asyncrequest_firmwareinterface(). Another thing is, drivers may want to cache their firmware in main memory, that sort of thing...Note that the above firmware problem could be dealt with also with the pre-suspend/post-resume. Allowing to pre-request firmware etc... and keep it around until after resume, because we know we will need it. Gives a chance to drivers to perform things while the system is still live, filesystems still working, etc... (big memory allocations for example).
Quoted 4 lines
Quoted 3 lines
And that's just a small list off the top of my mind, of known problems that will cause deadlocks or misbehaviours today, with or without the freezer, and that need to be addressed.
Quoted 5 lines
Quoted 1 line
Userspace device drivers too?
Maybe but they are less of an issue, most of the time, they don't do DMA or whatever harmful things. If they are USB drivers, for example, they are an non-issues at that level.
(Leaving the rest of the message intact so we don't have to fragment the discussion into a million subthreads).
Regards,
Nigel
Quoted 4 lines · Nigel Cunningham
Quoted 1 line · On Friday 06 July 2007 09:20:43 Benjamin Herrenschmidt wrote:
No, the freezer creates all those places what are harmful for a task to block because they will break the freezer :-)
Nice try :) Okay then, you remove the freezer, try hibernating, then get back to me after you've fixed your filesystem because some process that wasn't frozen started writing things after the atomic copy (making the on disk filesystem inconsistent with the snapshot).
Umm, this thread is NOT ABOUT HIBERNATING!!! Please go back and read the subject, specifically the "suspend to RAM" parts :-D. When your hardware can put itself to sleep and atomically preserve memory as it does so, you don't need an atomic copy. For Real Suspend(TM) (IE: Suspend-to-RAM), the list of things to do is short and simple:
1) Stop DMA and put most hardware into low-power states (stops all interrupt sources) 2) Ensure that the other CPUs have finished any trailing interrupt handlers and put them to sleep 3) Put the interrupt-controllers into low-power state 4) Go to sleep
Quoted 1 line
As Pavel rightly said, you can get rid of the freezer, but you're only going to have to implement another one that does the essentially the same thing, even if it is at some other level.
How about a freezer whose job it is to "wait for pending hard interrupts to complete when we have already guaranteed that we won't get any more"? That part should be really *REALLY* easy. You don't need to care about either userspace processes or kernel threads at all. Specifically, Step 1 consists of:
suspend_device(dev)
{
set_no_bind_flag(dev);
for (dev->subdevices)
suspend_device(dev);
set_no_io_flag(dev);
wait_for_in_progress_dma(dev);
turn_off_interrupts(dev);
go_to_low_power_state(dev);
}After you've set the "no_bind" flag, you won't get any *new* subdevices trying to bind, therefore it's safe to iterate over the list of present sub-devices and suspend them. Once those are suspended and in low-power states you can set a "no_io" flag to prevent the driver from submitting more IO. At that point you can lazily wait for existing DMA/IO/interrupts to finish on the device, since *NOBODY* will be submitting them anymore, and we certainly aren't probing for new devices. Then you can just turn off the power to the device. When all the leaf devices are off, the parent device can be turned off because everything waiting on the leaf devices is blocked on them and won't unblock until the parent device *AND* the leaf device are turned on again, in that order.
Scheduling and userspace are all still fully enabled in this scenario. Once all your devices are turned off, the only remaining running threads will be those which haven't done IO since the beginning of the suspend. We can then disable preemption, turn off the timer interrupts, and tell the other CPUs to park all their remaining threads in schedule() and sleep. Then we put the IRQ controller to sleep and go to sleep ourselves. If our driver model locking is sufficient to handle putting a parent device to sleep while threads are sleeping on a child device then there are exactly 0 problems.
Resuming is basically running the whole process in reverse. Runtime-suspend is achieved by not setting the 'no_io' or 'no_bind' flags and putting selective device-subtrees to sleep without doing anything to the rest of the system.
Cheers,
Kyle Moffett
Quoted 4 lines · Nigel Cunningham
Quoted 1 line · On Friday 06 July 2007 09:20:43 Benjamin Herrenschmidt wrote:
No, the freezer creates all those places what are harmful for a task to block because they will break the freezer :-)
Nice try :) Okay then, you remove the freezer, try hibernating, then get back to me after you've fixed your filesystem because some process that wasn't frozen started writing things after the atomic copy (making the on disk filesystem inconsistent with the snapshot).
Umm, this thread is NOT ABOUT HIBERNATING!!! Please go back and read the subject, specifically the "suspend to RAM" parts :-D. When your hardware can put itself to sleep and atomically preserve memory as it does so, you don't need an atomic copy. For Real Suspend(TM) (IE: Suspend-to-RAM), the list of things to do is short and simple:
1) Stop DMA and put most hardware into low-power states (stops all interrupt sources) 2) Ensure that the other CPUs have finished any trailing interrupt handlers and put them to sleep 3) Put the interrupt-controllers into low-power state 4) Go to sleep
Quoted 1 line
As Pavel rightly said, you can get rid of the freezer, but you're only going to have to implement another one that does the essentially the same thing, even if it is at some other level.
How about a freezer whose job it is to "wait for pending hard interrupts to complete when we have already guaranteed that we won't get any more"? That part should be really *REALLY* easy. You don't need to care about either userspace processes or kernel threads at all. Specifically, Step 1 consists of:
suspend_device(dev)
{
set_no_bind_flag(dev);
for (dev->subdevices)
suspend_device(dev);
set_no_io_flag(dev);
wait_for_in_progress_dma(dev);
turn_off_interrupts(dev);
go_to_low_power_state(dev);
}After you've set the "no_bind" flag, you won't get any *new* subdevices trying to bind, therefore it's safe to iterate over the list of present sub-devices and suspend them. Once those are suspended and in low-power states you can set a "no_io" flag to prevent the driver from submitting more IO. At that point you can lazily wait for existing DMA/IO/interrupts to finish on the device, since *NOBODY* will be submitting them anymore, and we certainly aren't probing for new devices. Then you can just turn off the power to the device. When all the leaf devices are off, the parent device can be turned off because everything waiting on the leaf devices is blocked on them and won't unblock until the parent device *AND* the leaf device are turned on again, in that order.
Scheduling and userspace are all still fully enabled in this scenario. Once all your devices are turned off, the only remaining running threads will be those which haven't done IO since the beginning of the suspend. We can then disable preemption, turn off the timer interrupts, and tell the other CPUs to park all their remaining threads in schedule() and sleep. Then we put the IRQ controller to sleep and go to sleep ourselves. If our driver model locking is sufficient to handle putting a parent device to sleep while threads are sleeping on a child device then there are exactly 0 problems.
Resuming is basically running the whole process in reverse. Runtime-suspend is achieved by not setting the 'no_io' or 'no_bind' flags and putting selective device-subtrees to sleep without doing anything to the rest of the system.
Cheers,
Kyle Moffett
Hi.
Quoted 10 lines · On Friday 06 July 2007 11:19:32 Kyle Moffett wrote:
Quoted 8 lines · Nigel Cunningham
Quoted 2 lines · On Friday 06 July 2007 09:20:43 Benjamin Herrenschmidt wrote:
No, the freezer creates all those places what are harmful for a task to block because they will break the freezer :-)
Nice try :) Okay then, you remove the freezer, try hibernating, then get back to me after you've fixed your filesystem because some process that wasn't frozen started writing things after the atomic copy (making the on disk filesystem inconsistent with the snapshot).
Quoted 5 lines
Umm, this thread is NOT ABOUT HIBERNATING!!! Please go back and read the subject, specifically the "suspend to RAM" parts :-D. When your hardware can put itself to sleep and atomically preserve memory as it does so, you don't need an atomic copy. For Real Suspend(TM) (IE:
Suspend-to-RAM), the list of things to do is short and simple:
We agreed a while back that you don't need the freezer for suspend to ram. As far as I was aware, we went off-topic, so the topic is out of date.
Quoted 28 lines
1) Stop DMA and put most hardware into low-power states (stops all interrupt sources)
2) Ensure that the other CPUs have finished any trailing interrupt handlers and put them to sleep
3) Put the interrupt-controllers into low-power state
4) Go to sleepQuoted 3 lines
As Pavel rightly said, you can get rid of the freezer, but you're only going to have to implement another one that does the essentially the same thing, even if it is at some other level.
How about a freezer whose job it is to "wait for pending hard interrupts to complete when we have already guaranteed that we won't get any more"? That part should be really *REALLY* easy. You don't need to care about either userspace processes or kernel threads at all. Specifically, Step 1 consists of:
suspend_device(dev){ set_no_bind_flag(dev); for (dev->subdevices) suspend_device(dev); set_no_io_flag(dev); wait_for_in_progress_dma(dev); turn_off_interrupts(dev); go_to_low_power_state(dev); }
Quoted 12 lines
After you've set the "
no_bind" flag, you won't get any *new* subdevices trying to bind, therefore it's safe to iterate over the list of present sub-devices and suspend them. Once those are suspended and in low-power states you can set a "no_io" flag to prevent the driver from submitting more IO. At that point you can lazily wait for existing DMA/IO/interrupts to finish on the device, since *NOBODY* will be submitting them anymore, and we certainly aren't probing for new devices. Then you can just turn off the power to the device. When all the leaf devices are off, the parent device can be turned off because everything waiting on the leaf devices is blocked on them and won't unblock until the parent device *AND* the leaf device are turned on again, in that order.
For suspending, yes. For hibernating, that's not enough, because other processes can still be happily allocating and freeing memory, and will only get stopped when they try to do i/o or such like. If you're trying to make hibernation reliable, you need to be able to reliably check whether you're going to have enough storage for the image you're preparing, and enough memory for the atomic copy and so on. That's why the freezer is needed for hibernation. If you don't have it, any hibernation implementation you make is going to be only as reliable as the extent to which the system is otherwise idle.
Quoted 11 lines
Scheduling and userspace are all still fully enabled in this scenario. Once all your devices are turned off, the only remaining running threads will be those which haven't done IO since the beginning of the suspend. We can then disable preemption, turn off the timer interrupts, and tell the other CPUs to park all their remaining threads in
schedule()and sleep. Then we put the IRQ controller to sleep and go to sleep ourselves. If our driver model locking is sufficient to handle putting a parent device to sleep while threads are sleeping on a child device then there are exactly 0 problems.
Quoted 4 lines
Resuming is basically running the whole process in reverse. Runtime- suspend is achieved by not setting the '
no_io' or 'no_bind' flags and putting selective device-subtrees to sleep without doing anything to the rest of the system.
Fully agree when it comes to suspend to ram. There, this process should work, so far as I can see. But as I said, we went - to one degree or another - off topic, and did discuss hibernation too.
Regards,
Nigel
Signature · 2 lines
See http://www.tuxonice.net for Howtos, FAQs, mailing lists, wiki and bugzilla info.
Hi.
Quoted 10 lines · On Friday 06 July 2007 11:19:32 Kyle Moffett wrote:
Quoted 8 lines · Nigel Cunningham
Quoted 2 lines · On Friday 06 July 2007 09:20:43 Benjamin Herrenschmidt wrote:
No, the freezer creates all those places what are harmful for a task to block because they will break the freezer :-)
Nice try :) Okay then, you remove the freezer, try hibernating, then get back to me after you've fixed your filesystem because some process that wasn't frozen started writing things after the atomic copy (making the on disk filesystem inconsistent with the snapshot).
Quoted 5 lines
Umm, this thread is NOT ABOUT HIBERNATING!!! Please go back and read the subject, specifically the "suspend to RAM" parts :-D. When your hardware can put itself to sleep and atomically preserve memory as it does so, you don't need an atomic copy. For Real Suspend(TM) (IE:
Suspend-to-RAM), the list of things to do is short and simple:
We agreed a while back that you don't need the freezer for suspend to ram. As far as I was aware, we went off-topic, so the topic is out of date.
Quoted 28 lines
1) Stop DMA and put most hardware into low-power states (stops all interrupt sources)
2) Ensure that the other CPUs have finished any trailing interrupt handlers and put them to sleep
3) Put the interrupt-controllers into low-power state
4) Go to sleepQuoted 3 lines
As Pavel rightly said, you can get rid of the freezer, but you're only going to have to implement another one that does the essentially the same thing, even if it is at some other level.
How about a freezer whose job it is to "wait for pending hard interrupts to complete when we have already guaranteed that we won't get any more"? That part should be really *REALLY* easy. You don't need to care about either userspace processes or kernel threads at all. Specifically, Step 1 consists of:
suspend_device(dev){ set_no_bind_flag(dev); for (dev->subdevices) suspend_device(dev); set_no_io_flag(dev); wait_for_in_progress_dma(dev); turn_off_interrupts(dev); go_to_low_power_state(dev); }
Quoted 12 lines
After you've set the "
no_bind" flag, you won't get any *new* subdevices trying to bind, therefore it's safe to iterate over the list of present sub-devices and suspend them. Once those are suspended and in low-power states you can set a "no_io" flag to prevent the driver from submitting more IO. At that point you can lazily wait for existing DMA/IO/interrupts to finish on the device, since *NOBODY* will be submitting them anymore, and we certainly aren't probing for new devices. Then you can just turn off the power to the device. When all the leaf devices are off, the parent device can be turned off because everything waiting on the leaf devices is blocked on them and won't unblock until the parent device *AND* the leaf device are turned on again, in that order.
For suspending, yes. For hibernating, that's not enough, because other processes can still be happily allocating and freeing memory, and will only get stopped when they try to do i/o or such like. If you're trying to make hibernation reliable, you need to be able to reliably check whether you're going to have enough storage for the image you're preparing, and enough memory for the atomic copy and so on. That's why the freezer is needed for hibernation. If you don't have it, any hibernation implementation you make is going to be only as reliable as the extent to which the system is otherwise idle.
Quoted 11 lines
Scheduling and userspace are all still fully enabled in this scenario. Once all your devices are turned off, the only remaining running threads will be those which haven't done IO since the beginning of the suspend. We can then disable preemption, turn off the timer interrupts, and tell the other CPUs to park all their remaining threads in
schedule()and sleep. Then we put the IRQ controller to sleep and go to sleep ourselves. If our driver model locking is sufficient to handle putting a parent device to sleep while threads are sleeping on a child device then there are exactly 0 problems.
Quoted 4 lines
Resuming is basically running the whole process in reverse. Runtime- suspend is achieved by not setting the '
no_io' or 'no_bind' flags and putting selective device-subtrees to sleep without doing anything to the rest of the system.
Fully agree when it comes to suspend to ram. There, this process should work, so far as I can see. But as I said, we went - to one degree or another - off topic, and did discuss hibernation too.
Regards,
Nigel
Signature · 2 lines
See http://www.tuxonice.net for Howtos, FAQs, mailing lists, wiki and bugzilla info.
Quoted 6 lines
How about a freezer whose job it is to "wait for pending hard interrupts to complete when we have already guaranteed that we won't get any more"? That part should be really *REALLY* easy. You don't need to care about either userspace processes or kernel threads at all. Specifically, Step 1 consists of:
Well, waiting for pending DMA and making sure to not trigger more activity is what driver suspend() is supposed to do. With the ability for simple drivers that can cope with it to just basically use a late_suspend(), called after IRQs are off, that basically does what you
describe: wait for pending HW tasks to complete (polling) and turn the damn thing off.
Note that the later is really a shortcut for somewhat dump and directly accessible devices (PCI comes to mind). Things like USB has to use the "normal" mechanism of blocking IOs etc... at suspend(), at least, USB devices have to since the USB HC will not issue any new URBs. (And will return them with a nice error code which is a perfect way to deal with it in driver, been there, it works fine, once we fixed the races in the USB host code itself, which I think we pretty much did by now).
Quoted 10 lines
Scheduling and userspace are all still fully enabled in this scenario. Once all your devices are turned off, the only remaining running threads will be those which haven't done IO since the beginning of the suspend. We can then disable preemption, turn off the timer interrupts, and tell the other CPUs to park all their remaining threads in
schedule()and sleep. Then we put the IRQ controller to sleep and go to sleep ourselves. If our driver model locking is sufficient to handle putting a parent device to sleep while threads are sleeping on a child device then there are exactly 0 problems.
What you propose is basically a slightly over-simplistic version of what I think (and Paulus think) should be done. We do need to do it via driver callbacks down the tree since only drivers can know how to deal with their DMA etc... and ordering need to be respected, but that's basically it.
And guess what ? It's what we do on powerbooks, and it works fine, without a freezer :-)
Ben.
Quoted 6 lines
How about a freezer whose job it is to "wait for pending hard interrupts to complete when we have already guaranteed that we won't get any more"? That part should be really *REALLY* easy. You don't need to care about either userspace processes or kernel threads at all. Specifically, Step 1 consists of:
Well, waiting for pending DMA and making sure to not trigger more activity is what driver suspend() is supposed to do. With the ability for simple drivers that can cope with it to just basically use a late_suspend(), called after IRQs are off, that basically does what you
describe: wait for pending HW tasks to complete (polling) and turn the damn thing off.
Note that the later is really a shortcut for somewhat dump and directly accessible devices (PCI comes to mind). Things like USB has to use the "normal" mechanism of blocking IOs etc... at suspend(), at least, USB devices have to since the USB HC will not issue any new URBs. (And will return them with a nice error code which is a perfect way to deal with it in driver, been there, it works fine, once we fixed the races in the USB host code itself, which I think we pretty much did by now).
Quoted 10 lines
Scheduling and userspace are all still fully enabled in this scenario. Once all your devices are turned off, the only remaining running threads will be those which haven't done IO since the beginning of the suspend. We can then disable preemption, turn off the timer interrupts, and tell the other CPUs to park all their remaining threads in
schedule()and sleep. Then we put the IRQ controller to sleep and go to sleep ourselves. If our driver model locking is sufficient to handle putting a parent device to sleep while threads are sleeping on a child device then there are exactly 0 problems.
What you propose is basically a slightly over-simplistic version of what I think (and Paulus think) should be done. We do need to do it via driver callbacks down the tree since only drivers can know how to deal with their DMA etc... and ordering need to be respected, but that's basically it.
And guess what ? It's what we do on powerbooks, and it works fine, without a freezer :-)
Ben.
Quoted 33 lines · Benjamin Herrenschmidt
Quoted 6 lines
How about a freezer whose job it is to "wait for pending hard interrupts to complete when we have already guaranteed that we won't get any more"? That part should be really *REALLY* easy. You don't need to care about either userspace processes or kernel threads at all. Specifically, Step 1 consists of:
Well, waiting for pending DMA and making sure to not trigger more activity is what driver
suspend()is supposed to do. With the ability for simple drivers that can cope with it to just basically use alate_suspend(), called after IRQs are off, that basically does what you
describe: wait for pending HW tasks to complete (polling) and turn the damn thing off.Note that the later is really a shortcut for somewhat dump and directly accessible devices (PCI comes to mind). Things like USB has to use the "normal" mechanism of blocking IOs etc... at
suspend(), at least, USB devices have to since the USB HC will not issue any new URBs. (And will return them with a nice error code which is a perfect way to deal with it in driver, been there, it works fine, once we fixed the races in the USB host code itself, which I think we pretty much did by now).Quoted 10 lines
Scheduling and userspace are all still fully enabled in this scenario. Once all your devices are turned off, the only remaining running threads will be those which haven't done IO since the beginning of the suspend. We can then disable preemption, turn off the timer interrupts, and tell the other CPUs to park all their remaining threads in
schedule()and sleep. Then we put the IRQ controller to sleep and go to sleep ourselves. If our driver model locking is sufficient to handle putting a parent device to sleep while threads are sleeping on a child device then there are exactly 0 problems.
Quoted 8 lines
What you propose is basically a slightly over-simplistic version of what I think (and Paulus think) should be done. We do need to do it via driver callbacks down the tree since only drivers can know how to deal with their DMA etc... and ordering need to be respected, but that's basically it.
And guess what ? It's what we do on powerbooks, and it works fine, without a freezer :-)
On powerbooks you disable the nonboot CPUs before suspending devices, which simplifies things _a_ _lot_ in comparison with the general case.
If you additionally disable kernel preemption, then you don't need anything like the freezer anyway in that case (except for detecting situations in which the suspend process can deadlock with a task stuck in the D state holding a lock, but that's overkill).
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Quoted 3 lines
On powerbooks you disable the nonboot CPUs before suspending devices, which simplifies things _a_ _lot_ in comparison with the general case.
Not that much actually. It avoids having to gather them all in the last stage at the low level but that isn't really related to what we are talking about right now.
Quoted 4 lines
If you additionally disable kernel preemption, then you don't need anything like the freezer anyway in that case (except for detecting situations in which the suspend process can deadlock with a task stuck in the D state holding a lock, but that's overkill).
kernel preemption and SMP have nothing to do with it. You can still schedule because one of the driver suspend() callback is schedul'ing, maybe waiting for some requests to complete, etc... Happens typically with the disk suspend callbacks.
I agree that it does lower the likelyness of having a userspace process pound on the wrong driver at the wrong time though.
Ben.
Quoted 3 lines
On powerbooks you disable the nonboot CPUs before suspending devices, which simplifies things _a_ _lot_ in comparison with the general case.
Not that much actually. It avoids having to gather them all in the last stage at the low level but that isn't really related to what we are talking about right now.
Quoted 4 lines
If you additionally disable kernel preemption, then you don't need anything like the freezer anyway in that case (except for detecting situations in which the suspend process can deadlock with a task stuck in the D state holding a lock, but that's overkill).
kernel preemption and SMP have nothing to do with it. You can still schedule because one of the driver suspend() callback is schedul'ing, maybe waiting for some requests to complete, etc... Happens typically with the disk suspend callbacks.
I agree that it does lower the likelyness of having a userspace process pound on the wrong driver at the wrong time though.
Ben.
Quoted 8 lines · Benjamin Herrenschmidt
What you propose is basically a slightly over-simplistic version of what I think (and Paulus think) should be done. We do need to do it via driver callbacks down the tree since only drivers can know how to deal with their DMA etc... and ordering need to be respected, but that's basically it.
And guess what ? It's what we do on powerbooks, and it works fine, without a freezer :-)
I wish you'd stop saying that. Have you ever done any serious testing?
Here's something to try: Add a time delay to the end of hub_suspend in drivers/usb/core/hub.c, so you can provoke a race manually. Then while one of your root hubs is being suspended and the system is waiting in that delay, either plug in a new USB device to that hub or unplug an existing device.
Be sure that CONFIG_USB_DEBUG is on so that we can figure out what happened after the fact.
Alan Stern
Quoted 8 lines · Benjamin Herrenschmidt
What you propose is basically a slightly over-simplistic version of what I think (and Paulus think) should be done. We do need to do it via driver callbacks down the tree since only drivers can know how to deal with their DMA etc... and ordering need to be respected, but that's basically it.
And guess what ? It's what we do on powerbooks, and it works fine, without a freezer :-)
I wish you'd stop saying that. Have you ever done any serious testing?
Here's something to try: Add a time delay to the end of hub_suspend in drivers/usb/core/hub.c, so you can provoke a race manually. Then while one of your root hubs is being suspended and the system is waiting in that delay, either plug in a new USB device to that hub or unplug an existing device.
Be sure that CONFIG_USB_DEBUG is on so that we can figure out what happened after the fact.
Alan Stern
Quoted 13 lines · Alan Stern
Quoted 8 lines · Benjamin Herrenschmidt
What you propose is basically a slightly over-simplistic version of what I think (and Paulus think) should be done. We do need to do it via driver callbacks down the tree since only drivers can know how to deal with their DMA etc... and ordering need to be respected, but that's basically it.
And guess what ? It's what we do on powerbooks, and it works fine, without a freezer :-)
I wish you'd stop saying that. Have you ever done any serious testing?
Quoted 8 lines
Here's something to try: Add a time delay to the end of
hub_suspendindrivers/usb/core/hub.c, so you can provoke a race manually. Then while one of your root hubs is being suspended and the system is waiting in that delay, either plug in a new USB device to that hub or unplug an existing device.Be sure that
CONFIG_USB_DEBUGis on so that we can figure out what happened after the fact.
If you remember, one of the things I've been advocating has always been that we should put on hold all plug activity (unplug might be alright as long as the user events are just delayed) when we start suspending. No new devices, no new bindings. "hub" type devices are respondible for bringing in the new stuff after resume.
Ben.
Hi!
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
And guess what ? It's what we do on powerbooks, and it works fine, without a freezer :-)
Well, issue is, you should stop claiming it works fine until issue below is fixed... please?
And anyway I believe that current issue (fuse deadlocks with s2ram) should be present on powerbooks, too... it is just way harder to trigger. All that is neccessary is fused (or one of its helpers) to get frozen by accessing suspended device.
Pavel
Quoted 16 lines
Quoted 10 lines
I wish you'd stop saying that. Have you ever done any serious testing?
Here's something to try: Add a time delay to the end of
hub_suspendindrivers/usb/core/hub.c, so you can provoke a race manually. Then while one of your root hubs is being suspended and the system is waiting in that delay, either plug in a new USB device to that hub or unplug an existing device.Be sure that
CONFIG_USB_DEBUGis on so that we can figure out what happened after the fact.If you remember, one of the things I've been advocating has always been that we should put on hold all plug activity (unplug might be alright as long as the user events are just delayed) when we start suspending. No new devices, no new bindings. "hub" type devices are respondible for bringing in the new stuff after resume.
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 4 lines · Pavel Machek
And anyway I believe that current issue (fuse deadlocks with s2ram) should be present on powerbooks, too... it is just way harder to trigger. All that is neccessary is fused (or one of its helpers) to get frozen by accessing suspended device.
I don't see any fuse specific issue without a freezer, but I see generic issues such as kmalloc blocking in a driver with a mutex held etc... but I've talked about these already. They have nothing to do with the freezer though.
Ben.
Quoted 8 lines · Benjamin Herrenschmidt
Quoted 2 lines
Quoted 2 lines
And guess what ? It's what we do on powerbooks, and it works fine, without a freezer :-)
If you remember, one of the things I've been advocating has always been that we should put on hold all plug activity (unplug might be alright as long as the user events are just delayed) when we start suspending. No new devices, no new bindings. "hub" type devices are respondible for bringing in the new stuff after resume.
Which is exactly my point. It _doesn't_ work fine without a freezer, because the USB stack currently relies on the freezer to prevent plug activity.
Alan Stern
Quoted 11 lines · Alan Stern
Quoted 8 lines · Benjamin Herrenschmidt
Quoted 2 lines
Quoted 2 lines
And guess what ? It's what we do on powerbooks, and it works fine, without a freezer :-)
If you remember, one of the things I've been advocating has always been that we should put on hold all plug activity (unplug might be alright as long as the user events are just delayed) when we start suspending. No new devices, no new bindings. "hub" type devices are respondible for bringing in the new stuff after resume.
Quoted 3 lines
Which is exactly my point. It _doesn't_ work fine without a freezer, because the USB stack currently relies on the freezer to prevent plug activity.
Putting on hold plug activity has nothing, NOTHING, to do with the half assed piece of deadlocking crap we have now we call a freezer.
As long as you guys keep mixing up all the issues and coming up with totally bogus solutions that cannot work, we won't have a useful suspend (either to RAM or to disk) in linux.
Ben.
Quoted 11 lines · Alan Stern
Quoted 8 lines · Benjamin Herrenschmidt
Quoted 2 lines
Quoted 2 lines
And guess what ? It's what we do on powerbooks, and it works fine, without a freezer :-)
If you remember, one of the things I've been advocating has always been that we should put on hold all plug activity (unplug might be alright as long as the user events are just delayed) when we start suspending. No new devices, no new bindings. "hub" type devices are respondible for bringing in the new stuff after resume.
Quoted 3 lines
Which is exactly my point. It _doesn't_ work fine without a freezer, because the USB stack currently relies on the freezer to prevent plug activity.
Putting on hold plug activity has nothing, NOTHING, to do with the half assed piece of deadlocking crap we have now we call a freezer.
As long as you guys keep mixing up all the issues and coming up with totally bogus solutions that cannot work, we won't have a useful suspend (either to RAM or to disk) in linux.
Ben.
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 3 lines
Which is exactly my point. It _doesn't_ work fine without a freezer, because the USB stack currently relies on the freezer to prevent plug activity.
Putting on hold plug activity has nothing, NOTHING, to do with the half assed piece of deadlocking crap we have now we call a freezer.
You're wrong; it _does_ have something to do with the freezer. The connection is that the code uses the freezer to put plug activity on hold.
You probably meant to say that it _should_ have nothing to do with the freezer. That's a different matter. But in any case you should write what you actually mean, rather than just putting down something as inflammatory as possible.
Quoted 3 lines
As long as you guys keep mixing up all the issues and coming up with totally bogus solutions that cannot work, we won't have a useful suspend (either to RAM or to disk) in linux.
In my defense, you should realize that until Rafael's notifier chain was added (just a few weeks ago, still not in mainline I believe) there was no other way to do it. Plug activity needs to be stopped before the child devices are suspended, and the PM core does not send any notification to drivers at that time. All it does is activate the freezer.
Alan Stern
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 3 lines
Which is exactly my point. It _doesn't_ work fine without a freezer, because the USB stack currently relies on the freezer to prevent plug activity.
Putting on hold plug activity has nothing, NOTHING, to do with the half assed piece of deadlocking crap we have now we call a freezer.
You're wrong; it _does_ have something to do with the freezer. The connection is that the code uses the freezer to put plug activity on hold.
You probably meant to say that it _should_ have nothing to do with the freezer. That's a different matter. But in any case you should write what you actually mean, rather than just putting down something as inflammatory as possible.
Quoted 3 lines
As long as you guys keep mixing up all the issues and coming up with totally bogus solutions that cannot work, we won't have a useful suspend (either to RAM or to disk) in linux.
In my defense, you should realize that until Rafael's notifier chain was added (just a few weeks ago, still not in mainline I believe) there was no other way to do it. Plug activity needs to be stopped before the child devices are suspended, and the PM core does not send any notification to drivers at that time. All it does is activate the freezer.
Alan Stern
Quoted 7 lines
In my defense, you should realize that until Rafael's notifier chain was added (just a few weeks ago, still not in mainline I believe) there was no other way to do it. Plug activity needs to be stopped before the child devices are suspended, and the PM core does not send any notification to drivers at that time. All it does is activate the freezer.
That's true. That was one of the reason I've always wanted the pre-suspend and post-resume hooks. (I prefer keeping the ordering there too, rather than a notifier, but a notifier is fine I suppose).
Among the clients we want here the firmware stuff, the allocators, etc... to get themselves in conditions that won't deadlock during suspend cycle.
I think that's a much bigger issue overall than freezer vs. no freezer :-)
Ben.
Quoted 12 lines · Benjamin Herrenschmidt
Quoted 7 lines
In my defense, you should realize that until Rafael's notifier chain was added (just a few weeks ago, still not in mainline I believe) there was no other way to do it. Plug activity needs to be stopped before the child devices are suspended, and the PM core does not send any notification to drivers at that time. All it does is activate the freezer.
That's true. That was one of the reason I've always wanted the pre-suspend and post-resume hooks. (I prefer keeping the ordering there too, rather than a notifier, but a notifier is fine I suppose).
Quoted 6 lines
Among the clients we want here the firmware stuff, the allocators, etc... to get themselves in conditions that won't deadlock during suspend cycle.
I think that's a much bigger issue overall than freezer vs. no freezer :-)
Yes. The freezer is only one part of the PM infrastructure that we have currently and that is not very sophisticated, so to speak.
I'm all for changing this infrastructure, but in an organized way (ie. we discuss what to do next, we do that and then we go to the next step) and in the order that everyone will be comfortable with.
So, let's finish this thread and start over from discussing what needs to be done, how (ie. in what order etc.) we are going to do that and who is going to do what. Shall we?
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Quoted 7 lines · Rafael J. Wysocki
I'm all for changing this infrastructure, but in an organized way (ie. we discuss what to do next, we do that and then we go to the next step) and in the order that everyone will be comfortable with.
So, let's finish this thread and start over from discussing what needs to be done, how (ie. in what order etc.) we are going to do that and who is going to do what. Shall we?
IMO we should start by using the new notifier chain and by implementing a central "icebox" routine. Then we can forbid device registration during suspend.
It might also be a good idea to add a freezable keventd-like workqueue specifically intended for things that need to block during a suspend. Although maybe this will end up being unnecessary; it's too soon to tell.
Alan Stern
Quoted 7 lines · Rafael J. Wysocki
I'm all for changing this infrastructure, but in an organized way (ie. we discuss what to do next, we do that and then we go to the next step) and in the order that everyone will be comfortable with.
So, let's finish this thread and start over from discussing what needs to be done, how (ie. in what order etc.) we are going to do that and who is going to do what. Shall we?
IMO we should start by using the new notifier chain and by implementing a central "icebox" routine. Then we can forbid device registration during suspend.
It might also be a good idea to add a freezable keventd-like workqueue specifically intended for things that need to block during a suspend. Although maybe this will end up being unnecessary; it's too soon to tell.
Alan Stern
Hi!
Quoted 8 lines
Quoted 7 lines
I'm all for changing this infrastructure, but in an organized way (ie. we discuss what to do next, we do that and then we go to the next step) and in the order that everyone will be comfortable with.
So, let's finish this thread and start over from discussing what needs to be done, how (ie. in what order etc.) we are going to do that and who is going to do what. Shall we?
Quoted 8 lines
IMO we should start by using the new notifier chain and by implementing a central "icebox" routine. Then we can forbid device registration during suspend.
It might also be a good idea to add a freezable keventd-like workqueue specifically intended for things that need to block during a suspend. Although maybe this will end up being unnecessary; it's too soon to tell.
We actually had patches for freezeable workqueues at one point.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Hi!
Quoted 8 lines
Quoted 7 lines
I'm all for changing this infrastructure, but in an organized way (ie. we discuss what to do next, we do that and then we go to the next step) and in the order that everyone will be comfortable with.
So, let's finish this thread and start over from discussing what needs to be done, how (ie. in what order etc.) we are going to do that and who is going to do what. Shall we?
Quoted 8 lines
IMO we should start by using the new notifier chain and by implementing a central "icebox" routine. Then we can forbid device registration during suspend.
It might also be a good idea to add a freezable keventd-like workqueue specifically intended for things that need to block during a suspend. Although maybe this will end up being unnecessary; it's too soon to tell.
We actually had patches for freezeable workqueues at one point.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 10 lines · Alan Stern
Quoted 7 lines · Rafael J. Wysocki
I'm all for changing this infrastructure, but in an organized way (ie. we discuss what to do next, we do that and then we go to the next step) and in the order that everyone will be comfortable with.
So, let's finish this thread and start over from discussing what needs to be done, how (ie. in what order etc.) we are going to do that and who is going to do what. Shall we?
Quoted 8 lines
IMO we should start by using the new notifier chain and by implementing a central "icebox" routine. Then we can forbid device registration during suspend.
It might also be a good idea to add a freezable keventd-like workqueue specifically intended for things that need to block during a suspend. Although maybe this will end up being unnecessary; it's too soon to tell.
I think looking at the kmallo/gfp issue I mentioned earlier should be done asap. I can try to spare some time for it this week but I can't promise, I'm actually swamped by something totally unrelated at the moment.
Another issue that's been a problem forever with suspend is the synchronous request_firmware interface. Lots of drivers do that in resume() which will generally not work.
Ben.
Quoted 10 lines · Alan Stern
Quoted 7 lines · Rafael J. Wysocki
I'm all for changing this infrastructure, but in an organized way (ie. we discuss what to do next, we do that and then we go to the next step) and in the order that everyone will be comfortable with.
So, let's finish this thread and start over from discussing what needs to be done, how (ie. in what order etc.) we are going to do that and who is going to do what. Shall we?
Quoted 8 lines
IMO we should start by using the new notifier chain and by implementing a central "icebox" routine. Then we can forbid device registration during suspend.
It might also be a good idea to add a freezable keventd-like workqueue specifically intended for things that need to block during a suspend. Although maybe this will end up being unnecessary; it's too soon to tell.
I think looking at the kmallo/gfp issue I mentioned earlier should be done asap. I can try to spare some time for it this week but I can't promise, I'm actually swamped by something totally unrelated at the moment.
Another issue that's been a problem forever with suspend is the synchronous request_firmware interface. Lots of drivers do that in resume() which will generally not work.
Ben.
Am Sonntag, 8. Juli 2007 schrieb Benjamin Herrenschmidt:
Quoted 3 lines
Another issue that's been a problem forever with suspend is the synchronous
request_firmwareinterface. Lots of drivers do that inresume()which will generally not work.
Unfortunately yes they do. We now have the notifier chains, which can be used. Firmware, especially if it is large, must be requested while the system is still fully functional and paging will work.
Asynchronocity will not help much because the devices must work after resumingand delaying that will not help with respect to needing devices to get at the firmware.
Regards
Oliver
Am Sonntag, 8. Juli 2007 schrieb Benjamin Herrenschmidt:
Quoted 3 lines
Another issue that's been a problem forever with suspend is the synchronous
request_firmwareinterface. Lots of drivers do that inresume()which will generally not work.
Unfortunately yes they do. We now have the notifier chains, which can be used. Firmware, especially if it is large, must be requested while the system is still fully functional and paging will work.
Asynchronocity will not help much because the devices must work after resumingand delaying that will not help with respect to needing devices to get at the firmware.
Regards
Oliver
Quoted 5 lines · Oliver Neukum
Am Sonntag, 8. Juli 2007 schrieb Benjamin Herrenschmidt:
Quoted 3 lines
Another issue that's been a problem forever with suspend is the synchronous
request_firmwareinterface. Lots of drivers do that inresume()which will generally not work.
Quoted 7 lines
Unfortunately yes they do. We now have the notifier chains, which can be used. Firmware, especially if it is large, must be requested while the system is still fully functional and paging will work.
Asynchronocity will not help much because the devices must work after resumingand delaying that will not help with respect to needing devices to get at the firmware.
True, pre-loading is the best approach.
Ben.
Quoted 10 lines · Benjamin Herrenschmidt
Quoted 9 lines · Oliver Neukum
Am Sonntag, 8. Juli 2007 schrieb Benjamin Herrenschmidt:
Quoted 3 lines
Another issue that's been a problem forever with suspend is the synchronous
request_firmwareinterface. Lots of drivers do that inresume()which will generally not work.Unfortunately yes they do. We now have the notifier chains, which can be used. Firmware, especially if it is large, must be requested while the system is still fully functional and paging will work.
Quoted 5 lines
Quoted 3 lines
Asynchronocity will not help much because the devices must work after resumingand delaying that will not help with respect to needing devices to get at the firmware.
True, pre-loading is the best approach.
Agreed.
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Quoted 10 lines · Benjamin Herrenschmidt
Quoted 9 lines · Oliver Neukum
Am Sonntag, 8. Juli 2007 schrieb Benjamin Herrenschmidt:
Quoted 3 lines
Another issue that's been a problem forever with suspend is the synchronous
request_firmwareinterface. Lots of drivers do that inresume()which will generally not work.Unfortunately yes they do. We now have the notifier chains, which can be used. Firmware, especially if it is large, must be requested while the system is still fully functional and paging will work.
Quoted 5 lines
Quoted 3 lines
Asynchronocity will not help much because the devices must work after resumingand delaying that will not help with respect to needing devices to get at the firmware.
True, pre-loading is the best approach.
Agreed.
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Quoted 12 lines · Benjamin Herrenschmidt
Quoted 7 lines
In my defense, you should realize that until Rafael's notifier chain was added (just a few weeks ago, still not in mainline I believe) there was no other way to do it. Plug activity needs to be stopped before the child devices are suspended, and the PM core does not send any notification to drivers at that time. All it does is activate the freezer.
That's true. That was one of the reason I've always wanted the pre-suspend and post-resume hooks. (I prefer keeping the ordering there too, rather than a notifier, but a notifier is fine I suppose).
Quoted 6 lines
Among the clients we want here the firmware stuff, the allocators, etc... to get themselves in conditions that won't deadlock during suspend cycle.
I think that's a much bigger issue overall than freezer vs. no freezer :-)
Yes. The freezer is only one part of the PM infrastructure that we have currently and that is not very sophisticated, so to speak.
I'm all for changing this infrastructure, but in an organized way (ie. we discuss what to do next, we do that and then we go to the next step) and in the order that everyone will be comfortable with.
So, let's finish this thread and start over from discussing what needs to be done, how (ie. in what order etc.) we are going to do that and who is going to do what. Shall we?
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Quoted 22 lines · Alan Stern
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 3 lines
Which is exactly my point. It _doesn't_ work fine without a freezer, because the USB stack currently relies on the freezer to prevent plug activity.
Putting on hold plug activity has nothing, NOTHING, to do with the half assed piece of deadlocking crap we have now we call a freezer.
You're wrong; it _does_ have something to do with the freezer. The connection is that the code uses the freezer to put plug activity on hold.
You probably meant to say that it _should_ have nothing to do with the freezer. That's a different matter. But in any case you should write what you actually mean, rather than just putting down something as inflammatory as possible.
Quoted 3 lines
As long as you guys keep mixing up all the issues and coming up with totally bogus solutions that cannot work, we won't have a useful suspend (either to RAM or to disk) in linux.
Quoted 6 lines
In my defense, you should realize that until Rafael's notifier chain was added (just a few weeks ago, still not in mainline I believe) there was no other way to do it. Plug activity needs to be stopped before the child devices are suspended, and the PM core does not send any notification to drivers at that time. All it does is activate the freezer.
Exactly.
And if we really want to get rid of the freezer, we need to _prepare_ for that. At least, we need to have an idea of how we will do thing when the freezer is not there.
For example, how will we check if the system is not in a state in which the resume is likely to fail?
There are more questions like that, IMO, and we should at least have a list of them _before_ we remove the freezer.
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Quoted 22 lines · Alan Stern
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 3 lines
Which is exactly my point. It _doesn't_ work fine without a freezer, because the USB stack currently relies on the freezer to prevent plug activity.
Putting on hold plug activity has nothing, NOTHING, to do with the half assed piece of deadlocking crap we have now we call a freezer.
You're wrong; it _does_ have something to do with the freezer. The connection is that the code uses the freezer to put plug activity on hold.
You probably meant to say that it _should_ have nothing to do with the freezer. That's a different matter. But in any case you should write what you actually mean, rather than just putting down something as inflammatory as possible.
Quoted 3 lines
As long as you guys keep mixing up all the issues and coming up with totally bogus solutions that cannot work, we won't have a useful suspend (either to RAM or to disk) in linux.
Quoted 6 lines
In my defense, you should realize that until Rafael's notifier chain was added (just a few weeks ago, still not in mainline I believe) there was no other way to do it. Plug activity needs to be stopped before the child devices are suspended, and the PM core does not send any notification to drivers at that time. All it does is activate the freezer.
Exactly.
And if we really want to get rid of the freezer, we need to _prepare_ for that. At least, we need to have an idea of how we will do thing when the freezer is not there.
For example, how will we check if the system is not in a state in which the resume is likely to fail?
There are more questions like that, IMO, and we should at least have a list of them _before_ we remove the freezer.
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Quoted 12 lines · Benjamin Herrenschmidt
Quoted 11 lines · Alan Stern
Quoted 8 lines · Benjamin Herrenschmidt
Quoted 2 lines
Quoted 2 lines
And guess what ? It's what we do on powerbooks, and it works fine, without a freezer :-)
If you remember, one of the things I've been advocating has always been that we should put on hold all plug activity (unplug might be alright as long as the user events are just delayed) when we start suspending. No new devices, no new bindings. "hub" type devices are respondible for bringing in the new stuff after resume.
Quoted 6 lines
Quoted 3 lines
Which is exactly my point. It _doesn't_ work fine without a freezer, because the USB stack currently relies on the freezer to prevent plug activity.
Putting on hold plug activity has nothing, NOTHING, to do with the half assed piece of deadlocking crap we have now we call a freezer.
Well, no matter how much bad names you will call it, that's what in use right now and it's not _that_ easy to get rid of.
I'm perfectly fine with readying drivers etc. for dropping the freezer, but in the meantime bugs in the freezer need to be fixed, if possible.
And if it deadlocks, there is a bug in it.
Quoted 3 lines
As long as you guys keep mixing up all the issues and coming up with totally bogus solutions that cannot work, we won't have a useful suspend (either to RAM or to disk) in linux.
Discussion at this level would be totally counterproductive and wouldn't lead to anything constructive, so let me avoid commenting your abusive remarks.
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Quoted 12 lines · Benjamin Herrenschmidt
Quoted 11 lines · Alan Stern
Quoted 8 lines · Benjamin Herrenschmidt
Quoted 2 lines
Quoted 2 lines
And guess what ? It's what we do on powerbooks, and it works fine, without a freezer :-)
If you remember, one of the things I've been advocating has always been that we should put on hold all plug activity (unplug might be alright as long as the user events are just delayed) when we start suspending. No new devices, no new bindings. "hub" type devices are respondible for bringing in the new stuff after resume.
Quoted 6 lines
Quoted 3 lines
Which is exactly my point. It _doesn't_ work fine without a freezer, because the USB stack currently relies on the freezer to prevent plug activity.
Putting on hold plug activity has nothing, NOTHING, to do with the half assed piece of deadlocking crap we have now we call a freezer.
Well, no matter how much bad names you will call it, that's what in use right now and it's not _that_ easy to get rid of.
I'm perfectly fine with readying drivers etc. for dropping the freezer, but in the meantime bugs in the freezer need to be fixed, if possible.
And if it deadlocks, there is a bug in it.
Quoted 3 lines
As long as you guys keep mixing up all the issues and coming up with totally bogus solutions that cannot work, we won't have a useful suspend (either to RAM or to disk) in linux.
Discussion at this level would be totally counterproductive and wouldn't lead to anything constructive, so let me avoid commenting your abusive remarks.
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Quoted 2 lines · Kyle Moffett
Umm, this thread is NOT ABOUT HIBERNATING!!! Please go back and read the subject, specifically the "suspend to RAM" parts :-D.
But it _is_ about the freezer; see the "Remove process freezer" part. :-) Since the freezer is used during hibernation, hibernation is a legitimate topic.
Quoted 11 lines
When your
hardware can put itself to sleep and atomically preserve memory as it does so, you don't need an atomic copy. For Real Suspend(TM) (IE:
Suspend-to-RAM), the list of things to do is short and simple:1) Stop DMA and put most hardware into low-power states (stops all interrupt sources)
2) Ensure that the other CPUs have finished any trailing interrupt handlers and put them to sleep
3) Put the interrupt-controllers into low-power state
4) Go to sleep
Your short and simple list omits a few crucial items:
A) Decide what to do about remote wakeup requests.
B) Prevent I/O requests from resuming devices that have been suspended.
C) Prevent devices and drivers from being registered or unregistered; in particular decide what to do about hot-plug or hot-unplug events.
D) Block driver bind or unbind calls.
Any of these things is capable of screwing up the course of events. (In fact A _should_ be allowed to abort a suspend.)
Quoted 21 lines
Quoted 3 lines
As Pavel rightly said, you can get rid of the freezer, but you're only going to have to implement another one that does the essentially the same thing, even if it is at some other level.
How about a freezer whose job it is to "wait for pending hard interrupts to complete when we have already guaranteed that we won't get any more"? That part should be really *REALLY* easy. You don't need to care about either userspace processes or kernel threads at all. Specifically, Step 1 consists of:
suspend_device(dev){ set_no_bind_flag(dev); for (dev->subdevices) suspend_device(dev); set_no_io_flag(dev); wait_for_in_progress_dma(dev); turn_off_interrupts(dev); go_to_low_power_state(dev); }
Quoted 2 lines
After you've set the "
no_bind" flag, you won't get any *new* subdevices trying to bind,
So what happens if a new subdevice arrives at the wrong time? Do you block instead of binding it? While holding a mutex needed to suspend the parent device?
What about drivers trying to bind to existing devices?
What happens to I/O requests submitted after the "no_io" flag is set? The driver will have to block them, effectively creating its own little "freezer".
Quoted 11 lines
therefore it's safe to iterate over the
list of present sub-devices and suspend them. Once those are suspended and in low-power states you can set a "no_io" flag to prevent the driver from submitting more IO. At that point you can lazily wait for existing DMA/IO/interrupts to finish on the device, since *NOBODY* will be submitting them anymore, and we certainly aren't probing for new devices. Then you can just turn off the power to the device. When all the leaf devices are off, the parent device can be turned off because everything waiting on the leaf devices is blocked on them and won't unblock until the parent device *AND* the leaf device are turned on again, in that order.
This is a lot like what we already do. The differences are:
There is nothing corresponding to your "no-bind" flag.
Most drivers don't have anything like your "no_io" flag; they assume that nobody will be around to submit an I/O request.
Quoted 11 lines
Scheduling and userspace are all still fully enabled in this scenario. Once all your devices are turned off, the only remaining running threads will be those which haven't done IO since the beginning of the suspend. We can then disable preemption, turn off the timer interrupts, and tell the other CPUs to park all their remaining threads in
schedule()and sleep. Then we put the IRQ controller to sleep and go to sleep ourselves. If our driver model locking is sufficient to handle putting a parent device to sleep while threads are sleeping on a child device then there are exactly 0 problems.
Quoted 4 lines
Resuming is basically running the whole process in reverse. Runtime- suspend is achieved by not setting the '
no_io' or 'no_bind' flags and putting selective device-subtrees to sleep without doing anything to the rest of the system.
Nobody doubts that suspend can be made to work without the freezer. The point is that doing it this way dumps a bunch of extra responsibility on drivers.
Alan Stern
Quoted 2 lines · Kyle Moffett
Umm, this thread is NOT ABOUT HIBERNATING!!! Please go back and read the subject, specifically the "suspend to RAM" parts :-D.
But it _is_ about the freezer; see the "Remove process freezer" part. :-) Since the freezer is used during hibernation, hibernation is a legitimate topic.
Quoted 11 lines
When your
hardware can put itself to sleep and atomically preserve memory as it does so, you don't need an atomic copy. For Real Suspend(TM) (IE:
Suspend-to-RAM), the list of things to do is short and simple:1) Stop DMA and put most hardware into low-power states (stops all interrupt sources)
2) Ensure that the other CPUs have finished any trailing interrupt handlers and put them to sleep
3) Put the interrupt-controllers into low-power state
4) Go to sleep
Your short and simple list omits a few crucial items:
A) Decide what to do about remote wakeup requests.
B) Prevent I/O requests from resuming devices that have been suspended.
C) Prevent devices and drivers from being registered or unregistered; in particular decide what to do about hot-plug or hot-unplug events.
D) Block driver bind or unbind calls.
Any of these things is capable of screwing up the course of events. (In fact A _should_ be allowed to abort a suspend.)
Quoted 21 lines
Quoted 3 lines
As Pavel rightly said, you can get rid of the freezer, but you're only going to have to implement another one that does the essentially the same thing, even if it is at some other level.
How about a freezer whose job it is to "wait for pending hard interrupts to complete when we have already guaranteed that we won't get any more"? That part should be really *REALLY* easy. You don't need to care about either userspace processes or kernel threads at all. Specifically, Step 1 consists of:
suspend_device(dev){ set_no_bind_flag(dev); for (dev->subdevices) suspend_device(dev); set_no_io_flag(dev); wait_for_in_progress_dma(dev); turn_off_interrupts(dev); go_to_low_power_state(dev); }
Quoted 2 lines
After you've set the "
no_bind" flag, you won't get any *new* subdevices trying to bind,
So what happens if a new subdevice arrives at the wrong time? Do you block instead of binding it? While holding a mutex needed to suspend the parent device?
What about drivers trying to bind to existing devices?
What happens to I/O requests submitted after the "no_io" flag is set? The driver will have to block them, effectively creating its own little "freezer".
Quoted 11 lines
therefore it's safe to iterate over the
list of present sub-devices and suspend them. Once those are suspended and in low-power states you can set a "no_io" flag to prevent the driver from submitting more IO. At that point you can lazily wait for existing DMA/IO/interrupts to finish on the device, since *NOBODY* will be submitting them anymore, and we certainly aren't probing for new devices. Then you can just turn off the power to the device. When all the leaf devices are off, the parent device can be turned off because everything waiting on the leaf devices is blocked on them and won't unblock until the parent device *AND* the leaf device are turned on again, in that order.
This is a lot like what we already do. The differences are:
There is nothing corresponding to your "no-bind" flag.
Most drivers don't have anything like your "no_io" flag; they assume that nobody will be around to submit an I/O request.
Quoted 11 lines
Scheduling and userspace are all still fully enabled in this scenario. Once all your devices are turned off, the only remaining running threads will be those which haven't done IO since the beginning of the suspend. We can then disable preemption, turn off the timer interrupts, and tell the other CPUs to park all their remaining threads in
schedule()and sleep. Then we put the IRQ controller to sleep and go to sleep ourselves. If our driver model locking is sufficient to handle putting a parent device to sleep while threads are sleeping on a child device then there are exactly 0 problems.
Quoted 4 lines
Resuming is basically running the whole process in reverse. Runtime- suspend is achieved by not setting the '
no_io' or 'no_bind' flags and putting selective device-subtrees to sleep without doing anything to the rest of the system.
Nobody doubts that suspend can be made to work without the freezer. The point is that doing it this way dumps a bunch of extra responsibility on drivers.
Alan Stern
Quoted 4 lines · Alan Stern
Quoted 1 line · Kyle Moffett
Umm, this thread is NOT ABOUT HIBERNATING!!! Please go back and read the subject, specifically the "suspend to RAM" parts :-D.
But it _is_ about the freezer; see the "Remove process freezer" part. :-) Since the freezer is used during hibernation, hibernation is a legitimate topic.
Except Linus already decreed (and I heartily agree) that hibernation and suspend-to-RAM were fundamentally completely different operations and therefore any attempts to share code were basically just making a big muddy mess of things. Would a thread "Remove phase-of-the-moon calculations from network-recv code" be relevant to lunar observation just because the two had to do with the phases of the moon? No!
Quoted 10 lines
Quoted 6 lines
When your hardware can put itself to sleep and atomically preserve memory as it does so, you don't need an atomic copy. For Real Suspend(TM) (IE: Suspend-to-RAM), the list of things to do is short and simple:
1) Stop DMA and put most hardware into low-power states (stops all interrupt sources) 2) Ensure that the other CPUs have finished any trailing interrupt handlers and put them to sleep 3) Put the interrupt-controllers into low-power stat 4) Go to sleepYour short and simple list omits a few crucial items:
A) Decide what to do about remote wakeup requests.
Why do we care? If the wakeup request arrives before we go to sleep, we obviously aren't asleep and so can't wake up. If it arrives after we go to sleep then it will wake us up. Anything that depends on a wakeup arriving mid-sequence is 100% masochistic race condition.
Quoted 1 line
B) Prevent I/O requests from resuming devices that have been suspended.
(1a) As I describe below, step (1) includes setting NO_BIND and NO_IO flags on devices as they are processed. Anybody who wants to do IO while those flags are set should just go sleep on a waitqueue.
Quoted 1 line
C) Prevent devices and drivers from being registered or unregistered; in particular decide what to do about hot-plug or hot-unplug events.
(1b) Again, that's where the NO_BIND flag comes in. If its set then any device probe events must sleep, otherwise they can go through.
Quoted 1 line
D) Block driver bind or unbind calls.
See points (1a) and (1b) above.
Quoted 1 line
Any of these things is capable of screwing up the course of events. (In fact A _should_ be allowed to abort a suspend.)
If any of those things screw up suspend-to-RAM then it is 100% the drivers fault and no "process freezer" is going to fix it, end of story. And "A" cannot be made reliable. At some point you shut off interrupts right before going to sleep, and at that point any remote wakeup event is just going to get dropped until you actually enter sleep mode and the hardware takes over again. If you miss a wakeup event then whatever sent it should just retry, just as with *every* other kind of network packet.
Quoted 13 lines
Quoted 13 lines
How about a freezer whose job it is to "wait for pending hard interrupts to complete when we have already guaranteed that we won't get any more"? That part should be really *REALLY* easy. You don't need to care about either userspace processes or kernel threads at all. Specifically, Step 1 consists of:
suspend_device(dev){ set_no_bind_flag(dev); for (dev->subdevices) suspend_device(dev); set_no_io_flag(dev); wait_for_in_progress_dma(dev); turn_off_interrupts(dev); go_to_low_power_state(dev); }
Quoted 3 lines
Quoted 1 line
After you've set the "
no_bind" flag, you won't get any *new* subdevices trying to bind,So what happens if a new subdevice arrives at the wrong time? Do you block instead of binding it? While holding a mutex needed to suspend the parent device?
That would be a driver bug. If you have asynchronous probing then proper suspend handling includes being able to postpone driver probe events until after resume. If you have synchronous probing then the problem doesn't exist because "set_no_bind_flag" is just telling the device not to raise any more device probe interrupts.
Quoted 1 line
What about drivers trying to bind to existing devices?
While binding it will clearly be holding a mutex/spinlock on the parent device, so the suspend process will wait for it. When binding is done the suspend_device() code will take the device lock and tell everything else to postpone further bind requests as above.
Quoted 1 line
What happens to I/O requests submitted after the "
no_io" flag is set? The driver will have to block them, effectively creating its own little "freezer".
Oh, so you're calling every waitqueue in the kernel a "freezer" now? We do these things at the driver level *all* *the* *time*. For instance, you can't submit new IOs to an ATA controller while it's renegotiating the bus speed, but that's never been a problem before.
Quoted 7 lines
Quoted 1 line
When all the leaf devices are off, the parent device can be turned off because everything waiting on the leaf devices is blocked on them and won't unblock until the parent device *AND* the leaf device are turned on again, in that order.
This is a lot like what we already do. The differences are:
There is nothing corresponding to your "no-bind" flag.
Most drivers don't have anything like your "
no_io" flag; they assume that nobody will be around to submit an I/O request.
Most drivers have an implicit NO_BIND flag: The device's interrupts are off and/or its in a low-power state. USB is already terribly buggy with regards to suspend: If you hotplug a device during suspend (like the touchpad in my powerbook powering down/up), then the USB stack will basically hang that controller. The device is off and the hotplug triggers interrupts and IO, *EVEN* *WITHOUT* *USERSPACE*.
So if your driver doesn't already have a proper way of blocking IO during suspend then it probably doesn't suspend 50% of the time anyways. A bug which bites *every* *time* is easy to fix, one which only bites when things hit a race condition is much harder.
Quoted 3 lines
Quoted 1 line
Resuming is basically running the whole process in reverse. Runtime-suspend is achieved by not setting the '
no_io' or 'no_bind' flags and putting selective device-subtrees to sleep without doing anything to the rest of the system.Nobody doubts that suspend can be made to work without the freezer. The point is that doing it this way dumps a bunch of extra responsibility on drivers.
That responsibility has been there ever since suspend-to-RAM support was added. Nobody ever denied that writing a proper driver wasn't tricky. You have to simultaneously be able to handle handle hot-unplug, IO errors, interrupts, IO requests, suspend-to-RAM, and hibernation. If your driver mutual-exclusion is buggy then it probably already bites you during hotplug or other similar scenarios. Let's at least make the problems much more reproducible so we can fix the drivers properly instead of continuing to kludge around it for all eternity.
Cheers,
Kyle Moffett
Quoted 4 lines · Alan Stern
Quoted 1 line · Kyle Moffett
Umm, this thread is NOT ABOUT HIBERNATING!!! Please go back and read the subject, specifically the "suspend to RAM" parts :-D.
But it _is_ about the freezer; see the "Remove process freezer" part. :-) Since the freezer is used during hibernation, hibernation is a legitimate topic.
Except Linus already decreed (and I heartily agree) that hibernation and suspend-to-RAM were fundamentally completely different operations and therefore any attempts to share code were basically just making a big muddy mess of things. Would a thread "Remove phase-of-the-moon calculations from network-recv code" be relevant to lunar observation just because the two had to do with the phases of the moon? No!
Quoted 10 lines
Quoted 6 lines
When your hardware can put itself to sleep and atomically preserve memory as it does so, you don't need an atomic copy. For Real Suspend(TM) (IE: Suspend-to-RAM), the list of things to do is short and simple:
1) Stop DMA and put most hardware into low-power states (stops all interrupt sources) 2) Ensure that the other CPUs have finished any trailing interrupt handlers and put them to sleep 3) Put the interrupt-controllers into low-power stat 4) Go to sleepYour short and simple list omits a few crucial items:
A) Decide what to do about remote wakeup requests.
Why do we care? If the wakeup request arrives before we go to sleep, we obviously aren't asleep and so can't wake up. If it arrives after we go to sleep then it will wake us up. Anything that depends on a wakeup arriving mid-sequence is 100% masochistic race condition.
Quoted 1 line
B) Prevent I/O requests from resuming devices that have been suspended.
(1a) As I describe below, step (1) includes setting NO_BIND and NO_IO flags on devices as they are processed. Anybody who wants to do IO while those flags are set should just go sleep on a waitqueue.
Quoted 1 line
C) Prevent devices and drivers from being registered or unregistered; in particular decide what to do about hot-plug or hot-unplug events.
(1b) Again, that's where the NO_BIND flag comes in. If its set then any device probe events must sleep, otherwise they can go through.
Quoted 1 line
D) Block driver bind or unbind calls.
See points (1a) and (1b) above.
Quoted 1 line
Any of these things is capable of screwing up the course of events. (In fact A _should_ be allowed to abort a suspend.)
If any of those things screw up suspend-to-RAM then it is 100% the drivers fault and no "process freezer" is going to fix it, end of story. And "A" cannot be made reliable. At some point you shut off interrupts right before going to sleep, and at that point any remote wakeup event is just going to get dropped until you actually enter sleep mode and the hardware takes over again. If you miss a wakeup event then whatever sent it should just retry, just as with *every* other kind of network packet.
Quoted 13 lines
Quoted 13 lines
How about a freezer whose job it is to "wait for pending hard interrupts to complete when we have already guaranteed that we won't get any more"? That part should be really *REALLY* easy. You don't need to care about either userspace processes or kernel threads at all. Specifically, Step 1 consists of:
suspend_device(dev){ set_no_bind_flag(dev); for (dev->subdevices) suspend_device(dev); set_no_io_flag(dev); wait_for_in_progress_dma(dev); turn_off_interrupts(dev); go_to_low_power_state(dev); }
Quoted 3 lines
Quoted 1 line
After you've set the "
no_bind" flag, you won't get any *new* subdevices trying to bind,So what happens if a new subdevice arrives at the wrong time? Do you block instead of binding it? While holding a mutex needed to suspend the parent device?
That would be a driver bug. If you have asynchronous probing then proper suspend handling includes being able to postpone driver probe events until after resume. If you have synchronous probing then the problem doesn't exist because "set_no_bind_flag" is just telling the device not to raise any more device probe interrupts.
Quoted 1 line
What about drivers trying to bind to existing devices?
While binding it will clearly be holding a mutex/spinlock on the parent device, so the suspend process will wait for it. When binding is done the suspend_device() code will take the device lock and tell everything else to postpone further bind requests as above.
Quoted 1 line
What happens to I/O requests submitted after the "
no_io" flag is set? The driver will have to block them, effectively creating its own little "freezer".
Oh, so you're calling every waitqueue in the kernel a "freezer" now? We do these things at the driver level *all* *the* *time*. For instance, you can't submit new IOs to an ATA controller while it's renegotiating the bus speed, but that's never been a problem before.
Quoted 7 lines
Quoted 1 line
When all the leaf devices are off, the parent device can be turned off because everything waiting on the leaf devices is blocked on them and won't unblock until the parent device *AND* the leaf device are turned on again, in that order.
This is a lot like what we already do. The differences are:
There is nothing corresponding to your "no-bind" flag.
Most drivers don't have anything like your "
no_io" flag; they assume that nobody will be around to submit an I/O request.
Most drivers have an implicit NO_BIND flag: The device's interrupts are off and/or its in a low-power state. USB is already terribly buggy with regards to suspend: If you hotplug a device during suspend (like the touchpad in my powerbook powering down/up), then the USB stack will basically hang that controller. The device is off and the hotplug triggers interrupts and IO, *EVEN* *WITHOUT* *USERSPACE*.
So if your driver doesn't already have a proper way of blocking IO during suspend then it probably doesn't suspend 50% of the time anyways. A bug which bites *every* *time* is easy to fix, one which only bites when things hit a race condition is much harder.
Quoted 3 lines
Quoted 1 line
Resuming is basically running the whole process in reverse. Runtime-suspend is achieved by not setting the '
no_io' or 'no_bind' flags and putting selective device-subtrees to sleep without doing anything to the rest of the system.Nobody doubts that suspend can be made to work without the freezer. The point is that doing it this way dumps a bunch of extra responsibility on drivers.
That responsibility has been there ever since suspend-to-RAM support was added. Nobody ever denied that writing a proper driver wasn't tricky. You have to simultaneously be able to handle handle hot-unplug, IO errors, interrupts, IO requests, suspend-to-RAM, and hibernation. If your driver mutual-exclusion is buggy then it probably already bites you during hotplug or other similar scenarios. Let's at least make the problems much more reproducible so we can fix the drivers properly instead of continuing to kludge around it for all eternity.
Cheers,
Kyle Moffett
Quoted 6 lines · Kyle Moffett
Except Linus already decreed (and I heartily agree) that hibernation and suspend-to-RAM were fundamentally completely different operations and therefore any attempts to share code were basically just making a big muddy mess of things. Would a thread "Remove phase-of-the-moon calculations from network-recv code" be relevant to lunar observation just because the two had to do with the phases of the moon? No!
For that matter, shutting down a CPU and hibernation are fundamentally different operations -- but they both use the freezer. Is that a big muddy mess? But never mind; I won't discuss hibernation.
Quoted 6 lines
Quoted 1 line
A) Decide what to do about remote wakeup requests.
Why do we care? If the wakeup request arrives before we go to sleep, we obviously aren't asleep and so can't wake up. If it arrives after we go to sleep then it will wake us up. Anything that depends on a wakeup arriving mid-sequence is 100% masochistic race condition.
You don't understand my point. If a wakeup request arrives before the system goes to sleep, and it is serviced, then a device which ought to have been suspended will in fact be awake. This will (if the parent's driver is written correctly) cause the sleep transition to abort.
Not that there's necessarily anything wrong with that. I just wanted to be sure you were aware of the potential problems.
Quoted 6 lines
Quoted 3 lines
C) Prevent devices and drivers from being registered or unregistered; in particular decide what to do about hot-plug or hot- unplug events.
(1b) Again, that's where the
NO_BINDflag comes in. If its set then any device probe events must sleep, otherwise they can go through.
I didn't say "bind", I said "registered". Admittedly, they are rather similar.
Still, there are difficulties. Let's say a driver has set the NO_BIND flag for one of its devices. A bind request comes in, and the driver puts it on a waitqueue. Note that the binding thread holds the device semaphore; this is always true when a driver's probe routine is called.
Later on it comes time for the PM core to resume the device, which will start up the threads on the waitqueue. Before doing so it must acquire the device semaphore. Deadlock!
Quoted 3 lines
If any of those things screw up suspend-to-RAM then it is 100% the drivers fault and no "process freezer" is going to fix it, end of story.
Why do you say that? A "process freezer" can prevent bind and registration calls from occurring, since these calls have to run in process context. Ergo a freezer _can_ fix some of these problems.
Quoted 6 lines
And "A" cannot be made reliable. At some point you shut off
interrupts right before going to sleep, and at that point any remote wakeup event is just going to get dropped until you actually enter sleep mode and the hardware takes over again. If you miss a wakeup event then whatever sent it should just retry, just as with *every* other kind of network packet.
Who mentioned network packets? And who says a remote wakeup event will get dropped once interrupts are disabled? More likely it will set a bit somewhere that causes the system to wake up immediately after it has gone to sleep.
Quoted 7 lines
Quoted 3 lines
So what happens if a new subdevice arrives at the wrong time? Do you block instead of binding it? While holding a mutex needed to suspend the parent device?
That would be a driver bug. If you have asynchronous probing then proper suspend handling includes being able to postpone driver probe events until after resume.
One of your conditions (embodied in the pseudocode you posted earlier) was that drivers should be told to prevent binding and registration before the child devices are suspended. Currently the PM core doesn't do anything like that. You can't blame the drivers for this lack.
Of course it could be added. Or perhaps more easily, the drivers that support asynchronous probing could be notified when a suspend is about to start so they could begin blocking bindings/registrations then.
Quoted 4 lines
Quoted 1 line
What about drivers trying to bind to existing devices?
While binding it will clearly be holding a mutex/spinlock on the parent device,
("Parent device"? Do you mean the device being bound? If so then I agree. Or do you mean the device's parent? If so then your statement is not clear at all. There is special-case code in the driver core to make sure it is true for USB devices, and it looks ugly as can be.)
Quoted 3 lines
so the suspend process will wait for it. When binding
is done thesuspend_device()code will take the device lock and tell everything else to postpone further bind requests as above.
My question referred to drivers trying to bind or unbind a device _after_ the device has been suspended. I suppose you'll say that's covered by the NO_BIND flag. But now we have the locking problem mentioned above: The thread trying to bind is holding a lock which is needed for resuming.
Quoted 2 lines
Most drivers have an implicit
NO_BINDflag: The device's interrupts are off and/or its in a low-power state.
That won't cause binding to block or be postponed; it will cause it to fail. Not the same thing at all.
Quoted 6 lines
USB is already terribly
buggy with regards to suspend: If you hotplug a device during suspend (like the touchpad in my powerbook powering down/up), then the USB stack will basically hang that controller. The device is off and the hotplug triggers interrupts and IO, *EVEN* *WITHOUT* *USERSPACE*.
As one of the people responsible for the USB power management implementation, I would appreciate more details about this. For example, a dmesg log with CONFIG_USB_DEBUG turned on together with a complete description of the actions you took to provoke the bug.
(I wonder how much of this "buginess" is caused by the lack of the freezer in PPC.)
Quoted 4 lines
So if your driver doesn't already have a proper way of blocking IO during suspend then it probably doesn't suspend 50% of the time anyways. A bug which bites *every* *time* is easy to fix, one which only bites when things hit a race condition is much harder.
The USB drivers (at least, the ones with runtime PM support) rely on the freezer to block I/O during suspend. As far as I know, they do suspend properly, on systems where the freezer is used.
Quoted 9 lines
That responsibility has been there ever since suspend-to-RAM support was added. Nobody ever denied that writing a proper driver wasn't tricky. You have to simultaneously be able to handle handle hot- unplug, IO errors, interrupts, IO requests, suspend-to-RAM, and hibernation. If your driver mutual-exclusion is buggy then it probably already bites you during hotplug or other similar scenarios. Let's at least make the problems much more reproducible so we can fix the drivers properly instead of continuing to kludge around it for all eternity.
Is reproducibility really a problem at this stage? A bug which bites 50% of the time might not be quite as easy to fix as one which occurs every time, but it isn't terribly bad either.
Alan Stern
Quoted 6 lines · Kyle Moffett
Except Linus already decreed (and I heartily agree) that hibernation and suspend-to-RAM were fundamentally completely different operations and therefore any attempts to share code were basically just making a big muddy mess of things. Would a thread "Remove phase-of-the-moon calculations from network-recv code" be relevant to lunar observation just because the two had to do with the phases of the moon? No!
For that matter, shutting down a CPU and hibernation are fundamentally different operations -- but they both use the freezer. Is that a big muddy mess? But never mind; I won't discuss hibernation.
Quoted 6 lines
Quoted 1 line
A) Decide what to do about remote wakeup requests.
Why do we care? If the wakeup request arrives before we go to sleep, we obviously aren't asleep and so can't wake up. If it arrives after we go to sleep then it will wake us up. Anything that depends on a wakeup arriving mid-sequence is 100% masochistic race condition.
You don't understand my point. If a wakeup request arrives before the system goes to sleep, and it is serviced, then a device which ought to have been suspended will in fact be awake. This will (if the parent's driver is written correctly) cause the sleep transition to abort.
Not that there's necessarily anything wrong with that. I just wanted to be sure you were aware of the potential problems.
Quoted 6 lines
Quoted 3 lines
C) Prevent devices and drivers from being registered or unregistered; in particular decide what to do about hot-plug or hot- unplug events.
(1b) Again, that's where the
NO_BINDflag comes in. If its set then any device probe events must sleep, otherwise they can go through.
I didn't say "bind", I said "registered". Admittedly, they are rather similar.
Still, there are difficulties. Let's say a driver has set the NO_BIND flag for one of its devices. A bind request comes in, and the driver puts it on a waitqueue. Note that the binding thread holds the device semaphore; this is always true when a driver's probe routine is called.
Later on it comes time for the PM core to resume the device, which will start up the threads on the waitqueue. Before doing so it must acquire the device semaphore. Deadlock!
Quoted 3 lines
If any of those things screw up suspend-to-RAM then it is 100% the drivers fault and no "process freezer" is going to fix it, end of story.
Why do you say that? A "process freezer" can prevent bind and registration calls from occurring, since these calls have to run in process context. Ergo a freezer _can_ fix some of these problems.
Quoted 6 lines
And "A" cannot be made reliable. At some point you shut off
interrupts right before going to sleep, and at that point any remote wakeup event is just going to get dropped until you actually enter sleep mode and the hardware takes over again. If you miss a wakeup event then whatever sent it should just retry, just as with *every* other kind of network packet.
Who mentioned network packets? And who says a remote wakeup event will get dropped once interrupts are disabled? More likely it will set a bit somewhere that causes the system to wake up immediately after it has gone to sleep.
Quoted 7 lines
Quoted 3 lines
So what happens if a new subdevice arrives at the wrong time? Do you block instead of binding it? While holding a mutex needed to suspend the parent device?
That would be a driver bug. If you have asynchronous probing then proper suspend handling includes being able to postpone driver probe events until after resume.
One of your conditions (embodied in the pseudocode you posted earlier) was that drivers should be told to prevent binding and registration before the child devices are suspended. Currently the PM core doesn't do anything like that. You can't blame the drivers for this lack.
Of course it could be added. Or perhaps more easily, the drivers that support asynchronous probing could be notified when a suspend is about to start so they could begin blocking bindings/registrations then.
Quoted 4 lines
Quoted 1 line
What about drivers trying to bind to existing devices?
While binding it will clearly be holding a mutex/spinlock on the parent device,
("Parent device"? Do you mean the device being bound? If so then I agree. Or do you mean the device's parent? If so then your statement is not clear at all. There is special-case code in the driver core to make sure it is true for USB devices, and it looks ugly as can be.)
Quoted 3 lines
so the suspend process will wait for it. When binding
is done thesuspend_device()code will take the device lock and tell everything else to postpone further bind requests as above.
My question referred to drivers trying to bind or unbind a device _after_ the device has been suspended. I suppose you'll say that's covered by the NO_BIND flag. But now we have the locking problem mentioned above: The thread trying to bind is holding a lock which is needed for resuming.
Quoted 2 lines
Most drivers have an implicit
NO_BINDflag: The device's interrupts are off and/or its in a low-power state.
That won't cause binding to block or be postponed; it will cause it to fail. Not the same thing at all.
Quoted 6 lines
USB is already terribly
buggy with regards to suspend: If you hotplug a device during suspend (like the touchpad in my powerbook powering down/up), then the USB stack will basically hang that controller. The device is off and the hotplug triggers interrupts and IO, *EVEN* *WITHOUT* *USERSPACE*.
As one of the people responsible for the USB power management implementation, I would appreciate more details about this. For example, a dmesg log with CONFIG_USB_DEBUG turned on together with a complete description of the actions you took to provoke the bug.
(I wonder how much of this "buginess" is caused by the lack of the freezer in PPC.)
Quoted 4 lines
So if your driver doesn't already have a proper way of blocking IO during suspend then it probably doesn't suspend 50% of the time anyways. A bug which bites *every* *time* is easy to fix, one which only bites when things hit a race condition is much harder.
The USB drivers (at least, the ones with runtime PM support) rely on the freezer to block I/O during suspend. As far as I know, they do suspend properly, on systems where the freezer is used.
Quoted 9 lines
That responsibility has been there ever since suspend-to-RAM support was added. Nobody ever denied that writing a proper driver wasn't tricky. You have to simultaneously be able to handle handle hot- unplug, IO errors, interrupts, IO requests, suspend-to-RAM, and hibernation. If your driver mutual-exclusion is buggy then it probably already bites you during hotplug or other similar scenarios. Let's at least make the problems much more reproducible so we can fix the drivers properly instead of continuing to kludge around it for all eternity.
Is reproducibility really a problem at this stage? A bug which bites 50% of the time might not be quite as easy to fix as one which occurs every time, but it isn't terribly bad either.
Alan Stern
Quoted 10 lines
Quoted 4 lines
so the suspend process will wait for it. When binding
is done thesuspend_device()code will take the device lock and tell everything else to postpone further bind requests as above.My question referred to drivers trying to bind or unbind a device _after_ the device has been suspended. I suppose you'll say that's covered by the
NO_BINDflag. But now we have the locking problem mentioned above: The thread trying to bind is holding a lock which is needed for resuming.
Why would it ? Just make it fail, maybe with some kind of -ERETRY... Or it can spin with the lock not held if it want. That's a detail really.
Quoted 7 lines
As one of the people responsible for the USB power management implementation, I would appreciate more details about this. For example, a dmesg log with
CONFIG_USB_DEBUGturned on together with a complete description of the actions you took to provoke the bug.(I wonder how much of this "buginess" is caused by the lack of the freezer in PPC.)
No. The freezer will hide some of those problems under the carpet, but not solve the basic issue which is the driver should be solid. Period.
The freezer is a flawed concept in the first place. If you go back to square one, what is the basic idea of it ? I'll basically expose the idea and go down all of the path I have in mind where it stops working and becomes an incredibly difficult thing that in the end doesn't even solve all the problems it's supposed to.
So first thing first...
I want a quiescent system with no new "IO requests" (whatever that mean in the context of drivers) issued to avoid races during suspend/resume.
That sounds like a nice idea. Yeah. Sounds... only. Problem is. How do you define that quiescent system ? First idea is ... let's stop userland. There are various ways of doing that, but the freezer hooking into the signal code is not necessarily a bad one.
No, I'm purposefully putting aside all the cases where the above doesn't work (user process in the kernel in some uninterruptible wait, etc...), which are the first big setback imho... our simple idea is suddenly not so simple anymore, but we can bring those back later.
Now, there is still a problem... kernel threads. In fact, there is no fundamental distinction between a kernel thread and a user process... one has an MM and the other doesn't but as far as we are concerned, it's the same. Kernel threads can issues IOs, or like khubd, detect devices, plug/unplug them, etc etc.... all over the place.
Easy answer that comes to mind -> freeze them too. Heh, but kernel threads don't do signals, so we end up with all those try_to_freeze(). Then what about the fact that drivers may need those kernel threads to proceed ? Some drivers queue up their IO requests to a kernel thread to process them and suspend() might need to flush those down, issue a couple more such as "spin down disks" before that kernel thread can actually be frozen... Hrm.. maybe not all of them then.
But how do you decide ? What defines that a kernel can issue an IO ? In fact, if you look closely, anything doing kmalloc(...,GFP_KERNEL) for example can trigger an IO... implicitely, via the VM pushing things out. And that's just one example.
In some case, those same threads that may need to be kept non-frozen are -also- the ones that will potentially submit new IOs or bring in new devices.
And then, there is keventd ... what do you do about work queues ? You have everybody pouring things at workqueues... some of these things may well hit your driver, some may not. Same goes in some cases with interrupt time stuff, such as timers or tasklets.. think about networking.
In the end, the nice idea that "threads/tasks cause requests, so we just stop them" basically falls appart. Half of the kernel can cause a driver to be hit somewhere and a given time, it can be from a thread context, directly caused by userland, or from some timer due to some subsystem having a keepalive thing ticking in or whatever else.
Now, we go back to the previous issue of what do we do about uninterruptible sleep... You want to abort suspend because, for example, somethign called a driver that does an msleep(200) or so ? Are you aware that 99% of laptop users close their laptops and shove it in the bag not even waiting for the disk to spin down ? And you want suspend to abort because some random "happen all the time" even such as a process being somewhere temporarily in uninterruptible state in the kernel ?
So let's say we freeze them from within the scheduler even when they are uininterruptible.. ouch... you just caused the deadlocks we talked about before. While without a freezer, suspend() can at least rely on the fact that it can wait for processes that have such pending locked constructs waiting will ultimately wakeupm and wait for them (or even explicitely wake them), it can't if they've been frozen. So what was a perfectly solvable moderate driver synchronisation issue becomes a deadlock nightmare.
And those are just example. During this discussion, we also brought the example of FUSE which is a big stab at the whole freezer concept. And I'm sure we can find more everyday.
Face it, we should seriously look into doing suspend/resume without a freezer. I even tend to think that we could do STD that way too, in fact, while Linus is right saying it's a different problem than STR, we could even probably re-use some of the STR infrastructure in some hackish way, still without a freezer. We could have ways to block page cache writeout, for example, to prevent new post-snapshot dirty data from hitting the platter, and use direct BIOs for writeout. That's just an example.
Ben.
Quoted 10 lines
Quoted 4 lines
so the suspend process will wait for it. When binding
is done thesuspend_device()code will take the device lock and tell everything else to postpone further bind requests as above.My question referred to drivers trying to bind or unbind a device _after_ the device has been suspended. I suppose you'll say that's covered by the
NO_BINDflag. But now we have the locking problem mentioned above: The thread trying to bind is holding a lock which is needed for resuming.
Why would it ? Just make it fail, maybe with some kind of -ERETRY... Or it can spin with the lock not held if it want. That's a detail really.
Quoted 7 lines
As one of the people responsible for the USB power management implementation, I would appreciate more details about this. For example, a dmesg log with
CONFIG_USB_DEBUGturned on together with a complete description of the actions you took to provoke the bug.(I wonder how much of this "buginess" is caused by the lack of the freezer in PPC.)
No. The freezer will hide some of those problems under the carpet, but not solve the basic issue which is the driver should be solid. Period.
The freezer is a flawed concept in the first place. If you go back to square one, what is the basic idea of it ? I'll basically expose the idea and go down all of the path I have in mind where it stops working and becomes an incredibly difficult thing that in the end doesn't even solve all the problems it's supposed to.
So first thing first...
I want a quiescent system with no new "IO requests" (whatever that mean in the context of drivers) issued to avoid races during suspend/resume.
That sounds like a nice idea. Yeah. Sounds... only. Problem is. How do you define that quiescent system ? First idea is ... let's stop userland. There are various ways of doing that, but the freezer hooking into the signal code is not necessarily a bad one.
No, I'm purposefully putting aside all the cases where the above doesn't work (user process in the kernel in some uninterruptible wait, etc...), which are the first big setback imho... our simple idea is suddenly not so simple anymore, but we can bring those back later.
Now, there is still a problem... kernel threads. In fact, there is no fundamental distinction between a kernel thread and a user process... one has an MM and the other doesn't but as far as we are concerned, it's the same. Kernel threads can issues IOs, or like khubd, detect devices, plug/unplug them, etc etc.... all over the place.
Easy answer that comes to mind -> freeze them too. Heh, but kernel threads don't do signals, so we end up with all those try_to_freeze(). Then what about the fact that drivers may need those kernel threads to proceed ? Some drivers queue up their IO requests to a kernel thread to process them and suspend() might need to flush those down, issue a couple more such as "spin down disks" before that kernel thread can actually be frozen... Hrm.. maybe not all of them then.
But how do you decide ? What defines that a kernel can issue an IO ? In fact, if you look closely, anything doing kmalloc(...,GFP_KERNEL) for example can trigger an IO... implicitely, via the VM pushing things out. And that's just one example.
In some case, those same threads that may need to be kept non-frozen are -also- the ones that will potentially submit new IOs or bring in new devices.
And then, there is keventd ... what do you do about work queues ? You have everybody pouring things at workqueues... some of these things may well hit your driver, some may not. Same goes in some cases with interrupt time stuff, such as timers or tasklets.. think about networking.
In the end, the nice idea that "threads/tasks cause requests, so we just stop them" basically falls appart. Half of the kernel can cause a driver to be hit somewhere and a given time, it can be from a thread context, directly caused by userland, or from some timer due to some subsystem having a keepalive thing ticking in or whatever else.
Now, we go back to the previous issue of what do we do about uninterruptible sleep... You want to abort suspend because, for example, somethign called a driver that does an msleep(200) or so ? Are you aware that 99% of laptop users close their laptops and shove it in the bag not even waiting for the disk to spin down ? And you want suspend to abort because some random "happen all the time" even such as a process being somewhere temporarily in uninterruptible state in the kernel ?
So let's say we freeze them from within the scheduler even when they are uininterruptible.. ouch... you just caused the deadlocks we talked about before. While without a freezer, suspend() can at least rely on the fact that it can wait for processes that have such pending locked constructs waiting will ultimately wakeupm and wait for them (or even explicitely wake them), it can't if they've been frozen. So what was a perfectly solvable moderate driver synchronisation issue becomes a deadlock nightmare.
And those are just example. During this discussion, we also brought the example of FUSE which is a big stab at the whole freezer concept. And I'm sure we can find more everyday.
Face it, we should seriously look into doing suspend/resume without a freezer. I even tend to think that we could do STD that way too, in fact, while Linus is right saying it's a different problem than STR, we could even probably re-use some of the STR infrastructure in some hackish way, still without a freezer. We could have ways to block page cache writeout, for example, to prevent new post-snapshot dirty data from hitting the platter, and use direct BIOs for writeout. That's just an example.
Ben.
Quoted 4 lines · Benjamin Herrenschmidt
Quoted 4 lines
Quoted 3 lines
so the suspend process will wait for it. When binding
is done thesuspend_device()code will take the device lock and tell everything else to postpone further bind requests as above.
Quoted 8 lines
Quoted 5 lines
My question referred to drivers trying to bind or unbind a device _after_ the device has been suspended. I suppose you'll say that's covered by the
NO_BINDflag. But now we have the locking problem mentioned above: The thread trying to bind is holding a lock which is needed for resuming.Why would it ? Just make it fail, maybe with some kind of
-ERETRY... Or it can spin with the lock not held if it want. That's a detail really.
Spinning in the driver with the lock not held is impossible, since the driver is called with the lock already acquired.
Failing with -ERETRY is non-transparent. I would prefer to block such requests at their source, before the lock is acquired. Perhaps in the driver core, perhaps even earlier.
(And rather than trying to manage a waitqueue or struct completion, it would be easiest to jump directly into the freezer! The driver or the core wouldn't have to worry about waking up all these blocked threads.)
Quoted 10 lines
Quoted 7 lines
As one of the people responsible for the USB power management implementation, I would appreciate more details about this. For example, a dmesg log with
CONFIG_USB_DEBUGturned on together with a complete description of the actions you took to provoke the bug.(I wonder how much of this "buginess" is caused by the lack of the freezer in PPC.)
No. The freezer will hide some of those problems under the carpet, but not solve the basic issue which is the driver should be solid. Period.
You're missing the point. If the driver and the freezer are both solid, there's no reason they can't share the work. If many drivers can pass off part of their workload to the single freezer, it's a net win.
So it isn't a question of how solid the drivers are; it's a question of how solid the freezer is. And bear in mind that if you convince people the freezer is not solid enough to be used, then you will have to find an alternative for purposes of hibernation.
Quoted 1 line
The freezer is a flawed concept in the first place.
<... Long and cogent argument which I will skip over for now ...>
Quoted 2 lines
Face it, we should seriously look into doing suspend/resume without a freezer.
I'm willing to try, although I think it will be a tremendous amount of work to verify that every driver does the right thing. There's lots of support missing. For example, don't you think we should block all sysfs I/O during suspend? And likewise for insmod/rmmod?
Quoted 7 lines
I even tend to think that we could do STD that way too, in fact, while Linus is right saying it's a different problem than STR, we could even probably re-use some of the STR infrastructure in some hackish way, still without a freezer. We could have ways to block page cache writeout, for example, to prevent new post-snapshot dirty data from hitting the platter, and use direct BIOs for writeout. That's just an example.
What about systems with no BIOS? I think this would be very hard or even impossible to make work.
Alan Stern
Quoted 4 lines · Benjamin Herrenschmidt
Quoted 4 lines
Quoted 3 lines
so the suspend process will wait for it. When binding
is done thesuspend_device()code will take the device lock and tell everything else to postpone further bind requests as above.
Quoted 8 lines
Quoted 5 lines
My question referred to drivers trying to bind or unbind a device _after_ the device has been suspended. I suppose you'll say that's covered by the
NO_BINDflag. But now we have the locking problem mentioned above: The thread trying to bind is holding a lock which is needed for resuming.Why would it ? Just make it fail, maybe with some kind of
-ERETRY... Or it can spin with the lock not held if it want. That's a detail really.
Spinning in the driver with the lock not held is impossible, since the driver is called with the lock already acquired.
Failing with -ERETRY is non-transparent. I would prefer to block such requests at their source, before the lock is acquired. Perhaps in the driver core, perhaps even earlier.
(And rather than trying to manage a waitqueue or struct completion, it would be easiest to jump directly into the freezer! The driver or the core wouldn't have to worry about waking up all these blocked threads.)
Quoted 10 lines
Quoted 7 lines
As one of the people responsible for the USB power management implementation, I would appreciate more details about this. For example, a dmesg log with
CONFIG_USB_DEBUGturned on together with a complete description of the actions you took to provoke the bug.(I wonder how much of this "buginess" is caused by the lack of the freezer in PPC.)
No. The freezer will hide some of those problems under the carpet, but not solve the basic issue which is the driver should be solid. Period.
You're missing the point. If the driver and the freezer are both solid, there's no reason they can't share the work. If many drivers can pass off part of their workload to the single freezer, it's a net win.
So it isn't a question of how solid the drivers are; it's a question of how solid the freezer is. And bear in mind that if you convince people the freezer is not solid enough to be used, then you will have to find an alternative for purposes of hibernation.
Quoted 1 line
The freezer is a flawed concept in the first place.
<... Long and cogent argument which I will skip over for now ...>
Quoted 2 lines
Face it, we should seriously look into doing suspend/resume without a freezer.
I'm willing to try, although I think it will be a tremendous amount of work to verify that every driver does the right thing. There's lots of support missing. For example, don't you think we should block all sysfs I/O during suspend? And likewise for insmod/rmmod?
Quoted 7 lines
I even tend to think that we could do STD that way too, in fact, while Linus is right saying it's a different problem than STR, we could even probably re-use some of the STR infrastructure in some hackish way, still without a freezer. We could have ways to block page cache writeout, for example, to prevent new post-snapshot dirty data from hitting the platter, and use direct BIOs for writeout. That's just an example.
What about systems with no BIOS? I think this would be very hard or even impossible to make work.
Alan Stern
Quoted 11 lines
Spinning in the driver with the lock not held is impossible, since the driver is called with the lock already acquired.
Failing with
-ERETRYis non-transparent. I would prefer to block such requests at their source, before the lock is acquired. Perhaps in the driver core, perhaps even earlier.(And rather than trying to manage a waitqueue or struct completion, it would be easiest to jump directly into the freezer! The driver or the core wouldn't have to worry about waking up all these blocked threads.)
That's wrong. The freezer is NOT a solution for that sort of thing. Just because you guys can't get your locking right.
Quoted 4 lines
You're missing the point. If the driver and the freezer are both solid, there's no reason they can't share the work. If many drivers can pass off part of their workload to the single freezer, it's a net win.
I've explained already multiple times that the freezer will not do what you guys expect it to do. IOs can be submited at non-task time and there is no clear distinction between IO generating threads that must and those that must not be frozen.
I really can't understand why you guys work so hard at trying to avoid the right solutions systematically.
Quoted 4 lines
So it isn't a question of how solid the drivers are; it's a question of how solid the freezer is. And bear in mind that if you convince people the freezer is not solid enough to be used, then you will have to find an alternative for purposes of hibernation.
Because I'm intimately convinced that the freezer is a wrong approach that cannot be made solid enough.
Quoted 3 lines
Quoted 1 line
The freezer is a flawed concept in the first place.
<... Long and cogent argument which I will skip over for now ...>
Too bad, that's where the interesting points that show that the freezer cannot work are..
Quoted 7 lines
Quoted 2 lines
Face it, we should seriously look into doing suspend/resume without a freezer.
I'm willing to try, although I think it will be a tremendous amount of work to verify that every driver does the right thing. There's lots of support missing. For example, don't you think we should block all sysfs I/O during suspend? And likewise for insmod/rmmod?
sysfs is a matter of driver. If a sysfs read/write callback in a driver is hitting the HW, it most certainly already has some kind of locking. That locking can/should be extended to deal with blocking when the HW is suspended.
However, since it seems that people universally consider it very hard to get right (I don't but heh), Linus and Paul have come up with a solution for most simple enough directly-mapped drivers such as PCI (ok, that doesn't include USB) which is to simply do the HW suspend in a late callback after IRQs are off, and not bother with the rest.
Quoted 10 lines
Quoted 7 lines
I even tend to think that we could do STD that way too, in fact, while Linus is right saying it's a different problem than STR, we could even probably re-use some of the STR infrastructure in some hackish way, still without a freezer. We could have ways to block page cache writeout, for example, to prevent new post-snapshot dirty data from hitting the platter, and use direct BIOs for writeout. That's just an example.
What about systems with no BIOS? I think this would be very hard or even impossible to make work.
You made the same mistake I did when reading Nigel's mail ... BIOs -> Block IO requests, not BIOS :-)
Ben.
Quoted 11 lines
Spinning in the driver with the lock not held is impossible, since the driver is called with the lock already acquired.
Failing with
-ERETRYis non-transparent. I would prefer to block such requests at their source, before the lock is acquired. Perhaps in the driver core, perhaps even earlier.(And rather than trying to manage a waitqueue or struct completion, it would be easiest to jump directly into the freezer! The driver or the core wouldn't have to worry about waking up all these blocked threads.)
That's wrong. The freezer is NOT a solution for that sort of thing. Just because you guys can't get your locking right.
Quoted 4 lines
You're missing the point. If the driver and the freezer are both solid, there's no reason they can't share the work. If many drivers can pass off part of their workload to the single freezer, it's a net win.
I've explained already multiple times that the freezer will not do what you guys expect it to do. IOs can be submited at non-task time and there is no clear distinction between IO generating threads that must and those that must not be frozen.
I really can't understand why you guys work so hard at trying to avoid the right solutions systematically.
Quoted 4 lines
So it isn't a question of how solid the drivers are; it's a question of how solid the freezer is. And bear in mind that if you convince people the freezer is not solid enough to be used, then you will have to find an alternative for purposes of hibernation.
Because I'm intimately convinced that the freezer is a wrong approach that cannot be made solid enough.
Quoted 3 lines
Quoted 1 line
The freezer is a flawed concept in the first place.
<... Long and cogent argument which I will skip over for now ...>
Too bad, that's where the interesting points that show that the freezer cannot work are..
Quoted 7 lines
Quoted 2 lines
Face it, we should seriously look into doing suspend/resume without a freezer.
I'm willing to try, although I think it will be a tremendous amount of work to verify that every driver does the right thing. There's lots of support missing. For example, don't you think we should block all sysfs I/O during suspend? And likewise for insmod/rmmod?
sysfs is a matter of driver. If a sysfs read/write callback in a driver is hitting the HW, it most certainly already has some kind of locking. That locking can/should be extended to deal with blocking when the HW is suspended.
However, since it seems that people universally consider it very hard to get right (I don't but heh), Linus and Paul have come up with a solution for most simple enough directly-mapped drivers such as PCI (ok, that doesn't include USB) which is to simply do the HW suspend in a late callback after IRQs are off, and not bother with the rest.
Quoted 10 lines
Quoted 7 lines
I even tend to think that we could do STD that way too, in fact, while Linus is right saying it's a different problem than STR, we could even probably re-use some of the STR infrastructure in some hackish way, still without a freezer. We could have ways to block page cache writeout, for example, to prevent new post-snapshot dirty data from hitting the platter, and use direct BIOs for writeout. That's just an example.
What about systems with no BIOS? I think this would be very hard or even impossible to make work.
You made the same mistake I did when reading Nigel's mail ... BIOs -> Block IO requests, not BIOS :-)
Ben.
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 3 lines
(And rather than trying to manage a waitqueue or struct completion, it would be easiest to jump directly into the freezer! The driver or the core wouldn't have to worry about waking up all these blocked threads.)
That's wrong. The freezer is NOT a solution for that sort of thing. Just because you guys can't get your locking right.
You misunderstood. Stop trying to incite riot, calm down, and pay attention to what I actually wrote. I'll explain it again in more explicit terms:
You agree that drivers need to block various activities during suspend. Principally I/O requests, but other things as well. So when one of these requests arrives, the driver has to make it wait somehow and then has to allow it to proceed at the appropriate time.
Normally a waitqueue or a struct completion would be used for this purpose. But either one puts the burden on the driver of defining a data structure and signalling it at the right time. That time is generally when the device is resumed, but there's nothing wrong with delaying it slightly, to after all the devices have been resumed (i.e., the time when the current PM code takes everything out of the freezer). In fact, we definitely don't want to unblock plug events until this later time.
So instead, why not have the PM core take care of all this? There could be a block_task_until_suspend_is_over() routine available for all drivers to use. Its effect would be exactly the same as sending the current task into the freezer, but it wouldn't be the freezer that exists now. It would just be some routine that blocks until the system suspend is over. We could call it "the icebox" instead of "the freezer". :-)
Does that make you happier?
Quoted 8 lines
Quoted 7 lines
Quoted 2 lines
Face it, we should seriously look into doing suspend/resume without a freezer.
I'm willing to try, although I think it will be a tremendous amount of work to verify that every driver does the right thing. There's lots of support missing. For example, don't you think we should block all sysfs I/O during suspend? And likewise for insmod/rmmod?
Quoted 4 lines
sysfs is a matter of driver. If a sysfs read/write callback in a driver is hitting the HW, it most certainly already has some kind of locking. That locking can/should be extended to deal with blocking when the HW is suspended.
User tasks can cause driver binding by writing to sysfs. Binding _can't_ be blocked in the driver; by then it's already too late. If it is going to be blocked at all, it has to be blocked earlier. One possibility is in the sysfs attribute code; another is to block all sysfs access.
Of course, another possibility is simply to fail the bind. But that's not very satisfying, since suspends should be transparent.
Quoted 5 lines
However, since it seems that people universally consider it very hard to get right (I don't but heh), Linus and Paul have come up with a solution for most simple enough directly-mapped drivers such as PCI (ok, that doesn't include USB) which is to simply do the HW suspend in a late callback after IRQs are off, and not bother with the rest.
Ben, you haven't given enough thought to the work needed to avoid locking problems.
For instance, you agree that during suspend we must not allow device or driver registration or unregistration, right? And we must not allow driver binding or unbinding. But these events generally involve acquiring a device semaphore, in the driver core and quite often in the core's caller. Since that semaphore is also needed for calling the suspend and resume methods, we have to be very careful about blocking binding/unbinding/registration/unregistration. It has to be done at a time when no device semaphores are held.
You also agree that kernel threads and workqueues must be allowed to operate during suspend. But consider this: By writing the appropriate sysfs attribute, a user task can cause a workqueue item to be queued to keventd that tries to unregister a device. That really puts you on the
spot: Unregistration can't be allowed to fail, it can't be allowed to succeed during a suspend, and keventd can't be blocked! So what should we do?
Alan Stern
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 3 lines
(And rather than trying to manage a waitqueue or struct completion, it would be easiest to jump directly into the freezer! The driver or the core wouldn't have to worry about waking up all these blocked threads.)
That's wrong. The freezer is NOT a solution for that sort of thing. Just because you guys can't get your locking right.
You misunderstood. Stop trying to incite riot, calm down, and pay attention to what I actually wrote. I'll explain it again in more explicit terms:
You agree that drivers need to block various activities during suspend. Principally I/O requests, but other things as well. So when one of these requests arrives, the driver has to make it wait somehow and then has to allow it to proceed at the appropriate time.
Normally a waitqueue or a struct completion would be used for this purpose. But either one puts the burden on the driver of defining a data structure and signalling it at the right time. That time is generally when the device is resumed, but there's nothing wrong with delaying it slightly, to after all the devices have been resumed (i.e., the time when the current PM code takes everything out of the freezer). In fact, we definitely don't want to unblock plug events until this later time.
So instead, why not have the PM core take care of all this? There could be a block_task_until_suspend_is_over() routine available for all drivers to use. Its effect would be exactly the same as sending the current task into the freezer, but it wouldn't be the freezer that exists now. It would just be some routine that blocks until the system suspend is over. We could call it "the icebox" instead of "the freezer". :-)
Does that make you happier?
Quoted 8 lines
Quoted 7 lines
Quoted 2 lines
Face it, we should seriously look into doing suspend/resume without a freezer.
I'm willing to try, although I think it will be a tremendous amount of work to verify that every driver does the right thing. There's lots of support missing. For example, don't you think we should block all sysfs I/O during suspend? And likewise for insmod/rmmod?
Quoted 4 lines
sysfs is a matter of driver. If a sysfs read/write callback in a driver is hitting the HW, it most certainly already has some kind of locking. That locking can/should be extended to deal with blocking when the HW is suspended.
User tasks can cause driver binding by writing to sysfs. Binding _can't_ be blocked in the driver; by then it's already too late. If it is going to be blocked at all, it has to be blocked earlier. One possibility is in the sysfs attribute code; another is to block all sysfs access.
Of course, another possibility is simply to fail the bind. But that's not very satisfying, since suspends should be transparent.
Quoted 5 lines
However, since it seems that people universally consider it very hard to get right (I don't but heh), Linus and Paul have come up with a solution for most simple enough directly-mapped drivers such as PCI (ok, that doesn't include USB) which is to simply do the HW suspend in a late callback after IRQs are off, and not bother with the rest.
Ben, you haven't given enough thought to the work needed to avoid locking problems.
For instance, you agree that during suspend we must not allow device or driver registration or unregistration, right? And we must not allow driver binding or unbinding. But these events generally involve acquiring a device semaphore, in the driver core and quite often in the core's caller. Since that semaphore is also needed for calling the suspend and resume methods, we have to be very careful about blocking binding/unbinding/registration/unregistration. It has to be done at a time when no device semaphores are held.
You also agree that kernel threads and workqueues must be allowed to operate during suspend. But consider this: By writing the appropriate sysfs attribute, a user task can cause a workqueue item to be queued to keventd that tries to unregister a device. That really puts you on the
spot: Unregistration can't be allowed to fail, it can't be allowed to succeed during a suspend, and keventd can't be blocked! So what should we do?
Alan Stern
Quoted 5 lines
You agree that drivers need to block various activities during suspend. Principally I/O requests, but other things as well. So when one of these requests arrives, the driver has to make it wait somehow and then has to allow it to proceed at the appropriate time.
Yes. The main thing I see here is that here is nothing common among drivers in what a "request" is and how it's processed.
For example, for block drivers, it's actually fairly simple to just stop processing the request queue and wait for pending ones to complete.
For network, in a similar vein, we can mostly just tell the network stack to stop sending us packets.
That's what I call the "main path". This is often the trivial part to deal with, mostly because for a whole lot of drivers, it can be done via a couple of helpers in the subsystem that the driver provides a service too, via a helper, asking that subsystem to stop calling into the said driver (the asking should be done by the driver itself of course, for ordering reasons).
We have some helpers, but I think not enough, and that's where we should focus imho. For example, I added fb_set_suspend() so that fbdev's can request fbcon to stop accessing them (it doesn't solve the problem of userland mmap's, that will have to be done, if we want to do it, in a more sneaky way, using VM tricks, but the DRM nowadays has the infrastructure to do it).
But that's only the "main" path. Aside for that, almost all drivers also have sideband "request" input and some driver don't actually live behind a subsystem. That ranges from ioctl, to direct read/write on a char dev from userland.
I think many of those cases can fairly well deal with just taking a PM semaphore, that's how I did for a couple of things in the past, provided that the request path isn't deadlocking with the semaphore held because of the system suspending of course.
But in a whole lot of cases, it's, I beleive, perfectly kosher to just return an error. You're trying to capture frame from your camera while the machine is suspended ? error. At worst, your capture app will be unhappy when you wakeup, nothing terrible and totally fixable in userland if it's a problem.
In some cases, we could use a little bit more help from the subsystem. Network for example, could have some explicit knowledge of the suspend state, and in addition to stopping the queue would also stop calling into things like change_mtu or set_multicast, provided it's agreed that the driver will account for those changes on resume (the actual MTU values or multicast lists are still updated in the netdev).
Quoted 2 lines
Normally a waitqueue or a struct completion would be used for this purpose.
I think there's no "normal" scenario, each driver or family of drivers will do things very differently.
Quoted 2 lines
But either one puts the burden on the driver of defining a data structure and signalling it at the right time.
Yes.
Quoted 3 lines
That time is generally when the device is resumed, but there's nothing wrong with delaying it slightly, to after all the devices have been resumed (i.e., the time when the current PM code takes everything out of the freezer).
In fact, the best is to have parallel suspend/resume of drivers and asynchronous resume but that's out of topic :-) (For the record, I did some bits like ADB resume like that, that is asynchronous, to speed up wakeup time).
Quoted 3 lines
In fact, we definitely don't want to unblock plug events until this later time.
There are two things I believe. There's a generic issue with usermode helpers that make no sense to call between pre-suspend and post-resume, and there's the specific issue of adding/removing devices.
I believe that "bus" drivers such as USB should indeed get a first round of notifications to tell them to stop performing bus plug/unplug operations (it's debatable whether we want to keep unplug going provided we can stack up the usermode events and re-send them later though, but let's say no for the sake of simplicity).
Quoted 7 lines
So instead, why not have the PM core take care of all this? There could be a
block_task_until_suspend_is_over()routine available for all drivers to use. Its effect would be exactly the same as sending the current task into the freezer, but it wouldn't be the freezer that exists now. It would just be some routine that blocks until the system suspend is over. We could call it "the icebox" instead of "the freezer". :-)
I'm not totally sure about that. I like some of it, but I think it's fairly different conceptually from the freezer (and the implementation could be as trivial as a single system wide wait queue).
Basically it has a very big difference to the current freezer, and I like that, which is that we don't have some 3rd party trying to find out what to freeze and what not (the freezer), but instead, we have explicitely drivers or kernel threads sending -themselves- to the "icebox" when they think it's a good idea. Think of it as lazy freezing -> you only freeze lazy tasks that are trying to do something that cannot be done because of suspend.
Quoted 1 line
Does that make you happier?
I think it's a fairly significant change from the current freezer and I also think it's a very good idea. The more I think about it, the more I like it, in the sense that it's a simple drop-in that you could put in a lot of the ioctl path of drivers to just block tasks that are trying to call in while suspending, and could be used selectively by things like the USB hub threads.
Quoted 8 lines
User tasks can cause driver binding by writing to sysfs. Binding _can't_ be blocked in the driver; by then it's already too late. If it is going to be blocked at all, it has to be blocked earlier. One possibility is in the sysfs attribute code; another is to block all sysfs access.
Of course, another possibility is simply to fail the bind. But that's not very satisfying, since suspends should be transparent.
I don't think suspend has to be -that- transparent (though there is some debate on whether it should be if we're gonna do some kind of fast "light" suspend for things like OLPC) but overall, I agree that a bind operation on sysfs should probably block until resume, and it does make sense to have the logic to do that in sysfs itself. It could perfectly use the above icebox thingy you came up with.
Quoted 5 lines
Ben, you haven't given enough thought to the work needed to avoid locking problems.
For instance, you agree that during suspend we must not allow device or driver registration or unregistration, right?
Registration is fine, binding/ubinding is not (no problem putting the driver on/off a list, though of course, you can't unregister a bound driver without unbinding, it's prefectly find to unregister an unbound driver).
Quoted 1 line
And we must not allow driver binding or unbinding.
That's where the meat is.
Quoted 6 lines
But these events generally involve acquiring a device semaphore, in the driver core and quite often in the core's caller. Since that semaphore is also needed for calling the suspend and resume methods, we have to be very careful about blocking binding/unbinding/registration/unregistration.
It has to be done at a time when no device semaphores are held.
I think that should indeed be handled within the driver core. Though I tend to think our driver core is a bit of a locking mess at the moment :-) (Who says it could use more RCU-like constructs ?).
Regarding unbinding, that's debatable, it might be perfectly allright to unbind while suspended, though then, there is the question of a driver being later on bound to a piece of HW that is suspended (though I suppose that could happen today... some machines have their firmware leave some devices off at boot).
As a general matter, If we have those pre-suspend/post-resume notifiers and we adapt the few (there isn't that much) bus drivers so that they stop all probe/unprobe operations before the suspend dance starts, we avoid a lot of that problem. At this point, it becomes fair enough for bind/unbind, in the core, to return an error (and maybe even stack trace in dmesg to catch the culprits) while suspend in in progress.
The only remaining annoying case is manual bind/unbind via sysfs which is a good candidate for the above described icebox.
Quoted 2 lines
You also agree that kernel threads and workqueues must be allowed to operate during suspend.
Yes, unless kernel threads explicitely decide to stop themselves (for example, khubd is a good candidate for that). Again, not a 3rd party trying to decide what to freeze and what not, but the drivers or kernel threads themselves deciding it.
Quoted 6 lines
But consider this: By writing the appropriate
sysfs attribute, a user task can cause a workqueue item to be queued to keventd that tries to unregister a device. That really puts you on the
spot: Unregistration can't be allowed to fail, it can't be allowed to succeed during a suspend, and keventd can't be blocked! So what should we do?
We can either stop it at the sysfs write level, or we can have the workqueue task reschedule itself later until we are resumed. In fact, worqueue items being what they are (queue items), we could imagine having a special list where they enqueue themselves to rescheduled after resume.
Don't get me wrong, I never said we don't need generic infrastructure and utilities, such as your proposed icebox scheme, or some of those workqueue bits, helpers in subsystems, etc...
I just think that the freezer approach, as it is, is backward. We can't have a 3rd party try to discriminate what to freeze and what not, it will always get something wrong, and in some cases with the wrong timing or ordering.
Cheers,
Ben.
Quoted 5 lines
You agree that drivers need to block various activities during suspend. Principally I/O requests, but other things as well. So when one of these requests arrives, the driver has to make it wait somehow and then has to allow it to proceed at the appropriate time.
Yes. The main thing I see here is that here is nothing common among drivers in what a "request" is and how it's processed.
For example, for block drivers, it's actually fairly simple to just stop processing the request queue and wait for pending ones to complete.
For network, in a similar vein, we can mostly just tell the network stack to stop sending us packets.
That's what I call the "main path". This is often the trivial part to deal with, mostly because for a whole lot of drivers, it can be done via a couple of helpers in the subsystem that the driver provides a service too, via a helper, asking that subsystem to stop calling into the said driver (the asking should be done by the driver itself of course, for ordering reasons).
We have some helpers, but I think not enough, and that's where we should focus imho. For example, I added fb_set_suspend() so that fbdev's can request fbcon to stop accessing them (it doesn't solve the problem of userland mmap's, that will have to be done, if we want to do it, in a more sneaky way, using VM tricks, but the DRM nowadays has the infrastructure to do it).
But that's only the "main" path. Aside for that, almost all drivers also have sideband "request" input and some driver don't actually live behind a subsystem. That ranges from ioctl, to direct read/write on a char dev from userland.
I think many of those cases can fairly well deal with just taking a PM semaphore, that's how I did for a couple of things in the past, provided that the request path isn't deadlocking with the semaphore held because of the system suspending of course.
But in a whole lot of cases, it's, I beleive, perfectly kosher to just return an error. You're trying to capture frame from your camera while the machine is suspended ? error. At worst, your capture app will be unhappy when you wakeup, nothing terrible and totally fixable in userland if it's a problem.
In some cases, we could use a little bit more help from the subsystem. Network for example, could have some explicit knowledge of the suspend state, and in addition to stopping the queue would also stop calling into things like change_mtu or set_multicast, provided it's agreed that the driver will account for those changes on resume (the actual MTU values or multicast lists are still updated in the netdev).
Quoted 2 lines
Normally a waitqueue or a struct completion would be used for this purpose.
I think there's no "normal" scenario, each driver or family of drivers will do things very differently.
Quoted 2 lines
But either one puts the burden on the driver of defining a data structure and signalling it at the right time.
Yes.
Quoted 3 lines
That time is generally when the device is resumed, but there's nothing wrong with delaying it slightly, to after all the devices have been resumed (i.e., the time when the current PM code takes everything out of the freezer).
In fact, the best is to have parallel suspend/resume of drivers and asynchronous resume but that's out of topic :-) (For the record, I did some bits like ADB resume like that, that is asynchronous, to speed up wakeup time).
Quoted 3 lines
In fact, we definitely don't want to unblock plug events until this later time.
There are two things I believe. There's a generic issue with usermode helpers that make no sense to call between pre-suspend and post-resume, and there's the specific issue of adding/removing devices.
I believe that "bus" drivers such as USB should indeed get a first round of notifications to tell them to stop performing bus plug/unplug operations (it's debatable whether we want to keep unplug going provided we can stack up the usermode events and re-send them later though, but let's say no for the sake of simplicity).
Quoted 7 lines
So instead, why not have the PM core take care of all this? There could be a
block_task_until_suspend_is_over()routine available for all drivers to use. Its effect would be exactly the same as sending the current task into the freezer, but it wouldn't be the freezer that exists now. It would just be some routine that blocks until the system suspend is over. We could call it "the icebox" instead of "the freezer". :-)
I'm not totally sure about that. I like some of it, but I think it's fairly different conceptually from the freezer (and the implementation could be as trivial as a single system wide wait queue).
Basically it has a very big difference to the current freezer, and I like that, which is that we don't have some 3rd party trying to find out what to freeze and what not (the freezer), but instead, we have explicitely drivers or kernel threads sending -themselves- to the "icebox" when they think it's a good idea. Think of it as lazy freezing -> you only freeze lazy tasks that are trying to do something that cannot be done because of suspend.
Quoted 1 line
Does that make you happier?
I think it's a fairly significant change from the current freezer and I also think it's a very good idea. The more I think about it, the more I like it, in the sense that it's a simple drop-in that you could put in a lot of the ioctl path of drivers to just block tasks that are trying to call in while suspending, and could be used selectively by things like the USB hub threads.
Quoted 8 lines
User tasks can cause driver binding by writing to sysfs. Binding _can't_ be blocked in the driver; by then it's already too late. If it is going to be blocked at all, it has to be blocked earlier. One possibility is in the sysfs attribute code; another is to block all sysfs access.
Of course, another possibility is simply to fail the bind. But that's not very satisfying, since suspends should be transparent.
I don't think suspend has to be -that- transparent (though there is some debate on whether it should be if we're gonna do some kind of fast "light" suspend for things like OLPC) but overall, I agree that a bind operation on sysfs should probably block until resume, and it does make sense to have the logic to do that in sysfs itself. It could perfectly use the above icebox thingy you came up with.
Quoted 5 lines
Ben, you haven't given enough thought to the work needed to avoid locking problems.
For instance, you agree that during suspend we must not allow device or driver registration or unregistration, right?
Registration is fine, binding/ubinding is not (no problem putting the driver on/off a list, though of course, you can't unregister a bound driver without unbinding, it's prefectly find to unregister an unbound driver).
Quoted 1 line
And we must not allow driver binding or unbinding.
That's where the meat is.
Quoted 6 lines
But these events generally involve acquiring a device semaphore, in the driver core and quite often in the core's caller. Since that semaphore is also needed for calling the suspend and resume methods, we have to be very careful about blocking binding/unbinding/registration/unregistration.
It has to be done at a time when no device semaphores are held.
I think that should indeed be handled within the driver core. Though I tend to think our driver core is a bit of a locking mess at the moment :-) (Who says it could use more RCU-like constructs ?).
Regarding unbinding, that's debatable, it might be perfectly allright to unbind while suspended, though then, there is the question of a driver being later on bound to a piece of HW that is suspended (though I suppose that could happen today... some machines have their firmware leave some devices off at boot).
As a general matter, If we have those pre-suspend/post-resume notifiers and we adapt the few (there isn't that much) bus drivers so that they stop all probe/unprobe operations before the suspend dance starts, we avoid a lot of that problem. At this point, it becomes fair enough for bind/unbind, in the core, to return an error (and maybe even stack trace in dmesg to catch the culprits) while suspend in in progress.
The only remaining annoying case is manual bind/unbind via sysfs which is a good candidate for the above described icebox.
Quoted 2 lines
You also agree that kernel threads and workqueues must be allowed to operate during suspend.
Yes, unless kernel threads explicitely decide to stop themselves (for example, khubd is a good candidate for that). Again, not a 3rd party trying to decide what to freeze and what not, but the drivers or kernel threads themselves deciding it.
Quoted 6 lines
But consider this: By writing the appropriate
sysfs attribute, a user task can cause a workqueue item to be queued to keventd that tries to unregister a device. That really puts you on the
spot: Unregistration can't be allowed to fail, it can't be allowed to succeed during a suspend, and keventd can't be blocked! So what should we do?
We can either stop it at the sysfs write level, or we can have the workqueue task reschedule itself later until we are resumed. In fact, worqueue items being what they are (queue items), we could imagine having a special list where they enqueue themselves to rescheduled after resume.
Don't get me wrong, I never said we don't need generic infrastructure and utilities, such as your proposed icebox scheme, or some of those workqueue bits, helpers in subsystems, etc...
I just think that the freezer approach, as it is, is backward. We can't have a 3rd party try to discriminate what to freeze and what not, it will always get something wrong, and in some cases with the wrong timing or ordering.
Cheers,
Ben.
Quoted 7 lines
I think it's a fairly significant change from the current freezer and I also think it's a very good idea. The more I think about it, the more I like it, in the sense that it's a simple drop-in that you could put in a lot of the ioctl path of drivers to just block tasks that are trying to call in while suspending, and could be used selectively by things like the USB hub threads.
Note that we could have also a per-device "icebox" (just a waitqueue). Might be nice for a device to resume whatever it froze just after it resumed itself, might even be necessary in case whatever thread got frozen is necessary for handling child devices.
Cheers,
Ben.
Quoted 7 lines
I think it's a fairly significant change from the current freezer and I also think it's a very good idea. The more I think about it, the more I like it, in the sense that it's a simple drop-in that you could put in a lot of the ioctl path of drivers to just block tasks that are trying to call in while suspending, and could be used selectively by things like the USB hub threads.
Note that we could have also a per-device "icebox" (just a waitqueue). Might be nice for a device to resume whatever it froze just after it resumed itself, might even be necessary in case whatever thread got frozen is necessary for handling child devices.
Cheers,
Ben.
Quoted 4 lines · Benjamin Herrenschmidt
Note that we could have also a per-device "icebox" (just a waitqueue). Might be nice for a device to resume whatever it froze just after it resumed itself, might even be necessary in case whatever thread got frozen is necessary for handling child devices.
This wouldn't need any special infrastructure. Just a regular waitqueue defined in the device's private data structure.
Alan Stern
Quoted 4 lines · Benjamin Herrenschmidt
Note that we could have also a per-device "icebox" (just a waitqueue). Might be nice for a device to resume whatever it froze just after it resumed itself, might even be necessary in case whatever thread got frozen is necessary for handling child devices.
This wouldn't need any special infrastructure. Just a regular waitqueue defined in the device's private data structure.
Alan Stern
On Sunday, 8 July 2007 07:14, Benjamin Herrenschmidt wrote:
[--snip--]
Quoted 5 lines
I just think that the freezer approach, as it is, is backward. We can't have a 3rd party try to discriminate what to freeze and what not, it will always get something wrong, and in some cases with the wrong timing or ordering.
Nice discussion, except for one thing: the freezer doesn't decide what to freeze. For example, even right now kernel threads decide if they want to be frozen.
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Quoted 11 lines · Rafael J. Wysocki
On Sunday, 8 July 2007 07:14, Benjamin Herrenschmidt wrote:
[--snip--]Quoted 5 lines
I just think that the freezer approach, as it is, is backward. We can't have a 3rd party try to discriminate what to freeze and what not, it will always get something wrong, and in some cases with the wrong timing or ordering.
Nice discussion, except for one thing: the freezer doesn't decide what to freeze. For example, even right now kernel threads decide if they want to be frozen.
Somewhat... userspace doesn't and workqueues are a gray area.
Also, I've been thinking this "icebox" idea a bit more and it seems in fact a bit racy in some areas, at least for use by things like drivers, unless we end up doing something aking to an RCU on suspend, waiting for all tasks to reach userland once, but that has the same annoyances as the current freezer.
Thus I'm tempted to go back to saying that driver can handle things locally :-)
Ben.
Hi!
Quoted 10 lines
Quoted 8 lines
Quoted 4 lines
I just think that the freezer approach, as it is, is backward. We can't have a 3rd party try to discriminate what to freeze and what not, it will always get something wrong, and in some cases with the wrong timing or ordering.
Nice discussion, except for one thing: the freezer doesn't decide what to freeze. For example, even right now kernel threads decide if they want to be frozen.
Somewhat... userspace doesn't and workqueues are a gray area.
But userspace must not be neccessary for kernel functioning, so that's quite okay. And we do need to solve the workqueues.
Quoted 8 lines
Also, I've been thinking this "icebox" idea a bit more and it seems in fact a bit racy in some areas, at least for use by things like drivers, unless we end up doing something aking to an RCU on suspend, waiting for all tasks to reach userland once, but that has the same annoyances as the current freezer.
Thus I'm tempted to go back to saying that driver can handle things locally :-)
:-). Or perhaps freezer is not _that_ evil after all?
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 8 lines · Rafael J. Wysocki
On Sunday, 8 July 2007 07:14, Benjamin Herrenschmidt wrote:
[--snip--]Quoted 5 lines
I just think that the freezer approach, as it is, is backward. We can't have a 3rd party try to discriminate what to freeze and what not, it will always get something wrong, and in some cases with the wrong timing or ordering.
Quoted 5 lines
Quoted 3 lines
Nice discussion, except for one thing: the freezer doesn't decide what to freeze. For example, even right now kernel threads decide if they want to be frozen.
Somewhat... userspace doesn't and workqueues are a gray area.
Workqueues are kernel threads and the creator decides if they are going to freeze. There are only two freezable worqueues in the entire tree right now.
Quoted 8 lines
Also, I've been thinking this "icebox" idea a bit more and it seems in fact a bit racy in some areas, at least for use by things like drivers, unless we end up doing something aking to an RCU on suspend, waiting for all tasks to reach userland once, but that has the same annoyances as the current freezer.
Thus I'm tempted to go back to saying that driver can handle things locally :-)
Actaully, I'm perfectly fine with that, as long as each task blocked by the driver due to suspend has PF_FROZEN (or something similar) set. Then, at least theoretically, we'll be able to drop the freezer from the suspend code path and move it after device_suspend() (or the hibernation-specific equivalent) for hibernation (in that case there shouldn't be a problem with any task waiting on I/O while the freezer is running ;-)).
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Quoted 3 lines · Rafael J. Wysocki
Workqueues are kernel threads and the creator decides if they are going to freeze. There are only two freezable worqueues in the entire tree right now.
That and keventd workqueues... my point is you may well end up with something in a workqueue doing things that should have been blocked after the freeze.
Quoted 6 lines
Actaully, I'm perfectly fine with that, as long as each task blocked by the driver due to suspend has
PF_FROZEN(or something similar) set. Then, at least theoretically, we'll be able to drop the freezer from the suspend code path and move it afterdevice_suspend()(or the hibernation-specific equivalent) for hibernation (in that case there shouldn't be a problem with any task waiting on I/O while the freezer is running ;-)).
I don't see the need for a freezer for snapshot but that's a different issue. (stop_machine looks good enough to me).
Ben
Quoted 3 lines · Rafael J. Wysocki
Workqueues are kernel threads and the creator decides if they are going to freeze. There are only two freezable worqueues in the entire tree right now.
That and keventd workqueues... my point is you may well end up with something in a workqueue doing things that should have been blocked after the freeze.
Quoted 6 lines
Actaully, I'm perfectly fine with that, as long as each task blocked by the driver due to suspend has
PF_FROZEN(or something similar) set. Then, at least theoretically, we'll be able to drop the freezer from the suspend code path and move it afterdevice_suspend()(or the hibernation-specific equivalent) for hibernation (in that case there shouldn't be a problem with any task waiting on I/O while the freezer is running ;-)).
I don't see the need for a freezer for snapshot but that's a different issue. (stop_machine looks good enough to me).
Ben
hibernation/snapshot design [was Re: [PATCH] Remove process freezer from suspend to RAM pathway]
Hi!
Quoted 9 lines
Quoted 6 lines
Actaully, I'm perfectly fine with that, as long as each task blocked by the driver due to suspend has
PF_FROZEN(or something similar) set. Then, at least theoretically, we'll be able to drop the freezer from the suspend code path and move it afterdevice_suspend()(or the hibernation-specific equivalent) for hibernation (in that case there shouldn't be a problem with any task waiting on I/O while the freezer is running ;-)).I don't see the need for a freezer for snapshot but that's a different issue. (
stop_machinelooks good enough to me).
Freezer is not needed for snapshot -- it is needed so that we can write out the snapshot to disk without the need for special drivers/block/simple-ide-for-suspend.c. (We are doing snapshot, then write to disk from userland code in uswsusp).
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
hibernation/snapshot design [was Re: [PATCH] Remove process freezer from suspend to RAM pathway]
In reply to Benjamin HerrenschmidtHi!
Quoted 9 lines
Quoted 6 lines
Actaully, I'm perfectly fine with that, as long as each task blocked by the driver due to suspend has
PF_FROZEN(or something similar) set. Then, at least theoretically, we'll be able to drop the freezer from the suspend code path and move it afterdevice_suspend()(or the hibernation-specific equivalent) for hibernation (in that case there shouldn't be a problem with any task waiting on I/O while the freezer is running ;-)).I don't see the need for a freezer for snapshot but that's a different issue. (
stop_machinelooks good enough to me).
Freezer is not needed for snapshot -- it is needed so that we can write out the snapshot to disk without the need for special drivers/block/simple-ide-for-suspend.c. (We are doing snapshot, then write to disk from userland code in uswsusp).
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: hibernation/snapshot design [was Re: [PATCH] Remove process freezer from suspend to RAM pathway]
Quoted 7 lines · Pavel Machek
Quoted 7 lines
Quoted 6 lines
Actaully, I'm perfectly fine with that, as long as each task blocked by the driver due to suspend has
PF_FROZEN(or something similar) set. Then, at least theoretically, we'll be able to drop the freezer from the suspend code path and move it afterdevice_suspend()(or the hibernation-specific equivalent) for hibernation (in that case there shouldn't be a problem with any task waiting on I/O while the freezer is running ;-)).
Quoted 7 lines
Quoted 2 lines
I don't see the need for a freezer for snapshot but that's a different issue. (
stop_machinelooks good enough to me).Freezer is not needed for snapshot -- it is needed so that we can write out the snapshot to disk without the need for special
drivers/block/simple-ide-for-suspend.c. (We are doing snapshot, then write to disk from userland code in uswsusp).
instead of trying to freeze most of the system, could you do something like start a virtual machine sandbox to write the data out, and not let any userspace other then the sandbox operate?
you would need to throw away disk buffers so that you don't mix current pending I/O with I/O from the sandbox, and this would be a visable change for how suspend is setup, but wouldn't this work?
David Lang
Re: hibernation/snapshot design [was Re: [PATCH] Remove process freezer from suspend to RAM pathway]
Hi!
Quoted 18 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Actaully, I'm perfectly fine with that, as long as each task blocked by the
driver due to suspend hasPF_FROZEN(or something similar) set. Then, at least theoretically, we'll be able to drop the freezer from the suspend code
path and move it afterdevice_suspend()(or the hibernation-specific equivalent) for hibernation (in that case there shouldn't be a problem with
any task waiting on I/O while the freezer is running ;-)).Quoted 7 lines
Quoted 2 lines
I don't see the need for a freezer for snapshot but that's a different issue. (
stop_machinelooks good enough to me).Freezer is not needed for snapshot -- it is needed so that we can write out the snapshot to disk without the need for special
drivers/block/simple-ide-for-suspend.c. (We are doing snapshot, then write to disk from userland code in uswsusp).
Quoted 7 lines
instead of trying to freeze most of the system, could you do something like start a virtual machine sandbox to write the data out, and not let any userspace other then the sandbox operate?
you would need to throw away disk buffers so that you don't mix current pending I/O with I/O from the sandbox, and this would be a visable change for how suspend is setup, but wouldn't this work?
It feels kind of expensive, but yes, we could use another kernel for doing the dump. Kdump people are using that. We could use hypervisor for doing the dump. Xen people are doing that. (But I do not think any of those solutions is suitable for "lets hibernate my notebook" case).
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: hibernation/snapshot design [was Re: [PATCH] Remove process freezer from suspend to RAM pathway]
In reply to [email protected]Hi!
Quoted 18 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Actaully, I'm perfectly fine with that, as long as each task blocked by the
driver due to suspend hasPF_FROZEN(or something similar) set. Then, at least theoretically, we'll be able to drop the freezer from the suspend code
path and move it afterdevice_suspend()(or the hibernation-specific equivalent) for hibernation (in that case there shouldn't be a problem with
any task waiting on I/O while the freezer is running ;-)).Quoted 7 lines
Quoted 2 lines
I don't see the need for a freezer for snapshot but that's a different issue. (
stop_machinelooks good enough to me).Freezer is not needed for snapshot -- it is needed so that we can write out the snapshot to disk without the need for special
drivers/block/simple-ide-for-suspend.c. (We are doing snapshot, then write to disk from userland code in uswsusp).
Quoted 7 lines
instead of trying to freeze most of the system, could you do something like start a virtual machine sandbox to write the data out, and not let any userspace other then the sandbox operate?
you would need to throw away disk buffers so that you don't mix current pending I/O with I/O from the sandbox, and this would be a visable change for how suspend is setup, but wouldn't this work?
It feels kind of expensive, but yes, we could use another kernel for doing the dump. Kdump people are using that. We could use hypervisor for doing the dump. Xen people are doing that. (But I do not think any of those solutions is suitable for "lets hibernate my notebook" case).
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: hibernation/snapshot design [was Re: [PATCH] Remove process freezer from suspend to RAM pathway]
Quoted 22 lines · Pavel Machek
Quoted 22 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Actaully, I'm perfectly fine with that, as long as each task blocked by the
driver due to suspend hasPF_FROZEN(or something similar) set. Then, at least theoretically, we'll be able to drop the freezer from the suspend code
path and move it afterdevice_suspend()(or the hibernation-specific equivalent) for hibernation (in that case there shouldn't be a problem with
any task waiting on I/O while the freezer is running ;-)).Quoted 7 lines
Quoted 2 lines
I don't see the need for a freezer for snapshot but that's a different issue. (
stop_machinelooks good enough to me).Freezer is not needed for snapshot -- it is needed so that we can write out the snapshot to disk without the need for special
drivers/block/simple-ide-for-suspend.c. (We are doing snapshot, then write to disk from userland code in uswsusp).instead of trying to freeze most of the system, could you do something like start a virtual machine sandbox to write the data out, and not let any userspace other then the sandbox operate?
Quoted 8 lines
Quoted 3 lines
you would need to throw away disk buffers so that you don't mix current pending I/O with I/O from the sandbox, and this would be a visable change for how suspend is setup, but wouldn't this work?
It feels kind of expensive, but yes, we could use another kernel for doing the dump. Kdump people are using that. We could use hypervisor for doing the dump. Xen people are doing that. (But I do not think any of those solutions is suitable for "lets hibernate my notebook" case).
expensive and reliable beats efficiant and unrelaible.
why do you say that neither would work for the "lets hibernate my notebook" case?
David Lang
Re: hibernation/snapshot design [was Re: [PATCH] Remove process freezer from suspend to RAM pathway]
In reply to Pavel MachekQuoted 22 lines · Pavel Machek
Quoted 22 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Actaully, I'm perfectly fine with that, as long as each task blocked by the
driver due to suspend hasPF_FROZEN(or something similar) set. Then, at least theoretically, we'll be able to drop the freezer from the suspend code
path and move it afterdevice_suspend()(or the hibernation-specific equivalent) for hibernation (in that case there shouldn't be a problem with
any task waiting on I/O while the freezer is running ;-)).Quoted 7 lines
Quoted 2 lines
I don't see the need for a freezer for snapshot but that's a different issue. (
stop_machinelooks good enough to me).Freezer is not needed for snapshot -- it is needed so that we can write out the snapshot to disk without the need for special
drivers/block/simple-ide-for-suspend.c. (We are doing snapshot, then write to disk from userland code in uswsusp).instead of trying to freeze most of the system, could you do something like start a virtual machine sandbox to write the data out, and not let any userspace other then the sandbox operate?
Quoted 8 lines
Quoted 3 lines
you would need to throw away disk buffers so that you don't mix current pending I/O with I/O from the sandbox, and this would be a visable change for how suspend is setup, but wouldn't this work?
It feels kind of expensive, but yes, we could use another kernel for doing the dump. Kdump people are using that. We could use hypervisor for doing the dump. Xen people are doing that. (But I do not think any of those solutions is suitable for "lets hibernate my notebook" case).
expensive and reliable beats efficiant and unrelaible.
why do you say that neither would work for the "lets hibernate my notebook" case?
David Lang
Re: hibernation/snapshot design [was Re: [PATCH] Remove process freezer from suspend to RAM pathway]
Quoted 34 lines · On Sun 2007-07-08 16:20:46, [email protected] wrote:
Quoted 23 lines · Pavel Machek
Quoted 23 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Actaully, I'm perfectly fine with that, as long as each task blocked by the
driver due to suspend hasPF_FROZEN(or something similar) set. Then, at
least theoretically, we'll be able to drop the freezer from the suspend code
path and move it afterdevice_suspend()(or the hibernation-specific equivalent) for hibernation (in that case there shouldn't be a problem with
any task waiting on I/O while the freezer is running ;-)).Quoted 7 lines
Quoted 2 lines
I don't see the need for a freezer for snapshot but that's a different issue. (
stop_machinelooks good enough to me).Freezer is not needed for snapshot -- it is needed so that we can write out the snapshot to disk without the need for special
drivers/block/simple-ide-for-suspend.c. (We are doing snapshot, then write to disk from userland code in uswsusp).instead of trying to freeze most of the system, could you do something like start a virtual machine sandbox to write the data out, and not let any userspace other then the sandbox operate?
Quoted 8 lines
Quoted 3 lines
you would need to throw away disk buffers so that you don't mix current pending I/O with I/O from the sandbox, and this would be a visable change for how suspend is setup, but wouldn't this work?
It feels kind of expensive, but yes, we could use another kernel for doing the dump. Kdump people are using that. We could use hypervisor for doing the dump. Xen people are doing that. (But I do not think any of those solutions is suitable for "lets hibernate my notebook" case).
Quoted 4 lines
expensive and reliable beats efficiant and unrelaible.
why do you say that neither would work for the "lets hibernate my notebook" case?
Both would work. One would eat 8-64MB of your RAM, permanently; second would eat 5-15% of your cpu, permanently. Not very suitable.
Who says current solution is unreliable?
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: hibernation/snapshot design [was Re: [PATCH] Remove process freezer from suspend to RAM pathway]
In reply to [email protected]Quoted 34 lines · On Sun 2007-07-08 16:20:46, [email protected] wrote:
Quoted 23 lines · Pavel Machek
Quoted 23 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Actaully, I'm perfectly fine with that, as long as each task blocked by the
driver due to suspend hasPF_FROZEN(or something similar) set. Then, at
least theoretically, we'll be able to drop the freezer from the suspend code
path and move it afterdevice_suspend()(or the hibernation-specific equivalent) for hibernation (in that case there shouldn't be a problem with
any task waiting on I/O while the freezer is running ;-)).Quoted 7 lines
Quoted 2 lines
I don't see the need for a freezer for snapshot but that's a different issue. (
stop_machinelooks good enough to me).Freezer is not needed for snapshot -- it is needed so that we can write out the snapshot to disk without the need for special
drivers/block/simple-ide-for-suspend.c. (We are doing snapshot, then write to disk from userland code in uswsusp).instead of trying to freeze most of the system, could you do something like start a virtual machine sandbox to write the data out, and not let any userspace other then the sandbox operate?
Quoted 8 lines
Quoted 3 lines
you would need to throw away disk buffers so that you don't mix current pending I/O with I/O from the sandbox, and this would be a visable change for how suspend is setup, but wouldn't this work?
It feels kind of expensive, but yes, we could use another kernel for doing the dump. Kdump people are using that. We could use hypervisor for doing the dump. Xen people are doing that. (But I do not think any of those solutions is suitable for "lets hibernate my notebook" case).
Quoted 4 lines
expensive and reliable beats efficiant and unrelaible.
why do you say that neither would work for the "lets hibernate my notebook" case?
Both would work. One would eat 8-64MB of your RAM, permanently; second would eat 5-15% of your cpu, permanently. Not very suitable.
Who says current solution is unreliable?
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: hibernation/snapshot design [was Re: [PATCH] Remove process freezer from suspend to RAM pathway]
Quoted 35 lines · Pavel Machek
Quoted 34 lines · On Sun 2007-07-08 16:20:46, [email protected] wrote:
Quoted 31 lines · Pavel Machek
Quoted 19 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Actaully, I'm perfectly fine with that, as long as each task blocked by the
driver due to suspend hasPF_FROZEN(or something similar) set. Then, at
least theoretically, we'll be able to drop the freezer from the suspend code
path and move it afterdevice_suspend()(or the hibernation-specific equivalent) for hibernation (in that case there shouldn't be a problem with
any task waiting on I/O while the freezer is running ;-)).Quoted 7 lines
Quoted 2 lines
I don't see the need for a freezer for snapshot but that's a different issue. (
stop_machinelooks good enough to me).Freezer is not needed for snapshot -- it is needed so that we can write out the snapshot to disk without the need for special
drivers/block/simple-ide-for-suspend.c. (We are doing snapshot, then write to disk from userland code in uswsusp).Quoted 7 lines
instead of trying to freeze most of the system, could you do something like start a virtual machine sandbox to write the data out, and not let any userspace other then the sandbox operate?
you would need to throw away disk buffers so that you don't mix current pending I/O with I/O from the sandbox, and this would be a visable change for how suspend is setup, but wouldn't this work?
It feels kind of expensive, but yes, we could use another kernel for doing the dump. Kdump people are using that. We could use hypervisor for doing the dump. Xen people are doing that. (But I do not think any of those solutions is suitable for "lets hibernate my notebook" case).
Quoted 7 lines
Quoted 4 lines
expensive and reliable beats efficiant and unrelaible.
why do you say that neither would work for the "lets hibernate my notebook" case?
Both would work. One would eat 8-64MB of your RAM, permanently; second would eat 5-15% of your cpu, permanently. Not very suitable.
how much overlap is there between the two approaches? are they close enough to be able to give the user the choice of which to use depending on their machine (new machines with the hardware virtualization support may want the hypervisor, other hardware may want to sacrafice 8M of ram)
Quoted 1 line
Who says current solution is unreliable?
users report problems, suspend* developers repeatedly state that the problems are that the rest of the kernel needs to be fixed to work properly with the existing approach.
I think it's safe to say that it doesn't work in the general case, even though it does work in some specific cases.
David Lang
Re: hibernation/snapshot design
In reply to Pavel MachekPavel Machek <[email protected]> writes:
[snip]
Quoted 4 lines
Quoted 2 lines
why do you say that neither would work for the "lets hibernate my notebook" case?
Both would work. One would eat 8-64MB of your RAM, permanently;
As I have stated in other messages, the kdump approach would not waste any RAM permanently. The reason that kdump must reserve memory at boot is that on panic, it cannot attempt to nicely stop drivers, and consequently there might be ongoing DMAs that could clobber anything but the reserved area; this reason does not apply to hibernate, though. I'll quote a previous message in which I stated a solution that can be used:
Immediately before jumping to the new kernel, the first X bytes (where X is the amount of memory the new kernel will get, typically 16MB or 64MB) of physical memory are backed up into the arbitrary discontiguous pages that are made available. This will not take very long, because copying even 64MB of memory is extremely fast. Then the new kernel is free to use the first X bytes of contiguous physical memory. Problem solved.
Signature · 1 line
Jeremy Maitin-Shepard
Re: hibernation/snapshot design
In reply to Pavel MachekPavel Machek <[email protected]> writes:
[snip]
Quoted 4 lines
Quoted 2 lines
why do you say that neither would work for the "lets hibernate my notebook" case?
Both would work. One would eat 8-64MB of your RAM, permanently;
As I have stated in other messages, the kdump approach would not waste any RAM permanently. The reason that kdump must reserve memory at boot is that on panic, it cannot attempt to nicely stop drivers, and consequently there might be ongoing DMAs that could clobber anything but the reserved area; this reason does not apply to hibernate, though. I'll quote a previous message in which I stated a solution that can be used:
Immediately before jumping to the new kernel, the first X bytes (where X is the amount of memory the new kernel will get, typically 16MB or 64MB) of physical memory are backed up into the arbitrary discontiguous pages that are made available. This will not take very long, because copying even 64MB of memory is extremely fast. Then the new kernel is free to use the first X bytes of contiguous physical memory. Problem solved.
Signature · 1 line
Jeremy Maitin-Shepard
Re: hibernation/snapshot design [was Re: [PATCH] Remove process freezer from suspend to RAM pathway]
In reply to Pavel MachekHi,
Quoted 9 lines · Pavel Machek
Hi!
Quoted 7 lines
Quoted 6 lines
Actaully, I'm perfectly fine with that, as long as each task blocked by the driver due to suspend has
PF_FROZEN(or something similar) set. Then, at least theoretically, we'll be able to drop the freezer from the suspend code path and move it afterdevice_suspend()(or the hibernation-specific equivalent) for hibernation (in that case there shouldn't be a problem with any task waiting on I/O while the freezer is running ;-)).
Quoted 7 lines
Quoted 2 lines
I don't see the need for a freezer for snapshot but that's a different issue. (
stop_machinelooks good enough to me).Freezer is not needed for snapshot -- it is needed so that we can write out the snapshot to disk without the need for special
drivers/block/simple-ide-for-suspend.c. (We are doing snapshot, then write to disk from userland code in uswsusp).
Yes.
BTW, this patch:
that's queued up in -mm contains a freezer documentation update, in which the reasons of using it, as well as its limitations, are described.
To summarize what was previously said in this thread:
* Apparently, we agree that the freezer is _generally_ not needed for suspend (ie. any transition to a system sleep state other than hibernation), but some of us (eg. me) think that it wouldn't be reasonable to drop the freezer from the suspend code path _right_ _now_ .
* Some of us, including you, Nigel and me, think that the freezer is needed for hibernation (please see the document in the patch above for details). In the (very) long run this might be avoided too, but (IMO) certainly not at this point.
* We seem to agree that in order to remove the freezer from the suspend code path some work needs to be done on device drivers, driver midlayers and the PM core. We also need to do some work on the PM core in order to introduce a separate hibernation framework and IMO it would be reasonable to synchronize these efforts.
* We are now to decide what to do so that the freezer can be safely removed from the suspend code path and how to integrate that change with the hibernation code path (if possible and reasonable).
* The freezer vs FUSE issue that started this thread remains unresolved, so it would be desirable to provide a short-term fix (need not be very nice).
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Re: hibernation/snapshot design [was Re: [PATCH] Remove process freezer from suspend to RAM pathway]
Hi!
Quoted 32 lines
Quoted 4 lines
Freezer is not needed for snapshot -- it is needed so that we can write out the snapshot to disk without the need for special
drivers/block/simple-ide-for-suspend.c. (We are doing snapshot, then write to disk from userland code in uswsusp).Yes.
BTW, this patch:
that's queued up in -mm contains a freezer documentation update, in which the reasons of using it, as well as its limitations, are described.
To summarize what was previously said in this thread:
* Apparently, we agree that the freezer is _generally_ not needed for suspend (ie. any transition to a system sleep state other than hibernation), but some of us (eg. me) think that it wouldn't be reasonable to drop the freezer from the suspend code path _right_ _now_ .
* Some of us, including you, Nigel and me, think that the freezer is needed for hibernation (please see the document in the patch above for details). In the (very) long run this might be avoided too, but (IMO) certainly not at this point.
* We seem to agree that in order to remove the freezer from the suspend code path some work needs to be done on device drivers, driver midlayers and the PM core. We also need to do some work on the PM core in order to introduce a separate hibernation framework and IMO it would be reasonable to synchronize these efforts.
Quoted 3 lines
* We are now to decide what to do so that the freezer can be safely removed from the suspend code path and how to integrate that change with the hibernation code path (if possible and reasonable).
Nice summary, thanks.
Quoted 2 lines
* The freezer vs FUSE issue that started this thread remains unresolved, so it would be desirable to provide a short-term fix (need not be very nice).
Actually there are _2_ freezer vs FUSE issues, and one of them should be simple to solve, once we have sysrq-t of the deadlock. (Or did I miss it somewhere with discussion going on 10 lists in parallel?)
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: hibernation/snapshot design [was Re: [PATCH] Remove process freezer from suspend to RAM pathway]
In reply to Rafael J. WysockiHi!
Quoted 32 lines
Quoted 4 lines
Freezer is not needed for snapshot -- it is needed so that we can write out the snapshot to disk without the need for special
drivers/block/simple-ide-for-suspend.c. (We are doing snapshot, then write to disk from userland code in uswsusp).Yes.
BTW, this patch:
that's queued up in -mm contains a freezer documentation update, in which the reasons of using it, as well as its limitations, are described.
To summarize what was previously said in this thread:
* Apparently, we agree that the freezer is _generally_ not needed for suspend (ie. any transition to a system sleep state other than hibernation), but some of us (eg. me) think that it wouldn't be reasonable to drop the freezer from the suspend code path _right_ _now_ .
* Some of us, including you, Nigel and me, think that the freezer is needed for hibernation (please see the document in the patch above for details). In the (very) long run this might be avoided too, but (IMO) certainly not at this point.
* We seem to agree that in order to remove the freezer from the suspend code path some work needs to be done on device drivers, driver midlayers and the PM core. We also need to do some work on the PM core in order to introduce a separate hibernation framework and IMO it would be reasonable to synchronize these efforts.
Quoted 3 lines
* We are now to decide what to do so that the freezer can be safely removed from the suspend code path and how to integrate that change with the hibernation code path (if possible and reasonable).
Nice summary, thanks.
Quoted 2 lines
* The freezer vs FUSE issue that started this thread remains unresolved, so it would be desirable to provide a short-term fix (need not be very nice).
Actually there are _2_ freezer vs FUSE issues, and one of them should be simple to solve, once we have sysrq-t of the deadlock. (Or did I miss it somewhere with discussion going on 10 lists in parallel?)
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: hibernation/snapshot design [was Re: [PATCH] Remove process freezer from suspend to RAM pathway]
In reply to Rafael J. WysockiHi.
Quoted 6 lines · On Monday 09 July 2007 09:01:27 Rafael J. Wysocki wrote:
Hi,
Quoted 3 lines · Pavel Machek
Hi!
Quoted 1 line
Quoted 1 line
Actaully, I'm perfectly fine with that, as long as each task blocked
by the
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
driver due to suspend has
PF_FROZEN(or something similar) set. Then,
at
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
least theoretically, we'll be able to drop the freezer from the
suspend code
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
path and move it after
device_suspend()(or the hibernation-specific equivalent) for hibernation (in that case there shouldn't be a problem
with
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 1 line
any task waiting on I/O while the freezer is running ;-)).
I don't see the need for a freezer for snapshot but that's a different issue. (
stop_machinelooks good enough to me).
Quoted 10 lines
Quoted 4 lines
Freezer is not needed for snapshot -- it is needed so that we can write out the snapshot to disk without the need for special
drivers/block/simple-ide-for-suspend.c. (We are doing snapshot, then write to disk from userland code in uswsusp).Yes.
BTW, this patch:
Quoted 2 lines
that's queued up in -mm contains a freezer documentation update, in which
the
Quoted 5 lines
reasons of using it, as well as its limitations, are described.
To summarize what was previously said in this thread:
* Apparently, we agree that the freezer is _generally_ not needed for
suspend
Quoted 1 line
(ie. any transition to a system sleep state other than hibernation), but
some
Quoted 1 line
of us (eg. me) think that it wouldn't be reasonable to drop the freezer
from
Quoted 5 lines
the suspend code path _right_ _now_ .
* Some of us, including you, Nigel and me, think that the freezer is needed for hibernation (please see the document in the patch above for details). In the (very) long run this might be avoided too, but (IMO) certainly not
at
Quoted 4 lines
this point.
* We seem to agree that in order to remove the freezer from the suspend code path some work needs to be done on device drivers, driver midlayers and
the
Quoted 1 line
PM core. We also need to do some work on the PM core in order to
introduce
Quoted 9 lines
a separate hibernation framework and IMO it would be reasonable to synchronize these efforts.
* We are now to decide what to do so that the freezer can be safely removed from the suspend code path and how to integrate that change with the hibernation code path (if possible and reasonable).
* The freezer vs FUSE issue that started this thread remains unresolved, so it would be desirable to provide a short-term fix (need not be very nice).
(Finally catching up on emails since Saturday!)
The freezer is also essential for doing a full image of memory - you have to be able to guarantee that some of the image won't change in order to be able to write it out before the atomic copy. Of course the freezer alone isn't enough, but it solves 95% of the issue.
Regards,
Nigel
Signature · 2 lines
See http://www.tuxonice.net for Howtos, FAQs, mailing lists, wiki and bugzilla info.
Re: Re: hibernation/snapshot design [was Re: [PATCH] Remove process freezer from suspend to RAM pathway]
Quoted 1 line · Nigel Cunningham
(Finally catching up on emails since Saturday!)
Yes, I know what you mean; I was occupied with other work stuff on Friday and not well on Saturday, and by that stage there was a backlog of about 500 emails for me to wade through... :/
Quoted 4 lines
The freezer is also essential for doing a full image of memory - you have to be able to guarantee that some of the image won't change in order to be able to write it out before the atomic copy. Of course the freezer alone isn't enough, but it solves 95% of the issue.
Sure. As I pointed out in another email, it's unrealistic to expect the freezer to be able to stop everything in a state where any arbitrary mutex is free. But as long as you don't need to do anything that depends on getting a mutex while the system is frozen, there should be no problem.
Paul.
Re: [linux-pm] Re: hibernation/snapshot design [was Re: [PATCH] Remove process freezer from suspend to RAM pathway]
In reply to Nigel CunninghamQuoted 1 line · Nigel Cunningham
(Finally catching up on emails since Saturday!)
Yes, I know what you mean; I was occupied with other work stuff on Friday and not well on Saturday, and by that stage there was a backlog of about 500 emails for me to wade through... :/
Quoted 4 lines
The freezer is also essential for doing a full image of memory - you have to be able to guarantee that some of the image won't change in order to be able to write it out before the atomic copy. Of course the freezer alone isn't enough, but it solves 95% of the issue.
Sure. As I pointed out in another email, it's unrealistic to expect the freezer to be able to stop everything in a state where any arbitrary mutex is free. But as long as you don't need to do anything that depends on getting a mutex while the system is frozen, there should be no problem.
Paul.
Re: hibernation/snapshot design [was Re: [PATCH] Remove process freezer from suspend to RAM pathway]
In reply to Rafael J. WysockiHi.
Quoted 6 lines · On Monday 09 July 2007 09:01:27 Rafael J. Wysocki wrote:
Hi,
Quoted 3 lines · Pavel Machek
Hi!
Quoted 1 line
Quoted 1 line
Actaully, I'm perfectly fine with that, as long as each task blocked
by the
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
driver due to suspend has
PF_FROZEN(or something similar) set. Then,
at
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
least theoretically, we'll be able to drop the freezer from the
suspend code
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
path and move it after
device_suspend()(or the hibernation-specific equivalent) for hibernation (in that case there shouldn't be a problem
with
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 1 line
any task waiting on I/O while the freezer is running ;-)).
I don't see the need for a freezer for snapshot but that's a different issue. (
stop_machinelooks good enough to me).
Quoted 10 lines
Quoted 4 lines
Freezer is not needed for snapshot -- it is needed so that we can write out the snapshot to disk without the need for special
drivers/block/simple-ide-for-suspend.c. (We are doing snapshot, then write to disk from userland code in uswsusp).Yes.
BTW, this patch:
Quoted 2 lines
that's queued up in -mm contains a freezer documentation update, in which
the
Quoted 5 lines
reasons of using it, as well as its limitations, are described.
To summarize what was previously said in this thread:
* Apparently, we agree that the freezer is _generally_ not needed for
suspend
Quoted 1 line
(ie. any transition to a system sleep state other than hibernation), but
some
Quoted 1 line
of us (eg. me) think that it wouldn't be reasonable to drop the freezer
from
Quoted 5 lines
the suspend code path _right_ _now_ .
* Some of us, including you, Nigel and me, think that the freezer is needed for hibernation (please see the document in the patch above for details). In the (very) long run this might be avoided too, but (IMO) certainly not
at
Quoted 4 lines
this point.
* We seem to agree that in order to remove the freezer from the suspend code path some work needs to be done on device drivers, driver midlayers and
the
Quoted 1 line
PM core. We also need to do some work on the PM core in order to
introduce
Quoted 9 lines
a separate hibernation framework and IMO it would be reasonable to synchronize these efforts.
* We are now to decide what to do so that the freezer can be safely removed from the suspend code path and how to integrate that change with the hibernation code path (if possible and reasonable).
* The freezer vs FUSE issue that started this thread remains unresolved, so it would be desirable to provide a short-term fix (need not be very nice).
(Finally catching up on emails since Saturday!)
The freezer is also essential for doing a full image of memory - you have to be able to guarantee that some of the image won't change in order to be able to write it out before the atomic copy. Of course the freezer alone isn't enough, but it solves 95% of the issue.
Regards,
Nigel
Signature · 2 lines
See http://www.tuxonice.net for Howtos, FAQs, mailing lists, wiki and bugzilla info.
Re: hibernation/snapshot design [was Re: [PATCH] Remove process freezer from suspend to RAM pathway]
In reply to Pavel MachekHi,
Quoted 9 lines · Pavel Machek
Hi!
Quoted 7 lines
Quoted 6 lines
Actaully, I'm perfectly fine with that, as long as each task blocked by the driver due to suspend has
PF_FROZEN(or something similar) set. Then, at least theoretically, we'll be able to drop the freezer from the suspend code path and move it afterdevice_suspend()(or the hibernation-specific equivalent) for hibernation (in that case there shouldn't be a problem with any task waiting on I/O while the freezer is running ;-)).
Quoted 7 lines
Quoted 2 lines
I don't see the need for a freezer for snapshot but that's a different issue. (
stop_machinelooks good enough to me).Freezer is not needed for snapshot -- it is needed so that we can write out the snapshot to disk without the need for special
drivers/block/simple-ide-for-suspend.c. (We are doing snapshot, then write to disk from userland code in uswsusp).
Yes.
BTW, this patch:
that's queued up in -mm contains a freezer documentation update, in which the reasons of using it, as well as its limitations, are described.
To summarize what was previously said in this thread:
* Apparently, we agree that the freezer is _generally_ not needed for suspend (ie. any transition to a system sleep state other than hibernation), but some of us (eg. me) think that it wouldn't be reasonable to drop the freezer from the suspend code path _right_ _now_ .
* Some of us, including you, Nigel and me, think that the freezer is needed for hibernation (please see the document in the patch above for details). In the (very) long run this might be avoided too, but (IMO) certainly not at this point.
* We seem to agree that in order to remove the freezer from the suspend code path some work needs to be done on device drivers, driver midlayers and the PM core. We also need to do some work on the PM core in order to introduce a separate hibernation framework and IMO it would be reasonable to synchronize these efforts.
* We are now to decide what to do so that the freezer can be safely removed from the suspend code path and how to integrate that change with the hibernation code path (if possible and reasonable).
* The freezer vs FUSE issue that started this thread remains unresolved, so it would be desirable to provide a short-term fix (need not be very nice).
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 8 lines · Rafael J. Wysocki
On Sunday, 8 July 2007 07:14, Benjamin Herrenschmidt wrote:
[--snip--]Quoted 5 lines
I just think that the freezer approach, as it is, is backward. We can't have a 3rd party try to discriminate what to freeze and what not, it will always get something wrong, and in some cases with the wrong timing or ordering.
Quoted 5 lines
Quoted 3 lines
Nice discussion, except for one thing: the freezer doesn't decide what to freeze. For example, even right now kernel threads decide if they want to be frozen.
Somewhat... userspace doesn't and workqueues are a gray area.
Workqueues are kernel threads and the creator decides if they are going to freeze. There are only two freezable worqueues in the entire tree right now.
Quoted 8 lines
Also, I've been thinking this "icebox" idea a bit more and it seems in fact a bit racy in some areas, at least for use by things like drivers, unless we end up doing something aking to an RCU on suspend, waiting for all tasks to reach userland once, but that has the same annoyances as the current freezer.
Thus I'm tempted to go back to saying that driver can handle things locally :-)
Actaully, I'm perfectly fine with that, as long as each task blocked by the driver due to suspend has PF_FROZEN (or something similar) set. Then, at least theoretically, we'll be able to drop the freezer from the suspend code path and move it after device_suspend() (or the hibernation-specific equivalent) for hibernation (in that case there shouldn't be a problem with any task waiting on I/O while the freezer is running ;-)).
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
On Sunday, 8 July 2007 07:14, Benjamin Herrenschmidt wrote:
[--snip--]
Quoted 5 lines
I just think that the freezer approach, as it is, is backward. We can't have a 3rd party try to discriminate what to freeze and what not, it will always get something wrong, and in some cases with the wrong timing or ordering.
Nice discussion, except for one thing: the freezer doesn't decide what to freeze. For example, even right now kernel threads decide if they want to be frozen.
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
I'll make this reply short by agreeing up front with most of what you say.
Quoted 4 lines · Benjamin Herrenschmidt
But that's only the "main" path. Aside for that, almost all drivers also have sideband "request" input and some driver don't actually live behind a subsystem. That ranges from ioctl, to direct read/write on a char dev from userland.
Yes, these are the problem cases.
Quoted 4 lines
I think many of those cases can fairly well deal with just taking a PM semaphore, that's how I did for a couple of things in the past, provided that the request path isn't deadlocking with the semaphore held because of the system suspending of course.
That's what USB does as well (for the drivers which have runtime PM support -- at the moment only a few of them).
Quoted 5 lines
But in a whole lot of cases, it's, I beleive, perfectly kosher to just return an error. You're trying to capture frame from your camera while the machine is suspended ? error. At worst, your capture app will be unhappy when you wakeup, nothing terrible and totally fixable in userland if it's a problem.
We can try falling back on this approach for now. If the drivers are smart enough to fail cleanly when the device is already suspended, it should work.
But I'm not sure it's a good idea in the long run. Think of a printer daemon, for example. It shouldn't have to experience unexpected I/O problems merely because someone has decided to put the system to sleep.
Quoted 6 lines
In some cases, we could use a little bit more help from the subsystem. Network for example, could have some explicit knowledge of the suspend state, and in addition to stopping the queue would also stop calling into things like
change_mtuorset_multicast, provided it's agreed that the driver will account for those changes on resume (the actual MTU values or multicast lists are still updated in the netdev).
This will be up to the people responsible for the subsystems. I can take care of USB.
Quoted 10 lines
There are two things I believe. There's a generic issue with usermode helpers that make no sense to call between pre-suspend and post-resume, and there's the specific issue of adding/removing devices.
I believe that "bus" drivers such as USB should indeed get a first round of notifications to tell them to stop performing bus plug/unplug operations (it's debatable whether we want to keep unplug going provided we can stack up the usermode events and re-send them later though, but let's say no for the sake of simplicity).
Yes. Rafael, how close is your new notifier chain to mainline? Can it at least be added to Greg KH's development tree so that I can start using it?
Quoted 11 lines
Quoted 7 lines
So instead, why not have the PM core take care of all this? There could be a
block_task_until_suspend_is_over()routine available for all drivers to use. Its effect would be exactly the same as sending the current task into the freezer, but it wouldn't be the freezer that exists now. It would just be some routine that blocks until the system suspend is over. We could call it "the icebox" instead of "the freezer". :-)I'm not totally sure about that. I like some of it, but I think it's fairly different conceptually from the freezer (and the implementation could be as trivial as a single system wide wait queue).
Exactly.
Quoted 8 lines
Basically it has a very big difference to the current freezer, and I like that, which is that we don't have some 3rd party trying to find out what to freeze and what not (the freezer), but instead, we have explicitely drivers or kernel threads sending -themselves- to the "icebox" when they think it's a good idea. Think of it as lazy freezing -> you only freeze lazy tasks that are trying to do something that cannot be done because of suspend.
Quoted 8 lines
Quoted 1 line
Does that make you happier?
I think it's a fairly significant change from the current freezer and I also think it's a very good idea. The more I think about it, the more I like it, in the sense that it's a simple drop-in that you could put in a lot of the ioctl path of drivers to just block tasks that are trying to call in while suspending, and could be used selectively by things like the USB hub threads.
That's what I had in mind. Rafael, can we add an "icebox" routine? Like Ben says, it doesn't need to be much more than a waitqueue that the current task puts itself on if a suspend is in progress. Callers arriving at a time when the icebox isn't activated should simply return without blocking. Basically the icebox should be active at the same times as the existing freezer.
Quoted 9 lines
Quoted 2 lines
Of course, another possibility is simply to fail the bind. But that's not very satisfying, since suspends should be transparent.
I don't think suspend has to be -that- transparent (though there is some debate on whether it should be if we're gonna do some kind of fast "light" suspend for things like OLPC) but overall, I agree that a bind operation on sysfs should probably block until resume, and it does make sense to have the logic to do that in sysfs itself. It could perfectly use the above icebox thingy you came up with.
Here's a wacky idea which just might work:
In order to prevent binding and unbinding, while suspending devices all the PM core has to do is avoid dropping the device semaphores! It can release the semaphores as it resumes the devices.
Of course, for this to work it's necessary to avoid changes to the device list during the suspend. However I believe the iteration can be made safe against unregistration, so we only have to prevent device registration. (And anyway, it won't be possible to unregister a device while the PM core is holding its semaphore.)
If we are willing to be somewhat non-transparent, this is easy to accomplish. After the notifier chain has been alerted about the upcoming suspend, we tell the driver core to disallow adding new devices. Maybe use SRCU to synchronize with registration calls that are in progress. Thus, until the suspend is over device_add() will immediately return an error. We could even add a new ESUSPENDING code to errno.h; it would come in handy in a few places.
Drivers are already prepared for device registration to fail (or they ought to be), so this change shouldn't knock the bottom out of things. device_add() isn't on a hot path, so adding an extra check and srcu_read_lock() won't hurt.
Quoted 5 lines
Regarding unbinding, that's debatable, it might be perfectly allright to unbind while suspended, though then, there is the question of a driver being later on bound to a piece of HW that is suspended (though I suppose that could happen today... some machines have their firmware leave some devices off at boot).
I have had the same thought, that unbinding and unregistration would be easier to handle than binding and registration. As it happens, holding the device semaphore will block both all three -- which makes life simpler.
Quoted 6 lines
As a general matter, If we have those pre-suspend/post-resume notifiers and we adapt the few (there isn't that much) bus drivers so that they stop all probe/unprobe operations before the suspend dance starts, we avoid a lot of that problem. At this point, it becomes fair enough for bind/unbind, in the core, to return an error (and maybe even stack trace in dmesg to catch the culprits) while suspend in in progress.
Putting a WARN_ON() in device_add() would be a good idea.
Quoted 7 lines
Quoted 6 lines
But consider this: By writing the appropriate
sysfs attribute, a user task can cause a workqueue item to be queued to keventd that tries to unregister a device. That really puts you on the
spot: Unregistration can't be allowed to fail, it can't be allowed to succeed during a suspend, and keventd can't be blocked! So what should we do?
Quoted 5 lines
We can either stop it at the sysfs write level, or we can have the workqueue task reschedule itself later until we are resumed. In fact, worqueue items being what they are (queue items), we could imagine having a special list where they enqueue themselves to rescheduled after resume.
There are other possibilities too. For example, instead of using keventd these attributes could use a separate workqueue which would put itself in the icebox during a suspend. Or maybe sysfs can be reworked so that they don't need to use a workqueue at all.
Quoted 3 lines
Don't get me wrong, I never said we don't need generic infrastructure and utilities, such as your proposed icebox scheme, or some of those workqueue bits, helpers in subsystems, etc...
I hope that everyone will agree that now is a good time to get started on them. There shouldn't be any problem about having them present along with the freezer, and then it will be all that much easier to remove the freezer later on if that's what we decide to do.
Alan Stern
I'll make this reply short by agreeing up front with most of what you say.
Quoted 4 lines · Benjamin Herrenschmidt
But that's only the "main" path. Aside for that, almost all drivers also have sideband "request" input and some driver don't actually live behind a subsystem. That ranges from ioctl, to direct read/write on a char dev from userland.
Yes, these are the problem cases.
Quoted 4 lines
I think many of those cases can fairly well deal with just taking a PM semaphore, that's how I did for a couple of things in the past, provided that the request path isn't deadlocking with the semaphore held because of the system suspending of course.
That's what USB does as well (for the drivers which have runtime PM support -- at the moment only a few of them).
Quoted 5 lines
But in a whole lot of cases, it's, I beleive, perfectly kosher to just return an error. You're trying to capture frame from your camera while the machine is suspended ? error. At worst, your capture app will be unhappy when you wakeup, nothing terrible and totally fixable in userland if it's a problem.
We can try falling back on this approach for now. If the drivers are smart enough to fail cleanly when the device is already suspended, it should work.
But I'm not sure it's a good idea in the long run. Think of a printer daemon, for example. It shouldn't have to experience unexpected I/O problems merely because someone has decided to put the system to sleep.
Quoted 6 lines
In some cases, we could use a little bit more help from the subsystem. Network for example, could have some explicit knowledge of the suspend state, and in addition to stopping the queue would also stop calling into things like
change_mtuorset_multicast, provided it's agreed that the driver will account for those changes on resume (the actual MTU values or multicast lists are still updated in the netdev).
This will be up to the people responsible for the subsystems. I can take care of USB.
Quoted 10 lines
There are two things I believe. There's a generic issue with usermode helpers that make no sense to call between pre-suspend and post-resume, and there's the specific issue of adding/removing devices.
I believe that "bus" drivers such as USB should indeed get a first round of notifications to tell them to stop performing bus plug/unplug operations (it's debatable whether we want to keep unplug going provided we can stack up the usermode events and re-send them later though, but let's say no for the sake of simplicity).
Yes. Rafael, how close is your new notifier chain to mainline? Can it at least be added to Greg KH's development tree so that I can start using it?
Quoted 11 lines
Quoted 7 lines
So instead, why not have the PM core take care of all this? There could be a
block_task_until_suspend_is_over()routine available for all drivers to use. Its effect would be exactly the same as sending the current task into the freezer, but it wouldn't be the freezer that exists now. It would just be some routine that blocks until the system suspend is over. We could call it "the icebox" instead of "the freezer". :-)I'm not totally sure about that. I like some of it, but I think it's fairly different conceptually from the freezer (and the implementation could be as trivial as a single system wide wait queue).
Exactly.
Quoted 8 lines
Basically it has a very big difference to the current freezer, and I like that, which is that we don't have some 3rd party trying to find out what to freeze and what not (the freezer), but instead, we have explicitely drivers or kernel threads sending -themselves- to the "icebox" when they think it's a good idea. Think of it as lazy freezing -> you only freeze lazy tasks that are trying to do something that cannot be done because of suspend.
Quoted 8 lines
Quoted 1 line
Does that make you happier?
I think it's a fairly significant change from the current freezer and I also think it's a very good idea. The more I think about it, the more I like it, in the sense that it's a simple drop-in that you could put in a lot of the ioctl path of drivers to just block tasks that are trying to call in while suspending, and could be used selectively by things like the USB hub threads.
That's what I had in mind. Rafael, can we add an "icebox" routine? Like Ben says, it doesn't need to be much more than a waitqueue that the current task puts itself on if a suspend is in progress. Callers arriving at a time when the icebox isn't activated should simply return without blocking. Basically the icebox should be active at the same times as the existing freezer.
Quoted 9 lines
Quoted 2 lines
Of course, another possibility is simply to fail the bind. But that's not very satisfying, since suspends should be transparent.
I don't think suspend has to be -that- transparent (though there is some debate on whether it should be if we're gonna do some kind of fast "light" suspend for things like OLPC) but overall, I agree that a bind operation on sysfs should probably block until resume, and it does make sense to have the logic to do that in sysfs itself. It could perfectly use the above icebox thingy you came up with.
Here's a wacky idea which just might work:
In order to prevent binding and unbinding, while suspending devices all the PM core has to do is avoid dropping the device semaphores! It can release the semaphores as it resumes the devices.
Of course, for this to work it's necessary to avoid changes to the device list during the suspend. However I believe the iteration can be made safe against unregistration, so we only have to prevent device registration. (And anyway, it won't be possible to unregister a device while the PM core is holding its semaphore.)
If we are willing to be somewhat non-transparent, this is easy to accomplish. After the notifier chain has been alerted about the upcoming suspend, we tell the driver core to disallow adding new devices. Maybe use SRCU to synchronize with registration calls that are in progress. Thus, until the suspend is over device_add() will immediately return an error. We could even add a new ESUSPENDING code to errno.h; it would come in handy in a few places.
Drivers are already prepared for device registration to fail (or they ought to be), so this change shouldn't knock the bottom out of things. device_add() isn't on a hot path, so adding an extra check and srcu_read_lock() won't hurt.
Quoted 5 lines
Regarding unbinding, that's debatable, it might be perfectly allright to unbind while suspended, though then, there is the question of a driver being later on bound to a piece of HW that is suspended (though I suppose that could happen today... some machines have their firmware leave some devices off at boot).
I have had the same thought, that unbinding and unregistration would be easier to handle than binding and registration. As it happens, holding the device semaphore will block both all three -- which makes life simpler.
Quoted 6 lines
As a general matter, If we have those pre-suspend/post-resume notifiers and we adapt the few (there isn't that much) bus drivers so that they stop all probe/unprobe operations before the suspend dance starts, we avoid a lot of that problem. At this point, it becomes fair enough for bind/unbind, in the core, to return an error (and maybe even stack trace in dmesg to catch the culprits) while suspend in in progress.
Putting a WARN_ON() in device_add() would be a good idea.
Quoted 7 lines
Quoted 6 lines
But consider this: By writing the appropriate
sysfs attribute, a user task can cause a workqueue item to be queued to keventd that tries to unregister a device. That really puts you on the
spot: Unregistration can't be allowed to fail, it can't be allowed to succeed during a suspend, and keventd can't be blocked! So what should we do?
Quoted 5 lines
We can either stop it at the sysfs write level, or we can have the workqueue task reschedule itself later until we are resumed. In fact, worqueue items being what they are (queue items), we could imagine having a special list where they enqueue themselves to rescheduled after resume.
There are other possibilities too. For example, instead of using keventd these attributes could use a separate workqueue which would put itself in the icebox during a suspend. Or maybe sysfs can be reworked so that they don't need to use a workqueue at all.
Quoted 3 lines
Don't get me wrong, I never said we don't need generic infrastructure and utilities, such as your proposed icebox scheme, or some of those workqueue bits, helpers in subsystems, etc...
I hope that everyone will agree that now is a good time to get started on them. There shouldn't be any problem about having them present along with the freezer, and then it will be all that much easier to remove the freezer later on if that's what we decide to do.
Alan Stern
Hi!
Quoted 11 lines
Quoted 10 lines
There are two things I believe. There's a generic issue with usermode helpers that make no sense to call between pre-suspend and post-resume, and there's the specific issue of adding/removing devices.
I believe that "bus" drivers such as USB should indeed get a first round of notifications to tell them to stop performing bus plug/unplug operations (it's debatable whether we want to keep unplug going provided we can stack up the usermode events and re-send them later though, but let's say no for the sake of simplicity).
Quoted 3 lines
Yes. Rafael, how close is your new notifier chain to mainline? Can it at least be added to Greg KH's development tree so that I can start using it?
It should be in -mm, IIRC.
Quoted 7 lines
Quoted 6 lines
I think it's a fairly significant change from the current freezer and I also think it's a very good idea. The more I think about it, the more I like it, in the sense that it's a simple drop-in that you could put in a lot of the ioctl path of drivers to just block tasks that are trying to call in while suspending, and could be used selectively by things like the USB hub threads.
Quoted 6 lines
That's what I had in mind. Rafael, can we add an "icebox" routine? Like Ben says, it doesn't need to be much more than a waitqueue that the current task puts itself on if a suspend is in progress. Callers arriving at a time when the icebox isn't activated should simply return without blocking. Basically the icebox should be active at the same times as the existing freezer.
You could use try_to_freeze(), but you want it to be separate routine so it can be grepped for... Can you #define icebox_me try_to_freeze for testing?
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Hi!
Quoted 11 lines
Quoted 10 lines
There are two things I believe. There's a generic issue with usermode helpers that make no sense to call between pre-suspend and post-resume, and there's the specific issue of adding/removing devices.
I believe that "bus" drivers such as USB should indeed get a first round of notifications to tell them to stop performing bus plug/unplug operations (it's debatable whether we want to keep unplug going provided we can stack up the usermode events and re-send them later though, but let's say no for the sake of simplicity).
Quoted 3 lines
Yes. Rafael, how close is your new notifier chain to mainline? Can it at least be added to Greg KH's development tree so that I can start using it?
It should be in -mm, IIRC.
Quoted 7 lines
Quoted 6 lines
I think it's a fairly significant change from the current freezer and I also think it's a very good idea. The more I think about it, the more I like it, in the sense that it's a simple drop-in that you could put in a lot of the ioctl path of drivers to just block tasks that are trying to call in while suspending, and could be used selectively by things like the USB hub threads.
Quoted 6 lines
That's what I had in mind. Rafael, can we add an "icebox" routine? Like Ben says, it doesn't need to be much more than a waitqueue that the current task puts itself on if a suspend is in progress. Callers arriving at a time when the icebox isn't activated should simply return without blocking. Basically the icebox should be active at the same times as the existing freezer.
You could use try_to_freeze(), but you want it to be separate routine so it can be grepped for... Can you #define icebox_me try_to_freeze for testing?
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 4 lines
But I'm not sure it's a good idea in the long run. Think of a printer daemon, for example. It shouldn't have to experience unexpected I/O problems merely because someone has decided to put the system to sleep.
Why not ? Printer is offline when machine is asleep... trying to print errors out, I don't see the problem there. At one point, we'll need a cleaner way to also notify userland in which case our daemon could become more intelligent and stop servicings things before sleep and resume afterward :-)
Quoted 2 lines
This will be up to the people responsible for the subsystems. I can take care of USB.
USB is not that much of a problem in the sense that for most "leaf" drivers, USB is a provider (ie, the bus they sit on), not the client (like the network stack is to network drivers).
In most cases, that "helper" thing would sit on the client subsystem, since it's the one feeding drivers with requests. The main ones I see at hand are block, alsa, net, fb/drm... Some of them already have infrastructure to do it, some my need some more work.
Quoted 7 lines
Quoted 6 lines
I think it's a fairly significant change from the current freezer and I also think it's a very good idea. The more I think about it, the more I like it, in the sense that it's a simple drop-in that you could put in a lot of the ioctl path of drivers to just block tasks that are trying to call in while suspending, and could be used selectively by things like the USB hub threads.
Quoted 6 lines
That's what I had in mind. Rafael, can we add an "icebox" routine? Like Ben says, it doesn't need to be much more than a waitqueue that the current task puts itself on if a suspend is in progress. Callers arriving at a time when the icebox isn't activated should simply return without blocking. Basically the icebox should be active at the same times as the existing freezer.
There is still the race of:
drivers_sysfs_write() try_to_icebox() <---- <sleep request gets here> hit hardware
Those are akin, in some ways, to the freezer races. Some kind of RCU might take care of them if we enable the icebox, then wait for all tasks to hit an explicit schedule point once (or return to userland). That would mean that drivers need to try_to_icebox() again if they do something that may schedule (such as __get_user). So it's not a magic solution, it has issues, but it can handle a lot of the simplest cases.
Quoted 20 lines
Here's a wacky idea which just might work:
In order to prevent binding and unbinding, while suspending devices all the PM core has to do is avoid dropping the device semaphores! It can release the semaphores as it resumes the devices.
Of course, for this to work it's necessary to avoid changes to the device list during the suspend. However I believe the iteration can be made safe against unregistration, so we only have to prevent device registration. (And anyway, it won't be possible to unregister a device while the PM core is holding its semaphore.)
If we are willing to be somewhat non-transparent, this is easy to accomplish. After the notifier chain has been alerted about the upcoming suspend, we tell the driver core to disallow adding new devices. Maybe use SRCU to synchronize with registration calls that are in progress. Thus, until the suspend is over
device_add()will immediately return an error. We could even add a new ESUSPENDING code toerrno.h; it would come in handy in a few places.
Quoted 4 lines
Drivers are already prepared for device registration to fail (or they ought to be), so this change shouldn't knock the bottom out of things.
device_add()isn't on a hot path, so adding an extra check andsrcu_read_lock()won't hurt.
True. Also, bus drivers could just flag the port with something saying "try registering again later". Don't underestimate the power of "try later" constructs :-)
Quoted 4 lines
I have had the same thought, that unbinding and unregistration would be easier to handle than binding and registration. As it happens, holding the device semaphore will block both all three -- which makes life simpler.
Yup. Fair and simple.
Quoted 4 lines
There are other possibilities too. For example, instead of using keventd these attributes could use a separate workqueue which would put itself in the icebox during a suspend. Or maybe sysfs can be reworked so that they don't need to use a workqueue at all.
I think having a facility for a given workqueue entry to requeue itself for after resume might be of use for drivers too.
Quoted 8 lines
Quoted 3 lines
Don't get me wrong, I never said we don't need generic infrastructure and utilities, such as your proposed icebox scheme, or some of those workqueue bits, helpers in subsystems, etc...
I hope that everyone will agree that now is a good time to get started on them. There shouldn't be any problem about having them present along with the freezer, and then it will be all that much easier to remove the freezer later on if that's what we decide to do.
Ben.
Quoted 4 lines
But I'm not sure it's a good idea in the long run. Think of a printer daemon, for example. It shouldn't have to experience unexpected I/O problems merely because someone has decided to put the system to sleep.
Why not ? Printer is offline when machine is asleep... trying to print errors out, I don't see the problem there. At one point, we'll need a cleaner way to also notify userland in which case our daemon could become more intelligent and stop servicings things before sleep and resume afterward :-)
Quoted 2 lines
This will be up to the people responsible for the subsystems. I can take care of USB.
USB is not that much of a problem in the sense that for most "leaf" drivers, USB is a provider (ie, the bus they sit on), not the client (like the network stack is to network drivers).
In most cases, that "helper" thing would sit on the client subsystem, since it's the one feeding drivers with requests. The main ones I see at hand are block, alsa, net, fb/drm... Some of them already have infrastructure to do it, some my need some more work.
Quoted 7 lines
Quoted 6 lines
I think it's a fairly significant change from the current freezer and I also think it's a very good idea. The more I think about it, the more I like it, in the sense that it's a simple drop-in that you could put in a lot of the ioctl path of drivers to just block tasks that are trying to call in while suspending, and could be used selectively by things like the USB hub threads.
Quoted 6 lines
That's what I had in mind. Rafael, can we add an "icebox" routine? Like Ben says, it doesn't need to be much more than a waitqueue that the current task puts itself on if a suspend is in progress. Callers arriving at a time when the icebox isn't activated should simply return without blocking. Basically the icebox should be active at the same times as the existing freezer.
There is still the race of:
drivers_sysfs_write() try_to_icebox() <---- <sleep request gets here> hit hardware
Those are akin, in some ways, to the freezer races. Some kind of RCU might take care of them if we enable the icebox, then wait for all tasks to hit an explicit schedule point once (or return to userland). That would mean that drivers need to try_to_icebox() again if they do something that may schedule (such as __get_user). So it's not a magic solution, it has issues, but it can handle a lot of the simplest cases.
Quoted 20 lines
Here's a wacky idea which just might work:
In order to prevent binding and unbinding, while suspending devices all the PM core has to do is avoid dropping the device semaphores! It can release the semaphores as it resumes the devices.
Of course, for this to work it's necessary to avoid changes to the device list during the suspend. However I believe the iteration can be made safe against unregistration, so we only have to prevent device registration. (And anyway, it won't be possible to unregister a device while the PM core is holding its semaphore.)
If we are willing to be somewhat non-transparent, this is easy to accomplish. After the notifier chain has been alerted about the upcoming suspend, we tell the driver core to disallow adding new devices. Maybe use SRCU to synchronize with registration calls that are in progress. Thus, until the suspend is over
device_add()will immediately return an error. We could even add a new ESUSPENDING code toerrno.h; it would come in handy in a few places.
Quoted 4 lines
Drivers are already prepared for device registration to fail (or they ought to be), so this change shouldn't knock the bottom out of things.
device_add()isn't on a hot path, so adding an extra check andsrcu_read_lock()won't hurt.
True. Also, bus drivers could just flag the port with something saying "try registering again later". Don't underestimate the power of "try later" constructs :-)
Quoted 4 lines
I have had the same thought, that unbinding and unregistration would be easier to handle than binding and registration. As it happens, holding the device semaphore will block both all three -- which makes life simpler.
Yup. Fair and simple.
Quoted 4 lines
There are other possibilities too. For example, instead of using keventd these attributes could use a separate workqueue which would put itself in the icebox during a suspend. Or maybe sysfs can be reworked so that they don't need to use a workqueue at all.
I think having a facility for a given workqueue entry to requeue itself for after resume might be of use for drivers too.
Quoted 8 lines
Quoted 3 lines
Don't get me wrong, I never said we don't need generic infrastructure and utilities, such as your proposed icebox scheme, or some of those workqueue bits, helpers in subsystems, etc...
I hope that everyone will agree that now is a good time to get started on them. There shouldn't be any problem about having them present along with the freezer, and then it will be all that much easier to remove the freezer later on if that's what we decide to do.
Ben.
Quoted 37 lines · Benjamin Herrenschmidt
Quoted 4 lines
But I'm not sure it's a good idea in the long run. Think of a printer daemon, for example. It shouldn't have to experience unexpected I/O problems merely because someone has decided to put the system to sleep.
Why not ? Printer is offline when machine is asleep... trying to print errors out, I don't see the problem there. At one point, we'll need a cleaner way to also notify userland in which case our daemon could become more intelligent and stop servicings things before sleep and resume afterward :-)
Quoted 2 lines
This will be up to the people responsible for the subsystems. I can take care of USB.
USB is not that much of a problem in the sense that for most "leaf" drivers, USB is a provider (ie, the bus they sit on), not the client (like the network stack is to network drivers).
In most cases, that "helper" thing would sit on the client subsystem, since it's the one feeding drivers with requests. The main ones I see at hand are block, alsa, net, fb/drm... Some of them already have infrastructure to do it, some my need some more work.
Quoted 7 lines
Quoted 6 lines
I think it's a fairly significant change from the current freezer and I also think it's a very good idea. The more I think about it, the more I like it, in the sense that it's a simple drop-in that you could put in a lot of the ioctl path of drivers to just block tasks that are trying to call in while suspending, and could be used selectively by things like the USB hub threads.
Quoted 6 lines
That's what I had in mind. Rafael, can we add an "icebox" routine? Like Ben says, it doesn't need to be much more than a waitqueue that the current task puts itself on if a suspend is in progress. Callers arriving at a time when the icebox isn't activated should simply return without blocking. Basically the icebox should be active at the same times as the existing freezer.
Quoted 8 lines
There is still the race of:
drivers_sysfs_write() try_to_icebox() <---- <sleep request gets here> hit hardwareThose are akin, in some ways, to the freezer races.
I'm not sure what races you're referring to, but never mind. :-)
This is the reason why the freezer waits for tasks to freeze, actually.
Quoted 3 lines
Some kind of RCU might take care of them if we enable the icebox, then wait for all tasks to hit an explicit schedule point once (or return to userland).
This is what the freezer does, isn't it? ;-)
Quoted 3 lines
That would mean that drivers need to
try_to_icebox()again if they do something that may schedule (such as__get_user). So it's not a magic solution, it has issues, but it can handle a lot of the simplest cases.
Well, can't we do:
drivers_sysfs_write()
while(!suspend_trylock()) try_to_icebox() --> or even try_to_freeze(), what's the difference?
hit hardware
unlock_suspend()
where the PM core must wait for the suspend lock to get released (say with a timeout)?
Quoted 36 lines
Quoted 20 lines
Here's a wacky idea which just might work:
In order to prevent binding and unbinding, while suspending devices all the PM core has to do is avoid dropping the device semaphores! It can release the semaphores as it resumes the devices.
Of course, for this to work it's necessary to avoid changes to the device list during the suspend. However I believe the iteration can be made safe against unregistration, so we only have to prevent device registration. (And anyway, it won't be possible to unregister a device while the PM core is holding its semaphore.)
If we are willing to be somewhat non-transparent, this is easy to accomplish. After the notifier chain has been alerted about the upcoming suspend, we tell the driver core to disallow adding new devices. Maybe use SRCU to synchronize with registration calls that are in progress. Thus, until the suspend is over
device_add()will immediately return an error. We could even add a new ESUSPENDING code toerrno.h; it would come in handy in a few places.Quoted 4 lines
Drivers are already prepared for device registration to fail (or they ought to be), so this change shouldn't knock the bottom out of things.
device_add()isn't on a hot path, so adding an extra check andsrcu_read_lock()won't hurt.True. Also, bus drivers could just flag the port with something saying "try registering again later". Don't underestimate the power of "try later" constructs :-)
Quoted 4 lines
I have had the same thought, that unbinding and unregistration would be easier to handle than binding and registration. As it happens, holding the device semaphore will block both all three -- which makes life simpler.
Yup. Fair and simple.
Quoted 7 lines
Quoted 4 lines
There are other possibilities too. For example, instead of using keventd these attributes could use a separate workqueue which would put itself in the icebox during a suspend. Or maybe sysfs can be reworked so that they don't need to use a workqueue at all.
I think having a facility for a given workqueue entry to requeue itself for after resume might be of use for drivers too.
Hmm, perhaps we can use a special workqueue that's created before the suspend (say by the PM core) and starts processing jobs after the resume?
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Quoted 10 lines
drivers_sysfs_write()while(!suspend_trylock()) try_to_icebox() --> or even try_to_freeze(), what's the difference?hit hardware
unlock_suspend()where the PM core must wait for the suspend lock to get released (say with a timeout)?
Somewhat. What I'd like is to have that a construct of that sort on a per-driver basis though :-) Now the question is, in what way would the above be different from a simple suspend mutex ? I've been using mutexes in the past for a couple of drivers (iirc, that's how I did it for dmasound_pmac, though that driver is long past obsolescence now).
But yes, that's the idea, something under control of drivers, instead of a 3rd party freezer that tries to hit at processes.
Quoted 2 lines
Hmm, perhaps we can use a special workqueue that's created before the suspend (say by the PM core) and starts processing jobs after the resume?
Yeah, whatever the implementation is, though, the interface should be transparent. But then, I see little use of that. Mostly things like this sysfs write to unbind Alan was talking about. Driver workqueues probably need to be functioning all the way until the driver itself is suspended, in which case, the driver may just flush_worqueues in it's suspend path at the right time to make sure it doesn't exit with something still pending.
Ben.
Quoted 11 lines · Benjamin Herrenschmidt
Quoted 9 lines
drivers_sysfs_write()while(!suspend_trylock()) try_to_icebox() --> or even try_to_freeze(), what's thedifference?
hit hardware
unlock_suspend()where the PM core must wait for the suspend lock to get released (say with a timeout)?
Somewhat. What I'd like is to have that a construct of that sort on a per-driver basis though :-) Now the question is, in what way would the above be different from a simple suspend mutex ? I've been using mutexes in the past for a couple of drivers (iirc, that's how I did it for
dmasound_pmac, though that driver is long past obsolescence now).
I agree completely. It's a bit trickier if you want to do work in uninterruptable contexts:
driver_suspend_callback(...)
{
dev_suspend_lock(dev);
put_hardware_to_sleep(dev);
}driver_resume_callback(...)
{
wake_hardware_up(dev);
dev_suspend_unlock(dev);
}Then for sleep-capable contexts:
dev_suspend_lock(dev); dev_suspend_unlock(dev);
And for no-sleep contexts like interrupts etc:
if (!dev_suspend_trylock(dev)) return postpone_work_for_later(dev, ...); do_stuff_with(dev); dev_suspend_unlock(dev);
You could do this with a straight mutex except for the dev_suspend_trylock/unlock bit in uninterruptable contexts, but I seem to recall somebody saying that could be made to work if there was a real need for it. Alternatively you could just drive the "Generic Mutex" guys up the wall by inventing your own pseudo-mutex with a spinlock, a boolean value, and a waitqueue.
Then when you put your driver to sleep, things trying to do IO will automatically "freeze" themselves exactly until the device is woken again.
Assuming the driver model and subsystem get the ordering right for which devices to suspend/resume, then it's impossible to deadlock or cause hardware confusion. And even further, if you manage to make the automagic mutex-debugging code work with the noninterruptable trylock it will yell at you when the driver model does nasty deadlock-y things.
On the other hand, if the driver model *doesn't* get the ordering right then it's fundamentally impossible to reliably suspend and resume.
Cheers,
Kyle Moffett
Quoted 11 lines · Benjamin Herrenschmidt
Quoted 9 lines
drivers_sysfs_write()while(!suspend_trylock()) try_to_icebox() --> or even try_to_freeze(), what's thedifference?
hit hardware
unlock_suspend()where the PM core must wait for the suspend lock to get released (say with a timeout)?
Somewhat. What I'd like is to have that a construct of that sort on a per-driver basis though :-) Now the question is, in what way would the above be different from a simple suspend mutex ? I've been using mutexes in the past for a couple of drivers (iirc, that's how I did it for
dmasound_pmac, though that driver is long past obsolescence now).
I agree completely. It's a bit trickier if you want to do work in uninterruptable contexts:
driver_suspend_callback(...)
{
dev_suspend_lock(dev);
put_hardware_to_sleep(dev);
}driver_resume_callback(...)
{
wake_hardware_up(dev);
dev_suspend_unlock(dev);
}Then for sleep-capable contexts:
dev_suspend_lock(dev); dev_suspend_unlock(dev);
And for no-sleep contexts like interrupts etc:
if (!dev_suspend_trylock(dev)) return postpone_work_for_later(dev, ...); do_stuff_with(dev); dev_suspend_unlock(dev);
You could do this with a straight mutex except for the dev_suspend_trylock/unlock bit in uninterruptable contexts, but I seem to recall somebody saying that could be made to work if there was a real need for it. Alternatively you could just drive the "Generic Mutex" guys up the wall by inventing your own pseudo-mutex with a spinlock, a boolean value, and a waitqueue.
Then when you put your driver to sleep, things trying to do IO will automatically "freeze" themselves exactly until the device is woken again.
Assuming the driver model and subsystem get the ordering right for which devices to suspend/resume, then it's impossible to deadlock or cause hardware confusion. And even further, if you manage to make the automagic mutex-debugging code work with the noninterruptable trylock it will yell at you when the driver model does nasty deadlock-y things.
On the other hand, if the driver model *doesn't* get the ordering right then it's fundamentally impossible to reliably suspend and resume.
Cheers,
Kyle Moffett
Quoted 7 lines
You could do this with a straight mutex except for the dev_suspend_trylock/unlock bit in uninterruptable contexts, but I seem to recall somebody saying that could be made to work if there was a real need for it. Alternatively you could just drive the "Generic Mutex" guys up the wall by inventing your own pseudo-mutex with a spinlock, a boolean value, and a waitqueue.
Most of the time, the interrupt/atomic contexts are part of what I call the "main path" of the driver, which doesn't need most of this stuff.
Depending on what is "upstream" from the driver, you typically set a condition stopping the flow of "interrupt" activity and wait for it to drain in suspend. For example, a block driver would instruct the driver to stop processing the request queue and wait for pending in flight requests to drain, or a network driver would stop the tx queue and wait for pending/concurrent xmit() callbacks to complete (basically sync. bh and sync. with NAPI poll).
In both examples, helpers can be provided in the block layer or network stack to make that easier.
In many cases, the driver may just turn off something in the chip in "suspend" (using a low level spinlock that it already has if it has an irq path to sync. HW access) and set some flag/state to instruct the irq handler to not restart, then synchronize_irq().
All those techniques are fairly simple and well known. The main source of problems are the "sideband" channels, such as sysfs accesses to driver tunables, ioctl's, etc... for which I believe mutexes can solve 90% of them.
Ben.
Quoted 7 lines
You could do this with a straight mutex except for the dev_suspend_trylock/unlock bit in uninterruptable contexts, but I seem to recall somebody saying that could be made to work if there was a real need for it. Alternatively you could just drive the "Generic Mutex" guys up the wall by inventing your own pseudo-mutex with a spinlock, a boolean value, and a waitqueue.
Most of the time, the interrupt/atomic contexts are part of what I call the "main path" of the driver, which doesn't need most of this stuff.
Depending on what is "upstream" from the driver, you typically set a condition stopping the flow of "interrupt" activity and wait for it to drain in suspend. For example, a block driver would instruct the driver to stop processing the request queue and wait for pending in flight requests to drain, or a network driver would stop the tx queue and wait for pending/concurrent xmit() callbacks to complete (basically sync. bh and sync. with NAPI poll).
In both examples, helpers can be provided in the block layer or network stack to make that easier.
In many cases, the driver may just turn off something in the chip in "suspend" (using a low level spinlock that it already has if it has an irq path to sync. HW access) and set some flag/state to instruct the irq handler to not restart, then synchronize_irq().
All those techniques are fairly simple and well known. The main source of problems are the "sideband" channels, such as sysfs accesses to driver tunables, ioctl's, etc... for which I believe mutexes can solve 90% of them.
Ben.
Quoted 37 lines · Benjamin Herrenschmidt
Quoted 4 lines
But I'm not sure it's a good idea in the long run. Think of a printer daemon, for example. It shouldn't have to experience unexpected I/O problems merely because someone has decided to put the system to sleep.
Why not ? Printer is offline when machine is asleep... trying to print errors out, I don't see the problem there. At one point, we'll need a cleaner way to also notify userland in which case our daemon could become more intelligent and stop servicings things before sleep and resume afterward :-)
Quoted 2 lines
This will be up to the people responsible for the subsystems. I can take care of USB.
USB is not that much of a problem in the sense that for most "leaf" drivers, USB is a provider (ie, the bus they sit on), not the client (like the network stack is to network drivers).
In most cases, that "helper" thing would sit on the client subsystem, since it's the one feeding drivers with requests. The main ones I see at hand are block, alsa, net, fb/drm... Some of them already have infrastructure to do it, some my need some more work.
Quoted 7 lines
Quoted 6 lines
I think it's a fairly significant change from the current freezer and I also think it's a very good idea. The more I think about it, the more I like it, in the sense that it's a simple drop-in that you could put in a lot of the ioctl path of drivers to just block tasks that are trying to call in while suspending, and could be used selectively by things like the USB hub threads.
Quoted 6 lines
That's what I had in mind. Rafael, can we add an "icebox" routine? Like Ben says, it doesn't need to be much more than a waitqueue that the current task puts itself on if a suspend is in progress. Callers arriving at a time when the icebox isn't activated should simply return without blocking. Basically the icebox should be active at the same times as the existing freezer.
Quoted 8 lines
There is still the race of:
drivers_sysfs_write() try_to_icebox() <---- <sleep request gets here> hit hardwareThose are akin, in some ways, to the freezer races.
I'm not sure what races you're referring to, but never mind. :-)
This is the reason why the freezer waits for tasks to freeze, actually.
Quoted 3 lines
Some kind of RCU might take care of them if we enable the icebox, then wait for all tasks to hit an explicit schedule point once (or return to userland).
This is what the freezer does, isn't it? ;-)
Quoted 3 lines
That would mean that drivers need to
try_to_icebox()again if they do something that may schedule (such as__get_user). So it's not a magic solution, it has issues, but it can handle a lot of the simplest cases.
Well, can't we do:
drivers_sysfs_write()
while(!suspend_trylock()) try_to_icebox() --> or even try_to_freeze(), what's the difference?
hit hardware
unlock_suspend()
where the PM core must wait for the suspend lock to get released (say with a timeout)?
Quoted 36 lines
Quoted 20 lines
Here's a wacky idea which just might work:
In order to prevent binding and unbinding, while suspending devices all the PM core has to do is avoid dropping the device semaphores! It can release the semaphores as it resumes the devices.
Of course, for this to work it's necessary to avoid changes to the device list during the suspend. However I believe the iteration can be made safe against unregistration, so we only have to prevent device registration. (And anyway, it won't be possible to unregister a device while the PM core is holding its semaphore.)
If we are willing to be somewhat non-transparent, this is easy to accomplish. After the notifier chain has been alerted about the upcoming suspend, we tell the driver core to disallow adding new devices. Maybe use SRCU to synchronize with registration calls that are in progress. Thus, until the suspend is over
device_add()will immediately return an error. We could even add a new ESUSPENDING code toerrno.h; it would come in handy in a few places.Quoted 4 lines
Drivers are already prepared for device registration to fail (or they ought to be), so this change shouldn't knock the bottom out of things.
device_add()isn't on a hot path, so adding an extra check andsrcu_read_lock()won't hurt.True. Also, bus drivers could just flag the port with something saying "try registering again later". Don't underestimate the power of "try later" constructs :-)
Quoted 4 lines
I have had the same thought, that unbinding and unregistration would be easier to handle than binding and registration. As it happens, holding the device semaphore will block both all three -- which makes life simpler.
Yup. Fair and simple.
Quoted 7 lines
Quoted 4 lines
There are other possibilities too. For example, instead of using keventd these attributes could use a separate workqueue which would put itself in the icebox during a suspend. Or maybe sysfs can be reworked so that they don't need to use a workqueue at all.
I think having a facility for a given workqueue entry to requeue itself for after resume might be of use for drivers too.
Hmm, perhaps we can use a special workqueue that's created before the suspend (say by the PM core) and starts processing jobs after the resume?
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Am Sonntag, 8. Juli 2007 schrieb Benjamin Herrenschmidt:
Quoted 5 lines
Quoted 3 lines
But I'm not sure it's a good idea in the long run. Think of a printer daemon, for example. It shouldn't have to experience unexpected I/O problems merely because someone has decided to put the system to sleep.
Why not ? Printer is offline when machine is asleep... trying to print
Not necessarily. The machine must survive going to sleep while you are printing. Any other error return than -ERESTARTSYS is not an option. We can't simply change the ABI.
Regards
Oliver
Am Sonntag, 8. Juli 2007 schrieb Benjamin Herrenschmidt:
Quoted 5 lines
Quoted 3 lines
But I'm not sure it's a good idea in the long run. Think of a printer daemon, for example. It shouldn't have to experience unexpected I/O problems merely because someone has decided to put the system to sleep.
Why not ? Printer is offline when machine is asleep... trying to print
Not necessarily. The machine must survive going to sleep while you are printing. Any other error return than -ERESTARTSYS is not an option. We can't simply change the ABI.
Regards
Oliver
Quoted 10 lines · Oliver Neukum
Am Sonntag, 8. Juli 2007 schrieb Benjamin Herrenschmidt:
Quoted 5 lines
Quoted 3 lines
But I'm not sure it's a good idea in the long run. Think of a printer daemon, for example. It shouldn't have to experience unexpected I/O problems merely because someone has decided to put the system to sleep.
Why not ? Printer is offline when machine is asleep... trying to print
Not necessarily. The machine must survive going to sleep while you are printing. Any other error return than
-ERESTARTSYSis not an option. We can't simply change the ABI.
Ugh ? Why returning an error from the printer driver to the userland print server/daemon would prevent the machine from "surviving" ? I would be happy with -EIO personally :-)
Ben.
Am Montag, 9. Juli 2007 schrieb Benjamin Herrenschmidt:
Quoted 8 lines · Oliver Neukum
Quoted 7 lines
Am Sonntag, 8. Juli 2007 schrieb Benjamin Herrenschmidt:
Quoted 5 lines
Quoted 3 lines
But I'm not sure it's a good idea in the long run. Think of a printer daemon, for example. It shouldn't have to experience unexpected I/O problems merely because someone has decided to put the system to sleep.
Why not ? Printer is offline when machine is asleep... trying to print
Quoted 7 lines
Quoted 3 lines
Not necessarily. The machine must survive going to sleep while you are printing. Any other error return than
-ERESTARTSYSis not an option. We can't simply change the ABI.Ugh ? Why returning an error from the printer driver to the userland print server/daemon would prevent the machine from "surviving" ? I would be happy with
-EIOpersonally :-)
Surviving is a bit strongly worded.
Suspension is to be transparent. Apart from a jump in the system clock user space must not notice, thus returning errors due to suspension is not an option.
Regards
Oliver
Am Montag, 9. Juli 2007 schrieb Benjamin Herrenschmidt:
Quoted 8 lines · Oliver Neukum
Quoted 7 lines
Am Sonntag, 8. Juli 2007 schrieb Benjamin Herrenschmidt:
Quoted 5 lines
Quoted 3 lines
But I'm not sure it's a good idea in the long run. Think of a printer daemon, for example. It shouldn't have to experience unexpected I/O problems merely because someone has decided to put the system to sleep.
Why not ? Printer is offline when machine is asleep... trying to print
Quoted 7 lines
Quoted 3 lines
Not necessarily. The machine must survive going to sleep while you are printing. Any other error return than
-ERESTARTSYSis not an option. We can't simply change the ABI.Ugh ? Why returning an error from the printer driver to the userland print server/daemon would prevent the machine from "surviving" ? I would be happy with
-EIOpersonally :-)
Surviving is a bit strongly worded.
Suspension is to be transparent. Apart from a jump in the system clock user space must not notice, thus returning errors due to suspension is not an option.
Regards
Oliver
Quoted 3 lines · Oliver Neukum
Suspension is to be transparent. Apart from a jump in the system clock user space must not notice, thus returning errors due to suspension is not an option.
Who says ?
If I'm talking to a USB printer, it will notice the USB bus being suspended, believe me. It's actually likely to screw up whatever job is in progress. It make perfect sense to error out attempts to talk to it when suspended.
I don't think "transparent" is an absolute requirement. In some cases, it doesn't make sense and the printer is a good example of that. The printing daemon is typically something that will ideally need to grow knowledge about suspend/resume to interrupt things at the right time.
That's one of the thing... we don't even have the kernel right, so we are light-years from having the rest of userland right.
For example, from a user point of view, what should happen if you suspend while printing ?
Well, it's a matter of policy (thus should be configurable), but I would exect (as a former Mac user) something around the lines of this as a default:
- If the laptop's clamshell has been closed, it's likely that the
user's just picking up the laptop for a ride, makes sense to abort jobs in progress.
- If this is a manual action via the menus, displaying a dialog asking
if you really want to suspend before your page is finished makes sense (with that dialog disappearing and the machine going to sleep if you just wait and let it print).
That sort of thing requires much more than just kernel collaboration of course, but a whole infrastructure in userland as well.
So no, suspend is -not- transparent, doesn't have to be, it's something that is to be decided on a case-by-case basis (or rather, driver-per-driver and possibly via policy settings).
Ben.
Quoted 17 lines · Benjamin Herrenschmidt
Quoted 3 lines · Oliver Neukum
Suspension is to be transparent. Apart from a jump in the system clock user space must not notice, thus returning errors due to suspension is not an option.
Who says ?
If I'm talking to a USB printer, it will notice the USB bus being suspended, believe me. It's actually likely to screw up whatever job is in progress. It make perfect sense to error out attempts to talk to it when suspended.
I don't think "transparent" is an absolute requirement. In some cases, it doesn't make sense and the printer is a good example of that. The printing daemon is typically something that will ideally need to grow knowledge about suspend/resume to interrupt things at the right time.
Quoted 5 lines
That's one of the thing... we don't even have the kernel right, so we are light-years from having the rest of userland right.
For example, from a user point of view, what should happen if you suspend while printing ?
There might be other existing things with a semantics that might be worth looking at, e.g.:
I don't have an USB printer, but what happens if you unplug the printer while printing, wait 30 seconds, and plug it in again?
Wait 3 hours?
Could this work theoretically?
Does it work in practice?
This are non-theoretical use cases kernel and userspace already somehow handle today, and for userspace an USB printer disconnected for 3 hours and a 3 hour suspend might simply be the same with the latter not requiring any extra userspace handling.
Another example might be mounted NFS file systems:
The case that a client's ethernet cable gets unplugged for 24 hours and plugged in again is a real life use case NFS and all applications already have to handle.
Quoted 13 lines
Well, it's a matter of policy (thus should be configurable), but I would exect (as a former Mac user) something around the lines of this as a default:
- If the laptop's clamshell has been closed, it's likely that the
user's just picking up the laptop for a ride, makes sense to abort jobs in progress.- If this is a manual action via the menus, displaying a dialog asking
if you really want to suspend before your page is finished makes sense (with that dialog disappearing and the machine going to sleep if you just wait and let it print).
Quoted 6 lines
That sort of thing requires much more than just kernel collaboration of course, but a whole infrastructure in userland as well.
So no, suspend is -not- transparent, doesn't have to be, it's something that is to be decided on a case-by-case basis (or rather, driver-per-driver and possibly via policy settings).
But keep in mind that every piece that does not work transparently might result in less use cases for suspend.
There are cases like CD burning while suspending that might not be solvable, but as much as possible should work as transparently as possible.
Quoted 1 line
Ben.
cu
Adrian
Signature · 4 lines
"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon SeedQuoted 17 lines · Benjamin Herrenschmidt
Quoted 3 lines · Oliver Neukum
Suspension is to be transparent. Apart from a jump in the system clock user space must not notice, thus returning errors due to suspension is not an option.
Who says ?
If I'm talking to a USB printer, it will notice the USB bus being suspended, believe me. It's actually likely to screw up whatever job is in progress. It make perfect sense to error out attempts to talk to it when suspended.
I don't think "transparent" is an absolute requirement. In some cases, it doesn't make sense and the printer is a good example of that. The printing daemon is typically something that will ideally need to grow knowledge about suspend/resume to interrupt things at the right time.
Quoted 5 lines
That's one of the thing... we don't even have the kernel right, so we are light-years from having the rest of userland right.
For example, from a user point of view, what should happen if you suspend while printing ?
There might be other existing things with a semantics that might be worth looking at, e.g.:
I don't have an USB printer, but what happens if you unplug the printer while printing, wait 30 seconds, and plug it in again?
Wait 3 hours?
Could this work theoretically?
Does it work in practice?
This are non-theoretical use cases kernel and userspace already somehow handle today, and for userspace an USB printer disconnected for 3 hours and a 3 hour suspend might simply be the same with the latter not requiring any extra userspace handling.
Another example might be mounted NFS file systems:
The case that a client's ethernet cable gets unplugged for 24 hours and plugged in again is a real life use case NFS and all applications already have to handle.
Quoted 13 lines
Well, it's a matter of policy (thus should be configurable), but I would exect (as a former Mac user) something around the lines of this as a default:
- If the laptop's clamshell has been closed, it's likely that the
user's just picking up the laptop for a ride, makes sense to abort jobs in progress.- If this is a manual action via the menus, displaying a dialog asking
if you really want to suspend before your page is finished makes sense (with that dialog disappearing and the machine going to sleep if you just wait and let it print).
Quoted 6 lines
That sort of thing requires much more than just kernel collaboration of course, but a whole infrastructure in userland as well.
So no, suspend is -not- transparent, doesn't have to be, it's something that is to be decided on a case-by-case basis (or rather, driver-per-driver and possibly via policy settings).
But keep in mind that every piece that does not work transparently might result in less use cases for suspend.
There are cases like CD burning while suspending that might not be solvable, but as much as possible should work as transparently as possible.
Quoted 1 line
Ben.
cu
Adrian
Signature · 4 lines
"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon SeedHi!
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
But I'm not sure it's a good idea in the long run. Think of a printer daemon, for example. It shouldn't have to experience unexpected I/O problems merely because someone has decided to put the system to sleep.
Why not ? Printer is offline when machine is asleep... trying to print
...filesystems are offline, too, when the machine is asleep. Yet, unmounting everything on suspend would not result in useful suspend support.
Yes, I believe we should be transparent.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 6 lines · Pavel Machek
Hi!
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
But I'm not sure it's a good idea in the long run. Think of a printer daemon, for example. It shouldn't have to experience unexpected I/O problems merely because someone has decided to put the system to sleep.
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Why not ? Printer is offline when machine is asleep... trying to print
...filesystems are offline, too, when the machine is asleep. Yet, unmounting everything on suspend would not result in useful suspend support.
Yes, I believe we should be transparent.
You just compared apple and oranges... Try printing and half way through the page, suspend your USB bus, and see how the printer reacts.
Ben.
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 2 lines
This will be up to the people responsible for the subsystems. I can take care of USB.
USB is not that much of a problem in the sense that for most "leaf" drivers, USB is a provider (ie, the bus they sit on), not the client (like the network stack is to network drivers).
That's why I thought I would be able to handle it! :-)
Quoted 7 lines
There is still the race of:
drivers_sysfs_write() try_to_icebox() <---- <sleep request gets here> hit hardware
Quoted 6 lines
Those are akin, in some ways, to the freezer races. Some kind of RCU might take care of them if we enable the icebox, then wait for all tasks to hit an explicit schedule point once (or return to userland). That would mean that drivers need to
try_to_icebox()again if they do something that may schedule (such as__get_user). So it's not a magic solution, it has issues, but it can handle a lot of the simplest cases.
It depends on what kind of race you're worried about. In general a sysfs access that causes I/O isn't much different from a char device's read or write. For such cases the driver would have to do something like this:
drivers_sysfs_write()
{
restart:
mutex_lock(private_io_mutex);
if (device is suspended) {
mutex_unlock(private_io_mutex);
icebox();
goto restart;
}
... hit hardware ...
mutex_unlock(private_io_mutex);
}And of course the suspend method would have to acquire the private_io_mutex. Some drivers might be able to use the device semaphore instead of adding a new mutex.
I'm more concerned about races involving device registration. The best solution I can come up with is to use an rwsem:
drivers_sysfs_write()
{
down_read(private_rwsem);
... register/unregister devices ...
up_read(private_rwsem);
}where the suspend notifer callout would do down_write() and the resume callout would do up_write(). Can you suggest anything better?
Quoted 8 lines
Quoted 4 lines
Drivers are already prepared for device registration to fail (or they ought to be), so this change shouldn't knock the bottom out of things.
device_add()isn't on a hot path, so adding an extra check andsrcu_read_lock()won't hurt.True. Also, bus drivers could just flag the port with something saying "try registering again later". Don't underestimate the power of "try later" constructs :-)
-ESUSPENDING would naturally imply that the caller should retry after the resume.
Alan Stern
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 2 lines
This will be up to the people responsible for the subsystems. I can take care of USB.
USB is not that much of a problem in the sense that for most "leaf" drivers, USB is a provider (ie, the bus they sit on), not the client (like the network stack is to network drivers).
That's why I thought I would be able to handle it! :-)
Quoted 7 lines
There is still the race of:
drivers_sysfs_write() try_to_icebox() <---- <sleep request gets here> hit hardware
Quoted 6 lines
Those are akin, in some ways, to the freezer races. Some kind of RCU might take care of them if we enable the icebox, then wait for all tasks to hit an explicit schedule point once (or return to userland). That would mean that drivers need to
try_to_icebox()again if they do something that may schedule (such as__get_user). So it's not a magic solution, it has issues, but it can handle a lot of the simplest cases.
It depends on what kind of race you're worried about. In general a sysfs access that causes I/O isn't much different from a char device's read or write. For such cases the driver would have to do something like this:
drivers_sysfs_write()
{
restart:
mutex_lock(private_io_mutex);
if (device is suspended) {
mutex_unlock(private_io_mutex);
icebox();
goto restart;
}
... hit hardware ...
mutex_unlock(private_io_mutex);
}And of course the suspend method would have to acquire the private_io_mutex. Some drivers might be able to use the device semaphore instead of adding a new mutex.
I'm more concerned about races involving device registration. The best solution I can come up with is to use an rwsem:
drivers_sysfs_write()
{
down_read(private_rwsem);
... register/unregister devices ...
up_read(private_rwsem);
}where the suspend notifer callout would do down_write() and the resume callout would do up_write(). Can you suggest anything better?
Quoted 8 lines
Quoted 4 lines
Drivers are already prepared for device registration to fail (or they ought to be), so this change shouldn't knock the bottom out of things.
device_add()isn't on a hot path, so adding an extra check andsrcu_read_lock()won't hurt.True. Also, bus drivers could just flag the port with something saying "try registering again later". Don't underestimate the power of "try later" constructs :-)
-ESUSPENDING would naturally imply that the caller should retry after the resume.
Alan Stern
Quoted 26 lines · Alan Stern
I'll make this reply short by agreeing up front with most of what you say.
Quoted 4 lines · Benjamin Herrenschmidt
But that's only the "main" path. Aside for that, almost all drivers also have sideband "request" input and some driver don't actually live behind a subsystem. That ranges from ioctl, to direct read/write on a char dev from userland.
Yes, these are the problem cases.
Quoted 4 lines
I think many of those cases can fairly well deal with just taking a PM semaphore, that's how I did for a couple of things in the past, provided that the request path isn't deadlocking with the semaphore held because of the system suspending of course.
That's what USB does as well (for the drivers which have runtime PM support -- at the moment only a few of them).
Quoted 5 lines
But in a whole lot of cases, it's, I beleive, perfectly kosher to just return an error. You're trying to capture frame from your camera while the machine is suspended ? error. At worst, your capture app will be unhappy when you wakeup, nothing terrible and totally fixable in userland if it's a problem.
Quoted 3 lines
We can try falling back on this approach for now. If the drivers are smart enough to fail cleanly when the device is already suspended, it should work.
And are they?
Quoted 3 lines
But I'm not sure it's a good idea in the long run. Think of a printer daemon, for example. It shouldn't have to experience unexpected I/O problems merely because someone has decided to put the system to sleep.
Agreed.
Quoted 21 lines
Quoted 6 lines
In some cases, we could use a little bit more help from the subsystem. Network for example, could have some explicit knowledge of the suspend state, and in addition to stopping the queue would also stop calling into things like
change_mtuorset_multicast, provided it's agreed that the driver will account for those changes on resume (the actual MTU values or multicast lists are still updated in the netdev).This will be up to the people responsible for the subsystems. I can take care of USB.
Quoted 10 lines
There are two things I believe. There's a generic issue with usermode helpers that make no sense to call between pre-suspend and post-resume, and there's the specific issue of adding/removing devices.
I believe that "bus" drivers such as USB should indeed get a first round of notifications to tell them to stop performing bus plug/unplug operations (it's debatable whether we want to keep unplug going provided we can stack up the usermode events and re-send them later though, but let's say no for the sake of simplicity).
Quoted 3 lines
Yes. Rafael, how close is your new notifier chain to mainline? Can it at least be added to Greg KH's development tree so that I can start using it?
It's in -mm. The patches queued up in -mm are also in my patchset at
http://www.sisk.pl/kernel/hibernation_and_suspend/2.6.22-rc7/patches/
Quoted 24 lines
Quoted 11 lines
Quoted 7 lines
So instead, why not have the PM core take care of all this? There could be a
block_task_until_suspend_is_over()routine available for all drivers to use. Its effect would be exactly the same as sending the current task into the freezer, but it wouldn't be the freezer that exists now. It would just be some routine that blocks until the system suspend is over. We could call it "the icebox" instead of "the freezer". :-)I'm not totally sure about that. I like some of it, but I think it's fairly different conceptually from the freezer (and the implementation could be as trivial as a single system wide wait queue).
Exactly.
Quoted 10 lines
Basically it has a very big difference to the current freezer, and I like that, which is that we don't have some 3rd party trying to find out what to freeze and what not (the freezer), but instead, we have explicitely drivers or kernel threads sending -themselves- to the "icebox" when they think it's a good idea. Think of it as lazy freezing -> you only freeze lazy tasks that are trying to do something that cannot be done because of suspend.
Quoted 1 line
Does that make you happier?
Quoted 8 lines
Quoted 6 lines
I think it's a fairly significant change from the current freezer and I also think it's a very good idea. The more I think about it, the more I like it, in the sense that it's a simple drop-in that you could put in a lot of the ioctl path of drivers to just block tasks that are trying to call in while suspending, and could be used selectively by things like the USB hub threads.
That's what I had in mind. Rafael, can we add an "icebox" routine?
Yes, I think so.
Quoted 5 lines
Like Ben says, it doesn't need to be much more than a waitqueue that the current task puts itself on if a suspend is in progress. Callers arriving at a time when the icebox isn't activated should simply return without blocking. Basically the icebox should be active at the same times as the existing freezer.
Hmm, I think this would be functionally equivalent to a modified freezer with the following changes:
(1) the actual freezing functionality is not hooked up to the signal code, but instead there are many invocations of try_to_freeze() all over the place,
(2) the freezer doesn't wait for tasks to freeze, only sets their TIF_FREEZE flags and exits, where TIF_FREEZE now means "there's a suspend in progress, please freeze yourself if need be".
BTW, this is similar to what I'd like to have for kernel threads RSN, except for the "doesn't wait" part.
IMO, something like this might be used for hibernation too, but in that case we need to do something about the tasks that haven't gone to the icebox.
I have some implementation-related questions:
* do we want each task to be notified individually or do we want a global variable, say "pm_entering_sleep_state", that will mean "now you're supposed to go to the icebox"
* at what point exactly this should be activated (ie. before the freezer or after it)
* how do we release tasks from the icebox (all at a time or individually, and if the latter then how exactly).
Quoted 22 lines
Quoted 9 lines
Quoted 2 lines
Of course, another possibility is simply to fail the bind. But that's not very satisfying, since suspends should be transparent.
I don't think suspend has to be -that- transparent (though there is some debate on whether it should be if we're gonna do some kind of fast "light" suspend for things like OLPC) but overall, I agree that a bind operation on sysfs should probably block until resume, and it does make sense to have the logic to do that in sysfs itself. It could perfectly use the above icebox thingy you came up with.
Here's a wacky idea which just might work:
In order to prevent binding and unbinding, while suspending devices all the PM core has to do is avoid dropping the device semaphores! It can release the semaphores as it resumes the devices.
Of course, for this to work it's necessary to avoid changes to the device list during the suspend. However I believe the iteration can be made safe against unregistration, so we only have to prevent device registration. (And anyway, it won't be possible to unregister a device while the PM core is holding its semaphore.)
Quoted 7 lines
If we are willing to be somewhat non-transparent, this is easy to accomplish. After the notifier chain has been alerted about the upcoming suspend, we tell the driver core to disallow adding new devices. Maybe use SRCU to synchronize with registration calls that are in progress. Thus, until the suspend is over
device_add()will immediately return an error. We could even add a new ESUSPENDING code toerrno.h; it would come in handy in a few places.
This last thing is a good idea, IMHO.
Quoted 11 lines
Drivers are already prepared for device registration to fail (or they ought to be), so this change shouldn't knock the bottom out of things.
device_add()isn't on a hot path, so adding an extra check andsrcu_read_lock()won't hurt.Quoted 5 lines
Regarding unbinding, that's debatable, it might be perfectly allright to unbind while suspended, though then, there is the question of a driver being later on bound to a piece of HW that is suspended (though I suppose that could happen today... some machines have their firmware leave some devices off at boot).
Quoted 4 lines
I have had the same thought, that unbinding and unregistration would be easier to handle than binding and registration. As it happens, holding the device semaphore will block both all three -- which makes life simpler.
I think we should do something like that in the beginning and probably try to add some flexibility later on.
Quoted 27 lines
Quoted 6 lines
As a general matter, If we have those pre-suspend/post-resume notifiers and we adapt the few (there isn't that much) bus drivers so that they stop all probe/unprobe operations before the suspend dance starts, we avoid a lot of that problem. At this point, it becomes fair enough for bind/unbind, in the core, to return an error (and maybe even stack trace in dmesg to catch the culprits) while suspend in in progress.
Putting a
WARN_ON()indevice_add()would be a good idea.Quoted 7 lines
Quoted 6 lines
But consider this: By writing the appropriate
sysfs attribute, a user task can cause a workqueue item to be queued to keventd that tries to unregister a device. That really puts you on the
spot: Unregistration can't be allowed to fail, it can't be allowed to succeed during a suspend, and keventd can't be blocked! So what should we do?Quoted 5 lines
We can either stop it at the sysfs write level, or we can have the workqueue task reschedule itself later until we are resumed. In fact, worqueue items being what they are (queue items), we could imagine having a special list where they enqueue themselves to rescheduled after resume.
There are other possibilities too. For example, instead of using keventd these attributes could use a separate workqueue which would put itself in the icebox during a suspend. Or maybe sysfs can be reworked so that they don't need to use a workqueue at all.
Quoted 8 lines
Quoted 3 lines
Don't get me wrong, I never said we don't need generic infrastructure and utilities, such as your proposed icebox scheme, or some of those workqueue bits, helpers in subsystems, etc...
I hope that everyone will agree that now is a good time to get started on them. There shouldn't be any problem about having them present along with the freezer, and then it will be all that much easier to remove the freezer later on if that's what we decide to do.
Agreed.
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Quoted 26 lines · Alan Stern
I'll make this reply short by agreeing up front with most of what you say.
Quoted 4 lines · Benjamin Herrenschmidt
But that's only the "main" path. Aside for that, almost all drivers also have sideband "request" input and some driver don't actually live behind a subsystem. That ranges from ioctl, to direct read/write on a char dev from userland.
Yes, these are the problem cases.
Quoted 4 lines
I think many of those cases can fairly well deal with just taking a PM semaphore, that's how I did for a couple of things in the past, provided that the request path isn't deadlocking with the semaphore held because of the system suspending of course.
That's what USB does as well (for the drivers which have runtime PM support -- at the moment only a few of them).
Quoted 5 lines
But in a whole lot of cases, it's, I beleive, perfectly kosher to just return an error. You're trying to capture frame from your camera while the machine is suspended ? error. At worst, your capture app will be unhappy when you wakeup, nothing terrible and totally fixable in userland if it's a problem.
Quoted 3 lines
We can try falling back on this approach for now. If the drivers are smart enough to fail cleanly when the device is already suspended, it should work.
And are they?
Quoted 3 lines
But I'm not sure it's a good idea in the long run. Think of a printer daemon, for example. It shouldn't have to experience unexpected I/O problems merely because someone has decided to put the system to sleep.
Agreed.
Quoted 21 lines
Quoted 6 lines
In some cases, we could use a little bit more help from the subsystem. Network for example, could have some explicit knowledge of the suspend state, and in addition to stopping the queue would also stop calling into things like
change_mtuorset_multicast, provided it's agreed that the driver will account for those changes on resume (the actual MTU values or multicast lists are still updated in the netdev).This will be up to the people responsible for the subsystems. I can take care of USB.
Quoted 10 lines
There are two things I believe. There's a generic issue with usermode helpers that make no sense to call between pre-suspend and post-resume, and there's the specific issue of adding/removing devices.
I believe that "bus" drivers such as USB should indeed get a first round of notifications to tell them to stop performing bus plug/unplug operations (it's debatable whether we want to keep unplug going provided we can stack up the usermode events and re-send them later though, but let's say no for the sake of simplicity).
Quoted 3 lines
Yes. Rafael, how close is your new notifier chain to mainline? Can it at least be added to Greg KH's development tree so that I can start using it?
It's in -mm. The patches queued up in -mm are also in my patchset at
http://www.sisk.pl/kernel/hibernation_and_suspend/2.6.22-rc7/patches/
Quoted 24 lines
Quoted 11 lines
Quoted 7 lines
So instead, why not have the PM core take care of all this? There could be a
block_task_until_suspend_is_over()routine available for all drivers to use. Its effect would be exactly the same as sending the current task into the freezer, but it wouldn't be the freezer that exists now. It would just be some routine that blocks until the system suspend is over. We could call it "the icebox" instead of "the freezer". :-)I'm not totally sure about that. I like some of it, but I think it's fairly different conceptually from the freezer (and the implementation could be as trivial as a single system wide wait queue).
Exactly.
Quoted 10 lines
Basically it has a very big difference to the current freezer, and I like that, which is that we don't have some 3rd party trying to find out what to freeze and what not (the freezer), but instead, we have explicitely drivers or kernel threads sending -themselves- to the "icebox" when they think it's a good idea. Think of it as lazy freezing -> you only freeze lazy tasks that are trying to do something that cannot be done because of suspend.
Quoted 1 line
Does that make you happier?
Quoted 8 lines
Quoted 6 lines
I think it's a fairly significant change from the current freezer and I also think it's a very good idea. The more I think about it, the more I like it, in the sense that it's a simple drop-in that you could put in a lot of the ioctl path of drivers to just block tasks that are trying to call in while suspending, and could be used selectively by things like the USB hub threads.
That's what I had in mind. Rafael, can we add an "icebox" routine?
Yes, I think so.
Quoted 5 lines
Like Ben says, it doesn't need to be much more than a waitqueue that the current task puts itself on if a suspend is in progress. Callers arriving at a time when the icebox isn't activated should simply return without blocking. Basically the icebox should be active at the same times as the existing freezer.
Hmm, I think this would be functionally equivalent to a modified freezer with the following changes:
(1) the actual freezing functionality is not hooked up to the signal code, but instead there are many invocations of try_to_freeze() all over the place,
(2) the freezer doesn't wait for tasks to freeze, only sets their TIF_FREEZE flags and exits, where TIF_FREEZE now means "there's a suspend in progress, please freeze yourself if need be".
BTW, this is similar to what I'd like to have for kernel threads RSN, except for the "doesn't wait" part.
IMO, something like this might be used for hibernation too, but in that case we need to do something about the tasks that haven't gone to the icebox.
I have some implementation-related questions:
* do we want each task to be notified individually or do we want a global variable, say "pm_entering_sleep_state", that will mean "now you're supposed to go to the icebox"
* at what point exactly this should be activated (ie. before the freezer or after it)
* how do we release tasks from the icebox (all at a time or individually, and if the latter then how exactly).
Quoted 22 lines
Quoted 9 lines
Quoted 2 lines
Of course, another possibility is simply to fail the bind. But that's not very satisfying, since suspends should be transparent.
I don't think suspend has to be -that- transparent (though there is some debate on whether it should be if we're gonna do some kind of fast "light" suspend for things like OLPC) but overall, I agree that a bind operation on sysfs should probably block until resume, and it does make sense to have the logic to do that in sysfs itself. It could perfectly use the above icebox thingy you came up with.
Here's a wacky idea which just might work:
In order to prevent binding and unbinding, while suspending devices all the PM core has to do is avoid dropping the device semaphores! It can release the semaphores as it resumes the devices.
Of course, for this to work it's necessary to avoid changes to the device list during the suspend. However I believe the iteration can be made safe against unregistration, so we only have to prevent device registration. (And anyway, it won't be possible to unregister a device while the PM core is holding its semaphore.)
Quoted 7 lines
If we are willing to be somewhat non-transparent, this is easy to accomplish. After the notifier chain has been alerted about the upcoming suspend, we tell the driver core to disallow adding new devices. Maybe use SRCU to synchronize with registration calls that are in progress. Thus, until the suspend is over
device_add()will immediately return an error. We could even add a new ESUSPENDING code toerrno.h; it would come in handy in a few places.
This last thing is a good idea, IMHO.
Quoted 11 lines
Drivers are already prepared for device registration to fail (or they ought to be), so this change shouldn't knock the bottom out of things.
device_add()isn't on a hot path, so adding an extra check andsrcu_read_lock()won't hurt.Quoted 5 lines
Regarding unbinding, that's debatable, it might be perfectly allright to unbind while suspended, though then, there is the question of a driver being later on bound to a piece of HW that is suspended (though I suppose that could happen today... some machines have their firmware leave some devices off at boot).
Quoted 4 lines
I have had the same thought, that unbinding and unregistration would be easier to handle than binding and registration. As it happens, holding the device semaphore will block both all three -- which makes life simpler.
I think we should do something like that in the beginning and probably try to add some flexibility later on.
Quoted 27 lines
Quoted 6 lines
As a general matter, If we have those pre-suspend/post-resume notifiers and we adapt the few (there isn't that much) bus drivers so that they stop all probe/unprobe operations before the suspend dance starts, we avoid a lot of that problem. At this point, it becomes fair enough for bind/unbind, in the core, to return an error (and maybe even stack trace in dmesg to catch the culprits) while suspend in in progress.
Putting a
WARN_ON()indevice_add()would be a good idea.Quoted 7 lines
Quoted 6 lines
But consider this: By writing the appropriate
sysfs attribute, a user task can cause a workqueue item to be queued to keventd that tries to unregister a device. That really puts you on the
spot: Unregistration can't be allowed to fail, it can't be allowed to succeed during a suspend, and keventd can't be blocked! So what should we do?Quoted 5 lines
We can either stop it at the sysfs write level, or we can have the workqueue task reschedule itself later until we are resumed. In fact, worqueue items being what they are (queue items), we could imagine having a special list where they enqueue themselves to rescheduled after resume.
There are other possibilities too. For example, instead of using keventd these attributes could use a separate workqueue which would put itself in the icebox during a suspend. Or maybe sysfs can be reworked so that they don't need to use a workqueue at all.
Quoted 8 lines
Quoted 3 lines
Don't get me wrong, I never said we don't need generic infrastructure and utilities, such as your proposed icebox scheme, or some of those workqueue bits, helpers in subsystems, etc...
I hope that everyone will agree that now is a good time to get started on them. There shouldn't be any problem about having them present along with the freezer, and then it will be all that much easier to remove the freezer later on if that's what we decide to do.
Agreed.
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Hi!
Quoted 5 lines
But in a whole lot of cases, it's, I beleive, perfectly kosher to just return an error. You're trying to capture frame from your camera while the machine is suspended ? error. At worst, your capture app will be unhappy when you wakeup, nothing terrible and totally fixable in userland if it's a problem.
Well, that way you'd have to teach applications about suspend... Which is quite bad. You mentioned it -- returning random errors will be very bad for machines like OLPC that want to suspend automatically. Plus it is a step back from current implementation, and ABI change, too...
Quoted 12 lines
Quoted 7 lines
So instead, why not have the PM core take care of all this? There could be a
block_task_until_suspend_is_over()routine available for all drivers to use. Its effect would be exactly the same as sending the current task into the freezer, but it wouldn't be the freezer that exists now. It would just be some routine that blocks until the system suspend is over. We could call it "the icebox" instead of "the freezer". :-)I'm not totally sure about that. I like some of it, but I think it's fairly different conceptually from the freezer (and the implementation could be as trivial as a single system wide wait queue).
Quoted 6 lines
Basically it has a very big difference to the current freezer, and I like that, which is that we don't have some 3rd party trying to find out what to freeze and what not (the freezer), but instead, we have explicitely drivers or kernel threads sending -themselves- to the "icebox" when they think it's a good idea. Think of it as lazy freezing
Kernel threads already send _themselves_ to the refrigerator. [Plus we put all the userland there, which is what you don't like, but kernel can not rely on userland after suspend starts, anyway, so it should not hurt].
Anyway.. PPC currently suspends without freezer, which puts rules on drivers. ("Must handle i/o requests after .suspend() method is ran, must not use GFP_KERNEL to do so, must not try to synchronously communicate with userspace before _all_ devices are unfrozen") I am not certain what the exact rules are, but you seem to know them. Could we get Doc*/power/suspend_wo_freezer.txt describing them for driver authors? That way we can make sure drivers work on ppc, too, and maybe get rid of freezer in the long run.
Quoted 7 lines
Quoted 2 lines
You also agree that kernel threads and workqueues must be allowed to operate during suspend.
Yes, unless kernel threads explicitely decide to stop themselves (for example, khubd is a good candidate for that). Again, not a 3rd party trying to decide what to freeze and what not, but the drivers or kernel threads themselves deciding it.
This is how it works currently in -mm.
(Plus, the rule is that threads that decide _not to_ stop themselves should not do any I/O.)
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Hi!
Quoted 5 lines
But in a whole lot of cases, it's, I beleive, perfectly kosher to just return an error. You're trying to capture frame from your camera while the machine is suspended ? error. At worst, your capture app will be unhappy when you wakeup, nothing terrible and totally fixable in userland if it's a problem.
Well, that way you'd have to teach applications about suspend... Which is quite bad. You mentioned it -- returning random errors will be very bad for machines like OLPC that want to suspend automatically. Plus it is a step back from current implementation, and ABI change, too...
Quoted 12 lines
Quoted 7 lines
So instead, why not have the PM core take care of all this? There could be a
block_task_until_suspend_is_over()routine available for all drivers to use. Its effect would be exactly the same as sending the current task into the freezer, but it wouldn't be the freezer that exists now. It would just be some routine that blocks until the system suspend is over. We could call it "the icebox" instead of "the freezer". :-)I'm not totally sure about that. I like some of it, but I think it's fairly different conceptually from the freezer (and the implementation could be as trivial as a single system wide wait queue).
Quoted 6 lines
Basically it has a very big difference to the current freezer, and I like that, which is that we don't have some 3rd party trying to find out what to freeze and what not (the freezer), but instead, we have explicitely drivers or kernel threads sending -themselves- to the "icebox" when they think it's a good idea. Think of it as lazy freezing
Kernel threads already send _themselves_ to the refrigerator. [Plus we put all the userland there, which is what you don't like, but kernel can not rely on userland after suspend starts, anyway, so it should not hurt].
Anyway.. PPC currently suspends without freezer, which puts rules on drivers. ("Must handle i/o requests after .suspend() method is ran, must not use GFP_KERNEL to do so, must not try to synchronously communicate with userspace before _all_ devices are unfrozen") I am not certain what the exact rules are, but you seem to know them. Could we get Doc*/power/suspend_wo_freezer.txt describing them for driver authors? That way we can make sure drivers work on ppc, too, and maybe get rid of freezer in the long run.
Quoted 7 lines
Quoted 2 lines
You also agree that kernel threads and workqueues must be allowed to operate during suspend.
Yes, unless kernel threads explicitely decide to stop themselves (for example, khubd is a good candidate for that). Again, not a 3rd party trying to decide what to freeze and what not, but the drivers or kernel threads themselves deciding it.
This is how it works currently in -mm.
(Plus, the rule is that threads that decide _not to_ stop themselves should not do any I/O.)
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 9 lines · Nigel Cunningham
Nice try :) Okay then, you remove the freezer, try hibernating, then get back to me after you've fixed your filesystem because some process that wasn't frozen started writing things after the atomic copy (making the on disk filesystem inconsistent with the snapshot).
As Pavel rightly said, you can get rid of the freezer, but you're only going to have to implement another one that does the essentially the same thing, even if it is at some other level.
I was mostly talking about STR... Regarding STD, we have a different problem and we all know it. The freezer is one somewhat horrible way to get it working for now, I would prefer something more along the way that blocks the page cache from writing out new dirty pages though, except those specifically flagged by the snapshot.
That is, some kind of proper snapshotting facility, as linus was describing some time ago.
Ben.
Quoted 47 lines
Quoted 30 lines
Quoted 7 lines
Quoted 5 lines
- Silently add
GFP_NOIOto all allocations, to avoid having things
blocking inkmalloc()with a mutex held that will deadlock withsuspend()in a driver for example. Or set some way to have all GFP waiters wakeup and fail rather than wait for IOs. It's hard/bizarre but necessary, again, with or without a freezer.
GFP_ATOMIC? (In driver suspend, they shouldn't be sleeping either, right?)NOIO should be enough I think but ATOMIC would do).
That's one of the reason why I used to have the pre-suspend and post-resume hooks in my original powermac implementation, for those few drivers complicated enough to require some pre-allocations.
Quoted 4 lines
Quoted 4 lines
- Deal with the firmware problem. The best way is probably to have an
asyncrequest_firmwareinterface(). Another thing is, drivers may want to cache their firmware in main memory, that sort of thing...Note that the above firmware problem could be dealt with also with the pre-suspend/post-resume. Allowing to pre-request firmware etc... and keep it around until after resume, because we know we will need it. Gives a chance to drivers to perform things while the system is still live, filesystems still working, etc... (big memory allocations for example).
Quoted 4 lines
Quoted 3 lines
And that's just a small list off the top of my mind, of known problems that will cause deadlocks or misbehaviours today, with or without the freezer, and that need to be addressed.
Quoted 5 lines
Quoted 1 line
Userspace device drivers too?
Maybe but they are less of an issue, most of the time, they don't do DMA or whatever harmful things. If they are USB drivers, for example, they are an non-issues at that level.
(Leaving the rest of the message intact so we don't have to fragment the discussion into a million subthreads).
Regards,
Nigel
Invalid signature
Quoted 9 lines · Nigel Cunningham
Nice try :) Okay then, you remove the freezer, try hibernating, then get back to me after you've fixed your filesystem because some process that wasn't frozen started writing things after the atomic copy (making the on disk filesystem inconsistent with the snapshot).
As Pavel rightly said, you can get rid of the freezer, but you're only going to have to implement another one that does the essentially the same thing, even if it is at some other level.
I was mostly talking about STR... Regarding STD, we have a different problem and we all know it. The freezer is one somewhat horrible way to get it working for now, I would prefer something more along the way that blocks the page cache from writing out new dirty pages though, except those specifically flagged by the snapshot.
That is, some kind of proper snapshotting facility, as linus was describing some time ago.
Ben.
Quoted 47 lines
Quoted 30 lines
Quoted 7 lines
Quoted 5 lines
- Silently add
GFP_NOIOto all allocations, to avoid having things
blocking inkmalloc()with a mutex held that will deadlock withsuspend()in a driver for example. Or set some way to have all GFP waiters wakeup and fail rather than wait for IOs. It's hard/bizarre but necessary, again, with or without a freezer.
GFP_ATOMIC? (In driver suspend, they shouldn't be sleeping either, right?)NOIO should be enough I think but ATOMIC would do).
That's one of the reason why I used to have the pre-suspend and post-resume hooks in my original powermac implementation, for those few drivers complicated enough to require some pre-allocations.
Quoted 4 lines
Quoted 4 lines
- Deal with the firmware problem. The best way is probably to have an
asyncrequest_firmwareinterface(). Another thing is, drivers may want to cache their firmware in main memory, that sort of thing...Note that the above firmware problem could be dealt with also with the pre-suspend/post-resume. Allowing to pre-request firmware etc... and keep it around until after resume, because we know we will need it. Gives a chance to drivers to perform things while the system is still live, filesystems still working, etc... (big memory allocations for example).
Quoted 4 lines
Quoted 3 lines
And that's just a small list off the top of my mind, of known problems that will cause deadlocks or misbehaviours today, with or without the freezer, and that need to be addressed.
Quoted 5 lines
Quoted 1 line
Userspace device drivers too?
Maybe but they are less of an issue, most of the time, they don't do DMA or whatever harmful things. If they are USB drivers, for example, they are an non-issues at that level.
(Leaving the rest of the message intact so we don't have to fragment the discussion into a million subthreads).
Regards,
Nigel
Invalid signature
Hi.
Quoted 3 lines · On Friday 06 July 2007 13:54:15 Benjamin Herrenschmidt wrote:
Quoted 2 lines · Nigel Cunningham
Nice try :) Okay then, you remove the freezer, try hibernating, then get
back
Quoted 5 lines
Quoted 5 lines
to me after you've fixed your filesystem because some process that wasn't frozen started writing things after the atomic copy (making the on disk filesystem inconsistent with the snapshot).
As Pavel rightly said, you can get rid of the freezer, but you're only
going
Quoted 11 lines
Quoted 2 lines
to have to implement another one that does the essentially the same thing, even if it is at some other level.
I was mostly talking about STR... Regarding STD, we have a different problem and we all know it. The freezer is one somewhat horrible way to get it working for now, I would prefer something more along the way that blocks the page cache from writing out new dirty pages though, except those specifically flagged by the snapshot.
That is, some kind of proper snapshotting facility, as linus was describing some time ago.
The kind of thing Linus was talking about would limit you (as swsusp and uswsusp do now) to only half the amount of memory. I suppose you could lzf compress as you did the snapshot. That would generally get you up to 2/3rds, but then again you can't know what compression ratio you'll get until you try, so reliability would suffer or it would take longer because of retrying.
I/O from swsusp and suspend2 use bios directly, so the page cache isn't an issue for them (apart from the fact that Suspend2 saves the page cache separately so it can get a full image). Not sure about uswsusp.
Only having half the amount of memory doesn't sound like a big limitation for modern desktops & laptops, but don't forget that there are embedded guys wanting to hbernate too :)
Regards,
Nigel
Signature · 5 lines
Nigel Cunningham Christian Reformed Church of Cobden 103 Curdie Street, Cobden 3266, Victoria, Australia Ph. +61 3 5595 1185 / +61 417 100 574 Communal Worship: 11 am Sunday.
Hi.
Quoted 3 lines · On Friday 06 July 2007 13:54:15 Benjamin Herrenschmidt wrote:
Quoted 2 lines · Nigel Cunningham
Nice try :) Okay then, you remove the freezer, try hibernating, then get
back
Quoted 5 lines
Quoted 5 lines
to me after you've fixed your filesystem because some process that wasn't frozen started writing things after the atomic copy (making the on disk filesystem inconsistent with the snapshot).
As Pavel rightly said, you can get rid of the freezer, but you're only
going
Quoted 11 lines
Quoted 2 lines
to have to implement another one that does the essentially the same thing, even if it is at some other level.
I was mostly talking about STR... Regarding STD, we have a different problem and we all know it. The freezer is one somewhat horrible way to get it working for now, I would prefer something more along the way that blocks the page cache from writing out new dirty pages though, except those specifically flagged by the snapshot.
That is, some kind of proper snapshotting facility, as linus was describing some time ago.
The kind of thing Linus was talking about would limit you (as swsusp and uswsusp do now) to only half the amount of memory. I suppose you could lzf compress as you did the snapshot. That would generally get you up to 2/3rds, but then again you can't know what compression ratio you'll get until you try, so reliability would suffer or it would take longer because of retrying.
I/O from swsusp and suspend2 use bios directly, so the page cache isn't an issue for them (apart from the fact that Suspend2 saves the page cache separately so it can get a full image). Not sure about uswsusp.
Only having half the amount of memory doesn't sound like a big limitation for modern desktops & laptops, but don't forget that there are embedded guys wanting to hbernate too :)
Regards,
Nigel
Signature · 5 lines
Nigel Cunningham Christian Reformed Church of Cobden 103 Curdie Street, Cobden 3266, Victoria, Australia Ph. +61 3 5595 1185 / +61 417 100 574 Communal Worship: 11 am Sunday.
Quoted 8 lines
I/O from swsusp and suspend2 use bios directly, so the page cache isn't an issue for them (apart from the fact that Suspend2 saves the page cache separately so it can get a full image). Not sure about uswsusp.
Only having half the amount of memory doesn't sound like a big limitation for modern desktops & laptops, but don't forget that there are embedded guys wanting to hbernate too :)
Wait wait wait ... uses the BIOS ? what do you mean ?
I know that for example, things like MacOS X use a separate polled path to the storage driver for suspend (works fine for the built-in IDE, but more complicated in large scale). If you can use BIOS calls to write your suspend image, that is, if you don't need any of the normal block infrastructure, then you don't need a freezer ! not at all !
You just do like STR ... and at the end of the day, once you have stopped all your driver, you shut interrupts off and do the BIOS thing....
I fail to see how processes could dirty pages while/after the BIOS thingy :-)
But then, the problem with that approach is that of course, you need a BIOS capable of doing that (or a special sideband path to the "blessed" block driver that will be used for suspend ... not necessarily a hard thing to do, would be trivial to add support to drivers/ide or libata for that sort of things I suppose).
Ben.
Hi.
Quoted 6 lines · On Friday 06 July 2007 14:41:40 Benjamin Herrenschmidt wrote:
Quoted 6 lines
I/O from swsusp and suspend2 use bios directly, so the page cache isn't an issue for them (apart from the fact that Suspend2 saves the page cache separately so it can get a full image). Not sure about uswsusp.
Only having half the amount of memory doesn't sound like a big limitation
for
Quoted 4 lines
Quoted 2 lines
modern desktops & laptops, but don't forget that there are embedded guys wanting to hbernate too :)
Wait wait wait ... uses the BIOS ? what do you mean ?
You misread me, Ben. Sorry for not being clearer. bios as in struct bio.
Regards,
Nigel
Signature · 2 lines
See http://www.tuxonice.net for Howtos, FAQs, mailing lists, wiki and bugzilla info.
Hi.
Quoted 6 lines · On Friday 06 July 2007 14:41:40 Benjamin Herrenschmidt wrote:
Quoted 6 lines
I/O from swsusp and suspend2 use bios directly, so the page cache isn't an issue for them (apart from the fact that Suspend2 saves the page cache separately so it can get a full image). Not sure about uswsusp.
Only having half the amount of memory doesn't sound like a big limitation
for
Quoted 4 lines
Quoted 2 lines
modern desktops & laptops, but don't forget that there are embedded guys wanting to hbernate too :)
Wait wait wait ... uses the BIOS ? what do you mean ?
You misread me, Ben. Sorry for not being clearer. bios as in struct bio.
Regards,
Nigel
Signature · 2 lines
See http://www.tuxonice.net for Howtos, FAQs, mailing lists, wiki and bugzilla info.
Quoted 5 lines · Nigel Cunningham
Quoted 4 lines · On Friday 06 July 2007 13:54:15 Benjamin Herrenschmidt wrote:
Quoted 3 lines · Nigel Cunningham
Nice try :) Okay then, you remove the freezer, try hibernating, then get back to me after you've fixed your filesystem because some process that wasn't frozen started writing things after the atomic copy (making the on disk filesystem inconsistent with the snapshot).
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
As Pavel rightly said, you can get rid of the freezer, but you're only going to have to implement another one that does the essentially the same thing, even if it is at some other level.
I was mostly talking about STR... Regarding STD, we have a different problem and we all know it. The freezer is one somewhat horrible way to get it working for now, I would prefer something more along the way that blocks the page cache from writing out new dirty pages though, except those specifically flagged by the snapshot.
That is, some kind of proper snapshotting facility, as linus was describing some time ago.
The kind of thing Linus was talking about would limit you (as swsusp and uswsusp do now) to only half the amount of memory.
How so? Suppose hibernate is implemented like this:
(1) Userspace program calls sys_freeze_processes()
(a) Pokes all CPUs with IPMIs and tells them to finish the
currently running timeslot then stop
(b) Atomically sends SIGSTOP to all userspace processes in a non-
trappable way, except the calling process and any process which is ptracing it.
(c) Returns to the calling process.
(2) Userspace process sends SIGCONT to only those processes which are necessary for sync and a device-mapper snapshot.
(3) Userspace calls sys_snapshot_kernel(snapshot_overhead_pages)
(a) Kernel starts freeing memory and swapping stuff out to make
room for a copy of *kernel* memory (not pagecache, not process RAM). It does the same for at least snapshot_overhead_pages extra (used by userspace later). It then allocates this memory to keep it from going away. Since most processes are stopped we won't have much else competing with us for the RAM.
(a) Kernel uses the device-mapper up-call-into-filesystem
machinery to get all mounted filesystems synced and ready for a DM snapshot. This may include sending data via the userspace processes resumed in (2). Any deadlocks here are userspace's fault (see (2)). Will need some modification to handle doing multiple blockdevs at a time. Anything using FUSE is basically perma-synced anyways (no dep-handling needed), and anything using loop should already be handled by DM. This includes allocating memory for the basic snapshot datastructures.
(b) At this point all blockdev operations should be halted and
disk caches flushed; that's all we care about.
(c) Go through the device tree and quiesce DMA and shut off
interrupts. Since all the disks are synced this is easy.
(d) Use IPMIs again to get all the CPUs together, which should be
easy as most processes are sleeping in IO or SIGSTOPed, and we're getting no interrupts.
(e) One CPU turns off all interrupts on itself and takes an atomic
snapshot of kernel memory into the previously allocated storage. Once again, does not include pagecache. The kernel also records a list of what pages *are* included in the pagecache. It then marks all userspace pages as copy-on-write.
(f) That CPU finalizes the modified DM snapshot using the
previously-allocated memory.
(g) That CPU frees up the snapshot_overhead_pages memory allocated
during step (a) for userspace to use.
(h) The CPU does the equivalent of a "swapoff -a" without
overwriting any data already on any swap device(s).
(i) The CPU then IPMI-signals the other CPUs to wake them up
(j) The kernel returns a FD-reference to the snapshot and the read-
only halves of the CoW pagecache to the process which called sys_snapshot_kernel().
(4) The userspace process now has a reference to the copy of the kernel pages and the unmodified pagecache pages. Since 99% of the processes aren't running, we aren't going to be having to CoW many of the pagecache pages.
(5) The userspace process uses read() or other syscalls to get data out of the kernel-snapshot FD in small chunks, within its snapshot_overhead_pages limit. It compresses these and writes them out to the snapshot-storage blockdev (must not be mounted during snapshot), or to any network server.
(6) The userspace process syncs the disks and halts the system. Any changed filesystem pages after the pseudo-DM-snapshot should have been stored in semi-volatile storage somewhere and will be discarded on the next reboot.
So basically your hibernate-overhead would consist of:
(1) The pages necessary for the atomic snapshot of kernel memory
and the list of pagecache pages at that time
(2) A little memory necessary for the kernel non-persistent DM
snapshot datastructures.
(3) The snapshot_overhead_pages needed by userspace.
If you're using swap devices then you can save 99% of the state of the running kernel with an initial swapout overhead of virtually nothing beyond the size of the unswappable kernel memory.
Cheers,
Kyle Moffett
Quoted 5 lines · Nigel Cunningham
Quoted 4 lines · On Friday 06 July 2007 13:54:15 Benjamin Herrenschmidt wrote:
Quoted 3 lines · Nigel Cunningham
Nice try :) Okay then, you remove the freezer, try hibernating, then get back to me after you've fixed your filesystem because some process that wasn't frozen started writing things after the atomic copy (making the on disk filesystem inconsistent with the snapshot).
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
As Pavel rightly said, you can get rid of the freezer, but you're only going to have to implement another one that does the essentially the same thing, even if it is at some other level.
I was mostly talking about STR... Regarding STD, we have a different problem and we all know it. The freezer is one somewhat horrible way to get it working for now, I would prefer something more along the way that blocks the page cache from writing out new dirty pages though, except those specifically flagged by the snapshot.
That is, some kind of proper snapshotting facility, as linus was describing some time ago.
The kind of thing Linus was talking about would limit you (as swsusp and uswsusp do now) to only half the amount of memory.
How so? Suppose hibernate is implemented like this:
(1) Userspace program calls sys_freeze_processes()
(a) Pokes all CPUs with IPMIs and tells them to finish the
currently running timeslot then stop
(b) Atomically sends SIGSTOP to all userspace processes in a non-
trappable way, except the calling process and any process which is ptracing it.
(c) Returns to the calling process.
(2) Userspace process sends SIGCONT to only those processes which are necessary for sync and a device-mapper snapshot.
(3) Userspace calls sys_snapshot_kernel(snapshot_overhead_pages)
(a) Kernel starts freeing memory and swapping stuff out to make
room for a copy of *kernel* memory (not pagecache, not process RAM). It does the same for at least snapshot_overhead_pages extra (used by userspace later). It then allocates this memory to keep it from going away. Since most processes are stopped we won't have much else competing with us for the RAM.
(a) Kernel uses the device-mapper up-call-into-filesystem
machinery to get all mounted filesystems synced and ready for a DM snapshot. This may include sending data via the userspace processes resumed in (2). Any deadlocks here are userspace's fault (see (2)). Will need some modification to handle doing multiple blockdevs at a time. Anything using FUSE is basically perma-synced anyways (no dep-handling needed), and anything using loop should already be handled by DM. This includes allocating memory for the basic snapshot datastructures.
(b) At this point all blockdev operations should be halted and
disk caches flushed; that's all we care about.
(c) Go through the device tree and quiesce DMA and shut off
interrupts. Since all the disks are synced this is easy.
(d) Use IPMIs again to get all the CPUs together, which should be
easy as most processes are sleeping in IO or SIGSTOPed, and we're getting no interrupts.
(e) One CPU turns off all interrupts on itself and takes an atomic
snapshot of kernel memory into the previously allocated storage. Once again, does not include pagecache. The kernel also records a list of what pages *are* included in the pagecache. It then marks all userspace pages as copy-on-write.
(f) That CPU finalizes the modified DM snapshot using the
previously-allocated memory.
(g) That CPU frees up the snapshot_overhead_pages memory allocated
during step (a) for userspace to use.
(h) The CPU does the equivalent of a "swapoff -a" without
overwriting any data already on any swap device(s).
(i) The CPU then IPMI-signals the other CPUs to wake them up
(j) The kernel returns a FD-reference to the snapshot and the read-
only halves of the CoW pagecache to the process which called sys_snapshot_kernel().
(4) The userspace process now has a reference to the copy of the kernel pages and the unmodified pagecache pages. Since 99% of the processes aren't running, we aren't going to be having to CoW many of the pagecache pages.
(5) The userspace process uses read() or other syscalls to get data out of the kernel-snapshot FD in small chunks, within its snapshot_overhead_pages limit. It compresses these and writes them out to the snapshot-storage blockdev (must not be mounted during snapshot), or to any network server.
(6) The userspace process syncs the disks and halts the system. Any changed filesystem pages after the pseudo-DM-snapshot should have been stored in semi-volatile storage somewhere and will be discarded on the next reboot.
So basically your hibernate-overhead would consist of:
(1) The pages necessary for the atomic snapshot of kernel memory
and the list of pagecache pages at that time
(2) A little memory necessary for the kernel non-persistent DM
snapshot datastructures.
(3) The snapshot_overhead_pages needed by userspace.
If you're using swap devices then you can save 99% of the state of the running kernel with an initial swapout overhead of virtually nothing beyond the size of the unswappable kernel memory.
Cheers,
Kyle Moffett
Hi Kyle.
Quoted 5 lines · On Friday 06 July 2007 15:01:48 Kyle Moffett wrote:
Quoted 2 lines · Nigel Cunningham
The kind of thing Linus was talking about would limit you (as swsusp and uswsusp do now) to only half the amount of memory.
How so? Suppose hibernate is implemented like this:
You're not talking about the same thing Linus was suggesting. He was just wanting a result = sys_snapshot() sort of call. That would limit us to half the amount of memory.
I've looked over what you've written below and want to consider it in detail. Right now though, I don't have the time. I'll try to get back to you promptly.
Nigel
Signature · 2 lines
See http://www.tuxonice.net for Howtos, FAQs, mailing lists, wiki and bugzilla info.
Hi Kyle.
Quoted 5 lines · On Friday 06 July 2007 15:01:48 Kyle Moffett wrote:
Quoted 2 lines · Nigel Cunningham
The kind of thing Linus was talking about would limit you (as swsusp and uswsusp do now) to only half the amount of memory.
How so? Suppose hibernate is implemented like this:
You're not talking about the same thing Linus was suggesting. He was just wanting a result = sys_snapshot() sort of call. That would limit us to half the amount of memory.
I've looked over what you've written below and want to consider it in detail. Right now though, I don't have the time. I'll try to get back to you promptly.
Nigel
Signature · 2 lines
See http://www.tuxonice.net for Howtos, FAQs, mailing lists, wiki and bugzilla info.
Hi.
Sorry for the long delay. Busy weekend and my motivation for working on programming is almost zero at the moment...
Quoted 29 lines · On Friday 06 July 2007 15:01:48 Kyle Moffett wrote:
Quoted 20 lines · Nigel Cunningham
Quoted 19 lines · On Friday 06 July 2007 13:54:15 Benjamin Herrenschmidt wrote:
Quoted 10 lines · Nigel Cunningham
Nice try :) Okay then, you remove the freezer, try hibernating, then get back to me after you've fixed your filesystem because some process that wasn't frozen started writing things after the atomic copy (making the on disk filesystem inconsistent with the snapshot).
As Pavel rightly said, you can get rid of the freezer, but you're only going to have to implement another one that does the essentially the same thing, even if it is at some other level.
I was mostly talking about STR... Regarding STD, we have a different problem and we all know it. The freezer is one somewhat horrible way to get it working for now, I would prefer something more along the way that blocks the page cache from writing out new dirty pages though, except those specifically flagged by the snapshot.
Quoted 5 lines
Quoted 2 lines
That is, some kind of proper snapshotting facility, as linus was describing some time ago.
The kind of thing Linus was talking about would limit you (as swsusp and uswsusp do now) to only half the amount of memory.
How so? Suppose hibernate is implemented like this:
Quoted 7 lines
(1) Userspace program calls
sys_freeze_processes()
(a) Pokes all CPUs with IPMIs and tells them to finish the
currently running timeslot then stop
(b) Atomically sends SIGSTOP to all userspace processes in a non-
trappable way, except the calling process and any process which is ptracing it.
(c) Returns to the calling process.
Ok. First, I'll ignore the specification that userspace does this - I don't think it matters whether it's userspace or kernel that does the suspending and I'm yet to see a good reason for it to be [required to be] done from userspace.
In this first step, you've reinvented the first part of the current freezer implementation. The reason we don't use a real signal is precisely so we can have an untrappable SIGSTOP. In this regard, I particularly remember Win4Lin from a few years ago. It would die if you sent it a real signal, so we had to do it this way. No doubt there are other instances I'm not aware of.
Quoted 2 lines
(2) Userspace process sends SIGCONT to only those processes which are necessary for sync and a device-mapper snapshot.
How do you determine which ones are needed? Why stop them in the first place?
Quoted 7 lines
(3) Userspace calls
sys_snapshot_kernel(snapshot_overhead_pages)
(a) Kernel starts freeing memory and swapping stuff out to make
room for a copy of *kernel* memory (not pagecache, not process RAM). It does the same for at leastsnapshot_overhead_pagesextra (used by userspace later). It then allocates this memory to keep it from going away. Since most processes are stopped we won't have much else competing with us for the RAM.
Ok. So now you also need processes running that are needed for swapping, because freeing that memory might involve swapping. Fully agree with the logic though (not really surprising - this is what I do in Suspend2^wTuxOnIce).
Quoted 13 lines
(a) Kernel uses the device-mapper up-call-into-filesystem
machinery to get all mounted filesystems synced and ready for a DM snapshot. This may include sending data via the userspace processes resumed in (2). Any deadlocks here are userspace's fault (see (2)). Will need some modification to handle doing multiple blockdevs at a time. Anything using FUSE is basically perma-synced anyways (no dep- handling needed), and anything using loop should already be handled by DM. This includes allocating memory for the basic snapshot datastructures.
(b) At this point all blockdev operations should be halted and
disk caches flushed; that's all we care about.
(c) Go through the device tree and quiesce DMA and shut off
interrupts. Since all the disks are synced this is easy.
Quoted 8 lines
(d) Use IPMIs again to get all the CPUs together, which should be
easy as most processes are sleeping in IO or SIGSTOPed, and we're getting no interrupts.
(e) One CPU turns off all interrupts on itself and takes an atomic
snapshot of kernel memory into the previously allocated storage. Once again, does not include pagecache. The kernel also records a list of what pages *are* included in the pagecache. It then marks all userspace pages as copy-on-write.
Hotplugging cpus (when all those locking issues are taken care of) is simpler. Prior to cpu hotplugging, I used IMPIs to put secondary cpus into a tight loop, so I know it's possible to do it this way too. That way, though, you have less flexibility. What if a cpu really is plugged in between hibernate and resume? With cpu hotplugging, it's handled properly and transparently. Without cpu hotplugging, you could be using uninitialised data after the atomic restore.
Marking userspace as COW makes things more complicated, too. You then have to add code to the COW handling to update the list of pages that need to be saved, and you reduce the reliability of the whole process. You can't predict beforehand how many of these COW pages are going to be needed, and therefore can't know how much memory to free earlier on in the process. If you run out of memory, what will be the effect?
Quoted 6 lines
(f) That CPU finalizes the modified DM snapshot using the
previously-allocated memory.
(g) That CPU frees up thesnapshot_overhead_pagesmemory allocated
during step (a) for userspace to use.
(h) The CPU does the equivalent of a "swapoff -a" without
overwriting any data already on any swap device(s).
You still need to remember what swap you're going to use to write the image. You'll probably want to get this information (and allocate the swap) sooner rather than later so that you're not racing against the memory freeing earlier, and don't run into issues with bmapping the pages or having enough memory to record the bdevs & sector numbers (not usually an issue, but if swap is highly fragmented...).
Quoted 4 lines
(i) The CPU then IPMI-signals the other CPUs to wake them up
(j) The kernel returns a FD-reference to the snapshot and the read-
only halves of the CoW pagecache to the process which calledsys_snapshot_kernel().
Readonly halves? I don't get that, sorry.
Quoted 4 lines
(4) The userspace process now has a reference to the copy of the kernel pages and the unmodified pagecache pages. Since 99% of the processes aren't running, we aren't going to be having to CoW many of the pagecache pages.
Mmm, but you still don't know how many.
Quoted 10 lines
(5) The userspace process uses
read()or other syscalls to get data out of the kernel-snapshot FD in small chunks, within itssnapshot_overhead_pageslimit. It compresses these and writes them out to the snapshot-storage blockdev (must not be mounted during snapshot), or to any network server.(6) The userspace process syncs the disks and halts the system. Any changed filesystem pages after the pseudo-DM-snapshot should have been stored in semi-volatile storage somewhere and will be discarded on the next reboot.
Are you thinking the changed filesystem pages are caught by COW? (AFAIUI, kernel writes aren't). If (as I expect), you're thinking about filesystem writes to DM based storage, what about non DM-based filesystem pages?
Quoted 10 lines
So basically your hibernate-overhead would consist of:
(1) The pages necessary for the atomic snapshot of kernel memory
and the list of pagecache pages at that time
(2) A little memory necessary for the kernel non-persistent DM
snapshot datastructures.
(3) Thesnapshot_overhead_pagesneeded by userspace.If you're using swap devices then you can save 99% of the state of the running kernel with an initial swapout overhead of virtually nothing beyond the size of the unswappable kernel memory.
FWIW, let me note an important variation from how Suspend2 works; it might provide food for thought. In Suspend2, we treat the processes that remain stopped throughout the whole process specially. We write their data to disk before the atomic copy (usually 70 or 80% of memory), and then use the memory they occupy for the destination of the atomic copy. This further reduces the amount of memory that has to be freed, almost always to zero.
Regards,
Nigel
Signature · 2 lines
See http://www.tuxonice.net for Howtos, FAQs, mailing lists, wiki and bugzilla info.
Hi.
Sorry for the long delay. Busy weekend and my motivation for working on programming is almost zero at the moment...
Quoted 29 lines · On Friday 06 July 2007 15:01:48 Kyle Moffett wrote:
Quoted 20 lines · Nigel Cunningham
Quoted 19 lines · On Friday 06 July 2007 13:54:15 Benjamin Herrenschmidt wrote:
Quoted 10 lines · Nigel Cunningham
Nice try :) Okay then, you remove the freezer, try hibernating, then get back to me after you've fixed your filesystem because some process that wasn't frozen started writing things after the atomic copy (making the on disk filesystem inconsistent with the snapshot).
As Pavel rightly said, you can get rid of the freezer, but you're only going to have to implement another one that does the essentially the same thing, even if it is at some other level.
I was mostly talking about STR... Regarding STD, we have a different problem and we all know it. The freezer is one somewhat horrible way to get it working for now, I would prefer something more along the way that blocks the page cache from writing out new dirty pages though, except those specifically flagged by the snapshot.
Quoted 5 lines
Quoted 2 lines
That is, some kind of proper snapshotting facility, as linus was describing some time ago.
The kind of thing Linus was talking about would limit you (as swsusp and uswsusp do now) to only half the amount of memory.
How so? Suppose hibernate is implemented like this:
Quoted 7 lines
(1) Userspace program calls
sys_freeze_processes()
(a) Pokes all CPUs with IPMIs and tells them to finish the
currently running timeslot then stop
(b) Atomically sends SIGSTOP to all userspace processes in a non-
trappable way, except the calling process and any process which is ptracing it.
(c) Returns to the calling process.
Ok. First, I'll ignore the specification that userspace does this - I don't think it matters whether it's userspace or kernel that does the suspending and I'm yet to see a good reason for it to be [required to be] done from userspace.
In this first step, you've reinvented the first part of the current freezer implementation. The reason we don't use a real signal is precisely so we can have an untrappable SIGSTOP. In this regard, I particularly remember Win4Lin from a few years ago. It would die if you sent it a real signal, so we had to do it this way. No doubt there are other instances I'm not aware of.
Quoted 2 lines
(2) Userspace process sends SIGCONT to only those processes which are necessary for sync and a device-mapper snapshot.
How do you determine which ones are needed? Why stop them in the first place?
Quoted 7 lines
(3) Userspace calls
sys_snapshot_kernel(snapshot_overhead_pages)
(a) Kernel starts freeing memory and swapping stuff out to make
room for a copy of *kernel* memory (not pagecache, not process RAM). It does the same for at leastsnapshot_overhead_pagesextra (used by userspace later). It then allocates this memory to keep it from going away. Since most processes are stopped we won't have much else competing with us for the RAM.
Ok. So now you also need processes running that are needed for swapping, because freeing that memory might involve swapping. Fully agree with the logic though (not really surprising - this is what I do in Suspend2^wTuxOnIce).
Quoted 13 lines
(a) Kernel uses the device-mapper up-call-into-filesystem
machinery to get all mounted filesystems synced and ready for a DM snapshot. This may include sending data via the userspace processes resumed in (2). Any deadlocks here are userspace's fault (see (2)). Will need some modification to handle doing multiple blockdevs at a time. Anything using FUSE is basically perma-synced anyways (no dep- handling needed), and anything using loop should already be handled by DM. This includes allocating memory for the basic snapshot datastructures.
(b) At this point all blockdev operations should be halted and
disk caches flushed; that's all we care about.
(c) Go through the device tree and quiesce DMA and shut off
interrupts. Since all the disks are synced this is easy.
Quoted 8 lines
(d) Use IPMIs again to get all the CPUs together, which should be
easy as most processes are sleeping in IO or SIGSTOPed, and we're getting no interrupts.
(e) One CPU turns off all interrupts on itself and takes an atomic
snapshot of kernel memory into the previously allocated storage. Once again, does not include pagecache. The kernel also records a list of what pages *are* included in the pagecache. It then marks all userspace pages as copy-on-write.
Hotplugging cpus (when all those locking issues are taken care of) is simpler. Prior to cpu hotplugging, I used IMPIs to put secondary cpus into a tight loop, so I know it's possible to do it this way too. That way, though, you have less flexibility. What if a cpu really is plugged in between hibernate and resume? With cpu hotplugging, it's handled properly and transparently. Without cpu hotplugging, you could be using uninitialised data after the atomic restore.
Marking userspace as COW makes things more complicated, too. You then have to add code to the COW handling to update the list of pages that need to be saved, and you reduce the reliability of the whole process. You can't predict beforehand how many of these COW pages are going to be needed, and therefore can't know how much memory to free earlier on in the process. If you run out of memory, what will be the effect?
Quoted 6 lines
(f) That CPU finalizes the modified DM snapshot using the
previously-allocated memory.
(g) That CPU frees up thesnapshot_overhead_pagesmemory allocated
during step (a) for userspace to use.
(h) The CPU does the equivalent of a "swapoff -a" without
overwriting any data already on any swap device(s).
You still need to remember what swap you're going to use to write the image. You'll probably want to get this information (and allocate the swap) sooner rather than later so that you're not racing against the memory freeing earlier, and don't run into issues with bmapping the pages or having enough memory to record the bdevs & sector numbers (not usually an issue, but if swap is highly fragmented...).
Quoted 4 lines
(i) The CPU then IPMI-signals the other CPUs to wake them up
(j) The kernel returns a FD-reference to the snapshot and the read-
only halves of the CoW pagecache to the process which calledsys_snapshot_kernel().
Readonly halves? I don't get that, sorry.
Quoted 4 lines
(4) The userspace process now has a reference to the copy of the kernel pages and the unmodified pagecache pages. Since 99% of the processes aren't running, we aren't going to be having to CoW many of the pagecache pages.
Mmm, but you still don't know how many.
Quoted 10 lines
(5) The userspace process uses
read()or other syscalls to get data out of the kernel-snapshot FD in small chunks, within itssnapshot_overhead_pageslimit. It compresses these and writes them out to the snapshot-storage blockdev (must not be mounted during snapshot), or to any network server.(6) The userspace process syncs the disks and halts the system. Any changed filesystem pages after the pseudo-DM-snapshot should have been stored in semi-volatile storage somewhere and will be discarded on the next reboot.
Are you thinking the changed filesystem pages are caught by COW? (AFAIUI, kernel writes aren't). If (as I expect), you're thinking about filesystem writes to DM based storage, what about non DM-based filesystem pages?
Quoted 10 lines
So basically your hibernate-overhead would consist of:
(1) The pages necessary for the atomic snapshot of kernel memory
and the list of pagecache pages at that time
(2) A little memory necessary for the kernel non-persistent DM
snapshot datastructures.
(3) Thesnapshot_overhead_pagesneeded by userspace.If you're using swap devices then you can save 99% of the state of the running kernel with an initial swapout overhead of virtually nothing beyond the size of the unswappable kernel memory.
FWIW, let me note an important variation from how Suspend2 works; it might provide food for thought. In Suspend2, we treat the processes that remain stopped throughout the whole process specially. We write their data to disk before the atomic copy (usually 70 or 80% of memory), and then use the memory they occupy for the destination of the atomic copy. This further reduces the amount of memory that has to be freed, almost always to zero.
Regards,
Nigel
Signature · 2 lines
See http://www.tuxonice.net for Howtos, FAQs, mailing lists, wiki and bugzilla info.
Thanks for the detailed reply!
Quoted 11 lines · Nigel Cunningham
Quoted 8 lines · On Friday 06 July 2007 15:01:48 Kyle Moffett wrote:
Suppose hibernate is implemented like this:
(1) Userspace program calls
sys_freeze_processes()
(a) Pokes all CPUs with IPMIs and tells them to finish the
currently running timeslot then stop
(b) Atomically sends SIGSTOP to all userspace processes in a
non-trappable way, except the calling process and any process which is ptracing it.
(c) Returns to the calling process.Ok. First, I'll ignore the specification that userspace does this - I don't think it matters whether it's userspace or kernel that does the suspending and I'm yet to see a good reason for it to be [required to be] done from userspace.
The reason it's _required_ to be done from userspace is that userspace is the only one which can figure out "These processes need to run for suspend to work", and then let those processes continue running after the freeze. The *ONLY* reason this even stops processes at all is so we can do the post-device-mapper-snapshot code with very little usably-free RAM (IE: only about 1MB for a standard desktop system).
Quoted 1 line
In this first step, you've reinvented the first part of the current freezer implementation. The reason we don't use a real signal is precisely so we can have an untrappable SIGSTOP. In this regard, I particularly remember Win4Lin from a few years ago. It would die if you sent it a real signal, so we had to do it this way. No doubt there are other instances I'm not aware of.
Well, you *do* want it to have semi-signal semantics, processes which receive it must not get back to userspace code so that they don't start allocating more memory when we're trying to do the freeze. You also don't want a process to be able to trap it (IE: like SIGSTOP or SIGKILL).
On the other hand, it should be delivered asynchronously (IE: It doesn't break an interruptable sleep or respond to most is-a-signal-present checks). You don't actually care if its sleeping in the kernel somewhere, just as long as it doesn't allocate much memory.
You would probably need a new signal "SIGFREEZE" which causes the process to be ignored as runnable the next time they schedule but never actually gets delivered, and a "SIGUNFREEZE" which does the reverse. That way userspace could selectively resume processes based on its policy of "this needs to run for hibernation".
Quoted 3 lines
Quoted 1 line
(2) Userspace process sends SIGCONT to only those processes which are necessary for sync and a device-mapper snapshot.
How do you determine which ones are needed?
It's userspace's job to know which ones are needed. For example, if you are hibernating over NFS then you need to resume the various NFS/RPC daemons and threads.
Quoted 1 line
Why stop them in the first place?
So they aren't allocating memory when we are doing the device-mapper snapshot.
Quoted 18 lines
Quoted 3 lines
(3) Userspace calls
sys_snapshot_kernel(snapshot_overhead_pages)
(a) Kernel starts freeing memory and swapping stuff out to make
room for a copy of *kernel* memory (not pagecache, not process RAM). It does the same for at leastsnapshot_overhead_pagesextra (used by userspace later). It then allocates this memory to keep it from going away. Since most processes are stopped we won't have much else competing with us for the RAM.Ok. So now you also need processes running that are needed for swapping, because freeing that memory might involve swapping. Fully agree with the logic though (not really surprising - this is what I do in Suspend2^wTuxOnIce).
Quoted 11 lines
(a) Kernel uses the device-mapper up-call-into-filesystem
machinery to get all mounted filesystems synced and ready for a DM snapshot. This may include sending data via the userspace processes resumed in (2). Any deadlocks here are userspace's fault (see (2)). Will need some modification to handle doing multiple blockdevs at a time. Anything using FUSE is basically perma-synced anyways (no dep-handling needed), and anything using loop should already be handled by DM. This includes allocating memory for the basic snapshot datastructures.
(b) At this point all blockdev operations should be halted and
disk caches flushed; that's all we care about.
(c) Go through the device tree and quiesce DMA and shut off
interrupts. Since all the disks are synced this is easy.
(d) Use IPMIs again to get all the CPUs together, which should
be easy as most processes are sleeping in IO or SIGSTOPed, and we're getting no interrupts.
(e) One CPU turns off all interrupts on itself and takes an
atomic snapshot of kernel memory into the previously allocated storage. Once again, does not include pagecache. The kernel also records a list of what pages *are* included in the pagecache. It then marks all userspace pages as copy-on-write.
Quoted 1 line
Hotplugging cpus (when all those locking issues are taken care of) is simpler. Prior to cpu hotplugging, I used IMPIs to put secondary cpus into a tight loop, so I know it's possible to do it this way too.
It may be simpler, but it really screws up things like cpusets, processor affinity, etc. It also ties hibernation to the presently very-flakey CPU-hotplug support, which is probably not what we want.
Quoted 1 line
That way, though, you have less flexibility. What if a cpu really is plugged in between hibernate and resume? With cpu hotplugging, it's handled properly and transparently. Without cpu hotplugging, you could be using uninitialised data after the atomic restore.
IMHO if the user pulls a CPU while the box is hibernated, then he/she gets what he/she deserves. If you really want to support that, then the user must do the hotplug operation *manually* before suspending. Anything else is just going to be shooting ourselves in the foot repeatedly.
Quoted 1 line
Marking userspace as COW makes things more complicated, too. You then have to add code to the COW handling to update the list of pages that need to be saved, and you reduce the reliability of the whole process. You can't predict beforehand how many of these COW pages are going to be needed, and therefore can't know how much memory to free earlier on in the process. If you run out of memory, what will be the effect?
You could pretty easily have a spare 128MB swap partition somewhere which is not used during system operation but is "swapon"ed by userspace after the COW snapshot to provide extra backing store.
Quoted 8 lines
Quoted 6 lines
(f) That CPU finalizes the modified DM snapshot using the
previously-allocated memory.
(g) That CPU frees up thesnapshot_overhead_pagesmemory
allocated during step (a) for userspace to use.
(h) The CPU does the equivalent of a "swapoff -a" without
overwriting any data already on any swap device(s).You still need to remember what swap you're going to use to write the image. You'll probably want to get this information (and allocate the swap) sooner rather than later so that you're not racing against the memory freeing earlier, and don't run into issues with bmapping the pages or having enough memory to record the bdevs & sector numbers (not usually an issue, but if swap is highly fragmented...).
Who says we have to use this swap to write the image? That may be the default use-case, but it's certainly shouldn't be mandatory. Really, for the write-image-to-swap case you would just need to preallocate sufficient memory for the bmap tables beforehand, then populate them at this phase.
Quoted 5 lines
Quoted 3 lines
(i) The CPU then IPMI-signals the other CPUs to wake them up
(j) The kernel returns a FD-reference to the snapshot and the
read-only halves of the CoW pagecache to the process which calledsys_snapshot_kernel().Readonly halves? I don't get that, sorry.
Well, each page is copy-on-write, so the FD reference would always provide access to the original page data, whereas the processes may end up copying the page so they can write to it. The trick would be that shared pages need to remain shared between processes even after the copy-on-write. This is likely to be the trickiest part.
Quoted 3 lines
Quoted 1 line
(4) The userspace process now has a reference to the copy of the kernel pages and the unmodified pagecache pages. Since 99% of the processes aren't running, we aren't going to be having to CoW many of the pagecache pages.
Mmm, but you still don't know how many.
Yes, but at this point we're basically running a segment of userspace with full kernel services available. Like I said above we can just add a dedicated 128MB swap device to provide some spare backing store. When you start running low on memory it might even page out to the swap device a part of the atomic copy of kernel memory.
Quoted 5 lines
Quoted 3 lines
(5) The userspace process uses
read()or other syscalls to get data out of the kernel-snapshot FD in small chunks, within itssnapshot_overhead_pageslimit. It compresses these and writes them out to the snapshot-storage blockdev (must not be mounted during snapshot), or to any network server.(6) The userspace process syncs the disks and halts the system. Any changed filesystem pages after the pseudo-DM-snapshot should have been stored in semi-volatile storage somewhere and will be discarded on the next reboot.
Are you thinking the changed filesystem pages are caught by COW? (AFAIUI, kernel writes aren't). If (as I expect), you're thinking about filesystem writes to DM based storage, what about non DM-based filesystem pages?
No, but a kernel write to a DM-snapshot calls the DM-snapshot code which copies the segment(s) to the snapshot device and modifies them there. Basically disk-filesystem pagecache pages would be synced and protected by the DM snapshot, while anonymous memory pages would be CoW-ed. And it might not be an unreasonable requirement to state that the disk-based filesystems must all be mapped through DM-snapshot devices (even just straight 1:1 linear mappings), so that they can be trivially snapshotted.
Quoted 10 lines
Quoted 8 lines
So basically your hibernate-overhead would consist of:
(1) The pages necessary for the atomic snapshot of kernel
memory and the list of pagecache pages at that time
(2) A little memory necessary for the kernel non-persistent DM
snapshot datastructures.
(3) Thesnapshot_overhead_pagesneeded by userspace.If you're using swap devices then you can save 99% of the state of the running kernel with an initial swapout overhead of virtually nothing beyond the size of the unswappable kernel memory.
FWIW, let me note an important variation from how Suspend2 works; it might provide food for thought. In Suspend2, we treat the processes that remain stopped throughout the whole process specially. We write their data to disk before the atomic copy (usually 70 or 80% of memory), and then use the memory they occupy for the destination of the atomic copy. This further reduces the amount of memory that has to be freed, almost always to zero.
I suppose you could record swap-outs done to SIGFREEZEd processes specially, so that they would be swapped in again before resuming userspace. That would effectively result in the same thing.
Cheers,
Kyle Moffett
Thanks for the detailed reply!
Quoted 11 lines · Nigel Cunningham
Quoted 8 lines · On Friday 06 July 2007 15:01:48 Kyle Moffett wrote:
Suppose hibernate is implemented like this:
(1) Userspace program calls
sys_freeze_processes()
(a) Pokes all CPUs with IPMIs and tells them to finish the
currently running timeslot then stop
(b) Atomically sends SIGSTOP to all userspace processes in a
non-trappable way, except the calling process and any process which is ptracing it.
(c) Returns to the calling process.Ok. First, I'll ignore the specification that userspace does this - I don't think it matters whether it's userspace or kernel that does the suspending and I'm yet to see a good reason for it to be [required to be] done from userspace.
The reason it's _required_ to be done from userspace is that userspace is the only one which can figure out "These processes need to run for suspend to work", and then let those processes continue running after the freeze. The *ONLY* reason this even stops processes at all is so we can do the post-device-mapper-snapshot code with very little usably-free RAM (IE: only about 1MB for a standard desktop system).
Quoted 1 line
In this first step, you've reinvented the first part of the current freezer implementation. The reason we don't use a real signal is precisely so we can have an untrappable SIGSTOP. In this regard, I particularly remember Win4Lin from a few years ago. It would die if you sent it a real signal, so we had to do it this way. No doubt there are other instances I'm not aware of.
Well, you *do* want it to have semi-signal semantics, processes which receive it must not get back to userspace code so that they don't start allocating more memory when we're trying to do the freeze. You also don't want a process to be able to trap it (IE: like SIGSTOP or SIGKILL).
On the other hand, it should be delivered asynchronously (IE: It doesn't break an interruptable sleep or respond to most is-a-signal-present checks). You don't actually care if its sleeping in the kernel somewhere, just as long as it doesn't allocate much memory.
You would probably need a new signal "SIGFREEZE" which causes the process to be ignored as runnable the next time they schedule but never actually gets delivered, and a "SIGUNFREEZE" which does the reverse. That way userspace could selectively resume processes based on its policy of "this needs to run for hibernation".
Quoted 3 lines
Quoted 1 line
(2) Userspace process sends SIGCONT to only those processes which are necessary for sync and a device-mapper snapshot.
How do you determine which ones are needed?
It's userspace's job to know which ones are needed. For example, if you are hibernating over NFS then you need to resume the various NFS/RPC daemons and threads.
Quoted 1 line
Why stop them in the first place?
So they aren't allocating memory when we are doing the device-mapper snapshot.
Quoted 18 lines
Quoted 3 lines
(3) Userspace calls
sys_snapshot_kernel(snapshot_overhead_pages)
(a) Kernel starts freeing memory and swapping stuff out to make
room for a copy of *kernel* memory (not pagecache, not process RAM). It does the same for at leastsnapshot_overhead_pagesextra (used by userspace later). It then allocates this memory to keep it from going away. Since most processes are stopped we won't have much else competing with us for the RAM.Ok. So now you also need processes running that are needed for swapping, because freeing that memory might involve swapping. Fully agree with the logic though (not really surprising - this is what I do in Suspend2^wTuxOnIce).
Quoted 11 lines
(a) Kernel uses the device-mapper up-call-into-filesystem
machinery to get all mounted filesystems synced and ready for a DM snapshot. This may include sending data via the userspace processes resumed in (2). Any deadlocks here are userspace's fault (see (2)). Will need some modification to handle doing multiple blockdevs at a time. Anything using FUSE is basically perma-synced anyways (no dep-handling needed), and anything using loop should already be handled by DM. This includes allocating memory for the basic snapshot datastructures.
(b) At this point all blockdev operations should be halted and
disk caches flushed; that's all we care about.
(c) Go through the device tree and quiesce DMA and shut off
interrupts. Since all the disks are synced this is easy.
(d) Use IPMIs again to get all the CPUs together, which should
be easy as most processes are sleeping in IO or SIGSTOPed, and we're getting no interrupts.
(e) One CPU turns off all interrupts on itself and takes an
atomic snapshot of kernel memory into the previously allocated storage. Once again, does not include pagecache. The kernel also records a list of what pages *are* included in the pagecache. It then marks all userspace pages as copy-on-write.
Quoted 1 line
Hotplugging cpus (when all those locking issues are taken care of) is simpler. Prior to cpu hotplugging, I used IMPIs to put secondary cpus into a tight loop, so I know it's possible to do it this way too.
It may be simpler, but it really screws up things like cpusets, processor affinity, etc. It also ties hibernation to the presently very-flakey CPU-hotplug support, which is probably not what we want.
Quoted 1 line
That way, though, you have less flexibility. What if a cpu really is plugged in between hibernate and resume? With cpu hotplugging, it's handled properly and transparently. Without cpu hotplugging, you could be using uninitialised data after the atomic restore.
IMHO if the user pulls a CPU while the box is hibernated, then he/she gets what he/she deserves. If you really want to support that, then the user must do the hotplug operation *manually* before suspending. Anything else is just going to be shooting ourselves in the foot repeatedly.
Quoted 1 line
Marking userspace as COW makes things more complicated, too. You then have to add code to the COW handling to update the list of pages that need to be saved, and you reduce the reliability of the whole process. You can't predict beforehand how many of these COW pages are going to be needed, and therefore can't know how much memory to free earlier on in the process. If you run out of memory, what will be the effect?
You could pretty easily have a spare 128MB swap partition somewhere which is not used during system operation but is "swapon"ed by userspace after the COW snapshot to provide extra backing store.
Quoted 8 lines
Quoted 6 lines
(f) That CPU finalizes the modified DM snapshot using the
previously-allocated memory.
(g) That CPU frees up thesnapshot_overhead_pagesmemory
allocated during step (a) for userspace to use.
(h) The CPU does the equivalent of a "swapoff -a" without
overwriting any data already on any swap device(s).You still need to remember what swap you're going to use to write the image. You'll probably want to get this information (and allocate the swap) sooner rather than later so that you're not racing against the memory freeing earlier, and don't run into issues with bmapping the pages or having enough memory to record the bdevs & sector numbers (not usually an issue, but if swap is highly fragmented...).
Who says we have to use this swap to write the image? That may be the default use-case, but it's certainly shouldn't be mandatory. Really, for the write-image-to-swap case you would just need to preallocate sufficient memory for the bmap tables beforehand, then populate them at this phase.
Quoted 5 lines
Quoted 3 lines
(i) The CPU then IPMI-signals the other CPUs to wake them up
(j) The kernel returns a FD-reference to the snapshot and the
read-only halves of the CoW pagecache to the process which calledsys_snapshot_kernel().Readonly halves? I don't get that, sorry.
Well, each page is copy-on-write, so the FD reference would always provide access to the original page data, whereas the processes may end up copying the page so they can write to it. The trick would be that shared pages need to remain shared between processes even after the copy-on-write. This is likely to be the trickiest part.
Quoted 3 lines
Quoted 1 line
(4) The userspace process now has a reference to the copy of the kernel pages and the unmodified pagecache pages. Since 99% of the processes aren't running, we aren't going to be having to CoW many of the pagecache pages.
Mmm, but you still don't know how many.
Yes, but at this point we're basically running a segment of userspace with full kernel services available. Like I said above we can just add a dedicated 128MB swap device to provide some spare backing store. When you start running low on memory it might even page out to the swap device a part of the atomic copy of kernel memory.
Quoted 5 lines
Quoted 3 lines
(5) The userspace process uses
read()or other syscalls to get data out of the kernel-snapshot FD in small chunks, within itssnapshot_overhead_pageslimit. It compresses these and writes them out to the snapshot-storage blockdev (must not be mounted during snapshot), or to any network server.(6) The userspace process syncs the disks and halts the system. Any changed filesystem pages after the pseudo-DM-snapshot should have been stored in semi-volatile storage somewhere and will be discarded on the next reboot.
Are you thinking the changed filesystem pages are caught by COW? (AFAIUI, kernel writes aren't). If (as I expect), you're thinking about filesystem writes to DM based storage, what about non DM-based filesystem pages?
No, but a kernel write to a DM-snapshot calls the DM-snapshot code which copies the segment(s) to the snapshot device and modifies them there. Basically disk-filesystem pagecache pages would be synced and protected by the DM snapshot, while anonymous memory pages would be CoW-ed. And it might not be an unreasonable requirement to state that the disk-based filesystems must all be mapped through DM-snapshot devices (even just straight 1:1 linear mappings), so that they can be trivially snapshotted.
Quoted 10 lines
Quoted 8 lines
So basically your hibernate-overhead would consist of:
(1) The pages necessary for the atomic snapshot of kernel
memory and the list of pagecache pages at that time
(2) A little memory necessary for the kernel non-persistent DM
snapshot datastructures.
(3) Thesnapshot_overhead_pagesneeded by userspace.If you're using swap devices then you can save 99% of the state of the running kernel with an initial swapout overhead of virtually nothing beyond the size of the unswappable kernel memory.
FWIW, let me note an important variation from how Suspend2 works; it might provide food for thought. In Suspend2, we treat the processes that remain stopped throughout the whole process specially. We write their data to disk before the atomic copy (usually 70 or 80% of memory), and then use the memory they occupy for the destination of the atomic copy. This further reduces the amount of memory that has to be freed, almost always to zero.
I suppose you could record swap-outs done to SIGFREEZEd processes specially, so that they would be swapped in again before resuming userspace. That would effectively result in the same thing.
Cheers,
Kyle Moffett
Quoted 38 lines · Benjamin Herrenschmidt
Quoted 8 lines · Nigel Cunningham
Quoted 6 lines
So I think Matthew is totally right. In fact, the presence of the freezer is the main reason why Paulus so far NACKed Johannes attempts at merging the PPC PM code with the generic code in
kernel/power.cWe've been doing fine without it so far and intend to continue to do so.
Fuse depends on !PPC?
No, that's not what I'm saying. I'm saying we've been doing STR without the freezer and that's the way to go imho.
Quoted 5 lines
Quoted 3 lines
As for suspend-to-disk, I refer you to the discussions we had in the past with Linus, where he explains I think quite clearly how wrong the current implementation of STR is :-)
I assume you mean STD.
Oops, yeah, sorry.
Quoted 3 lines
The problem there is that Linus doesn't care about STD.
If he did, I dare say he'd think through the issues more thoroughly than he apparently has.Heh, that might be the case :-)
Quoted 6 lines
Quoted 2 lines
Thing is, if you're going to do snapshots, you should probably not sync after you have "frozen" anyway.
Fully agree. But how do you stop things syncing while you're writing the image if you don't have a freezer or equivalent? (scheduler based, kexec.. they're all workarounds for this issue).
Well, I was saying that in the context of the -current- snapshotting mechanism which is based on the freezer, then you should not
sys_sync().
Quoted 5 lines
Some random user or kernel thread doing a sync is not a problem. It will stop in the middle of sync and resume on wakeup.
The problem is currently because STD -itself- attempts to sync after it has frozen things.
To be precise, it tries to sync after it has frozen the user land.
Quoted 11 lines
I think that should be changed. If you want to sync for whatever reason, (mostly save RAM ?) do it before the freeze. That means you may get new dirty data in memory that isn't written out by the sync before you freeze, but that's allright, that data will be in the suspend image anyway. If you fail to wakeup, that's akin to a normal crash, the user will only lose the last data written at the time of the suspend and journaling fs'es should take care of fs metadata integrity.
So to summarize, the plan that makes things work with fuse is:
- For STR, don't do the freezer thing.
In the long run, I agree.
Still, can you please read this post from Alan Stern:
https://lists.linux-foundation.org/pipermail/linux-pm/2007-June/012847.html
? I don't think I'm able to repeat the arguments given in there in a convincing way.
Quoted 1 line
- For STD, don't
sys_sync()after you froze
Yeah, I think we can move the syncing before the freezing, so to speak.
And it need not be called from within the freezer, BTW.
Quoted 4 lines
There might be -other- issues, but that should get you through some of them at least. Of course, you'll be in trouble if you try to do things like STD-to-a-file which sits on a fuse FS but there's a limit to insanity :-)
Yes. :-)
Ggreetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Hi!
Quoted 6 lines
So I think Matthew is totally right. In fact, the presence of the freezer is the main reason why Paulus so far NACKed Johannes attempts at merging the PPC PM code with the generic code in
kernel/power.cWe've been doing fine without it so far and intend to continue to do so.
How well does it work on SMP PPC?
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Hi!
Quoted 6 lines
So I think Matthew is totally right. In fact, the presence of the freezer is the main reason why Paulus so far NACKed Johannes attempts at merging the PPC PM code with the generic code in
kernel/power.cWe've been doing fine without it so far and intend to continue to do so.
How well does it work on SMP PPC?
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 1 line · Pavel Machek
How well does it work on SMP PPC?
Just fine, on those machines where we know how to reinitialize the video card. We currently require userspace to offline all except the boot cpu before suspending, but that could be moved into the kernel. I have no particular attachment to that way of doing it; it was just a "don't do things in the kernel that can be reasonably be done in userspace" kind of thing.
Paul.
Quoted 1 line · Pavel Machek
How well does it work on SMP PPC?
Just fine, on those machines where we know how to reinitialize the video card. We currently require userspace to offline all except the boot cpu before suspending, but that could be moved into the kernel. I have no particular attachment to that way of doing it; it was just a "don't do things in the kernel that can be reasonably be done in userspace" kind of thing.
Paul.
Quoted 8 lines · Matthew Garrett
Suspend to RAM on a machine with / on a fuse filesystem turns out to be a screaming nightmare - either the suspend fails because syslog (for instance) can't be frozen, or the machine deadlocks for some other reason I haven't tracked down. We could "fix" fuse, or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.
Signed-off-by Matthew Garrett <[email protected]>
(And with much pleasure :-)
Cheers,
Ben.
Quoted 8 lines · Matthew Garrett
Suspend to RAM on a machine with / on a fuse filesystem turns out to be a screaming nightmare - either the suspend fails because syslog (for instance) can't be frozen, or the machine deadlocks for some other reason I haven't tracked down. We could "fix" fuse, or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.
Signed-off-by Matthew Garrett <[email protected]>
(And with much pleasure :-)
Cheers,
Ben.
Quoted 8 lines · Benjamin Herrenschmidt
Quoted 7 lines · Matthew Garrett
Suspend to RAM on a machine with / on a fuse filesystem turns out to be a screaming nightmare - either the suspend fails because syslog (for instance) can't be frozen, or the machine deadlocks for some other reason I haven't tracked down. We could "fix" fuse, or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.
Quoted 5 lines
Quoted 1 line
Signed-off-by Matthew Garrett <[email protected]>(And with much pleasure :-)
Clashes with some code already in -mm.
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Quoted 6 lines · Matthew Garrett
Suspend to RAM on a machine with / on a fuse filesystem turns out to be a screaming nightmare - either the suspend fails because syslog (for instance) can't be frozen, or the machine deadlocks for some other reason I haven't tracked down. We could "fix" fuse, or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.
The main reason for deadlocks is because we do a sys_sync() after the freeze, which we shouldn't do.
Ben.
Quoted 6 lines · Matthew Garrett
Suspend to RAM on a machine with / on a fuse filesystem turns out to be a screaming nightmare - either the suspend fails because syslog (for instance) can't be frozen, or the machine deadlocks for some other reason I haven't tracked down. We could "fix" fuse, or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.
The main reason for deadlocks is because we do a sys_sync() after the freeze, which we shouldn't do.
Ben.
Quoted 10 lines · Benjamin Herrenschmidt
Quoted 6 lines · Matthew Garrett
Suspend to RAM on a machine with / on a fuse filesystem turns out to be a screaming nightmare - either the suspend fails because syslog (for instance) can't be frozen, or the machine deadlocks for some other reason I haven't tracked down. We could "fix" fuse, or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.
The main reason for deadlocks is because we do a
sys_sync()after the freeze, which we shouldn't do.
So why don't we remove the sys_sync() from freeze_processes() instead?
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Quoted 9 lines · Rafael J. Wysocki
Quoted 8 lines · Benjamin Herrenschmidt
Quoted 6 lines · Matthew Garrett
Suspend to RAM on a machine with / on a fuse filesystem turns out to be a screaming nightmare - either the suspend fails because syslog (for instance) can't be frozen, or the machine deadlocks for some other reason I haven't tracked down. We could "fix" fuse, or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.
Quoted 4 lines
Quoted 2 lines
The main reason for deadlocks is because we do a
sys_sync()after the freeze, which we shouldn't do.So why don't we remove the
sys_sync()fromfreeze_processes()instead?
The patch follows (untested).
Greetings,
Rafael
---
From: Rafael J. Wysocki <[email protected]>
We shouldn't sync filesystems from within the freezer, because it's not needed for suspend to RAM and leads to problems with FUSE.
--- kernel/power/disk.c | 4 ++++ kernel/power/process.c | 1 - 2 files changed, 4 insertions(+), 1 deletion(-)
kernel/power/disk.c +4 -0
@@ -296,6 +296,10 @@ int hibernate(void) {int error; +printk ("Syncing filesystems ... \n" ); +sys_sync (); +printk ("done.\n" ); +mutex_lock (&pm_mutex);/* The snapshot device should not be opened while we're running */ if (!atomic_add_unless (&snapshot_device_available,-1 ,0 )) {
kernel/power/process.c +0 -1
@@ -190,7 +190,6 @@ int freeze_processes(void)if (error)return error; -sys_sync (); error =try_to_freeze_tasks (FREEZER_KERNEL_THREADS );if (error)return error;
Am Dienstag, 3. Juli 2007 schrieb Rafael J. Wysocki:
Quoted 21 lines · Rafael J. Wysocki
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 8 lines · Matthew Garrett
Quoted 6 lines
Suspend to RAM on a machine with / on a fuse filesystem turns out to be a screaming nightmare - either the suspend fails because syslog (for instance) can't be frozen, or the machine deadlocks for some other reason I haven't tracked down. We could "fix" fuse, or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.
Quoted 4 lines
Quoted 2 lines
The main reason for deadlocks is because we do a
sys_sync()after the freeze, which we shouldn't do.So why don't we remove the
sys_sync()fromfreeze_processes()instead?The patch follows (untested).
Greetings,
Rafael
Quoted 5 lines
---
From: Rafael J. Wysocki <[email protected]>We shouldn't sync filesystems from within the freezer, because it's not needed for suspend to RAM and leads to problems with FUSE.
This seems fishy. Swsusp needs enough clean memory to make enough room for the image. If you sync before you freeze, the running tasks can redirty memory.
What makes you sure that you don't die as shrink_all_memory() writes out pages?
Regards
Oliver
Quoted 25 lines · Oliver Neukum
Am Dienstag, 3. Juli 2007 schrieb Rafael J. Wysocki:
Quoted 24 lines · Rafael J. Wysocki
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 8 lines · Matthew Garrett
Quoted 6 lines
Suspend to RAM on a machine with / on a fuse filesystem turns out to be a screaming nightmare - either the suspend fails because syslog (for instance) can't be frozen, or the machine deadlocks for some other reason I haven't tracked down. We could "fix" fuse, or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.
Quoted 4 lines
Quoted 2 lines
The main reason for deadlocks is because we do a
sys_sync()after the freeze, which we shouldn't do.So why don't we remove the
sys_sync()fromfreeze_processes()instead?The patch follows (untested).
Greetings,
Rafael---
From: Rafael J. Wysocki <[email protected]>
Quoted 8 lines
Quoted 2 lines
We shouldn't sync filesystems from within the freezer, because it's not needed for suspend to RAM and leads to problems with FUSE.
This seems fishy. Swsusp needs enough clean memory to make enough room for the image. If you sync before you freeze, the running tasks can redirty memory.
What makes you sure that you don't die asshrink_all_memory()writes out pages?
I don't think that would matter.
Still, I can remove the sync from the suspend code path only, leaving it in the hibernation code path. The patch will be bigger, but well.
Any objection to that?
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Quoted 7 lines
I don't think that would matter.
Still, I can remove the sync from the suspend code path only, leaving it in the hibernation code path. The patch will be bigger, but well.
Any objection to that?
Makes sense to sync before suspend tho, to limit the amount of dirty non-written pages in case things go wrong.
Ben.
Quoted 7 lines
I don't think that would matter.
Still, I can remove the sync from the suspend code path only, leaving it in the hibernation code path. The patch will be bigger, but well.
Any objection to that?
Makes sense to sync before suspend tho, to limit the amount of dirty non-written pages in case things go wrong.
Ben.
Quoted 10 lines · Benjamin Herrenschmidt
Quoted 7 lines
I don't think that would matter.
Still, I can remove the sync from the suspend code path only, leaving it in the hibernation code path. The patch will be bigger, but well.
Any objection to that?
Makes sense to sync before suspend tho, to limit the amount of dirty non-written pages in case things go wrong.
OK, below is the updated patch.
Greetings,
Rafael
---
From: Rafael J. Wysocki <[email protected]>
The syncing of filesystems from within the freezer in not needed for suspend to RAM and leads to problems with FUSE. Change freeze_processes() so that it doesn't execute sys_sync() and introduce the "syncing" version of it to be called from the hibernation code paths.
--- include/linux/freezer.h | 14 ++++++++++++-- kernel/power/disk.c | 2 +- kernel/power/main.c | 6 ++++++ kernel/power/process.c | 8 +++++--- kernel/power/user.c | 2 +- 5 files changed, 25 insertions(+), 7 deletions(-)
include/linux/freezer.h +12 -2
@@ -62,7 +62,7 @@ static inline int thaw_process(struct ta }extern void refrigerator (void ); -extern int freeze_processes (void ); +extern int __freeze_processes (int sync_filesystems);extern void thaw_processes (void );static inline int try_to_freeze (void )
@@ -134,7 +134,7 @@ static inline void clear_freeze_flag(strstatic inline int thaw_process (struct task_struct *p) {return 1 ; }static inline void refrigerator (void ) {} -static inline int freeze_processes (void ) {BUG ();return 0 ; } +static inline int __freeze_processes (int s) {BUG ();return 0 ; }static inline void thaw_processes (void ) {}static inline int try_to_freeze (void ) {return 0 ; }
@@ -145,4 +145,14 @@ static inline int freezer_should_skip(ststatic inline void set_freezable (void ) {}#endif +static inline int freeze_processes (void ) +{ +return __freeze_processes (0 ); +} + +static inline int freeze_processes_with_sync (void ) +{ +return __freeze_processes (1 ); +} +#endif /* FREEZER_H_INCLUDED */
kernel/power/disk.c +1 -1
@@ -281,7 +281,7 @@ static int prepare_processes(void)int error =0 ;pm_prepare_console (); -if (freeze_processes ()) { +if (freeze_processes_with_sync ()) { error = -EBUSY ;unprepare_processes (); }
kernel/power/main.c +6 -0
@@ -20,6 +20,7 @@#include <linux/resume-trace.h> #include <linux/freezer.h> #include <linux/vmstat.h> +#include <linux/syscalls.h> #include "power.h"
@@ -231,6 +232,11 @@ static int enter_state(suspend_state_t sif (!valid_state (state))return -ENODEV ; + +printk ("Syncing filesystems ... " ); +sys_sync (); +printk ("done.\n" ); +if (!mutex_trylock (&pm_mutex))return -EBUSY ;
kernel/power/process.c +5 -3
@@ -179,9 +179,9 @@ static int try_to_freeze_tasks(int freez }/** -* freeze_processes - tell processes to enter the refrigerator +* __freeze_processes - tell processes to enter the refrigerator */ -int freeze_processes (void ) +int __freeze_processes (int sync_filesystems) {int error;
@@ -190,7 +190,9 @@ int freeze_processes(void)if (error)return error; -sys_sync (); +if (sync_filesystems) +sys_sync (); + error =try_to_freeze_tasks (FREEZER_KERNEL_THREADS );if (error)return error;
kernel/power/user.c +1 -1
@@ -153,7 +153,7 @@ static int snapshot_ioctl(struct inode *mutex_lock (&pm_mutex); error =pm_notifier_call_chain (PM_HIBERNATION_PREPARE );if (!error) { - error =freeze_processes (); + error =freeze_processes_with_sync ();if (error)thaw_processes (); }
Quoted 10 lines · Benjamin Herrenschmidt
Quoted 7 lines
I don't think that would matter.
Still, I can remove the sync from the suspend code path only, leaving it in the hibernation code path. The patch will be bigger, but well.
Any objection to that?
Makes sense to sync before suspend tho, to limit the amount of dirty non-written pages in case things go wrong.
OK, below is the updated patch.
Greetings,
Rafael
---
From: Rafael J. Wysocki <[email protected]>
The syncing of filesystems from within the freezer in not needed for suspend to RAM and leads to problems with FUSE. Change freeze_processes() so that it doesn't execute sys_sync() and introduce the "syncing" version of it to be called from the hibernation code paths.
--- include/linux/freezer.h | 14 ++++++++++++-- kernel/power/disk.c | 2 +- kernel/power/main.c | 6 ++++++ kernel/power/process.c | 8 +++++--- kernel/power/user.c | 2 +- 5 files changed, 25 insertions(+), 7 deletions(-)
include/linux/freezer.h +12 -2
@@ -62,7 +62,7 @@ static inline int thaw_process(struct ta }extern void refrigerator (void ); -extern int freeze_processes (void ); +extern int __freeze_processes (int sync_filesystems);extern void thaw_processes (void );static inline int try_to_freeze (void )
@@ -134,7 +134,7 @@ static inline void clear_freeze_flag(strstatic inline int thaw_process (struct task_struct *p) {return 1 ; }static inline void refrigerator (void ) {} -static inline int freeze_processes (void ) {BUG ();return 0 ; } +static inline int __freeze_processes (int s) {BUG ();return 0 ; }static inline void thaw_processes (void ) {}static inline int try_to_freeze (void ) {return 0 ; }
@@ -145,4 +145,14 @@ static inline int freezer_should_skip(ststatic inline void set_freezable (void ) {}#endif +static inline int freeze_processes (void ) +{ +return __freeze_processes (0 ); +} + +static inline int freeze_processes_with_sync (void ) +{ +return __freeze_processes (1 ); +} +#endif /* FREEZER_H_INCLUDED */
kernel/power/disk.c +1 -1
@@ -281,7 +281,7 @@ static int prepare_processes(void)int error =0 ;pm_prepare_console (); -if (freeze_processes ()) { +if (freeze_processes_with_sync ()) { error = -EBUSY ;unprepare_processes (); }
kernel/power/main.c +6 -0
@@ -20,6 +20,7 @@#include <linux/resume-trace.h> #include <linux/freezer.h> #include <linux/vmstat.h> +#include <linux/syscalls.h> #include "power.h"
@@ -231,6 +232,11 @@ static int enter_state(suspend_state_t sif (!valid_state (state))return -ENODEV ; + +printk ("Syncing filesystems ... " ); +sys_sync (); +printk ("done.\n" ); +if (!mutex_trylock (&pm_mutex))return -EBUSY ;
kernel/power/process.c +5 -3
@@ -179,9 +179,9 @@ static int try_to_freeze_tasks(int freez }/** -* freeze_processes - tell processes to enter the refrigerator +* __freeze_processes - tell processes to enter the refrigerator */ -int freeze_processes (void ) +int __freeze_processes (int sync_filesystems) {int error;
@@ -190,7 +190,9 @@ int freeze_processes(void)if (error)return error; -sys_sync (); +if (sync_filesystems) +sys_sync (); + error =try_to_freeze_tasks (FREEZER_KERNEL_THREADS );if (error)return error;
kernel/power/user.c +1 -1
@@ -153,7 +153,7 @@ static int snapshot_ioctl(struct inode *mutex_lock (&pm_mutex); error =pm_notifier_call_chain (PM_HIBERNATION_PREPARE );if (!error) { - error =freeze_processes (); + error =freeze_processes_with_sync ();if (error)thaw_processes (); }
Quoted 25 lines · Oliver Neukum
Am Dienstag, 3. Juli 2007 schrieb Rafael J. Wysocki:
Quoted 24 lines · Rafael J. Wysocki
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 8 lines · Matthew Garrett
Quoted 6 lines
Suspend to RAM on a machine with / on a fuse filesystem turns out to be a screaming nightmare - either the suspend fails because syslog (for instance) can't be frozen, or the machine deadlocks for some other reason I haven't tracked down. We could "fix" fuse, or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.
Quoted 4 lines
Quoted 2 lines
The main reason for deadlocks is because we do a
sys_sync()after the freeze, which we shouldn't do.So why don't we remove the
sys_sync()fromfreeze_processes()instead?The patch follows (untested).
Greetings,
Rafael---
From: Rafael J. Wysocki <[email protected]>
Quoted 8 lines
Quoted 2 lines
We shouldn't sync filesystems from within the freezer, because it's not needed for suspend to RAM and leads to problems with FUSE.
This seems fishy. Swsusp needs enough clean memory to make enough room for the image. If you sync before you freeze, the running tasks can redirty memory.
What makes you sure that you don't die asshrink_all_memory()writes out pages?
Shrink_all_memory should just free enough memory, what's the problem? Yes, we can have dirty memory, shrink_all_memory() can write that out just fine.
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 25 lines · Oliver Neukum
Am Dienstag, 3. Juli 2007 schrieb Rafael J. Wysocki:
Quoted 24 lines · Rafael J. Wysocki
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 8 lines · Matthew Garrett
Quoted 6 lines
Suspend to RAM on a machine with / on a fuse filesystem turns out to be a screaming nightmare - either the suspend fails because syslog (for instance) can't be frozen, or the machine deadlocks for some other reason I haven't tracked down. We could "fix" fuse, or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.
Quoted 4 lines
Quoted 2 lines
The main reason for deadlocks is because we do a
sys_sync()after the freeze, which we shouldn't do.So why don't we remove the
sys_sync()fromfreeze_processes()instead?The patch follows (untested).
Greetings,
Rafael---
From: Rafael J. Wysocki <[email protected]>
Quoted 8 lines
Quoted 2 lines
We shouldn't sync filesystems from within the freezer, because it's not needed for suspend to RAM and leads to problems with FUSE.
This seems fishy. Swsusp needs enough clean memory to make enough room for the image. If you sync before you freeze, the running tasks can redirty memory.
What makes you sure that you don't die asshrink_all_memory()writes out pages?
Shrink_all_memory should just free enough memory, what's the problem? Yes, we can have dirty memory, shrink_all_memory() can write that out just fine.
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Am Donnerstag, 5. Juli 2007 schrieb Pavel Machek:
Quoted 35 lines · Oliver Neukum
Quoted 25 lines
Am Dienstag, 3. Juli 2007 schrieb Rafael J. Wysocki:
Quoted 24 lines · Rafael J. Wysocki
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 8 lines · Matthew Garrett
Quoted 6 lines
Suspend to RAM on a machine with / on a fuse filesystem turns out to be a screaming nightmare - either the suspend fails because syslog (for instance) can't be frozen, or the machine deadlocks for some other reason I haven't tracked down. We could "fix" fuse, or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.
Quoted 4 lines
Quoted 2 lines
The main reason for deadlocks is because we do a
sys_sync()after the freeze, which we shouldn't do.So why don't we remove the
sys_sync()fromfreeze_processes()instead?The patch follows (untested).
Greetings,
Rafael---
From: Rafael J. Wysocki <[email protected]>Quoted 8 lines
Quoted 2 lines
We shouldn't sync filesystems from within the freezer, because it's not needed for suspend to RAM and leads to problems with FUSE.
This seems fishy. Swsusp needs enough clean memory to make enough room for the image. If you sync before you freeze, the running tasks can redirty memory.
What makes you sure that you don't die asshrink_all_memory()writes out pages?
Quoted 3 lines
Shrink_all_memoryshould just free enough memory, what's the problem? Yes, we can have dirty memory,shrink_all_memory()can write that out just fine.
If there's any dirty memory to be written out through fuse, this will not work as user space is already frozen. Now I am told that with fuse writes are synchronous. Therefore I don't understand why having a call to sys_sync() can make a difference. IMHO removing it to make fuse work covers over a symptom but hides the bug.
Regards
Oliver
Am Donnerstag, 5. Juli 2007 schrieb Pavel Machek:
Quoted 35 lines · Oliver Neukum
Quoted 25 lines
Am Dienstag, 3. Juli 2007 schrieb Rafael J. Wysocki:
Quoted 24 lines · Rafael J. Wysocki
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 8 lines · Matthew Garrett
Quoted 6 lines
Suspend to RAM on a machine with / on a fuse filesystem turns out to be a screaming nightmare - either the suspend fails because syslog (for instance) can't be frozen, or the machine deadlocks for some other reason I haven't tracked down. We could "fix" fuse, or alternatively we could do what we do for suspend to RAM on other platforms (PPC and APM) and just not use the freezer.
Quoted 4 lines
Quoted 2 lines
The main reason for deadlocks is because we do a
sys_sync()after the freeze, which we shouldn't do.So why don't we remove the
sys_sync()fromfreeze_processes()instead?The patch follows (untested).
Greetings,
Rafael---
From: Rafael J. Wysocki <[email protected]>Quoted 8 lines
Quoted 2 lines
We shouldn't sync filesystems from within the freezer, because it's not needed for suspend to RAM and leads to problems with FUSE.
This seems fishy. Swsusp needs enough clean memory to make enough room for the image. If you sync before you freeze, the running tasks can redirty memory.
What makes you sure that you don't die asshrink_all_memory()writes out pages?
Quoted 3 lines
Shrink_all_memoryshould just free enough memory, what's the problem? Yes, we can have dirty memory,shrink_all_memory()can write that out just fine.
If there's any dirty memory to be written out through fuse, this will not work as user space is already frozen. Now I am told that with fuse writes are synchronous. Therefore I don't understand why having a call to sys_sync() can make a difference. IMHO removing it to make fuse work covers over a symptom but hides the bug.
Regards
Oliver
Am Dienstag, 3. Juli 2007 schrieb Rafael J. Wysocki:
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
The main reason for deadlocks is because we do a
sys_sync()after the freeze, which we shouldn't do.So why don't we remove the
sys_sync()fromfreeze_processes()instead?The patch follows (untested).
And a further question. The freezer is not atomic. What do you do if a task not yet frozen calls sys_sync(), but fuse is already frozen?
Regards
Oliver
Quoted 2 lines
And a further question. The freezer is not atomic. What do you do if a task not yet frozen calls
sys_sync(), but fuse is already frozen?
What do you do if a task not yet frozen writes to a pipe, on the other end of which is a task already frozen?
It doesn't matter. The only thing that should matter during suspend (not hibernate) is saving the state of devices to ram, and putting the devices to sleep.
I'm not sure why this can't be made atomic, but assuming, that it can't, fuse should still not need to be implicated. If it is, that's an indication about something wrong in the suspend procedure.
Miklos
Am Dienstag, 3. Juli 2007 schrieb Miklos Szeredi:
Quoted 5 lines
Quoted 2 lines
And a further question. The freezer is not atomic. What do you do if a task not yet frozen calls
sys_sync(), but fuse is already frozen?What do you do if a task not yet frozen writes to a pipe, on the other end of which is a task already frozen?
The same as you do with a pipe when the reader is not ready.
Quoted 3 lines
It doesn't matter. The only thing that should matter during suspend (not hibernate) is saving the state of devices to ram, and putting the devices to sleep.
Well, but you did remove sys_sync() from the freezer, which is and must be called in the hibernate path.
Quoted 3 lines
I'm not sure why this can't be made atomic, but assuming, that it can't, fuse should still not need to be implicated. If it is, that's an indication about something wrong in the suspend procedure.
Nope, something's wrong in fuse. You must be able to deal with sync until every task is frozen.
Regards
Oliver
Quoted 8 lines
Am Dienstag, 3. Juli 2007 schrieb Miklos Szeredi:
Quoted 5 lines
Quoted 2 lines
And a further question. The freezer is not atomic. What do you do if a task not yet frozen calls
sys_sync(), but fuse is already frozen?What do you do if a task not yet frozen writes to a pipe, on the other end of which is a task already frozen?
The same as you do with a pipe when the reader is not ready.
Yes. And if the fuse process is not ready, what will sys_sync() do?
(As a side note, sys_sync() actually does nothing in fuse, so these examples are slightly silly, but the concept applies to any filesystem operation).
Quoted 6 lines
Quoted 3 lines
It doesn't matter. The only thing that should matter during suspend (not hibernate) is saving the state of devices to ram, and putting the devices to sleep.
Well, but you did remove
sys_sync()from the freezer, which is and must be called in the hibernate path.
Since I don't know why sync() needs to be called from hibernate, I can't argue about this. But for _suspend_ it definitely should not be needed.
Quoted 6 lines
Quoted 3 lines
I'm not sure why this can't be made atomic, but assuming, that it can't, fuse should still not need to be implicated. If it is, that's an indication about something wrong in the suspend procedure.
Nope, something's wrong in fuse. You must be able to deal with sync until every task is frozen.
Why exactly? That's like saying the pipe must be able to deal with writes until every task is frozen.
As I've said, fuse is just special kind of IPC. The task calling into fuse can assume nothing about when it's request will be served. Just like a task writing into a pipe can assume nothing about when that write will return.
Miklos
Quoted 2 lines · Oliver Neukum
Well, but you did remove
sys_sync()from the freezer, which is and must be called in the hibernate path.
That's not really true. We _want_ to call sys_sync() in both the hibernate and suspend paths (in case the batteries run down), to help avoid filesystem problems if something goes wrong with the resume. But it isn't a hard requirement.
Quoted 6 lines
Quoted 3 lines
I'm not sure why this can't be made atomic, but assuming, that it can't, fuse should still not need to be implicated. If it is, that's an indication about something wrong in the suspend procedure.
Nope, something's wrong in fuse. You must be able to deal with sync until every task is frozen.
That's ridiculous. FUSE itself runs partially as a user task. How can you expect it to carry out a sync or anything else when it is frozen?
I suppose you could "deal" with it by having the kernel portion return an error if the userspace part is frozen. If the hibernate/suspend code bothered to check the return value, it would immediately abort the suspend.
Alan Stern
Quoted 15 lines
Quoted 2 lines
Well, but you did remove
sys_sync()from the freezer, which is and must be called in the hibernate path.That's not really true. We _want_ to call
sys_sync()in both the hibernate and suspend paths (in case the batteries run down), to help avoid filesystem problems if something goes wrong with the resume. But it isn't a hard requirement.Quoted 6 lines
Quoted 3 lines
I'm not sure why this can't be made atomic, but assuming, that it can't, fuse should still not need to be implicated. If it is, that's an indication about something wrong in the suspend procedure.
Nope, something's wrong in fuse. You must be able to deal with sync until every task is frozen.
Quoted 7 lines
That's ridiculous. FUSE itself runs partially as a user task. How can you expect it to carry out a sync or anything else when it is frozen?
I suppose you could "deal" with it by having the kernel portion return an error if the userspace part is frozen. If the hibernate/suspend code bothered to check the return value, it would immediately abort the suspend.
I strongly believe, that we don't want to deal with it. If we want to call sync(), do it while the system is fully operational. It's a best effort thing anyway, and you can loose data in other ways if resume fails.
Miklos
Quoted 15 lines
Quoted 2 lines
Well, but you did remove
sys_sync()from the freezer, which is and must be called in the hibernate path.That's not really true. We _want_ to call
sys_sync()in both the hibernate and suspend paths (in case the batteries run down), to help avoid filesystem problems if something goes wrong with the resume. But it isn't a hard requirement.Quoted 6 lines
Quoted 3 lines
I'm not sure why this can't be made atomic, but assuming, that it can't, fuse should still not need to be implicated. If it is, that's an indication about something wrong in the suspend procedure.
Nope, something's wrong in fuse. You must be able to deal with sync until every task is frozen.
Quoted 7 lines
That's ridiculous. FUSE itself runs partially as a user task. How can you expect it to carry out a sync or anything else when it is frozen?
I suppose you could "deal" with it by having the kernel portion return an error if the userspace part is frozen. If the hibernate/suspend code bothered to check the return value, it would immediately abort the suspend.
I strongly believe, that we don't want to deal with it. If we want to call sync(), do it while the system is fully operational. It's a best effort thing anyway, and you can loose data in other ways if resume fails.
Miklos
Quoted 15 lines · Miklos Szeredi
Quoted 15 lines
Quoted 2 lines
Well, but you did remove
sys_sync()from the freezer, which is and must be called in the hibernate path.That's not really true. We _want_ to call
sys_sync()in both the hibernate and suspend paths (in case the batteries run down), to help avoid filesystem problems if something goes wrong with the resume. But it isn't a hard requirement.Quoted 6 lines
Quoted 3 lines
I'm not sure why this can't be made atomic, but assuming, that it can't, fuse should still not need to be implicated. If it is, that's an indication about something wrong in the suspend procedure.
Nope, something's wrong in fuse. You must be able to deal with sync until every task is frozen.
Quoted 7 lines
Quoted 7 lines
That's ridiculous. FUSE itself runs partially as a user task. How can you expect it to carry out a sync or anything else when it is frozen?
I suppose you could "deal" with it by having the kernel portion return an error if the userspace part is frozen. If the hibernate/suspend code bothered to check the return value, it would immediately abort the suspend.
Er, do_sync() doesn't return a result.
Quoted 4 lines
I strongly believe, that we don't want to deal with it. If we want to call
sync(), do it while the system is fully operational. It's a best effort thing anyway, and you can loose data in other ways if resume fails.
The requirement of syncing when the system (including the user space) is fully operational is FUSE-specific. Thus we'd rather like to sync FUSE filesystems before freezing the user space and freeze the other filesystems after freezing the user space.
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Quoted 15 lines · Miklos Szeredi
Quoted 15 lines
Quoted 2 lines
Well, but you did remove
sys_sync()from the freezer, which is and must be called in the hibernate path.That's not really true. We _want_ to call
sys_sync()in both the hibernate and suspend paths (in case the batteries run down), to help avoid filesystem problems if something goes wrong with the resume. But it isn't a hard requirement.Quoted 6 lines
Quoted 3 lines
I'm not sure why this can't be made atomic, but assuming, that it can't, fuse should still not need to be implicated. If it is, that's an indication about something wrong in the suspend procedure.
Nope, something's wrong in fuse. You must be able to deal with sync until every task is frozen.
Quoted 7 lines
Quoted 7 lines
That's ridiculous. FUSE itself runs partially as a user task. How can you expect it to carry out a sync or anything else when it is frozen?
I suppose you could "deal" with it by having the kernel portion return an error if the userspace part is frozen. If the hibernate/suspend code bothered to check the return value, it would immediately abort the suspend.
Er, do_sync() doesn't return a result.
Quoted 4 lines
I strongly believe, that we don't want to deal with it. If we want to call
sync(), do it while the system is fully operational. It's a best effort thing anyway, and you can loose data in other ways if resume fails.
The requirement of syncing when the system (including the user space) is fully operational is FUSE-specific. Thus we'd rather like to sync FUSE filesystems before freezing the user space and freeze the other filesystems after freezing the user space.
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Am Dienstag, 3. Juli 2007 schrieben Sie:
Quoted 9 lines · Oliver Neukum
Quoted 3 lines
Well, but you did remove
sys_sync()from the freezer, which is and must be called in the hibernate path.That's not really true. We _want_ to call
sys_sync()in both the hibernate and suspend paths (in case the batteries run down), to help avoid filesystem problems if something goes wrong with the resume. But it isn't a hard requirement.
But the ability to launder pages is needed. During hibernation we need to shrink memory. I don't see how this would be fundamentally different from calling sync.
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
I'm not sure why this can't be made atomic, but assuming, that it can't, fuse should still not need to be implicated. If it is, that's an indication about something wrong in the suspend procedure.
Nope, something's wrong in fuse. You must be able to deal with sync until every task is frozen.
That's ridiculous. FUSE itself runs partially as a user task. How can you expect it to carry out a sync or anything else when it is frozen?
I don't and it might point to a fundamental problem.
But I cannot help but notice that syscalls may happen while the system is partially frozen. It must be dealt with.
Quoted 4 lines
I suppose you could "deal" with it by having the kernel portion return an error if the userspace part is frozen. If the hibernate/suspend code bothered to check the return value, it would immediately abort the suspend.
Where exactly would that code notice the errors?
Regards
Oliver
Am Dienstag, 3. Juli 2007 schrieben Sie:
Quoted 9 lines · Oliver Neukum
Quoted 3 lines
Well, but you did remove
sys_sync()from the freezer, which is and must be called in the hibernate path.That's not really true. We _want_ to call
sys_sync()in both the hibernate and suspend paths (in case the batteries run down), to help avoid filesystem problems if something goes wrong with the resume. But it isn't a hard requirement.
But the ability to launder pages is needed. During hibernation we need to shrink memory. I don't see how this would be fundamentally different from calling sync.
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
I'm not sure why this can't be made atomic, but assuming, that it can't, fuse should still not need to be implicated. If it is, that's an indication about something wrong in the suspend procedure.
Nope, something's wrong in fuse. You must be able to deal with sync until every task is frozen.
That's ridiculous. FUSE itself runs partially as a user task. How can you expect it to carry out a sync or anything else when it is frozen?
I don't and it might point to a fundamental problem.
But I cannot help but notice that syscalls may happen while the system is partially frozen. It must be dealt with.
Quoted 4 lines
I suppose you could "deal" with it by having the kernel portion return an error if the userspace part is frozen. If the hibernate/suspend code bothered to check the return value, it would immediately abort the suspend.
Where exactly would that code notice the errors?
Regards
Oliver
Quoted 7 lines · Oliver Neukum
Quoted 2 lines
I'm not sure why this can't be made atomic, but assuming, that it can't, fuse should still not need to be implicated. If it is,
that's
Quoted 1 line
an indication about something wrong in the suspend procedure.
Nope, something's wrong in fuse. You must be able to deal with sync until every task is frozen.
Pipe dream
Ben.
Am Dienstag, 3. Juli 2007 schrieb Benjamin Herrenschmidt:
Quoted 10 lines · Oliver Neukum
Quoted 7 lines
Quoted 2 lines
I'm not sure why this can't be made atomic, but assuming, that it can't, fuse should still not need to be implicated. If it is,
that's
Quoted 1 line
an indication about something wrong in the suspend procedure.
Nope, something's wrong in fuse. You must be able to deal with sync until every task is frozen.
Pipe dream
Then tell me how you want to avoid that condition.
Oliver
Am Dienstag, 3. Juli 2007 schrieb Benjamin Herrenschmidt:
Quoted 10 lines · Oliver Neukum
Quoted 7 lines
Quoted 2 lines
I'm not sure why this can't be made atomic, but assuming, that it can't, fuse should still not need to be implicated. If it is,
that's
Quoted 1 line
an indication about something wrong in the suspend procedure.
Nope, something's wrong in fuse. You must be able to deal with sync until every task is frozen.
Pipe dream
Then tell me how you want to avoid that condition.
Oliver
Quoted 5 lines · Oliver Neukum
Am Dienstag, 3. Juli 2007 schrieb Benjamin Herrenschmidt:
Quoted 4 lines · Oliver Neukum
Quoted 3 lines
Quoted 2 lines
I'm not sure why this can't be made atomic, but assuming, that it can't, fuse should still not need to be implicated. If it is,
that's
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
an indication about something wrong in the suspend procedure.
Nope, something's wrong in fuse. You must be able to deal with sync until every task is frozen.
Pipe dream
Then tell me how you want to avoid that condition.
Don't freeze :-)
Ben.
Quoted 5 lines · Oliver Neukum
Am Dienstag, 3. Juli 2007 schrieb Benjamin Herrenschmidt:
Quoted 4 lines · Oliver Neukum
Quoted 3 lines
Quoted 2 lines
I'm not sure why this can't be made atomic, but assuming, that it can't, fuse should still not need to be implicated. If it is,
that's
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
an indication about something wrong in the suspend procedure.
Nope, something's wrong in fuse. You must be able to deal with sync until every task is frozen.
Pipe dream
Then tell me how you want to avoid that condition.
Don't freeze :-)
Ben.
Am Dienstag, 3. Juli 2007 schrieb Benjamin Herrenschmidt:
Quoted 8 lines · Oliver Neukum
Quoted 7 lines
Am Dienstag, 3. Juli 2007 schrieb Benjamin Herrenschmidt:
Quoted 6 lines · Oliver Neukum
Quoted 5 lines
Quoted 2 lines
I'm not sure why this can't be made atomic, but assuming, that it can't, fuse should still not need to be implicated. If it is,
that's
Quoted 1 line
an indication about something wrong in the suspend procedure.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Nope, something's wrong in fuse. You must be able to deal with sync until every task is frozen.
Pipe dream
Then tell me how you want to avoid that condition.
Don't freeze :-)
Then you will have to deal with all syscalls unfrozen tasks can make.
Regards
Oliver
Am Dienstag, 3. Juli 2007 schrieb Benjamin Herrenschmidt:
Quoted 8 lines · Oliver Neukum
Quoted 7 lines
Am Dienstag, 3. Juli 2007 schrieb Benjamin Herrenschmidt:
Quoted 6 lines · Oliver Neukum
Quoted 5 lines
Quoted 2 lines
I'm not sure why this can't be made atomic, but assuming, that it can't, fuse should still not need to be implicated. If it is,
that's
Quoted 1 line
an indication about something wrong in the suspend procedure.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Nope, something's wrong in fuse. You must be able to deal with sync until every task is frozen.
Pipe dream
Then tell me how you want to avoid that condition.
Don't freeze :-)
Then you will have to deal with all syscalls unfrozen tasks can make.
Regards
Oliver
Quoted 12 lines · Oliver Neukum
Am Dienstag, 3. Juli 2007 schrieb Benjamin Herrenschmidt:
Quoted 11 lines · Oliver Neukum
Quoted 10 lines
Am Dienstag, 3. Juli 2007 schrieb Benjamin Herrenschmidt:
Quoted 9 lines · Oliver Neukum
Quoted 7 lines
Quoted 2 lines
I'm not sure why this can't be made atomic, but assuming, that it can't, fuse should still not need to be implicated. If it is,
that's
Quoted 1 line
an indication about something wrong in the suspend procedure.
Nope, something's wrong in fuse. You must be able to deal with sync until every task is frozen.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Pipe dream
Then tell me how you want to avoid that condition.
Don't freeze :-)
Then you will have to deal with all syscalls unfrozen tasks can make.
Yup, and the majority of them is totally harmless. Looks like people around here have a problem with the idea of writing robust drivers ...
Ben.
Quoted 12 lines · Oliver Neukum
Am Dienstag, 3. Juli 2007 schrieb Benjamin Herrenschmidt:
Quoted 11 lines · Oliver Neukum
Quoted 10 lines
Am Dienstag, 3. Juli 2007 schrieb Benjamin Herrenschmidt:
Quoted 9 lines · Oliver Neukum
Quoted 7 lines
Quoted 2 lines
I'm not sure why this can't be made atomic, but assuming, that it can't, fuse should still not need to be implicated. If it is,
that's
Quoted 1 line
an indication about something wrong in the suspend procedure.
Nope, something's wrong in fuse. You must be able to deal with sync until every task is frozen.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Pipe dream
Then tell me how you want to avoid that condition.
Don't freeze :-)
Then you will have to deal with all syscalls unfrozen tasks can make.
Yup, and the majority of them is totally harmless. Looks like people around here have a problem with the idea of writing robust drivers ...
Ben.