Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kernel: idle: introduce idle enter hook #83760

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions include/zephyr/platform/hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,12 @@ void board_early_init_hook(void);
*/
void board_late_init_hook(void);

/**
* @brief Hook executed when idle is entered.
*
* This hook is implemented by the SoC and can be used to perform any
* SoC-specific idle enter logic.
*/
void idle_enter_hook(void);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's SoC specific, maybe clearer and more consistent is

Suggested change
void idle_enter_hook(void);
void soc_idle_enter_hook(void);


#endif
1 change: 1 addition & 0 deletions kernel/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1078,3 +1078,4 @@ endmenu
rsource "Kconfig.device"
rsource "Kconfig.vm"
rsource "Kconfig.init"
rsource "Kconfig.idle"
15 changes: 15 additions & 0 deletions kernel/Kconfig.idle
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (c) 2025 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0

menu "Kernel idle options"

config IDLE_ENTER_HOOK
bool "Execute idle enter hook"
help
Execute idle_exit_hook() when entering idle.

config IDLE_DEFAULT_ROUTINE
bool "Execute idle default routine"
default y
Comment on lines +11 to +13
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any options executed by the default routine should depend on this option, right? e.g. policy stuff


endmenu
7 changes: 7 additions & 0 deletions kernel/idle.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2016 Wind River Systems, Inc.
* Copyright (c) 2025 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -27,6 +28,11 @@ void idle(void *unused1, void *unused2, void *unused3)
__ASSERT_NO_MSG(arch_current_thread()->base.prio >= 0);

while (true) {
#ifdef CONFIG_IDLE_ENTER_HOOK
idle_enter_hook();
#endif /* CONFIG_IDLE_ENTER_HOOK */

#ifdef CONFIG_IDLE_DEFAULT_ROUTINE
/* SMP systems without a working IPI can't actual
* enter an idle state, because they can't be notified
* of scheduler changes (i.e. threads they should
Expand Down Expand Up @@ -90,6 +96,7 @@ void idle(void *unused1, void *unused2, void *unused3)
}
# endif /* !defined(CONFIG_USE_SWITCH) || defined(CONFIG_SPARC) */
#endif /* !defined(CONFIG_PREEMPT_ENABLED) */
#endif /* CONFIG_IDLE_DEFAULT_ROUTINE */
}
}

Expand Down
Loading