public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kselftest: cpufreq: Add RTC wakeup alarm
@ 2024-07-11 12:10 Shreeya Patel
  2024-07-11 12:13 ` Rafael J. Wysocki
  0 siblings, 1 reply; 3+ messages in thread
From: Shreeya Patel @ 2024-07-11 12:10 UTC (permalink / raw)
  To: rafael, viresh.kumar, shuah
  Cc: linux-pm, linux-kselftest, linux-kernel, kernel, Shreeya Patel

Add RTC wakeup alarm for devices to resume after specific time interval.
This improvement in the test will help in enabling this test
in the CI systems and will eliminate the need of manual intervention
for resuming back the devices after suspend/hibernation.

Signed-off-by: Shreeya Patel <shreeya.patel@collabora.com>
---
 tools/testing/selftests/cpufreq/cpufreq.sh | 24 ++++++++++++++++++++++
 tools/testing/selftests/cpufreq/main.sh    | 13 +++++++++++-
 2 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/cpufreq/cpufreq.sh b/tools/testing/selftests/cpufreq/cpufreq.sh
index a8b1dbc0a3a5..a0f5b944a8fe 100755
--- a/tools/testing/selftests/cpufreq/cpufreq.sh
+++ b/tools/testing/selftests/cpufreq/cpufreq.sh
@@ -231,6 +231,30 @@ do_suspend()
 
 		for i in `seq 1 $2`; do
 			printf "Starting $1\n"
+
+			if [ "$3" = "rtc" ]; then
+				now=$(date +%s)
+				wakeup_time=$((now + 15)) # Wake up after 15 seconds
+
+				echo $wakeup_time > /sys/class/rtc/rtc0/wakealarm
+
+				if [ $? -ne 0 ]; then
+					printf "Failed to set RTC wake alarm\n"
+					return 1
+				fi
+
+				# Enable the RTC as a wakeup source
+				echo enabled > /sys/class/rtc/rtc0/device/power/wakeup
+
+				if [ $? -ne 0 ]; then
+					printf "Failed to set RTC wake alarm\n"
+					return 1
+				fi
+
+				# Reset the wakeup alarm
+				echo 0 > /sys/class/rtc/rtc0/wakealarm
+			fi
+
 			echo $filename > $SYSFS/power/state
 			printf "Came out of $1\n"
 
diff --git a/tools/testing/selftests/cpufreq/main.sh b/tools/testing/selftests/cpufreq/main.sh
index a0eb84cf7167..f12ff7416e41 100755
--- a/tools/testing/selftests/cpufreq/main.sh
+++ b/tools/testing/selftests/cpufreq/main.sh
@@ -24,6 +24,8 @@ helpme()
 	[-t <basic: Basic cpufreq testing
 	     suspend: suspend/resume,
 	     hibernate: hibernate/resume,
+	     suspend_rtc: suspend/resume back using the RTC wakeup alarm,
+	     hibernate_rtc: hibernate/resume back using the RTC wakeup alarm,
 	     modtest: test driver or governor modules. Only to be used with -d or -g options,
 	     sptest1: Simple governor switch to produce lockdep.
 	     sptest2: Concurrent governor switch to produce lockdep.
@@ -76,7 +78,8 @@ parse_arguments()
 				helpme
 				;;
 
-			t) # --func_type (Function to perform: basic, suspend, hibernate, modtest, sptest1/2/3/4 (default: basic))
+			t) # --func_type (Function to perform: basic, suspend, hibernate,
+			   # suspend_rtc, hibernate_rtc, modtest, sptest1/2/3/4 (default: basic))
 				FUNC=$OPTARG
 				;;
 
@@ -121,6 +124,14 @@ do_test()
 		do_suspend "hibernate" 1
 		;;
 
+		"suspend_rtc")
+                do_suspend "suspend" 1 rtc
+                ;;
+
+                "hibernate_rtc")
+                do_suspend "hibernate" 1 rtc
+                ;;
+
 		"modtest")
 		# Do we have modules in place?
 		if [ -z $DRIVER_MOD ] && [ -z $GOVERNOR_MOD ]; then
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] kselftest: cpufreq: Add RTC wakeup alarm
  2024-07-11 12:10 [PATCH] kselftest: cpufreq: Add RTC wakeup alarm Shreeya Patel
@ 2024-07-11 12:13 ` Rafael J. Wysocki
  2024-07-11 15:18   ` Shreeya Patel
  0 siblings, 1 reply; 3+ messages in thread
From: Rafael J. Wysocki @ 2024-07-11 12:13 UTC (permalink / raw)
  To: Shreeya Patel
  Cc: rafael, viresh.kumar, shuah, linux-pm, linux-kselftest,
	linux-kernel, kernel

On Thu, Jul 11, 2024 at 2:10 PM Shreeya Patel
<shreeya.patel@collabora.com> wrote:
>
> Add RTC wakeup alarm for devices to resume after specific time interval.
> This improvement in the test will help in enabling this test
> in the CI systems and will eliminate the need of manual intervention
> for resuming back the devices after suspend/hibernation.

Why don't you use rtcwake for this?

> Signed-off-by: Shreeya Patel <shreeya.patel@collabora.com>
> ---
>  tools/testing/selftests/cpufreq/cpufreq.sh | 24 ++++++++++++++++++++++
>  tools/testing/selftests/cpufreq/main.sh    | 13 +++++++++++-
>  2 files changed, 36 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/cpufreq/cpufreq.sh b/tools/testing/selftests/cpufreq/cpufreq.sh
> index a8b1dbc0a3a5..a0f5b944a8fe 100755
> --- a/tools/testing/selftests/cpufreq/cpufreq.sh
> +++ b/tools/testing/selftests/cpufreq/cpufreq.sh
> @@ -231,6 +231,30 @@ do_suspend()
>
>                 for i in `seq 1 $2`; do
>                         printf "Starting $1\n"
> +
> +                       if [ "$3" = "rtc" ]; then
> +                               now=$(date +%s)
> +                               wakeup_time=$((now + 15)) # Wake up after 15 seconds
> +
> +                               echo $wakeup_time > /sys/class/rtc/rtc0/wakealarm
> +
> +                               if [ $? -ne 0 ]; then
> +                                       printf "Failed to set RTC wake alarm\n"
> +                                       return 1
> +                               fi
> +
> +                               # Enable the RTC as a wakeup source
> +                               echo enabled > /sys/class/rtc/rtc0/device/power/wakeup
> +
> +                               if [ $? -ne 0 ]; then
> +                                       printf "Failed to set RTC wake alarm\n"
> +                                       return 1
> +                               fi
> +
> +                               # Reset the wakeup alarm
> +                               echo 0 > /sys/class/rtc/rtc0/wakealarm
> +                       fi
> +
>                         echo $filename > $SYSFS/power/state
>                         printf "Came out of $1\n"
>
> diff --git a/tools/testing/selftests/cpufreq/main.sh b/tools/testing/selftests/cpufreq/main.sh
> index a0eb84cf7167..f12ff7416e41 100755
> --- a/tools/testing/selftests/cpufreq/main.sh
> +++ b/tools/testing/selftests/cpufreq/main.sh
> @@ -24,6 +24,8 @@ helpme()
>         [-t <basic: Basic cpufreq testing
>              suspend: suspend/resume,
>              hibernate: hibernate/resume,
> +            suspend_rtc: suspend/resume back using the RTC wakeup alarm,
> +            hibernate_rtc: hibernate/resume back using the RTC wakeup alarm,
>              modtest: test driver or governor modules. Only to be used with -d or -g options,
>              sptest1: Simple governor switch to produce lockdep.
>              sptest2: Concurrent governor switch to produce lockdep.
> @@ -76,7 +78,8 @@ parse_arguments()
>                                 helpme
>                                 ;;
>
> -                       t) # --func_type (Function to perform: basic, suspend, hibernate, modtest, sptest1/2/3/4 (default: basic))
> +                       t) # --func_type (Function to perform: basic, suspend, hibernate,
> +                          # suspend_rtc, hibernate_rtc, modtest, sptest1/2/3/4 (default: basic))
>                                 FUNC=$OPTARG
>                                 ;;
>
> @@ -121,6 +124,14 @@ do_test()
>                 do_suspend "hibernate" 1
>                 ;;
>
> +               "suspend_rtc")
> +                do_suspend "suspend" 1 rtc
> +                ;;
> +
> +                "hibernate_rtc")
> +                do_suspend "hibernate" 1 rtc
> +                ;;
> +
>                 "modtest")
>                 # Do we have modules in place?
>                 if [ -z $DRIVER_MOD ] && [ -z $GOVERNOR_MOD ]; then
> --
> 2.39.2
>
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] kselftest: cpufreq:  Add RTC wakeup alarm
  2024-07-11 12:13 ` Rafael J. Wysocki
@ 2024-07-11 15:18   ` Shreeya Patel
  0 siblings, 0 replies; 3+ messages in thread
From: Shreeya Patel @ 2024-07-11 15:18 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: viresh.kumar, shuah, linux-pm, linux-kselftest, linux-kernel,
	kernel

On Thursday, July 11, 2024 17:43 IST, "Rafael J. Wysocki" <rafael@kernel.org> wrote:

Hi,

> On Thu, Jul 11, 2024 at 2:10 PM Shreeya Patel
> <shreeya.patel@collabora.com> wrote:
> >
> > Add RTC wakeup alarm for devices to resume after specific time interval.
> > This improvement in the test will help in enabling this test
> > in the CI systems and will eliminate the need of manual intervention
> > for resuming back the devices after suspend/hibernation.
> 
> Why don't you use rtcwake for this?
> 

You are right, using rtcwake would have been better here.
I'll send a v2 with the changes


Thanks,
Shreeya Patel

> > Signed-off-by: Shreeya Patel <shreeya.patel@collabora.com>
> > ---
> >  tools/testing/selftests/cpufreq/cpufreq.sh | 24 ++++++++++++++++++++++
> >  tools/testing/selftests/cpufreq/main.sh    | 13 +++++++++++-
> >  2 files changed, 36 insertions(+), 1 deletion(-)
> >
> > diff --git a/tools/testing/selftests/cpufreq/cpufreq.sh b/tools/testing/selftests/cpufreq/cpufreq.sh
> > index a8b1dbc0a3a5..a0f5b944a8fe 100755
> > --- a/tools/testing/selftests/cpufreq/cpufreq.sh
> > +++ b/tools/testing/selftests/cpufreq/cpufreq.sh
> > @@ -231,6 +231,30 @@ do_suspend()
> >
> >                 for i in `seq 1 $2`; do
> >                         printf "Starting $1\n"
> > +
> > +                       if [ "$3" = "rtc" ]; then
> > +                               now=$(date +%s)
> > +                               wakeup_time=$((now + 15)) # Wake up after 15 seconds
> > +
> > +                               echo $wakeup_time > /sys/class/rtc/rtc0/wakealarm
> > +
> > +                               if [ $? -ne 0 ]; then
> > +                                       printf "Failed to set RTC wake alarm\n"
> > +                                       return 1
> > +                               fi
> > +
> > +                               # Enable the RTC as a wakeup source
> > +                               echo enabled > /sys/class/rtc/rtc0/device/power/wakeup
> > +
> > +                               if [ $? -ne 0 ]; then
> > +                                       printf "Failed to set RTC wake alarm\n"
> > +                                       return 1
> > +                               fi
> > +
> > +                               # Reset the wakeup alarm
> > +                               echo 0 > /sys/class/rtc/rtc0/wakealarm
> > +                       fi
> > +
> >                         echo $filename > $SYSFS/power/state
> >                         printf "Came out of $1\n"
> >
> > diff --git a/tools/testing/selftests/cpufreq/main.sh b/tools/testing/selftests/cpufreq/main.sh
> > index a0eb84cf7167..f12ff7416e41 100755
> > --- a/tools/testing/selftests/cpufreq/main.sh
> > +++ b/tools/testing/selftests/cpufreq/main.sh
> > @@ -24,6 +24,8 @@ helpme()
> >         [-t <basic: Basic cpufreq testing
> >              suspend: suspend/resume,
> >              hibernate: hibernate/resume,
> > +            suspend_rtc: suspend/resume back using the RTC wakeup alarm,
> > +            hibernate_rtc: hibernate/resume back using the RTC wakeup alarm,
> >              modtest: test driver or governor modules. Only to be used with -d or -g options,
> >              sptest1: Simple governor switch to produce lockdep.
> >              sptest2: Concurrent governor switch to produce lockdep.
> > @@ -76,7 +78,8 @@ parse_arguments()
> >                                 helpme
> >                                 ;;
> >
> > -                       t) # --func_type (Function to perform: basic, suspend, hibernate, modtest, sptest1/2/3/4 (default: basic))
> > +                       t) # --func_type (Function to perform: basic, suspend, hibernate,
> > +                          # suspend_rtc, hibernate_rtc, modtest, sptest1/2/3/4 (default: basic))
> >                                 FUNC=$OPTARG
> >                                 ;;
> >
> > @@ -121,6 +124,14 @@ do_test()
> >                 do_suspend "hibernate" 1
> >                 ;;
> >
> > +               "suspend_rtc")
> > +                do_suspend "suspend" 1 rtc
> > +                ;;
> > +
> > +                "hibernate_rtc")
> > +                do_suspend "hibernate" 1 rtc
> > +                ;;
> > +
> >                 "modtest")
> >                 # Do we have modules in place?
> >                 if [ -z $DRIVER_MOD ] && [ -z $GOVERNOR_MOD ]; then
> > --
> > 2.39.2
> >
> >
> _______________________________________________
> Kernel mailing list -- kernel@mailman.collabora.com
> To unsubscribe send an email to kernel-leave@mailman.collabora.com
> This list is managed by https://mailman.collabora.com


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-07-11 15:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-11 12:10 [PATCH] kselftest: cpufreq: Add RTC wakeup alarm Shreeya Patel
2024-07-11 12:13 ` Rafael J. Wysocki
2024-07-11 15:18   ` Shreeya Patel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox