Skip to content

kernel: k_sleep bug in no multi-threading mode #81210

@KushnerovMikhail

Description

@KushnerovMikhail

Describe the bug
Bug in k_sleep implementation for no multi-threading mode.

Absolute value of timeout expiration was fed to the k_busy_wait() function instead of delta value. That caused bug like incrementing of sleep time in geometric progression (while actual function argument is constant) during program running.

Suggested solution
#80979

To Reproduce

  1. Replace hello_world sample source with simple code:
#include <zephyr/kernel.h>

int main (void)
{
	uint32_t new_ticks = 0;
	uint32_t old_ticks = sys_clock_tick_get_32();

	while (1) {
		k_sleep(K_MSEC(1000));
		new_ticks = sys_clock_tick_get_32();
		printf("%u\n", new_ticks - old_ticks);
		old_ticks = new_ticks;
	}

	return 0;
}
  1. write CONFIG_MULTITHREADING=n flag in prj.conf
  2. cd zephyr
  3. west build -b qemu-riscv64 samples/hello_world
  4. west build -t run
  5. See, that waiting time between console outputs increases, even though constant value is passed into k_sleep

Expected behavior
Expected, that k_sleep will wait actual amount of time, specified in function argument

Impact
Programs start to sleep a lot of time, when compile for no multi-threading mode

Logs and console output
Output from qemu_riscv64:

100
200
400
800
...

Environment (please complete the following information):

  • OS: Linux
  • Toolchain: zephyr-sdk-0.16.1
  • Commit SHA or Version used: c3466b1

Additional context
NA

Metadata

Metadata

Labels

area: KernelbugThe issue is a bug, or the PR is fixing a bugpriority: mediumMedium impact/importance bug

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions