Take a Snapshot (Compact 2013)

3/26/2014

At a high level, taking a snapshot consists of identifying the memory that has to be saved to storage, saving the CPU state, optionally compressing the resulting snapshot image, and writing the snapshot image to storage.

The following figure captures the order of function calls made to the OAL code that you write to take a snapshot.

Steps to take a snapshot

The following describes, at a high level, what occurs at each point in the process:

  1. After the device is booted and any applications that you want to include in the snapshot are running and in the state that you want, you issue an IOCTL_KLIB_MAKESNAP call to take the snapshot.
  2. OEMGetSnapshotRegions is an optional function and, if you provide it, it is the first function the OS calls to take the snapshot. From this function you report any OEM specific memory that the OS is not aware of that should be saved in the snapshot. For example, if you have display memory or memory that is shared between the OS and the OAL for global variables that is not known to the OS, report it here so that it will be included in the snapshot.
  3. Next, the OS calls your OEMTakeCPUSnapshot function in which you save the CPU state to a buffer that will be included in the snapshot.
  4. The OS has now identified all of the memory and state that will be saved in the snapshot, so it calls the optional OEMCompressSnapshot function. Compressing the snapshot is an optimization that can save storage space and time if there is less memory to transfer to and from persistent storage as a result of compressing it.
  5. The OS can now calculate how much memory is required to save the snapshot, so it calls the OEMPrepareSnapshot() function. Here you prepare the storage that you will use to store the snapshot. For example, if you are using storage such as NAND flash that must be erased before you can rewrite it, you will erase enough flash to hold the snapshot image. If you do not prepare the minimum amount of storage to store the snapshot, OEMWriteSnapshot will fail.
  6. Finally, the OS calls OEMWriteSnapshot to write the snapshot image to storage.

When you issue IOCTL_KLIB_MAKESNAP to take a snapshot, the OS pages all memory out to storage and suspends the device. It then resumes the device. This reduces the number of pages that will be stored in the snapshot, and the time that is required to save and restore the snapshot.

After the device resumes, the snapshot-taking process pauses for one minute. This delay provides an opportunity to start one or more applications by bringing them to the foreground. When you start an application by bringing it to the foreground, the OS pages memory back into RAM for the code and data that belong to that application. The memory will then be saved as part of the snapshot. This means that the application will respond more quickly after the device reboots.

The device is then suspended a final time, the snapshot is taken and written to storage, and the device is resumed. Because the snapshot is taken when the device is in the suspended state, drivers will be in the power-off state in the snapshot image. When you boot from a snapshot, you will have to reinitialize your drivers as if you were resuming from a cold boot. After booting from a snapshot and reinitializing the device, the device will be in the state it was in after the snapshot was taken.

Implement APIs to Take a Snapshot

Describes in detail the functions you must implement to take a snapshot.

Snapshot Boot Reference

Describes the snapshot boot programming elements.

Show: