home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1938 / README < prev    next >
Encoding:
Text File  |  1990-12-28  |  6.4 KB  |  139 lines

  1. pmckpt 0.95, 10/10/90.
  2. Placed into the public domain by Daniel J. Bernstein.
  3. Comments to him at brnstnd@nyu.edu. Please let him know if pmckpt works
  4. on your machine, and what applications you might have found for it.
  5.  
  6.  
  7. This is a beta release of pmckpt, the poor man's checkpointer.
  8.  
  9. The idea of a checkpointer is to save the state of a running process in
  10. a file, so that you can restore the process later where it left off.
  11. pmckpt is a cooperative checkpointer: you have to add checkpointing to
  12. your program explicitly. You can't just checkpoint a random executable
  13. without the source code.
  14.  
  15. Checkpointing has many uses. One is to have processes survive a crash.
  16. You just checkpoint the process periodically, and restart it if the
  17. system crashes. Another is to avoid long, complex initializations on
  18. startup; if you checkpoint after initialization, you won't have to waste
  19. the time again. Another is to transfer running programs between
  20. computers with the same architecture.
  21.  
  22. pmckpt is (should be, at least) much more portable than other available
  23. checkpointing systems, including undump and Condor. It just saves the
  24. data, stack, and heap (allocated memory) to a file. It doesn't try to
  25. read the infinite variety of core file formats. Most importantly, it
  26. doesn't use setjmp() or longjmp(), so your compiler can put variables
  27. and intermediate values into registers without any risk of destroying
  28. the values of those variables (as longjmp() usually does). It handles
  29. stacks in either direction. It also restores file positions and signal
  30. handlers.
  31.  
  32.  
  33. In any routine where you want to allow checkpointing:
  34.  
  35.   Put a CKPT VARS flush left on a line by itself at the top, right after
  36.   the {.
  37.  
  38.   Put a CKPT TOPS flush left on a line by itself after all the variables.
  39.   (Actually, you can have statements above CKPT TOPS; see below.)
  40.  
  41.   Put a CKPT POINT x y flush left on a line by itself anywhere that you
  42.   want to allow a checkpoint. x is declared as a variable, and y is
  43.   declared as a label, so be careful to use unique names.
  44.  
  45.   Put a CKPT BOTS flush left on a line by itself right before the final }.
  46.  
  47. You must #include "pmckpt.h" at the top of the file. This may seem like
  48. a lot of work for a checkpointer, but remember that the most advanced
  49. control structure used by pmckpt is goto. A setjmp()-based system may be
  50. easier to use, but it'll also lose variable values when you least expect
  51. it.
  52.  
  53.  
  54. IMPORTANT RULE:
  55.  
  56. You *MUST* have a CKPT POINT immediately before calling any subroutine
  57. that's checkpointed. (See the main() call of sub1(), line 39 of test.c.)
  58. There must be absolutely no side effects (and maybe no computation at
  59. all, depending on your compiler) between the CKPT POINT line and the
  60. call. You may have to rewrite the function call to achieve this.
  61.  
  62.  
  63. You schedule a checkpoint by calling ckpt_schedule(). At the next CKPT
  64. POINT, your program will save some crucial information, followed by its
  65. text, data, and stack, to the CHECKPOINT file. To set this filename to
  66. the value of the CKPTFN environment variable instead, call ckpt_init().
  67. (This also sets a temporary file name, default CHECKPOINT.TEMP, to the
  68. value of CKPTFNTEMP. The temporary file is used to ensure atomic
  69. checkpointing.) test.c shows how you can schedule a checkpoint on any
  70. interrupt. In practice you probably want to checkpoint at regular
  71. intervals, with whatever your system uses for a timer.
  72.  
  73.  
  74. To run your program starting from the checkpoint, run
  75.  
  76.   % checkpoint prog CHECKPOINT
  77.  
  78. where prog is the program name and CHECKPOINT is the checkpoint file
  79. name. If you're lucky, everything will work.
  80.  
  81. You can have statements after the variables and before CKPT TOPS. These
  82. statements form the ``preamble.'' They're executed every time the
  83. function is entered, whether in normal execution or as part of a
  84. restore. You should be very careful with statements in a preamble, as
  85. you will lose any variable values set in a preamble during a restore.
  86. One safe use of the preamble is at the top of main(), to open files
  87. (perhaps passed as arguments to the program) in a fixed order. In fact,
  88. if you don't do this, files opened within the program won't be reopened
  89. on a restore.
  90.  
  91.  
  92. To compile a pmckpt program, such as test.c, run the following:
  93.  
  94.   % ckptcvt < test.c > tmp.c
  95.   % cc -c tmp.c
  96.   % cc -o tmp pmckpt.o tmp.o pmceot.o
  97.  
  98. tmp can be any name. Make sure that pmckpt.o comes before all other .o's
  99. loaded (except maybe crt0---though this probably leads to bugs), and
  100. pmceot.o comes after all .o's loaded. You shouldn't have to worry about
  101. dynamic loading on Suns, or other weird schemes; pmckpt is pretty
  102. portable, for a checkpointer.
  103.  
  104. Finally, to complete our outside-in tour of pmckpt, you have to compile
  105. the pmckpt library itself before using it in programs as above. To do
  106. this, edit the options in Makefile and type ``make''.
  107.  
  108.  
  109. To test pmckpt, compile test.c into tmp by the above instructions. Run
  110. tmp. You should see 13 lines of output. Run it again; a CKPT POINT comes
  111. after each output, so if you type ^C, the program will save state after
  112. the next output in CHECKPOINT. Try typing ^C at any moment. If you run
  113. % checkpoint tmp CHECKPOINT, the program should restart from where it
  114. left off. ^C works after a restore too, so a single program can
  115. checkpoint and restart any number of times.
  116.  
  117. For a more sophisticated test, try redirecting the output of tmp to a
  118. file. tail -f file & to see what's happening. Type ^C after a few
  119. seconds; after a few seconds more, to simulate a system crash, interrupt
  120. the process with ^\ (or whatever your interrupt key is). tmp will dump
  121. core. Kill the tail, and restore tmp from CHECKPOINT, redirecting output
  122. to the same file with >>. When it finishes, look at the file. tmp should
  123. have moved back to the location of the first checkpoint, so that output
  124. between the checkpoint and the ``crash'' won't have been written twice.
  125. In other words, you shouldn't be able to tell from looking at the file
  126. that tmp had crashed at all.
  127.  
  128. Try running the last test again, but don't kill the tail. What should
  129. happen is that what shows up on your tty is the correct output in order,
  130. and what ends up in foo is the correct output in order---even though
  131. some output is written between the last checkpoint and the crash! The
  132. reason that tail doesn't write anything twice to your tty is that it
  133. doesn't go backwards in the file when pmckpt does.
  134.  
  135.  
  136. Internally, pmckpt wends its way down through the saved process stack to
  137. get to where it was before. Run a post-ckptcvt program through cpp if
  138. you want to see what's going on.
  139.