zephyr power management - elinux.org · kernel scheduling and idling ... system power management...

34
Zephyr™ Power Management Ramesh Thomas OTC, Intel Zephyr is a trademark of the Linux Foundation. *Other names and brands may be claimed as the property of others.

Upload: hoangthuy

Post on 08-May-2018

233 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Zephyr Power Management - eLinux.org · Kernel scheduling and idling ... System Power Management happens in Idle Thread ... CPU Low Power State CPU clock gated Peripherals active

Zephyr™ Power Management

Ramesh Thomas

OTC, Intel

Zephyr is a trademark of the Linux Foundation. *Other names and brands may be claimed as the property of others.

Page 2: Zephyr Power Management - eLinux.org · Kernel scheduling and idling ... System Power Management happens in Idle Thread ... CPU Low Power State CPU clock gated Peripherals active

Agenda

Why Power Management?

The core concepts behind Zephyr RTOS PM

Power Management Infrastructures

Future direction

Page 3: Zephyr Power Management - eLinux.org · Kernel scheduling and idling ... System Power Management happens in Idle Thread ... CPU Low Power State CPU clock gated Peripherals active

Think Possible…

Page 4: Zephyr Power Management - eLinux.org · Kernel scheduling and idling ... System Power Management happens in Idle Thread ... CPU Low Power State CPU clock gated Peripherals active

Zephyr RTOS PM – Core Concepts

Multi architecture/board/SOC

Designed for IoT/embedded

Customizable for different needs

Flexibility and variety of options

Scalable design

Follow open source process

Page 5: Zephyr Power Management - eLinux.org · Kernel scheduling and idling ... System Power Management happens in Idle Thread ... CPU Low Power State CPU clock gated Peripherals active

Zephyr RTOS components (partial)

Application

API

Device Management Power Management

Device Drivers Kernel

HAL

Peripherals

UART SPI I2C TimersBoot

ROM…

Page 6: Zephyr Power Management - eLinux.org · Kernel scheduling and idling ... System Power Management happens in Idle Thread ... CPU Low Power State CPU clock gated Peripherals active

PM high level layout

SOC Interface

Boot ROM

HAL

SOC PM

Interface

Application

Thread

1

Thread

2Thread

3

Kernel

PM

Subsystem

Device

Management

SHIM

Device Drivers

Page 7: Zephyr Power Management - eLinux.org · Kernel scheduling and idling ... System Power Management happens in Idle Thread ... CPU Low Power State CPU clock gated Peripherals active

Zephyr RTOS PM Deep Dive

Page 8: Zephyr Power Management - eLinux.org · Kernel scheduling and idling ... System Power Management happens in Idle Thread ... CPU Low Power State CPU clock gated Peripherals active

Zephyr RTOS PM features

Event based kernel idling

System power management

Device power management

Page 9: Zephyr Power Management - eLinux.org · Kernel scheduling and idling ... System Power Management happens in Idle Thread ... CPU Low Power State CPU clock gated Peripherals active

First a quick intro to the scheduler…

Page 10: Zephyr Power Management - eLinux.org · Kernel scheduling and idling ... System Power Management happens in Idle Thread ... CPU Low Power State CPU clock gated Peripherals active

Kernel scheduling and idling

Priority based scheduling

Threads wait on semaphore or

yield

Idle Thread scheduled when

no other thread can run

Idle Thread is lowest priority

thread

System Power Management

happens in Idle Thread

Thread 1 Thread 2 Thread 3

Thread 4 Thread 5 Thread 6

Thread 7 Thread 8 Thread 9

Idle Thread

Equal Priority

High

Priority

Low

Priority

Page 11: Zephyr Power Management - eLinux.org · Kernel scheduling and idling ... System Power Management happens in Idle Thread ... CPU Low Power State CPU clock gated Peripherals active

Inside the Idle Thread

CPU Wait

for event

Kernel scheduler gets invoked from ISR of

timer or other event

If no thread is ready to run, schedules Idle

Thread again

Periodic mode timer ticks

Page 12: Zephyr Power Management - eLinux.org · Kernel scheduling and idling ... System Power Management happens in Idle Thread ... CPU Low Power State CPU clock gated Peripherals active

Event Based Idling

CPU Wait

for event Power saved by avoiding unnecessary

wake events

ISR turns periodic mode timer on again

Turn off

periodic mode

timer

Set one shot

timerNo ticks until a thread is ready to run

2 secs 5 secs 10 secs 15 secs

Ordered list of thread wait/timeout periods

Page 13: Zephyr Power Management - eLinux.org · Kernel scheduling and idling ... System Power Management happens in Idle Thread ... CPU Low Power State CPU clock gated Peripherals active

System Power Management

Page 14: Zephyr Power Management - eLinux.org · Kernel scheduling and idling ... System Power Management happens in Idle Thread ... CPU Low Power State CPU clock gated Peripherals active

Hooks into the Kernel Idle Thread

_sys_soc_suspend(idle time)

Going to idle

_sys_soc_resume()

Notify low power state exit or wake event

SOC implementation dependent

Simple and intuitive

When idle - save power

When active - real-time performance

Page 15: Zephyr Power Management - eLinux.org · Kernel scheduling and idling ... System Power Management happens in Idle Thread ... CPU Low Power State CPU clock gated Peripherals active

Triggered from Idle Thread

CPU Wait

for event

Turn off

periodic

mode timer

Call hook function

_sys_soc_suspend(idle time)

Handled?

Yes

No

_sys_soc_suspend() sets wake event

Wake -> ISR -> Periodic Mode On -> Scheduler

Set one

shot timer

Page 16: Zephyr Power Management - eLinux.org · Kernel scheduling and idling ... System Power Management happens in Idle Thread ... CPU Low Power State CPU clock gated Peripherals active

Inside _sys_soc_suspend

Page 17: Zephyr Power Management - eLinux.org · Kernel scheduling and idling ... System Power Management happens in Idle Thread ... CPU Low Power State CPU clock gated Peripherals active

Quick look into HW PM features…

Page 18: Zephyr Power Management - eLinux.org · Kernel scheduling and idling ... System Power Management happens in Idle Thread ... CPU Low Power State CPU clock gated Peripherals active

Categories based on HW PM features

CPU Low Power State

CPU clock gated

Peripherals active

SOC Deep Sleep

CPU power gated

Selective RAM retention

Most peripherals lose power

Different power savings

Different wake latencies

Different resume paths

CPU SRAM

Internal

Clocks

Peripherals

SPI I2C Timers …

Page 19: Zephyr Power Management - eLinux.org · Kernel scheduling and idling ... System Power Management happens in Idle Thread ... CPU Low Power State CPU clock gated Peripherals active

_sys_soc_suspend(<idle time>)

Setup wake event

If short idle time

Any PM operation that takes less time

Enter a CPU low power state

If long idle time

Save states of devices that will lose power

Any PM operation that saves more power

Enter SOC Deep Sleep

Page 20: Zephyr Power Management - eLinux.org · Kernel scheduling and idling ... System Power Management happens in Idle Thread ... CPU Low Power State CPU clock gated Peripherals active

_sys_soc_resume()

Deep Sleep wake notification

Depends on SOC specific implementation

Wake event notification

Optionally called from ISR of wake events

Before Kernel schedules other tasks or process nested

interrupts

Call _sys_soc_disable_wake_event_notification() if not

required

Page 21: Zephyr Power Management - eLinux.org · Kernel scheduling and idling ... System Power Management happens in Idle Thread ... CPU Low Power State CPU clock gated Peripherals active

Device Power Management

Page 22: Zephyr Power Management - eLinux.org · Kernel scheduling and idling ... System Power Management happens in Idle Thread ... CPU Low Power State CPU clock gated Peripherals active

Device Power States

Classified based on device state retention

DEVICE_PM_ACTIVE_STATE

DEVICE_PM_LOW_POWER_STATE

DEVICE_PM_SUSPEND_STATE

DEVICE_PM_OFF_STATE

Page 23: Zephyr Power Management - eLinux.org · Kernel scheduling and idling ... System Power Management happens in Idle Thread ... CPU Low Power State CPU clock gated Peripherals active

Device Power Management Overview

Integrated with Device Management

Drivers maintain per device power states

Device APIs to set and get state

Application, Driver or SOC interface can set

states

Multiple design options to manage device PM

Central – Only in _sys_soc_suspend()

Distributed – By Applications, Drivers, SOC Interface.

Page 24: Zephyr Power Management - eLinux.org · Kernel scheduling and idling ... System Power Management happens in Idle Thread ... CPU Low Power State CPU clock gated Peripherals active

Device PM APIs

device_list_get(struct device **device_list, int *device_count)

device_get_power_state(struct device *device,

uint32_t *device_power_state)

device_set_power_state(struct device *device,

uint32_t device_power_state)

device_busy_set(), device_busy_clear(),

device_any_busy_check(), device_busy_check()

Page 25: Zephyr Power Management - eLinux.org · Kernel scheduling and idling ... System Power Management happens in Idle Thread ... CPU Low Power State CPU clock gated Peripherals active

Device Driver PM Interface

PM Control Function

Control codesDEVICE_PM_SET_POWER_STATE

DEVICE_PM_GET_POWER_STATE

Part of Device Interface

Access only through Device

APIs

int (*device_pm_control)(

struct device *device,

uint32_t command, void *context);

static int example_control_fn(…)

{

switch (ctrl_command) {

case DEVICE_PM_SET_POWER_STATE:

set state code

case DEVICE_PM_GET_POWER_STATE:

get state code

}

return 0;

}

Page 26: Zephyr Power Management - eLinux.org · Kernel scheduling and idling ... System Power Management happens in Idle Thread ... CPU Low Power State CPU clock gated Peripherals active

Power Management Examples

Page 27: Zephyr Power Management - eLinux.org · Kernel scheduling and idling ... System Power Management happens in Idle Thread ... CPU Low Power State CPU clock gated Peripherals active

PM Example 1 (Distributed Device PM)

App UART SPI SOC

InterfaceHWIdle

Threadset_state

SUSPEND

set_state

SUSPEND

_sys_soc_suspend

_sys_soc_suspend

SOC Deep Sleep

Yield

Yield

Page 28: Zephyr Power Management - eLinux.org · Kernel scheduling and idling ... System Power Management happens in Idle Thread ... CPU Low Power State CPU clock gated Peripherals active

PM Example 2 (Central Device PM)

App UART SPI SOC

InterfaceHWIdle

Thread

set_state

SUSPEND

set_state

SUSPEND

_sys_soc_suspend

SOC Deep Sleep

Resumeset_state

ACTIVE

set_state

ACTIVE

Yield

Page 29: Zephyr Power Management - eLinux.org · Kernel scheduling and idling ... System Power Management happens in Idle Thread ... CPU Low Power State CPU clock gated Peripherals active

PM Example 3 (Flash on SPI)

App Flash SPI

set_state

SUSPEND

set_state

SUSPEND

set_state

ACTIVE set_state

ACTIVE

Page 30: Zephyr Power Management - eLinux.org · Kernel scheduling and idling ... System Power Management happens in Idle Thread ... CPU Low Power State CPU clock gated Peripherals active

Adding PM Support

Configure Board, SOC, CPU, Arch

(If not done already…)

Enable/Disable PM feature configs

_sys_soc_suspend / _sys_soc_resume

PM support in device drivers

PM support in application

Page 31: Zephyr Power Management - eLinux.org · Kernel scheduling and idling ... System Power Management happens in Idle Thread ... CPU Low Power State CPU clock gated Peripherals active

Summary

Page 32: Zephyr Power Management - eLinux.org · Kernel scheduling and idling ... System Power Management happens in Idle Thread ... CPU Low Power State CPU clock gated Peripherals active

Future direction

New PM features derived from kernel

updates

Tick-less kernel

Different time unit options

Add ARC* and ARM* examples

Distributed Device PM examples

*Other names and brands may be claimed as the property of others.

Page 33: Zephyr Power Management - eLinux.org · Kernel scheduling and idling ... System Power Management happens in Idle Thread ... CPU Low Power State CPU clock gated Peripherals active

Summary

Multi Arch, CPU, SOC, Board support

Simple and Intuitive hook interface

Versatile Device PM options

Configurable, Scalable, Portable

Open Source

Page 34: Zephyr Power Management - eLinux.org · Kernel scheduling and idling ... System Power Management happens in Idle Thread ... CPU Low Power State CPU clock gated Peripherals active

Questions