summaryrefslogtreecommitdiff
path: root/src/clock.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/clock.c')
-rw-r--r--src/clock.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/src/clock.c b/src/clock.c
index 651465e0a8..97a09ddeaf 100644
--- a/src/clock.c
+++ b/src/clock.c
@@ -12,17 +12,20 @@
* 2010-05-20 Bernard fix the tick exceeds the maximum limits
* 2010-07-13 Bernard fix rt_tick_from_millisecond issue found by kuronca
* 2011-06-26 Bernard add rt_tick_set function.
+ * 2018-11-22 Jesven add per cpu tick
*/
#include <rthw.h>
#include <rtthread.h>
+#ifdef RT_USING_SMP
+#define rt_tick rt_cpu_index(0)->tick
+#else
static rt_tick_t rt_tick = 0;
-
-extern void rt_timer_check(void);
+#endif
/**
- * This function will init system tick and set it to zero.
+ * This function will initialize system tick and set it to zero.
* @ingroup SystemInit
*
* @deprecated since 1.1.0, this function does not need to be invoked
@@ -71,7 +74,11 @@ void rt_tick_increase(void)
struct rt_thread *thread;
/* increase the global tick */
+#ifdef RT_USING_SMP
+ rt_cpu_self()->tick ++;
+#else
++ rt_tick;
+#endif
/* check time slice */
thread = rt_thread_self();
@@ -82,6 +89,8 @@ void rt_tick_increase(void)
/* change to initialized tick */
thread->remaining_tick = thread->init_tick;
+ thread->stat |= RT_THREAD_STAT_YIELD;
+
/* yield */
rt_thread_yield();
}
@@ -100,15 +109,20 @@ void rt_tick_increase(void)
*
* @return the calculated tick
*/
-int rt_tick_from_millisecond(rt_int32_t ms)
+rt_tick_t rt_tick_from_millisecond(rt_int32_t ms)
{
- int tick;
+ rt_tick_t tick;
if (ms < 0)
- tick = RT_WAITING_FOREVER;
+ {
+ tick = (rt_tick_t)RT_WAITING_FOREVER;
+ }
else
- tick = (RT_TICK_PER_SECOND * ms + 999) / 1000;
-
+ {
+ tick = RT_TICK_PER_SECOND * (ms / 1000);
+ tick += (RT_TICK_PER_SECOND * (ms % 1000) + 999) / 1000;
+ }
+
/* return the calculated tick */
return tick;
}