Commit graph

467 commits

Author SHA1 Message Date
Andy Ross 7cbdb6c5c0 drivers/timer: Restore non-tickless tick count behavior
The newer series of timer drivers will compare counters vs. the last
tick boundary to compute a number of ticks to announce to the kernel.
In the case of CONFIG_TICKLESS=n, this actually represents a change of
behavior from our old scheme where "ticks" always reflected the number
of interrupts received.

The distinction only matters when an interrupt is delayed more than a
full tick, of course.  But that actually makes a difference to some
timekeeping code.  Restore the old behavior.

This also has the benefit of further reducing code size when !TICKLESS
and improving performance of the ISR by removing the division
(remember Cortex M0 has no hardware divide!).

Fixes #12409

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-02-28 16:11:02 -08:00
Piotr Zięcik d30c9aeafd drivers: nrf_power_clock: Migrate to DTS.
This commit migrates the nrf_power_clock driver to DTS.

Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-02-25 17:51:24 +01:00
Carlos Stuart 75f77db432 include: misc: util.h: Rename min/max to MIN/MAX
There are issues using lowercase min and max macros when compiling a C++
application with a third-party toolchain such as GNU ARM Embedded when
using some STL headers i.e. <chrono>.

This is because there are actual C++ functions called min and max
defined in some of the STL headers and these macros interfere with them.
By changing the macros to UPPERCASE, which is consistent with almost all
other pre-processor macros this naming conflict is avoided.

All files that use these macros have been updated.

Signed-off-by: Carlos Stuart <carlosstuart1970@gmail.com>
2019-02-14 22:16:03 -05:00
Krzysztof Chruscinski 5bfe8612a2 drivers: timer: Fix broken dependency for nrf_rtc_timer
nrf_rtc_timer was selecting counter RTC1 instance even though it
is not using counter API at all.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-02-07 16:14:00 -05:00
Krzysztof Chruscinski 5d0d5c0a7a drivers: counter: Counter API implementation for nRF Series (RTC).
Shim for counter API using nrfx_rtc driver.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-02-07 16:14:00 -05:00
Peter A. Bigot e03c3d8f79 drivers: timer: conflict RTC timer with RTC1 counter
The system timer uses RTC1, but does not implement the counter API with
it.  Instead of auto-enabling the counter API on the system timer make
the two conflict until/unless both APIs are supported by the peripheral.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
2019-02-07 16:14:00 -05:00
Krzysztof Chruscinski da0d9bab2d drivers: counter: Counter API implementation for nRF Series (RTC).
Shim for counter API using nrfx_rtc driver.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-02-07 16:14:00 -05:00
Bobby Noelte 666cf22c60 arch: allow system clock driver selection for cortex m
The selection of the Cortex M systick driver to be used
as a system clock driver is controlled by
CONFIG_CORTEX_M_SYSTICK.

To replace it by another driver CONFIG_CORTEX_M_SYSTICK
must be set to 'n'. Unfortunately this also controls
the interrupt vector for the systick interrupt. It is
now routed to __reserved. More bad the interrupt vector
can not be set by IRQ_CONNECT as it is one of the hard
coded interrupts in the interrupt table.

Route the hard coded systick interrupt to z_clock_isr
and make z_clock_isr a weak symbol that can be overwritten
by an alternative systick system clock driver.

Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
2019-02-05 18:43:03 -06:00
Anas Nashif a93651085e boards: remove pulpino board
This board is unmaintained and unsupported. It is not known to work and
has lots of conditional code across the tree that makes code
unmaintainable.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-01-31 22:47:18 -05:00
Wayne Ren c48971cc61 driver: arcv2_timer0: fixes and optimize the timer driver
* MIN_DELAY: 1024 -> 512
* optimzie some code sequence
* fix a bug in setting the new timer limit value
   * case: before set limit register with new value,
     if counter rolls back to 0, the limit value should be
     adjusted.

Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2019-01-31 06:37:32 -05:00
Daniel Leung d0ad419737 timer: xtensa: restore smp_timer_init()
The smp_timer_init() was removed during timer re-write.
This results in undefined references error during compilation
when CONFIG_SMP=y. So add it back so we can compile for SMP.
The logic is updated from the previous version to the latest
in the driver.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2019-01-31 06:15:39 -05:00
Martin Benda 9653e15139 drivers: timer: Add RTC-based system timer for Atmel SAM0 series MCU
Add sam0_rtc_driver that implements system timer API on top of the RTC
and can be used as a replacement for the default systick timer.

Signed-off-by: Martin Benda <martin.benda@omsquare.com>
2019-01-29 17:58:05 +01:00
Marti Bolivar 58d8afb476 interrupt_controller: RV32M1: add intmux driver / DT bindings
Add a level 2 interrupt controller for the RV32M1 SoC. This uses the
INTMUX peripheral.

As a first customer, convert the timer driver over to using this,
adding nodes for the LPTMR peripherals. This lets users select the
timer instance they want to use, and what intmux channel they want to
route its interrupt to, using DT overlays.

Signed-off-by: Marti Bolivar <marti@foundries.io>
Signed-off-by: Mike Scott <mike@foundries.io>
2019-01-25 11:59:46 -05:00
Marti Bolivar 502d306630 soc: riscv32: add RV32M1 SoC as openisa_rv32m1
The OpenISA RV32M1 SoC has four CPU cores. Two of these are RISC-V
32-bit cores, which are named "RI5CY" and "ZERO-RISCY". (The other two
cores are ARM Cortex-M0+ and -M4.) This patch adds basic SoC
enablement for the RISC-V cores:

- basic dtsi, to be extended as additional drivers are added
- SoC definition in soc/riscv32/openisa_rv32m1 for RI5CY / ZERO-RISCY
- system timer driver for RI5CY, based on LPTMR0 peripheral

The timer driver will be generalized a bit soon once proper
multi-level interrupt support is available.

Emphasis is on supporting the RI5CY core as the more capable of the
two; the ZERO-RISCY SoC definitions are a good starting point, but
additional work setting up a dtsi and initial drivers is needed to
support that core.

Signed-off-by: Marti Bolivar <marti@foundries.io>
Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-25 11:59:46 -05:00
Peter A. Bigot ac36886e62 drivers: nrf: timer: add inline qualifier where inlining is intended
Not necessary with gcc, and Zephyr is inconsistent about using the
qualifier, but making the intent explicit is a good thing.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
2019-01-23 21:38:09 +01:00
Peter A. Bigot 084363a0dc drivers: timer: nrf: refactor for speed and correctness
The existing implementation of z_clock_set_timeout() calculates the
compare value based on a complex series of operations including an
unconditional integer division and multiplication intended to ensure the
compare value is aligned to a tick boundary.  On the nRF51 this division
requires a call to an outline function with a data-dependent execution
time.

In the common case where the timeout is set less than one tick past the
last observed tick the devision can be elided, as can several extra
operations intended to deal with fractional ticks.

The code also failed to account for a ticks-per-cycle that violated the
minimum delay required to guarantee a compare value would result in a
match without wrapping.  The minimum delay was also unreasonably long
(about 1 ms).  Reduce it to a more reasonable value to allow for a
higher ticks-per-second, and diagnose attempts to set the tick frequency
above the supported maximum (8192 Hz).

Finally, move the parts of the compare calculation that are not
dependent on the live counter value out of the locked region.

Prior to this change the observed time between the irq_lock() and
irq_unlock() in z_clock_set_timeout() on the nRF51 ranged between 5 us
and 8 us.

With the revised algorithm the observed lock duration is between 2.16 us
(1024 Hz) and 2.88 us (100 Hz) in the common case that the compare is
set within the current tick.  If the compare is set late the duration
will be higher, but no greater than the previous implementation.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
2019-01-23 21:38:09 +01:00
Peter A. Bigot 71882ff8c4 drivers: timer: nrf: drop unnecessary counter mask
The RTC COUNTER register doesn't care that it receives a value larger
than it can hold; it'll discard the bits internally.  No need to spend
cycles doing it manually.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
2019-01-23 21:38:09 +01:00
Peter A. Bigot 4b24e88fa4 drivers: timer: nrf: use irq_lock instead of spinlock
spinlock gains us nothing on an architecture that doesn't support SMP.
Use the standard irq_lock() API so when we search for conditions that
may decrease ISR responsiveness we can find them.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
2019-01-23 21:38:09 +01:00
Anas Nashif d9ec5eca24 hpet: remove HPET_TIMER_*_EDGE and HPET_TIMER_LEVEL_*
This option is not used anywhere and was removed when the hpet driver
was rewritten.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-01-22 07:45:22 -05:00
Anas Nashif 1d11945739 hpet: remove unused HPET_TIMER_LEGACY_EMULATION
This option is not used anywhere and was removed when the hpet
driver was rewritten.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-01-22 07:45:22 -05:00
Anas Nashif 2621f6dc40 hpet: remove unused HPET_TIMER_DEBUG option
This option is not used anywhere and was removed when the hpet driver
was rewritten.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-01-22 07:45:22 -05:00
Anas Nashif 5aa44e6108 timer: cleanup dependencies in kconfig
Cleanup dependencies in Kconfig and convert some top-level options to
menuconfig. guard all dependent options with if instead of using
'depends on' for readibility.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-01-22 07:45:22 -05:00
Andrzej Głąbek 37fbff6179 drivers: nrf: Adjust clock_control and timer drivers for nRF9160
Minor adjustments are done to the nRF clock_control and rtc_timer
drivers to make them usable on nRF9160 as well.
The arm_irq_vector_table test code is modified only because it uses
the function that has been renamed in the nrf_rtc_timer driver.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2019-01-21 10:13:34 +01:00
Ioannis Glaropoulos 2e687653fa drivers: clock control: rename nrf5_power_clock source and header
This commit renames the nrf5_clock_control.h and
nrf5_clock_control.c files to nrf_clock_control.h and
nrf_clock_control.c, respectively, as they are used
in nRF9160 builds, as well.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-01-15 18:03:24 +01:00
Ioannis Glaropoulos 302a746bd6 drivers: clock control: nrf: rename CLOCK_CONTROL_NRF5 Kconfig symbol
This commit renames the CLOCK_CONTROL_NRF5 Kconfig symbol to
CLOCK_CONTROL_NRF. The change is required to aleviates confusion
when selecting the symbol in nRF9160 SOC definition.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-01-15 18:03:24 +01:00
Andy Ross 3642f67b05 drivers/timer/hpet: Fix logic for !TICKLESS
When tickless was disabled, this inverted test would never fire the
first interrupt and the timer would be silent.  Just remove it.
There's no harm in unconditionally enabling a single timer interrupt
at boot.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-01-11 15:18:52 -05:00
Andy Ross b69d0da82d arch/x86_64: New architecture added
This patch adds a x86_64 architecture and qemu_x86_64 board to Zephyr.
Only the basic architecture support needed to run 64 bit code is
added; no drivers are added, though a low-level console exists and is
wired to printk().

The support is built on top of a "X86 underkernel" layer, which can be
built in isolation as a unit test on a Linux host.

Limitations:

+ Right now the SDK lacks an x86_64 toolchain.  The build will fall
  back to a host toolchain if it finds no cross compiler defined,
  which is tested to work on gcc 8.2.1 right now.

+ No x87/SSE/AVX usage is allowed.  This is a stronger limitation than
  other architectures where the instructions work from one thread even
  if the context switch code doesn't support it.  We are passing
  -no-sse to prevent gcc from automatically generating SSE
  instructions for non-floating-point purposes, which has the side
  effect of changing the ABI.  Future work to handle the FPU registers
  will need to be combined with an "application" ABI distinct from the
  kernel one (or just to require USERSPACE).

+ Paging is enabled (it has to be in long mode), but is a 1:1 mapping
  of all memory.  No MMU/USERSPACE support yet.

+ We are building with -mno-red-zone for stack size reasons, but this
  is a valuable optimization.  Enabling it requires automatic stack
  switching, which requires a TSS, which means it has to happen after
  MMU support.

+ The OS runs in 64 bit mode, but for compatibility reasons is
  compiled to the 32 bit "X32" ABI.  So while the full 64 bit
  registers and instruction set are available, C pointers are 32 bits
  long and Zephyr is constrained to run in the bottom 4G of memory.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-01-11 15:18:52 -05:00
Andy Ross f2d0591830 drivers/timer/hpet: Fix default IRQ
The HPET default is to deliver events on the same INTIn as the legacy
PIT IRQ, and in fact our code requires that because it uses the
"legacy routing" option.  So this isn't really a configurable and has
to be set correctly.  Do it right in the kconfig default instead of
forcing boards to set it.

(No, I have no idea where "20" came from either.)

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-01-11 15:18:52 -05:00
David Vincze 936d8bd378 drivers: timer: fix disable systick function
This patch fixes a bug in System timer driver where
the sys_clock_disable() function was enabling the
timer instead of disabling it.

Change-Id: I4a667d30d43d1f84094d074241ee18d7bb2b2565
Signed-off-by: David Vincze <david.vincze@arm.com>
2018-12-12 15:40:36 -06:00
Wayne Ren f8022b2630 driver: arcv2_timer0: optimze the code
use a local variable to replace the ctrl_cache

Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2018-12-07 17:08:15 -05:00
Wayne Ren 37b4d2cd06 drivers: arcv2_timer0: bug fixes
* remove QEMU related definitions
* fix the definition of TIMER 0 IRQ

Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2018-12-07 17:08:15 -05:00
Wayne Ren f477f564c1 driver: arcv2_timer0.c: minor changes according to review
* code style and comment clean up

Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2018-12-07 17:08:15 -05:00
Wayne Ren fceaf894c4 driver: refactor the arcv2 timer0 driver
refactor the arcv2 timer0 driver according to
the latest changes in sys clock dirver.

Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2018-12-07 17:08:15 -05:00
Patrik Flykt 8ff96b5a57 drivers: Add 'U' to unsigned variable assignments
Add 'U' to a value when assigning it to an unsigned variable.
MISRA-C rule 7.2

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2018-12-04 22:51:56 -05:00
Peter A. Bigot d2f507855b drivers: timer: nrf_rtc_timer: fix handling for 24-bit counter
Two subtractions failed to account for the possibility that a calculated
time exceeded the counter resolution, allowing a comparison to
improperly indicate that a minimum delay was satisfied.

Use the subtraction helper to avoid the problem.

(The subtraction in z_clock_set_timeout was the cause of issue #11694;
the one in rtc1_nrf5_isr was replaced based on inspection rather than
testing.)

Closes #11694

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
2018-11-30 15:05:25 +01:00
Andrew Boie 42cfd4ff26 kernel: expose k_busy_wait() to user mode
If we just had the kernel's implementation, we could
just move this to lib/, but possible arch-specific
implementations dictate that we just make this a
syscall.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-11-15 16:20:36 -05:00
Andy Ross 7aeeb92535 drivers/timer/xtensa_sys_timer: Add hook for old-style interrupt handling
We still have one platform using (for now) the pre-asm2 integration
where the timer interrupt was handled via custom assembly.  It calls a
function named "_timer_int_handler" always, not the one we register
with IRQ_CONNECT.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-11-14 19:08:27 -05:00
Andy Ross 39b2a09f38 drivers/timer: New xtensa timer with tickless support
Rewritten Xtensa CCOUNT driver along the lines of all the other new
drivers.  The new API permits much smaller code.

Notably: The Xtensa counter is a 32 bit up-counter with a comparator
register.  It's in some sense the archetype of this kind of timer as
it's the simplest of the bunch (everything else has quirks: NRF is
very slow and 24 bit, HPET has a runtime frequency detection, RISC-V
is 64 bit...).  I should have written this one first.

Note also that this includes a blacklist of the xtensa architecture on
the tests/driver/ipm test.  I'm getting spurious failures there where
a k_sem_take() call with a non-zero timeout is being made out of the
console output code in interrupt context.  This seems to have nothing
to do with the timer; I suspect it's because the old timer drivers
would (incorrectly!) call z_clock_announce() in non-interrupt context
in some contexts (e.g. "expiring really soon").  Apparently this test
(or something in the IPM or Xtensa console code) was somehow relying
on that on Xtensa.  But IPM is a Quark thing and there's no particular
reason to run this test there.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-11-13 17:10:07 -05:00
Andy Ross f04f797c2b drivers/timer: New, tickless-capable RISC-V machine timer driver
Rewritten driver along the lines of all the other new drivers,
implementing the new timer API.  Structurally, the machine timer is an
up-counter with comparator, so it works broadly the same way HPET and
NRF do.  The quirk here is that it's a 64 bit counter, which needs a
little more care.

Unlike the other timer reworks, this driver has grown by a few lines
as it used to be very simple.  But in exchange, we get full tickless
support on the platform.

Fixes #10609 in the process (the 64 bit timer registers are unlatched
for sub-word transfers, so you have to use careful ordering).

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-11-13 17:10:07 -05:00
Andy Ross 03f007edaf drivers/timer: Reworked NRF driver with tickless support
Reworked using the older hardware interface code, but with an
implementation of the new API only.  Much smaller & simpler.

As yet, tested (manually) only on a nrf52_pca10056 board.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-11-13 17:10:07 -05:00
Andy Ross 002a9f4cb7 drivers/timer/hpet: Completely new, simplified, tickless-capable driver
Rewritten along the lines of ARM SysTick.  Implements only the new,
simplified API.  MUCH smaller.  Works with tickless pervasively.  No
loss of functionality.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-11-13 17:10:07 -05:00
Andy Ross 9ff98f797a drivers/timer: Add more default stubs
Many drivers won't need to implement z_clock_idle_exit() or
sys_clock_disable(). Make those weak stubs too.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-11-13 17:10:07 -05:00
Andy Ross c0a184c067 drivers/timer: Select tickless via driver kconfig flag
Add a TICKLESS_CAPABLE kconfig variable which is used by the kernel to
select tickless mode's default automatically on drivers that support
it (rather than having to set the default per-board).  Select it from
the ARM SysTick and Intel HPET drivers.

Also remove the old qemu_cortex_m3 default settings which this
replaces.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-11-13 17:10:07 -05:00
Andy Ross 0f444c84e5 drivers/timer: Add a standard workaround for known qemu issues
Qemu doesn't like tickless.  By default[1] it tries to be realtime as
vied by the host CPU -- presenting read values from hardware cycle
counters and interrupt timings at the appropriate real world clock
times according to whatever the simulated counter frequency is.  But
when the host system is loaded, there is always the problem that the
qemu process might not see physical CPU time for large chunks of time
(i.e. a host OS scheduling quantum -- generally about the same size as
guest ticks!) leading to lost cycles.

When those timer interrupts are delivered by the emulated hardware at
fixed frequencies without software intervention, that's not so bad:
the work the guest has to do after the interrupt generally happens
synchronously (because the qemu process has just started running) and
nothing notices the dropout.

But with tickless, the interrupts need to be explicitly programmed by
guest software!  That means the driver needs to be sure it's going to
get some real CPU time within some small fraction of a Zephyr tick of
the right time, otherwise the computations get wonky.

The end result is that qemu tends to work with tickless well on an
unloaded/idle run, but not in situations (like sanitycheck) where it
needs to content with other processes for host CPU.

So, add a flag that drivers can use to "fake" tickless behavior when
run under qemu (only), and enable it (only!) for the small handful of
tests that are having trouble.

[1] There is an -icount feature to implement proper cycle counting at
the expense of real-world-time correspondence.  Maybe someday we might
get it to work for us.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-11-13 17:10:07 -05:00
Andy Ross c535300539 drivers/timer: New ARM SysTick driver
Newer, and much smaller driver written to the new timer API.  Supports
all the features the old one did (including shutting off the clock
when clock_always_on is disabled), should be faster in practice, and
should be significantly more accurate due to the "lost cycle" trick
applied in z_clock_set_timeout().

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-11-13 17:10:07 -05:00
Daniel Leung e4aa946c55 timer: xtensa_sys_timer: set compare register at init
Since CCOMPARE* registers have undefined values after reset,
set compare value first before enabling timer interrupt.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2018-11-03 12:40:33 -04:00
Anas Nashif 4071f2c8bb drivers: timer: use weak functions after declaration
Got a warning when building with XCC.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-11-02 08:37:27 -04:00
Kumar Gala aa2bdbe322 drivers: Remove board.h include
We either don't need board.h in the driver or we should be include soc.h
instead.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-11-01 13:21:11 -04:00
Andy Ross cfe62038d2 kernel: Checkpatch fixups
I was pretty careful, but these snuck in.  Most of them are due to
overbroad string replacements in comments.  The pull request is very
large, and I'm too lazy to find exactly where to back-merge all of
these.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-10-16 15:03:10 -04:00
Andy Ross 987c0e5fc1 kernel: New timeout implementation
Now that the API has been fixed up, replace the existing timeout queue
with a much smaller version.  The basic algorithm is unchanged:
timeouts are stored in a sorted dlist with each node nolding a delta
time from the previous node in the list; the announce call just walks
this list pulling off the heads as needed.  Advantages:

* Properly spinlocked and SMP-aware.  The earlier timer implementation
  relied on only CPU 0 doing timeout work, and on an irq_lock() being
  taken before entry (something that was violated in a few spots).
  Now any CPU can wake up for an event (or all of them) and everything
  works correctly.

* The *_thread_timeout() API is now expressible as a clean wrapping
  (just one liners) around the lower-level interface based on function
  pointer callbacks.  As a result the timeout objects no longer need
  to store backpointers to the thread and wait_q and have shrunk by
  33%.

* MUCH smaller, to the tune of hundreds of lines of code removed.

* Future proof, in that all operations on the queue are now fronted by
  just two entry points (_add_timeout() and z_clock_announce()) which
  can easily be augmented with fancier data structures.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-10-16 15:03:10 -04:00
Andy Ross 96013b0375 system_timer.h: Change "now" uptime API to be simpler for drivers
The current z_clock_uptime() call (recently renamed from
_get_elapsed_program_time) requires the driver to track a full 64 bit
uptime value in ticks, which is entirely separate from the one the
kernel is already keeping.

Don't do that.  Just ask the drivers to track uptime since the last
call to z_clock_announce(), since that is going to map better to
built-in hardware capability.

Obviously existing drivers already have this feature, so they're
actually getting slightly larger in order to implement the new API in
terms of the old one.  But future drivers will thank us.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-10-16 15:03:10 -04:00
Andy Ross bf531ac4fc drivers/timer: Add default z_clock_set_timeout() fallback
Useful for tick-only drivers like Pulpino that don't support this.
Ideally we'd have a header-level interface definition for individual
timer drivers to eliminate the noop function call, but this is clean
for now (even the Pulpino hardware looks like it should support
timeouts just fine, so effort would be better spent there than on a
clean "ticked" interface).

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-10-16 15:03:10 -04:00
Andy Ross 722a888ef7 timer: Clean up hairy tickless APIs
The tickless driver had a bunch of "hairy" APIs which forced the timer
drivers to do needless low-level accounting for the benefit of the
kernel, all of which then proceeded to implement them via cut and
paste.  Specifically the "program_time" calls forced the driver to
expose to the kernel exactly when the next interrupt was due and how
much time had elapsed, in a parallel API to the existing "what time is
it" and "announce a tick" interrupts that carry the same information.

Remove these from the kernel, replacing them with synthesized logic
written in terms of the simpler APIs.

In some cases there will be a performance impact due to the use of the
64 bit uptime call, but that will go away soon.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-10-16 15:03:10 -04:00
Andy Ross 1a1a9539ea include/system_timer.h: Timer API cleanup
Rename timer driver API functions to be consistent.  ADD DOCS TO THE
HEADER so implementations understand what the requirements are.
Remove some unused functions that don't need declarations here.

Also removes the per-platform #if's around the power control callback
in favor of a weak-linked noop function in the driver initialization
(adds a few bytes of code to default platforms -- we'll live, I
think).

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-10-16 15:03:10 -04:00
Andy Ross ab488277bc drivers/timer: Unify timeout setting APIs
The existing API had two almost identical functions: _set_time() and
_timer_idle_enter().  Both simply instruct the timer driver to set the
next timer interrupt expiration appropriately so that the call to
z_clock_announce() will be made at the requested number of ticks.  On
most/all hardware, these should be implementable identically.

Unfortunately because they are specified differently, existing drivers
have implemented them in parallel.

Specify a new, unified, z_clock_set_timeout().  Document it clearly
for implementors.  And provide a shim layer for legacy drivers that
will continue to use the old functions.

Note that this patch fixes an existing bug found by inspection: the
old call to _set_time() out of z_clock_announce() failed to test for
the "wait forever" case in the situation where clock_always_on is
true, meaning that a system that reached this point and then never set
another timeout would freeze its uptime clock incorrectly.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-10-16 15:03:10 -04:00
Andy Ross fa99ad66d0 sys_clock: Fix up tick announce API
There were three separate "announce ticks" entry points exposed for
use by drivers.  Unify them to just a single z_clock_announce()
function, making the "final" tick announcement the business of the
driver only, not the kernel.

Note the oddness with "_sys_idle_elapsed_ticks": this was a global
variable exposed by the kernel.  But it was never actually used by the
kernel.  It was updated and inspected only within the timer drivers,
and only so that it could be passed back to the kernel as the default
(actually hidden) argument to the announce function.  Break this false
dependency by putting this variable into each timer driver
individually.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-10-16 15:03:10 -04:00
Andy Ross 317178b88f sys_clock: Fix unsafe tick count usage
The system tick count is a 64 bit quantity that gets updated from
interrupt context, meaning that it's dangerously non-atomic and has to
be locked.  The core kernel clock code did this right.

But the value was also exposed to the rest of the universe as a global
variable, and virtually nothing else was doing this correctly.  Even
in the timer ISRs themselves, the interrupts may be themselves
preempted (most of our architectures support nested interrupts) by
code that wants to set timeouts and inspect system uptime.

Define a z_tick_{get,set}() API, eliminate the old variable, and make
sure everyone uses the right mechanism.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-10-16 15:03:10 -04:00
Andy Ross b2e4283555 sys_clock: Make sys_clock_hw_cycles_per_tick() a proper API
This was another "global variable" API.  Give it function syntax too.
Also add a warning, because on nRF devices (at least) the cycle clock
runs in kHz and is too slow to give a precise answer here.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-10-16 15:03:10 -04:00
Andy Ross cbb77be675 sys_clock.h: Remove sys_clock_ticks_per_sec()
This just got turned into a function from a "variable" API, but
post-the-most-recent-patch it turns out to be degenerate anyway.
Everyone everywhere should always have been using the kconfig variable
directly, and it was only a weirdness in the tickless API that made it
confusing.  Fix.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-10-16 15:03:10 -04:00
Andy Ross 220d4f8347 sys_clock.h: Make "global variable" APIs into proper functions
The existing API defined sys_clock_{hw_cycles,ticks}_per_sec as simple
"variables" to be shared, except that they were only real storage in
certain modes (the HPET driver, basically) and everywhere else they
were a build constant.

Properly, these should be an API defined by the timer driver (who
controls those rates) and consumed by the clock subsystem.  So give
them function syntax as a stepping stone to get there.

Note that this also removes the deprecated variable
_sys_clock_us_per_tick rather than give it the same treatment.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-10-16 15:03:10 -04:00
Alberto Escolar Piedras 10bd2e6eef drivers: timer nRF: use new BabbleSim config option
The simulator symbol was renamed.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-10-15 09:36:37 -04:00
Alberto Escolar Piedras 30fbf56a7a drivers: timer nRF: simplify kconfig depend
Simplify the Kconfig dependency for the nrf timer driver.
CLOCK_CONTROL_NRF5 depends on the SOC_FAMILY_NRF already.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-10-15 09:36:37 -04:00
Alberto Escolar Piedras ba4a01e8ff drivers: timer: native_posix: Support SYSTEM_CLOCK_DISABLE
Add support for CONFIG_SYSTEM_CLOCK_DISABLE so applications
may be compiled with CONFIG_REBOOT.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-10-09 16:15:45 -04:00
Adithya Baglody 36365e38ba drivers: timers: systick: Enforce a barrier in _timer_cycle_get_32.
The code assumes that when the systick counter hits zero,
the timer interrupt will be taken before the loop can
read the LOAD/VAL registers, but this is not architecturally
guaranteed, and so the code can see a post-reload SysTick->VAL
and a pre-reload clock_accumulated_count, which causes it to
return an incorrectly small cycle count. By adding a ISB we
overcome this issue.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2018-09-20 20:35:25 -04:00
Anas Nashif a9f32d66cf tracing: remove stray event_logger code
Remove obsolete kernel event logger code.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-09-05 16:05:08 -04:00
Anas Nashif a2248782a2 kernel: event_logger: remove kernel_event_logger
Move to more generic tracing hooks that can be implemented in different
ways and do not interfere with the kernel.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-08-21 05:45:47 -07:00
Anas Nashif b6304e66f6 tracing: support generic tracing hooks
Define generic interface and hooks for tracing to replace
kernel_event_logger and existing tracing facilities with something more
common.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-08-21 05:45:47 -07:00
Adithya Baglody 1d27b404a6 tests: benchmarks: timing_info: Enable benchmarks for riscv32.
This patch provides support needed to get timing related
information from riscv32 based SOC.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2018-08-20 06:51:25 -07:00
Adithya Baglody 79f65d4db7 tests: benchmarks: timing_info: Enable benchmarks for nios2.
This patch provides support needed to get timing related
information from nios2 based SOC.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2018-08-20 06:51:25 -07:00
Adithya Baglody bb918d85f8 tests: benchmarks: timing_info: Enable benchmarks for xtensa.
This patch provides support needed to get timing related
information from xtensa based SOC.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2018-08-20 06:51:25 -07:00
Adithya Baglody db0c5ca08b arch: arc: Added benchmark related hooks.
The benchmark application timing_info needs certain hooks to be
present in the kernel to get the accurate measurements. This
patch adds these hook at all the required locations.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2018-08-20 06:51:25 -07:00
Flavio Ceolin 0866d18d03 irq: Fix irq_lock api usage
irq_lock returns an unsigned int, though, several places was using
signed int. This commit fix this behaviour.

In order to avoid this error happens again, a coccinelle script was
added and can be used to check violations.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-08-16 19:47:41 -07:00
Ulf Magnusson 8cf8db3a73 Kconfig: Use a short, consistent style for prompts
Consistently use

    config FOO
            bool/int/hex/string "Prompt text"

instead of

    config FOO
            bool/int/hex/string
            prompt "Prompt text"

(...and a bunch of other variations that e.g. swapped the order of the
type and the 'prompt', or put other properties between them).

The shorthand is fully equivalent to using 'prompt'. It saves lines and
avoids tricking people into thinking there is some semantic difference.

Most of the grunt work was done by a modified version of
https://unix.stackexchange.com/questions/26284/
how-can-i-use-sed-to-replace-a-multi-line-string/26290#26290, but some
of the rarer variations had to be converted manually.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-08-15 04:10:10 -07:00
Piotr Zięcik 24abedbd14 driver: timer: nrf: Remove redundant RTC_COUNTER reads.
This commit removes redundant reads of RTC_COUNTER register
propagating optimizations made in the k_cycle_get_32() function.

Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2018-08-13 13:10:50 -07:00
Piotr Zięcik 1dfd33b7ad drivers: timer: nrf: Optimize k_cycle_get_32().
The previous implementation of _timer_cycle_get_32() (which is directly
mapped to k_cycle_get_32()) taken from 87 to 132 cycles. As result it
was too heavy for using it as source of time for logger.

This commit makes this function faster by removing redundant access
to the RTC register (each access consumed 28 CPU cycles) as well as
loop, which made this call non-deterministic.

After these changes the k_cycle_get_32() needs only 50-52 cycles
in to calculate 32-bit timestamp.

Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2018-08-13 13:10:50 -07:00
Alberto Escolar Piedras 00b07615fa native_posix: Add missing headers and function prototypes
A few function prototypes were missing in the native_posix
board and its drivers.
Let's add them.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-08-02 19:14:19 +02:00
Zide Chen 50a08d9e8b loapic timer: LVTT should be programmed before ICR
Intel SDM Vol3 10.5.4.1 states that "A write to LVT Timer Register that
changes the timer mode disarms the local APIC timer".

This implies that LVT Timer register needs to be programmed before
Initial Count register, otherwise the LOAPIC timer could not be armed.

Signed-off-by: Zide Chen <zide.chen@intel.com>
2018-07-24 09:19:33 -04:00
Piotr Zięcik 2fe998cdef kernel: Deprecate sys_clock_us_per_tick variable.
On some architectures tick time cannot be expressed as integer
number of microseconds, introducing error in calculations using
sys_clock_us_per_tick variable.

This commit deprecates the sys_clock_us_per_tick variable and
replaces its usage by more precise calculations based on
sys_clock_hw_cycles_per_sec and sys_clock_ticks_per_sec.

Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2018-07-20 00:03:52 -04:00
Ramakrishna Pallala 5f44309018 drivers: timer: nrf: Fix expected_sys_ticks issue in case of k_busy_wait
In case of tickless kernel, k_busy_wait() calls __enable_sys_clock()
which in turn calls _set_time() with maximum RTC counter programmable
value. This will set the expected_sys_ticks to maximum tick value even
though there is no explicit timeout is requested from the kernel or from
an application. In this scenario, if an app calls k_sleep() which in
turn calls _add_timeout() which will adjust timeout value as per the
elapsed program time which based on incorrectly set expected_sys_ticks.

To fix this issue, we should not set the expected_sys_ticks in case
of __enable_sys_clock() as it just requests to run the counter but
a timeout event request.

Signed-off-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
2018-07-15 22:48:34 -04:00
Ulf Magnusson 120b8fc3a6 drivers: timer: Kconfig: Remove redundant 'default n' properties
Bool symbols implicitly default to 'n'.

A 'default n' can make sense e.g. in a Kconfig.defconfig file, if you
want to override a 'default y' on the base definition of the symbol. It
isn't used like that on any of these symbols though, and is
inconsistent.

This will make the auto-generated Kconfig documentation have "No
defaults. Implicitly defaults to n." as well, which is clearer than
'default n if ...'

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-07-03 17:11:31 -04:00
Anas Nashif 80e6a978a6 kernel/drivers: fix compile warnings
Uncovered by clang we have some functions being only used conditionally,
so gaurd them to make them only available when those conditions are met.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-07-01 22:58:23 +02:00
Alberto Escolar Piedras 785faea8d4 drivers: timer: nRFx: Use nrf_rtc hal for registers w sideeffects
To enable for easier testing, replace direct use of registers
from Nordic's nrfx MDK with accesses via its HAL inlined functions

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-06-18 11:09:19 +02:00
Gautier Seidel 77643677a1 esp32: update to ESP-IDF v3.0-dev-2648-gb2ff235b
Recent ESP-IDF provides OS-agnostic wifi binary, needed by #3723

Closes #8240

Signed-off-by: Gautier Seidel <gautier.seidel@tado.com>
2018-06-13 18:53:43 -04:00
Piotr Zięcik 3f3a907bb8 drivers: timer: Use sys_clock_hw_cycles_per_tick in nrf_rtc_timer.
The nrf_rtc_timer used own method to calculate number of timer cycles
per tick. As the result value was different than the one used by
the kernel, the reported time was incorrect.

This commit fixes the problem described above by using global
sys_clock_hw_cycles_per_tick instead of custom RTC_TICKS_PER_SYS_TICK.

Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2018-06-11 17:38:13 -04:00
Vinayak Kariappa Chettimada edb2ad11f0 Bluetooth: controller: Remove redundant include of cmsis.h
Remove the redundant include of cmsis.h as soc.h already
includes it as necessary.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-06-11 17:30:29 -04:00
Vinayak Kariappa Chettimada e2393a002e drivers: timer: nRFx: Remove redundant code
Remove redundant declaration of youve_print. This probably
had been a review oversight and upstreamed.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-05-16 10:16:29 +02:00
Ioannis Glaropoulos 8d2b22cd05 drivers: timer: expose RTC1 ISR handler function
This commit exposes the RTC1 ISR handling function, so the
function can be directly used in tests which generate
customized vector tables manually and require a visible symbol
for the ISR function.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-04-08 08:47:36 -04:00
Anas Nashif 788aa45888 drivers: timer: remove unkown jira ID
Remove RTOS-2676 from the comment, this is a jira issue number that was
used with zephyr in the past and not available anywhere for reference.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-03-26 13:13:04 -04:00
Carles Cufi f49150cab6 arch: arm: nrf: Rename nrf5 SoC Family to nrf
Upcoming Nordic ICs that share many of the peripherals and architecture
with the currently supported nRF5x ones are no longer part of the nRF5
family. In order to accomodate that, rename the SoC family from nrf5 to
nrf, so that it can contain all of the members of the wider Nordic
family.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-03-20 11:57:14 +01:00
Holman Greenhand 400dc79326 timer: cortex_m: Fix the discontinuous readings of the cycle counter.
On a stm32, When we use the k_busy_wait function to wait a
delay (500us) just after an idle tickless period the delay could be
lower than the requested one. Consecutive readings of the cycle counter
made with the function k_cycle_get_32 juste after tickeless period
provides erroneous values (value jump) after some time (100 us).

To fix this issue we needs:

- Add the update of clock_accumulated_count value in the
_timer_idle_exit function.

- Treat the case in the get_elapsed_count function when the reload value
of the timer is set to a remaining value to wait until end of tick (see
_timer_idle_exit) . In this case the time elapsed until the systick
timer restart was not yet added to clock_accumulated_count. To retrieve
a correct cycle count we must therefore consider the number of cycle
since current tick period start and not only the cycle number since the
timer restart.

Fixes #6164

Signed-off-by: Holman Greenhand <greenhandholman@gmail.com>
2018-02-23 08:58:23 -06:00
Andy Ross 564f59060c kernel: SMP timer integration
In SMP, the system timer is used for timeslicing on auxiliary CPUs,
but the base system timekeeping via _nano_sys_clock_tick_announce() is
still done on CPU0 only (because the framework isn't prepared for
asynchronous notification yet).  Skip processing on CPU1+.

Also, due to a hardware interaction* that is difficult to work around,
timer initialization on the auxiliary CPUs is done at the very end of
the CPU bringup, just before the swap into the scheduler.  A
smp_timer_init() API has been added for this purpose.

* On ESP-32, enabling the timer seems to result in a near-synchronous
  interrupt being delivered despite my best attempts to keep it
  masked, then blowing things up because the CPU record isn't set up
  to handle it yet.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-02-16 10:44:29 -05:00
Andy Ross bba98a9c38 drivers/timer/xtensa_sys_timer: Add init/update hooks for asm2
The earlier xtensa layer put the timer initialization and update
directly into the interrupt handler, which is... weird.  Under asm2,
it's just a regular ISR and needs to do the work in the driver.

Really, this driver needs a bunch of cleanup.  The xtensa CPU timer is
two registers and one ISR: a global cycle count register, and a
compare register that will fire the IRQ when they match.  There is
*way* too much code here.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-02-16 10:44:29 -05:00
Andy Ross 39f78b9b85 drivers/timer/xtensa_sys_timer: Correctly declare ISR
The existing hand-written interrupt code is manually calling the timer
ISR, which is sort of silly and about to be replaced.  Correctly
declare the ISR with IRQ_CONNECT() so that a conventional interrupt
handling implementation can find it.  With current code this is a
noop.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-02-16 10:44:29 -05:00
Alberto Escolar Piedras 6c483ead26 native: timer bugfix in tickless mode part
Bugfix in the tickless mode part:
During _time_idle_exit it was not announcing to the kernel the
already passed silent ticks, but it was left for the tick interrupt
itself.
This did not cause any trouble so far as there was only the timer
interrupt in this board.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-02-08 15:56:48 -08:00
Alberto Escolar Piedras 66c1652fb8 native: native_posix timer + irq fix
Added possibility to reconfigure CONFIG_SYS_CLOCK_TICKS_PER_SEC
for the native_posix board (before it could only be 100)
+
Fixed tickless idle support
+
Minor fixes in irq wrapping

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-02-07 16:28:16 -05:00
Jan Van Winkel ff110b4db5 timer: Corrected types in nRF system timer functions
Corrected parameter and return types  in nRF system timer functions

Signed-off-by: Jan Van Winkel <jan.van_winkel@dxplore.eu>
2018-02-02 15:28:32 +01:00
Anas Nashif 7ae749828f kconfig: fix help text indentation
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-01-08 08:08:45 -05:00
Anas Nashif 6b55598ad4 board: posix: add native_posix board definition
Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-12-27 14:16:08 -05:00
Anas Nashif 429c2a4d9d kconfig: fix help syntax and add spaces
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-12-13 17:43:28 -06:00
Ramakrishna Pallala eb51886d8c drivers: timer: Add Altera shim driver for timer soft IP
Delete the native timer soft IP driver as we will be reusing
the Altera's HAL drivers for most of the soft IP's.

Add shim driver support for Altera timer system clock soft IP.

Signed-off-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
2017-11-17 07:46:40 -05:00
Sebastian Bøe 0829ddfe9a kbuild: Removed KBuild
Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-08 20:00:22 -05:00
Sebastian Bøe 12f8f76165 Introduce cmake-based rewrite of KBuild
Introducing CMake is an important step in a larger effort to make
Zephyr easy to use for application developers working on different
platforms with different development environment needs.

Simplified, this change retains Kconfig as-is, and replaces all
Makefiles with CMakeLists.txt. The DSL-like Make language that KBuild
offers is replaced by a set of CMake extentions. These extentions have
either provided simple one-to-one translations of KBuild features or
introduced new concepts that replace KBuild concepts.

This is a breaking change for existing test infrastructure and build
scripts that are maintained out-of-tree. But for FW itself, no porting
should be necessary.

For users that just want to continue their work with minimal
disruption the following should suffice:

Install CMake 3.8.2+

Port any out-of-tree Makefiles to CMake.

Learn the absolute minimum about the new command line interface:

$ cd samples/hello_world
$ mkdir build && cd build
$ cmake -DBOARD=nrf52_pca10040 ..

$ cd build
$ make

PR: zephyrproject-rtos#4692
docs: http://docs.zephyrproject.org/getting_started/getting_started.html

Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-08 20:00:22 -05:00
Gustavo Lima Chaves 9bb07ff69a jailhouse: add support for x2APIC mode for all LOAPIC accesses
Besides the fact that we did not have that for the current supported
boards, that makes sense for this new, virtualized mode, that is meant
to be run on top of full-fledged x86 64 CPUs.

By having xAPIC mode access only, Jailhouse has to intercept those MMIO
reads and writes, in order to examine what they do and arbitrate if it's
safe or not (e.g. not all values are accepted to ICR register). This
means that we can't run away from having a VM-exit event for each and
every access to APIC memory region and this impacts the latency the
guest OS observes over bare metal a lot.

When in x2APIC mode, Jailhouse does not require VM-exits for MSR
accesses other that writes to the ICR register, so the latency the guest
observes is reduced to almost zero.

Here are some outputs of the the command line

  $ sudo ./tools/jailhouse cell stats tiny-demo

on a Jailhouse's root cell console, for one of the Zephyr demos using
LOAPIC timers, left for a couple of seconds:

Statistics for tiny-demo cell (x2APIC root, x2APIC inmate)

COUNTER                              SUM   PER SEC
vmexits_total                          7         0
vmexits_management                     3         0
vmexits_cr                             2         0
vmexits_cpuid                          1         0
vmexits_msr                            1         0
vmexits_exception                      0         0
vmexits_hypercall                      0         0
vmexits_mmio                           0         0
vmexits_pio                            0         0
vmexits_xapic                          0         0
vmexits_xsetbv                         0         0

Statistics for tiny-demo cell (xAPIC root, xAPIC inmate)

COUNTER                              SUM   PER SEC
vmexits_total                       4087        40
vmexits_xapic                       4080        40
vmexits_management                     3         0
vmexits_cr                             2         0
vmexits_cpuid                          1         0
vmexits_msr                            1         0
vmexits_exception                      0         0
vmexits_hypercall                      0         0
vmexits_mmio                           0         0
vmexits_pio                            0         0
vmexits_xsetbv                         0         0

Statistics for tiny-demo cell (xAPIC root, x2APIC inmate)

COUNTER                              SUM   PER SEC
vmexits_total                       4087        40
vmexits_msr                         4080        40
vmexits_management                     3         0
vmexits_cr                             2         0
vmexits_cpuid                          1         0
vmexits_exception                      0         0
vmexits_hypercall                      0         0
vmexits_mmio                           0         0
vmexits_pio                            0         0
vmexits_xapic                          0         0
vmexits_xsetbv                         0         0

See that under x2APIC mode on both Jailhouse/root-cell and guest, the
interruptions from the hypervisor are minimal. That is not the case when
Jailhouse is on xAPIC mode, though. Note also that, as a plus, x2APIC
accesses on the guest will map to xAPIC MMIO on the hypervisor just
fine.

Signed-off-by: Gustavo Lima Chaves <gustavo.lima.chaves@intel.com>
2017-11-07 08:58:49 -05:00
Youvedeep Singh 833025dd94 timer: xtensa_sys_timer: Tickless Kernel Implementation for Xtensa
Implement Tickless Kernel support for Xtensa Architecture.

Signed-off-by: Youvedeep Singh <youvedeep.singh@intel.com>
2017-11-07 08:17:40 -05:00
Anas Nashif 780324b8ed cleanup: rename fiber/task -> thread
We still have many places talking about tasks and threads, replace those
with thread terminology.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-10-30 18:41:15 -04:00
David B. Kinder 4600c37ff1 doc: Fix misspellings in header/doxygen comments
Occasional scan for misspellings missed during PR reviews

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-10-17 19:40:29 -04:00
Youvedeep Singh 91063a33a4 tests: benchmark: timing_info: Add support for nrf series processors
nrf SOC uses nrf rtc timer (not sys tick), which is 32kHz,
whereas CPU runs at higher speed (nrf52 runs at 64MHz).
So 32Khz is too slow to measure critical kernel parameters.

This patch does :-
1. Add support for nrf SOC for timing_info benchmarking.
2. Uses SOC timer to measure kernel parameters.

Jira: ZEP-2314

Signed-off-by: Youvedeep Singh <youvedeep.singh@intel.com>
2017-08-31 14:25:31 -04:00
Youvedeep Singh 76b577e180 tests: benchmark: timing_info: Change API/variable Name.
The API/Variable names in timing_info looks very speicific to
platform (like systick etc), whereas these variabled are used
across platforms (nrf/arm/quark).
So this patch :-
1. changing API/Variable names to generic one.
2. Creating some of Macros whose implimentation is platform
depenent.

Jira: ZEP-2314

Signed-off-by: Youvedeep Singh <youvedeep.singh@intel.com>
2017-08-31 14:25:31 -04:00
Youvedeep Singh a4063f5362 Timer: Add TICKLESS_KERNEL support for nrf_rtc_timer.
Add support for TICKLESS KERNEL in nrf_rtc_timer for Nordic family of
processors. This patch includes :-
 1. Programming RTC based on "next timer" value from timeout queue while
     A. exiting idle_exit.
     B. on RTC interrupt.
 2. Impliments some of functions which will be required by sys_clock and
    scheduler.

ZEP-1819

Signed-off-by: Youvedeep Singh <youvedeep.singh@intel.com>
2017-08-10 13:56:24 -04:00
Youvedeep Singh 5efaca470c Timer Systick : Handle Systick timer rollback in tickless kernel Case
In Tickeless kernel Platform timekeeping is having error because
"_sys_clock_tick_count" is not getting updated correctly.
Currently "OVERFLOW" Flag (bit 16 in timer control register)
is reset before it is taken into account into _sys_clock_tick_count.

This patch sets a flag as soon as Timer Overflow occues and clears
it when time is accounted into _sys_clock_tick_count.

Jira : ZEP-2217

Signed-off-by: Youvedeep Singh <youvedeep.singh@intel.com>
2017-08-08 08:51:24 -04:00
Andrew Boie f253af2d30 drivers: timer: init earlier in boot sequence
By the time we get to POST_KERNEL, kernel services and kernel objects
should be available for use. This should include timers and the random
number generator, but we don't init the system clock until sometime
during the POST_KERNEL phase. Initialize it earlier.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-07-10 11:44:56 -07:00
Kumar Gala fb56b39cdd timer: xtensa_sys: Cleanup use of C99 types
We introduced some see C99 types, so convert them over to the Zephyr
types.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-06-22 13:47:28 -04:00
Anas Nashif 397d29db42 linker: move all linker headers to include/linker
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-06-18 09:24:04 -05:00
Vinayak Kariappa Chettimada 707500899d drivers: timer: Fix nRF RTC timer _timer_cycle_get_32
Fix nRF RTC timer from returning more than actual cycles
in _timer_cycle_get_32, under race condition when ISR
announces to kernel.

Jira: ZEP-2229

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-01 20:06:10 -04:00
Max Filippov 6a89999787 xtensa: use inline assembly instead of XT_* macros
XT_* macros are defined in xtensa HAL headers as xcc intrinsics. gcc
does not have any of these intrinsics. Replace XT_* macros with inline
assembly or provide gcc-compatible definitions.

Change-Id: If823ea8a7898a11a3a8363b17efdba27dee4c6a4
Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
2017-05-11 16:51:56 -04:00
Adithya Baglody d03b2496cd test: benchmarking: Timing metrics for the kernel
JIRA: ZEP-1822, ZEP-1823, ZEP-1825

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2017-05-03 08:46:30 -04:00
Ramesh Thomas b414cc56f5 timer: tickless: arcv2: Add tickless kernel support
Add tickless kernel support. Sets timer always in one
shot mode to the time the kernel scheduler needs the
next timer event. Uses mili seconds as the scheduling
time unit.

Jira: ZEP-1817
Change-Id: Ia2e63711cdd9d7d9c241b9ff08a606aa79575012
Signed-off-by: Ramesh Thomas <ramesh.thomas@intel.com>
2017-04-27 13:46:32 +00:00
Ramesh Thomas 0beffbe6be timer: tickless: cortex_m: Add tickless kernel support
Add tickless kernel support. Sets timer always in one
shot mode to the time the kernel scheduler needs the
next timer event. Uses mili seconds as the scheduling
time unit.

Jira: ZEP-1818
Change-Id: I21ce037b571c4c6ff588033a15aa49624cba7a57
Signed-off-by: Ramesh Thomas <ramesh.thomas@intel.com>
2017-04-27 13:46:31 +00:00
Ramesh Thomas 74ecc24976 timer: tickless: loapic: Add tickless kernel support
Add tickless kernel support. Sets timer always in one
shot mode to the time the kerneel scheduler needs the
next timer event. Uses mili seconds as the scheduling
time unit.

Jira: ZEP-1816
Change-Id: I85232b572759b9653c6396edc057ff4409525c97
Signed-off-by: Ramesh Thomas <ramesh.thomas@intel.com>
2017-04-27 13:46:30 +00:00
Ramesh Thomas e314ea3819 timer: tickless: hpet: Add tickless kernel support
Update the timer to use the tickless kernel interface
provided by kernel to operate in event based mode. In
this mode, the timer would not generate periodic ticks
and would only be programmed in one shot mode. It would
announce elapsed time in wall time units instead of
ticks. Timer can also be disabled enabling waiting
forever for a non-timer event.

Jira: ZEP-1812
Change-Id: I13110b9fb53b33a9244cc91a3d991f8452d330b1
Signed-off-by: Ramesh Thomas <ramesh.thomas@intel.com>
2017-04-27 13:46:29 +00:00
Ramesh Thomas 89ffd44dfb kernel: tickless: Add tickless kernel support
Adds event based scheduling logic to the kernel. Updates
management of timeouts, timers, idling etc. based on
time tracked at events rather than periodic ticks. Provides
interfaces for timers to announce and get next timer expiry
based on kernel scheduling decisions involving time slicing
of threads, timeouts and idling. Uses wall time units instead
of ticks in all scheduling activities.

The implementation involves changes in the following areas

1. Management of time in wall units like ms/us instead of ticks
The existing implementation already had an option to configure
number of ticks in a second. The new implementation builds on
top of that feature and provides option to set the size of the
scheduling granurality to mili seconds or micro seconds. This
allows most of the current implementation to be reused. Due to
this re-use and co-existence with tick based kernel, the names
of variables may contain the word "tick". However, in the
tickless kernel implementation, it represents the currently
configured time unit, which would be be mili seconds or
micro seconds. The APIs that take time as a parameter are not
impacted and they continue to pass time in mili seconds.

2. Timers would not be programmed in periodic mode
generating ticks. Instead they would be programmed in one
shot mode to generate events at the time the kernel scheduler
needs to gain control for its scheduling activities like
timers, timeouts, time slicing, idling etc.

3. The scheduler provides interfaces that the timer drivers
use to announce elapsed time and get the next time the scheduler
needs a timer event. It is possible that the scheduler may not
need another timer event, in which case the system would wait
for a non-timer event to wake it up if it is idling.

4. New APIs are defined to be implemented by timer drivers. Also
they need to handler timer events differently. These changes
have been done in the HPET timer driver. In future other timers
that support tickles kernel should implement these APIs as well.
These APIs are to re-program the timer, update and announce
elapsed time.

5. Philosopher and timer_api applications have been enabled to
test tickless kernel. Separate configuration files are created
which define the necessary CONFIG flags. Run these apps using
following command
make pristine && make BOARD=qemu_x86 CONF_FILE=prj_tickless.conf qemu

Jira: ZEP-339 ZEP-1946 ZEP-948
Change-Id: I7d950c31bf1ff929a9066fad42c2f0559a2e5983
Signed-off-by: Ramesh Thomas <ramesh.thomas@intel.com>
2017-04-27 13:46:28 +00:00
Kumar Gala cc334c7273 Convert remaining code to using newly introduced integer sized types
Convert code to use u{8,16,32,64}_t and s{8,16,32,64}_t instead of C99
integer types.  This handles the remaining includes and kernel, plus
touching up various points that we skipped because of include
dependancies.  We also convert the PRI printf formatters in the arch
code over to normal formatters.

Jira: ZEP-2051

Change-Id: Iecbb12601a3ee4ea936fd7ddea37788a645b08b0
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-21 11:38:23 -05:00
Kumar Gala ccad5bf3e3 drivers: convert to using newly introduced integer sized types
Convert code to use u{8,16,32,64}_t and s{8,16,32,64}_t instead of C99
integer types.

Jira: ZEP-2051

Change-Id: I08f51e2bfd475f6245771c1bd2df7ffc744c48c4
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-21 10:06:48 -05:00
Kumar Gala 789081673f Introduce new sized integer typedefs
This is a start to move away from the C99 {u}int{8,16,32,64}_t types to
Zephyr defined u{8,16,32,64}_t and s{8,16,32,64}_t.  This allows Zephyr
to define the sized types in a consistent manor across all the
architectures we support and not conflict with what various compilers
and libc might do with regards to the C99 types.

We introduce <zephyr/types.h> as part of this and have it include
<stdint.h> for now until we transition all the code away from the C99
types.

We go with u{8,16,32,64}_t and s{8,16,32,64}_t as there are some
existing variables defined u8 & u16 as well as to be consistent with
Zephyr naming conventions.

Jira: ZEP-2051

Change-Id: I451fed0623b029d65866622e478225dfab2c0ca8
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-20 16:07:08 +00:00
David B. Kinder 896cf7a00a spell: fix doxygen comment typos: /drivers
Fix doxygen comment typos used to generate API docs

Change-Id: I6fd5051c99bdcc731740c92001e525349c254d85
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-04-19 10:45:34 -07:00
Anas Nashif fdd045b52b kconfig: rename non-Kconfig CONFIG_* variables
CONFIG_* usually come from Kconfig, rename variables that are locally
defined to avoid confusion about where they are set.

Change-Id: I83b8459913c5deb68dc1b9f5386b8934363a6d1f
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-04-11 03:14:23 +00:00
Anas Nashif b84dc2e124 kernel: remove all remaining references to nanokernel
Change-Id: I43067508898bc092879f7fe9d656ccca6fd92ab2
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-04-10 20:21:10 +00:00
Anas Nashif d7bc60f096 kernel: remove remaining microkernel references
Change-Id: Ie648dbaaf714316c21395bd43e555618013dbd19
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-04-10 20:21:05 +00:00
Jean-Paul Etienne cd14317c41 timer: riscv_machine_timer: prevent spurious interrupt while rearming the timer
Rearming the riscv machine timer is done by first updating the
mtimecmp low value register. If the low value is updated with a
relatively small value, a timer interrupt can be generated while
updating the mtimecmp high value.

To avoid such a spurious interrupt to occur, disable the timer
interrupt while rearming the timer.

Change-Id: I50ab3f19554a9a8dfe70943b6da0d20be3de88dc
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-04-02 15:15:03 +00:00
Jean-Paul Etienne 1451f82aeb timer: riscv_machine_timer driver depends on SOC_FAMILY_RISCV_PRIVILEGE
Change-Id: I5cbb2845979f88eb005dfd7e0b1714b6fe6167d3
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-04-02 15:14:59 +00:00
Ricardo Salveti 51036ca5f4 nrf_rtc_timer: clear events and counter when disabling sys_clock
Clear pending IRQ when starting and restore back the RTC1 state when
disabling sys_clock, to avoid issues when soft rebooting the device or
chainloading another Zephyr image (e.g. mcuboot).

Change-Id: I693d9168196ad2cfb8475ecfa2051eac043b1fbd
Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
2017-03-27 09:05:57 -05:00
Andrew Boie b8d57738b8 cortex_m_systick: fix _timer_cycle_get_32() race
We need to account for the interrupt happening in the middle
of the calculation.

Issue: ZEP-1546
Change-Id: I193534856d7521cac7ca354d3e5b65e93b984bb1
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-02-22 18:45:36 +00:00
Øyvind Hovdsveen d787099c90 drivers/timer: Fixing issue in nRF RTC driver when RTC handler is blocked.
Fixes an unlikely issue that could arise if the RTC handler in the nRF RTC
driver was blocked for more than one sys tick interval. This could lead to
_sys_clock_tick_announce() being called with more than one sys tick when the
kernel did not expect it.

Jira: ZEP-1763

Change-ID: I5608fca6f0ac97a17c1ce452c1c5c67696a49a9a
Signed-off-by: Øyvind Hovdsveen <oyvind.hovdsveen@nordicsemi.no>
2017-02-22 13:58:53 +00:00
Andrew Boie 68c9d9779c x86: loapic_timer: use TSC for k_cycle_get_32()
The LOAPIC driver was doing this in a way susceptible to a very
nasty race condition: the CCR register could reset and be readable
before the associated interrupt could be delivered.

This resulted in a small window of time where CCR was reset, but
accumulated_cycle_count not updated, causing some calls to
k_cycle_get_32() to appear to jump backwards in time.

Just use the x86 TSC for these cycle timestamps. A divisor may be
provided in cases where the CPU clock speed is some multiple of
the bus speed. Modern x86 CPUs do not change their TSC rate even
when adjusting cpu frequency, so this should be a reliable timing
source.

Issue: ZEP-1546
Change-Id: I441bd8e32af866587a91f306e89e3fa0ece512b5
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-02-21 22:30:47 +00:00
Andrew Boie 15b8ed1a6a arcv2_timer: fix cycle count race
It's possible the timer interrupt could occur when performing the
computation, resulting in incorrect values returned.

It's still possible for bad values to be returned if the function is
called with interrupts locked, but that is only fixable with a second
timer source.

Issue: ZEP-1546
Change-Id: I16d5b04c3e32377f7249eb4fb1bf2f7c22bd0836
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-02-21 01:44:01 +00:00
Wojciech Bober 923560a959 drivers/timer: Rework the nRF RTC driver.
This is a reworked version of the previous RTC driver. The main
changed is related to the handling _timer_idle_exit() on non-RTC
wake-ups. The previous version didn't announce the elapsed time
to the kernel in _timer_idle_exit(). Additionally, the driver now
makes sure never to announce more idle ticks than the kernel asked
for, since the kernel does not handle negative deltas in its timeout
queues.

Change-Id: I312a357a7ce8f0c22adf5153731064b92870e47e
Signed-off-by: Wojciech Bober <wojciech.bober@nordicsemi.no>
Signed-off-by: Øyvind Hovdsveen <oyvind.hovdsveen@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-02-17 20:27:10 +00:00
Andrew Boie e08d07c97d kernel: add flexibility to k_cycle_get_32() definition
Some arches may want to define this as an inline function, or
define in core arch code instead of timer driver code.
Unfortunately, this means we need to remove from the footprint
tests, but this is not typically a large function.

Issue: ZEP-1546
Change-Id: Ic0d7a33507da855995838f4703d872cd613a2ca2
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-02-16 19:27:59 +00:00
Andrew Boie 09648cf8ec altera_avalon_timer: disable high-resolution timestamps
On Nios II the same timer peripheral IP block can't function
as a periodic system timer and a high-resolution timestamp source.
A second timer instance with different configuration is required.
Until that is implemented, just return the accumulated cycle count.

Issue: ZEP-1546
Change-Id: If3dcebdc60334bf3aa0ab45ccd82f1b2531b6bc1
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-02-16 19:10:19 +00:00
Andrew Boie 97d76cad66 riscv_machine_timer: fix k_cycle_get_32()
There are race conditions trying to coordinate the value between
the accumulated_cycle_count (updated at interrupt time) and
trying to compute the delta from the last interrupt using the
mtime registers. An unlucky call could result in the timestamp
appearing to move backwards in time.

the 'mtime' register isn't reset at every interrupt. Since we just
want a cycle counter, report its raw value.

Issue: ZEP-1546
Change-Id: I9f404b33214d6502fea47374fcf0ecbf84ef8136
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-02-16 19:08:04 +00:00
Mazen NEIFER 4bff13e20a Xtensa port: Fixed Xtensa timer in case of tickles idle.
This driver was written for v1.5 before the introduction of the function
_sys_clock_final_tick_announce. At that time _sys_idle_elapsed_ticks was reset
to 0 automatically. Now that it is reset by the new function, the driver needed
to be fixed.

Change-Id: I039b4dbacb691aaf992b37e44404abd19a54a833
Signed-off-by: Mazen NEIFER <mazen@nestwave.com>
2017-02-13 11:39:02 -08:00
Mazen NEIFER ff0828faf3 Xtensa port: Fixed compilation errors caused by last rebase on master.
Change-Id: If2896bcce26652ded2059a11620370e34f98d1e4
Signed-off-by: Mazen NEIFER <mazen@nestwave.com>
2017-02-13 11:39:02 -08:00
Mazen NEIFER 8f92bc255c Xtensa port: Added support for Xtensa internal timer as system timer.
Change-Id: I1a0be1a377999f18ae47687edf4fc4950dcc5ba5
Signed-off-by: Mazen NEIFER <mazen@nestwave.com>
2017-02-13 08:04:27 -08:00
Mazen NEIFER b0669a04b3 Xtensa port: Added support for Xtensa simulator console driver.
Change-Id: I58effa98fd6ff53bcfd21cb8de2fcd89651dc1d9
Signed-off-by: Mazen NEIFER <mazen@nestwave.com>
2017-02-13 08:04:27 -08:00
Mazen NEIFER 0c736f2916 Xtensa port: Added Xtensa internal timer configuration need by assembly files.
This is needed by next commit as some assembly files handling interrupts use
some options from this file.
This file is not included in next commit to separate code and build system
aptches.

Change-Id: Iff3a8019362599beb0c0058c3169480fa5183c1c
Signed-off-by: Mazen NEIFER <mazen@nestwave.com>
2017-02-13 08:04:27 -08:00
Jean-Paul Etienne 5d5265bca4 riscv32: timer: disable riscv_machine_timer driver by default for riscv32
Enabling the riscv_machine_timer driver by default for riscv32
causes compilation issues on riscv32 boards (like zedboard_pulpino)
not supporting it.

Boards supporting the driver enable it via their respective
config file.

Change-Id: Ieb0d25fa339834fd386ae2725f40b6b7b72dc52b
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-02-09 00:26:26 +01:00
Ramesh Thomas 444ecafeee kernel: Remove redundant TICKLESS_IDLE_SUPPORTED option
This flag is no longer necessary and TICKLESS_IDLE will be
enabled by default if SYS_POWER_MANAGEMENT is enabled.

Jira: ZEP-1325
Change-Id: Ic6cd4b8dc0a17c6a413cabf6509b215a4558318d
Signed-off-by: Ramesh Thomas <ramesh.thomas@intel.com>
2017-02-08 13:02:34 +00:00
Jean-Paul Etienne c989f0b408 riscv32: timer: replace riscv_qemu_driver by the generic riscv_machine_driver
riscv defines the machine-mode timer registers that are implemented
by the all riscv SOCs that follow the riscv privileged architecture
specification.

The timer registers implemented in riscv-qemu follow this specification.
To account for future riscv SOCs, reimplement the riscv_qemu_driver by
the riscv_machine_driver.

Change-Id: I645b03c91b4e07d0f2609908decc27ba9b8240d4
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-02-03 19:20:52 +01:00
Kumar Gala f85dbb1b34 arm: cmsis: Convert _ScbExcPrioSet to NVIC_SetPriority
Replace _ScbExcPrioSet with calls to NVIC_SetPriority as it handles both
interrupt and exception priorities.  We don't need to shift around the
priority values for NVIC_SetPriority.

Jira: ZEP-1568

Change-Id: Iccd68733c3f7faa82b7ccb17200eef328090b6da
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-01-30 11:02:36 -06:00
Kumar Gala 8c75d79a15 timer: nrf_rtc: Use CMSIS NVIC APIs directly
Convert driver to use the CMSIS NVIC APIs rather than the internal ones
so we can remove them in the future.

Change-Id: I31c2f37bc0aa35668a441f4ef2821b768dd7b817
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-01-23 15:15:55 -06:00
Kumar Gala 7f5dc1ab30 arm: cmsis: Convert systick to CMSIS
Remove use of __scs structures and defines in place of CMSIS defined
ones.  Also, use __ISB() instead of inline asm.

Jira: ZEP-1568

Change-Id: I8798206a12680f6c50105c7c28112632ac9dde50
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-01-23 15:15:55 -06:00
David B. Kinder ac74d8b652 license: Replace Apache boilerplate with SPDX tag
Replace the existing Apache 2.0 boilerplate header with an SPDX tag
throughout the zephyr code tree. This patch was generated via a
script run over the master branch.

Also updated doc/porting/application.rst that had a dependency on
line numbers in a literal include.

Manually updated subsys/logging/sys_log.c that had a malformed
header in the original file.  Also cleanup several cases that already
had a SPDX tag and we either got a duplicate or missed updating.

Jira: ZEP-1457

Change-Id: I6131a1d4ee0e58f5b938300c2d2fc77d2e69572c
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-01-19 03:50:58 +00:00
Anas Nashif 6b65dcefd2 legacy: Move TICKS_UNLIMITED -> K_FOREVER
Change-Id: Ic1e73959a3444bc6e015e341899c75b1ef850189
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-01-17 19:03:35 +00:00
Jean-Paul Etienne 23cef9e655 timer: added support for the riscv-qemu timer driver
The riscv-qemu timer driver does not implement
TICKLESS_IDLE

Change-Id: I3eeb5abb05b3f16b55ab9343c2045295b3010cfd
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-13 19:56:09 +00:00
Jean-Paul Etienne ec76a4bb63 timer: added timer driver for the pulpino SOC
The pulpino_timer driver does not implement TICKLESS_IDLE
for the time being.

Change-Id: I0cce8c8a7e203d551a924863462e6c86af4c98ff
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-13 19:55:50 +00:00
Benjamin Walsh 3c39e55ab1 arc: fix unaligned variables resulting in unaligned k_cpu_sleep_mode
Force-align all variables defined via asm .word to ensure 4-byte
alignment.

The straddled_tick_on_idle_enter variable was a bool, which resolved in
an one-byte quantity. Changing it to a 32-bit integer. It would have
occupied 4 bytes anyway with alignment.

Fixes ZEP-1549.

Change-Id: If5e0aa1a75dbc73d896b44616f059d221fe191c6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2017-01-13 01:36:08 +00:00
Kumar Gala b7386c3a26 arm: nordic_nrf5: Cleanup Kconfig dependencies for timer and clocks
On the nRF5x platforms we need always need the NRF_RTC_TIMER and it
depends on the CLOCK_CONTROL_NRF5.  So enable all of these always.

Fixes issues if one tries to build nRF5x platforms w/o CONFIG_BLUETOOTH.

Change-Id: I0f9af785e785f37ec289a935ddf70ee6dec08cd4
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-01-09 20:55:10 +00:00
Benjamin Walsh 50f7032fb4 arc/nios2: rename sys_cycle_get_32 to k_cycle_get_32
Oversight from unified kernel effort.

Change-Id: Ib81ead8a38e06b72dc60cdce666d3a4eedf1901c
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-12-21 19:50:05 +00:00
Anas Nashif 3d8e86c12c drivers: eliminate nano/micro kernel usage
Jira: ZEP-1415

Change-Id: I4a009ff57edb799750175aef574a865589f96c14
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-12-21 18:45:02 +00:00
Anas Nashif cfbe9b05a1 kernel: rename NANOKERNEL_TICKLESS_IDLE_SUPPORTED
rename NANOKERNEL_TICKLESS_IDLE_SUPPORTED to
TICKLESS_IDLE_SUPPORTED and remove nanokernel occurances in Kconfig
files.

Make TICKLESS_IDLE depend on hardware that supports it.

Change-Id: I6a2e4fb0f7cf4b45475b48e71823ea089ee98759
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-12-19 19:58:35 +00:00
Anas Nashif c1f2e26584 timer: hpet: rename debug function to avoid conflict
PRINTK was conflicting, reanme to DBG.

Jira: ZEP-953
Change-Id: If5d6ef385c5ed223f6f7eae9bde887ae4a1b946a
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-12-19 19:17:33 +00:00
Anas Nashif 5ad2905532 arm: remove old GDB_INFO support
That module is not used anymore: it was introduced pre-Zephyr to add
some kind of awareness when debugging ARM Cortex-M3 code with GDB but
was never really used by anyone. It has bitrotted, and with the recent
move of the tTCS and tNANO data structures to common _kernel and
k_thread, it does not even compile anymore.

Jira: ZEP-1284, ZEP-951

Change-Id: Ic9afed00f4229324fe5d2aa97dc6f1c935953244
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-12-19 19:17:30 +00:00
Carles Cufi ca0951d42d drivers: timer: Optimize RTC driver and prevent past events
The nRF RTC driver, which is used a system clock driver due to the lack
of SysTick hardware on the SoC, was using too much CPU time in its
_timer_idle_exit() implementation due to the use of 64-bit arithmetical
operations. This was causing the ISR wrapper to add excessive latency to
critical interrupts, causing BLE controller asserts.
This patch addresses the issue by using exclusively RTC ticks instead of
OS ticks, thus avoiding the necessity to convert during
_timer_idle_exit() calls, which are the most critical to interrupt
latency.

In addition the driver is now able to detect setting tick events in the
past due to it being interrupted by a higher priority context, and will
reschedule and trigger the ISR at the same time.

Change-id: I56a3be96b9fdd554c3650012d647af2f0415eb8a
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-12-16 12:51:15 +00:00
Julien Delayen d127864366 arcv2_timer0: Add suspend and resume support
When going into DEEP_SLEEP state, the ARC timer
needs to be restored.

This implements the function to restore the timer
after sleep.
As the time spent during sleep is not currently known,
the timer is expired to reschedule the application task.

Jira: ZEP-1224

Change-Id: I22a30d0fd79f177cf166b9a29dc78d68f7d7fbad
Signed-off-by: Julien Delayen <julien.delayen@intel.com>
2016-12-15 12:49:32 +00:00
Kumar Gala 41c6493472 drivers: timers: remove unneeded include path addition
ccflags-y += -I$(srctree)/kernel/unified/include isn't need so lets
remove it.

Change-Id: I910bbac4a189de965d844f5fc36571e8dcb5705d
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2016-12-10 02:15:49 +00:00
Flavio Santes b04cdcd6e6 drivers: Remove legacy nanokernel.h include
This commit replaces the nanokernel.h include by kernel.h.

Change-Id: Ib42fbf2d9f77a73c0831f569b3dbbfb342ea2e1d
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2016-12-04 14:59:37 -06:00
Vinayak Chettimada 6276ca68c8 drivers: timer: replace deprecated interface in nrf_rtc_timer
Rename sys_cycle_get_32 to k_cycle_get_32 in nrf_rtc_timer.

Change-id: I50af876b254dc5bc3dbb2ccfdf27d33bc4b8d5e5
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-11-30 19:21:54 +00:00
Vinayak Chettimada 883f9c39f7 drivers: timer: Fix missing sys_clock_disable in nrf_rtc_timer
Change-id: Ia453b8484050c8431d2f793e8f5726684afa21f4
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-11-30 17:25:48 +00:00
Anas Nashif 247a4509ce drivers: nrf timer: remove unused variable
retval is not being initialised or set.

Change-Id: Iaab4f1acbb009b1fb9cdbc4b3c29ffb696dc8615
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-11-27 22:36:02 -05:00
Vinayak Chettimada a100ada866 drivers: timer: nRF SoC Series RTC system clock implementation
The nRF5x series SoCs do not implement systick, hence we disable
CORTEX_M_SYSTICK.
Instead, use nRF SoC Series NRF_RTC1 for system clock interfaces.
The kernel system clock interface is implemented using the low
power real time counter NRF_RTC1. NRF_RTC0 is used by the BLE
controller.

In addition, cleanup nRF5x series defconfig to be consistent.

Jira: ZEP-742
Jira: ZEP-1308
Jira: ZEP-1315

Change-id: I0f6cc1836fe0820a65f2cbb02cf5ae7e9eb92e1d
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-11-27 19:39:27 +00:00
Anas Nashif 92c5f91413 arm: systick: Some SoCs do not have systick
Make the systick feature optional that can be selected by the SoC.

Change-Id: I4a405640b84daecc17fc1882743d3cafb78ff861
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-11-27 19:39:26 +00:00
Benjamin Walsh f6ca7de09c kernel/arch: consolidate tTCS and TNANO definitions
There was a lot of duplication between architectures for the definition
of threads and the "nanokernel" guts. These have been consolidated.

Now, a common file kernel/unified/include/kernel_structs.h holds the
common definitions. Architectures provide two files to complement it:
kernel_arch_data.h and kernel_arch_func.h. The first one contains at
least the struct _thread_arch and struct _kernel_arch data structures,
as well as the struct _callee_saved and struct _caller_saved register
layouts. The second file contains anything that needs what is provided
by the common stuff in kernel_structs.h. Those two files are only meant
to be included in kernel_structs.h in very specific locations.

The thread data structure has been separated into three major parts:
common struct _thread_base and struct k_thread, and arch-specific struct
_thread_arch. The first and third ones are included in the second.

The struct s_NANO data structure has been split into two: common struct
_kernel and arch-specific struct _kernel_arch. The latter is included in
the former.

Offsets files have also changed: nano_offsets.h has been renamed
kernel_offsets.h and is still included by the arch-specific offsets.c.
Also, since the thread and kernel data structures are now made of
sub-structures, offsets have to be added to make up the full offset.
Some of these additions have been consolidated in shorter symbols,
available from kernel/unified/include/offsets_short.h, which includes an
arch-specific offsets_arch_short.h. Most of the code include
offsets_short.h now instead of offsets.h.

Change-Id: I084645cb7e6db8db69aeaaf162963fe157045d5a
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-11-12 07:04:52 -05:00
Andrew Boie 0b474eef9c kernel: deprecate old init levels
PRIMARY, SECONDARY, NANOKERNEL, MICROKERNEL init levels are now
deprecated.

New init levels introduced: PRE_KERNEL_1, PRE_KERNEL_2, POST_KERNEL
to replace them.

Most existing code has instances of PRIMARY replaced with PRE_KERNEL_1,
SECONDARY with POST_KERNEL as SECONDARY has had a longstanding bug
where the documentation specified SECONDARY ran before the kernel started
up, but actually ran afterwards.

Change-Id: I771bc634e9caf7f17dbf214a270bc9967eed7d32
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2016-11-09 17:59:44 +00:00
Andrew Boie 9024a93bee drivers: timer: remove old kernel support
Change-Id: I64169402d6e3b6cb0e89beeceba8b5a3bf734cf4
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2016-11-07 11:32:57 -08:00
Dmitriy Korovkin dc76dbf2ef unified: Add tickless idle support for ARC
Change-Id: I89684e7bee379be0a18f64e4f2c39ae132fe7e6d
Signed-off-by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
2016-10-22 01:27:01 +00:00
Peter Mitsis 96cb05ca50 unified: Add tickless idle support for x86 and ARM
Change-Id: I42d20355321f431900727768a0836ee18e96b667
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-04 20:02:50 +00:00
Ramesh Thomas 0d2b8224b1 timer: Fixes a build error when MVIC is used
MVIC does not have _REG_TIMER_CFG defined because it does
not have a timer config register. Add checks for MVIC at
places where it is used.

Jira: ZEP-1015
Change-Id: I59f5c43cc2d1b17cf9e88b940631c2542e9729ab
Signed-off-by: Ramesh Thomas <ramesh.thomas@intel.com>
2016-10-03 17:28:02 +00:00
Andrew Boie edeb1f1c52 x86: interrupts: optimize and simplify IRQ stubs
Interrupt stubs now just push the ISR and parameter onto the stack
and jump to the common interrupt code, never to return.

Change-Id: I82543d8148b5c7dfe116c43f41791f852614bb28
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2016-09-28 20:28:06 +00:00
amirkapl c490219d1e power_mgmt: Update sample and drivers according to new pm device API
Update the power sample and drivers with the new device driver power
management API using the existing logic

Jira: ZEP-954
Change-Id: Idd94232e458767635973e94e9fc673c01612c1e2
Signed-off-by: Amir Kaplan <amir.kaplan@intel.com>
2016-09-22 00:23:43 +00:00
Javier B Perez 035ec8249d drivers: timer: cortex_m_systick remove dead code
Removed CONFIG_INT_LATENCY_BENCHMARK dead code.
CONFIG_INT_LATENCY_BENCHMARK depends on ARCH="x86", it will never
be true for ARM code.

Change-Id: Ia5779a69b1bf670ebb140c2923c9fe0af6b781d4
Signed-off-by: Javier B Perez <javier.b.perez.hernandez@intel.com>
2016-09-21 23:11:41 +00:00
Javier B Perez d4429bfb88 drivers: timer: loapic remove unused workaround
Removed unused workaround in loapic. There are no references
of usage.

Change-Id: I8700b4b7ce8efef5e7b95e6cdd2b201eae3f1f37
Signed-off-by: Javier B Perez <javier.b.perez.hernandez@intel.com>
2016-09-21 14:51:34 +00:00
Benjamin Walsh 3caec4e95d unified/drivers: adapt timer drivers to unified kernel
They must provide the k_cycles_get_32() API and must not refer to
command packets: the latter do not exist on unified kernels.

Change-Id: Ia354dc060e5ad2595850f97da82d8feb590d16b7
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-13 17:12:55 -04:00
Ramesh Thomas fa175975e9 power_mgmt: Make device_pm_ops definition static
DEFINE_DEVICE_PM macro was not defining device_pm_ops
as 'static'. Fixes the issue and impacted areas.

Jira: ZEP-639
Change-Id: I5e1de6af97bf7b2b690af0c81034ce167e655e43
Signed-off-by: Ramesh Thomas <ramesh.thomas@intel.com>
2016-09-12 00:28:05 +00:00
Andrew Boie e98ac235e6 x86: declare internal API for interrupt controllers
Originally, x86 just supported APIC. Then later support
for the Mint Valley Interrupt Controller was added. This
controller is mostly similar to the APIC with some differences,
but was integrated in a somewhat hacked-up fashion.

Now we define irq_controller.h, which is a layer of abstraction
between the core arch code and the interrupt controller
implementation.

Contents of the API:

- Controllers with a fixed irq-to-vector mapping define
_IRQ_CONTROLLER_VECTOR_MAPPING(irq) to obtain a compile-time
map between the two.

- _irq_controller_program() notifies the interrupt controller
what vector will be used for a particular IRQ along with triggering
flags

- _irq_controller_isr_vector_get() reports the vector number of
the IRQ currently being serviced

- In assembly language domain, _irq_controller_eoi implements
EOI handling.

- Since triggering options can vary, some common defines for
triggering IRQ_TRIGGER_EDGE, IRQ_TRIGGER_LEVEL, IRQ_POLARITY_HIGH,
IRQ_POLARITY_LOW introduced.

Specific changes made:

- New Kconfig X86_FIXED_IRQ_MAPPING for those interrupt controllers
that have a fixed relationship between IRQ lines and IDT vectors.

- MVIC driver rewritten per the HAS instead of the tortuous methods
used to get it to behave like LOAPIC. We are no longer writing values
to reserved registers. Additional assertions added.

- Some cleanup in the loapic_timer driver to make the MVIC differences
clearer.

- Unused APIs removed, or folded into calling code when used just once.

- MVIC doesn't bother to write a -1 to the intList priority field since
it gets ignored anyway

Issue: ZEP-48
Change-Id: I071a477ea68c36e00c3d0653ce74b3583454154d
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2016-09-06 18:35:47 +00:00
Benjamin Walsh 36ece00163 arc/soc: remove unused CONFIG_TIMER0_CLOCK_FREQ
Defined in all SoCs, but never referenced anywhere. That definition has
been replaced by CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC.

Change-Id: I1801f72a03925717ded6fbfdef22b1993f843461
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-08-27 10:49:01 +00:00
Andrew Boie 533c2ee30d arc: fix management of IRQ priority levels
A previous re-work of IRQ priorities was led astray by an incorrect
comment. Priority level 1 is not a non-maskable interrupt priority.
In addition, zero latency IRQs are not implemented on ARC.

Timer driver now doesn't specify IRQ_ZERO_LATENCY (as that wouldn't be
correct) and its IRQ priority is now tunable in Kconfig. The default is 0.

IPM driver on both ARC and x86 side were being configured with hard-coded
priority of 2, which wasn't valid for ARC and caused an assertion failure.
The priority level is now tunable with Kconfig and defaults to 1 for ARC.

Issue: ZEP-693
Change-Id: If76dbfee214be7630d787be0bce4549a1ecbcb5b
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2016-08-17 20:51:05 +00:00
Andrew Boie 96cadd1a9a arc: move special-purpose irq priorities to flags
We have already done this on x86 and ARM. The policy is as follows:

* IRQ priority levels starting at 0 all have the same semantics and
do not have special properties. The priority level is either ignored
on arches which do not support programmable priority levels, or lower
priority levels take precedence over higher ones.
* Special-case priorty levels are specified via flags, in which case
the supplied priority level is ignored.

Issue: ZEP-60
Change-Id: Ic603f49299ee1426fb9350ca29d0b8ef96a1d53a
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2016-07-26 15:06:28 +00:00
Ramesh Thomas 8f0fdb668a timer: Adds device suspend/resume to loapic timer
This is part of a change to enable device suspend/resume and
Deep Sleep support in applications. Adds suspend/resume handling
in loapic timer.

Jira: ZEP-512
Change-Id: I9da2c8419bd9109fb71ef5a6caf736de7c7de9e1
Signed-off-by: Ramesh Thomas <ramesh.thomas@intel.com>
2016-07-21 11:25:31 -07:00
Andrew Boie 133dab4a63 altera_avalon_timer: new timer driver for Nios II
Tickless idle is not yet supported. We program the timer period
to the desired system clock tick rate (sys_clock_hw_cycles_per_tick).

This was renamed to the same name used in the Altera Embedded IP
Peripherals Guide; used by other CPUs than Nios II.

Change-Id: Ic4fca8c16b923295b77b63f98f45cd3483c5f560
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2016-06-22 19:00:35 +00:00
Ramesh Thomas a4568aac44 arc: fixes a missing declaration compile error
Building microkernel for ARC causes a compiler error
due to missing declaration of _sys_idle_elapsed_ticks.
Declare this as extern.

Jira: ZEP-397
Change-Id: I83701f693fea0fcb1ae2c30e0c52abe7987de1f1
Signed-off-by: Ramesh Thomas <ramesh.thomas@intel.com>
2016-05-26 02:15:06 +00:00
Chuck Jordan 49dec0dad5 arc: clarify in comment that ARC must have timer0
The timer implementation for ARC currently requires timer0 to be present.
I've added a comment that this is an assumption and to encourage developers
to build the ARC CPU with Timer0, when it is to be used with Zephyr.
There is also an optional provision for a Timer1. In future, this
code could be conditional to use either timer.

Change-Id: I4eb3aec59ba4e85f8b70d5531b21bdaab00b93bb
Signed-off-by: Chuck Jordan <cjordan@synopsys.com>
2016-05-09 20:56:51 +00:00
Andrew Boie 9433895954 nios2: basic build, non-functional
Basic build framework for Nios2. Everything is stubbed out,
we just want to have a build going so that we can start to
parallelize implementation tasks.

This patch is not intended to be functional, but should be
able to produce a binary for all the nanokernel-based
sanity checks.

Change-Id: I12dd8ca4a2273f7662bee46175822c9bbd99202a
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2016-05-03 23:18:45 +00:00
Ramesh Thomas bb19e6f82f power_mgmt: Make names consistent with new RFC
Changed names of Kconfig flags, variables, functions, files and
return codes consistent with names used in the RFC. Updated
relevant comments to match the changes.

Origin: Original
Change-Id: Ie7941032d7ad7af61fc02928f74538745e7966e8
Signed-off-by: Ramesh Thomas <ramesh.thomas@intel.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-03-26 14:35:11 -04:00
Dmitriy Korovkin 661d2f3a16 microkernel: Add support for *_sleep() during initialization
Add support for task_sleep() and fiber_sleep() during the
system initialization. When CONFIG_NANO_TIMEOUTS defined,
before the k_server() starts, kernel uses nanokernel
system clock announce and task sleep functionality.

To give device drivers early sleep functionality, the system
clock has to start on SECONDARY initialization level, same
as most of the drivers.

Change-Id: Ie1d391945cd1cfb9a5dc199783c2d224eb1b0ef3
Signed-off-by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
2016-03-26 10:17:15 +00:00
Simon Desfarges 9abc29e3ae arc_timer: assert that counter always lower than limit
ASSERT are put each time the timer0 limit register or the timer0 count register
is modified.

Change-Id: I38684d57803de285f4e26c68b449c71396e4c750
Signed-off-by: Simon Desfarges <simon.desfarges@intel.com>
2016-03-24 12:05:37 +00:00
Simon Desfarges a51f88638e arc_timer: fix tickless idle
When exiting from tickless idle uppon an external IRQ, the TICK timer
is set to fire at next TICK boundary. The current algorithm can lead
to a point that timer0_count register is higher than the timer0_limit
register.

In this situation the next TICK will fire after the counter has
wrapped and performed another cycle (~133 seconds).

This condition appears when the counter reaches the limit after the
Interrupt Pending flag is checked. At this point the counter is
automatically wrapped to 0, but is set just next to the limit to fire
at next TICK boundary by SW. At exit of the _timer_idle_exit function,
the timer handler is called, and sets the limit to 1 TICK. At this
point the situation is:
- limit register == 1 TICK
- count register is just below the old limit register and higher than
  1 TICK

To fix this issue, at _timer_idle_exit, the limit register is always
set to 1 TICK and the count register set such as the next TICK fires
on time.

Change-Id: Ifa002809d426aa04109592e53d2b02a224f51101
Signed-off-by: Simon Desfarges <simon.desfarges@intel.com>
2016-03-23 17:21:25 +00:00
Simon Desfarges e6ded3f581 arc_timer: fix wrong programmed limit when entering idle
The timer counts from 0 to programmed_limit included.

Change-Id: Ifc8585210c319f5452fafc911d4f6d72c4b91eaa
Signed-off-by: Simon Desfarges <simon.desfarges@intel.com>
2016-03-23 17:21:24 +00:00
Anas Nashif 4f9239984f Revert "microkernel: Add support for *_sleep() during initialization"
This reverts commit 0d50329105.

This breaks sanitychecks in CI. The early_sleep kernel test case is failing
randomly.

Change-Id: I015f20699c052b4089076699fc0180945c4d3d16
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-03-11 22:08:44 +00:00
Dmitriy Korovkin 0d50329105 microkernel: Add support for *_sleep() during initialization
Add support for task_sleep() and fiber_sleep() during the
system initialization. When CONFIG_NANO_TIMEOUTS defined,
before the k_server() starts, kernel uses nanokernel
system clock announce and task sleep functionality.

To give device drivers early sleep functionality, the system
clock has to start on SECONDARY initialization level, same
as most of the drivers.

Change-Id: I5b3cf3da4c8d8398a966e901ab211f2fcee18dd6
Signed-off-by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
2016-03-10 18:39:33 +00:00
Benjamin Walsh e893869435 Revert "sys_clock: start the microkernel ticker in the MICROKERNEL init level"
This reverts commit 3c66686a43.

That commit fixed announcing ticks before the microkernel was up, but
prevented devices initializing before the MICROKERNEL level from having
access to the hi-res part of the system clock, which they could not poll
anymore.

Change-Id: Ia1c55d482e63d295160942f97ebc8e8afd1e8315
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-02-11 17:26:06 -05:00
Sergio Rodriguez 4dee326306 tickless idle x86: Tickless idle support on nanokernel for x86
Modifications to timer drivers and interrupt setup, to manage
the tickless idle for the x86 architecture

Change-Id: Ie02d484b7e5636de6ea382ba2eeed57e704c8498
Signed-off-by: Sergio Rodriguez <sergio.sf.rodriguez@intel.com>
2016-02-11 19:10:24 +00:00