Commit graph

22 commits

Author SHA1 Message Date
Vilem Gottwald 1c7eb9ee72 samples: synchronization: add static thread
Replace one of the dynamic threads with a static thread to show the
all the possible ways of creating threads.

Signed-off-by: Vilem Gottwald <xvigo.dev@gmail.com>
2023-11-16 09:25:33 +01:00
Vilem Gottwald 5a4e0af54a samples: synchronization: fix comments & structure
This commit has no functional changes. It makes the comments up to date
with the code and changes the code structure to ensure consistency.

These inconsistencies were introduced when the static thread definition
was replaced with dynamic, but the comments remained unchanged.

 - Fixed outdated comments about the static approach that were
   not corresponding to the code.
 - Rearrange thread definitions, to obtain similar code structure
   for both threads.

Signed-off-by: Vilem Gottwald <xvigo.dev@gmail.com>
2023-11-16 09:25:33 +01:00
Keith Packard 0b90fd5adf samples, tests, boards: Switch main return type from void to int
As both C and C++ standards require applications running under an OS to
return 'int', adapt that for Zephyr to align with those standard. This also
eliminates errors when building with clang when not using -ffreestanding,
and reduces the need for compiler flags to silence warnings for both clang
and gcc.

Most of these changes were automated using coccinelle with the following
script:

@@
@@
- void
+ int
main(...) {
	...
-	return;
+	return 0;
	...
}

Approximately 40 files had to be edited by hand as coccinelle was unable to
fix them.

Signed-off-by: Keith Packard <keithp@keithp.com>
2023-04-14 07:49:41 +09:00
Kumar Gala 7fff3de993 samples: synchronization: Convert CONFIG_MP_NUM_CPUS handling
Move runtime checks to use arch_num_cpus() and build checks
to use CONFIG_MP_MAX_NUM_CPUS.  This is to allow runtime
determination of the number of CPUs in the future.

Signed-off-by: Kumar Gala <kumar.gala@intel.com>
2022-10-27 13:59:57 -04:00
Gerard Marull-Paretas 79e6b0e0f6 includes: prefer <zephyr/kernel.h> over <zephyr/zephyr.h>
As of today <zephyr/zephyr.h> is 100% equivalent to <zephyr/kernel.h>.
This patch proposes to then include <zephyr/kernel.h> instead of
<zephyr/zephyr.h> since it is more clear that you are including the
Kernel APIs and (probably) nothing else. <zephyr/zephyr.h> sounds like a
catch-all header that may be confusing. Most applications need to
include a bunch of other things to compile, e.g. driver headers or
subsystem headers like BT, logging, etc.

The idea of a catch-all header in Zephyr is probably not feasible
anyway. Reason is that Zephyr is not a library, like it could be for
example `libpython`. Zephyr provides many utilities nowadays: a kernel,
drivers, subsystems, etc and things will likely grow. A catch-all header
would be massive, difficult to keep up-to-date. It is also likely that
an application will only build a small subset. Note that subsystem-level
headers may use a catch-all approach to make things easier, though.

NOTE: This patch is **NOT** removing the header, just removing its usage
in-tree. I'd advocate for its deprecation (add a #warning on it), but I
understand many people will have concerns.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-09-05 16:31:47 +02:00
Gerard Marull-Paretas c7b5b3c419 samples: migrate includes to contain <zephyr/...> prefix
In order to bring consistency in-tree, migrate all samples to the use
the new prefix <zephyr/...>. Note that the conversion has been scripted:

```python
from pathlib import Path
import re

EXTENSIONS = ("c", "h", "cpp", "rst")

for p in Path(".").glob("samples/**/*"):
    if not p.is_file() or p.suffix and p.suffix[1:] not in EXTENSIONS:
        continue

    content = ""
    with open(p) as f:
        for line in f:
            m = re.match(r"^(.*)#include <(.*)>(.*)$", line)
            if (m and
                not m.group(2).startswith("zephyr/") and
                (Path(".") / "include" / "zephyr" / m.group(2)).exists()):
                content += (
                    m.group(1) +
                    "#include <zephyr/" + m.group(2) +">" +
                    m.group(3) + "\n"
                )
            else:
                content += line

    with open(p, "w") as f:
        f.write(content)
```

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-05-06 11:29:59 +02:00
Anas Nashif e2a3e72a02 samples: synchronization: use k_thread_cpu_pin
Use shortcut API to pin thread to a CPU.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-04-19 13:05:09 -04:00
Andy Ross 686b9fff5e samples/synchronization: Clean up SMP CPU pinning example
There was some code to demonstrate the cpu_mask API here, but it was
asymmetric (only thread B was pinned) and assumed exactly two CPUs.

Start both threads pinned to CPUs 0 and 1 from an external main, and
predicate the pinning on there actually being more than one SMP CPU.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2021-02-18 12:04:49 -05:00
Anas Nashif 802d214582 debug: analyzer: add support for thread runtime stats
Add thread runtime statistics to the thread analyser.

With CONFIG_THREAD_RUNTIME_STATS enabled:

Booting from ROM..*** Booting Zephyr OS build zephyr-v2.4.0-2330-g77be0e93e65b  ***
thread_a: Hello World from cpu 0 on qemu_x86!
Thread analyze:
 thread_b            : STACK: unused 740 usage 284 / 1024 (27 %); CPU: 0 %
 thread_analyzer     : STACK: unused 8 usage 504 / 512 (98 %); CPU: 0 %
 thread_a            : STACK: unused 648 usage 376 / 1024 (36 %); CPU: 98 %
 idle 00             : STACK: unused 204 usage 116 / 320 (36 %); CPU: 0 %
thread_b: Hello World from cpu 0 on qemu_x86!
thread_a: Hello World from cpu 0 on qemu_x86!
thread_b: Hello World from cpu 0 on qemu_x86!
thread_a: Hello World from cpu 0 on qemu_x86!
thread_b: Hello World from cpu 0 on qemu_x86!
thread_a: Hello World from cpu 0 on qemu_x86!
thread_b: Hello World from cpu 0 on qemu_x86!
thread_a: Hello World from cpu 0 on qemu_x86!
Thread analyze:
 thread_b            : STACK: unused 648 usage 376 / 1024 (36 %); CPU: 7 %
 thread_analyzer     : STACK: unused 8 usage 504 / 512 (98 %); CPU: 0 %
 thread_a            : STACK: unused 648 usage 376 / 1024 (36 %); CPU: 9 %
 idle 00             : STACK: unused 204 usage 116 / 320 (36 %); CPU: 82 %
thread_b: Hello World from cpu 0 on qemu_x86!

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-12-14 13:00:47 -05:00
Anas Nashif ad8caa65e8 samples: synchronisation: run thread_b on cpu 0 in SMP mode
Always run thread_b on CPU 0 by setting cpu_mask if on SMP system.

Run this with CONFIG_SCHED_CPU_MASK=y set on an SMP system.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-10-19 10:57:15 -04:00
Anas Nashif c916411239 samples: synchronization: show cpu
Show which CPU were are running on systems with SMP enabled.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-10-19 10:57:15 -04:00
Anas Nashif 2718a23781 samples: synchronisation: handle empty thread name
In some cases we were returning empty thread names, so make sure we
check for the thread names correctly.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-09-20 21:27:55 -04:00
Andy Ross 32bb2395c2 timeout: Fix up API usage
Kernel timeouts have always been a 32 bit integer despite the
existence of generation macros, and existing code has been
inconsistent about using them.  Upcoming commits are going to make the
timeout arguments opaque, so fix things up to be rigorously correct.
Changes include:

+ Adding a K_TIMEOUT_EQ() macro for code that needs to compare timeout
  values for equality (e.g. with K_FOREVER or K_NO_WAIT).

+ Adding a k_msleep() synonym for k_sleep() which can continue to take
  integral arguments as k_sleep() moves away to timeout arguments.

+ Pervasively using the K_MSEC(), K_SECONDS(), et. al. macros to
  generate timeout arguments.

+ Removing the usage of K_NO_WAIT as the final argument to
  K_THREAD_DEFINE().  This is just a count of milliseconds and we need
  to use a zero.

This patch include no logic changes and should not affect generated
code at all.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-03-31 19:40:47 -04:00
Anas Nashif 9ab2a56751 cleanup: include/: move misc/printk.h to sys/printk.h
move misc/printk.h to sys/printk.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 2f30c5dcb8 samples: synchronisation: set thread names
- Use new k_thread_name_set to set thread names.
- Use board name in sample instead of architecture.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-09-27 08:58:55 +05:30
Sebastian Bøe 0829ddfe9a kbuild: Removed KBuild
Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-08 20:00:22 -05:00
Andrew Boie e87eacacfa samples: use K_THREAD_STACK_DEFINE macros
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-06-09 18:53:28 -04:00
Andrew Boie 39962dc92c samples: use k_thread_create()
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-05-11 20:24:22 -04:00
David B. Kinder ac74d8b652 license: Replace Apache boilerplate with SPDX tag
Replace the existing Apache 2.0 boilerplate header with an SPDX tag
throughout the zephyr code tree. This patch was generated via a
script run over the master branch.

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

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

Jira: ZEP-1457

Change-Id: I6131a1d4ee0e58f5b938300c2d2fc77d2e69572c
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-01-19 03:50:58 +00:00
Flavio Santes d47abac73d samples: Add the ARG_UNUSED macro
Avoid compiler warnings by incorporating the ARG_UNUSED macro.

Change-Id: Iea567bf5f42d9f609bf68d171e0bc0e03b62b821
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2016-12-21 12:54:53 +00:00
Anas Nashif 55fa31196e samples: remove legacy usage and convert to unified APIs
Change-Id: Idf281b0bbb7c8f6f1eff74e275d5ebb4e427cd2f
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-11-30 21:45:21 +00:00
Anas Nashif 886677c3de samples: synchronization: move to legacy/
Change-Id: I72d6fcba0c747e27c0e9cb9fade7abcf8bd077bc
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-11-02 22:05:29 +00:00