Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 304397
b: refs/heads/master
c: e2d8cce
h: refs/heads/master
i:
  304395: a1f8c39
v: v3
  • Loading branch information
John Stultz authored and Greg Kroah-Hartman committed Apr 20, 2012
1 parent 70d1037 commit db6d584
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 59 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 8f9064a8a3b9f0dfd53bb0dfb3bbbfb457dda4bb
refs/heads/master: e2d8ccef0a8e8aedaf401edca6ad54663b0da24b
3 changes: 1 addition & 2 deletions trunk/drivers/staging/android/alarm-dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ static long alarm_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
break;
case ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP:
case ANDROID_ALARM_ELAPSED_REALTIME:
tmp_time =
ktime_to_timespec(alarm_get_elapsed_realtime());
get_monotonic_boottime(&tmp_time);
break;
case ANDROID_ALARM_TYPE_COUNT:
case ANDROID_ALARM_SYSTEMTIME:
Expand Down
70 changes: 15 additions & 55 deletions trunk/drivers/staging/android/alarm.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ struct alarm_queue {
struct rb_root alarms;
struct rb_node *first;
struct hrtimer timer;
ktime_t delta;
bool stopped;
ktime_t stopped_time;
};
Expand Down Expand Up @@ -107,8 +106,8 @@ static void update_timer_locked(struct alarm_queue *base, bool head_removed)
}

hrtimer_try_to_cancel(&base->timer);
base->timer.node.expires = ktime_add(base->delta, alarm->expires);
base->timer._softexpires = ktime_add(base->delta, alarm->softexpires);
base->timer.node.expires = alarm->expires;
base->timer._softexpires = alarm->softexpires;
hrtimer_start_expires(&base->timer, HRTIMER_MODE_ABS);
}

Expand Down Expand Up @@ -279,10 +278,6 @@ int android_alarm_set_rtc(struct timespec new_time)
alarms[i].stopped = true;
alarms[i].stopped_time = timespec_to_ktime(tmp_time);
}
alarms[ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP].delta =
alarms[ANDROID_ALARM_ELAPSED_REALTIME].delta =
ktime_sub(alarms[ANDROID_ALARM_ELAPSED_REALTIME].delta,
timespec_to_ktime(timespec_sub(tmp_time, new_time)));
spin_unlock_irqrestore(&alarm_slock, flags);
ret = do_settimeofday(&new_time);
spin_lock_irqsave(&alarm_slock, flags);
Expand Down Expand Up @@ -310,24 +305,6 @@ int android_alarm_set_rtc(struct timespec new_time)
return ret;
}

/**
* alarm_get_elapsed_realtime - get the elapsed real time in ktime_t format
*
* returns the time in ktime_t format
*/
ktime_t alarm_get_elapsed_realtime(void)
{
ktime_t now;
unsigned long flags;
struct alarm_queue *base = &alarms[ANDROID_ALARM_ELAPSED_REALTIME];

spin_lock_irqsave(&alarm_slock, flags);
now = base->stopped ? base->stopped_time : ktime_get_real();
now = ktime_sub(now, base->delta);
spin_unlock_irqrestore(&alarm_slock, flags);
return now;
}

static enum hrtimer_restart alarm_timer_triggered(struct hrtimer *timer)
{
struct alarm_queue *base;
Expand All @@ -339,7 +316,6 @@ static enum hrtimer_restart alarm_timer_triggered(struct hrtimer *timer)

base = container_of(timer, struct alarm_queue, timer);
now = base->stopped ? base->stopped_time : hrtimer_cb_get_time(timer);
now = ktime_sub(now, base->delta);

pr_alarm(INT, "alarm_timer_triggered type %td at %lld\n",
base - alarms, ktime_to_ns(now));
Expand Down Expand Up @@ -536,40 +512,25 @@ static struct platform_driver alarm_driver = {
}
};

static int __init alarm_late_init(void)
{
unsigned long flags;
struct timespec tmp_time, system_time;

/* this needs to run after the rtc is read at boot */
spin_lock_irqsave(&alarm_slock, flags);
/* We read the current rtc and system time so we can later calculate
* elasped realtime to be (boot_systemtime + rtc - boot_rtc) ==
* (rtc - (boot_rtc - boot_systemtime))
*/
getnstimeofday(&tmp_time);
ktime_get_ts(&system_time);
alarms[ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP].delta =
alarms[ANDROID_ALARM_ELAPSED_REALTIME].delta =
timespec_to_ktime(timespec_sub(tmp_time, system_time));

spin_unlock_irqrestore(&alarm_slock, flags);
return 0;
}

static int __init alarm_driver_init(void)
{
int err;
int i;

for (i = 0; i < ANDROID_ALARM_SYSTEMTIME; i++) {
hrtimer_init(&alarms[i].timer,
CLOCK_REALTIME, HRTIMER_MODE_ABS);
alarms[i].timer.function = alarm_timer_triggered;
}
hrtimer_init(&alarms[ANDROID_ALARM_RTC_WAKEUP].timer,
CLOCK_REALTIME, HRTIMER_MODE_ABS);
hrtimer_init(&alarms[ANDROID_ALARM_RTC].timer,
CLOCK_REALTIME, HRTIMER_MODE_ABS);
hrtimer_init(&alarms[ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP].timer,
CLOCK_BOOTTIME, HRTIMER_MODE_ABS);
hrtimer_init(&alarms[ANDROID_ALARM_ELAPSED_REALTIME].timer,
CLOCK_BOOTTIME, HRTIMER_MODE_ABS);
hrtimer_init(&alarms[ANDROID_ALARM_SYSTEMTIME].timer,
CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
alarms[ANDROID_ALARM_SYSTEMTIME].timer.function = alarm_timer_triggered;
CLOCK_MONOTONIC, HRTIMER_MODE_ABS);

for (i = 0; i < ANDROID_ALARM_TYPE_COUNT; i++)
alarms[i].timer.function = alarm_timer_triggered;

err = platform_driver_register(&alarm_driver);
if (err < 0)
goto err1;
Expand All @@ -595,7 +556,6 @@ static void __exit alarm_exit(void)
platform_driver_unregister(&alarm_driver);
}

late_initcall(alarm_late_init);
module_init(alarm_driver_init);
module_exit(alarm_exit);

7 changes: 6 additions & 1 deletion trunk/drivers/staging/android/android_alarm.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ enum android_alarm_type {

#include <linux/ktime.h>
#include <linux/rbtree.h>
#include <linux/hrtimer.h>

/*
* The alarm interface is similar to the hrtimer interface but adds support
Expand Down Expand Up @@ -71,7 +72,11 @@ void android_alarm_start_range(struct android_alarm *alarm, ktime_t start,
ktime_t end);
int android_alarm_try_to_cancel(struct android_alarm *alarm);
int android_alarm_cancel(struct android_alarm *alarm);
ktime_t alarm_get_elapsed_realtime(void);

static inline ktime_t alarm_get_elapsed_realtime(void)
{
return ktime_get_boottime();
}

/* set rtc while preserving elapsed realtime */
int android_alarm_set_rtc(const struct timespec ts);
Expand Down

0 comments on commit db6d584

Please sign in to comment.