On Tue, Sep 26, 2006 at 11:48:51AM +0200, Rafael J. Wysocki wrote:
> On Monday, 25 September 2006 23:35, Pavel Machek wrote:
 
> > > Implement the userspace part of "use platform mode to suspend machines".
> > > 
> > > Index: suspend.c
> > > ===================================================================
> > > RCS file: /cvsroot/suspend/suspend/suspend.c,v
> > > retrieving revision 1.57
> > > diff -u -p -r1.57 suspend.c
> > > --- suspend.c     24 Sep 2006 08:09:59 -0000      1.57
> > > +++ suspend.c     25 Sep 2006 17:37:53 -0000
> > > @@ -67,7 +67,7 @@ static char s2ram;
> > >  static char early_writeout;
> > >  static char splash_param;
> > >  #define SHUTDOWN_LEN     16
> > > -static char shutdown_method[SHUTDOWN_LEN];
> > > +static char shutdown_method[SHUTDOWN_LEN] = "platform";
> > >  
> > >  static int suspend_swappiness = SUSPEND_SWAPPINESS;
> > >  static struct splash splash;
> > > @@ -659,13 +659,18 @@ static int reset_signature(int fd)
> > >  }
> > >  #endif
> > >  
> > > -static void suspend_shutdown(void)
> > > +static void suspend_shutdown(int dev)
> > 
> > Can you perhaps call the parameter "snapshot_fd" to be consistent with
> > rest of code?

Ok,

> > 
> > > @@ -99,6 +104,21 @@ static inline int atomic_restore(int dev
> > >   return ioctl(dev, SNAPSHOT_ATOMIC_RESTORE, 0);
> > >  }
> > >  
> > > +static inline int platform_prepare(int dev)
> > > +{
> > > + return ioctl (dev, SNAPSHOT_PMOPS, PMOPS_FINISH);
> >                 ~ please do not  add space between function and
> >                   its arguments

Yes, sorry for that

> > Otherwise looks okay to me.
> 
> I'd prefer to have a variable, say use_platform_suspend, that is set to one
> in main() if shutdown_method contains the string "platform", so that we can
> get rid of the repeated strcmp(shutdown_method, "platform") invocations.

Yes, this was basically the first incarnation of the patch, then i figured
that a global variable might not be the best solution. I do not really care
though, so will change that.

> Also, when platform_finish() is called, the variable ret is not necessary, and
> we don't intend to implement S3 in suspend_shutdown() (s2both is for that).

Ok.

Next try:

===================================================================
RCS file: /cvsroot/suspend/suspend/suspend.c,v
retrieving revision 1.57
diff -u -p -r1.57 suspend.c
--- suspend.c   24 Sep 2006 08:09:59 -0000      1.57
+++ suspend.c   26 Sep 2006 10:58:05 -0000
@@ -67,7 +67,8 @@ static char s2ram;
 static char early_writeout;
 static char splash_param;
 #define SHUTDOWN_LEN   16
-static char shutdown_method[SHUTDOWN_LEN];
+static char shutdown_method[SHUTDOWN_LEN] = "platform";
+static int use_platform_suspend;
 
 static int suspend_swappiness = SUSPEND_SWAPPINESS;
 static struct splash splash;
@@ -659,13 +660,17 @@ static int reset_signature(int fd)
 }
 #endif
 
-static void suspend_shutdown(void)
+static void suspend_shutdown(int snapshot_fd)
 {
-       /* todo: platform, S3 */
        if (!strcmp(shutdown_method, "reboot"))
                reboot();
-       else
-               power_off();
+       else if (use_platform_suspend) {
+               int ret = platform_enter(snapshot_fd);
+               if (ret < 0)
+                       fprintf(stderr, "suspend: pm_ops->enter returned"
+                               " error %d, calling power_off\n", ret);
+       }
+       power_off();
        /* Signature is on disk, it is very dangerous to continue now.
         * We'd do resume with stale caches on next boot. */
        fprintf(stderr,"Powerdown failed. That's impossible.\n");
@@ -699,6 +704,13 @@ int suspend_system(int snapshot_fd, int 
        if (error)
                goto Unfreeze;
 
+       if (use_platform_suspend) {
+               int ret = platform_prepare(snapshot_fd);
+               if (ret < 0)
+                       fprintf(stderr, "suspend: pm_ops->prepare returned "
+                               "error %d\n", ret);
+       }
+
        printf("suspend: Snapshotting system\n");
        attempts = 2;
        do {
@@ -709,6 +721,8 @@ int suspend_system(int snapshot_fd, int 
                if (!atomic_snapshot(snapshot_fd, &in_suspend)) {
                        if (!in_suspend) {
                                free_snapshot(snapshot_fd);
+                               if (use_platform_suspend)
+                                       platform_finish(snapshot_fd);
                                break;
                        }
                        error = write_image(snapshot_fd, resume_fd);
@@ -716,14 +730,14 @@ int suspend_system(int snapshot_fd, int 
                                splash.progress(100);
 #ifdef CONFIG_BOTH
                                if (!s2ram) {
-                                       suspend_shutdown();
+                                       suspend_shutdown(snapshot_fd);
                                } else {
                                        /* If we die (and allow system to 
continue) between
                                          * now and reset_signature(), very bad 
things will
                                          * happen. */
                                        error = suspend_to_ram(snapshot_fd);
                                        if (error)
-                                               suspend_shutdown();
+                                               suspend_shutdown(snapshot_fd);
                                        reset_signature(resume_fd);
                                        free_swap_pages(snapshot_fd);
                                        free_snapshot(snapshot_fd);
@@ -731,7 +745,7 @@ int suspend_system(int snapshot_fd, int 
                                        goto Unfreeze;
                                }
 #else
-                               suspend_shutdown();
+                               suspend_shutdown(snapshot_fd);
 #endif
                        } else {
                                free_swap_pages(snapshot_fd);
@@ -1150,6 +1164,8 @@ int main(int argc, char *argv[])
        if (early_writeout != 'n' && early_writeout != 'N')
                early_writeout = 1;
 
+       use_platform_suspend = !strcmp(shutdown_method, "platform");
+
        page_size = getpagesize();
        buffer_size = BUFFER_PAGES * page_size;
 
Index: swsusp.h
===================================================================
RCS file: /cvsroot/suspend/suspend/swsusp.h,v
retrieving revision 1.27
diff -u -p -r1.27 swsusp.h
--- swsusp.h    24 Sep 2006 08:09:59 -0000      1.27
+++ swsusp.h    26 Sep 2006 10:58:05 -0000
@@ -26,7 +26,12 @@
 #define SNAPSHOT_FREE_SWAP_PAGES       _IO(SNAPSHOT_IOC_MAGIC, 9)
 #define SNAPSHOT_SET_SWAP_FILE         _IOW(SNAPSHOT_IOC_MAGIC, 10, unsigned 
int)
 #define SNAPSHOT_S2RAM                 _IO(SNAPSHOT_IOC_MAGIC, 11)
-#define SNAPSHOT_IOC_MAXNR     11
+#define SNAPSHOT_PMOPS                 _IOW(SNAPSHOT_IOC_MAGIC, 12, unsigned 
int)
+#define SNAPSHOT_IOC_MAXNR     12
+
+#define PMOPS_PREPARE  1
+#define PMOPS_ENTER    2
+#define PMOPS_FINISH   3
 
 #define        LINUX_REBOOT_MAGIC1     0xfee1dead
 #define        LINUX_REBOOT_MAGIC2     672274793
@@ -99,6 +104,21 @@ static inline int atomic_restore(int dev
        return ioctl(dev, SNAPSHOT_ATOMIC_RESTORE, 0);
 }
 
+static inline int platform_prepare(int dev)
+{
+       return ioctl(dev, SNAPSHOT_PMOPS, PMOPS_FINISH);
+}
+
+static inline int platform_enter(int dev)
+{
+       return ioctl(dev, SNAPSHOT_PMOPS, PMOPS_FINISH);
+}
+
+static inline int platform_finish(int dev)
+{
+       return ioctl(dev, SNAPSHOT_PMOPS, PMOPS_FINISH);
+}
+
 static inline int free_snapshot(int dev)
 {
        return ioctl(dev, SNAPSHOT_FREE, 0);
-- 
Stefan Seyfried                     | "Please, just tell people
QA / R&D Team Mobile Devices        |               to use KDE."
SUSE LINUX Products GmbH, Nürnberg  |          -- Linus Torvalds

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Suspend-devel mailing list
Suspend-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/suspend-devel

Reply via email to