From owner-freebsd-multimedia@FreeBSD.ORG Tue Mar 12 22:31:14 2013 Return-Path: Delivered-To: freebsd-multimedia@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 779DAE1A for ; Tue, 12 Mar 2013 22:31:14 +0000 (UTC) (envelope-from adrian.chadd@gmail.com) Received: from mail-we0-x232.google.com (mail-we0-x232.google.com [IPv6:2a00:1450:400c:c03::232]) by mx1.freebsd.org (Postfix) with ESMTP id 05E9DD12 for ; Tue, 12 Mar 2013 22:31:13 +0000 (UTC) Received: by mail-we0-f178.google.com with SMTP id o45so371866wer.23 for ; Tue, 12 Mar 2013 15:31:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:sender:date:x-google-sender-auth:message-id :subject:from:to:content-type; bh=AEDZDB+6qUsQ4b5VbETb6dCCgmsix9JwRgFOg2sAgBw=; b=SQr7+gkszjcVSH4pPrzbPDEgvcJNeiNYLqyKls2BfqXuJNp7KbuRJkK3T3uHKDoefP rhQt/EEeqtHIbqgaKmmzeP7VC0YU6ComX88z5v2ldD/N39ssnVJ0tTpXoPyheet6aM7E r7HuxmwOqYKoOKmmjwCjuJuCusL1554K+QCquceObrDfcswFnfPfyqzd6GTfKvDALbZ+ CQrLYNvnmgW+I8SKr1u5KQv6GMKdgl/KxTRhRVJWlI6ZvIwa2XRStU7hqULX9qwdSyNT uXdFFiuPvP2I3UNJDTJyL8gm5r+ewsHgdx0pD9pDcU7nK/c49ekPIX9b8fWa6GYqj9NJ CYRg== MIME-Version: 1.0 X-Received: by 10.180.87.129 with SMTP id ay1mr22975456wib.1.1363127473137; Tue, 12 Mar 2013 15:31:13 -0700 (PDT) Sender: adrian.chadd@gmail.com Received: by 10.216.111.201 with HTTP; Tue, 12 Mar 2013 15:31:13 -0700 (PDT) Date: Tue, 12 Mar 2013 15:31:13 -0700 X-Google-Sender-Auth: gXz0N58P64Zog11G5wq2JCj-j9A Message-ID: Subject: FreeBSD OSS + Alsa - what's the right behaviour for non-blocking IO? From: Adrian Chadd To: freebsd-multimedia@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: freebsd-multimedia@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Multimedia discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Mar 2013 22:31:14 -0000 Hi, I've been hacking on some Alsa code on Linux which uses poll() and non-blocking IO to schedule audio. When I run that code on FreeBSD, it chews 100% of CPU. Now, the mechanics are pretty clear: * the /dev/dsp.X FD always returns POLLOUT; * when I then call alsalib to fetch the number of samples available to write into the playback buffer, I get 0 * this happens for quite a while until it finally returns non-zero. Digging into it (ie, snd.verbose=4 and looking at the sound setup routines) I discovered that the watermark was being set to the playback buffer size (32768 frames in my case, so 131072 bytes) and no subsequent adjustment was done. The oss plugin for alsa-lib calls SNDCTL_DSP_LOW_WATER So I'll go and tinker with the ALSA setup side in order to see what the story is (it's almost certain I'm setting things up incorrectly for non-blocking IO here and I need to to wave the right magic wand to get the low watermark reset right. However, there's definitely a behavioural difference here - FreeBSD shouldn't be returning POLLOUT on the dsp device, only to find that there's no space in the playback FIFO. Any ideas? Thanks, Adrian