Scheduler ( was: Just a second ) ...
A message that is not in the archive (sent off-list or not yet received): [email protected]
[ cc'd back to Linux kernel, in case somebody wants to take a look whether
there is something wrong in the sound drivers, for example ]
Quoted 6 lines · William Lee Irwin III
This is no benchmark. This is my home machine it's taking a bite out of. I'm trying to websurf and play mp3's and read email here. No forkbombs. No databases. No made-up benchmarks. I don't know what it's doing (or trying to do) in there but I'd like the CPU cycles back.
Quoted 9 lines
From a recent
/proc/profiledump on 2.4.17-pre1 (no patches), my top 5 (excludingdefault_idle) are:
--------------------------------------------------------
22420 total 0.0168
4624default_idle96.3333
1280 schedule 0.6202
1130handle_IRQ_event11.7708
929file_read_actor9.6771
843fast_clear_page7.5268
The most likely cause is simply waking up after each sound interrupt: you also have a _lot_ of time handling interrupts. Quite frankly, web surfing and mp3 playing simply shouldn't use any noticeable amounts of CPU.
The point being that I really doubt it's the scheduler proper, it's probably how it is _used_. And I'd suspect your sound driver (or user) conspires to keep scheduling stuff.
For example (and this is _purely_ an example, I don't know if this is your particular case), this sounds like a classic case of "bad buffering". What bad buffering would do is:
- you have a sound buffer that the mp3 player tries to keep full
- your sound buffer is, let's pick a random number, 64 entries of 1024 bytes each.
- the sound card gives an interrupt every time it has emptied a buffer.
- the mp3 player is waiting on "free space"
- we wake up the mp3 player for _every_ sound fragment filled.
Do you see what this leads to? We schedule the mp3 task (which gets a high priority because it tends to run for a really short time, filling just 1 small buffer each time) _every_ time a single buffer empties. Even though we have 63 other full buffers.
The classic fix for these kinds of things is _not_ to make the scheduler faster. Sure, that would help, but that's not really the problem. The _real_ fix is to use water-marks, and make the sound driver wake up the writing process only when (say) half the buffers have emptied.
Now the mp3 player can fill 32 of the buffers at a time, and gets scheduled an order of magnitude less. It doesn't end up waking up every time.
Which sound driver are you using, just in case this _is_ the reason?
Linus
Quoted 3 lines · Linus Torvalds
The most likely cause is simply waking up after each sound interrupt: you also have a _lot_ of time handling interrupts. Quite frankly, web surfing and mp3 playing simply shouldn't use any noticeable amounts of CPU.
It must be noted that wking up a task is going to take two lock operations ( and two unlock ), one in try_to_wakeup() and the other one in schedule(). This double the frequency seen by the lock.
- Davide
Quoted 3 lines · Linus Torvalds
The most likely cause is simply waking up after each sound interrupt: you also have a _lot_ of time handling interrupts. Quite frankly, web surfing and mp3 playing simply shouldn't use any noticeable amounts of CPU.
I think we have a winner:/proc/interrupts
------------------------------------------------
CPU0
0: 17321824 XT-PIC timer 1: 4 XT-PIC keyboard 2: 0 XT-PIC cascade 5: 46490271 XT-PIC soundblaster 9: 400232 XT-PIC usb-ohci, eth0, eth1 11: 939150 XT-PIC aic7xxx, aic7xxx 14: 13 XT-PIC ide0
Approximately 4 times more often than the timer interrupt. That's not nice...
Quoted 1 line · Linus Torvalds
Which sound driver are you using, just in case this _is_ the reason?
SoundBlaster 16
A change of hardware should help verify this.
Cheers,
Bill
Quoted 5 lines · William Lee Irwin III
5: 46490271 XT-PIC soundblaster
Approximately 4 times more often than the timer interrupt. That's not nice...
Yeah.
Well, looking at the issue, the problem is probably not just in the sb
driver: the soundblaster driver shares the output buffer code with a number of other drivers (there's some horrible "dmabuf.c" code in common).
And yes, the dmabuf code will wake up the writer on every single DMA complete interrupt. Considering that you seem to have them at least 400 times a second (and probably more, unless you've literally had sound going since the machine was booted), I think we know why your setup spends time in the scheduler.
Quoted 5 lines · Linus Torvalds
Quoted 1 line
Which sound driver are you using, just in case this _is_ the reason?
SoundBlaster 16
A change of hardware should help verify this.
A number of sound drivers will use the same logic.
You may be able to change this more easily some other way, by using a larger fragment size for example. That's up to the sw that actually feeds the sound stream, so it might be your decoder that selects a small fragment size.
Quite frankly I don't know the sound infrastructure well enough to make any more intelligent suggestions about other decoders or similar to try, at this point I just start blathering.
But yes, I bet you'll also see much less impact of this if you were to switch to more modern hardware.
grep grep grep.. Oh, before you do that, how about changing "min_fragment" in sb_audio.c from 5 to something bigger like 9 or 10?
That
audio_devs[devc->dev]->min_fragment = 5;
literally means that your minimum fragment size seems to be a rather pathetic 32 bytes (which doesn't mean that your sound will be set to that, but it _might_ be). That sounds totally ridiculous, but maybe I've misunderstood the code.
Jeff, you've worked on the sb code at some point - does it really do 32-byte sound fragments? Why? That sounds truly insane if I really parsed that code correctly. That's thousands of separate DMA transfers and interrupts per second..
Raising that min_fragment thing from 5 to 10 would make the minimum DMA buffer go from 32 bytes to 1kB, which is a _lot_ more reasonable (what, at 2*2 bytes per sample and 44kHz would mean that a 1kB DMA buffer empties in less than 1/100th of a second, but at least it should be < 200 irqs/sec rather than >400).
Linus
Quoted 4 lines · Linus Torvalds
Jeff, you've worked on the sb code at some point - does it really do 32-byte sound fragments? Why? That sounds truly insane if I really parsed that code correctly. That's thousands of separate DMA transfers and interrupts per second..
I do not see a hardware minimum fragment size in the HW docs... The default hardware reset frag size is 2048 bytes. So, yes, 32 bytes is pretty small for today's rate.
But... I wonder if the fault lies more with the application setting a too-small fragment size and the driver actually allows it to do so, or, the code following this comment in reorganize_buffers in drivers/sound/audio.c needs to be revisited:
/* Compute the fragment size using the default algorithm */
Remember this code is from ancient times... probably written way before 44 Khz was common at all.
Jeff
Signature · 3 lines
Jeff Garzik | Only so many songs can be sung Building 1024 | with two lips, two lungs, and one tongue. MandrakeSoft | - nomeansno
Quoted 6 lines · Linus Torvalds
Quoted 5 lines · William Lee Irwin III
5: 46490271 XT-PIC soundblaster
Approximately 4 times more often than the timer interrupt. That's not nice...
That's not nearly as much as your typical server system runs in network packets and wakeups of the samba/database/http daemons, though ...
Quoted 3 lines
Well, looking at the issue, the problem is probably not just in the sb
driver: the soundblaster driver shares the output buffer code with a number of other drivers (there's some horrible "dmabuf.c" code in common).
So you fixed it for the sound driver, nice. We still have the issue tha the scheduler can take up lots of time on busy server systems, though.
(though I suspect on those systems it probably spends more time recalculating than selecting processes)
regards,
Rik
Signature · 3 lines
DMCA, SSSCA, W3C? Who cares? http://thefreeworld.net/ http://www.surriel.com/ http://distro.conectiva.com/
Quoted 3 lines
Well, looking at the issue, the problem is probably not just in the sb
driver: the soundblaster driver shares the output buffer code with a number of other drivers (there's some horrible "dmabuf.c" code in common).
The sb driver is fine
Quoted 1 line
A number of sound drivers will use the same logic.
Most hardware does
Quoted 3 lines
Quite frankly I don't know the sound infrastructure well enough to make any more intelligent suggestions about other decoders or similar to try, at this point I just start blathering.
some of the sound stuff uses very short fragments to get accurate audio/video synchronization. Some apps also do it gratuitously when they should be using other API's. Its also used sensibly for things like gnome-meeting where its worth trading CPU for latency because 1K of buffering starts giving you earth<->moon type conversations
Quoted 2 lines
But yes, I bet you'll also see much less impact of this if you were to switch to more modern hardware.
Not really - the app asked for an event every 32 bytes. This is an app not kernel problem.
Quoted 3 lines
at 2*2 bytes per sample and 44kHz would mean that a 1kB DMA buffer empties in less than 1/100th of a second, but at least it should be < 200 irqs/sec rather than >400).
With a few exceptions the applications tend to use 4K or larger DMA chunks anyway. Very few need tiny chunks.
Alan
Quoted 7 lines · Alan Cox
Quoted 4 lines
at 2*2 bytes per sample and 44kHz would mean that a 1kB DMA buffer empties in less than 1/100th of a second, but at least it should be < 200 irqs/sec rather than >400).
With a few exceptions the applications tend to use 4K or larger DMA chunks anyway. Very few need tiny chunks.
Doing another grep seems to imply that none of the other drivers even allow as small chunks as the sb driver does, 32 byte "events" is just ridiculous. At simple 2-channel, 16-bits, CD-quality sound, that's a DMA event every 0.18 msec (5500 times a second, 181 _micro_seconds appart).
I obviously agree that the app shouldn't even ask for small chunks:
whether a mp3 player reacts within 1/10th or 1/1000th of a second of the user asking it to switch tracks, nobody can even tell. So an mp3 player should probably use a big fragment size on the order of 4kB or similar (that still gives max fragment latency of 0.022 seconds, faster than humans can react).
So it sounds like a player sillyness, but I don't think the driver should even allow such waste of resources, considering that no other driver allows it either..
Linus
Quoted 7 lines · Linus Torvalds
Quoted 5 lines · William Lee Irwin III
5: 46490271 XT-PIC soundblaster
Approximately 4 times more often than the timer interrupt. That's not nice...
0: 24867181 XT-PIC timer 5: 9070614 XT-PIC soundblaster
After I bootup I start X and then xmms and then my system plays mp3's almost all the time.
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Which sound driver are you using, just in case this _is_ the reason?
SoundBlaster 16
I have an old ISA SoundBlaster 16
Quoted 5 lines
Raising that
min_fragmentthing from 5 to 10 would make the minimum DMA buffer go from 32 bytes to 1kB, which is a _lot_ more reasonable (what, at 2*2 bytes per sample and 44kHz would mean that a 1kB DMA buffer empties in less than 1/100th of a second, but at least it should be < 200 irqs/sec rather than >400).
After watchning /proc/interrupts with 30 second intervals I see that I only get 43 interrupts/second when playing 16bit 44.1kHz stereo.
And according to vmstat I have 153-158 interrupts/second in total (it's probably the networktraffic that increases it a little above 143).
/Martin
Quoted 3 lines · Martin Josefsson
After watchning
/proc/interruptswith 30 second intervals I see that I only get 43 interrupts/second when playing 16bit 44.1kHz stereo.
That's _exactly_ what you get with a 4kB fragment size.
You have a sane player that asks for a sane fragment size. While whatever William uses seems to ask for a really small one..
Linus
This might be of interest on linux-audio-dev too...
Quoted 41 lines · Linus Torvalds
Quoted 4 lines · William Lee Irwin III
5: 46490271 XT-PIC soundblaster
Approximately 4 times more often than the timer interrupt. That's not nice...
Yeah.
Well, looking at the issue, the problem is probably not just in the sb
driver: the soundblaster driver shares the output buffer code with a number of other drivers (there's some horrible "dmabuf.c" code in common).And yes, the dmabuf code will wake up the writer on every single DMA complete interrupt. Considering that you seem to have them at least 400 times a second (and probably more, unless you've literally had sound going since the machine was booted), I think we know why your setup spends time in the scheduler.
Quoted 5 lines · Linus Torvalds
Quoted 1 line
Which sound driver are you using, just in case this _is_ the reason?
SoundBlaster 16
A change of hardware should help verify this.A number of sound drivers will use the same logic.
You may be able to change this more easily some other way, by using a larger fragment size for example. That's up to the sw that actually feeds the sound stream, so it might be your decoder that selects a small fragment size.
Quite frankly I don't know the sound infrastructure well enough to make any more intelligent suggestions about other decoders or similar to try, at this point I just start blathering.
But yes, I bet you'll also see much less impact of this if you were to switch to more modern hardware.
grep grep grep.. Oh, before you do that, how about changing "
min_fragment" insb_audio.cfrom 5 to something bigger like 9 or 10?
Quoted 8 lines
That
audio_devs[devc->dev]->min_fragment = 5;literally means that your minimum fragment size seems to be a rather pathetic 32 bytes (which doesn't mean that your sound will be set to that, but it _might_ be). That sounds totally ridiculous, but maybe I've misunderstood the code.
I think it really is 32 samples, yes that is little - but too small? It depends on the used sample frequency...
Paul Davis wrote this on linux-audio-dev 2001-12-05
"in doing lots of testing on JACK, i've noticed that although the trident driver now works (there were some patches from jaroslav and myself), in general i still get xruns with the lowest possible latency setting for that card (1.3msec per interrupt, 2.6msec buffer). with the same settings on my hammerfall, i don't get xruns, even with substantial system load."
Quoted 6 lines
Jeff, you've worked on the sb code at some point - does it really do 32-byte sound fragments? Why? That sounds truly insane if I really parsed that code correctly. That's thousands of separate DMA transfers and interrupts per second..
Lets see: we have >1 GHz CPU and interrupts at >1000 Hz
=> 1 Mcycle / interrupt - is that insane?
If the hardware can support it? Why not let it? It is really up to the applications/user to decide...
Quoted 6 lines
Raising that
min_fragmentthing from 5 to 10 would make the minimum DMA buffer go from 32 bytes to 1kB, which is a _lot_ more reasonable (what, at 2*2 bytes per sample and 44kHz would mean that a 1kB DMA buffer empties in less than 1/100th of a second, but at least it should be < 200 irqs/sec rather than >400).
Yes, it is probably more reasonable - but if the soundcard can support it? (I have a vision of lots of linux-audio-dev folks pulling out their new soundcard and replacing it with their since long forgotten SB16...)
/RogerL
Signature · 3 lines
Roger Larsson Skellefteå Sweden
Quoted 3 lines · Roger Larsson
Lets see: we have >1 GHz CPU and interrupts at >1000 Hz
=> 1 Mcycle / interrupt - is that insane?
Ehh.. First off, the CPU may be 1GHz, but the memory subsystem, and the PCI subsystem definitely are _not_. Most PCI cards still run at a (comparatively) leisurely 33MHz, and when we're talking about audio, we're talking about actually having to _access_ that audio device.
Yes. At 33MHz, not at 1GHz.
Also, at 32-byte fragments, the frequency is actually 5.5kHz, not 1kHz. Now, I seriously doubt the mp3-player actually used 32-byte fragments (it probably just asked for something small, and got it), but let's say it asked for something in the kHz range (ie 256-512 byte frags). That does _not_ equate to "1 Mcycle". It equates to 33 _kilocycles_ in PCI-land, and a PCI read will take several cycles.
Quoted 2 lines
If the hardware can support it? Why not let it? It is really up to the applications/user to decide...
Well, this particular user was unhappy with the CPU spending a noticeably amount of time on just web-surfing and mp3-playing.
So clearly the _user_ didn't ask for it.
And I suspect that the app writer just didn't even realize what he did. He may have used another sound card that didn't even allow small fragments.
Linus
My tuppence worth from a real-time embedded perspective:
A shorter time slice and other real-time improvements to the scheduler will certainly improve life to the embedded crowd. Bear in mind that 90% of processors are used for embedded apps. Shorter time slices etc. means smaller buffers, less RAM and lower cost.
I don't know what the current distribution is for Linux regarding embedded vs data processing, but the embedded use of Linux is certainly growing rapidly - we expect to make a million thingummyjigs running Linux next year and there are many other companies doing the same. Within the next few years, I expect embedded use of Linux to overshadow data use by a large margin.
Since embedded processors are 'invisible' and never in the news, I would be very happy if Linus and others will keep us poor boys in mind... --
Herman Oosthuysen
[email protected]
Suite 300, #3016, 5th Ave NE,
Calgary, Alberta, T2A 6K4, Canada
Phone: (403) 569-5688, Fax: (403) 235-3965
----- Original Message ----- >
Quoted 9 lines
Lets see: we have >1 GHz CPU and interrupts at >1000 Hz
=> 1 Mcycle / interrupt - is that insane?If the hardware can support it? Why not let it? It is really up to the applications/user to decide...
Quoted 3 lines
Raising that
min_fragmentthing from 5 to 10 would make the minimum DMA buffer go from 32 bytes to 1kB, which is a _lot_ more reasonable (what, at 2*2 bytes per sample and 44kHz would mean that a 1kB DMA buffer
empties
Quoted 1 line
Quoted 1 line
in less than 1/100th of a second, but at least it should be < 200
irqs/sec
Quoted 9 lines
Quoted 2 lines
rather than >400).
/RogerL
--
Roger Larsson
Skellefteå
Sweden
Quoted 3 lines
audio_devs[devc->dev]->min_fragment = 5;
Generally speaking, you want to be able to specify about a 1ms fragment, speaking as a realtime audio programmer (no offense Victor...). However, 1ms is 128 bytes at 16bit stereo, but only 32 bytes at 8bit mono. Nobody does 8bit mono, but that's probably why it's there. A lot of drivers seem to have 128 byte as minimum fragment size. Even the high end stuff like the RME hammerfall only go down to 64 byte fragment PER CHANNEL, which is the same as 128 bytes for stereo in the SB 16.
Quoted 5 lines
Raising that
min_fragmentthing from 5 to 10 would make the minimum DMA buffer go from 32 bytes to 1kB, which is a _lot_ more reasonable (what, at 2*2 bytes per sample and 44kHz would mean that a 1kB DMA buffer empties in less than 1/100th of a second, but at least it should be < 200 irqs/sec rather than >400).
Note that the ALSA drivers allow the app to set watermarks for wakeup, while allowing flexibility in fragment size and number. You can essentially say, wake me up when there are at least n fragments empty, and put me to sleep if m fragments are full.
David
Signature · 4 lines
/==============================\ | David Mansfield | | [email protected] | \==============================/
Quoted 9 lines · David Mansfield
Quoted 3 lines
audio_devs[devc->dev]->min_fragment = 5;Generally speaking, you want to be able to specify about a 1ms fragment, speaking as a realtime audio programmer (no offense Victor...). However, 1ms is 128 bytes at 16bit stereo, but only 32 bytes at 8bit mono. Nobody does 8bit mono, but that's probably why it's there. A lot of drivers seem to have 128 byte as minimum fragment size.
Good point.
Somebody should really look at "dma_set_fragment", and see whether we can make "min_fragment" be really just a hardware minimum chunk size, but use other heuristics like frequency to cut off the minimum size (ie just do something like
/* We want to limit it to 1024 Hz */ min_bytes = freq*channel*bytes_per_channel >> 10;
Although I'm not sure we _have_ the frequency at that point: somebody might set the fragment size first, and the frequency later.
Maybe the best thing to do is to educate the people who write the sound apps for Linux (somebody was complaining about "esd" triggering this, for example).
Linus
Quoted 3 lines
Maybe the best thing to do is to educate the people who write the sound apps for Linux (somebody was complaining about "esd" triggering this, for example).
esd is a culprit, and artsd to an extent. esd is scheduled to die so artsd is the big one to tidy. Kernel side OSS is dead so its a matter for ALSA
Quoted 1 line
Kernel side OSS is dead
What do you mean with "Kernel side OSS"? Only Hannu's OSS/free drivers? Or all current kernel drivers which support the OSS API, including most (all?) PCI sound drivers which don't use any old OSS/free code?
Gerd
Signature · 1 line
#define ENOCLUE 125 /* userland programmer induced race condition */
Quoted 3 lines · Linus Torvalds
Maybe the best thing to do is to educate the people who write the sound apps for Linux (somebody was complaining about "esd" triggering this, for example).
Yes, esd is an interrupt hog, it seems. When reading this thread, I checked, and sure enough I was getting 190 interrupts/sec on the sound card while not playing any sound. I killed esd (which I don't use anyways), and interrupts went to 0/sec when not playing sound. Still at 190/sec when using mpg123 on my ymfpci (Yamaha YMF744B DS-1S) sound card.
Cheers, Andreas
--
Andreas Dilger
http://sourceforge.net/projects/ext2resize/
http://www-mddsp.enel.ucalgary.ca/People/adilger/
Quoted 7 lines · Andreas Dilger
Yes, esd is an interrupt hog, it seems. When reading this thread, I checked, and sure enough I was getting 190 interrupts/sec on the sound card while not playing any sound. I killed esd (which I don't use anyways), and interrupts went to 0/sec when not playing sound. Still at 190/sec when using mpg123 on my ymfpci (Yamaha YMF744B DS-1S) sound card.
190 interrupts / sec sounds excessive, but not wildly so. The interrupt per se is not going to be a CPU hog unless the sound card does programmed IO to fill the data queues, and while that is not unheard of, I don't think such a card has been made in the last five years.
Obviously getting 190 irq's per second even when not actually _doing_ anything is a total waste of CPU, and is bad form. There may be some reason why esd does it, most probably for good synchronization between sound events and to avoid popping when the sound is shut down (many sound drivers seem to pop a bit on open/close, possibly due to driver bugs, but possibly because some hard-to-avoid-programmatically hardware glitch when powering down the logic.
So waiting a while with the driver active may actually be a reasonable thing to do, although I suspect that after long sequences of silence "esd" should really shut down for a while (and "long" here is probably on the order of seconds, not minutes).
What probably _really_ ends up hurting performance is probably not the interrupt per se (although it is noticeable), but the fact that we wake up and cause a schedule - which often blows any CPU caches, making the _next_ interrupt also be more expensive than it would possibly need to be.
The code for that (in the case of drivers that use the generic "dmabuf.c" infrastructure) seems to be in "finish_output_interrupt()", and I suspect that it could be improved with something like
dmap = adev->dmap_out;
lim = dmap->nbufs;
if (lim < 2) lim = 2;
if (dmap->qlen <= lim/2) {
...
}around the current unconditional wakeups.
Yeah, yeah, untested, stupid example, the idea being that we only wake up if we have at least half the frags free now, instead of waking up for _every_ fragment that free's up.
The above is just as a suggestion for some testing, if somebody actually feels like trying it out. It probably won't be good as-is, but as a starting point..
Linus
Quoted 7 lines · Andreas Dilger
Quoted 4 lines · Linus Torvalds
Maybe the best thing to do is to educate the people who write the sound apps for Linux (somebody was complaining about "esd" triggering this, for example).
Quoted 6 lines
Yes, esd is an interrupt hog, it seems. When reading this thread, I checked, and sure enough I was getting 190 interrupts/sec on the sound card while not playing any sound. I killed esd (which I don't use anyways), and interrupts went to 0/sec when not playing sound. Still at 190/sec when using mpg123 on my ymfpci (Yamaha YMF744B DS-1S) sound card.
Weel, evidently esd and artsd both do this (well, I assume esd does now, it didn't do this in the past). Basically, they both transmit silence over the sound chip when nothing else is going on. So even though you don't hear anything, the same sound output DMA is taking place. That avoids things like nasty pops when you start up the sound hardware for a beep and that sort of thing. It also maintains state where as dropping output entirely could result in things like module auto unloading and then reloading on the next beep, etc. Personally, the interrupt count and overhead annoyed me enough that when I started hacking on the i810 sound driver one of my primary goals was to get overhead and interrupt count down. I think I suceeded quite well. On my current workstation:
Context switches per second not playing any sound: 8300 - 8800
Context switches per second playing an MP3: 9200 - 9900
Interrupts per second from sound device: 86
%CPU used when not playing MP3: 0 - 3% (magicdev is a CPU pig once every 2 seconds) %CPU used when playing MP3s: 0 - 4%
In any case, it might be worth the original poster's time in figuring out just how much of his lost CPU is because of playing sound and how much is actually caused by the windowing system and all the associated bloat that comes with it now a days.
Signature · 3 lines
Doug Ledford <[email protected]> http://people.redhat.com/dledford Please check my web site for aic7xxx updates/answers before e-mailing me about problems
Quoted 8 lines · Doug Ledford
Quoted 6 lines · Andreas Dilger
Yes, esd is an interrupt hog, it seems. When reading this thread, I checked, and sure enough I was getting 190 interrupts/sec on the sound card while not playing any sound. I killed esd (which I don't use anyways), and interrupts went to 0/sec when not playing sound. Still at 190/sec when using mpg123 on my ymfpci (Yamaha YMF744B DS-1S) sound card.
Quoted 6 lines
Weel, evidently esd and artsd both do this (well, I assume esd does now, it didn't do this in the past). Basically, they both transmit silence over the sound chip when nothing else is going on. So even though you don't hear anything, the same sound output DMA is taking place. That avoids things like nasty pops when you start up the sound hardware for a beep and that sort of thing.
Hmm, I _do_ notice a pop when the sound hardware is first initialized at boot time, but not when mpg123 starts/stops (without esd running) so I personally don't get any benefit from "the sound of silence". That said, asside from the 190 interrupts/sec from esd, it doesn't appear to use any measurable CPU time by itself.
Quoted 2 lines
Context switches per second not playing any sound: 8300 - 8800 Context switches per second playing an MP3: 9200 - 9900
Hmm, something seems very strange there. On an idle system, I get about 100 context switches/sec, and about 150/sec when playing sound (up to 400/sec when moving the mouse between windows). 9000 cswitches/sec is _very_ high. This is with a text-only player which has screen output (other than the ID3 info from the currently played song).
Cheers, Andreas
--
Andreas Dilger
http://sourceforge.net/projects/ext2resize/
http://www-mddsp.enel.ucalgary.ca/People/adilger/
Quoted 11 lines · Andreas Dilger
Hmm, I _do_ notice a pop when the sound hardware is first initialized at boot time, but not when mpg123 starts/stops (without esd running) so I personally don't get any benefit from "the sound of silence". That said, asside from the 190 interrupts/sec from esd, it doesn't appear to use any measurable CPU time by itself.
Quoted 3 lines
Context switches per second not playing any sound: 8300 - 8800 Context switches per second playing an MP3: 9200 - 9900
Quoted 5 lines
Hmm, something seems very strange there. On an idle system, I get about 100 context switches/sec, and about 150/sec when playing sound (up to 400/sec when moving the mouse between windows). 9000 cswitches/sec is _very_ high. This is with a text-only player which has screen output (other than the ID3 info from the currently played song).
I haven't taken the time to track down what's causing all the context switches, but on my system they are indeed "normal". I suspect large numbers of them are a result of interactions between gnome, nautilus, X, xmms, esd, and gnome-xmms. However, I did just track down one reason for it. It's not 8300 - 8800, its 830 - 880. There appears to be a bug in the procinfo -n1 mode that results in an extra digit getting tacked onto the end of the context switch line. So, take my original numbers and lop off the last digit from the context switch numbers and that's more like what the machine is actually doing.
Signature · 3 lines
Doug Ledford <[email protected]> http://people.redhat.com/dledford Please check my web site for aic7xxx updates/answers before e-mailing me about problems
Quoted 36 lines · Doug Ledford
Quoted 7 lines · Andreas Dilger
Quoted 4 lines · Linus Torvalds
Maybe the best thing to do is to educate the people who write the sound apps for Linux (somebody was complaining about "esd" triggering this, for example).
Quoted 6 lines
Yes, esd is an interrupt hog, it seems. When reading this thread, I checked, and sure enough I was getting 190 interrupts/sec on the sound card while not playing any sound. I killed esd (which I don't use anyways), and interrupts went to 0/sec when not playing sound. Still at 190/sec when using mpg123 on my ymfpci (Yamaha YMF744B DS-1S) sound card.
Weel, evidently esd and artsd both do this (well, I assume esd does now, it didn't do this in the past). Basically, they both transmit silence over the sound chip when nothing else is going on. So even though you don't hear anything, the same sound output DMA is taking place. That avoids things like nasty pops when you start up the sound hardware for a beep and that sort of thing. It also maintains state where as dropping output entirely could result in things like module auto unloading and then reloading on the next beep, etc. Personally, the interrupt count and overhead annoyed me enough that when I started hacking on the i810 sound driver one of my primary goals was to get overhead and interrupt count down. I think I suceeded quite well. On my current workstation:
Context switches per second not playing any sound: 8300 - 8800 Context switches per second playing an MP3: 9200 - 9900 Interrupts per second from sound device: 86
%CPU used when not playing MP3: 0 - 3% (magicdev is a CPU pig once every 2 seconds)
%CPU used when playing MP3s: 0 - 4%
Quoted 5 lines
In any case, it might be worth the original poster's time in figuring out just how much of his lost CPU is because of playing sound and how much is actually caused by the windowing system and all the associated bloat that comes with it now a days.
Do you really think 8000 context switches are sane?
pippin:/var/log # vmstat 1
procs memory swap io system cpu
r b w swpd free buff cache si so bi bo in cs us sy id 2 0 0 100728 4424 121572 27800 0 1 6 6 61 77 98 2 0 2 0 0 100728 5448 121572 27800 0 0 0 68 112 811 93 7 0 2 0 0 100728 5448 121572 27800 0 0 0 0 101 776 95 5 0 3 0 0 100728 4928 121572 27800 0 0 0 0 101 794 92 8 0
having a load ~2.1 (2 seti@home)
Quoted 4 lines · Doug Ledford
Weel, evidently esd and artsd both do this (well, I assume esd does now, it didn't do this in the past). Basically, they both transmit silence over the sound chip when nothing else is going on. So even though you don't hear anything, the same sound output DMA is taking place.
Uuurgh. :-(
Quoted 2 lines
That avoids things
like nasty pops when you start up the sound hardware for a beep and that
Yuk, bad hardware. Pops when you start or stop writing? You don't even have to turn the volume off or something to get a pop? Toss it.
Quoted 3 lines
sort of thing. It also maintains state where as dropping output entirely could result in things like module auto unloading and then reloading on the next beep, etc.
Much better solved by having the device open, but not writing anything. Open devices don't unload.
Helge Hafting
Quoted 4 lines · Doug Ledford
Weel, evidently esd and artsd both do this (well, I assume esd does now, it didn't do this in the past). Basically, they both transmit silence over the sound chip when nothing else is going on. So even though you don't hear anything, the same sound output DMA is taking place. That avoids
THAT explains it.
My Dell Inspiron 3500 laptop's built-in sound (NeoMagic MagicMedia 256 AV, uses ad1848 module) works fine when I first boot the sucker, but looses its marbles after an APM suspend and stops receiving interrupts. (Extensive poking around with setpci has so far failed to get it working again, but on a shutdown and restart the bios sets it up fine. Not a clue what's up there. The bios and module agree it's using IRQ 7, but lspci insists it's IRQ 11, both before and after apm suspend. Boggle.)
I was confused for a while about how exactly it was failing because KDE and mpg123 from the command line fail in different ways. mpg123 will play the same half-second clip in a loop (ahah! no interrupt!), but sound in kde just vanishes and I get silence and hung apps whenever I try to launch anything.
The clue is that it doesn't always fail when I suspend it without having X up. Translation: maybe the sound card's getting hosed by being open and in use on APM shutdown!
Hmmm... I should poke at this over the weekend...
(Nope, not a new problem. My laptop's sound has been like this since at least 2.4.4, which I think was the first version I installed on the box. But it's still annoying, I can go weeks without a true reboot 'cause I have a zillion konqueror windows and such open. I have to clear my desktop to get sound working again for a few hours. Obnoxious...)
Rob
Quoted 9 lines · Linus Torvalds
Well, looking at the issue, the problem is probably not just in the sb
driver: the soundblaster driver shares the output buffer code with a number of other drivers (there's some horrible "dmabuf.c" code in common). And yes, the dmabuf code will wake up the writer on every single DMA complete interrupt. Considering that you seem to have them at least 400 times a second (and probably more, unless you've literally had sound going since the machine was booted), I think we know why your setup spends time in the scheduler.
A number of sound drivers will use the same logic.
I've chucked the sb32 and plugged in the emu10k1 I had been planning to install for a while, to good effect. It's not an ISA sb16, but it apparently uses the same driver.
I'm getting an overall 1% reduction in system load, and the following "top 5" profile:
53374 total 0.0400
11430 default_idle 238.1250
8820 handle_IRQ_event 91.8750
2186 do_softirq 10.5096
1984 schedule 1.2525
1612 number 1.4816
1473 __generic_copy_to_user 18.4125
Oddly, I'm getting even more interrupts than I saw with the sb32...
0: 2752924 XT-PIC timer 9: 14223905 XT-PIC EMU10K1, eth1
(eth1 generates orders of magnitude fewer interrupts than the timer)
Quoted 7 lines · Linus Torvalds
You may be able to change this more easily some other way, by using a larger fragment size for example. That's up to the sw that actually feeds the sound stream, so it might be your decoder that selects a small fragment size.
Quite frankly I don't know the sound infrastructure well enough to make any more intelligent suggestions about other decoders or similar to try, at this point I just start blathering.
Already more insight into the problem I was experiencing than I had before, and I must confess to those such as myself this lead certainly seems "plucked out of the air". Good work! =)
Quoted 2 lines · Linus Torvalds
But yes, I bet you'll also see much less impact of this if you were to switch to more modern hardware.
I hear from elsewhere the emu10k1 has a bad reputation as source of excessive interrupts. Looks like I bought the wrong sound card(s). Maybe I should go shopping. =)
Thanks a bunch!
Bill
Quoted 17 lines · William Lee Irwin III
Quoted 3 lines · Linus Torvalds
The most likely cause is simply waking up after each sound interrupt: you also have a _lot_ of time handling interrupts. Quite frankly, web surfing and mp3 playing simply shouldn't use any noticeable amounts of CPU.
I think we have a winner:
/proc/interrupts
------------------------------------------------
CPU00: 17321824 XT-PIC timer 1: 4 XT-PIC keyboard 2: 0 XT-PIC cascade 5: 46490271 XT-PIC soundblaster 9: 400232 XT-PIC usb-ohci, eth0, eth1 11: 939150 XT-PIC aic7xxx, aic7xxx 14: 13 XT-PIC ide0
Quoted 2 lines
Approximately 4 times more often than the timer interrupt. That's not nice...
FWIW, I have an ES1371 based sound card, and mpg123 drives it at 172 interrupts/sec (calculated in procinfo). But that _is_ only when playing. And (my slightly hacked) timidity drives my card w/ only 23(@48kHz sample rate; 21 @ 44.1kHz) interrupts/sec
Is this 172 figure right? (Not through esd either. i almost always turn it off, and sp recompiled mpg123 to use the std OSS driver)
Quoted 15 lines · Linus Torvalds
Quoted 1 line
Which sound driver are you using, just in case this _is_ the reason?
SoundBlaster 16
A change of hardware should help verify this.Cheers,
Bill
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/