mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Tina Ruchandani <ruchandani.tina@gmail.com>
Cc: arnd@arndb.de, perex@perex.cz, alsa-devel@alsa-project.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ALSA: es1968: Replace timeval with ktime_t
Date: Thu, 30 Oct 2014 08:06:10 +0100	[thread overview]
Message-ID: <s5hh9ymc9zx.wl-tiwai@suse.de> (raw)
In-Reply-To: <20141029174810.GA48058@localhost>

At Wed, 29 Oct 2014 10:48:10 -0700,
Tina Ruchandani wrote:
> 
> es1968_measure_clock uses struct timeval, which on 32-bit systems will overflow
> in 2038, leading to incorrect interpretation of time.This patch changes the
> function to use ktime_t instead of struct timeval, which implies:
> - no y2038: ktime_t uses a 64-bit datatype explicitly.
> - efficent subtraction: The earlier version computes the difference in usecs
>   while dealing with secs and nsecs. It requires checks to see if the nsecs of
>   stop is less than start. This patch uses a direct subtract of ktime_t and
>   converts to usecs.
> - use of monotonic clock (ktime_get) over real time (do_gettimeofday),
>   which simplifies timekeeping, as it does not have to deal with cases
>   where stop_time is less than start_time.
> 
> Signed-off-by: Tina Ruchandani <ruchandani.tina@gmail.com>
> Reviewed-by: Arnd Bergmann <arnd@arndb.de>

Applied, thanks.


Takashi

> ---
>  sound/pci/es1968.c | 15 ++++++---------
>  1 file changed, 6 insertions(+), 9 deletions(-)
> 
> diff --git a/sound/pci/es1968.c b/sound/pci/es1968.c
> index a9956a7..6039700 100644
> --- a/sound/pci/es1968.c
> +++ b/sound/pci/es1968.c
> @@ -1710,7 +1710,8 @@ 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;
> +	ktime_t start_time, stop_time;
> +	ktime_t diff;
>  
>  	if (chip->clock == 0)
>  		chip->clock = 48000; /* default clock value */
> @@ -1761,12 +1762,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);
> +	start_time = ktime_get();
>  	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);
> +	stop_time = ktime_get();
>  	snd_es1968_trigger_apu(chip, apu, 0); /* stop */
>  	snd_es1968_bob_dec(chip);
>  	chip->in_measurement = 0;
> @@ -1777,12 +1778,8 @@ static void es1968_measure_clock(struct es1968 *chip)
>  	offset &= 0xfffe;
>  	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;
> -	else
> -		t += stop_time.tv_usec - start_time.tv_usec;
> +	diff = ktime_sub(stop_time, start_time);
> +	t = ktime_to_us(diff);
>  	if (t == 0) {
>  		dev_err(chip->card->dev, "?? calculation error..\n");
>  	} else {
> -- 
> 2.1.0.rc2.206.gedb03e5
> 

      reply	other threads:[~2014-10-30  7:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-29 17:48 Tina Ruchandani
2014-10-30  7:06 ` Takashi Iwai [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=s5hh9ymc9zx.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=arnd@arndb.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=ruchandani.tina@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®