Commit 1b3b38f8 authored by Andrew Morton's avatar Andrew Morton Committed by David Mosberger

[PATCH] clean up timer interpolation code

From: Christoph Hellwig <hch@lst.de>

- don't add one level of indentation when taking a lock

- remove useless ti_global struct
parent d8a2bcae
...@@ -1226,47 +1226,36 @@ void __init init_timers(void) ...@@ -1226,47 +1226,36 @@ void __init init_timers(void)
} }
#ifdef CONFIG_TIME_INTERPOLATION #ifdef CONFIG_TIME_INTERPOLATION
volatile unsigned long last_nsec_offset; volatile unsigned long last_nsec_offset;
struct time_interpolator *time_interpolator;
#ifndef __HAVE_ARCH_CMPXCHG #ifndef __HAVE_ARCH_CMPXCHG
spinlock_t last_nsec_offset_lock = SPIN_LOCK_UNLOCKED; spinlock_t last_nsec_offset_lock = SPIN_LOCK_UNLOCKED;
#endif #endif
static struct { struct time_interpolator *time_interpolator;
spinlock_t lock; /* lock protecting list */ struct time_interpolator *time_interpolator_list;
struct time_interpolator *list; /* list of registered interpolators */ spinlock_t time_interpolator_lock = SPIN_LOCK_UNLOCKED;
} ti_global = {
.lock = SPIN_LOCK_UNLOCKED
};
static inline int static inline int
is_better_time_interpolator(struct time_interpolator *new) is_better_time_interpolator(struct time_interpolator *new)
{ {
if (!time_interpolator) if (!time_interpolator)
return 1; return 1;
return new->frequency > 2*time_interpolator->frequency return new->frequency > 2*time_interpolator->frequency ||
|| (unsigned long) new->drift < (unsigned long) time_interpolator->drift; (unsigned long)new->drift < (unsigned long)time_interpolator->drift;
} }
void void
register_time_interpolator(struct time_interpolator *ti) register_time_interpolator(struct time_interpolator *ti)
{ {
spin_lock(&ti_global.lock); spin_lock(&time_interpolator_lock);
{
write_seqlock_irq(&xtime_lock); write_seqlock_irq(&xtime_lock);
{
if (is_better_time_interpolator(ti)) if (is_better_time_interpolator(ti))
time_interpolator = ti; time_interpolator = ti;
}
write_sequnlock_irq(&xtime_lock); write_sequnlock_irq(&xtime_lock);
ti->next = ti_global.list; ti->next = time_interpolator_list;
ti_global.list = ti; time_interpolator_list = ti;
} spin_unlock(&time_interpolator_lock);
spin_unlock(&ti_global.lock);
} }
void void
...@@ -1274,9 +1263,8 @@ unregister_time_interpolator(struct time_interpolator *ti) ...@@ -1274,9 +1263,8 @@ unregister_time_interpolator(struct time_interpolator *ti)
{ {
struct time_interpolator *curr, **prev; struct time_interpolator *curr, **prev;
spin_lock(&ti_global.lock); spin_lock(&time_interpolator_lock);
{ prev = &time_interpolator_list;
prev = &ti_global.list;
for (curr = *prev; curr; curr = curr->next) { for (curr = *prev; curr; curr = curr->next) {
if (curr == ti) { if (curr == ti) {
*prev = curr->next; *prev = curr->next;
...@@ -1284,20 +1272,17 @@ unregister_time_interpolator(struct time_interpolator *ti) ...@@ -1284,20 +1272,17 @@ unregister_time_interpolator(struct time_interpolator *ti)
} }
prev = &curr->next; prev = &curr->next;
} }
write_seqlock_irq(&xtime_lock); write_seqlock_irq(&xtime_lock);
{
if (ti == time_interpolator) { if (ti == time_interpolator) {
/* we lost the best time-interpolator: */ /* we lost the best time-interpolator: */
time_interpolator = NULL; time_interpolator = NULL;
/* find the next-best interpolator */ /* find the next-best interpolator */
for (curr = ti_global.list; curr; curr = curr->next) for (curr = time_interpolator_list; curr; curr = curr->next)
if (is_better_time_interpolator(curr)) if (is_better_time_interpolator(curr))
time_interpolator = curr; time_interpolator = curr;
} }
}
write_sequnlock_irq(&xtime_lock); write_sequnlock_irq(&xtime_lock);
} spin_unlock(&time_interpolator_lock);
spin_unlock(&ti_global.lock);
} }
#endif /* CONFIG_TIME_INTERPOLATION */ #endif /* CONFIG_TIME_INTERPOLATION */
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