Commit graph

1347 commits

Author SHA1 Message Date
Johan Hedberg 47a28a9612 mempool: Remove unnecessary call to get_pool()
The pointer that get_pool() returns is already stored in the 'p'
variable.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-01-12 08:05:08 -05:00
Johan Hedberg 1a8a8d9019 mempool: Don't store redundant information for k_malloc/k_free
We don't need to store the full k_mem_block, rather just the
k_mem_block_id. In effect, this saves 4 bytes of memory per allocated
memory chunk. Also take advantage of the newly introduced
k_mem_pool_free_id API here.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-01-12 08:05:08 -05:00
Johan Hedberg 7d887cb615 mempool: Add k_mem_pool_free_id API
The k_mem_pool_free API has no use for the full k_mem_block struct. In
particular, it only needs the k_mem_block_id. Introduce a new API
which takes only this essential struct. This paves the way to
simplify & improve the k_malloc/k_free implementation a bit.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-01-12 08:05:08 -05:00
Anas Nashif a805c97edb kernel: enable boot banner by default
Have all samples and tests print the banner and timestamp. This can
easily be turned off if needed.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-01-08 10:03:57 -05:00
Anas Nashif 274ad46a84 kernel: move posix header to posix/
Having posix headers in the default include path causes issues with the
posix port. Move to a sub-directory to avoid any conflicts.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-12-27 14:16:08 -05:00
Anas Nashif 94d034dd5e kernel: support custom k_busy_wait()
Support architectures implementing their own k_busy_wait.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-12-27 14:16:08 -05:00
Adithya Baglody 9cde20aefa kernel: mem_domain: Add to current thread should configure immediately.
when a current thread is added to a memory domain the pages/sections
must be configured immediately.
A problem occurs when we add a thread to current and then drop
down to usermode. In such a case memory domain will become active
the next time a swap occurs.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2017-12-21 11:52:27 -08:00
Adithya Baglody 13ac4d4264 kernel: mem_domain: Add an arch interface to configure memory domain
Add an architecure specfic code for the memory domain
configuration. This is needed to support a memory domain API
k_mem_domain_add_thread.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2017-12-21 11:52:27 -08:00
Adithya Baglody e1f4a002f3 kernel: mem_domain: Add arch specfic destroy for remove thread API.
If the thread id is same as current then handle the cleanup of the
memory domain.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2017-12-21 11:52:27 -08:00
Youvedeep Singh b4292cf35b kernel: posix: separating posix APIs according to their types.
Currently all posix APIs are put into single files (pthread.c).
This patch creates separate files for different API areas.

Signed-off-by: Youvedeep Singh <youvedeep.singh@intel.com>
2017-12-20 14:59:04 -05:00
Adithya Baglody 2fce4e4c9b kernel: userspace: Fixed the issue of handlers getting dropped by linker
The linker was always picking a weak handler over the actual one.
The linker always searches for the first definition of any function
weak or otherwise. When it finds this function it just links and
skips traversing through the full list.

In the context of userspace, we create the _handlers_ for each system
call in the respective file. And these _handlers_ would get linked to
a table defined in syscalls_dispatch.c. If for instance that this
handler is not defined then we link to a default error handler.

In the build procedure we create a library file from the kernel folder.
When creating this library file, we need to make sure that the file
syscalls_dispatch.c is the last to get linked(i.e userspace.c).
Because the table inside syscalls_dispatch.c would need all the
correct _handler_ definitions. If this is not handled then the system
call layer will not function correctly because of the linker feature.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2017-12-14 09:07:23 -08:00
Anas Nashif 429c2a4d9d kconfig: fix help syntax and add spaces
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-12-13 17:43:28 -06:00
Anas Nashif b893dac6b3 kernel: remove reference to legacy_timer.c in build system
We do not have this file anymore, remove it from the cmake files.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-12-09 08:48:51 -06:00
Anas Nashif fb4eecaf5f kernel: threads: remove thread groups
We have removed this features when we moved to the unified kernel. Those
functions existed to support migration from the old kernel and can go
now.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-12-09 08:48:51 -06:00
Anas Nashif 5efb6a1d94 kernel: sys_clock: remove obsolete and unused functions
Those functions are duplicated and leftovers from migration to unified
kernel.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-12-09 08:48:51 -06:00
Kumar Gala a2caf36103 kernel: Remove deprecated k_mem_pool_defrag code
Remove references to k_mem_pool_defrag and any related bits associated
with mem_pool defrag that don't make sense anymore.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-11-28 15:23:22 -05:00
Anas Nashif 54d19f2719 kconfig: update BOOT_BANNER help message
USAP is a thing of the past, remove it and update the help message of
this option.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-11-27 22:15:30 -05:00
Luiz Augusto von Dentz 8786244ebc poll: Update code comments to reflect latest changes
It is now possible to poll event if there is another thread polling.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-11-21 06:54:51 -05:00
Andrew Boie 9f38d2a91a kernel: have k_sched_lock call _sched_lock
Having two implementations of the same thing is bad,
especially when one can just call the other inline version.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-11-17 17:42:54 -05:00
Andrew Boie a79c69823f mempool: add assertion for calloc bounds overflow
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-11-14 12:50:10 -08:00
Punit Vara ce60d04fb6 kernel: sched.c: Fix datatype mismatch in comparision
All arguments comes from userspace has data type u32_t but
base.prio has data type of s8_t. Comparision between s8_t and u32_t
cannot be done. That's why typecast priority coming from userspace(prio)
to s8_t data type.

Signed-off-by: Punit Vara <punit.vara@intel.com>
2017-11-14 09:49:00 -08:00
Andrew Boie a7fedb7073 _setup_new_thread: fix crash on ARM
On arches which have custom logic to do the initial swap into
the main thread, _current may be NULL. This happens when
instantiating the idle and main threads.

If this is the case, skip checks for memory domain and object
permission inheritance, in this case there is never anything to
inherit.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-11-13 16:25:40 -08:00
Andrew Boie 7f95e83361 mempool: add k_calloc()
This uses the kernel heap to implement traditional calloc()
semantics.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-11-13 09:50:15 -08:00
Sebastian Bøe 0829ddfe9a kbuild: Removed KBuild
Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-08 20:00:22 -05:00
Sebastian Bøe 12f8f76165 Introduce cmake-based rewrite of KBuild
Introducing CMake is an important step in a larger effort to make
Zephyr easy to use for application developers working on different
platforms with different development environment needs.

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

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

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

Install CMake 3.8.2+

Port any out-of-tree Makefiles to CMake.

Learn the absolute minimum about the new command line interface:

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

$ cd build
$ make

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

Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-08 20:00:22 -05:00
Andrew Boie 0bf9d33602 mem_domain: inherit from parent thread
New threads inherit any memory domain membership held by the
parent thread.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-11-08 09:14:52 -08:00
Adithya Baglody 7bb40bd9ca kernel: init: mem_domain structure is initialized for dummy thread.
For the dummy thread, contents in the mem_domain structure
is insignificant hence setting it to NULL.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2017-11-07 12:22:43 -08:00
Adithya Baglody eff2ec6ac9 kernel: Arch specific memory domain APIs added
Added arch specific calls to handle memory domain destroy
and removal of partition.

GH-3852

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2017-11-07 12:22:43 -08:00
Adithya Baglody 57832073c6 kernel: arch interface for memory domain
Additional arch specific interfaces to handle memory domain
destroy and single partition removal.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2017-11-07 12:22:43 -08:00
Andrew Boie 818a96d3af userspace: assign thread IDs at build time
Kernel object metadata had an extra data field added recently to
store bounds for stack objects. Use this data field to assign
IDs to thread objects at build time. This has numerous advantages:

* Threads can be granted permissions on kernel objects before the
  thread is initialized. Previously, it was necessary to call
  k_thread_create() with a K_FOREVER delay, assign permissions, then
  start the thread. Permissions are still completely cleared when
  a thread exits.

* No need for runtime logic to manage thread IDs

* Build error if CONFIG_MAX_THREAD_BYTES is set too low

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-11-03 11:29:23 -07:00
Leandro Pereira b007b64d30 kernel: Add option to ensure writable pages are not executable
This adds CONFIG_EXECUTE_XOR_WRITE, which is enabled by default on
systems that support controlling whether a page can contain executable
code.  This is also known as W^X[1].

Trying to add a memory domain with a page that is both executable and
writable, either for supervisor mode threads, or for user mode threads,
will result in a kernel panic.

There are few cases where a writable page should also be executable
(JIT compilers, which are most likely out of scope for Zephyr), so an
option is provided to disable the check.

Since the memory domain APIs are executed in supervisor mode, a
determined person could bypass these checks with ease.  This is seen
more as a way to avoid people shooting themselves in the foot.

[1] https://en.wikipedia.org/wiki/W%5EX

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-11-02 13:40:50 -07:00
Adithya Baglody edd072e730 tests: benchmarking: cleanup of the benchmarking code.
The kernel will no longer reference the code written in the
test folder.

GH-1236

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2017-11-02 09:01:06 -04:00
Leandro Pereira da9b0ddf5b drivers: Rename random to entropy
This should clear up some of the confusion with random number
generators and drivers that obtain entropy from the hardware.  Also,
many hardware number generators have limited bandwidth, so it's natural
for their output to be only used for seeding a random number generator.

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-11-01 08:26:29 -04:00
Leandro Pereira adce1d1888 subsys: Add random subsystem
Some "random" drivers are not drivers at all: they just implement the
function `sys_rand32_get()`.  Move those to a random subsystem in
preparation for a reorganization.

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-11-01 08:26:29 -04:00
Anas Nashif 780324b8ed cleanup: rename fiber/task -> thread
We still have many places talking about tasks and threads, replace those
with thread terminology.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-10-30 18:41:15 -04:00
Andrew Boie e5b3918a9f userspace: remove some driver object types
Use-cases for these  subsystems appear to be limited to board/SOC
code, network stacks, or other drivers, no need to expose to
userspace at this time. If we change our minds it's easy enough
to add them back.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-10-30 13:20:19 -07:00
Youvedeep Singh 9644f6782e kernel: boot_delay: change to busy wait instaed of wait
Intention of CONFIG_BOOT_DELAY is to delay booting of system for certain
time. Currently it is only delaying start of _main thread as delay is
created using k_sleep. This leads to putting _main thread into timeout
queue and continue kernel boot. This is causing some of undesirable
effects in some of test Automation usecase.
This patch changes k_sleep to k_busy_wait which result in delay in OS
boot instead of delaying start of _main.

Signed-off-by: Youvedeep Singh <youvedeep.singh@intel.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-10-28 14:20:25 -04:00
Ramakrishna Pallala 1777c57bec kernel: fix bit clearing logic in _k_thread_group_leave
Fix init_group bit clearing in _k_thread_group_leave()

Fix _k_object_uninit calling order. Though the order won't
make much difference in this case it is always good to destroy
or uninitialize in the reverse order of the object creation or
initialization.

Signed-off-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
2017-10-27 10:56:58 -07:00
Ramakrishna Pallala c44046acc1 kernel: Fix comment section of semaphore object
Fix description of semaphore object in comment section.

Signed-off-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
2017-10-27 10:56:58 -07:00
Ramakrishna Pallala 67426261ad kernel: Remove dead or commented code from k_mutex_lock()
Remove dead code from k_mutex_lock() function and
also fix typo in a comment block.

Signed-off-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
2017-10-24 11:11:00 -07:00
Andrew Boie 98bf5234dc Revert "kernel: arch interface for memory domain"
This reverts commit 9bbe7bd61e.
2017-10-20 15:02:59 -04:00
Andrew Boie fd2927609d Revert "kernel: Arch specific memory domain APIs added"
This reverts commit 8d910b36a3.
2017-10-20 15:02:59 -04:00
Adithya Baglody 8d910b36a3 kernel: Arch specific memory domain APIs added
Added arch specific calls to handle memory domain destroy
and removal of partition.

GH-3852

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2017-10-20 10:39:51 -07:00
Adithya Baglody 9bbe7bd61e kernel: arch interface for memory domain
Additional arch specific interfaces to handle memory domain
destroy and single partition removal.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2017-10-20 10:39:51 -07:00
Leandro Pereira d24daa426d kernel: Compare pointers before strings when getting device binding
Most calls to device_get_binding() will pass named constants generated
by Kconfig; these constants will all point to the same place, so
compare the pointer before attempting to match the whole string.

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-10-19 14:43:48 -07:00
Luiz Augusto von Dentz 48fadfe623 queue: k_queue_cancel_wait: Fix not interrupting other threads
When k_poll is being used k_queue_cancel_wait shall mark the state as
K_POLL_STATE_NOT_READY so other threads will get properly notified with
a NULL pointer return.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-10-18 13:02:52 -04:00
Luiz Augusto von Dentz fc775a095c poll: k_poll: Return -EINTR if not ready
In case _handle_obj_poll_events is called with K_POLL_STATE_NOT_READY
set -EINTR as return to the poller thread.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-10-18 13:02:52 -04:00
Luiz Augusto von Dentz f87c4c6743 queue: k_queue_get: Fix NULL return
k_queue_get shall never return NULL when timeout is K_FOREVER which can
happen when a higher priority thread cancel/take an item before the
waiting thread.

Fixes issue #4358

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-10-18 13:02:52 -04:00
Andrew Boie e12857aabf kernel: add k_thread_access_grant()
This is a runtime counterpart to K_THREAD_ACCESS_GRANT().
This function takes a thread and a NULL-terminated list of kernel
objects and runs k_object_access_grant() on each of them.
This function doesn't require any special permissions and doesn't
need to become a system call.

__attribute__((sentinel)) added to warn users if they omit the
required NULL termination.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-10-18 07:37:38 -07:00
Andrew Boie 877f82e847 userspace: add K_THREAD_ACCCESS_GRANT()
It's possible to declare static threads that start up as K_USER,
but these threads can't do much since they start with permissions on
no kernel objects other than their own thread object.

Rather than do some run-time synchronization to have some other thread
grant the necessary permissions, we introduce macros
to conveniently assign object permissions to these threads when they
are brought up at boot by the kernel. The tables generated here
are constant and live in ROM when possible.

Example usage:

K_THREAD_DEFINE(my_thread, STACK_SIZE, my_thread_entry,
                NULL, NULL, NULL, 0, K_USER, K_NO_WAIT);

K_THREAD_ACCESS_GRANT(my_thread, &my_sem, &my_mutex, &my_pipe);

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-10-18 07:37:38 -07:00