From patchwork Thu Apr 26 12:44:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 134514 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp2263687lji; Thu, 26 Apr 2018 05:44:57 -0700 (PDT) X-Google-Smtp-Source: AIpwx4858KcRjE90oPcLR5Uwgdc7/fMDJHbTQGeH9BMGM0E0UlXx1p+3YQsGT2tzSCVYnxULQasZ X-Received: by 2002:adf:8e44:: with SMTP id n62-v6mr28493063wrb.159.1524746697772; Thu, 26 Apr 2018 05:44:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524746697; cv=none; d=google.com; s=arc-20160816; b=0gWDVDFPptF4fX86l0b+EwBPYYLcvuuR059tUqqVFo3368z5ggbi0/980KfLDEMi4c uN7ybXzuTLcHI6hnOvyOiNayWrZBqrQUXeh03EfGyjqbqc0a6qEj0PUKm9xPsqzQ2VNo OAbvKoTrQ4O1uIAzFvlRWdMwZoTJjQnINsLlv2THGa62JEw2C2OGTYTnPZgYp5KBajIe ZF4ILrKKZr1Ith59oq6i/HevBeaIybgiPb+LfIBWoy/awXeBq6IzOU9W2m8TYybyqS1t WE+YYlG8M3B8SLRJ2ekL/wuZ9y617fS+GKC/Qv4YoLdUhLN36/zGQdCK4H8WGBu+NYyj clow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:delivered-to:arc-authentication-results; bh=88YO6kIp4IFqMJUzvxfZETf0LaHbmXPtaClvvTE/4G4=; b=n6Hg4CZeMaPOtKSobXLTd8cgAdjecLacdfV1fNqwMyUmS1sQWrdz+fVr2n9dBGteG2 1BDz+0xmnT3imIcltV8rHEcOxhU26QSVuRXOIU6xZxMaidvJvLcGcOmRU28VYt3mni97 jurrKPr3dKBcMCS8BhzBd2TaFVv239zRDE8XWQS01c4CBA61ofgVgm+Runi2pG+aX6ob 9WXX4nYCoNiSJKgfsJ5T4X0Gw2nrLTVa/t51otWzg8kF87w9bsGtZcjSIz0Ieup3+rTr 5XAEKvonKVA8mUVMgfppcCiMftLBSUXcZnCXI80a2qSdqlEvWPELO3Bv8GaYFvG2+gVO pKmw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of alsa-devel-bounces@alsa-project.org designates 77.48.224.243 as permitted sender) smtp.mailfrom=alsa-devel-bounces@alsa-project.org Return-Path: Received: from alsa0.perex.cz (alsa0.perex.cz. [77.48.224.243]) by mx.google.com with ESMTP id 47-v6si16012471wrc.328.2018.04.26.05.44.57; Thu, 26 Apr 2018 05:44:57 -0700 (PDT) Received-SPF: pass (google.com: domain of alsa-devel-bounces@alsa-project.org designates 77.48.224.243 as permitted sender) client-ip=77.48.224.243; Authentication-Results: mx.google.com; spf=pass (google.com: domain of alsa-devel-bounces@alsa-project.org designates 77.48.224.243 as permitted sender) smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 9C0662677F1; Thu, 26 Apr 2018 14:44:55 +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 A6E092677F6; Thu, 26 Apr 2018 14:44:52 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail1.perex.cz X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2 autolearn=disabled version=3.4.0 Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.126.133]) by alsa0.perex.cz (Postfix) with ESMTP id 3D7DF26779A for ; Thu, 26 Apr 2018 14:44:49 +0200 (CEST) Received: from wuerfel.lan ([95.208.111.237]) by mrelayeu.kundenserver.de (mreue004 [212.227.15.129]) with ESMTPA (Nemesis) id 0Lgc09-1eYpCB3Hld-00nxXq; Thu, 26 Apr 2018 14:44:42 +0200 From: Arnd Bergmann To: y2038@lists.linaro.org, linux-kernel@vger.kernel.org Date: Thu, 26 Apr 2018 14:44:19 +0200 Message-Id: <20180426124422.2921744-2-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20180426124422.2921744-1-arnd@arndb.de> References: <20180426124422.2921744-1-arnd@arndb.de> X-Provags-ID: V03:K1:qzYLM6CVOtmwrPRq4abQ+GcDbPz8Lk+Tkvud2ps5vc70MVi2WTD iSpGX8YFAvRHEyZM+jk/TNEw/CMIPk0hAvDa+zsiNADPW65/fvWb8xfEv2oPlWFvP/X9Faq qnCqG7RzXxPttAJ8dr9Rm7d1/H9Cbanf9qmvphCn9iOuuCPl1POYs8p1TUuTlPknd600xR8 uZvn5wfywyzJ1cPpnvUmw== X-UI-Out-Filterresults: notjunk:1; V01:K0:bgJ1mYyx3Fc=:mh5Xh6GzgHekLptA0tEaCi JexTnzu9qJRUOlbl6hA07ySECy84TvzAEVp/EPaAniNl1k51NroMVWsGMZ9JN9a6oYfKjFXZ9 +sBNqdE1Nw866wMHrYx8Tgk980tFyczS9HlUW0L1B44bgCzggaI1VhgTfRhCVO92IV88WVOnD kTIHEdjP3qyO1nJ+VvN+kDubbZ1w88klkVeeVNkv++yY3JfcQ5bKIFBYkZ+Vz0skNKyTKt4tu JBAr19Fjt2pFKdOVdKF9ies0H+hVSUUSRxcAV8a3vEMxjlLoPS9yeRJcK21ntqTZyLM+B7smw ZgOFsFqbPaeDyGTCg5B5OejX+DLWp29hn/7QdoPLdkb0rnvImNUdZJFLfbzWvyxN5CdRLN2Wq wjudPj0vhWivWs3BOB9ee0g3gpoaD9n9skReb+N5xFc7Bw56Dfuop3jqQbwqMlc1FmBHnQMGg HqD9KvwqDvAd0kfnYFEAOLE04nRasEpo4MnogKi9ANx3pWG95NlqUGk5O9rLL78oD/g2RXMxd 1ZfXZyCrAsz6jGZ1VVNUQ8ynTGFoxg56/FMK7ld8rBjS8EizwNEzwGb6bR7GSbB++a1ZLiX6o s7YTe1MVu4xMKcuyRDkTmXz7CrC+NRQoZcEOtXHOqo5/fqOKtn1KdMOOz31d+aEdj6MvNrM0u TV0HFGHfEYXSky/6x+5je6Vhwc8hmJZ+TQl5J7Wc9UPUWnChfVngEO1SdymkvAcEtWp0= Cc: alsa-devel@alsa-project.org, Arnd Bergmann , Baolin Wang , tiwai@suse.com, lgirdwood@gmail.com, o-takashi@sakamocchi.jp, broonie@kernel.org Subject: [alsa-devel] [PATCH 1/4] ALSA: Replace timespec with timespec64 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 From: Baolin Wang Since timespec is not year 2038 safe on 32bit system, and we need to convert all timespec variables to timespec64 type for sound subsystem. This patch is used to do preparation for following patches, that will convert all structures defined in uapi/sound/asound.h to use 64-bit time_t. Signed-off-by: Baolin Wang [arnd: fix a compile-time bug] Signed-off-by: Arnd Bergmann --- include/sound/pcm.h | 18 +++++++++--------- include/sound/timer.h | 4 ++-- sound/core/pcm_compat.c | 32 ++++++++++++++++++++------------ sound/core/pcm_lib.c | 36 ++++++++++++++++++++++-------------- sound/core/pcm_native.c | 12 ++++++++---- sound/core/timer.c | 28 ++++++++++++++-------------- sound/pci/hda/hda_controller.c | 10 +++++----- sound/soc/intel/skylake/skl-pcm.c | 4 ++-- 8 files changed, 82 insertions(+), 62 deletions(-) -- 2.9.0 _______________________________________________ Alsa-devel mailing list Alsa-devel@alsa-project.org http://mailman.alsa-project.org/mailman/listinfo/alsa-devel diff --git a/include/sound/pcm.h b/include/sound/pcm.h index e054c583d3b3..973d6745217a 100644 --- a/include/sound/pcm.h +++ b/include/sound/pcm.h @@ -75,7 +75,7 @@ struct snd_pcm_ops { int (*trigger)(struct snd_pcm_substream *substream, int cmd); snd_pcm_uframes_t (*pointer)(struct snd_pcm_substream *substream); int (*get_time_info)(struct snd_pcm_substream *substream, - struct timespec *system_ts, struct timespec *audio_ts, + struct timespec64 *system_ts, struct timespec64 *audio_ts, struct snd_pcm_audio_tstamp_config *audio_tstamp_config, struct snd_pcm_audio_tstamp_report *audio_tstamp_report); int (*fill_silence)(struct snd_pcm_substream *substream, int channel, @@ -351,7 +351,7 @@ static inline void snd_pcm_pack_audio_tstamp_report(__u32 *data, __u32 *accuracy struct snd_pcm_runtime { /* -- Status -- */ struct snd_pcm_substream *trigger_master; - struct timespec trigger_tstamp; /* trigger timestamp */ + struct timespec64 trigger_tstamp; /* trigger timestamp */ bool trigger_tstamp_latched; /* trigger timestamp latched in low-level driver/hardware */ int overrange; snd_pcm_uframes_t avail_max; @@ -427,7 +427,7 @@ struct snd_pcm_runtime { /* -- audio timestamp config -- */ struct snd_pcm_audio_tstamp_config audio_tstamp_config; struct snd_pcm_audio_tstamp_report audio_tstamp_report; - struct timespec driver_tstamp; + struct timespec64 driver_tstamp; #if IS_ENABLED(CONFIG_SND_PCM_OSS) /* -- OSS things -- */ @@ -1175,22 +1175,22 @@ static inline void snd_pcm_set_runtime_buffer(struct snd_pcm_substream *substrea } /** - * snd_pcm_gettime - Fill the timespec depending on the timestamp mode + * snd_pcm_gettime - Fill the timespec64 depending on the timestamp mode * @runtime: PCM runtime instance - * @tv: timespec to fill + * @tv: timespec64 to fill */ static inline void snd_pcm_gettime(struct snd_pcm_runtime *runtime, - struct timespec *tv) + struct timespec64 *tv) { switch (runtime->tstamp_type) { case SNDRV_PCM_TSTAMP_TYPE_MONOTONIC: - ktime_get_ts(tv); + ktime_get_ts64(tv); break; case SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW: - getrawmonotonic(tv); + getrawmonotonic64(tv); break; default: - getnstimeofday(tv); + ktime_get_real_ts64(tv); break; } } diff --git a/include/sound/timer.h b/include/sound/timer.h index 7ae226ab6990..91b9baab50f7 100644 --- a/include/sound/timer.h +++ b/include/sound/timer.h @@ -104,7 +104,7 @@ struct snd_timer_instance { unsigned long ticks, unsigned long resolution); void (*ccallback) (struct snd_timer_instance * timeri, int event, - struct timespec * tstamp, + struct timespec64 * tstamp, unsigned long resolution); void (*disconnect)(struct snd_timer_instance *timeri); void *callback_data; @@ -128,7 +128,7 @@ struct snd_timer_instance { */ int snd_timer_new(struct snd_card *card, char *id, struct snd_timer_id *tid, struct snd_timer **rtimer); -void snd_timer_notify(struct snd_timer *timer, int event, struct timespec *tstamp); +void snd_timer_notify(struct snd_timer *timer, int event, struct timespec64 *tstamp); int snd_timer_global_new(char *id, int device, struct snd_timer **rtimer); int snd_timer_global_free(struct snd_timer *timer); int snd_timer_global_register(struct snd_timer *timer); diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c index b719d0bd833e..e21d3f35a724 100644 --- a/sound/core/pcm_compat.c +++ b/sound/core/pcm_compat.c @@ -229,8 +229,10 @@ static int snd_pcm_status_user_compat(struct snd_pcm_substream *substream, if (clear_user(src, sizeof(*src))) return -EFAULT; if (put_user(status.state, &src->state) || - compat_put_timespec(&status.trigger_tstamp, &src->trigger_tstamp) || - compat_put_timespec(&status.tstamp, &src->tstamp) || + put_user(status.trigger_tstamp.tv_sec, &src->trigger_tstamp.tv_sec) || + put_user(status.trigger_tstamp.tv_sec, &src->trigger_tstamp.tv_nsec) || + put_user(status.tstamp.tv_sec, &src->tstamp.tv_sec) || + put_user(status.tstamp.tv_nsec, &src->tstamp.tv_nsec) || put_user(status.appl_ptr, &src->appl_ptr) || put_user(status.hw_ptr, &src->hw_ptr) || put_user(status.delay, &src->delay) || @@ -239,8 +241,10 @@ static int snd_pcm_status_user_compat(struct snd_pcm_substream *substream, put_user(status.overrange, &src->overrange) || put_user(status.suspended_state, &src->suspended_state) || put_user(status.audio_tstamp_data, &src->audio_tstamp_data) || - compat_put_timespec(&status.audio_tstamp, &src->audio_tstamp) || - compat_put_timespec(&status.driver_tstamp, &src->driver_tstamp) || + put_user(status.audio_tstamp.tv_sec, &src->audio_tstamp.tv_sec) || + put_user(status.audio_tstamp.tv_nsec, &src->audio_tstamp.tv_nsec) || + put_user(status.driver_tstamp.tv_sec, &src->driver_tstamp.tv_sec) || + put_user(status.driver_tstamp.tv_nsec, &src->driver_tstamp.tv_nsec) || put_user(status.audio_tstamp_accuracy, &src->audio_tstamp_accuracy)) return -EFAULT; @@ -252,8 +256,8 @@ static int snd_pcm_status_user_compat(struct snd_pcm_substream *substream, struct snd_pcm_status_x32 { s32 state; u32 rsvd; /* alignment */ - struct timespec trigger_tstamp; - struct timespec tstamp; + struct __kernel_timespec trigger_tstamp; + struct __kernel_timespec tstamp; u32 appl_ptr; u32 hw_ptr; s32 delay; @@ -262,8 +266,8 @@ struct snd_pcm_status_x32 { u32 overrange; s32 suspended_state; u32 audio_tstamp_data; - struct timespec audio_tstamp; - struct timespec driver_tstamp; + struct __kernel_timespec audio_tstamp; + struct __kernel_timespec driver_tstamp; u32 audio_tstamp_accuracy; unsigned char reserved[52-2*sizeof(struct timespec)]; } __packed; @@ -293,8 +297,10 @@ static int snd_pcm_status_user_x32(struct snd_pcm_substream *substream, if (clear_user(src, sizeof(*src))) return -EFAULT; if (put_user(status.state, &src->state) || - put_timespec(&status.trigger_tstamp, &src->trigger_tstamp) || - put_timespec(&status.tstamp, &src->tstamp) || + put_user(status.trigger_tstamp.tv_sec, &src->trigger_tstamp.tv_sec) || + put_user(status.trigger_tstamp.tv_sec, &src->trigger_tstamp.tv_nsec) || + put_user(status.tstamp.tv_sec, &src->tstamp.tv_sec) || + put_user(status.tstamp.tv_nsec, &src->tstamp.tv_nsec) || put_user(status.appl_ptr, &src->appl_ptr) || put_user(status.hw_ptr, &src->hw_ptr) || put_user(status.delay, &src->delay) || @@ -303,8 +309,10 @@ static int snd_pcm_status_user_x32(struct snd_pcm_substream *substream, put_user(status.overrange, &src->overrange) || put_user(status.suspended_state, &src->suspended_state) || put_user(status.audio_tstamp_data, &src->audio_tstamp_data) || - put_timespec(&status.audio_tstamp, &src->audio_tstamp) || - put_timespec(&status.driver_tstamp, &src->driver_tstamp) || + put_user(status.audio_tstamp.tv_sec, &src->audio_tstamp.tv_sec) || + put_user(status.audio_tstamp.tv_nsec, &src->audio_tstamp.tv_nsec) || + put_user(status.driver_tstamp.tv_sec, &src->driver_tstamp.tv_sec) || + put_user(status.driver_tstamp.tv_nsec, &src->driver_tstamp.tv_nsec) || put_user(status.audio_tstamp_accuracy, &src->audio_tstamp_accuracy)) return -EFAULT; diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c index f4a19509cccf..9278b5ded9a2 100644 --- a/sound/core/pcm_lib.c +++ b/sound/core/pcm_lib.c @@ -158,8 +158,12 @@ static void xrun(struct snd_pcm_substream *substream) struct snd_pcm_runtime *runtime = substream->runtime; trace_xrun(substream); - if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) - snd_pcm_gettime(runtime, (struct timespec *)&runtime->status->tstamp); + if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) { + struct timespec64 tstamp; + + snd_pcm_gettime(runtime, &tstamp); + runtime->status->tstamp = timespec64_to_timespec(tstamp); + } snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN); if (xrun_debug(substream, XRUN_DEBUG_BASIC)) { char name[16]; @@ -217,12 +221,12 @@ int snd_pcm_update_state(struct snd_pcm_substream *substream, } static void update_audio_tstamp(struct snd_pcm_substream *substream, - struct timespec *curr_tstamp, - struct timespec *audio_tstamp) + struct timespec64 *curr_tstamp, + struct timespec64 *audio_tstamp) { struct snd_pcm_runtime *runtime = substream->runtime; u64 audio_frames, audio_nsecs; - struct timespec driver_tstamp; + struct timespec64 driver_tstamp; if (runtime->tstamp_mode != SNDRV_PCM_TSTAMP_ENABLE) return; @@ -246,18 +250,22 @@ static void update_audio_tstamp(struct snd_pcm_substream *substream, } audio_nsecs = div_u64(audio_frames * 1000000000LL, runtime->rate); - *audio_tstamp = ns_to_timespec(audio_nsecs); + *audio_tstamp = ns_to_timespec64(audio_nsecs); } - if (!timespec_equal(&runtime->status->audio_tstamp, audio_tstamp)) { - runtime->status->audio_tstamp = *audio_tstamp; - runtime->status->tstamp = *curr_tstamp; + + if (runtime->status->audio_tstamp.tv_sec != audio_tstamp->tv_sec || + runtime->status->audio_tstamp.tv_nsec != audio_tstamp->tv_nsec) { + runtime->status->audio_tstamp = + timespec64_to_timespec(*audio_tstamp); + runtime->status->tstamp = timespec64_to_timespec(*curr_tstamp); } + /* * re-take a driver timestamp to let apps detect if the reference tstamp * read by low-level hardware was provided with a delay */ - snd_pcm_gettime(substream->runtime, (struct timespec *)&driver_tstamp); + snd_pcm_gettime(substream->runtime, &driver_tstamp); runtime->driver_tstamp = driver_tstamp; } @@ -270,8 +278,8 @@ static int snd_pcm_update_hw_ptr0(struct snd_pcm_substream *substream, snd_pcm_sframes_t hdelta, delta; unsigned long jdelta; unsigned long curr_jiffies; - struct timespec curr_tstamp; - struct timespec audio_tstamp; + struct timespec64 curr_tstamp; + struct timespec64 audio_tstamp; int crossed_boundary = 0; old_hw_ptr = runtime->status->hw_ptr; @@ -294,9 +302,9 @@ static int snd_pcm_update_hw_ptr0(struct snd_pcm_substream *substream, /* re-test in case tstamp type is not supported in hardware and was demoted to DEFAULT */ if (runtime->audio_tstamp_report.actual_type == SNDRV_PCM_AUDIO_TSTAMP_TYPE_DEFAULT) - snd_pcm_gettime(runtime, (struct timespec *)&curr_tstamp); + snd_pcm_gettime(runtime, &curr_tstamp); } else - snd_pcm_gettime(runtime, (struct timespec *)&curr_tstamp); + snd_pcm_gettime(runtime, &curr_tstamp); } if (pos == SNDRV_PCM_POS_XRUN) { diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index 35ffccea94c3..c57dd4b30198 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -884,12 +884,12 @@ int snd_pcm_status(struct snd_pcm_substream *substream, status->suspended_state = runtime->status->suspended_state; if (status->state == SNDRV_PCM_STATE_OPEN) goto _end; - status->trigger_tstamp = runtime->trigger_tstamp; + status->trigger_tstamp = timespec64_to_timespec(runtime->trigger_tstamp); if (snd_pcm_running(substream)) { snd_pcm_update_hw_ptr(substream); if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) { status->tstamp = runtime->status->tstamp; - status->driver_tstamp = runtime->driver_tstamp; + status->driver_tstamp = timespec64_to_timespec(runtime->driver_tstamp); status->audio_tstamp = runtime->status->audio_tstamp; if (runtime->audio_tstamp_report.valid == 1) @@ -902,8 +902,12 @@ int snd_pcm_status(struct snd_pcm_substream *substream, } } else { /* get tstamp only in fallback mode and only if enabled */ - if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) - snd_pcm_gettime(runtime, &status->tstamp); + if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) { + struct timespec64 tstamp; + + snd_pcm_gettime(runtime, &tstamp); + status->tstamp = timespec64_to_timespec(tstamp); + } } _tstamp_end: status->appl_ptr = runtime->control->appl_ptr; diff --git a/sound/core/timer.c b/sound/core/timer.c index dc87728c5b74..a77b4619f1b7 100644 --- a/sound/core/timer.c +++ b/sound/core/timer.c @@ -73,7 +73,7 @@ struct snd_timer_user { spinlock_t qlock; unsigned long last_resolution; unsigned int filter; - struct timespec tstamp; /* trigger tstamp */ + struct timespec64 tstamp; /* trigger tstamp */ wait_queue_head_t qchange_sleep; struct fasync_struct *fasync; struct mutex ioctl_lock; @@ -448,12 +448,12 @@ static void snd_timer_notify1(struct snd_timer_instance *ti, int event) struct snd_timer *timer; unsigned long resolution = 0; struct snd_timer_instance *ts; - struct timespec tstamp; + struct timespec64 tstamp; if (timer_tstamp_monotonic) - ktime_get_ts(&tstamp); + ktime_get_ts64(&tstamp); else - getnstimeofday(&tstamp); + ktime_get_real_ts64(&tstamp); if (snd_BUG_ON(event < SNDRV_TIMER_EVENT_START || event > SNDRV_TIMER_EVENT_PAUSE)) return; @@ -998,7 +998,7 @@ static int snd_timer_dev_disconnect(struct snd_device *device) return 0; } -void snd_timer_notify(struct snd_timer *timer, int event, struct timespec *tstamp) +void snd_timer_notify(struct snd_timer *timer, int event, struct timespec64 *tstamp) { unsigned long flags; unsigned long resolution = 0; @@ -1295,7 +1295,7 @@ static void snd_timer_user_append_to_tqueue(struct snd_timer_user *tu, static void snd_timer_user_ccallback(struct snd_timer_instance *timeri, int event, - struct timespec *tstamp, + struct timespec64 *tstamp, unsigned long resolution) { struct snd_timer_user *tu = timeri->callback_data; @@ -1309,7 +1309,7 @@ static void snd_timer_user_ccallback(struct snd_timer_instance *timeri, return; memset(&r1, 0, sizeof(r1)); r1.event = event; - r1.tstamp = *tstamp; + r1.tstamp = timespec64_to_timespec(*tstamp); r1.val = resolution; spin_lock_irqsave(&tu->qlock, flags); snd_timer_user_append_to_tqueue(tu, &r1); @@ -1332,7 +1332,7 @@ static void snd_timer_user_tinterrupt(struct snd_timer_instance *timeri, { struct snd_timer_user *tu = timeri->callback_data; struct snd_timer_tread *r, r1; - struct timespec tstamp; + struct timespec64 tstamp; int prev, append = 0; memset(&r1, 0, sizeof(r1)); @@ -1345,14 +1345,14 @@ static void snd_timer_user_tinterrupt(struct snd_timer_instance *timeri, } if (tu->last_resolution != resolution || ticks > 0) { if (timer_tstamp_monotonic) - ktime_get_ts(&tstamp); + ktime_get_ts64(&tstamp); else - getnstimeofday(&tstamp); + ktime_get_real_ts64(&tstamp); } if ((tu->filter & (1 << SNDRV_TIMER_EVENT_RESOLUTION)) && tu->last_resolution != resolution) { r1.event = SNDRV_TIMER_EVENT_RESOLUTION; - r1.tstamp = tstamp; + r1.tstamp = timespec64_to_timespec(tstamp); r1.val = resolution; snd_timer_user_append_to_tqueue(tu, &r1); tu->last_resolution = resolution; @@ -1366,14 +1366,14 @@ static void snd_timer_user_tinterrupt(struct snd_timer_instance *timeri, prev = tu->qtail == 0 ? tu->queue_size - 1 : tu->qtail - 1; r = &tu->tqueue[prev]; if (r->event == SNDRV_TIMER_EVENT_TICK) { - r->tstamp = tstamp; + r->tstamp = timespec64_to_timespec(tstamp); r->val += ticks; append++; goto __wake; } } r1.event = SNDRV_TIMER_EVENT_TICK; - r1.tstamp = tstamp; + r1.tstamp = timespec64_to_timespec(tstamp); r1.val = ticks; snd_timer_user_append_to_tqueue(tu, &r1); append++; @@ -1852,7 +1852,7 @@ static int snd_timer_user_status(struct file *file, if (!tu->timeri) return -EBADFD; memset(&status, 0, sizeof(status)); - status.tstamp = tu->tstamp; + status.tstamp = timespec64_to_timespec(tu->tstamp); status.resolution = snd_timer_resolution(tu->timeri); status.lost = tu->timeri->lost; status.overrun = tu->overrun; diff --git a/sound/pci/hda/hda_controller.c b/sound/pci/hda/hda_controller.c index d1eb14842340..c3e45168b848 100644 --- a/sound/pci/hda/hda_controller.c +++ b/sound/pci/hda/hda_controller.c @@ -502,7 +502,7 @@ static inline bool is_link_time_supported(struct snd_pcm_runtime *runtime, } static int azx_get_time_info(struct snd_pcm_substream *substream, - struct timespec *system_ts, struct timespec *audio_ts, + struct timespec64 *system_ts, struct timespec64 *audio_ts, struct snd_pcm_audio_tstamp_config *audio_tstamp_config, struct snd_pcm_audio_tstamp_report *audio_tstamp_report) { @@ -522,7 +522,7 @@ static int azx_get_time_info(struct snd_pcm_substream *substream, if (audio_tstamp_config->report_delay) nsec = azx_adjust_codec_delay(substream, nsec); - *audio_ts = ns_to_timespec(nsec); + *audio_ts = ns_to_timespec64(nsec); audio_tstamp_report->actual_type = SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK; audio_tstamp_report->accuracy_report = 1; /* rest of structure is valid */ @@ -539,16 +539,16 @@ static int azx_get_time_info(struct snd_pcm_substream *substream, return -EINVAL; case SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW: - *system_ts = ktime_to_timespec(xtstamp.sys_monoraw); + *system_ts = ktime_to_timespec64(xtstamp.sys_monoraw); break; default: - *system_ts = ktime_to_timespec(xtstamp.sys_realtime); + *system_ts = ktime_to_timespec64(xtstamp.sys_realtime); break; } - *audio_ts = ktime_to_timespec(xtstamp.device); + *audio_ts = ktime_to_timespec64(xtstamp.device); audio_tstamp_report->actual_type = SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK_SYNCHRONIZED; diff --git a/sound/soc/intel/skylake/skl-pcm.c b/sound/soc/intel/skylake/skl-pcm.c index 15cb8ac3e374..a69b56fc3417 100644 --- a/sound/soc/intel/skylake/skl-pcm.c +++ b/sound/soc/intel/skylake/skl-pcm.c @@ -1163,7 +1163,7 @@ static u64 skl_adjust_codec_delay(struct snd_pcm_substream *substream, } static int skl_get_time_info(struct snd_pcm_substream *substream, - struct timespec *system_ts, struct timespec *audio_ts, + struct timespec64 *system_ts, struct timespec64 *audio_ts, struct snd_pcm_audio_tstamp_config *audio_tstamp_config, struct snd_pcm_audio_tstamp_report *audio_tstamp_report) { @@ -1181,7 +1181,7 @@ static int skl_get_time_info(struct snd_pcm_substream *substream, if (audio_tstamp_config->report_delay) nsec = skl_adjust_codec_delay(substream, nsec); - *audio_ts = ns_to_timespec(nsec); + *audio_ts = ns_to_timespec64(nsec); audio_tstamp_report->actual_type = SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK; audio_tstamp_report->accuracy_report = 1; /* rest of struct is valid */ From patchwork Thu Apr 26 12:44:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 134516 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp2264443lji; Thu, 26 Apr 2018 05:45:30 -0700 (PDT) X-Google-Smtp-Source: AIpwx49w6ivWiw7kptfclkLwB/6ybapCAzQa1Kz/xSBsFsq4JOH+1Lt5IpRnO7A3/phjDgqOMSRz X-Received: by 2002:adf:b004:: with SMTP id f4-v6mr28295245wra.75.1524746730906; Thu, 26 Apr 2018 05:45:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524746730; cv=none; d=google.com; s=arc-20160816; b=LdUIgh/4IY8z4h2YPfjmr+cfpWxuWxPnZ036DhxSnDg74A8o/T9zTNMizUkVNKzk19 1ZWxUYVSn80OdVRglHr/GFEV9pNKy4ecnwcA1wkHGeGz6LWa+ZwKdG3cLL9gq0EDe3Z3 Z5sSfgT58K90nH27mXDziotqWG/GSBPMyLk5302F1jerZDt71daS1WAvpgeD3eiYwyf8 CeDQl3k32MJ0sTMOjN6mGVb3FJwG8zUehIGqggHufs6r/v+pj+iV7TOL/xIpLBVP/rHa D2gQLejo9gbf3d9BuQLak4LBL8XNVSQOAyRYc1VSi6JSZ+FL1UW00H91VjkvMBWEnyFI 6M6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:delivered-to:arc-authentication-results; bh=7Erf8dQMgLQKJ6n1wvSR4yz8Vu78nX90N0f0WHDgpts=; b=H89ja9KTLCOYLcr2KTAXUgc+gemb0WLPz+NXPKYSBC5W2K/UHjJ9sfe5jj7JX2Wm3P kNwznEzZN5G4gcoMI0b6n2lTrHFYo2Z3X5p9pNuCggQGo8o+Tah8sbHBZv7PAFJGY4YC 066pV5mHtlNS+y57tUJ2/1Tb9bJa8gyRsdhpXx1RqXmkd9GtIgGWb5AdIQcK0V/jVPeV 6gmY4ux8XqVFXv6lkO8POZk69MoLPVg6aCEGOe5m1OPN4yAJncow4nyjbSYWVG+w+/nT 8jSJbn0Ve4zeae7tzHdso2Ngf6AyuPwimVh9XF7+EgV/wjpcg1Qt7yqEYHc96pdaE9OD kanw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of alsa-devel-bounces@alsa-project.org designates 77.48.224.243 as permitted sender) smtp.mailfrom=alsa-devel-bounces@alsa-project.org Return-Path: Received: from alsa0.perex.cz (alsa0.perex.cz. [77.48.224.243]) by mx.google.com with ESMTP id 200si9374423wmb.15.2018.04.26.05.45.30; Thu, 26 Apr 2018 05:45:30 -0700 (PDT) Received-SPF: pass (google.com: domain of alsa-devel-bounces@alsa-project.org designates 77.48.224.243 as permitted sender) client-ip=77.48.224.243; Authentication-Results: mx.google.com; spf=pass (google.com: domain of alsa-devel-bounces@alsa-project.org designates 77.48.224.243 as permitted sender) smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 0B96B26782F; Thu, 26 Apr 2018 14:45:25 +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 311D4267812; Thu, 26 Apr 2018 14:45:22 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail1.perex.cz X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2 autolearn=disabled version=3.4.0 Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.126.187]) by alsa0.perex.cz (Postfix) with ESMTP id 2CFEE2677F6 for ; Thu, 26 Apr 2018 14:45:19 +0200 (CEST) Received: from wuerfel.lan ([95.208.111.237]) by mrelayeu.kundenserver.de (mreue004 [212.227.15.129]) with ESMTPA (Nemesis) id 0Le9A8-1ebIAK1pKW-00psI3; Thu, 26 Apr 2018 14:44:44 +0200 From: Arnd Bergmann To: y2038@lists.linaro.org, linux-kernel@vger.kernel.org Date: Thu, 26 Apr 2018 14:44:20 +0200 Message-Id: <20180426124422.2921744-3-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20180426124422.2921744-1-arnd@arndb.de> References: <20180426124422.2921744-1-arnd@arndb.de> X-Provags-ID: V03:K1:TDTPdewdp6MHvn7a74pHVhc+qASKxsLqxuFEZBUL+xm39HbziuE PcSLB5uC5i74pR2w0j5l1HR4hWRXxlcPn/3xevUlzR1zGfg8+2z83YNlSk2XVYd7gqXoIhx j61Oiwi8hiQIqeFe7nzwzeO9YAytxuwKohZ/SxLqQA9REwGxPKvzqjpWYPhop89L0Xo1S9Y XdQvcgjAuKpXphn+U6dhA== X-UI-Out-Filterresults: notjunk:1; V01:K0:LLyQxPRrTgI=:o+mVQxtCkX+amY035mknlC JBBoPo0GplMRWK+buOr1uydoctmzJbapsuGCdG1LV4f0zabdg+4lto6gw1UOomv17utPSVWUx rd215x3kRdPARCQ7rWQmT+XVkKr08pSucdGFG7abW+LZDS6RBLFTHgzsMydirgMrvzs1Gpe3C pY5BowdO/h89yJ02tnpYlkTewmw62M0ZkX8JMoLnpMJt7U4sWy8HX1OImxywxs4d+0e/G4rWW 6QJBayPzpjlu0Jyk8ceLgSKtYh0zAWDg7X3aztM1ArqWo2TGZFjmM0SgFiw5P7C+PvbzMI5mh yw8VpCDrQzIe5nO6XH6jP+OiHe363+xGKU4XyudH6fknT/fAPQoTXlAFErulAKC6okfoa5e7s prVnSqh/qteu2NvqJpHH88e/hrQqKiXZUMc+B3G1HN85WShO+rTl7qb7NZzs4DpTXA3OWwe26 RGdW/wVd7BbiVfG7Ikm4sEnC38MM6Veyxze7+z+qoFL7APka0rxErqJATg9YfpMIcGQmqAfmi 7hBIOD2zmvD5DaW+YtGLrKBPSv5QGe6HPbaqdoRVd/49g4N8A2FaZ29yImlpUxRMmiwMJBmS4 OWuH+5t8blY8v84MtfaGkKZQyh0EQf5QbV4Vk8XgfImZ453+Y9VzvlRzvRwI8ktQzCQlKeQhg iG1xF1fY5zI7FHUuj3DhJuLOieqJdLPQhfL+P9jYGWKvQS5rVeRjwhDEaYcMRi4sOOig= Cc: alsa-devel@alsa-project.org, Arnd Bergmann , Baolin Wang , tiwai@suse.com, lgirdwood@gmail.com, o-takashi@sakamocchi.jp, broonie@kernel.org Subject: [alsa-devel] [PATCH 2/4] ALSA: Avoid using timespec for struct snd_ctl_elem_value 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 From: Baolin Wang The struct snd_ctl_elem_value will use 'timespec' type variables to record timestamp, which is not year 2038 safe on 32bits system. Since there are no drivers will implemented the tstamp member of the struct snd_ctl_elem_value, and also the stucture size will not be changed if we change timespec to s64 for tstamp member of struct snd_ctl_elem_value. >From Takashi's comments, "In the library, applications are not expected to access to this structure directly. The applications get opaque pointer to the structure and must use any control APIs to operate it. Actually the library produce no API to handle 'struct snd_ctl_elem_value.tstamp'. This means that we can drop this member from alsa-lib without decline of functionality." Thus we can simply remove the tstamp member to avoid using the type which is not year 2038 safe on 32bits system. Signed-off-by: Baolin Wang Signed-off-by: Arnd Bergmann --- include/uapi/sound/asound.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) -- 2.9.0 _______________________________________________ Alsa-devel mailing list Alsa-devel@alsa-project.org http://mailman.alsa-project.org/mailman/listinfo/alsa-devel diff --git a/include/uapi/sound/asound.h b/include/uapi/sound/asound.h index ed0a120d4f08..1231f0a943f1 100644 --- a/include/uapi/sound/asound.h +++ b/include/uapi/sound/asound.h @@ -954,8 +954,7 @@ struct snd_ctl_elem_value { } bytes; struct snd_aes_iec958 iec958; } value; /* RO */ - struct timespec tstamp; - unsigned char reserved[128-sizeof(struct timespec)]; + unsigned char reserved[128]; }; struct snd_ctl_tlv { From patchwork Thu Apr 26 12:44:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 134518 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp2264802lji; Thu, 26 Apr 2018 05:45:47 -0700 (PDT) X-Google-Smtp-Source: AIpwx49M7oL4+d1EcvF4F+NSGLhkW98YCudB/HJcKL71tDCEvl+aao2HzzUCASE9ejiQarXq2HCa X-Received: by 2002:adf:9287:: with SMTP id 7-v6mr19379837wrn.67.1524746747046; Thu, 26 Apr 2018 05:45:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524746747; cv=none; d=google.com; s=arc-20160816; b=siVLt5+f1XB6djLjPviYdUyB/g6mZM6wzzJlXCOQ5oQNUqoDvM42w2zibxZ/CH+EoZ 8/c7JJE2U3fg4lNkjOBcAgCZUNoCeRFPATCGBX3t7cMAfWir/z86xoU7QSXwaT70/hMC 8YFW6mXICrxynXBSr2nvlRI9Fo2cBGaoB3/0F5J6uEC6TzvMlgMiS6QSjMgORfca5dQ8 kxT/f15ExYy3H7MYljnjG+9RMejF8WGhKaKmcHG5wPUVYU1MqYlOMv5evjEWctlg4CjC iKtEMjiiY+yr0pB0UQkkskgJVSifxhPE+HRXB/dDi1fWa4PMZH70ETCweHH28khUyASX 24zQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:delivered-to:arc-authentication-results; bh=SawwOcAImK5301Amh+iUYz54aP8jq4pVcPRe1MK7D7w=; b=EbHRrlPeF/EbMByNpLMkHBDuZ18xPVq0Qmy7SVVUkmKMXRpEVYqouPW17X+cLmnJU6 z9nR7zSAqLg/FNR/EdIA8OCIc027RbcrAfYiI0xiJSSEOBYHuOW8nRp3+X5+ou7i9xh+ VYucZt4xHxq5rXocA8zUllbuG0mQYpst43Cn9HJUHguE3qjgajzZIL+0XQNZvjRYxrYc oL6TzHvGilw1yCSdR4DRYmjqs//H3RNXagUzAN9VeVvjl4tEGWhgUxjv6foAW3rTygKI cnkz1STI9S8DBGlwMWs/R1JN/DQy8Q9uHkHzpNH81bGpWn8gNqp/cmFJ4DQO/IispGQV lmRw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of alsa-devel-bounces@alsa-project.org designates 77.48.224.243 as permitted sender) smtp.mailfrom=alsa-devel-bounces@alsa-project.org Return-Path: Received: from alsa0.perex.cz (alsa0.perex.cz. [77.48.224.243]) by mx.google.com with ESMTP id 62-v6si3129002wrd.230.2018.04.26.05.45.46; Thu, 26 Apr 2018 05:45:47 -0700 (PDT) Received-SPF: pass (google.com: domain of alsa-devel-bounces@alsa-project.org designates 77.48.224.243 as permitted sender) client-ip=77.48.224.243; Authentication-Results: mx.google.com; spf=pass (google.com: domain of alsa-devel-bounces@alsa-project.org designates 77.48.224.243 as permitted sender) smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 14D11267837; Thu, 26 Apr 2018 14:45:31 +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 8EC30267845; Thu, 26 Apr 2018 14:45:26 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail1.perex.cz X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_DNSWL_NONE autolearn=disabled version=3.4.0 Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.126.131]) by alsa0.perex.cz (Postfix) with ESMTP id B0B7926782E for ; Thu, 26 Apr 2018 14:45:23 +0200 (CEST) Received: from wuerfel.lan ([95.208.111.237]) by mrelayeu.kundenserver.de (mreue004 [212.227.15.129]) with ESMTPA (Nemesis) id 0Mefts-1f0cac0O88-00OGjL; Thu, 26 Apr 2018 14:44:46 +0200 From: Arnd Bergmann To: y2038@lists.linaro.org, linux-kernel@vger.kernel.org Date: Thu, 26 Apr 2018 14:44:21 +0200 Message-Id: <20180426124422.2921744-4-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20180426124422.2921744-1-arnd@arndb.de> References: <20180426124422.2921744-1-arnd@arndb.de> X-Provags-ID: V03:K1:3iUdw2ouGME42UZgjbae7U/3KQRQWezzIH+ahdu44WXvDLR27Rg wj024UFjf6ZB+yB3VI1PjtfqXhjpGijwFU8brVXKAPTZOlsmX4zhiW1qEjsIw4uoqaU00Xq eMW42tATGDSJbYjgBMR9dL9hBzI8otAMWRB59BPX4BXdsLExh+dO8QY1Lb+gEbHAR61dXlL AmEJSi0xCp7fsf3F1zPTw== X-UI-Out-Filterresults: notjunk:1; V01:K0:5IV4do7FqX8=:FfwKp9qh+5ClKlqSsHunI9 z1ac6LZrn4hq+z9YCY1JRrHyJQubz8dJ76XrGo+DGgbDutOYa6VNfFE0kFU/KiTif0utAMKYu +mzWD5oU/36lVQlEIkvd2vWCOeXJY9iZhcJZO1XNY4TgAjBu23ItkYcXroundnEYqRlSzSX1p iTw6UuC/50mVj5VzG19dC+uNRRfhkLw7lldE2l/Zkxg3jVi9Eh+p3Y4ok0x0EUQBosthGkZ0P SnK1aj7trZ/jg8EsLD21PYm8PFaaUibMf75MinJ0KnFzxR4MazZgVBii9uggiBx5PsJEqTifr pgD+qtyUFDam1HGay/+thjmUFOWRayGfYYBJyD1f/AWDdtkLIjQwuSbL0ezQI7DUIsTJLvml+ jZnksgeMwc5qvPEfelyXfV66ttk9qmDc8owejYnSvszik0x5FHVWBgwbopDd7yv7G7WC5Bf4B +NivP+Ej0qdd6l4LI6iRn7JlSV4FWfS7PMl8WF5tItJuNgl8yGXfp5yhu5STx4MFu5cLBymUX LFs9Gz66rOy9lGyfsLtnLcEuI5Ojd39Gp/s0ZK/jb1SoAOzdzvxK+qjF7bjuEn509I3j/vxox N6C4G/qWxQa7Oz0rzLNNvV1FtfPfo9P01ZkDcqWc9rnQftsh0/P5853bnHoI+cEBFG82TWkjF 2tZOtLOT+dIGMR5U7i4Aol0DJ8K4cg6GfHqh0Wjpm4f03rXlc3NYtyM7TmyYpdDID/XU= Cc: alsa-devel@alsa-project.org, Arnd Bergmann , Baolin Wang , tiwai@suse.com, lgirdwood@gmail.com, o-takashi@sakamocchi.jp, broonie@kernel.org Subject: [alsa-devel] [PATCH 3/4] ALSA: replace timespec types in uapi headers 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 This changes the user API for ALSA to not rely on time_t as the type any more, so it can survive the update to new C libraries that redefine time_t to 64 bit. This is a much simpler approach than earlier patches, simply defining the API to use '__kernel_ulong_t' for tv_sec and tv_nsec, keeping the existing binary interface but changing the way we express it. The downside of this approach is that it requires significant user space changes in alsa-lib and simialr projects in order to convert back the 32-bit timestamps into 'timespec' for consumption by applications, and that it requires using monotonic timestamps to avoid overflowing a timespec in y2038. To try to counter the incompatibility with existing user sources, the new type is only used when __USE_TIME_BITS64 is set. This gets defined by glibc when an application is compiled with 64-bit time_t. Unfortunately, existing alsa-lib releases come with their own copy of sound/asound.h and don't use the version provided by the linux/libc headers, so alsa-lib is still silently broken when rebuilt with a new libc until it gets updated to use the new header. I also try to be extra conservative with the naming of the structure, giving it the rather long name 'snd_monotonic_timestamp' to clarify that this can only be used for monotonic timestamps after we have decided not to extend the current interface to 64 bit stamps. A separate patch is used to allow enforcing the use of monotonic timestamps in the kernel. Signed-off-by: Arnd Bergmann --- include/sound/asound.h | 8 ++++++++ include/uapi/sound/asound.h | 46 +++++++++++++++++++++++++++++++++++---------- sound/core/compat.h | 11 +++++++++++ sound/core/pcm_compat.c | 38 +++++++++++++++++++------------------ sound/core/pcm_lib.c | 6 +++--- sound/core/pcm_native.c | 9 ++++----- sound/core/rawmidi_compat.c | 12 ++++++------ sound/core/timer.c | 10 +++++----- sound/core/timer_compat.c | 4 +++- 9 files changed, 96 insertions(+), 48 deletions(-) create mode 100644 sound/core/compat.h -- 2.9.0 _______________________________________________ Alsa-devel mailing list Alsa-devel@alsa-project.org http://mailman.alsa-project.org/mailman/listinfo/alsa-devel diff --git a/include/sound/asound.h b/include/sound/asound.h index c2dff5369d33..8c919eb9bb45 100644 --- a/include/sound/asound.h +++ b/include/sound/asound.h @@ -37,4 +37,12 @@ #endif #include + + +static inline struct snd_monotonic_timestamp +timespec64_to_snd_monotonic_timestamp(struct timespec64 ts) +{ + return (struct snd_monotonic_timestamp) { (u32)ts.tv_sec, ts.tv_nsec }; +}; + #endif /* __SOUND_ASOUND_H */ diff --git a/include/uapi/sound/asound.h b/include/uapi/sound/asound.h index 1231f0a943f1..9c61cf77beb8 100644 --- a/include/uapi/sound/asound.h +++ b/include/uapi/sound/asound.h @@ -455,10 +455,36 @@ enum { SNDRV_PCM_AUDIO_TSTAMP_TYPE_LAST = SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK_SYNCHRONIZED }; +#if (__BITS_PER_LONG == 32 && defined(__USE_TIME_BITS64)) || defined __KERNEL__ +/* + * We used to use 'struct timespec' here, but that no longer works on + * 32 bit architectures since the migration to 64-bit time_t in user + * space. Rather than updating all ioctls, we change the internal type + * to a new one with the same binary layout as before. + * + * We use a 'unsigned long' as the base type here to give us a little + * extra range over the traditional signed type, but this really + * should only be used for CLOCK_MONOTONIC timestamps, not CLOCK_REALTIME, + * to avoid all issues with y2038 overflow, hence the name. + * + * alsa-lib 1.1.6 and earlier are incompatible with this definition and + * will break either at compile time or at runtime if built against + * an older header while using a 64-bit time_t on a 32-bit architecture, + * so if you run into a build problem here, please upgrade to the latest + * alsa-lib. + */ +struct snd_monotonic_timestamp { + __kernel_ulong_t tv_sec; + __kernel_ulong_t tv_nsec; +}; +#else +#define snd_monotonic_timestamp timespec +#endif + struct snd_pcm_status { snd_pcm_state_t state; /* stream state */ - struct timespec trigger_tstamp; /* time when stream was started/stopped/paused */ - struct timespec tstamp; /* reference timestamp */ + struct snd_monotonic_timestamp trigger_tstamp;/* time when stream was started/stopped/paused */ + struct snd_monotonic_timestamp tstamp; /* reference timestamp */ snd_pcm_uframes_t appl_ptr; /* appl ptr */ snd_pcm_uframes_t hw_ptr; /* hw ptr */ snd_pcm_sframes_t delay; /* current delay in frames */ @@ -467,19 +493,19 @@ struct snd_pcm_status { snd_pcm_uframes_t overrange; /* count of ADC (capture) overrange detections from last status */ snd_pcm_state_t suspended_state; /* suspended stream state */ __u32 audio_tstamp_data; /* needed for 64-bit alignment, used for configs/report to/from userspace */ - struct timespec audio_tstamp; /* sample counter, wall clock, PHC or on-demand sync'ed */ - struct timespec driver_tstamp; /* useful in case reference system tstamp is reported with delay */ + struct snd_monotonic_timestamp audio_tstamp; /* sample counter, wall clock, PHC or on-demand sync'ed */ + struct snd_monotonic_timestamp driver_tstamp; /* useful in case reference system tstamp is reported with delay */ __u32 audio_tstamp_accuracy; /* in ns units, only valid if indicated in audio_tstamp_data */ - unsigned char reserved[52-2*sizeof(struct timespec)]; /* must be filled with zero */ + unsigned char reserved[52-2*sizeof(struct snd_monotonic_timestamp)]; /* must be filled with zero */ }; struct snd_pcm_mmap_status { snd_pcm_state_t state; /* RO: state - SNDRV_PCM_STATE_XXXX */ int pad1; /* Needed for 64 bit alignment */ snd_pcm_uframes_t hw_ptr; /* RO: hw ptr (0...boundary-1) */ - struct timespec tstamp; /* Timestamp */ + struct snd_monotonic_timestamp tstamp; /* Timestamp */ snd_pcm_state_t suspended_state; /* RO: suspended stream state */ - struct timespec audio_tstamp; /* from sample counter or wall clock */ + struct snd_monotonic_timestamp audio_tstamp; /* from sample counter or wall clock */ }; struct snd_pcm_mmap_control { @@ -649,7 +675,7 @@ struct snd_rawmidi_params { struct snd_rawmidi_status { int stream; - struct timespec tstamp; /* Timestamp */ + struct snd_monotonic_timestamp tstamp; /* Timestamp */ size_t avail; /* available bytes */ size_t xruns; /* count of overruns since last status (in bytes) */ unsigned char reserved[16]; /* reserved for future use */ @@ -761,7 +787,7 @@ struct snd_timer_params { }; struct snd_timer_status { - struct timespec tstamp; /* Timestamp - last update */ + struct snd_monotonic_timestamp tstamp; /* Timestamp - last update */ unsigned int resolution; /* current period resolution in ns */ unsigned int lost; /* counter of master tick lost */ unsigned int overrun; /* count of read queue overruns */ @@ -811,7 +837,7 @@ enum { struct snd_timer_tread { int event; - struct timespec tstamp; + struct snd_monotonic_timestamp tstamp; unsigned int val; }; diff --git a/sound/core/compat.h b/sound/core/compat.h new file mode 100644 index 000000000000..7a08d6e34955 --- /dev/null +++ b/sound/core/compat.h @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: GPL-2.0 + +#ifndef SND_CORE_COMPAT_H +#define SND_CORE_COMPAT_H + +struct compat_snd_monotonic_timestamp { + __u32 tv_sec; + __u32 tv_nsec; +}; + +#endif diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c index e21d3f35a724..40e9be542322 100644 --- a/sound/core/pcm_compat.c +++ b/sound/core/pcm_compat.c @@ -23,6 +23,8 @@ #include #include +#include "compat.h" + static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream, s32 __user *src) { @@ -189,8 +191,8 @@ static int snd_pcm_channel_info_user(struct snd_pcm_substream *substream, struct snd_pcm_status32 { s32 state; - struct compat_timespec trigger_tstamp; - struct compat_timespec tstamp; + struct compat_snd_monotonic_timestamp trigger_tstamp; + struct compat_snd_monotonic_timestamp tstamp; u32 appl_ptr; u32 hw_ptr; s32 delay; @@ -199,10 +201,10 @@ struct snd_pcm_status32 { u32 overrange; s32 suspended_state; u32 audio_tstamp_data; - struct compat_timespec audio_tstamp; - struct compat_timespec driver_tstamp; + struct compat_snd_monotonic_timestamp audio_tstamp; + struct compat_snd_monotonic_timestamp driver_tstamp; u32 audio_tstamp_accuracy; - unsigned char reserved[52-2*sizeof(struct compat_timespec)]; + unsigned char reserved[52-2*sizeof(struct compat_snd_monotonic_timestamp)]; } __attribute__((packed)); @@ -269,11 +271,9 @@ struct snd_pcm_status_x32 { struct __kernel_timespec audio_tstamp; struct __kernel_timespec driver_tstamp; u32 audio_tstamp_accuracy; - unsigned char reserved[52-2*sizeof(struct timespec)]; + unsigned char reserved[52-2*sizeof(struct __kernel_timespec)]; } __packed; -#define put_timespec(src, dst) copy_to_user(dst, src, sizeof(*dst)) - static int snd_pcm_status_user_x32(struct snd_pcm_substream *substream, struct snd_pcm_status_x32 __user *src, bool ext) @@ -461,14 +461,13 @@ static int snd_pcm_ioctl_xfern_compat(struct snd_pcm_substream *substream, return err; } - struct snd_pcm_mmap_status32 { s32 state; s32 pad1; u32 hw_ptr; - struct compat_timespec tstamp; + struct compat_snd_monotonic_timestamp tstamp; s32 suspended_state; - struct compat_timespec audio_tstamp; + struct compat_snd_monotonic_timestamp audio_tstamp; } __attribute__((packed)); struct snd_pcm_mmap_control32 { @@ -535,10 +534,11 @@ static int snd_pcm_ioctl_sync_ptr_compat(struct snd_pcm_substream *substream, snd_pcm_stream_unlock_irq(substream); if (put_user(sstatus.state, &src->s.status.state) || put_user(sstatus.hw_ptr, &src->s.status.hw_ptr) || - compat_put_timespec(&sstatus.tstamp, &src->s.status.tstamp) || + put_user(sstatus.tstamp.tv_sec, &src->s.status.tstamp.tv_sec) || + put_user(sstatus.tstamp.tv_nsec, &src->s.status.tstamp.tv_nsec) || put_user(sstatus.suspended_state, &src->s.status.suspended_state) || - compat_put_timespec(&sstatus.audio_tstamp, - &src->s.status.audio_tstamp) || + put_user(sstatus.audio_tstamp.tv_sec, &src->s.status.audio_tstamp.tv_sec) || + put_user(sstatus.audio_tstamp.tv_nsec, &src->s.status.audio_tstamp.tv_nsec) || put_user(scontrol.appl_ptr, &src->c.control.appl_ptr) || put_user(scontrol.avail_min, &src->c.control.avail_min)) return -EFAULT; @@ -553,10 +553,10 @@ struct snd_pcm_mmap_status_x32 { s32 pad1; u32 hw_ptr; u32 pad2; /* alignment */ - struct timespec tstamp; + struct __kernel_timespec tstamp; s32 suspended_state; s32 pad3; - struct timespec audio_tstamp; + struct __kernel_timespec audio_tstamp; } __packed; struct snd_pcm_mmap_control_x32 { @@ -624,9 +624,11 @@ static int snd_pcm_ioctl_sync_ptr_x32(struct snd_pcm_substream *substream, snd_pcm_stream_unlock_irq(substream); if (put_user(sstatus.state, &src->s.status.state) || put_user(sstatus.hw_ptr, &src->s.status.hw_ptr) || - put_timespec(&sstatus.tstamp, &src->s.status.tstamp) || + put_user(sstatus.tstamp.tv_sec, &src->s.status.tstamp.tv_sec) || + put_user(sstatus.tstamp.tv_nsec, &src->s.status.tstamp.tv_nsec) || put_user(sstatus.suspended_state, &src->s.status.suspended_state) || - put_timespec(&sstatus.audio_tstamp, &src->s.status.audio_tstamp) || + put_user(sstatus.audio_tstamp.tv_sec, &src->s.status.audio_tstamp.tv_sec) || + put_user(sstatus.audio_tstamp.tv_nsec, &src->s.status.audio_tstamp.tv_nsec) || put_user(scontrol.appl_ptr, &src->c.control.appl_ptr) || put_user(scontrol.avail_min, &src->c.control.avail_min)) return -EFAULT; diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c index 9278b5ded9a2..e676356bd3be 100644 --- a/sound/core/pcm_lib.c +++ b/sound/core/pcm_lib.c @@ -162,7 +162,7 @@ static void xrun(struct snd_pcm_substream *substream) struct timespec64 tstamp; snd_pcm_gettime(runtime, &tstamp); - runtime->status->tstamp = timespec64_to_timespec(tstamp); + runtime->status->tstamp = timespec64_to_snd_monotonic_timestamp(tstamp); } snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN); if (xrun_debug(substream, XRUN_DEBUG_BASIC)) { @@ -256,8 +256,8 @@ static void update_audio_tstamp(struct snd_pcm_substream *substream, if (runtime->status->audio_tstamp.tv_sec != audio_tstamp->tv_sec || runtime->status->audio_tstamp.tv_nsec != audio_tstamp->tv_nsec) { runtime->status->audio_tstamp = - timespec64_to_timespec(*audio_tstamp); - runtime->status->tstamp = timespec64_to_timespec(*curr_tstamp); + timespec64_to_snd_monotonic_timestamp(*audio_tstamp); + runtime->status->tstamp = timespec64_to_snd_monotonic_timestamp(*curr_tstamp); } diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index c57dd4b30198..d27c6252e14c 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -884,14 +884,13 @@ int snd_pcm_status(struct snd_pcm_substream *substream, status->suspended_state = runtime->status->suspended_state; if (status->state == SNDRV_PCM_STATE_OPEN) goto _end; - status->trigger_tstamp = timespec64_to_timespec(runtime->trigger_tstamp); + status->trigger_tstamp = timespec64_to_snd_monotonic_timestamp(runtime->trigger_tstamp); if (snd_pcm_running(substream)) { snd_pcm_update_hw_ptr(substream); if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) { status->tstamp = runtime->status->tstamp; - status->driver_tstamp = timespec64_to_timespec(runtime->driver_tstamp); - status->audio_tstamp = - runtime->status->audio_tstamp; + status->driver_tstamp = timespec64_to_snd_monotonic_timestamp(runtime->driver_tstamp); + status->audio_tstamp = runtime->status->audio_tstamp; if (runtime->audio_tstamp_report.valid == 1) /* backwards compatibility, no report provided in COMPAT mode */ snd_pcm_pack_audio_tstamp_report(&status->audio_tstamp_data, @@ -906,7 +905,7 @@ int snd_pcm_status(struct snd_pcm_substream *substream, struct timespec64 tstamp; snd_pcm_gettime(runtime, &tstamp); - status->tstamp = timespec64_to_timespec(tstamp); + status->tstamp = timespec64_to_snd_monotonic_timestamp(tstamp); } } _tstamp_end: diff --git a/sound/core/rawmidi_compat.c b/sound/core/rawmidi_compat.c index f69764d7cdd7..bf8b0c9da690 100644 --- a/sound/core/rawmidi_compat.c +++ b/sound/core/rawmidi_compat.c @@ -55,7 +55,7 @@ static int snd_rawmidi_ioctl_params_compat(struct snd_rawmidi_file *rfile, struct snd_rawmidi_status32 { s32 stream; - struct compat_timespec tstamp; + struct snd_monotonic_timestamp tstamp; u32 avail; u32 xruns; unsigned char reserved[16]; @@ -85,7 +85,8 @@ static int snd_rawmidi_ioctl_status_compat(struct snd_rawmidi_file *rfile, if (err < 0) return err; - if (compat_put_timespec(&status.tstamp, &src->tstamp) || + if (put_user(status.tstamp.tv_sec, &src->tstamp.tv_sec) || + put_user(status.tstamp.tv_nsec, &src->tstamp.tv_nsec) || put_user(status.avail, &src->avail) || put_user(status.xruns, &src->xruns)) return -EFAULT; @@ -98,14 +99,12 @@ static int snd_rawmidi_ioctl_status_compat(struct snd_rawmidi_file *rfile, struct snd_rawmidi_status_x32 { s32 stream; u32 rsvd; /* alignment */ - struct timespec tstamp; + struct __kernel_timespec tstamp; u32 avail; u32 xruns; unsigned char reserved[16]; } __attribute__((packed)); -#define put_timespec(src, dst) copy_to_user(dst, src, sizeof(*dst)) - static int snd_rawmidi_ioctl_status_x32(struct snd_rawmidi_file *rfile, struct snd_rawmidi_status_x32 __user *src) { @@ -130,7 +129,8 @@ static int snd_rawmidi_ioctl_status_x32(struct snd_rawmidi_file *rfile, if (err < 0) return err; - if (put_timespec(&status.tstamp, &src->tstamp) || + if (put_user(status.tstamp.tv_sec, &src->tstamp.tv_sec) || + put_user(status.tstamp.tv_nsec, &src->tstamp.tv_nsec) || put_user(status.avail, &src->avail) || put_user(status.xruns, &src->xruns)) return -EFAULT; diff --git a/sound/core/timer.c b/sound/core/timer.c index a77b4619f1b7..b7059a9e9edc 100644 --- a/sound/core/timer.c +++ b/sound/core/timer.c @@ -1309,7 +1309,7 @@ static void snd_timer_user_ccallback(struct snd_timer_instance *timeri, return; memset(&r1, 0, sizeof(r1)); r1.event = event; - r1.tstamp = timespec64_to_timespec(*tstamp); + r1.tstamp = timespec64_to_snd_monotonic_timestamp(*tstamp); r1.val = resolution; spin_lock_irqsave(&tu->qlock, flags); snd_timer_user_append_to_tqueue(tu, &r1); @@ -1352,7 +1352,7 @@ static void snd_timer_user_tinterrupt(struct snd_timer_instance *timeri, if ((tu->filter & (1 << SNDRV_TIMER_EVENT_RESOLUTION)) && tu->last_resolution != resolution) { r1.event = SNDRV_TIMER_EVENT_RESOLUTION; - r1.tstamp = timespec64_to_timespec(tstamp); + r1.tstamp = timespec64_to_snd_monotonic_timestamp(tstamp); r1.val = resolution; snd_timer_user_append_to_tqueue(tu, &r1); tu->last_resolution = resolution; @@ -1366,14 +1366,14 @@ static void snd_timer_user_tinterrupt(struct snd_timer_instance *timeri, prev = tu->qtail == 0 ? tu->queue_size - 1 : tu->qtail - 1; r = &tu->tqueue[prev]; if (r->event == SNDRV_TIMER_EVENT_TICK) { - r->tstamp = timespec64_to_timespec(tstamp); + r->tstamp = timespec64_to_snd_monotonic_timestamp(tstamp); r->val += ticks; append++; goto __wake; } } r1.event = SNDRV_TIMER_EVENT_TICK; - r1.tstamp = timespec64_to_timespec(tstamp); + r1.tstamp = timespec64_to_snd_monotonic_timestamp(tstamp); r1.val = ticks; snd_timer_user_append_to_tqueue(tu, &r1); append++; @@ -1852,7 +1852,7 @@ static int snd_timer_user_status(struct file *file, if (!tu->timeri) return -EBADFD; memset(&status, 0, sizeof(status)); - status.tstamp = timespec64_to_timespec(tu->tstamp); + status.tstamp = timespec64_to_snd_monotonic_timestamp(tu->tstamp); status.resolution = snd_timer_resolution(tu->timeri); status.lost = tu->timeri->lost; status.overrun = tu->overrun; diff --git a/sound/core/timer_compat.c b/sound/core/timer_compat.c index e00f7e399e46..960d1075071f 100644 --- a/sound/core/timer_compat.c +++ b/sound/core/timer_compat.c @@ -22,6 +22,8 @@ #include +#include "compat.h" + /* * ILP32/LP64 has different size for 'long' type. Additionally, the size * of storage alignment differs depending on architectures. Here, '__packed' @@ -84,7 +86,7 @@ static int snd_timer_user_info_compat(struct file *file, } struct snd_timer_status32 { - struct compat_timespec tstamp; + struct compat_snd_monotonic_timestamp tstamp; u32 resolution; u32 lost; u32 overrun; From patchwork Thu Apr 26 12:44:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 134517 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp2264652lji; Thu, 26 Apr 2018 05:45:39 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+7B7WMPDJAFSU15dsKBzDzKylx5vWV8DsiZBliznkwlTYheuS+4k/zFC/K/zfiDOAEBQ57 X-Received: by 2002:adf:a617:: with SMTP id k23-v6mr28433833wrc.200.1524746739876; Thu, 26 Apr 2018 05:45:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524746739; cv=none; d=google.com; s=arc-20160816; b=rLVQ6m1mCK3Rl/4TFO2wQQdZYP621Xm1VJzzdFscfZHd4JTaI64uXL+y+/uy7BvugQ SjAWvTzTnT9JIf7okLF1ZdAqFezRnkwahjgbJFeJ+G8w0/t7XemDCuO2Cegc1SM3JfM8 xDv7lzsUBbRx8CLOX/vt4lH1gvwAG9oVEu2mtVMEB4oKVNvurtyq8b8n34ZndeEd2wgX 2/2EUxiltEQLom1G3EPBkzq6/Jna+ZoTGTHmTaoajOfcs5vKOLOqk5DdQLFXfQ0j1ND4 cdNdgHsNfuWx3BCqTnW6scfMBPuTsV9DjcNhDuorumms5XGpoNwTG+qwSfjHHqJeVBL+ yXpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:delivered-to:arc-authentication-results; bh=1w9itqWGsAu7cnF6bavk27xIOMI+LVjqxaasQ2AP3nE=; b=vvD0hKnYCI/vc1BwPyS8cQvCbkvInxF4io2877ND+YIlzwJoeOdPk/XfRzmST3NRPN AXF+zEMUfEjamzW9h1O03K3isiU4xlcJFgEcQcSYuS1kAw+1xAXywgl9Co0SylVZGu2y FpX22s6Vt8iRuKJvsq1/lw8+yK5+njwaAHGMglldRLtzMORkA8tpcyoDFJ0xrWsMDaJ+ Zettrycf6AIfLOw6gaDRRSpwWtzd56hXR6D+h7rzKSzl8xqLKNS+MXLB6uZbg0M8mMub qc74Araa8jtLiCiv3gr/p6mgE9PCtNhkCql/oSN1kTxsuHwEbZdsasjMf53+lHqP89qI oIxg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of alsa-devel-bounces@alsa-project.org designates 77.48.224.243 as permitted sender) smtp.mailfrom=alsa-devel-bounces@alsa-project.org Return-Path: Received: from alsa0.perex.cz (alsa0.perex.cz. [77.48.224.243]) by mx.google.com with ESMTP id y144si10618737wmc.53.2018.04.26.05.45.39; Thu, 26 Apr 2018 05:45:39 -0700 (PDT) Received-SPF: pass (google.com: domain of alsa-devel-bounces@alsa-project.org designates 77.48.224.243 as permitted sender) client-ip=77.48.224.243; Authentication-Results: mx.google.com; spf=pass (google.com: domain of alsa-devel-bounces@alsa-project.org designates 77.48.224.243 as permitted sender) smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id AC03F26784A; Thu, 26 Apr 2018 14:45:29 +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 7830E267847; Thu, 26 Apr 2018 14:45:26 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail1.perex.cz X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_DNSWL_NONE autolearn=disabled version=3.4.0 Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.126.135]) by alsa0.perex.cz (Postfix) with ESMTP id 6EFA6267837 for ; Thu, 26 Apr 2018 14:45:24 +0200 (CEST) Received: from wuerfel.lan ([95.208.111.237]) by mrelayeu.kundenserver.de (mreue004 [212.227.15.129]) with ESMTPA (Nemesis) id 0LZjJo-1eWsLU2ffg-00lUZL; Thu, 26 Apr 2018 14:44:48 +0200 From: Arnd Bergmann To: y2038@lists.linaro.org, linux-kernel@vger.kernel.org Date: Thu, 26 Apr 2018 14:44:22 +0200 Message-Id: <20180426124422.2921744-5-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20180426124422.2921744-1-arnd@arndb.de> References: <20180426124422.2921744-1-arnd@arndb.de> X-Provags-ID: V03:K1:p7oOHxqsY0PquRttUOx8oMhfBUij6xId9+ve+ooS9bGlKjv4uir rWYd46+5vcYGx3IWNxO3i7VFNI1Tixr3hcM/osA/3TGUP0t93pSAKlnhQq5BggTH+HRwk4R pW7qLPEoEBnlSMKF0zJDhjI5sIAH/q5r1Oma1R9Ey4DLlJU8ZSnY4zsDsEq7+KWiE3BHBJb zZJ4uebvhjRhM0uCvZmPA== X-UI-Out-Filterresults: notjunk:1; V01:K0:wciMYjq1mik=:/4cwklliaRmkOhBMJoFzne yGQpdC7dNjDknEbnar1L/RMraLjTm2UOGy0KLkXSqPgdvzpXjEiuso4CnaFKo7DQhevP+qCuT FddkHC9RYNzYfzbYCAGLXBLItBwx0ESGwWxyfxMn8lLRX71Rf7wiGFPRw984t0ZdYR1TzWdHx BLQwdSGibIYmJIyTwnrbpXDo4J9XgxHPI6k/OqLC3WaUsmiUjSDgb4cb6yTf80karDwz6Vg12 7uHwMXDVa48N4EXOgV/dkThj9T6QDUZgxQ61+cGZtRQfX1Av0/nP7lw0xqsuvRWWdxWHKcBM9 2ry3LYTSQZ7Rjdrb2xvxZDP+emElfHm3t8OWSicm4k+GkvgNh4VdY5jSAKrhDQaxsKdO6SYe7 Ua0exH3WIwOZ7Lk3lFK31I2dUjgrQHWitRruNR18LOP01GxYtzVQYOorHGukrPhENS3afo2lW 2gAg8WA2Rnh64y402jdtnub/miURJlL3igQcYZLb95h5VKEmQYdsi4Dev9EY2ZNmXA7RVChpu 6dLlBl7ksU2HtfQuw0ZYwYf/XtVV3edn3YaktKgIi8KlYTQ+fj60OfgRfzNrxFM0MLxIsYxVo /bolfU7CB7XLKnIys+2IDhx7oOFZJy8HpqLsPMm14yR5c7NhFy+33FwK+/UGmxzLe26Mkz/wg GsCQUqPRRXHIIJvqtiRMBaA2oKyeZMn2O6sXCoHr6hEm4huChNnvf+lAhNRPRgcHNAfg= Cc: alsa-devel@alsa-project.org, Arnd Bergmann , Baolin Wang , tiwai@suse.com, lgirdwood@gmail.com, o-takashi@sakamocchi.jp, broonie@kernel.org Subject: [alsa-devel] [PATCH 4/4] ALSA: Deprecate CLOCK_REALTIME timestamps 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 The kernel has supported monotonic timestamps since linux-2.6.25, but it still defaults to CLOCK_REALTIME, which has multiple problems: It skips backwards for every leap second, it may skip at any time from settimeofday() or NTP updates, and it overflows in year 2038. alsa-lib already tries to use monotonic timestamps whenever they are available, so user space should generally be fine with it. To be on the safe side, I'm adding a Kconfig option that allows retaining the current behavior, while making the default to disallow CLOCK_REALTIME stamps. That default makes sense because of the decision to not extend the ioctl interface to 64-bit time stamps. We need today's kernels to run beyond 2038 in certain embedded markets, so it's better to discover any possible problems now rather than running into them only after time stamps overflow. I'm defaulting to SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW behavior rather than SNDRV_PCM_TSTAMP_TYPE_MONOTONIC since the latter is not supported by the HDA hardware timestamps. A similar change was done in the DRM subsystem and it turned out that nothing relied on CLOCK_REALTIME behavior for their timestamps, and the option was subsequently removed. If the same turns out to be true here, we can do the same and clean it out in a few years. Signed-off-by: Arnd Bergmann --- include/sound/pcm.h | 4 ++++ include/uapi/sound/asound.h | 4 +++- sound/core/Kconfig | 11 +++++++++++ sound/core/pcm.c | 3 +++ sound/core/pcm_native.c | 10 ++++++++++ sound/pci/hda/hda_controller.c | 4 ++++ 6 files changed, 35 insertions(+), 1 deletion(-) -- 2.9.0 _______________________________________________ Alsa-devel mailing list Alsa-devel@alsa-project.org http://mailman.alsa-project.org/mailman/listinfo/alsa-devel diff --git a/include/sound/pcm.h b/include/sound/pcm.h index 973d6745217a..5d5daa190b08 100644 --- a/include/sound/pcm.h +++ b/include/sound/pcm.h @@ -1190,7 +1190,11 @@ static inline void snd_pcm_gettime(struct snd_pcm_runtime *runtime, getrawmonotonic64(tv); break; default: +#ifdef CONFIG_SND_TSTAMP_REALTIME ktime_get_real_ts64(tv); +#else + ktime_get_ts64(tv); +#endif break; } } diff --git a/include/uapi/sound/asound.h b/include/uapi/sound/asound.h index 9c61cf77beb8..1d8546731306 100644 --- a/include/uapi/sound/asound.h +++ b/include/uapi/sound/asound.h @@ -542,8 +542,10 @@ struct snd_xfern { }; enum { +#if !(__BITS_PER_LONG == 32 && defined(__USE_TIME_BITS64)) SNDRV_PCM_TSTAMP_TYPE_GETTIMEOFDAY = 0, /* gettimeofday equivalent */ - SNDRV_PCM_TSTAMP_TYPE_MONOTONIC, /* posix_clock_monotonic equivalent */ +#endif + SNDRV_PCM_TSTAMP_TYPE_MONOTONIC = 1, /* posix_clock_monotonic equivalent */ SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW, /* monotonic_raw (no NTP) */ SNDRV_PCM_TSTAMP_TYPE_LAST = SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW, }; diff --git a/sound/core/Kconfig b/sound/core/Kconfig index 6e937a8146a1..6dedb0661fa4 100644 --- a/sound/core/Kconfig +++ b/sound/core/Kconfig @@ -100,6 +100,17 @@ config SND_HRTIMER To compile this driver as a module, choose M here: the module will be called snd-hrtimer. +config SND_TSTAMP_REALTIME + bool "allow CLOCK_REALTIME timestamps" + help + Say Y here if you have user space applications that rely on + the traditional CLOCK_REALTIME based timestamps rather than + using CLOCK_MONOTONIC or CLOCK_MONOTONIC_RAW. + CLOCK_REALTIME has problems with overflow in year 2038, with + leap seconds and concurrent time updates (e.g. through NTP). + + If unsure, say N. + config SND_DYNAMIC_MINORS bool "Dynamic device file minor numbers" help diff --git a/sound/core/pcm.c b/sound/core/pcm.c index 66ac89aad681..aaed96566bde 100644 --- a/sound/core/pcm.c +++ b/sound/core/pcm.c @@ -1028,6 +1028,9 @@ int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream, init_waitqueue_head(&runtime->sleep); init_waitqueue_head(&runtime->tsleep); +#ifdef CONFIG_SND_TSTAMP_REALTIME + runtime->tstamp_type = SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW; +#endif runtime->status->state = SNDRV_PCM_STATE_OPEN; diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index d27c6252e14c..a2196208b057 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -811,6 +811,11 @@ static int snd_pcm_sw_params(struct snd_pcm_substream *substream, if (params->proto >= SNDRV_PROTOCOL_VERSION(2, 0, 12) && params->tstamp_type > SNDRV_PCM_TSTAMP_TYPE_LAST) return -EINVAL; +#ifndef CONFIG_SND_TSTAMP_REALTIME + /* all other types are invalid here, and fall back to raw mono */ + if (params->tstamp_type != SNDRV_PCM_TSTAMP_TYPE_MONOTONIC) + params->tstamp_type = SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW; +#endif if (params->avail_min == 0) return -EINVAL; if (params->silence_size >= runtime->boundary) { @@ -2769,6 +2774,11 @@ static int snd_pcm_tstamp(struct snd_pcm_substream *substream, int __user *_arg) return -EFAULT; if (arg < 0 || arg > SNDRV_PCM_TSTAMP_TYPE_LAST) return -EINVAL; +#ifndef CONFIG_SND_TSTAMP_REALTIME + /* all other types are invalid here, and fall back to raw mono */ + if (arg != SNDRV_PCM_TSTAMP_TYPE_MONOTONIC) + arg = SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW; +#endif runtime->tstamp_type = arg; return 0; } diff --git a/sound/pci/hda/hda_controller.c b/sound/pci/hda/hda_controller.c index c3e45168b848..a2fca77582d5 100644 --- a/sound/pci/hda/hda_controller.c +++ b/sound/pci/hda/hda_controller.c @@ -543,7 +543,11 @@ static int azx_get_time_info(struct snd_pcm_substream *substream, break; default: +#ifdef CONFIG_SND_TSTAMP_REALTIME *system_ts = ktime_to_timespec64(xtstamp.sys_realtime); +#else + *system_ts = ktime_to_timespec64(xtstamp.sys_monoraw); +#endif break; }