From nobody Wed Dec 17 09:04:01 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C59BFEE4996 for ; Tue, 22 Aug 2023 15:06:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236510AbjHVPGY (ORCPT ); Tue, 22 Aug 2023 11:06:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236034AbjHVPGW (ORCPT ); Tue, 22 Aug 2023 11:06:22 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22E381B9 for ; Tue, 22 Aug 2023 08:06:19 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-31c66b7da88so55293f8f.0 for ; Tue, 22 Aug 2023 08:06:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692716777; x=1693321577; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=hiuif0UPEilRfTqfvjhgYV9OjFsrTUZzsOgS/HAy03Q=; b=EK/QqDRkxi36aIi0UBd9fmgJGjMU2iJAesESNS7RXj3CU+4OgQFnmS0DRe1Pjqt3Vj aSNjrghPdOk8/h1SE6SKPJAzc5DqcD4+5PrMeavHJyeyp9S2zKh9XaOtlZn7mY5eYSD/ cm7wR5jRdkxFzEfC6rjLF6OrbpWnmsYdVYAbNFkRPqOaRDPsW+L2vGKCop7uzax2TDuC euiDhxVc05SOEdjkhWgM5YYDIwbmQVLcQmKlNFbOLPaHYZPkGsrL6Tw3elinaF/uY5e/ yOhAj28EKnvg3I1Q1bZmpJZa6Itn2Tc0RfB8et8DvcNdvmh/azKkJDvWb84xZwElkzTw kTWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692716777; x=1693321577; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=hiuif0UPEilRfTqfvjhgYV9OjFsrTUZzsOgS/HAy03Q=; b=R0lHPJ5DXEDEFeZZoXJQfFGSLl6m340F0HO/J/uvtNuvzyIoYm5HwxEZi9mM7SfVgx /lK/hT1/2ed0b2QKDTYYU/Hf+oxSGQ5/slcPlb8SHoTzG+tjFr82SJ8NNv6TuVeuU/pV 5+nV0leMsgRpqd3khQBetBizbqpYdszZHEiXqmbdfv9HPjOXoF7rwwOuQVbesyeUjjXp YN6cp8yDJOS6Dak1Nc/QjhRVL8KhFpodbUTpyPUVUYP0fwaeFn7imPrRroSneabZ++Mu 1cgsRyCZyti4L/xTbAqO5TiUkvG1Z6M4oNFYTyfC+j8OcVF5l0U6No1yIukEg8+f+5GQ SLXQ== X-Gm-Message-State: AOJu0YzqH/G9zLk8esc88YD1862W5HiW+NmJr18/5cCiW31wwi2ITkO0 RWwLZJzMzF1MduQVDyOlvCM= X-Google-Smtp-Source: AGHT+IG/WYaK4QKoY/sXJElN3HnYE35+BGE/wEL15yzukGUemxKM29AaJP9Afn93aZrjhi0CYRIJjg== X-Received: by 2002:adf:e710:0:b0:317:3d36:b2c1 with SMTP id c16-20020adfe710000000b003173d36b2c1mr8082225wrm.7.1692716776656; Tue, 22 Aug 2023 08:06:16 -0700 (PDT) Received: from ivan-HLYL-WXX9.. ([141.136.93.153]) by smtp.gmail.com with ESMTPSA id p13-20020adff20d000000b0031c52e81490sm6619066wro.72.2023.08.22.08.06.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Aug 2023 08:06:16 -0700 (PDT) From: Ivan Orlov To: perex@perex.cz, tiwai@suse.com Cc: Ivan Orlov , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Subject: [PATCH] ALSA: pcmtest: Add support for pcm pausing Date: Tue, 22 Aug 2023 19:05:41 +0400 Message-Id: <20230822150541.8450-1-ivan.orlov0322@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add pause push/release support to the virtual PCM test driver. Add 'suspend' boolean field to the pcmtst_buf_iter structure, so we can pause the timer without shutting it down. Update the trigger callback handler correspondingly. Extract buffer initialization to the 'reset_buf_iterator' function since it is used in multiple places now. Signed-off-by: Ivan Orlov --- sound/drivers/pcmtest.c | 49 ++++++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/sound/drivers/pcmtest.c b/sound/drivers/pcmtest.c index 27cbb9d38f08..b59b78a09224 100644 --- a/sound/drivers/pcmtest.c +++ b/sound/drivers/pcmtest.c @@ -108,6 +108,7 @@ struct pcmtst_buf_iter { size_t total_bytes; // Total bytes read/written size_t chan_block; // Bytes in one channel buffer when non-interleaved struct snd_pcm_substream *substream; + bool suspend; // We need to pause timer without shutting it down struct timer_list timer_instance; }; =20 @@ -115,7 +116,8 @@ static struct snd_pcm_hardware snd_pcmtst_hw =3D { .info =3D (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_NONINTERLEAVED | - SNDRV_PCM_INFO_MMAP_VALID), + SNDRV_PCM_INFO_MMAP_VALID | + SNDRV_PCM_INFO_PAUSE), .formats =3D SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE, .rates =3D SNDRV_PCM_RATE_8000_48000, .rate_min =3D 8000, @@ -346,6 +348,9 @@ static void timer_timeout(struct timer_list *data) v_iter =3D from_timer(v_iter, data, timer_instance); substream =3D v_iter->substream; =20 + if (v_iter->suspend) + return; + if (substream->stream =3D=3D SNDRV_PCM_STREAM_PLAYBACK && !v_iter->is_buf= _corrupted) check_buf_block(v_iter, substream->runtime); else if (substream->stream =3D=3D SNDRV_PCM_STREAM_CAPTURE) @@ -358,7 +363,9 @@ static void timer_timeout(struct timer_list *data) v_iter->period_pos %=3D v_iter->period_bytes; snd_pcm_period_elapsed(substream); } - mod_timer(&v_iter->timer_instance, jiffies + TIMER_INTERVAL + inject_dela= y); + + if (!v_iter->suspend) + mod_timer(&v_iter->timer_instance, jiffies + TIMER_INTERVAL + inject_del= ay); } =20 static int snd_pcmtst_pcm_open(struct snd_pcm_substream *substream) @@ -373,19 +380,15 @@ static int snd_pcmtst_pcm_open(struct snd_pcm_substre= am *substream) if (!v_iter) return -ENOMEM; =20 + v_iter->substream =3D substream; runtime->hw =3D snd_pcmtst_hw; runtime->private_data =3D v_iter; - v_iter->substream =3D substream; - v_iter->buf_pos =3D 0; - v_iter->is_buf_corrupted =3D false; - v_iter->period_pos =3D 0; - v_iter->total_bytes =3D 0; =20 playback_capture_test =3D 0; ioctl_reset_test =3D 0; =20 timer_setup(&v_iter->timer_instance, timer_timeout, 0); - mod_timer(&v_iter->timer_instance, jiffies + TIMER_INTERVAL); + return 0; } =20 @@ -400,10 +403,40 @@ static int snd_pcmtst_pcm_close(struct snd_pcm_substr= eam *substream) return 0; } =20 +static inline void reset_buf_iterator(struct pcmtst_buf_iter *v_iter) +{ + v_iter->buf_pos =3D 0; + v_iter->is_buf_corrupted =3D false; + v_iter->period_pos =3D 0; + v_iter->total_bytes =3D 0; +} + +static inline void start_pcmtest_timer(struct pcmtst_buf_iter *v_iter) +{ + v_iter->suspend =3D false; + mod_timer(&v_iter->timer_instance, jiffies + TIMER_INTERVAL); +} + static int snd_pcmtst_pcm_trigger(struct snd_pcm_substream *substream, int= cmd) { + struct pcmtst_buf_iter *v_iter =3D substream->runtime->private_data; + if (inject_trigger_err) return -EINVAL; + switch (cmd) { + case SNDRV_PCM_TRIGGER_START: + reset_buf_iterator(v_iter); + start_pcmtest_timer(v_iter); + break; + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: + start_pcmtest_timer(v_iter); + break; + case SNDRV_PCM_TRIGGER_STOP: + case SNDRV_PCM_TRIGGER_PAUSE_PUSH: + // We can't call timer_shutdown_sync here, as it is forbidden to sleep h= ere + v_iter->suspend =3D true; + break; + } =20 return 0; } --=20 2.34.1