[alsa-devel] Measuring Device Throughput - MMAP vs. RW
Pavel Hofman
pavhofman at gmail.com
Sun Sep 8 17:23:36 CEST 2019
Hi,
Gathering data for USB async gadget feedback (
https://mailman.alsa-project.org/pipermail/alsa-devel/2019-August/154819.html
) requires measuring average data rate to/from a device. For testing I
added measuring/averaging code to methods snd_pcm_hw_writei, snd_pcm_hw_readi,
and snd_pcm_hw_mmap_commit in
https://github.com/alsa-project/alsa-lib/blob/master/src/pcm/pcm_hw.c . In
all cases I take the parameter "size" of all the three methods as the
number of samples written/read.
RW: The averaging works very well for R/W access (hw:X) for playback and
capture, I get same values on the same device (playback/capture timed by
one clock).
MMAP: When mmap is used (e.g. plughw:X + sample format conversion), I get
very stable results for MMAP playback on all soundcards I have tested. But
for capture I get identical results to playback for one soundcard (PCI
Envy24), while the averaged rate calculated from "size" in
snd_pcm_hw_mmap_commit fluctuates for capture on Intel HDA.
The averaging is simply summing "size" in every call of the method and
dividing by passed nanosecs every approx 10 seconds:
Working OK (Infrasonic Quartet, and all soundcards for read/write mode):
Playback
MMAP Time: 19440.900391, averaged samplerate: 48000.511829
MMAP Time: 19451.140625, averaged samplerate: 48000.360218
MMAP Time: 19461.380859, averaged samplerate: 48000.176846
MMAP Time: 19471.619141, averaged samplerate: 48000.664570
MMAP Time: 19481.861328, averaged samplerate: 48000.199970
MMAP Time: 19492.101562, averaged samplerate: 48000.589854
MMAP Time: 19502.341797, averaged samplerate: 48000.288977
MMAP Time: 19512.580078, averaged samplerate: 48000.516104
MMAP Time: 19522.820312, averaged samplerate: 48000.225282
Capture:
MMAP Time: 19454.578125, averaged samplerate: 48000.430766
MMAP Time: 19464.818359, averaged samplerate: 48000.397611
MMAP Time: 19475.056641, averaged samplerate: 48000.400049
MMAP Time: 19485.296875, averaged samplerate: 48000.293275
MMAP Time: 19495.539062, averaged samplerate: 48000.549048
MMAP Time: 19505.779297, averaged samplerate: 48000.445214
MMAP Time: 19516.017578, averaged samplerate: 48000.417299
MMAP Time: 19526.257812, averaged samplerate: 48000.376264
MMAP Time: 19536.498047, averaged samplerate: 48000.422957
MMAP Time: 19546.738281, averaged samplerate: 48000.538619
MMAP Time: 19556.976562, averaged samplerate: 48000.241647
MMAP Time: 19567.216797, averaged samplerate: 48000.447243
Fluctuating Capture (Intel HDA):
Playback - OK:
MMAP Time: 19574.498047, averaged samplerate: 47998.971874
MMAP Time: 19584.568359, averaged samplerate: 47998.871734
MMAP Time: 19594.636719, averaged samplerate: 47998.929850
MMAP Time: 19604.707031, averaged samplerate: 47998.972555
MMAP Time: 19614.775391, averaged samplerate: 47998.925531
MMAP Time: 19624.845703, averaged samplerate: 47998.893351
MMAP Time: 19634.916016, averaged samplerate: 47998.949489
MMAP Time: 19644.986328, averaged samplerate: 47998.593678
MMAP Time: 19655.056641, averaged samplerate: 47999.230857
MMAP Time: 19665.125000, averaged samplerate: 47998.777034
MMAP Time: 19675.195312, averaged samplerate: 47999.177460
MMAP Time: 19685.263672, averaged samplerate: 47998.798503
Capture - fluctuating, clearly some samples are not counted:
MMAP Time: 19539.853516, averaged samplerate: 47191.039837
MMAP Time: 19549.923828, averaged samplerate: 46369.921890
MMAP Time: 19559.994141, averaged samplerate: 47998.831508
MMAP Time: 19570.148438, averaged samplerate: 47190.998307
MMAP Time: 19580.302734, averaged samplerate: 47191.275432
MMAP Time: 19590.373047, averaged samplerate: 47998.894343
MMAP Time: 19600.443359, averaged samplerate: 47998.906779
MMAP Time: 19610.511719, averaged samplerate: 47999.174771
MMAP Time: 19620.582031, averaged samplerate: 47998.747971
MMAP Time: 19630.650391, averaged samplerate: 47998.881964
MMAP Time: 19640.722656, averaged samplerate: 47998.999974
MMAP Time: 19650.791016, averaged samplerate: 47998.769240
I suspect the size parameter of snd_pcm_hw_mmap_commit is not the actual
amount of samples read during the MMAP capture. Please how to calculate the
number of samples read from the variables available in that method?
Thanks a lot.
Pavel.
More information about the Alsa-devel
mailing list