Assorted Project 4 Notes
P4 this semester
How it all fits together
P4 and the real world
"What's Project 4 this semester?"
A small extension to your Project 3 kernel...
Sound Blaster 16 driver
Driver and syscall interface
Shouldn't be too difficult concurrencywise...
...but the hardware...
About 2347845923854 clones
advertised being "Sound Blaster Compatible"
Emulated by everybody, too
Saves you the hassle of learning about PCI
Designed to be programmed in assembly
Overview of the SB16
Command interface distinct from data interface
DMA interface off-chip
Cannot talk directly to memory!
You get to program each of the bits
Where is it?
You get to go looking for it
Has 'command queues'
"Wake me up after
Reads samples from the DMA controller, who knows nothing about this number
carefully chosen so that you can refill the buffer
The DMA Talk
Who here knows what DMA stands for?
Mechanism for a device to get data from the host
intervention on each byte, word, qword, ...
Kernel says "Here's how to get to some memory, have at"
Some time later, device comes back
A Device's Worth
DMA engine usually tightly coupled to each device
How about 'on the same chip'?
Device asks for a word
DMA engine says either "OK!", or "Uh-oh"
Host sets up DMA engine, then tells DMA engine and device to go ahead.
DMA buffer strategies
Buffer, length, done.
A little better?
List of buffers and lengths
What's better than a list?
Especially if the hardware guys are stuck with implementing it?
of buffers and lengths!
Used on many network cards
Some buffers can have flags associated with them
Typical scatter-gather setup
Like everything else on the PC, DMA is sad
Logic very expensive in the late 1980s
DMA controller goes with the
, not the card
What you will implement is a crazy part of PC history, and
"how DMA works" in the real world.
Back to the SB16!
DMA controller will be programmed
You tell it:
Location of buffer (over the course of many writes)
Size of buffer
It feeds samples
Buffer strategy, part 1
Fill it all up, then tell the sound card to interrupt you after reading the whole thing
When woken up, you go fill it up again
Buffer strategy, part 1.5
What went wrong?
Well, the interrupt didn't really get there in time, maybe
Or even if it did, by the time you started copying data...
Old data got played, and it sounds
Buffer strategy, part 2
We really need
While we're filling one, the card is playing from the other
not to intersect the card's play pointer!
Buffer strategy, part 2.5
...except our DMA controller sucks.
We only get one buffer. :(
So let's split the buffer in the middle.
Tell the card the buffer is half as big as it is
Not just 2
Since the buffer loops, it might as well be one long buffer
Let's consider a different strategy:
Interrupt every N
For N <<<< the buffer size, we can see it like this:
Pick a N, any N
If we get some interrupt, what can we tell?
We know where the card just played from... ...so we know what's not in use... ...so we know what we can fill.
This is another possible strategy.
Which you choose is a
Sound is fun
Buffers are a pain
DMA controllers are weird
You're lucky you're not using PCI
Have fun with this!