From patchwork Tue Nov 13 06:41:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 10679883 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C3C1118F0 for ; Tue, 13 Nov 2018 07:32:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8CE852A449 for ; Tue, 13 Nov 2018 07:32:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 814F12A44F; Tue, 13 Nov 2018 07:32:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2F0FD2A47F for ; Tue, 13 Nov 2018 07:32:23 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id D9042267B9E; Tue, 13 Nov 2018 07:42:58 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 800E3267B92; Tue, 13 Nov 2018 07:42:53 +0100 (CET) Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) by alsa0.perex.cz (Postfix) with ESMTP id 7CE93267B3F for ; Tue, 13 Nov 2018 07:42:36 +0100 (CET) Received: by mail-pg1-f196.google.com with SMTP id 32-v6so5232826pgu.2 for ; Mon, 12 Nov 2018 22:42:36 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=f48Xn1HGdncdsarqsNjqZPod00SdE93/OK3yHUqec44=; b=uDcKIt5fSXEM5UiAp/tHXfO3TfrMwOE5VCGb89P+nwQ30C/9ML7ZDR0JkGvv6W5gqh H5zhVjrS8ecnLfz8DzY1Nsl1naFH/ChYLE9xBrWOUGOO/wsanaIyfC3w95Md/45g4Sc1 TJCf/FpX+aO17fq1HAMtIEKBG22nHQZtrUnkB+xu2zyHpsYW9hf/S9LNqaqzODNk7ItX TcaBVQHatn3qdBcw8NMI65+xNVEX2dDJFG3eUGMWx4JRulYm2J3AV8BAoPbzx/ShIRAt iclH+C62+2/ultqpe/w2tZPpkMTuXRawXlexYGaU7T0mF5OmHyiK4dCEbPoxeNcYnEEh KGHA== X-Gm-Message-State: AGRZ1gIp6+dwyANisEIBPCwtf071Wf6SpcI6T/a+12lpxpuMplSJnLag ooVLgxQF1YUFEXy2MjZevxJ+v9JR X-Google-Smtp-Source: AJdET5co7YuAkwvyx21VhzpPeAL9KLwUDJqv1OyF3n41B/BL93G9XVsgK1u+HdXuexWsK/0s2jK4og== X-Received: by 2002:a63:588:: with SMTP id 130mr3585877pgf.273.1542091355505; Mon, 12 Nov 2018 22:42:35 -0800 (PST) Received: from localhost.localdomain ([2405:6580:9660:3200:acf1:2274:aafd:ab4c]) by smtp.gmail.com with ESMTPSA id h7sm11207634pfa.105.2018.11.12.22.42.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Nov 2018 22:42:34 -0800 (PST) From: Takashi Sakamoto To: tiwai@suse.de, perex@perex.cz Date: Tue, 13 Nov 2018 15:41:36 +0900 Message-Id: <20181113064147.13577-24-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181113064147.13577-1-o-takashi@sakamocchi.jp> References: <20181113062459.DD8F7267A5C@alsa0.perex.cz> <20181113064147.13577-1-o-takashi@sakamocchi.jp> MIME-Version: 1.0 Cc: alsa-devel@alsa-project.org Subject: [alsa-devel] [PATCH 24/35] axfer: add an option to suppress event waiting X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP In aplay, '--test-nowait' is used to suppress calls of snd_pcm_wait() when I/O operations return -EAGAIN or process truncated number of data frames. This seems to be for debugging purpose. In this program, this option is equivalent to suppress event waiting. This commit adds support for this option. Signed-off-by: Takashi Sakamoto --- axfer/xfer-libasound-irq-mmap.c | 10 ++++++---- axfer/xfer-libasound-irq-rw.c | 20 ++++++++++++-------- axfer/xfer-libasound.c | 16 ++++++++++++++++ axfer/xfer-libasound.h | 3 +++ 4 files changed, 37 insertions(+), 12 deletions(-) diff --git a/axfer/xfer-libasound-irq-mmap.c b/axfer/xfer-libasound-irq-mmap.c index 87ef7e0..18f6dfe 100644 --- a/axfer/xfer-libasound-irq-mmap.c +++ b/axfer/xfer-libasound-irq-mmap.c @@ -81,10 +81,12 @@ static int irq_mmap_process_frames(struct libasound_state *state, snd_pcm_sframes_t consumed_count; int err; - // Wait for hardware IRQ when no avail space in buffer. - err = snd_pcm_wait(state->handle, -1); - if (err < 0) - return err; + if (state->use_waiter) { + // Wait for hardware IRQ when no avail space in buffer. + err = snd_pcm_wait(state->handle, -1); + if (err < 0) + return err; + } // Sync cache in user space to data in kernel space to calculate avail // frames according to the latest positions on PCM buffer. diff --git a/axfer/xfer-libasound-irq-rw.c b/axfer/xfer-libasound-irq-rw.c index f05ac4b..625c095 100644 --- a/axfer/xfer-libasound-irq-rw.c +++ b/axfer/xfer-libasound-irq-rw.c @@ -133,10 +133,12 @@ static int r_process_frames_nonblocking(struct libasound_state *state, goto error; } - // Wait for hardware IRQ when no available space. - err = snd_pcm_wait(state->handle, -1); - if (err < 0) - goto error; + if (state->use_waiter) { + // Wait for hardware IRQ when no available space. + err = snd_pcm_wait(state->handle, -1); + if (err < 0) + goto error; + } // Check available space on the buffer. avail = snd_pcm_avail(state->handle); @@ -286,10 +288,12 @@ static int w_process_frames_nonblocking(struct libasound_state *state, unsigned int avail_count; int err; - // Wait for hardware IRQ when no left space. - err = snd_pcm_wait(state->handle, -1); - if (err < 0) - goto error; + if (state->use_waiter) { + // Wait for hardware IRQ when no left space. + err = snd_pcm_wait(state->handle, -1); + if (err < 0) + goto error; + } // Check available space on the buffer. avail = snd_pcm_avail(state->handle); diff --git a/axfer/xfer-libasound.c b/axfer/xfer-libasound.c index c2e1282..61ae115 100644 --- a/axfer/xfer-libasound.c +++ b/axfer/xfer-libasound.c @@ -12,6 +12,7 @@ enum no_short_opts { // 200 or later belong to non us-ascii character set. OPT_FATAL_ERRORS = 200, + OPT_TEST_NOWAIT, }; #define S_OPTS "D:NM" @@ -21,6 +22,7 @@ static const struct option l_opts[] = { {"mmap", 0, 0, 'M'}, // For debugging. {"fatal-errors", 0, 0, OPT_FATAL_ERRORS}, + {"test-nowait", 0, 0, OPT_TEST_NOWAIT}, }; static int xfer_libasound_init(struct xfer_context *xfer, @@ -54,6 +56,8 @@ static int xfer_libasound_parse_opt(struct xfer_context *xfer, int key, state->mmap = true; else if (key == OPT_FATAL_ERRORS) state->finish_at_xrun = true; + else if (key == OPT_TEST_NOWAIT) + state->test_nowait = true; else err = -ENXIO; @@ -80,6 +84,15 @@ int xfer_libasound_validate_opts(struct xfer_context *xfer) return -EINVAL; } + if (state->test_nowait) { + if (!state->nonblock && !state->mmap) { + fprintf(stderr, + "An option for nowait test should be used with " + "nonblock or mmap options.\n"); + return -EINVAL; + } + } + return err; } @@ -124,6 +137,9 @@ static int open_handle(struct xfer_context *xfer) return err; } + if ((state->nonblock || state->mmap) && !state->test_nowait) + state->use_waiter = true; + err = snd_pcm_hw_params_any(state->handle, state->hw_params); if (err < 0) return err; diff --git a/axfer/xfer-libasound.h b/axfer/xfer-libasound.h index 550b1c2..f3ce73f 100644 --- a/axfer/xfer-libasound.h +++ b/axfer/xfer-libasound.h @@ -33,6 +33,9 @@ struct libasound_state { bool finish_at_xrun:1; bool nonblock:1; bool mmap:1; + bool test_nowait:1; + + bool use_waiter:1; }; // For internal use in 'libasound' module.