[alsa-devel] ALSA: es1968: Use monotonic clock

Takashi Iwai tiwai at suse.de
Mon Aug 10 11:28:54 CEST 2015


On Sun, 09 Aug 2015 03:48:23 +0200,
Abhilash Jindal wrote:
> 
> Wall time obtained from do_gettimeofday is susceptible to sudden jumps due
> to
> user setting the time or due to NTP.
> 
> Monotonic time is constantly increasing time better suited
> for comparing two timestamps.

Your sign-off is missing.

Also, if we use ktime, ktime_get_raw_ns() or such would be much easier
to use.  It'll be a good cleanup in the end.


thanks,

Takashi

> ---
>  sound/pci/es1968.c |   14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/sound/pci/es1968.c b/sound/pci/es1968.c
> index b0e3d92..6830c31 100644
> --- a/sound/pci/es1968.c
> +++ b/sound/pci/es1968.c
> @@ -1710,7 +1710,7 @@ static void es1968_measure_clock(struct es1968 *chip)
>   int i, apu;
>   unsigned int pa, offset, t;
>   struct esm_memory *memory;
> - struct timeval start_time, stop_time;
> + struct timespec start_time, stop_time;
> 
>   if (chip->clock == 0)
>   chip->clock = 48000; /* default clock value */
> @@ -1759,12 +1759,12 @@ static void es1968_measure_clock(struct es1968
> *chip)
>   snd_es1968_bob_inc(chip, ESM_BOB_FREQ);
>   __apu_set_register(chip, apu, 5, pa & 0xffff);
>   snd_es1968_trigger_apu(chip, apu, ESM_APU_16BITLINEAR);
> - do_gettimeofday(&start_time);
> + ktime_get_ts(&start_time);
>   spin_unlock_irq(&chip->reg_lock);
>   msleep(50);
>   spin_lock_irq(&chip->reg_lock);
>   offset = __apu_get_register(chip, apu, 5);
> - do_gettimeofday(&stop_time);
> + ktime_get_ts(&stop_time);
>   snd_es1968_trigger_apu(chip, apu, 0); /* stop */
>   snd_es1968_bob_dec(chip);
>   chip->in_measurement = 0;
> @@ -1776,11 +1776,11 @@ static void es1968_measure_clock(struct es1968
> *chip)
>   offset += chip->measure_count * (CLOCK_MEASURE_BUFSIZE/2);
> 
>   t = stop_time.tv_sec - start_time.tv_sec;
> - t *= 1000000;
> - if (stop_time.tv_usec < start_time.tv_usec)
> - t -= start_time.tv_usec - stop_time.tv_usec;
> + t *= USEC_PER_SEC;
> + if (stop_time.tv_nsec < start_time.tv_nsec)
> + t -= (start_time.tv_nsec - stop_time.tv_nsec)/NSEC_PER_USEC;
>   else
> - t += stop_time.tv_usec - start_time.tv_usec;
> + t += (stop_time.tv_nsec - start_time.tv_nsec)/NSEC_PER_USEC;
>   if (t == 0) {
>   snd_printk(KERN_ERR "?? calculation error..\n");
>   } else {
> -- 
> 1.7.9.5
> [2  <text/html; UTF-8 (quoted-printable)>]
> 


More information about the Alsa-devel mailing list