diff options
author | Benjamin Walsh <benjamin.walsh@windriver.com> | 2016-12-20 14:39:08 -0500 |
---|---|---|
committer | Anas Nashif <nashif@linux.intel.com> | 2016-12-21 19:50:07 +0000 |
commit | 6209218f4069f2a3fe202fec3328a5803f11dc8e (patch) | |
tree | d8d09b5c907ba5582c29eecd2b53d876f6677d1f /kernel/sched.c | |
parent | 95061b656173ffdee4550df52557eff5325635ad (diff) |
kernel: optimize ms-to-ticks for certain tick frequencies
Some tick frequencies lend themselves to optimized conversions from ms
to ticks and vice-versa.
- 1000Hz which does not need any conversion
- 500Hz, 250Hz, 125Hz where the division/multiplication are a straight
shift since they are power-of-two factors of 1000.
In addition, some more generally used values are made to use optimized
conversion equations rather than the generic one that uses 64-bit math,
and often results in calling compiler intrinsics.
These values are: 100Hz, 50Hz, 25Hz, 20Hz, 10Hz, 1Hz (the last one used
in some testing).
Avoiding the 64-bit math intrisics has the additional benefit, in
addition to increased performance, of using a significant lower amount
of stack space: 52 bytes on ARM Cortex-M and 80 bytes on x86.
Change-Id: I080eb338a2637d6b1c6838c119af1a9fa37fe869
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
Diffstat (limited to 'kernel/sched.c')
-rw-r--r-- | kernel/sched.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/kernel/sched.c b/kernel/sched.c index 2755d8101..c6674c013 100644 --- a/kernel/sched.c +++ b/kernel/sched.c @@ -19,6 +19,7 @@ #include <atomic.h> #include <ksched.h> #include <wait_q.h> +#include <misc/util.h> /* the only struct _kernel instance */ struct _kernel _kernel = {0}; @@ -191,15 +192,14 @@ static int _is_wait_q_insert_point(sys_dnode_t *node, void *insert_prio) /* convert milliseconds to ticks */ -#define ceiling(numerator, divider) \ - (((numerator) + ((divider) - 1)) / (divider)) - +#ifdef _NON_OPTIMIZED_TICKS_PER_SEC int32_t _ms_to_ticks(int32_t ms) { int64_t ms_ticks_per_sec = (int64_t)ms * sys_clock_ticks_per_sec; - return (int32_t)ceiling(ms_ticks_per_sec, MSEC_PER_SEC); + return (int32_t)ceiling_fraction(ms_ticks_per_sec, MSEC_PER_SEC); } +#endif /* pend the specified thread: it must *not* be in the ready queue */ /* must be called with interrupts locked */ |