From patchwork Fri Sep 30 12:43:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Subhransu S. Prusty" X-Patchwork-Id: 9358453 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AAF4E600C8 for ; Fri, 30 Sep 2016 14:40:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A63429FE6 for ; Fri, 30 Sep 2016 14:40:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8B4672A02D; Fri, 30 Sep 2016 14:40:49 +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=-1.9 required=2.0 tests=BAYES_00, 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 AB50129FE6 for ; Fri, 30 Sep 2016 14:40:48 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id E223C2667EE; Fri, 30 Sep 2016 16:40:46 +0200 (CEST) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 738AB2665DC; Fri, 30 Sep 2016 16:38:22 +0200 (CEST) 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 0363F2665DC; Fri, 30 Sep 2016 14:50:28 +0200 (CEST) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by alsa0.perex.cz (Postfix) with ESMTP id ED9D0261A1A for ; Fri, 30 Sep 2016 14:50:21 +0200 (CEST) Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga101.jf.intel.com with ESMTP; 30 Sep 2016 05:50:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,272,1473145200"; d="scan'208";a="15394965" Received: from subhransu-desktop.iind.intel.com ([10.223.96.24]) by orsmga004.jf.intel.com with ESMTP; 30 Sep 2016 05:50:18 -0700 From: "Subhransu S. Prusty" To: alsa-devel@alsa-project.org Date: Fri, 30 Sep 2016 18:13:29 +0530 Message-Id: <1475239410-16548-7-git-send-email-subhransu.s.prusty@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1475239410-16548-1-git-send-email-subhransu.s.prusty@intel.com> References: <1475239410-16548-1-git-send-email-subhransu.s.prusty@intel.com> Cc: tiwai@suse.de, lgirdwood@gmail.com, Pierre-Louis Bossart , patches.audio@intel.com, broonie@kernel.org, "Subhransu S. Prusty" Subject: [alsa-devel] [PATCH 6/7] ALSA: usb: no_period_wake and max_inflight_bytes report 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: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP From: Pierre-Louis Bossart Enable no_period_wake and report max_inflight_bytes. The estimate is a worst-case, it could be refined based on actual number of packets per URB and total URBs, however this information is only available in the prepare step Signed-off-by: Pierre-Louis Bossart Signed-off-by: Subhransu S. Prusty --- sound/usb/pcm.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c index 44d178e..5bcc729 100644 --- a/sound/usb/pcm.c +++ b/sound/usb/pcm.c @@ -713,7 +713,8 @@ static int configure_endpoint(struct snd_usb_substream *subs) static int snd_usb_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *hw_params) { - struct snd_usb_substream *subs = substream->runtime->private_data; + struct snd_pcm_runtime *runtime = substream->runtime; + struct snd_usb_substream *subs = runtime->private_data; struct audioformat *fmt; int ret; @@ -728,7 +729,6 @@ static int snd_usb_hw_params(struct snd_pcm_substream *substream, subs->buffer_periods = params_periods(hw_params); subs->channels = params_channels(hw_params); subs->cur_rate = params_rate(hw_params); - fmt = find_format(subs); if (!fmt) { dev_dbg(&subs->dev->dev, @@ -749,6 +749,26 @@ static int snd_usb_hw_params(struct snd_pcm_substream *substream, subs->altset_idx = fmt->altset_idx; subs->need_setup_ep = true; + /* + * worst-case max_inflight_bytes is one URB (MAX_PACKS ms), + * multiply by size of 1ms packet for this format. The delay + * can be larger since there are up to MAX_URBS submitted, + * we only track the max number of bytes transferred when one + * URB is submitted. + */ + runtime->hw.max_inflight_bytes = DIV_ROUND_UP( + MAX_PACKS * subs->cur_rate * subs->channels * + snd_pcm_format_width(subs->pcm_format), 8 * 1000); + + /* + * The number of packets cannot exceed the ring buffer size, reflect + * constraints for low-latency usages + */ + if (runtime->hw.max_inflight_bytes > + subs->period_bytes * subs->buffer_periods) + runtime->hw.max_inflight_bytes = + subs->period_bytes * subs->buffer_periods; + return 0; } @@ -851,6 +871,7 @@ static struct snd_pcm_hardware snd_usb_hardware = .info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_BATCH | + SNDRV_PCM_INFO_NO_PERIOD_WAKEUP | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_PAUSE, @@ -1225,6 +1246,7 @@ static int snd_usb_pcm_open(struct snd_pcm_substream *substream, int direction) subs->interface = -1; subs->altset_idx = 0; runtime->hw = snd_usb_hardware; + runtime->hw.max_inflight_bytes = 0; /* will be set in hw_params() */ runtime->private_data = subs; subs->pcm_substream = substream; /* runtime PM is also done there */ @@ -1328,7 +1350,7 @@ static void retire_capture_urb(struct snd_usb_substream *subs, } } - if (period_elapsed) + if (period_elapsed && !runtime->no_period_wakeup) snd_pcm_period_elapsed(subs->pcm_substream); } @@ -1542,7 +1564,7 @@ static void prepare_playback_urb(struct snd_usb_substream *subs, spin_unlock_irqrestore(&subs->lock, flags); urb->transfer_buffer_length = bytes; - if (period_elapsed) + if (period_elapsed && !runtime->no_period_wakeup) snd_pcm_period_elapsed(subs->pcm_substream); }