Skip to content

Commit

Permalink
[kernel] dynamic timer support from external sources
Browse files Browse the repository at this point in the history
  • Loading branch information
travisg authored and Ajay Dudani committed Jul 28, 2011
1 parent 28da92a commit 9045c06
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
6 changes: 5 additions & 1 deletion include/kernel/thread.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
* Copyright (c) 2008-2009 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
Expand Down Expand Up @@ -205,7 +205,11 @@ int wait_queue_wake_all(wait_queue_t *, bool reschedule, status_t wait_queue_err
status_t thread_unblock_from_wait_queue(thread_t *t, bool reschedule, status_t wait_queue_error);

/* thread level statistics */
#if DEBUGLEVEL > 1
#define THREAD_STATS 1
#else
#define THREAD_STATS 0
#endif
#if THREAD_STATS
struct thread_stats {
bigtime_t idle_time;
Expand Down
22 changes: 21 additions & 1 deletion kernel/thread.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
* Copyright (c) 2008-2009 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
Expand Down Expand Up @@ -61,6 +61,11 @@ thread_t *idle_thread;
static void thread_resched(void);
static void idle_thread_routine(void) __NO_RETURN;

#if PLATFORM_HAS_DYNAMIC_TIMER
/* preemption timer */
static timer_t preempt_timer;
#endif

/* run queue manipulation */
static void insert_in_run_queue_head(thread_t *t)
{
Expand Down Expand Up @@ -294,6 +299,17 @@ void thread_resched(void)
ASSERT(newthread->saved_critical_section_count > 0);
#endif

#if PLATFORM_HAS_DYNAMIC_TIMER
/* if we're switching from idle to a real thread, set up a periodic
* timer to run our preemption tick.
*/
if (oldthread == idle_thread) {
timer_set_periodic(&preempt_timer, 10, (timer_callback)thread_timer_tick, NULL);
} else if (newthread == idle_thread) {
timer_cancel(&preempt_timer);
}
#endif

/* do the switch */
oldthread->saved_critical_section_count = critical_section_count;
current_thread = newthread;
Expand Down Expand Up @@ -391,6 +407,7 @@ static enum handler_return thread_sleep_handler(timer_t *timer, time_t now, void
return INT_RESCHEDULE;
}

/* Put thread to sleep; delay specified in ms */
void thread_sleep(time_t delay)
{
timer_t timer;
Expand Down Expand Up @@ -434,6 +451,9 @@ void thread_init_early(void)

void thread_init(void)
{
#if PLATFORM_HAS_DYNAMIC_TIMER
timer_initialize(&preempt_timer);
#endif
}

void thread_set_name(const char *name)
Expand Down

0 comments on commit 9045c06

Please sign in to comment.