Skip to contentSkip to conversation

ALSA: pcm: Yet finer pending signal check in OSS read/write loop

PATCH In review Takashi Iwai 1 participant 3 messages Apr 6, 2018 – Apr 7, 2018 Sound

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 ALSA: pcm: Yet finer pending signal check in OSS read/write loop

PCM OSS emulation has the nested inner loops, and the loops in snd_pcm_oss_read3() and write3() have no pending signal check, so potentially they can hog for too long time for processing. Add the extra check there.

While we're at it, a slight code cleanup using the standard macro for the PCM state check is used.

---
 sound/core/oss/pcm_oss.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
sound/core/oss/pcm_oss.c +7 -5
index 481ab0e94ffa..5e009a444d9d 100644
@@ -1221,8 +1221,7 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
 	struct snd_pcm_runtime *runtime = substream->runtime;
 	int ret;
 	while (1) {
-		if (runtime->status->state == SNDRV_PCM_STATE_XRUN ||
-		    runtime->status->state == SNDRV_PCM_STATE_SUSPENDED) {
+		if (!snd_pcm_running(substream)) {
 #ifdef OSS_DEBUG
 			pcm_dbg(substream->pcm,
 				"pcm_oss: write: recovering from %s\n",
@@ -1241,6 +1240,8 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
 		/* has not been started */
 		if (runtime->status->state == SNDRV_PCM_STATE_PREPARED)
 			return -EAGAIN;
+		if (signal_pending(current))
+			return -ERESTARTSYS;
 	}
 	return ret;
 }
@@ -1278,10 +1279,11 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
 				if (ret < 0)
 					break;
 			}
-			continue;
-		}
-		if (ret != -ESTRPIPE)
+		} else if (ret != -ESTRPIPE) {
 			break;
+		}
+		if (signal_pending(current))
+			return -ERESTARTSYS;
 	}
 	return ret;
 }
Signature · 1 line
2.16.3
#1 lore raw

PATCH 2/2 ALSA: pcm: Add cond_resched() in OSS read/write loop

The PCM OSS read/write loops may take too long occasionally when a huge size of data is given. Add cond_resched() to become more system- friendlier.

---
 sound/core/oss/pcm_oss.c | 2 ++
 1 file changed, 2 insertions(+)
sound/core/oss/pcm_oss.c +2 -0
index 5e009a444d9d..54984119c0b3 100644
@@ -1452,6 +1452,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
 			break;
 		}
 		tmp = 0;
+		cond_resched();
 	}
 	atomic_dec(&runtime->oss.rw_ref);
 	return xfer > 0 ? (snd_pcm_sframes_t)xfer : tmp;
@@ -1547,6 +1548,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
 			break;
 		}
 		tmp = 0;
+		cond_resched();
 	}
 	atomic_dec(&runtime->oss.rw_ref);
 	return xfer > 0 ? (snd_pcm_sframes_t)xfer : tmp;
Signature · 1 line
2.16.3
#2 lore raw
In reply to Takashi Iwai
Quoted 10 lines · Takashi Iwai

PCM OSS emulation has the nested inner loops, and the loops in snd_pcm_oss_read3() and write3() have no pending signal check, so potentially they can hog for too long time for processing. Add the extra check there.

While we're at it, a slight code cleanup using the standard macro for the PCM state check is used.

Scratch these two patches. Both are superfluous, not really fix anything substantial.

Sorry for the noise.

Takashi