Chinaunix首页 | 论坛 | 博客
  • 博客访问: 250254
  • 博文数量: 101
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 95
  • 用 户 组: 普通用户
  • 注册时间: 2011-12-12 12:35
文章分类

全部博文(101)

文章存档

2016年(5)

2015年(16)

2014年(37)

2013年(32)

2012年(8)

2011年(3)

我的朋友

分类: LINUX

2014-09-18 15:06:18

Something about software suspend (swsusp)

What is swsusp(sofeware suspend)?

swsusp (Software Suspend) is a suspend-to-disk implementation in the 2.6 series . It is the equivalent of functionality. To be simple, Software suspend is the ability to freeze the kernel state and dump it on disk, then restore it upon resuming. This allows to completely stop a computer for a long period while keeping an internal session opened.

Open swsusp feature

To enable swsusp, the following should be selected during kernel configuration:

Power management options → <*>Power management support (CONFIG_PM)

Power management options → <*>Software Suspend (CONFIG_SOFTWARE_SUSPEND)

Power management options → [/dev/resume_partition]Default resume partition (CONFIG_PM_STD_PARTITION)

Do swsusp

. mount sysfs

 # mkdir /sys

 # mount -t sysfs none /sys

. enable flash as swap

  # mkswap /dev/mtdblock3

  # swapon /dev/mtdblock3

. trigger suspend to disk

  # echo disk > /sys/power/state

After the suspend to disk is triggered, messages are emitted to console, and machine would halt.

On next bootup of the board, pass below additional argument to kernel:

resume=/dev/mtdblock3

Below is an example:

#setenv bootargs console=ttyS0,115200n8 ip=dhcp root=/dev/nfs resume=/dev/mtdblock3

# saveenv

 

Implement swsusp(s2disk)

Suspend procedure

The suspend procedure is shown below:

1. Trigger

Suspend procedure is triggered from writing disk to /sys/power/state operation. The call stack to the entrance of the suspend procedure is shown as below.

sys_write()

+-vfs_write()

+-sysfs_write_file()

+-flush_write_buffer()

+-subsys_attr_store()

+-state_store()

+-enter_state()

+-pm_suspend_disk()

suspend

2. Freeze processes

This is done by calling the freeze_processes() procedure. It freezes user processes, and then freezes kernel tasks.

3. Free unnecessary memory

This is done by calling the free_some_memory() procedure. It calls shrink_all_memory() inside.

4. Suspend devices

This is done by calling the device_suspend() procedure. It calls suspend_device() and then the suspend() method for all listed active devices.

5. Power down devices

This is done by calling the device_power_down() procedure. It calls suspend_device() to for all listed power off devices.

6. Save processor state

This is done by calling the save_processor_state() procedure. It will save registers other than generic ones, such as segment registers, co-processor registers, and so on.

7. Save processor registers

This is done by calling the swsusp_arch_suspend() procedure. It will save general registers. This is written in assembly language, since the stack may not be used.

8. Allocate memory for snapshot image

This is done by calling the swsusp_alloc() procedure. Page directories get allocated by calling __get_free_pages(), and pages for the image itself gets allocated by get_zeroes_page() for each page directory entry.

9. Copy memory contents to allocated area

This is done by calling the copy_data_pages() procedure. It calls memcpy() for each page to copy.

10. Restore processor state

This is done by calling the restore_processor_state() procedure in swsusp_suspend(). This

is where the software suspend resume procedure comes back. It restores the previously saved processor state.

11. Power up devices

This is done by calling the device_power_up() procedure. It resumes system devices and all listed power off device.

12. Resume devices

This is done by calling the device_resume() procedure. It resumes devices in power off device list.

13. Write page, pagedir, header image to swap

Now that the devices are active, write to swap could be performed. This is done by calling the write_suspend_image() procedure. It writes image data, page directories, and then image header into swap.

14. Power down devices

This is done by calling the device_shutdown() procedure. It calls the shutdown() method for each device. Then, the system device is shutdown.

15. Halt machine

This is done by calling the machine_power_off() procedure. It calls pm_power_off() and the machine halts.

 

Resume procedure

The resume procedure is shown below:

1. Start resume

Resume starts by calling the software_resume() procedure in do_initcalls(), at late_initcall

timing.

2. Check kernel parameter

In software_resume(), it checks for the kernel command line for the resume swap device.

3. Check signature and header of snapshot image

This is done by calling the check_sig() and check_header() procedures. It checks swap image signature for snapshot image, and that the header for the kernel used for suspend and resume is the same.

4. Allocate memory space for snapshot image

5. Read page directory into allocated memory

This is done by calling the read_pagedir() procedure. It allocates page directory memory space by using __get_free_pages() and reads page directory information with bio_read_page().

6. Relocate page directory (if necessary)

7. Read swap image into allocated memory

This is done by calling the data_read() procedure. The page directory area gets relocated if it collides with the snapshot image. Then the snapshot image is read from swap with bio_read_page().

8. Prepare resume

9. Freeze process

10. Free unnecessary memory

11. Suspend devices

These steps are taken to accomplish consistency between suspend and resume, and in case resume fails. These steps are same as Steps 2 to 4 of the suspend procedure.

12. Power down devices

This step is taken to accomplish consistency between suspend and resume. This step is same as Step 5 of the suspend procedure.

13. Save processor state

These steps are taken in case resume fails. These steps are same as Step 6 of the suspend procedure.

14. Copy snapshot image in allocated memory to its original address

15. Restore processor registers

This is done by calling the swsusp_arch_resume() procedure. It copies all image pages from the allocated memory address to its original memory address. It also restores general purpose registers. Since registers are restored, the return address used by this function would be the same as the one in effect for the swsusp_arch_suspend() procedure call at suspend time.

16. Restore processor state

17. Power up devices

This is exactly the same as Steps 10 to 11 of the suspend procedure.

18. Free memory allocated for image

This is done by calling the free_image_pages() procedure. It does free_page() for all pages in image. Page directories are also freed.

19. Resume devices

This is done by calling the device_resume() procedure. The process is the same as Step 12 of the suspend procedure.

20. Thaw processes

This is done by calling the thaw_processes() procedure. This wakes up every thread by calling the wake_up_process() procedure.

 


 

The corresponding block diagrams are draw as below:


References

[1] Suspend To Disk For ARM

[2] Software-suspend-linux-mini-HOWTO

 

[3] Software suspend feature

[4] µswsusp

[5] Improving Linux Startup Time Using Software Resume and other techniques.pdf

文件:Improving_Linux_Startup_Time_Using_Software_Resume_and_other_techniques.pdf
大小:177KB
下载:下载


阅读(683) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~