PM / suspend: measure the time of filesystem syncing
Subsystems (2)
PATCH 1/1 PM / suspend: measure the time of filesystem syncing
This patch gives the reader an intuitive metric of the time cost by the kernel issuing a filesystem sync during suspend; although developer can guess by the timestamp of next log or enable the ftrace power event for manual calculation, this manner is easier to read and benefits the automatic script.
--- kernel/power/suspend.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
kernel/power/suspend.c +8 -1
@@ -550,6 +550,8 @@ static void suspend_finish(void)static int enter_state (suspend_state_t state) {int error; +ktime_t start, end, elapsed; +unsigned int elapsed_msecs;trace_suspend_resume (TPS ("suspend_enter" ), state, true);if (state ==PM_SUSPEND_TO_IDLE ) {
@@ -570,9 +572,14 @@ static int enter_state(suspend_state_t state)#ifndef CONFIG_SUSPEND_SKIP_SYNC trace_suspend_resume (TPS ("sync_filesystems" ),0 , true); + start =ktime_get_boottime ();pr_info ("Syncing filesystems ... " );ksys_sync (); -pr_cont ("done.\n" ); + end =ktime_get_boottime (); + elapsed =ktime_sub (end, start); + elapsed_msecs =ktime_to_ms (elapsed); +pr_cont ("(elapsed %d.%03d seconds) done.\n" , elapsed_msecs /1000 , + elapsed_msecs %1000 );trace_suspend_resume (TPS ("sync_filesystems" ),0 , false);#endif
Signature · 1 line
2.18.1
Quoted 16 lines · CET Harry Pan
This patch gives the reader an intuitive metric of the time cost by the kernel issuing a filesystem sync during suspend; although developer can guess by the timestamp of next log or enable the ftrace power event for manual calculation, this manner is easier to read and benefits the automatic script.
Signed-off-by Harry Pan <[email protected]>--- kernel/power/suspend.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)kernel/power/suspend.c +0
-0
kernel/power/suspend.c static void suspend_finish(void) · line 553
Quoted 4 lines
kernel/power/suspend.c +1
-0@@ -550,6 +550,8 @@ static void suspend_finish(void)static int enter_state (suspend_state_t state) {int error; +ktime_t start, end, elapsed;
Why do you need three vars here? One should be sufficient.
kernel/power/suspend.c static int enter_state(suspend_state_t state) · line 575
Quoted 9 lines
kernel/power/suspend.c +2
-0+unsigned int elapsed_msecs;trace_suspend_resume (TPS ("suspend_enter" ), state, true);if (state ==PM_SUSPEND_TO_IDLE ) {@@ -570,9 +572,14 @@ static int enter_state(suspend_state_t state)#ifndef CONFIG_SUSPEND_SKIP_SYNC trace_suspend_resume (TPS ("sync_filesystems" ),0 , true); + start =ktime_get_boottime ();
Why _boottime()?
Quoted 12 lines
kernel/power/suspend.c +5
-1pr_info ("Syncing filesystems ... " );ksys_sync (); -pr_cont ("done.\n" ); + end =ktime_get_boottime (); + elapsed =ktime_sub (end, start); + elapsed_msecs =ktime_to_ms (elapsed); +pr_cont ("(elapsed %d.%03d seconds) done.\n" , elapsed_msecs /1000 , + elapsed_msecs %1000 );trace_suspend_resume (TPS ("sync_filesystems" ),0 , false);#endif
Quoted 4 lines · Rafael J. Wysocki
kernel/power/suspend.c static void suspend_finish(void) · line 553
Quoted 2 lines
kernel/power/suspend.c +1
-0+ktime_t start, end, elapsed;Why do you need three vars here? One should be sufficient.
...
Quoted 4 lines
kernel/power/suspend.c static int enter_state(suspend_state_t state) · line 575
Quoted 1 line
kernel/power/suspend.c +1
-0+ start =ktime_get_boottime ();Why
_boottime()?
Yes, I agree both comments.
BTW, The initial idea came from processes freezing, apology my sketchy imitation not considering the context well to choose a proper API.
-Harry
Quoted 5 lines · Harry Pan
This patch gives the reader an intuitive metric of the time cost by the kernel issuing a filesystem sync during suspend; although developer can guess by the timestamp of next log or enable the ftrace power event for manual calculation, this manner is easier to read and benefits the automatic script.
Do we really need this functionality?
As you explained, developers can already use next timestamp or ftrace... and this is really not that interesting number.
Pavel
Quoted 34 lines
Signed-off-by Harry Pan <[email protected]>--- kernel/power/suspend.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)kernel/power/suspend.c +8
-1@@ -550,6 +550,8 @@ static void suspend_finish(void)static int enter_state (suspend_state_t state) {int error; +ktime_t start, end, elapsed; +unsigned int elapsed_msecs;trace_suspend_resume (TPS ("suspend_enter" ), state, true);if (state ==PM_SUSPEND_TO_IDLE ) {@@ -570,9 +572,14 @@ static int enter_state(suspend_state_t state)#ifndef CONFIG_SUSPEND_SKIP_SYNC trace_suspend_resume (TPS ("sync_filesystems" ),0 , true); + start =ktime_get_boottime ();pr_info ("Syncing filesystems ... " );ksys_sync (); -pr_cont ("done.\n" ); + end =ktime_get_boottime (); + elapsed =ktime_sub (end, start); + elapsed_msecs =ktime_to_ms (elapsed); +pr_cont ("(elapsed %d.%03d seconds) done.\n" , elapsed_msecs /1000 , + elapsed_msecs %1000 );trace_suspend_resume (TPS ("sync_filesystems" ),0 , false);#endif
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 10 lines · Pavel Machek
Quoted 8 lines · Harry Pan
This patch gives the reader an intuitive metric of the time cost by the kernel issuing a filesystem sync during suspend; although developer
can guess by the timestamp of next log or enable the ftrace power event
for manual calculation, this manner is easier to read and benefits the
automatic script.
Quoted 4 lines
Do we really need this functionality?
As you explained, developers can already use next timestamp or ftrace... and this is really not that interesting number.
The backdrop is some stress test script of suspend/resume, like Chrome OS, is designed to program an expected RTC wake-alarm then issue suspend command, while in rare case (or buggy software), the filesystem sync could cost longer time in seconds, this consumes the alarm budget causes suspend aborting, it could be abstruse to production line developers to realize it is not a platform issue in terms of drivers suspending; given a such metric might make the communication easier, this is my intuition.
-Harry
Quoted 12 lines
The backdrop is some stress test script of suspend/resume, like Chrome
OS, is designed to program an expected RTC wake-alarm then issue suspend command, while in rare case (or buggy software), the filesystem
sync could cost longer time in seconds, this consumes the alarm budget
causes suspend aborting, it could be abstruse to production line developers to realize it is not a platform issue in terms of drivers suspending; given a such metric might make the communication easier, this is my intuition.
apologize rephrase: my intuition -> my motivation
Quoted 16 lines · Harry
Quoted 10 lines · Pavel Machek
Quoted 8 lines · Harry Pan
This patch gives the reader an intuitive metric of the time cost by the kernel issuing a filesystem sync during suspend; although developer
can guess by the timestamp of next log or enable the ftrace power event
for manual calculation, this manner is easier to read and benefits the
automatic script.Quoted 4 lines
Do we really need this functionality?
As you explained, developers can already use next timestamp or ftrace... and this is really not that interesting number.
Quoted 8 lines
The backdrop is some stress test script of suspend/resume, like Chrome OS, is designed to program an expected RTC wake-alarm then issue suspend command, while in rare case (or buggy software), the filesystem sync could cost longer time in seconds, this consumes the alarm budget causes suspend aborting, it could be abstruse to production line developers to realize it is not a platform issue in terms of drivers suspending; given a such metric might make the communication easier, this is my intuition.
I'd rather educate other developers that this may happen. dmesg timestamps should already make it easy to see.
And actually... if you do "time sync" in userspace just before programing the RTC and suspending, this whole issue should go away.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 8 lines
I'd rather educate other developers that this may happen. dmesg timestamps should already make it easy to see.
And actually... if you do "time sync" in userspace just before programing the RTC and suspending, this whole issue should go away.
I agree w/ you on both comments basically.
Thad said, when it comes to dmesg, readers would guess by current implementation of the program, the two lines of pr_info and pm_pr_dbg are controlled by compilation flags as well as printk run-level, I think the information is enough while it is not guaranteed for this subject.
Another reason is, months ago I worked on my community to illustrate this odd, adding 'sync' policy in the userspace script [1] mitigated the longer sync (issued by kernel) in suspending, however I realized there is still rare case because the userspace sync is before the processes freeze, the script is potentially competing w/ other high loading tasks which means there is still a small window (sync -> program alarm -> suspend until freeze) that could generate such odd.
Short recap this topic is trying to give a clear indication as simple mechanism for the platform and OS developers who may concern the suspending time w/ some sort of time constrain; given a clear metric it allows developers to have an easier triage such hard-to-reproduce issue shall go to virtual memory/filesystem rather than examine whether there is longer cost on each PM sub-state along w/ the device callbacks through a long suspending log.
Lastly, I understand this data might not so interesting to kernel developers; somehow my role is sitting in between trying to bridge kernel and OS developers, I fully respect reviewers' comments and justification.
Sincerely,
Harry
[1]
https://chromium-review.googlesource.com/c/chromiumos/platform2/+/458560/14/power_manager/tools/suspend_stress_test#202
(Apologize long URL and context as reference)
PATCH 1/1 PM / suspend: measure the time of filesystem syncing
In reply to Harry PanThis patch gives the reader an intuitive metric of the time cost by the kernel issuing a filesystem sync during suspend; although developer can guess by the timestamp of next log or enable the ftrace power event for manual calculation, this manner is easier to read and benefits the automatic script.
v2: simplify the variables, apply the simplest form of ktime API.
--- kernel/power/suspend.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
kernel/power/suspend.c +6 -1
@@ -550,6 +550,8 @@ static void suspend_finish(void)static int enter_state (suspend_state_t state) {int error; +ktime_t start; +unsigned int elapsed_msecs;trace_suspend_resume (TPS ("suspend_enter" ), state, true);if (state ==PM_SUSPEND_TO_IDLE ) {
@@ -570,9 +572,12 @@ static int enter_state(suspend_state_t state)#ifndef CONFIG_SUSPEND_SKIP_SYNC trace_suspend_resume (TPS ("sync_filesystems" ),0 , true); + start =ktime_get ();pr_info ("Syncing filesystems ... " );ksys_sync (); -pr_cont ("done.\n" ); + elapsed_msecs =ktime_to_ms (ktime_sub (ktime_get (), start)); +pr_cont ("(elapsed %d.%03d seconds) done.\n" , elapsed_msecs /1000 , + elapsed_msecs %1000 );trace_suspend_resume (TPS ("sync_filesystems" ),0 , false);#endif
Signature · 1 line
2.18.1
Pavel Machek
NAKQuoted 9 lines · Harry Pan
This patch gives the reader an intuitive metric of the time cost by the kernel issuing a filesystem sync during suspend; although developer can guess by the timestamp of next log or enable the ftrace power event for manual calculation, this manner is easier to read and benefits the automatic script.
v2: simplify the variables, apply the simplest form of ktime API.
Signed-off-by Harry Pan <[email protected]>
NAK.
Pavel
Quoted 31 lines
--- kernel/power/suspend.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)kernel/power/suspend.c +6
-1@@ -550,6 +550,8 @@ static void suspend_finish(void)static int enter_state (suspend_state_t state) {int error; +ktime_t start; +unsigned int elapsed_msecs;trace_suspend_resume (TPS ("suspend_enter" ), state, true);if (state ==PM_SUSPEND_TO_IDLE ) {@@ -570,9 +572,12 @@ static int enter_state(suspend_state_t state)#ifndef CONFIG_SUSPEND_SKIP_SYNC trace_suspend_resume (TPS ("sync_filesystems" ),0 , true); + start =ktime_get ();pr_info ("Syncing filesystems ... " );ksys_sync (); -pr_cont ("done.\n" ); + elapsed_msecs =ktime_to_ms (ktime_sub (ktime_get (), start)); +pr_cont ("(elapsed %d.%03d seconds) done.\n" , elapsed_msecs /1000 , + elapsed_msecs %1000 );trace_suspend_resume (TPS ("sync_filesystems" ),0 , false);#endif
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Rafael J. Wysocki
maintainerQuoted 19 lines · Harry Pan
This patch gives the reader an intuitive metric of the time cost by the kernel issuing a filesystem sync during suspend; although developer can guess by the timestamp of next log or enable the ftrace power event for manual calculation, this manner is easier to read and benefits the automatic script.
v2: simplify the variables, apply the simplest form of ktime API.
Signed-off-by Harry Pan <[email protected]>--- kernel/power/suspend.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)kernel/power/suspend.c +0
-0
kernel/power/suspend.c static void suspend_finish(void) · line 554
Quoted 5 lines
kernel/power/suspend.c +2
-0@@ -550,6 +550,8 @@ static void suspend_finish(void)static int enter_state (suspend_state_t state) {int error; +ktime_t start; +unsigned int elapsed_msecs;
You only need these two if CONFIG_SUSPEND_SKIP_SYNC is set, ->
kernel/power/suspend.c static int enter_state(suspend_state_t state) · line 573
Quoted 6 lines
kernel/power/suspend.c +0
-0trace_suspend_resume (TPS ("suspend_enter" ), state, true);if (state ==PM_SUSPEND_TO_IDLE ) {@@ -570,9 +572,12 @@ static int enter_state(suspend_state_t state)#ifndef CONFIG_SUSPEND_SKIP_SYNC
-> so I would change this to
if (IS_ENABLED(CONFIG_SUSPEND_SKIP_SYNC)) {
ktime_t start;
unsigned int elapsed_msecs;kernel/power/suspend.c static int enter_state(suspend_state_t state) · line 575
Quoted 2 lines
kernel/power/suspend.c +1
-0trace_suspend_resume (TPS ("sync_filesystems" ),0 , true); + start =ktime_get ();
Why don't you do this after printing the message below?
kernel/power/suspend.c static int enter_state(suspend_state_t state) · line 580
Quoted 6 lines
kernel/power/suspend.c +3
-1pr_info ("Syncing filesystems ... " );ksys_sync (); -pr_cont ("done.\n" ); + elapsed_msecs =ktime_to_ms (ktime_sub (ktime_get (), start)); +pr_cont ("(elapsed %d.%03d seconds) done.\n" , elapsed_msecs /1000 , + elapsed_msecs %1000 );
Use MSEC_PER_SEC here.
Quoted 3 lines
kernel/power/suspend.c +0
-0trace_suspend_resume (TPS ("sync_filesystems" ),0 , false);#endif
Rafael J. Wysocki
maintainerQuoted 34 lines · Rafael J. Wysocki
Quoted 19 lines · Harry Pan
This patch gives the reader an intuitive metric of the time cost by the kernel issuing a filesystem sync during suspend; although developer can guess by the timestamp of next log or enable the ftrace power event for manual calculation, this manner is easier to read and benefits the automatic script.
v2: simplify the variables, apply the simplest form of ktime API.
Signed-off-by Harry Pan <[email protected]>--- kernel/power/suspend.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)kernel/power/suspend.c +0
-0kernel/power/suspend.c static void suspend_finish(void) · line 554
Quoted 5 lines
kernel/power/suspend.c +2
-0@@ -550,6 +550,8 @@ static void suspend_finish(void)static int enter_state (suspend_state_t state) {int error; +ktime_t start; +unsigned int elapsed_msecs;You only need these two if
CONFIG_SUSPEND_SKIP_SYNCis set, ->Quoted 5 lines
kernel/power/suspend.c +0
-0trace_suspend_resume (TPS ("suspend_enter" ), state, true);if (state ==PM_SUSPEND_TO_IDLE ) {@@ -570,9 +572,12 @@ static int enter_state(suspend_state_t state)
Quoted 5 lines
kernel/power/suspend.c static int enter_state(suspend_state_t state) · line 573
Quoted 1 line
kernel/power/suspend.c +0
-0#ifndef CONFIG_SUSPEND_SKIP_SYNC -> so I would change this to
if (
IS_ENABLED(CONFIG_SUSPEND_SKIP_SYNC)) {
if (!IS_ENABLED(CONFIG_SUSPEND_SKIP_SYNC)) {
that is (missing "!").
Quoted 20 lines
ktime_t start; unsigned int elapsed_msecs;kernel/power/suspend.c static int enter_state(suspend_state_t state) · line 575
Quoted 2 lines
kernel/power/suspend.c +1
-0trace_suspend_resume (TPS ("sync_filesystems" ),0 , true); + start =ktime_get ();Why don't you do this after printing the message below?
kernel/power/suspend.c static int enter_state(suspend_state_t state) · line 580
Quoted 6 lines
kernel/power/suspend.c +3
-1pr_info ("Syncing filesystems ... " );ksys_sync (); -pr_cont ("done.\n" ); + elapsed_msecs =ktime_to_ms (ktime_sub (ktime_get (), start)); +pr_cont ("(elapsed %d.%03d seconds) done.\n" , elapsed_msecs /1000 , + elapsed_msecs %1000 );Use
MSEC_PER_SEChere.Quoted 3 lines
kernel/power/suspend.c +0
-0trace_suspend_resume (TPS ("sync_filesystems" ),0 , false);#endif
Rafael J. Wysocki
maintainerQuoted 16 lines · Rafael J. Wysocki
Quoted 14 lines · Harry Pan
This patch gives the reader an intuitive metric of the time cost by the kernel issuing a filesystem sync during suspend; although developer can guess by the timestamp of next log or enable the ftrace power event for manual calculation, this manner is easier to read and benefits the automatic script.
v2: simplify the variables, apply the simplest form of ktime API.
Signed-off-by Harry Pan <[email protected]>--- kernel/power/suspend.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
Quoted 12 lines
kernel/power/suspend.c static void suspend_finish(void) · line 554
Quoted 10 lines
kernel/power/suspend.c +2
-0@@ -550,6 +550,8 @@ static void suspend_finish(void)static int enter_state (suspend_state_t state) {int error; +ktime_t start; +unsigned int elapsed_msecs;You only need these two if
CONFIG_SUSPEND_SKIP_SYNCis set, ->
s/set/unset/
Sorry for the confusion.
PATCH v2 1/1 PM / suspend: measure the time of filesystem syncing
In reply to Harry PanThis patch gives the reader an intuitive metric of the time cost by the kernel issuing a filesystem sync during suspend; although developer can guess by the timestamp of next log or enable the ftrace power event for manual calculation, this manner is easier to read and benefits the automatic script.
v2: simplify the variables, apply the simplest form of ktime API.
--- kernel/power/suspend.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
kernel/power/suspend.c +6 -1
@@ -550,6 +550,8 @@ static void suspend_finish(void)static int enter_state (suspend_state_t state) {int error; +ktime_t start; +unsigned int elapsed_msecs;trace_suspend_resume (TPS ("suspend_enter" ), state, true);if (state ==PM_SUSPEND_TO_IDLE ) {
@@ -570,9 +572,12 @@ static int enter_state(suspend_state_t state)#ifndef CONFIG_SUSPEND_SKIP_SYNC trace_suspend_resume (TPS ("sync_filesystems" ),0 , true); + start =ktime_get ();pr_info ("Syncing filesystems ... " );ksys_sync (); -pr_cont ("done.\n" ); + elapsed_msecs =ktime_to_ms (ktime_sub (ktime_get (), start)); +pr_cont ("(elapsed %d.%03d seconds) done.\n" , elapsed_msecs /1000 , + elapsed_msecs %1000 );trace_suspend_resume (TPS ("sync_filesystems" ),0 , false);#endif
Signature · 1 line
2.18.1
PATCH v3 1/1 PM / suspend: measure the time of filesystem syncing
This patch gives the reader an intuitive metric of the time cost by the kernel issuing a filesystem sync during suspend; although developer can guess by the timestamp of next log or enable the ftrace power event for manual calculation, this manner is easier to read and benefits the automatic script.
v2: simplify the variables, apply the simplest form of ktime API.
v3: reduce conditional compilation, rectify profiling in better syntax
--- kernel/power/suspend.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
kernel/power/suspend.c +14 -7
@@ -568,13 +568,20 @@ static int enter_state(suspend_state_t state)if (state ==PM_SUSPEND_TO_IDLE )s2idle_begin (); -#ifndef CONFIG_SUSPEND_SKIP_SYNC -trace_suspend_resume (TPS ("sync_filesystems" ),0 , true); -pr_info ("Syncing filesystems ... " ); -ksys_sync (); -pr_cont ("done.\n" ); -trace_suspend_resume (TPS ("sync_filesystems" ),0 , false); -#endif +if (!IS_ENABLED (CONFIG_SUSPEND_SKIP_SYNC )) { +ktime_t start; +unsigned int elapsed_msecs; + +trace_suspend_resume (TPS ("sync_filesystems" ),0 , true); +pr_info ("Syncing filesystems ... " ); + start =ktime_get (); +ksys_sync (); + elapsed_msecs =ktime_to_ms (ktime_sub (ktime_get (), start)); +pr_cont ("(elapsed %d.%03d seconds) done.\n" , + elapsed_msecs /MSEC_PER_SEC , + elapsed_msecs %MSEC_PER_SEC ); +trace_suspend_resume (TPS ("sync_filesystems" ),0 , false); + }pm_pr_dbg ("Preparing system for sleep (%s)\n" , mem_sleep_labels[state]);pm_suspend_clear_flags ();
Signature · 1 line
2.18.1
PATCH v3 1/1 PM / suspend: measure the time of filesystem syncing
In reply to Harry PanThis patch gives the reader an intuitive metric of the time cost by the kernel issuing a filesystem sync during suspend; although developer can guess by the timestamp of next log or enable the ftrace power event for manual calculation, this manner is easier to read and benefits the automatic script.
v2: simplify the variables, apply the simplest form of ktime API.
v3: reduce conditional compilation, rectify profiling in better syntax
--- kernel/power/suspend.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
kernel/power/suspend.c +14 -7
@@ -568,13 +568,20 @@ static int enter_state(suspend_state_t state)if (state ==PM_SUSPEND_TO_IDLE )s2idle_begin (); -#ifndef CONFIG_SUSPEND_SKIP_SYNC -trace_suspend_resume (TPS ("sync_filesystems" ),0 , true); -pr_info ("Syncing filesystems ... " ); -ksys_sync (); -pr_cont ("done.\n" ); -trace_suspend_resume (TPS ("sync_filesystems" ),0 , false); -#endif +if (!IS_ENABLED (CONFIG_SUSPEND_SKIP_SYNC )) { +ktime_t start; +unsigned int elapsed_msecs; + +trace_suspend_resume (TPS ("sync_filesystems" ),0 , true); +pr_info ("Syncing filesystems ... " ); + start =ktime_get (); +ksys_sync (); + elapsed_msecs =ktime_to_ms (ktime_sub (ktime_get (), start)); +pr_cont ("(elapsed %d.%03d seconds) done.\n" , + elapsed_msecs /MSEC_PER_SEC , + elapsed_msecs %MSEC_PER_SEC ); +trace_suspend_resume (TPS ("sync_filesystems" ),0 , false); + }pm_pr_dbg ("Preparing system for sleep (%s)\n" , mem_sleep_labels[state]);pm_suspend_clear_flags ();
Signature · 1 line
2.18.1
Quoted 31 lines · CET Harry Pan
This patch gives the reader an intuitive metric of the time cost by the kernel issuing a filesystem sync during suspend; although developer can guess by the timestamp of next log or enable the ftrace power event for manual calculation, this manner is easier to read and benefits the automatic script.
v2: simplify the variables, apply the simplest form of ktime API.
v3: reduce conditional compilation, rectify profiling in better syntaxSigned-off-by Harry Pan <[email protected]>--- kernel/power/suspend.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)kernel/power/suspend.c +2
-7@@ -568,13 +568,20 @@ static int enter_state(suspend_state_t state)if (state ==PM_SUSPEND_TO_IDLE )s2idle_begin (); -#ifndef CONFIG_SUSPEND_SKIP_SYNC -trace_suspend_resume (TPS ("sync_filesystems" ),0 , true); -pr_info ("Syncing filesystems ... " ); -ksys_sync (); -pr_cont ("done.\n" ); -trace_suspend_resume (TPS ("sync_filesystems" ),0 , false); -#endif +if (!IS_ENABLED (CONFIG_SUSPEND_SKIP_SYNC )) { +ktime_t start;
kernel/power/suspend.c static int enter_state(suspend_state_t state) · line 582
Quoted 10 lines
kernel/power/suspend.c +10
-0+unsigned int elapsed_msecs; + +trace_suspend_resume (TPS ("sync_filesystems" ),0 , true); +pr_info ("Syncing filesystems ... " ); + start =ktime_get (); +ksys_sync (); + elapsed_msecs =ktime_to_ms (ktime_sub (ktime_get (), start)); +pr_cont ("(elapsed %d.%03d seconds) done.\n" , + elapsed_msecs /MSEC_PER_SEC , + elapsed_msecs %MSEC_PER_SEC );
One more nit.
Since you are printing the sync time anyway, there is a little sense to split the message using pr_cont() that may be messed up with by any intervening messages, so why don't you just print a one-line pr_info("Filesystems sync: %d.%03d seconds\n", ...) message?
Also, if you change it here, I guess it would be consistent to make an analogous change for hibernation.
Quoted 6 lines
kernel/power/suspend.c +2
-0+trace_suspend_resume (TPS ("sync_filesystems" ),0 , false); + }pm_pr_dbg ("Preparing system for sleep (%s)\n" , mem_sleep_labels[state]);pm_suspend_clear_flags ();
Thanks for comments.
Quoted 16 lines
kernel/power/suspend.c static int enter_state(suspend_state_t state) · line 582
Quoted 13 lines
kernel/power/suspend.c +9
-0+if (!IS_ENABLED (CONFIG_SUSPEND_SKIP_SYNC )) { +ktime_t start; +unsigned int elapsed_msecs; + +trace_suspend_resume (TPS ("sync_filesystems" ),0 , true); +pr_info ("Syncing filesystems ... " ); + start =ktime_get (); +ksys_sync (); + elapsed_msecs = ktime_to_ms(ktime_sub(ktime_get(),start));
kernel/power/suspend.c +3
-0+pr_cont ("(elapsed %d.%03d seconds) done.\n" , + elapsed_msecs /MSEC_PER_SEC , + elapsed_msecs %MSEC_PER_SEC );One more nit.
Quoted 6 lines
Since you are printing the sync time anyway, there is a little sense to
split the message usingpr_cont()that may be messed up with by any intervening messages, so why don't you just print a one-linepr_info("Filesystems sync: %d.%03d seconds\n", ...)message?
Yes, I agree.
In practical, I did see intervening messages (between pr_info and pr_cont) when it came to long sync in kernel.
I was hesitated in this considering not fully understanding the backdrop of split messages using pr_info() then pr_cont().
Quoted 2 lines
Also, if you change it here, I guess it would be consistent to make an analogous change for hibernation.
One potential last-mile need your wisdom, which is about the switch case of SNAPSHOT_FREEZE of the userspace interface you wrote. I am yet to touch it, nor understand how to validate it.
That said, I am digesting your documents and source; I used the pm_test from the doc to validate the patch on hibernation partially even non of my handy laptons fully work well on it.
Sincerely,
Harry
Rafael J. Wysocki
maintainerQuoted 31 lines · Harry
Thanks for comments.
Quoted 14 lines
kernel/power/suspend.c static int enter_state(suspend_state_t state) · line 582
Quoted 13 lines
kernel/power/suspend.c +9
-0+if (!IS_ENABLED (CONFIG_SUSPEND_SKIP_SYNC )) { +ktime_t start; +unsigned int elapsed_msecs; + +trace_suspend_resume (TPS ("sync_filesystems" ),0 , true); +pr_info ("Syncing filesystems ... " ); + start =ktime_get (); +ksys_sync (); + elapsed_msecs = ktime_to_ms(ktime_sub(ktime_get(),start));
kernel/power/suspend.c +3
-0+pr_cont ("(elapsed %d.%03d seconds) done.\n" , + elapsed_msecs /MSEC_PER_SEC , + elapsed_msecs %MSEC_PER_SEC );Quoted 8 lines
One more nit.
Since you are printing the sync time anyway, there is a little sense to
split the message usingpr_cont()that may be messed up with by any intervening messages, so why don't you just print a one-linepr_info("Filesystems sync: %d.%03d seconds\n", ...)message?Yes, I agree.
In practical, I did see intervening messages (betweenpr_infoandpr_cont) when it came to long sync in kernel.
I was hesitated in this considering not fully understanding the backdrop of split messages usingpr_info()thenpr_cont().
Quoted 6 lines
Quoted 2 lines
Also, if you change it here, I guess it would be consistent to make an analogous change for hibernation.
One potential last-mile need your wisdom, which is about the switch case of
SNAPSHOT_FREEZEof the userspace interface you wrote. I am yet to touch it, nor understand how to validate it.
Why don't you add a "sync" helper function in main.c with the timing and message that will be called from hibernate.c, user.c and suspend.c (in the last one conditional on !IS_ENABLED(CONFIG_SUSPEND_SKIP_SYNC))?
That would reduce some code duplication nicely.
Quoted 7 lines
Why don't you add a "sync" helper function in
main.cwith the timing and message that will be called fromhibernate.c,user.candsuspend.c
(in the last one conditional on !IS_ENABLED(CONFIG_SUSPEND_SKIP_SYNC))?That would reduce some code duplication nicely.
I uploaded v5 in reciprocate to your comment, I apologize I sent it second time in order to clean up the header files.
-Harry
PATCH v4 1/1 PM / suspend: measure the time of filesystem syncing
In reply to Harry PanThis patch gives the reader an intuitive metric of the time cost by the kernel issuing a filesystem sync during suspend; although developer can guess by the timestamp of next log or enable the ftrace power event for manual calculation, this manner is easier to read and benefits the automatic script.
v2: simplify the variables, apply the simplest form of ktime API.
v3: reduce conditional compilation, rectify profiling in better syntax
v4: avoid interposition, profile on hibernation, rectify printk format
--- kernel/power/hibernate.c | 9 +++++++-- kernel/power/suspend.c | 20 +++++++++++++------- 2 files changed, 20 insertions(+), 9 deletions(-)
kernel/power/hibernate.c +7 -2
@@ -688,6 +688,8 @@ int hibernate(void) {int error, nr_calls =0 ;bool snapshot_test = false; +ktime_t start; +s64 elapsed_msecs;if (!hibernation_available ()) {pm_pr_dbg ("Hibernation not available.\n" );
@@ -709,9 +711,12 @@ int hibernate(void) goto Exit; } -pr_info ("Syncing filesystems ... \n" ); + start =ktime_get ();ksys_sync (); -pr_info ("done.\n" ); + elapsed_msecs =ktime_to_ms (ktime_sub (ktime_get (), start)); +pr_info ("Filesystems sync: %lld.%03lld seconds\n" , + elapsed_msecs /MSEC_PER_SEC , + elapsed_msecs %MSEC_PER_SEC ); error =freeze_processes ();if (error)
kernel/power/suspend.c +13 -7
@@ -568,13 +568,19 @@ static int enter_state(suspend_state_t state)if (state ==PM_SUSPEND_TO_IDLE )s2idle_begin (); -#ifndef CONFIG_SUSPEND_SKIP_SYNC -trace_suspend_resume (TPS ("sync_filesystems" ),0 , true); -pr_info ("Syncing filesystems ... " ); -ksys_sync (); -pr_cont ("done.\n" ); -trace_suspend_resume (TPS ("sync_filesystems" ),0 , false); -#endif +if (!IS_ENABLED (CONFIG_SUSPEND_SKIP_SYNC )) { +ktime_t start; +s64 elapsed_msecs; + +trace_suspend_resume (TPS ("sync_filesystems" ),0 , true); + start =ktime_get (); +ksys_sync (); + elapsed_msecs =ktime_to_ms (ktime_sub (ktime_get (), start)); +pr_info ("Filesystems sync: %lld.%03lld seconds\n" , + elapsed_msecs /MSEC_PER_SEC , + elapsed_msecs %MSEC_PER_SEC ); +trace_suspend_resume (TPS ("sync_filesystems" ),0 , false); + }pm_pr_dbg ("Preparing system for sleep (%s)\n" , mem_sleep_labels[state]);pm_suspend_clear_flags ();
Signature · 1 line
2.18.1
PATCH v4 1/1 PM / suspend: measure the time of filesystem syncing
In reply to Harry PanThis patch gives the reader an intuitive metric of the time cost by the kernel issuing a filesystem sync during suspend; although developer can guess by the timestamp of next log or enable the ftrace power event for manual calculation, this manner is easier to read and benefits the automatic script.
v2: simplify the variables, apply the simplest form of ktime API.
v3: reduce conditional compilation, rectify profiling in better syntax
v4: avoid interposition, profile on hibernation, rectify printk format
--- kernel/power/hibernate.c | 9 +++++++-- kernel/power/suspend.c | 20 +++++++++++++------- 2 files changed, 20 insertions(+), 9 deletions(-)
kernel/power/hibernate.c +7 -2
@@ -688,6 +688,8 @@ int hibernate(void) {int error, nr_calls =0 ;bool snapshot_test = false; +ktime_t start; +s64 elapsed_msecs;if (!hibernation_available ()) {pm_pr_dbg ("Hibernation not available.\n" );
@@ -709,9 +711,12 @@ int hibernate(void) goto Exit; } -pr_info ("Syncing filesystems ... \n" ); + start =ktime_get ();ksys_sync (); -pr_info ("done.\n" ); + elapsed_msecs =ktime_to_ms (ktime_sub (ktime_get (), start)); +pr_info ("Filesystems sync: %lld.%03lld seconds\n" , + elapsed_msecs /MSEC_PER_SEC , + elapsed_msecs %MSEC_PER_SEC ); error =freeze_processes ();if (error)
kernel/power/suspend.c +13 -7
@@ -568,13 +568,19 @@ static int enter_state(suspend_state_t state)if (state ==PM_SUSPEND_TO_IDLE )s2idle_begin (); -#ifndef CONFIG_SUSPEND_SKIP_SYNC -trace_suspend_resume (TPS ("sync_filesystems" ),0 , true); -pr_info ("Syncing filesystems ... " ); -ksys_sync (); -pr_cont ("done.\n" ); -trace_suspend_resume (TPS ("sync_filesystems" ),0 , false); -#endif +if (!IS_ENABLED (CONFIG_SUSPEND_SKIP_SYNC )) { +ktime_t start; +s64 elapsed_msecs; + +trace_suspend_resume (TPS ("sync_filesystems" ),0 , true); + start =ktime_get (); +ksys_sync (); + elapsed_msecs =ktime_to_ms (ktime_sub (ktime_get (), start)); +pr_info ("Filesystems sync: %lld.%03lld seconds\n" , + elapsed_msecs /MSEC_PER_SEC , + elapsed_msecs %MSEC_PER_SEC ); +trace_suspend_resume (TPS ("sync_filesystems" ),0 , false); + }pm_pr_dbg ("Preparing system for sleep (%s)\n" , mem_sleep_labels[state]);pm_suspend_clear_flags ();
Signature · 1 line
2.18.1
PATCH v5 1/1 PM / sleep: measure the time of filesystem syncing
This patch gives the reader an intuitive metric of the time cost by the kernel issuing a filesystem sync during system sleep; although developer can guess by the timestamp of next log or enable the ftrace power event for manual calculation, this manner is easier to read and benefits the automatic script.
v2: simplify the variables, apply the simplest form of ktime API.
v3: reduce conditional compilation, rectify profiling in better syntax
v4: avoid interposition, profile on hibernation, rectify printk format
v5: introduce sync helper shared by suspend, hibernate, and snapshot
--- include/linux/suspend.h | 3 +++ kernel/power/hibernate.c | 4 +--- kernel/power/main.c | 15 +++++++++++++++ kernel/power/suspend.c | 13 +++++-------- kernel/power/user.c | 4 +--- 5 files changed, 25 insertions(+), 14 deletions(-)
include/linux/suspend.h +3 -0
@@ -425,6 +425,7 @@ void restore_processor_state(void);/* kernel/power/main.c */ extern int register_pm_notifier (struct notifier_block *nb);extern int unregister_pm_notifier (struct notifier_block *nb); +extern void ksys_sync_helper (void );#define pm_notifier (fn, pri) { \ static struct notifier_block fn##_nb = \
@@ -462,6 +463,8 @@ static inline int unregister_pm_notifier(struct notifier_block *nb)return 0 ; } +static inline void ksys_sync_helper (void ) {} +#define pm_notifier (fn, pri) do { (void)(fn); } while (0)static inline bool pm_wakeup_pending (void ) {return false; }
kernel/power/hibernate.c +1 -3
@@ -709,9 +709,7 @@ int hibernate(void) goto Exit; } -pr_info ("Syncing filesystems ... \n" ); -ksys_sync (); -pr_info ("done.\n" ); +ksys_sync_helper (); error =freeze_processes ();if (error)
kernel/power/main.c +15 -0
@@ -16,6 +16,7 @@#include <linux/debugfs.h> #include <linux/seq_file.h> #include <linux/suspend.h> +#include <linux/syscalls.h> #include "power.h"
@@ -51,6 +52,20 @@ void unlock_system_sleep(void) }EXPORT_SYMBOL_GPL (unlock_system_sleep); +void ksys_sync_helper (void ) +{ +ktime_t start; +s64 elapsed_msecs; + + start =ktime_get (); +ksys_sync (); + elapsed_msecs =ktime_to_ms (ktime_sub (ktime_get (), start)); +pr_info ("Filesystems sync: %lld.%03lld seconds\n" , + elapsed_msecs /MSEC_PER_SEC , + elapsed_msecs %MSEC_PER_SEC ); +} +EXPORT_SYMBOL_GPL (ksys_sync_helper); +/* Routines for PM-transition notifications */ static BLOCKING_NOTIFIER_HEAD (pm_chain_head);
kernel/power/suspend.c +5 -8
@@ -17,7 +17,6 @@#include <linux/console.h> #include <linux/cpu.h> #include <linux/cpuidle.h> -#include <linux/syscalls.h> #include <linux/gfp.h> #include <linux/io.h> #include <linux/kernel.h>
@@ -568,13 +567,11 @@ static int enter_state(suspend_state_t state)if (state ==PM_SUSPEND_TO_IDLE )s2idle_begin (); -#ifndef CONFIG_SUSPEND_SKIP_SYNC -trace_suspend_resume (TPS ("sync_filesystems" ),0 , true); -pr_info ("Syncing filesystems ... " ); -ksys_sync (); -pr_cont ("done.\n" ); -trace_suspend_resume (TPS ("sync_filesystems" ),0 , false); -#endif +if (!IS_ENABLED (CONFIG_SUSPEND_SKIP_SYNC )) { +trace_suspend_resume (TPS ("sync_filesystems" ),0 , true); +ksys_sync_helper (); +trace_suspend_resume (TPS ("sync_filesystems" ),0 , false); + }pm_pr_dbg ("Preparing system for sleep (%s)\n" , mem_sleep_labels[state]);pm_suspend_clear_flags ();
kernel/power/user.c +1 -3
@@ -228,9 +228,7 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd,if (data->frozen)break ; -printk ("Syncing filesystems ... " ); -ksys_sync (); -printk ("done.\n" ); +ksys_sync_helper (); error =freeze_processes ();if (error)
Signature · 1 line
2.18.1
kbuild test robot
build botRe: [PATCH v5] PM / sleep: measure the time of filesystem syncing
Thank you for the patch! Yet something to improve:
Hi Harry,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on linus/master]
[also build test ERROR on v5.0-rc4 next-20190222]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Harry-Pan/PM-sleep-measure-the-time-of-filesystem-syncing/20190225-023616
config: nds32-defconfig (attached as .config)
compiler: nds32le-linux-gcc (GCC) 6.4.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=6.4.0 make.cross ARCH=nds32
All errors (new ones prefixed by >>):
kernel/power/main.o: In function `ksys_sync_helper':
>> main.c:(.text+0x150): undefined reference to `__moddi3' main.c:(.text+0x154): undefined reference to `__moddi3' >> main.c:(.text+0x168): undefined reference to `__divdi3'
main.c:(.text+0x16c): undefined reference to `__divdi3'
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
kbuild test robot
build botRe: [PATCH v5] PM / sleep: measure the time of filesystem syncing
In reply to Harry PanThank you for the patch! Yet something to improve:
Hi Harry,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on linus/master]
[also build test ERROR on v5.0-rc4 next-20190222]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Harry-Pan/PM-sleep-measure-the-time-of-filesystem-syncing/20190225-023616
config: mips-allmodconfig (attached as .config)
compiler: mips-linux-gnu-gcc (Debian 8.2.0-11) 8.2.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=8.2.0 make.cross ARCH=mips
All errors (new ones prefixed by >>):
mips-linux-gnu-ld: kernel/power/main.o: in function `ksys_sync_helper':
>> main.c:(.text.ksys_sync_helper+0x130): undefined reference to `__divdi3' >> mips-linux-gnu-ld: main.c:(.text.ksys_sync_helper+0x14c): undefined reference to `__moddi3'
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
PATCH v5 1/1 PM / sleep: measure the time of filesystem syncing
In reply to Harry PanThis patch gives the reader an intuitive metric of the time cost by the kernel issuing a filesystem sync during system sleep; although developer can guess by the timestamp of next log or enable the ftrace power event for manual calculation, this manner is easier to read and benefits the automatic script.
v2: simplify the variables, apply the simplest form of ktime API.
v3: reduce conditional compilation, rectify profiling in better syntax
v4: avoid interposition, profile on hibernation, rectify printk format
v5: introduce sync helper shared by suspend, hibernate, and snapshot
--- include/linux/suspend.h | 3 +++ kernel/power/hibernate.c | 5 +---- kernel/power/main.c | 15 +++++++++++++++ kernel/power/suspend.c | 13 +++++-------- kernel/power/user.c | 5 +---- 5 files changed, 25 insertions(+), 16 deletions(-)
include/linux/suspend.h +3 -0
@@ -425,6 +425,7 @@ void restore_processor_state(void);/* kernel/power/main.c */ extern int register_pm_notifier (struct notifier_block *nb);extern int unregister_pm_notifier (struct notifier_block *nb); +extern void ksys_sync_helper (void );#define pm_notifier (fn, pri) { \ static struct notifier_block fn##_nb = \
@@ -462,6 +463,8 @@ static inline int unregister_pm_notifier(struct notifier_block *nb)return 0 ; } +static inline void ksys_sync_helper (void ) {} +#define pm_notifier (fn, pri) do { (void)(fn); } while (0)static inline bool pm_wakeup_pending (void ) {return false; }
kernel/power/hibernate.c +1 -4
@@ -14,7 +14,6 @@#include <linux/export.h> #include <linux/suspend.h> -#include <linux/syscalls.h> #include <linux/reboot.h> #include <linux/string.h> #include <linux/device.h>
@@ -709,9 +708,7 @@ int hibernate(void) goto Exit; } -pr_info ("Syncing filesystems ... \n" ); -ksys_sync (); -pr_info ("done.\n" ); +ksys_sync_helper (); error =freeze_processes ();if (error)
kernel/power/main.c +15 -0
@@ -16,6 +16,7 @@#include <linux/debugfs.h> #include <linux/seq_file.h> #include <linux/suspend.h> +#include <linux/syscalls.h> #include "power.h"
@@ -51,6 +52,20 @@ void unlock_system_sleep(void) }EXPORT_SYMBOL_GPL (unlock_system_sleep); +void ksys_sync_helper (void ) +{ +ktime_t start; +s64 elapsed_msecs; + + start =ktime_get (); +ksys_sync (); + elapsed_msecs =ktime_to_ms (ktime_sub (ktime_get (), start)); +pr_info ("Filesystems sync: %lld.%03lld seconds\n" , + elapsed_msecs /MSEC_PER_SEC , + elapsed_msecs %MSEC_PER_SEC ); +} +EXPORT_SYMBOL_GPL (ksys_sync_helper); +/* Routines for PM-transition notifications */ static BLOCKING_NOTIFIER_HEAD (pm_chain_head);
kernel/power/suspend.c +5 -8
@@ -17,7 +17,6 @@#include <linux/console.h> #include <linux/cpu.h> #include <linux/cpuidle.h> -#include <linux/syscalls.h> #include <linux/gfp.h> #include <linux/io.h> #include <linux/kernel.h>
@@ -568,13 +567,11 @@ static int enter_state(suspend_state_t state)if (state ==PM_SUSPEND_TO_IDLE )s2idle_begin (); -#ifndef CONFIG_SUSPEND_SKIP_SYNC -trace_suspend_resume (TPS ("sync_filesystems" ),0 , true); -pr_info ("Syncing filesystems ... " ); -ksys_sync (); -pr_cont ("done.\n" ); -trace_suspend_resume (TPS ("sync_filesystems" ),0 , false); -#endif +if (!IS_ENABLED (CONFIG_SUSPEND_SKIP_SYNC )) { +trace_suspend_resume (TPS ("sync_filesystems" ),0 , true); +ksys_sync_helper (); +trace_suspend_resume (TPS ("sync_filesystems" ),0 , false); + }pm_pr_dbg ("Preparing system for sleep (%s)\n" , mem_sleep_labels[state]);pm_suspend_clear_flags ();
kernel/power/user.c +1 -4
@@ -10,7 +10,6 @@*/ #include <linux/suspend.h> -#include <linux/syscalls.h> #include <linux/reboot.h> #include <linux/string.h> #include <linux/device.h>
@@ -228,9 +227,7 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd,if (data->frozen)break ; -printk ("Syncing filesystems ... " ); -ksys_sync (); -printk ("done.\n" ); +ksys_sync_helper (); error =freeze_processes ();if (error)
Signature · 1 line
2.18.1
Pavel Machek
NAKRe: [PATCH v5] PM / sleep: measure the time of filesystem syncing
Quoted 82 lines · Harry Pan
This patch gives the reader an intuitive metric of the time cost by the kernel issuing a filesystem sync during system sleep; although developer can guess by the timestamp of next log or enable the ftrace power event for manual calculation, this manner is easier to read and benefits the automatic script.
v2: simplify the variables, apply the simplest form of ktime API.
v3: reduce conditional compilation, rectify profiling in better syntax
v4: avoid interposition, profile on hibernation, rectify printk format
v5: introduce sync helper shared by suspend, hibernate, and snapshotSigned-off-by Harry Pan <[email protected]>--- include/linux/suspend.h | 3 +++ kernel/power/hibernate.c | 5 +---- kernel/power/main.c | 15 +++++++++++++++ kernel/power/suspend.c | 13 +++++-------- kernel/power/user.c | 5 +---- 5 files changed, 25 insertions(+), 16 deletions(-)include/linux/suspend.h +3
-0@@ -425,6 +425,7 @@ void restore_processor_state(void);/* kernel/power/main.c */ extern int register_pm_notifier (struct notifier_block *nb);extern int unregister_pm_notifier (struct notifier_block *nb); +extern void ksys_sync_helper (void );#define pm_notifier (fn, pri) { \ static struct notifier_block fn##_nb = \@@ -462,6 +463,8 @@ static inline int unregister_pm_notifier(struct notifier_block *nb)return 0 ; } +static inline void ksys_sync_helper (void ) {} +#define pm_notifier (fn, pri) do { (void)(fn); } while (0)static inline bool pm_wakeup_pending (void ) {return false; }kernel/power/hibernate.c +1
-4@@ -14,7 +14,6 @@#include <linux/export.h> #include <linux/suspend.h> -#include <linux/syscalls.h> #include <linux/reboot.h> #include <linux/string.h> #include <linux/device.h> @@ -709,9 +708,7 @@ int hibernate(void) goto Exit; } -pr_info ("Syncing filesystems ... \n" ); -ksys_sync (); -pr_info ("done.\n" ); +ksys_sync_helper (); error =freeze_processes ();if (error)kernel/power/main.c +3
-0@@ -16,6 +16,7 @@#include <linux/debugfs.h> #include <linux/seq_file.h> #include <linux/suspend.h> +#include <linux/syscalls.h> #include "power.h" @@ -51,6 +52,20 @@ void unlock_system_sleep(void) }EXPORT_SYMBOL_GPL (unlock_system_sleep); +void ksys_sync_helper (void ) +{
kernel/power/main.c void unlock_system_sleep(void) · line 66
Quoted 10 lines
kernel/power/main.c +10
-0+ktime_t start; +s64 elapsed_msecs; + + start =ktime_get (); +ksys_sync (); + elapsed_msecs =ktime_to_ms (ktime_sub (ktime_get (), start)); +pr_info ("Filesystems sync: %lld.%03lld seconds\n" , + elapsed_msecs /MSEC_PER_SEC , + elapsed_msecs %MSEC_PER_SEC ); +}
Sharing code is fine. Changing message, remove partial print before long operation is not.
Adding timing is not, either. There are other ways to get that info.
NAK.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
PATCH v6 1/2 PM / sleep: refactor the filesystems sync to reduce duplication
In reply to Harry PanThis patch creates a common helper to sync filesystems and shares to the suspend, hibernate, and snapshot.
--- include/linux/suspend.h | 3 +++ kernel/power/hibernate.c | 5 +---- kernel/power/main.c | 9 +++++++++ kernel/power/suspend.c | 13 +++++-------- kernel/power/user.c | 5 +---- 5 files changed, 19 insertions(+), 16 deletions(-)
include/linux/suspend.h +3 -0
@@ -425,6 +425,7 @@ void restore_processor_state(void);/* kernel/power/main.c */ extern int register_pm_notifier (struct notifier_block *nb);extern int unregister_pm_notifier (struct notifier_block *nb); +extern void ksys_sync_helper (void );#define pm_notifier (fn, pri) { \ static struct notifier_block fn##_nb = \
@@ -462,6 +463,8 @@ static inline int unregister_pm_notifier(struct notifier_block *nb)return 0 ; } +static inline void ksys_sync_helper (void ) {} +#define pm_notifier (fn, pri) do { (void)(fn); } while (0)static inline bool pm_wakeup_pending (void ) {return false; }
kernel/power/hibernate.c +1 -4
@@ -14,7 +14,6 @@#include <linux/export.h> #include <linux/suspend.h> -#include <linux/syscalls.h> #include <linux/reboot.h> #include <linux/string.h> #include <linux/device.h>
@@ -709,9 +708,7 @@ int hibernate(void) goto Exit; } -pr_info ("Syncing filesystems ... \n" ); -ksys_sync (); -pr_info ("done.\n" ); +ksys_sync_helper (); error =freeze_processes ();if (error)
kernel/power/main.c +9 -0
@@ -16,6 +16,7 @@#include <linux/debugfs.h> #include <linux/seq_file.h> #include <linux/suspend.h> +#include <linux/syscalls.h> #include "power.h"
@@ -51,6 +52,14 @@ void unlock_system_sleep(void) }EXPORT_SYMBOL_GPL (unlock_system_sleep); +void ksys_sync_helper (void ) +{ +pr_info ("Syncing filesystems ... " ); +ksys_sync (); +pr_cont ("done.\n" ); +} +EXPORT_SYMBOL_GPL (ksys_sync_helper); +/* Routines for PM-transition notifications */ static BLOCKING_NOTIFIER_HEAD (pm_chain_head);
kernel/power/suspend.c +5 -8
@@ -17,7 +17,6 @@#include <linux/console.h> #include <linux/cpu.h> #include <linux/cpuidle.h> -#include <linux/syscalls.h> #include <linux/gfp.h> #include <linux/io.h> #include <linux/kernel.h>
@@ -568,13 +567,11 @@ static int enter_state(suspend_state_t state)if (state ==PM_SUSPEND_TO_IDLE )s2idle_begin (); -#ifndef CONFIG_SUSPEND_SKIP_SYNC -trace_suspend_resume (TPS ("sync_filesystems" ),0 , true); -pr_info ("Syncing filesystems ... " ); -ksys_sync (); -pr_cont ("done.\n" ); -trace_suspend_resume (TPS ("sync_filesystems" ),0 , false); -#endif +if (!IS_ENABLED (CONFIG_SUSPEND_SKIP_SYNC )) { +trace_suspend_resume (TPS ("sync_filesystems" ),0 , true); +ksys_sync_helper (); +trace_suspend_resume (TPS ("sync_filesystems" ),0 , false); + }pm_pr_dbg ("Preparing system for sleep (%s)\n" , mem_sleep_labels[state]);pm_suspend_clear_flags ();
kernel/power/user.c +1 -4
@@ -10,7 +10,6 @@*/ #include <linux/suspend.h> -#include <linux/syscalls.h> #include <linux/reboot.h> #include <linux/string.h> #include <linux/device.h>
@@ -228,9 +227,7 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd,if (data->frozen)break ; -printk ("Syncing filesystems ... " ); -ksys_sync (); -printk ("done.\n" ); +ksys_sync_helper (); error =freeze_processes ();if (error)
Signature · 1 line
2.18.1
PATCH v6 2/2 PM / sleep: measure the time of filesystems syncing
This patch gives the reader an intuitive metric of the time cost by the kernel issuing filesystems sync during system sleep; although developer can guess by the timestamp of next log or enable the ftrace power event for manual calculation, this manner is easier to read and benefits the automation script.
--- kernel/power/main.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
kernel/power/main.c +8 -2
@@ -54,9 +54,15 @@ EXPORT_SYMBOL_GPL(unlock_system_sleep);void ksys_sync_helper (void ) { -pr_info ("Syncing filesystems ... " ); +ktime_t start; +s64 elapsed_msecs; + + start =ktime_get ();ksys_sync (); -pr_cont ("done.\n" ); + elapsed_msecs =ktime_to_ms (ktime_sub (ktime_get (), start)); +pr_info ("Filesystems sync: %lld.%03lld seconds\n" , + elapsed_msecs /MSEC_PER_SEC , + elapsed_msecs %MSEC_PER_SEC ); }EXPORT_SYMBOL_GPL (ksys_sync_helper);
Signature · 1 line
2.18.1
kbuild test robot
build botRe: [PATCH v6 2/2] PM / sleep: measure the time of filesystems syncing
Thank you for the patch! Yet something to improve:
Hi Harry,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on linus/master]
[also build test ERROR on v5.0-rc4 next-20190222]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Harry-Pan/PM-sleep-refactor-the-filesystems-sync-to-reduce-duplication/20190225-025843
config: i386-defconfig (attached as .config)
compiler: gcc-8 (Debian 8.2.0-20) 8.2.0 reproduce:
# save the attached .config to linux build tree
make ARCH=i386 All errors (new ones prefixed by >>):
ld: kernel/power/main.o: in function `ksys_sync_helper.cold.2':
>> main.c:(.text.unlikely+0x23): undefined reference to `__moddi3' >> ld: main.c:(.text.unlikely+0x37): undefined reference to `__divdi3'
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
kbuild test robot
build botRe: [PATCH v6 2/2] PM / sleep: measure the time of filesystems syncing
In reply to Harry PanThank you for the patch! Yet something to improve:
Hi Harry,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on linus/master]
[also build test ERROR on v5.0-rc4 next-20190222]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Harry-Pan/PM-sleep-refactor-the-filesystems-sync-to-reduce-duplication/20190225-025843
config: arm-allmodconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (Debian 8.2.0-11) 8.2.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=8.2.0 make.cross ARCH=arm
All errors (new ones prefixed by >>):
arm-linux-gnueabi-ld: kernel/power/main.o: in function `ksys_sync_helper':
>> main.c:(.text+0x150): undefined reference to `__aeabi_ldivmod' >> arm-linux-gnueabi-ld: main.c:(.text+0x16c): undefined reference to `__aeabi_ldivmod'
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
PATCH v7 1/2 PM / sleep: refactor the filesystems sync to reduce duplication
In reply to Harry PanThis patch creates a common helper to sync filesystems and shares to the suspend, hibernate, and snapshot.
--- include/linux/suspend.h | 3 +++ kernel/power/hibernate.c | 5 +---- kernel/power/main.c | 9 +++++++++ kernel/power/suspend.c | 13 +++++-------- kernel/power/user.c | 5 +---- 5 files changed, 19 insertions(+), 16 deletions(-)
include/linux/suspend.h +3 -0
@@ -425,6 +425,7 @@ void restore_processor_state(void);/* kernel/power/main.c */ extern int register_pm_notifier (struct notifier_block *nb);extern int unregister_pm_notifier (struct notifier_block *nb); +extern void ksys_sync_helper (void );#define pm_notifier (fn, pri) { \ static struct notifier_block fn##_nb = \
@@ -462,6 +463,8 @@ static inline int unregister_pm_notifier(struct notifier_block *nb)return 0 ; } +static inline void ksys_sync_helper (void ) {} +#define pm_notifier (fn, pri) do { (void)(fn); } while (0)static inline bool pm_wakeup_pending (void ) {return false; }
kernel/power/hibernate.c +1 -4
@@ -14,7 +14,6 @@#include <linux/export.h> #include <linux/suspend.h> -#include <linux/syscalls.h> #include <linux/reboot.h> #include <linux/string.h> #include <linux/device.h>
@@ -709,9 +708,7 @@ int hibernate(void) goto Exit; } -pr_info ("Syncing filesystems ... \n" ); -ksys_sync (); -pr_info ("done.\n" ); +ksys_sync_helper (); error =freeze_processes ();if (error)
kernel/power/main.c +9 -0
@@ -16,6 +16,7 @@#include <linux/debugfs.h> #include <linux/seq_file.h> #include <linux/suspend.h> +#include <linux/syscalls.h> #include "power.h"
@@ -51,6 +52,14 @@ void unlock_system_sleep(void) }EXPORT_SYMBOL_GPL (unlock_system_sleep); +void ksys_sync_helper (void ) +{ +pr_info ("Syncing filesystems ... " ); +ksys_sync (); +pr_cont ("done.\n" ); +} +EXPORT_SYMBOL_GPL (ksys_sync_helper); +/* Routines for PM-transition notifications */ static BLOCKING_NOTIFIER_HEAD (pm_chain_head);
kernel/power/suspend.c +5 -8
@@ -17,7 +17,6 @@#include <linux/console.h> #include <linux/cpu.h> #include <linux/cpuidle.h> -#include <linux/syscalls.h> #include <linux/gfp.h> #include <linux/io.h> #include <linux/kernel.h>
@@ -568,13 +567,11 @@ static int enter_state(suspend_state_t state)if (state ==PM_SUSPEND_TO_IDLE )s2idle_begin (); -#ifndef CONFIG_SUSPEND_SKIP_SYNC -trace_suspend_resume (TPS ("sync_filesystems" ),0 , true); -pr_info ("Syncing filesystems ... " ); -ksys_sync (); -pr_cont ("done.\n" ); -trace_suspend_resume (TPS ("sync_filesystems" ),0 , false); -#endif +if (!IS_ENABLED (CONFIG_SUSPEND_SKIP_SYNC )) { +trace_suspend_resume (TPS ("sync_filesystems" ),0 , true); +ksys_sync_helper (); +trace_suspend_resume (TPS ("sync_filesystems" ),0 , false); + }pm_pr_dbg ("Preparing system for sleep (%s)\n" , mem_sleep_labels[state]);pm_suspend_clear_flags ();
kernel/power/user.c +1 -4
@@ -10,7 +10,6 @@*/ #include <linux/suspend.h> -#include <linux/syscalls.h> #include <linux/reboot.h> #include <linux/string.h> #include <linux/device.h>
@@ -228,9 +227,7 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd,if (data->frozen)break ; -printk ("Syncing filesystems ... " ); -ksys_sync (); -printk ("done.\n" ); +ksys_sync_helper (); error =freeze_processes ();if (error)
Signature · 1 line
2.18.1
PATCH v7 2/2 PM / sleep: measure the time of filesystems syncing
This patch gives the reader an intuitive metric of the time cost by the kernel issuing filesystems sync during system sleep; although developer can guess by the timestamp of next log or enable the ftrace power event for manual calculation, this manner is easier to read and benefits the automation script.
v1 to v5: context discussion
v6: split patches logically in code refactor and sync profile
v7: improve 32/64 bit machine compatibility
--- kernel/power/main.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
kernel/power/main.c +8 -2
@@ -54,9 +54,15 @@ EXPORT_SYMBOL_GPL(unlock_system_sleep);void ksys_sync_helper (void ) { -pr_info ("Syncing filesystems ... " ); +ktime_t start; +long elapsed_msecs; + + start =ktime_get ();ksys_sync (); -pr_cont ("done.\n" ); + elapsed_msecs =ktime_to_ms (ktime_sub (ktime_get (), start)); +pr_info ("Filesystems sync: %ld.%03ld seconds\n" , + elapsed_msecs /MSEC_PER_SEC , + elapsed_msecs %MSEC_PER_SEC ); }EXPORT_SYMBOL_GPL (ksys_sync_helper);
Signature · 1 line
2.18.1
PATCH v7 1/2 PM / sleep: refactor the filesystems sync to reduce duplication
In reply to Harry PanThis patch creates a common helper to sync filesystems and shares to the suspend, hibernate, and snapshot.
--- include/linux/suspend.h | 3 +++ kernel/power/hibernate.c | 5 +---- kernel/power/main.c | 9 +++++++++ kernel/power/suspend.c | 13 +++++-------- kernel/power/user.c | 5 +---- 5 files changed, 19 insertions(+), 16 deletions(-)
include/linux/suspend.h +3 -0
@@ -425,6 +425,7 @@ void restore_processor_state(void);/* kernel/power/main.c */ extern int register_pm_notifier (struct notifier_block *nb);extern int unregister_pm_notifier (struct notifier_block *nb); +extern void ksys_sync_helper (void );#define pm_notifier (fn, pri) { \ static struct notifier_block fn##_nb = \
@@ -462,6 +463,8 @@ static inline int unregister_pm_notifier(struct notifier_block *nb)return 0 ; } +static inline void ksys_sync_helper (void ) {} +#define pm_notifier (fn, pri) do { (void)(fn); } while (0)static inline bool pm_wakeup_pending (void ) {return false; }
kernel/power/hibernate.c +1 -4
@@ -14,7 +14,6 @@#include <linux/export.h> #include <linux/suspend.h> -#include <linux/syscalls.h> #include <linux/reboot.h> #include <linux/string.h> #include <linux/device.h>
@@ -709,9 +708,7 @@ int hibernate(void) goto Exit; } -pr_info ("Syncing filesystems ... \n" ); -ksys_sync (); -pr_info ("done.\n" ); +ksys_sync_helper (); error =freeze_processes ();if (error)
kernel/power/main.c +9 -0
@@ -16,6 +16,7 @@#include <linux/debugfs.h> #include <linux/seq_file.h> #include <linux/suspend.h> +#include <linux/syscalls.h> #include "power.h"
@@ -51,6 +52,14 @@ void unlock_system_sleep(void) }EXPORT_SYMBOL_GPL (unlock_system_sleep); +void ksys_sync_helper (void ) +{ +pr_info ("Syncing filesystems ... " ); +ksys_sync (); +pr_cont ("done.\n" ); +} +EXPORT_SYMBOL_GPL (ksys_sync_helper); +/* Routines for PM-transition notifications */ static BLOCKING_NOTIFIER_HEAD (pm_chain_head);
kernel/power/suspend.c +5 -8
@@ -17,7 +17,6 @@#include <linux/console.h> #include <linux/cpu.h> #include <linux/cpuidle.h> -#include <linux/syscalls.h> #include <linux/gfp.h> #include <linux/io.h> #include <linux/kernel.h>
@@ -568,13 +567,11 @@ static int enter_state(suspend_state_t state)if (state ==PM_SUSPEND_TO_IDLE )s2idle_begin (); -#ifndef CONFIG_SUSPEND_SKIP_SYNC -trace_suspend_resume (TPS ("sync_filesystems" ),0 , true); -pr_info ("Syncing filesystems ... " ); -ksys_sync (); -pr_cont ("done.\n" ); -trace_suspend_resume (TPS ("sync_filesystems" ),0 , false); -#endif +if (!IS_ENABLED (CONFIG_SUSPEND_SKIP_SYNC )) { +trace_suspend_resume (TPS ("sync_filesystems" ),0 , true); +ksys_sync_helper (); +trace_suspend_resume (TPS ("sync_filesystems" ),0 , false); + }pm_pr_dbg ("Preparing system for sleep (%s)\n" , mem_sleep_labels[state]);pm_suspend_clear_flags ();
kernel/power/user.c +1 -4
@@ -10,7 +10,6 @@*/ #include <linux/suspend.h> -#include <linux/syscalls.h> #include <linux/reboot.h> #include <linux/string.h> #include <linux/device.h>
@@ -228,9 +227,7 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd,if (data->frozen)break ; -printk ("Syncing filesystems ... " ); -ksys_sync (); -printk ("done.\n" ); +ksys_sync_helper (); error =freeze_processes ();if (error)
Signature · 1 line
2.18.1
PATCH v7 2/2 PM / sleep: measure the time of filesystems syncing
This patch gives the reader an intuitive metric of the time cost by the kernel issuing filesystems sync during system sleep; although developer can guess by the timestamp of next log or enable the ftrace power event for manual calculation, this manner is easier to read and benefits the automation script.
v1 to v5: context discussion
v6: split patches logically in code refactor and sync profile
v7: improve 32/64 bit machine compatibility
--- kernel/power/main.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
kernel/power/main.c +8 -2
@@ -54,9 +54,15 @@ EXPORT_SYMBOL_GPL(unlock_system_sleep);void ksys_sync_helper (void ) { -pr_info ("Syncing filesystems ... " ); +ktime_t start; +long elapsed_msecs; + + start =ktime_get ();ksys_sync (); -pr_cont ("done.\n" ); + elapsed_msecs =ktime_to_ms (ktime_sub (ktime_get (), start)); +pr_info ("Filesystems sync: %ld.%03ld seconds\n" , + elapsed_msecs /MSEC_PER_SEC , + elapsed_msecs %MSEC_PER_SEC ); }EXPORT_SYMBOL_GPL (ksys_sync_helper);
Signature · 1 line
2.18.1
Re: [PATCH v7 1/2] PM / sleep: refactor the filesystems sync to reduce duplication
In reply to Harry PanQuoted 4 lines · Harry Pan
This patch creates a common helper to sync filesystems and shares to the suspend, hibernate, and snapshot.
Signed-off-by Harry Pan <[email protected]>
ACK.
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
kbuild test robot
build botRe: [PATCH v5] PM / sleep: measure the time of filesystem syncing
In reply to Harry PanThank you for the patch! Yet something to improve:
Hi Harry,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on linus/master]
[also build test ERROR on v5.0-rc4 next-20190222]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Harry-Pan/PM-sleep-measure-the-time-of-filesystem-syncing/20190225-032342
config: powerpc-sbc8548_defconfig (attached as .config)
compiler: powerpc-linux-gnu-gcc (Debian 8.2.0-11) 8.2.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=8.2.0 make.cross ARCH=powerpc
All errors (new ones prefixed by >>):
powerpc-linux-gnu-ld: warning: orphan section .branch_lt' from arch/powerpc/kernel/head_fsl_booke.o' being placed in section `.branch_lt'
powerpc-linux-gnu-ld: kernel/power/main.o: in function `ksys_sync_helper':
main.c:(.text+0x6e0): undefined reference to `__moddi3'
>> powerpc-linux-gnu-ld: main.c:(.text+0x6fc): undefined reference to `__divdi3'
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation