mirror of
https://github.com/zephyrproject-rtos/zephyr
synced 2025-08-25 12:15:23 +00:00
This flag is an indication to the timer driver that the OS doesn't care about rollover conditions of the tick count while idling, so the system doesn't need to wake up once per counter flip[1]. Obviously in that circumstance values returned from k_uptime_get_32() are going to be wrong, so the implementation had an assert to check for misuse. But no one understood that from the docs, so the only place these APIs were used in practice were as "guards" around code that needed to call k_uptime_get_32(), even though that's 100% wrong per docs! Clarify the docs. Remove the incorrect guards. Change the flag to initialize to true so that uptime isn't broken-by-default in tickless mode. Also move the implemenations of the functions out of the header, as there's no good reason for these to need to be inlined. [1] Which can be significant. A 100MHz ARM using the 24 bit SysTick counter rolls over at about 6 Hz, and if it had to come out of idle at that rate it would be a significant power issue that would swamp the gains from tickless. Obviously systems with slow counters like nRF or 64 bit ones like RISC-V or x86's TSC aren't as affected. Signed-off-by: Andy Ross <andrew.j.ross@intel.com> |
||
---|---|---|
.. | ||
src | ||
CMakeLists.txt | ||
prj_tickless.conf | ||
prj.conf | ||
README.rst | ||
sample.yaml |
.. _dining-philosophers-sample: Dining Philosophers ################### Overview ******** An implementation of a solution to the Dining Philosophers problem (a classic multi-thread synchronization problem). This particular implementation demonstrates the usage of multiple preemptible and cooperative threads of differing priorities, as well as dynamic mutexes and thread sleeping. The philosopher always tries to get the lowest fork first (f1 then f2). When done, he will give back the forks in the reverse order (f2 then f1). If he gets two forks, he is EATING. Otherwise, he is THINKING. Transitional states are shown as well, such as STARVING when the philosopher is hungry but the forks are not available, and HOLDING ONE FORK when a philosopher is waiting for the second fork to be available. Each Philosopher will randomly alternate between the EATING and THINKING state. It is possible to run the demo in coop-only or preempt-only mode. To achieve this, set these values for CONFIG_NUM_COOP_PRIORITIES and CONFIG_NUM_PREEMPT_PRIORITIES in prj.conf: preempt-only: CONFIG_NUM_PREEMPT_PRIORITIES 6 CONFIG_NUM_COOP_PRIORITIES 0 coop-only: CONFIG_NUM_PREEMPT_PRIORITIES 0 CONFIG_NUM_COOP_PRIORITIES 6 In these cases, the philosopher threads will run with priorities 0 to 5 (preempt-only) and -7 to -2 (coop-only). Building and Running ******************** This project outputs to the console. It can be built and executed on QEMU as follows: .. zephyr-app-commands:: :zephyr-app: samples/philosophers :host-os: unix :board: qemu_x86 :goals: run :compact: Sample Output ============= .. code-block:: console Philosopher 0 [P: 3] HOLDING ONE FORK Philosopher 1 [P: 2] HOLDING ONE FORK Philosopher 2 [P: 1] EATING [ 1900 ms ] Philosopher 3 [P: 0] THINKING [ 2500 ms ] Philosopher 4 [C:-1] THINKING [ 2200 ms ] Philosopher 5 [C:-2] THINKING [ 1700 ms ]