Change behavior of chopstx_poll to correctly update *USEC_P.
This commit is contained in:
@@ -1,3 +1,10 @@
|
|||||||
|
2018-12-07 NIIBE Yutaka <gniibe@fsij.org>
|
||||||
|
|
||||||
|
* chopstx.c (chx_timer_dequeue): Return ticks remained.
|
||||||
|
(chx_wakeup, chopstx_mutex_lock): Use return value of
|
||||||
|
chx_timer_dequeue.
|
||||||
|
(chx_snooze): Update *USEC_P, accordingly.
|
||||||
|
|
||||||
2018-11-12 NIIBE Yutaka <gniibe@fsij.org>
|
2018-11-12 NIIBE Yutaka <gniibe@fsij.org>
|
||||||
|
|
||||||
* VERSION: 1.12.
|
* VERSION: 1.12.
|
||||||
|
|||||||
@@ -293,8 +293,8 @@ chx_request_preemption (uint16_t prio)
|
|||||||
* AAPCS: ARM Architecture Procedure Call Standard
|
* AAPCS: ARM Architecture Procedure Call Standard
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* 1 on wakeup by others.
|
* >= 1 on wakeup by others, value means ticks remained for sleep.
|
||||||
* 0 on normal wakeup (timer expiration, lock aquirement).
|
* 0 on normal wakeup (timer expiration, lock acquirement).
|
||||||
* -1 on cancellation.
|
* -1 on cancellation.
|
||||||
*/
|
*/
|
||||||
static uintptr_t __attribute__ ((naked, noinline))
|
static uintptr_t __attribute__ ((naked, noinline))
|
||||||
|
|||||||
39
chopstx.c
39
chopstx.c
@@ -107,7 +107,7 @@ static struct chx_queue q_intr;
|
|||||||
static void chx_request_preemption (uint16_t prio);
|
static void chx_request_preemption (uint16_t prio);
|
||||||
static int chx_wakeup (struct chx_pq *p);
|
static int chx_wakeup (struct chx_pq *p);
|
||||||
static struct chx_thread * chx_timer_insert (struct chx_thread *tp, uint32_t usec);
|
static struct chx_thread * chx_timer_insert (struct chx_thread *tp, uint32_t usec);
|
||||||
static void chx_timer_dequeue (struct chx_thread *tp);
|
static uint32_t chx_timer_dequeue (struct chx_thread *tp);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -349,12 +349,14 @@ chx_timer_insert (struct chx_thread *tp, uint32_t usec)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static uint32_t
|
||||||
chx_timer_dequeue (struct chx_thread *tp)
|
chx_timer_dequeue (struct chx_thread *tp)
|
||||||
{
|
{
|
||||||
struct chx_thread *tp_prev;
|
struct chx_thread *tp_prev;
|
||||||
|
uint32_t ticks_remained;
|
||||||
|
|
||||||
chx_spin_lock (&q_timer.lock);
|
chx_spin_lock (&q_timer.lock);
|
||||||
|
ticks_remained = chx_systick_get ();
|
||||||
tp_prev = (struct chx_thread *)tp->prev;
|
tp_prev = (struct chx_thread *)tp->prev;
|
||||||
if (tp_prev == (struct chx_thread *)&q_timer.q)
|
if (tp_prev == (struct chx_thread *)&q_timer.q)
|
||||||
{
|
{
|
||||||
@@ -362,16 +364,22 @@ chx_timer_dequeue (struct chx_thread *tp)
|
|||||||
chx_set_timer (tp_prev, 0); /* Cancel timer*/
|
chx_set_timer (tp_prev, 0); /* Cancel timer*/
|
||||||
else
|
else
|
||||||
{ /* Update timer. */
|
{ /* Update timer. */
|
||||||
uint32_t next_ticks = chx_systick_get () + tp->v;
|
ticks_remained += tp->v;
|
||||||
|
chx_set_timer (tp_prev, ticks_remained);
|
||||||
chx_set_timer (tp_prev, next_ticks);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
tp_prev->v += tp->v;
|
{
|
||||||
|
struct chx_pq *p;
|
||||||
|
|
||||||
|
tp_prev->v += tp->v;
|
||||||
|
for (p = q_timer.q.next; p != (struct chx_pq *)tp; p = p->next)
|
||||||
|
ticks_remained += p->v;
|
||||||
|
}
|
||||||
ll_dequeue ((struct chx_pq *)tp);
|
ll_dequeue ((struct chx_pq *)tp);
|
||||||
tp->v = 0;
|
tp->v = 0;
|
||||||
chx_spin_unlock (&q_timer.lock);
|
chx_spin_unlock (&q_timer.lock);
|
||||||
|
return ticks_remained;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -502,9 +510,11 @@ chx_wakeup (struct chx_pq *pq)
|
|||||||
tp = px->master;
|
tp = px->master;
|
||||||
if (tp->state == THREAD_WAIT_POLL)
|
if (tp->state == THREAD_WAIT_POLL)
|
||||||
{
|
{
|
||||||
tp->v = (uintptr_t)1;
|
|
||||||
if (tp->parent == &q_timer.q)
|
if (tp->parent == &q_timer.q)
|
||||||
chx_timer_dequeue (tp);
|
tp->v = (uintptr_t)chx_timer_dequeue (tp);
|
||||||
|
else
|
||||||
|
tp->v = (uintptr_t)1;
|
||||||
|
|
||||||
chx_ready_enqueue (tp);
|
chx_ready_enqueue (tp);
|
||||||
if (!running || tp->prio > running->prio)
|
if (!running || tp->prio > running->prio)
|
||||||
yield = 1;
|
yield = 1;
|
||||||
@@ -679,6 +689,11 @@ chx_snooze (uint32_t state, uint32_t *usec_p)
|
|||||||
r = chx_sched (CHX_SLEEP);
|
r = chx_sched (CHX_SLEEP);
|
||||||
if (r == 0)
|
if (r == 0)
|
||||||
*usec_p -= usec0;
|
*usec_p -= usec0;
|
||||||
|
else if (r > 0)
|
||||||
|
{
|
||||||
|
*usec_p -= (usec0 - r / MHZ);
|
||||||
|
r = 1;
|
||||||
|
}
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
@@ -803,9 +818,10 @@ chopstx_mutex_lock (chopstx_mutex_t *mutex)
|
|||||||
if (tp0->state == THREAD_WAIT_TIME
|
if (tp0->state == THREAD_WAIT_TIME
|
||||||
|| tp0->state == THREAD_WAIT_POLL)
|
|| tp0->state == THREAD_WAIT_POLL)
|
||||||
{
|
{
|
||||||
tp0->v = (uintptr_t)1;
|
|
||||||
if (tp0->parent == &q_timer.q)
|
if (tp0->parent == &q_timer.q)
|
||||||
chx_timer_dequeue (tp0);
|
tp0->v = (uintptr_t)chx_timer_dequeue (tp0);
|
||||||
|
else
|
||||||
|
tp0->v = (uintptr_t)1;
|
||||||
|
|
||||||
chx_ready_enqueue (tp0);
|
chx_ready_enqueue (tp0);
|
||||||
tp0 = NULL;
|
tp0 = NULL;
|
||||||
@@ -1347,7 +1363,8 @@ chx_proxy_init (struct chx_px *px, uint32_t *cp)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* chopstx_poll - wait for condition variable, thread's exit, or IRQ
|
* chopstx_poll - wait for condition variable, thread's exit, or IRQ
|
||||||
* @usec_p: Pointer to usec for timeout. Forever if NULL.
|
* @usec_p: Pointer to usec for timeout. Forever if NULL. It is
|
||||||
|
* updated on return
|
||||||
* @n: Number of poll descriptors
|
* @n: Number of poll descriptors
|
||||||
* @pd_array: Pointer to an array of poll descriptor pointer which
|
* @pd_array: Pointer to an array of poll descriptor pointer which
|
||||||
* should be one of:
|
* should be one of:
|
||||||
|
|||||||
Reference in New Issue
Block a user