Commit 3915bf29 authored by Arnd Bergmann's avatar Arnd Bergmann Committed by Takashi Iwai

ALSA: seq_timer: use monotonic times internally

The sequencer client manager reports timestamps in units of unsigned
32-bit seconds/nanoseconds, but that does not suffer from the y2038
overflow because it stores only the delta since the 'last_update'
time was recorded.

However, the use of the do_gettimeofday() function is problematic
and we have to replace it to avoid the overflow on on 32-bit
architectures.

This uses 'struct timespec64' to record 'last_update', and changes
the code to use monotonic timestamps that do not suffer from leap
seconds and settimeofday updates.

As a side-effect, the code can now use the timespec64_sub() helper
and become more readable and also avoid a multiplication to convert
from microseconds to nanoseconds.
Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent d1691338
...@@ -165,7 +165,7 @@ static void snd_seq_timer_interrupt(struct snd_timer_instance *timeri, ...@@ -165,7 +165,7 @@ static void snd_seq_timer_interrupt(struct snd_timer_instance *timeri,
snd_seq_timer_update_tick(&tmr->tick, resolution); snd_seq_timer_update_tick(&tmr->tick, resolution);
/* register actual time of this timer update */ /* register actual time of this timer update */
do_gettimeofday(&tmr->last_update); ktime_get_ts64(&tmr->last_update);
spin_unlock_irqrestore(&tmr->lock, flags); spin_unlock_irqrestore(&tmr->lock, flags);
...@@ -392,7 +392,7 @@ static int seq_timer_start(struct snd_seq_timer *tmr) ...@@ -392,7 +392,7 @@ static int seq_timer_start(struct snd_seq_timer *tmr)
return -EINVAL; return -EINVAL;
snd_timer_start(tmr->timeri, tmr->ticks); snd_timer_start(tmr->timeri, tmr->ticks);
tmr->running = 1; tmr->running = 1;
do_gettimeofday(&tmr->last_update); ktime_get_ts64(&tmr->last_update);
return 0; return 0;
} }
...@@ -420,7 +420,7 @@ static int seq_timer_continue(struct snd_seq_timer *tmr) ...@@ -420,7 +420,7 @@ static int seq_timer_continue(struct snd_seq_timer *tmr)
} }
snd_timer_start(tmr->timeri, tmr->ticks); snd_timer_start(tmr->timeri, tmr->ticks);
tmr->running = 1; tmr->running = 1;
do_gettimeofday(&tmr->last_update); ktime_get_ts64(&tmr->last_update);
return 0; return 0;
} }
...@@ -444,17 +444,12 @@ snd_seq_real_time_t snd_seq_timer_get_cur_time(struct snd_seq_timer *tmr) ...@@ -444,17 +444,12 @@ snd_seq_real_time_t snd_seq_timer_get_cur_time(struct snd_seq_timer *tmr)
spin_lock_irqsave(&tmr->lock, flags); spin_lock_irqsave(&tmr->lock, flags);
cur_time = tmr->cur_time; cur_time = tmr->cur_time;
if (tmr->running) { if (tmr->running) {
struct timeval tm; struct timespec64 tm;
int usec;
do_gettimeofday(&tm); ktime_get_ts64(&tm);
usec = (int)(tm.tv_usec - tmr->last_update.tv_usec); tm = timespec64_sub(tm, tmr->last_update);
if (usec < 0) { cur_time.tv_nsec = tm.tv_nsec;
cur_time.tv_nsec += (1000000 + usec) * 1000; cur_time.tv_sec = tm.tv_sec;
cur_time.tv_sec += tm.tv_sec - tmr->last_update.tv_sec - 1;
} else {
cur_time.tv_nsec += usec * 1000;
cur_time.tv_sec += tm.tv_sec - tmr->last_update.tv_sec;
}
snd_seq_sanity_real_time(&cur_time); snd_seq_sanity_real_time(&cur_time);
} }
spin_unlock_irqrestore(&tmr->lock, flags); spin_unlock_irqrestore(&tmr->lock, flags);
......
...@@ -52,7 +52,7 @@ struct snd_seq_timer { ...@@ -52,7 +52,7 @@ struct snd_seq_timer {
unsigned int skew; unsigned int skew;
unsigned int skew_base; unsigned int skew_base;
struct timeval last_update; /* time of last clock update, used for interpolation */ struct timespec64 last_update; /* time of last clock update, used for interpolation */
spinlock_t lock; spinlock_t lock;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment