Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timer stop & start functions fix #1154

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions include/sys/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ int tm_stop(timer_t *tm);
/*! \brief Used by interrupt filter routine to trigger a callback. */
void tm_trigger(timer_t *tm);

/*! \brief Select timer used as a main time source (for binuptime, etc.) */
void tm_select(timer_t *tm);

#endif /* !_KERNEL */

#endif /* !_SYS_TIMER_H_ */
1 change: 0 additions & 1 deletion sys/aarch64/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ static int arm_timer_attach(device_t *dev) {
state->irq_res = device_take_irq(dev, 0, RF_ACTIVE);

tm_register(&state->timer);
tm_select(&state->timer);

bus_intr_setup(dev, state->irq_res, arm_timer_intr, NULL, dev,
"ARM CPU timer");
Expand Down
17 changes: 11 additions & 6 deletions sys/drv/pit.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,19 @@ static int timer_pit_start(timer_t *tm, unsigned flags, const bintime_t start,
/* Maximal counter value which we can store in pit timer */
assert(counter <= 0xFFFF);

pit->sec = 0;
pit->ticks = 0;
pit->prev_ticks16 = 0;
pit->period_ticks = counter;
wiklam marked this conversation as resolved.
Show resolved Hide resolved
pit->noticed_overflow = false;

pit_set_frequency(pit);

bus_intr_setup(dev, pit->irq_res, pit_intr, NULL, pit, "i8254 timer");
return 0;
}

static int timer_pit_stop(timer_t *tm) {
device_t *dev = device_of(tm);
pit_state_t *pit = dev->state;
bus_intr_teardown(dev, pit->irq_res);

outb(TIMER_MODE, TIMER_SEL0 | TIMER_16BIT | TIMER_ONESHOT);

return 0;
}

Expand All @@ -142,6 +139,10 @@ static int pit_attach(device_t *dev) {
pit->regs = device_take_ioports(dev, 0, RF_ACTIVE);
assert(pit->regs != NULL);

pit->sec = 0;
pit->ticks = 0;
pit->prev_ticks16 = 0;
pit->noticed_overflow = false;
pit->irq_res = device_take_irq(dev, 0, RF_ACTIVE);

pit->timer = (timer_t){
Expand All @@ -157,8 +158,12 @@ static int pit_attach(device_t *dev) {
.tm_priv = dev,
};

timer_pit_stop(&pit->timer);

tm_register(&pit->timer);

bus_intr_setup(dev, pit->irq_res, pit_intr, NULL, pit, "i8254 timer");

return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion sys/kern/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ time_t tm2sec(tm_t *t) {
const int32_t year_scale_s = 31536000, day_scale_s = 86400,
hour_scale_s = 3600, min_scale_s = 60;
time_t res = 0;
static const int month_in_days[13] = {0, 31, 59, 90, 120, 151,
static const int month_in_days[12] = {0, 31, 59, 90, 120, 151,
wiklam marked this conversation as resolved.
Show resolved Hide resolved
181, 212, 243, 273, 304, 334};

res += (time_t)month_in_days[t->tm_mon] * day_scale_s;
Expand Down
4 changes: 0 additions & 4 deletions sys/kern/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,6 @@ void tm_trigger(timer_t *tm) {
tm->tm_event_cb(tm, tm->tm_arg);
}

void tm_select(timer_t *tm) {
time_source = tm;
}

bintime_t binuptime(void) {
/* XXX: probably a race condition here */
timer_t *tm = time_source;
Expand Down
25 changes: 13 additions & 12 deletions sys/mips/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static int set_next_tick(mips_timer_state_t *state) {
/* calculate next value of compare register based on timer period */
do {
state->compare.val += state->period_cntr;
mips32_set_c0(C0_COMPARE, state->compare.lo);
mips32_setcompare(state->compare.lo);
hadarai marked this conversation as resolved.
Show resolved Hide resolved
(void)read_count(state);
ticks++;
} while (state->compare.val <= state->count.val);
Expand All @@ -74,26 +74,17 @@ static int mips_timer_start(timer_t *tm, unsigned flags, const bintime_t start,
assert(flags & TMF_PERIODIC);
assert(!(flags & TMF_ONESHOT));

mips32_setcount(0);

device_t *dev = tm->tm_priv;
mips_timer_state_t *state = dev->state;
state->sec = 0;
state->cntr_modulo = 0;
state->last_count_lo = 0;
state->period_cntr = bintime_mul(period, tm->tm_frequency).sec;
state->compare.val = read_count(state);

set_next_tick(state);
bus_intr_setup(dev, state->irq_res, mips_timer_intr, NULL, dev,
"MIPS CPU timer");
return 0;
}

static int mips_timer_stop(timer_t *tm) {
device_t *dev = tm->tm_priv;
mips_timer_state_t *state = dev->state;
bus_intr_teardown(dev, state->irq_res);
static inline int mips_timer_stop(timer_t *tm) {
mips32_setcompare(0xffffffff);
return 0;
}

Expand All @@ -119,8 +110,15 @@ static int mips_timer_probe(device_t *dev) {
static int mips_timer_attach(device_t *dev) {
mips_timer_state_t *state = dev->state;

mips32_setcount(0);

state->sec = 0;
state->cntr_modulo = 0;
state->last_count_lo = 0;
state->irq_res = device_take_irq(dev, 0, RF_ACTIVE);

mips_timer_stop(&state->timer);

state->timer = (timer_t){
.tm_name = "mips-cpu-timer",
.tm_flags = TMF_PERIODIC,
Expand All @@ -136,6 +134,9 @@ static int mips_timer_attach(device_t *dev) {

tm_register(&state->timer);

bus_intr_setup(dev, state->irq_res, mips_timer_intr, NULL, dev,
"MIPS CPU timer");

return 0;
}

Expand Down