Commit graph

1347 commits

Author SHA1 Message Date
Vinayak Chettimada 09ba96d856 kernel: declare main and idle stack as globals
Renamed main_stack and idle_stack, to _main_stack and
_idle_stack, respectively, and made them globals. This does
not affect performance. They are still kept kernel private
symbols and not part of kernel API.

This will allow these symbols to be referenced in calls to
stack_analyse misc functions to profile stack usage in
applications.

Change-id: Id6b746c5cfda617c26901c6e62c3e17114471f57
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-11-23 00:24:00 +00:00
Benjamin Walsh 296a234ddb kernel: add support for switching to main thread without _Swap()
It's possible that an architecture needs a custom way of switching to
the main() task, rather than using _Swap() with a dummy thread.

Change-Id: I14e9bc67be35174ff16209bcea27b18a069ff754
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-11-23 00:23:58 +00:00
Benjamin Walsh 8fcc7f69da kernel/arch: remove unused uk_task_ptr parameter from _new_thread()
Artifact from microkernel, for handling multiple pending tasks on
nanokernel objects.

Change-Id: I3c2959ea2b87f568736384e6534ce8e275f1098f
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-11-23 00:23:57 +00:00
Benjamin Walsh 358a53cb2f kernel: support for more than 32 total priorities
In addition to more priorities taking more memory to host them, finding
the next thread to run when it is not cached is slower since each extra
set of 32 priorities maps to a loop iteration. That loop is remove
entirely when the number of priorities is less than 32 (31 + the idle
thread).

Fixes ZEP-1303.

Change-Id: I3205df90d379a0f4456ff1d7f1aaa67ad2cddf15
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-11-18 23:45:34 +00:00
Allan Stephens 66a07bbd48 kernel: Minor optimization to kernel event logger timestamping
Rewrites the timestamping logic to always generate timestamps
via a function pointer that is initialized to sys_cycle_get_32(),
but can be changed to point to a user-supplied function. This
eliminates the need for an if/then/else construct in every place
that a timestamp is generated.

Change-Id: Id11f8c41b193a93cece16565978a525056010f0e
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-11-18 23:17:51 +00:00
Allan Stephens 72efec3d2b doc: Fix up API descriptions for kernel event logger
Prepares the kernel event logger APIs for inclusion in the
API guide. Also corrects a couple of other issues:

* Gets rid of obsolete thread monitor code.
* Renames "timer_func" global variable to "_sys_k_timer_func"
  to align it with kernel naming conventions.

Change-Id: I93d403f83ae44ff45dda489c2ead7bfec6ce1fa3
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-11-18 23:17:50 +00:00
Allan Stephens 671f0ae17e kernel: Ensure event logger APIs convert timeouts to millseconds
Event logger APIs still express timeout delays in ticks;
need to convert to milliseconds when using unified kernel APIs.

Change-Id: I5fab66be660621cd2029417eaff3758e3ef4ba2c
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-11-18 23:17:49 +00:00
Benjamin Walsh a4e033fdba kernel: fix obsolete access to fields in K_DEBUG() calls
When moving arch-specific thread structure to arch-agnostic, some field
accesses were missed when used in K_DEBUG statements, which are turned
off by default.

Change-Id: Ife0f49b8185a0db468deab73555f7034f20ca3e8
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-11-18 23:08:47 +00:00
Benjamin Walsh 669360d5ec kernel: fix thread prio and stack size types in some APIs
Prio should be an int, since values are small integers, not a fixed-size
int32_t. It aligns with the prio parameters of the other APIs.

Stack size should be size_t.

Change-Id: Id29751b86c4ad7a7c2a7ffe446c2a96ae83c77bf
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-11-18 23:08:46 +00:00
Anas Nashif 61f4b2419c kernel: remove v2 usage and rename KERNEL_V2_DEBUG
Change-Id: I6b3f07714322ad79aeec2342621a4cddfe84cb2c
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-11-18 19:00:34 +00:00
Allan Stephens 82d4c3a68b doc: Minor cosmetic tweaks for kernel API descriptions
Change-Id: Ie989b45b19e5e70958301dd8d903cf2876709f5a
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-11-18 02:31:35 +00:00
Anas Nashif 3accae1da6 kernel: event_logger: use POST_KERNEL instead of NANOKERNEL
NANOKERNEL is obsolete and this kernel service is still using it causing
deperecaton warnings. Move it to POST_KERNEL

Change-Id: I17fabd080645f93a8599f4ea25da844e1ec5f4bb
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-11-18 00:24:26 +00:00
Allan Stephens ac4a351ba9 kernel: Enhance naming of memory pool configuration options
Replaces confusing (and excessively long) configuration option
names with more intuitive names. Also enhances the description
of each option to clarify its use.

Change-Id: If4d4541407627482b1e90302cfc9df3bc8130d44
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-11-16 21:43:17 +00:00
Benjamin Walsh 59a382e339 kernel: remove last instances of tNANO in comments
Change-Id: I3d533b819422d4b754afb81d3ea67c03bc7f5630
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-11-14 10:30:24 -05:00
Benjamin Walsh ba26678fc6 kernel: fix typo in comment
Change-Id: I1919fd7b0ae3cb3ac434acc2dceddf3afb4a975b
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-11-14 10:30:18 -05:00
Anas Nashif 8f6c3c666d kernel: remove nano and micro default configs
Change-Id: Ibe73b4fe25822731ad6c671cdefe0d8d5923a3e0
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-11-13 13:54:13 +00:00
Anas Nashif 22a75145ef kernel: event_logger: fixed assert checking for priority
prio is member of base, not k_thread struct.

Change-Id: I77de52497e196eb058bf8850e25eabe42cb2ab14
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-11-12 21:38:38 -05:00
Benjamin Walsh ade6dc937f kernel: fix mailbox usage of SYS_DLIST_FOR_EACH_NODE()
SYS_DLIST_FOR_EACH_NODE() is marked as non-safe when an item is removed
from the list while looping over it. This is not true per-se, since the
item, when removed, keeps its next and prev pointers intact; however, it
is true if the item is then put into a list, be it a different one or
the same one. To prevent this, SYS_DLIST_FOR_EACH_NODE_SAFE() must be
used.

_mbox_message_put() can remove items from the rx queue and then put them
in the ready queue: this would cause the loop to start processing other
ready threads as item in the rx queue.

k_mbox_get() also removes items, from the tx queue, but does not seem to
add them to another list; however, it now uses the safe version as well,
since that is the proper usage.

Change-Id: Ieccbff238fc8a036c0d53d873eaaf55f4f5a14af
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-11-12 21:16:01 +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
Allan Stephens dd07b4779f kernel: Eliminate use of KERNEL_V2 configuration option
The unified kernel is now the only supported kernel, so this
option is unnessary. Eliminating this option also enables
the removal of some legacy code that is no longer required.

Change-Id: Ibfc339d643c8de16a2ed2009c9b468848b8b4972
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-11-12 12:04:39 +00:00
Allan Stephens 3cd702010f kernel: Fix bug in dynamic alert initialization
k_alert_init() needs to set the "flags" field of its associated
work item to zero, indicating that the work item has not yet
been submitted to the system workqueue. Using the standard work
item initializer macro ensures this is done correctly.

Change-Id: I0001a5920f20fb1d8dc182191e6a549c5bf89be5
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-11-11 22:13:30 +00:00
Ramesh Thomas 8367056efa power_mgmt: Rename _sys_soc_resume notification disabling API
The API to disable _sys_soc_resume notification is currently
called _sys_soc_disable_wake_event_notification. This is
misleading because it is possible that the ISR from which
_sys_soc_resume is called could be from a different interrupt
with higher priority that happened before interrupts were
enabled. More accurately, it is a notification of exit from
kernel idling after pm operations.

Jira: ZEP-1271
Change-Id: I83747f2cacac1bc17f135d12f4aa4478970fc02d
Signed-off-by: Ramesh Thomas <ramesh.thomas@intel.com>
2016-11-11 20:40:54 +00:00
Ramesh Thomas c0cd7acf34 power_mgmt: Simplify _sys_soc_resume notification
_sys_soc_resume hook is over loaded to handle to different
scenarios. It is primarily called to notify exit of kernel idling
after PM operations. It is also used to notify exit from deep sleep.
This is very confusing and also makes the implementation of the
hook function very difficult because of very different conditions
involved in the 2 different use cases. Further, users may not require
either or both use cases depending of their custom boot flow and
power state handling. To simplify, create a separate hook for the
purpose of deep sleep exit notification. Use the existing one to
only notify kernel idling exit after PM operations.

Jira: ZEP-1256
Change-Id: I96350199a0fd37f16590c8ee5302a94a3d71b8ba
Signed-off-by: Ramesh Thomas <ramesh.thomas@intel.com>
2016-11-11 20:40:52 +00:00
Benjamin Walsh 8215ce19ce kernel: fix k_msgq_get/put() from ISR
There was no check to see if the current context was running an ISR when
taking a decision whether to do a context switch or not.

Change-Id: Ib9c426de8c0893b3d9383290bb59f6e0e41e9f52
Signed-off-by: Benjamin Walsh <walsh.benj@gmail.com>
2016-11-10 23:38:06 +00:00
Benjamin Walsh 445830dcec kernel: add k_is_preempt_thread()
Useful for finding out if the current thread is protected against
preemption when using non-preemption to protect data structures.

Change-Id: Ib545a3609af3646ba49eeeb5a2c50dc51af010d4
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-11-10 23:18:56 +00:00
Benjamin Walsh d7ad176be6 kernel: export k_sched_lock and k_sched_unlock.
Oversight. These functions are used extensively in the kernel guts, but
are also supposed to be an API.

k_sched_lock used to be implemented as a static inline. However, until
the header files are cleaned-up, and everything, including applications
get access to the kernel internal data structures, it must be
implemented as a function. To reduce the cost to the internals of the
kernel, the new internal _sched_lock() contains the same implemetation,
but is inlined.

Change-Id: If2f61d7714f87d81ddbeed69fedd111b8ce01376
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-11-10 23:18:55 +00:00
Allan Stephens 073442ecc5 kernel: Treat aborting by main() as a fatal system error
An application-supplied main() routine is now considered to be
essential to system operation. Thus, if main() experiences an
error that aborts the main thread a fatal system error is raised.

Note: If main() completes its work and does a standard return-
to-caller the main thread terminates normally.

Change-Id: Icc9499f13578299244a856a246ad2a7d34a72f54
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-11-10 18:51:42 +00:00
Allan Stephens 40325d2d28 kernel: Fix bug in spawning of legacy tasks using floating point
A thread defined via a legacy MDEF that belongs to the FPU or
SSE task group must set the thread option bits for FP or SSE
register use prior to being spawned.

If this is not done, and the kernel is configured for SSE support,
the kernel will auto-enable the thread's use of floating point
so that the thread saves SSE register context info even if it
belongs to just the FPU task group, which could cause the thread
to overflow its stack.

Note that this change only increases footprint for x86-based
applications that enable floating point register sharing.

Change-Id: Idfe4d20bcd7bc42b4cee6ac40ad7987e2a45ccf6
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-11-10 18:51:41 +00:00
Anas Nashif d3e2b0255a kernel: logger: move to unified kernel APIs
move to new APIs and cleanup syntax a bit.

Change-Id: Idc9a663ddcc4886182c5d5120261b813de1e5ad2
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-11-09 23:01:42 +00:00
Andrew Boie b85e58ad6d kernel: don't directly use deprecated sys_tick_get APIs
Change-Id: I438769018e1002d508e4a22bdd6806f77e1a1394
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2016-11-09 19:59:07 +00: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
Benjamin Walsh c7ba8b17e1 kernel: rename k_am_in_isr() to k_is_in_isr()
Change-Id: Ie312da34dbbfbeb2c76bbf38905d8f334da28b63
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-11-08 20:27:31 -05:00
Benjamin Walsh 3cc2ba9f9c kernel: add __ASSERT() for thread priorities
Verify the thread priorities are within the bounds when starting a new
thread and when changing the priority of a thread.

Change-Id: I007b3b249e4b80235b6439cbee44cad2f31973bb
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-11-08 20:27:31 -05:00
Benjamin Walsh c13fad3bb8 kernel: add utility functions to compare thread priorities
Since lower-numbered thread priorities are higher, the code can be
misleading when comparing priorities, and often require the same type of
comments. Instead, use utility inline functions that does the
comparisons.

_is_prio_higher already existed, but add comparisons for "lower than",
"higher than or equal to" and "lower than or equal to".

Change-Id: I8b58fe9a3dd0eb70e224e970fe851a2575ad468b
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-11-08 20:26:39 -05:00
Benjamin Walsh 8450c903be kernel: fix issues in idle thread
- Add missing irq_lock() before invoking power management.
- Only yield if the idle thread is a coop thread (in coop-only
  configurations).

Change-Id: I030795e782590b3023f1d7883bbd058da2c45f4f
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-11-08 23:38:55 +00:00
Benjamin Walsh 4e5b4c74af kernel_event_logger: fix _current.prio acces in __ASSERT()
_current is a pointer.

Change-Id: I8efbd1daca58b687732abec4d759f10a5dff8ef6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-11-08 23:38:34 +00:00
Dmitriy Korovkin 6f357b60ff unified/kernel: Assert that mutex is not unlocked without previous locking
Add an assertion against unlocking mutex that is not locked.

Change-Id: I1032fb904e364015b486502c035529c8fe31de7a
Signed-off-by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
2016-11-08 21:34:29 +00:00
Andrew Boie e51c4c2989 kernel: remove old kernel support in v2 code
Change-Id: I3675ff42c9742664351975294f61b920995f0c3a
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2016-11-07 11:34:18 -08:00
Andrew Boie 4f798177cf kernel: remove old micro/nanokernel C code
include/ will be cleaned up in a subsequent patch.

Change-Id: If3609f5fc8562ec4a6fec4592aefeec155599cfb
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2016-11-07 19:29:19 +00:00
Allan Stephens 22ea605eab kernel: Remove traces of legacy task groups from public API
Change-Id: Id4c4508020063ac8a7186daea7b56f5ce29a62d6
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-11-07 18:52:32 +00:00
Anas Nashif 12ffc58d4b benchmarks: rename _NanoTscRead -> _tsc_read
Change-Id: Id5687f79ac13136f14a14d250e149436a0173f04
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-11-07 15:39:15 +00:00
Benjamin Walsh 8cf56bcac7 unified: dissociate system workqueue from common workqueue module
Making a reference to the common work queue code should not necessarily
drag in the system workqueue, since it is possible to use a workqueue
that is not the system workqueue. This is done by moving the system
workqueue into its own code module.

Moving the system workqueue to its own code module allows removing the
NANO_WORKQUEUE and SYSTEM_WORKQUEUE kconfig options, and compiling the
common workqueue code and system workqueue all the time. They are only
linked in the final image if a reference to them exist, same as the
other kernel modules.

Change-Id: I6f48d2542bda24f4702e7c2e317818dd082b3c11
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-11-04 22:39:54 +00:00
Allan Stephens 1342adbd63 unified: Add missing arguments to K_TIMER_DEFINE()
It is now possible to specify the expiry and stop functions
of a statically-defined timer, just as can be done for a
dynamically-defined timer.

[Part of fix to ZEP-1186]

Change-Id: Ibb9096f3fdafdc6c904184587f86ecd52accdd66
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-11-04 00:47:23 +00:00
Allan Stephens a3f3de3741 unified: Rename ESSENTIAL to K_ESSENTIAL
Adds standard prefix to symbolic option that flags a thread
as essential to system operation.

Change-Id: Ia904a81ce343fdd1cd44caaaeae641d822777f9b
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-11-04 00:47:08 +00:00
Ramesh Thomas ded076d175 tests: power_mgmt: Make power test unified kernel based
Port the power management test app to use unified kernel.

Change-Id: I2f10748be5ca7d9792f6e97c35f5f2aabab769e7
Signed-off-by: Ramesh Thomas <ramesh.thomas@intel.com>
2016-11-03 14:47:56 -07:00
Julien Delayen fec01af64a power: Update Quark SE PM layer with QMSI 1.3
QMSI 1.3 natively supports restoring the SoC and peripherals
after sleep.

The Zephyr Power Management shim layer is updated
in order to support QMSI functions.

The following functions have been added:
void _sys_soc_set_power_state(enum power_state);
void _sys_soc_power_state_post_ops(void);

In order to fully support deep sleep, the function
_sys_soc_set_power_state now support saving and
restoring CPU context and returns to the application.

_sys_soc_set_power_state function also abstracts
QMSI cpu states and enable the application to choose
between C1/C2 or C2LP states.

The QMSI power states are mapped as follows:
SYS_SOC_POWER_STATE_CPU_LPS -> power_cpu_c2lp
SYS_SOC_POWER_STATE_CPU_LPS_1 -> power_cpu_c2
SYS_SOC_POWER_STATE_CPU_LPS_2 -> power_cpu_c1
SYS_SOC_POWER_STATE_DEEP_SLEEP -> power_soc_deep_sleep
SYS_SOC_POWER_STATE_DEEP_SLEEP_1 -> power_soc_sleep

The following functions have been removed:
void _sys_soc_set_power_policy(uint32_t pm_policy);
int _sys_soc_get_power_policy(void);
FUNC_NORETURN void _sys_soc_put_deep_sleep(void);
void _sys_soc_put_low_power_state(void);
void _sys_soc_deep_sleep_post_ops(void);

Those changes are propagated to the samples.
All calls to QMSI are removed.

Jira: ZEP-1045, ZEP-993, ZEP-1047

Change-Id: I26822727985b63be0a310cc3590a3e71b8e72c8c
Signed-off-by: Julien Delayen <julien.delayen@intel.com>
Signed-off-by: Ramesh Thomas <ramesh.thomas@intel.com>
2016-11-03 21:31:30 +00:00
Allan Stephens e7d2cc216d unified: Add object tracing support for kernel objects
Defines an object tracing list for each kernel object type
that supports object tracing, and ensures that both statically
and dynamically defined objects are added to the appropriate list.

Ensure that each static kernel object is grouped together with
the other static objects of the same type. Revise the initialization
function for each kernel type (or create it, if needed) so that
each static object is added to the object tracing list for its
associated type.

Note 1: Threads are handled a bit differently than other kernel
object types. A statically-defined thread is added to the thread
list when the thread is started, not when the kernel initializes.
Also, a thread is removed from the thread list when the thread
terminates or aborts, unlike other types of kernel objects which
are never removed from an object tracing list. (Such support would
require the creation of APIs to "uninitialize" the kernel object.)

Note 2: The list head variables for all kernel object types
are now explicitly defined. However, the list head variable for
the ring buffer type continues to be implicitly defined for the
time being, since it isn't considered to be an core kernel object
type.

Change-Id: Ie24d41023e05b3598dc6b344e6871a9692bba02d
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-11-02 21:56:27 +00:00
Peter Mitsis 058fa4e493 unified: API changes to event handling
Allows event objects to pend signals in a cumulative way using
the semaphore in a non-binary way.

Jira: ZEP-928
Change-Id: I3ce8a075ef89309118596ec5781c15d4f3289d34
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-11-01 16:27:41 -04:00
Peter Mitsis 348eb4c4fb unified: Update kernel.h doxygen comments
Jira: ZEP-981
Change-Id: I3797f5e8824b4a01153f3c1fe0e070d3b107f596
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-31 23:56:04 +00:00
Peter Mitsis 5f8fa677b5 unified: Fix boot_time nanokernel benchmark
Enables boot time timestamps for unified kernel.

Also Splits the source code into microkernel and nanokernel versions
instead of having common code. Not only does this make the code for
each project easier to read, but it also easily allows the nanokernel
version to link against the correct version of main().

Change-Id: Ie0afa2272c3347ebdacc0e3daeebbfe9583fe596
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-31 17:06:26 +00:00
Andrew Boie f1c373c2d5 unified: handle MDEF files that declare main()
Before, the kernel would run the main() function twice; first
as an entry in k_task_list, and then again from _main(). The
_main() invocation would be using a potentially insufficient stack
size.

Now if an MDEF file declares a main() thread, invoke it from
_main(), but honor the desired priority and stack size.

Issue: ZEP-1145
Change-Id: I1abf38fc038e270059589b11d96fae1b3f265208
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2016-10-28 21:54:38 +00:00
Benjamin Walsh 31a3f6a70e unified: rename 'events' to 'alerts'
Event is such an overloaded and generic term (event logger, *kernel*
event logger, "protocol" events in other subsystems, etc.), that it is
confusing for the name an object. Events are kinda like signals, but not
exactly, so we chose not to name them 'signals' to prevent further
confusion. "Alerts" felt like a good fit, since they are used to "alert"
an application that something of significance should be addressed and
because an "alert handler" can be proactively registered with an alert.

Change-Id: Ibfeb5eaf0e6e62702ac3fec281d17f8a63145fa1
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-10-28 18:44:18 +00:00
Benjamin Walsh 7ef0f624a7 unified: rename 'memory maps' to 'memory slabs'
This better aligns with the actual functionality of the object.

Change-Id: I70abf54f994e92abd7367251089ea4f735d273fe
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-10-28 18:44:18 +00:00
Dmitriy Korovkin 3c7dda3897 unified/arc: Fix scheduler algorithm bug
Fix the error in thread rescheduling:

Fix Fast IRQ exit routine error when it reschedules threads if
(prio >= 0) || (sched_locked == 0) || (next_thread == _current),
while the correct condition for thread rescheduling is:
(prio >= 0) && (sched_locked == 0) && (next_thread != _current),

Fix regular IRQ error when the regular IRQ exit routine rescheduled
threads when (next_thread == _current) instead of
(next_thread != current).

Increased IDLE_STACK_SIZE for ARC architecture, to hold saved
registers.

Change-Id: I1d87a968e231e13822844b7564567e6ca310cde2
Signed-off-by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
2016-10-28 17:46:54 +00:00
Benjamin Walsh b452817b67 kernel: merge _IS_IN_ISR() with _is_in_isr()
They were the same, standardize on the lowercase one.

Change-Id: I8bca080e45f3e0970697d4451e468b9081f96f5f
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-10-27 21:45:03 +00:00
Ramesh Thomas 3e0f20a7d5 power_mgmt: Update changes in k_idle.c missing in idle.c
Some changes that went into k_idle.c were missing in idle.c
causing errors while building power management code for
unified kernel. Added the missing changes.

Tested with power_mgr app built for unified kernel.

Jira: ZEP-1139
Change-Id: I9fe005544f7ee69d3cb3ff10c649be28037fcf15
Signed-off-by: Ramesh Thomas <ramesh.thomas@intel.com>
2016-10-27 21:18:43 +00:00
Allan Stephens 743bdb8143 unified: Enable handling of thread options for static threads
Change-Id: I51d2d9cfa0eeb5f974a6cf1db32406399ef57418
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-10-27 08:36:14 -05:00
Benjamin Walsh 115d118a2e unified: remove mention of 'fiber' in kernel_event_logger
Adapting to unified kernel naming of 'coop thread'.

Change-Id: I66cb766c2269acf0867e434bc21f633ea1111f89
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-10-26 23:38:14 +00:00
Benjamin Walsh 10f30a5f61 kernel event logger: fix longer-than-80 chars lines
Change-Id: I503c18d339a0731b0fcbb7b83b3dc16b08c2d7a1
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-10-26 23:38:07 +00:00
Benjamin Walsh 673cd8bc2b unified: add _sem_give_non_preemptible()
Needed by the kernel event logger when it records a context switch.

The kernel event logger releases a semaphore when a new event is
available in the log so that a thread can consume the event. However,
giving that semaphore cannot add a context switch event itself in the
log or the logger would be caught in an infinite loop.

Change-Id: I571a4aa0d302775e09cdc2d654a6b61f8b2e42c7
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-10-26 23:37:59 +00:00
Benjamin Walsh c9dd56ec71 unified: add kconfig option for idle thread stack size
Idle thread may need a bigger stack depending on extra work it has to
do, like power management or kernel event logging.

Change-Id: Iff691d7838036d602bad79799820b68ad55ad00f
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-10-26 20:42:11 +00:00
Allan Stephens 9f0977791f unified: Cosmetic changes to thread-code comments
Eliminates references to "fibers" and "tasks". Eliminates unnecessary
doxygen tags for internal routines. Miscellaneous other corrections
and improvements.

Change-Id: I0272fa477773c075799b67138bad5debcfd6b01e
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-10-26 17:03:14 +00:00
Allan Stephens 4aef71b9f6 unified: Finish adding thread monitoring support
Existing code wasn't removing a thread from the kernel's list
of active threads if the thread terminated or aborted. (It did
remove it if the delayed starting of a thread was cancelled.)

Change-Id: Icc97917e33765696480d0e9bf31e882ef555d095
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-10-26 17:03:13 +00:00
Allan Stephens 1be7bca333 kernel: Add interrupt locking to thread monitoring exit API
This is needed because some thread termination paths can be
invoked with no guarantee that thread preemption won't happen.
(It also aligns with the approach taken by the thread monitoring
initialization code.)

Change-Id: I28a384e051775390eb047498cb23fed22910e4df
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-10-26 17:03:13 +00:00
Allan Stephens 92e75040a2 kernel: Revise thread monitoring exit API naming
Renames _thread_exit() to _thread_monitoring_exit() to make
its purpose clearer. Revises the associated comments and
removes unnecessary doxygen tags.

Change-Id: I010a328d35d2d79d2a29b9d0b6c02097bb655989
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-10-26 17:03:12 +00:00
Allan Stephens e262615280 unified: Remove k_thread_abort_handler() support
The new kernel doesn't support the thread abort handler concept,
so only the legacy API for this capability is needed.

Change-Id: Ie809092e73b784504c3d298911d216bed8dd8993
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-10-26 17:03:12 +00:00
Allan Stephens 480a131ad9 unified: Support heap memory pool
Fleshes out the prototype heap memory pool support
to make it fully operational. Noteworthy changes are
listed below:

Tweaks arguments to k_malloc() and k_free() to be more like
malloc() and free(). Similarly, modifies k_free() to take
no action when passed a NULL pointer.

Now stores the complete block descriptor at the start
of any block allocated from the heap memory pool. This
increases memory overhead by 4 bytes per block, but
streamlines the allocation and freeing algorithms. It also
ensures that the routines will work if the block descriptor
internals are changed in the future.

Now allows the heap memory pool to be defined using the
HEAP_MEM_POOL_SIZE configuration option. This will be the
official configuration approach in the unified kernel.

Also allows the heap memory pool to be defined using the
(undocumented) HEAP_SIZE entry in the MDEF. This is provided
for legacy reasons only.

Co-locates memory pool initialization code to keep the line
that causes memory pool initialization to be done during booting
right next to the routine that does the initialization.

Change-Id: Ifea9d88142fb434d4bea38bb1fcc4856a3853d8d
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-10-25 00:10:34 +00:00
Allan Stephens 904cf97263 unified: Eliminate thread config structure used by work queues
Reworks k_work_q_start() so that it accepts its 3 configuration
settings directly, rather than forcing the caller to pass in a
configuration data structure.

Change-Id: Ic0bd1b94f1a1c8e0f8a84b3bd3677d59d0708734
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-10-25 00:10:34 +00:00
Ramesh Thomas 6249c567f5 device_pm: Update control function name and doc to indicate PM specific
PM control function is used only by the PM subsystem. Update
documentations to make it clear and name the relevant structures and
functions with _pm_ in the name.

Jira: ZEP-1044
Change-Id: I29e5b7690db34a228ed30a24a2e912e1360a0090
Signed-off-by: Ramesh Thomas <ramesh.thomas@intel.com>
2016-10-21 23:32:52 +00:00
Peter Mitsis 429f69a8f6 unified: idle.c to include power.h
Needed to resolve various undeclared symbols when SYS_POWER_MANAGEMENT
is enabled.

Jira: ZEP-1073
Change-Id: I21db2580efb15c80d84d9163fe9e8245d6dc0391
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-21 15:59:44 +00:00
Peter Mitsis 5f39924e58 unified: memory pool APIs to use size_t
Change-Id: Id1dd37ad3bb35052fd53a6a26711c9e0c2070a25
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-21 15:33:58 +00:00
Peter Mitsis fb02d576c0 unified: Memory map APIs to use size_t
Change-Id: I035019c0cb7193400d02f493546fd3964baf073a
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-21 15:33:45 +00:00
Peter Mitsis 4a5d62fe15 unified: Update mem_map doxygen style function headers
Change-Id: Ic683a3ea6f723cf3d615ad28ebf603ed50af9155
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-21 15:33:44 +00:00
Allan Stephens b9a4bd906c kernel: Relocate ring buffer suppport to 'misc' directory
Moves the source code for ring buffers to the 'misc' area, since
it isn't really a central component of the kernel. (This also
aligns the ring buffer source code with its include file, which
is already under 'include/misc'.)

Change-Id: I765a383a05f51fa67d154446f412496e689f9702
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-10-21 15:33:31 +00:00
Allan Stephens 729fdf8ec8 unified: Rename file containing legacy task offload support
Add 'legacy_' prefix, as per the revised naming convention.

Change-Id: I0eaff33a561523ad11621b3104862c574930556e
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-10-21 15:33:30 +00:00
Allan Stephens 7f6f948b30 unified: Eliminate kernel's 'legacy' directory
Since the unified kernel's build system doesn't properly handle
a file in the 'legacy' directory if it contains an initialization
function, some legacy code can't be located there. To avoid confusion,
the revised convention for legacy code is to keep any file that
contains only legacy code in the main kernel directory, and to give
it a "legacy_" prefix.

Change-Id: I019adc8f36611d4481bdcf31dde66597d4cf54ae
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-10-21 15:33:30 +00:00
Allan Stephens 6c98c4d378 unified: Ensure delays do not time out prematurely
Ensures that all APIs which accept a timeout value wait for at least
the specified amount of time, and do not time out prematurely.

* The kernel now waits for the next system clock tick to occur before
  the timeout interval is considered to have started. (That is, the only
  way to ensure a delay of N tick intervals is to wait for N+1 ticks
  to occur.)

* Gets rid of ticks -> milliseconds -> ticks conversion in task_sleep()
  and fiber_sleep() legacy APIs, since this introduces rounding that
  -- coupled with the previous change -- can alter the number of ticks
  being requested during the sleep operation.

* Corrects work queue API that was incorrectly shown to use a delay
  measured in ticks, rather than milliseconds.

Change-Id: I8b04467237b24fb0364c8f344d872457418c18da
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-10-21 15:33:29 +00:00
Peter Mitsis 026b4ed4e2 unified: msgqs to use size_t
Change-Id: I9bedf22a052990395a1f83417c533b197b31987a
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-20 15:20:40 -04:00
Allan Stephens 45bfa37f97 unified: Revise timer code to conform to new API specification
Provides users with a more compact and intuitive API for kernel
timers.

Provides legacy support for microkernel timers and nanokernel
timers by building on the new kernel timer infrastructure.
Each timer type requires only a small amount of additional
wrapper code, as well as the addition of a single pointer
field to the underlying timer structure, all of which will be
easily removed when support for the legacy APIs is discontinued.

Change-Id: I282dfaf1ed08681703baabf21e4dbc3516ee7463
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-10-19 18:14:58 +00:00
Peter Mitsis d7a3750b3c unified: Update msgq doxygen styled function headers
Change-Id: I4648ebcda9e6c3abea05b420584e2bcb112f3ed4
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-19 14:54:45 +00:00
Peter Mitsis 1da807e7a8 unified: Tweak msgq API parameters
- Reorders parameters where necessary
 - Adds alignment parameter to K_MSGQ_DEFINE() for buffer alignment
 - Renames parameters where necessary so they are more intuitive

Change-Id: I0b53105c04109127897bf4790e6908082f82da4e
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-19 14:54:44 +00:00
Peter Mitsis 578f9111ed unified: Tweak mem_map API parameters
- Reorders parameters where necessary
 - Adds buffer alignment parameter to K_MEM_MAP_DEFINE()

Change-Id: Ifa1a09c62492cd6db8bdd83f31a5ca5ba072b484
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-18 15:31:51 +00:00
Peter Mitsis 937042c22a unified: Update mem_pool doxygen style function headers
Change-Id: I3b751522bbabaec5c5146cc28b85d188344a693f
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-18 15:30:40 +00:00
Allan Stephens 7e6540a301 unified: Fix bug in invocation of init functions
Now invokes any microkernel-level init functions used by
legacy applications.

Change-Id: I8f68ddba764f13d037a679b74121713983f4aaba
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-10-18 15:29:17 +00:00
Peter Mitsis b2fd5be4dc unified: Rework K_THREAD_DEFINE()
K_THREAD_DEFINE() can no longer specify a thread group. However, it now
accepts a 'delay' parameter just as k_thread_spawn() does.

To create a statically defined thread that may belong to one or more thread
groups the new internal _MDEF_THREAD_DEFINE() macro is used. It is only used
for legacy purposes.

Threads can not both have a delayed start AND belong to a thread group.

Jira: ZEP-916
Change-Id: Ia6e59ddcb4fc68f1f60f9c6b0f4f227f161ad1bb
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-17 17:52:33 +00:00
Peter Mitsis 1209270bf8 unified: Relocate mailbox doxygen style function headers
Change-Id: I06e9ce40da650df67f05db8779a5f6199e6091d5
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-15 07:41:23 +00:00
Peter Mitsis 40680f6eb9 unified: Tweak mailbox API parameters
Tweak mailbox API parameters so that not only are their descriptions
correct, but their names match across header file and C file.

Change-Id: Ieeb3a40fb7c535a5eac2e06533d01d13aaf69181
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-15 07:41:23 +00:00
Peter Mitsis e5d9c58301 unified: Tweak pipe API parameters
- Reorders parameters where necessary
 - Adds alignment parameter to K_PIPE_DEFINE()
 - Renames parameters where necessary so they are sync'd
   between header and source files

Change-Id: I4f2367abc28aff646cc90beb9f08bb266e143b0c
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-15 07:09:58 +00:00
Allan Stephens be315245a0 unified: Fix bug in memory pool defragmentation code (ZEP-1051)
Reverts a change that was made to the defragmentation routine
when memory pool support was ported from the microkernel to the
unified kernel.

The change was intended to improve the readability of the algorithm,
but introduced a subtle change in behavior. For example, when
k and i are zero and the number of block set entries is one
the original algorithm did not execute the while loop, while the
revised algorithm executed the loop once.

Change-Id: I2b0263a8d7b80846013c459847817d314f803457
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-10-14 21:15:42 +00:00
Benjamin Walsh b4b108de4d unified: rename sched.h to ksched.h
Build breaks when enabling CONFIG_NEWLIB_LIBC because it has its own
sched.h file.

This is a bad symptom of a greater issue: the build system passes many
'-I<path>' options to the compiler, and that allows including header
files by simply specifying their names (when located somewhere else than
<zephyr>/include/) and can cause clashes when several files in different
locations have the same name, like in this case.

Fixes ZEP-1062.

Change-Id: I81d1d69ee6669a609cd0c420b1b8f870d17dcb67
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-10-14 20:49:36 +00:00
Benjamin Walsh 3751123fa9 unified: align prototype and definition of k_thread_priority_set
Change-Id: I7299ded2fc66acb5806499ea26e1e5daedc7cc9c
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-10-14 20:49:36 +00:00
Allan Stephens 1d07bd1bff unified: Eliminate support for dynamic timers
Gets rid of official support for dynamic timer allocation
in the unified kernel, since users can easily define and
initialize timers at any time. Legacy support for dynamic
timers is maintained for backwards compatibility reasons
for the time being ...

Change-Id: I12b3e25914fe11e3886065bee4e96fb96f59b299
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-10-13 13:54:00 +00:00
Allan Stephens 018cd9a656 unified: Eliminate k_stack_init_with_buffer()
Folds this API into k_stack_init() to provide a single API
that requires the caller to pass in the stack buffer, just
as is done for other kernel objects initialization APIs
involving the use of a buffer.

Change-Id: Icad5fd6e5387d634738d1574f8dfbc5421cd642d
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-10-13 13:54:00 +00:00
Allan Stephens 399d0ad55a unified: Rationalize thread priority APIs
* Gets rid of k_current_priority_get(). Users can just call
  k_thread_priority_get(k_current_get()) instead.

* Declares k_thread_priority_get() in kernel.h, where it
  really belongs.

* Removes duplicate declaration of k_thread_priority_set().

Change-Id: I616ae6f2e06c95ecba3b92324186b3fa29162fd1
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-10-13 13:53:59 +00:00
Benjamin Walsh a6e85b248a unified: fix remaining issues for building without SYS_CLOCK_EXIST
Do not include timeout_q.h when !SYS_CLOCK_EXIST, this allows removing
_unpend_thread_timing_out() in that case.

Have _abort_thread_timeout() return 0 (success) when !SYS_CLOCK_EXIST.

With this change, the minimal footprint nanokernel project compiles for
the unified kernel.

Change-Id: Ifbf9167a82fb3ebcf6941bf3f85c105c23c9060c
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-10-10 21:27:44 +00:00
Benjamin Walsh ce9f782a7f unified: use _is_thread_pending() rather than poking in _timeout
That's what the interfaces are for.

Change-Id: Ida0b4d6561c7848a63bcb06537e0dbaafd8dbbfd
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-10-10 21:27:43 +00:00
Benjamin Walsh 48efb384f8 unified: do not compile out _k_neg_eagain when !CONFIG_ERRNO
It is always needed by the kernel, since the return codes are now
errnos. CONFIG_ERRNO is the mechanism for having a per-thread errno, not
using errno values.

Change-Id: I4ed14896a342f4122793d91b13c41b4a6a74716d
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-10-10 21:27:42 +00:00
Benjamin Walsh 1a5450bb8e unified: merge NANO_TIMERS and NANO_TIMEOUTS with SYS_CLOCK_EXISTS
Timers are based off timeouts now, which can only be enabled when the
system clock is enabled. So the three are really just one setting now.

Keep the NANO_TIMERS and NANO_TIMEOUTS around for now until all
middleware that rely on them is updated. They are always enabled when
SYS_CLOCK_EXISTS is enabled.

Change-Id: Iaef1302ef9ad8fc5640542ab6d7304d67aafcfdc
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-10-10 21:27:41 +00:00
Benjamin Walsh 8ae55deaf9 unified: remove unused references from nano_private.h
Leftover from the nanokernel.

Change-Id: I06f43f182ddbf40617b97aea424252e9c46a95e1
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-10-10 21:27:40 +00:00
Benjamin Walsh c742d7e6b3 unified: cleanup kernel initialization
- ensure dummy thread's stack is aligned
- rename nano_init() to prepare_multithreading
- move _Swap() to main thread into its own function

Change-Id: I6c8dbe2a4e034f3db90b55d1a5e30bc73bac3d50
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-10-10 21:27:39 +00:00
Benjamin Walsh b7ef0cba5f unified: remove last instances of struct tcs
Change-Id: I956bf0e96266e68ac1743f02a82ffafe77ebb0e8
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-10-10 21:27:38 +00:00
Benjamin Walsh 055262c159 unified: remaining timeout cleanup
Rename remaining functions to fit with kernel naming convention for
internal interfaces. Use struct k_thread instead of struct tcs.

Change-Id: I28cd7f6f4d7ddaeb825c8d2999242d8d2dd93f31
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-10-10 21:27:37 +00:00
Benjamin Walsh 601b354ffe unified: clean-up timeout code for unpending a thread
Integrate _timeout_remove_tcs_from_wait_q() into
_unpend_thread_timing_out().

Change-Id: Id57d9fd8f9e877e580460091172aaabf451f3d4b
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-10-10 21:27:37 +00:00
Benjamin Walsh 688973e5ab unified: streamline "timeout add" internal interfaces.
Rename _do_timeout_add to _add_timeout, rename _TIMEOUT_ADD to
_add_thread_timeout to better reflect their functionalities. Have the
latter call the former, remove _do_timeout_add and
_nano_timer_timeout_add.

Change-Id: Ica86bea10d99d72bf78379598a942d277e7002d0
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-10-10 21:27:36 +00:00
Benjamin Walsh 0bd7e0d148 unified/mem_pool: use K_NO_WAIT, not TICKS_NONE
TICKS_NONE is only for legacy API.

Change-Id: Iffd53fbd4115da51dac18b4d74786d164353dbfb
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-10-10 21:27:35 +00:00
Benjamin Walsh 7caef4581d unified: streamline "timeout abort" internal interface
Rename _do_timeout_abort to _abort_timeout, rename _timeout_abort to
_abort_thread_timeout to better reflect their functionalities. Have the
latter call the former, remove _do_timeout_abort and
_nano_timer_timeout_abort.

Change-Id: I0fea9474b19a2eb47a37489eb06c0d1d56886c9c
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-10-10 21:27:34 +00:00
Benjamin Walsh 179fd3a80c unified/legacy: disable clock-based work_q APIs when no system clock
Change-Id: I15e76499a8425539a631819960976801356d8fa6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-10-10 21:27:33 +00:00
Benjamin Walsh 35497d6c5e unified: cache the next thread to run
When adding a thread to the ready queue, it is often known at that time
if the thread added will be the next one to run or not. So, instead of
simply updating the ready queues and the bitmask, also cache what that
thread is, so that when the scheduler is invoked, it can simply fetch it
from there. This is only done if there is a thread in the cache, since
the way the cache is updated is by comparing the priorities of the
thread being added and the cached thread.

When a thread is removed from the ready queue, if it is currently the
cached thread, it is also removed from the cache. The cache is not
updated at this time, since this would be a preemptive fetching that
could be overriden before the newly cached thread would even be
scheduled in.

Finally, when a thread is scheduled in, it now becomes the cached thread
since the fact that it is running means that by definition it was the
next one to run.

Doing this can speed up considerably some context switch times,
especially when a thread is preempted by an interrupt and the same
thread is scheduled when the interrupt exits.

Change-Id: I6dc8391cfca566699bb9b217eafe6bc6a063c8bb
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-10-10 21:27:31 +00:00
Benjamin Walsh 7bc86c0344 unified: use sys_dlist_peek_head_not_empty()
When fetching the next thread to run, we know at least one thread is
available.

Change-Id: I568c33a61b6a0a6d6a7f79c337caecffd5ef70b6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-10-10 21:27:30 +00:00
Kumar Gala d12d8af186 unified: move code from nanokernel into unified kernel
As the unified kernel should replace the nanokernel and microkernel
lets go ahead and move code shared between the nanonkernel and unified
kernel into the unified kernel.

Change-Id: I8931efa5d67025381d5d0d9563e7c6632cece87f
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2016-10-10 00:46:40 +00:00
Anas Nashif 33118f9212 sensor: grove: use global sensor init priority
Change-Id: Ie56ee7e4b267b4dc67026be4531834f550134969
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-10-07 20:53:29 +00:00
Anas Nashif d3fe63702f kernel: boot banner requires early console, so select it
If you select the BOOT_BANNER on its own, nothing happens and
you are left to wonder what is going, it happens very early in
the boot process and requires very early console initialisation.

Change-Id: Id548491f7e3f7f399ddc572199ce39e6fc268ed4
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-10-07 14:07:25 +00:00
Ricardo Salveti 81e7749cd5 kernel: event logger needs ring buffer
Change-Id: Ia5bb7e0c7cf7f94b03aad9826d5798af7813d0b5
Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
2016-10-06 12:56:19 +00:00
Dmitriy Korovkin 19f2884738 unified: Fix build broblem caused by concurrent make processes in single dir
Make sure that kernel/unified, that is included in libs-y does not
built recursively through building kernel/ directory.
Make sure that any lib.a library is not included into libzephyr.a
and thus object modules from those lib.a files are linked only if a
function from that object module is referenced from the application.

Jira: ZEP-1025

Change-Id: Id3a3e96ca0b8abc9aedde0ffb9baa0164e380464
Signed-off-by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
2016-10-05 10:29:31 +00:00
Ramesh Thomas c4c0ed414b power_mgmt: Reduce complexity in handling of power hooks
Simplified some documentation, removing inconsistencies and making
it easier to understand by separating PM infrastructure areas and
soc specific components that implement the hooks.

Removed the DEVICE_SUSPEND_ONLY policy as it is redundant and
causes high complexity in the flow. It is also not practical
to use it because it was meant to be used without doing CPU or SOC
low power state operations. This means it would do device PM
operations in the ISR of the system timer used by the scheduler.
This can disrupt the scheduler time.

Added a check of a flag around the notification sent from the ISR
of the wake event and created APIs to set/clear it. This will
allow disabling the notification when not needed from
_sys_soc_suspend().

Jira: ZEP-972
Change-Id: Id7aa7d2683384eabed518d4efac446ecc84c3498
Signed-off-by: Ramesh Thomas <ramesh.thomas@intel.com>
2016-10-05 10:05:42 +00:00
Iván Briano 9c7b5eacea unified: Fix building of the unified kernel
Change-Id: I6824cdb9123a574a56af10efdebdc1c8b82427f8
Signed-off-by: Iván Briano <ivan.briano@intel.com>
2016-10-04 18:11:05 -03:00
Peter Mitsis 340d00ab51 unified: Simplify k_msgq_purge()
Simplifies k_msgq_purge() at the expense of making the case of an
already empty message queue a little slower.

Change-Id: I8fafd6d49233efbf23b95d171f81bf795e828454
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-04 20:04:46 +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
Peter Mitsis a04c0d70e1 unified: Rename k_thread_static_init structure
Renames the k_thread_static_init structure to better follow
Zephyr naming conventions.

Change-Id: I479add2aefa3421ebc0b879e0d04c0c7ffd7f107
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-04 19:57:58 +00:00
Luiz Augusto von Dentz ee1e99b3b7 unified: Add k_work_pending
This adds k_work_pending which can be use to check if a k_work is
pending execution.

Change-Id: Ifd56e8d65d555c7e9722c547fe83e13e886d63cd
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-10-04 17:30:42 +03:00
Luiz Augusto von Dentz cd4501c453 nano_work: Add nano_work_pending
This adds nano_work_pending which can be use to check if a nano_work
is pending execution.

Change-Id: Iae0492a750de93fcd7e89e3a2e74509ffce4983b
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-10-04 17:29:59 +03:00
Benjamin Walsh bbe361ccaf nano: remove duplicated typedef
Obtained from device.h, which includes microkernel.h when building for a
microkernel system.

Caught by LLVM.

Change-Id: I98a00269b2b6cb38c851b176323de1228d65603d
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-10-04 12:28:27 +00:00
Peter Mitsis 0cb65c3c0d unified: Eliminate k_mem_pool_t typedef
Replaces it with a pointer as there is no need for an opaque memory
pool type.

Jira: ZEP-916
Change-Id: I5493eed25c9c34e1b850dc3b20699864edb22d28
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-03 20:17:02 +00:00
Peter Mitsis 0ca7cea8f3 unified: Relocate internal thread group APIs
Moves the following internal thread group APIs from the public
kernel.h header file to the more private thread.c source file as
they do not need to be public APIs.
	_k_task_list_start[];
	_k_task_list_end[];
	_FOREACH_STATIC_THREAD()
	is_in_any_group()

Change-Id: I0b731fb0c20a5574cb1b3c1397803af82918d69d
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-03 20:17:02 +00:00
Daniel Thompson 9a81ffa7ad device: Make device_get_binding() const correct
Currently passing a constant string (other than a string
literal) to device_get_binding() generates a spurious warning.
The warning is spurious because device_get_binding() does not,
nor is it ever likely to, modify its argument. To fix the
warning we modify the prototype to make clear name will never
be modified.

Change-Id: I2df22de61eb2580b2086a685549900d7ed4a322d
Signed-off-by: Daniel Thompson <daniel.thompson@linaro.org>
2016-09-29 13:46:43 +00:00
Dmitriy Korovkin 9558d47fd3 unified: Build kernel objects as a static library
Building kernel objects as a static library allows not
to include the initialization function for an object
type if this type is not used by the application.
It reduces memory footprint

Change-Id: I2b3c79cb2591fdd1ce15d27684c4a874e759c559
Signed-off-by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
2016-09-28 19:13:36 +00:00
Dmitriy Korovkin 284042d746 unified: Invoke kernel object initialization with SYS_INIT macro
Kernel object initialization needs to follow the common initialization
scheme.

Change-Id: I6693678ed7c4975b3c588061013fa0c5d24968c3
Signed-off-by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
2016-09-28 19:13:35 +00:00
Dmitriy Korovkin 4223ba7964 unified: Add initialization priority level for kernel objects
The separate initialization priority provides more
flexibility when it's needed to arrange the initialization
sequence.

Change-Id: Ie1b7b48d282618f6d641320bf3b24f63716a7342
Signed-off-by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
2016-09-28 19:13:35 +00:00
Benjamin Walsh ba5ddc189e unified: implement k_uptime_{get,delta}()
Simple conversion from ticks for now.

Change-Id: Ib81fc738d45641a6a3a88d2adec1f3eb861f3f97
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-23 21:39:40 +00:00
Peter Mitsis 19547d09f7 unified: Eliminate useless check in idle thread
There is no reason to check if the idle thread is a cooperative thread
before invoking k_yield(); it is safe to unconditionally invoke it every
iteration.

Rationale: If the idle thread is cooperative, k_yield() must be invoked
to allow a new thread to get scheduled to run. If the idle thread is
preemptive, then k_yield() effectively becomes a no-op.

Change-Id: Ide3204c92381640b5d12b39ca0f258d56d8cc3d0
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-09-23 19:53:22 +00:00
Peter Mitsis ba26615a47 unified: Remove unused _nano_get_earliest_deadline()
The routine _nano_get_earliest_deadline() is still used by both
the microkernel and nanokernel.

Change-Id: I14501e6d41ca5faac27dead5873ef897e79831aa
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-09-23 19:53:22 +00:00
Peter Mitsis 7e9d7058cc unified: Remove #if 0 code block from wait_q.h
Change-Id: Ic916c161b7faa9260e85899682c43d97f24e5197
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-09-23 19:53:21 +00:00
Peter Mitsis e02c720e3d unified: Remove obsolete wait_q.h macros
Removes the following wait_q.h macros
  _NANO_OBJECT_WAIT()
  _TIMEOUT_UPDATE()
  _TIMEOUT_TICK_GET()

Change-Id: I7cb78728aaad74acf7f121c79f03d32fa6af5aac
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-09-23 19:53:21 +00:00
Peter Mitsis b27249486a unified: Remove references to obsolete task_timeout
Change-Id: I7c3b1b8418809914d3daf9d68ed8e4c3b99dd0b1
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-09-23 19:53:20 +00:00
Peter Mitsis 3259d0e3c4 unified: Replace _nano_get_earliest_deadline()
Replaces _nano_get_earlist_deadline() with the more streamlined
routine _timeout_get_next_expiry().

Change-Id: Iee7ec727f0500cb28e37a364036fd40a483b40c3
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-09-23 19:53:20 +00:00
Dmitriy Korovkin bf9972113f unified: Add legacy task_offload_to_fiber() routine
For unified kernel the routine is implemented through
a wait queue.

Change-Id: Iceab7b821e3b55e0773ad780f4b9b0a1dfc21f5d
Signed-off-by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
2016-09-23 18:51:06 +00:00
Peter Mitsis 653ff0b949 unified: Remove check in _reschedule_threads()
The routine _reschedule_threads() does not need to check that the
scheduler is locked as this is done as part of _must_switch_threads().

Change-Id: I701b811512836eef591b2adcd708991ec9324b3d
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-09-23 18:25:49 +00:00
Andy Ross 8d8b2acb26 k_timer: Don't allocate dynamic timers by default
Most apps run fine with static k_timer objects.  Don't pay the cost
for the timer pool if no one asks for it.

Also turn off the allocate/free API in the header if it can't possibly
work at runtime as it's an obviously-detectable error that would
otherwise be visible only at runtime.

Change-Id: I492e6e01c4213e3544f707247eea6e4bc601fefd
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2016-09-23 18:25:37 +00:00
Benjamin Walsh 0bee91dae1 unified: fix some leftover K_<obj>_DEFINE macros
The K_<obj>_DEFINE macros in the unified kernel create objects of name
'name', and not a pointer named 'name' to an object. Some macros
contained the code from early prototyping.

Change-Id: I7262570fbe0b267012874eac0185b4e0cd7f523d
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-22 21:09:22 +00:00
amirkapl d305da61e9 power_mgmt: Update Power Management device driver API
Have one function that can be used for all possible device
purposes using a control code instead of the suspend
resume functions, makes it generic for device control.
Added device power states.
The older replaced APIs will be deprecated in a future patch

Jira: ZEP-954
Change-Id: I6dd3ebfd0fde3546b2d8397f19842f5758fda0c4
Signed-off-by: Amir Kaplan <amir.kaplan@intel.com>
2016-09-22 00:23:43 +00:00
Dmitriy Korovkin 7f14618227 unified: Enable memory pools in mailbox tests
Change-Id: I216fbff4db7e97bfca3574f6bfc5294d73ae8e9c
Signed-off-by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
2016-09-20 22:04:46 +00:00
Dmitriy Korovkin 3c426888a1 unified: Implement memory pools
Due to the memory pool structure only static declaration of
memory pool is possible.

Change-Id: I4797ed88fd2ac3b7812ff26e552e1745611c4575
Signed-off-by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
2016-09-20 22:04:46 +00:00
Peter Mitsis 45403678aa unified: Add support for semaphore groups
Semaphore groups are enabled by default. Disabling them will both
decrease the footprint as well as improve the performance of the
k_sem_give() routine.

Change-Id: If6c1b0e2e1f71afd43e620f05f17068039d12b05
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-09-20 11:45:28 -04:00
Peter Mitsis 68d1f4b562 unified: Add timeslice support
Change-Id: I5b6c1ef5c015d1ddaea21b1c5447336b1b04db39
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-09-20 15:28:54 +00:00
Peter Mitsis bd69658571 unified: Add _is_next_thread_current()
The routine _is_next_thread_current() checks if the current thread
is still the highest priority thread that is ready to run.

It is useful for determining if a thread must be swapped out when
timeslicing is in effect.

Change-Id: Ide7b89742a64f6082ca4c679a4b2fbd60792e30f
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-09-20 15:28:54 +00:00
Peter Mitsis 685254f524 unified: Preemption check to include sched lock
Change-Id: I8dc635bc53036938b249220d655dceb1f6f413f0
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-09-20 15:28:53 +00:00
Benjamin Walsh 7e6dacd65f unified/build: allow building the unified kernel
Added needed kconfig options. KERNEL_V2 selects MICROKERNEL to allow
middleware and application that differentiate between NANOKERNEL and
MICROKERNEL to run unmodified.

Build the unified/ kernel directory: do not touch the
nanokernel/microkernel directories.

Invoke sysgen for both microkernel and unified kernel. Only have sysgen
reference include/microkernel if building an original microkernel.

Change-Id: If74779146143434f7ee274bbef32d6c894b9f1a1
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-13 17:12:55 -04:00
Benjamin Walsh 456c6daa9f unified: initial unified kernel implementation
Summary of what this includes:

    initialization:

    Copy from nano_init.c, with the following changes:

    - the main thread is the continuation of the init thread, but an idle
      thread is created as well

    - _main() initializes threads in groups and starts the EXE group

    - the ready queues are initialized

    - the main thread is marked as non-essential once the system init is
      done

    - a weak main() symbol is provided if the application does not provide a
      main() function

    scheduler:

    Not an exhaustive list, but basically provide primitives for:

    - adding/removing a thread to/from a wait queue
    - adding/removing a thread to/from the ready queue
    - marking thread as ready
    - locking/unlocking the scheduler
      - instead of locking interrupts
    - getting/setting thread priority
      - checking what state (coop/preempt) a thread is currenlty running in
    - rescheduling threads
    - finding what thread is the next to run
    - yielding/sleeping/aborting sleep
    - finding the current thread

    threads:

    - Add operationns on threads, such as creating and starting them.

    standardized handling of kernel object return codes:

    - Kernel objects now cause _Swap() to return the following values:
         0      => operation successful
        -EAGAIN => operation timed out
        -Exxxxx => operation failed for another reason

    - The thread's swap_data field can be used to return any additional
    information required to complete the operation, such as the actual
    result of a successful operation.

    timeouts:

    - same as nano timeouts, renamed to simply 'timeouts'
    - the kernel is still tick-based, but objects take timeout values in
      ms for forward compatibility with a tickless kernel.

    semaphores:

      - Port of the nanokernel semaphores, which have the same basic behaviour
      as the microkernel ones. Semaphore groups are not yet implemented.

      - These semaphores are enhanced in that they accept an initial count and a
      count limit. This allows configuring them as binary semaphores, and also
      provisioning them without having to "give" the semaphore multiple times
      before using them.

    mutexes:

    - Straight port of the microkernel mutexes. An init function is added to
    allow defining them at runtime.

    pipes:

    - straight port

    timers:

    - amalgamation of nano and micro timers, with all functionalities
      intact.

    events:

    - re-implementation, using semaphores and workqueues.

    mailboxes:

    - straight port

    message queues:

    - straight port of  microkernel FIFOs

    memory maps:

    - straight port

    workqueues:

    - Basically, have all APIs follow the k_ naming rule, and use the _timeout
    subsystem from the unified kernel directory, and not the _nano_timeout
    one.

    stacks:

    - Port of the nanokernel stacks. They can now have multiple threads
    pending on them and threads can wait with a timeout.

    LIFOs:

    - Straight port of the nanokernel LIFOs.

    FIFOs:

    - Straight port of the nanokernel FIFOs.

Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
         Peter Mitsis <peter.mitsis@windriver.com>
         Allan Stephens <allan.stephens@windriver.com>
         Benjamin Walsh <benjamin.walsh@windriver.com>

Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-13 17:12:55 -04:00
Benjamin Walsh 851c537f29 kernel: add CONFIG_MDEF
Easier to build logic for when an MDEF file is to be parsed since
unified kernel needs to do it as well. Can also be useful for testing,
when toggling between static and dynamic objects in the same test case.

Change-Id: I51eb8919e18443516ade13caab04698d37d91803
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-13 17:12:55 -04:00
Andrew Boie d6053db355 kernel: abolish FUNC_NO_FP
These impede debugging and we have CONFIG_OMIT_FRAME_POINTER
now which does this globally for the entire kernel.

Change-Id: I46939223e27dd298ca3ed162ff5790cb2e9ed2a2
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2016-09-09 21:13:30 +00:00
Andrew Boie 7d432bbd0a microkernel: remove deprecated task IRQs
Change-Id: I02264a587b77ae597133b9c52b342b8e5520a131
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2016-09-06 16:15:59 +00:00
Marcus Shawcroft 530e285770 kernel: Rename CONFIG_CUSTOM_RANDOM_GENERATOR to CONFIG_RANDOM_GENERATOR
Initialization code in nano_init.c gated by the config parameter
CONFIG_CUSTOM_RANDOM_GENERATOR is out of step with the rest of the
tree where support for this config parameter was removed by
commit 27bcb431cb ("Random number generator driver unification")

Change-Id: If6086fd85e61579c646d09029ef129e8a3b464b8
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2016-08-31 10:40:28 +00:00
David B. Kinder d748577706 doc: Fix terminology in Kconfig files for 'platform'
Completing the terminology change started with change 4008
by updating the Kconfig files processed to produce the
online documentation, plus header files processed by
doxygen.  References to 'platform' are change to 'board'

Change-Id: Id0ed3dc1439a0ea0a4bd19d4904889cf79bec33e
Jira: ZEP-534
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2016-08-18 21:17:29 +00:00
Andrew Boie 4760753ab0 Revert "microkernel: remove deprecated task IRQs"
This reverts commit d73a9bb9c6.
The patch was intended for 1.6.0 release.

Change-Id: Id42058b746a3d2a54e4b1a2983eb58bd10b1ed40
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2016-08-05 20:37:25 +00:00
Andrew Boie d73a9bb9c6 microkernel: remove deprecated task IRQs
Change-Id: I06393c8ee0e864105cd0183c92e453638679fe81
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2016-08-05 16:55:42 +00:00
Juro Bystricky 19d84d8e00 nano_init.c: STACK_CANARY_INIT fix for ARC
An updated version of ARC GCC reports this error:
nano_init.c:340: Error: inappropriate arguments for opcode 'mov'

The offending in-line assembly code tried to move register value into a
memory location.

Use store "st" instruction instead of "mov" istruction to store
a value in memory.

Change-Id: I91ebd20495612da4d5639a3ef848379705f6dedd
Signed-off-by: Juro Bystricky <juro.bystricky@intel.com>
2016-07-27 15:23:15 +00:00
Johan Hedberg a95b6eeafb nano_work: Fix never yielding from fiber
If the delayed work FIFO never goes empty (e.g. because the work
callback keeps resubmitting or there's a very active ISR feeding items
there) then the fiber would never yield, causing all sorts of problems
for the system. Adding an explicit fiber_yield() call at the end of
the while-loop solves the issue.

Change-Id: I233b9fc18fc9db9172daf8689bd22d09952089cb
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-07-27 14:44:13 +00:00
Allan Stephens 2275cae089 kernel: Remove unneeded ASSERT from memory pool subsystem
Eliminates assert check that complains about an attempt to allocate
a memory pool block larger than the largest possible block size.
In such cases the allocation code now just returns a NULL pointer
indicating that it was unable to allocate the requested block, just
as it does when a block smaller than the maximum size cannot be
allocated because none is currently available.

Note: One scenario in which it isn't unreasonable for an application
writer to request a block that is too big is the case where a receiving
task using a mailbox first receives an excessively large message without
its data and then tries to retrieve the data into a memory pool block
allocated by the mailbox. Rather than forcing the application writer
to check to see if the size of the received message is too big for the
memory pool, or adding code to the mailbox subsystem to do such a check,
it's easier to pass on the request to the memory pool and simply have it
return NULL, which causes the mailbox to report that data retrieval
failed. The application can then perform a single check that catches
both the case where the memory pool simply ran out of blocks and the case
where it didn't have any block big enough to handle the message.

Change-Id: Ifd2cdd8a5927b93d3e9c5df301544e522131d2c6
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-07-26 04:53:07 +00:00
Andrew Boie 917159188c nano_init: force nanokernel stack alignment
The interrupt stack pointer is now aligned, and we error out if
the sizes of the interrupt and main task stacks aren't a multiple
of the stack alignment.

Change-Id: I2a70c82fc94e25cc6c7a9d5ec165bf2370b8a166
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2016-07-20 21:26:00 +00:00
Andrew Boie 6a1474e75b nanokernel: support GCC compiler atomic builtins
Arches now select whether they want to use the GCC built-ins,
their own assembly implementation, or the generic C code.

At the moment, the SDK compilers only support builtins for ARM
and X86. ZEP-557 opened to investigate further.

Change-Id: I53e411b4967d87f737338379bd482bd653f19422
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2016-07-18 23:20:52 +00:00
tulasinagraj ce2574a30b nanokernel: remove duplicate symbols in image file
Jira ZEP-68,zephyr.elf shows duplicate routines which increases the foot print.
Current fix removes duplicate routines and reduces foot print of the image

Change-Id: I01a2e5a8a02481ab33a2bb09e9c545d6879c1b81
Signed-off-by: tulasinagraj <tulasi.r@tcs.com>
2016-07-18 18:47:03 +00:00
Allan Stephens 7bbf48bf5b kernel: Cosmetic cleanups to memory pool code
Improves a handful of comments, and removes some unneeded blank lines.

Change-Id: Ia2b951d23131b0080104c18c06324342de3359ef
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-07-08 23:04:40 +00:00
Allan Stephens ff48e07f70 kernel: Rename fields of private memory pool type
Revises two fields of the memory pool structure to better reflect
that block sets are involved.

Change-Id: I44a751e7457270391fbe99705010345448df2ff4
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-07-08 23:04:40 +00:00
Allan Stephens dc9556c4f7 kernel: Rename field of private memory pool type
Revises the memory pool block set field that points to its array
of quad-blocks to better reflect that quad-blocks are involved.

Change-Id: I159805ce8eee9091221cb1f494a4ab082e3736e5
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-07-08 23:04:39 +00:00
Allan Stephens c0fd08e82d kernel: Rename private memory pool types
Revises the names of 2 types to make them better reflect the
data structures they represent, namely:

- block set: a collection of memory pool blocks of a given size
- quad-block: four contiguous memory pool blocks of a given size

Change-Id: I3e424586e97157eea185fba6836e2e89d10d9cd6
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-07-08 23:04:39 +00:00
Allan Stephens 569d08a940 kernel: Eliminate unused memory pool structure field
Eliminates the memory pool field indicating the size of the
pool's memory buffer, since it isn't used anywhere.
(Anyway, it could be computed by multiplying the maximum
block size by the number of maximum-sized blocks.)

Change-Id: Ia11554bdc2b246a1ba0ea33f05c5e6ce6a32ca13
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-07-08 23:04:39 +00:00
Allan Stephens 28c427d6c0 kernel: Invert polarity of memory pool's quad-block memory status field
Alters the use of the field so that a 1 bit indicates that the
associated block is available (i.e. can be allocated from the pool),
and a 0 bit indicates the block is unavailable (i.e. it is already
allocated or does not exist).

The revised definition of this field is more intuitive, since it follows
the conventional "1 = thing is present, 0 = this is not present" model.

Change-Id: Id133d1940aca0dd1c3c1672f989d0c0bb083ebc5
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-07-08 23:04:38 +00:00
Allan Stephens 8b925dc5de kernel: Optimize memory pool initialization routine
No longer initializes the quad-block descriptors for block sets,
except for the one containing the largest size blocks. The descriptors
for the other block sets don't need initialization since sysgen already
ensures the block pointer field is NULL, and the block status field can
be anything (since it is ignored if the pointer is NULL).

Change-Id: I72cdf772329ef3e6d1babd9da11706d11611e61a
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-07-08 23:04:38 +00:00
Allan Stephens 6f3f29a0f3 kernel: Enhance memory pool defragmentation routine
Adds missing check to prevent defragmentation algorithm from
going past the end of a block set's array of quad-blocks.
Optimizes quad-block deletion algorithm so that it simply moves
the final array entry into the slot for the deleted entry,
rather than shifting all of the entries in between them.

Also enhances comments to make it easier to understand
what is going on.

Change-Id: Ic281c6f3c6dd5df9ec532a302b4103f3d929665b
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-07-08 23:04:38 +00:00
Allan Stephens a8b0301087 kernel: Standardize memory pool block set computation
Now use a standard routine for identifying which block set to use,
rather than duplicating the identification code in multiple places.

Change-Id: I2f6577879c23183f3f91e4418d1ea0b2f6eec184
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-07-08 20:31:35 +00:00
Allan Stephens 032041e644 kernel: Enhance memory pool block deallocation routine
Revises algorithm to call an existing routine to free an allocated
block, rather than duplicating the logic to do the freeing.

Also enhances comments to make it easier to understand what is
going on.

Change-Id: Ie7a83a8a2e978e8a685c27e07acb5b70aea37afa
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-07-08 20:31:35 +00:00
Allan Stephens 4b67b115d3 kernel: Enhance memory pool block deallocation routine
Revises algorithm for deallocating an existing block to make it
more compact (and efficient). Address calculation is simplified
and unnecessary error checking is removed (& replaced by asserts).

Also enhances routine name and comments to make it easier to
understand what is going on.

Change-Id: If1803ee09c8f4f73693c0cff9e433a7938f14398
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-07-08 20:31:35 +00:00
Allan Stephens f2abf7425a kernel: Enhance memory pool defragmentation routine
Enhances comments to make it easier to understand what is going on.
(Doesn't change actual defragmentation algorithm.)

Change-Id: I294f55b8f233d88c01ce30ba9ccff88000dc7936
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-07-08 20:31:34 +00:00
Allan Stephens 5a8c054544 kernel: Enhance memory pool block allocation routine
Enhances routine name and comments to make it easier to understand
what is going on. (Doesn't change actual allocation algorithm.)

Change-Id: I7d982ed8eeda3a2edd4602c5a10003aa8532457d
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-07-08 20:31:34 +00:00
Allan Stephens 18f4557513 kernel: Enhance memory pool block allocation routine
Revises algorithm for allocating an existing free block to make it
more compact (and efficient) by using the same logic to handle the
allocation of any block within a quad-block.

Also enhances routine name and comments to make it easier to
understand what is going on.

Change-Id: I55ca513e6f85df2b548502262e4dbe6bb272596b
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-07-08 20:31:33 +00:00
Allan Stephens ea5a523c43 kernel: Enhance memory pool block allocation routine
Converts check for a request for an impossibly large block
from a run-time check to an assertion. (The run-time check logic
was faulty anyway, since an excessive request would result
in a negative value for "offset", which would then get used
as an array index!)

Also enhances comments to make it easier to understand what is
going on.

Change-Id: I3faa86be177dcbc76912e23fabc2d24724fcba18
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-07-08 20:31:33 +00:00
Allan Stephens e6112a0cb8 kernel: Enhance memory pool initialization routine
Makes a couple of minor optimizations to initialization algorithm:

- Now initializes block status array for largest size blocks once,
  rather than twice.
- Doesn't initialize "count" field of block size descriptors to zero,
  since sysgen ensures that this happens automatically.

Also enhances comments for initialization routine to make it easier
to understand what is going on.

Change-Id: I00d907c0f2a86f5b6ea8a63475b40074fe89357c
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-07-08 20:31:33 +00:00
Allan Stephens 06dc3090d5 kernel: Eliminate unused memory pool structure field
Eliminates memory pool field associated with a capability that was
never implemented. (This field was initialized, but never subsequently
referenced.)

Change-Id: I58cf8c4bb846a66b4c8754654ffc3ff55abcff7f
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-07-08 20:31:32 +00:00
Andrew Boie 5b9378ab7e nanokernel: move dataCopy() and bssZero() to common code
Used by ARC, ARM, Nios II. x86 has alternate code done in assembly.

Linker scripts had some alarming comments about data/BSS overlap,
but the beginning of BSS is aligned so this can't happen even if
the end of data isn't.

The common code doesn't use fake pointer values for the number of
words in these sections, don't compute or export them.

Change-Id: I4291c2a6d0222d0a3e95c140deae7539ebab3cc3
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2016-07-08 18:23:11 +00:00
Andrew Boie ef29812d51 nios2: support more global pointer scenarios
We now allow use of -mgpopt=global and -mgpopt=data. The 'global'
option is now the default instead of compiler-default local, expanding
global pointer usage to all small data in the system.

For systems where all RAM is less than 64K, the 'data' option may be
appropriate.

Some fixes had to be made to the system in order to get around some
issues:

* prep_c.c no longer uses fake linker variables to figure out the size
of data or BSS, as these gave the linker fits as it tried to compute
relative addresses to them.

* _k_task_ptr_idle is create by sysgen and placed in a special section.
Any small data in a special section needs to be declared extern
with __attribute__((section)) else the compiler will assume it's in
.sdata.

* same situation with extern references to k_pipe_t (fixed pipe_priv
test)

For legacy applications being ported to Nios II which do things that
freak out global pointer calculation, it can be disabled entirely.

Change-Id: I5eb86ee8aefb8e2fac49c5cdd104ee19cea23f6f
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2016-07-06 18:14:31 +00:00
Juan Manuel Cruz 870ca36a0b tracing: _k_command_stack is explicitly not tracked.
Jira: ZEP-379
Change-Id: I94a1695fd4efb288dac9cfcaa4d3423e2970e108
Signed-off-by: Juan Manuel Cruz <juan.m.cruz.alcaraz@intel.com>
2016-06-16 16:30:46 +00:00
Benjamin Walsh d8994f69be nanokernel: add nano_fifo_put_list() APIs
Introduce the family of nano_fifo_put_list and nano_fifo_put_slist APIs,
which allow queuing a list of elements on a nanokernel fifo in one
shot. When called from an ISR or a fiber, the behaviour is not really
different than calling nano_fifo_put for each element to enqueue.
However, when called from a task, it allows the task to enqueue the full
list without yielding to fibers that were waiting on the fifo.

All fibers currently waiting on the fifo will be awakened and given an
element from the list in their order of priority. When some elements are
not matched with a receiver, they are queued normally.

There are two ways of passing a list: with either an ad-hoc queue, by
passing the head and the tail elements, or with a sys_slist_t object.
For the latter, the object must be reinitialized afterwards.

Change-Id: I6ac077f556dc39995191e9149c4a047a3433826f
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-06-13 20:24:41 +00:00
Luiz Augusto von Dentz 967f8fb602 nanokernel: Add callback to _nano_timeout once again
It is now safe to introduce the callback since nano_timer_init now
calls _nano_timeout_init which does takes care of initializing all
the fields properly.

Change-Id: I5735eeebef233a0a541ec8b2a354b65da98082fc
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-06-01 00:35:05 +00:00
Luiz Augusto von Dentz 4afb4e4150 nano_timer: Make nano_timer_init call _nano_timeout_init
With the introduction of _nano_timeout_init it prefered to call it
to initialize the _nano_timeout fields properly.

Change-Id: I83e9c63f9bb2903c508264d1199d2c687c330ec8
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-06-01 00:34:55 +00:00
Luiz Augusto von Dentz d6f039ed79 nanokernel: extract _nano_timeout_init from _nano_timeout_tcs_init
This will allow initializing a nano timeout that is not associated with
a thread.

Change-Id: Ic71175b0059396b19a0e3616f4fab570071c3d48
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-05-31 22:53:17 +00:00
Luiz Augusto von Dentz b559c1bca2 nano_work: Add delayed version
This adds a delayed version of nano_work API which is useful when
handling timeouts since the same stack/workqueue can be shared.

Change-Id: Iac43796fe96deb0a9c8976c91a65104b57779b00
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-05-31 22:52:51 +00:00
Kumar Gala 9ec2f3be80 Cleanup whitespace in Kconfig files
Convert leading whitespace into tabs in Kconfig files.  Also replaced
double spaces between config and <prompt>.

Change-Id: I341c718ecf4143529b477c239bbde88e18f37062
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2016-05-25 13:28:07 -05:00
Fabrice Olivero 128dcbbe13 kernel event logger: add possibility to use custom timestamp
By default, kernel event logger is using the system timer. But on
some platforms where the timer driver maintains the system timer
cycle accumulator in software, such as ones using the LOAPIC timer,
the system timer behavior leads to timestamp errors. For example,
the timer interrupt is logged with a wrong timestamp since the HW
timer value has been reset (periodic mode) but accumulated value not
updated yet (done later in the ISR).

This patch is adding the possibility to register a timer callback
function that will be used by the kernel event logger. For example,
on Quark SE, this allows using RTC or AON counter which accuracy is
sufficient and behavior more straight forward compared to system
timer.

Change-Id: I754c7557350ef29fc10701e62a35a5425e035f11
Signed-off-by: Fabrice Olivero <fabrice.olivero@intel.com>
2016-05-23 21:27:49 +00:00
Anas Nashif 65febf9417 Revert "nanokernel: Add callback to _nano_timeout"
This reverts commit f4465c651c.

Breaks samples/sensor/bmi160/ in Arduino 101:

ipm_console0: 'IMU: Binding...'
ipm_console0: 'Testing the polling mode.'
ipm_console0: 'Gyro (rad/s): X=-0.006517, Y=0.007581, Z=0.011172'
ipm_console0: 'Acc (m/s^2): X=-2.221632, Y=-4.826304, Z=74.965716'
ipm_console0: 'Temperature (Celsius): 31.661555'
ipm_console0: 'Exception vector: 0x00000003, cause code: 0x00000006, parameter 0x00000000'
ipm_console0: 'Address 0x0074006e'
ipm_console0: 'Fatal fault in ISR ! Spinning...'

Change-Id: I3c38ba4795c9996e42816c0581e249c1b5f70bc2
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-05-21 18:28:57 -04:00
Luiz Augusto von Dentz f4465c651c nanokernel: Add callback to _nano_timeout
This adds a callback to struct _nano_timeout which is called in ISR
context allowing more flexible handling of timeouts.

Change-Id: If837b0b51b24dfffebac6f99f4d66fdf01c164f0
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-05-21 12:02:57 +00:00
Benjamin Walsh 9977951f93 kernel: catch overflowing kserver stack with asserts
Overflowing the k_server command stack will now trigger an __ASSERT()
when CONFIG_ASSERT=y.

Change-Id: Icf6f4242ab8a9897918769415a0f7485602d7630
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-05-18 22:06:39 +00:00
Vlad Dogaru 818a2e2975 nanokernel: Introduce workqueue API
Add a generic API for drivers to start workqueues and submit work
items.  This is needed by drivers which need to schedule code that might
sleep from an ISR to run in fiber context.

Also add the option to start a system-wide workqueue.

Both additions are optional.  They can be deactivated for systems that
do not need them.

Change-Id: Ia843568fde5daf6d4279ef7bf241c26c1e3dcfb7
Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
2016-05-12 15:26:39 +00:00
Anas Nashif 7e5692d914 device: add documentation for device_get_binding
Moved comments from code to header.

Jira: ZEP-160
Change-Id: Ifd0f3c930289256e682b5941d77433aca3d3f941
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-05-12 10:57:27 +00:00
Fabrice Olivero f39b9b85a1 kernel event profiler: add dynamic enable/disable/configure
Added CONFIG_KERNEL_EVENT_PROFILER_DYNAMIC flag for enabling that
capability. When set, nothing will be logged by default

Change-Id: I03552483e5a6bfd9e2505eda56908f0d0ae98618
Signed-off-by: Fabrice Olivero <fabrice.olivero@intel.com>
2016-05-12 02:19:19 +00:00
Fabrice Olivero 68e7fca45c Set kernel event logger timestamps to HW cycles
OS tick period (usually 10 ms) is not sufficiently precise for task
execution analysis (like processing CPU load per context)

With that modification, the timestamp used by the kernel event logger
is 32-bit LSB of platform HW timer (for example Lakemont APIC timer
for Quark SE).
This timer period is very small and leads to timestamp wraparound
happening quite often (e.g. every 134s for Quark SE).

This wraparound must be considered when analyzing kernel event logger
data and care must be taken when tickless idle is enabled and sleep
duration can exceed maximum HW timer value.

Change-Id: Idc545da8f828a7357a69d83ff25c9afd09dab3c4
Signed-off-by: Fabrice Olivero <fabrice.olivero@intel.com>
2016-05-12 01:51:09 +00:00
Benjamin Walsh 1b5b6e44f7 kernel: add _IS_IDLE_TASK()
Add a way of finding if a microkernel task is the idle task instead of
of duplicating:

  task_priority_get() == (CONFIG_NUM_TASK_PRIORITIES - 1)

which could be subject to change.

Only available for microkernel, since there is no such concept in the
nanokernel.

Change-Id: Ie8930981f1a2ac5ff16f905f4eb4e333c8b59c5d
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-05-11 20:22:24 +00:00
Chuck Jordan 48e1749721 kernel: _MOVE_INSTR needs to be defined for CONFIG_ARC
In order to build test/kernel/test_stackprot/microkernel for the ARC,
the _MOVE_INSTR needs to define what the move instruction is for this
target.

Change-Id: I087cc5baa4c41297ce52323556e94aab424aa891
Signed-off-by: Chuck Jordan <cjordan@synopsys.com>
2016-05-05 00:06:03 -07:00
Peter Mitsis 46e6c6f8cb microkernel: lock interrupts in _k_state_bit_[re]set()
Locks interrupts in the microkernel routines _k_state_bit_reset() and
_k_state_bit_set(). This is a necessary pre-requisite for allowing
microkernel objects to pend on nanokernel objects since that feature
will require the manipulation of the microkernel queues in the context
of an ISR as well as the kernel server fiber.

Change-Id: I2d263707e0d3aed75bba971df878daa3d7ae1d11
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-05-04 22:51:35 +00:00
Peter Mitsis 59c21a5f62 microkernel: Fibers and ISRs may invoke microkernel no-op
Adds support that allows fibers and ISRs to invoke the microkernel
no-op kernel service request. This is useful for cases when the
nanokernel needs to invoke the microkernel task scheduler.

Change-Id: I1f4b2a39ac6b5e44bb1b6c6b3cd6034262bbada8
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-05-04 22:51:35 +00:00
Peter Mitsis e53c1851e9 nanokernel: Fix nanokernel object timeout recalculation
Fixes the timeout recalculation in the following routines:
	nano_task_fifo_get()
	nano_task_lifo_get()
	nano_task_sem_take()
	_nano_task_sleep()
Without this fix, a task that called one of the previously listed
routines could in theory sleep/wait up to almost twice the requested
timeout.

Change-Id: I53196be84e65874e94a62d5b0be1b7aaaaeda91f
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-05-04 22:51:35 +00:00
Peter Mitsis 1cbc9089ee nanokernel: [un]block tasks on nanokernel objects infrastructure
Adds the nanokernel infrastructure to permit microkernel tasks
to block/unblock on nanokernel objects. Multiple tasks may wait
on a nanokernel object's dedicated task wait queue.

It is important to note that when data is posted to the object
all the tasks on that object's dedicated task wait queue may be
woken up but the data is not immediately given to any of the tasks.
This is done to maintain consistent behavior with the nanokernel
as in a nanokernel system, fibers are given preference in both
waiting on and getting data from a nanokernel object.

Change-Id: Ia5c7f21ae59a367d9fec23dafc3a918d9e767db5
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-05-04 22:51:33 +00:00
Peter Mitsis 4ce3c0004b microkernel: [un]block tasks on nanokernel objects infrastructure
Adds the microkernel infrastructure to permit a microkernel task
to [un]block on a nanokernel object. Unlike tasks that [un]block
on microkernel objects, the work for [un]blocking tasks on nanokernel
objects will not always be done in the kernel service fiber. One of
the repercussions of this is that in many cases the microkernel task
scheduler must be explicitly invoked (by issuing a no-op kernel
service call).

Origin: Original
Change-Id: I2b145668cef142a7a4034e191116fcb344a9b8b3
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-05-04 22:51:33 +00:00
Peter Mitsis b58878bb89 kernel: Init back pointer to microkernel task
Fibers initialize this back pointer to NULL as they are (by definition)
not microkernel tasks.  Microkernel tasks initialize it to their
corresponding 'ktask_t'.

However for nanokernel systems, the back pointer is always NULL. This
is because there is only one task in a nanokernel system (the background
task) and it can not pend on a nanokernel object--it must poll.

Change-Id: I9840fecc44224bef63d09d587d703720cf33ad57
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-05-04 22:51:33 +00:00
Peter Mitsis f0948a4cbc microkernel: Add TF_NANO wait flag reason
Adds the TF_NANO wait flag reason to indicate that a task is pending
on a nanokernel object.

Change-Id: Ic20ef79398da7d9118bdf775e22b8f8a31501f7f
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-05-04 22:51:32 +00:00
Andrew Boie 68b3b6135e errno: implement _get_errno() in common code
We really should have more faith in the compiler, it generates
code to implement this exactly like the arch-specific assembly
versions, and on ARM is actually 4 bytes shorter.

FUNC_NO_FP used to disable the usual C preamble to update the
frame/stack pointers, which is how the sizes are still the same
or less. It's debatable how useful the occasional use of
FUNC_NO_FP is in practice since it hinders debugging and in a
production build frame pointers should be globally disabled, but
we can address that later.

Change-Id: I6c4b64ab3e3a9b6f91d52fa8c92e6e79a986fc77
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2016-05-04 17:04:14 +00:00
Geoff Thorpe ded3070c1c nanokernel: tighten _is_thread_essential()
Of the 3 related functions;
  _thread_essential_set()
  _thread_essential_clear()
  _is_thread_essential()

The first two are parameter-less and always operate on
"_nanokernel.current". The last one takes a 'thread' parameter but will
operate on _nanokernel.current if the parameter is NULL. All calls to
_is_thread_essential() pass NULL!

This change makes the 3 functions consistent by removing the parameter
to the 3rd function. This should also be marginally more efficient,
though consistency was the motivation. This change corrects the doc
preamble to all 3 functions.

(These functions would probably be better as inlines. Also, the choice
of when to use wrappers seems a bit arbitrary. E.g. there's nothing
for setting/testing the "FIBER" flag.)

Change-Id: Ie3589f8a28b227c6d7a3a31b664d3b3e6e9c6d17
Signed-off-by: Geoff Thorpe <geoff.thorpe@nxp.com>
2016-05-03 17:42:54 +00:00
Geoff Thorpe 8b16cac073 microkernel: use _thread_essential_set()
This wrapper exists so that the ESSENTIAL bit doesn't have to be set
explicitly in _nanokernel.current. (And a note is added to nano_init to
avoid a nasty gotcha there.)

Change-Id: I4026ac0cfeace60e36abdbccf15554759f2dbf7a
Signed-off-by: Geoff Thorpe <geoff.thorpe@nxp.com>
2016-05-03 17:42:54 +00:00
Andrew Boie 7327c9ee1f nanokernel: move C atomic operations to centralized code
These C variants of atomic operations can work on any arch,
have platforms select them if they don't have ASM equivalents.

Change-Id: I38eb03bb58beff865681ee56ef7bc0fcded1e906
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2016-04-27 21:40:19 +00:00
Andre Guedes 36c8e09a3a device: Include errno.h
The file device.c uses errno codes so it should include errno.h.

Change-Id: I93e806a9b20b2c9bcb245ac5e86fba70486c9591
Signed-off-by: Andre Guedes <andre.guedes@intel.com>
2016-04-26 22:49:49 +00:00
Daeseok Youn fa442b0287 microkernel: Match alignment with open parenthesis
fix alignment coding style issue

Change-Id: I29fefd994ffe772a6a52995b83ad5b0bf9a0dd2c
Signed-off-by: Daeseok Youn <daeseok.youn@gmail.com>
2016-04-26 11:10:37 +00:00
Jithu Joseph 592882e5f4 power_mgmt: APIs for devices to signal busy
Certain Low power SOC states (e.g. deep sleep)  will result in device
IP blocks losing state. In such a scenario it can be useful to have
a mechanism for devices (driver code) to signal the power manager /
policy that they are in the middle of a transaction.

We expect the device driver code to make a call to
device_busy_set(device *) before initiating a transaction and
device_busy_clear(device *) on completion. It is expected that device
driver developers will add this as necessary in their drivers.

Further an API is provided  for power manager application / policy to
check this. Based on this the power manager / policy can  decide
whether or not to go into a particular power state.

Change-Id: I0fedd90b98e182cd41b53c7f9e08655532822faa
Signed-off-by: Jithu Joseph <jithu.joseph@intel.com>
2016-04-23 02:14:21 +00:00
Daniel Leung dd5e90ec6c device_get_binding() returns NULL if driver_api is not set
This changes the behavior of device_get_binding() so that
it returns NULL if driver_api is not set. This provides
a way for driver to state that it has not been initialized
properly, and prevents app from using it since no reference
to the device struct will be returned.

This implements the idea specified in [1]. The idea is to
reuse an existing resource by piggy-backing onto driver_api,
thus avoiding an extra "device state" variable in the device
struct. This differs from the code specified in the mailing
list by checking driver_api for NULL first. This avoids
the unnecessary strcmp() if driver_api is NULL.

[1] https://lists.zephyrproject.org/archives/list/devel@lists.zephyrproject.org/message/MZB5PYBSRHV3NIEHJYXYQVLTPFIIHPB3/

Change-Id: I978b1a6683cd56c8a72532d6368c47e67515c82d
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2016-04-12 19:30:35 +08:00
Peter Mitsis 5aaf7ab930 nano_fifo: Fix problem with nano_fifo and timeouts
Fixes a problem where the nanokernel FIFO state information could get
out of sync due to a timeout.

The nanokernel FIFO structure nano_fifo now maintains two separate
queues: one for waiting fibers and the other for posted data. This
permits the safe and independent querying of the queues as needed
when getting and/or putting data from/on the nanokernel FIFO.

Change-Id: Ifbcb5004558b06fc55cad2a955f5be20e716b392
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-04-12 01:22:42 +00:00
Dmitriy Korovkin 4fc7d0242c kernel: Make idle task sleep
Device drivers may use task_sleep() routine during the initialization.
As device driver initialization is carried by idle task, it can not
be sheduled out as any other task. Idle task goes into a wait loop
instead.

In order to invoke task_sleep() device drivers must enable
CONFIG_NANO_TIMEOUTS option.

Change-Id: Ib73a2ad1f3c0bda44c24f2417e102bfaa3a13a15
Signed-off-by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
2016-04-08 15:08:33 +00:00
Daniel Leung 546b8ade37 refactor common driver initialization priorities
Most of the SoC and board Kconfig use the same values for
driver initialization priorities. So refactor them, and
discard duplicate ones.

The shared IRQ init priority was changed so that the kernel
default init and device init priorities can be standardized
across all SoC/boards. Same goes for DesignWare SPI driver.

This also changes the UART_CONSOLE_PRIORITY and
IPM_CONSOLE_PRIORITY to UART_CONSOLE_INIT_PRIORITY and
IPM_CONSOLE_INIT_PRIORITY, to standardize across all drivers.

Note that this does not take away the ability to override
those values. This just provides reasonable defaults such
that there is virtually no need to override.

Change-Id: Ibbd95d802c637df06f9a2fd48763ee1e6f4ff627
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2016-03-28 15:58:29 -07:00
Daniel Leung 8df10d4584 kconfig: untangle ordering and dependencies
There are two major issues with the kconfig:

() Some of the config options have incorrect dependencies inside help
   under menuconfig. For example, CONFIG_GPIO depends on BOARD_GALILEO.

() Since the SoC and board specific kconfig files are parsed first,
   the help screen would say, for example, CONFIG_SPI is defined at
   arch/arm/soc/fsl_frdm_k64f/Kconfig. This is incorrect because
   the actual config is defined in drivers/spi/Kconfig.

These cause great confusion to users of menuconfig/xconfig.

To fix these, the SoC and board defaults are now to be parsed last.

Note that the position swapping of defaults in this patch is due to
the fact the the default parsed last will be used.

And, spi_test is broken due to the fact that it requires
CONFIG_SPI_INTEL_PORT_1, but never enables it anywhere. This is
bypassed for now.

Origin: refactored and edited from existing files
Change-Id: I2a4b1ae5be4d27e68c960aa47d91ef350f2d500f
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2016-03-26 20:36:32 -04:00
Ramesh Thomas 4104bbfb08 power_mgmt: Add device power management support
Added device power management hook infrastructure. Added
DEVICE_INIT_PM and SYS_INIT_PM macros that creates device
structures with the supplied device_ops structure containing
the hooks.

Added example support in gpio_dw driver.  Updated the sample
app and tested using LPS and Device Suspend Only policies.

Change-Id: I2fe347f8d8fd1041d8318e02738990deb8c5d68e
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
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
Dmitriy Korovkin 9b2452047d kernel: Combine nano_timers and nano_timeouts
To avoid code duplication nano_timers use nano_timeout
mechanism.

Change-Id: I916bffd2b86e29ee7b7ff7bbb009cd4c844e2a44
Signed-off-by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
2016-03-26 09:20:10 +00:00
Anas Nashif 6b8c6403ec kconfig: move kernel options close together
have micro and nano kernel next to eachother.

JIRA: ZEP-107
Change-Id: I8d6e4354cf6a8cdf1193c641b112a078cd7ec460
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-03-17 13:00:20 +00:00
Juan Manuel Cruz 57cd459e71 debug: fixes issue on debug tracing for pool struct
Change-Id: I6af44e2388db76b4f6d38f634ae983a0d458871d
Signed-off-by: Juan Manuel Cruz <juan.m.cruz.alcaraz@intel.com>
2016-03-14 22:17:10 +00:00
Anas Nashif 207d0e799e kconfig: remove redundant EVENT_LOGGER option
KERNEL_EVENT_LOGGER selects EVENT_LOGGER which is then used to
enabling building. Skip EVENT_LOGGER and use KERNEL_EVENT_LOGGER
directly.

Change-Id: Ib9cf3a58b12bf4e78f264d8e8ac48a8104120c3b
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-03-14 16:50:51 -04:00
Anas Nashif a033c14dd1 kconfig: add power management options into a menu
Change-Id: I8e847c7f3305b63647f01a83a002a7962056732a
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-03-14 16:50:50 -04:00
Anas Nashif a13b04e022 kernel: fix boot banner option
Add missing option for adding time stamp to boot banner.

Change-Id: Idda61feeef4a89c1aa8bb7e81b52272babeb1efe
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-03-14 16:50:50 -04:00
Juan Manuel Cruz 568df1b17d debug: add debug tracing support for task initialization
Change-Id: I3d6ec2364f97b415bc27c0ce36df289e8eae9397
Signed-off-by: Juan Manuel Cruz <juan.m.cruz.alcaraz@intel.com>
2016-03-11 22:13:30 +00:00
Juan Manuel Cruz 787b41c8a3 debug: adds object tracing capability to microkernel timers
Microkernel timers are defined at compile time as a static list
but they are allocated dynamically in kernel execution.

The object tracing list will only list those timers that are
currently allocated at debug time. For this reason, timers
can be removed from the tracing list at any time.

A very simple double linked list was implemented to reduce the
complexity of the action to remove an item from the list from O(n)
to O(1) and simplify the remove implementation.

Change-Id: Ib7ea718b52e7c719a32b3fa4ff1d7e6b00482c28
Signed-off-by: Juan Manuel Cruz <juan.m.cruz.alcaraz@intel.com>
2016-03-11 22:13:15 +00:00
Juan Manuel Cruz f240bf18f7 debug: adds object tracing capability to nano stack
Change-Id: I0a13741a0b250fa587293936110291a4e6eec809
Signed-off-by: Juan Manuel Cruz <juan.m.cruz.alcaraz@intel.com>
2016-03-11 22:12:26 +00:00
Juan Manuel Cruz d151776e59 debug: thread monitor allow to access more thread information
The thread monitor allows to iterate over the thread context
structures for each existing thread (fiber/task) in the system.

Thread context structures do not expose thread entry information
directly. Although all the information can be scavenged from memory
stacks. Besides, accessing the information depends on the stack
implementation for each architecture.

By extending the tcs we allow a direct access to the thread
entry point and its parameters, only when thread monitor is
enabled.

It also allows a task to access its kernel task structure
through the first parameter of the thread.

This allows a debugger application to access the information directly
from the thread context structures list.

Change-Id: I0a435942b80eddffdf405016ac4056eb7aa1239c
Signed-off-by: Juan Manuel Cruz <juan.m.cruz.alcaraz@intel.com>
2016-03-11 22:11:39 +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
Juan Manuel Cruz c15259aca1 debug: expose thread monitor in object tracing header
Exposes the CONFIG_THREAD_MONITOR functionality as part of the
object tracing header.

Change-Id: I2022a580df2cf33e543b980dc9c33b9adca3d3bf
Signed-off-by: Juan Manuel Cruz <juan.m.cruz.alcaraz@intel.com>
2016-03-11 22:07:16 +00:00
Juan Manuel Cruz caa17577ef debug: kernel's object tracing api
Restructure the kernel's object tracing implementation
to provide a public API that allows debug tools to use
the debug hooks easier and allows kernel developers
to extend the kernel's object tracing scope and include
new kernel objects easier.

The API provides the trace list abstraction to keep track
of different types of kernel objects. The API contains
a simple single-linked list implementation that allows
to save space and simplifies the access to the data for
debug tools such as gdb.

Change-Id: Ic4d393d584576f67f2c5b706e61bae08869debba
Signed-off-by: Juan Manuel Cruz <juan.m.cruz.alcaraz@intel.com>
2016-03-11 12:00:07 +00:00
Jithu Joseph 6182fca156 memory_pool: Refactor code into a helper function
Moves some code from pool_alloc into a helper function,
to avoid code duplication when implementing a pool based heap.

Change-Id: I29b9bc1b8ba166a2187df5ea037aad4d4a522f69
Signed-off-by: Jithu Joseph <jithu.joseph@intel.com>
2016-03-10 23:19:59 +00:00
Jithu Joseph 9e45411a59 memory_pool_heap: malloc/free access over a heap memory pool
Specifying  HEAP_SIZE keyword in an app's MDEF file, results in
creating a new memory pool, which can be accessed using the
task_malloc() and task_free() APIs, which have the usual malloc/free
like semantics.

Expected format in MDEF file
HEAP_SIZE    <value>

Change-Id: I0569cffeecf8a2c23c20c7b359256123ece91982
Signed-off-by: Jithu Joseph <jithu.joseph@intel.com>
2016-03-10 23:19:59 +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
Yannis Damigos baddeadda1 arch: & kernel: Updated Kconfigs to remove errors in html generation
This patch updates some help sections to remove the "ERROR:
Unexpected indentation" messages during hmtl documentation
generation.

Change-Id: Idcdc17727b921b6145f9eb28d85975ceca273ce2
Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2016-03-04 13:26:15 +00:00
Anas Nashif 29d0d234e1 device: add missing license header
Change-Id: Ice01a19373ad17a9f8080f93c066d8be31a3b115
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-03-02 12:56:17 +00:00
Benjamin Walsh fcfb4b6bda kernel: add fiber_wakeup()
Like for the other context-specific APIs, also provide a
context-agnostic wrapper.

Change-Id: Icf0a62f4c06aec42f0febc298edbd8bdeec63749
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-02-25 11:06:09 -05:00
Benjamin Walsh 7a613adc14 kernel: fix xxx_fiber_wakeup() if the timeout has expired
A call to xxx_fiber_wakeup() if the timeout had expired would put the
fiber on the fiber ready queue _again_, corrupting it, or could remove
the fiber from a nanokernel object wait queue, prematurely un-pending
it.

We now verify the fiber is indeed still on the timeout queue and also
not on a wait queue, meaning the fiber is indeed sleeping.

Change-Id: Iba454d79ab50db01632b0591fb7b589221b5110b
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-02-25 11:06:09 -05:00
Benjamin Walsh 2aee77f8cf kernel: record when a fiber is removed from a wait queue
Until now, this was not needed since the checks for being on a wait
queue were only performed if a fiber was known to be on a timeout queue
as well. However, an upcoming fix for _fiber_wakeup() needs to verify if
a fiber is on a wait queue even if it is not timing out, because said
fix needs to check if the fiber is timing out as well.

Change-Id: If1694ceb551f2029d6a145963e81d3826956fd1d
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-02-25 11:06:09 -05:00
Benjamin Walsh b1903d7e48 kernel: have _nano_timeout_abort() return an error code
An upcoming fix for _fiber_wakeup() will need to know if the fiber was
dequeued from a timeout queue.

Change-Id: I09ca039098c09a997db73f4719261352f0af07c1
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-02-25 11:06:09 -05:00
Peter Mitsis b4313cef6f nanokernel: Add routines for waking a fiber
Adds the following routines for waking a fiber that was previously
put to sleep using fiber_sleep().
    isr_fiber_wakeup()
    fiber_fiber_wakeup()
    task_fiber_wakeup()

Change-Id: I7d78ee6997163d71b92f388a7b4c484f2e97862b
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-23 10:48:54 -05:00
Peter Mitsis cee79a7ca9 nanokernel: Change fiber_start() return type
The fiber_start() family of routines now return a nanokernel
thread id (nano_thread_id_t).  This is a pre-requisite step for
allowing fiber_sleep() operations to be cancelled.

Change-Id: I74a3885eda3252c158f4a48e90244569633469c3
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-23 10:48:54 -05:00
Peter Mitsis 06e2b4e129 nanokernel: Change fiber_delayed_start() return type
Instead of returning a 'void *', the nanokernel fiber_delayed_start()
family of routines now return a handle of type nano_thread_id_t.

Consequently, the nanokernel fiber_delayed_start_cancel() family of
routines now accept a parameter of type nano_thread_id_t instead of
'void *'.

The complete list of affected nanokernel routines is:
    fiber_delayed_start()        fiber_delayed_start_cancel()
    fiber_fiber_delayed_start()  fiber_fiber_delayed_start_cancel()
    task_fiber_delayed_start()   task_fiber_delayed_start_cancel()

Change-Id: Ibd4658df3ef07e79a81b7643a8be9ea5ffe08ba0
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-23 10:48:54 -05:00
Ramesh Thomas 3888735e0d adv_power:Advanced Power Management APIs
This is part of an ongoing development of power management
support in zephyr. This implementation builds upon an existing
hook interface and adds more enhancements. This was tested
with reference implementations on quark_d2000 and quark_se.

Change-Id: I28092b7ec90ce1f1cc661cf99ca88708910c8eb2
Signed-off-by: Ramesh Thomas <ramesh.thomas@intel.com>
2016-02-12 11:20:32 -08:00
Ramesh Thomas 72e248b11b adv_power:Rename PM functions according to coding convention
Renamed functions and labels used in power management code
according to coding convention.  Only doing this to relevant
functions and not touching functions that will be removed in
future patches.

The stack used during resume would be necessary so
renamed that too.

Change-Id: I2f09a349b0f0fd6520c11b4cd73f4c8e1a13f100
Signed-off-by: Ramesh Thomas <ramesh.thomas@intel.com>
2016-02-12 10:57:51 -08:00
Benjamin Walsh 038790a945 sys_clock/microkernel: do not announce ticks until microkernel is up
This is a prologue to reverting:

	commit 3c66686
	Author: Benjamin Walsh <benjamin.walsh@windriver.com>
	Date:   Tue Feb 9 17:34:02 2016 -0500

		sys_clock: start the microkernel ticker in the MICROKERNEL init level

to allow the devices initializing in pre-MICROKERNEL init levels to poll
the hi-res clock (sys_cycle_get_32()), which relies on the system clock
having been started.

This change allows starting the system clock in the NANOKERNEL init
level by delaying announcing the ticks until the MICROKERNEL init level.

Change-Id: I43d54bb5e2f182d4edd880da0124a0817f911943
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-02-11 17:10:49 -05:00
Anas Nashif 1e825f9c0f remove redundant checking for CONFIG_STACK_CANARIES
The file is already guarded with

obj-$(CONFIG_STACK_CANARIES) += compiler_stack_protect.o

So no need to check for CONFIG_STACK_CANARIES again in the file itself.

Change-Id: I09cf274679a1678f02478fca799a3f6507e77211
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-02-11 18:48:45 +00:00
Peter Mitsis 76357932d8 arm: Enable support for sys_thread_busy_wait()
It is now safe to enable sys_thread_busy_wait() for ARM as an earlier
patch has fixed the build system to link against the correct intrinsics
library.

Change-Id: Ib5ed036d996461b91f372b2b3e8f597a925d3292
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-11 14:13:05 +00:00
Dan Kalowsky 21a99e639d nanokernel : clean up comments
Moving comments back to the 70 character limit.  Also moving some of the
comments up to be included in the doxygen headers instead of inline.

Change-Id: I56a6015e5fd6da81e9a06701217e62e899b6aa62
Signed-off-by: Dan Kalowsky <daniel.kalowsky@intel.com>
2016-02-11 01:10:15 +00:00
Juan Manuel Cruz 65ec185f79 logger: include task monitor in kernel event logger
Zephyr includes a Task Monitor feature that allows to
track events on the microkernel server scheduler.
Task monitor is integrated as a profiler point for the
Kernel Event Logger feature.

Change-Id: I7b8be5872439a333f976eada1aa3511d93b46388
Signed-off-by: Juan Manuel Cruz <juan.m.cruz.alcaraz@linux.intel.com>
2016-02-09 13:53:41 -05:00
Juan Manuel Cruz d481b3ff4c logger: removes TASK_MONITOR_CAPACITY symbol
Task monitor is being tracked as a profiler point of the kernel
event logger. Now, the capacity to register task monitor events
is dictated by KERNEL_EVENT_LOGGER_BUFFER_SIZE symbol.

Change-Id: Ia4fe04c7d46fe41524c53447ad51af2e03ea5a15
Signed-off-by: Juan Manuel Cruz <juan.m.cruz.alcaraz@linux.intel.com>
2016-02-09 13:03:19 -05:00
Juan Manuel Cruz a641710aea logger: removes old task monitor structures.
Kernel event logger keeps track of task monitor events.
Old structures are not needed anymore.

Change-Id: I2267bdb3c2f27ea87d8675c4ecf0646ea62761ae
Signed-off-by: Juan Manuel Cruz <juan.m.cruz.alcaraz@linux.intel.com>
2016-02-09 13:03:19 -05:00
Peter Mitsis 61e6f4a299 sys_clock: Lock interrupts when processing announced ticks
Interrupts must be locked when processing announced ticks in
_nano_sys_clock_tick_announce().  This prevents higher priority
interrupts from interrupting the tick announcement and possibly
corrupting the timeout and/or timer queues.

Change-Id: I4e87fc5b3ad36161e0accb50b2691f975f5877e5
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:25:28 -05:00
Benjamin Walsh a4ec963138 init: use SYS_INIT() where it makes sense
Mostly SoC initialization and some kernel subsystems, but also some
device drivers like the interrupt controllers.

Change-Id: I8dc1844c33acd877c075b6b03558fdca6f87500b
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-02-05 20:25:25 -05:00
Benjamin Walsh dcfd4e96f4 device: remove obsolete DEVICE_DEFINE/INIT_CONFIG_DEFINE()
They have been replaced by DEVICE_INIT().

Change-Id: I06551f37593a3debb7eb221badd267bb5c7040c0
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-02-05 20:25:25 -05:00
Benjamin Walsh d340d4cb3f device: use DEVICE_INIT everwhere
This is the last step before obsoleting DEVICE_DEFINE() and
DEVICE_INIT_CONFIG_DEFINE().

Change-Id: Ica4257662969048083ab9839872b4b437b8b351b
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-02-05 20:25:25 -05:00
Benjamin Walsh 0303d8cab9 device: rename SYS_DEFINE_DEVICE()
Rename it to DEVICE_DEFINE() so that it fits in the 'device' namespace.

Change-Id: I3af3a39cf9154359b31d22729d0db9f710cd202b
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-02-05 20:25:25 -05:00
Benjamin Walsh bfc27206b2 device: rename DECLARE_DEVICE_INIT_CONFIG()
Rename it to DEVICE_INIT_CONFIG_DEFINE(), because (a) it was not fitting
in any namespace and (b) it is not used to declare, but rather define a
object.

Change-Id: I1da5822f06b85a9fb024b5b184afd0ccc01012ec
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-02-05 20:25:25 -05:00
Benjamin Walsh 2858cbf829 idle: fix tasks waiting when NANO_TIMEOUTS is enabled
Fix an issue where, if a task is pending on a nano timeout, the duration
it wants to wait is not taken into account by the tickless idle code.
This could cause a system to wait forever, or to the limit of the timer
hardware (which is forever, for all intents and purposes).

This fix is to add one field in the nanokernel data structure for one
task to record the amount of ticks it will wait on a nano timeout. Only
one task has to be able to record this information, since, these waits
being looping busy waits, the task of highest priority is the only task
that can be actively waiting with a nano timeout. If a task of lower
priority was previously waiting, and a new task is now waiting, it means
that the wait of the original task has been interrupted, which will
cause said task to run the busy loop on the object again when it gets
scheduled, and the number of ticks it wants to wait has to be recomputed
and recorded again.

Change-Id: Ibcf0f288fc42d96897642cfee00ab7359716703f
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-02-05 20:25:24 -05:00
Peter Mitsis 8e35cc8eb4 build: Add C++ support
Adds C++ support to the build system.

Change-Id: Ice1e57a13598e7a48b0bf3298fc318f4ce012ee6
Signed-off-by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:25:23 -05:00
Anas Nashif 2fe1a05b74 task monitor: remove ifdef, we check in Makefile already
Change-Id: I507c3e803a0d781e6cb84f03684d1ed0043678b8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-02-05 20:25:23 -05:00
Peter Mitsis a0e4568760 c++: Add extern "C" { } block to header files
Adds extern "C" { } blocks to header files so that they can be
safely used by C++ source files.

Change-Id: Ia4db0c36a5dac5d3de351184a297d2af0df64532
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:25:22 -05:00
Andrew Boie 583126adf9 microkernel: remove task_irq_free() API
This is being removed for a few reasons:

- AFAICT this is the only API in Zephyr that follows an allocate/free
model.

- There are no public APIs in the interrupt subsystem for releasing
or reconfiguring an interrupt. This code was relying on arch-specific
private APIs. If we really want to keep this capability we should
make these APIs public and consistent across arches.

- The use-case for this API is not clear, as Zephyr is not intended
for hot-pluggable peripherals. Built-in hardware tends to need its
interrupt for its entire life cycle.

- The current implementation of dynamic interrupts on x86 does not
support freeing a dynamic IRQ that was reserved with
irq_connect_dynamic(), causing this code not to work. To add this
would require reimplementing _get_dynamic_stub() to use a bitfield
or set of bitfields to track unused stubs rather than the simple
counter it uses now.

Change-Id: I7a03c134fb3498b91a1816318a88b293e26b846c
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2016-02-05 20:25:21 -05:00
Andrew Boie d9cfbd5a61 interrupts: new static IRQ API
The interrupt API has been redesigned:

- irq_connect() for dynamic interrupts renamed to irq_connect_dynamic().
  It will be used in situations where the new static irq_connect()
  won't work, i.e. the value of arguments can't be computed at build time
- a new API for static interrupts replaces irq_connect(). it is used
  exactly the same way as its dynamic counterpart. The old static irq
  macros will be removed
- Separate stub assembly files are no longer needed as the stubs are now
  generated inline with irq_connect()

ReST documentation updated for the changed API. Some detail about the
IDT in ROM added, and an oblique reference to the internal-only
_irq_handler_set() API removed; we don't talk about internal APIs in
the official documentation.

Change-Id: I280519993da0e0fe671eb537a876f67de33d3cd4
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2016-02-05 20:25:17 -05:00
Peter Mitsis d63a4f7bf7 nano_timers: Simplify nano_xxx_timer_test() API family
Simplifies the nanokernel timer API so that the timeout parameter must be
specified when invoking nano_isr_timer_test(), nano_fiber_timer_test(),
nano_task_timer_test() and nano_timer_test().

This obsoletes the following APIs:
	nano_fiber_timer_wait()
	nano_task_timer_wait()
	nano_timer_wait()

Note that even the though the new API requires that the timeout parameter
be specified, there are currentl only two acceptable values:
	TICKS_NONE and TICKS_UNLIMITED

Theoretically, the current implementation would allow one to supply a
finite positive value for the timeout and the system would wait up to
that many ticks for the timer to expire. However, it is thought that
that unnecessarily complicates the nanokernel timer model and so it is
left as an unsupported option.  Should that change, then that feature
could be enabled by updating the documentation.

Change-Id: I8835c5342ab5025d6f70fdfbed54a50add7568d7
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:25:15 -05:00
Peter Mitsis 5c01c09f4d nano_stack: Simplify nano_xxx_stack_pop() API family
Changes the nanokernel stack API so that the timeout parameter must be
specified when invoking nano_isr_stack_pop(), nano_fiber_stack_pop(),
nano_task_stack_pop() and nano_stack_pop().

This obsoletes the following APIs:
	nano_fiber_stack_pop_wait()
	nano_task_stack_pop_wait()
	nano_stack_pop_wait()

Note that even though the new API requires that the timeout parameter
be specified, there are currently only two acceptable values:
	TICKS_NONE and TICKS_UNLIMITED
This nanokernel option does not support CONFIG_NANO_TIMEOUTS.

Change-Id: Ic7f16ee30c3534115ceffa19ef8591ecc5a79080
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:25:14 -05:00
Peter Mitsis f0b55aa624 nano_lifo: Simplify nano_xxx_lifo_get() API family
Changes the nanokernel LIFO API so that the timeout parameter must be
specified when invoking nano_isr_lifo_get(), nano_fiber_lifo_get(),
nano_task_lifo_get() and nano_lifo_get().

This obsoletes the following APIs:
	nano_fiber_lifo_get_wait()
	nano_fiber_lifo_get_wait_timeout()
	nano_task_lifo_get_wait()
	nano_task_lifo_get_wait_timeout()
	nano_lifo_get_wait()
	nano_lifo_get_wait_timeout()

Change-Id: Ie9f93e46da42ea33c32544c02ab1d70b893cc198
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:25:14 -05:00
Peter Mitsis 54b782a88b nano_sema: Simplify nano_xxx_sem_take() API family
Changes the nanokernel semaphore API so that the timeout parameter must be
specified when invoking nano_isr_sem_take(), nano_fiber_sem_take(),
nano_task_sem_take() and nano_sem_take().

This obsoletes the following APIs:
	nano_fiber_sem_take_wait()
	nano_fiber_sem_take_wait_timeout()
	nano_task_sem_take_wait()
	nano_task_sem_take_wait_timeout()
	nano_sem_take_wait()
	nano_sem_take_wait_timeout()

Change-Id: If7a4bce1bd8ec8d6410d04f3c16ff1922ff0910e
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:25:14 -05:00
Peter Mitsis cd6db374de nano_fifo: Simplify nano_xxx_fifo_get() API family
Changes the nanokernel FIFO API so that the timeout parameter must be
specified when invoking nano_isr_fifo_get(), nano_fiber_fifo_get(),
nano_task_fifo_get() and nano_fifo_get().

This obsoletes the following APIs:
	nano_fiber_fifo_get_wait()
	nano_fiber_fifo_get_wait_timeout()
	nano_task_fifo_get_wait()
	nano_task_fifo_get_wait_timeout()
	nano_fifo_get_wait()
	nano_fifo_get_wait_timeout()

Change-Id: Icbd2909292f1ced0bad8a70a075478536a141ef2
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:25:14 -05:00
Peter Mitsis a6b20d4c04 nano timeouts: Add support macros
The macros _NANO_TIMEOUT_TICK_GET() and _NANO_TIMEOUT_ADD() will be
used in later commits to help simplify the nanokernel APIs.

Change-Id: I668af85d775eab112953d064d9c91de607f60a59
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:25:14 -05:00
Peter Mitsis 58acef1162 kconfig: Fix INT_LATENCY_BENCHMARK description
Fixes the routine names referenced in the INT_LATENCY_BENCHMARK
kconfig option description.

Change-Id: I74c67a8f54cfc3b0ce75fc390d7ab6bd39561d6f
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:25:13 -05:00
Peter Mitsis 4146b346b4 x86: streamline irq_lock()/irq_unlock()
The routines _int_latency_start() and _int_latency_stop() have been
replaced by macros that evaluate to nothing when the kernel config
option INT_LATENCY_BENCHMARK is not enabled thereby giving a performance
boost to the x86 versions of irq_lock() and and irq_unlock().

Change-Id: Iabfa7bf001f5b8396e7bcf5eebd6b1aa342bac46
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:25:13 -05:00
Benjamin Walsh 1ffdea1eb9 idle: add infrastructure for tickless support in nanokernels
An architecture that supports tickless idle in the nanokernel can allow
selecting TICKLESS_IDLE by forcing NANOKERNEL_TICKLESS_IDLE_SUPPORTED to
be enabled.

Change-Id: I4e45b619c599913d40b7bc19902094fb361b1e3b
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:25:13 -05:00
Dirk Brandewie ad99c3f93b kconfig: remove useless tickless idle dependency
Re-applying this patch, which was lost when moving to kbuild:

	commit 64c0f13f9380 ("kconfig: remove useless tickless idle dependency")
	Author: Benjamin Walsh <benjamin.walsh@windriver.com>
	Date:   Mon May 11 15:13:46 2015 -0400

	kconfig: remove useless tickless idle dependency

	TICKLESS_IDLE_THRESH depends on TICKLESS_IDLE, which depends on
	ADVANCED_POWER_MANAGEMENT, which itself already depends on
	MICROKERNEL. There is thus no point in having TICKLESS_IDLE_THRESH
	depend on MICROKERNEL.

Change-Id: I95edcc7b927dd122b80f376c96233decdcc9afab
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Signed-off-by: Dirk Brandewie <dirk.j.brandewie@intel.com>
2016-02-05 20:25:13 -05:00
Benjamin Walsh 38a601e578 idle: add support for nanokernel tickless idle
The architectures need to add support for it in their nano_cpu_idle()
and nano_cpu_atomic_idle() implementations, as well as in their
interrupt entry and exit code.

Change-Id: I44a241c56e624dc8e32e08db29a84489314cd7a4
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:25:13 -05:00
Daniel Leung 699564c69c microkernel: fix build issue when CONFIG_TASK_MONITOR=y
Note that the A->Comm is a pointer to the microkernel functions,
and thus is highly probable that the high 8-bit is occupied.
Therefore adds a new field in the monitor struct to store the pointer.

Change-Id: I7bcb34108c89a97cc38b2ac411ae4139b62786f3
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2016-02-05 20:25:12 -05:00
Dmitriy Korovkin e02a6fe585 init: Move SECONDARY init level to the idle task.
Move SECONDARY init level from essential pseudo-fiber
to the idle task, so the device initialization routines
may use interrupts and wait for interrupts.

Change-Id: I5afa92d8b304de5b295450f0a8a761385b7c2566
Signed-off-by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
2016-02-05 20:25:10 -05:00
Peter Mitsis 05e0c02a5d fifo: Simplify task_fifo_get() API family
Changes the FIFO API so that the timeout parameter must be specified
when invoking task_fifo_get() thereby making the following APIs obsolete:
    task_fifo_get_wait()
    task_fifo_get_wait_timeout()
    _task_fifo_get()

Change-Id: Iac626d9d6d4836033e06ffd5a2ca415ab2630b1a
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:25:06 -05:00
Peter Mitsis 5deb202a8c fifo: Simplify task_fifo_put() API family
Changes the FIFO API so that the timeout parameter must be specified
when invoking task_fifo_put() thereby making the following APIs obsolete:
    task_fifo_put_wait()
    task_fifo_put_wait_timeout()
    _task_fifo_put()

Change-Id: Ifbbfb7018fd9a71551ccba648fda6d2d59d589a6
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:25:05 -05:00
Peter Mitsis 4eae500445 mutex: Simplify task_mutex_lock() API family
Changes the mutex API so that the timeout parameter must be specified
when invoking task_mutex_lock() thereby obsoleting the following APIs:
    task_mutex_lock_wait()
    task_mutex_lock_wait_timeout()
    _task_mutex_lock()

Change-Id: I15d4bddbdc2707b3cbdab672498170da1c47b8db
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:25:05 -05:00
Peter Mitsis 9cc9bdcd53 mem_pool: Simplify task_mem_pool_alloc() API family
Changes the mem_pool API so that the timeout parameter must be specified
when invoking task_mem_pool_alloc() thereby obsoleting the following APIs:
	task_mem_pool_alloc_wait()
	task_mem_pool_alloc_wait_alloc()
	_task_mem_pool_alloc()

Change-Id: Ifa88f13bca98ca3c7d0e1a3b64b40a00068619e0
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:25:05 -05:00
Peter Mitsis e2cb5f5bdd mem_map: Simplify task_mem_map_alloc() API family
Changes the mem_map API so that the timeout parameter must be specified
when invoking task_mem_map_alloc() thereby obsoleting the following APIs:
    task_mem_map_alloc_wait()
    task_mem_map_alloc_wait_alloc()
    _task_mem_map_alloc()

Change-Id: I8905d07fa4b8c3729ca144e8f09e7ad0c7bf0f43
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:25:05 -05:00
Peter Mitsis f863d66dd8 semgroup: Simplify task_sem_group_take() API family
Changes the semaphore API so that the timeout parameter must be specified
when invoking task_sem_group_take() thereby obsoleting the following APIs:
	task_sem_group_take_wait()
	task_sem_group_take_wait_timeout()
	_task_sem_group_take()

Change-Id: I64e3f4c9f1e74a86b49d4a0e55b82ecee7733220
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:25:05 -05:00
Peter Mitsis 40eba989e2 semaphore: Simplify task_sem_take() API family
Changes the semaphore API so that the timeout parameter must be specified
when invoking task_sem_take() thereby obsoleting the following APIs:
	task_sem_take_wait()
	task_sem_take_wait_timeout()
	_task_sem_take()

Change-Id: I746d5c966a3b81ffe014333af51aa10ea8a63263
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:25:05 -05:00
Peter Mitsis 57c7977ecf pipes: Simplify task_pipe_get() API family
Changes the pipe API so that the timeout parameter must be specified
when invoking task_pipe_get() thereby obsoleting the following APIs:
	task_pipe_get_wait()
	task_pipe_get_wait_timeout()
	_task_pipe_get()

Change-Id: If249e57d086fef15fdc1616965f53b310ac9cf9d
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:25:05 -05:00
Peter Mitsis f5d90e1584 pipes: Simplify task_pipe_put() API family
Changes the pipe API so that the timeout parameter must be specified
when invoking task_pipe_put() thereby obsoletingg the following APIs:
	task_pipe_put_wait()
	task_pipe_put_wait_timeout()
	_task_pipe_put()

Change-Id: Ie5693716828e9d8681434c0d130792279ab97acc
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:25:05 -05:00
Peter Mitsis 18ea9a4d05 pipe, cosmetic: Put constant in comparisons on the right
Updates comparisons in the pipe code to put the constant on the
right side of the test. This improves compliance with checkpatch.

Change-Id: I8e55afd94e0532dd7a67bd83e737846279654dff
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:25:05 -05:00
Peter Mitsis d3e4b72da2 mailbox: Simplify task_mbox_data_block_get() API family
Changes the mailbox API so that the timeout parameter must be specified
when invoking task_mbox_data_block_get() thereby obsoleting the
following APIs:
    task_mbox_data_block_get_wait()
    task_mbox_data_block_get_wait_timeout()
    _task_mbox_data_block_get()

Change-Id: I284be505e6de792ba5483611d1299063162550e1
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:25:05 -05:00
Peter Mitsis a67b7070b7 events: Simplify task_event_recv() API family
Changes the event AIP so that the timeout parameter must be specified
when invoking task_event_recv() thereby making the following APIs obsolete:

	task_event_recv()
	task_event_recv_wait()
	task_event_recv_wait_timeout()
	_task_event_recv()

Change-Id: I165a8efbdedb431fee0c20e9ad1f1942c04124c0
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:25:05 -05:00
Peter Mitsis 1a163f53b7 task_irq: Simplify task_irq_test() API family
Changes the task IRQ API so that not only does task_irq_test() become
task_irq_wait(), but that the timeout parameter must also be specified.
Use of task_irq_wait() obsoletes the following APIs:
	task_irq_test()
	task_irq_test_wait()
	task_irq_test_wait_timeout()
	_task_irq_test()

Change-Id: Ie4d15f29941429249e9fbb258d29ec2b3ae73a93
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:25:05 -05:00
Peter Mitsis b4ba8087e7 mailbox: Simplify task_mbox_get() API family
Changes the mailbox API so that the timeout parameter must be specified
when invoking task_mbox_get() thereby obsoleting the following APIs:
    task_mbox_get_wait()
    task_mbox_get_wait_timeout()
    _task_mbox_get()

Change-Id: Ie028223ec342666e61d3d69750aec37dbe2b493e
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:25:05 -05:00
Peter Mitsis 96116cadbb mailbox: Simplify task_mbox_put() API family
Changes the mailbox API so that the timeout parameter must be specified
when invoking task_mbox_put() thereby obsoleting the following APIs:
	task_mbox_put_wait()
	task_mbox_put_wait_timeout()
	_task_mbox_put()

Change-Id: I174857bdf32fe7e59b79838185666cd557312814
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:25:05 -05:00
Peter Mitsis 95de74e121 mailbox, cosmetic: Put constant in comparisons on the right
Updates comparisons in the mailbox code to put the constant on the
right side of the test. This improves compliance with checkpatch.

Change-Id: If84cfbe4bbca312fabbb70d45f05675c9c15d011
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:25:05 -05:00
Dirk Brandewie 88ce5bc8f5 kernel: remove CONFIG_INT_LATENCY_BENCHMARK fences from code path
Add null definitions for the interrupt latency measurement API so we
can remove compile fences in C code.

Change-Id: If86eedf79afcb49002108814dd4fb864956eb667
Signed-off-by: Dirk Brandewie <dirk.j.brandewie@intel.com>
2016-02-05 20:25:04 -05:00
Benjamin Walsh 3181df6db4 kernel: add per-thread errno support
Saves an errno per-thread, retrieved via _get_errno(), instead of
changing the value of a global variable during context switches to avoid
a hit to the context switch performance.

Per-arch asm implementations are provided for maximum performance.

Enabled by default, but can be disabled via the CONFIG_ERRNO option.

Change-Id: I81d57a2e318c94c68eee913ae0d4ca3a3609c7a4
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-02-05 20:24:58 -05:00
Anas Nashif 275ca60b08 Fixed file description and applied doxygen style
Removed old style file description and documnetation and apply
doxygen synatx.

Change-Id: I3ac9f06d4f574bf3c79c6f6044cec3a7e2f6e4c8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-02-05 20:24:58 -05:00
Yonattan Louise c5d86e90a1 Fix logging of interrupt events.
The system crashed if an interrupt occurs before the
kernel event logger is initialized (Error seen on Galileo).
This patch adds a condition to check if the logger is ready
to operate.

Change-Id: I27d7cc31f386780725b0c47a9c92e9c064fc128a
Signed-off-by: Yonattan Louise <yonattan.a.louise.mendoza@intel.com>
2016-02-05 20:24:58 -05:00
Yonattan Louise 8885d093c4 Add support for profiling sleep events in nanokernel.
This patch remove the dependency of the ADVANCE_POWER_MANAGEMENT
for profiling sleep events that was supported only for microkernel.
Allowing us to also use this feature in nanokernel-only systems.

Change-Id: I1761eb6c4d72f477b419dfca5dc152b0fb69ee27
Signed-off-by: Yonattan Louise <yonattan.a.louise.mendoza@intel.com>
2016-02-05 20:24:58 -05:00
Peter Mitsis 78ed31ac01 kernel: Replace nano/task_cycle_get_32()
Replaces calls to nano_cycle_get_32() and task_cycle_get_32()
with sys_cycle_get_32() as that is the preferred API to use.

Change-Id: I0ad1c50083c4cfdd9a26c2f20ba24e065410d90d
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:24:55 -05:00
Peter Mitsis 92b21c7153 timer: Rename _sys_clock_cycle_get()
Renames _sys_clock_cycle_get() (provided by the timer driver)
to sys_cycle_get_32().  It is the preferred method to read the
hardware clock.

Change-Id: Ifea5213d8c04a8bf7b9114b048c5db0ccee61549
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:24:55 -05:00
Dmitriy Korovkin 57f2741e4f init: Implement fine-grained initialization policy
Put initialization priorities as device driver Kconfig
parameter.

Initialization priority value for each platform is defined
in the platform Kconfig file.

Drivers and platform code use SYS_DEFINE_DEVICE to add
and initialization function.

Change-Id: I2f4f3c7370dac02408a1b50a0a1bade8b427a282
Signed-off-by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-02-05 20:24:54 -05:00
Peter Mitsis cd9893d563 microkernel: Elminate task_tick_xxx() APIs
Eliminates task_tick_xxx APIs in favor of sys_tick_xxx APIs.
	task_tick_get()    -> sys_tick_get()
	task_tick_get_32() -> sys_tick_get_32()
	task_tick_delta    -> sys_tick_delta()
	task_tick_delta_32 -> sys_tick_delta_32()

Change-Id: Ie8c2bc114a08f091997faaf68f6fc5536b2ba25d
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:24:54 -05:00
Peter Mitsis c40e84c57a nanokernel: Rename nano_tick_xxx APIs
Renames the following nanokernel tick APIs.
	nano_tick_get()      -> sys_tick_get()
	nano_tick_get_32()   -> sys_tick_get_32()
	nano_tick_delta()    -> sys_tick_delta()
	nano_tick_delta_32() -> sys_tick_delta_32()

Change-Id: Ie969545335d76df94b4e2d200fef86a93596f5e8
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:24:53 -05:00
Peter Mitsis 7afd7035a2 sys_clock: Replace microkernel _k_sys_clock_tick_count
Replaces microkernel global variable _k_sys_clock_tick_count with the
global variable _sys_clock_tick_count.  This allows both the microkernel
and the nanokernel to use the same variable to track system clock ticks
instead of using two different ones.

Change-Id: Ia4eebf022f59d130ad1882e0e550016527543a45
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:24:53 -05:00
Peter Mitsis 43b05eb463 sys_clock: Rename _nano_ticks
Renames nanokernel global variable _nano_ticks to _sys_clock_tick_count.

Change-Id: I857407f1f7e8d9fd2eedc1c1696851173e58d2b4
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:24:53 -05:00
Peter Mitsis 30bf5c05c8 sys_clock: fix _sys_idle_elapsed_ticks type
Fixes the type of global variable _sys_idle_elapsed_ticks such that
both its nanokernel and microkernel definitions are of the same
type--int32_t.

One of the repercussions of this is that code related to the routine
_nano_sys_clock_tick_announce() does not need the application of
typecasting.

Change-Id: I3d7374cd1a32aea7e4651726febde74ebe4ac8ac
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:24:53 -05:00
Allan Stephens 6b07c1d548 doc: Update descriptions for semaphore APIs
Standardizes appearance, corrects errors, improves readability,
and fils in gaps. Also relocates documentation for internal APIs.

Removes mention of non-existent task_sem_group_take() API from
the Kernel Primer document. The microkernel's semaphore group logic
currently allows a task to take a semaphore from a semaphore group
in a blocking manner.

Change-Id: Ib41a43775a97483a5adc552b70575ae4269aba35
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-02-05 20:24:53 -05:00
Benjamin Walsh 5ce563b3f1 kernel: rename _nano_fiber_schedule()
It's not really scheduling a fiber, it's making it ready. So, rename it
to _nano_fiber_ready().

Change-Id: I34bf67a8f0ea641bb2fd1c47fe8d689fef754cb8
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-02-05 20:24:53 -05:00
Benjamin Walsh fde6458f0b sys_clock: add option for setting timer frequency at runtime
Some timer devices, such as the HPET, read their frequencies at runtime.
All global constant values must be set at runtime in that case.

Change-Id: I408babce6deb857748a87691132d7e27e88f0bb8
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-02-05 20:24:53 -05:00
Benjamin Walsh cdf8123589 sys_clock: remove global variables duplication
Some global variables were duplicated, being defined in either
k_ticker.o or nano_sys_clock.o depending on the type of kernel.
nano_sys_clock.o is always generated, so move the definitions found in
that file from inside the NANOKERNEL guard and remove them from
k_ticker.c to avoid useless duplication.

Change-Id: Iea67f89cad44b29671df7fa4d573105c0bbe3102
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-02-05 20:24:53 -05:00
Peter Mitsis 8c658e11b1 nanokernel: Add task_sleep()
This routine allows the background task to sleep for a specified
number of ticks.

Change-Id: I2533005e3d9a564c2ca0de8333e224743cefb658
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:24:53 -05:00
Peter Mitsis e63ceae6b4 nanokernel: Move fiber_sleep() to nano_sleep.c
Change-Id: I5faaa44cf40a3d2d31a37e3b84cbef3c8dacff32
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:24:53 -05:00
Peter Mitsis 699b4ee03d nanokernel: Add generic stack routines
Adds the following generic stack routines:
	nano_stack_push()
	nano_stack_stack_pop()
	nano_stack_pop_wait()

Those routines are convenience wrappers for invoking the task, fiber and
ISR (if applicable) specific implementations.

Change-Id: I6e7bb2ca69bb2e3d5ed955654390746e76e4ab92
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:24:53 -05:00
Peter Mitsis 836eaee18a nanokernel: Add generic semaphore routines
Adds the following generic semaphore routines:
	nano_sem_take()
	nano_sem_take_wait()

Those routines are convenience wrappers for invoking the task, fiber and
ISR (if applicable) specific implementations.

Change-Id: I09d715d07263eb0ee526231120ba65d1e3feebce
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:24:53 -05:00
Peter Mitsis 16c7452f6b nanokernel: Add generic lifo routines
Adds the following generic lifo routines:
	nano_lifo_put()
	nano_lifo_get()
	nano_lifo_get_wait()
	nano_lifo_get_wait_timeout()

Those routines are convenience wrappers for invoking the task, fiber and
ISR (if applicable) specific implementations.

Change-Id: I5252e4643fe4772f1309b26c1b3e4319f5035956
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:24:53 -05:00
Peter Mitsis 829967786c nanokernel: Add generic fifo routine
Adds the following generic fifo routine:
	nano_fifo_get_wait_timeout()

That routine is a convenience wrapper for invoking the task or fiber
specific implementation.

Change-Id: I9bd709ea416db834e2a0c5de81257c363e7db066
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:24:53 -05:00
Peter Mitsis 3d2afc63c0 nanokernel: Add generic timer routines
Adds the following timer routines:
	nano_isr_timer_start()
	nano_isr_timer_stop()
	nano_isr_timer_test()
	nano_timer_start()
	nano_timer_stop()
	nano_timer_test()
	nano_timer_wait()

Change-Id: Ib93f2ef2ffaa12dea3ddb52e9f3ae758b2987300
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:24:53 -05:00
Anas Nashif 77ba3c3b8b kconfig: define architecture as a kconfig variable
Do not depend on environment variables and use a kconfig variable
for defining the architecture.

In addition, remove the X86_32 variable, it just duplicates X86 for
not good reason, at least until start supporting MCUs with 64bit.

Change-Id: Ia001db81ed007e6a43f34506fed9be1345b88a4b
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-02-05 20:24:52 -05:00
Anas Nashif 401c4da142 kconfig: do not set default for frequency
Force setting the value in the platform kconfig instead of defaulting
to 0.

Change-Id: Iceeb6346afc4217dd09d31c28898e3693b08f781
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-02-05 20:24:48 -05:00
Benjamin Walsh 15d3ca1de6 events: add __ASSERT()s in APIs to validate event IDs
Event ID are not validated anymore against the maximum event number in
the system, since they are pointers now instead of low integers.
Validation can be useful, but only do it in a debug kernel, with no
penalty to a deployment system.

Change-Id: Ifd8dc8841892f6d19bbcb0c641a655fd0cb6ddb7
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-02-05 20:24:48 -05:00
Allan Stephens dca7f8ccca doc: Update descriptions for memory map APIs
Standardizes appearance, corrects errors, improves readability,
and fills in gaps. Also streamlines descriptions for internal APIs
that don't require the same level of detail as public APIs.

Change-Id: Ic0f8149d14a8dab5e6df28b594c9b2e17f73e7b6
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-02-05 20:24:48 -05:00
Dmitriy Korovkin f1420515a7 irq: Add flags to IRQ_CONNECT_STATIC() macro and irq_connect() function
Flags allow passing IRQ triggering option for x86 architecture.
Each platform defines flags for a particular device and then
device driver uses them when registers the interrupt handler.

The change in API means that device drivers and sample
applications need to use the new API.

IRQ triggering configuration is now handled by device drivers
by using flags passed to interrupt registering API:
IRQ_CONNECT_STATIC() or irq_connect()

Change-Id: Ibc4312ea2b4032a2efc5b913c6389f780a2a11d1
Signed-off-by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
2016-02-05 20:24:44 -05:00
Yonattan Louise 16ddcfa43d Fix kernel event logger sample for nanokernel-only systems.
This commit fixes the nanokernel sample of the kernel event logger
that shows the event messages for context switch and interrupt events.

Change-Id: I4e972adb06b81f2f548bbabe8cd6577af633001c
Signed-off-by: Yonattan Louise <yonattan.a.louise.mendoza@intel.com>
2016-02-05 20:24:43 -05:00
Peter Mitsis 9fce2a2209 Remove obsolete ctors section
Remove prototype support for C++ constructors, since it is not well
designed. Device drivers (or other application code) that requires an
automatic initialization capability should use the device initialization
macros instead.

Note: Support for C++ constructors may be re-introduced at a later date.
However, a number of issues need to be settled, such as when the
constructors are invoked and what context they run in. (Running them
during nanokernel initialization, as was previously done, is probably
not the right approach.)

Change-Id: If6d27ac16b485cb39d5ec34084e9d0f1991074f4
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:24:43 -05:00
Benjamin Walsh 55afb68e83 x86: remove NANOKERNEL guard around nano_cpu_idle()
It can be used by some subsystems even in a microkernel.

Change-Id: I07241aab94ecf67c94dce2d05f2cd774b2a6b044
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-02-05 20:24:43 -05:00
Allan Stephens 0c8965fd99 kernel: Specify alignment of microkernel server command stack items
The microkernel server now relies on the fact that the command packets,
events, and semaphores passed to it via its command stack are 32 bit
aligned. This change explicitly ensures this alignment, rather than
leaving it to the compiler's discretion.

Change-Id: Ied7a0a0b4cc504c924520b72ef2b207b49470448
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-02-05 20:24:42 -05:00
Allan Stephens 7c4b9ce1f7 kernel: Eliminate the need for command packet sets
Revises microkernel semaphore sub-system to allow ISRs and fibers
to give a semaphore without having to define a command packet set.
The microkernel server now supports a 3rd command type on its
command stack, allowing a semaphore to be given in a similar manner
to the one used for the existing "give event" command type.

Change-Id: Ibd7fb1a77949792f72acd20a9ee304d6eabd62f7
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-02-05 20:24:42 -05:00
Anas Nashif 6de1c20809 core: remove NO_ISRS feature
This option is not building and currently not supported, removing
it because there does not seem to be a use case for it.

Change-Id: Idb8ffedf83f43cffc68a01573c6f2d1a90fc40fb
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-02-05 20:24:42 -05:00
Yonattan Louise e378747706 Rename Profiler to Event Logger.
In order to have a name according to the functionality of the feature.
This commit rename any text, function and variable related with the
Profiler name to Event logger.

Change-Id: I4f612cbc7c37965c35a64f06cc3ce5e3249d90e5
Signed-off-by: Yonattan Louise <yonattan.a.louise.mendoza@intel.com>
2016-02-05 20:24:41 -05:00
Allan Stephens 16504c27c1 kernel: Revise microkernel server's recognition of command types
Revises microkernel server command stack processing to allow the
server to support more than 2 types of commands. The lowest 2 bits
of the command now indicate the command's type:

0 - process specified command packet
1 - give specified event (from ISR or fiber)
2 - give specified semaphore (from ISR or fiber)
3 - reserved for future use

Note: Support for type 2 will be provided in a future commit.

Change-Id: I9f83f92a301fb5df3dd479b5d43b187371e11ad8
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-02-05 20:24:41 -05:00
Dan Kalowsky 2a57d02400 checkpatch: warning - spacing
Change-Id: Ia63d6c9d8d3c1bd9c540a039263cb8507af82b1e
Signed-off-by: Dan Kalowsky <daniel.kalowsky@intel.com>
2016-02-05 20:24:35 -05:00
Dan Kalowsky 2a63743192 cleanup: removing NOMANUAL
The \NOMANUAL tag is a remnant from days of yore and is no longer
needed or useful.  Cleaning up the code references to this.

Change-Id: I1b8cc9c9560d1dbb711f05fa63fd23386789875c
Signed-off-by: Dan Kalowsky <daniel.kalowsky@intel.com>
2016-02-05 20:24:35 -05:00
Dan Kalowsky 72f0a1314e checkpatch: warning - unnecssary_else
Change-Id: I6cc45cfcf09448b8fc988dc56219ea7560636af4
Signed-off-by: Dan Kalowsky <daniel.kalowsky@intel.com>
2016-02-05 20:24:35 -05:00
Daniel Leung 851c6f8f60 microkernel: introduce private event objects
This patch enables defining microkernel events within source code.
This is similar to other private kernel object patches.

The test has been modified a little bit due to the fact that
the event ID is now a memory address, instead of numeric ID.

Change-Id: Ie3c8d4f4e459d9c631e50bb242cf7a05ca8ea82c
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-02-05 20:24:35 -05:00
Peter Mitsis 079a0affee Remove kernel configuration option CUSTOM_SECURITY
The Kconfig option CUSTOM_SECURITY is not used anywhere.

Change-Id: Ifac00cd1234ff9498c2f977054a902e0153b6b28
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:24:34 -05:00
Dan Kalowsky 827f6ba7dc checkpatch: warning - long_line
Change-Id: I7dd5645db1de00ab4bf2ca3c7a8bae906e8d9e54
Signed-off-by: Dan Kalowsky <daniel.kalowsky@intel.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-02-05 20:24:33 -05:00
Dan Kalowsky 7f9080671b checkpatch: warning - suspect_code_indent
Change-Id: I7e920e6de8f4b7a726c03c05edea3cbac69eb374
Signed-off-by: Dan Kalowsky <daniel.kalowsky@intel.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-02-05 20:24:33 -05:00
Dan Kalowsky 890cc2f1ef checkpatch: warning - line_spacing
Change-Id: I2276676142deea21cf8079449ce153f2fb887a8e
Signed-off-by: Dan Kalowsky <daniel.kalowsky@intel.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-02-05 20:24:33 -05:00
Dan Kalowsky e8563c2f97 checkpatch: error - trailing_whitespace
Change-Id: I819d13f0d7a23e3a61dcda6a3ced18810b192158
Signed-off-by: Dan Kalowsky <daniel.kalowsky@intel.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-02-05 20:24:33 -05:00
Dan Kalowsky 9760129627 checkpatch: error - open_brace
Change-Id: Ie655181d5ed11a71cadfa218f396f0b64992ca34
Signed-off-by: Dan Kalowsky <daniel.kalowsky@intel.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-02-05 20:24:33 -05:00
Dan Kalowsky a92e48890c checkpatch: error - global_initialisers
Change-Id: Ib3f69be9f9273e57952a3ebceebc82d84c607c64
Signed-off-by: Dan Kalowsky <daniel.kalowsky@intel.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-02-05 20:24:33 -05:00
Dan Kalowsky da67b29569 checkpatch: warning - block_comment_style
Change-Id: I6da43e41f9c6efee577b70513ec368ae3cce0144
Signed-off-by: Dan Kalowsky <daniel.kalowsky@intel.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-02-05 20:24:33 -05:00
Dan Kalowsky 3a109b1f00 Adding in doxygen comment headers
Moving many of the functions from the old format of inline comments to
the newer doxygen format.

Change-Id: Ib0fe0d8627d7cd90219385a3ab627da8f9637d98
Signed-off-by: Dan Kalowsky <daniel.kalowsky@intel.com>
2016-02-05 20:24:33 -05:00
Yonattan Louise 86ea4e6827 OS Awareness: Add microkernel object tracing.
Add a list for each kind of microkernel object. Add the register of
the public objects to the tracing lists in the dynamic initialization
function of sysgen.

Change-Id: I8c413812e4db0f443c9dd3a5501e0096270dc70e
Signed-off-by: Yonattan Louise <yonattan.a.louise.mendoza@intel.com>
2016-02-05 20:24:32 -05:00
Yonattan Louise abc2c9e59d OS Awareness: Add nanokernel object tracing.
Add a list for each kind of nanokernel object. And link the object
to the list on the initialization function.

Change-Id: I7a51902a8d1b306ec50d9486e55af286127fcb1a
Signed-off-by: Yonattan Louise <yonattan.a.louise.mendoza@intel.com>
2016-02-05 20:24:32 -05:00
Dan Kalowsky 2e938481ce checkpatch: error - initialised_static
Change-Id: I8f51f861e2250c87c296b697ef5b6610ce644b34
Signed-off-by: Dan Kalowsky <daniel.kalowsky@intel.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-02-05 20:24:31 -05:00
Dan Kalowsky 0182d863cd checkpatch: error - function_without_args
Change-Id: Id020ac7eafbb20352d839565256f0bf47f7fe301
Signed-off-by: Dan Kalowsky <daniel.kalowsky@intel.com>
2016-02-05 20:24:31 -05:00
Dan Kalowsky 39063598db checkpatch: error - spacing
Change-Id: Ie6e1c43581dd4b0734625b3a4e59a4ca79619e99
Signed-off-by: Dan Kalowsky <daniel.kalowsky@intel.com>
2016-02-05 20:24:31 -05:00
Dan Kalowsky 4518f747af checkpatch: error - trailing_whitespace
Change-Id: I9ccc8aef40de7b66e1899994e3dbc7147df61414
Signed-off-by: Dan Kalowsky <daniel.kalowsky@intel.com>
2016-02-05 20:24:31 -05:00