Skip to content

Commit

Permalink
kernel: add _timeout_q dump before and after adding timeout
Browse files Browse the repository at this point in the history
Kernel debugging aid.

Change-Id: I852ba2f626f133d943be2ecac41354fecca478d6
Signed-off-by: Benjamin Walsh <[email protected]>
  • Loading branch information
benwrs authored and Andrew Boie committed Jan 6, 2017
1 parent 99eef25 commit 66b99f1
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion kernel/include/timeout_q.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,36 @@ static inline int _abort_thread_timeout(struct k_thread *thread)
return _abort_timeout(&thread->base.timeout);
}

static inline void _dump_timeout(struct _timeout *timeout, int extra_tab)
{
#ifdef CONFIG_KERNEL_DEBUG
char *tab = extra_tab ? "\t" : "";

K_DEBUG("%stimeout %p, prev: %p, next: %p\n"
"%s\tthread: %p, wait_q: %p\n"
"%s\tticks remaining: %d\n"
"%s\tfunction: %p\n",
tab, timeout, timeout->node.prev, timeout->node.next,
tab, timeout->thread, timeout->wait_q,
tab, timeout->delta_ticks_from_prev,
tab, timeout->func);
#endif
}

static inline void _dump_timeout_q(void)
{
#ifdef CONFIG_KERNEL_DEBUG
sys_dnode_t *node;

K_DEBUG("_timeout_q: %p, head: %p, tail: %p\n",
&_timeout_q, _timeout_q.head, _timeout_q.tail);

SYS_DLIST_FOR_EACH_NODE(&_timeout_q, node) {
_dump_timeout((struct _timeout *)node, 1);
}
#endif
}

/*
* Add timeout to timeout queue. Record waiting thread and wait queue if any.
*
Expand All @@ -170,6 +200,10 @@ static inline void _add_timeout(struct k_thread *thread,
timeout->thread = thread;
timeout->wait_q = (sys_dlist_t *)wait_q;

K_DEBUG("before adding timeout %p\n", timeout);
_dump_timeout(timeout, 0);
_dump_timeout_q();

int32_t *delta = &timeout->delta_ticks_from_prev;
sys_dnode_t *node;

Expand All @@ -180,13 +214,18 @@ static inline void _add_timeout(struct k_thread *thread,
in_q->delta_ticks_from_prev -= *delta;
sys_dlist_insert_before(&_timeout_q, node,
&timeout->node);
return;
goto inserted;
}

*delta -= in_q->delta_ticks_from_prev;
}

sys_dlist_append(&_timeout_q, &timeout->node);

inserted:
K_DEBUG("after adding timeout %p\n", timeout);
_dump_timeout(timeout, 0);
_dump_timeout_q();
}

/*
Expand Down

0 comments on commit 66b99f1

Please sign in to comment.