mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	posix-timers: Make use of forward/remaining callbacks
Replace the hrtimer calls by calls to the new forward/remaining kclock callbacks and move the hrtimer specific implementation into the corresponding callback functions. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: Peter Zijlstra <peterz@infradead.org> Cc: John Stultz <john.stultz@linaro.org> Link: http://lkml.kernel.org/r/20170530211657.121437232@linutronix.de
This commit is contained in:
		
							parent
							
								
									63841b2a69
								
							
						
					
					
						commit
						91d57bae08
					
				
					 1 changed files with 50 additions and 16 deletions
				
			
		| 
						 | 
					@ -607,6 +607,20 @@ static struct k_itimer *__lock_timer(timer_t timer_id, unsigned long *flags)
 | 
				
			||||||
	return NULL;
 | 
						return NULL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static ktime_t common_hrtimer_remaining(struct k_itimer *timr, ktime_t now)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct hrtimer *timer = &timr->it.real.timer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return __hrtimer_expires_remaining_adjusted(timer, now);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int common_hrtimer_forward(struct k_itimer *timr, ktime_t now)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct hrtimer *timer = &timr->it.real.timer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return (int)hrtimer_forward(timer, now, timr->it_interval);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Get the time remaining on a POSIX.1b interval timer.  This function
 | 
					 * Get the time remaining on a POSIX.1b interval timer.  This function
 | 
				
			||||||
 * is ALWAYS called with spin_lock_irq on the timer, thus it must not
 | 
					 * is ALWAYS called with spin_lock_irq on the timer, thus it must not
 | 
				
			||||||
| 
						 | 
					@ -626,43 +640,55 @@ static struct k_itimer *__lock_timer(timer_t timer_id, unsigned long *flags)
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
common_timer_get(struct k_itimer *timr, struct itimerspec64 *cur_setting)
 | 
					common_timer_get(struct k_itimer *timr, struct itimerspec64 *cur_setting)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						const struct k_clock *kc = timr->kclock;
 | 
				
			||||||
	ktime_t now, remaining, iv;
 | 
						ktime_t now, remaining, iv;
 | 
				
			||||||
	struct hrtimer *timer = &timr->it.real.timer;
 | 
						struct timespec64 ts64;
 | 
				
			||||||
 | 
						bool sig_none;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	memset(cur_setting, 0, sizeof(*cur_setting));
 | 
						memset(cur_setting, 0, sizeof(*cur_setting));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						sig_none = (timr->it_sigev_notify & ~SIGEV_THREAD_ID) != SIGEV_NONE;
 | 
				
			||||||
	iv = timr->it_interval;
 | 
						iv = timr->it_interval;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* interval timer ? */
 | 
						/* interval timer ? */
 | 
				
			||||||
	if (iv)
 | 
						if (iv) {
 | 
				
			||||||
		cur_setting->it_interval = ktime_to_timespec64(iv);
 | 
							cur_setting->it_interval = ktime_to_timespec64(iv);
 | 
				
			||||||
	else if (!hrtimer_active(timer) &&
 | 
						} else if (!timr->it_active) {
 | 
				
			||||||
		 (timr->it_sigev_notify & ~SIGEV_THREAD_ID) != SIGEV_NONE)
 | 
							/*
 | 
				
			||||||
 | 
							 * SIGEV_NONE oneshot timers are never queued. Check them
 | 
				
			||||||
 | 
							 * below.
 | 
				
			||||||
 | 
							 */
 | 
				
			||||||
 | 
							if (!sig_none)
 | 
				
			||||||
			return;
 | 
								return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	now = timer->base->get_time();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * When a requeue is pending or this is a SIGEV_NONE
 | 
						 * The timespec64 based conversion is suboptimal, but it's not
 | 
				
			||||||
	 * timer move the expiry time forward by intervals, so
 | 
						 * worth to implement yet another callback.
 | 
				
			||||||
	 * expiry is > now.
 | 
					 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	if (iv && (timr->it_requeue_pending & REQUEUE_PENDING ||
 | 
						kc->clock_get(timr->it_clock, &ts64);
 | 
				
			||||||
		   (timr->it_sigev_notify & ~SIGEV_THREAD_ID) == SIGEV_NONE))
 | 
						now = timespec64_to_ktime(ts64);
 | 
				
			||||||
		timr->it_overrun += (unsigned int) hrtimer_forward(timer, now, iv);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	remaining = __hrtimer_expires_remaining_adjusted(timer, now);
 | 
						/*
 | 
				
			||||||
 | 
						 * When a requeue is pending or this is a SIGEV_NONE timer move the
 | 
				
			||||||
 | 
						 * expiry time forward by intervals, so expiry is > now.
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						if (iv && (timr->it_requeue_pending & REQUEUE_PENDING || sig_none))
 | 
				
			||||||
 | 
							timr->it_overrun += kc->timer_forward(timr, now);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						remaining = kc->timer_remaining(timr, now);
 | 
				
			||||||
	/* Return 0 only, when the timer is expired and not pending */
 | 
						/* Return 0 only, when the timer is expired and not pending */
 | 
				
			||||||
	if (remaining <= 0) {
 | 
						if (remaining <= 0) {
 | 
				
			||||||
		/*
 | 
							/*
 | 
				
			||||||
		 * A single shot SIGEV_NONE timer must return 0, when
 | 
							 * A single shot SIGEV_NONE timer must return 0, when
 | 
				
			||||||
		 * it is expired !
 | 
							 * it is expired !
 | 
				
			||||||
		 */
 | 
							 */
 | 
				
			||||||
		if ((timr->it_sigev_notify & ~SIGEV_THREAD_ID) != SIGEV_NONE)
 | 
							if (!sig_none)
 | 
				
			||||||
			cur_setting->it_value.tv_nsec = 1;
 | 
								cur_setting->it_value.tv_nsec = 1;
 | 
				
			||||||
	} else
 | 
						} else {
 | 
				
			||||||
		cur_setting->it_value = ktime_to_timespec64(remaining);
 | 
							cur_setting->it_value = ktime_to_timespec64(remaining);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Get the time remaining on a POSIX.1b interval timer. */
 | 
					/* Get the time remaining on a POSIX.1b interval timer. */
 | 
				
			||||||
SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
 | 
					SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
 | 
				
			||||||
| 
						 | 
					@ -1049,6 +1075,8 @@ static const struct k_clock clock_realtime = {
 | 
				
			||||||
	.timer_get	= common_timer_get,
 | 
						.timer_get	= common_timer_get,
 | 
				
			||||||
	.timer_del	= common_timer_del,
 | 
						.timer_del	= common_timer_del,
 | 
				
			||||||
	.timer_rearm	= common_hrtimer_rearm,
 | 
						.timer_rearm	= common_hrtimer_rearm,
 | 
				
			||||||
 | 
						.timer_forward	= common_hrtimer_forward,
 | 
				
			||||||
 | 
						.timer_remaining= common_hrtimer_remaining,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const struct k_clock clock_monotonic = {
 | 
					static const struct k_clock clock_monotonic = {
 | 
				
			||||||
| 
						 | 
					@ -1061,6 +1089,8 @@ static const struct k_clock clock_monotonic = {
 | 
				
			||||||
	.timer_get	= common_timer_get,
 | 
						.timer_get	= common_timer_get,
 | 
				
			||||||
	.timer_del	= common_timer_del,
 | 
						.timer_del	= common_timer_del,
 | 
				
			||||||
	.timer_rearm	= common_hrtimer_rearm,
 | 
						.timer_rearm	= common_hrtimer_rearm,
 | 
				
			||||||
 | 
						.timer_forward	= common_hrtimer_forward,
 | 
				
			||||||
 | 
						.timer_remaining= common_hrtimer_remaining,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const struct k_clock clock_monotonic_raw = {
 | 
					static const struct k_clock clock_monotonic_raw = {
 | 
				
			||||||
| 
						 | 
					@ -1088,6 +1118,8 @@ static const struct k_clock clock_tai = {
 | 
				
			||||||
	.timer_get	= common_timer_get,
 | 
						.timer_get	= common_timer_get,
 | 
				
			||||||
	.timer_del	= common_timer_del,
 | 
						.timer_del	= common_timer_del,
 | 
				
			||||||
	.timer_rearm	= common_hrtimer_rearm,
 | 
						.timer_rearm	= common_hrtimer_rearm,
 | 
				
			||||||
 | 
						.timer_forward	= common_hrtimer_forward,
 | 
				
			||||||
 | 
						.timer_remaining= common_hrtimer_remaining,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const struct k_clock clock_boottime = {
 | 
					static const struct k_clock clock_boottime = {
 | 
				
			||||||
| 
						 | 
					@ -1100,6 +1132,8 @@ static const struct k_clock clock_boottime = {
 | 
				
			||||||
	.timer_get	= common_timer_get,
 | 
						.timer_get	= common_timer_get,
 | 
				
			||||||
	.timer_del	= common_timer_del,
 | 
						.timer_del	= common_timer_del,
 | 
				
			||||||
	.timer_rearm	= common_hrtimer_rearm,
 | 
						.timer_rearm	= common_hrtimer_rearm,
 | 
				
			||||||
 | 
						.timer_forward	= common_hrtimer_forward,
 | 
				
			||||||
 | 
						.timer_remaining= common_hrtimer_remaining,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const struct k_clock * const posix_clocks[] = {
 | 
					static const struct k_clock * const posix_clocks[] = {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue