Skip to contentSkip to conversation

Modular Scheduler Core and Completely Fair Scheduler [CFS]

PATCH In review Ingo Molnar 76 participants 711 messages Apr 13, 2007 – Jun 30, 2007 10 messages not in the archive Page 2 of 4

Subsystems (11)
lore
Share & tools
lore
#243 lore raw
In reply to William Lee Irwin III
Quoted 20 lines · William Lee Irwin III
Quoted 1 line · Andrew Morton
Quoted 1 line

Yes, there are potential compatibility problems. Example: a machine with 100 busy httpd processes and suddenly a big gzip starts up from console or cron.

[...]

Quoted 2 lines · Ingo Molnar

hmmmm. How about the following then: default to nice -10 for all (SCHED_NORMAL) kernel threads and all root-owned tasks. Root _is_ special: root already has disk space reserved to it, root has special memory allocation allowances, etc. I dont see a reason why we couldnt by default make all root tasks have nice -10. This would be instantly loved by sysadmins i suspect ;-) (distros that go the extra mile of making Xorg run under non-root could also go another extra one foot to renice that X server to -10.)

I'd further recommend making priority levels accessible to kernel threads that are not otherwise accessible to processes, both above and below user-available priority levels. Basically, if you can get SCHED_RR and SCHED_FIFO to coexist as "intimate scheduler classes," then a SCHED_KERN scheduler class can coexist with SCHED_OTHER in like fashion, but with availability of higher and lower priorities than any userspace process is allowed, and potentially some differing scheduling semantics. In such a manner nonessential background processing intended not to ever disturb userspace can be given priorities appropriate to it (perhaps even con's SCHED_IDLEPRIO would make sense), and other, urgent processing can be given priority over userspace altogether.

Quoted 3 lines

I believe root's default priority can be adjusted in userspace as things now stand somewhere in /etc/ but I'm not sure of the specifics. Word is somewhere in /etc/security/limits.conf

This is sounding very much like System V Release 4 (and descendants) except that they call it SCHED_SYS and also give SCHED_NORMAL tasks that are in system mode dynamic priorities in the SCHED_SYS range (to avoid priority inversion, I believe).

Peter

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#244 lore raw
Quoted 11 lines · William Lee Irwin III
Quoted 11 lines

I'd further recommend making priority levels accessible to kernel threads that are not otherwise accessible to processes, both above and below user-available priority levels. Basically, if you can get SCHED_RR and SCHED_FIFO to coexist as "intimate scheduler classes," then a SCHED_KERN scheduler class can coexist with SCHED_OTHER in like fashion, but with availability of higher and lower priorities than any userspace process is allowed, and potentially some differing scheduling semantics. In such a manner nonessential background processing intended not to ever disturb userspace can be given priorities appropriate to it (perhaps even con's SCHED_IDLEPRIO would make sense), and other, urgent processing can be given priority over userspace altogether.

Quoted 4 lines · Peter Williams

This is sounding very much like System V Release 4 (and descendants) except that they call it SCHED_SYS and also give SCHED_NORMAL tasks that are in system mode dynamic priorities in the SCHED_SYS range (to avoid priority inversion, I believe).

Descriptions of that are probably where I got the idea (hurrah for OS textbooks). It makes a fair amount of sense. Not sure what the take on the specific precedent is. The only content here is expanding the priority range with ranges above and below for the exclusive use of ultra-privileged tasks, so it's really trivial. Actually it might be so trivial it should just be some permission checks in the SCHED_OTHER renicing code.

-- wli

#245 lore raw
Quoted 13 lines · William Lee Irwin III
Quoted 11 lines · William Lee Irwin III
Quoted 11 lines

I'd further recommend making priority levels accessible to kernel threads that are not otherwise accessible to processes, both above and below user-available priority levels. Basically, if you can get SCHED_RR and SCHED_FIFO to coexist as "intimate scheduler classes," then a SCHED_KERN scheduler class can coexist with SCHED_OTHER in like fashion, but with availability of higher and lower priorities than any userspace process is allowed, and potentially some differing scheduling semantics. In such a manner nonessential background processing intended not to ever disturb userspace can be given priorities appropriate to it (perhaps even con's SCHED_IDLEPRIO would make sense), and other, urgent processing can be given priority over userspace altogether.

Quoted 5 lines
Quoted 1 line · Peter Williams

This is sounding very much like System V Release 4 (and descendants) except that they call it SCHED_SYS and also give SCHED_NORMAL tasks that are in system mode dynamic priorities in the SCHED_SYS range (to avoid priority inversion, I believe).

Descriptions of that are probably where I got the idea (hurrah for OS textbooks).

And long term background memory. :-)

Quoted 1 line

It makes a fair amount of sense.

Yes. You could also add a SCHED_IA in between SCHED_SYS and SCHED_OTHER (a la Solaris) for interactive tasks. The only problem is how to get a task into SCHED_IA without root privileges.

Quoted 6 lines

Not sure what the take on
the specific precedent is. The only content here is expanding the priority range with ranges above and below for the exclusive use of ultra-privileged tasks, so it's really trivial. Actually it might be so trivial it should just be some permission checks in the SCHED_OTHER renicing code.

Perhaps.

Peter

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#246 lore raw
In reply to Ingo Molnar
Quoted 22 lines · Ingo Molnar
Quoted 11 lines · Andrew Morton
Quoted 2 lines

And yes, by fairly, I mean fairly among all threads as a base resource class, because that's what Linux has always done

Yes, there are potential compatibility problems. Example: a machine with 100 busy httpd processes and suddenly a big gzip starts up from console or cron.

Under current kernels, that gzip will take ages and the httpds will take a 1% slowdown, which may well be exactly the behaviour which is desired.

Quoted 7 lines

If we were to schedule by UID then the gzip suddenly gets 50% of the CPU and those httpd's all take a 50% hit, which could be quite serious.

That's simple to fix via nicing, but people have to know to do that, and there will be a transition period where some disruption is possible.

Quoted 6 lines

hmmmm. How about the following then: default to nice -10 for all (SCHED_NORMAL) kernel threads and all root-owned tasks. Root _is_
special: root already has disk space reserved to it, root has special memory allocation allowances, etc. I dont see a reason why we couldnt by default make all root tasks have nice -10. This would be instantly loved by sysadmins i suspect ;-)

I have no problem with doing fancy new fairness classes and things.

But considering that we _need_ to have per-thread fairness and that is also what the current scheduler has and what we need to do well for obvious reasons, the best path to take is to get per-thread scheduling up to a point where it is able to replace the current scheduler, then look at more complex things after that.

#247 lore raw

Renice X for cpu schedulers

In reply to Ingo Molnar

Ok, there are 3 known schedulers currently being "promoted" as solid replacements for the mainline scheduler which address most of the issues with mainline (and about 10 other ones not currently being promoted). The main way they do this is through attempting to maintain solid fairness. There is enough evidence mounting now from the numerous test cases fixed by much fairer designs that this is the way forward for a general purpose cpu scheduler which is what linux needs.

Interactivity of just about everything that needs low latency (ie audio and video players) are easily managed by maintaining low latency between wakeups and scheduling of all these low cpu users. The one fly in the ointment for linux remains X. I am still, to this moment, completely and utterly stunned at why everyone is trying to find increasingly complex unique ways to manage X when all it needs is more cpu[1]. Now most of these are actually very good ideas about _extra_ features that would be desirable in the long run for linux, but given the ludicrous simplicity of renicing X I cannot fathom why people keep promoting these alternatives. At the time of 2.6.0 coming out we were desparately trying to get half decent interactivity within a reasonable time frame to release 2.6.0 without rewiring the whole scheduler. So I tweaked the crap out of the tunables that were already there[2].

So let's hear from the 3 people who generated the schedulers under the spotlight. These are recent snippets and by no means the only time these comments have been said. Without sounding too bold, we do know a thing or two about scheduling.

CFS:

Quoted 9 lines · Ingo Molnar

hmmmm. How about the following then: default to nice -10 for all (SCHED_NORMAL) kernel threads and all root-owned tasks. Root _is_
special: root already has disk space reserved to it, root has special memory allocation allowances, etc. I dont see a reason why we couldnt by default make all root tasks have nice -10. This would be instantly loved by sysadmins i suspect ;-)

(distros that go the extra mile of making Xorg run under non-root could also go another extra one foot to renice that X server to -10.)

Nicksched:

Quoted 2 lines · Nick Piggin

What's wrong with allowing X to get more than it's fair share of CPU time by "fiddling with nice levels"? That's what they're there for.

and

Staircase-Deadline:

Quoted 1 line · Con Kolivas

Remember to renice X to -10 for nicest desktop behaviour :)

[1]The one caveat I can think of is that when you share X sessions across multiple users -with a fair cpu scheduler-, having them all nice 0 also makes the distribution of cpu across the multiple users very even and smooth, without the expense of burning away the other person's cpu time they'd like for compute intensive non gui things. If you make a scheduler that always favours X this becomes impossible. I've had enough users offlist ask me to help them set up multiuser environments just like this with my schedulers because they were unable to do it with mainline, even with SCHED_BATCH, short of nicing everything +19. This makes the argument for not favouring X within the scheduler with tweaks even stronger.

[2] Nick was promoting renicing X with his Nicksched alternative at the time of 2.6.0 and while we were not violently opposed to renicing X, Nicksched was still very new on the scene and didn't have the luxury of extended testing and reiteration in time for 2.6 and he put the project on hold for some time after that. The correctness of his views on renicing certainly have become more obvious over time.

So yes go ahead and think up great ideas for other ways of metering out cpu bandwidth for different purposes, but for X, given the absurd simplicity of renicing, why keep fighting it? Again I reiterate that most users of SD have not found the need to renice X anyway except if they stick to old habits of make -j4 on uniprocessor and the like, and I expect that those on CFS and Nicksched would also have similar experiences.

Signature · 1 line
-ck
#248 lore raw

Re: Renice X for cpu schedulers

Con Kolivas wrote:
s go ahead and think up great ideas for other ways of metering out cpu

Quoted 1 line

bandwidth for different purposes, but for X, given the absurd simplicity of renicing, why keep fighting it? Again I reiterate that most users of SD have not found the need to renice X anyway except if they stick to old habits of make -j4 on uniprocessor and the like, and I expect that those on CFS and Nicksched would also have similar experiences.

Just plain "make" (no -j2 or -j9999) is enough to kill interactivity on my 2GHz P-M single-core non-HT machine with SD.

But with the very first posted version of CFS by Ingo,
I can do "make -j2" no problem and still have a nicely interactive destop.

-ml

#249 lore raw

Re: Renice X for cpu schedulers

Quoted 9 lines · Mark Lord

Con Kolivas wrote:
s go ahead and think up great ideas for other ways of metering out cpu

Quoted 5 lines

bandwidth for different purposes, but for X, given the absurd simplicity of renicing, why keep fighting it? Again I reiterate that most users of SD have not found the need to renice X anyway except if they stick to old habits of make -j4 on uniprocessor and the like, and I expect that those on CFS and Nicksched would also have similar experiences.

Quoted 5 lines

Just plain "make" (no -j2 or -j9999) is enough to kill interactivity on my 2GHz P-M single-core non-HT machine with SD.

But with the very first posted version of CFS by Ingo,
I can do "make -j2" no problem and still have a nicely interactive destop.

Cool. Then there's clearly a bug with SD that manifests on your machine as it should not have that effect at all (and doesn't on other people's machines). I suggest trying the latest version which fixes some bugs.

Thanks.

Signature · 1 line
-ck
#250 lore raw

Re: Renice X for cpu schedulers

Quoted 9 lines · Con Kolivas
Quoted 8 lines · Mark Lord

Con Kolivas wrote:
s go ahead and think up great ideas for other ways of metering out cpu

Quoted 5 lines

bandwidth for different purposes, but for X, given the absurd simplicity of renicing, why keep fighting it? Again I reiterate that most users of SD have not found the need to renice X anyway except if they stick to old habits of make -j4 on uniprocessor and the like, and I expect that those on CFS and Nicksched would also have similar experiences.

Quoted 7 lines
Quoted 5 lines

Just plain "make" (no -j2 or -j9999) is enough to kill interactivity on my 2GHz P-M single-core non-HT machine with SD.

But with the very first posted version of CFS by Ingo,
I can do "make -j2" no problem and still have a nicely interactive destop.

Cool. Then there's clearly a bug with SD that manifests on your machine as it should not have that effect at all (and doesn't on other people's machines). I suggest trying the latest version which fixes some bugs.

SD just doesn't do nearly as good as the stock scheduler, or CFS, here.

I'm quite likely one of the few single-CPU/non-HT testers of this stuff. If it should ever get more widely used I think we'd hear a lot more complaints.

Cheers

#251 lore raw

Re: Renice X for cpu schedulers

Quoted 18 lines · Mark Lord
Quoted 17 lines · Con Kolivas
Quoted 15 lines · Mark Lord

Con Kolivas wrote:
s go ahead and think up great ideas for other ways of metering out cpu

Quoted 5 lines

bandwidth for different purposes, but for X, given the absurd simplicity of renicing, why keep fighting it? Again I reiterate that most users of SD have not found the need to renice X anyway except if they stick to old habits of make -j4 on uniprocessor and the like, and I expect that those on CFS and Nicksched would also have similar experiences.

Just plain "make" (no -j2 or -j9999) is enough to kill interactivity on my 2GHz P-M single-core non-HT machine with SD.

But with the very first posted version of CFS by Ingo, I can do "make -j2" no problem and still have a nicely interactive destop.

Quoted 5 lines
Quoted 3 lines

Cool. Then there's clearly a bug with SD that manifests on your machine as it should not have that effect at all (and doesn't on other people's machines). I suggest trying the latest version which fixes some bugs.

SD just doesn't do nearly as good as the stock scheduler, or CFS, here.

I found the early SD's much friendlier here, but I also think that at that point I was comparing SD to stock 2.6.21-rc5 and 6, and to say that it sucked would be a slight understatement.

Quoted 3 lines

I'm quite likely one of the few single-CPU/non-HT testers of this stuff. If it should ever get more widely used I think we'd hear a lot more complaints.

I'm in that row of seats too Mark. Someday I have to build a new box, that's all there is to it...

Signature · 6 lines
Cheers, Gene
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
Lots of folks confuse bad management with destiny.
		-- Frank Hubbard
#252 lore raw

Re: Renice X for cpu schedulers

In reply to Mark Lord
Quoted 23 lines · Mark Lord
Quoted 14 lines · Con Kolivas
Quoted 13 lines · Mark Lord

Con Kolivas wrote:
s go ahead and think up great ideas for other ways of metering out cpu

Quoted 6 lines

bandwidth for different purposes, but for X, given the absurd simplicity of renicing, why keep fighting it? Again I reiterate that most users of SD have not found the need to renice X anyway except if they stick to old habits of make -j4 on uniprocessor and the like, and I expect that those on CFS and Nicksched would also have similar experiences.

Just plain "make" (no -j2 or -j9999) is enough to kill interactivity on my 2GHz P-M single-core non-HT machine with SD.

Quoted 7 lines
Quoted 3 lines

But with the very first posted version of CFS by Ingo, I can do "make -j2" no problem and still have a nicely interactive destop.

Cool. Then there's clearly a bug with SD that manifests on your machine as it should not have that effect at all (and doesn't on other people's machines). I suggest trying the latest version which fixes some bugs.

Quoted 5 lines

SD just doesn't do nearly as good as the stock scheduler, or CFS, here.

I'm quite likely one of the few single-CPU/non-HT testers of this stuff. If it should ever get more widely used I think we'd hear a lot more complaints.

You are not really one of the few. A lot of my own work is done on a single core pentium M 1.7Ghz laptop. I am not endowed with truckloads of hardware like all the paid developers are. I recall extreme frustration myself when a developer a few years ago (around 2002) said he couldn't reproduce poor behaviour on his 4GB ram 4 x Xeon machine. Even today if I add up every machine I have in my house and work at my disposal it doesn't amount to that many cpus and that much ram.

Signature · 1 line
-ck
#253 lore raw

Re: Renice X for cpu schedulers

In reply to Mark Lord
Quoted 16 lines · Mark Lord
Quoted 15 lines · Con Kolivas
Quoted 13 lines · Mark Lord

Con Kolivas wrote:
s go ahead and think up great ideas for other ways of metering out cpu

Quoted 5 lines

bandwidth for different purposes, but for X, given the absurd simplicity of renicing, why keep fighting it? Again I reiterate that most users of SD have not found the need to renice X anyway except if they stick to old habits of make -j4 on uniprocessor and the like, and I expect that those on CFS and Nicksched would also have similar experiences.

Just plain "make" (no -j2 or -j9999) is enough to kill interactivity on my 2GHz P-M single-core non-HT machine with SD.

But with the very first posted version of CFS by Ingo,
I can do "make -j2" no problem and still have a nicely interactive destop.

Quoted 8 lines
Quoted 3 lines

Cool. Then there's clearly a bug with SD that manifests on your machine as it should not have that effect at all (and doesn't on other people's machines). I suggest trying the latest version which fixes some bugs.

SD just doesn't do nearly as good as the stock scheduler, or CFS, here.

I'm quite likely one of the few single-CPU/non-HT testers of this stuff. If it should ever get more widely used I think we'd hear a lot more complaints.

amd64 UP here. SD with several makes running works just fine.

Ed Tomlinson

#254 lore raw

Re: Renice X for cpu schedulers

Quoted 7 lines · Ed Tomlinson
Quoted 5 lines

SD just doesn't do nearly as good as the stock scheduler, or CFS, here.

I'm quite likely one of the few single-CPU/non-HT testers of this stuff. If it should ever get more widely used I think we'd hear a lot more complaints.

amd64 UP here. SD with several makes running works just fine.

The thing is, it probably depends *heavily* on just how much work the X server ends up doing. Fast video hardware? The X server doesn't need to busy-wait much. Not a lot of eye-candy? The X server is likely fast enough even with a slower card that it still gets sufficient CPU time and isn't getting dinged by any balancing. DRI vs non-DRI? Which window manager (maybe some of the user-visible lags come from there..) etc etc.

Anyway, I'd ask people to look a bit at the current *regressions* instead of spending all their time on something that won't even be merged before 2.6.21 is released, and we thus have some mroe pressing issues. Please?

Linus

#255 lore raw

Re: Renice X for cpu schedulers

In reply to Mark Lord
Quoted 10 lines · Mark Lord

Con Kolivas wrote:
s go ahead and think up great ideas for other ways of metering out cpu

Quoted 5 lines

bandwidth for different purposes, but for X, given the absurd simplicity of renicing, why keep fighting it? Again I reiterate that most users of SD have not found the need to renice X anyway except if they stick to old habits of make -j4 on uniprocessor and the like, and I expect that those on CFS and Nicksched would also have similar experiences.

Just plain "make" (no -j2 or -j9999) is enough to kill interactivity on my 2GHz P-M single-core non-HT machine with SD.

Is this with or without X reniced?

Quoted 2 lines

But with the very first posted version of CFS by Ingo,
I can do "make -j2" no problem and still have a nicely interactive destop.

How well does cfs run if you have the granularity set to something like 30ms (30000000)?

#256 lore raw

Re: Renice X for cpu schedulers

Quoted 5 lines · Nick Piggin
Quoted 2 lines · Mark Lord

Just plain "make" (no -j2 or -j9999) is enough to kill interactivity on my 2GHz P-M single-core non-HT machine with SD.

Is this with or without X reniced?

That was with no manual jiggling, everything the same as with stock kernels, except that stock kernels don't kill interactivity here.

Quoted 5 lines
Quoted 2 lines

But with the very first posted version of CFS by Ingo,
I can do "make -j2" no problem and still have a nicely interactive destop.

How well does cfs run if you have the granularity set to something like 30ms (30000000)?

Dunno, I've put this stuff aside for now until things settle down. With four schedulers, and lots of patches / revisions / tuning-knobs, there's just no way to keep up with it all here.

Cheers

#257 lore raw

Re: Renice X for cpu schedulers

Just to throw another possibly-overlooked variable into the mess:

My system here is using the on-demand cpufreq policy governor. I wonder how that interacts with the various schedulers here?

I suppose for the "make" kernel case, after a couple of seconds the cpufreq would hit max and stay there for the rest of the build, so it shouldn't really be a factor for (non-)interactivity during the build.

Or should it?

Cheers

#258 lore raw

Re: Renice X for cpu schedulers

Quoted 11 lines · Mark Lord

Just to throw another possibly-overlooked variable into the mess:

My system here is using the on-demand cpufreq policy governor. I wonder how that interacts with the various schedulers here?

I suppose for the "make" kernel case, after a couple of seconds the cpufreq would hit max and stay there for the rest of the build, so it shouldn't really be a factor for (non-)interactivity during the build.

Or should it?

Short answer: shouldn't matter :)

Signature · 1 line
-ck
#259 lore raw

Re: Renice X for cpu schedulers

In reply to Con Kolivas
Quoted 3 lines · Con Kolivas

Ok, there are 3 known schedulers currently being "promoted" as solid replacements for the mainline scheduler which address most of the issues with mainline (and about 10 other ones not currently being promoted). The main way they do this is through attempting to maintain solid fairness. There is enough evidence mounting now from the numerous test cases fixed by much fairer designs that this is the way forward for a general purpose cpu scheduler which is what linux needs.

Interactivity of just about everything that needs low latency (ie audio and video players) are easily managed by maintaining low latency between wakeups and scheduling of all these low cpu users.

On a "fair" scheduler these will all get high priority (and good response) because their CPU bandwidth usage will be much smaller than their entitlement and the scheduler will be trying to help them "catch up". So (as you say) they shouldn't be a problem.

Quoted 1 line

The one fly in the ointment for linux remains X. I am still, to this moment, completely and utterly stunned at why everyone is trying to find increasingly complex unique ways to manage X when all it needs is more cpu[1]. Now most of these are actually very good ideas about _extra_ features that would be desirable in the long run for linux, but given the ludicrous simplicity of renicing X I cannot fathom why people keep promoting these alternatives. At the time of 2.6.0 coming out we were desparately trying to get half decent interactivity within a reasonable time frame to release 2.6.0 without rewiring the whole scheduler. So I tweaked the crap out of the tunables that were already there[2].

X's needs are more complex than that (from my observations) in that the part of X that processes input doesn't use much CPU but the part that does output can be quite a heavy user of CPU (e.g. do a "ls -lR /" in an xterm and watch X chew up the CPU). At the same time, the part of X that processes input needs quick responsiveness as it's part of the interactive chain where this is less so for the output part.

Where X comes unstuck in the current scheduler is that when the output part goes on one of its CPU storms it ceases to look like an interactive task and gets given lower priority. Ironically, this doesn't effect the output part of X but it does effect the input part and is manifest as crappy interactive response. One wonders whether modifying X so that it has two threads: one for output and one for input; that could be scheduled separately might help. I guess it would depend on whether there is insufficient independence between the two halves.

Part of this issue is that giving X a high static priority runs the risk of the CPU hog output part disrupting scheduling of other important tasks. So don't give it too big a boost.

Quoted 11 lines

So let's hear from the 3 people who generated the schedulers under the spotlight. These are recent snippets and by no means the only time these comments have been said. Without sounding too bold, we do know a thing or two about scheduling.

CFS:

Quoted 6 lines · Ingo Molnar

hmmmm. How about the following then: default to nice -10 for all (SCHED_NORMAL) kernel threads and all root-owned tasks. Root _is_
special: root already has disk space reserved to it, root has special memory allocation allowances, etc. I dont see a reason why we couldnt by default make all root tasks have nice -10. This would be instantly loved by sysadmins i suspect ;-)

It's worth noting that the -10 mentioned is roughly equivalent (in the old scheduler) to restoring interactive task status to X in those cases where it loses it due to a CPU storm in its output part.

Quoted 6 lines
Quoted 3 lines

(distros that go the extra mile of making Xorg run under non-root could also go another extra one foot to renice that X server to -10.)

Nicksched:
On Wednesday 18 April 2007 15:00, Nick Piggin wrote:

Quoted 8 lines
Quoted 2 lines

What's wrong with allowing X to get more than it's fair share of CPU time by "fiddling with nice levels"? That's what they're there for.

and

Staircase-Deadline:

Quoted 1 line · Con Kolivas

Remember to renice X to -10 for nicest desktop behaviour :)

I'd like to add the EBS scheduler (posted by Aurema Pty Ltd a couple of years back) to this list as it also recommended running X at nice -5 to -10.

Also some of the "interactive bonus" mechanisms in my SPA schedulers could be removed if X was reniced. In fact, with a reniced X the spa_svr (server oriented scheduler which attempts to minimise the time tasks spend on the queue waiting for CPU access and which doesn't have interactive bonuses) might be usable on a work station.

Quoted 9 lines

[1]The one caveat I can think of is that when you share X sessions across multiple users -with a fair cpu scheduler-, having them all nice 0 also makes the distribution of cpu across the multiple users very even and smooth, without the expense of burning away the other person's cpu time they'd like for compute intensive non gui things. If you make a scheduler that always favours X this becomes impossible. I've had enough users offlist ask me to help them set up multiuser environments just like this with my schedulers because they were unable to do it with mainline, even with SCHED_BATCH, short of nicing everything +19. This makes the argument for not favouring X within the scheduler with tweaks even stronger.

[2] Nick was promoting renicing X with his Nicksched alternative at the time of 2.6.0 and while we were not violently opposed to renicing X, Nicksched was still very new on the scene and didn't have the luxury of extended testing and reiteration in time for 2.6 and he put the project on hold for some time after that. The correctness of his views on renicing certainly have become more obvious over time.

So yes go ahead and think up great ideas for other ways of metering out cpu bandwidth for different purposes, but for X, given the absurd simplicity of renicing, why keep fighting it? Again I reiterate that most users of SD have not found the need to renice X anyway except if they stick to old habits of make -j4 on uniprocessor and the like, and I expect that those on CFS and Nicksched would also have similar experiences.

Peter

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#260 lore raw

Re: Renice X for cpu schedulers

Quoted 11 lines · Peter Williams
Quoted 2 lines · Con Kolivas

Ok, there are 3 known schedulers currently being "promoted" as solid replacements for the mainline scheduler which address most of the issues with mainline (and about 10 other ones not currently being promoted). The main way they do this is through attempting to maintain solid fairness. There is enough evidence mounting now from the numerous test cases fixed by much fairer designs that this is the way forward for a general purpose cpu scheduler which is what linux needs. Interactivity of just about everything that needs low latency (ie audio and video players) are easily managed by maintaining low latency between wakeups and scheduling of all these low cpu users.

On a "fair" scheduler these will all get high priority (and good response) because their CPU bandwidth usage will be much smaller than their entitlement and the scheduler will be trying to help them "catch up". So (as you say) they shouldn't be a problem.

Quoted 1 line

The one fly in the ointment for linux remains X. I am still, to this moment, completely and utterly stunned at why everyone is trying to find increasingly complex unique ways to manage X when all it needs is more cpu[1]. Now most of these are actually very good ideas about _extra_ features that would be desirable in the long run for linux, but given the ludicrous simplicity of renicing X I cannot fathom why people keep promoting these alternatives. At the time of 2.6.0 coming out we were desparately trying to get half decent interactivity within a reasonable time frame to release 2.6.0 without rewiring the whole scheduler. So I tweaked the crap out of the tunables that were already there[2].

X's needs are more complex than that (from my observations) in that the part of X that processes input doesn't use much CPU but the part that does output can be quite a heavy user of CPU (e.g. do a "ls -lR /" in an xterm and watch X chew up the CPU). At the same time, the part of X that processes input needs quick responsiveness as it's part of the interactive chain where this is less so for the output part.

Where X comes unstuck in the current scheduler is that when the output part goes on one of its CPU storms it ceases to look like an interactive task and gets given lower priority. Ironically, this doesn't effect the output part of X but it does effect the input part and is manifest as crappy interactive response. One wonders whether modifying X so that it has two threads: one for output and one for input; that could be scheduled separately might help. I guess it would depend on whether there is insufficient independence between the two halves.

I forgot to make my point here and that was that if X could be split in two neither half would need to be reniced. As a very low CPU bandwidth user the input half would get along just fine like the other interactive tasks that you mention. And the output put part isn't adversely effected by not having a boost so it would get along just fine as well and you don't want it having a boost when it's in a CPU storm anyway.

Of course, if the interdependence between the two halves is such that the equivalent of priority inversion occurs between the two threads. However, that might be solved by making the division between the two halves on a dimension other than the input/output one.

Peter
PS I think that the tasks most likely to be adversely effected by X's CPU storms (enough to annoy the user) are audio streamers so when you're doing tests to determine the best nice value for X I suggest that would be a good criterion. Video streamers are also susceptible but glitches in video don't seem to annoy users as much as audio ones.

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#261 lore raw

Re: Renice X for cpu schedulers

Quoted 5 lines · Peter Williams

PS I think that the tasks most likely to be adversely effected by X's CPU storms (enough to annoy the user) are audio streamers so when you're doing tests to determine the best nice value for X I suggest that would be a good criterion. Video streamers are also susceptible but glitches in video don't seem to annoy users as much as audio ones.

IMHO audio streamers should use SCHED_FIFO thread for time critical work. I think it's insane to expect the scheduler to figure out that these processes need low latency when they can just be explicit about it. "Professional" audio software does it already, on Linux as well as other OS...

Lee

#262 lore raw

Re: Renice X for cpu schedulers

Quoted 5 lines · Lee Revell

IMHO audio streamers should use SCHED_FIFO thread for time critical work. I think it's insane to expect the scheduler to figure out that these processes need low latency when they can just be explicit about it. "Professional" audio software does it already, on Linux as well as other OS...

It is certainly true that SCHED_FIFO is currently necessary in the layers of an audio application lying closest to the hardware, if you don't want to throw a monstrous hardware ring buffer at the problem. See the alsa-devel archives for a patch to aplay (sched_setscheduler plus some cleanups) that converts it from "unsafe at any speed" (on a non-RT kernel) to a rock-solid 18ms round trip from PCM in to PCM out. (The hardware and driver aren't terribly exotic for an SoC, and the measurement was done with aplay -C | aplay -P -- on a not-particularly-tuned CONFIG_PREEMPT kernel with a 12ms+ peak scheduling latency according to cyclictest. A similar test via /dev/dsp, done through a slightly modified OSS emulation layer to the same driver, measures at 40ms and is probably tuned too conservatively.)

Note that SCHED_FIFO may be less necessary on an -rt kernel, but I haven't had that option on the embedded hardware I've been working with lately. Ingo, please please pretty please pick a -stable branch one of these days and provide a git repo with -rt integrated against that branch. Then I could port our chip support to it -- all of which will be GPLed after the impending code review -- after which I might have a prayer of strong-arming our chip vendor into porting their WiFi driver onto -rt. It's really a much more interesting scheduler use case than make -j200 under X, because it's a best-effort SCHED_BATCH-ish load that wants to be temporally clustered for power management reasons.

(Believe it or not, a stable -rt branch with a clock-scaling-aware scheduler is the one thing that might lead to this major WiFi vendor's GPLing their driver core. They're starting to see the light on the biz dev side, and the nature of the devices their chip will go in makes them somewhat less concerned about the regulatory fig leaf aspect of a closed-source driver; but they would have to port off of the third-party real-time executive embedded within the driver, and mainline's task and timer granularity won't cut it. I can't even get more detail about _why_ it won't cut it unless there's some remotely supportable -rt base they could port to.)

But I think SCHED_FIFO on a chain of tasks is fundamentally not the right way to handle low audio latency. The object with a low latency requirement isn't the task, it's the device. When it's starting to get urgent to deliver more data to the device, the task that it's waiting on should slide up the urgency scale; and if it's waiting on something else, that something else should slide up the scale; and so forth. Similarly, responding to user input is urgent; so when user input is available (by whatever mechanism), the task that's waiting for it should slide up the urgency scale, etc.

In practice, you probably don't want to burden desktop Linux with priority inheritance where you don't have to. Priority queues with algorithmically efficient decrease-key operations (Fibonacci heaps and their ilk) are complicated to implement and have correspondingly high constant factors. (However, a sufficiently clever heuristic for assigning quasi-static task priorities would usually short-circuit the priority cascade; if you can keep N small in the tasks-with-unpredictable-priority queue, you can probably use a simpler flavor with O(log N) decrease-key. Ask someone who knows more about data structures than I do.)

More importantly, non-real-time application coders aren't very smart about grouping data structure accesses on one side or the other of a system call that is likely to release a lock and let something else run, flushing application data out of cache. (Kernel coders aren't always smart about this either; see LKML threads a few weeks ago about racy, and cache-stall-prone, f_pos handling in VFS.) So switching tasks immediately on lock release is usually the wrong thing to do if letting the task run a little longer would allow it to reach a point where it has to block anyway.

Anyway, I already described the urgency-driven strategy to the extent that I've thought it out, elsewhere in this thread. I only held this draft back because I wanted to double-check my latency measurements.

Cheers,
- Michael

#263 lore raw

Re: Renice X for cpu schedulers

Quoted 9 lines · Michael K. Edwards

But I think SCHED_FIFO on a chain of tasks is fundamentally not the right way to handle low audio latency. The object with a low latency requirement isn't the task, it's the device. When it's starting to get urgent to deliver more data to the device, the task that it's waiting on should slide up the urgency scale; and if it's waiting on something else, that something else should slide up the scale; and so forth. Similarly, responding to user input is urgent; so when user input is available (by whatever mechanism), the task that's waiting for it should slide up the urgency scale, etc.

DSP operations like, particularly with digital synthesis, tend to max the CPU doing vector operations on as many processors as it can get a hold of. In a live performance critical application, it's important to be able to deliver a protected amount of CPU to a thread doing that work as well as response to external input such as controllers, etc...

Quoted 10 lines

In practice, you probably don't want to burden desktop Linux with priority inheritance where you don't have to. Priority queues with algorithmically efficient decrease-key operations (Fibonacci heaps and their ilk) are complicated to implement and have correspondingly high constant factors. (However, a sufficiently clever heuristic for assigning quasi-static task priorities would usually short-circuit the priority cascade; if you can keep N small in the tasks-with-unpredictable-priority queue, you can probably use a simpler flavor with O(log N) decrease-key. Ask someone who knows more about data structures than I do.)

These are app issue and not really somethings that's mutable in kernel per se with regard to the -rt patch.

Quoted 9 lines

More importantly, non-real-time application coders aren't very smart about grouping data structure accesses on one side or the other of a system call that is likely to release a lock and let something else run, flushing application data out of cache. (Kernel coders aren't always smart about this either; see LKML threads a few weeks ago about racy, and cache-stall-prone, f_pos handling in VFS.) So switching tasks immediately on lock release is usually the wrong thing to do if letting the task run a little longer would allow it to reach a point where it has to block anyway.

I have Solaris style adaptive locks in my tree with my lockstat patch under -rt. I've also modified my lockstat patch to track readers correctly now with rwsem and the like to see where the single reader limitation in the rtmutex blows it.

So far I've seen less than 10 percent of in-kernel contention events actually worth spinning on and the rest of the stats imply that the mutex owner in question is either preempted or blocked on something else.

I've been trying to get folks to try this on a larger machine than my 2x AMD64 box so that I there is more data regarding Linux contention and overschedulling in -rt.

Quoted 3 lines

Anyway, I already described the urgency-driven strategy to the extent that I've thought it out, elsewhere in this thread. I only held this draft back because I wanted to double-check my latency measurements.

bill

#264 lore raw

Re: Renice X for cpu schedulers

Quoted 5 lines · hui Bill Huey

DSP operations like, particularly with digital synthesis, tend to max the CPU doing vector operations on as many processors as it can get a hold of. In a live performance critical application, it's important to be able to deliver a protected amount of CPU to a thread doing that work as well as response to external input such as controllers, etc...

Actual fractional CPU reservation is a bit different, and is probably best handled with "container"-type infrastructure (not quite virtualization, but not quite scheduling classes either). SGI pioneered this (in "open systems" space -- IBM probably had it first, as usual) with GRIO in XFS. (That was I/O throughput reservation of course, not "CPU bandwidth" -- but IIRC IRIX had CPU reservation too). There's a more general class of techniques in which it's worth spending idle cycles speculating along paths that might or might not be taken depending on unpredictable I/O; I'd be surprised if you couldn't approximate most of the sane balancing strategies in this area within the "economic dispatch" scheduler model. (Good JIT bytecode engines more or less do this already if you let them, with a cap on JIT cache size serving as a crude CPU throttle.)

Quoted 11 lines
Quoted 10 lines

In practice, you probably don't want to burden desktop Linux with priority inheritance where you don't have to. Priority queues with algorithmically efficient decrease-key operations (Fibonacci heaps and their ilk) are complicated to implement and have correspondingly high constant factors. (However, a sufficiently clever heuristic for assigning quasi-static task priorities would usually short-circuit the priority cascade; if you can keep N small in the tasks-with-unpredictable-priority queue, you can probably use a simpler flavor with O(log N) decrease-key. Ask someone who knows more about data structures than I do.)

Quoted 2 lines

These are app issue and not really somethings that's mutable in kernel per se with regard to the -rt patch.

I don't know where the -rt patch enters in. But if you need agile reprioritization with a deep runnable queue, either under direct application control or as a side effect of priority inheritance or a related OS-enforced protocol, then you need a kernel-level data structure with a fancier interface than the classic insert/find/delete-min priority queue. From what I've read (this is not my area of expertise and I don't have Knuth handy), the relatively simple heap-based implementations of priority queues can't reprioritize an entry any more quickly than find+delete+insert, which pretty much rules them out as a basis for a scalable scheduler with priority inheritance (let alone PCP emulation).

Quoted 4 lines

I have Solaris style adaptive locks in my tree with my lockstat patch under -rt. I've also modified my lockstat patch to track readers correctly now with rwsem and the like to see where the single reader limitation in the rtmutex blows it.

Ooh, that's neat. The next time I can cook up an excuse to run a kernel that won't load this damn WiFi driver, I'll try it out. Some of the people I work with are real engineers and respect in-system instrumentation.

Quoted 4 lines

So far I've seen less than 10 percent of in-kernel contention events actually worth spinning on and the rest of the stats imply that the mutex owner in question is either preempted or blocked on something else.

That's a good thing; it implies that in-kernel algorithms don't take locks needlessly as a matter of cargo-cult habit. Attempting to take a lock (other than an uncontended futex, which is practically free) should almost always transfer control to the thread that has the power to deliver the information (or the free slot) that you're looking for -- or in the case of an external data source/sink, should send you into low-power mode until time and tide give you something new to do. Think of it as a just-in-time inventory system; if you keep too much product in stock (or free warehouse space), you're wasting space and harming responsiveness to a shift in demand. Once in a while you have to play Sokoban in order to service a request promptly; that's exactly the case that priority inheritance is meant to help with.

The fiddly part, on a non-real-time-no-matter-what-the-label-says system with an opaque cache architecture and mysterious hidden costs of context switching, is to minimize the lossage resulting from brutal timer- or priority-inheritance-driven preemption. Given the way people code these days -- OK, it was probably just as bad back in the day -- the only thing worse than letting the axe fall at random is to steal the CPU away the moment a contended lock is released, because the next 20 lines of code probably poke one last time at all the data structures the task had in cache right before entering the critical section. That doesn't hurt so bad on RTOS-friendly hardware -- an MMU-less system with either zero or near-infinite cache -- but it's got to make this year's Intel/AMD/whatever kotatsu stall left and right when that task gets rescheduled.

Quoted 3 lines

I've been trying to get folks to try this on a larger machine than my 2x AMD64 box so that I there is more data regarding Linux contention and overschedulling in -rt.

Dave Miller, maybe? He seems to be one of the few people around here with the skills and the institutional motivation to push for scalability under the typical half-assed middle-tier application workload. Which, make no mistake, stands to benefit a lot more from a properly engineered SCHED_OTHER scheduler than any "real-time" media gadget that sells by the forklift-load at Fry's. (NUMA boxen might also benefit, but AFAICT their target applications are different enough not to count.) And if anyone from Cavium is lurking, now would be a real good time to show up and shoulder some of the load. Heck, even Intel ought to pitch in -- the Yonah team may have saved your ass for now, but you'll be playing the 32-thread throughput-per-erg stakes soon enough.

Cheers,
- Michael

#265 lore raw

Re: Renice X for cpu schedulers

Quoted 5 lines · Michael K. Edwards

Actual fractional CPU reservation is a bit different, and is probably best handled with "container"-type infrastructure (not quite virtualization, but not quite scheduling classes either). SGI pioneered this (in "open systems" space -- IBM probably had it first, as usual) with GRIO in XFS. (That was I/O throughput reservation of

I'm very aware of this having grow up on those systems and see what 30k USD of hardware can do for you with the right kernel facilties. It would be a mind blower to get OpenGL and friends back to that level of performance with regards to React/Pro's rt abilities, frame drop would just be gone and we'd own gaming. No joke.

We have a number of former SGI XFS engineers here at NetApp and I should ask them about the GRIO implementation.

Quoted 6 lines

course, not "CPU bandwidth" -- but IIRC IRIX had CPU reservation too). There's a more general class of techniques in which it's worth spending idle cycles speculating along paths that might or might not be taken depending on unpredictable I/O; I'd be surprised if you couldn't approximate most of the sane balancing strategies in this area within the "economic dispatch" scheduler model. (Good JIT

What is that ? never heard of it before.

Quoted 11 lines

I don't know where the -rt patch enters in. But if you need agile reprioritization with a deep runnable queue, either under direct application control or as a side effect of priority inheritance or a related OS-enforced protocol, then you need a kernel-level data structure with a fancier interface than the classic insert/find/delete-min priority queue. From what I've read (this is not my area of expertise and I don't have Knuth handy), the relatively simple heap-based implementations of priority queues can't reprioritize an entry any more quickly than find+delete+insert, which pretty much rules them out as a basis for a scalable scheduler with priority inheritance (let alone PCP emulation).

The -rt patch has turnstile-esque infrastructure that's stack allocated. Linux's lock hierarchy is relatively shallow (compensated with a heavy use of per CPU method and RCU-ified algorithms in place of rwlocks) so I've encountered nothing close to this that would demand such an overly sophisticated mechanism. I'm aware of PCP and preemptions thresholds. I created the lockstat infrastructure as a means of precisely measuring contention in -rt in anticipation to experiment with these techniques.

I mention -rt because it's the most likely place to encounter what you're talking about, not an app.

Quoted 2 lines
Quoted 2 lines

I have Solaris style adaptive locks in my tree with my lockstat patch under -rt. I've also modified my lockstat patch to track readers

...

Quoted 4 lines

Ooh, that's neat. The next time I can cook up an excuse to run a kernel that won't load this damn WiFi driver, I'll try it out. Some of the people I work with are real engineers and respect in-system instrumentation.

It's not publically released yet since I'm still stuck in .20-rc6 land and the soft lock up detector triggers. I need to forward port it and my lockstat changes to the most recent -rt patch.

I've been stalled on revision control problem that I'm trying to solve with monotone for at least a month (of my own spare time).

Quoted 2 lines

That's a good thing; it implies that in-kernel algorithms don't take locks needlessly as a matter of cargo-cult habit. Attempting to take

The jury is still out on this until I can record what the rtmutex owner's state is in. No further conclusion can be made until then. I think this is very interesting pursuit/investigation.

Quoted 11 lines

a lock (other than an uncontended futex, which is practically free) should almost always transfer control to the thread that has the power to deliver the information (or the free slot) that you're looking for -- or in the case of an external data source/sink, should send you into low-power mode until time and tide give you something new to do.

Think of it as a just-in-time inventory system; if you keep too much product in stock (or free warehouse space), you're wasting space and harming responsiveness to a shift in demand. Once in a while you have to play Sokoban in order to service a request promptly; that's exactly the case that priority inheritance is meant to help with.

What did you mean by this ? Victor Yodaiken's stuff ?

Quoted 7 lines

The fiddly part, on a non-real-time-no-matter-what-the-label-says system with an opaque cache architecture and mysterious hidden costs of context switching, is to minimize the lossage resulting from brutal timer- or priority-inheritance-driven preemption. Given the way people code these days -- OK, it was probably just as bad back in the day -- the only thing worse than letting the axe fall at random is to steal the CPU away the moment a contended lock is released, because

My adaptive spin stuff in front of an rtmutex is design to complement Steve Rostedt's owner stealing code also in that path and prevent this from happening. I record stealing events as well.

Quoted 6 lines

the next 20 lines of code probably poke one last time at all the data structures the task had in cache right before entering the critical section. That doesn't hurt so bad on RTOS-friendly hardware -- an MMU-less system with either zero or near-infinite cache -- but it's got to make this year's Intel/AMD/whatever kotatsu stall left and right when that task gets rescheduled.

Cache and tlb's are a bitch.

Quoted 5 lines
Quoted 3 lines

I've been trying to get folks to try this on a larger machine than my 2x AMD64 box so that I there is more data regarding Linux contention and overschedulling in -rt.

Dave Miller, maybe? He seems to be one of the few people around here

Don't know. I do know that somebody is going to try -rt on large hardware because they go some crazy app that needs both tons of CPU and rt abilties, like IRIX. I wouldn't mind the help and access to an 8x machine.

bill

#266 lore raw

Re: Renice X for cpu schedulers

In reply to Con Kolivas

On Thursday 19 April 2007, Con Kolivas wrote:

[and I snipped a good overview]

Quoted 6 lines

So yes go ahead and think up great ideas for other ways of metering out cpu bandwidth for different purposes, but for X, given the absurd simplicity of renicing, why keep fighting it? Again I reiterate that most users of SD have not found the need to renice X anyway except if they stick to old habits of make -j4 on uniprocessor and the like, and I expect that those on CFS and Nicksched would also have similar experiences.

FWIW folks, I have never touched x's niceness, its running at the default -1 for all of my so-called 'tests', and I have another set to be rebooted to right now. And yes, my kernel makeit script uses -j4 by default, and has used -j8 just for effects, which weren't all that different from what I expected in 'abusing' a UP system that way. The system DID remain usable, not snappy, but usable.

Having tried re-nicing X a while back, and having the rest of the system suffer in quite obvious ways for even 1 + or - from its default felt pretty bad from this users perspective.

It is my considered opinion (yeah I know, I'm just a leaf in the hurricane of this list) that if X has to be re-niced from the 1 point advantage its had for ages, then something is basicly wrong with the overall scheduling, cpu or i/o, or both in combination. FWIW I'm using cfq for i/o.

Signature · 7 lines
Cheers, Gene
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
Moore's Constant:
	Everybody sets out to do something, and everybody
	does something, but no one does what he sets out to do.
#267 lore raw

Re: Renice X for cpu schedulers

Quoted 8 lines · Gene Heskett

Having tried re-nicing X a while back, and having the rest of the system suffer in quite obvious ways for even 1 + or - from its default felt pretty bad from this users perspective.

It is my considered opinion (yeah I know, I'm just a leaf in the hurricane of this list) that if X has to be re-niced from the 1 point advantage its had for ages, then something is basicly wrong with the overall scheduling, cpu or i/o, or both in combination. FWIW I'm using cfq for i/o.

I think I just realized why the X server is such a problem. If it gets preempted when it's not actually selecting/polling over a set of fds that includes the input devices, the scheduler doesn't know that it's a good candidate for scheduling when data arrives on those devices. (That's all that any of these dynamic priority heuristics really seem to do -- weight the scheduler towards switching to conspicuously I/O bound tasks when they become runnable, without the forced preemption on lock release that would result from a true priority inheritance mechanism.)

One way of looking at this is that "fairness-driven" scheduling is a poor man's priority ceiling protocol for I/O bound workloads, with the implicit priority of an fd or lock given by how desperately the reader side needs more data in order to accomplish anything. "Nice" on a task is sort of an indirect way of boosting or dropping the base priority of the fds it commonly waits on. I recognize this is a drastic oversimplification, and possibly even a misrepresentation of the design _intent_; but I think it's fairly accurate in terms of the design _effect_.

The event-driven, non-threaded design of the X server makes it particularly vulnerable to "non-interactive behavior" penalties, which is appropriate to the extent that it's an output device having trouble keeping up with rendering -- in fact, that's exactly the throttling mechanism you need in order to exert back-pressure on the X client. (Trying to exert back-pressure over Linux's local domain sockets seems to be like pushing on a rope, but that's a different problem.) That same event-driven design would prioritize input events just fine -- except the scheduler won't wake the task in order to deliver them, because as far as it's concerned the X server is getting more than enough I/O to keep it busy. It's not only not blocked on the input device, it isn't even selecting on it at the moment that its timeslice expires -- so no amount of poor-man's PCP emulation is going to help.

What "more negative nice on the X server than on any CPU-bound process" seems to do is to put the X server on a hair-trigger, boosting its dynamic priority in a render-limited scenario (on some graphics cards!) just enough to cancel the penalty for non-interactive behavior. It's forced to share _some_ CPU cycles, but nobody else is allowed a long enough timeslice to keep the X server off the CPU (and insensitive to input events) for long. Not terribly efficient in terms of context switch / cache eviction overhead, but certainly friendlier to the PEBCAK (who is clearly putting totally inappropriate load on a single-threaded CPU by running both a local X server and non-SCHED_BATCH compute jobs) than a frozen mouse cursor.

So what's the right answer? Not special-casing the X server, that's for sure. If this analysis is correct (and as of now it's pure speculation), any event-driven application that does compute work opportunistically in the absence of user interaction is vulnerable to the same overzealous squelching. I wouldn't design a new application that way, of course -- user interaction belongs in a separate thread on any UNIX-legacy system which assigns priorities to threads of control instead of to patterns of activity. But all sorts of Linux applications have been designed to implicitly elevate artificial throughput benchmarks over user responsiveness -- that has been the UNIX way at least since SVR4, and Linux's history of expensive thread switches prior to NPTL didn't help.

If you want responsiveness when the CPU is oversubscribed -- and I for one do, which is one reason why I abandoned the Linux desktop once both Microsoft and Apple figured out how to make hyperthreading work in their favor -- you should probably think about how to get it without rewriting half of userspace. IMHO, dinking around with "fairness", as if there were any relationship these days between UIDs or process groups or any other control structure and the work that's trying to flow through the system, is not going to get you there.

If this were my problem, I might start by attaching urgency to behavior instead of to thread ID, which demands a scheduler queue built around a data structure with a cheap decrease-key operation. I'd figure out how to propagate this urgency not just along lock chains but also along chains of fds that need flushing (or refilling) -- even if the reader (or writer) got preempted for unrelated reasons. Tie appropriate urgency to audio and input devices, and SCHED_FIFO can pretty much go away along with nice -10 X.

Then I would use the fact that taking an uncontended futex is impressively cheap, ask Ulrich for an extra class of thread-private recursive mutexes streamlined for the never-contended case, and encourage application developers to use them to bracket any short section that would prefer not to have its cache footprint evicted out from under it. Unless things get pretty nasty, when you're too impatient to wait for a task to block, you want to preempt it at a local minimum in its working set; the easy way to do this is to have a per-CPU "soft preemption" timer that causes a per-CPU kernel thread to attempt to take the foreground task's thread-private mutex. The foreground task will then block on the next entry into a "cache-hot" section, and you can remember its appetite for CPU cycles by the urgency on its thread-private futex.

For better or for worse, this is far more work than _I'm_ likely to do on a volunteer basis, and whether or not this analysis is right, it is guaranteed to fail with -ENOPATCH.

Oh, by the way -- maybe someone should look at whether a little backpressure on /tmp/.X11-unix/X0 and friends helps, too. (Evidently it works right over pipes, or else hardly anything on Linux would DWIM.) That might succeed in papering over the problem, without requiring actual design effort before wading into the code. Then again, I haven't actually looked at the local domain socket code, so for all I know there's already backpressure there but X.org's excessive cleverness defeats it.

Cheers,
- Michael

#268 lore raw

Re: Renice X for cpu schedulers

In reply to Gene Heskett
Quoted 12 lines · Gene Heskett

On Thursday 19 April 2007, Con Kolivas wrote:

[and I snipped a good overview]

Quoted 7 lines

So yes go ahead and think up great ideas for other ways of metering out cpu bandwidth for different purposes, but for X, given the absurd simplicity of renicing, why keep fighting it? Again I reiterate that most users of SD have not found the need to renice X anyway except if they stick to old habits of make -j4 on uniprocessor and the like, and I expect that those on CFS and Nicksched would also have similar experiences.

Quoted 6 lines

FWIW folks, I have never touched x's niceness, its running at the default -1 for all of my so-called 'tests', and I have another set to be rebooted to right now. And yes, my kernel makeit script uses -j4 by default, and has used -j8 just for effects, which weren't all that different from what I expected in 'abusing' a UP system that way. The system DID remain usable, not snappy, but usable.

Gene, you're agreeing with me. You've shown that you're very happy with a fair distribution of cpu and leaving X at nice 0.

Quoted 9 lines

Having tried re-nicing X a while back, and having the rest of the system suffer in quite obvious ways for even 1 + or - from its default felt pretty bad from this users perspective.

It is my considered opinion (yeah I know, I'm just a leaf in the hurricane of this list) that if X has to be re-niced from the 1 point advantage its had for ages, then something is basicly wrong with the overall scheduling, cpu or i/o, or both in combination. FWIW I'm using cfq for i/o.

It's those who want X to have an unfair advantage that want it to do something "special". Your agreement that it works fine at nice 0 shows you don't want it to have an unfair advantage. Others who want it to have an unfair advantage _can_ renice it if they desire. But if the cpu scheduler gives X an unfair advantage within the kernel by default then you have _no_ choice. If you leave the choice up to userspace (renice or not) then both parties get their way. If you put it into the kernel only one party wins and there is no way for the Genes (and Cons) of this world to get it back.

Your opinion is as valuable as eveyone else's Gene. It is hard to get people to speak on as frightening a playground as the linux kernel mailing list so please do.

Signature · 1 line
-ck
#269 lore raw

Re: Renice X for cpu schedulers

Quoted 20 lines · Con Kolivas
Quoted 12 lines · Gene Heskett

On Thursday 19 April 2007, Con Kolivas wrote:

[and I snipped a good overview]

Quoted 7 lines

So yes go ahead and think up great ideas for other ways of metering out cpu bandwidth for different purposes, but for X, given the absurd simplicity of renicing, why keep fighting it? Again I reiterate that most users of SD have not found the need to renice X anyway except if they stick to old habits of make -j4 on uniprocessor and the like, and I expect that those on CFS and Nicksched would also have similar experiences.

Quoted 6 lines

FWIW folks, I have never touched x's niceness, its running at the default -1 for all of my so-called 'tests', and I have another set to be rebooted to right now. And yes, my kernel makeit script uses -j4 by default, and has used -j8 just for effects, which weren't all that different from what I expected in 'abusing' a UP system that way. The system DID remain usable, not snappy, but usable.

Quoted 2 lines

Gene, you're agreeing with me. You've shown that you're very happy with a fair distribution of cpu and leaving X at nice 0.

I was quite happy till Ingo's first patch came out, and it was even better, but I over-wrote it, and we're still figuring out just exactly what the magic twanger was that made it all click for me. OTOH, I don't think that patch passed muster with Mike G., either. We have obviously different workloads, and critical points in them.

Quoted 18 lines
Quoted 8 lines

Having tried re-nicing X a while back, and having the rest of the system suffer in quite obvious ways for even 1 + or - from its default felt pretty bad from this users perspective.

It is my considered opinion (yeah I know, I'm just a leaf in the hurricane of this list) that if X has to be re-niced from the 1 point advantage its had for ages, then something is basicly wrong with the overall scheduling, cpu or i/o, or both in combination. FWIW I'm using cfq for i/o.

It's those who want X to have an unfair advantage that want it to do something "special". Your agreement that it works fine at nice 0 shows you don't want it to have an unfair advantage. Others who want it to have an unfair advantage _can_ renice it if they desire. But if the cpu scheduler gives X an unfair advantage within the kernel by default then you have _no_ choice. If you leave the choice up to userspace (renice or not) then both parties get their way. If you put it into the kernel only one party wins and there is no way for the Genes (and Cons) of this world to get it back.

Quoted 3 lines

Your opinion is as valuable as eveyone else's Gene. It is hard to get people to speak on as frightening a playground as the linux kernel mailing list so please do.

In the FWIW category, htop has always told me that x is running at -1, not zero. Now, I have NDI where this is actually set at, so I'd have to ask stupid questions here if I did wanna play with it. Which I really don't, the last time I tried to -5 x, kde got a whole lot LESS responsive. But heck, 2.6.2 was freshly minted then too and I've long since forgot how I went about that unless I used htop to change it, the most likely scenario that I can picture at this late date.

As for speaking my mind, yes, and I've been slapped down a few times, as much because I do a lot of bitching and microscopic amounts of patch submission. The only patch I ever submitted was for something in the floppy driver, way back in the middle of 2.2 days, rejected because I didn't know how to use the tools correctly. I didn't, so it was a shrug and my feelings weren't hurt.

Some see that as an unbalanced set of books and I'm aware of it. OTOH, I think I do a pretty good job of playing the canary here, and that should be worth something if for no other reason than I can turn into a burr under somebodies saddle when things go all aglay. But I figure if its happening to me, then if I don't fuss, and that gotcha gets into a distro kernel, there are gonna be a hell of a lot more folks than me trying to grab the microphone.

BTW, I'm glad you are feeling well enough to get into this again.

Signature · 6 lines
Cheers, Gene
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
There cannot be a crisis next week.  My schedule is already full.
		-- Henry Kissinger
#270 lore raw

Re: Renice X for cpu schedulers

In reply to Con Kolivas
Quoted 20 lines · Con Kolivas
Quoted 12 lines · Gene Heskett

On Thursday 19 April 2007, Con Kolivas wrote:

[and I snipped a good overview]

Quoted 7 lines

So yes go ahead and think up great ideas for other ways of metering out cpu bandwidth for different purposes, but for X, given the absurd simplicity of renicing, why keep fighting it? Again I reiterate that most users of SD have not found the need to renice X anyway except if they stick to old habits of make -j4 on uniprocessor and the like, and I expect that those on CFS and Nicksched would also have similar experiences.

Quoted 6 lines

FWIW folks, I have never touched x's niceness, its running at the default -1 for all of my so-called 'tests', and I have another set to be rebooted to right now. And yes, my kernel makeit script uses -j4 by default, and has used -j8 just for effects, which weren't all that different from what I expected in 'abusing' a UP system that way. The system DID remain usable, not snappy, but usable.

Quoted 2 lines

Gene, you're agreeing with me. You've shown that you're very happy with a fair distribution of cpu and leaving X at nice 0.

I was quite happy till Ingo's first patch came out, and it was even better, but I over-wrote it, and we're still figuring out just exactly what the magic twanger was that made it all click for me. OTOH, I don't think that patch passed muster with Mike G., either. We have obviously different workloads, and critical points in them.

Quoted 18 lines
Quoted 8 lines

Having tried re-nicing X a while back, and having the rest of the system suffer in quite obvious ways for even 1 + or - from its default felt pretty bad from this users perspective.

It is my considered opinion (yeah I know, I'm just a leaf in the hurricane of this list) that if X has to be re-niced from the 1 point advantage its had for ages, then something is basicly wrong with the overall scheduling, cpu or i/o, or both in combination. FWIW I'm using cfq for i/o.

It's those who want X to have an unfair advantage that want it to do something "special". Your agreement that it works fine at nice 0 shows you don't want it to have an unfair advantage. Others who want it to have an unfair advantage _can_ renice it if they desire. But if the cpu scheduler gives X an unfair advantage within the kernel by default then you have _no_ choice. If you leave the choice up to userspace (renice or not) then both parties get their way. If you put it into the kernel only one party wins and there is no way for the Genes (and Cons) of this world to get it back.

Quoted 3 lines

Your opinion is as valuable as eveyone else's Gene. It is hard to get people to speak on as frightening a playground as the linux kernel mailing list so please do.

In the FWIW category, htop has always told me that x is running at -1, not zero. Now, I have NDI where this is actually set at, so I'd have to ask stupid questions here if I did wanna play with it. Which I really don't, the last time I tried to -5 x, kde got a whole lot LESS responsive. But heck, 2.6.2 was freshly minted then too and I've long since forgot how I went about that unless I used htop to change it, the most likely scenario that I can picture at this late date.

As for speaking my mind, yes, and I've been slapped down a few times, as much because I do a lot of bitching and microscopic amounts of patch submission. The only patch I ever submitted was for something in the floppy driver, way back in the middle of 2.2 days, rejected because I didn't know how to use the tools correctly. I didn't, so it was a shrug and my feelings weren't hurt.

Some see that as an unbalanced set of books and I'm aware of it. OTOH, I think I do a pretty good job of playing the canary here, and that should be worth something if for no other reason than I can turn into a burr under somebodies saddle when things go all aglay. But I figure if its happening to me, then if I don't fuss, and that gotcha gets into a distro kernel, there are gonna be a hell of a lot more folks than me trying to grab the microphone.

BTW, I'm glad you are feeling well enough to get into this again.

Signature · 6 lines
Cheers, Gene
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
There cannot be a crisis next week.  My schedule is already full.
		-- Henry Kissinger
#271 lore raw

Re: Renice X for cpu schedulers

In reply to Con Kolivas
Quoted 2 lines · Con Kolivas

It's those who want X to have an unfair advantage that want it to do something "special".

I hope you're not lumping me in with "those". If X + client had been able to get their fair share and do so in the low latency manner they need, I would have been one of the carrots instead of being the stick.

-Mike

#272 lore raw

Re: Renice X for cpu schedulers

In reply to Con Kolivas
Quoted 4 lines · Con Kolivas

The one fly in the ointment for
linux remains X. I am still, to this moment, completely and utterly stunned at why everyone is trying to find increasingly complex unique ways to manage X when all it needs is more cpu[1].

[...and hence should be reniced]

The problem is that X is not unique. There's postgresql, memcached, mysql, db2, a little embedded app I wrote... all of these perform work on behalf of another process. It's just most *noticeable* with X, as pretty much everyone is running that.

If we had some way for the scheduler to decide to donate part of a client process's time slice to the server it just spoke to (with an exponential dampening factor -- take 50% from the client, give 25% to the server, toss the rest on the floor), that -- from my naive point of view -- would be a step toward fixing the underlying issue. Or I might be spouting crap, who knows.

The problem is real, though, and not limited to X.

While I have the floor, thank you, Con, for all your work.

Ray

#273 lore raw

Re: Renice X for cpu schedulers

Quoted 20 lines · Ray Lee
Quoted 4 lines · Con Kolivas

The one fly in the ointment for
linux remains X. I am still, to this moment, completely and utterly stunned at why everyone is trying to find increasingly complex unique ways to manage X when all it needs is more cpu[1].

[...and hence should be reniced]

The problem is that X is not unique. There's postgresql, memcached, mysql, db2, a little embedded app I wrote... all of these perform work on behalf of another process. It's just most *noticeable* with X, as pretty much everyone is running that.

If we had some way for the scheduler to decide to donate part of a client process's time slice to the server it just spoke to (with an exponential dampening factor -- take 50% from the client, give 25% to the server, toss the rest on the floor), that -- from my naive point of view -- would be a step toward fixing the underlying issue. Or I might be spouting crap, who knows.

Quoted 3 lines

The problem is real, though, and not limited to X.

While I have the floor, thank you, Con, for all your work.

You're welcome and thanks for taking the floor to speak. I would say you have actually agreed with me though. X is not unique, it's just an obvious so let's not design the cpu scheduler around the problem with X. Same goes for every other application. Leaving the choice to hand out differential cpu usage when they seem to need is should be up to the users. The donation idea has been done before in some fashion or other in things like "back-boost" which Linus himself tried in 2.5.X days. It worked lovely till it did the wrong thing and wreaked havoc. As is shown repeatedly, the workarounds and the tweaks and the bonuses and the decide on who to give advantage to, when done by the cpu scheduler, is also what is its undoing as it can't always get it right. The consequences of getting it wrong on the other hand are disastrous. The cpu scheduler core is a cpu bandwidth and latency proportionator and should be nothing more or less.

Signature · 1 line
-ck
#274 lore raw

Re: Renice X for cpu schedulers

Quoted 2 lines · Con Kolivas

The cpu scheduler core is a cpu bandwidth and latency proportionator and should be nothing more or less.

Not really. The CPU scheduler is (or ought to be) what electric utilities call an economic dispatch mechanism -- a real-time controller whose goal is to service competing demands cost-effectively from a limited supply, without compromising system stability.

If you live in the 1960's, coal and nuclear (and a little bit of fig-leaf hydro) are all you have, it takes you twelve hours to bring plants on and off line, and there's no live operational control or pricing signal between you and your customers. So you're stuck running your system at projected peak + operating margin, dumping excess power as waste heat most of the time, and browning or blacking people out willy-nilly when there's excess demand. Maybe you get to trade off shedding the loads with the worst transmission efficiency against degrading the customers with the most tolerance for brownouts (or the least regulatory clout). That's life without modern economic dispatch.

If you live in 2007, natural gas and (outside the US) better control over nuclear plants give you more ability to ramp supply up and down with demand on something like a 15-minute cycle. Better yet, you can store a little energy "in the grid" to smooth out instantaneous demand fluctuations; if you're lucky, you also have enough fast-twitch hydro (thanks, Canada!) that you can run your coal and lame-ass nuclear very close to base load even when gas is expensive, and even pump water back uphill when demand dips. (Coal is nasty stuff and a worse contributor by far to radiation exposure than nuclear generation; but on current trends it's going to last a lot longer than oil and gas, and it's a lot easier to stockpile next to the generator.)

Best of all, you have industrial customers who will trade you live control (within limits) over when and how much power they take in return for a lower price per unit energy. Some of them will even dump power back into the grid when you ask them to. So now the biggest challenge in making supply and demand meet (in the short term) is to damp all the different ways that a control feedback path might result in an oscillation -- or in runaway pricing. Because there's always some asshole greedhead who will gamble with system stability in order to game the pricing mechanism. Lots of 'em, if you're in California and your legislature is so dumb, or so bought, that they let the asshole greedheads design the whole system so they can game it to the max. (But that's a whole 'nother rant.)

Embedded systems are already in 2007, and the mainline Linux scheduler frankly sucks on them, because it thinks it's back in the 1960's with a fixed supply and captive demand, pissing away "CPU bandwidth" as waste heat. Not to say it's an easy problem; even academics with a dozen publications in this area don't seem to be able to model energy usage to the nearest big O, let alone design a stable economic dispatch engine. But it helps to acknowledge what the problem is:
even in a 1960's raised-floor screaming-air-conditioners screw-the-power-bill machine room, you can't actually run a half-decent CPU flat out any more without burning it to a crisp.

You can act ignorant and let the PMIC brown you out when it has to. Or you can start coping in mainline the way that organizations big enough (and smart enough) to feel the heat in their pocketbooks do in their pet kernels. (Boo on Google for not sharing, and props to IBM for doing their damnedest.) And guess what? The system will actually get simpler, and stabler, and faster, and easier to maintain, because it'll be based on a real theory of operation with equations and things instead of a bunch of opaque, undocumented shotgun heuristics.

This hypothetical economic-dispatch scheduler will still _have_ heuristics, of course -- you can't begin to model a modern CPU accurately on-line. But they will be contained in _data_ rather than _code_, and issues of numerical stability will be separated cleanly from the rule set. You'll be able to characterize the rule set's domain of stability, given a conservative set of assumptions about the feedback paths in the system under control, with the sort of techniques they teach in the engineering schools that none of us (me included) seem to have attended. (I went to school thinking I was going to be a physicist. Wishful thinking -- but I was young and stupid. What's your excuse? ;-)

OK, it feels better to have that off my chest. Apologies to those readers -- doubtless the vast majority of LKML, including everyone else in this thread -- for whom it's irrelevant, pseudo-learned pontification with no patch attached. And my sincere thanks to Ingo, Con, and really everyone else CC'ed, without whom Linux wouldn't be as good as it is (really quite good, all things considered) and wouldn't contribute as much as it does to my own livelihood.

Cheers,
- Michael

#275 lore raw

Re: Renice X for cpu schedulers

Quoted 11 lines · Michael K. Edwards

Embedded systems are already in 2007, and the mainline Linux scheduler frankly sucks on them, because it thinks it's back in the 1960's with a fixed supply and captive demand, pissing away "CPU bandwidth" as waste heat. Not to say it's an easy problem; even academics with a dozen publications in this area don't seem to be able to model energy usage to the nearest big O, let alone design a stable economic dispatch engine. But it helps to acknowledge what the problem is:
even in a 1960's raised-floor screaming-air-conditioners screw-the-power-bill machine room, you can't actually run a half-decent CPU flat out any more without burning it to a crisp. stupid. What's your excuse? ;-)

It's now possible to QoS significant parts of the kernel since we now have a deadline mechanism in place. In the original 2.4 kernel, TimeSys's irq-thread allowed for the processing of skbuffs in a thread under a CPU reservation run category which was use to provide QoS I believe. This basic mechanish can now be generalized to many place in the kernel and put it under scheduler control.

It's just a matter of who and when somebody is going take on this task.

bill

#276 lore raw

Re: Renice X for cpu schedulers

In reply to Con Kolivas
Quoted 8 lines · Con Kolivas

You're welcome and thanks for taking the floor to speak. I would say you have actually agreed with me though. X is not unique, it's just an obvious so let's not design the cpu scheduler around the problem with X. Same goes for every other application. Leaving the choice to hand out differential cpu usage when they seem to need is should be up to the users. The donation idea has been done before in some fashion or other in things like "back-boost" which Linus himself tried in 2.5.X days. It worked lovely till it did the wrong thing and wreaked havoc.

<nod> I know. I came to the party late, or I would have played with it back then. Perhaps you could correct me, but it seems his back-boost didn't do any dampening, which means the system could get into nasty capture scenarios, where two processes bouncing messages back and forth could take over the scheduler and starve out the rest. It seems pretty obvious in hind-sight that something without exponential dampening would allow feedback loops.

Regardless, perhaps we are in agreement. I just don't like the idea of having to guess how much work postgresql is going to be doing on my client processes' behalf. Worse, I don't necessarily want it to have that -10 priority when it's going and updating statistics or whatnot, or any other housekeeping activity that shouldn't make a noticeable impact on the rest of the system. Worst, I'm leery of the idea that if I get its nice level wrong, that I'm going to be affecting the overall throughput of the server.

All of which are only hypothetical worries, granted.

Anyway, I'll shut up now. Thanks again for stickin' with it.

Ray

#277 lore raw

Re: Renice X for cpu schedulers

In reply to Ray Lee
Quoted 6 lines · Ray Lee
Quoted 5 lines · Con Kolivas

The one fly in the ointment for
linux remains X. I am still, to this moment, completely and utterly stunned at why everyone is trying to find increasingly complex unique ways to manage
X when all it needs is more cpu[1].

Quoted 6 lines

[...and hence should be reniced]

The problem is that X is not unique. There's postgresql, memcached, mysql, db2, a little embedded app I wrote... all of these perform work on behalf of another process. It's just most *noticeable* with X, as pretty much everyone is running that.

But for most of those apps, we don't actually care if they do fairly degrade in performance as other loads on the system ramp up. However the user prefers X to be given priority in these situations. Whether that is the design of X, x clients, or the human condition really doesn't matter two hoots to the scheduler.

Quoted 6 lines

If we had some way for the scheduler to decide to donate part of a client process's time slice to the server it just spoke to (with an exponential dampening factor -- take 50% from the client, give 25% to the server, toss the rest on the floor), that -- from my naive point of view -- would be a step toward fixing the underlying issue. Or I might be spouting crap, who knows.

Firstly, lots of clients in your list are remote. X usually isn't. However for X, a syscall or something to donate time might not be such a bad idea... but given a couple of X clients and a server against a parallel make, this is probably just going to make the clients slow down as well without giving enough priority to the server.

X isn't special so much because it does work on behalf of others (as you said, lots of things do that). It is special simply because we _want_ rendering to have priority of the CPU (if you shifed CPU intensive rendering to the clients, you'd most likely want to give them priority to); nice, right?

#278 lore raw

Re: Renice X for cpu schedulers

Quoted 9 lines · Nick Piggin
Quoted 8 lines · Ray Lee
Quoted 5 lines · Con Kolivas

The one fly in the ointment for
linux remains X. I am still, to this moment, completely and utterly stunned at why everyone is trying to find increasingly complex unique ways to manage
X when all it needs is more cpu[1].

[...and hence should be reniced]

Quoted 7 lines
Quoted 4 lines

The problem is that X is not unique. There's postgresql, memcached, mysql, db2, a little embedded app I wrote... all of these perform work on behalf of another process. It's just most *noticeable* with X, as pretty much everyone is running that.

But for most of those apps, we don't actually care if they do fairly degrade in performance as other loads on the system ramp up.

(Who's this 'we' kemosabe? I do. Desktop systems are increasingly using databases for their day-to-day tasks. As they should, a db is not something that should be reinvented poorly.)

Quoted 4 lines

However
the user prefers X to be given priority in these situations. Whether that is the design of X, x clients, or the human condition really doesn't matter two hoots to the scheduler.

Hmm, let's try this again. Anything that communicates out of process as part of its normal usage for Getting Work Done gets impacted by the scheduler. That means pipelines in the shell, d-bus on the desktop, and lots of other things that follow the unix philosophy of lots of little programs communicating.

Quoted 8 lines
Quoted 6 lines

If we had some way for the scheduler to decide to donate part of a client process's time slice to the server it just spoke to (with an exponential dampening factor -- take 50% from the client, give 25% to the server, toss the rest on the floor), that -- from my naive point of view -- would be a step toward fixing the underlying issue. Or I might be spouting crap, who knows.

Firstly, lots of clients in your list are remote. X usually isn't.

They really aren't, unless you happen to work somewhere that can afford to dedicate a box to a db, which suddenly makes the scheduler a dull topic.

For example, I have a db and web server installed on my laptop, so that the few times that I have to do web app programming (while wearing a mustache and glasses so that I don't have to admit to it in polite company), I can be functional with just one computer.

Quoted 2 lines

However for X, a syscall or something to donate time might not be such a bad idea...

We have one already, it's called write(). We have another called read(), too. Okay, so they have some data related side-effects other than the scheduler hints, but I claim the scheduler hint is already implicitly there.

Quoted 4 lines

but given a couple of X clients and a server
against a parallel make, this is probably just going to make the clients slow down as well without giving enough priority to the server.

Do you have data, or at least a theory to back up that hypothesis?

Quoted 3 lines

X isn't special so much because it does work on behalf of others (as you said, lots of things do that). It is special simply because we _want_ rendering to have priority of the CPU

Really not. I'm trying to get across that this is a general problem with interprocess communication, or any systems that rely on multiple processes to make forward progress on a problem. Sure, let the clients make forward progress until they can't any more. If they stop making forward progress by blocking on a read or sleeping after a write to another process, then there's a big hint there as to who should get focus next.

Quoted 3 lines

(if you shifed CPU
intensive rendering to the clients, you'd most likely want to give them priority to); nice, right?

They'd have it automatically, if they were spending their time computing rather than rendering.

Ray

#279 lore raw

Re: Renice X for cpu schedulers

Quoted 10 lines · Ray Lee
Quoted 1 line

Firstly, lots of clients in your list are remote. X usually isn't.

They really aren't, unless you happen to work somewhere that can afford to dedicate a box to a db, which suddenly makes the scheduler a dull topic.

For example, I have a db and web server installed on my laptop, so that the few times that I have to do web app programming (while wearing a mustache and glasses so that I don't have to admit to it in polite company), I can be functional with just one computer.

Indeed. The vast majority of people doing "LAMP" web services are doing it on a single machine. Or VM for that matter.

It seems that this is a lot like the priority inheritance problem. If a nice -19 process blocks on the db running at nice 0, the db ought to get a boost until it wakes the original process up. The same should apply at the level of dynamic priorities at the same nice level.

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#280 lore raw
In reply to Linus Torvalds
Quoted 7 lines · Linus Torvalds
Quoted 4 lines · Matt Mackall

Why is X special? Because it does work on behalf of other processes? Lots of things do this. Perhaps a scheduler should focus entirely on the implicit and directed wakeup matrix and optimizing that instead[1].

Quoted 8 lines

I 100% agree - the perfect scheduler would indeed take into account where the wakeups come from, and try to "weigh" processes that help other processes make progress more. That would naturally give server processes more CPU power, because they help others

I don't believe for a second that "fairness" means "give everybody the same amount of CPU". That's a totally illogical measure of fairness. All processes are _not_ created equal.

That said, even trying to do "fairness by effective user ID" would probably already do a lot. In a desktop environment, X would get as much CPU time as the user processes, simply because it's in a different protection domain (and that's really what "effective user ID" means: it's not about "users", it's really about "protection domains").

And "fairness by euid" is probably a hell of a lot easier to do than trying to figure out the wakeup matrix.

You probably want to consider the controlling terminal as well... do you want to have people starting 'at' jobs competing on equal footing with people typing at a terminal? I'm not offering an answer, just raising the question.

And for some database applications, everyone in a group may connect with the same login-id, then do sub authorization to the database application. euid may be an issue there as well.

Signature · 3 lines
Bill Davidsen <[email protected]>
  "We have more to fear from the bungling of the incompetent than from
the machinations of the wicked."  - from Slashdot
#281 lore raw
In reply to Nick Piggin
Quoted 4 lines · Nick Piggin
Quoted 1 line

All things are not equal; they all have different properties. I like

Exactly. So we have to explore those properties and evaluate performance (in all meanings of the word). That's only logical.

I had a quick look at Ingo's code yesterday. Ingo is always smart to prepare a main dish (feature) with a nice sider (code cleanup) to Linus ;) And even this code does that pretty nicely. The deadline designs looks good, although I think the final "key" calculation code will end up quite different from what it looks now.
I would suggest to thoroughly test all your alternatives before deciding. Some code and design may look very good and small at the beginning, but when you start patching it to cover all the dark spots, you effectively end up with another thing (in both design and code footprint). About O(1), I never thought it was a must (besides a good marketing material), and O(log(N)) *may* be just fine (to be verified, of course).

- Davide

#282 lore raw
Quoted 5 lines · Davide Libenzi

I had a quick look at Ingo's code yesterday. Ingo is always smart to prepare a main dish (feature) with a nice sider (code cleanup) to Linus ;) And even this code does that pretty nicely. The deadline designs looks good, although I think the final "key" calculation code will end up quite different from what it looks now.

The additive nice_offset breaks nice levels. A multiplicative priority weighting of a different, nonnegative metric of cpu utilization from what's now used is required for nice levels to work. I've been trying to point this out politely by strongly suggesting testing whether nice levels work.

Quoted 6 lines · Davide Libenzi

I would suggest to thoroughly test all your alternatives before deciding. Some code and design may look very good and small at the beginning, but when you start patching it to cover all the dark spots, you effectively end up with another thing (in both design and code footprint). About O(1), I never thought it was a must (besides a good marketing material), and O(log(N)) *may* be just fine (to be verified, of course).

The trouble with thorough testing right now is that no one agrees on what the tests should be and a number of the testcases are not in great shape. An agreed-upon set of testcases for basic correctness should be devised and the implementations of those testcases need to be maintainable code and the tests set up for automated testing and changing their parameters without recompiling via command-line options.

Once there's a standard regression test suite for correctness, one needs to be devised for performance, including interactive performance. The primary difficulty I see along these lines is finding a way to automate tests of graphics and input device response performance. Others, like how deterministically priorities are respected over progressively smaller time intervals and noninteractive workload performance are nowhere near as difficult to arrange and in many cases already exist. Just reuse SDET, AIM7/AIM9, OAST, contest, interbench, et al.

-- wli

#283 lore raw
Quoted 22 lines · William Lee Irwin III
Quoted 2 lines · Davide Libenzi

I had a quick look at Ingo's code yesterday. Ingo is always smart to prepare a main dish (feature) with a nice sider (code cleanup) to Linus ;)
And even this code does that pretty nicely. The deadline designs looks good, although I think the final "key" calculation code will end up quite different from what it looks now.

The additive nice_offset breaks nice levels. A multiplicative priority weighting of a different, nonnegative metric of cpu utilization from what's now used is required for nice levels to work. I've been trying to point this out politely by strongly suggesting testing whether nice levels work.

Quoted 2 lines · Davide Libenzi

I would suggest to thoroughly test all your alternatives before deciding. Some code and design may look very good and small at the beginning, but when you start patching it to cover all the dark spots, you effectively end up with another thing (in both design and code footprint). About O(1), I never thought it was a must (besides a good marketing material), and O(log(N)) *may* be just fine (to be verified, of course).

The trouble with thorough testing right now is that no one agrees on what the tests should be and a number of the testcases are not in great shape. An agreed-upon set of testcases for basic correctness should be devised and the implementations of those testcases need to be maintainable code and the tests set up for automated testing and changing their parameters without recompiling via command-line options.

Quoted 8 lines

Once there's a standard regression test suite for correctness, one needs to be devised for performance, including interactive performance. The primary difficulty I see along these lines is finding a way to automate tests of graphics and input device response performance. Others, like how deterministically priorities are respected over progressively smaller time intervals and noninteractive workload performance are nowhere near as difficult to arrange and in many cases already exist. Just reuse SDET, AIM7/AIM9, OAST, contest, interbench, et al.

At this point, I'd like direct everyone's attention to the simloads package:

<http://downloads.sourceforge.net/cpuse/simloads-0.1.1.tar.gz>

which contains a set of programs designed to be used in the construction of CPU scheduler tests. Of particular use is the aspin program which can be used to launch tasks with specified sleep/wake characteristics.

Peter

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#284 lore raw
In reply to William Lee Irwin III
Quoted 8 lines · William Lee Irwin III

The trouble with thorough testing right now is that no one agrees on what the tests should be and a number of the testcases are not in great shape. An agreed-upon set of testcases for basic correctness should be devised and the implementations of those testcases need to be maintainable code and the tests set up for automated testing and changing their parameters without recompiling via command-line options.

Quoted 8 lines

Once there's a standard regression test suite for correctness, one needs to be devised for performance, including interactive performance. The primary difficulty I see along these lines is finding a way to automate tests of graphics and input device response performance. Others, like how deterministically priorities are respected over progressively smaller time intervals and noninteractive workload performance are nowhere near as difficult to arrange and in many cases already exist. Just reuse SDET, AIM7/AIM9, OAST, contest, interbench, et al.

Definitely. It would be really good if we could have interactivity regression tests too (see my earlier wishful email). The problem with a lot of the scripted interactivity tests I see is that they don't really capture the complexities of the interactions between, say, an interactive X session. Others just go straight for trying to exploit the design by making lots of high priority processes runnablel at once. This just provides an unrealistic decoy and you end up trying to tune for the wrong thing.

#285 lore raw
In reply to William Lee Irwin III
Quoted 15 lines · William Lee Irwin III
Quoted 6 lines · Davide Libenzi

I would suggest to thoroughly test all your alternatives before deciding. Some code and design may look very good and small at the beginning, but when you start patching it to cover all the dark spots, you effectively end up with another thing (in both design and code footprint). About O(1), I never thought it was a must (besides a good marketing material), and O(log(N)) *may* be just fine (to be verified, of course).

The trouble with thorough testing right now is that no one agrees on what the tests should be and a number of the testcases are not in great shape. An agreed-upon set of testcases for basic correctness should be devised and the implementations of those testcases need to be maintainable code and the tests set up for automated testing and changing their parameters without recompiling via command-line options.

Quoted 8 lines

Once there's a standard regression test suite for correctness, one needs to be devised for performance, including interactive performance. The primary difficulty I see along these lines is finding a way to automate tests of graphics and input device response performance. Others, like how deterministically priorities are respected over progressively smaller time intervals and noninteractive workload performance are nowhere near as difficult to arrange and in many cases already exist. Just reuse SDET, AIM7/AIM9, OAST, contest, interbench, et al.

What I meant was, that the rules (requirements and associated test cases) for this new Scheduler Amazing Race should be set forward, and not kept a moving target to fit&follow one or the other implementation.

- Davide

#286 lore raw
Quoted 26 lines · Davide Libenzi
Quoted 15 lines · William Lee Irwin III
Quoted 6 lines · Davide Libenzi

I would suggest to thoroughly test all your alternatives before deciding. Some code and design may look very good and small at the beginning, but when you start patching it to cover all the dark spots, you effectively end up with another thing (in both design and code footprint). About O(1), I never thought it was a must (besides a good marketing material), and O(log(N)) *may* be just fine (to be verified, of course).

The trouble with thorough testing right now is that no one agrees on what the tests should be and a number of the testcases are not in great shape. An agreed-upon set of testcases for basic correctness should be devised and the implementations of those testcases need to be maintainable code and the tests set up for automated testing and changing their parameters without recompiling via command-line options.

Quoted 8 lines

Once there's a standard regression test suite for correctness, one needs to be devised for performance, including interactive performance. The primary difficulty I see along these lines is finding a way to automate tests of graphics and input device response performance. Others, like how deterministically priorities are respected over progressively smaller time intervals and noninteractive workload performance are nowhere near as difficult to arrange and in many cases already exist. Just reuse SDET, AIM7/AIM9, OAST, contest, interbench, et al.

Quoted 3 lines

What I meant was, that the rules (requirements and associated test cases) for this new Scheduler Amazing Race should be set forward, and not kept a moving target to fit&follow one or the other implementation.

Exactly. Well I don't mind if it is a moving target as such, just as long as the decisions are rational (no "blah is more important because I say so").

#287 lore raw
In reply to William Lee Irwin III
Quoted 7 lines · William Lee Irwin III
Quoted 5 lines · Davide Libenzi

I had a quick look at Ingo's code yesterday. Ingo is always smart to prepare a main dish (feature) with a nice sider (code cleanup) to Linus ;) And even this code does that pretty nicely. The deadline designs looks good, although I think the final "key" calculation code will end up quite different from what it looks now.

Quoted 5 lines

The additive nice_offset breaks nice levels. A multiplicative priority weighting of a different, nonnegative metric of cpu utilization from what's now used is required for nice levels to work. I've been trying to point this out politely by strongly suggesting testing whether nice levels work.

granted, CFS's nice code is still incomplete, but you err quite significantly with this extreme statement that they are "broken".

nice levels certainly work to a fair degree even in the current code and much of the focus is elsewhere - just try it. (In fact i claim that CFS's nice levels often work _better_ than the mainline scheduler's nice level support, for the testcases that matter to users.)

The precise behavior of nice levels, as i pointed it out in previous mails, is largely 'uninteresting' and it has changed multiple times in the past 10 years.

What matters to users is mainly: whether X reniced to -10 does get enough CPU time and whether stuff reniced to +19 doesnt take away too much CPU time from the rest of the system. _How_ a Linux scheduler achieves this is an internal matter and certainly CFS does it in a hacky way at the moment.

All the rest, 'CPU bandwidth utilization' or whatever abstract metric we could come up with is just a fancy academic technicality that has no real significance to any of the testers who are trying CFS right now.

Sure we prefer final solutions that are clean and make sense (because such things are the easiest to maintain long-term), and often such final solutions are quite close to academic concepts, and i think Davide correctly observed this by saying that "the final key calculation code will end up quite different from what it looks now", but your extreme-end claim of 'breakage' for something that is just plain incomplete is not really a fair characterisation at this point.

Anyone who thinks that there exists only two kinds of code: 100% correct and 100% incorrect with no shades of grey inbetween is in reality a sort of an extremist: whom, depending on mood and affection, we could call either a 'coding purist' or a 'coding taliban' ;-)

Ingo

#288 lore raw
Quoted 24 lines · Ingo Molnar
Quoted 7 lines · William Lee Irwin III
Quoted 5 lines · Davide Libenzi

I had a quick look at Ingo's code yesterday. Ingo is always smart to prepare a main dish (feature) with a nice sider (code cleanup) to Linus ;) And even this code does that pretty nicely. The deadline designs looks good, although I think the final "key" calculation code will end up quite different from what it looks now.

Quoted 5 lines

The additive nice_offset breaks nice levels. A multiplicative priority weighting of a different, nonnegative metric of cpu utilization from what's now used is required for nice levels to work. I've been trying to point this out politely by strongly suggesting testing whether nice levels work.

granted, CFS's nice code is still incomplete, but you err quite significantly with this extreme statement that they are "broken".

nice levels certainly work to a fair degree even in the current code and much of the focus is elsewhere - just try it. (In fact i claim that CFS's nice levels often work _better_ than the mainline scheduler's nice level support, for the testcases that matter to users.)

Quoted 7 lines

The precise behavior of nice levels, as i pointed it out in previous mails, is largely 'uninteresting' and it has changed multiple times in the past 10 years.

What matters to users is mainly: whether X reniced to -10 does get enough CPU time and whether stuff reniced to +19 doesnt take away too much CPU time from the rest of the system.

I agree there.

Quoted 16 lines

_How_ a Linux scheduler
achieves this is an internal matter and certainly CFS does it in a hacky way at the moment.

All the rest, 'CPU bandwidth utilization' or whatever abstract metric we could come up with is just a fancy academic technicality that has no real significance to any of the testers who are trying CFS right now.

Sure we prefer final solutions that are clean and make sense (because such things are the easiest to maintain long-term), and often such final solutions are quite close to academic concepts, and i think Davide correctly observed this by saying that "the final key calculation code will end up quite different from what it looks now", but your extreme-end claim of 'breakage' for something that is just plain incomplete is not really a fair characterisation at this point.

Quoted 4 lines

Anyone who thinks that there exists only two kinds of code: 100% correct and 100% incorrect with no shades of grey inbetween is in reality a sort of an extremist: whom, depending on mood and affection, we could call either a 'coding purist' or a 'coding taliban' ;-)

Only if you are an extremist-naming extremist with no shades of grey. Others, like myself, also include 'coding al-qaeda' and 'coding john howard' in that scale.

#289 lore raw
Quoted 9 lines · Nick Piggin
Quoted 5 lines

Anyone who thinks that there exists only two kinds of code: 100% correct and 100% incorrect with no shades of grey inbetween is in reality a sort of an extremist: whom, depending on mood and affection, we could call either a 'coding purist' or a 'coding taliban' ;-)

Only if you are an extremist-naming extremist with no shades of grey. Others, like myself, also include 'coding al-qaeda' and 'coding john howard' in that scale.

heh ;) You, you ... nitpicking extremist! ;)

And beware that you just commited another act of extremism too:

Quoted 1 line

I agree there.

because you just went to the extreme position of saying that "i agree with this portion 100%", instead of saying "this seems to be 91.5% correct in my opinion, Tue, 17 Apr 2007 09:40:25 +0200".

and the nasty thing is, that in reality even shades of grey, if you print them out, are just a set of extreme black dots on an extreme white sheet of paper! ;)

[ so i guess we've got to consider the scope of extremism too: the
larger the scope, the more limiting and hence the more dangerous it is. ]

Ingo

#290 lore raw
In reply to Ingo Molnar
Quoted 5 lines · William Lee Irwin III
Quoted 5 lines

The additive nice_offset breaks nice levels. A multiplicative priority weighting of a different, nonnegative metric of cpu utilization from what's now used is required for nice levels to work. I've been trying to point this out politely by strongly suggesting testing whether nice levels work.

Quoted 2 lines · Ingo Molnar

granted, CFS's nice code is still incomplete, but you err quite significantly with this extreme statement that they are "broken".

I used the word relatively loosely. Nothing extreme is going on. Maybe the phrasing exaggerated the force of the opinion. I'm sorry about having misspoke so.

Quoted 4 lines · Ingo Molnar

nice levels certainly work to a fair degree even in the current code and much of the focus is elsewhere - just try it. (In fact i claim that CFS's nice levels often work _better_ than the mainline scheduler's nice level support, for the testcases that matter to users.)

Al Boldi's testcase appears to reveal some issues. I'm plotting a testcase of my own if I can ever get past responding to email.

Quoted 3 lines · Ingo Molnar

The precise behavior of nice levels, as i pointed it out in previous mails, is largely 'uninteresting' and it has changed multiple times in the past 10 years.

I expect that whether a scheduler can handle such prioritization has a rather strong predictive quality regarding whether it can handle, say, CKRM controls. I remain convinced that there should be some target behavior and that some attempt should be made to achieve it. I don't think any particular behavior is best, just that the behavior should be well-defined.

Quoted 5 lines · Ingo Molnar

What matters to users is mainly: whether X reniced to -10 does get enough CPU time and whether stuff reniced to +19 doesnt take away too much CPU time from the rest of the system. _How_ a Linux scheduler achieves this is an internal matter and certainly CFS does it in a hacky way at the moment.

It's not so far out. Basically just changing the key calculation in a relatively simple manner should get things into relatively good shape. It can, of course, be done other ways (I did it a rather different way in vdls, though that method is not likely to be considered desirable).

I can't really write a testcase for such loose semantics, so the above description is useless to me. These squishy sorts of definitions of semantics are also uninformative to users, who, I would argue, do have some interest in what nice levels mean. There have been at least a small number of concerns about the strength of nice levels, and it would reveal issues surrounding that area earlier if there were an objective one could test to see if it were achieved.

It's furthermore a user-visible change in system call semantics we should be more careful about changing out from beneath users.

So I see a lot of good reasons to pin down nice numbers. Incompleteness is not a particularly mortal sin, but the proliferation of competing schedulers is creating a need for standards, and that's what I'm really on about.

Quoted 3 lines · Ingo Molnar

All the rest, 'CPU bandwidth utilization' or whatever abstract metric we could come up with is just a fancy academic technicality that has no real significance to any of the testers who are trying CFS right now.

I could say "percent cpu" if it sounds less like formal jargon, which "CPU bandwidth utilization" isn't really.

Quoted 7 lines · Ingo Molnar

Sure we prefer final solutions that are clean and make sense (because such things are the easiest to maintain long-term), and often such final solutions are quite close to academic concepts, and i think Davide correctly observed this by saying that "the final key calculation code will end up quite different from what it looks now", but your extreme-end claim of 'breakage' for something that is just plain incomplete is not really a fair characterisation at this point.

It wasn't meant to be quite as strong a statement as it came out. Sorry about that.

Quoted 4 lines · Ingo Molnar

Anyone who thinks that there exists only two kinds of code: 100% correct and 100% incorrect with no shades of grey inbetween is in reality a sort of an extremist: whom, depending on mood and affection, we could call either a 'coding purist' or a 'coding taliban' ;-)

I've made no such claims. Also rest assured that the tone of the critique is not hostile, and wasn't meant to sound that way.

Also, given the general comments it appears clear that some statistical metric of deviation from the intended behavior furthermore qualified by timescale is necessary, so this appears to be headed toward a sort of performance metric as opposed to a pass/fail test anyway. However, to even measure this at all, some statement of intention is required. I'd prefer that there be a Linux-standard semantics for nice so results are more directly comparable and so that users also get similar nice behavior from the scheduler as it varies over time and possibly implementations if users should care to switch them out with some scheduler patch or other.

-- wli

#291 lore raw
Quoted 2 lines · William Lee Irwin III

[...] Also rest assured that the tone of the critique is not hostile, and wasn't meant to sound that way.

ok :) (And i guess i was too touchy - sorry about coming out swinging.)

Quoted 10 lines

Also, given the general comments it appears clear that some statistical metric of deviation from the intended behavior furthermore qualified by timescale is necessary, so this appears to be headed toward a sort of performance metric as opposed to a pass/fail test anyway. However, to even measure this at all, some statement of intention is required. I'd prefer that there be a Linux-standard semantics for nice so results are more directly comparable and so that users also get similar nice behavior from the scheduler as it varies over time and possibly implementations if users should care to switch them out with some scheduler patch or other.

yeah. If you could come up with a sane definition that also translates into low overhead on the algorithm side that would be great! The only good generic definition i could come up with (nice levels are isolated buckets with a constant maximum relative percentage of CPU time available to every active bucket) resulted in having a per-nice-level array of rbtree roots, which did not look worth the hassle at first sight :-)

until now the main approach for nice levels in Linux was always:
"implement your main scheduling logic for nice 0 and then look for some low-overhead method that can be glued to it that does something that behaves like nice levels". Feel free to turn that around into a more natural approach, but the algorithm should remain fairly simple i think.

Ingo

#292 lore raw
Quoted 4 lines · William Lee Irwin III
Quoted 4 lines

Also, given the general comments it appears clear that some statistical metric of deviation from the intended behavior furthermore qualified by timescale is necessary, so this appears to be headed toward a sort of performance metric as opposed to a pass/fail test

[...]

Quoted 7 lines · Ingo Molnar

yeah. If you could come up with a sane definition that also translates into low overhead on the algorithm side that would be great! The only good generic definition i could come up with (nice levels are isolated buckets with a constant maximum relative percentage of CPU time available to every active bucket) resulted in having a per-nice-level array of rbtree roots, which did not look worth the hassle at first sight :-)

Interesting! That's what vdls did, except its fundamental data structure was more like a circular buffer data structure (resembling Davide Libenzi's timer ring in concept, but with all the details different). I'm not entirely sure how that would've turned out performancewise if I'd done any tuning at all. I was mostly interested in doing something like what I heard Bob Mullens did in 1976 for basic pedagogical value about schedulers to prepare for writing patches for gang scheduling as opposed to creating a viable replacement for the mainline scheduler.

I'm relatively certain a different key calculation will suffice, but it may disturb other desired semantics since they really need to be nonnegative for multiplying by a scaling factor corresponding to its nice number to work properly. Well, as the cfs code now stands, it would correspond to negative keys. Dividing positive keys by the nice scaling factor is my first thought of how to extend the method to the current key semantics. Or such are my thoughts on the subject.

I expect that all that's needed is to fiddle with those numbers a bit. There's quite some capacity for expression there given the precision.

Quoted 5 lines · Ingo Molnar

until now the main approach for nice levels in Linux was always:
"implement your main scheduling logic for nice 0 and then look for some low-overhead method that can be glued to it that does something that behaves like nice levels". Feel free to turn that around into a more natural approach, but the algorithm should remain fairly simple i think.

Part of my insistence was because it seemed to be relatively close to a one-liner, though I'm not entirely sure what particular computation to use to handle the signedness of the keys. I guess I could pick some particular nice semantics myself and then sweep the extant schedulers to use them after getting a testcase hammered out.

-- wli

#293 lore raw
Quoted 9 lines · William Lee Irwin III
Quoted 6 lines · Ingo Molnar

until now the main approach for nice levels in Linux was always:
"implement your main scheduling logic for nice 0 and then look for some low-overhead method that can be glued to it that does something that behaves like nice levels". Feel free to turn that around into a more natural approach, but the algorithm should remain fairly simple i think.

Quoted 5 lines

Part of my insistence was because it seemed to be relatively close to a one-liner, though I'm not entirely sure what particular computation to use to handle the signedness of the keys. I guess I could pick some particular nice semantics myself and then sweep the extant schedulers to use them after getting a testcase hammered out.

i'd love to have a oneliner solution :-)

wrt. signedness: note that in v2 i have made rq_running signed, and most calculations (especially those related to nice) are signed values. (On 64-bit systems this all isnt a big issue - most of the arithmetics gymnastics in CFS are done to keep deltas within 32 bits, so that divisions and multiplications are sane.)

Ingo

#294 lore raw
In reply to William Lee Irwin III
Quoted 8 lines · William Lee Irwin III

Interesting! That's what vdls did, except its fundamental data structure was more like a circular buffer data structure (resembling Davide Libenzi's timer ring in concept, but with all the details different). I'm not entirely sure how that would've turned out performancewise if I'd done any tuning at all. I was mostly interested in doing something like what I heard Bob Mullens did in 1976 for basic pedagogical value about schedulers to prepare for writing patches for gang scheduling as opposed to creating a viable replacement for the mainline scheduler.

Con helped me dredge up the vdls bits, so here is the last version I before I got tired of toying with the idea. It's not all that clean, with a fair amount of debug code floating around and a number of idiocies (it seems there was a plot to use a heap somewhere I forgot about entirely, never mind other cruft), but I thought I should at least say something more provable than "there was a patch I never posted."

Enjoy!

-- wli

fs/proc/array.c +4 -4
diff -prauN linux-2.6.0-test11/fs/proc/array.c sched-2.6.0-test11-5/fs/proc/array.c
@@ -162,7 +162,7 @@ static inline char * task_state(struct t
 		"Uid:\t%d\t%d\t%d\t%d\n"
 		"Gid:\t%d\t%d\t%d\t%d\n",
 		get_task_state(p),
-		(p->sleep_avg/1024)*100/(1000000000/1024),
+		0UL, /* was ->sleep_avg */
 	       	p->tgid,
 		p->pid, p->pid ? p->real_parent->pid : 0,
 		p->pid && p->ptrace ? p->parent->pid : 0,
@@ -345,7 +345,7 @@ int proc_pid_stat(struct task_struct *ta
 	read_unlock(&tasklist_lock);
 	res = sprintf(buffer,"%d (%s) %c %d %d %d %d %d %lu %lu \
 %lu %lu %lu %lu %lu %ld %ld %ld %ld %d %ld %llu %lu %ld %lu %lu %lu %lu %lu \
-%lu %lu %lu %lu %lu %lu %lu %lu %d %d %lu %lu\n",
+%lu %lu %lu %lu %lu %lu %lu %lu %d %d %d %d\n",
 		task->pid,
 		task->comm,
 		state,
@@ -390,8 +390,8 @@ int proc_pid_stat(struct task_struct *ta
 		task->cnswap,
 		task->exit_signal,
 		task_cpu(task),
-		task->rt_priority,
-		task->policy);
+		task_prio(task),
+		task_sched_policy(task));
 	if(mm)
 		mmput(mm);
 	return res;
include/asm-i386/thread_info.h +2 -0
diff -prauN linux-2.6.0-test11/include/asm-i386/thread_info.h sched-2.6.0-test11-5/include/asm-i386/thread_info.h
@@ -114,6 +114,8 @@ static inline struct thread_info *curren
 #define TIF_SINGLESTEP		4	/* restore singlestep on return to user mode */
 #define TIF_IRET		5	/* return with iret */
 #define TIF_POLLING_NRFLAG	16	/* true if poll_idle() is polling TIF_NEED_RESCHED */
+#define TIF_QUEUED		17
+#define TIF_PREEMPT		18
 
 #define _TIF_SYSCALL_TRACE	(1<<TIF_SYSCALL_TRACE)
 #define _TIF_NOTIFY_RESUME	(1<<TIF_NOTIFY_RESUME)
include/linux/binomial.h +16 -0
diff -prauN linux-2.6.0-test11/include/linux/binomial.h sched-2.6.0-test11-5/include/linux/binomial.h
@@ -0,0 +1,16 @@
+/*
+ * Simple binomial heaps.
+ */
+
+struct binomial {
+	unsigned priority, degree;
+	struct binomial *parent, *child, *sibling;
+};
+
+
+struct binomial *binomial_minimum(struct binomial **);
+void binomial_union(struct binomial **, struct binomial **, struct binomial **);
+void binomial_insert(struct binomial **, struct binomial *);
+struct binomial *binomial_extract_min(struct binomial **);
+void binomial_decrease(struct binomial **, struct binomial *, unsigned);
+void binomial_delete(struct binomial **, struct binomial *);
include/linux/init_task.h +7 -5
diff -prauN linux-2.6.0-test11/include/linux/init_task.h sched-2.6.0-test11-5/include/linux/init_task.h
@@ -56,6 +56,12 @@
 	.siglock	= SPIN_LOCK_UNLOCKED, 		\
 }
 
+#define INIT_SCHED_INFO(info)					\
+{								\
+	.run_list	= LIST_HEAD_INIT((info).run_list),	\
+	.policy		= 1 /* SCHED_POLICY_TS */,		\
+}
+
 /*
  *  INIT_TASK is used to set up the first task table, touch at
  * your own risk!. Base=0, limit=0x1fffff (=2MB)
@@ -67,14 +73,10 @@
 	.usage		= ATOMIC_INIT(2),				\
 	.flags		= 0,						\
 	.lock_depth	= -1,						\
-	.prio		= MAX_PRIO-20,					\
-	.static_prio	= MAX_PRIO-20,					\
-	.policy		= SCHED_NORMAL,					\
+	.sched_info	= INIT_SCHED_INFO(tsk.sched_info),		\
 	.cpus_allowed	= CPU_MASK_ALL,					\
 	.mm		= NULL,						\
 	.active_mm	= &init_mm,					\
-	.run_list	= LIST_HEAD_INIT(tsk.run_list),			\
-	.time_slice	= HZ,						\
 	.tasks		= LIST_HEAD_INIT(tsk.tasks),			\
 	.ptrace_children= LIST_HEAD_INIT(tsk.ptrace_children),		\
 	.ptrace_list	= LIST_HEAD_INIT(tsk.ptrace_list),		\
include/linux/sched.h +64 -21

129 lines not on this page · raw message

kernel/Makefile +1 -1
diff -prauN linux-2.6.0-test11/kernel/Makefile sched-2.6.0-test11-5/kernel/Makefile
@@ -6,7 +6,7 @@ obj-y     = sched.o fork.o exec_domain.o
 	    exit.o itimer.o time.o softirq.o resource.o \
 	    sysctl.o capability.o ptrace.o timer.o user.o \
 	    signal.o sys.o kmod.o workqueue.o pid.o \
-	    rcupdate.o intermodule.o extable.o params.o posix-timers.o
+	    rcupdate.o intermodule.o extable.o params.o posix-timers.o sched/
 
 obj-$(CONFIG_FUTEX) += futex.o
 obj-$(CONFIG_GENERIC_ISA_DMA) += dma.o
kernel/exit.c +1 -1
diff -prauN linux-2.6.0-test11/kernel/exit.c sched-2.6.0-test11-5/kernel/exit.c
@@ -225,7 +225,7 @@ void reparent_to_init(void)
 	/* Set the exit signal to SIGCHLD so we signal init on exit */
 	current->exit_signal = SIGCHLD;
 
-	if ((current->policy == SCHED_NORMAL) && (task_nice(current) < 0))
+	if (task_nice(current) < 0)
 		set_user_nice(current, 0);
 	/* cpus_allowed? */
 	/* rt_priority? */
kernel/fork.c +14 -34

89 lines not on this page · raw message

kernel/sched/Makefile +1 -0
diff -prauN linux-2.6.0-test11/kernel/sched/Makefile sched-2.6.0-test11-5/kernel/sched/Makefile
@@ -0,0 +1 @@
+obj-y = util.o ts.o idle.o rt.o batch.o
kernel/sched/batch.c +190 -0

190 lines not on this page · raw message

kernel/sched/idle.c +99 -0

99 lines not on this page · raw message

kernel/sched/queue.h +104 -0

104 lines not on this page · raw message

kernel/sched/rt.c +208 -0

208 lines not on this page · raw message

kernel/sched/ts.c +841 -0

841 lines not on this page · raw message

kernel/sched/util.c +37 -0
diff -prauN linux-2.6.0-test11/kernel/sched/util.c sched-2.6.0-test11-5/kernel/sched/util.c
@@ -0,0 +1,37 @@
+#include <linux/sched.h>
+#include <linux/list.h>
+#include <linux/percpu.h>
+#include <asm/page.h>
+#include "queue.h"
+
+int find_first_circular_bit(unsigned long *addr, int start, int end)
+{
+	int bit = find_next_bit(addr, end, start);
+	if (bit < end)
+		return bit;
+	bit = find_first_bit(addr, start);
+	if (bit < start)
+		return bit;
+	return end;
+}
+
+void queue_nop(struct queue *queue, task_t *task)
+{
+}
+
+void nop_renice(struct queue *queue, task_t *task, int nice)
+{
+}
+
+void nop_fini(struct policy *policy, int cpu)
+{
+}
+
+unsigned long nop_timeslice(struct queue *queue, task_t *task)
+{
+	return 0;
+}
+
+void nop_set_timeslice(struct queue *queue, task_t *task, unsigned long n)
+{
+}
kernel/sched.c +318 -673

1,209 lines not on this page · raw message

lib/Makefile +1 -1
diff -prauN linux-2.6.0-test11/lib/Makefile sched-2.6.0-test11-5/lib/Makefile

Lines of this file are not shown. View the raw message.

lib/binomial.c +138 -0

138 lines not on this page · raw message

mm/oom_kill.c +0 -1
diff -prauN linux-2.6.0-test11/mm/oom_kill.c sched-2.6.0-test11-5/mm/oom_kill.c

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Part of the diff is not shown here. View the raw message.

#295 lore raw
In reply to Ingo Molnar
Quoted 19 lines · Ingo Molnar
Quoted 2 lines · William Lee Irwin III

[...] Also rest assured that the tone of the critique is not hostile, and wasn't meant to sound that way.

ok :) (And i guess i was too touchy - sorry about coming out swinging.)

Quoted 10 lines

Also, given the general comments it appears clear that some statistical metric of deviation from the intended behavior furthermore qualified by timescale is necessary, so this appears to be headed toward a sort of performance metric as opposed to a pass/fail test anyway. However, to even measure this at all, some statement of intention is required. I'd prefer that there be a Linux-standard semantics for nice so results are more directly comparable and so that users also get similar nice behavior from the scheduler as it varies over time and possibly implementations if users should care to switch them out with some scheduler patch or other.

Quoted 2 lines

yeah. If you could come up with a sane definition that also translates into low overhead on the algorithm side that would be great!

How's this:

If you're running two identical CPU hog tasks A and B differing only by nice level (Anice, Bnice), the ratio cputime(A)/cputime(B) should be a constant f(Anice - Bnice).

Other definitions make things hard to analyze and probably not well-bounded when confronted with > 2 tasks.

I -think- this implies keeping a separate scaled CPU usage counter, where the scaling factor is a trivial exponential function of nice level where f(0) == 1. Then you schedule based on this scaled usage counter rather than unscaled.

I also suspect we want to keep the exponential base small so that the maximal difference is 10x-100x.

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#296 lore raw
Quoted 2 lines · Ingo Molnar
Quoted 2 lines

yeah. If you could come up with a sane definition that also translates into low overhead on the algorithm side that would be great!

Quoted 4 lines · Matt Mackall

How's this:
If you're running two identical CPU hog tasks A and B differing only by nice level (Anice, Bnice), the ratio cputime(A)/cputime(B) should be a constant f(Anice - Bnice).

Quoted 8 lines

Other definitions make things hard to analyze and probably not well-bounded when confronted with > 2 tasks.
I -think- this implies keeping a separate scaled CPU usage counter, where the scaling factor is a trivial exponential function of nice level where f(0) == 1. Then you schedule based on this scaled usage counter rather than unscaled.
I also suspect we want to keep the exponential base small so that the maximal difference is 10x-100x.

I'm already working with this as my assumed nice semantics (actually something with a specific exponential base, suggested in other emails) until others start saying they want something different and agree.

-- wli

#297 lore raw
Quoted 18 lines · William Lee Irwin III
Quoted 2 lines · Ingo Molnar
Quoted 2 lines

yeah. If you could come up with a sane definition that also translates into low overhead on the algorithm side that would be great!

Quoted 4 lines · Matt Mackall

How's this:
If you're running two identical CPU hog tasks A and B differing only by nice level (Anice, Bnice), the ratio cputime(A)/cputime(B) should be a constant f(Anice - Bnice).

Quoted 8 lines

Other definitions make things hard to analyze and probably not well-bounded when confronted with > 2 tasks.
I -think- this implies keeping a separate scaled CPU usage counter, where the scaling factor is a trivial exponential function of nice level where f(0) == 1. Then you schedule based on this scaled usage counter rather than unscaled.
I also suspect we want to keep the exponential base small so that the maximal difference is 10x-100x.

Quoted 3 lines

I'm already working with this as my assumed nice semantics (actually something with a specific exponential base, suggested in other emails) until others start saying they want something different and agree.

Good. This has a couple nice mathematical properties, including "bounded unfairness" which I mentioned earlier. What base are you looking at?

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#298 lore raw
Quoted 3 lines · William Lee Irwin III
Quoted 3 lines

I'm already working with this as my assumed nice semantics (actually something with a specific exponential base, suggested in other emails) until others start saying they want something different and agree.

Quoted 3 lines · Matt Mackall

Good. This has a couple nice mathematical properties, including "bounded unfairness" which I mentioned earlier. What base are you looking at?

I'm working with the following suggestion:

Quoted 5 lines · James Bruce

Nonlinear is a must IMO. I would suggest X = exp(ln(10)/10) ~= 1.2589 That value has the property that a nice=10 task gets 1/10th the cpu of a nice=0 task, and a nice=20 task gets 1/100 of nice=0. I think that would be fairly easy to explain to admins and users so that they can know what to expect from nicing tasks.

I'm not likely to write the testcase until this upcoming weekend, though.

-- wli

#299 lore raw
Quoted 13 lines · William Lee Irwin III
Quoted 3 lines · William Lee Irwin III
Quoted 3 lines

I'm already working with this as my assumed nice semantics (actually something with a specific exponential base, suggested in other emails) until others start saying they want something different and agree.

Quoted 3 lines · Matt Mackall

Good. This has a couple nice mathematical properties, including "bounded unfairness" which I mentioned earlier. What base are you looking at?

I'm working with the following suggestion:

Quoted 8 lines
Quoted 5 lines · James Bruce

Nonlinear is a must IMO. I would suggest X = exp(ln(10)/10) ~= 1.2589 That value has the property that a nice=10 task gets 1/10th the cpu of a nice=0 task, and a nice=20 task gets 1/100 of nice=0. I think that would be fairly easy to explain to admins and users so that they can know what to expect from nicing tasks.

I'm not likely to write the testcase until this upcoming weekend, though.

So that means there's a 10000:1 ratio between nice 20 and nice -19. In that sort of dynamic range, you're likely to have non-trivial numerical accuracy issues in integer/fixed-point math.

(Especially if your clock is jiffies-scale, which a significant number of machines will continue to be.)

I really think if we want to have vastly different ratios, we probably want to be looking at BATCH and RT scheduling classes instead.

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#300 lore raw
Quoted 5 lines · James Bruce
Quoted 5 lines
Quoted 5 lines

Nonlinear is a must IMO. I would suggest X = exp(ln(10)/10) ~= 1.2589 That value has the property that a nice=10 task gets 1/10th the cpu of a nice=0 task, and a nice=20 task gets 1/100 of nice=0. I think that would be fairly easy to explain to admins and users so that they can know what to expect from nicing tasks.

Quoted 1 line · William Lee Irwin III
Quoted 1 line

I'm not likely to write the testcase until this upcoming weekend, though.

Quoted 7 lines · Matt Mackall

So that means there's a 10000:1 ratio between nice 20 and nice -19. In that sort of dynamic range, you're likely to have non-trivial numerical accuracy issues in integer/fixed-point math. (Especially if your clock is jiffies-scale, which a significant number of machines will continue to be.)
I really think if we want to have vastly different ratios, we probably want to be looking at BATCH and RT scheduling classes instead.

100**(1/39.0) ~= 1.12534 may do if so, but it seems a little weak, and even 1000**(1/39.0) ~= 1.19378 still seems weak.

I suspect that in order to get low nice numbers strong enough without making high nice numbers too strong something sub-exponential may need to be used. Maybe just picking percentages outright as opposed to some particular function.

We may also be better off defining it in terms of a share weighting as opposed to two tasks in competition. In such a manner the extension to N tasks is more automatic. f(n) would be a univariate function of nice numbers and two tasks in competition with nice numbers n_1 and n_2 would get shares f(n_1)/(f(n_1)+f(n_2)) and f(n_2)/(f(n_1)+f(n_2)). In the exponential case f(n) = K*e**(r*n) this ends up as 1/(1+e**(r*(n_2-n_1))) which is indeed a function of n_1-n_2 but for other choices it's not so. f(n) = n+K for K >= 20 results in a share weighting of (n_1+K,n_2+K)/(n_1+n_2+2*K), which is not entirely clear in its impact. My guess is that f(n)=1/(n+1) when n >= 0 and f(n)=1-n when n <= 0 is highly plausible. An exponent or an additive constant may be worthwhile to throw in. In this case, f(-19) = 20, f(20) = 1/21, and the ratio of shares is 420, which is still arithmeticaly feasible. -10 vs. 0 and 0 vs. 10 are both 10:1.

-- wli

#301 lore raw
Quoted 8 lines · William Lee Irwin III

100**(1/39.0) ~= 1.12534 may do if so, but it seems a little weak, and even 1000**(1/39.0) ~= 1.19378 still seems weak.

I suspect that in order to get low nice numbers strong enough without making high nice numbers too strong something sub-exponential may need to be used. Maybe just picking percentages outright as opposed to some particular function.

Quoted 14 lines

We may also be better off defining it in terms of a share weighting as opposed to two tasks in competition. In such a manner the extension to N tasks is more automatic. f(n) would be a univariate function of nice numbers and two tasks in competition with nice numbers n_1 and n_2 would get shares f(n_1)/(f(n_1)+f(n_2)) and f(n_2)/(f(n_1)+f(n_2)). In the exponential case f(n) = K*e**(r*n) this ends up as 1/(1+e**(r*(n_2-n_1))) which is indeed a function of n_1-n_2 but for other choices it's not so. f(n) = n+K for K >= 20 results in a share weighting of (n_1+K,n_2+K)/(n_1+n_2+2*K), which is not entirely clear in its impact. My guess is that f(n)=1/(n+1) when n >= 0 and f(n)=1-n when n <= 0 is highly plausible. An exponent or an additive constant may be worthwhile to throw in. In this case, f(-19) = 20, f(20) = 1/21, and the ratio of shares is 420, which is still arithmeticaly feasible. -10 vs. 0 and 0 vs. 10 are both 10:1.

This makes more sense, and the ratio at the extremes is something reasonable.

- Davide

#302 lore raw
In reply to Matt Mackall
Quoted 10 lines · Matt Mackall
Quoted 9 lines · William Lee Irwin III

On Tue, Apr 17, 2007 at 03:32:56PM -0700, William Lee Irwin III wrote:
I'm working with the following suggestion:

Quoted 5 lines · James Bruce

Nonlinear is a must IMO. I would suggest X = exp(ln(10)/10) ~= 1.2589 That value has the property that a nice=10 task gets 1/10th the cpu of a nice=0 task, and a nice=20 task gets 1/100 of nice=0. I think that would be fairly easy to explain to admins and users so that they can know what to expect from nicing tasks.

Quoted 5 lines
Quoted 1 line

I'm not likely to write the testcase until this upcoming weekend, though.

So that means there's a 10000:1 ratio between nice 20 and nice -19. In that sort of dynamic range, you're likely to have non-trivial numerical accuracy issues in integer/fixed-point math.

Well, you *are* specifying vastly different priorities. The question is how many nice=20 tasks should it take to interfere with a nice=-19 task?
If you've only got a 100:1 ratio, 100 nice=20 tasks will take ~50% of
the CPU away from a nice=-19 task. I don't think that's ideal, as in my mind a -19 task shouldn't have to care how many nice=20 tasks there are (within reason). IMHO, if a user is running a CPU hog at nice=-19, and expecting nice=20 tasks to run immediately, I don't think the scheduler is the problem.

Quoted 5 lines

(Especially if your clock is jiffies-scale, which a significant number of machines will continue to be.)

I really think if we want to have vastly different ratios, we probably want to be looking at BATCH and RT scheduling classes instead.

I, like all users, can live with anything, but there should be a clear specification of what the user should expect. Magic changes in the function at nice=0, or no real clear meaning at all (mainline), are both things that don't help the users to figure that out. I like the exponential base because shifting all tasks up or down one nice level does not change the relative cpu distribution (i.e. two tasks {nice=-5,nice=0} get the same relative cpu distribution as if they were {nice=0,nice=5}. An exponential base is the only way that property can hold.

Now, perhaps implementation issues may prevent something like the "1.2589" ratio rule from being realized, but I'm not sure we should throw it out _before_ we know that it's actually a problem. This is the same sort of resistance that the timekeeping code updates faces (using nanoseconds everywhere instead of "natural" clock bases), but that got addressed eventually.

- Jim Bruce

#303 lore raw
In reply to Davide Libenzi
Quoted 7 lines · Davide Libenzi
Quoted 4 lines · Nick Piggin
Quoted 1 line

All things are not equal; they all have different properties. I like

Exactly. So we have to explore those properties and evaluate performance (in all meanings of the word). That's only logical.

Quoted 11 lines

I had a quick look at Ingo's code yesterday. Ingo is always smart to prepare a main dish (feature) with a nice sider (code cleanup) to Linus ;) And even this code does that pretty nicely. The deadline designs looks good, although I think the final "key" calculation code will end up quite different from what it looks now.
I would suggest to thoroughly test all your alternatives before deciding. Some code and design may look very good and small at the beginning, but when you start patching it to cover all the dark spots, you effectively end up with another thing (in both design and code footprint). About O(1), I never thought it was a must (besides a good marketing material), and O(log(N)) *may* be just fine (to be verified, of course).

To be clear, I'm not saying O(logN) itself is a big problem. Type

plot [10:100] x with lines, log(x) with lines, 1 with lines

into gnuplot. I was just trying to point out that we need to evalute things. Considering how long we've had this scheduler with its known deficiencies, let's pick a new one wisely.

#304 lore raw
Quoted 3 lines · Nick Piggin

To be clear, I'm not saying O(logN) itself is a big problem. Type

plot [10:100] x with lines, log(x) with lines, 1 with lines

Haha, Nick, I know how a log() looks like :)
The Time Ring I posted as example (that nothing is other than a ring-based bucket sort), keeps O(1) if you can concede some timer clustering.

- Davide

#305 lore raw
In reply to Nick Piggin
Quoted 21 lines · Nick Piggin
Quoted 20 lines · Peter Williams
Quoted 19 lines · Nick Piggin
Quoted 5 lines · Mike Galbraith
Quoted 4 lines · Peter Williams
Quoted 3 lines · Mike Galbraith

Demystify what? The casual observer need only read either your attempt
at writing a scheduler, or my attempts at fixing the one we have, to see that it was high time for someone with the necessary skills to step in.

Quoted 7 lines
Quoted 1 line

Make that "someone with the necessary clout".

No, I was brutally honest to both of us, but quite correct.

Quoted 3 lines
Quoted 2 lines

Now progress can happen, which was _not_ happening before.

This is true.

Yup, and progress _is_ happening now, quite rapidly.

Progress as in progress on Ingo's scheduler. I still don't know how we'd decide when to replace the mainline scheduler or with what.

I don't think we can say Ingo's is better than the alternatives, can we? If there is some kind of bakeoff, then I'd like one of Con's designs to be involved, and mine, and Peter's...

Quoted 8 lines
Quoted 3 lines

I myself was thinking of this as the chance for a much needed simplification of the scheduling code and if this can be done with the result being "reasonable" it then gives us the basis on which to propose improvements based on the ideas of others such as you mention.

As the size of the cpusched indicates, trying to evaluate alternative proposals based on the current O(1) scheduler is fraught. Hopefully,

I don't know why. The problem is that you can't really evaluate good proposals by looking at the code (you can say that one is bad, ie. the current one, which has a huge amount of temporal complexity and is explicitly unfair), but it is pretty hard to say one behaves well.

I meant that it's indicative of the amount of work that you have to do to implement a new scheduling discipline for evaluation.

Quoted 3 lines

And my scheduler for example cuts down the amount of policy code and code size significantly.

Yours is one of the smaller patches mainly because you perpetuate (or you did in the last one I looked at) the (horrible to my eyes) dual array (active/expired) mechanism. That this idea was bad should have been apparent to all as soon as the decision was made to excuse some tasks from being moved from the active array to the expired array. This essentially meant that there would be circumstances where extreme unfairness (to the extent of starvation in some cases) -- the very things that the mechanism was originally designed to ensure (as far as I can gather). Right about then in the development of the O(1) scheduler alternative solutions should have been sought.

Other hints that it was a bad idea was the need to transfer time slices between children and parents during fork() and exit().

This disregard for the dual array mechanism has prevented me from looking at the rest of your scheduler in any great detail so I can't comment on any other ideas that may be in there.

Quoted 2 lines

I haven't looked at Con's ones for a while,
but I believe they are also much more straightforward than mainline...

I like Con's scheduler (partly because it uses a single array) but mainly because it's nice and simple. However, his earlier schedulers were prone to starvation (admittedly, only if you went out of your way to make it happen) and I tried to convince him to use the anti starvation mechanism in my SPA schedulers but was unsuccessful. I haven't looked at his latest scheduler that sparked all this furore so can't comment on it.

Quoted 3 lines

For example, let's say all else is equal between them, then why would we go with the O(logN) implementation rather than the O(1)?

In the highly unlikely event that you can't separate them on technical grounds, Occam's razor recommends choosing the simplest solution. :-)

To digress, my main concern is that load balancing is being lumped in with this new change. It's becoming "accept this beg lump of new code or nothing". I'd rather see a good fix to the intra runqueue/CPU scheduler problem implemented first and then if there really are any outstanding problems with the load balancer attack them later. Them all being mixed up together gives me a nasty deja vu of impending disaster.

Peter

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#306 lore raw
Quoted 7 lines · Peter Williams
Quoted 2 lines · Nick Piggin

And my scheduler for example cuts down the amount of policy code and code size significantly.

Yours is one of the smaller patches mainly because you perpetuate (or you did in the last one I looked at) the (horrible to my eyes) dual array (active/expired) mechanism.

Actually, I wasn't comparing with other out of tree schedulers (but it is good to know mine is among the smaller ones). I was comparing with the mainline scheduler, which also has the dual arrays.

Quoted 3 lines

That this idea was bad should have
been apparent to all as soon as the decision was made to excuse some tasks from being moved from the active array to the expired array. This

My patch doesn't implement any such excusing.

Quoted 5 lines

essentially meant that there would be circumstances where extreme unfairness (to the extent of starvation in some cases) -- the very things that the mechanism was originally designed to ensure (as far as I can gather). Right about then in the development of the O(1) scheduler alternative solutions should have been sought.

Fairness has always been my first priority, and I consider it a bug if it is possible for any process to get more CPU time than a CPU hog over the long term. Or over another task doing the same thing, for that matter.

Quoted 2 lines

Other hints that it was a bad idea was the need to transfer time slices between children and parents during fork() and exit().

I don't see how that has anything to do with dual arrays. If you put a new child at the back of the queue, then your various interactive shell commands that typically do a lot of dependant forking get slowed right down behind your compile job. If you give a new child its own timeslice irrespective of the parent, then you have things like 'make' (which doesn't use a lot of CPU time) spawning off lots of high priority children.

You need to do _something_ (Ingo's does). I don't see why this would be tied with a dual array. FWIW, mine doesn't do anything on exit() like most others, but it may need more tuning in this area.

Quoted 3 lines

This disregard for the dual array mechanism has prevented me from looking at the rest of your scheduler in any great detail so I can't comment on any other ideas that may be in there.

Well I wasn't really asking you to review it. As I said, everyone has their own idea of what a good design does, and review can't really distinguish between the better of two reasonable designs.

A fair evaluation of the alternatives seems like a good idea though. Nobody is actually against this, are they?

Quoted 10 lines
Quoted 2 lines

I haven't looked at Con's ones for a while,
but I believe they are also much more straightforward than mainline...

I like Con's scheduler (partly because it uses a single array) but mainly because it's nice and simple. However, his earlier schedulers were prone to starvation (admittedly, only if you went out of your way to make it happen) and I tried to convince him to use the anti starvation mechanism in my SPA schedulers but was unsuccessful. I haven't looked at his latest scheduler that sparked all this furore so can't comment on it.

I agree starvation or unfairness is unacceptable for a new scheduler.

Quoted 5 lines
Quoted 2 lines

For example, let's say all else is equal between them, then why would we go with the O(logN) implementation rather than the O(1)?

In the highly unlikely event that you can't separate them on technical grounds, Occam's razor recommends choosing the simplest solution. :-)

O(logN) vs O(1) is technical grounds.

But yeah, see my earlier comment: simplicity would be a factor too.

#307 lore raw
Quoted 25 lines · Nick Piggin
Quoted 4 lines · Peter Williams
Quoted 2 lines · Nick Piggin

And my scheduler for example cuts down the amount of policy code and code size significantly.

Yours is one of the smaller patches mainly because you perpetuate (or you did in the last one I looked at) the (horrible to my eyes) dual array (active/expired) mechanism.

Actually, I wasn't comparing with other out of tree schedulers (but it is good to know mine is among the smaller ones). I was comparing with the mainline scheduler, which also has the dual arrays.

Quoted 2 lines

That this idea was bad should have
been apparent to all as soon as the decision was made to excuse some tasks from being moved from the active array to the expired array. This

My patch doesn't implement any such excusing.

Quoted 1 line

essentially meant that there would be circumstances where extreme unfairness (to the extent of starvation in some cases) -- the very things that the mechanism was originally designed to ensure (as far as I can gather). Right about then in the development of the O(1) scheduler alternative solutions should have been sought.

Fairness has always been my first priority, and I consider it a bug if it is possible for any process to get more CPU time than a CPU hog over the long term. Or over another task doing the same thing, for that matter.

Quoted 3 lines
Quoted 1 line

Other hints that it was a bad idea was the need to transfer time slices between children and parents during fork() and exit().

I don't see how that has anything to do with dual arrays.

It's totally to do with the dual arrays. The only real purpose of the time slice in O(1) (regardless of what its perceived purpose was) was to control the switching between the arrays.

Quoted 7 lines

If you put
a new child at the back of the queue, then your various interactive shell commands that typically do a lot of dependant forking get slowed right down behind your compile job. If you give a new child its own timeslice irrespective of the parent, then you have things like 'make' (which doesn't use a lot of CPU time) spawning off lots of high priority children.

This is an artefact of trying to control nice using time slices while using them for controlling array switching and whatever else they were being used for. Priority (static and dynamic) is the the best way to implement nice.

Quoted 6 lines

You need to do _something_ (Ingo's does). I don't see why this would be tied with a dual array. FWIW, mine doesn't do anything on exit() like most others, but it may need more tuning in this area.

Quoted 8 lines
Quoted 1 line

This disregard for the dual array mechanism has prevented me from looking at the rest of your scheduler in any great detail so I can't comment on any other ideas that may be in there.

Well I wasn't really asking you to review it. As I said, everyone has their own idea of what a good design does, and review can't really distinguish between the better of two reasonable designs.

A fair evaluation of the alternatives seems like a good idea though. Nobody is actually against this, are they?

No. It would be nice if the basic ideas that each scheduler tries to implement could be extracted and explained though. This could lead to a melding of ideas that leads to something quite good.

Quoted 6 lines
Quoted 5 lines
Quoted 4 lines

I haven't looked at Con's ones for a while,
but I believe they are also much more straightforward than mainline...

I like Con's scheduler (partly because it uses a single array) but mainly because it's nice and simple. However, his earlier schedulers were prone to starvation (admittedly, only if you went out of your way to make it happen) and I tried to convince him to use the anti starvation mechanism in my SPA schedulers but was unsuccessful. I haven't looked at his latest scheduler that sparked all this furore so can't comment on it.

Quoted 8 lines

I agree starvation or unfairness is unacceptable for a new scheduler.

Quoted 3 lines
Quoted 2 lines

For example, let's say all else is equal between them, then why would we go with the O(logN) implementation rather than the O(1)?

In the highly unlikely event that you can't separate them on technical grounds, Occam's razor recommends choosing the simplest solution. :-)

O(logN) vs O(1) is technical grounds.

In that case I'd go O(1) provided that the k factor for the O(1) wasn't greater than O(logN)'s k factor multiplied by logMaxN.

Quoted 2 lines

But yeah, see my earlier comment: simplicity would be a factor too.

Peter

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#308 lore raw
Quoted 9 lines · Peter Williams
Quoted 4 lines · Nick Piggin
Quoted 2 lines

Other hints that it was a bad idea was the need to transfer time slices between children and parents during fork() and exit().

I don't see how that has anything to do with dual arrays.

It's totally to do with the dual arrays. The only real purpose of the time slice in O(1) (regardless of what its perceived purpose was) was to control the switching between the arrays.

The O(1) design is pretty convoluted in that regard. In my scheduler, the only purpose of the arrays is to renew time slices.

The fork/exit logic is added to make interactivity better. Ingo's scheduler has similar equivalent logic.

Quoted 8 lines
Quoted 7 lines

If you put
a new child at the back of the queue, then your various interactive shell commands that typically do a lot of dependant forking get slowed right down behind your compile job. If you give a new child its own timeslice irrespective of the parent, then you have things like 'make' (which doesn't use a lot of CPU time) spawning off lots of high priority children.

Quoted 4 lines

This is an artefact of trying to control nice using time slices while using them for controlling array switching and whatever else they were being used for. Priority (static and dynamic) is the the best way to implement nice.

I don't like the timeslice based nice in mainline. It's too nasty with latencies. nicksched is far better in that regard IMO.

But I don't know how you can assert a particular way is the best way to do something.

Quoted 37 lines
Quoted 9 lines

You need to do _something_ (Ingo's does). I don't see why this would be tied with a dual array. FWIW, mine doesn't do anything on exit() like most others, but it may need more tuning in this area.

Quoted 3 lines

This disregard for the dual array mechanism has prevented me from looking at the rest of your scheduler in any great detail so I can't comment on any other ideas that may be in there.

Quoted 6 lines

Well I wasn't really asking you to review it. As I said, everyone has their own idea of what a good design does, and review can't really distinguish between the better of two reasonable designs.

A fair evaluation of the alternatives seems like a good idea though. Nobody is actually against this, are they?

No. It would be nice if the basic ideas that each scheduler tries to implement could be extracted and explained though. This could lead to a melding of ideas that leads to something quite good.

Quoted 17 lines
Quoted 11 lines
Quoted 4 lines

I haven't looked at Con's ones for a while,
but I believe they are also much more straightforward than mainline...

I like Con's scheduler (partly because it uses a single array) but mainly because it's nice and simple. However, his earlier schedulers were prone to starvation (admittedly, only if you went out of your way to make it happen) and I tried to convince him to use the anti starvation mechanism in my SPA schedulers but was unsuccessful. I haven't looked at his latest scheduler that sparked all this furore so can't comment on it.

I agree starvation or unfairness is unacceptable for a new scheduler.

Quoted 2 lines
Quoted 2 lines

For example, let's say all else is equal between them, then why would we go with the O(logN) implementation rather than the O(1)?

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

In the highly unlikely event that you can't separate them on technical grounds, Occam's razor recommends choosing the simplest solution. :-)

O(logN) vs O(1) is technical grounds.

In that case I'd go O(1) provided that the k factor for the O(1) wasn't greater than O(logN)'s k factor multiplied by logMaxN.

Yes, or even significantly greater around typical large sizes of N.

#309 lore raw
Quoted 20 lines · Nick Piggin
Quoted 4 lines · Peter Williams
Quoted 2 lines · Nick Piggin
Quoted 1 line

Other hints that it was a bad idea was the need to transfer time slices between children and parents during fork() and exit().

I don't see how that has anything to do with dual arrays.

It's totally to do with the dual arrays. The only real purpose of the time slice in O(1) (regardless of what its perceived purpose was) was to control the switching between the arrays.

The O(1) design is pretty convoluted in that regard. In my scheduler, the only purpose of the arrays is to renew time slices.

The fork/exit logic is added to make interactivity better. Ingo's scheduler has similar equivalent logic.

Quoted 7 lines
Quoted 7 lines

If you put
a new child at the back of the queue, then your various interactive shell commands that typically do a lot of dependant forking get slowed right down behind your compile job. If you give a new child its own timeslice irrespective of the parent, then you have things like 'make' (which doesn't use a lot of CPU time) spawning off lots of high priority children.

Quoted 7 lines
Quoted 1 line

This is an artefact of trying to control nice using time slices while using them for controlling array switching and whatever else they were being used for. Priority (static and dynamic) is the the best way to implement nice.

I don't like the timeslice based nice in mainline. It's too nasty with latencies. nicksched is far better in that regard IMO.

But I don't know how you can assert a particular way is the best way to do something.

I should have added "I may be wrong but I think that ...".

My opinion is based on a lot of experience with different types of scheduler design and the observation from gathering scheduling statistics while playing with these schedulers that the size of the time slices we're talking about is much larger than the CPU chunks most tasks use in any one go so time slice size has no real effect on most tasks and the faster CPUs become the more this becomes true.

Quoted 23 lines
Quoted 23 lines
Quoted 7 lines

You need to do _something_ (Ingo's does). I don't see why this would be tied with a dual array. FWIW, mine doesn't do anything on exit() like most others, but it may need more tuning in this area.

Quoted 7 lines
Quoted 1 line

This disregard for the dual array mechanism has prevented me from looking at the rest of your scheduler in any great detail so I can't comment on any other ideas that may be in there.

Well I wasn't really asking you to review it. As I said, everyone has their own idea of what a good design does, and review can't really distinguish between the better of two reasonable designs.

A fair evaluation of the alternatives seems like a good idea though. Nobody is actually against this, are they?

No. It would be nice if the basic ideas that each scheduler tries to implement could be extracted and explained though. This could lead to a melding of ideas that leads to something quite good.

Quoted 7 lines
Quoted 4 lines
Quoted 3 lines

I haven't looked at Con's ones for a while,
but I believe they are also much more straightforward than mainline...

I like Con's scheduler (partly because it uses a single array) but mainly because it's nice and simple. However, his earlier schedulers were prone to starvation (admittedly, only if you went out of your way to make it happen) and I tried to convince him to use the anti starvation mechanism in my SPA schedulers but was unsuccessful. I haven't looked at his latest scheduler that sparked all this furore so can't comment on it.

I agree starvation or unfairness is unacceptable for a new scheduler.

Quoted 7 lines
Quoted 5 lines
Quoted 4 lines
Quoted 3 lines
Quoted 2 lines

For example, let's say all else is equal between them, then why would we go with the O(logN) implementation rather than the O(1)?

In the highly unlikely event that you can't separate them on technical grounds, Occam's razor recommends choosing the simplest solution. :-)

O(logN) vs O(1) is technical grounds.

In that case I'd go O(1) provided that the k factor for the O(1) wasn't greater than O(logN)'s k factor multiplied by logMaxN.

Yes, or even significantly greater around typical large sizes of N.

Yes. In fact its' probably better to use the maximum number of threads allowed on the system for N. We know that value don't we?

Peter

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#310 lore raw
Quoted 7 lines · Peter Williams
Quoted 5 lines · Nick Piggin

I don't like the timeslice based nice in mainline. It's too nasty with latencies. nicksched is far better in that regard IMO.

But I don't know how you can assert a particular way is the best way to do something.

Quoted 8 lines

I should have added "I may be wrong but I think that ...".

My opinion is based on a lot of experience with different types of scheduler design and the observation from gathering scheduling statistics while playing with these schedulers that the size of the time slices we're talking about is much larger than the CPU chunks most tasks use in any one go so time slice size has no real effect on most tasks and the faster CPUs become the more this becomes true.

For desktop loads, maybe. But for things that are compute bound, the cost of context switching I believe still gets worse as CPUs continue to be able to execute more instructions per cycle, get clocked faster, and get larger caches.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

In that case I'd go O(1) provided that the k factor for the O(1) wasn't greater than O(logN)'s k factor multiplied by logMaxN.

Yes, or even significantly greater around typical large sizes of N.

Yes. In fact its' probably better to use the maximum number of threads allowed on the system for N. We know that value don't we?

Well we might be able to work it out by looking at the tunables or amount of kernel memory available, but I guess it is hard to just pick a number.

I'll try running a few more benchmarks.

#311 lore raw
In reply to Peter Williams
Quoted 13 lines · Peter Williams
Quoted 2 lines

And my scheduler for example cuts down the amount of policy code and code size significantly.

Yours is one of the smaller patches mainly because you perpetuate (or you did in the last one I looked at) the (horrible to my eyes) dual array (active/expired) mechanism. That this idea was bad should have been apparent to all as soon as the decision was made to excuse some tasks from being moved from the active array to the expired array. This essentially meant that there would be circumstances where extreme unfairness (to the extent of starvation in some cases) -- the very things that the mechanism was originally designed to ensure (as far as I can gather). Right about then in the development of the O(1) scheduler alternative solutions should have been sought.

in hindsight i'd agree. But back then we were clearly not ready for fine-grained accurate statistics + trees (cpus are alot faster at more complex arithmetics today, plus people still believed that low-res can be done well enough), and taking out any of these two concepts from CFS would result in a similarly complex runqueue implementation. Also, the array switch was just thought to be of another piece of 'if the heuristics go wrong, we fall back to an array switch' logic, right in line with the other heuristics. And you have to accept it, mainline's ability to auto-renice make -j jobs (and other CPU hogs) was quite a plus for developers, so it had (and probably still has) quite some inertia.

Ingo

#312 lore raw
Quoted 6 lines · Ingo Molnar
Quoted 2 lines · Peter Williams
Quoted 1 line

And my scheduler for example cuts down the amount of policy code and code size significantly.

Yours is one of the smaller patches mainly because you perpetuate (or you did in the last one I looked at) the (horrible to my eyes) dual array (active/expired) mechanism. That this idea was bad should have been apparent to all as soon as the decision was made to excuse some tasks from being moved from the active array to the expired array. This essentially meant that there would be circumstances where extreme unfairness (to the extent of starvation in some cases) -- the very things that the mechanism was originally designed to ensure (as far as I can gather). Right about then in the development of the O(1) scheduler alternative solutions should have been sought.

in hindsight i'd agree.

Hindsight's a wonderful place isn't it :-) and, of course, it's where I was making my comments from.

Quoted 2 lines

But back then we were clearly not ready for fine-grained accurate statistics + trees (cpus are alot faster at more complex arithmetics today, plus people still believed that low-res can be done well enough), and taking out any of these two concepts from CFS would result in a similarly complex runqueue implementation.

I disagree. The single priority array with a promotion mechanism that I use in the SPA schedulers can do the job of avoiding starvation with no measurable increase in the overhead. Fairness, nice, good interactive responsiveness can then be managed by how you determine tasks' dynamic priorities.

Quoted 1 line

Also, the array switch was just thought to be of another piece of 'if the heuristics go wrong, we fall back to an array switch' logic, right in line with the other heuristics. And you have to accept it, mainline's ability to auto-renice make -j jobs (and other CPU hogs) was quite a plus for developers, so it had (and probably still has) quite some inertia.

I agree, it wasn't totally useless especially for the average user. My main problem with it was that the effect of "nice" wasn't consistent or predictable enough for reliable resource allocation.

I also agree with the aims of the various heuristics i.e. you have to be unfair and give some tasks preferential treatment in order to give the users the type of responsiveness that they want. It's just a shame that it got broken in the process but as you say it's easier to see these things in hindsight than in the middle of the melee.

Peter

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#313 lore raw
In reply to Con Kolivas

* Con Kolivas <[email protected]> wrote:

[ i'm quoting this bit out of order: ]

Quoted 4 lines

2. Since then I've been thinking/working on a cpu scheduler design that takes away all the guesswork out of scheduling and gives very predictable, as fair as possible, cpu distribution and latency while preserving as solid interactivity as possible within those confines.

yeah. I think you were right on target with this call. I've applied the sched.c change attached at the bottom of this mail to the CFS patch, if you dont mind. (or feel free to suggest some other text instead.)

Quoted 5 lines

1. I tried in vain some time ago to push a working extensable pluggable cpu scheduler framework (based on wli's work) for the linux kernel. It was perma-vetoed by Linus and Ingo (and Nick also said he didn't like it) as being absolutely the wrong approach and that we should never do that. [...]

i partially replied to that point to Will already, and i'd like to make it clear again: yes, i rejected plugsched 2-3 years ago (which already drifted away from wli's original codebase) and i would still reject it today.

First and foremost, please dont take such rejections too personally - i had my own share of rejections (and in fact, as i mentioned it in a previous mail, i had a fair number of complete project throwaways:
4g:4g, in-kernel Tux, irqrate and many others). I know that they can hurt and can demoralize, but if i dont like something it's my job to tell that.

Can i sum up your argument as: "you rejected plugsched, but then why on earth did you modularize portions of the scheduler in CFS? Isnt your position thus woefully inconsistent?" (i'm sure you would never put it this impolitely though, but i guess i can flame myself with impunity ;)

While having an inconsistent position isnt a terminal sin in itself, please realize that the scheduler classes code in CFS is quite different from plugsched: it was a result of what i saw to be technological pressure for _internal modularization_. (This internal/policy modularization aspect is something that Will said was present in his original plugsched code, but which aspect i didnt see in the plugsched patches that i reviewed.)

That possibility never even occured to me to until 3 days ago. You never raised it either AFAIK. No patches to simplify the scheduler that way were ever sent. Plugsched doesnt even touch the core load-balancer for example, and most of the time i spent with the modularization was to get the load-balancing details right. So it's really apples to oranges.

My view about plugsched: first please take a look at the latest plugsched code:

http://downloads.sourceforge.net/cpuse/plugsched-6.5-for-2.6.20.patch

  26 files changed, 8951 insertions(+), 1495 deletions(-)

As an experiment i've removed all the add-on schedulers (both the core and the include files, only kept the vanilla one) from the plugsched patch (and the makefile and kconfig complications, etc), to see the 'infrastructure cost', and it still gave:

  12 files changed, 1933 insertions(+), 1479 deletions(-)

that's the extra complication i didnt like 3 years ago and which i still dont like today. What the current plugsched code does is that it simplifies the adding of new experimental schedulers, but it doesnt really do what i wanted: to simplify the _scheduler itself_. Personally i'm still not primarily interested in having a large selection of schedulers, i'm mainly interested in a good and maintainable scheduler that works for people.

so the rejection was on these grounds, and i still very much stand by that position here and today: i didnt want to see the Linux scheduler landscape balkanized and i saw no technological reasons for the complication that external modularization brings.

the new scheding classes code in the CFS patch was not a result of "oh, i want to write a new scheduler, lets make schedulers pluggable" kind of thinking. That result was just a side-effect of it. (and as you correctly noted it, the CFS related modularization is incomplete).

Btw., the thing that triggered the scheduling classes code wasnt even plugsched or RSDL/SD, it was Mike's patches. Mike had an itch and he fixed it within the framework of the existing scheduler, and the end result behaved quite well when i threw various testloads on it.

But i felt a bit uncomfortable that it added another few hundred lines of code to an already complex sched.c. This felt unnatural so i mailed Mike that i'd attempt to clean these infrastructure aspects of sched.c up a bit so that it becomes more hackable to him. Thus 3 days ago, without having made up my mind about anything, i started this experiment (which ended up in the modularization and in the CFS scheduler) to simplify the code and to enable Mike to fix such itches in an easier way. By your logic Mike should in fact be quite upset about this: if the new code works out and proves to be useful then it obsoletes a whole lot of code of him!

Quoted 4 lines

For weeks now, Ingo has said that the interactivity regressions were showstoppers and we should address them, never mind the fact that the so-called regressions were purely "it slows down linearly with load" which to me is perfectly desirable behaviour. [...]

yes. For me the first thing when considering a large scheduler patch is:
"does a patch do what it claims" and "does it work". If those goals are met (and if it's a complete scheduler i actually try it quite extensively) then i look at the code cleanliness issues. Mike's patch was the first one that seemed to meet that threshold in my own humble testing, and CFS was a direct result of that.

note that i tried the same workloads with CFS and while it wasnt as good as mainline, it handled them better than SD. Mike reported the same, and Mark Lord (who too reported SD interactivity problems) reported success yesterday too.

(but .. CFS is a mere 2 days old so we cannot really tell anything with certainty yet.)

Quoted 6 lines

[...] However at one stage I virtually begged for support with my attempts and help with the code. Dmitry Adamushko is the only person who actually helped me with the code in the interim, while others poked sticks at it. Sure the sticks helped at times but the sticks always seemed to have their ends kerosene doused and flaming for reasons I still don't get. No other help was forthcoming.

i'm really sorry you got that impression.

in 2004 i had a good look at the staircase scheduler and said:

http://www.uwsg.iu.edu/hypermail/linux/kernel/0408.0/1146.html

"But in general i'm quite positive about the staircase scheduler."

and even tested it and gave you feedback:

http://lwn.net/Articles/96562/

i think i even told Andrew that i dont really like pluggable schedulers and if there's any replacement for the current scheduler then that would be a full replacement, and it would be the staircase scheduler.

Hey, i told this to you as recently as 1 month ago as well:

http://lkml.org/lkml/2007/3/8/54

"cool! I like this even more than i liked your original staircase
scheduler from 2 years ago :)"

Ingo

----------->

kernel/sched.c +1 -0
Index: linux/kernel/sched.c
===================================================================
@@ -16,6 +16,7 @@
  *		by Davide Libenzi, preemptible kernel bits by Robert Love.
  *  2003-09-03	Interactivity tuning by Con Kolivas.
  *  2004-04-02	Scheduler domains code by Nick Piggin
+ *  2007-04-15	Con Kolivas was dead right: fairness matters! :)
  */
 
#314 lore raw
Quoted 4 lines · Ingo Molnar

so the rejection was on these grounds, and i still very much stand by that position here and today: i didnt want to see the Linux scheduler landscape balkanized and i saw no technological reasons for the complication that external modularization brings.

But "balkanization" is a good thing. "Monoculture" is a bad thing.

Look at what happened with I/O scheduling. Opening things up to some new ideas by making it possible to select your I/O scheduler took us from 10 years of stagnation to healthy, competitive development, which gave us a substantially better I/O scheduler.

Look at what's happening right now with TCP congestion algorithms. We've had decades of tweaking Reno slightly now turned into a vibrant research area with lots of radical alternatives. A winner will eventually emerge and it will probably look quite a bit different than Reno.

Similar things have gone on since the beginning with filesystems on Linux. Being able to easily compare filesystems head to head has been immensely valuable in improving our 'core' Linux filesystems.

And what we've had up to now is a scheduler monoculture. Until Andrew put RSDL in -mm, if people wanted to experiment with other schedulers, they had to go well off the beaten path to do it. So all the people who've been hopelessy frustrated with the mainline scheduler go off to the -ck ghetto, or worse, stick with 2.4.

Whether your motivations have been protectionist or merely shortsighted, you've stomped pretty heavily on alternative scheduler development by completely rejecting the whole plugsched concept. If we'd opened up mainline to a variety of schedulers _3 years ago_, we'd probably have gotten to where we are today much sooner.

Hopefully, the next time Rik suggests pluggable page replacement algorithms, folks will actually seriously consider it.

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#315 lore raw
Quoted 4 lines · Matt Mackall

Look at what happened with I/O scheduling. Opening things up to some new ideas by making it possible to select your I/O scheduler took us from 10 years of stagnation to healthy, competitive development, which gave us a substantially better I/O scheduler.

actually, 2-3 years ago we already had IO schedulers, and my opinion against plugsched back then (also shared by Nick and Linus) was very much considering them. There are at least 4 reasons why I/O schedulers are different from CPU schedulers:

1) CPUs are a non-persistent resource shared by _all_ tasks and workloads in the system. Disks are _persistent_ resources very much attached to specific workloads. (If tasks had to be 'persistent' to the CPU they were started on we'd have much different scheduling technology, and there would be much less complexity.) More analogous to CPU schedulers would perhaps be VM/MM schedulers, and those tend to be hard to modularize in a technologically sane way too. (and unlike disks there's no good generic way to attach VM/MM schedulers to particular workloads.) So it's apples to oranges.

in practice it comes down to having one good scheduler that runs all workloads on a system reasonably well. And given that a very large portion of system runs mixed workloads, the demand for one good scheduler is pretty high. While i can run with mixed IO schedulers just fine.

2) plugsched did not allow on the fly selection of schedulers, nor did it allow a per CPU selection of schedulers. IO schedulers you can change per disk, on the fly, making them much more useful in practice. Also, IO schedulers (while definitely not being slow!) are alot less performance sensitive than CPU schedulers.

3) I/O schedulers are pretty damn clean code, and plugsched, at least the last version i saw of it, didnt come even close.

4) the good thing that happened to I/O, after years of stagnation isnt I/O schedulers. The good thing that happened to I/O is called Jens Axboe. If you care about the I/O subystem then print that name out and hang it on the wall. That and only that is what mattered.

all in one, while there are definitely uses (embedded would like to have a smaller/different scheduler, etc.), the technical case for modularization for the sake of selectability is alot lower for CPU schedulers than it is for I/O schedulers.

nor was the non-modularity of some piece of code ever an impediment to competition. May i remind you of the pretty competitive SLAB allocator landscape, resulting in things like the SLOB allocator, written by yourself? ;-)

Ingo

#316 lore raw
Quoted 12 lines · Ingo Molnar
Quoted 4 lines · Matt Mackall

Look at what happened with I/O scheduling. Opening things up to some new ideas by making it possible to select your I/O scheduler took us from 10 years of stagnation to healthy, competitive development, which gave us a substantially better I/O scheduler.

actually, 2-3 years ago we already had IO schedulers, and my opinion against plugsched back then (also shared by Nick and Linus) was very much considering them. There are at least 4 reasons why I/O schedulers are different from CPU schedulers:

...

Quoted 2 lines

3) I/O schedulers are pretty damn clean code, and plugsched, at least the last version i saw of it, didnt come even close.

That's irrelevant. Plugsched was an attempt to get alternative schedulers exposure in mainline. I know, because I remember encouraging Bill to pursue it. Not only did you veto plugsched (which may have been a perfectly reasonable thing to do), but you also vetoed the whole concept of multiple schedulers in the tree too. "We don't want to balkanize the scheduling landscape".

And that latter part is what I'm claiming has set us back for years. It's not a technical argument but a strategic one. And it's just not a good strategy.

Quoted 4 lines

4) the good thing that happened to I/O, after years of stagnation isnt I/O schedulers. The good thing that happened to I/O is called Jens Axboe. If you care about the I/O subystem then print that name out and hang it on the wall. That and only that is what mattered.

Disagree. Things didn't actually get interesting until Nick showed up with AS and got it in-tree to demonstrate the huge amount of room we had for improvement. It took several iterations of AS and CFQ (with a couple complete rewrites) before CFQ began to look like the winner. The resulting time-sliced CFQ was fairly heavily influenced by the ideas in AS.

Similarly, things in scheduler land had been pretty damn boring until Con finally got Andrew to take one of his schedulers for a spin.

Quoted 4 lines

nor was the non-modularity of some piece of code ever an impediment to competition. May i remind you of the pretty competitive SLAB allocator landscape, resulting in things like the SLOB allocator, written by yourself? ;-)

Thankfully no one came out and said "we don't want to balkanize the allocator landscape" when I submitted it or I probably would have just dropped it, rather than painfully dragging it along out of tree for years. I'm not nearly the glutton for punishment that Con is. :-P

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#317 lore raw
Quoted 7 lines · Matt Mackall
Quoted 4 lines · Ingo Molnar

4) the good thing that happened to I/O, after years of stagnation isnt I/O schedulers. The good thing that happened to I/O is called Jens Axboe. If you care about the I/O subystem then print that name out and hang it on the wall. That and only that is what mattered.

Quoted 6 lines

Disagree. Things didn't actually get interesting until Nick showed up with AS and got it in-tree to demonstrate the huge amount of room we had for improvement. It took several iterations of AS and CFQ (with a couple complete rewrites) before CFQ began to look like the winner. The resulting time-sliced CFQ was fairly heavily influenced by the ideas in AS.

Well to be fair, Jens had just implemented deadline, which got me interested ;)

Actually, I would still like to be able to deprecate deadline for AS, because AS has a tunable that you can switch to turn off read anticipation and revert to deadline behaviour (or very close to).

It would have been nice if CFQ were then a layer on top of AS that implemented priorities (or vice versa). And then AS could be deprecated and we'd be back to 1 primary scheduler.

Well CFQ seems to be going in the right direction with that, however some large users still find AS faster for some reason...

Anyway, moral of the story is that I think it would have been nice if we hadn't proliferated IO schedulers, however in practice it isn't easy to just layer features on top of each other, and also keeping deadline helped a lot to be able to debug and examine performance regressions and actually get code upstream. And this was true even when it was globally boottine switchable only.

I'd prefer if we kept a single CPU scheduler in mainline, because I think that simplifies analysis and focuses testing. I think we can have one that is good enough for everyone. But if the only other option for progress is that Linus or Andrew just pull one out of a hat, then I would rather merge all of them. Yes I think Con's scheduler should get a fair go, ditto for Ingo's, mine, and anyone else's.

Quoted 9 lines
Quoted 4 lines

nor was the non-modularity of some piece of code ever an impediment to competition. May i remind you of the pretty competitive SLAB allocator landscape, resulting in things like the SLOB allocator, written by yourself? ;-)

Thankfully no one came out and said "we don't want to balkanize the allocator landscape" when I submitted it or I probably would have just dropped it, rather than painfully dragging it along out of tree for years. I'm not nearly the glutton for punishment that Con is. :-P

I don't think this is a fault of the people or the code involved. We just didn't have much collective drive to replace the scheduler, and even less an idea of how to decide between any two of them.

I've kept nicksched around since 2003 or so and no hard feelings ;)

#318 lore raw
Quoted 2 lines · Nick Piggin

I'd prefer if we kept a single CPU scheduler in mainline, because I think that simplifies analysis and focuses testing.

I think you'll find something like 80-90% of the testing will be done on the default choice, even if other choices exist. So you really won't have much of a problem here.

But when the only choice for other schedulers is to go out-of-tree, then only 1% of the people will try it out and those people are guaranteed to be the ones who saw scheduling problems in mainline. So the alternative won't end up getting any testing on many of the workloads that work fine in mainstream so their feedback won't tell you very much at all.

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#319 lore raw
Quoted 8 lines · Matt Mackall
Quoted 2 lines · Nick Piggin

I'd prefer if we kept a single CPU scheduler in mainline, because I think that simplifies analysis and focuses testing.

I think you'll find something like 80-90% of the testing will be done on the default choice, even if other choices exist. So you really won't have much of a problem here.

Quoted 6 lines

But when the only choice for other schedulers is to go out-of-tree, then only 1% of the people will try it out and those people are guaranteed to be the ones who saw scheduling problems in mainline. So the alternative won't end up getting any testing on many of the workloads that work fine in mainstream so their feedback won't tell you very much at all.

Yeah I concede that perhaps it is the only way to get things going any further. But how do we decide if and when the current scheduler should be demoted from default, and which should replace it?

#320 lore raw
Quoted 16 lines · Nick Piggin
Quoted 8 lines · Matt Mackall
Quoted 2 lines · Nick Piggin

I'd prefer if we kept a single CPU scheduler in mainline, because I think that simplifies analysis and focuses testing.

I think you'll find something like 80-90% of the testing will be done on the default choice, even if other choices exist. So you really won't have much of a problem here.

Quoted 6 lines

But when the only choice for other schedulers is to go out-of-tree, then only 1% of the people will try it out and those people are guaranteed to be the ones who saw scheduling problems in mainline. So the alternative won't end up getting any testing on many of the workloads that work fine in mainstream so their feedback won't tell you very much at all.

Quoted 3 lines

Yeah I concede that perhaps it is the only way to get things going any further. But how do we decide if and when the current scheduler should be demoted from default, and which should replace it?

Step one is ship both in -mm. If that doesn't give us enough confidence, ship both in mainline. If that doesn't give us enough confidence, wait until vendors ship both. Eventually a clear picture should emerge. If it doesn't, either the change is not significant or no one cares.

But it really is important to be able to do controlled experiments on this stuff with little effort. That's the recipe for getting lots of valid feedback.

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#321 lore raw
In reply to Matt Mackall
Quoted 9 lines · Matt Mackall

That's irrelevant. Plugsched was an attempt to get alternative schedulers exposure in mainline. I know, because I remember encouraging Bill to pursue it. Not only did you veto plugsched (which may have been a perfectly reasonable thing to do), but you also vetoed the whole concept of multiple schedulers in the tree too. "We don't want to balkanize the scheduling landscape".
And that latter part is what I'm claiming has set us back for years. It's not a technical argument but a strategic one. And it's just not a good strategy.

[... excellent post trimmed...]

These are some rather powerful arguments. I think I'll actually start looking at plugsched again.

-- wli

#322 lore raw
In reply to Ingo Molnar
Quoted 5 lines · Ingo Molnar

2) plugsched did not allow on the fly selection of schedulers, nor did it allow a per CPU selection of schedulers. IO schedulers you can change per disk, on the fly, making them much more useful in practice. Also, IO schedulers (while definitely not being slow!) are alot less performance sensitive than CPU schedulers.

One of the reasons I never posted my own code is that it never met its own design goals, which absolutely included switching on the fly. I think Peter Williams may have done something about that. It was my hope to be able to do insmod sched_foo.ko until it became clear that the effort it was intended to assist wasn't going to get even the limited hardware access required, at which point I largely stopped working on it.

Quoted 2 lines · Ingo Molnar

3) I/O schedulers are pretty damn clean code, and plugsched, at least the last version i saw of it, didnt come even close.

I'm not sure what happened there. It wasn't a big enough patch to take hits in this area due to getting overwhelmed by the programming burden like some other efforts of mine. Maybe things started getting ugly once on-the-fly switching entered the picture. My guess is that Peter Williams will have to chime in here, since things have diverged enough from my one-time contribution 4 years ago.

-- wli

#323 lore raw
Quoted 10 lines · William Lee Irwin III
Quoted 5 lines · Ingo Molnar

2) plugsched did not allow on the fly selection of schedulers, nor did it allow a per CPU selection of schedulers. IO schedulers you can change per disk, on the fly, making them much more useful in practice. Also, IO schedulers (while definitely not being slow!) are alot less performance sensitive than CPU schedulers.

One of the reasons I never posted my own code is that it never met its own design goals, which absolutely included switching on the fly. I think Peter Williams may have done something about that.

I didn't but some students did.

In a previous life, I did implement a runtime configurable CPU scheduling mechanism (implemented on True64, Solaris and Linux) that allowed schedulers to be loaded as modules at run time. This was released commercially on True64 and Solaris. So I know that it can be done.

I have thought about doing something similar for the SPA schedulers which differ in only small ways from each other but lack motivation.

Quoted 11 lines

It was my hope
to be able to do insmod sched_foo.ko until it became clear that the effort it was intended to assist wasn't going to get even the limited hardware access required, at which point I largely stopped working on it.

Quoted 2 lines · Ingo Molnar

3) I/O schedulers are pretty damn clean code, and plugsched, at least the last version i saw of it, didnt come even close.

Quoted 6 lines

I'm not sure what happened there. It wasn't a big enough patch to take hits in this area due to getting overwhelmed by the programming burden like some other efforts of mine. Maybe things started getting ugly once on-the-fly switching entered the picture. My guess is that Peter Williams will have to chime in here, since things have diverged enough from my one-time contribution 4 years ago.

From my POV, the current version of plugsched is considerably simpler than it was when I took the code over from Con as I put considerable effort into minimizing code overlap in the various schedulers.

I also put considerable effort into minimizing any changes to the load balancing code (something Ingo seems to think is a deficiency) and the result is that plugsched allows "intra run queue" scheduling to be easily modified WITHOUT effecting load balancing. To my mind scheduling and load balancing are orthogonal and keeping them that way simplifies things.

As Ingo correctly points out, plugsched does not allow different schedulers to be used per CPU but it would not be difficult to modify it so that they could. Although I've considered doing this over the years I decided not to as it would just increase the complexity and the amount of work required to keep the patch set going. About six months ago I decided to reduce the amount of work I was doing on plugsched (as it was obviously never going to be accepted) and now only publish patches against the vanilla kernel's major releases (and the only reason that I kept doing that is that the download figures indicated that about 80 users were interested in the experiment).

Peter
PS I no longer read LKML (due to time constraints) and would appreciate it if I could be CC'd on any e-mails suggesting scheduler changes.
PPS I'm just happy to see that Ingo has finally accepted that the vanilla scheduler was badly in need of fixing and don't really care who fixes it.
PPS Different schedulers for different aims (i.e. server or work station) do make a difference. E.g. the spa_svr scheduler in plugsched does about 1% better on kernbench than the next best scheduler in the bunch.
PPPS Con, fairness isn't always best as humans aren't very altruistic and we need to give unfair preference to interactive tasks in order to stop the users flinging their PCs out the window. But the current scheduler doesn't do this very well and is also not very good at fairness so needs to change. But the changes need to address interactive response and fairness not just fairness.

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#324 lore raw
Quoted 8 lines · William Lee Irwin III
Quoted 8 lines

One of the reasons I never posted my own code is that it never met its own design goals, which absolutely included switching on the fly. I think Peter Williams may have done something about that.
It was my hope
to be able to do insmod sched_foo.ko until it became clear that the effort it was intended to assist wasn't going to get even the limited hardware access required, at which point I largely stopped working on it.

Quoted 7 lines · Peter Williams

I didn't but some students did.
In a previous life, I did implement a runtime configurable CPU scheduling mechanism (implemented on True64, Solaris and Linux) that allowed schedulers to be loaded as modules at run time. This was released commercially on True64 and Solaris. So I know that it can be done. I have thought about doing something similar for the SPA schedulers which differ in only small ways from each other but lack motivation.

Driver models for scheduling are not so far out. AFAICS it's largely a tug-of-war over design goals, e.g. maintaining per-cpu runqueues and switching out intra-queue policies vs. switching out whole-system policies, SMP handling and all. Whether this involves load balancing depends strongly on e.g. whether you have per-cpu runqueues. A 2.4.x scheduler module, for instance, would not have a load balancer at all, as it has only one global runqueue. There are other sorts of policies wanting significant changes to SMP handling vs. the stock load balancing.

Quoted 6 lines · William Lee Irwin III
Quoted 6 lines

I'm not sure what happened there. It wasn't a big enough patch to take hits in this area due to getting overwhelmed by the programming burden like some other efforts of mine. Maybe things started getting ugly once on-the-fly switching entered the picture. My guess is that Peter Williams will have to chime in here, since things have diverged enough from my one-time contribution 4 years ago.

Quoted 9 lines · Peter Williams

From my POV, the current version of plugsched is considerably simpler than it was when I took the code over from Con as I put considerable effort into minimizing code overlap in the various schedulers. I also put considerable effort into minimizing any changes to the load balancing code (something Ingo seems to think is a deficiency) and the result is that plugsched allows "intra run queue" scheduling to be easily modified WITHOUT effecting load balancing. To my mind scheduling and load balancing are orthogonal and keeping them that way simplifies things.

ISTR rearranging things for con in such a fashion that it no longer worked out of the box (though that wasn't the intention; restructuring it to be more suited to his purposes was) and that's what he worked off of afterward. I don't remember very well what changed there as I clearly invested less effort there than the prior versions. Now that I think of it, that may have been where the sample policy demonstrating scheduling classes was lost.

Quoted 10 lines · Peter Williams

As Ingo correctly points out, plugsched does not allow different schedulers to be used per CPU but it would not be difficult to modify it so that they could. Although I've considered doing this over the years I decided not to as it would just increase the complexity and the amount of work required to keep the patch set going. About six months ago I decided to reduce the amount of work I was doing on plugsched (as it was obviously never going to be accepted) and now only publish patches against the vanilla kernel's major releases (and the only reason that I kept doing that is that the download figures indicated that about 80 users were interested in the experiment).

That's a rather different goal from what I was going on about with it, so it's all diverged quite a bit. Where I had a significant need for mucking with the entire concept of how SMP was handled, this is rather different. At this point I'm questioning the relevance of my own work, though it was already relatively marginal as it started life as an attempt at a sort of debug patch to help gang scheduling (which is in itself a rather marginally relevant feature to most users) code along.

Quoted 6 lines · Peter Williams

PS I no longer read LKML (due to time constraints) and would appreciate it if I could be CC'd on any e-mails suggesting scheduler changes. PPS I'm just happy to see that Ingo has finally accepted that the vanilla scheduler was badly in need of fixing and don't really care who fixes it.
PPS Different schedulers for different aims (i.e. server or work

Quoted 8 lines

station) do make a difference. E.g. the spa_svr scheduler in plugsched does about 1% better on kernbench than the next best scheduler in the bunch. PPPS Con, fairness isn't always best as humans aren't very altruistic and we need to give unfair preference to interactive tasks in order to stop the users flinging their PCs out the window. But the current scheduler doesn't do this very well and is also not very good at fairness so needs to change. But the changes need to address interactive response and fairness not just fairness.

Kernel compiles not so useful a benchmark. SDET, OAST, AIM7, etc. are better ones. I'd not bother citing kernel compile results.

In any event, I'm not sure what to say about different schedulers for different aims. My intentions with plugsched were not centered around production usage or intra-queue policy. I'm relatively indifferent to the notion of having pluggable CPU schedulers, intra-queue or otherwise, in mainline. I don't see any particular harm in it, but neither am I particularly motivated to have it in. I had a rather strong sense of instrumentality about it, and since it became useless to me (at a conceptual level; the implementation was never finished ot the point of dynamic loading of scheduler modules) for assisting development on large systems via reboot avoidance by dint of it becoming clear that access to such was never going to happen, I've stopped looking at it.

-- wli

#325 lore raw
Quoted 15 lines · William Lee Irwin III
Quoted 8 lines · William Lee Irwin III
Quoted 8 lines

One of the reasons I never posted my own code is that it never met its own design goals, which absolutely included switching on the fly. I think Peter Williams may have done something about that.
It was my hope
to be able to do insmod sched_foo.ko until it became clear that the effort it was intended to assist wasn't going to get even the limited hardware access required, at which point I largely stopped working on it.

Quoted 3 lines · Peter Williams

I didn't but some students did.
In a previous life, I did implement a runtime configurable CPU scheduling mechanism (implemented on True64, Solaris and Linux) that allowed schedulers to be loaded as modules at run time. This was released commercially on True64 and Solaris. So I know that it can be done. I have thought about doing something similar for the SPA schedulers which differ in only small ways from each other but lack motivation.

Quoted 9 lines

Driver models for scheduling are not so far out. AFAICS it's largely a tug-of-war over design goals, e.g. maintaining per-cpu runqueues and switching out intra-queue policies vs. switching out whole-system policies, SMP handling and all. Whether this involves load balancing depends strongly on e.g. whether you have per-cpu runqueues. A 2.4.x scheduler module, for instance, would not have a load balancer at all, as it has only one global runqueue. There are other sorts of policies wanting significant changes to SMP handling vs. the stock load balancing.

Well a single run queue removes the need for load balancing but has scalability issues on large systems. Personally, I think something in between would be the best solution i.e. multiple run queues but more than one CPU per run queue. I think that this would be a particularly good solution to the problems introduced by hyper threading and multi core systems and also NUMA systems. E.g. if all CPUs in a hyper thread package are using the one queue then the case where one CPU is trying to run a high priority task and the other a low priority task (i.e. the cases that the sleeping dependent mechanism tried to address) is less likely to occur.

By the way, I think that it's a very bad idea for the scheduling mechanism and the load balancing mechanism to be coupled. The anomalies that will be experienced and the attempts to make ad hoc fixes for them will lead to complexity spiralling out of control.

Quoted 14 lines
Quoted 6 lines · William Lee Irwin III
Quoted 6 lines

I'm not sure what happened there. It wasn't a big enough patch to take hits in this area due to getting overwhelmed by the programming burden like some other efforts of mine. Maybe things started getting ugly once on-the-fly switching entered the picture. My guess is that Peter Williams will have to chime in here, since things have diverged enough from my one-time contribution 4 years ago.

Quoted 2 lines · Peter Williams

From my POV, the current version of plugsched is considerably simpler than it was when I took the code over from Con as I put considerable effort into minimizing code overlap in the various schedulers.
I also put considerable effort into minimizing any changes to the load balancing code (something Ingo seems to think is a deficiency) and the result is that plugsched allows "intra run queue" scheduling to be easily modified WITHOUT effecting load balancing. To my mind scheduling and load balancing are orthogonal and keeping them that way simplifies things.

Quoted 7 lines

ISTR rearranging things for con in such a fashion that it no longer worked out of the box (though that wasn't the intention; restructuring it to be more suited to his purposes was) and that's what he worked off of afterward. I don't remember very well what changed there as I clearly invested less effort there than the prior versions. Now that I think of it, that may have been where the sample policy demonstrating scheduling classes was lost.

I can't comment here as (as far as I can recall) I never saw your code and only became involved when Con posted his version of cpusched.

Quoted 7 lines · Peter Williams
Quoted 1 line

As Ingo correctly points out, plugsched does not allow different schedulers to be used per CPU but it would not be difficult to modify it so that they could. Although I've considered doing this over the years I decided not to as it would just increase the complexity and the amount of work required to keep the patch set going. About six months ago I decided to reduce the amount of work I was doing on plugsched (as it was obviously never going to be accepted) and now only publish patches against the vanilla kernel's major releases (and the only reason that I kept doing that is that the download figures indicated that about 80 users were interested in the experiment).

That's a rather different goal from what I was going on about with it, so it's all diverged quite a bit.

Yes, pragmatic considerations dictated a change of tack.

Quoted 3 lines

Where I had a significant need for
mucking with the entire concept of how SMP was handled, this is rather different.

Yes, I went with the idea of intra run queue scheduling being orthogonal to load balancing for two reasons:

1. I think that coupling them is a bad idea from the complexity POV, and
2. it's enough of a battle fighting for modifications to one bit of the code without trying to do it to two simultaneously.

Quoted 4 lines

At this point I'm questioning the relevance of my own work, though it was already relatively marginal as it started life as an attempt at a sort of debug patch to help gang scheduling (which is in itself a rather marginally relevant feature to most users) code along.

The main commercial plug in scheduler used with the run time loadable module scheduler that I mentioned earlier did gang scheduling (at the insistence of the Tru64 kernel folks). As this scheduler was a hierarchical "fair share" scheduler: i.e. allocating CPU "fairly" ("unfairly" really in according to an allocation policy) among higher level entities such as users, groups and applications as well as processes; it was fairly easy to make it a gang scheduler by modifying it to give all of a process's threads the same priority based on the process's CPU usage rather than different priorities based on the threads' usage rates. In fact, it would have been possible to select between gang and non gang on a per process basis if that was considered desirable.

The fact that threads and processes are distinct entities on Tru64 and Solaris made this easier to do on them than on Linux.

My experience with this scheduler leads me to believe that to achieve gang scheduling and fairness, etc. you need (usage) statistics based schedulers.

Quoted 10 lines · Peter Williams
Quoted 4 lines

PS I no longer read LKML (due to time constraints) and would appreciate it if I could be CC'd on any e-mails suggesting scheduler changes.
PPS I'm just happy to see that Ingo has finally accepted that the vanilla scheduler was badly in need of fixing and don't really care who fixes it.
PPS Different schedulers for different aims (i.e. server or work station) do make a difference. E.g. the spa_svr scheduler in plugsched does about 1% better on kernbench than the next best scheduler in the bunch.
PPPS Con, fairness isn't always best as humans aren't very altruistic and we need to give unfair preference to interactive tasks in order to stop the users flinging their PCs out the window. But the current scheduler doesn't do this very well and is also not very good at fairness so needs to change. But the changes need to address interactive response and fairness not just fairness.

Kernel compiles not so useful a benchmark. SDET, OAST, AIM7, etc. are better ones. I'd not bother citing kernel compile results.

spa_svr actually does its best work when the system isn't fully loaded as the type of improvement it strives to achieve (minimizing on queue wait time) hasn't got much room to manoeuvre when the system is fully loaded. Therefore, the fact that it's 1% better even in these circumstances is a good result and also indicates that the overhead for keeping the scheduling statistics it uses for its decision making is well spent. Especially, when you consider that the total available room for improvement on this benchmark is less than 3%.

To elaborate, the motivation for this scheduler was acquired from the observation of scheduling statistics (in particular, on queue wait time) on systems running at about 30% to 50% load. Theoretically, at these load levels there should be no such waiting but the statistics show that there is considerable waiting (sometimes as high as 30% to 50%). I put this down to "lack of serendipity" e.g. everyone sleeping at the same time and then trying to run at the same time would be complete lack of serendipity. On the other hand, if everyone is synced then there would be total serendipity.

Obviously, from the POV of a client, time the server task spends waiting on the queue adds to the response time for any request that has been made so reduction of this time on a server is a good thing(tm). Equally obviously, trying to achieve this synchronization by asking the tasks to cooperate with each other is not a feasible solution and some external influence needs to be exerted and this is what spa_svr does -- it nudges the scheduling order of the tasks in a way that makes them become well synced.

Unfortunately, this is not a good scheduler for an interactive system as it minimizes the response times for ALL tasks (and the system as a whole) and this can result in increased response time for some interactive tasks (clunkiness) which annoys interactive users. When you start fiddling with this scheduler to bring back "interactive unfairness" you kill a lot of its superior low overall wait time performance.

So this is why I think "horses for courses" schedulers are worth while.

Quoted 7 lines

In any event, I'm not sure what to say about different schedulers for different aims. My intentions with plugsched were not centered around production usage or intra-queue policy. I'm relatively indifferent to the notion of having pluggable CPU schedulers, intra-queue or otherwise, in mainline. I don't see any particular harm in it, but neither am I particularly motivated to have it in.

If you look at the struct sched_spa_child in the file include/linux/sched_spa.h you'll see that the interface for switching between the various SPA schedulers is quite small and making them runtime switchable would be easy (I haven't done this in cpusched as I wanted to keep the same interface for switching schedulers for all schedulers: i.e. all run time switchable or none run time switchable; as the main aim of plugsched had become a mechanism for evaluating different intra queue scheduling designs.)

Quoted 6 lines

I had a rather strong sense of
instrumentality about it, and since it became useless to me (at a conceptual level; the implementation was never finished ot the point of dynamic loading of scheduler modules) for assisting development on large systems via reboot avoidance by dint of it becoming clear that access to such was never going to happen, I've stopped looking at it.

I'll probably stop looking at this problem as well at least for the time being until all this new code has settled.

Peter
PS As I no longer read LKML, I haven't yet seen Ingo's or Con's or Nick's new schedulers yet so am unable to comment on their technical merits with respect to my comments above.

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#326 lore raw
Quoted 9 lines · William Lee Irwin III
Quoted 9 lines

Driver models for scheduling are not so far out. AFAICS it's largely a tug-of-war over design goals, e.g. maintaining per-cpu runqueues and switching out intra-queue policies vs. switching out whole-system policies, SMP handling and all. Whether this involves load balancing depends strongly on e.g. whether you have per-cpu runqueues. A 2.4.x scheduler module, for instance, would not have a load balancer at all, as it has only one global runqueue. There are other sorts of policies wanting significant changes to SMP handling vs. the stock load balancing.

Quoted 10 lines · Peter Williams

Well a single run queue removes the need for load balancing but has scalability issues on large systems. Personally, I think something in between would be the best solution i.e. multiple run queues but more than one CPU per run queue. I think that this would be a particularly good solution to the problems introduced by hyper threading and multi core systems and also NUMA systems. E.g. if all CPUs in a hyper thread package are using the one queue then the case where one CPU is trying to run a high priority task and the other a low priority task (i.e. the cases that the sleeping dependent mechanism tried to address) is less likely to occur.

This wasn't meant to sing the praises of the 2.4.x scheduler; it was rather meant to point out that the 2.4.x scheduler, among others, is unimplementable within the framework if it assumes per-cpu runqueues. More plausibly useful single-queue schedulers would likely use a vastly different policy and attempt to carry out all queue manipulations via lockless operations.

Quoted 4 lines · Peter Williams

By the way, I think that it's a very bad idea for the scheduling mechanism and the load balancing mechanism to be coupled. The anomalies that will be experienced and the attempts to make ad hoc fixes for them will lead to complexity spiralling out of control.

This is clearly unavoidable in the case of gang scheduling. There is simply no other way to schedule N tasks which must all be run simultaneously when they run at all on N cpus of the system without such coupling and furthermore at an extremely intimate level, particularly when multiple competing gangs must be scheduled in such a fashion.

Quoted 3 lines · William Lee Irwin III
Quoted 3 lines

Where I had a significant need for
mucking with the entire concept of how SMP was handled, this is rather different.

Quoted 5 lines · Peter Williams

Yes, I went with the idea of intra run queue scheduling being orthogonal to load balancing for two reasons:
1. I think that coupling them is a bad idea from the complexity POV, and
2. it's enough of a battle fighting for modifications to one bit of the code without trying to do it to two simultaneously.

As nice as that sounds, such a code structure would've precluded the entire raison d'etre of the patch, i.e. gang scheduling.

Quoted 4 lines · William Lee Irwin III
Quoted 4 lines

At this point I'm questioning the relevance of my own work, though it was already relatively marginal as it started life as an attempt at a sort of debug patch to help gang scheduling (which is in itself a rather marginally relevant feature to most users) code along.

Quoted 9 lines · Peter Williams

The main commercial plug in scheduler used with the run time loadable module scheduler that I mentioned earlier did gang scheduling (at the insistence of the Tru64 kernel folks). As this scheduler was a hierarchical "fair share" scheduler: i.e. allocating CPU "fairly" ("unfairly" really in according to an allocation policy) among higher level entities such as users, groups and applications as well as processes; it was fairly easy to make it a gang scheduler by modifying it to give all of a process's threads the same priority based on the process's CPU usage rather than different priorities based on the

Quoted 8 lines

threads' usage rates. In fact, it would have been possible to select between gang and non gang on a per process basis if that was considered desirable.
The fact that threads and processes are distinct entities on Tru64 and Solaris made this easier to do on them than on Linux.
My experience with this scheduler leads me to believe that to achieve gang scheduling and fairness, etc. you need (usage) statistics based schedulers.

This does not appear to make sense unless it's based on an incorrect use of the term "gang scheduling." I'm referring to a gang as a set of tasks (typically restricted to threads of the same process) which must all be considered runnable or unrunnable simultaneously, and are for the sake of performance required to all actually be run simultaneously. This means a gang of N threads, when run, must run on N processors at once. A time and a set of processors must be chosen for any time interval where the gang is running. This interacts with load balancing by needing to choose the cpus to run the gang on, and also arranging for a set of cpus available for the gang to use to exist by means of migrating tasks off the chosen cpus.

Quoted 2 lines · William Lee Irwin III
Quoted 2 lines

Kernel compiles not so useful a benchmark. SDET, OAST, AIM7, etc. are better ones. I'd not bother citing kernel compile results.

Quoted 8 lines · Peter Williams

spa_svr actually does its best work when the system isn't fully loaded as the type of improvement it strives to achieve (minimizing on queue wait time) hasn't got much room to manoeuvre when the system is fully loaded. Therefore, the fact that it's 1% better even in these circumstances is a good result and also indicates that the overhead for keeping the scheduling statistics it uses for its decision making is well spent. Especially, when you consider that the total available room for improvement on this benchmark is less than 3%.

None of these benchmarks require the system to be fully loaded. They are, on the other hand, vastly more realistic simulated workloads than kernel compiles, and furthermore are actually developed as benchmarks, with in some cases even measurements of variance, iteration to convergence, and similar such things that make them actually scientific.

Quoted 9 lines · Peter Williams

To elaborate, the motivation for this scheduler was acquired from the observation of scheduling statistics (in particular, on queue wait time) on systems running at about 30% to 50% load. Theoretically, at these load levels there should be no such waiting but the statistics show that there is considerable waiting (sometimes as high as 30% to 50%). I put this down to "lack of serendipity" e.g. everyone sleeping at the same time and then trying to run at the same time would be complete lack of serendipity. On the other hand, if everyone is synced then there would be total serendipity.

Quoted 8 lines

Obviously, from the POV of a client, time the server task spends waiting on the queue adds to the response time for any request that has been made so reduction of this time on a server is a good thing(tm). Equally obviously, trying to achieve this synchronization by asking the tasks to cooperate with each other is not a feasible solution and some external influence needs to be exerted and this is what spa_svr does -- it nudges the scheduling order of the tasks in a way that makes them become well synced.

This all sounds like a relatively good idea. So it's good for throughput vs. latency or otherwise not particularly interactive. No big deal, just use it where it makes sense.

Quoted 8 lines · Peter Williams

Unfortunately, this is not a good scheduler for an interactive system as it minimizes the response times for ALL tasks (and the system as a whole) and this can result in increased response time for some interactive tasks (clunkiness) which annoys interactive users. When you start fiddling with this scheduler to bring back "interactive unfairness" you kill a lot of its superior low overall wait time performance.
So this is why I think "horses for courses" schedulers are worth while.

I have no particular objection to using an appropriate scheduler for the system's workload. I also have little or no preference as to how that's accomplished overall. But I really think that if we want to push pluggable scheduling it should load schedulers as kernel modules on the fly and so on versus pure /proc/ tunables and a compiled-in set of alternatives.

Quoted 6 lines · William Lee Irwin III
Quoted 6 lines

In any event, I'm not sure what to say about different schedulers for different aims. My intentions with plugsched were not centered around production usage or intra-queue policy. I'm relatively indifferent to the notion of having pluggable CPU schedulers, intra-queue or otherwise, in mainline. I don't see any particular harm in it, but neither am I particularly motivated to have it in.

Quoted 8 lines · Peter Williams

If you look at the struct sched_spa_child in the file include/linux/sched_spa.h you'll see that the interface for switching between the various SPA schedulers is quite small and making them runtime switchable would be easy (I haven't done this in cpusched as I wanted to keep the same interface for switching schedulers for all
schedulers: i.e. all run time switchable or none run time switchable; as the main aim of plugsched had become a mechanism for evaluating different intra queue scheduling designs.)

I remember actually looking at this, and I would almost characterize the differences between the SPA schedulers as a tunable parameter. I have a different concept of what pluggability means from how the SPA schedulers were switched, but no particular objection to the method given the commonalities between them.

-- wli

#327 lore raw
Quoted 23 lines · William Lee Irwin III
Quoted 9 lines · William Lee Irwin III
Quoted 9 lines

Driver models for scheduling are not so far out. AFAICS it's largely a tug-of-war over design goals, e.g. maintaining per-cpu runqueues and switching out intra-queue policies vs. switching out whole-system policies, SMP handling and all. Whether this involves load balancing depends strongly on e.g. whether you have per-cpu runqueues. A 2.4.x scheduler module, for instance, would not have a load balancer at all, as it has only one global runqueue. There are other sorts of policies wanting significant changes to SMP handling vs. the stock load balancing.

Quoted 1 line · Peter Williams

Well a single run queue removes the need for load balancing but has scalability issues on large systems. Personally, I think something in between would be the best solution i.e. multiple run queues but more than one CPU per run queue. I think that this would be a particularly good solution to the problems introduced by hyper threading and multi core systems and also NUMA systems. E.g. if all CPUs in a hyper thread package are using the one queue then the case where one CPU is trying to run a high priority task and the other a low priority task (i.e. the cases that the sleeping dependent mechanism tried to address) is less likely to occur.

This wasn't meant to sing the praises of the 2.4.x scheduler; it was rather meant to point out that the 2.4.x scheduler, among others, is unimplementable within the framework if it assumes per-cpu runqueues. More plausibly useful single-queue schedulers would likely use a vastly different policy and attempt to carry out all queue manipulations via lockless operations.

On Mon, Apr 16, 2007 at 03:09:31PM +1000, Peter Williams wrote:

Quoted 8 lines
Quoted 1 line

By the way, I think that it's a very bad idea for the scheduling mechanism and the load balancing mechanism to be coupled. The anomalies that will be experienced and the attempts to make ad hoc fixes for them will lead to complexity spiralling out of control.

This is clearly unavoidable in the case of gang scheduling. There is simply no other way to schedule N tasks which must all be run simultaneously when they run at all on N cpus of the system without such coupling and furthermore at an extremely intimate level, particularly when multiple competing gangs must be scheduled in such a fashion.

I can't see the logic here or why you would want to do such a thing. It certainly doesn't coincide with what I interpret "gang scheduling" to mean.

Quoted 7 lines
Quoted 3 lines · William Lee Irwin III
Quoted 3 lines

Where I had a significant need for
mucking with the entire concept of how SMP was handled, this is rather different.

Quoted 7 lines
Quoted 3 lines · Peter Williams

Yes, I went with the idea of intra run queue scheduling being orthogonal to load balancing for two reasons:
1. I think that coupling them is a bad idea from the complexity POV, and
2. it's enough of a battle fighting for modifications to one bit of the code without trying to do it to two simultaneously.

As nice as that sounds, such a code structure would've precluded the entire raison d'etre of the patch, i.e. gang scheduling.

Not for what I understand "gang scheduling" to mean. As I understand it the constraints of gang scheduling are no where near as strict as you seem to think they are. And for what it's worth I don't think that what you think it means is in any sense a reasonable target.

Quoted 8 lines
Quoted 4 lines · William Lee Irwin III
Quoted 4 lines

At this point I'm questioning the relevance of my own work, though it was already relatively marginal as it started life as an attempt at a sort of debug patch to help gang scheduling (which is in itself a rather marginally relevant feature to most users) code along.

Quoted 7 lines
Quoted 3 lines · Peter Williams

The main commercial plug in scheduler used with the run time loadable module scheduler that I mentioned earlier did gang scheduling (at the insistence of the Tru64 kernel folks). As this scheduler was a hierarchical "fair share" scheduler: i.e. allocating CPU "fairly" ("unfairly" really in according to an allocation policy) among higher level entities such as users, groups and applications as well as processes; it was fairly easy to make it a gang scheduler by modifying it to give all of a process's threads the same priority based on the process's CPU usage rather than different priorities based on the threads' usage rates. In fact, it would have been possible to select between gang and non gang on a per process basis if that was considered desirable. The fact that threads and processes are distinct entities on Tru64 and Solaris made this easier to do on them than on Linux.
My experience with this scheduler leads me to believe that to achieve gang scheduling and fairness, etc. you need (usage) statistics based schedulers.

This does not appear to make sense unless it's based on an incorrect use of the term "gang scheduling."

It's become obvious that we mean different things.

Quoted 10 lines

I'm referring to a gang as a set of
tasks (typically restricted to threads of the same process) which must all be considered runnable or unrunnable simultaneously, and are for the sake of performance required to all actually be run simultaneously. This means a gang of N threads, when run, must run on N processors at once. A time and a set of processors must be chosen for any time interval where the gang is running. This interacts with load balancing by needing to choose the cpus to run the gang on, and also arranging for a set of cpus available for the gang to use to exist by means of migrating tasks off the chosen cpus.

Sounds like a job for the load balancer NOT the scheduler.

Also I can't see you meeting such strict constraints without making the tasks all SCHED_FIFO.

Quoted 45 lines
Quoted 2 lines · William Lee Irwin III
Quoted 2 lines

Kernel compiles not so useful a benchmark. SDET, OAST, AIM7, etc. are better ones. I'd not bother citing kernel compile results.

Quoted 1 line · Peter Williams

spa_svr actually does its best work when the system isn't fully loaded as the type of improvement it strives to achieve (minimizing on queue wait time) hasn't got much room to manoeuvre when the system is fully loaded. Therefore, the fact that it's 1% better even in these circumstances is a good result and also indicates that the overhead for keeping the scheduling statistics it uses for its decision making is well spent. Especially, when you consider that the total available room for improvement on this benchmark is less than 3%.

None of these benchmarks require the system to be fully loaded. They are, on the other hand, vastly more realistic simulated workloads than kernel compiles, and furthermore are actually developed as benchmarks, with in some cases even measurements of variance, iteration to convergence, and similar such things that make them actually scientific.

Quoted 2 lines · Peter Williams

To elaborate, the motivation for this scheduler was acquired from the observation of scheduling statistics (in particular, on queue wait time) on systems running at about 30% to 50% load. Theoretically, at these load levels there should be no such waiting but the statistics show that there is considerable waiting (sometimes as high as 30% to 50%). I put this down to "lack of serendipity" e.g. everyone sleeping at the same time and then trying to run at the same time would be complete lack of serendipity. On the other hand, if everyone is synced then there would be total serendipity. Obviously, from the POV of a client, time the server task spends waiting on the queue adds to the response time for any request that has been made so reduction of this time on a server is a good thing(tm). Equally obviously, trying to achieve this synchronization by asking the tasks to cooperate with each other is not a feasible solution and some external influence needs to be exerted and this is what spa_svr does -- it nudges the scheduling order of the tasks in a way that makes them become well synced.

This all sounds like a relatively good idea. So it's good for throughput vs. latency or otherwise not particularly interactive. No big deal, just use it where it makes sense.

Quoted 2 lines · Peter Williams

Unfortunately, this is not a good scheduler for an interactive system as it minimizes the response times for ALL tasks (and the system as a whole) and this can result in increased response time for some interactive tasks (clunkiness) which annoys interactive users. When you start fiddling with this scheduler to bring back "interactive unfairness" you kill a lot of its superior low overall wait time performance. So this is why I think "horses for courses" schedulers are worth while.

I have no particular objection to using an appropriate scheduler for the system's workload. I also have little or no preference as to how that's accomplished overall. But I really think that if we want to push pluggable scheduling it should load schedulers as kernel modules on the fly and so on versus pure /proc/ tunables and a compiled-in set of alternatives.

Quoted 6 lines · William Lee Irwin III
Quoted 6 lines

In any event, I'm not sure what to say about different schedulers for different aims. My intentions with plugsched were not centered around production usage or intra-queue policy. I'm relatively indifferent to the notion of having pluggable CPU schedulers, intra-queue or otherwise, in mainline. I don't see any particular harm in it, but neither am I particularly motivated to have it in.

Quoted 8 lines
Quoted 1 line · Peter Williams

If you look at the struct sched_spa_child in the file include/linux/sched_spa.h you'll see that the interface for switching between the various SPA schedulers is quite small and making them runtime switchable would be easy (I haven't done this in cpusched as I wanted to keep the same interface for switching schedulers for all schedulers: i.e. all run time switchable or none run time switchable; as the main aim of plugsched had become a mechanism for evaluating different intra queue scheduling designs.)

I remember actually looking at this, and I would almost characterize the differences between the SPA schedulers as a tunable parameter. I have a different concept of what pluggability means from how the SPA schedulers were switched, but no particular objection to the method given the commonalities between them.

Yes, that's the way I look at them (in fact, in Zaphod that's exactly what they were -- i.e. Zaphod could be made to behave like various SPA schedulers by fiddling its run time parameters). They illustrate (to my mind) that once you get rid of the O(1) scheduler and replace it with a simple mechanism such as SPA (where there's a small number of points where the scheduling discipline gets to do its thing rather than being interspersed willy nilly throughout the rest of the code) adding run time switchable "horses for courses" scheduler disciplines becomes simple. I think that the simplifications in Ingo's new scheduler (whose scheduling classes now look a lot like Solaris's and its predecessor OSes' scheduler classes) may make it possible to have switchable scheduling disciplines within a scheduling class.

I think that something similar (i.e. switchability) could be done for load balancing so that different load balancers could be used when required. By keeping this load balancing functionality orthogonal to the intra run queue scheduling disciplines you increase the number of options available.

As I see it, if the scheduling discipline in use does its job properly within a run queue and the load balancer does its job of keeping the weighted load/demand on each run queue roughly equal (except where it has to do otherwise for your version of "gang scheduling") then the overall outcome will meet expectations. Note that I talk of run queues not CPUs as I think a shift to multiple CPUs per run queue may be a good idea.

Peter

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#328 lore raw
Quoted 3 lines · Peter Williams

Note that I talk of run queues
not CPUs as I think a shift to multiple CPUs per run queue may be a good idea.

This observation of Peter's is the best thing to come out of this whole foofaraw. Looking at what's happening in CPU-land, I think it's going to be necessary, within a couple of years, to replace the whole idea of "CPU scheduling" with "run queue scheduling" across a complex, possibly dynamic mix of CPU-ish resources. Ergo, there's not much point in churning the mainline scheduler through a design that isn't significantly more flexible than any of those now under discussion.

For instance, there are architectures where several "CPUs" (instruction stream decoders feeding execution pipelines) share parts of a cache hierarchy ("chip-level multitasking"). On these machines, you may want to co-schedule a "real" processing task on one pipeline with a "cache warming" task on the other pipeline -- but only for tasks whose memory access patterns have been sufficiently analyzed to write the "cache warming" task code. Some other tasks may want to idle the second pipeline so they can use the full cache-to-RAM bandwidth. Yet other tasks may be genuinely CPU-intensive (or I/O bound but so context-heavy that it's not worth yielding the CPU during quick I/Os), and hence perfectly happy to run concurrently with an unrelated task on the other pipeline.

There are other architectures where several "hardware threads" fight over parts of a cache hierarchy (sometimes bizarrely described as "sharing" the cache, kind of the way most two-year-olds "share" toys). On these machines, one instruction pipeline can't help the other along cache-wise, but it sure can hurt. A scheduler designed, tested, and tuned principally on one of these architectures (hint:
"hyperthreading") will probably leave a lot of performance on the floor on processors in the former category.

In the not-so-distant future, we're likely to see architectures with dynamically reconfigurable interconnect between instruction issue units and execution resources. (This is already quite feasible on, say, Virtex4 FX devices with multiple PPC cores, or Altera FPGAs with as many Nios II cores as fit on the chip.) Restoring task context may involve not just MMU swaps and FPU instructions (with state-dependent hidden costs) but processsor reconfiguration. Achieving "fairness" according to any standard that a platform integrator cares about (let alone an end user) will require a fairly detailed model of the hidden costs associated with different sorts of task switch.

So if you are interested in schedulers for some reason other than a paycheck, let the distros worry about 5% improvements on x86[_64]. Get hold of some different "hardware" -- say:
- a Xilinx ML410 if you've got $3K to blow and want to explore
reconfigurable processors;
- a SunFire T2000 if you've got $11K and want to mess with a CMT
system that's actually shipping;
- a QEMU-simulated massively SMP x86 if you're poor but clever
enough to implement funky cross-core cache effects yourself; or
- a cycle-accurate simulator from Gaisler or Virtio if you want a
real research project.
Then go explore some more interesting regions of parameter space and see what the demands on mainline Linux will look like in a few years.

Cheers,
- Michael

#329 lore raw
Quoted 5 lines · Michael K. Edwards
Quoted 3 lines · Peter Williams

Note that I talk of run queues
not CPUs as I think a shift to multiple CPUs per run queue may be a good idea.

Quoted 7 lines

This observation of Peter's is the best thing to come out of this whole foofaraw. Looking at what's happening in CPU-land, I think it's going to be necessary, within a couple of years, to replace the whole idea of "CPU scheduling" with "run queue scheduling" across a complex, possibly dynamic mix of CPU-ish resources. Ergo, there's not much point in churning the mainline scheduler through a design that isn't significantly more flexible than any of those now under discussion.

Why? If you do that, then your load balancer just becomes less flexible because it is harder to have tasks run on one or the other.

You can have single-runqueue-per-domain behaviour (or close to) just by relaxing all restrictions on idle load balancing within that domain. It is harder to go the other way and place any per-cpu affinity or restirctions with multiple cpus on a single runqueue.

Quoted 4 lines

For instance, there are architectures where several "CPUs" (instruction stream decoders feeding execution pipelines) share parts of a cache hierarchy ("chip-level multitasking"). On these machines, you may want to co-schedule a "real" processing task on one pipeline

Quoted 8 lines

with a "cache warming" task on the other pipeline -- but only for tasks whose memory access patterns have been sufficiently analyzed to write the "cache warming" task code. Some other tasks may want to idle the second pipeline so they can use the full cache-to-RAM bandwidth. Yet other tasks may be genuinely CPU-intensive (or I/O bound but so context-heavy that it's not worth yielding the CPU during quick I/Os), and hence perfectly happy to run concurrently with an unrelated task on the other pipeline.

We can do all that now with load balancing, affinities or by shutting down threads dynamically.

Quoted 20 lines

There are other architectures where several "hardware threads" fight over parts of a cache hierarchy (sometimes bizarrely described as "sharing" the cache, kind of the way most two-year-olds "share" toys). On these machines, one instruction pipeline can't help the other along cache-wise, but it sure can hurt. A scheduler designed, tested, and tuned principally on one of these architectures (hint:
"hyperthreading") will probably leave a lot of performance on the floor on processors in the former category.

In the not-so-distant future, we're likely to see architectures with dynamically reconfigurable interconnect between instruction issue units and execution resources. (This is already quite feasible on, say, Virtex4 FX devices with multiple PPC cores, or Altera FPGAs with as many Nios II cores as fit on the chip.) Restoring task context may involve not just MMU swaps and FPU instructions (with state-dependent hidden costs) but processsor reconfiguration. Achieving "fairness" according to any standard that a platform integrator cares about (let alone an end user) will require a fairly detailed model of the hidden costs associated with different sorts of task switch.

Quoted 13 lines

So if you are interested in schedulers for some reason other than a paycheck, let the distros worry about 5% improvements on x86[_64]. Get hold of some different "hardware" -- say:
- a Xilinx ML410 if you've got $3K to blow and want to explore
reconfigurable processors;
- a SunFire T2000 if you've got $11K and want to mess with a CMT
system that's actually shipping;
- a QEMU-simulated massively SMP x86 if you're poor but clever
enough to implement funky cross-core cache effects yourself; or
- a cycle-accurate simulator from Gaisler or Virtio if you want a
real research project.
Then go explore some more interesting regions of parameter space and see what the demands on mainline Linux will look like in a few years.

There are no doubt improvements to be made, but they are generally intended to be able to be done within the sched-domains framework. I am not aware of a particular need that would be impossible to do using that topology hierarchy and per-CPU runqueues, and there are added complications involved with multiple CPUs per runqueue.

#330 lore raw
Quoted 13 lines · Nick Piggin
Quoted 11 lines · Michael K. Edwards
Quoted 3 lines · Peter Williams

Note that I talk of run queues
not CPUs as I think a shift to multiple CPUs per run queue may be a good idea.

This observation of Peter's is the best thing to come out of this whole foofaraw. Looking at what's happening in CPU-land, I think it's going to be necessary, within a couple of years, to replace the whole idea of "CPU scheduling" with "run queue scheduling" across a complex, possibly dynamic mix of CPU-ish resources. Ergo, there's not much point in churning the mainline scheduler through a design that isn't significantly more flexible than any of those now under discussion.

Quoted 7 lines

Why? If you do that, then your load balancer just becomes less flexible because it is harder to have tasks run on one or the other.

You can have single-runqueue-per-domain behaviour (or close to) just by relaxing all restrictions on idle load balancing within that domain. It is harder to go the other way and place any per-cpu affinity or restirctions with multiple cpus on a single runqueue.

Allowing N (where N can be one or greater) CPUs per run queue actually increases flexibility as you can still set N to 1 to get the current behaviour.

One advantage of allowing multiple CPUs per run queue would be at the smaller end of the system scale i.e. a PC with a single hyper threading chip (i.e. 2 CPUs) would not need to worry about load balancing at all if both CPUs used the one runqueue and all the nasty side effects that come with hyper threading would be minimized at the same time.

Peter

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#331 lore raw
Quoted 17 lines · Peter Williams
Quoted 16 lines · Nick Piggin
Quoted 11 lines · Michael K. Edwards
Quoted 3 lines · Peter Williams

Note that I talk of run queues
not CPUs as I think a shift to multiple CPUs per run queue may be a good idea.

This observation of Peter's is the best thing to come out of this whole foofaraw. Looking at what's happening in CPU-land, I think it's going to be necessary, within a couple of years, to replace the whole idea of "CPU scheduling" with "run queue scheduling" across a complex, possibly dynamic mix of CPU-ish resources. Ergo, there's not much point in churning the mainline scheduler through a design that isn't significantly more flexible than any of those now under discussion.

Why? If you do that, then your load balancer just becomes less flexible because it is harder to have tasks run on one or the other.

Quoted 8 lines
Quoted 4 lines

You can have single-runqueue-per-domain behaviour (or close to) just by relaxing all restrictions on idle load balancing within that domain. It is harder to go the other way and place any per-cpu affinity or restirctions with multiple cpus on a single runqueue.

Allowing N (where N can be one or greater) CPUs per run queue actually increases flexibility as you can still set N to 1 to get the current behaviour.

But you add extra code for that on top of what we have, and are also prevented from making per-cpu assumptions.

And you can get N CPUs per runqueue behaviour by having them in a domain with no restrictions on idle balancing. So where does your increased flexibilty come from?

Quoted 5 lines

One advantage of allowing multiple CPUs per run queue would be at the smaller end of the system scale i.e. a PC with a single hyper threading chip (i.e. 2 CPUs) would not need to worry about load balancing at all if both CPUs used the one runqueue and all the nasty side effects that come with hyper threading would be minimized at the same time.

I don't know about that -- the current load balancer already minimises the nasty multi threading effects. SMT is very important for IBM's chips for example, and they've never had any problem with that side of it since it was introduced and bugs ironed out (at least, none that I've heard).

#332 lore raw
Quoted 30 lines · Nick Piggin
Quoted 13 lines · Peter Williams
Quoted 12 lines · Nick Piggin
Quoted 11 lines · Michael K. Edwards
Quoted 3 lines · Peter Williams

Note that I talk of run queues
not CPUs as I think a shift to multiple CPUs per run queue may be a good idea.

This observation of Peter's is the best thing to come out of this whole foofaraw. Looking at what's happening in CPU-land, I think it's going to be necessary, within a couple of years, to replace the whole idea of "CPU scheduling" with "run queue scheduling" across a complex, possibly dynamic mix of CPU-ish resources. Ergo, there's not much point in churning the mainline scheduler through a design that isn't significantly more flexible than any of those now under discussion.

Quoted 8 lines
Quoted 7 lines

Why? If you do that, then your load balancer just becomes less flexible because it is harder to have tasks run on one or the other.

You can have single-runqueue-per-domain behaviour (or close to) just by relaxing all restrictions on idle load balancing within that domain. It is harder to go the other way and place any per-cpu affinity or restirctions with multiple cpus on a single runqueue.

Allowing N (where N can be one or greater) CPUs per run queue actually increases flexibility as you can still set N to 1 to get the current behaviour.

But you add extra code for that on top of what we have, and are also prevented from making per-cpu assumptions.

And you can get N CPUs per runqueue behaviour by having them in a domain with no restrictions on idle balancing. So where does your increased flexibilty come from?

Quoted 8 lines
Quoted 1 line

One advantage of allowing multiple CPUs per run queue would be at the smaller end of the system scale i.e. a PC with a single hyper threading chip (i.e. 2 CPUs) would not need to worry about load balancing at all if both CPUs used the one runqueue and all the nasty side effects that come with hyper threading would be minimized at the same time.

I don't know about that -- the current load balancer already minimises the nasty multi threading effects. SMT is very important for IBM's chips for example, and they've never had any problem with that side of it since it was introduced and bugs ironed out (at least, none that I've heard).

There's a lot of ugly code in the load balancer that is only there to overcome the side effects of SMT and dual core. A lot of it was put there by Intel employees trying to make load balancing more friendly to their systems. What I'm suggesting is that an N CPUs per runqueue is a better way of achieving that end. I may (of course) be wrong but I think that the idea deserves more consideration than you're willing to give it.

Peter

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#333 lore raw
Quoted 7 lines · Peter Williams

There's a lot of ugly code in the load balancer that is only there to overcome the side effects of SMT and dual core. A lot of it was put there by Intel employees trying to make load balancing more friendly to their systems. What I'm suggesting is that an N CPUs per runqueue is a better way of achieving that end. I may (of course) be wrong but I think that the idea deserves more consideration than you're willing to give it.

This may be a good one to ask Ingo about, as he did significant performance work on per-core runqueues for SMT. While I did write per-node runqueue code for NUMA at some point in the past, I did no tuning or other performance work on it, only functionality.

I've actually dealt with kernels using elder versions of Ingo's code for per-core runqueues on SMT, but was never called upon to examine that particular code for either performance or stability, so I'm largely ignorant of what the perceived outcome of it was.

-- wli

#334 lore raw
In reply to Peter Williams
Quoted 22 lines · Peter Williams
Quoted 14 lines · Nick Piggin

But you add extra code for that on top of what we have, and are also prevented from making per-cpu assumptions.

And you can get N CPUs per runqueue behaviour by having them in a domain with no restrictions on idle balancing. So where does your increased flexibilty come from?

Quoted 5 lines

One advantage of allowing multiple CPUs per run queue would be at the smaller end of the system scale i.e. a PC with a single hyper threading chip (i.e. 2 CPUs) would not need to worry about load balancing at all if both CPUs used the one runqueue and all the nasty side effects that come with hyper threading would be minimized at the same time.

Quoted 6 lines

I don't know about that -- the current load balancer already minimises the nasty multi threading effects. SMT is very important for IBM's chips for example, and they've never had any problem with that side of it since it was introduced and bugs ironed out (at least, none that I've heard).

Quoted 3 lines

There's a lot of ugly code in the load balancer that is only there to overcome the side effects of SMT and dual core. A lot of it was put there by Intel employees trying to make load balancing more friendly to

I agree that some of that has exploded complexity. I have some thoughts about better approaches for some of those things, but basically been stuck working on VM problems for a while.

Quoted 4 lines

their systems. What I'm suggesting is that an N CPUs per runqueue is a better way of achieving that end. I may (of course) be wrong but I think that the idea deserves more consideration than you're willing to give it.

Put it this way: it is trivial to group the load balancing stats of N CPUs with their own runqueues. Just put them under a domain and take the sum. The domain essentially takes on the same function as a single queue with N CPUs under it. Anything _further_ you can do with individual runqueues (like naturally adding an affinity pressure ranging from nothing to absolute) are things that you don't trivially get with 1:N approach. AFAIKS.

So I will definitely give any idea consideration, but I just need to be shown where the benefit comes from.

#335 lore raw
In reply to Peter Williams
Quoted 7 lines · Peter Williams

There's a lot of ugly code in the load balancer that is only there to overcome the side effects of SMT and dual core. A lot of it was put there by Intel employees trying to make load balancing more friendly to their systems. What I'm suggesting is that an N CPUs per runqueue is a better way of achieving that end. I may (of course) be wrong but I think that the idea deserves more consideration than you're willing to give it.

i actually implemented that some time ago and i'm afraid it was ugly as hell and pretty fragile. Load-balancing gets simpler, but task picking gets alot uglier.

Ingo

#336 lore raw
In reply to Nick Piggin
Quoted 7 lines · Michael K. Edwards
Quoted 7 lines

This observation of Peter's is the best thing to come out of this whole foofaraw. Looking at what's happening in CPU-land, I think it's going to be necessary, within a couple of years, to replace the whole idea of "CPU scheduling" with "run queue scheduling" across a complex, possibly dynamic mix of CPU-ish resources. Ergo, there's not much point in churning the mainline scheduler through a design that isn't significantly more flexible than any of those now under discussion.

Quoted 2 lines · Nick Piggin

Why? If you do that, then your load balancer just becomes less flexible because it is harder to have tasks run on one or the other.

Quoted 4 lines · Nick Piggin

You can have single-runqueue-per-domain behaviour (or close to) just by relaxing all restrictions on idle load balancing within that domain. It is harder to go the other way and place any per-cpu affinity or restirctions with multiple cpus on a single runqueue.

The big sticking point here is order-sensitivity. One can point to stringent sched_yield() ordering but that's not so important in and of itself. The more significant case is RT applications which are order- sensitive. Per-cpu runqueues rather significantly disturb the ordering requirements of applications that care about it.

In terms of a plugging framework, the per-cpu arrangement precludes or makes extremely awkward scheduling policies that don't have per-cpu runqueues, for instance, the 2.4.x policy. There is also the alternate SMP scalability strategy of a lockless scheduler with a single global queue, which is more performance-oriented.

-- wli

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#344 lore raw
Quoted 6 lines · William Lee Irwin III
Quoted 2 lines · Peter Williams

This doesn't make any sense to me.
For a start, exact simultaneous operation would be impossible to achieve except with highly specialized architecture such as the long departed transputer. And secondly, I can't see why it's necessary.

We're not going to make any headway here, so we might as well drop the thread.

Yes, we were starting to go around in circles weren't we?

Quoted 11 lines

There are other things to talk about anyway, for instance I'm seeing interest in plugsched come about from elsewhere and am taking an interest in getting it into shape wrt. various design goals therefore.

Probably the largest issue of note is getting scheduler drivers loadable as kernel modules. Addressing the points Ingo made that can be addressed are also lined up for this effort.

Comments on which directions you'd like this to go in these respects would be appreciated, as I regard you as the current "project owner."

I'd do scan through LKML from about 18 months ago looking for mention of runtime configurable version of plugsched. Some students at a university (in Germany, I think) posted some patches adding this feature to plugsched around about then.

I never added them to plugsched proper as I knew (from previous experience when the company I worked for posted patches with similar functionality) that Linux would like this idea less than he did the current plugsched mechanism.

Unfortunately, my own cache of the relevant e-mails got overwritten during a Fedora Core upgrade (I've since moved /var onto a separate drive to avoid a repetition) or I would dig them out and send them to you. I'd provided with copies of the company's patches to use as a guide to how to overcome the problems associated with changing schedulers on a running system (a few non trivial locking issues pop up).

Maybe if one of the students still reads LKML he will provide a pointer.

Peter

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#345 lore raw
Quoted 2 lines · William Lee Irwin III
Quoted 2 lines

Comments on which directions you'd like this to go in these respects would be appreciated, as I regard you as the current "project owner."

Quoted 4 lines · Peter Williams

I'd do scan through LKML from about 18 months ago looking for mention of runtime configurable version of plugsched. Some students at a university (in Germany, I think) posted some patches adding this feature to plugsched around about then.

Excellent. I'll go hunting for that.

Quoted 4 lines · Peter Williams

I never added them to plugsched proper as I knew (from previous experience when the company I worked for posted patches with similar functionality) that Linux would like this idea less than he did the current plugsched mechanism.

Odd how the requirements ended up including that. Fickleness abounds. If only we knew up-front what the end would be.

Quoted 7 lines · Peter Williams

Unfortunately, my own cache of the relevant e-mails got overwritten during a Fedora Core upgrade (I've since moved /var onto a separate drive to avoid a repetition) or I would dig them out and send them to you. I'd provided with copies of the company's patches to use as a guide to how to overcome the problems associated with changing schedulers on a running system (a few non trivial locking issues pop up). Maybe if one of the students still reads LKML he will provide a pointer.

I was tempted to restart from scratch given Ingo's comments, but I reconsidered and I'll be working with your code (and the German students' as well). If everything has to change, so be it, but it'll still be a derived work. It would be ignoring precedent and failure to properly attribute if I did otherwise.

-- wli

#346 lore raw
Quoted 18 lines · William Lee Irwin III
Quoted 2 lines · William Lee Irwin III
Quoted 2 lines

Comments on which directions you'd like this to go in these respects would be appreciated, as I regard you as the current "project owner."

Quoted 1 line · Peter Williams

I'd do scan through LKML from about 18 months ago looking for mention of runtime configurable version of plugsched. Some students at a university (in Germany, I think) posted some patches adding this feature to plugsched around about then.

Excellent. I'll go hunting for that.

Quoted 1 line · Peter Williams

I never added them to plugsched proper as I knew (from previous experience when the company I worked for posted patches with similar functionality) that Linux would like this idea less than he did the current plugsched mechanism.

Odd how the requirements ended up including that. Fickleness abounds. If only we knew up-front what the end would be.

On Tue, Apr 17, 2007 at 06:00:06PM +1000, Peter Williams wrote:

Quoted 8 lines
Quoted 2 lines

Unfortunately, my own cache of the relevant e-mails got overwritten during a Fedora Core upgrade (I've since moved /var onto a separate drive to avoid a repetition) or I would dig them out and send them to you. I'd provided with copies of the company's patches to use as a guide to how to overcome the problems associated with changing schedulers on a running system (a few non trivial locking issues pop up). Maybe if one of the students still reads LKML he will provide a pointer.

I was tempted to restart from scratch given Ingo's comments, but I reconsidered and I'll be working with your code (and the German students' as well). If everything has to change, so be it, but it'll still be a derived work. It would be ignoring precedent and failure to properly attribute if I did otherwise.

I can give you a patch (or set of patches) against the latest git vanilla kernel version if that would help. There have been changes to the vanilla scheduler code since 2.6.20 so the latest patch on sourceforge won't apply cleanly. I've found that implementing this as a series of patches rather than one big patch makes it easier fro me to cope with changes to the underlying code.

Peter

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#347 lore raw
Quoted 8 lines · Peter Williams
Quoted 5 lines · William Lee Irwin III

I was tempted to restart from scratch given Ingo's comments, but I reconsidered and I'll be working with your code (and the German students' as well). If everything has to change, so be it, but it'll still be a derived work. It would be ignoring precedent and failure to properly attribute if I did otherwise.

I can give you a patch (or set of patches) against the latest git vanilla kernel version if that would help. There have been changes to the vanilla scheduler code since 2.6.20 so the latest patch on sourceforge won't apply cleanly. I've found that implementing this as a series of patches rather than one big patch makes it easier fro me to cope with changes to the underlying code.

I've just placed a single patch for plugsched against 2.6.21-rc7 updated to Linus's git tree as of an hour or two ago on sourceforge:

<http://downloads.sourceforge.net/cpuse/plugsched-6.5-for-2.6.21-rc7.patch>

This should at least enable you to get it to apply cleanly to the latest kernel sources. Let me know if you'd also like this as a quilt/mq friendly patch series?

Peter

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#348 lore raw
Quoted 15 lines
Quoted 13 lines · Peter Williams
Quoted 5 lines · William Lee Irwin III

I was tempted to restart from scratch given Ingo's comments, but I reconsidered and I'll be working with your code (and the German students' as well). If everything has to change, so be it, but it'll still be a derived work. It would be ignoring precedent and failure to properly attribute if I did otherwise.

I can give you a patch (or set of patches) against the latest git vanilla kernel version if that would help. There have been changes to the vanilla scheduler code since 2.6.20 so the latest patch on sourceforge won't apply cleanly. I've found that implementing this as a series of patches rather than one big patch makes it easier fro me to cope with changes to the underlying code.

Quoted 6 lines · Peter Williams

I've just placed a single patch for plugsched against 2.6.21-rc7 updated to Linus's git tree as of an hour or two ago on sourceforge:
<http://downloads.sourceforge.net/cpuse/plugsched-6.5-for-2.6.21-rc7.patch>
This should at least enable you to get it to apply cleanly to the latest kernel sources. Let me know if you'd also like this as a quilt/mq friendly patch series?

A quilt-friendly series would be most excellent if you could arrange it.

Thanks.

-- wli

#349 lore raw
Quoted 7 lines · William Lee Irwin III
Quoted 7 lines
Quoted 6 lines · Peter Williams
Quoted 5 lines · William Lee Irwin III

I was tempted to restart from scratch given Ingo's comments, but I reconsidered and I'll be working with your code (and the German students' as well). If everything has to change, so be it, but it'll still be a derived work. It would be ignoring precedent and failure to properly attribute if I did otherwise.

Quoted 7 lines
Quoted 1 line
Quoted 1 line

I can give you a patch (or set of patches) against the latest git vanilla kernel version if that would help. There have been changes to the vanilla scheduler code since 2.6.20 so the latest patch on sourceforge won't apply cleanly. I've found that implementing this as a series of patches rather than one big patch makes it easier fro me to cope with changes to the underlying code.

Quoted 3 lines · Peter Williams

I've just placed a single patch for plugsched against 2.6.21-rc7 updated to Linus's git tree as of an hour or two ago on sourceforge:
<http://downloads.sourceforge.net/cpuse/plugsched-6.5-for-2.6.21-rc7.patch>
This should at least enable you to get it to apply cleanly to the latest kernel sources. Let me know if you'd also like this as a quilt/mq friendly patch series?

A quilt-friendly series would be most excellent if you could arrange it.

Done:

<http://downloads.sourceforge.net/cpuse/plugsched-6.5-for-2.6.21-rc7.patch-series.tar.gz>

Just untar this in the base directory of your Linux kernel source and Bob's your uncle.

Peter

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#350 lore raw
In reply to Peter Williams
Quoted 1 line · Peter Williams

To my mind scheduling and load balancing are orthogonal and keeping them that way simplifies things.

Scuse me if I jump in here, but doesn't the load balancer need some way to figure out a) when to run, and b) which tasks to pull and where to push them?

I suppose you could abstract this into a per-scheduler API, but to me at least these are the hard parts of the load balancer...

Chris

#351 lore raw
Quoted 5 lines · Chris Friesen
Quoted 1 line · Peter Williams

To my mind scheduling and load balancing are orthogonal and keeping them that way simplifies things.

Scuse me if I jump in here, but doesn't the load balancer need some way to figure out a) when to run, and b) which tasks to pull and where to push them?

Yes but both of these are independent of the scheduler discipline in force.

Quoted 2 lines

I suppose you could abstract this into a per-scheduler API, but to me at least these are the hard parts of the load balancer...

Load balancing needs to be based on the static priorities (i.e. nice or real time priority) of the runnable tasks not the dynamic priorities. If the load balancer manages to keep the weighted (according to static priority) load and distribution of priorities within the loads on the CPUs roughly equal and the scheduler does a good job of ensuring fairness, interactive responsiveness etc. for the tasks within a CPU then the result will be good system performance within the constraints set by the sys admins use of real time priorities and nice.

The smpnice modifications to the load balancer were meant to give it the appropriate behaviour and what we need to fix now is the intra CPU scheduling.

Even if the load balancer isn't yet perfect perfecting it can be done separately to fixing the scheduler preferably with as little interdependency as possible. Probably the only contribution to load balancing that the scheduler really needs to make is the calculating of the average weighted load on each of the CPUs (or run queues if there's more than one CPU per runqueue).

Peter

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#352 lore raw
Quoted 4 lines · Peter Williams
Quoted 1 line · Chris Friesen

Scuse me if I jump in here, but doesn't the load balancer need some way to figure out a) when to run, and b) which tasks to pull and where to push them?

Yes but both of these are independent of the scheduler discipline in force.

It is not clear to me that this is always the case, especially once you mix in things like resource groups.

Quoted 2 lines

If
the load balancer manages to keep the weighted (according to static priority) load and distribution of priorities within the loads on the CPUs roughly equal and the scheduler does a good job of ensuring fairness, interactive responsiveness etc. for the tasks within a CPU then the result will be good system performance within the constraints set by the sys admins use of real time priorities and nice.

Suppose I have a really high priority task running. Another very high priority task wakes up and would normally preempt the first one. However, there happens to be another cpu available. It seems like it would be a win if we moved one of those tasks to the available cpu immediately so they can both run simultaneously. This would seem to require some communication between the scheduler and the load balancer.

Certainly the above design could introduce a lot of context switching. But if my goal is a scheduler that minimizes latency (even at the cost of throughput) then that's an acceptable price to pay.

Chris

#353 lore raw
Quoted 4 lines · Chris Friesen
Quoted 2 lines · Peter Williams
Quoted 1 line · Chris Friesen

Scuse me if I jump in here, but doesn't the load balancer need some way to figure out a) when to run, and b) which tasks to pull and where to push them?

Quoted 8 lines
Quoted 1 line

Yes but both of these are independent of the scheduler discipline in force.

It is not clear to me that this is always the case, especially once you mix in things like resource groups.

Quoted 2 lines

If
the load balancer manages to keep the weighted (according to static priority) load and distribution of priorities within the loads on the CPUs roughly equal and the scheduler does a good job of ensuring fairness, interactive responsiveness etc. for the tasks within a CPU then the result will be good system performance within the constraints set by the sys admins use of real time priorities and nice.

Suppose I have a really high priority task running. Another very high priority task wakes up and would normally preempt the first one. However, there happens to be another cpu available. It seems like it would be a win if we moved one of those tasks to the available cpu immediately so they can both run simultaneously. This would seem to require some communication between the scheduler and the load balancer.

Not really the load balancer can do this on its own AND the decision should be based on the STATIC priority of the task being woken.

Quoted 2 lines

Certainly the above design could introduce a lot of context switching. But if my goal is a scheduler that minimizes latency (even at the cost of throughput) then that's an acceptable price to pay.

It would actually probably reduce context switching as putting the woken task on the best CPU at wake up means you don't have to move it later on. The wake up code already does a little bit in this direction when it chooses which CPU to put a newly woken task on but could do more -- the only real cost would be the cost of looking at more candidate CPUs than it currently does.

Peter

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#354 lore raw
Quoted 6 lines · Peter Williams
Quoted 1 line · Chris Friesen

Suppose I have a really high priority task running. Another very high priority task wakes up and would normally preempt the first one. However, there happens to be another cpu available. It seems like it would be a win if we moved one of those tasks to the available cpu immediately so they can both run simultaneously. This would seem to require some communication between the scheduler and the load balancer.

Not really the load balancer can do this on its own AND the decision should be based on the STATIC priority of the task being woken.

I guess I don't follow. How would the load balancer know that it needs to run? Running on every task wake-up seems expensive. Also, static priority isn't everything. What about the gang-scheduler concept where certain tasks must be scheduled simultaneously on different cpus? What about a resource-group scenario where you have per-cpu resource limits, so that for good latency/fairness you need to force a high priority task to migrate to another cpu once it has consumed the cpu allocation of that group on the current cpu?

I can see having a generic load balancer core code, but it seems to me that the scheduler proper needs to have some way of triggering the load balancer to run, and some kind of goodness functions to indicate a) which tasks to move, and b) where to move them.

Chris

#355 lore raw
Quoted 11 lines · Chris Friesen
Quoted 6 lines · Peter Williams
Quoted 1 line · Chris Friesen

Suppose I have a really high priority task running. Another very high priority task wakes up and would normally preempt the first one. However, there happens to be another cpu available. It seems like it would be a win if we moved one of those tasks to the available cpu immediately so they can both run simultaneously. This would seem to require some communication between the scheduler and the load balancer.

Not really the load balancer can do this on its own AND the decision should be based on the STATIC priority of the task being woken.

I guess I don't follow. How would the load balancer know that it needs to run? Running on every task wake-up seems expensive. Also, static priority isn't everything. What about the gang-scheduler concept where certain tasks must be scheduled simultaneously on different cpus? What about a resource-group scenario where you have per-cpu resource limits, so that for good latency/fairness you need to force a high priority task to migrate to another cpu once it has consumed the cpu allocation of that group on the current cpu?

I can see having a generic load balancer core code, but it seems to me that the scheduler proper needs to have some way of triggering the load balancer to run,

It doesn't have to be closely coupled with the load balancer to does this. It just needs to know where the trigger is.

Quoted 1 line

and some kind of goodness functions to indicate a) which tasks to move, and b) where to move them.

That's the load balancer's job and even if you use dynamic priority for load balancing it still wouldn't need to be closely coupled. The load balancer would just need to know how to find a process's dynamic priority.

In fact, in the current set up, the load balancer decides how much load needs to be moved based on the static load on the CPUs but uses dynamic priority (to a large degree) to decide which ones to move. This is due more to computational efficiency considerations than any deliberate design (I suspect) as the fact that tasks are stored on the runqueue in dynamic priority order makes looking at processes in dynamic priority order is the most efficient strategy.

Peter

Signature · 4 lines
Peter Williams                                   [email protected]

"Learning, n. The kind of ignorance distinguishing the studious."
 -- Ambrose Bierce
#356 lore raw
In reply to Ingo Molnar
Quoted 7 lines · Ingo Molnar
Quoted 4 lines · Con Kolivas

2. Since then I've been thinking/working on a cpu scheduler design that takes away all the guesswork out of scheduling and gives very predictable, as fair as possible, cpu distribution and latency while preserving as solid interactivity as possible within those confines.

yeah. I think you were right on target with this call.

Yay thank goodness :) It's time to fix the damn cpu scheduler once and for all. Everyone uses this; it's no minor driver or $bigsmp or $bigram or $small_embedded_RT_hardware feature.

Quoted 7 lines

I've applied the
sched.c change attached at the bottom of this mail to the CFS patch, if you dont mind. (or feel free to suggest some other text instead.)

  *  2003-09-03	Interactivity tuning by Con Kolivas.
  *  2004-04-02	Scheduler domains code by Nick Piggin
+ *  2007-04-15	Con Kolivas was dead right: fairness matters! :)

LOL that's awful. I'd prefer something meaningful like "Work begun on replacing all interactivity tuning with a fair virtual-deadline design by Con Kolivas".

While you're at it, it's worth getting rid of a few slightly pointless name changes too. Don't rename SCHED_NORMAL yet again, and don't call all your things sched_fair blah_fair __blah_fair and so on. It means that anything else is by proxy going to be considered unfair. Leave SCHED_NORMAL as is, replace the use of the word _fair with _cfs. I don't really care how many copyright notices you put into our already noisy bootup but it's redundant since there is no choice; we all get the same cpu scheduler.

Quoted 10 lines
Quoted 5 lines

1. I tried in vain some time ago to push a working extensable pluggable cpu scheduler framework (based on wli's work) for the linux kernel. It was perma-vetoed by Linus and Ingo (and Nick also said he didn't like it) as being absolutely the wrong approach and that we should never do that. [...]

i partially replied to that point to Will already, and i'd like to make it clear again: yes, i rejected plugsched 2-3 years ago (which already drifted away from wli's original codebase) and i would still reject it today.

No that was just me being flabbergasted by what appeared to be you posting your own plugsched. Note nowhere in the 40 iterations of rsdl->sd did I ask/suggest for plugsched. I said in my first announcement my aim was to create a scheduling policy robust enough for all situations rather than fantastic a lot of the time and awful sometimes. There are plenty of people ready to throw out arguments for plugsched now and I don't have the energy to continue that fight (I never did really).

But my question still stands about this comment:

Quoted 2 lines

case, all of SD's logic could be added via a kernel/sched_sd.c module as well, if Con is interested in such an approach. ]

What exactly would be the purpose of such a module that governs nothing in particular? Since there'll be no pluggable scheduler by your admission it has no control over SCHED_NORMAL, and would require another scheduling policy for it to govern which there is no express way to use at the moment and people tend to just use the default without great effort.

Quoted 6 lines

First and foremost, please dont take such rejections too personally - i had my own share of rejections (and in fact, as i mentioned it in a previous mail, i had a fair number of complete project throwaways:
4g:4g, in-kernel Tux, irqrate and many others). I know that they can hurt and can demoralize, but if i dont like something it's my job to tell that.

Hmm? No that's not what this is about. Remember dynticks which was not originally my code but I tried to bring it up to mainline standard which I fought with for months? You came along with yet another rewrite from scratch and the flaws in the design I was working with were obvious so I instantly bowed down to that and never touched my code again. I didn't ask for credit back then, but obviously brought the requirement for a no idle tick implementation to the table.

Quoted 5 lines

My view about plugsched: first please take a look at the latest plugsched code:

http://downloads.sourceforge.net/cpuse/plugsched-6.5-for-2.6.20.patch

Quoted 8 lines
  26 files changed, 8951 insertions(+), 1495 deletions(-)

As an experiment i've removed all the add-on schedulers (both the core and the include files, only kept the vanilla one) from the plugsched patch (and the makefile and kconfig complications, etc), to see the 'infrastructure cost', and it still gave:

  12 files changed, 1933 insertions(+), 1479 deletions(-)

I do not see extra code per-se as being a bad thing. I've heard said a few times before "ever notice how when the correct solution is done it is a lot more code than the quick hack that ultimately fails?". Insert long winded discussion of perfect is the enemy of good here, _but_ I'm not arguing perfect versus good, I'm talking about solid code versus quick fix. Again, none of this comment is directed specifically at this implementation of plugsched, its code quality or intent, but using "extra code is bad" as an argument is not enough.

Quoted 12 lines

By your logic Mike should in fact be quite upset about this: if the new code works out and proves to be useful then it obsoletes a whole lot of code of him!

Quoted 6 lines

[...] However at one stage I virtually begged for support with my attempts and help with the code. Dmitry Adamushko is the only person who actually helped me with the code in the interim, while others poked sticks at it. Sure the sticks helped at times but the sticks always seemed to have their ends kerosene doused and flaming for reasons I still don't get. No other help was forthcoming.

Quoted 6 lines

Hey, i told this to you as recently as 1 month ago as well:

http://lkml.org/lkml/2007/3/8/54

"cool! I like this even more than i liked your original staircase
scheduler from 2 years ago :)"

Email has an awful knack of disguising intent so I took that on face value that you did like the idea :).

Above when I said "no other help was forthcoming" all I was hoping for was really simple obvious bugfixes to help me along while I was laid up in bed such as "I like what you're doing but oh your use of memset here is bogus, here is a one line patch". I wasn't specifically expecting you to fix my code; you've got truckloads of things you need to do.

It just reminds me that the concept of "release early, release often" doesn't actually work in the kernel. What is far more obvious is "release code only when it's so close to perfect that noone can argue against it" since most of the work is done by one person, otherwise someone will come out with a counterpatch that is _complete_ earlier but in all possibility not as good, it's just ready sooner. *NOTE* In no way am I saying your code is not as good as mine; I would have to say exactly the opposite is true pretty much always (<sarcasm>conversely then I doubt if I dropped you in my work environment you'd do as good a job as I do</sarcasm>). At one stage wli (again at my request) put together a quick hack to check for non-preemptible regions within the kernel. From that quick hack you adopted it and turned it into that beautiful latency tracer that is the cornerstone of the -rt tree testing. However, there are many instances I've seen good evolving code in the linux kernel be trumped by not-as-good but already-working alternatives written from scratch with no reference to the original work. This is the NIH (not invented here) mechanism I see happening that is worth objecting to.

What you may find most amusing is the very first iterations of RSDL looked _nothing_ like the mainline scheduler. There were all sorts of different structures, mechanisms, one priority array, plans to remove scheduler_tick entirely and so on. Most of those were never made for public consumption. I spent about half a dozen iterations of RSDL removing all of that and making it as close to the mainline design as possible, thus minimising the size of the patch, and to make it readily readable for most people familiar with the scheduler policy code in sched.c (all 5 of them). I should have just said bugger it and started everything from scratch with little to no reference to the original scheduler but found myself obliged to try to do things the minimal code patch size readable difference thingy that was valued in linux kernel development. I think the radically different approach would have been better in the long run. Trying to play ball I ruined it.

Either way I've decided for myself, my family, my career and my sanity I'm abandoning SD. I will shelve SD and try to have fond memories of SD as an intellectual prompting exercise only

Quoted 1 line

Ingo

Signature · 1 line
-ck
#357 lore raw

On Monday 16 April 2007, Con Kolivas wrote:

And I snipped, Sorry fellas.

Con's original submission was to me, quite an improvement. But I have to say it, and no denegration of your efforts is intended Con, but you did 'pull the trigger' and get this thing rolling by scratching the itch & drawing attention to an ugly lack of user interactivity that had crept into the 2.6 family. So from me to Con, a tip of the hat, and a deep bow in your direction, thank you. Now, you have done what you aimed to do, so please get well.

I've now been through most of an amanda session using Ingo's "CFS" and I have to say that it is another improvement over your 0.40 that's is just as obvious as your first patch was against the stock scheduler. No other scheduler yet has allowed the full utilization of the cpu, and maintained user interactivity as well as this one has, my cpu is running about 5 degrees F hotter just from this effect alone. gzip, if the rest of the system is in between tasks, is consistently showing around 95%, but let anything else stick up its hand, like procmail etc, and gzip now dutifully steps aside, dropping into the 40% range until procmail and spamd are done, at which point there is no rest for the wicked and the cpu never gets a chance to cool.

There was, just now, a pause of about 2 seconds, while amanda moved a tarball from the holding disk area on /dev/hda to the vtapes disk on /dev/hdd, so that would have been an I/O bound situation.

This one Ingo, even without any other patches and I think I did see one go by in this thread which I didn't apply, is a definite keeper. Sweet even.

Signature · 6 lines
Cheers, Gene
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
A word to the wise is enough.
		-- Miguel de Cervantes
#358 lore raw
In reply to Ingo Molnar
Quoted 5 lines · Ingo Molnar

[announce] [patch] Modular Scheduler Core and Completely Fair Scheduler [CFS]

i'm pleased to announce the first release of the "Modular Scheduler Core and Completely Fair Scheduler [CFS]" patchset:

Quoted 8 lines

http://redhat.com/~mingo/cfs-scheduler/sched-modular+cfs.patch

This project is a complete rewrite of the Linux task scheduler. My goal is to address various feature requests and to fix deficiencies in the vanilla scheduler that were suggested/found in the past few years, both for desktop scheduling and for server scheduling workloads.

[...]

I took a brief look at it. Have you tested priority inheritance?
As far as I can see rt_mutex_setprio doesn't have much effect on SCHED_FAIR/SCHED_BATCH. I am looking for a place where such a task change scheduler class when boosted in rt_mutex_setprio().

Esben

#359 lore raw
Quoted 1 line · Esben Nielsen

I took a brief look at it. Have you tested priority inheritance?

yeah, you are right, it's broken at the moment, i'll fix it. But the good news is that i think PI could become cleaner via scheduling classes.

Quoted 3 lines

As far as I can see rt_mutex_setprio doesn't have much effect on SCHED_FAIR/SCHED_BATCH. I am looking for a place where such a task change scheduler class when boosted in rt_mutex_setprio().

i think via scheduling classes we dont have to do the p->policy and p->prio based gymnastics anymore, we can just have a clean look at p->sched_class and stack the original scheduling class into p->real_sched_class. It would probably also make sense to 'privatize' p->prio into the scheduling class. That way PI would be a pure property of sched_rt, and the PI scheduler would be driven purely by p->rt_priority, not by p->prio. That way all the normal_prio() kind of complications and interactions with SCHED_OTHER/SCHED_FAIR would be eliminated as well. What do you think?

Ingo

#360 lore raw
Quoted 13 lines · Ingo Molnar
Quoted 1 line · Esben Nielsen

I took a brief look at it. Have you tested priority inheritance?

yeah, you are right, it's broken at the moment, i'll fix it. But the good news is that i think PI could become cleaner via scheduling classes.

Quoted 3 lines

As far as I can see rt_mutex_setprio doesn't have much effect on SCHED_FAIR/SCHED_BATCH. I am looking for a place where such a task change scheduler class when boosted in rt_mutex_setprio().

Quoted 10 lines

i think via scheduling classes we dont have to do the p->policy and p->prio based gymnastics anymore, we can just have a clean look at p->sched_class and stack the original scheduling class into p->real_sched_class. It would probably also make sense to 'privatize' p->prio into the scheduling class. That way PI would be a pure property of sched_rt, and the PI scheduler would be driven purely by p->rt_priority, not by p->prio. That way all the normal_prio() kind of complications and interactions with SCHED_OTHER/SCHED_FAIR would be eliminated as well. What do you think?

Now I have not read your patch into detail. But agree it would be nice to have it more "OO" and remove cross references between schedulers. But first one should consider wether PI between SCHED_FAIR tasks or not is usefull or not. Does PI among dynamic priorities make sense at all? I think it
does: On heavy loaded systems where a nice 19 might not get the CPU for very long, a nice -20 task can be priority inverted for a very long time.
But I see no need it taking the dynamic part of the effective priorities into account. The current/old solution of mapping the static nice values into a global priority index which can incorporate the two scheduler classes is probably good enough - it just has to be "switched on" a again :-)

But what about other scheduler classes which some people want to add in the future? What about having a "cleaner design"?

My thought was to generalize the concept of 'priority' to be an
object (a struct prio) to be interpreted with help from a scheduler class instead of globally interpreted integer.

int compare_prio(struct prio *a, struct prio *b)

{
	if (a->sched_class->class_prio < b->sched_class->class_prio)
		return -1;

	if (a->sched_class->class_prio < b->sched_class->class_prio)
		return +1;


	return a->sched_class->compare_prio(a, b);

}

Problem 1: Performance.

Problem 2: Operations on a plist with these generalized priorities are not bounded because the number of different priorites are not bounded.

Problem 2 could be solved by using a combined plist (for rt priorities) and rbtree (for fair priorities) - making operations logarithmic just as the fair scheduler itself. But that would take more memory for every rtmutex.

I conclude that is too complicated and go on to the obvious idea:
Use a global priority index where each scheduler class get's it own range (rt: 0-99, fair 100-139 :-). Let the scheduler class have a function returning it instead of reading it directly from task_struct such that new scheduler classes can return their own numbers.

Esben

Quoted 2 lines

Ingo

#361 lore raw
In reply to Ingo Molnar

Hi,

Quoted 7 lines · On Friday 13 April 2007 23:21:00 Ingo Molnar wrote:

[announce] [patch] Modular Scheduler Core and Completely Fair Scheduler [CFS]

i'm pleased to announce the first release of the "Modular Scheduler Core and Completely Fair Scheduler [CFS]" patchset:

http://redhat.com/~mingo/cfs-scheduler/sched-modular+cfs.patch

Tested this on top of Linus' GIT tree but the system gets very unresponsive during high disk i/o using ext3 as filesystem but even writing a 300mb file to a usb disk (iPod actually) has the same affect.

Regards,
ismail

#362 lore raw
Quoted 5 lines · Ismail Dönmez

Hi,

Quoted 3 lines · On Friday 13 April 2007 23:21:00 Ingo Molnar wrote:

[announce] [patch] Modular Scheduler Core and Completely Fair Scheduler [CFS]

Quoted 8 lines
Quoted 4 lines

i'm pleased to announce the first release of the "Modular Scheduler Core and Completely Fair Scheduler [CFS]" patchset:

http://redhat.com/~mingo/cfs-scheduler/sched-modular+cfs.patch

Tested this on top of Linus' GIT tree but the system gets very unresponsive during high disk i/o using ext3 as filesystem but even writing a 300mb file to a usb disk (iPod actually) has the same affect.

just to make sure; this exact same workload but with the stock scheduler does not have this effect?

if so, then it could well be that the scheduler is too fair for it's own good (being really fair inevitably ends up not batching as much as one should, and batching is needed to get any kind of decent performance out of disks nowadays)

Signature · 2 lines
if you want to mail me at work (you don't), use arjan (at) linux.intel.com
Test the interaction between Linux and your BIOS via http://www.linuxfirmwarekit.org
#363 lore raw
Quoted 16 lines · On Monday 16 April 2007 02:23:08 Arjan van de Ven wrote:
Quoted 6 lines · Ismail Dönmez

Hi,

Quoted 3 lines · On Friday 13 April 2007 23:21:00 Ingo Molnar wrote:

[announce] [patch] Modular Scheduler Core and Completely Fair Scheduler [CFS]

Quoted 8 lines
Quoted 4 lines

i'm pleased to announce the first release of the "Modular Scheduler Core and Completely Fair Scheduler [CFS]" patchset:

http://redhat.com/~mingo/cfs-scheduler/sched-modular+cfs.patch

Tested this on top of Linus' GIT tree but the system gets very unresponsive during high disk i/o using ext3 as filesystem but even writing a 300mb file to a usb disk (iPod actually) has the same affect.

Quoted 7 lines

just to make sure; this exact same workload but with the stock scheduler does not have this effect?

if so, then it could well be that the scheduler is too fair for it's own good (being really fair inevitably ends up not batching as much as one should, and batching is needed to get any kind of decent performance out of disks nowadays)

Tried with make install in kdepim (which made system sluggish with CFS) and the system is just fine (using CFQ).

Regards,
ismail

#364 lore raw
In reply to Ismail Dönmez
Quoted 4 lines · Ismail Dönmez

Tested this on top of Linus' GIT tree but the system gets very unresponsive during high disk i/o using ext3 as filesystem but even writing a 300mb file to a usb disk (iPod actually) has the same affect.

hm. Is this an SMP system+kernel by any chance?

Ingo

#365 lore raw
Quoted 7 lines · On Monday 16 April 2007 14:58:54 Ingo Molnar wrote:
Quoted 4 lines · Ismail Dönmez

Tested this on top of Linus' GIT tree but the system gets very unresponsive during high disk i/o using ext3 as filesystem but even writing a 300mb file to a usb disk (iPod actually) has the same affect.

hm. Is this an SMP system+kernel by any chance?

Nope the kernel and the system is UP.

Regards,
ismail

#366 lore raw
In reply to Ingo Molnar
Quoted 6 lines · Ingo Molnar

[announce] [patch] Modular Scheduler Core and Completely Fair Scheduler [CFS]

i'm pleased to announce the first release of the "Modular Scheduler Core and Completely Fair Scheduler [CFS]" patchset:

http://redhat.com/~mingo/cfs-scheduler/sched-modular+cfs.patch

I would suggest to drop the tsc.c change. The "small errors" can be really large on some systems and you can also see large backward jumps. I have a proper (but complicated) solution pending
in ftp://ftp.firstfloor.org/pub/ak/x86_64/quilt/sched-clock-share

BTW with all this CPU time measurement it would be really nice to report it to the user too. It seems a bit bizarre that the scheduler keeps track of ns, but top only knows jiffies with large sampling errors.

-Andi

#367 lore raw
Quoted 8 lines · Andi Kleen
Quoted 4 lines

i'm pleased to announce the first release of the "Modular Scheduler Core and Completely Fair Scheduler [CFS]" patchset:

http://redhat.com/~mingo/cfs-scheduler/sched-modular+cfs.patch

I would suggest to drop the tsc.c change. The "small errors" can be really large on some systems and you can also see large backward jumps.

actually, i designed the CFS code assuming a per-CPU TSC (with no global synchronization), not assuming any globally sync TSC. In fact i wrote it on such systems: a CoreDuo2 box that has stops the TSC in C3 and the different cores have wildly different TSC values and a dual-core Athlon64 that quickly drifts its TSC. So i'll keep the sched_clock() change for now.

Quoted 4 lines

BTW with all this CPU time measurement it would be really nice to report it to the user too. It seems a bit bizarre that the scheduler keeps track of ns, but top only knows jiffies with large sampling errors.

yeah - i'll fix that too if someone doesnt beat me at it.

Ingo

#368 lore raw
Quoted 2 lines

actually, i designed the CFS code assuming a per-CPU TSC (with no global synchronization), not assuming any globally sync TSC. In fact i wrote it

That already worked in the old scheduler (just in a hackish way)

Quoted 4 lines

on such systems: a CoreDuo2 box that has stops the TSC in C3 and the different cores have wildly different TSC values and a dual-core Athlon64 that quickly drifts its TSC. So i'll keep the sched_clock() change for now.

The problem is not CPU synchronized TSC, but TSC with varying frequency on a single CPU like on the A64.

The old implementation can lose really badly on that because it mixes measurements at different frequencies together without individual scaling.

The error gets worse the longer the system runs.

Quoted 6 lines
Quoted 4 lines

BTW with all this CPU time measurement it would be really nice to report it to the user too. It seems a bit bizarre that the scheduler keeps track of ns, but top only knows jiffies with large sampling errors.

yeah - i'll fix that too if someone doesnt beat me at it.

I've been pondering for some time if doubling the NMI watchdog as a ring 0 counter for this is worth it. So far I'm still undecided (and it's moot now since it's disabled by default :/)

-Andi

#369 lore raw
In reply to Ingo Molnar
Quoted 97 lines · Ingo Molnar

[announce] [patch] Modular Scheduler Core and Completely Fair Scheduler [CFS]

i'm pleased to announce the first release of the "Modular Scheduler Core and Completely Fair Scheduler [CFS]" patchset:

http://redhat.com/~mingo/cfs-scheduler/sched-modular+cfs.patch

This project is a complete rewrite of the Linux task scheduler. My goal is to address various feature requests and to fix deficiencies in the vanilla scheduler that were suggested/found in the past few years, both for desktop scheduling and for server scheduling workloads.

[ QuickStart: apply the patch to v2.6.21-rc6, recompile, reboot. The
new scheduler will be active by default and all tasks will default to the new SCHED_FAIR interactive scheduling class. ]

Highlights are:

- the introduction of Scheduling Classes: an extensible hierarchy of scheduler modules. These modules encapsulate scheduling policy details and are handled by the scheduler core without the core code assuming about them too much.

- sched_fair.c implements the 'CFS desktop scheduler': it is a replacement for the vanilla scheduler's SCHED_OTHER interactivity code.

i'd like to give credit to Con Kolivas for the general approach here:
he has proven via RSDL/SD that 'fair scheduling' is possible and that it results in better desktop scheduling. Kudos Con!

The CFS patch uses a completely different approach and implementation from RSDL/SD. My goal was to make CFS's interactivity quality exceed that of RSDL/SD, which is a high standard to meet :-) Testing feedback is welcome to decide this one way or another. [ and, in any case, all of SD's logic could be added via a kernel/sched_sd.c module as well, if Con is interested in such an approach. ]

CFS's design is quite radical: it does not use runqueues, it uses a time-ordered rbtree to build a 'timeline' of future task execution, and thus has no 'array switch' artifacts (by which both the vanilla scheduler and RSDL/SD are affected).

CFS uses nanosecond granularity accounting and does not rely on any jiffies or other HZ detail. Thus the CFS scheduler has no notion of 'timeslices' and has no heuristics whatsoever. There is only one central tunable:

/proc/sys/kernel/sched_granularity_ns

which can be used to tune the scheduler from 'desktop' (low latencies) to 'server' (good batching) workloads. It defaults to a setting suitable for desktop workloads. SCHED_BATCH is handled by the CFS scheduler module too.

due to its design, the CFS scheduler is not prone to any of the 'attacks' that exist today against the heuristics of the stock
scheduler: fiftyp.c, thud.c, chew.c, ring-test.c, massive_intr.c all work fine and do not impact interactivity and produce the expected behavior.

the CFS scheduler has a much stronger handling of nice levels and
SCHED_BATCH: both types of workloads should be isolated much more agressively than under the vanilla scheduler.

( another rdetail: due to nanosec accounting and timeline sorting,
sched_yield() support is very simple under CFS, and in fact under CFS sched_yield() behaves much better than under any other scheduler i have tested so far. )

- sched_rt.c implements SCHED_FIFO and SCHED_RR semantics, in a simpler way than the vanilla scheduler does. It uses 100 runqueues (for all 100 RT priority levels, instead of 140 in the vanilla scheduler) and it needs no expired array.

- reworked/sanitized SMP load-balancing: the runqueue-walking assumptions are gone from the load-balancing code now, and iterators of the scheduling modules are used. The balancing code got quite a bit simpler as a result.

the core scheduler got smaller by more than 700 lines:

 kernel/sched.c | 1454 ++++++++++++++++------------------------------------------------
 1 file changed, 372 insertions(+), 1082 deletions(-)

and even adding all the scheduling modules, the total size impact is relatively small:

 18 files changed, 1454 insertions(+), 1133 deletions(-)

most of the increase is due to extensive comments. The kernel size impact is in fact a small negative:

   text    data     bss     dec     hex filename
  23366    4001      24   27391    6aff kernel/sched.o.vanilla
  24159    2705      56   26920    6928 kernel/sched.o.CFS
Quoted 8 lines

(this is mainly due to the benefit of getting rid of the expired array and its data structure overhead.)

thanks go to Thomas Gleixner and Arjan van de Ven for review of this patchset.

as usual, any sort of feedback, bugreports, fixes and suggestions are more than welcome,

Pushed this through the test.kernel.org and nothing new blew up. Notably the kernbench figures are within expectations even on the bigger numa systems, commonly badly affected by balancing problems in the schedular.

I see there is a second one out, I'll push that one through too.

-apw

#370 lore raw
Quoted 10 lines · Andy Whitcroft
Quoted 3 lines

as usual, any sort of feedback, bugreports, fixes and suggestions are more than welcome,

Pushed this through the test.kernel.org and nothing new blew up. Notably the kernbench figures are within expectations even on the bigger numa systems, commonly badly affected by balancing problems in the schedular.

I see there is a second one out, I'll push that one through too.

Well I just sent some feedback on cfs-v2, but realised it went off-list, so I'll resend here because others may find it interesting too. Sorry about jamming it in here, but it is relevant to performance...

Anyway, roughly in the context of good cfs-v2 interactivity, I wrote:

Well I'm not too surprised. I am disappointed that it uses such small timeslices (or whatever they are called) as the default.

Using small timeslices is actually a pretty easy way to ensure everything stays smooth even under load, but is bad for efficiency. Sure you can say you'll have desktop and server tunings, but... With nicksched I'm testing a default timeslice of *300ms* even on the desktop, wheras Ingo's seems to be effectively 3ms :P So if you compare default tunings, it isn't exactly fair!

Kbuild times on a 2x Xeon:

2.6.21-rc7
508.87user 32.47system 2:17.82elapsed 392%CPU
509.05user 32.25system 2:17.84elapsed 392%CPU
508.75user 32.26system 2:17.83elapsed 392%CPU
508.63user 32.17system 2:17.88elapsed 392%CPU
509.01user 32.26system 2:17.90elapsed 392%CPU
509.08user 32.20system 2:17.95elapsed 392%CPU

2.6.21-rc7-cfs-v2
534.80user 30.92system 2:23.64elapsed 393%CPU
534.75user 31.01system 2:23.70elapsed 393%CPU
534.66user 31.07system 2:23.76elapsed 393%CPU
534.56user 30.91system 2:23.76elapsed 393%CPU
534.66user 31.07system 2:23.67elapsed 393%CPU
535.43user 30.62system 2:23.72elapsed 393%CPU

2.6.21-rc7-nicksched
505.60user 32.31system 2:17.91elapsed 390%CPU
506.55user 32.42system 2:17.66elapsed 391%CPU
506.41user 32.30system 2:17.85elapsed 390%CPU
506.48user 32.36system 2:17.77elapsed 391%CPU
506.10user 32.40system 2:17.81elapsed 390%CPU
506.69user 32.16system 2:17.78elapsed 391%CPU

#371 lore raw
Quoted 7 lines · Nick Piggin

2.6.21-rc7-cfs-v2
534.80user 30.92system 2:23.64elapsed 393%CPU 534.75user 31.01system 2:23.70elapsed 393%CPU 534.66user 31.07system 2:23.76elapsed 393%CPU 534.56user 30.91system 2:23.76elapsed 393%CPU 534.66user 31.07system 2:23.67elapsed 393%CPU 535.43user 30.62system 2:23.72elapsed 393%CPU

Thanks for testing this! Could you please try this also with:

echo 100000000 > /proc/sys/kernel/sched_granularity

on the same system, so that we can get a complete set of numbers? Just to make sure that lowering the preemption frequency indeed has the expected result of moving kernbench numbers back to mainline levels. (if not then that would indicate some CFS buglet)

could you maybe even try a more extreme setting of:

echo 500000000 > /proc/sys/kernel/sched_granularity

for kicks? This would allow us to see how much kernbench we lose due to preemption granularity. Thanks!

Ingo

#372 lore raw
Quoted 20 lines · Ingo Molnar
Quoted 7 lines · Nick Piggin

2.6.21-rc7-cfs-v2
534.80user 30.92system 2:23.64elapsed 393%CPU 534.75user 31.01system 2:23.70elapsed 393%CPU 534.66user 31.07system 2:23.76elapsed 393%CPU 534.56user 30.91system 2:23.76elapsed 393%CPU 534.66user 31.07system 2:23.67elapsed 393%CPU 535.43user 30.62system 2:23.72elapsed 393%CPU

Thanks for testing this! Could you please try this also with:

   echo 100000000 > /proc/sys/kernel/sched_granularity

on the same system, so that we can get a complete set of numbers? Just to make sure that lowering the preemption frequency indeed has the expected result of moving kernbench numbers back to mainline levels. (if not then that would indicate some CFS buglet)

Quoted 6 lines

could you maybe even try a more extreme setting of:

   echo 500000000 > /proc/sys/kernel/sched_granularity

for kicks? This would allow us to see how much kernbench we lose due to preemption granularity. Thanks!

Yeah but I just powered down the test-box, so I'll have to get onto that tomorrow.

#373 lore raw
In reply to Ingo Molnar
Quoted 11 lines · Ingo Molnar
Quoted 7 lines · Nick Piggin

2.6.21-rc7-cfs-v2
534.80user 30.92system 2:23.64elapsed 393%CPU 534.75user 31.01system 2:23.70elapsed 393%CPU 534.66user 31.07system 2:23.76elapsed 393%CPU 534.56user 30.91system 2:23.76elapsed 393%CPU 534.66user 31.07system 2:23.67elapsed 393%CPU 535.43user 30.62system 2:23.72elapsed 393%CPU

Quoted 3 lines

Thanks for testing this! Could you please try this also with:

   echo 100000000 > /proc/sys/kernel/sched_granularity

507.68user 31.87system 2:18.05elapsed 390%CPU
507.99user 31.93system 2:18.09elapsed 390%CPU
507.46user 31.78system 2:18.03elapsed 390%CPU
507.68user 31.93system 2:18.11elapsed 390%CPU
507.63user 31.98system 2:18.01elapsed 390%CPU
507.83user 31.94system 2:18.28elapsed 390%CPU

Quoted 3 lines

could you maybe even try a more extreme setting of:

   echo 500000000 > /proc/sys/kernel/sched_granularity

504.87user 32.13system 2:18.03elapsed 389%CPU
505.94user 32.29system 2:17.87elapsed 390%CPU
506.10user 31.90system 2:17.96elapsed 389%CPU
505.02user 32.02system 2:17.96elapsed 389%CPU
506.69user 31.96system 2:17.82elapsed 390%CPU
505.70user 31.84system 2:17.90elapsed 389%CPU

Again, for comparison 2.6.21-rc7 mainline:

508.87user 32.47system 2:17.82elapsed 392%CPU
509.05user 32.25system 2:17.84elapsed 392%CPU
508.75user 32.26system 2:17.83elapsed 392%CPU
508.63user 32.17system 2:17.88elapsed 392%CPU
509.01user 32.26system 2:17.90elapsed 392%CPU
509.08user 32.20system 2:17.95elapsed 392%CPU

So looking at elapsed time, a granularity of 100ms is just behind the mainline score. However it is using slightly less user time and slightly more idle time, which indicates that balancing might have got a bit less aggressive.

But anyway, it conclusively shows the efficiency impact of such tiny timeslices.

#374 lore raw
Quoted 42 lines · Nick Piggin
Quoted 9 lines · Ingo Molnar
Quoted 7 lines · Nick Piggin

2.6.21-rc7-cfs-v2
534.80user 30.92system 2:23.64elapsed 393%CPU 534.75user 31.01system 2:23.70elapsed 393%CPU 534.66user 31.07system 2:23.76elapsed 393%CPU 534.56user 30.91system 2:23.76elapsed 393%CPU 534.66user 31.07system 2:23.67elapsed 393%CPU 535.43user 30.62system 2:23.72elapsed 393%CPU

Quoted 3 lines

Thanks for testing this! Could you please try this also with:

   echo 100000000 > /proc/sys/kernel/sched_granularity

507.68user 31.87system 2:18.05elapsed 390%CPU
507.99user 31.93system 2:18.09elapsed 390%CPU
507.46user 31.78system 2:18.03elapsed 390%CPU
507.68user 31.93system 2:18.11elapsed 390%CPU
507.63user 31.98system 2:18.01elapsed 390%CPU
507.83user 31.94system 2:18.28elapsed 390%CPU

Quoted 3 lines

could you maybe even try a more extreme setting of:

   echo 500000000 > /proc/sys/kernel/sched_granularity

504.87user 32.13system 2:18.03elapsed 389%CPU
505.94user 32.29system 2:17.87elapsed 390%CPU
506.10user 31.90system 2:17.96elapsed 389%CPU
505.02user 32.02system 2:17.96elapsed 389%CPU
506.69user 31.96system 2:17.82elapsed 390%CPU
505.70user 31.84system 2:17.90elapsed 389%CPU

Again, for comparison 2.6.21-rc7 mainline:

508.87user 32.47system 2:17.82elapsed 392%CPU
509.05user 32.25system 2:17.84elapsed 392%CPU
508.75user 32.26system 2:17.83elapsed 392%CPU
508.63user 32.17system 2:17.88elapsed 392%CPU
509.01user 32.26system 2:17.90elapsed 392%CPU
509.08user 32.20system 2:17.95elapsed 392%CPU

Quoted 7 lines

So looking at elapsed time, a granularity of 100ms is just behind the mainline score. However it is using slightly less user time and slightly more idle time, which indicates that balancing might have got a bit less aggressive.

But anyway, it conclusively shows the efficiency impact of such tiny timeslices.

See test.kernel.org for how (the now defunct) SD was performing on kernbench. It had low latency _and_ equivalent throughput to mainline. Set the standard appropriately on both counts please.

Signature · 1 line
-ck
#375 lore raw
Quoted 15 lines · Con Kolivas
Quoted 14 lines · Nick Piggin

Again, for comparison 2.6.21-rc7 mainline:

508.87user 32.47system 2:17.82elapsed 392%CPU
509.05user 32.25system 2:17.84elapsed 392%CPU
508.75user 32.26system 2:17.83elapsed 392%CPU
508.63user 32.17system 2:17.88elapsed 392%CPU
509.01user 32.26system 2:17.90elapsed 392%CPU
509.08user 32.20system 2:17.95elapsed 392%CPU

So looking at elapsed time, a granularity of 100ms is just behind the mainline score. However it is using slightly less user time and slightly more idle time, which indicates that balancing might have got a bit less aggressive.

Quoted 6 lines
Quoted 2 lines

But anyway, it conclusively shows the efficiency impact of such tiny timeslices.

See test.kernel.org for how (the now defunct) SD was performing on kernbench. It had low latency _and_ equivalent throughput to mainline. Set the standard appropriately on both counts please.

I can give it a run. Got an updated patch against -rc7?

#376 lore raw
Quoted 16 lines · Nick Piggin
Quoted 15 lines · Con Kolivas
Quoted 14 lines · Nick Piggin

Again, for comparison 2.6.21-rc7 mainline:

508.87user 32.47system 2:17.82elapsed 392%CPU
509.05user 32.25system 2:17.84elapsed 392%CPU
508.75user 32.26system 2:17.83elapsed 392%CPU
508.63user 32.17system 2:17.88elapsed 392%CPU
509.01user 32.26system 2:17.90elapsed 392%CPU
509.08user 32.20system 2:17.95elapsed 392%CPU

So looking at elapsed time, a granularity of 100ms is just behind the mainline score. However it is using slightly less user time and slightly more idle time, which indicates that balancing might have got a bit less aggressive.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

But anyway, it conclusively shows the efficiency impact of such tiny timeslices.

See test.kernel.org for how (the now defunct) SD was performing on kernbench. It had low latency _and_ equivalent throughput to mainline. Set the standard appropriately on both counts please.

I can give it a run. Got an updated patch against -rc7?

I said I wasn't pursuing it but since you're offering, the rc6 patch should apply ok.

http://ck.kolivas.org/patches/staircase-deadline/2.6.21-rc6-sd-0.40.patch

Signature · 1 line
-ck
#377 lore raw
Quoted 24 lines · Con Kolivas
Quoted 23 lines · Nick Piggin
Quoted 21 lines · Con Kolivas
Quoted 9 lines · Nick Piggin

Again, for comparison 2.6.21-rc7 mainline:

508.87user 32.47system 2:17.82elapsed 392%CPU
509.05user 32.25system 2:17.84elapsed 392%CPU
508.75user 32.26system 2:17.83elapsed 392%CPU
508.63user 32.17system 2:17.88elapsed 392%CPU
509.01user 32.26system 2:17.90elapsed 392%CPU
509.08user 32.20system 2:17.95elapsed 392%CPU

Quoted 7 lines

So looking at elapsed time, a granularity of 100ms is just behind the mainline score. However it is using slightly less user time and slightly more idle time, which indicates that balancing might have got a bit less aggressive.

But anyway, it conclusively shows the efficiency impact of such tiny timeslices.

See test.kernel.org for how (the now defunct) SD was performing on kernbench. It had low latency _and_ equivalent throughput to mainline. Set the standard appropriately on both counts please.

Quoted 6 lines
Quoted 1 line

I can give it a run. Got an updated patch against -rc7?

I said I wasn't pursuing it but since you're offering, the rc6 patch should apply ok.

http://ck.kolivas.org/patches/staircase-deadline/2.6.21-rc6-sd-0.40.patch

Oh and if you go to the effort of trying you may as well try the timeslice tweak to see what effect it has on SD as well.

/proc/sys/kernel/rr_interval

100 is the highest.

Signature · 1 line
-ck
#378 lore raw
In reply to Nick Piggin
Quoted 13 lines · Nick Piggin
Quoted 5 lines
Quoted 1 line

535.43user 30.62system 2:23.72elapsed 393%CPU

Thanks for testing this! Could you please try this also with:

   echo 100000000 > /proc/sys/kernel/sched_granularity

507.68user 31.87system 2:18.05elapsed 390%CPU
507.99user 31.93system 2:18.09elapsed 390%CPU

Quoted 3 lines

could you maybe even try a more extreme setting of:

   echo 500000000 > /proc/sys/kernel/sched_granularity
Quoted 7 lines

506.69user 31.96system 2:17.82elapsed 390%CPU
505.70user 31.84system 2:17.90elapsed 389%CPU

Again, for comparison 2.6.21-rc7 mainline:

508.87user 32.47system 2:17.82elapsed 392%CPU
509.05user 32.25system 2:17.84elapsed 392%CPU

thanks for testing this!

Quoted 7 lines

So looking at elapsed time, a granularity of 100ms is just behind the mainline score. However it is using slightly less user time and slightly more idle time, which indicates that balancing might have got a bit less aggressive.

But anyway, it conclusively shows the efficiency impact of such tiny timeslices.

yeah, the 4% drop in a CPU-cache-sensitive workload like kernbench is not unexpected when going to really frequent preemption. Clearly, the default preemption granularity needs to be tuned up.

I think you said you measured ~3msec average preemption rate per CPU? That would suggest the average cache-trashing cost was 120 usecs per every 3 msec window. Taking that as a ballpark figure, to get the difference back into the noise range we'd have to either use ~5 msec:

    echo 5000000 > /proc/sys/kernel/sched_granularity

or 15 msec:

    echo 15000000 > /proc/sys/kernel/sched_granularity

(depending on whether it's 5x 3msec or 5x 1msec - i'm still not sure i correctly understood your 3msec value. I'd have to know your kernbench workload's approximate 'steady state' context-switch rate to do a more accurate calculation.)

Ingo

#379 lore raw
Quoted 8 lines · Ingo Molnar
Quoted 5 lines · Nick Piggin

So looking at elapsed time, a granularity of 100ms is just behind the mainline score. However it is using slightly less user time and slightly more idle time, which indicates that balancing might have got a bit less aggressive.

Quoted 8 lines
Quoted 2 lines

But anyway, it conclusively shows the efficiency impact of such tiny timeslices.

yeah, the 4% drop in a CPU-cache-sensitive workload like kernbench is not unexpected when going to really frequent preemption. Clearly, the default preemption granularity needs to be tuned up.

I think you said you measured ~3msec average preemption rate per CPU?

This was just looking at ctxsw numbers from running 2 cpu hogs on the same runqueue.

Quoted 6 lines

That would suggest the average cache-trashing cost was 120 usecs per every 3 msec window. Taking that as a ballpark figure, to get the difference back into the noise range we'd have to either use ~5 msec:

    echo 5000000 > /proc/sys/kernel/sched_granularity
Quoted 8 lines

or 15 msec:

    echo 15000000 > /proc/sys/kernel/sched_granularity

(depending on whether it's 5x 3msec or 5x 1msec - i'm still not sure i correctly understood your 3msec value. I'd have to know your kernbench workload's approximate 'steady state' context-switch rate to do a more accurate calculation.)

The kernel compile (make -j8 on 4 thread system) is doing 1800 total context switches per second (450/s per runqueue) for cfs, and 670 for mainline. Going up to 20ms granularity for cfs brings the context switch numbers similar, but user time is still a % or so higher. I'd be more worried about compute heavy threads which naturally don't do much context switching.

Some other numbers on the same system
Hackbench: 2.6.21-rc7 cfs-v2 1ms[*] nicksched
10 groups: Time: 1.332 0.743 0.607
20 groups: Time: 1.197 1.100 1.241
30 groups: Time: 1.754 2.376 1.834
40 groups: Time: 3.451 2.227 2.503
50 groups: Time: 3.726 3.399 3.220
60 groups: Time: 3.548 4.567 3.668
70 groups: Time: 4.206 4.905 4.314
80 groups: Time: 4.551 6.324 4.879
90 groups: Time: 7.904 6.962 5.335
100 groups: Time: 7.293 7.799 5.857
110 groups: Time: 10.595 8.728 6.517
120 groups: Time: 7.543 9.304 7.082
130 groups: Time: 8.269 10.639 8.007
140 groups: Time: 11.867 8.250 8.302
150 groups: Time: 14.852 8.656 8.662
160 groups: Time: 9.648 9.313 9.541

Mainline seems pretty inconsistent here.

lmbench 0K ctxsw latency bound to CPU0:
tasks
2 2.59 3.42 2.50
4 3.26 3.54 3.09
8 3.01 3.64 3.22
16 3.00 3.66 3.50
32 2.99 3.70 3.49
64 3.09 4.17 3.50
128 4.80 5.58 4.74
256 5.79 6.37 5.76

cfs is noticably disadvantaged.

[*] 500ms didn't make much difference in either test.

#380 lore raw
Quoted 34 lines · Nick Piggin
Quoted 6 lines · Ingo Molnar
Quoted 5 lines · Nick Piggin

So looking at elapsed time, a granularity of 100ms is just behind the mainline score. However it is using slightly less user time and slightly more idle time, which indicates that balancing might have got a bit less aggressive.

Quoted 8 lines
Quoted 2 lines

But anyway, it conclusively shows the efficiency impact of such tiny timeslices.

yeah, the 4% drop in a CPU-cache-sensitive workload like kernbench is not unexpected when going to really frequent preemption. Clearly, the default preemption granularity needs to be tuned up.

I think you said you measured ~3msec average preemption rate per CPU?

This was just looking at ctxsw numbers from running 2 cpu hogs on the same runqueue.

Quoted 6 lines

That would suggest the average cache-trashing cost was 120 usecs per every 3 msec window. Taking that as a ballpark figure, to get the difference back into the noise range we'd have to either use ~5 msec:

    echo 5000000 > /proc/sys/kernel/sched_granularity
Quoted 8 lines

or 15 msec:

    echo 15000000 > /proc/sys/kernel/sched_granularity

(depending on whether it's 5x 3msec or 5x 1msec - i'm still not sure i correctly understood your 3msec value. I'd have to know your kernbench workload's approximate 'steady state' context-switch rate to do a more accurate calculation.)

Quoted 6 lines

The kernel compile (make -j8 on 4 thread system) is doing 1800 total context switches per second (450/s per runqueue) for cfs, and 670 for mainline. Going up to 20ms granularity for cfs brings the context switch numbers similar, but user time is still a % or so higher. I'd be more worried about compute heavy threads which naturally don't do much context switching.

While kernel compiles are nice and easy to do I've seen enough criticism of them in the past to wonder about their usefulness as a standard benchmark on their own.

Quoted 11 lines

Some other numbers on the same system
Hackbench: 2.6.21-rc7 cfs-v2 1ms[*] nicksched
10 groups: Time: 1.332 0.743 0.607
20 groups: Time: 1.197 1.100 1.241
30 groups: Time: 1.754 2.376 1.834
40 groups: Time: 3.451 2.227 2.503
50 groups: Time: 3.726 3.399 3.220
60 groups: Time: 3.548 4.567 3.668
70 groups: Time: 4.206 4.905 4.314
80 groups: Time: 4.551 6.324 4.879

Quoted 8 lines

90 groups: Time: 7.904 6.962 5.335
100 groups: Time: 7.293 7.799 5.857
110 groups: Time: 10.595 8.728 6.517
120 groups: Time: 7.543 9.304 7.082
130 groups: Time: 8.269 10.639 8.007
140 groups: Time: 11.867 8.250 8.302
150 groups: Time: 14.852 8.656 8.662
160 groups: Time: 9.648 9.313 9.541

Hackbench even more so. A prolonged discussion with Rusty Russell on this issue he suggested hackbench was more a pass/fail benchmark to ensure there was no starvation scenario that never ended, and very little value should be placed on the actual results returned from it.

Wli's concerns regarding some sort of standard framework for a battery of accepted meaningful benchmarks comes to mind as important rather than ones that highlight one over the other. So while interesting for their own endpoints, I certainly wouldn't put either benchmark as some sort of yardstick for a "winner". Note I'm not saying that we shouldn't be looking at them per se, but since the whole drive for a new scheduler is trying to be more objective we need to start expanding the range of benchmarks. Even though I don't feel the need to have SD in the "race" I guess it stands for more data to compare what is possible/where as well.

Quoted 16 lines

Mainline seems pretty inconsistent here.

lmbench 0K ctxsw latency bound to CPU0:
tasks
2 2.59 3.42 2.50
4 3.26 3.54 3.09
8 3.01 3.64 3.22
16 3.00 3.66 3.50
32 2.99 3.70 3.49
64 3.09 4.17 3.50
128 4.80 5.58 4.74
256 5.79 6.37 5.76

cfs is noticably disadvantaged.

[*] 500ms didn't make much difference in either test.

Signature · 1 line
-ck
#381 lore raw
Quoted 9 lines · Con Kolivas
Quoted 7 lines · Nick Piggin

The kernel compile (make -j8 on 4 thread system) is doing 1800 total context switches per second (450/s per runqueue) for cfs, and 670 for mainline. Going up to 20ms granularity for cfs brings the context switch numbers similar, but user time is still a % or so higher. I'd be more worried about compute heavy threads which naturally don't do much context switching.

Quoted 3 lines

While kernel compiles are nice and easy to do I've seen enough criticism of them in the past to wonder about their usefulness as a standard benchmark on their own.

Actually it is a real workload for most kernel developers including you no doubt :)

The criticism's of kernbench for the kernel are probably fair in that kernel compiles don't exercise a lot of kernel functionality (page allocator and fault paths mostly, IIRC). However as far as I'm concerned, they're great for testing the CPU scheduler, because it doesn't actually matter whether you're running in userspace or kernel space for a context switch to blow your caches. The results are quite stable.

You could actually make up a benchmark that hurts a whole lot more from context switching, but I figure that kernbench is a real world thing that shows it up quite well.

Quoted 19 lines
Quoted 10 lines

Some other numbers on the same system
Hackbench: 2.6.21-rc7 cfs-v2 1ms[*] nicksched
10 groups: Time: 1.332 0.743 0.607
20 groups: Time: 1.197 1.100 1.241
30 groups: Time: 1.754 2.376 1.834
40 groups: Time: 3.451 2.227 2.503
50 groups: Time: 3.726 3.399 3.220
60 groups: Time: 3.548 4.567 3.668
70 groups: Time: 4.206 4.905 4.314
80 groups: Time: 4.551 6.324 4.879

Quoted 8 lines

90 groups: Time: 7.904 6.962 5.335
100 groups: Time: 7.293 7.799 5.857
110 groups: Time: 10.595 8.728 6.517
120 groups: Time: 7.543 9.304 7.082
130 groups: Time: 8.269 10.639 8.007
140 groups: Time: 11.867 8.250 8.302
150 groups: Time: 14.852 8.656 8.662
160 groups: Time: 9.648 9.313 9.541

Quoted 4 lines

Hackbench even more so. A prolonged discussion with Rusty Russell on this issue he suggested hackbench was more a pass/fail benchmark to ensure there was no starvation scenario that never ended, and very little value should be placed on the actual results returned from it.

Yeah, cfs seems to do a little worse than nicksched here, but I include the numbers not because I think that is significant, but to show mainline's poor characteristics.

#382 lore raw
In reply to Andy Whitcroft
Quoted 7 lines · Andy Whitcroft
Quoted 2 lines

as usual, any sort of feedback, bugreports, fixes and suggestions are more than welcome,

Pushed this through the test.kernel.org and nothing new blew up. Notably the kernbench figures are within expectations even on the bigger numa systems, commonly badly affected by balancing problems in the schedular.

thanks! Given the really low preemption latency/granularity default (roughly equivalent to 'timeslice length'), and that basically all of my focus was on interactivity characteristics, this is a pretty good result. I suspect it will be necessary to increase the default to 10 msecs (or more) to be on the safe side. (Nick has reported a 4% kernbench drop so for his kernbench workload it's needed.)

Ingo

#383 lore raw

CFS and suspend2: hang in atomic copy (was: [Announce] [patch] Modular Scheduler Core and Completely Fair Scheduler [CFS])

In reply to Ingo Molnar

Hi Ingo and all,

Quoted 2 lines · Ingo Molnar

as usual, any sort of feedback, bugreports, fixes and suggestions are more than welcome,

I just gave CFS a try on my system. From a user's point of view it looks good so far. Thanks for your work.

However I found a problem: When trying to suspend a system patched with suspend2 2.2.9.11 it hangs with "doing atomic copy". Pressing the ESC key results in a message that it tries to abort suspend, but then still hangs.

I cced suspend2 devel list, perhaps Nigel is interested as well.

Signature · 2 lines
Regards,
Chris
#384 lore raw

Re: CFS and suspend2: hang in atomic copy (was: [Announce] [patch] Modular Scheduler Core and Completely Fair Scheduler [CFS])

Quoted 8 lines · Christian Hesse

Hi Ingo and all,

Quoted 2 lines · Ingo Molnar

as usual, any sort of feedback, bugreports, fixes and suggestions are more than welcome,

I just gave CFS a try on my system. From a user's point of view it looks good so far. Thanks for your work.

you are welcome!

Quoted 4 lines

However I found a problem: When trying to suspend a system patched with suspend2 2.2.9.11 it hangs with "doing atomic copy". Pressing the ESC key results in a message that it tries to abort suspend, but then still hangs.

i took a quick look at suspend2 and it makes some use of yield(). There's a bug in CFS's yield code, i've attached a patch that should fix it, does it make any difference to the hang?

Ingo

kernel/sched_fair.c +18 -4
Index: linux/kernel/sched_fair.c
===================================================================
@@ -264,15 +264,26 @@ static void dequeue_task_fair(struct rq 
 
 /*
  * sched_yield() support is very simple via the rbtree, we just
- * dequeue and enqueue the task, which causes the task to
- * roundrobin to the end of the tree:
+ * dequeue the task and move it to the rightmost position, which
+ * causes the task to roundrobin to the end of the tree.
  */
 static void requeue_task_fair(struct rq *rq, struct task_struct *p)
 {
 	dequeue_task_fair(rq, p);
 	p->on_rq = 0;
-	enqueue_task_fair(rq, p);
+	/*
+	 * Temporarily insert at the last position of the tree:
+	 */
+	p->fair_key = LLONG_MAX;
+	__enqueue_task_fair(rq, p);
 	p->on_rq = 1;
+
+	/*
+	 * Update the key to the real value, so that when all other
+	 * tasks from before the rightmost position have executed,
+	 * this task is picked up again:
+	 */
+	p->fair_key = rq->fair_clock - p->wait_runtime + p->nice_offset;
 }
 
 /*
@@ -380,7 +391,10 @@ static void task_tick_fair(struct rq *rq
 	 * Dequeue and enqueue the task to update its
 	 * position within the tree:
 	 */
-	requeue_task_fair(rq, curr);
+	dequeue_task_fair(rq, curr);
+	curr->on_rq = 0;
+	enqueue_task_fair(rq, curr);
+	curr->on_rq = 1;
 
 	/*
 	 * Reschedule if another task tops the current one.
#385 lore raw

Re: CFS and suspend2: hang in atomic copy

Quoted 5 lines · Ingo Molnar
Quoted 4 lines · Christian Hesse
Quoted 2 lines · Ingo Molnar

as usual, any sort of feedback, bugreports, fixes and suggestions are more than welcome,

Quoted 8 lines
Quoted 4 lines

When trying to suspend a system patched
with suspend2 2.2.9.11 it hangs with "doing atomic copy". Pressing the ESC key results in a message that it tries to abort suspend, but then still hangs.

i took a quick look at suspend2 and it makes some use of yield(). There's a bug in CFS's yield code, i've attached a patch that should fix it, does it make any difference to the hang?

This patch should apply cleanly against what? The second hunk is ignored as it has already been applied. Is this correct?

But no, it does not change anything. Let me know if you have any other patches to test.

Signature · 2 lines
Regards,
Chris
#386 lore raw

Re: CFS and suspend2: hang in atomic copy

Quoted 6 lines · Christian Hesse
Quoted 3 lines

i took a quick look at suspend2 and it makes some use of yield(). There's a bug in CFS's yield code, i've attached a patch that should fix it, does it make any difference to the hang?

This patch should apply cleanly against what? The second hunk is ignored as it has already been applied. Is this correct?

hm, i think you might have had one of the earlier CFS patches.

Quoted 2 lines

But no, it does not change anything. Let me know if you have any other patches to test.

could you try the -v3 patch i released a few hours ago:

http://redhat.com/~mingo/cfs-scheduler/

although probably your suspend2 problem is still not fixed, it's worth a try nevertheless. Which suspend2 patch did you apply, and was it against -rc6 or -rc7?

Ingo

#387 lore raw

Re: CFS and suspend2: hang in atomic copy

Quoted 9 lines · Ingo Molnar
Quoted 6 lines · Christian Hesse
Quoted 3 lines

i took a quick look at suspend2 and it makes some use of yield(). There's a bug in CFS's yield code, i've attached a patch that should fix it, does it make any difference to the hang?

This patch should apply cleanly against what? The second hunk is ignored as it has already been applied. Is this correct?

hm, i think you might have had one of the earlier CFS patches.

You are right.

Quoted 10 lines
Quoted 2 lines

But no, it does not change anything. Let me know if you have any other patches to test.

could you try the -v3 patch i released a few hours ago:

http://redhat.com/~mingo/cfs-scheduler/

although probably your suspend2 problem is still not fixed, it's worth a try nevertheless. Which suspend2 patch did you apply, and was it against -rc6 or -rc7?

You are right again. ;-)

Linux 2.6.21-rc7
Suspend2 2.2.9.11 (applies cleanly to -rc7)
CFS v3 (without any additional patches)

And it still hangs on suspend.

Signature · 2 lines
Regards,
Chris
#388 lore raw

Re: CFS and suspend2: hang in atomic copy

Quoted 11 lines · Christian Hesse
Quoted 3 lines

although probably your suspend2 problem is still not fixed, it's worth a try nevertheless. Which suspend2 patch did you apply, and was it against -rc6 or -rc7?

You are right again. ;-)

Linux 2.6.21-rc7
Suspend2 2.2.9.11 (applies cleanly to -rc7)
CFS v3 (without any additional patches)

And it still hangs on suspend.

what's the easiest way for me to try suspend2? Apply the patch, reboot into the kernel, then execute what command to suspend? (there's a confusing mismash of initiators of all the suspend variants. Can i drive this by echoing to /sys/power/state?)

Ingo

#389 lore raw

Re: CFS and suspend2: hang in atomic copy

Quoted 11 lines · Ingo Molnar
Quoted 10 lines · Christian Hesse
Quoted 3 lines

although probably your suspend2 problem is still not fixed, it's worth a try nevertheless. Which suspend2 patch did you apply, and was it against -rc6 or -rc7?

You are right again. ;-)

Linux 2.6.21-rc7
Suspend2 2.2.9.11 (applies cleanly to -rc7)
CFS v3 (without any additional patches)

Quoted 6 lines
Quoted 1 line

And it still hangs on suspend.

what's the easiest way for me to try suspend2? Apply the patch, reboot into the kernel, then execute what command to suspend? (there's a confusing mismash of initiators of all the suspend variants. Can i drive this by echoing to /sys/power/state?)

Perhaps you have to install suspend2-userui as well for the output (I'm not shure whether it works without). Then you can trigger the suspend by echoing to /sys/power/suspend2/do_suspend.
Useful informations can be found in the Howto:

http://www.suspend2.net/HOWTO

I dropped some ccs to not abuse Linus and friends.

Signature · 2 lines
Regards,
Chris
#390 lore raw

Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy

Hi.

Quoted 19 lines · Christian Hesse
Quoted 11 lines · Ingo Molnar
Quoted 10 lines · Christian Hesse
Quoted 3 lines

although probably your suspend2 problem is still not fixed, it's worth a try nevertheless. Which suspend2 patch did you apply, and was it against -rc6 or -rc7?

You are right again. ;-)

Linux 2.6.21-rc7
Suspend2 2.2.9.11 (applies cleanly to -rc7)
CFS v3 (without any additional patches)

Quoted 6 lines
Quoted 1 line

And it still hangs on suspend.

what's the easiest way for me to try suspend2? Apply the patch, reboot into the kernel, then execute what command to suspend? (there's a confusing mismash of initiators of all the suspend variants. Can i drive this by echoing to /sys/power/state?)

Quoted 8 lines

Perhaps you have to install suspend2-userui as well for the output (I'm not shure whether it works without). Then you can trigger the suspend by echoing to /sys/power/suspend2/do_suspend.
Useful informations can be found in the Howto:

http://www.suspend2.net/HOWTO

I dropped some ccs to not abuse Linus and friends.

You can suspend and resume without it.

Regards,

Nigel

#391 lore raw

Re: CFS and suspend2: hang in atomic copy

In reply to Ingo Molnar

Ingo Molnar wrote: [Wed Apr 18 2007, 06:02:28PM EDT]

Quoted 13 lines · Christian Hesse
Quoted 11 lines
Quoted 4 lines

although probably your suspend2 problem is still not fixed, it's worth a try nevertheless. Which suspend2 patch did you apply, and was it against -rc6 or -rc7?

You are right again. ;-)

Linux 2.6.21-rc7
Suspend2 2.2.9.11 (applies cleanly to -rc7)
CFS v3 (without any additional patches)

Quoted 8 lines
Quoted 1 line

And it still hangs on suspend.

what's the easiest way for me to try suspend2? Apply the patch, reboot into the kernel, then execute what command to suspend? (there's a confusing mismash of initiators of all the suspend variants. Can i drive this by echoing to /sys/power/state?)

Ingo

I had hoped to collect more data with CFS V2. It crashes in scale_nice_down for s2ram when attempting to disable_nonboot_cpus. So part of traceback looks like (typed by hand with obvious omissions):

scale_nice_down
update_stats_wait_end - not shown in traceback because inlined pick_next_task_fair
migration_call
task_rq_lock
notifier_call_chain
_cpu_down
disable_nonboot_cpus
...

This is standard -rc7 with V2 CFS applied. It could be a completely unrelated issue. I'll attempt to debug further tomorrow.

bob

#392 lore raw

Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy

Hi.

Quoted 36 lines · Bob Picco

Ingo Molnar wrote: [Wed Apr 18 2007, 06:02:28PM EDT]

Quoted 13 lines · Christian Hesse
Quoted 11 lines
Quoted 4 lines

although probably your suspend2 problem is still not fixed, it's worth a try nevertheless. Which suspend2 patch did you apply, and was it against -rc6 or -rc7?

You are right again. ;-)

Linux 2.6.21-rc7
Suspend2 2.2.9.11 (applies cleanly to -rc7)
CFS v3 (without any additional patches)

Quoted 8 lines
Quoted 1 line

And it still hangs on suspend.

what's the easiest way for me to try suspend2? Apply the patch, reboot into the kernel, then execute what command to suspend? (there's a confusing mismash of initiators of all the suspend variants. Can i drive this by echoing to /sys/power/state?)

Ingo

I had hoped to collect more data with CFS V2. It crashes in scale_nice_down for s2ram when attempting to disable_nonboot_cpus. So part of traceback looks like (typed by hand with obvious omissions):

scale_nice_down
update_stats_wait_end - not shown in traceback because inlined pick_next_task_fair
migration_call
task_rq_lock
notifier_call_chain
_cpu_down
disable_nonboot_cpus
...

Quoted 2 lines

This is standard -rc7 with V2 CFS applied. It could be a completely unrelated issue. I'll attempt to debug further tomorrow.

That - and Christian's other reply with the jpg - look to me more like this is an interaction between CFS and cpu hotplugging than Suspend2 itself. Can you also reproduce this with swsusp?

Regards,

Nigel

#393 lore raw

Re: CFS and suspend2: hang in atomic copy

In reply to Bob Picco
Quoted 4 lines · Bob Picco

I had hoped to collect more data with CFS V2. It crashes in scale_nice_down for s2ram when attempting to disable_nonboot_cpus. So part of traceback looks like (typed by hand with obvious omissions):

Quoted 8 lines

scale_nice_down
update_stats_wait_end - not shown in traceback because inlined pick_next_task_fair
migration_call
task_rq_lock
notifier_call_chain
_cpu_down
disable_nonboot_cpus

ok, this looks similar to the jpeg Christian did. Does the patch below fix the crash for you?

Ingo

---
 kernel/sched.c |    2 ++
 1 file changed, 2 insertions(+)
kernel/sched.c +2 -0
Index: linux/kernel/sched.c
===================================================================
@@ -4425,6 +4425,8 @@ static void migrate_dead_tasks(unsigned 
 	struct task_struct *next;
 
 	for (;;) {
+		if (!rq->nr_running)
+			break;
 		next = pick_next_task(rq, rq->curr);
 		if (!next)
 			break;
#394 lore raw

Re: CFS and suspend2: hang in atomic copy

Ingo Molnar wrote: [Thu Apr 19 2007, 02:29:36AM EDT]

Quoted 30 lines · Bob Picco
Quoted 5 lines

I had hoped to collect more data with CFS V2. It crashes in scale_nice_down for s2ram when attempting to disable_nonboot_cpus. So part of traceback looks like (typed by hand with obvious omissions):

Quoted 8 lines

scale_nice_down
update_stats_wait_end - not shown in traceback because inlined pick_next_task_fair
migration_call
task_rq_lock
notifier_call_chain
_cpu_down
disable_nonboot_cpus

ok, this looks similar to the jpeg Christian did. Does the patch below fix the crash for you?

Ingo

---
 kernel/sched.c |    2 ++
 1 file changed, 2 insertions(+)

Index: linux/kernel/sched.c
===================================================================

kernel/sched.c static void migrate_dead_tasks(unsigned · line 4432

Quoted 8 lines
kernel/sched.c +2 -0
@@ -4425,6 +4425,8 @@ static void migrate_dead_tasks(unsigned 
 	struct task_struct *next;
 
 	for (;;) {
+		if (!rq->nr_running)
+			break;
 		next = pick_next_task(rq, rq->curr);
 		if (!next)
 			break;

This patch repairs s2ram issue.

Thanks.

bob

#395 lore raw

Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy

In reply to Ingo Molnar

Hi.

Quoted 12 lines · Ingo Molnar
Quoted 10 lines · Christian Hesse
Quoted 3 lines

although probably your suspend2 problem is still not fixed, it's worth a try nevertheless. Which suspend2 patch did you apply, and was it against -rc6 or -rc7?

You are right again. ;-)

Linux 2.6.21-rc7
Suspend2 2.2.9.11 (applies cleanly to -rc7)
CFS v3 (without any additional patches)

Quoted 6 lines
Quoted 1 line

And it still hangs on suspend.

what's the easiest way for me to try suspend2? Apply the patch, reboot into the kernel, then execute what command to suspend? (there's a confusing mismash of initiators of all the suspend variants. Can i drive this by echoing to /sys/power/state?)

From subsequent emails, I think you already got your answer, but just in case...

Yes, if you enabled "Replace swsusp by default" and you already had it set up for getting swsusp to resume. If not, and you're using an initrd/ramfs, you'll need to modify it to echo

Quoted 1 line

/sys/power/suspend2/do_resume after /sys and /proc are mounted but

prior to mounting / and so on.

Regards,

Nigel

#396 lore raw

Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy

Quoted 8 lines · Nigel Cunningham

From subsequent emails, I think you already got your answer, but just in case...

Yes, if you enabled "Replace swsusp by default" and you already had it set up for getting swsusp to resume. If not, and you're using an initrd/ramfs, you'll need to modify it to echo

Quoted 1 line

/sys/power/suspend2/do_resume after /sys and /proc are mounted but

prior to mounting / and so on.

yeah, went with the default suggested by your patch:

CONFIG_SUSPEND2_REPLACE_SWSUSP=y

and it was pretty easy to set things up. I used "echo disk > /sys/power/state" to trigger it.

In hindsight it was all pretty straightforward and suspend2 worked beautifully on an UP and on an SMP system i tried. So in exchange for suspend2 folks debugging a bug in CFS here's some suspend2 review feedback ;) Any plans about moving suspend2 to the upstream kernel? It should be pretty easy for it to co-exist with the current swsuspend code.

The patch has quite some size:

 89 files changed, 16452 insertions(+), 69 deletions(-)

that should obviously be split up into more than a dozen sub-patches, and fed to lkml with the small ones first. (unless it already is split up?)

i cannot comment on the kernel/power/ bits (they are way too large anyway), other than that they look pretty clean visually, but the lowlevel arch and generic kernel bits look sane in detail too, sans a few mostly trivial cleanliness issues:

+int suspend2_faulted = 0;
+EXPORT_SYMBOL(suspend2_faulted);

should be done via the pagefault notifier chain mechanism. Also, all the exports you added should be EXPORT_SYMBOL_GPL().

this:

-               ClearPageReserved(virt_to_page(addr));
-               init_page_count(virt_to_page(addr));
+               //ClearPageReserved(virt_to_page(addr));
+               //init_page_count(virt_to_page(addr));

looks like there's a buglet in there still somewhere?

+ if(PageHighMem(page))
+ return 0;

coding style.

+ BUG_ON( test_suspend_state(SUSPEND_RUNNING) && /* Suspend2, that is */

make this a WARN_ON() or a WARN_ON_ONCE() - that way you have a chance to even get feedback from users, instead of a 'uhm, X froze' report.

+#define FREEZER_OFF 0
+#define FREEZER_USERSPACE_FROZEN 1
+#define FREEZER_FULLY_ON 2

should be:

+#define FREEZER_OFF 0
+#define FREEZER_USERSPACE_FROZEN 1
+#define FREEZER_FULLY_ON 2

(you want your reviewers have an pleasant time reading your code :)

+#define NETLINK_SUSPEND2_USERUI 20 /* For suspend2's userui */

IIRC userui was at the center of suspend2 merge flames, right? So you might want to layer it ontop a less flashy suspend2-core and thus get 90% of your patch upstream?

+++ linux/mm/vmscan.c

the MM impact looks quite nontrivial. But i suspect this is unavoidable, because you zap portions of the pagecache on the way to disk, so when it comes back it results in a different pagecache (new lru lists, etc.), right?

+++ linux/lib/dyn_pageflags.c

shouldnt this be in mm/dyn_pageflags.c? Plus it would be nice to use some other core kernel user for this infrastructure. (but it's not a necessity i guess)

but ... again, the patch looks sane all around.

Ingo

#397 lore raw

Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy

Hi Ingo.

Quoted 18 lines · Ingo Molnar
Quoted 8 lines · Nigel Cunningham

From subsequent emails, I think you already got your answer, but just in case...

Yes, if you enabled "Replace swsusp by default" and you already had it set up for getting swsusp to resume. If not, and you're using an initrd/ramfs, you'll need to modify it to echo

Quoted 1 line

/sys/power/suspend2/do_resume after /sys and /proc are mounted but

prior to mounting / and so on.

yeah, went with the default suggested by your patch:

CONFIG_SUSPEND2_REPLACE_SWSUSP=y

and it was pretty easy to set things up. I used "echo disk > /sys/power/state" to trigger it.

Quoted 6 lines

In hindsight it was all pretty straightforward and suspend2 worked beautifully on an UP and on an SMP system i tried. So in exchange for suspend2 folks debugging a bug in CFS here's some suspend2 review feedback ;) Any plans about moving suspend2 to the upstream kernel? It should be pretty easy for it to co-exist with the current swsuspend code.

I really would like to get it into Linus' tree but Pavel doesn't want it (obviously!) and I haven't got together enough of a case yet to convince Andrew. I yet another here's-why-I-think-it-should-be-merged email in the works (poor Andrew!) but there are too many other things on my plate at the mo.

Quoted 7 lines

The patch has quite some size:

 89 files changed, 16452 insertions(+), 69 deletions(-)

that should obviously be split up into more than a dozen sub-patches, and fed to lkml with the small ones first. (unless it already is split up?)

Right. A good portion (~2000 lines) of that is documentation.

Quoted 10 lines

i cannot comment on the kernel/power/ bits (they are way too large anyway), other than that they look pretty clean visually, but the lowlevel arch and generic kernel bits look sane in detail too, sans a few mostly trivial cleanliness issues:

(quoted diff) +2 -0
+int suspend2_faulted = 0;
+EXPORT_SYMBOL(suspend2_faulted);

should be done via the pagefault notifier chain mechanism. Also, all the exports you added should be EXPORT_SYMBOL_GPL().

I'll look at that, but I'm not sure if it's a good idea - this is for during the atomic copy & restore, when DEBUG_PAGEALLOC is enabled on x86. Other things might touch memory in ways we don't want. It's only needed for slab pages that get unmapped but not freed.

As far as the module exports go, I'm not expecting them to get merged. I like building Suspend2 as modules (it helps speed the development cycle), and see it as potentially useful for embedded but IMO there are too many export symbols to make merging that code a possibility. This is why they're all in one file rather than sprinkled through the files that define the symbols.

Quoted 8 lines

this:

(quoted diff) +2 -2
-               ClearPageReserved(virt_to_page(addr));
-               init_page_count(virt_to_page(addr));
+               //ClearPageReserved(virt_to_page(addr));
+               //init_page_count(virt_to_page(addr));

looks like there's a buglet in there still somewhere?

Yeah. When I was recently debugging, I found that cpu hotplugging is using something marked __init which is causing the machine to spontaneously reboot when cpus are replugged if DEBUG_PAGEALLOC is enabled. Haven't had the time to get back to it, and also need some help with the approach (what makes the machine reboot in this case instead of oopsing, and how do I stop it?).

Quoted 4 lines
(quoted diff) +2 -0
+       if(PageHighMem(page))
+               return 0;

coding style.

Oh. The space missing after the if? Ok.

Quoted 15 lines

+ BUG_ON( test_suspend_state(SUSPEND_RUNNING) && /* Suspend2, that is */

make this a WARN_ON() or a WARN_ON_ONCE() - that way you have a chance to even get feedback from users, instead of a 'uhm, X froze' report.

(quoted diff) +3 -0
+#define FREEZER_OFF 0
+#define FREEZER_USERSPACE_FROZEN 1
+#define FREEZER_FULLY_ON 2

should be:

(quoted diff) +3 -0
+#define FREEZER_OFF			0
+#define FREEZER_USERSPACE_FROZEN	1
+#define FREEZER_FULLY_ON		2
Quoted 1 line

(you want your reviewers have an pleasant time reading your code :)

Ok.

Quoted 5 lines

+#define NETLINK_SUSPEND2_USERUI 20 /* For suspend2's userui */

IIRC userui was at the center of suspend2 merge flames, right? So you might want to layer it ontop a less flashy suspend2-core and thus get 90% of your patch upstream?

Ok. I've just separated that into it's own file/module, so that will be straightforward to do.

Quoted 6 lines

+++ linux/mm/vmscan.c

the MM impact looks quite nontrivial. But i suspect this is unavoidable, because you zap portions of the pagecache on the way to disk, so when it comes back it results in a different pagecache (new lru lists, etc.), right?

The modifications do three things.

First, we're seeking to keep the LRU static once while we're suspending. I originally sought to achieve that by avoiding entering the vmscan.c logic (not as drastic as it sounds - Suspend2 is the only thing running!). I think it was Nick who said he'd rather see it the pages unlinked and kept safe that way, so now I do that. Oh, as part of this, I separated out the code from shrink_inactive_list that returns isolated pages, since relink_lru_lists uses it too.

The other part is (prior to the above) seeking to get in a situation where we have enough memory available to do the cycle. I used to use shrink_all_zones, but some users with lots of Highmem were finding issues that let me to take a more per-zone based approach, hence shrink_one_zone.

The last thing is a patch Rafael recently posted to improve kswapd freezing.

Quoted 5 lines

+++ linux/lib/dyn_pageflags.c

shouldnt this be in mm/dyn_pageflags.c? Plus it would be nice to use some other core kernel user for this infrastructure. (but it's not a necessity i guess)

Yeah, I guess mm makes more sense.

Quoted 1 line

but ... again, the patch looks sane all around.

Thanks for the feedback. Although I'd like to see Suspend2 merged, I've been feeling a bit like it's a lost cause. It's nice to get some encouragement.

Nigel

#398 lore raw

suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

In reply to Ingo Molnar

Hi!

Quoted 16 lines
Quoted 8 lines

From subsequent emails, I think you already got your answer, but just in case...

Yes, if you enabled "Replace swsusp by default" and you already had it set up for getting swsusp to resume. If not, and you're using an initrd/ramfs, you'll need to modify it to echo

Quoted 1 line

/sys/power/suspend2/do_resume after /sys and /proc are mounted but

prior to mounting / and so on.

yeah, went with the default suggested by your patch:

CONFIG_SUSPEND2_REPLACE_SWSUSP=y

and it was pretty easy to set things up. I used "echo disk > /sys/power/state" to trigger it.

Quoted 6 lines

In hindsight it was all pretty straightforward and suspend2 worked beautifully on an UP and on an SMP system i tried. So in exchange for suspend2 folks debugging a bug in CFS here's some suspend2 review feedback ;) Any plans about moving suspend2 to the upstream kernel? It should be pretty easy for it to co-exist with the current swsuspend code.

Well, current uswsusp code can do most of stuff suspend2 can do, with 20% (or so) of kernel code.

"Major feature" that is missing is ability to save 100% of memory if it is all the pagecache. I think that is not that important; we have 200 line patch to do that, but noone was able to verify it is correct.

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#399 lore raw

Re: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

Quoted 3 lines · Pavel Machek

Well, current uswsusp code can do most of stuff suspend2 can do, with 20% (or so) of kernel code.

Btw, this is a totally inane argument.

If the code just moved somewhere else, it's not "less code".

You compare complete subsystems against complete subsystems, OR YOU DON'T COMPARE THEM AT ALL!

This whole notion that "kernel lines of code" is somehow different is a stupid and idiotic _disease_ that is spread by microkernel people and people who have been brainwashed by them.

Code is code, and sometimes it's better in the kernel, sometimes it's better in user space, and you cannot say "we only have 10 lines of kernel code", if that is then combined with a million lines of user space code that actually is the only reason for the 10 lines of code in the first place.

Separation of code often makes things *harder* to understand and debug. A few prime examples of this f*cking idiotic stupid disease of discounting user level code because it somehow "doesn't matter" is:

- the old 16-bit pcmcia layer that did all the "policy" in user space, and only the "device access" in kernel space, and as a result _neither_ actually knew what the hell they were actually doing, and debugging was a nightmare.

We've become a *lot* better off with a device layer that actually knows and understands what it is doing, and having the code in one place, rather than having two broken pieces.

And we became better exactly by doing *more* in the kernel, and havign a *higher* level of abstraction. This is a BIG ISSUE. Abstraction is good, but abstraction is good only if it is at a high enough level to make sense and matter, and give the abstraction level a choice in how to implement the lower layers.

- the old module loader was also split into user/kernel space, and yes, we made the kernel part "larger" by moving some parts into the kernel, but in doing so, we actually made the *combined* code smaller, and a hell of a lot more maintainable.

It also automatically (again, because of a higher level of abstraction) meant that the new module loader infrastructure was not only more maintainable, but could actually *do* more. Suddenly you can do things like check for cryptographic signatures etc, because you know what you're actually doing, as opposed to getting a ready-made "binary blob" that you don't know anything about, that has been pre-linked etc.

So stop blathering about "less kernel code". That's the *least* of any worries. The only thing that matters is the end result, and trying to say that magically only one part counts is just dishonest and stupid.

In general, the kernel should be self-sufficient and *understand* what it is doing. If the kernel cannot understand the bigger picture, nobody can ever maintain the kernel, because the kernel is just a broken piece bobbing around in a mindless churning sea during a thunderstorm. You cannot have purpose, and you cannot improve yourself if you don't actyally understand your lot in life. That's as true of kernels as it is of people.

User-space should set high-level policy, but if the kernel doesn't know what it's all about, the kernel can never do anything smarter and can never *fix* itself. That was the case in both PCMCIA and in kernel module loaders.

I have not a frigging clue whether that is the case in suspend2 vs uswsusp, but I object to this idiotic argument of counting "kernel code". That's simply not a valid argument. It never was.

Linus

#400 lore raw

RE: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

Quoted 3 lines

This whole notion that "kernel lines of code" is somehow different is a stupid and idiotic _disease_ that is spread by microkernel people and people who have been brainwashed by them.

I think a lot of people are tired of this argument, but I am glad you speak up (as you did last year wrt s2ram).

Quoted 1 line

The only thing that matters is the end result

Amen to that. The end result is not just code size, but quality and whether it actually *works reliably*.

Cheers,

Hua

#401 lore raw

Re: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

In reply to Linus Torvalds
Quoted 3 lines · Linus Torvalds

I have not a frigging clue whether that is the case in suspend2 vs uswsusp, but I object to this idiotic argument of counting "kernel code". That's simply not a valid argument. It never was.

the raw linecount appears to be the following:

suspend2-2.2.9.12-for-2.6.21-rc6.patch

   89 files changed, 16452 insertions(+), 69 deletions(-)
 $ suspend-0.5> countlines
 32260

so, while it's probably apples to oranges, uswsusp seems to be larger, while there's at least one feature that it is missing.

also, from the structure of the suspend2 patch it seemed to me that they could peacefully coexist in the kernel without stepping on each other's toes - why not do that? Users will then pick the winner.

Ingo

#402 lore raw

Re: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

Hi!

Quoted 4 lines
Quoted 3 lines

I have not a frigging clue whether that is the case in suspend2 vs uswsusp, but I object to this idiotic argument of counting "kernel code". That's simply not a valid argument. It never was.

Quoted 8 lines

the raw linecount appears to be the following:

suspend2-2.2.9.12-for-2.6.21-rc6.patch

   89 files changed, 16452 insertions(+), 69 deletions(-)
 $ suspend-0.5> countlines
 32260

(I'm getting very different numbers here. Userland part:)

pavel@amd:~/sf/suspend$ wc -l *.c
   125 bootsplash.c
    12 breakit.c
   119 config.c
   136 delme.c
   207 dmidecode.c
    92 encrypt.c
   222 keygen.c
   447 md5.c
   286 radeontool.c
   870 resume.c
   434 s2ram.c
    78 splash.c
    73 splashy_funcs.c
  1481 suspend.c
   117 swap-offset.c
    11 vfork_test.c
   123 vt.c
   413 whitelist.c
   136 whitelist2.c
  5382 total
pavel@amd:~/sf/suspend$ wc -l *.h
    23 bootsplash.h
    26 config.h
    62 encrypt.h
   106 md5.h
  1764 radeon_reg.h
    20 s2ram.h
    26 splash.h
    25 splashy_funcs.h
   217 swsusp.h
    10 vt.h
  2279 total
pavel@amd:~/sf/suspend$
Quoted 2 lines

so, while it's probably apples to oranges, uswsusp seems to be larger, while there's at least one feature that it is missing.

(We are talking "save 100% memory" here).

As I said, that one feature is doable in uswsusp, too. It is 200 lines. It also makes mm <-> swsusp interaction _way_ more complex, and noone was able to review it. It will corrupt memory if we got it wrong.

(Suspend2 has the same problem. It includes that same feature, and noone is able to review it. It has few more problems.).

Quoted 3 lines

also, from the structure of the suspend2 patch it seemed to me that they could peacefully coexist in the kernel without stepping on each other's toes - why not do that? Users will then pick the winner.

We do not want to fragment the testing base, and suspend2 does not really have any interesting features over uswsusp.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#403 lore raw

Re: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

Quoted 7 lines · Pavel Machek
Quoted 2 lines

so, while it's probably apples to oranges, uswsusp seems to be larger, while there's at least one feature that it is missing.

(We are talking "save 100% memory" here).

As I said, that one feature is doable in uswsusp, too. It is 200 lines. It also makes mm <-> swsusp interaction _way_ more complex, and

Sounds like the perfect reason to put that in kernel space.

Ray

#404 lore raw

Re: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

In reply to Pavel Machek
Quoted 2 lines · Pavel Machek

We do not want to fragment the testing base, and suspend2 does not really have any interesting features over uswsusp.

The testing base is already fragmented!

What the current situation means is that you simply never hear from the people who get fed up with suspend but who manage to get suspend2 working.

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#405 lore raw

Re: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

Hi!

Quoted 8 lines
Quoted 2 lines

We do not want to fragment the testing base, and suspend2 does not really have any interesting features over uswsusp.

The testing base is already fragmented!

What the current situation means is that you simply never hear from the people who get fed up with suspend but who manage to get suspend2 working.

Well, and what can I do?

I can wait for suspend2 to slowly disappear on their own. Merging suspend2 would just make testing base _more_ fragmented then it is today.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#406 lore raw

Re: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

In reply to Matt Mackall
Quoted 10 lines · Matt Mackall
Quoted 2 lines · Pavel Machek

We do not want to fragment the testing base, and suspend2 does not really have any interesting features over uswsusp.

The testing base is already fragmented!

What the current situation means is that you simply never hear from the people who get fed up with suspend but who manage to get suspend2 working.

I have to feel that having a *working resume* capability is "any interesting features" enough. What you say about "simply never hear from" is unfortunately true.

Quoted 4 lines · Pavel Machek

It is not Rafael's fault. Actually it is quite hard to work with Nigel, because he implements every feature someone asks for, and wants to merge them all :-( . I don't expect to ever agree with Nigel on anything important, sorry.

The fact that Pavel thinks giving the users what they want is a problem certainly defines the difference between them, the populist "give them what they want" and the elitist "let's them make do with what I think they should have."

I do respect Pavel for all the stuff he has done and is doing, I wish I could have found a nicer way to say that.

Signature · 3 lines
Bill Davidsen <[email protected]>
  "We have more to fear from the bungling of the incompetent than from
the machinations of the wicked."  - from Slashdot
#407 lore raw

Re: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

In reply to Linus Torvalds

Hi!

Quoted 6 lines
Quoted 2 lines

Well, current uswsusp code can do most of stuff suspend2 can do, with 20% (or so) of kernel code.

Btw, this is a totally inane argument.

If the code just moved somewhere else, it's not "less code".

It is not "just moved". It is in userspace, where we can use liblzf / gcrypt / ( and vbetool for s2ram/s2both) as libraries. We have about 7000 LoC of userland code (that is not libraries).

Quoted 2 lines

You compare complete subsystems against complete subsystems, OR YOU DON'T COMPARE THEM AT ALL!

Ok, I do not know how big suspend2 user code is, but kernel uswsusp (4 kLoC) + userland support (7 kLoC) is still smaller than suspend2 kernel code (+ ? kLoC suspend2 userland support).

Quoted 3 lines

This whole notion that "kernel lines of code" is somehow different is a stupid and idiotic _disease_ that is spread by microkernel people and people who have been brainwashed by them.

Yep, sorry about that.

Quoted 3 lines

Separation of code often makes things *harder* to understand and debug. A few prime examples of this f*cking idiotic stupid disease of discounting user level code because it somehow "doesn't matter" is:

I believe uswsusp user/kernel separation is clean enough. Kernel provides "snapshot image" and "resume image". (Thanks go to Rafael for very clean interface).

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#408 lore raw

Re: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

Quoted 6 lines · Pavel Machek
Quoted 2 lines

If the code just moved somewhere else, it's not "less code".

It is not "just moved". It is in userspace, where we can use liblzf / gcrypt / ( and vbetool for s2ram/s2both) as libraries. We have about 7000 LoC of userland code (that is not libraries).

If it's in user land, we also have

- communication difficulties between two parts, and all the *crap* that tends to entail (ie legacy interfaces forever, and upgrading one without the other etc)

- people who work on the kernel part are working "blind" (ie they are at the mercy of whatever userland does, and it's not a "contained" subsystem). This just ends up becoming worse when you then interact with ten different versions of the user-land stuff, thanks to small tweaks by five different vendors, and a hundred random people.

And don't tell me that doesn't happen. Maybe it doesn't happen _now_, because people who use it all get the patches from one place, but the moment we start talking about integration into the standard kernel, that means that the kernel needs to work regardless of whether somebody uses SuSE, RH, Fedora, Ubuntu or cooked his own distro entirely using some development version of the suspend user-space tools.

This is why I don't believe in the whole kernel-line-counting thing. I'm personally 100% convinced that it's better to have ten times as many lines in the kernel, if it means that you can just forget about version skew and bad user-space interfaces etc.

So if you want to enumerate "good" points, you'd damn well also face the _problems_.

This is why there's a lot to be said for

echo mem > /sys/power/state

and being able to follow the path through _one_ object (the kernel) over trying to figure out the interaction between many different parts with different versions.

Quoted 3 lines

I believe uswsusp user/kernel separation is clean enough. Kernel provides "snapshot image" and "resume image". (Thanks go to Rafael for very clean interface).

Now, *that* is the kind of argument that matters.

Quite frankly, if you want to convince me, it's not by "lines of kernel code", but by talking about easy-to-understand interfaces that actuually do one thing and do it well (and by "one thing", I mean "one _whole_ thing"). Because I care a lot less about lines of code than about "maintainable interfaces that people can think about and debug".

I absolutely detest all suspend-to-disk crap. Quite frankly, I hate the whole thing. I think they've _all_ caused problems for the "true" suspend (suspend-to-ram), and the last thing I want to see is three or four different suspend-to-disk implementations. So unlike Ingo, I don't think "let's just integrate them all side-by-side and maintain them and look who wins" is really a good idea.

How many different magic ioctl's does the thing introduce? Is it really just *two* entry-points (and how simple are they, interface-wise), and nothing else?

Linus

#409 lore raw

Re: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

Quoted 3 lines · Linus Torvalds

How many different magic ioctl's does the thing introduce? Is it really just *two* entry-points (and how simple are they, interface-wise), and nothing else?

Aren't you a little late to the party here? The userland version is the one that currently is in the kernel, after all the people who said "doing it in userland is not necessarily a good idea" got happily ignored. Suspend2 which is the continuity of the fully-in-kernel one is the one that has been constantly rejected by Pavel, lately by saying "it should be done in userspace", and hence never merged.

Incidentally, it's 13 ioctls, and it's documented in Documentation/power/userland-swsusp.txt in a hard drive near you. I especially like the "get the available swap space in bytes" one that can only handle 32 bits.

OG.

#410 lore raw

Re: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

In reply to Linus Torvalds
Quoted 10 lines · Linus Torvalds

I absolutely detest all suspend-to-disk crap. Quite frankly, I hate the whole thing. I think they've _all_ caused problems for the "true" suspend (suspend-to-ram), and the last thing I want to see is three or four different suspend-to-disk implementations. So unlike Ingo, I don't think "let's just integrate them all side-by-side and maintain them and look who wins" is really a good idea.

How many different magic ioctl's does the thing introduce? Is it really just *two* entry-points (and how simple are they, interface-wise), and nothing else?

userspace-driven-suspend is already in the kernel, today. So it's not really "two versions side by side doing the same thing", but more of:

A B C + D E F G H

where "ABC" is used by the uswsusp code today, and "ABCDEFGH" is used by suspend2. So any "suspend2 merge" would largely be about adding "DEFGH". (uswsusp of course redoes 'DEFGH' in user-space its own way, and there is the inevitable "+" glue code as well, but it's at least not two parallel versions of the same thing in the kernel, which would be gross.)

My original mail was about the following thing: i tried the suspend2 patch (which just makes "echo disk > /sys/power/state" work as expected, as long as you give the booting up kernel image an idea about where the swap partition we suspended to is, via a single boot option) and that it was pretty straightforward and worked well, and that i think its way of reusing the existing suspend infrastructure and doing the add-ons cleanly while keeping the existing user-hibernate code intact looked viable to me.

I.e. to me it looked like while there are apparent conflicts of personalities suspend2 did not really seem to be a hostile reimplementation of 'A B C', but that it tries to build upon 'A B C' and just has a different technical opinion about whether 'DEFGH' should be in the kernel or outside of it.

Ingo

#411 lore raw

Re: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

Hi!

Quoted 11 lines
Quoted 10 lines

I absolutely detest all suspend-to-disk crap. Quite frankly, I hate the whole thing. I think they've _all_ caused problems for the "true" suspend (suspend-to-ram), and the last thing I want to see is three or four different suspend-to-disk implementations. So unlike Ingo, I don't think "let's just integrate them all side-by-side and maintain them and look who wins" is really a good idea.

How many different magic ioctl's does the thing introduce? Is it really just *two* entry-points (and how simple are they, interface-wise), and nothing else?

Quoted 7 lines

userspace-driven-suspend is already in the kernel, today. So it's not really "two versions side by side doing the same thing", but more of:

A B C + D E F G H

where "ABC" is used by the uswsusp code today, and "ABCDEFGH" is used by suspend2. So any "suspend2 merge" would largely be about adding "DEFGH".

Actually, we have 'D H' in kernel, today. It is called swsusp... (Encryption, swapFile support and Graphical progress are missing from today's kernel.)

Quoted 3 lines

My original mail was about the following thing: i tried the suspend2 patch (which just makes "echo disk > /sys/power/state" work as expected, as long as you give the booting up kernel image an idea about where the

..and it means that 'echo disk > ...' should work w/o suspend2 patch, too. (Just try it). You'll miss compression part, but that provides only small speedup.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#412 lore raw

Re: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

Quoted 11 lines · Pavel Machek
Quoted 7 lines

userspace-driven-suspend is already in the kernel, today. So it's not really "two versions side by side doing the same thing", but more of:

A B C + D E F G H

where "ABC" is used by the uswsusp code today, and "ABCDEFGH" is used by suspend2. So any "suspend2 merge" would largely be about adding "DEFGH".

Actually, we have 'D H' in kernel, today. It is called swsusp... (Encryption, swapFile support and Graphical progress are missing from today's kernel.)

Please stop using FUD.
Graphical progress it's not in the kernel, even with suspend2.

Quoted 8 lines
Quoted 4 lines

My original mail was about the following thing: i tried the suspend2 patch (which just makes "echo disk > /sys/power/state" work as expected, as long as you give the booting up kernel image an idea about where the

..and it means that 'echo disk > ...' should work w/o suspend2 patch, too. (Just try it). You'll miss compression part, but that provides only small speedup.

I beg to differ:
Compressed 904687616 bytes into 418828687 (53 percent compression).

Almost 500mb less to write (did I mention it writes the full image?). Now imagine the time it takes to write that with those pesky 4200rpm laptop hdds.

Signature · 5 lines
Cioby

"Mr Linus, how do you debug the kernel, what tools do you use?"
"Ever heard of prinf ?"
(From an presentation at the "Politehnica" University of Bucharest, 1995)
#413 lore raw

Re: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

Hi!

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

userspace-driven-suspend is already in the kernel, today. So it's not really "two versions side by side doing the same thing", but more of:

A B C + D E F G H

where "ABC" is used by the uswsusp code today, and "ABCDEFGH" is used by suspend2. So any "suspend2 merge" would largely be about adding "DEFGH".

Quoted 6 lines
Quoted 3 lines

Actually, we have 'D H' in kernel, today. It is called swsusp... (Encryption, swapFile support and Graphical progress are missing from today's kernel.)

Please stop using FUD.
Graphical progress it's not in the kernel, even with suspend2.

It was ascii-art, but still 'graphical', last time I checked.

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#414 lore raw

Re: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

Quoted 10 lines · Pavel Machek

Hi!

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

userspace-driven-suspend is already in the kernel, today. So it's not really "two versions side by side doing the same thing", but more of:

A B C + D E F G H

where "ABC" is used by the uswsusp code today, and "ABCDEFGH" is used by suspend2. So any "suspend2 merge" would largely be about adding "DEFGH".

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Actually, we have 'D H' in kernel, today. It is called swsusp... (Encryption, swapFile support and Graphical progress are missing from today's kernel.)

Please stop using FUD.
Graphical progress it's not in the kernel, even with suspend2.

It was ascii-art, but still 'graphical', last time I checked.

That would be suspend2ui_text , an userspace app.
It also works without it.

Signature · 1 line
Cioby
#415 lore raw

Re: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

In reply to Pavel Machek
Quoted 4 lines · Pavel Machek
Quoted 2 lines

Please stop using FUD.
Graphical progress it's not in the kernel, even with suspend2.

It was ascii-art, but still 'graphical', last time I checked.

Suspend2 talks to an userspace client via netlink. While I find the name of the message ("redraw UI") rather appaling, there's nothing wrong in principle that userspace starts the suspend process and the kernel keeps feeding back progress information ("I froze all processes now") so it can display a graphical progress bar.

The real question here is what to do with compression and encryption. However, if you settle for one compression algorithm (such as LZF in the case of suspend2) and use the _existing_ in-kernel crypto API for encryption, suddenly the benefits of userspace suspend are not clear.

As you and Rafael seem to be mostly interested in uswsusp, why don't we replace the old in-kernel implementation with suspend2?

Pekka

#416 lore raw

Re: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

Quoted 12 lines · Pekka Enberg
Quoted 4 lines · Pavel Machek
Quoted 2 lines

Please stop using FUD.
Graphical progress it's not in the kernel, even with suspend2.

It was ascii-art, but still 'graphical', last time I checked.

Suspend2 talks to an userspace client via netlink. While I find the name of the message ("redraw UI") rather appaling, there's nothing wrong in principle that userspace starts the suspend process and the kernel keeps feeding back progress information ("I froze all processes now") so it can display a graphical progress bar.

Quoted 7 lines

The real question here is what to do with compression and encryption. However, if you settle for one compression algorithm (such as LZF in the case of suspend2) and use the _existing_ in-kernel crypto API for encryption, suddenly the benefits of userspace suspend are not clear.

As you and Rafael seem to be mostly interested in uswsusp, why don't we replace the old in-kernel implementation with suspend2?

It has a lot of common code with uswsusp. Practically, the saving of the image is the only part of it that could be removed, but this is simple and _really_ helps with debugging.

In principle, we could add suspend2 as an alternative (in analogy with the I/O schedulers, for example), but I think for this purpose it should be reviewed properly.

There also is a real problem with how it uses the LRU pages. It _seems_ to work, but at least to me it seems to be potentially dangerous.

Greetings,
Rafael

#417 lore raw

Re: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

Quoted 3 lines · Rafael J. Wysocki

In principle, we could add suspend2 as an alternative (in analogy with the I/O schedulers, for example), but I think for this purpose it should be reviewed properly.

Yeah, this makes sense.

Quoted 2 lines · Rafael J. Wysocki

There also is a real problem with how it uses the LRU pages. It _seems_ to work, but at least to me it seems to be potentially dangerous.

I am new to suspend2 so can you please explain what exactly is dangerous about it?

Pekka

#418 lore raw

Re: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

Quoted 6 lines · Pekka Enberg
Quoted 3 lines · Rafael J. Wysocki

In principle, we could add suspend2 as an alternative (in analogy with the I/O schedulers, for example), but I think for this purpose it should be reviewed properly.

Quoted 8 lines

Yeah, this makes sense.

Quoted 2 lines · Rafael J. Wysocki

There also is a real problem with how it uses the LRU pages. It _seems_ to work, but at least to me it seems to be potentially dangerous.

I am new to suspend2 so can you please explain what exactly is dangerous about it?

After freezing tasks, it first saves the contents of the LRU pages, freezes devices and then uses the LRU pages for storing the suspend image (if more memory is needed, it's allocated, but that's irrelevant here). Now, we have no warranty that the LRU pages are not updated after we've saved their contents (first potential problem here).

After the image has been created, we have to unfreeze devices and save the image. Now, we have no warranty that no one will be writing to the LRU pages that we have used to store the image, for whatever reasons known to him, so the image can potentially get corrupted while it's being saved.

In principle, device drivers can do this and there are some kernel threads that also can do this (we don't freeze them, because they're needed for the image saving).

The design is conceptually really really complicated and it makes strong assumptions about the behavior of different subsystems. While these assumptions _may_ be satisfied right now, we'd have to ensure the satisfaction of them in the future if suspend2 were merged.

Greetings,
Rafael

#419 lore raw

Re: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

Hi.

Quoted 27 lines · Rafael J. Wysocki
Quoted 6 lines · Pekka Enberg
Quoted 3 lines · Rafael J. Wysocki

In principle, we could add suspend2 as an alternative (in analogy with the I/O schedulers, for example), but I think for this purpose it should be reviewed properly.

Quoted 8 lines

Yeah, this makes sense.

Quoted 2 lines · Rafael J. Wysocki

There also is a real problem with how it uses the LRU pages. It _seems_ to work, but at least to me it seems to be potentially dangerous.

I am new to suspend2 so can you please explain what exactly is dangerous about it?

After freezing tasks, it first saves the contents of the LRU pages, freezes devices and then uses the LRU pages for storing the suspend image (if more memory is needed, it's allocated, but that's irrelevant here). Now, we have no warranty that the LRU pages are not updated after we've saved their contents (first potential problem here).

After the image has been created, we have to unfreeze devices and save the image. Now, we have no warranty that no one will be writing to the LRU pages that we have used to store the image, for whatever reasons known to him, so the image can potentially get corrupted while it's being saved.

Quoted 8 lines

In principle, device drivers can do this and there are some kernel threads that also can do this (we don't freeze them, because they're needed for the image saving).

The design is conceptually really really complicated and it makes strong assumptions about the behavior of different subsystems. While these assumptions _may_ be satisfied right now, we'd have to ensure the satisfaction of them in the future if suspend2 were merged.

That's a good description of the issue, although I think _may_ and _seems_ are stating things a bit more pessimistically than is necessary.

You see, we need to remember that the pages which are saved separately are LRU pages. Because userspace is frozen, their contents are going to be static. The only possibilities for modifying them come from timer routines, improperly frozen filesystems and device drivers.

We have code to check that the LRU isn't changing, and I've only seen one report of modifications to about 20 LRU pages. I haven't had the time yet to chase down the cause, but hope to do so soon.

The general scheme has been working for four or five years - if there was a fundamental issue, we would have found it by now.

The scheme isn't complicated. The algo for figuring out whether to save the page in an atomic copy just says: Iterate through all LRU pages. For each page, ask: Is this used by the thread suspending, or by userui? No? Save separately. Yes? Save in the atomic copy.... oh, and save everything else that needs to be saved in the atomic copy.

Regards,

Nigel

#420 lore raw

Re: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

Quoted 34 lines · Nigel Cunningham

Hi.

Quoted 31 lines · Rafael J. Wysocki
Quoted 6 lines · Pekka Enberg
Quoted 3 lines · Rafael J. Wysocki

In principle, we could add suspend2 as an alternative (in analogy with the I/O schedulers, for example), but I think for this purpose it should be reviewed properly.

Quoted 8 lines

Yeah, this makes sense.

Quoted 2 lines · Rafael J. Wysocki

There also is a real problem with how it uses the LRU pages. It _seems_ to work, but at least to me it seems to be potentially dangerous.

I am new to suspend2 so can you please explain what exactly is dangerous about it?

After freezing tasks, it first saves the contents of the LRU pages, freezes devices and then uses the LRU pages for storing the suspend image (if more memory is needed, it's allocated, but that's irrelevant here). Now, we have no warranty that the LRU pages are not updated after we've saved their contents (first potential problem here).

After the image has been created, we have to unfreeze devices and save the image. Now, we have no warranty that no one will be writing to the LRU pages that we have used to store the image, for whatever reasons known to him, so the image can potentially get corrupted while it's being saved.

In principle, device drivers can do this and there are some kernel threads that also can do this (we don't freeze them, because they're needed for the image saving).

Quoted 8 lines
Quoted 4 lines

The design is conceptually really really complicated and it makes strong assumptions about the behavior of different subsystems. While these assumptions _may_ be satisfied right now, we'd have to ensure the satisfaction of them in the future if suspend2 were merged.

That's a good description of the issue, although I think _may_ and _seems_ are stating things a bit more pessimistically than is necessary.

I've used them to express my personal concerns.

Quoted 4 lines

You see, we need to remember that the pages which are saved separately are LRU pages. Because userspace is frozen, their contents are going to be static. The only possibilities for modifying them come from timer routines, improperly frozen filesystems and device drivers.

And kernel threads that we don't freeze deliberately. Currently, these are all worker threads, dm-related kernel threads and some others.

Quoted 3 lines

We have code to check that the LRU isn't changing, and I've only seen one report of modifications to about 20 LRU pages. I haven't had the time yet to chase down the cause, but hope to do so soon.

I didn't say that would be common. If it had been, you'd have seen problems with it. To me the problem is the lack of warranty that it won't happen.

Quoted 4 lines

The general scheme has been working for four or five years - if there was a fundamental issue, we would have found it by now.

The scheme isn't complicated.

Conceptually, it is complicated just because you're using the LRU.

Greetings,
Rafael

#421 lore raw

Re: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

Hi.

Quoted 61 lines · Rafael J. Wysocki
Quoted 34 lines · Nigel Cunningham

Hi.

Quoted 31 lines · Rafael J. Wysocki
Quoted 6 lines · Pekka Enberg
Quoted 3 lines · Rafael J. Wysocki

In principle, we could add suspend2 as an alternative (in analogy with the I/O schedulers, for example), but I think for this purpose it should be reviewed properly.

Quoted 8 lines

Yeah, this makes sense.

Quoted 2 lines · Rafael J. Wysocki

There also is a real problem with how it uses the LRU pages. It _seems_ to work, but at least to me it seems to be potentially dangerous.

I am new to suspend2 so can you please explain what exactly is dangerous about it?

After freezing tasks, it first saves the contents of the LRU pages, freezes devices and then uses the LRU pages for storing the suspend image (if more memory is needed, it's allocated, but that's irrelevant here). Now, we have no warranty that the LRU pages are not updated after we've saved their contents (first potential problem here).

After the image has been created, we have to unfreeze devices and save the image. Now, we have no warranty that no one will be writing to the LRU pages that we have used to store the image, for whatever reasons known to him, so the image can potentially get corrupted while it's being saved.

In principle, device drivers can do this and there are some kernel threads that also can do this (we don't freeze them, because they're needed for the image saving).

Quoted 8 lines
Quoted 4 lines

The design is conceptually really really complicated and it makes strong assumptions about the behavior of different subsystems. While these assumptions _may_ be satisfied right now, we'd have to ensure the satisfaction of them in the future if suspend2 were merged.

That's a good description of the issue, although I think _may_ and _seems_ are stating things a bit more pessimistically than is necessary.

I've used them to express my personal concerns.

Quoted 4 lines

You see, we need to remember that the pages which are saved separately are LRU pages. Because userspace is frozen, their contents are going to be static. The only possibilities for modifying them come from timer routines, improperly frozen filesystems and device drivers.

And kernel threads that we don't freeze deliberately. Currently, these are all worker threads, dm-related kernel threads and some others.

Quoted 3 lines

We have code to check that the LRU isn't changing, and I've only seen one report of modifications to about 20 LRU pages. I haven't had the time yet to chase down the cause, but hope to do so soon.

I didn't say that would be common. If it had been, you'd have seen problems with it. To me the problem is the lack of warranty that it won't happen.

Quoted 6 lines
Quoted 4 lines

The general scheme has been working for four or five years - if there was a fundamental issue, we would have found it by now.

The scheme isn't complicated.

Conceptually, it is complicated just because you're using the LRU.

Well, I'm willing to look at other ideas. I actually selected LRU because it was simple. Prior to this, we did have a try at just iterating over the pages of frozen processes, but it didn't yield enough pages to be viable. I wouldn't be surprised if hunting down the cause of these changing pages leads to doing the opposite - starting with LRU pages and then removing all the ones owned by processes. (Am I right in thinking the remainder would be anonymous pages? I must learn more mm inards :>).

Nigel

#422 lore raw

Re: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

Quoted 71 lines · Nigel Cunningham

Hi.

Quoted 61 lines · Rafael J. Wysocki
Quoted 34 lines · Nigel Cunningham

Hi.

Quoted 31 lines · Rafael J. Wysocki
Quoted 6 lines · Pekka Enberg
Quoted 3 lines · Rafael J. Wysocki

In principle, we could add suspend2 as an alternative (in analogy with the I/O schedulers, for example), but I think for this purpose it should be reviewed properly.

Quoted 8 lines

Yeah, this makes sense.

Quoted 2 lines · Rafael J. Wysocki

There also is a real problem with how it uses the LRU pages. It _seems_ to work, but at least to me it seems to be potentially dangerous.

I am new to suspend2 so can you please explain what exactly is dangerous about it?

After freezing tasks, it first saves the contents of the LRU pages, freezes devices and then uses the LRU pages for storing the suspend image (if more memory is needed, it's allocated, but that's irrelevant here). Now, we have no warranty that the LRU pages are not updated after we've saved their contents (first potential problem here).

After the image has been created, we have to unfreeze devices and save the image. Now, we have no warranty that no one will be writing to the LRU pages that we have used to store the image, for whatever reasons known to him, so the image can potentially get corrupted while it's being saved.

In principle, device drivers can do this and there are some kernel threads that also can do this (we don't freeze them, because they're needed for the image saving).

Quoted 8 lines
Quoted 4 lines

The design is conceptually really really complicated and it makes strong assumptions about the behavior of different subsystems. While these assumptions _may_ be satisfied right now, we'd have to ensure the satisfaction of them in the future if suspend2 were merged.

That's a good description of the issue, although I think _may_ and _seems_ are stating things a bit more pessimistically than is necessary.

I've used them to express my personal concerns.

Quoted 4 lines

You see, we need to remember that the pages which are saved separately are LRU pages. Because userspace is frozen, their contents are going to be static. The only possibilities for modifying them come from timer routines, improperly frozen filesystems and device drivers.

And kernel threads that we don't freeze deliberately. Currently, these are all worker threads, dm-related kernel threads and some others.

Quoted 3 lines

We have code to check that the LRU isn't changing, and I've only seen one report of modifications to about 20 LRU pages. I haven't had the time yet to chase down the cause, but hope to do so soon.

I didn't say that would be common. If it had been, you'd have seen problems with it. To me the problem is the lack of warranty that it won't happen.

Quoted 6 lines
Quoted 4 lines

The general scheme has been working for four or five years - if there was a fundamental issue, we would have found it by now.

The scheme isn't complicated.

Conceptually, it is complicated just because you're using the LRU.

Quoted 8 lines

Well, I'm willing to look at other ideas. I actually selected LRU because it was simple. Prior to this, we did have a try at just iterating over the pages of frozen processes, but it didn't yield enough pages to be viable. I wouldn't be surprised if hunting down the cause of these changing pages leads to doing the opposite - starting with LRU pages and then removing all the ones owned by processes. (Am I right in thinking the remainder would be anonymous pages? I must learn more mm inards :>).

I think we can discuss that, and the other things too. I'm open to cooperation. :-)

Greetings,
Rafael

#423 lore raw

Re: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

Hi.

Quoted 81 lines · Rafael J. Wysocki
Quoted 71 lines · Nigel Cunningham

Hi.

Quoted 61 lines · Rafael J. Wysocki
Quoted 34 lines · Nigel Cunningham

Hi.

Quoted 31 lines · Rafael J. Wysocki
Quoted 6 lines · Pekka Enberg
Quoted 3 lines · Rafael J. Wysocki

In principle, we could add suspend2 as an alternative (in analogy with the I/O schedulers, for example), but I think for this purpose it should be reviewed properly.

Quoted 8 lines

Yeah, this makes sense.

Quoted 2 lines · Rafael J. Wysocki

There also is a real problem with how it uses the LRU pages. It _seems_ to work, but at least to me it seems to be potentially dangerous.

I am new to suspend2 so can you please explain what exactly is dangerous about it?

After freezing tasks, it first saves the contents of the LRU pages, freezes devices and then uses the LRU pages for storing the suspend image (if more memory is needed, it's allocated, but that's irrelevant here). Now, we have no warranty that the LRU pages are not updated after we've saved their contents (first potential problem here).

After the image has been created, we have to unfreeze devices and save the image. Now, we have no warranty that no one will be writing to the LRU pages that we have used to store the image, for whatever reasons known to him, so the image can potentially get corrupted while it's being saved.

In principle, device drivers can do this and there are some kernel threads that also can do this (we don't freeze them, because they're needed for the image saving).

Quoted 8 lines
Quoted 4 lines

The design is conceptually really really complicated and it makes strong assumptions about the behavior of different subsystems. While these assumptions _may_ be satisfied right now, we'd have to ensure the satisfaction of them in the future if suspend2 were merged.

That's a good description of the issue, although I think _may_ and _seems_ are stating things a bit more pessimistically than is necessary.

I've used them to express my personal concerns.

Quoted 4 lines

You see, we need to remember that the pages which are saved separately are LRU pages. Because userspace is frozen, their contents are going to be static. The only possibilities for modifying them come from timer routines, improperly frozen filesystems and device drivers.

And kernel threads that we don't freeze deliberately. Currently, these are all worker threads, dm-related kernel threads and some others.

Quoted 3 lines

We have code to check that the LRU isn't changing, and I've only seen one report of modifications to about 20 LRU pages. I haven't had the time yet to chase down the cause, but hope to do so soon.

I didn't say that would be common. If it had been, you'd have seen problems with it. To me the problem is the lack of warranty that it won't happen.

Quoted 6 lines
Quoted 4 lines

The general scheme has been working for four or five years - if there was a fundamental issue, we would have found it by now.

The scheme isn't complicated.

Conceptually, it is complicated just because you're using the LRU.

Quoted 8 lines

Well, I'm willing to look at other ideas. I actually selected LRU because it was simple. Prior to this, we did have a try at just iterating over the pages of frozen processes, but it didn't yield enough pages to be viable. I wouldn't be surprised if hunting down the cause of these changing pages leads to doing the opposite - starting with LRU pages and then removing all the ones owned by processes. (Am I right in thinking the remainder would be anonymous pages? I must learn more mm inards :>).

Quoted 2 lines

I think we can discuss that, and the other things too. I'm open to cooperation. :-)

Great!

Nigel

#424 lore raw

Re: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

In reply to Rafael J. Wysocki
Quoted 6 lines · Rafael J. Wysocki
Quoted 4 lines

The general scheme has been working for four or five years - if there was a fundamental issue, we would have found it by now.

The scheme isn't complicated.

Conceptually, it is complicated just because you're using the LRU.

I know that I've seen many projects that are working on or claim to have suceeded in being able to do live migration of processes from one system to another. has anyone looked at useing any of these mechanisms for snapshoting the user processes for the std situation? if you can do this a process at a time you may be able to avoid the massive blob of a write

instead of what linus was saying

buff = snapshot()
write(buff)

it would be
start_snapshot() /* stops all userspace schedulers except for this process */
foreach(pid) {
buff = snapshotpid(pid)
write(buff)
}

David Lang

#425 lore raw

Re: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

In reply to Pavel Machek

Hi.

Quoted 16 lines · Pavel Machek

Hi!

Quoted 14 lines
Quoted 10 lines

I absolutely detest all suspend-to-disk crap. Quite frankly, I hate the whole thing. I think they've _all_ caused problems for the "true" suspend (suspend-to-ram), and the last thing I want to see is three or four different suspend-to-disk implementations. So unlike Ingo, I don't think "let's just integrate them all side-by-side and maintain them and look who wins" is really a good idea.

How many different magic ioctl's does the thing introduce? Is it really just *two* entry-points (and how simple are they, interface-wise), and nothing else?

userspace-driven-suspend is already in the kernel, today. So it's not really "two versions side by side doing the same thing", but more of:

Quoted 8 lines
Quoted 4 lines

A B C + D E F G H

where "ABC" is used by the uswsusp code today, and "ABCDEFGH" is used by suspend2. So any "suspend2 merge" would largely be about adding "DEFGH".

Actually, we have 'D H' in kernel, today. It is called swsusp... (Encryption, swapFile support and Graphical progress are missing from today's kernel.)

Along with a lot of other things (see my "Reasons to merge Suspend2" email from earlier in the day).

Quoted 7 lines
Quoted 3 lines

My original mail was about the following thing: i tried the suspend2 patch (which just makes "echo disk > /sys/power/state" work as expected, as long as you give the booting up kernel image an idea about where the

..and it means that 'echo disk > ...' should work w/o suspend2 patch, too. (Just try it). You'll miss compression part, but that provides only small speedup.

Please don't spread misinformation to support your case. LZF compression (which is what all Suspend2 users use AFAIK) generally doubles the speed of your cycle.

Nigel

#426 lore raw

Re: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

In reply to Pavel Machek
Quoted 4 lines · Pavel Machek

..and it means that 'echo disk > ...' should work w/o suspend2 patch, too. (Just try it). You'll miss compression part, but that provides only small speedup.

In my experience, the speedup is significant, both in hibernating and in waking up, and since the full image is written to disk, the system wakes up *usable*. It takes forever for a system that wakes up from uswsusp to be usable again, it keeps tripping over page faults for *minutes*.

Fede

#427 lore raw

Re: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

In reply to Pavel Machek
Quoted 1 line · Pavel Machek

You'll miss compression part, but that provides only small speedup.

Not here:

----
fgrep -h Compressed /var/log/rawlog*

Apr 22 13:41:34 vaio kernel:   Compressed 85655552 bytes into 46779248 (45 percent compression).
Apr 22 16:09:13 vaio kernel:   Compressed 1380552704 bytes into 435656971 (68 percent compression).
Apr 22 17:06:11 vaio kernel:   Compressed 1488437248 bytes into 437400026 (70 percent compression).
Apr 22 22:55:41 vaio kernel:   Compressed 1875677184 bytes into 623450953 (66 percent compression).
Apr 23 12:30:33 vaio kernel:   Compressed 1731796992 bytes into 528194347 (69 percent compression).
Apr 23 18:13:32 vaio kernel:   Compressed 1883869184 bytes into 691016832 (63 percent compression).
Apr 24 11:55:07 vaio kernel:   Compressed 1795903488 bytes into 703370960 (60 percent compression).

<snip>
----

-Kenny

Signature · 2 lines
Kenneth R. Crudup  Sr. SW Engineer, Scott County Consulting, Los Angeles
O: 3630 S. Sepulveda Blvd. #138, L.A., CA 90034-6809      (888) 454-8181
#428 lore raw

Re: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

In reply to Linus Torvalds

Hi!

Quoted 7 lines

This is why there's a lot to be said for

echo mem > /sys/power/state

and being able to follow the path through _one_ object (the kernel) over trying to figure out the interaction between many different parts with different versions.

The 'promise' is 'if you can get echo disk > /sys/power/state working, uswsusp will work. too'. IOW it should be ok to debug the in-kernel parts, only.

Even I am running in-kernel swsusp, but my managers were pretty clear they want graphical progress bar hiding all the 'ugly' swsusp messages... and in the end the same uswsusp enables compression, too.

Quoted 3 lines

I absolutely detest all suspend-to-disk crap. Quite frankly, I hate the whole thing. I think they've _all_ caused problems for the "true" suspend (suspend-to-ram), and the last thing I want to see is three or four

Well, it is a bit more complex than that.

suspend-to-disk is a workaround for

'suspend-to-ram eats too much power' (plus some details like being able to replace battery).

suspend-to-ram is a workaround for

'idle machine takes way too much power' (plus some details like don't spin the disk so that machine is safe to carry).

I'm starting to think that we should fix the idle power consumption problem. Cell phones do it right. They pretend to be ready/idle all the time, yet they have _days_ of standby.

OLPC can do something like that, too: it is capable of entering suspend-to-ram with screen on and input devices ready to wake the system up.

And with right network card (and right userland) ... I think normal PCs could enter suspend-to-ram during screensaver, too. When you are about to turn off the screen, machine should enable WOL on any packet, arm RTC wakeup for the next packet, and s2ram happily.

(Obviously we are far away from that on PC.)
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#429 lore raw

Re: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

Quoted 8 lines · Pavel Machek
Quoted 3 lines

I absolutely detest all suspend-to-disk crap. Quite frankly, I hate the whole thing. I think they've _all_ caused problems for the "true" suspend (suspend-to-ram), and the last thing I want to see is three or four

Well, it is a bit more complex than that.

suspend-to-disk is a workaround for

Quoted 7 lines

'suspend-to-ram eats too much power' (plus some details like being able to replace battery).

suspend-to-ram is a workaround for

'idle machine takes way too much power' (plus some details like don't spin the disk so that machine is safe to carry).

I think it depends on who you ask. I personally think that suspend-to- $youchoose is a workaround for the slowness of system startup. I never turn off my laptop, I just suspend it.

(And guess what, it uses APM and suspend is really faster and way more reliable than each kernel implementation I could try).

Xav

#430 lore raw

Re: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

Hi.

Quoted 17 lines · Xavier Bestel
Quoted 8 lines · Pavel Machek
Quoted 3 lines

I absolutely detest all suspend-to-disk crap. Quite frankly, I hate the whole thing. I think they've _all_ caused problems for the "true" suspend (suspend-to-ram), and the last thing I want to see is three or four

Well, it is a bit more complex than that.

suspend-to-disk is a workaround for

Quoted 7 lines

'suspend-to-ram eats too much power' (plus some details like being able to replace battery).

suspend-to-ram is a workaround for

'idle machine takes way too much power' (plus some details like don't spin the disk so that machine is safe to carry).

Quoted 6 lines

I think it depends on who you ask. I personally think that suspend-to- $youchoose is a workaround for the slowness of system startup. I never turn off my laptop, I just suspend it.

(And guess what, it uses APM and suspend is really faster and way more reliable than each kernel implementation I could try).

If you tried Suspend2 and had problems with reliability, please send me logs. I'll do all I can to help. (I have to qualify it a bit, because I'm not able to fix drivers, but if it's a Suspend2 issue, tell me and I'll fix it).

Regards,

Nigel

#431 lore raw

Re: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

Quoted 7 lines · Nigel Cunningham
Quoted 2 lines

(And guess what, it uses APM and suspend is really faster and way more reliable than each kernel implementation I could try).

If you tried Suspend2 and had problems with reliability, please send me logs. I'll do all I can to help. (I have to qualify it a bit, because I'm not able to fix drivers, but if it's a Suspend2 issue, tell me and I'll fix it).

Does suspend2 work with APM ? After much trying, I think now the ACPI implementation of my laptop (a vintage Compaq Armada 1700) is busted, only APM works.

AFAIR the problem with suspend2 was that it didn't poweroff some parts of the laptop (the led of the wifi pcmcia card was on, and the lcd light was on too), but that was last year. Kernel's suspend kind of worked but didn't resume (no reaction on button press). As I tried all this last year, I may have forgotten some things.
Honestly, I like this laptop when it works flawlessly, so I don't see many reasons to try *susp* again. I'll do it when I'm bored, just not today.

Thanks,
Xav

#432 lore raw

Re: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

Hi.

Quoted 4 lines · Xavier Bestel
Quoted 3 lines · Nigel Cunningham
Quoted 2 lines

(And guess what, it uses APM and suspend is really faster and way more reliable than each kernel implementation I could try).

Quoted 8 lines
Quoted 4 lines

If you tried Suspend2 and had problems with reliability, please send me logs. I'll do all I can to help. (I have to qualify it a bit, because I'm not able to fix drivers, but if it's a Suspend2 issue, tell me and I'll fix it).

Does suspend2 work with APM ? After much trying, I think now the ACPI implementation of my laptop (a vintage Compaq Armada 1700) is busted, only APM works.

It should do. If you set the powerdown method to 0, it will use machine_power_off() instead of trying to use acpi, fall back to machine_halt() if that fails and lastly (should not be needed) a while(1) cpu_relax() loop.

Quoted 5 lines

AFAIR the problem with suspend2 was that it didn't poweroff some parts of the laptop (the led of the wifi pcmcia card was on, and the lcd light was on too), but that was last year. Kernel's suspend kind of worked but didn't resume (no reaction on button press). As I tried all this last year, I may have forgotten some things.

The code to poweroff those parts will be dependent on the drivers (assuming I'm making the right calls). If it's something where swsusp works and suspend2 doesn't, it will be because I'm doing something wrong. If they both don't do the right thing, then it's probably the driver.

Quoted 3 lines

Honestly, I like this laptop when it works flawlessly, so I don't see many reasons to try *susp* again. I'll do it when I'm bored, just not today.

Okay :) Just let me know if I can help.

Nigel

#433 lore raw

Re: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

In reply to Xavier Bestel
Quoted 12 lines · Xavier Bestel
Quoted 6 lines · Nigel Cunningham
Quoted 2 lines

(And guess what, it uses APM and suspend is really faster and way more reliable than each kernel implementation I could try).

If you tried Suspend2 and had problems with reliability, please send me logs. I'll do all I can to help. (I have to qualify it a bit, because I'm not able to fix drivers, but if it's a Suspend2 issue, tell me and I'll fix it).

Does suspend2 work with APM ? After much trying, I think now the ACPI implementation of my laptop (a vintage Compaq Armada 1700) is busted, only APM works.

Quoted 9 lines

AFAIR the problem with suspend2 was that it didn't poweroff some parts of the laptop (the led of the wifi pcmcia card was on, and the lcd light was on too), but that was last year. Kernel's suspend kind of worked but didn't resume (no reaction on button press). As I tried all this last year, I may have forgotten some things.
Honestly, I like this laptop when it works flawlessly, so I don't see many reasons to try *susp* again. I'll do it when I'm bored, just not today.

Actually on some old laptops I just use the apm command, with -s (or -S, I forget by now), and that works.

Signature · 3 lines
Bill Davidsen <[email protected]>
  "We have more to fear from the bungling of the incompetent than from
the machinations of the wicked."  - from Slashdot
#434 lore raw

Re: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2:hang in atomic copy)

In reply to Pavel Machek
Quoted 5 lines · Pavel Machek

suspend-to-disk is a workaround for

'suspend-to-ram eats too much power' (plus some details like being able to replace battery).

...and let me add 'suspend-to-disk' is a workaround for when s2ram does not work for a gazillion interacting reasons (ACPI, vga bios, drm/dri, you name it).
I am quite happy with s2ram now on my AMD-based vaio, but it started to work with 2.6.17 kernels (Ubuntu Edgy, really), and the three years before that suspend-to-disk (sometime Pavel's, sometime Nigel's) saved the day (yes, it's quite faster to use suspend-to-disk that doing shutdown, reboot, and re-open all the applications).

So, please do not dismiss suspend-to-disk as "crap". It has its place under the sun.

Romano

--
Romano Giannetti --- [email protected]
Sorry for the following disclaimer, it's attached by our outgoing server and I cannot shut it up.

--
La presente comunicación tiene carácter confidencial y es para el exclusivo uso del destinatario indicado en la misma. Si Ud. no es el destinatario indicado, le informamos que cualquier forma de distribución, reproducción o uso de esta comunicación y/o de la información contenida en la misma están estrictamente prohibidos por la ley. Si Ud. ha recibido esta comunicación por error, por favor, notifíquelo inmediatamente al remitente contestando a este mensaje y proceda a continuación a destruirlo. Gracias por su colaboración.

This communication contains confidential information. It is for the exclusive use of the intended addressee. If you are not the intended addressee, please note that any form of distribution, copying or use of this communication or the information in it is strictly prohibited by law. If you have received this communication in error, please immediately notify the sender by reply e-mail and destroy this message. Thank you for your cooperation.

#435 lore raw

Re: suspend2 merge

Am Mittwoch 25 April 2007 schrieb Romano Giannetti:

Quoted 9 lines · Pavel Machek
Quoted 4 lines

suspend-to-disk is a workaround for

'suspend-to-ram eats too much power' (plus some details like being able to replace battery).

...and let me add 'suspend-to-disk' is a workaround for when s2ram does not work for a gazillion interacting reasons (ACPI, vga bios, drm/dri, you name it).

Hello Romano,

for me not only. I usually do not put the batteries into my laptops if not needed cause I read and experienced that I can extend battery life by that while making sure they are always charged more than 50%. Suspend to RAM thus wouldn't work at all for me.

I use suspend2 since 2.6.14 cause I never managed to get userspace software suspend working on my ThinkPad T23 and T42, not even with standard Debian kernel packages, didn't try the latest ones however, AFAIR my last try was with one 2.6.18 package. And cause its faster and the machine is more responsive after resuming than swsusp that I used upto kernel 2.6.13.

With that 1.5 GB RAM on my T42 suspending to disk with suspend2 takes quite some time and resuming also, but I didn't optimize it and thus it saves out almost everything of that:

martin@shambala:~> free -m
total used free shared buffers cached
Mem: 1518 1219 298 0 0 831
-/+ buffers/cache: 388 1130
Swap: 1908 0 1908

Probably should limit that.

I would like suspend2 getting merged! Its proven technology and just works, while I couldn't get userspace software suspend to work for me. Maybe I made a mistake while setting it up, but I think setting it up at first shouldn't be that complicated than I perceived it to be.

I use suspend2 for our workstations at work, too, and my workstation has a uptime of more than 43 days with more than 17 successful suspend and resume cycles.

Regards,

Signature · 2 lines
Martin 'Helios' Steigerwald - http://www.Lichtvoll.de
GPG: 03B0 0D6C 0040 0710 4AFA  B82F 991B EAAC A599 84C7
#436 lore raw

Re: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

In reply to Pavel Machek
Quoted 22 lines · Pavel Machek

Hi!

Quoted 7 lines

This is why there's a lot to be said for

echo mem > /sys/power/state

and being able to follow the path through _one_ object (the kernel) over trying to figure out the interaction between many different parts with different versions.

The 'promise' is 'if you can get echo disk > /sys/power/state working, uswsusp will work. too'. IOW it should be ok to debug the in-kernel parts, only.

Even I am running in-kernel swsusp, but my managers were pretty clear they want graphical progress bar hiding all the 'ugly' swsusp messages... and in the end the same uswsusp enables compression, too.

Quoted 3 lines

I absolutely detest all suspend-to-disk crap. Quite frankly, I hate the whole thing. I think they've _all_ caused problems for the "true" suspend (suspend-to-ram), and the last thing I want to see is three or four

Quoted 7 lines

Well, it is a bit more complex than that.

suspend-to-disk is a workaround for

'suspend-to-ram eats too much power' (plus some details like being able to replace battery).
...

Why does everyone think suspend-to-disk was a laptop-only thing?

My personal usage of suspend-to-disk is for turning the computer off in the evening and getting the complete FVWM with all programs running, open browser tabs,... back the next morning.

All I need for suspending is:
- echo "disk" > /sys/power/state

All I need for getting a running and usable system back is:
- turn on the power at the socket my computer is connected at
- swapoff -a; swapon -a [1]
- wait a bit until the above commands finished

That's much more convenient than a cold boot.

And it's working with a plain 2.6.16 kernel and zero userspace support.

Quoted 1 line

Pavel

cu
Adrian

[1] required step: working with 1 or 2 GB swapped out is horrible

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 Seed
#437 lore raw

Re: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

Hi!

Quoted 16 lines
Quoted 8 lines

Even I am running in-kernel swsusp, but my managers were pretty clear they want graphical progress bar hiding all the 'ugly' swsusp messages... and in the end the same uswsusp enables compression, too.

Quoted 3 lines

I absolutely detest all suspend-to-disk crap. Quite frankly, I hate the whole thing. I think they've _all_ caused problems for the "true" suspend (suspend-to-ram), and the last thing I want to see is three or four

Quoted 7 lines

Well, it is a bit more complex than that.

suspend-to-disk is a workaround for

'suspend-to-ram eats too much power' (plus some details like being able to replace battery).
...

Quoted 5 lines

Why does everyone think suspend-to-disk was a laptop-only thing?

My personal usage of suspend-to-disk is for turning the computer off in the evening and getting the complete FVWM with all programs running, open browser tabs,... back the next morning.

Ok ok ok, suspend-to-disk has some other uses, too.

But ... you are really using suspend-to-disk as a workaround for "my desktop takes too much power when idle". Imagine pressing "lock screensaver" combination, and your machine going to low power mode (3W?), immediately. (Quiet, too; you can't generate much noise for 3W). In the morning, you'd just press any key, machine would power up, immediately... ok, you'd have to ifconfig eth0 down, so that spurious packets on the local net would wake your machine, with all its fans etc.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#438 lore raw

Re: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

Quoted 26 lines · Pavel Machek

Hi!

Quoted 16 lines
Quoted 8 lines

Even I am running in-kernel swsusp, but my managers were pretty clear they want graphical progress bar hiding all the 'ugly' swsusp messages... and in the end the same uswsusp enables compression, too.

Quoted 3 lines

I absolutely detest all suspend-to-disk crap. Quite frankly, I hate the whole thing. I think they've _all_ caused problems for the "true" suspend (suspend-to-ram), and the last thing I want to see is three or four

Quoted 7 lines

Well, it is a bit more complex than that.

suspend-to-disk is a workaround for

'suspend-to-ram eats too much power' (plus some details like being able to replace battery).
...

Quoted 5 lines

Why does everyone think suspend-to-disk was a laptop-only thing?

My personal usage of suspend-to-disk is for turning the computer off in the evening and getting the complete FVWM with all programs running, open browser tabs,... back the next morning.

Ok ok ok, suspend-to-disk has some other uses, too.

Quoted 8 lines

But ... you are really using suspend-to-disk as a workaround for "my desktop takes too much power when idle". Imagine pressing "lock screensaver" combination, and your machine going to low power mode (3W?), immediately. (Quiet, too; you can't generate much noise for 3W). In the morning, you'd just press any key, machine would power up, immediately... ok, you'd have to ifconfig eth0 down, so that spurious packets on the local net would wake your machine, with all its fans etc.

3W for the complete system? In CPU state S1? [1]
And even 3W would still be a waste of energy.

And what would be the advantage? The socket my computer is connected at is located below my bed so I can turn the power on while still lying in bed (the computer is not reachable from my bed). OK, I could create an external power button for the computer using longer cables connected to the motherboard, but I still haven't understood why this should be better for my use case than suspend-to-disk.

Quoted 1 line

Pavel

cu
Adrian

[1] unless I'm misunderstanding [2], page 9, that's the highest state my processor supports
[2] http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/24309.pdf

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 Seed
#439 lore raw

Re: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

Quoted 2 lines · Adrian Bunk

3W for the complete system? In CPU state S1? [1]

In STR, 3W is quite realistic. The CPU is off, all (or most - up to you) the devices are off, but the motherboard and memory is powered.

Quoted 1 line

And even 3W would still be a waste of energy.

.. but if the alternative is a feature that just isn't worth it, and likely to not only have its own bugs, but cause bugs elsewhere? (And yes, I believe STD is both of those. There's a reason it's called "STD". Go to google and type "STD" and press "I'm feeling lucky". Google is God).

Linus

#440 lore raw

RE: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

Quoted 10 lines

In STR, 3W is quite realistic. The CPU is off, all (or most - up to you) the devices are off, but the motherboard and memory is powered.

Quoted 1 line

And even 3W would still be a waste of energy.

.. but if the alternative is a feature that just isn't worth it, and likely to not only have its own bugs, but cause bugs elsewhere? (And yes,
I believe STD is both of those. There's a reason it's called "STD". Go to google and type "STD" and press "I'm feeling lucky". Google is God).

Linus, the fact that you personally don't use S2D does not mean it's not useful for other people. I've been using solely laptop for six years and until recently (when my commute is now only two miles) I'd always used hibernate when I go to or leave form work. And even now if I take my laptop to somewhere farther away (like on a vacation) I need hibernation.

This is one area where Windows has been doing great for many years, and it's not like Linux has not had a mature implementation for many years either. So don't you think your comments are a bit odd at this point?

Hua

#441 lore raw

Re: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

In reply to Linus Torvalds
Quoted 8 lines · Linus Torvalds
Quoted 2 lines · Adrian Bunk

3W for the complete system? In CPU state S1? [1]

In STR, 3W is quite realistic. The CPU is off, all (or most - up to you) the devices are off, but the motherboard and memory is powered.

As far as I understand it, the CPU isn't off in S1.

Quoted 6 lines
Quoted 1 line

And even 3W would still be a waste of energy.

.. but if the alternative is a feature that just isn't worth it, and likely to not only have its own bugs, but cause bugs elsewhere? (And yes, I believe STD is both of those. There's a reason it's called "STD". Go to google and type "STD" and press "I'm feeling lucky". Google is God).

Is there really no use case for STD?

No worries if power is completely lost.
Some people might boot Windows between suspending and resuming.
...

Quoted 1 line

Linus

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 Seed
#442 lore raw

Re: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

Quoted 7 lines · Adrian Bunk
Quoted 5 lines

.. but if the alternative is a feature that just isn't worth it, and likely to not only have its own bugs, but cause bugs elsewhere? (And yes, I believe STD is both of those. There's a reason it's called "STD". Go to google and type "STD" and press "I'm feeling lucky". Google is God).

Is there really no use case for STD?

People seem to have reading comprehension problems.

The STD code is buggy, and has introduced bugs in STR too, largely thanks to bad design. Some of them have happily gotten fixed. Others did not, and now we have three totally different versions (two of which share some infrastructure), all of which are broken (ie the "suspend2" people will swear up-and-down that swsusp doesn't work for them, but anybody who thinks that "suspend2" will work for everybody is just being a total idiot, and I have a bridge to sell to them).

I'd actually be happier *removing* STD support in the sense it is now:
it's way too closely integrated with STR, even though it has absolutely nothing in common with it. When you STD, you'e actually much closer to a *shutdown* than to STR, yet the STD code continually seems to want to be in the "suspend" path, as shown even by its name.

So my objections to STD have nothing to do with saving state and shutting down. They have everything to do with the fact that it is not - and will never be - a "suspend", and it shouldn't affect suspend.

And that's a *fundamental* problem. If the STD people cannot even realize that they have less to do with "suspend" than to "reboot", how do you ever expect them to get anything to work, and not affect other things negatively?

Yeah, I'm down on it. I'm down on it because every person involved with the whole STD thing seems to have basically zero taste, and a total inability to work with anybody else.

Linus

#443 lore raw

Re: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

Hi!

Quoted 9 lines
Quoted 6 lines
Quoted 4 lines

.. but if the alternative is a feature that just isn't worth it, and likely to not only have its own bugs, but cause bugs elsewhere? (And yes, I believe STD is both of those. There's a reason it's called "STD". Go to google and type "STD" and press "I'm feeling lucky". Google is God).

Is there really no use case for STD?

People seem to have reading comprehension problems.

Quoted 7 lines

The STD code is buggy, and has introduced bugs in STR too, largely thanks to bad design. Some of them have happily gotten fixed. Others did not, and now we have three totally different versions (two of which share some infrastructure), all of which are broken (ie the "suspend2" people will swear up-and-down that swsusp doesn't work for them, but anybody who thinks that "suspend2" will work for everybody is just being a total idiot, and I have a bridge to sell to them).

Well, lets get some credit to STD... it worked before STR, and it allowed debugging basic driver infrastructure.

Quoted 3 lines

So my objections to STD have nothing to do with saving state and shutting down. They have everything to do with the fact that it is not - and will never be - a "suspend", and it shouldn't affect suspend.

STD needs to snapshot system, and then it needs devices to be suspended so that snapshot is consistent.

Quoted 4 lines

And that's a *fundamental* problem. If the STD people cannot even realize that they have less to do with "suspend" than to "reboot", how do you ever expect them to get anything to work, and not affect other things negatively?

STD worked first ;-). Yes, these days it has little to do with "suspend", it was mostly separated to "snapshot" and "restore".

We still keep swsusp in kernel for compatibility (and because it makes debugging very easy).
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#444 lore raw

Re: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

Quoted 8 lines · Pavel Machek

Hi!

Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

.. but if the alternative is a feature that just isn't worth it, and likely to not only have its own bugs, but cause bugs elsewhere? (And yes, I believe STD is both of those. There's a reason it's called "STD". Go to google and type "STD" and press "I'm feeling lucky". Google is God).

Is there really no use case for STD?

[--snip--]

Quoted 6 lines
Quoted 3 lines

So my objections to STD have nothing to do with saving state and shutting down. They have everything to do with the fact that it is not - and will never be - a "suspend", and it shouldn't affect suspend.

STD needs to snapshot system, and then it needs devices to be suspended so that snapshot is consistent.

Not suspended. _Frozen_. In fact don't want any DMA transfers or interrupts to take place when we're creating the image. That's all and that's what we're doing (or rather, trying to do).

So, the "suspend" and "resume" for the functions being called for that are wrong, but then we call them with PMSG_FREEZE. ;-) Still, we could add .freeze() and .thaw() callbacks for hibernation just fine. This wouldn't even be that difficult ...

Greetings,
Rafael

#445 lore raw

Re: suspend2 merge (was Re: [Suspend2-devel] Re: CFS and suspend2: hang in atomic copy)

Hi!

Quoted 12 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

.. but if the alternative is a feature that just isn't worth it, and likely to not only have its own bugs, but cause bugs elsewhere? (And yes, I believe STD is both of those. There's a reason it's called "STD". Go to google and type "STD" and press "I'm feeling lucky". Google is God).

Is there really no use case for STD?

[--snip--]

Quoted 4 lines
Quoted 3 lines

So my objections to STD have nothing to do with saving state and shutting down. They have everything to do with the fact that it is not - and will never be - a "suspend", and it shouldn't affect suspend.

Quoted 6 lines
Quoted 2 lines

STD needs to snapshot system, and then it needs devices to be suspended so that snapshot is consistent.

Not suspended. _Frozen_. In fact don't want any DMA transfers or interrupts to take place when we're creating the image. That's all and that's what we're doing (or rather, trying to do).

Yep, _frozen_. That's the right word.

Quoted 4 lines

So, the "suspend" and "resume" for the functions being called for that are wrong, but then we call them with PMSG_FREEZE. ;-) Still, we could add .freeze() and .thaw() callbacks for hibernation just fine. This wouldn't even be that difficult ...

It would be ugly big patch I'm afraid.

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#446 lore raw

driver power operations (was Re: suspend2 merge)

Quoted 6 lines · Pavel Machek
Quoted 4 lines

So, the "suspend" and "resume" for the functions being called for that are wrong, but then we call them with PMSG_FREEZE. ;-) Still, we could add .freeze() and .thaw() callbacks for hibernation just fine. This wouldn't even be that difficult ...

It would be ugly big patch I'm afraid.

It'd be a lot of code churn, but well worth it. And most of the changes would be trivial too. You need to start looking beyond "this is ugly in the short term" and realise that it's much more maintainable in the long term if driver writers know what they're supposed to do as opposed to just hacking at it until it mostly works or just doing a full device down/up cycle including resetting full driver state.

Look at it now:

 * FREEZE       Quiesce operations so that a consistent image can be saved;
 *              but do NOT otherwise enter a low power device state, and do
 *              NOT emit system wakeup events.
 *
 * PRETHAW      Quiesce as if for FREEZE; additionally, prepare for restoring
 *              the system from a snapshot taken after an earlier FREEZE.
 *              Some drivers will need to reset their hardware state instead
 *              of preserving it, to ensure that it's never mistaken for the
 *              state which that earlier snapshot had set up.

Why is prethaw even necessary? As far as I can tell it's only necessary because resume() can't tell you whether you just want to thaw or need to reset since it doesn't tell you at what point it's invoked.

Having ->freeze(), ->thaw() and ->restart() (can somebody come up with a better name?) that are called at the appropriate places (with freeze/thaw around preparing the image and freeze/restart around restoring would go a long way of clearing up the confusion in all the drivers. Of course, it'd have to be documented that freeze/thaw isn't the only valid combination but that freeze/restart is used too, but that's not hard to do nor hard to understand.

And, incidentally, it could possibly make both suspend and hibernate work much faster too. The comments there talk about "minimally power management aware" drivers which always do the wrong thing for suspend, in that they always reset everything... Of course, some drivers will actually need to do that, but if freeze/suspend and thaw/restart/resume have the same prototypes (probably just int <function>(void)) then drivers can trivially assign the same there.
And hibernate would benefit since a lot of drivers could do a lot less work for freeze/thaw.

Or, if we don't want to have five calls and use 40 bytes (on 64-bit) just for these callback pointers for each device we could just as well have a single callback ->pm(what) and make "what" indicate which one of these five things... But then drivers can't make that code depend on the swsusp configuration which would be doable with five callbacks.

johannes

#447 lore raw

Re: driver power operations (was Re: suspend2 merge)

Quoted 40 lines · Johannes Berg
Quoted 6 lines · Pavel Machek
Quoted 4 lines

So, the "suspend" and "resume" for the functions being called for that are wrong, but then we call them with PMSG_FREEZE. ;-) Still, we could add .freeze() and .thaw() callbacks for hibernation just fine. This wouldn't even be that difficult ...

It would be ugly big patch I'm afraid.

It'd be a lot of code churn, but well worth it. And most of the changes would be trivial too. You need to start looking beyond "this is ugly in the short term" and realise that it's much more maintainable in the long term if driver writers know what they're supposed to do as opposed to just hacking at it until it mostly works or just doing a full device down/up cycle including resetting full driver state.

Look at it now:

 * FREEZE       Quiesce operations so that a consistent image can be saved;
 *              but do NOT otherwise enter a low power device state, and do
 *              NOT emit system wakeup events.
 *
 * PRETHAW      Quiesce as if for FREEZE; additionally, prepare for restoring
 *              the system from a snapshot taken after an earlier FREEZE.
 *              Some drivers will need to reset their hardware state instead
 *              of preserving it, to ensure that it's never mistaken for the
 *              state which that earlier snapshot had set up.

Why is prethaw even necessary? As far as I can tell it's only necessary because resume() can't tell you whether you just want to thaw or need to reset since it doesn't tell you at what point it's invoked.

Having ->freeze(), ->thaw() and ->restart() (can somebody come up with a better name?) that are called at the appropriate places (with freeze/thaw around preparing the image and freeze/restart around restoring would go a long way of clearing up the confusion in all the drivers. Of course, it'd have to be documented that freeze/thaw isn't the only valid combination but that freeze/restart is used too, but that's not hard to do nor hard to understand.

Quoted 9 lines

And, incidentally, it could possibly make both suspend and hibernate work much faster too. The comments there talk about "minimally power management aware" drivers which always do the wrong thing for suspend, in that they always reset everything... Of course, some drivers will actually need to do that, but if freeze/suspend and thaw/restart/resume have the same prototypes (probably just int <function>(void)) then drivers can trivially assign the same there.
And hibernate would benefit since a lot of drivers could do a lot less work for freeze/thaw.

I violently agree with all of the above.

Moreover, for the hibernation we have two special cases that are of no interest for the suspend:
1) drivers compiled as modules and not loaded before we restore the image
2) drivers that need to allocate much memory in .freeze()

Quoted 5 lines

Or, if we don't want to have five calls and use 40 bytes (on 64-bit) just for these callback pointers for each device we could just as well have a single callback ->pm(what) and make "what" indicate which one of these five things... But then drivers can't make that code depend on the swsusp configuration which would be doable with five callbacks.

Five callbacks are fine by me, especially if we can define reasonable defaults for the hibernation (and can we?).

Rafael

#448 lore raw

Re: driver power operations (was Re: suspend2 merge)

Hi!

Quoted 17 lines
Quoted 9 lines

And, incidentally, it could possibly make both suspend and hibernate work much faster too. The comments there talk about "minimally power management aware" drivers which always do the wrong thing for suspend, in that they always reset everything... Of course, some drivers will actually need to do that, but if freeze/suspend and thaw/restart/resume have the same prototypes (probably just int <function>(void)) then drivers can trivially assign the same there.
And hibernate would benefit since a lot of drivers could do a lot less work for freeze/thaw.

I violently agree with all of the above.

Moreover, for the hibernation we have two special cases that are of no interest for the suspend:
1) drivers compiled as modules and not loaded before we restore the image
2) drivers that need to allocate much memory in .freeze()

Quoted 8 lines
Quoted 5 lines

Or, if we don't want to have five calls and use 40 bytes (on 64-bit) just for these callback pointers for each device we could just as well have a single callback ->pm(what) and make "what" indicate which one of these five things... But then drivers can't make that code depend on the swsusp configuration which would be doable with five callbacks.

Five callbacks are fine by me, especially if we can define reasonable defaults for the hibernation (and can we?).

Well, we still can default to suspend(PMSG_FREEZE) for freeze(), and resume() for thaw(). Anything else is just not sane way forward.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#449 lore raw

Re: driver power operations (was Re: suspend2 merge)

In reply to Rafael J. Wysocki

Hi!

Quoted 17 lines
Quoted 9 lines

And, incidentally, it could possibly make both suspend and hibernate work much faster too. The comments there talk about "minimally power management aware" drivers which always do the wrong thing for suspend, in that they always reset everything... Of course, some drivers will actually need to do that, but if freeze/suspend and thaw/restart/resume have the same prototypes (probably just int <function>(void)) then drivers can trivially assign the same there.
And hibernate would benefit since a lot of drivers could do a lot less work for freeze/thaw.

I violently agree with all of the above.

Moreover, for the hibernation we have two special cases that are of no interest for the suspend:
1) drivers compiled as modules and not loaded before we restore the image
2) drivers that need to allocate much memory in .freeze()

Quoted 8 lines
Quoted 5 lines

Or, if we don't want to have five calls and use 40 bytes (on 64-bit) just for these callback pointers for each device we could just as well have a single callback ->pm(what) and make "what" indicate which one of these five things... But then drivers can't make that code depend on the swsusp configuration which would be doable with five callbacks.

Five callbacks are fine by me, especially if we can define reasonable defaults for the hibernation (and can we?).

Well, we still can default to suspend(PMSG_FREEZE) for freeze(), and resume() for thaw(). Anything else is just not sane way forward.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#450 lore raw

Re: driver power operations (was Re: suspend2 merge)

Quoted 5 lines · Pavel Machek
Quoted 2 lines

Five callbacks are fine by me, especially if we can define reasonable defaults for the hibernation (and can we?).

Well, we still can default to suspend(PMSG_FREEZE) for freeze(), and resume() for thaw(). Anything else is just not sane way forward.

I think we should remove the argument to suspend() in the same patch series. Yes, that would mean porting all drivers that currently use it, but that's not actually all that many since most drivers are dumbed-down wrt. power management.

And realistically, resume for thaw makes no sense, nor does suspend for freeze, so we probably want to change those over to suspend/restart and use them. or something.

johannes

#451 lore raw

Re: driver power operations (was Re: suspend2 merge)

Hi!

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

Five callbacks are fine by me, especially if we can define reasonable defaults for the hibernation (and can we?).

Well, we still can default to suspend(PMSG_FREEZE) for freeze(), and resume() for thaw(). Anything else is just not sane way forward.

I think we should remove the argument to suspend() in the same patch series. Yes, that would mean porting all drivers that currently use it,

Well, if you can do it in one patch series, go ahead. But I think such massive change all over kernel will take slightly longer, so I'd prefer to keep the dummy argument for a while (so it still compiles) and fix it slowly.

Of course, it is up to the person doing the series. And yes, such series would be welcome.

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#452 lore raw

Re: driver power operations (was Re: suspend2 merge)

In reply to Pavel Machek
Quoted 5 lines · Pavel Machek
Quoted 2 lines

Five callbacks are fine by me, especially if we can define reasonable defaults for the hibernation (and can we?).

Well, we still can default to suspend(PMSG_FREEZE) for freeze(), and resume() for thaw(). Anything else is just not sane way forward.

I think we should remove the argument to suspend() in the same patch series. Yes, that would mean porting all drivers that currently use it, but that's not actually all that many since most drivers are dumbed-down wrt. power management.

And realistically, resume for thaw makes no sense, nor does suspend for freeze, so we probably want to change those over to suspend/restart and use them. or something.

johannes

#453 lore raw

Re: driver power operations (was Re: suspend2 merge)

In reply to Johannes Berg
Quoted 40 lines · Johannes Berg
Quoted 6 lines · Pavel Machek
Quoted 4 lines

So, the "suspend" and "resume" for the functions being called for that are wrong, but then we call them with PMSG_FREEZE. ;-) Still, we could add .freeze() and .thaw() callbacks for hibernation just fine. This wouldn't even be that difficult ...

It would be ugly big patch I'm afraid.

It'd be a lot of code churn, but well worth it. And most of the changes would be trivial too. You need to start looking beyond "this is ugly in the short term" and realise that it's much more maintainable in the long term if driver writers know what they're supposed to do as opposed to just hacking at it until it mostly works or just doing a full device down/up cycle including resetting full driver state.

Look at it now:

 * FREEZE       Quiesce operations so that a consistent image can be saved;
 *              but do NOT otherwise enter a low power device state, and do
 *              NOT emit system wakeup events.
 *
 * PRETHAW      Quiesce as if for FREEZE; additionally, prepare for restoring
 *              the system from a snapshot taken after an earlier FREEZE.
 *              Some drivers will need to reset their hardware state instead
 *              of preserving it, to ensure that it's never mistaken for the
 *              state which that earlier snapshot had set up.

Why is prethaw even necessary? As far as I can tell it's only necessary because resume() can't tell you whether you just want to thaw or need to reset since it doesn't tell you at what point it's invoked.

Having ->freeze(), ->thaw() and ->restart() (can somebody come up with a better name?) that are called at the appropriate places (with freeze/thaw around preparing the image and freeze/restart around restoring would go a long way of clearing up the confusion in all the drivers. Of course, it'd have to be documented that freeze/thaw isn't the only valid combination but that freeze/restart is used too, but that's not hard to do nor hard to understand.

Quoted 9 lines

And, incidentally, it could possibly make both suspend and hibernate work much faster too. The comments there talk about "minimally power management aware" drivers which always do the wrong thing for suspend, in that they always reset everything... Of course, some drivers will actually need to do that, but if freeze/suspend and thaw/restart/resume have the same prototypes (probably just int <function>(void)) then drivers can trivially assign the same there.
And hibernate would benefit since a lot of drivers could do a lot less work for freeze/thaw.

I violently agree with all of the above.

Moreover, for the hibernation we have two special cases that are of no interest for the suspend:
1) drivers compiled as modules and not loaded before we restore the image
2) drivers that need to allocate much memory in .freeze()

Quoted 5 lines

Or, if we don't want to have five calls and use 40 bytes (on 64-bit) just for these callback pointers for each device we could just as well have a single callback ->pm(what) and make "what" indicate which one of these five things... But then drivers can't make that code depend on the swsusp configuration which would be doable with five callbacks.

Five callbacks are fine by me, especially if we can define reasonable defaults for the hibernation (and can we?).

Rafael

#454 lore raw

Re: [linux-pm] driver power operations (was Re: suspend2 merge)

In reply to Johannes Berg
Quoted 12 lines · Johannes Berg

Look at it now:

 * FREEZE       Quiesce operations so that a consistent image can be saved;
 *              but do NOT otherwise enter a low power device state, and do
 *              NOT emit system wakeup events.
 *
 * PRETHAW      Quiesce as if for FREEZE; additionally, prepare for restoring
 *              the system from a snapshot taken after an earlier FREEZE.
 *              Some drivers will need to reset their hardware state instead
 *              of preserving it, to ensure that it's never mistaken for the
 *              state which that earlier snapshot had set up.
Quoted 3 lines

Why is prethaw even necessary? As far as I can tell it's only necessary because resume() can't tell you whether you just want to thaw or need to reset since it doesn't tell you at what point it's invoked.

I think you're wrong here. It's a little hard to say because the terminology is confusing and not yet standardized.

For the sake of argument, let's call the stages of STD and STR by these names (also noted are the current PSMG values):

Suspend to disk:
"prepare to create snapshot" (= FREEZE)
"continue after snapshot" (= RESUME)

Resume from disk:
"prepare to restore snapshot" (= PRETHAW)
"continue after restore" (= RESUME)

Suspend to RAM:
"suspend" (= SUSPEND)
"resume" (= RESUME)

The real reason for adding PRETHAW was that drivers couldn't distinguish between "continue after restore" and "resume", other than by examining the device's state -- since the PM core doesn't pass any information to the resume() method.

I suppose we could have modified the "prepare to create snapshot" code instead, but doing so would mean that "continue after snapshot" and "continue after restore" would always do the same thing, which is not necessarily a good idea.

Anyway, based on this analysis it seems reasonable to have Six (6) method pointers. Suggested names (in the same order as above):

pre_snaphot()
post_snapshot()
pre_restore()
post_restore()
suspend()
resume()

People apparently assume that pre_snapshot() and pre_restore() would always do the same thing and hence be redundant. I'm not so sure; time will tell. Doing it this way certainly is more clear.

Then there's the question of having early_ and late_ versions of some of these things (i.e., one called with interrupts enabled, the other with interrupts disabled). I don't know to what extent that would be necessary; perhaps the each method call should occur in two phases with the interrupt-enable status changed in between. Then the interrupt-enable setting could be passed as an argument.

Alan Stern

#455 lore raw

Re: driver power operations (was Re: suspend2 merge)

Quoted 11 lines · Alan Stern

For the sake of argument, let's call the stages of STD and STR by these names (also noted are the current PSMG values):

Suspend to disk:
"prepare to create snapshot" (= FREEZE)
"continue after snapshot" (= RESUME)

Resume from disk:
"prepare to restore snapshot" (= PRETHAW)
"continue after restore" (= RESUME)

Quoted 8 lines

Suspend to RAM:
"suspend" (= SUSPEND)
"resume" (= RESUME)

The real reason for adding PRETHAW was that drivers couldn't distinguish between "continue after restore" and "resume", other than by examining the device's state -- since the PM core doesn't pass any information to the resume() method.

That's pretty much what I said about prethaw though, no? Anyway,

Quoted 10 lines

Anyway, based on this analysis it seems reasonable to have Six (6) method pointers. Suggested names (in the same order as above):

pre_snaphot()
post_snapshot()
pre_restore()
post_restore()
suspend()
resume()

Quoted 3 lines

People apparently assume that pre_snapshot() and pre_restore() would always do the same thing and hence be redundant. I'm not so sure; time will tell. Doing it this way certainly is more clear.

Right. I did assume that pre_snapshot and pre_restore would be effectively the same since they both have to quiesce the device and assume not much more. I'm not averse to making it explicit, many drivers that don't care can just assign the same function.

Quoted 6 lines

Then there's the question of having early_ and late_ versions of some of these things (i.e., one called with interrupts enabled, the other with interrupts disabled). I don't know to what extent that would be necessary; perhaps the each method call should occur in two phases with the interrupt-enable status changed in between. Then the interrupt-enable setting could be passed as an argument.

Good point. Though if we go for passing the interrupt-enable setting as an argument then many drivers will have the same
"if (irqs_disabled()) return" code. Hm. I guess passing it isn't even strictly necessary.

johannes

#456 lore raw

Re: [linux-pm] driver power operations (was Re: suspend2 merge)

In reply to Alan Stern
Quoted 11 lines · Alan Stern

For the sake of argument, let's call the stages of STD and STR by these names (also noted are the current PSMG values):

Suspend to disk:
"prepare to create snapshot" (= FREEZE)
"continue after snapshot" (= RESUME)

Resume from disk:
"prepare to restore snapshot" (= PRETHAW)
"continue after restore" (= RESUME)

Quoted 8 lines

Suspend to RAM:
"suspend" (= SUSPEND)
"resume" (= RESUME)

The real reason for adding PRETHAW was that drivers couldn't distinguish between "continue after restore" and "resume", other than by examining the device's state -- since the PM core doesn't pass any information to the resume() method.

That's pretty much what I said about prethaw though, no? Anyway,

Quoted 10 lines

Anyway, based on this analysis it seems reasonable to have Six (6) method pointers. Suggested names (in the same order as above):

pre_snaphot()
post_snapshot()
pre_restore()
post_restore()
suspend()
resume()

Quoted 3 lines

People apparently assume that pre_snapshot() and pre_restore() would always do the same thing and hence be redundant. I'm not so sure; time will tell. Doing it this way certainly is more clear.

Right. I did assume that pre_snapshot and pre_restore would be effectively the same since they both have to quiesce the device and assume not much more. I'm not averse to making it explicit, many drivers that don't care can just assign the same function.

Quoted 6 lines

Then there's the question of having early_ and late_ versions of some of these things (i.e., one called with interrupts enabled, the other with interrupts disabled). I don't know to what extent that would be necessary; perhaps the each method call should occur in two phases with the interrupt-enable status changed in between. Then the interrupt-enable setting could be passed as an argument.

Good point. Though if we go for passing the interrupt-enable setting as an argument then many drivers will have the same
"if (irqs_disabled()) return" code. Hm. I guess passing it isn't even strictly necessary.

johannes

#457 lore raw

Re: [linux-pm] driver power operations (was Re: suspend2 merge)

Quoted 4 lines · Johannes Berg

Good point. Though if we go for passing the interrupt-enable setting as an argument then many drivers will have the same
"if (irqs_disabled()) return" code. Hm. I guess passing it isn't even strictly necessary.

Eh, the point I actually wanted to make is that many drivers don't care for the irqs disabled case and would have to add code to exclude it.

johannes

#458 lore raw

Re: [linux-pm] driver power operations (was Re: suspend2 merge)

Quoted 9 lines · Johannes Berg
Quoted 4 lines · Johannes Berg

Good point. Though if we go for passing the interrupt-enable setting as an argument then many drivers will have the same
"if (irqs_disabled()) return" code. Hm. I guess passing it isn't even strictly necessary.

Eh, the point I actually wanted to make is that many drivers don't care for the irqs disabled case and would have to add code to exclude it.

I think we can use 'stages' and pass them as arguments to the functions.

In that case we can have two callbacks for the hibernation (I'd prefer to say 'hibernation' instead of 'suspend to disk' from now on), one 'quiesce' callback and one 'activate' callback that can be called many times in one snapshot/restore cycle with different arguments, for example:

quiesce(PREPARE) -- that may be needed for drivers that allocate much memory before quiescing devices (if any)
...
quiesce(PRE_SNAPSHOT)
...
quiesce(PRE_SNAPSHOT_IRQ_OFF)
...
activate(POST_SNAPSHOT_IRQ_OFF)
...
activate(POST_SNAPSHOT)
...
activate(FINISH)

etc.

Greetings,
Rafael

#459 lore raw

Re: driver power operations (was Re: suspend2 merge)

Quoted 6 lines · Rafael J. Wysocki

I think we can use 'stages' and pass them as arguments to the functions.

In that case we can have two callbacks for the hibernation (I'd prefer to say 'hibernation' instead of 'suspend to disk' from now on), one 'quiesce' callback and one 'activate' callback that can be called many times in one snapshot/restore cycle with different arguments, for example:

But you're not proposing to add suspend/resume to this interface too, I hope :)

Quoted 4 lines

quiesce(PREPARE) -- that may be needed for drivers that allocate much memory before quiescing devices (if any)
...
quiesce(PRE_SNAPSHOT)

Quoted 8 lines

...
quiesce(PRE_SNAPSHOT_IRQ_OFF)
...
activate(POST_SNAPSHOT_IRQ_OFF)
...
activate(POST_SNAPSHOT)
...
activate(FINISH)

I'm still not sure I like having to switch on the argument for every implementation. Is it really worth it?

johannes

#460 lore raw

Re: [linux-pm] driver power operations (was Re: suspend2 merge)

In reply to Rafael J. Wysocki
Quoted 6 lines · Rafael J. Wysocki

I think we can use 'stages' and pass them as arguments to the functions.

In that case we can have two callbacks for the hibernation (I'd prefer to say 'hibernation' instead of 'suspend to disk' from now on), one 'quiesce' callback and one 'activate' callback that can be called many times in one snapshot/restore cycle with different arguments, for example:

But you're not proposing to add suspend/resume to this interface too, I hope :)

Quoted 4 lines

quiesce(PREPARE) -- that may be needed for drivers that allocate much memory before quiescing devices (if any)
...
quiesce(PRE_SNAPSHOT)

Quoted 8 lines

...
quiesce(PRE_SNAPSHOT_IRQ_OFF)
...
activate(POST_SNAPSHOT_IRQ_OFF)
...
activate(POST_SNAPSHOT)
...
activate(FINISH)

I'm still not sure I like having to switch on the argument for every implementation. Is it really worth it?

johannes

#461 lore raw

Re: [linux-pm] driver power operations (was Re: suspend2 merge)

In reply to Rafael J. Wysocki
Quoted 2 lines · Rafael J. Wysocki

I think we can use 'stages' and pass them as arguments to the functions.

No, no NOOOO!

If you use stages, just describe them in the function name instead.

Quoted 6 lines

quiesce(PREPARE) -- that may be needed for drivers that allocate much memory before quiescing devices (if any)
...
quiesce(PRE_SNAPSHOT)
...
quiesce(PRE_SNAPSHOT_IRQ_OFF)

There is *no* advantage to this (and _lots_ of disadvantages) compared to saying

	dev->snapshot_prepare(dev);
	dev->snapshot_freeze(dev);
	dev->snapshot(dev)

The latter is
- more readable
- MUCH easier for programmers to write readable code for (if-statements and case-statements are *by*definition* more complicated to parse both for humans and for CPU's - static information is good)
- allows for the different stages to have different arguments, and somewhat related to that, to have better static C type checking.

Look here, which one is more readable:

	int some_mixed_function(int arg)
	{
		do_one_thing();
		if (arg == SLEEP)
			do_another_thing();
		else
			do_yet_another_thing();
	}

or

	int do_sleep(void)
	{
		do_one_thing();
		do_another_thing();
	}

	int prepare_to_sleep(void)
	{
		do_one_thing();
		do_yet_another_thing();
	}

and quite frankly, while the second case may take more lines of code, anybody who says that it's not clearer what it does (because it can "self-document" with function names etc) is either lying, or just a really bad programmer. The second case is also likely faster and probably not larger code-size-wise either, since it does static decisions _statically_ (since all callers are realistically going to use a constant argument anyway, and the argument really is static).

Finally, the second case is *much* easier to fix, exactly because it doesn't mix up the cases. You can change the arguments, you can have totally different locking, you don't need things like

	int gfp = (arg == SLEEP) ? GFP_ATOMIC : GFP_KERNEL;

etc, and it's just more logical.

So don't overload a function. That's the *bug* with the current "dev->suspend()" interface already. Don't re-create it. The current one overloads two *totally*different* operations onto one function.

Just don't do it. Not in the suspend part, not *ever*.

Linus

#462 lore raw

Re: [linux-pm] driver power operations (was Re: suspend2 merge)

Quoted 70 lines · Linus Torvalds
Quoted 2 lines · Rafael J. Wysocki

I think we can use 'stages' and pass them as arguments to the functions.

No, no NOOOO!

If you use stages, just describe them in the function name instead.

Quoted 6 lines

quiesce(PREPARE) -- that may be needed for drivers that allocate much memory before quiescing devices (if any)
...
quiesce(PRE_SNAPSHOT)
...
quiesce(PRE_SNAPSHOT_IRQ_OFF)

There is *no* advantage to this (and _lots_ of disadvantages) compared to saying

	dev->snapshot_prepare(dev);
	dev->snapshot_freeze(dev);
	dev->snapshot(dev)

The latter is
- more readable
- MUCH easier for programmers to write readable code for (if-statements and case-statements are *by*definition* more complicated to parse both for humans and for CPU's - static information is good)
- allows for the different stages to have different arguments, and somewhat related to that, to have better static C type checking.

Look here, which one is more readable:

	int some_mixed_function(int arg)
	{
		do_one_thing();
		if (arg == SLEEP)
			do_another_thing();
		else
			do_yet_another_thing();
	}

or

	int do_sleep(void)
	{
		do_one_thing();
		do_another_thing();
	}

	int prepare_to_sleep(void)
	{
		do_one_thing();
		do_yet_another_thing();
	}

and quite frankly, while the second case may take more lines of code, anybody who says that it's not clearer what it does (because it can "self-document" with function names etc) is either lying, or just a really bad programmer. The second case is also likely faster and probably not larger code-size-wise either, since it does static decisions _statically_ (since all callers are realistically going to use a constant argument anyway, and the argument really is static).

Finally, the second case is *much* easier to fix, exactly because it doesn't mix up the cases. You can change the arguments, you can have totally different locking, you don't need things like

	int gfp = (arg == SLEEP) ? GFP_ATOMIC : GFP_KERNEL;
Quoted 7 lines

etc, and it's just more logical.

So don't overload a function. That's the *bug* with the current "dev->suspend()" interface already. Don't re-create it. The current one overloads two *totally*different* operations onto one function.

Just don't do it. Not in the suspend part, not *ever*.

OK, I won't.

Greetings,
Rafael

#463 lore raw

Re: driver power operations (was Re: suspend2 merge)

In reply to Linus Torvalds
Quoted 70 lines · Linus Torvalds
Quoted 2 lines · Rafael J. Wysocki

I think we can use 'stages' and pass them as arguments to the functions.

No, no NOOOO!

If you use stages, just describe them in the function name instead.

Quoted 6 lines

quiesce(PREPARE) -- that may be needed for drivers that allocate much memory before quiescing devices (if any)
...
quiesce(PRE_SNAPSHOT)
...
quiesce(PRE_SNAPSHOT_IRQ_OFF)

There is *no* advantage to this (and _lots_ of disadvantages) compared to saying

	dev->snapshot_prepare(dev);
	dev->snapshot_freeze(dev);
	dev->snapshot(dev)

The latter is
- more readable
- MUCH easier for programmers to write readable code for (if-statements and case-statements are *by*definition* more complicated to parse both for humans and for CPU's - static information is good)
- allows for the different stages to have different arguments, and somewhat related to that, to have better static C type checking.

Look here, which one is more readable:

	int some_mixed_function(int arg)
	{
		do_one_thing();
		if (arg == SLEEP)
			do_another_thing();
		else
			do_yet_another_thing();
	}

or

	int do_sleep(void)
	{
		do_one_thing();
		do_another_thing();
	}

	int prepare_to_sleep(void)
	{
		do_one_thing();
		do_yet_another_thing();
	}

and quite frankly, while the second case may take more lines of code, anybody who says that it's not clearer what it does (because it can "self-document" with function names etc) is either lying, or just a really bad programmer. The second case is also likely faster and probably not larger code-size-wise either, since it does static decisions _statically_ (since all callers are realistically going to use a constant argument anyway, and the argument really is static).

Finally, the second case is *much* easier to fix, exactly because it doesn't mix up the cases. You can change the arguments, you can have totally different locking, you don't need things like

	int gfp = (arg == SLEEP) ? GFP_ATOMIC : GFP_KERNEL;
Quoted 7 lines

etc, and it's just more logical.

So don't overload a function. That's the *bug* with the current "dev->suspend()" interface already. Don't re-create it. The current one overloads two *totally*different* operations onto one function.

Just don't do it. Not in the suspend part, not *ever*.

OK, I won't.

Greetings,
Rafael

#464 lore raw

Re: driver power operations (was Re: suspend2 merge)

In reply to Johannes Berg
Quoted 9 lines · Johannes Berg
Quoted 4 lines · Johannes Berg

Good point. Though if we go for passing the interrupt-enable setting as an argument then many drivers will have the same
"if (irqs_disabled()) return" code. Hm. I guess passing it isn't even strictly necessary.

Eh, the point I actually wanted to make is that many drivers don't care for the irqs disabled case and would have to add code to exclude it.

I think we can use 'stages' and pass them as arguments to the functions.

In that case we can have two callbacks for the hibernation (I'd prefer to say 'hibernation' instead of 'suspend to disk' from now on), one 'quiesce' callback and one 'activate' callback that can be called many times in one snapshot/restore cycle with different arguments, for example:

quiesce(PREPARE) -- that may be needed for drivers that allocate much memory before quiescing devices (if any)
...
quiesce(PRE_SNAPSHOT)
...
quiesce(PRE_SNAPSHOT_IRQ_OFF)
...
activate(POST_SNAPSHOT_IRQ_OFF)
...
activate(POST_SNAPSHOT)
...
activate(FINISH)

etc.

Greetings,
Rafael

#465 lore raw

Re: [linux-pm] driver power operations (was Re: suspend2 merge)

In reply to Johannes Berg
Quoted 3 lines · Johannes Berg

Eh, the point I actually wanted to make is that many drivers don't care for the irqs disabled case and would have to add code to exclude it.

You really *really* want to do a two-phase thing, at least for the case I care about. Whether that snapshotting thing does or not, I could care less.

There's a damn good reason why the kernel uses

	/* phase 1 */
	for_each_dev()
		dev->suspend(dev);

	cli();
	/* phase 2 */
	for_each_dev()
		dev->suspend_late(dev);

(and the reverse case on resume).

The reason is simply that there are two totally different cases: things like disks etc want to spin down and do slow and high-level operations, while things like USB controllers and console devices do *not* want to be suspended early, because if you do, you lose debuggability.

So some things really *really* want to be done when they know that there isn't anything else going on any more, and they want to delay the shutdown to the very end. While other things really *require* that they can send requests that can take time, and cannot run with interrupts disabled.

I actually think that "snapshot" is totally different, exactly because for snapshotting, the slow operations like spinning down disks etc probably don't really even exist, and would always be no-ops. But who knows..

Anyway, I do have a final comment:

DO NOT PASS "STATE FLAGS" TO DRIVERS

(or, even worse, assume that drivers would test "implicit" state by calling the same function under two different states, and then have the drivers test for "are interrupts disabled? Then I need to do something else").

If drivers are possibly going to do two different things, make it two different entry-points. There's absolutely no downsides. It's _clearer_ to the device writer when he gets called two different ways that it's not the same case, and in case a particular device can do the same thing for both cases, he can just set the function pointer to the same entry for both.

Never EVER pass dynamic flags that modify behaviour. It's simply bad programming. A function should do *one* thing, and do it well.

Linus

#466 lore raw

Re: driver power operations (was Re: suspend2 merge)

In reply to Alan Stern
Quoted 56 lines · Alan Stern
Quoted 12 lines · Johannes Berg

Look at it now:

 * FREEZE       Quiesce operations so that a consistent image can be saved;
 *              but do NOT otherwise enter a low power device state, and do
 *              NOT emit system wakeup events.
 *
 * PRETHAW      Quiesce as if for FREEZE; additionally, prepare for restoring
 *              the system from a snapshot taken after an earlier FREEZE.
 *              Some drivers will need to reset their hardware state instead
 *              of preserving it, to ensure that it's never mistaken for the
 *              state which that earlier snapshot had set up.
Quoted 3 lines

Why is prethaw even necessary? As far as I can tell it's only necessary because resume() can't tell you whether you just want to thaw or need to reset since it doesn't tell you at what point it's invoked.

I think you're wrong here. It's a little hard to say because the terminology is confusing and not yet standardized.

For the sake of argument, let's call the stages of STD and STR by these names (also noted are the current PSMG values):

Suspend to disk:
"prepare to create snapshot" (= FREEZE)
"continue after snapshot" (= RESUME)

Resume from disk:
"prepare to restore snapshot" (= PRETHAW)
"continue after restore" (= RESUME)

Suspend to RAM:
"suspend" (= SUSPEND)
"resume" (= RESUME)

The real reason for adding PRETHAW was that drivers couldn't distinguish between "continue after restore" and "resume", other than by examining the device's state -- since the PM core doesn't pass any information to the resume() method.

I suppose we could have modified the "prepare to create snapshot" code instead, but doing so would mean that "continue after snapshot" and "continue after restore" would always do the same thing, which is not necessarily a good idea.

Anyway, based on this analysis it seems reasonable to have Six (6) method pointers. Suggested names (in the same order as above):

pre_snaphot()
post_snapshot()
pre_restore()
post_restore()
suspend()
resume()

Quoted 3 lines

People apparently assume that pre_snapshot() and pre_restore() would always do the same thing and hence be redundant. I'm not so sure; time will tell. Doing it this way certainly is more clear.

How do we differentiate between post_snapshot() and post_restore()? I mean, after the restore we're entering the same code path as after the snapshot, so do we use a global var for this purpose?

Rafael

#467 lore raw

Re: [linux-pm] driver power operations (was Re: suspend2 merge)

In reply to Alan Stern
Quoted 56 lines · Alan Stern
Quoted 12 lines · Johannes Berg

Look at it now:

 * FREEZE       Quiesce operations so that a consistent image can be saved;
 *              but do NOT otherwise enter a low power device state, and do
 *              NOT emit system wakeup events.
 *
 * PRETHAW      Quiesce as if for FREEZE; additionally, prepare for restoring
 *              the system from a snapshot taken after an earlier FREEZE.
 *              Some drivers will need to reset their hardware state instead
 *              of preserving it, to ensure that it's never mistaken for the
 *              state which that earlier snapshot had set up.
Quoted 3 lines

Why is prethaw even necessary? As far as I can tell it's only necessary because resume() can't tell you whether you just want to thaw or need to reset since it doesn't tell you at what point it's invoked.

I think you're wrong here. It's a little hard to say because the terminology is confusing and not yet standardized.

For the sake of argument, let's call the stages of STD and STR by these names (also noted are the current PSMG values):

Suspend to disk:
"prepare to create snapshot" (= FREEZE)
"continue after snapshot" (= RESUME)

Resume from disk:
"prepare to restore snapshot" (= PRETHAW)
"continue after restore" (= RESUME)

Suspend to RAM:
"suspend" (= SUSPEND)
"resume" (= RESUME)

The real reason for adding PRETHAW was that drivers couldn't distinguish between "continue after restore" and "resume", other than by examining the device's state -- since the PM core doesn't pass any information to the resume() method.

I suppose we could have modified the "prepare to create snapshot" code instead, but doing so would mean that "continue after snapshot" and "continue after restore" would always do the same thing, which is not necessarily a good idea.

Anyway, based on this analysis it seems reasonable to have Six (6) method pointers. Suggested names (in the same order as above):

pre_snaphot()
post_snapshot()
pre_restore()
post_restore()
suspend()
resume()

Quoted 3 lines

People apparently assume that pre_snapshot() and pre_restore() would always do the same thing and hence be redundant. I'm not so sure; time will tell. Doing it this way certainly is more clear.

How do we differentiate between post_snapshot() and post_restore()? I mean, after the restore we're entering the same code path as after the snapshot, so do we use a global var for this purpose?

Rafael

#468 lore raw

Re: driver power operations (was Re: suspend2 merge)

Quoted 3 lines · Rafael J. Wysocki

How do we differentiate between post_snapshot() and post_restore()? I mean, after the restore we're entering the same code path as after the snapshot, so do we use a global var for this purpose?

That's pretty easy to do though, we already know at which point we are so we just put an if(...) invoke_post_snapshot() else invoke_post_restore().

johannes

#469 lore raw

Re: [linux-pm] driver power operations (was Re: suspend2 merge)

In reply to Rafael J. Wysocki
Quoted 3 lines · Rafael J. Wysocki

How do we differentiate between post_snapshot() and post_restore()? I mean, after the restore we're entering the same code path as after the snapshot, so do we use a global var for this purpose?

That's pretty easy to do though, we already know at which point we are so we just put an if(...) invoke_post_snapshot() else invoke_post_restore().

johannes

#470 lore raw

Re: driver power operations (was Re: suspend2 merge)

In reply to Johannes Berg
Quoted 11 lines · Johannes Berg
 * FREEZE       Quiesce operations so that a consistent image can be saved;
 *              but do NOT otherwise enter a low power device state, and do
 *              NOT emit system wakeup events.
 *
 * PRETHAW      Quiesce as if for FREEZE; additionally, prepare for restoring
 *              the system from a snapshot taken after an earlier FREEZE.
 *              Some drivers will need to reset their hardware state instead
 *              of preserving it, to ensure that it's never mistaken for the
 *              state which that earlier snapshot had set up.
Quoted 1 line

Why is prethaw even necessary?

Read the patch comments for the patch adding that transition. Briefly, adding that transition to swsusp resume was a significant bugfix for all drivers that rely on controller state to determine how to resume.

(That's mostly drivers that are intelligent about wakeup events... so unless you're working with such drivers, the issue may be unclear.)

Quoted 3 lines

As far as I can tell it's only necessary
because resume() can't tell you whether you just want to thaw or need to reset since it doesn't tell you at what point it's invoked.

More like: because swsusp overloaded the suspend()/resume() code paths to do double duty.

Instead of just putting devices into low power states (just *which* state is another discussion), they evolved into support for swsusp transitions... causing trouble (and sometimes breakage) for non-swsusp models.

Quoted 7 lines

Having ->freeze(), ->thaw() and ->restart() (can somebody come up with a better name?) that are called at the appropriate places (with freeze/thaw around preparing the image and freeze/restart around restoring would go a long way of clearing up the confusion in all the drivers. Of course, it'd have to be documented that freeze/thaw isn't the only valid combination but that freeze/restart is used too, but that's not hard to do nor hard to understand.

I suspect that after snapshot resume restart() should always be used. That shouldn't be hard to understand at all. It'd be sub-optimal in the same cases today's system resume is sub-optimal: devices that were in low power states before system suspend wouldn't be that way after system resume.

Quoted 4 lines

And, incidentally, it could possibly make both suspend and hibernate work much faster too. The comments there talk about "minimally power management aware" drivers which always do the wrong thing for suspend, in that they always reset everything...

That comment was purely about existing practice ... and was mostly about resume() processing, not suspend() paths.

It's an unfortunate reality that most device drivers are stupid in terms of power management, so we need to be clear about just how stupid they're allowed to be without being terminally broken.

Additionally, it would be a Good Thing if changes to clean up the swsusp-related code paths didn't make "real suspend" more painful.

Quoted 6 lines

Of course, some drivers will
actually need to do that, but if freeze/suspend and thaw/restart/resume have the same prototypes (probably just int <function>(void)) then drivers can trivially assign the same there.
And hibernate would benefit since a lot of drivers could do a lot less work for freeze/thaw.

That actually gets into discussions from a while back about wanting to be able to quiesce() devices, as separate from actually putting them into low power states.

- Dave

#471 lore raw

Re: [linux-pm] driver power operations (was Re: suspend2 merge)

In reply to Johannes Berg
Quoted 11 lines · Johannes Berg
 * FREEZE       Quiesce operations so that a consistent image can be saved;
 *              but do NOT otherwise enter a low power device state, and do
 *              NOT emit system wakeup events.
 *
 * PRETHAW      Quiesce as if for FREEZE; additionally, prepare for restoring
 *              the system from a snapshot taken after an earlier FREEZE.
 *              Some drivers will need to reset their hardware state instead
 *              of preserving it, to ensure that it's never mistaken for the
 *              state which that earlier snapshot had set up.
Quoted 1 line

Why is prethaw even necessary?

Read the patch comments for the patch adding that transition. Briefly, adding that transition to swsusp resume was a significant bugfix for all drivers that rely on controller state to determine how to resume.

(That's mostly drivers that are intelligent about wakeup events... so unless you're working with such drivers, the issue may be unclear.)

Quoted 3 lines

As far as I can tell it's only necessary
because resume() can't tell you whether you just want to thaw or need to reset since it doesn't tell you at what point it's invoked.

More like: because swsusp overloaded the suspend()/resume() code paths to do double duty.

Instead of just putting devices into low power states (just *which* state is another discussion), they evolved into support for swsusp transitions... causing trouble (and sometimes breakage) for non-swsusp models.

Quoted 7 lines

Having ->freeze(), ->thaw() and ->restart() (can somebody come up with a better name?) that are called at the appropriate places (with freeze/thaw around preparing the image and freeze/restart around restoring would go a long way of clearing up the confusion in all the drivers. Of course, it'd have to be documented that freeze/thaw isn't the only valid combination but that freeze/restart is used too, but that's not hard to do nor hard to understand.

I suspect that after snapshot resume restart() should always be used. That shouldn't be hard to understand at all. It'd be sub-optimal in the same cases today's system resume is sub-optimal: devices that were in low power states before system suspend wouldn't be that way after system resume.

Quoted 4 lines

And, incidentally, it could possibly make both suspend and hibernate work much faster too. The comments there talk about "minimally power management aware" drivers which always do the wrong thing for suspend, in that they always reset everything...

That comment was purely about existing practice ... and was mostly about resume() processing, not suspend() paths.

It's an unfortunate reality that most device drivers are stupid in terms of power management, so we need to be clear about just how stupid they're allowed to be without being terminally broken.

Additionally, it would be a Good Thing if changes to clean up the swsusp-related code paths didn't make "real suspend" more painful.

Quoted 6 lines

Of course, some drivers will
actually need to do that, but if freeze/suspend and thaw/restart/resume have the same prototypes (probably just int <function>(void)) then drivers can trivially assign the same there.
And hibernate would benefit since a lot of drivers could do a lot less work for freeze/thaw.

That actually gets into discussions from a while back about wanting to be able to quiesce() devices, as separate from actually putting them into low power states.

- Dave

#472 lore raw

Re: [linux-pm] driver power operations (was Re: suspend2 merge)

Quoted 72 lines · David Brownell
Quoted 11 lines · Johannes Berg
 * FREEZE       Quiesce operations so that a consistent image can be saved;
 *              but do NOT otherwise enter a low power device state, and do
 *              NOT emit system wakeup events.
 *
 * PRETHAW      Quiesce as if for FREEZE; additionally, prepare for restoring
 *              the system from a snapshot taken after an earlier FREEZE.
 *              Some drivers will need to reset their hardware state instead
 *              of preserving it, to ensure that it's never mistaken for the
 *              state which that earlier snapshot had set up.
Quoted 1 line

Why is prethaw even necessary?

Read the patch comments for the patch adding that transition. Briefly, adding that transition to swsusp resume was a significant bugfix for all drivers that rely on controller state to determine how to resume.

(That's mostly drivers that are intelligent about wakeup events... so unless you're working with such drivers, the issue may be unclear.)

Quoted 3 lines

As far as I can tell it's only necessary
because resume() can't tell you whether you just want to thaw or need to reset since it doesn't tell you at what point it's invoked.

More like: because swsusp overloaded the suspend()/resume() code paths to do double duty.

Instead of just putting devices into low power states (just *which* state is another discussion), they evolved into support for swsusp transitions... causing trouble (and sometimes breakage) for non-swsusp models.

Quoted 7 lines

Having ->freeze(), ->thaw() and ->restart() (can somebody come up with a better name?) that are called at the appropriate places (with freeze/thaw around preparing the image and freeze/restart around restoring would go a long way of clearing up the confusion in all the drivers. Of course, it'd have to be documented that freeze/thaw isn't the only valid combination but that freeze/restart is used too, but that's not hard to do nor hard to understand.

I suspect that after snapshot resume restart() should always be used. That shouldn't be hard to understand at all. It'd be sub-optimal in the same cases today's system resume is sub-optimal: devices that were in low power states before system suspend wouldn't be that way after system resume.

Quoted 4 lines

And, incidentally, it could possibly make both suspend and hibernate work much faster too. The comments there talk about "minimally power management aware" drivers which always do the wrong thing for suspend, in that they always reset everything...

That comment was purely about existing practice ... and was mostly about resume() processing, not suspend() paths.

It's an unfortunate reality that most device drivers are stupid in terms of power management, so we need to be clear about just how stupid they're allowed to be without being terminally broken.

Additionally, it would be a Good Thing if changes to clean up the swsusp-related code paths didn't make "real suspend" more painful.

Quoted 6 lines

Of course, some drivers will
actually need to do that, but if freeze/suspend and thaw/restart/resume have the same prototypes (probably just int <function>(void)) then drivers can trivially assign the same there.
And hibernate would benefit since a lot of drivers could do a lot less work for freeze/thaw.

Quoted 3 lines

That actually gets into discussions from a while back about wanting to be able to quiesce() devices, as separate from actually putting them into low power states.

Yes, exactly.

Moreover, I think we should separate the current suspend code from the hibernation (aka STD) code paths we're discussing. I mean, we need hibernation-specific equivalents of drivers/base/power/suspend.c etc.

Greetings,
Rafael

#473 lore raw

Re: driver power operations (was Re: suspend2 merge)

In reply to David Brownell
Quoted 72 lines · David Brownell
Quoted 11 lines · Johannes Berg
 * FREEZE       Quiesce operations so that a consistent image can be saved;
 *              but do NOT otherwise enter a low power device state, and do
 *              NOT emit system wakeup events.
 *
 * PRETHAW      Quiesce as if for FREEZE; additionally, prepare for restoring
 *              the system from a snapshot taken after an earlier FREEZE.
 *              Some drivers will need to reset their hardware state instead
 *              of preserving it, to ensure that it's never mistaken for the
 *              state which that earlier snapshot had set up.
Quoted 1 line

Why is prethaw even necessary?

Read the patch comments for the patch adding that transition. Briefly, adding that transition to swsusp resume was a significant bugfix for all drivers that rely on controller state to determine how to resume.

(That's mostly drivers that are intelligent about wakeup events... so unless you're working with such drivers, the issue may be unclear.)

Quoted 3 lines

As far as I can tell it's only necessary
because resume() can't tell you whether you just want to thaw or need to reset since it doesn't tell you at what point it's invoked.

More like: because swsusp overloaded the suspend()/resume() code paths to do double duty.

Instead of just putting devices into low power states (just *which* state is another discussion), they evolved into support for swsusp transitions... causing trouble (and sometimes breakage) for non-swsusp models.

Quoted 7 lines

Having ->freeze(), ->thaw() and ->restart() (can somebody come up with a better name?) that are called at the appropriate places (with freeze/thaw around preparing the image and freeze/restart around restoring would go a long way of clearing up the confusion in all the drivers. Of course, it'd have to be documented that freeze/thaw isn't the only valid combination but that freeze/restart is used too, but that's not hard to do nor hard to understand.

I suspect that after snapshot resume restart() should always be used. That shouldn't be hard to understand at all. It'd be sub-optimal in the same cases today's system resume is sub-optimal: devices that were in low power states before system suspend wouldn't be that way after system resume.

Quoted 4 lines

And, incidentally, it could possibly make both suspend and hibernate work much faster too. The comments there talk about "minimally power management aware" drivers which always do the wrong thing for suspend, in that they always reset everything...

That comment was purely about existing practice ... and was mostly about resume() processing, not suspend() paths.

It's an unfortunate reality that most device drivers are stupid in terms of power management, so we need to be clear about just how stupid they're allowed to be without being terminally broken.

Additionally, it would be a Good Thing if changes to clean up the swsusp-related code paths didn't make "real suspend" more painful.

Quoted 6 lines

Of course, some drivers will
actually need to do that, but if freeze/suspend and thaw/restart/resume have the same prototypes (probably just int <function>(void)) then drivers can trivially assign the same there.
And hibernate would benefit since a lot of drivers could do a lot less work for freeze/thaw.

Quoted 3 lines

That actually gets into discussions from a while back about wanting to be able to quiesce() devices, as separate from actually putting them into low power states.

Yes, exactly.

Moreover, I think we should separate the current suspend code from the hibernation (aka STD) code paths we're discussing. I mean, we need hibernation-specific equivalents of drivers/base/power/suspend.c etc.

Greetings,
Rafael

#474 lore raw

Re: driver power operations (was Re: suspend2 merge)

In reply to Johannes Berg

Hi!

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

So, the "suspend" and "resume" for the functions being called for that are wrong, but then we call them with PMSG_FREEZE. ;-) Still, we could add .freeze() and .thaw() callbacks for hibernation just fine. This wouldn't even be that difficult ...

Quoted 8 lines
Quoted 1 line

It would be ugly big patch I'm afraid.

It'd be a lot of code churn, but well worth it. And most of the changes would be trivial too. You need to start looking beyond "this is ugly in the short term" and realise that it's much more maintainable in the long term if driver writers know what they're supposed to do as opposed to just hacking at it until it mostly works or just doing a full device down/up cycle including resetting full driver state.

I do not disagree with you. It will be ugly big patch, but it is probably worth it, so the patch will be welcome.

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html