From nobody Sun Mar 31 19:21:37 2024 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4V73st1NRZz5GFR2; Sun, 31 Mar 2024 19:21:38 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4V73st0xmSz4SJH; Sun, 31 Mar 2024 19:21:38 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1711912898; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=5QLegiki3QPeC3B9BnomLXGz+15D2nAIFQP0Lk8SPLo=; b=Fjz95xYXZp+ubVfEz1xZYlEW8BnfnCZz8YVuWfJtCToqk7B42x7IgLA/LrXca/P53o1dg2 p4HJAAPw9nnTS+yAu6t+B1xEdFxpBr7/rChAy27zSsad59yn4L1M3IDoj6bG3DSlvFsacA LSi9gnX7Obdv4UelryfCT8P1YIhZBdpEQRxbHWuRLFRS5ln+VauBBxy91HP4kuYMEvU94j eJcvx6cX8bMu56YdF8r0cOad15ULrmRvZoWMpYsVvCbbmq9uH7O7yjbE7xc7VDxcxijmHb 7+st+n0z8obLcLUE6TaNdM+1SMEg8+ZhTR5+feWnSuncTtMk/ZVwzlvwurDRiw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1711912898; a=rsa-sha256; cv=none; b=f3FlFubbw05yPEOQVBVSnQAQua+gG7Xhn4ZN6tVaJn0qJAJ35KRbNk/+SrECLOvFqZvK7N Atb0obmzpcBEMzTkUlPM46gosF/rJwoVW9ql3badYpx23Ql7omKgsr7LY07vMe9N+negIr YCN9dq8tajD5NaP1VFnWy8Of3zs1ZCSShv3gYSKMnoJpxaM3r/HSTVf8W2mQZXKPHVypmM N6YH49y5/0pHrHv3p9xvPYuesXPvWDUyZdLZlQz2QYeq4bhElYfwsBPuk6FAAeKlw579fE QOqaXwgimyjtt6J1Gv3Rl5U9eTky2Sc9X6rCf4xJgcLwau40jzkjkiWslQy1ow== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1711912898; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=5QLegiki3QPeC3B9BnomLXGz+15D2nAIFQP0Lk8SPLo=; b=P0O7OrXCPMdvffJFL09VYnhFkOKpHi7vFakQZ6bphIOdc/JB6FX20EzkiKlA9SkxJLnhBa zCsxBAPz7usd9fZvX807UB4xjsuGdgVnLvJZGoANNp4idDB2HiuwbX9HvGBTJTNIQ8KO3C HtMlttzu89wSGXM1xn3GwuYxIQQb1pe47EaFfHJ+qAxNy5G7gGM9KfgiBCcecmB2+r6vFy 5sHIudUD1xlS2a/PxKr21mQaMxbGS6mTI/wGyM/fd3DoanA3RcCsJBQn6skX81fcd8cknb UkUYooz4tJhaS8OtZ78GGtcpRt5Hx+8dERcNTPfp5yhb1VGj/Km/0jBfADZPAw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4V73st0Ybgzr0M; Sun, 31 Mar 2024 19:21:38 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 42VJLbmp097321; Sun, 31 Mar 2024 19:21:37 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 42VJLbcr097318; Sun, 31 Mar 2024 19:21:37 GMT (envelope-from git) Date: Sun, 31 Mar 2024 19:21:37 GMT Message-Id: <202403311921.42VJLbcr097318@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Ruslan Bukin Subject: git: ee36e7faceaf - main - snd_hdspe(4): Only buffer_copy() audio data once. List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: br X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: ee36e7faceafeef05c5e81654a1d8ec11d314894 Auto-Submitted: auto-generated The branch main has been updated by br: URL: https://cgit.FreeBSD.org/src/commit/?id=ee36e7faceafeef05c5e81654a1d8ec11d314894 commit ee36e7faceafeef05c5e81654a1d8ec11d314894 Author: Florian Walpen AuthorDate: 2024-03-31 19:14:16 +0000 Commit: Ruslan Bukin CommitDate: 2024-03-31 19:14:16 +0000 snd_hdspe(4): Only buffer_copy() audio data once. Instead of blindly copying two periods of audio data to and from DMA buffers, keep track of the writing position and derive the actual part of audio data that needs to be copied. This approximately halves the number of samples copied in total. Differential Revision: https://reviews.freebsd.org/D44084 --- sys/dev/sound/pci/hdspe-pcm.c | 46 ++++++++++++++++++++++++++++++++++--------- sys/dev/sound/pci/hdspe.h | 1 + 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/sys/dev/sound/pci/hdspe-pcm.c b/sys/dev/sound/pci/hdspe-pcm.c index 594a4f704028..0e78be113a66 100644 --- a/sys/dev/sound/pci/hdspe-pcm.c +++ b/sys/dev/sound/pci/hdspe-pcm.c @@ -540,7 +540,8 @@ buffer_copy(struct sc_chinfo *ch) struct sc_pcminfo *scp; struct sc_info *sc; uint32_t row, ports; - unsigned int pos; + uint32_t dma_pos; + unsigned int pos, length, offset; unsigned int n; unsigned int adat_width, pcm_width; @@ -558,13 +559,35 @@ buffer_copy(struct sc_chinfo *ch) else pcm_width = 8; - if (ch->dir == PCMDIR_PLAY) - pos = sndbuf_getreadyptr(ch->buffer); - else - pos = sndbuf_getfreeptr(ch->buffer); + /* Derive buffer position and length to be copied. */ + if (ch->dir == PCMDIR_PLAY) { + /* Position per channel is n times smaller than PCM. */ + pos = sndbuf_getreadyptr(ch->buffer) / n; + length = sndbuf_getready(ch->buffer) / n; + /* Copy no more than 2 periods in advance. */ + if (length > (sc->period * 4 * 2)) + length = (sc->period * 4 * 2); + /* Skip what was already copied last time. */ + offset = (ch->position + HDSPE_CHANBUF_SIZE) - pos; + offset %= HDSPE_CHANBUF_SIZE; + if (offset <= length) { + pos = (pos + offset) % HDSPE_CHANBUF_SIZE; + length -= offset; + } + } else { + /* Position per channel is n times smaller than PCM. */ + pos = sndbuf_getfreeptr(ch->buffer) / n; + /* Get DMA buffer write position. */ + dma_pos = hdspe_read_2(sc, HDSPE_STATUS_REG); + dma_pos &= HDSPE_BUF_POSITION_MASK; + /* Copy what is newly available. */ + length = (dma_pos + HDSPE_CHANBUF_SIZE) - pos; + length %= HDSPE_CHANBUF_SIZE; + } - pos /= 4; /* Bytes per sample. */ - pos /= n; /* Destination buffer n-times smaller. */ + /* Position and length in samples (4 bytes). */ + pos /= 4; + length /= 4; /* Iterate through rows of ports with contiguous slots. */ ports = ch->ports; @@ -576,10 +599,10 @@ buffer_copy(struct sc_chinfo *ch) while (row != 0) { if (ch->dir == PCMDIR_PLAY) buffer_mux_port(sc->pbuf, ch->data, row, ch->ports, pos, - sc->period * 2, adat_width, pcm_width); + length, adat_width, pcm_width); else buffer_demux_port(sc->rbuf, ch->data, row, ch->ports, - pos, sc->period * 2, adat_width, pcm_width); + pos, length, adat_width, pcm_width); ports &= ~row; if (pcm_width == adat_width) @@ -587,6 +610,8 @@ buffer_copy(struct sc_chinfo *ch) else row = hdspe_port_first(ports); } + + ch->position = ((pos + length) * 4) % HDSPE_CHANBUF_SIZE; } static int @@ -620,6 +645,8 @@ clean(struct sc_chinfo *ch) row = hdspe_port_first_row(ports); } + ch->position = 0; + return (0); } @@ -664,6 +691,7 @@ hdspechan_init(kobj_t obj, void *devinfo, struct snd_dbuf *b, /* Allocate maximum buffer size. */ ch->size = HDSPE_CHANBUF_SIZE * hdspe_channel_count(ch->ports, 8); ch->data = malloc(ch->size, M_HDSPE, M_NOWAIT); + ch->position = 0; ch->buffer = b; ch->channel = c; diff --git a/sys/dev/sound/pci/hdspe.h b/sys/dev/sound/pci/hdspe.h index 26694f60ce58..de20462170e7 100644 --- a/sys/dev/sound/pci/hdspe.h +++ b/sys/dev/sound/pci/hdspe.h @@ -184,6 +184,7 @@ struct sc_chinfo { /* Buffer */ uint32_t *data; uint32_t size; + uint32_t position; /* Flags */ uint32_t run;