From: Takashi Iwai Subject: Re: [PATCH] Reduce interrupt latency in sound/pci/via82xx.c Date: Mon, 12 Sep 2005 17:07:12 +0200 Message-ID: References: <200509121418.05184.annabellesgarden@yahoo.de> <200509121509.27712.annabellesgarden@yahoo.de> <200509121631.32066.annabellesgarden@yahoo.de> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Return-path: In-Reply-To: <200509121631.32066.annabellesgarden@yahoo.de> Sender: alsa-devel-admin@lists.sourceforge.net Errors-To: alsa-devel-admin@lists.sourceforge.net List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , List-Archive: To: Karsten Wiese Cc: alsa-devel@lists.sourceforge.net List-Id: alsa-devel@alsa-project.org At Mon, 12 Sep 2005 16:31:31 +0200, Karsten Wiese wrote: > > Am Montag, 12. September 2005 15:09 schrieb Takashi Iwai: > > Hmm, then let's fix the handling of 0 read in all cases. > > We can simply assume the next period in this case as an exception. > > No. I've looked at the change sequence of CUR_COUNT through an iopl(3)ed > app running as root polling CUR_COUNT. > The problem case looks like this: > step value > ====== ========== > 0 0x01000020 // page index 1, 32 bytes left to transfer > 1 0x01000000 // page index 1 complete > 2 0x02000000 // switched to page index 2, looks like complete > // _but hasn't yet started!_ > 3 0x02001000 // page index 2, 4096 bytes left to transfer > > > Step 1 values could be red up to ~270 times in a row. > Step 2 values occurred maximum 2 times in a row so far. Well, we can check the validity of the assumed position by comparing with the last position. An untested patch is below. > If above Step 2 repetition count would reflect real worst case, > we could handle (CUR_COUNT & 0xFFFFFF)==0 like this: > > read CUR_COUNT 3 times in a row. > index page of lowest (CUR_COUNT >> 24) has completed > > Problem is that 3 times in a row might not be enough for all machines. > So we'd assume 6 times to be safe and that would give significant > latency again, though still better than what we have now. > > How about: > - when in interrupt, read CUR_COUNT 1 time. > if (CUR_COUNT & 0xFFFFFF)==0 use fast position with period > resolution > - when not in interrupt get position from chip by reading > CUR_COUNT maximum 6 times This sounds not bad. > - provide default off module_parameter "fast_position" > to always only use fast position ... if the solution witout loop doesn't work. Takashi Index: alsa-kernel/pci/via82xx.c =================================================================== RCS file: /home/iwai/cvs/alsa/alsa-kernel/pci/via82xx.c,v retrieving revision 1.178 diff -u -r1.178 via82xx.c --- alsa-kernel/pci/via82xx.c 12 Sep 2005 10:27:50 -0000 1.178 +++ alsa-kernel/pci/via82xx.c 12 Sep 2005 15:03:34 -0000 @@ -325,6 +325,7 @@ struct snd_via_sg_table *idx_table; /* for recovery from the unexpected pointer */ unsigned int lastpos; + unsigned int hwpos; unsigned int fragsize; unsigned int bufsize; unsigned int bufsize2; @@ -596,6 +597,7 @@ outb(0x00, VIADEV_REG(viadev, OFFSET_TYPE)); /* for via686 */ // outl(0, VIADEV_REG(viadev, OFFSET_CURR_PTR)); viadev->lastpos = 0; + viadev->hwpos = 0; } @@ -626,6 +628,8 @@ if (! c_status) continue; if (viadev->substream && viadev->running) { + viadev->hwpos += viadev->fragsize; + viadev->hwpos %= viadev->bufsize; spin_unlock(&chip->reg_lock); snd_pcm_period_elapsed(viadev->substream); spin_lock(&chip->reg_lock); @@ -771,29 +775,34 @@ via82xx_t *chip = snd_pcm_substream_chip(substream); viadev_t *viadev = (viadev_t *)substream->runtime->private_data; unsigned int idx, count, res; - int timeout = 5000; snd_assert(viadev->tbl_entries, return 0); if (!(inb(VIADEV_REG(viadev, OFFSET_STATUS)) & VIA_REG_STAT_ACTIVE)) return 0; spin_lock(&chip->reg_lock); - do { - count = inl(VIADEV_REG(viadev, OFFSET_CURR_COUNT)); - /* some mobos read 0 count */ - if ((count & 0xffffff) || ! viadev->running) - break; - } while (--timeout); - if (! timeout) - snd_printd(KERN_ERR "zero position is read\n"); - idx = count >> 24; - if (idx >= viadev->tbl_entries) { + count = inl(VIADEV_REG(viadev, OFFSET_CURR_COUNT)); + /* some mobos read 0 count + * + * This happens when the register is being updated. We assume the + * new period here + */ + if (! (count & 0xffffff)) { + res = viadev->hwpos; + if (check_invalid_pos(viadev, res)) + res = viadev->lastpos; + else + viadev->lastpos = res; + } else { + idx = count >> 24; + if (idx >= viadev->tbl_entries) { #ifdef POINTER_DEBUG - printk("fail: invalid idx = %i/%i\n", idx, viadev->tbl_entries); + printk("fail: invalid idx = %i/%i\n", idx, viadev->tbl_entries); #endif - res = viadev->lastpos; - } else { - count &= 0xffffff; - res = calc_linear_pos(viadev, idx, count); + res = viadev->lastpos; + } else { + count &= 0xffffff; + res = calc_linear_pos(viadev, idx, count); + } } spin_unlock(&chip->reg_lock); ------------------------------------------------------- SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf