]> git.alsa-project.org Git - alsa-lib.git/commitdiff
pcm: dmix: Fix semaphore usage with lockless operation
authorTakashi Iwai <tiwai@suse.de>
Fri, 19 Jun 2020 16:40:46 +0000 (18:40 +0200)
committerTakashi Iwai <tiwai@suse.de>
Tue, 7 Jul 2020 09:57:03 +0000 (11:57 +0200)
As Maarten Baert recently reported, the current dmix code applies the
semaphore unnecessarily around mixing streams even when the lockless
mix operation is used on x86.  This was rather introduced mistakenly
at the commit 267d7c728196 ("Add support of little-endian on
i386/x86_64 dmix") where the generic dmix code was included on x86,
too.

For achieving the original performance back, this patch changes the
semaphore handling to be checked at run time instead of statically at
compile time.

Reviewed-by: Jaroslav Kysela <perex@perex.cz>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
src/pcm/pcm_direct.h
src/pcm/pcm_dmix.c
src/pcm/pcm_dmix_generic.c
src/pcm/pcm_dmix_i386.c
src/pcm/pcm_dmix_x86_64.c

index 8a236970a3a1b87f58a5352aa4495ad62e804b91..2150bce15449372ef0ebf33255d1980f5416d0cb 100644 (file)
@@ -186,6 +186,7 @@ struct snd_pcm_direct {
                        mix_areas_32_t *remix_areas_32;
                        mix_areas_24_t *remix_areas_24;
                        mix_areas_u8_t *remix_areas_u8;
+                       unsigned int use_sem;
                } dmix;
                struct {
                        unsigned long long chn_mask;
index 843fa3168756b5260170ac8145593092245ebc95..e9343b19a536e91f5276c1cc0bee6776d8d2e755 100644 (file)
@@ -292,13 +292,17 @@ static void remix_areas(snd_pcm_direct_t *dmix,
  * the area via semaphore
  */
 #ifndef DOC_HIDDEN
-#ifdef NO_CONCURRENT_ACCESS
-#define dmix_down_sem(dmix) snd_pcm_direct_semaphore_down(dmix, DIRECT_IPC_SEM_CLIENT)
-#define dmix_up_sem(dmix) snd_pcm_direct_semaphore_up(dmix, DIRECT_IPC_SEM_CLIENT)
-#else
-#define dmix_down_sem(dmix)
-#define dmix_up_sem(dmix)
-#endif
+static void dmix_down_sem(snd_pcm_direct_t *dmix)
+{
+       if (dmix->u.dmix.use_sem)
+               snd_pcm_direct_semaphore_down(dmix, DIRECT_IPC_SEM_CLIENT);
+}
+
+static void dmix_up_sem(snd_pcm_direct_t *dmix)
+{
+       if (dmix->u.dmix.use_sem)
+               snd_pcm_direct_semaphore_up(dmix, DIRECT_IPC_SEM_CLIENT);
+}
 #endif
 
 /*
index 40c08747a74a4676a7de460e42dd5217afdc45fc..8a5b6f148556fa6414e8e2170624feba75cea92d 100644 (file)
@@ -43,7 +43,6 @@ static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
 #ifndef ARCH_ADD
 #define ARCH_ADD(p,a) (*(p) += (a))
 #define ARCH_CMPXCHG(p,a,b) (*(p)) /* fake */
-#define NO_CONCURRENT_ACCESS   /* use semaphore to avoid race */
 #define IS_CONCURRENT  0       /* no race check */
 #endif
 
@@ -530,6 +529,7 @@ static void generic_mix_select_callbacks(snd_pcm_direct_t *dmix)
        dmix->u.dmix.mix_areas_u8 = generic_mix_areas_u8;
        dmix->u.dmix.remix_areas_24 = generic_remix_areas_24;
        dmix->u.dmix.remix_areas_u8 = generic_remix_areas_u8;
+       dmix->u.dmix.use_sem = 1;
 }
 
 #endif
index 1ab983a8a373e4fbe9c5e996f90f8fe7d23e6de1..82a91c5c2897ca3eebd4c66c10806f9328884d94 100644 (file)
@@ -135,4 +135,5 @@ static void mix_select_callbacks(snd_pcm_direct_t *dmix)
                dmix->u.dmix.mix_areas_24 = smp > 1 ? mix_areas_24_smp: mix_areas_24;
                dmix->u.dmix.remix_areas_24 = smp > 1 ? remix_areas_24_smp: remix_areas_24;
        }
+       dmix->u.dmix.use_sem = 0;
 }
index 34c40d4e9d1d0610cadbab884e9356ef36519771..4d882bfd01bfce336622d47d00e5a1d07469bf2f 100644 (file)
@@ -102,4 +102,5 @@ static void mix_select_callbacks(snd_pcm_direct_t *dmix)
        dmix->u.dmix.remix_areas_32 = smp > 1 ? remix_areas_32_smp : remix_areas_32;
        dmix->u.dmix.mix_areas_24 = smp > 1 ? mix_areas_24_smp : mix_areas_24;
        dmix->u.dmix.remix_areas_24 = smp > 1 ? remix_areas_24_smp : remix_areas_24;
+       dmix->u.dmix.use_sem = 0;
 }