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
os/pm, os/driver/pm: Add pm_timer module #6129
Conversation
ritesh55555
commented
Apr 3, 2024
•
edited
edited
- This commit adds pm_timer module in os/pm to use multiple timers for PM operation and PM driver also.
- It defines a structure for multiple wakeup timers. All the timers are stored in a list and just before system sleeps, the timer with nearest future expiration time is started.
os/board/rtl8730e/src/component/bluetooth/example/ble_scatternet/scatternet.c
Outdated
Show resolved
Hide resolved
Hi @ritesh55555 , |
the new modification still uses g_pm_timer, pm_set_timer() and pm_init_handler() as before . The PM LOCK TIMER is same as before. the moment app will request pm_lock with timer, it will set pm_set_timer(PM_LOCK_TIMER, timer_interval) and do the up_set_pm_timer() and start the timer as before. So /dev/pm uses the os/pm apis , and the final setup for timer is same as before. During up_set_pm_timer in amebasmart_pmhelpers.c . i hope this explains! |
49f5138
to
20f6028
Compare
os/board/rtl8730e/src/component/bluetooth/example/ble_scatternet/scatternet.c
Outdated
Show resolved
Hide resolved
20f6028
to
8bf9929
Compare
@edwakuwaku Hi currently for pm_lock with timer , we dont have a way to stop the timer . Suppose we want to stop it inbetween by calling pm_unlock. It will only pm_relax() but it will not stop the timer that was started by pm_lock timer. Then during expiration, it will call pm_relax() again and it will crash. |
Can you try
|
Let me confirm with my understanding, for the stop it in between before pm_unlock, I assume that you do not need this timer to trigger wakeup or handle some other operation. Thus you would like to stop it, so that it will not trigger callback to do pm_relax at the same state more than once, is that correct? |
yes , i just want to stop it . No callback needed. |
54c997e
to
97f64b1
Compare
os/drivers/pm/pm.c
Outdated
* Data | ||
****************************************************************************/ | ||
static const struct file_operations pm_fops = { | ||
0, /* open */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how it works without open? lock, reference count and something else are unnecessary?
d3f8c52
to
29ad25f
Compare
9cd8cde
to
7a9907c
Compare
os/include/tinyara/pm/pm.h
Outdated
int pid; /* id of process that created pm timer */ | ||
uint8_t flags; /* See pm timer definations above*/ | ||
int delay; /* refers to time of sleep expected */ | ||
void (*callback)(struct pm_wakeup_timer_s *timer); /* function to be executed when timer expires */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is some strange..
please check this
os/pm/Kconfig
Outdated
@@ -45,6 +45,15 @@ config PM_METRICS_DURATION | |||
|
|||
endif | |||
|
|||
config PM_MAX_WAKEUP_TIMER |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about PM_MAX_STATIC_TIMER ?
And this pr is having both pm_wakeup_timer and pm_timer.
How about unifying the terms into one?
c0eb0c5
to
c4e911e
Compare
a89212e
to
433556c
Compare
1. this commit adds a semaphore variable to the timer structure. This will allow the system to lock the thread before and after pm sleep. Here the "thread" refers to the thread that called pm_sleep api through pm driver. 2. This commit adds a callback api to the timer structure. Whenever a pm timer expires, this api will be called.
ceaf664
to
31b6d56
Compare
@@ -561,12 +561,11 @@ int tash_execute_cmd(char **args, int argc) | |||
if (tash_cmds_info.cmd[cmd_idx].exec_type == TASH_EXECMD_SYNC) { | |||
/* function call to execute SYNC command */ | |||
#ifdef CONFIG_PM | |||
pm_arg_t pm_arg = {PM_IDLE_DOMAIN, PM_NORMAL}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please seperate commit
os/drivers/pm/pm.c
Outdated
case PMIOC_SLEEP: | ||
if (arg > 0) { | ||
/* Converting from milliseconds to ticks */ | ||
arg = ((arg * CLOCKS_PER_SEC) / 1000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we not need to provide an API in milliseconds for kernel functions that use pm_sleep rather than driver?
I think it is better to do this in the pm_sleep() function. And if necessary, please change the name to pm_msleep().
os/include/tinyara/pm/pm.h
Outdated
uint8_t timer_type; /* Bits here are set according to the timer that is to be used */ | ||
uint32_t timer_interval; /* The interval for whichever timer is to be used */ | ||
clock_t last_wifi_alive_send_time; /* Time tick of the last wifi keep alive signal sent time */ | ||
struct pm_wakeup_timer_s { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use pm_timer in all APIs, But only in this structure data type, we call it pm_wakeup_timer.
Please change it to pm_timer as well.
Comment that our pm_timer means waking up the main core on time.
os/pm/pm_timer/pm_timer_activity.c
Outdated
if (curr->delay > CONFIG_PM_MIN_SLEEP_TIME) { | ||
pmvdbg("Setting timer and Board will wake up after %d millisecond\n", curr->delay); | ||
/* Converting ticks to nanoseconds */ | ||
up_set_pm_timer((curr->delay * 1000000) / CLOCKS_PER_SEC); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use TICK2NSEC(curr->delay)
os/pm/pm_timedStay.c
Outdated
/* PM transition will be relaxed here */ | ||
if (pid_timerMap[pid] != NULL) { | ||
pm_relax(PM_IDLE_DOMAIN, (enum pm_state_e)state); | ||
wd_delete(pid_timerMap[pid]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change PIDHASH(pid)
os/pm/pm_timedStay.c
Outdated
|
||
/* Check if there is already a wdog lock timer running for | ||
* the process */ | ||
if (pid_timerMap[pid] != NULL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is already a timer, it is recommended that we do not clear the timer and start again after wd_cancel.
And if timer_interval is entered as 0, please call wd_cancel and wd_delete only(not start).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would be failed when a new thread with the same pid hash comes in.
9e43040
to
44244c1
Compare
* | ||
************************************************************************/ | ||
|
||
int pm_msleep(int timer_interval) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please change file name to pm_msleep()
os/pm/pm_timedStay.c
Outdated
/* This array maps the pid to their respective wdog timer. | ||
* Assumption: when a thread does a timed lock , only the same thread | ||
* can unlock the "timed lock" before it expire */ | ||
static WDOG_ID pid_timerMap[CONFIG_MAX_TASKS]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check coding rule.
g_pid_timer_map[]
- This commit adds pm_timedstay api that can perform pm state suspend for a given time duration.It also updates pm driver code.
- this commit updates the pm suspend and pm resume code for SYNC cmd because of the new changes in the pm driver.
3048e30
to
99f1e09
Compare