[PATCH v5 0/3] ALSA: compress_offload: Add 64-bit safe timestamp API

Joris Verhaegen posted 3 patches 4 days, 7 hours ago
include/sound/compress_driver.h               |  2 +-
include/sound/soc-component.h                 |  4 +-
include/sound/soc-dai.h                       |  7 +-
include/uapi/sound/compress_offload.h         | 35 ++++++-
sound/core/compress_offload.c                 | 98 +++++++++++++------
sound/soc/codecs/wm_adsp.c                    |  4 +-
sound/soc/codecs/wm_adsp.h                    |  2 +-
.../intel/atom/sst-mfld-platform-compress.c   | 12 ++-
sound/soc/intel/atom/sst-mfld-platform.h      |  2 +-
sound/soc/intel/atom/sst/sst_drv_interface.c  |  9 +-
sound/soc/intel/avs/probes.c                  |  2 +-
sound/soc/qcom/qdsp6/q6apm-dai.c              | 26 +++--
sound/soc/qcom/qdsp6/q6asm-dai.c              | 26 +++--
sound/soc/soc-component.c                     |  2 +-
sound/soc/soc-compress.c                      |  2 +-
sound/soc/soc-dai.c                           |  2 +-
sound/soc/sof/amd/acp-probes.c                |  2 +-
sound/soc/sof/compress.c                      |  2 +-
sound/soc/sof/intel/hda-probes.c              |  2 +-
sound/soc/sof/sof-client-probes.c             |  2 +-
sound/soc/sof/sof-client-probes.h             |  4 +-
sound/soc/sprd/sprd-pcm-compress.c            |  6 +-
sound/soc/sprd/sprd-pcm-dma.h                 |  4 +-
sound/soc/uniphier/aio-compress.c             |  2 +-
24 files changed, 172 insertions(+), 87 deletions(-)
[PATCH v5 0/3] ALSA: compress_offload: Add 64-bit safe timestamp API
Posted by Joris Verhaegen 4 days, 7 hours ago
The current compress offload timestamping API relies on struct
snd_compr_tstamp, whose cumulative counters like copied_total are
defined as __u32. On long-running high-resolution audio streams, these
32-bit counters can overflow, causing incorrect availability
calculations.

This patch series transitions to a 64-bit safe API to solve the problem
while maintaining perfect backward compatibility with the existing UAPI.
The pointer operation is reworked to use a new timestamp struct with
64-bit fields for the cumulative counters, named snd_compr_tstamp64.
ASoC drivers are updated to use the 64-bit structures. Corresponding
ioctls are added to expose them to user-space.

The series is structured as follows:

Patch 1: Updates the pointer op, refactors the core logic and ASoC
drivers to use it, and defines the new UAPI structs.

Patch 2: Exposes the SNDRV_COMPRESS_TSTAMP64 ioctl.

Patch 3: Exposes the corresponding SNDRV_COMPRESS_AVAIL64 ioctl.

This series has been tested on a Pixel 9 device. All compress offload
use cases, including long-running playback, were verified to work
correctly with the new 64-bit API.

Thanks,
Joris (George) Verhaegen

Signed-off-by: Joris Verhaegen <verhaegen@google.com>

---
Changes in v2:
  - Corrected author and Signed-off-by to be consistent (Mark Brown).
Changes in v3:
  - Rework pointer op to return 64-bit timestamp, rather than adding a
    parallel pointer64 op (Charles Keepax, Takashi Iwai, Vinod Koul)
  - Bump the protocol version for ABI change (Takashi Iwai)
  -Fix linker error on Intel Atom (lkp@intel.com)
  -Rebase on latest for-next sound tree (Takashi Iwai)
  -Avoid changing return error code for ioctl (internal)
  -ASoC: Replace u64 % u32 by do_div(u64, u32) (internal)
  -ASoC: sprd: change current_data_offset to u64 (internal)
Changes in v4:
  -Fix compiler error on Intel AVS (lkp@intel.com)
Changes in v5:
  -Revert formatting change in compress_offload.c (Vinod Koul)

Joris Verhaegen (3):
  ALSA: compress_offload: Add 64-bit safe timestamp infrastructure
  ALSA: compress_offload: Add SNDRV_COMPRESS_TSTAMP64 ioctl
  ALSA: compress_offload: Add SNDRV_COMPRESS_AVAIL64 ioctl

 include/sound/compress_driver.h               |  2 +-
 include/sound/soc-component.h                 |  4 +-
 include/sound/soc-dai.h                       |  7 +-
 include/uapi/sound/compress_offload.h         | 35 ++++++-
 sound/core/compress_offload.c                 | 98 +++++++++++++------
 sound/soc/codecs/wm_adsp.c                    |  4 +-
 sound/soc/codecs/wm_adsp.h                    |  2 +-
 .../intel/atom/sst-mfld-platform-compress.c   | 12 ++-
 sound/soc/intel/atom/sst-mfld-platform.h      |  2 +-
 sound/soc/intel/atom/sst/sst_drv_interface.c  |  9 +-
 sound/soc/intel/avs/probes.c                  |  2 +-
 sound/soc/qcom/qdsp6/q6apm-dai.c              | 26 +++--
 sound/soc/qcom/qdsp6/q6asm-dai.c              | 26 +++--
 sound/soc/soc-component.c                     |  2 +-
 sound/soc/soc-compress.c                      |  2 +-
 sound/soc/soc-dai.c                           |  2 +-
 sound/soc/sof/amd/acp-probes.c                |  2 +-
 sound/soc/sof/compress.c                      |  2 +-
 sound/soc/sof/intel/hda-probes.c              |  2 +-
 sound/soc/sof/sof-client-probes.c             |  2 +-
 sound/soc/sof/sof-client-probes.h             |  4 +-
 sound/soc/sprd/sprd-pcm-compress.c            |  6 +-
 sound/soc/sprd/sprd-pcm-dma.h                 |  4 +-
 sound/soc/uniphier/aio-compress.c             |  2 +-
 24 files changed, 172 insertions(+), 87 deletions(-)

-- 
2.51.0.355.g5224444f11-goog
Re: [PATCH v5 0/3] ALSA: compress_offload: Add 64-bit safe timestamp API
Posted by Takashi Iwai 1 day, 8 hours ago
On Fri, 05 Sep 2025 11:12:53 +0200,
Joris Verhaegen wrote:
> 
> The current compress offload timestamping API relies on struct
> snd_compr_tstamp, whose cumulative counters like copied_total are
> defined as __u32. On long-running high-resolution audio streams, these
> 32-bit counters can overflow, causing incorrect availability
> calculations.
> 
> This patch series transitions to a 64-bit safe API to solve the problem
> while maintaining perfect backward compatibility with the existing UAPI.
> The pointer operation is reworked to use a new timestamp struct with
> 64-bit fields for the cumulative counters, named snd_compr_tstamp64.
> ASoC drivers are updated to use the 64-bit structures. Corresponding
> ioctls are added to expose them to user-space.
> 
> The series is structured as follows:
> 
> Patch 1: Updates the pointer op, refactors the core logic and ASoC
> drivers to use it, and defines the new UAPI structs.
> 
> Patch 2: Exposes the SNDRV_COMPRESS_TSTAMP64 ioctl.
> 
> Patch 3: Exposes the corresponding SNDRV_COMPRESS_AVAIL64 ioctl.
> 
> This series has been tested on a Pixel 9 device. All compress offload
> use cases, including long-running playback, were verified to work
> correctly with the new 64-bit API.
> 
> Thanks,
> Joris (George) Verhaegen
> 
> Signed-off-by: Joris Verhaegen <verhaegen@google.com>
> 
> ---
> Changes in v2:
>   - Corrected author and Signed-off-by to be consistent (Mark Brown).
> Changes in v3:
>   - Rework pointer op to return 64-bit timestamp, rather than adding a
>     parallel pointer64 op (Charles Keepax, Takashi Iwai, Vinod Koul)
>   - Bump the protocol version for ABI change (Takashi Iwai)
>   -Fix linker error on Intel Atom (lkp@intel.com)
>   -Rebase on latest for-next sound tree (Takashi Iwai)
>   -Avoid changing return error code for ioctl (internal)
>   -ASoC: Replace u64 % u32 by do_div(u64, u32) (internal)
>   -ASoC: sprd: change current_data_offset to u64 (internal)
> Changes in v4:
>   -Fix compiler error on Intel AVS (lkp@intel.com)
> Changes in v5:
>   -Revert formatting change in compress_offload.c (Vinod Koul)
> 
> Joris Verhaegen (3):
>   ALSA: compress_offload: Add 64-bit safe timestamp infrastructure
>   ALSA: compress_offload: Add SNDRV_COMPRESS_TSTAMP64 ioctl
>   ALSA: compress_offload: Add SNDRV_COMPRESS_AVAIL64 ioctl

Applied all patches now to for-next branch for 6.18.


thanks,

Takashi
Re: [PATCH v5 0/3] ALSA: compress_offload: Add 64-bit safe timestamp API
Posted by Vinod Koul 1 day, 10 hours ago
On 05-09-25, 10:12, Joris Verhaegen wrote:
> The current compress offload timestamping API relies on struct
> snd_compr_tstamp, whose cumulative counters like copied_total are
> defined as __u32. On long-running high-resolution audio streams, these
> 32-bit counters can overflow, causing incorrect availability
> calculations.
> 
> This patch series transitions to a 64-bit safe API to solve the problem
> while maintaining perfect backward compatibility with the existing UAPI.
> The pointer operation is reworked to use a new timestamp struct with
> 64-bit fields for the cumulative counters, named snd_compr_tstamp64.
> ASoC drivers are updated to use the 64-bit structures. Corresponding
> ioctls are added to expose them to user-space.
> 
> The series is structured as follows:
> 
> Patch 1: Updates the pointer op, refactors the core logic and ASoC
> drivers to use it, and defines the new UAPI structs.
> 
> Patch 2: Exposes the SNDRV_COMPRESS_TSTAMP64 ioctl.
> 
> Patch 3: Exposes the corresponding SNDRV_COMPRESS_AVAIL64 ioctl.
> 
> This series has been tested on a Pixel 9 device. All compress offload
> use cases, including long-running playback, were verified to work
> correctly with the new 64-bit API.

Acked-by: Vinod Koul <vkoul@kernel.org>

Please updated tinycompress changes with this once this is picked up by
Takashi-san

-- 
~Vinod
Re: [PATCH v5 0/3] ALSA: compress_offload: Add 64-bit safe timestamp API
Posted by Charles Keepax 4 days, 1 hour ago
On Fri, Sep 05, 2025 at 10:12:53AM +0100, Joris Verhaegen wrote:
> The current compress offload timestamping API relies on struct
> snd_compr_tstamp, whose cumulative counters like copied_total are
> defined as __u32. On long-running high-resolution audio streams, these
> 32-bit counters can overflow, causing incorrect availability
> calculations.
> 
> This patch series transitions to a 64-bit safe API to solve the problem
> while maintaining perfect backward compatibility with the existing UAPI.
> The pointer operation is reworked to use a new timestamp struct with
> 64-bit fields for the cumulative counters, named snd_compr_tstamp64.
> ASoC drivers are updated to use the 64-bit structures. Corresponding
> ioctls are added to expose them to user-space.
> 
> The series is structured as follows:
> 
> Patch 1: Updates the pointer op, refactors the core logic and ASoC
> drivers to use it, and defines the new UAPI structs.
> 
> Patch 2: Exposes the SNDRV_COMPRESS_TSTAMP64 ioctl.
> 
> Patch 3: Exposes the corresponding SNDRV_COMPRESS_AVAIL64 ioctl.
> 
> This series has been tested on a Pixel 9 device. All compress offload
> use cases, including long-running playback, were verified to work
> correctly with the new 64-bit API.
> 
> Thanks,
> Joris (George) Verhaegen
> 
> Signed-off-by: Joris Verhaegen <verhaegen@google.com>
> 
> ---

Reviewed-by: Charles Keepax <ckeepax@opensource.cirrus.com>

Thanks,
Charles