From: Pavel M. <pa...@uc...> - 2002-05-21 22:30:25
|
Hi! Here's suspend-to-{RAM,disk} combined patch for 2.5.17. Suspend-to-disk is pretty stable and was tested in 2.4-ac. Suspend-to-RAM is little more experimental, but works for me, and is certainly better than disk-eating version currently in kernel. Major parts are: process stopper, S3 specific code, S4 specific code. What can I do to make this applied? Pavel --- clean/Documentation/driver-model.txt Sun Mar 10 20:06:28 2002 +++ linux-swsusp/Documentation/driver-model.txt Fri May 3 00:08:35 2002 @@ -52,7 +52,8 @@ Each bus layer should implement the callbacks for these drivers. It then forwards the calls on to the device-specific callbacks. This means that device-specific drivers must still implement callbacks for each operatio= n. -But, they are not called from the top level driver layer. +But, they are not called from the top level driver layer. [So for exampl= e +PCI devices will not call device_register but pci_device_register.] =20 This does add another layer of indirection for calling one of these func= tions, but there are benefits that are believed to outweigh this slowdown. @@ -60,7 +61,7 @@ First, it prevents device-specific drivers from having to know about the global device layer. This speeds up integration time incredibly. It also allows drivers to be more portable across kernel versions. Note that the -former was intentional, the latter is an added bonus. +former was intentional, the latter is an added bonus.=20 =20 Second, this added indirection allows the bus to perform any additional = logic necessary for its child devices. A bus layer may add additional informat= ion to @@ -225,7 +226,6 @@ It also allows the platform driver (e.g. ACPI) to a driver without the = driver having to have explicit knowledge of (atrocities like) ACPI. =20 - current_state: Current power state of the device. For PCI and other modern devices, th= is is 0-3, though it's not necessarily limited to those values. @@ -251,18 +251,24 @@ } =20 probe: - Check for device existence and associate driver with it. + Check for device existence and associate driver with it. In case of dev= ice=20 + insertion, *all* drivers are called. Struct device has parent and bus_i= d=20 + valid at this point. probe() may only be called from process context. R= eturns + 0 if it handles that device, -ESRCH if this driver does not know how to= handle + this device, valid error otherwise. =20 remove: Dissociate driver with device. Releases device so that it could be used= by another driver. Also, if it is a hotplug device (hotplug PCI, Cardbus),= an - ejection event could take place here. + ejection event could take place here. remove() can be called from inter= rupt=20 + context. [Fixme: Is that good?] Returns 0 on success. [Can we recover f= rom + failed remove or should I define that remove() never fails?] =20 suspend: - Perform one step of the device suspend process. + Perform one step of the device suspend process. Returns 0 on success. =20 resume: - Perform one step of the device resume process. + Perform one step of the device resume process. Returns 0 on success. =20 The probe() and remove() callbacks are intended to be much simpler than = the current PCI correspondents. @@ -275,7 +281,7 @@ =20 Some device initialisation was done in probe(). This should not be the c= ase anymore. All initialisation should take place in the open() call for the -device. +device. [FIXME: How do you "open" uhci?] =20 Breaking initialisation code out must also be done for the resume() call= back, as most devices will have to be completely reinitialised when coming bac= k from @@ -324,6 +330,7 @@ =20 enum{ SUSPEND_NOTIFY, + SUSPEND_DISABLE, SUSPEND_SAVE_STATE, SUSPEND_POWER_DOWN, }; @@ -331,6 +338,7 @@ enum { RESUME_POWER_ON, RESUME_RESTORE_STATE, + RESUME_ENABLE, }; =20 =20 @@ -352,9 +360,9 @@ Instead, the walking of the device tree has been moved to userspace. Whe= n a user requests the system to suspend, it will walk the device tree, as ex= ported via driverfs, and tell each device to go to sleep. It will do this multi= ple -times based on what the system policy is. - -[ FIXME: URL pointer to the corresponding utility is missing here! ] +times based on what the system policy is. [Not possible. Take ACPI enabl= ed=20 +system, with battery critically low. In such state, you want to suspend-= to-disk, +*fast*. User maybe is not even running powerd (think system startup)!] =20 Device resume should happen in the same manner when the system awakens. =20 @@ -366,22 +374,25 @@ cannot resume the hardware from the requested level, or it feels that it= is too important to be put to sleep, it should return an error from this fu= nction. =20 -It does not have to stop I/O requests or actually save state at this poi= nt. +It does not have to stop I/O requests or actually save state at this poi= nt. Called +from process context. =20 SUSPEND_DISABLE: =20 The driver should stop taking I/O requests at this stage. Because the sa= ve state stage happens afterwards, the driver may not want to physically di= sable -the device; only mark itself unavailable if possible. +the device; only mark itself unavailable if possible. Called from proces= s=20 +context. =20 SUSPEND_SAVE_STATE: =20 The driver should allocate memory and save any device state that is rele= vant -for the state it is going to enter. +for the state it is going to enter. Called from process context. =20 SUSPEND_POWER_DOWN: =20 -The driver should place the device in the power state requested. +The driver should place the device in the power state requested. May be = called +from interrupt context. =20 =20 For resume, the stages are defined as follows: @@ -389,25 +400,27 @@ RESUME_POWER_ON: =20 Devices should be powered on and reinitialised to some known working sta= te. +Called from process context. =20 RESUME_RESTORE_STATE: =20 The driver should restore device state to its pre-suspend state and free= any -memory allocated for its saved state. +memory allocated for its saved state. Called from process context. =20 RESUME_ENABLE: =20 -The device should start taking I/O requests again. +The device should start taking I/O requests again. Called from process c= ontext. =20 =20 Each driver does not have to implement each stage. But, it if it does -implemente a stage, it should do what is described above. It should not = assume +implement a stage, it should do what is described above. It should not a= ssume that it performed any stage previously, or that it will perform any stag= e -later. +later. [Really? It makes sense to support SAVE_STATE only after DISABLE]. =20 It is quite possible that a driver can fail during the suspend process, = for whatever reason. In this event, the calling process must gracefully reco= ver -and restore everything to their states before the suspend transition beg= an. +and restore everything to their states before the suspend transition beg= an.=20 +[Suspend may not fail, think battery low.] =20 If a driver knows that it cannot suspend or resume properly, it should f= ail during the notify stage. Properly implemented power management schemes s= hould --- clean/Documentation/swsusp.txt Sat Jan 5 21:39:47 2002 +++ linux-swsusp/Documentation/swsusp.txt Fri May 3 00:08:35 2002 @@ -0,0 +1,159 @@ +From kernel/suspend.c: + + * BIG FAT WARNING *****************************************************= **** + * + * If you have unsupported (*) devices using DMA... + * ...say goodbye to your data. + * + * If you touch anything on disk between suspend and resume... + * ...kiss your data goodbye. + * + * If your disk driver does not support suspend... (IDE does) + * ...you'd better find out how to get along + * without your data. + * + * (*) pm interface support is needed to make it safe. + +You need to append resume=3D/dev/your_swap_partition to kernel command +line. Then you suspend by echo 4 > /proc/acpi/sleep. + +[Notice. Rest docs is pretty outdated (see date!) It should be safe to +use swsusp on ext3/reiserfs these days.] + + +Article about goals and implementation of Software Suspend for Linux +Author: G=82=E1bor Kuti +Last revised: 2002-04-08 + +Idea and goals to achieve + +Nowadays it is common in several laptops that they have a suspend button= . It +saves the state of the machine to a filesystem or to a partition and swi= tches +to standby mode. Later resuming the machine the saved state is loaded ba= ck to +ram and the machine can continue its work. It has two real benefits. Fir= st we +save ourselves the time machine goes down and later boots up, energy cos= ts +real high when running from batteries. The other gain is that we don't h= ave to +interrupt our programs so processes that are calculating something for a= long +time shouldn't need to be written interruptible. + +On desk machines the power saving function isn't as important as it is i= n +laptops but we really may benefit from the second one. Nowadays the numb= er of +desk machines supporting suspend function in their APM is going up but t= here +are (and there will still be for a long time) machines that don't even s= upport +APM of any kind. On the other hand it is reported that using APM's suspe= nd +some irqs (e.g. ATA disk irq) is lost and it is annoying for the user un= til +the Linux kernel resets the device. + +So I started thinking about implementing Software Suspend which doesn't = need +any APM support and - since it uses pretty near only high-level routines= - is +supposed to be architecture independent code. + +Using the code + +The code is experimental right now - testers, extra eyes are welcome. To +compile this support into the kernel, you need CONFIG_EXPERIMENTAL,=20 +and then CONFIG_SOFTWARE_SUSPEND in menu General Setup to be enabled. I= t +cannot be used as a module and I don't think it will ever be needed. + +You have two ways to use this code. The first one is if you've compiled = in +sysrq support then you may press Sysrq-D to request suspend. The other w= ay +is with a patched SysVinit (my patch is against 2.76 and available at my +home page). You might call 'swsusp' or 'shutdown -z <time>'. Next way is= to +echo 4 > /proc/acpi/sleep. + +Either way it saves the state of the machine into active swaps and then +reboots. You must explicitly specify the swap partition to resume from w= ith ``resume=3D'' +kernel option. If signature is found it loads and restores saved state. = If the +option ``noresume'' is specified as a boot parameter, it skips the resum= ing. +Warning! Look at section ``Things to implement'' to see what isn't yet +implemented. Also I strongly suggest you to list all active swaps in +/etc/fstab. Firstly because you don't have to specify anything to resume= and +secondly if you have more than one swap area you can't decide which one = has the +'root' signature.=20 + +In the meantime while the system is suspended you should not touch any o= f the +hardware! + +About the code +Goals reached + +The code can be downloaded from +http://falcon.sch.bme.hu/~seasons/linux/. It mainly works but there are = still +some of XXXs, TODOs, FIXMEs in the code which seem not to be too importa= nt. It +should work all right except for the problems listed in ``Things to +implement''. Notes about the code are really welcome. + +How the code works + +When suspending is triggered it immediately wakes up process bdflush. Bd= flush +checks whether we have anything in our run queue tq_bdflush. Since we qu= eued up +function do_software_suspend, it is called. Here we shrink everything in= cluding +dcache, inodes, buffers and memory (here mainly processes are swapped ou= t). We +count how many pages we need to duplicate (we have to be atomical!) then= we +create an appropiate sized page directory. It will point to the original= and +the new (copied) address of the page. We get the free pages by +__get_free_pages() but since it changes state we have to be able to trac= k it +later so it also flips in a bit in page's flags (a new Nosave flag). We +duplicate pages and then mark them as used (so atomicity is ensured). Af= ter +this we write out the image to swaps, do another sync and the machine ma= y +reboot. We also save registers to stack. + +By resuming an ``inverse'' method is executed. The image if exists is lo= aded, +loadling is either triggered by ``resume=3D'' kernel option. We +change our task to bdflush (it is needed because if we don't do this ini= t does +an oops when it is waken up later) and then pages are copied back to the= ir +original location. We restore registers, free previously allocated memor= y, +activate memory context and task information. Here we should restore har= dware +state but even without this the machine is restored and processes are co= ntinued +to work. I think hardware state should be restored by some list (using +notify_chain) and probably by some userland program (run-parts?) for use= rs' +pleasure. Check out my patch at the same location for the sysvinit patch. + +WARNINGS! +- It does not like pcmcia cards. And this is logical: pcmcia cards need = cardmgr to be + initialized. they are not initialized during singleuser boot, but "res= umed" kernel does + expect them to be initialized. That leads to armagedon. You should eje= ct any pcmcia cards + before suspending. + +Things to implement +- SMP support. I've done an SMP support but since I don't have access to= a kind + of this one I cannot test it. Please SMP people test it. .. Tested it= , + doesn't work. Had no time to figure out why. There is some mess with + interrupts AFAIK.. +- We should only make a copy of data related to kernel segment, since an= y + process data won't be changed. +- By copying pages back to their original position, copy_page caused Gen= eral + Protection Fault. Why? +- Hardware state restoring. Now there's support for notifying via the n= otify + chain, event handlers are welcome. Some devices may have microcodes lo= aded + into them. We should have event handlers for them aswell. +- We should support other architectures (There are really only some arch + related functions..) +- We should also restore original state of swaps if the ``noresume'' ker= nel + option is specified.. Or do we need such a feature to save state for s= ome + other time? Do we need some kind of ``several saved states''? (Linux-= HA + people?). There's been some discussion about checkpointing on linux-fu= ture. +- Should make more sanity checks. Or are these enough? + +Not so important ideas for implementing + +- If a real time process is running then don't suspend the machine. +- Is there any sense in compressing the outwritten pages? +- Support for power.conf file as in Solaris, autoshutdown, special + devicetypes support, maybe in sysctl. +- Introduce timeout for SMP locking. But first locking ought to work :O +- Pre-detect if we don't have enough swap space or free it instead of + calling panic. +- Support for adding/removing hardware while suspended? +- We should not free pages at the beginning so aggressively, most of the= m + go there anyway.. +- If X is active while suspending then by resuming calling svgatextmode + corrupts the virtual console of X.. (Maybe this has been fixed AFAIK). + +Any other idea you might have tell me! + +Contacting the author +If you have any question or any patch that solves the above or detected +problems please contact me at se...@fa.... I might delay +answering, sorry about that. + --- clean/MAINTAINERS Tue May 21 23:21:35 2002 +++ linux-swsusp/MAINTAINERS Tue May 21 23:33:30 2002 @@ -1446,6 +1446,14 @@ L: lin...@vg... S: Maintained =20 +SOFTWARE SUSPEND: +P: Gabor Kuti +M: se...@fa... +M: se...@ma... +L: http://lister.fornax.hu/mailman/listinfo/swsusp +W: http://falcon.sch.bme.hu/~seasons/linux +S: Maintained + SONIC NETWORK DRIVER P: Thomas Bogendoerfer M: tsb...@al... diff -ur -x .dep* -x .hdep* -x *.[oas] -x *~ -x #* -x *CVS* -x *.orig -x = *.rej -x *.old -x .menu* -x asm -x local.h -x System.map -x autoconf.h -x= compile.h -x version.h -x .version -x defkeymap.c -x uni_hash.tbl -x zIm= age -x vmlinux -x vmlinuz -x TAGS -x bootsect -x *RCS* -x conmakehash -x = map -x build -x build -x configure -x *target* -x *.flags -x *.bak clean/= arch/i386/Config.help linux-swsusp/arch/i386/Config.help --- clean/arch/i386/Config.help Thu May 2 21:12:02 2002 +++ linux-swsusp/arch/i386/Config.help Fri May 3 00:08:35 2002 @@ -940,3 +940,28 @@ CONFIG_DEBUG_OBSOLETE Say Y here if you want to reduce the chances of the tree compiling, and are prepared to dig into driver internals to fix compile errors. + +Software Suspend +CONFIG_SOFTWARE_SUSPEND + Enable the possibilty of suspendig machine. It doesn't need APM. + You may suspend your machine by either pressing Sysrq-d or with + 'swsusp' or 'shutdown -z <time>' (patch for sysvinit needed). It + creates an image which is saved in your active swaps. By the next + booting the kernel detects the saved image, restores the memory from + it and then it continues to run as before you've suspended. + If you don't want the previous state to continue use the 'noresume' + kernel option. However note that your partitions will be fsck'd and + you must re-mkswap your swap partitions/files. + + Right now you may boot without resuming and then later resume but + in meantime you cannot use those swap partitions/files which were + involved in suspending. Also in this case there is a risk that buffers + on disk won't match with saved ones. + + SMP is supported ``as-is''. There's a code for it but doesn't work. + There have been problems reported relating SCSI. + =20 + This option is about getting stable. However there is still some + absence of features. + + For more information take a look at Documentation/swsusp.txt. --- clean/arch/i386/boot/video.S Thu Jul 5 20:28:16 2001 +++ linux-swsusp/arch/i386/boot/video.S Sun May 19 16:23:15 2002 @@ -438,6 +438,7 @@ =20 # Setting of user mode (AX=3Dmode ID) =3D> CF=3Dsuccess mode_set: + movw %ax, %fs:(0x01fa) # Store mode for use in acpi_wakeup.S movw %ax, %bx cmpb $0xff, %ah jz setalias --- clean/arch/i386/config.in Mon May 13 23:26:57 2002 +++ linux-swsusp/arch/i386/config.in Wed May 8 23:40:20 2002 @@ -396,6 +396,9 @@ =20 mainmenu_option next_comment comment 'Kernel hacking' +if [ "$CONFIG_EXPERIMENTAL" =3D "y" ]; then + dep_bool 'Software Suspend' CONFIG_SOFTWARE_SUSPEND $CONFIG_PM +fi =20 bool 'Kernel debugging' CONFIG_DEBUG_KERNEL if [ "$CONFIG_DEBUG_KERNEL" !=3D "n" ]; then --- clean/arch/i386/defconfig Sun May 19 18:52:01 2002 +++ linux-swsusp/arch/i386/defconfig Sun May 19 19:03:14 2002 @@ -119,6 +119,7 @@ CONFIG_BINFMT_MISC=3Dy CONFIG_PM=3Dy # CONFIG_APM is not set +# CONFIG_SOFTWARE_SUSPEND is not set =20 # # Memory Technology Devices (MTD) --- clean/arch/i386/kernel/acpi.c Mon May 13 23:26:57 2002 +++ linux-swsusp/arch/i386/kernel/acpi.c Sun May 19 17:31:33 2002 @@ -44,6 +44,8 @@ #include <asm/pgalloc.h> #include <asm/io_apic.h> #include <asm/tlbflush.h> +#define ACPI_C +#include <asm/suspend.h> =20 =20 #define PREFIX "ACPI: " @@ -621,6 +623,34 @@ { acpi_wakeup_address =3D (unsigned long)alloc_bootmem_low(PAGE_SIZE); printk(KERN_DEBUG "ACPI: have wakeup address 0x%8.8lx\n", acpi_wakeup_a= ddress); +} + +/* + * (KG): Since we affect stack here, we make this function as flat and e= asy + * as possible in order to not provoke gcc to use local variables on the= stack. + * Note that on resume, all (expect nosave) variables will have the stat= e from + * the time of writing (suspend_save_image) and the registers (including= the + * stack pointer, but excluding the instruction pointer) will be loaded = with=20 + * the values saved at save_processor_context() time. + */ +void do_suspend_magic(int resume) +{ + /* DANGER WILL ROBINSON! + * + * If this function is too difficult for gcc to optimize, it will crash= and burn! + * see above. + * + * DO NOT TOUCH. + */ + if (!resume) { + save_processor_context(); + acpi_save_register_state((unsigned long)&&acpi_sleep_done); + acpi_enter_sleep_state(3); + return; + } +acpi_sleep_done: + restore_processor_context(); + printk("CPU context restored...\n"); } =20 #endif /*CONFIG_ACPI_SLEEP*/ --- clean/arch/i386/kernel/acpi_wakeup.S Thu May 2 21:12:03 2002 +++ linux-swsusp/arch/i386/kernel/acpi_wakeup.S Sun May 19 17:33:32 2002 @@ -3,6 +3,7 @@ #include <linux/linkage.h> #include <asm/segment.h> =20 +# Do we need to deal with A20? =20 ALIGN wakeup_start: @@ -10,8 +11,16 @@ wakeup_code_start =3D . .code16 =20 + movw $0xb800, %ax + movw %ax,%fs + movw $0x0e00 + 'L', %fs:(0x10) cli cld + =20 +# setup video mode +# movw $0x4117, %bx # 0x4000 for linear framebuffer +# movw $0x4f02, %ax +# int $0x10 =20 # setup data segment movw %cs, %ax @@ -20,6 +29,14 @@ movw %ax, %ds movw %ax, %ss mov $(wakeup_stack - wakeup_data), %sp # Private stack is needed for A= SUS board + movw $0x0e00 + 'S', %fs:(0x12)=09 + + movl real_magic - wakeup_data, %eax + cmpl $0x12345678, %eax + jne bogus_real_magic + + mov video_mode - wakeup_data, %ax + call mode_set =20 # set up page table movl (real_save_cr3 - wakeup_data), %eax @@ -28,40 +45,114 @@ # make sure %cr4 is set correctly (features, etc) movl (real_save_cr4 - wakeup_data), %eax movl %eax, %cr4 + movw $0xb800, %ax + movw %ax,%fs + movw $0x0e00 + 'i', %fs:(0x12) =20 # need a gdt lgdt real_save_gdt - wakeup_data =20 - movl %cr0, %eax - orl $0x80000001, %eax + movl (real_save_cr0 - wakeup_data), %eax movl %eax, %cr0 + movw $0x0e00 + 'n', %fs:(0x14) + + movl real_magic - wakeup_data, %eax + cmpl $0x12345678, %eax + jne bogus_real_magic =20 ljmpl $__KERNEL_CS,$wakeup_pmode_return =20 +bogus_real_magic: + movw $0x0e00 + 'B', %fs:(0x12) + jmp bogus_real_magic + +/* This code uses an extended set of video mode numbers. These include: + * Aliases for standard modes + * NORMAL_VGA (-1) + * EXTENDED_VGA (-2) + * ASK_VGA (-3) + * Video modes numbered by menu position -- NOT RECOMMENDED because of l= ack + * of compatibility when extending the table. These are between 0x00 and= 0xff. + */ +#define VIDEO_FIRST_MENU 0x0000 + +/* Standard BIOS video modes (BIOS number + 0x0100) */ +#define VIDEO_FIRST_BIOS 0x0100 + +/* VESA BIOS video modes (VESA number + 0x0200) */ +#define VIDEO_FIRST_VESA 0x0200 + +/* Video7 special modes (BIOS number + 0x0900) */ +#define VIDEO_FIRST_V7 0x0900 + +# Setting of user mode (AX=3Dmode ID) =3D> CF=3Dsuccess +mode_set: + movw %ax, %bx +#if 0 + cmpb $0xff, %ah + jz setalias + + testb $VIDEO_RECALC>>8, %ah + jnz _setrec + + cmpb $VIDEO_FIRST_RESOLUTION>>8, %ah + jnc setres +=09 + cmpb $VIDEO_FIRST_SPECIAL>>8, %ah + jz setspc + + cmpb $VIDEO_FIRST_V7>>8, %ah + jz setv7 +#endif +=09 + cmpb $VIDEO_FIRST_VESA>>8, %ah + jnc check_vesa +#if 0=09 + orb %ah, %ah + jz setmenu +#endif +=09 + decb %ah +# jz setbios Add bios modes later + +setbad: clc + ret + +check_vesa: + subb $VIDEO_FIRST_VESA>>8, %bh + orw $0x4000, %bx # Use linear frame buffer + movw $0x4f02, %ax # VESA BIOS mode set call + int $0x10 + cmpw $0x004f, %ax # AL=3D4f if implemented + jnz _setbad # AH=3D0 if OK + + stc + ret + +_setbad: jmp setbad + .code32 ALIGN =20 -.org 0x100 +.org 0x300 wakeup_data: .word 0 real_save_gdt: .word 0 .long 0 +real_save_cr0: .long 0 real_save_cr3: .long 0 real_save_cr4: .long 0 +real_magic: .long 0 +video_mode: .long 0 =20 -.org 0x300 +.org 0x500 wakeup_stack: wakeup_end: =20 wakeup_pmode_return: - # restore data segment movl $__KERNEL_DS, %eax - movw %ax, %ds - movw %ax, %es - - # and restore the stack - movw %ax, %ss - movl saved_esp, %esp + movl %eax, %ds + movw $0x0e00 + 'u', %ds:(0xb8016) =20 # restore other segment registers xorl %eax, %eax @@ -72,6 +163,30 @@ lgdt saved_gdt lidt saved_idt lldt saved_ldt + ljmp $(__KERNEL_CS),$1f +1: + movl %cr3, %eax + movl %eax, %cr3 + wbinvd + + # and restore the stack ... but you need gdt for this to work + movl $__KERNEL_DS, %eax + movw %ax, %ss + movw %ax, %ds + movw %ax, %es + movw %ax, %fs + movw %ax, %gs + movl saved_esp, %esp + + movw $0x0e00 + 'W', %ds:(0xb8018) + movl $(1024*1024*3), %ecx + movl $0, %esi + rep lodsb + movw $0x0e00 + 'O', %ds:(0xb8018) + + movl %cs:saved_magic2, %eax + cmpl $0x12345678, %eax + jne bogus_magic =20 # restore the other general registers movl saved_ebx, %ebx @@ -81,8 +196,21 @@ =20 # jump to place where we left off movl saved_eip,%eax + movw $0x0e00 + 'x', %ds:(0xb8018) + pushl %eax + popl %eax + movw $0x0e00 + '!', %ds:(0xb801a) jmp *%eax =20 +bogus_magic: + movw $0x0e00 + 'B', %ds:(0xb8018) + jmp bogus_magic + +bogus_magic2: + movw $0x0e00 + '2', %ds:(0xb8018) + jmp bogus_magic2 + =09 + ## # acpi_copy_wakeup_routine # @@ -113,23 +241,22 @@ movl %edx, real_save_cr3 - wakeup_start (%eax) movl %cr4, %edx movl %edx, real_save_cr4 - wakeup_start (%eax) + movl %cr0, %edx + movl %edx, real_save_cr0 - wakeup_start (%eax) sgdt real_save_gdt - wakeup_start (%eax) =20 + movl saved_videomode, %edx + movl %edx, video_mode - wakeup_start (%eax) + movl $0x12345678, real_magic - wakeup_start (%eax) + movl $0x12345678, saved_magic2 + # restore the regs we used popl %edi popl %esi ret =20 - .data ALIGN -# saved registers -saved_gdt: .long 0,0 -saved_idt: .long 0,0 -saved_ldt: .long 0 -saved_tss: .long 0 -saved_cr0: .long 0 - ENTRY(saved_ebp) .long 0 ENTRY(saved_esi) .long 0 ENTRY(saved_edi) .long 0 @@ -137,3 +264,16 @@ =20 ENTRY(saved_eip) .long 0 ENTRY(saved_esp) .long 0 + +ENTRY(saved_magic) .long 0 +ENTRY(saved_magic2) .long 0=09 +ENTRY(saved_videomode) .long 0 + +ALIGN +# saved registers +saved_gdt: .long 0,0 +saved_idt: .long 0,0 +saved_ldt: .long 0 +saved_tss: .long 0 +saved_cr0: .long 0 + --- clean/arch/i386/kernel/apm.c Thu May 2 21:12:03 2002 +++ linux-swsusp/arch/i386/kernel/apm.c Fri May 3 00:08:35 2002 @@ -1667,6 +1667,7 @@ daemonize(); =20 strcpy(current->comm, "kapmd"); + current->flags |=3D PF_IOTHREAD; sigfillset(¤t->blocked); =20 if (apm_info.connection_version =3D=3D 0) { --- clean/arch/i386/kernel/i8259.c Thu May 2 21:12:03 2002 +++ linux-swsusp/arch/i386/kernel/i8259.c Fri May 3 00:08:35 2002 @@ -11,6 +11,7 @@ #include <linux/smp_lock.h> #include <linux/init.h> #include <linux/kernel_stat.h> +#include <linux/device.h> =20 #include <asm/atomic.h> #include <asm/system.h> @@ -237,7 +238,19 @@ } } =20 -void __init init_8259A(int auto_eoi) +static struct device device_i8259A =3D { + name: "i8259A", + bus_id: "0020", +}; + +static void __init init_8259A_devicefs(void) +{ + register_sys_device(&device_i8259A); +} + +__initcall(init_8259A_devicefs); + +void init_8259A(int auto_eoi) { unsigned long flags; =20 --- clean/arch/i386/kernel/setup.c Sun May 19 18:52:01 2002 +++ linux-swsusp/arch/i386/kernel/setup.c Sun May 19 19:03:14 2002 @@ -168,6 +168,8 @@ static int disable_x86_serial_nr __initdata =3D 1; static int disable_x86_fxsr __initdata =3D 0; =20 +extern unsigned long saved_videomode; + /* * This is set up by the setup-routine at boot-time */ @@ -182,6 +184,7 @@ #define SYS_DESC_TABLE (*(struct sys_desc_table_struct*)(PARAM+0xa0)) #define MOUNT_ROOT_RDONLY (*(unsigned short *) (PARAM+0x1F2)) #define RAMDISK_FLAGS (*(unsigned short *) (PARAM+0x1F8)) +#define VIDEO_MODE (*(unsigned short *) (PARAM+0x1FA)) #define ORIG_ROOT_DEV (*(unsigned short *) (PARAM+0x1FC)) #define AUX_DEVICE_INFO (*(unsigned char *) (PARAM+0x1FF)) #define LOADER_TYPE (*(unsigned char *) (PARAM+0x210)) @@ -681,6 +684,8 @@ drive_info =3D DRIVE_INFO; screen_info =3D SCREEN_INFO; apm_info.bios =3D APM_BIOS_INFO; + saved_videomode =3D VIDEO_MODE; + printk("Video mode to be used for restore is %lx\n", saved_videomode); if( SYS_DESC_TABLE.length !=3D 0 ) { MCA_bus =3D SYS_DESC_TABLE.table[3] &0x2; machine_id =3D SYS_DESC_TABLE.table[0]; --- clean/arch/i386/kernel/signal.c Mon May 13 23:27:07 2002 +++ linux-swsusp/arch/i386/kernel/signal.c Mon May 13 23:02:53 2002 @@ -21,6 +21,7 @@ #include <linux/tty.h> #include <linux/personality.h> #include <linux/binfmts.h> +#include <linux/suspend.h> #include <asm/ucontext.h> #include <asm/uaccess.h> #include <asm/i387.h> @@ -594,6 +595,11 @@ if ((regs->xcs & 3) !=3D 3) return 1; =20 + if (current->flags & PF_FREEZE) { + refrigerator(0); + goto no_signal; + } + if (!oldset) oldset =3D ¤t->blocked; =20 @@ -701,6 +707,7 @@ return 1; } =20 + no_signal: /* Did we come from a system call? */ if (regs->orig_eax >=3D 0) { /* Restart the system call - no handlers present */ diff -ur -x .dep* -x .hdep* -x *.[oas] -x *~ -x #* -x *CVS* -x *.orig -x = *.rej -x *.old -x .menu* -x asm -x local.h -x System.map -x autoconf.h -x= compile.h -x version.h -x .version -x defkeymap.c -x uni_hash.tbl -x zIm= age -x vmlinux -x vmlinuz -x TAGS -x bootsect -x *RCS* -x conmakehash -x = map -x build -x build -x configure -x *target* -x *.flags -x *.bak clean/= arch/i386/kernel/time.c linux-swsusp/arch/i386/kernel/time.c --- clean/arch/i386/kernel/time.c Sun Mar 10 20:06:31 2002 +++ linux-swsusp/arch/i386/kernel/time.c Fri May 3 00:08:35 2002 @@ -42,6 +42,7 @@ #include <linux/init.h> #include <linux/smp.h> #include <linux/module.h> +#include <linux/device.h> =20 #include <asm/io.h> #include <asm/smp.h> @@ -635,6 +636,17 @@ bad_ctc: return 0; } + +static struct device device_i8253; + +static void time_init_driverfs(void) +{ + strcpy(device_i8253.name, "i8253"); + strcpy(device_i8253.bus_id, "0040"); + register_sys_device(&device_i8253); +} + +__initcall(time_init_driverfs); =20 void __init time_init(void) { --- clean/arch/i386/vmlinux.lds Sun May 19 18:52:01 2002 +++ linux-swsusp/arch/i386/vmlinux.lds Sun May 19 19:03:14 2002 @@ -66,6 +66,12 @@ __init_end =3D .; =20 . =3D ALIGN(4096); + __nosave_begin =3D .; + .data_nosave : { *(.data.nosave) } + . =3D ALIGN(4096); + __nosave_end =3D .; + + . =3D ALIGN(4096); .data.page_aligned : { *(.data.idt) } =20 . =3D ALIGN(32); --- clean/drivers/acpi/acpi_system.c Thu Apr 18 22:45:30 2002 +++ linux-swsusp/drivers/acpi/acpi_system.c Sun May 19 17:25:33 2002 @@ -33,6 +33,7 @@ #include <linux/delay.h> #include <linux/sysrq.h> #include <linux/pm.h> +#include <linux/device.h> #include <asm/uaccess.h> #include <asm/acpi.h> #include "acpi_bus.h" @@ -128,6 +129,12 @@ /* restore device context */ device_resume(RESUME_RESTORE_STATE); #endif + + if (dmi_broken & BROKEN_INIT_AFTER_S1) { + printk("Broken toshiba laptop -> kicking interrupts\n"); + init_8259A(0); + } + return AE_OK; } =20 @@ -254,23 +261,21 @@ switch (state) { case ACPI_STATE_S1: - /* do nothing */ + barrier(); + status =3D acpi_enter_sleep_state(state); break; =20 case ACPI_STATE_S2: case ACPI_STATE_S3: - acpi_save_register_state((unsigned long)&&acpi_sleep_done); + do_suspend_magic(0); break; } =20 - barrier(); - status =3D acpi_enter_sleep_state(state); - -acpi_sleep_done: - + printk("acpi_restore_register_state..."); acpi_restore_register_state(); restore_flags(flags); =20 + printk("acpi returning..."); return status; } =20 @@ -290,6 +295,8 @@ if (state < ACPI_STATE_S1 || state > ACPI_STATE_S5) return AE_ERROR; =20 + freeze_processes(); + /* do we have a wakeup address for S2 and S3? */ if (state =3D=3D ACPI_STATE_S2 || state =3D=3D ACPI_STATE_S3) { if (!acpi_wakeup_address) @@ -315,7 +322,9 @@ * no matter what. */ acpi_system_restore_state(state); + printk("acpi_leave_sleep_state..."); acpi_leave_sleep_state(state); + printk("ook\n"); =20 /* make sure interrupts are enabled */ ACPI_ENABLE_IRQS(); @@ -323,6 +332,8 @@ /* reset firmware waking vector */ acpi_set_firmware_waking_vector((ACPI_PHYSICAL_ADDRESS) 0); =20 + thaw_processes(); + return status; } =20 @@ -700,8 +773,17 @@ =09 if (!system->states[state]) return_VALUE(-ENODEV); + =09 +#ifdef CONFIG_SOFTWARE_SUSPEND + if (state =3D=3D 4) { + /* We are working from process context, that's why we may call it dire= ctly. */=20 + do_software_suspend(); + return_VALUE(count); + } +#endif status =3D acpi_suspend(state); + if (ACPI_FAILURE(status)) return_VALUE(-ENODEV); =09 @@ -1180,6 +1262,10 @@ } } printk(")\n"); +#ifdef CONFIG_SOFTWARE_SUSPEND + printk(KERN_INFO "Software suspend =3D> we can do S4."); + system->states[4] =3D 1; +#endif =20 #ifdef CONFIG_PM /* Install the soft-off (S5) handler. */ --- clean/drivers/block/floppy.c Tue May 21 23:21:37 2002 +++ linux-swsusp/drivers/block/floppy.c Tue May 21 23:33:32 2002 @@ -173,6 +173,7 @@ #include <linux/interrupt.h> #include <linux/init.h> #include <linux/devfs_fs_kernel.h> +#include <linux/device.h> =20 /* * PS/2 floppies have much slower step rates than regular floppies. @@ -4178,11 +4179,15 @@ =20 static int have_no_fdc=3D -ENODEV; =20 +static struct device device_floppy; =20 int __init floppy_init(void) { int i,unit,drive; =20 + strcpy(device_floppy.name, "floppy"); + strcpy(device_floppy.bus_id, "03?0"); + register_sys_device(&device_floppy); =20 raw_cmd =3D NULL; =20 --- clean/drivers/block/ll_rw_blk.c Tue May 21 23:21:37 2002 +++ linux-swsusp/drivers/block/ll_rw_blk.c Tue May 21 23:33:32 2002 @@ -1418,7 +1419,9 @@ req->buffer =3D bio_data(bio); /* see ->buffer comment above */ req->waiting =3D NULL; req->bio =3D req->biotail =3D bio; - req->rq_dev =3D to_kdev_t(bio->bi_bdev->bd_dev); + if (bio->bi_bdev) + req->rq_dev =3D to_kdev_t(bio->bi_bdev->bd_dev); + else req->rq_dev =3D NODEV; add_request(q, req, insert_here); out: if (freereq) --- clean/drivers/block/loop.c Mon May 13 22:30:12 2002 +++ linux-swsusp/drivers/block/loop.c Mon May 6 11:39:11 2002 @@ -71,11 +71,11 @@ #include <linux/smp_lock.h> #include <linux/swap.h> #include <linux/slab.h> +#include <linux/loop.h> +#include <linux/suspend.h> =20 #include <asm/uaccess.h> =20 -#include <linux/loop.h> =09 - #define MAJOR_NR LOOP_MAJOR =20 static int max_loop =3D 8; @@ -534,6 +534,7 @@ daemonize(); =20 sprintf(current->comm, "loop%d", lo->lo_number); + current->flags |=3D PF_IOTHREAD; =20 spin_lock_irq(¤t->sigmask_lock); sigfillset(¤t->blocked); --- clean/drivers/char/sysrq.c Thu Mar 21 11:35:58 2002 +++ linux-swsusp/drivers/char/sysrq.c Fri May 3 00:08:35 2002 @@ -27,6 +27,7 @@ #include <linux/quotaops.h> #include <linux/smp_lock.h> #include <linux/module.h> +#include <linux/suspend.h> =20 #include <linux/spinlock.h> =20 @@ -317,6 +318,22 @@ action_msg: "Kill All Tasks", }; =20 +#ifdef CONFIG_SOFTWARE_SUSPEND +static void sysrq_handle_swsusp(int key, struct pt_regs *pt_regs, + struct kbd_struct *kbd, struct tty_struct *tty) { + if(!software_suspend_enabled) { + printk("Software Suspend is not possible now\n"); + return; + } + software_suspend(); +} +static struct sysrq_key_op sysrq_swsusp_op =3D { + handler: sysrq_handle_swsusp, + help_msg: "suspenD", + action_msg: "Software suspend\n", +}; +#endif + /* END SIGNAL SYSRQ HANDLERS BLOCK */ =20 =20 @@ -339,7 +356,11 @@ and will never arive */ /* b */ &sysrq_reboot_op, /* c */ NULL, +#ifdef CONFIG_SOFTWARE_SUSPEND +/* d */ &sysrq_swsusp_op, +#else /* d */ NULL, +#endif /* e */ &sysrq_term_op, /* f */ NULL, /* g */ NULL, --- clean/drivers/ide/ide-disk.c Sun May 19 18:52:03 2002 +++ linux-swsusp/drivers/ide/ide-disk.c Sun May 19 19:03:17 2002 @@ -27,6 +27,7 @@ #include <linux/slab.h> #include <linux/delay.h> #include <linux/ide.h> +#include <linux/suspend.h> =20 #include <asm/byteorder.h> #include <asm/irq.h> @@ -561,6 +562,8 @@ /* I hope that every freeze operations from the upper levels have * already been done... */ + + BUG_ON(in_interrupt()); =20 if (level !=3D SUSPEND_SAVE_STATE) return 0; --- clean/drivers/pci/power.c Tue May 21 23:21:39 2002 +++ linux-swsusp/drivers/pci/power.c Tue May 21 23:33:33 2002 @@ -110,7 +110,7 @@ return error; } =20 -static int pci_pm_suspend(u32 state) +int pci_pm_suspend(u32 state) { struct list_head *list; struct pci_bus *bus; @@ -123,7 +123,7 @@ return 0; } =20 -static int pci_pm_resume(void) +int pci_pm_resume(void) { struct list_head *list; struct pci_bus *bus; --- clean/drivers/usb/storage/usb.c Sun May 19 18:52:05 2002 +++ linux-swsusp/drivers/usb/storage/usb.c Sun May 19 19:03:20 2002 @@ -323,6 +323,7 @@ /* avoid getting signals */ spin_lock_irq(¤t->sigmask_lock); flush_signals(current); + current->flags |=3D PF_IOTHREAD; sigfillset(¤t->blocked); recalc_sigpending(); spin_unlock_irq(¤t->sigmask_lock); --- clean/fs/buffer.c Tue May 21 23:21:40 2002 +++ linux-swsusp/fs/buffer.c Tue May 21 23:33:34 2002 @@ -32,6 +32,7 @@ #include <linux/writeback.h> #include <linux/mempool.h> #include <linux/hash.h> +#include <linux/suspend.h> #include <asm/bitops.h> =20 #define BH_ENTRY(list) list_entry((list), struct buffer_head, b_assoc_bu= ffers) @@ -122,6 +123,8 @@ smp_mb__after_clear_bit(); wake_up_buffer(bh); } + +DECLARE_TASK_QUEUE(tq_bdflush); =20 /* * Block until a buffer comes unlocked. This doesn't stop it --- clean/fs/jbd/journal.c Tue May 21 23:21:41 2002 +++ linux-swsusp/fs/jbd/journal.c Tue May 21 23:35:33 2002 @@ -32,6 +32,7 @@ #include <linux/init.h> #include <linux/mm.h> #include <linux/slab.h> +#include <linux/suspend.h> #include <linux/pagemap.h> #include <asm/uaccess.h> #include <linux/proc_fs.h> @@ -225,6 +226,7 @@ journal->j_commit_interval / HZ); list_add(&journal->j_all_journals, &all_journals); =20 + current->flags |=3D PF_KERNTHREAD; /* And now, wait forever for commit wakeup events. */ while (1) { if (journal->j_flags & JFS_UNMOUNT) @@ -245,7 +247,15 @@ } =20 wake_up(&journal->j_wait_done_commit); - interruptible_sleep_on(&journal->j_wait_commit); + if (current->flags & PF_FREEZE) { /* The simpler the better. Flushing = journal isn't a + good idea, because that depends on threads that + may be already stopped. */ + jbd_debug(1, "Now suspending kjournald\n"); + refrigerator(PF_IOTHREAD); + jbd_debug(1, "Resuming kjournald\n"); =09 + } else /* we assume on resume that commits are already there, + so we don't sleep */ + interruptible_sleep_on(&journal->j_wait_commit); =20 jbd_debug(1, "kjournald wakes\n"); =20 --- clean/fs/reiserfs/journal.c Tue May 21 23:21:42 2002 +++ linux-swsusp/fs/reiserfs/journal.c Tue May 21 23:33:36 2002 @@ -57,6 +57,7 @@ #include <linux/stat.h> #include <linux/string.h> #include <linux/smp_lock.h> +#include <linux/suspend.h>=20 =20 /* the number of mounted filesystems. This is used to decide when to ** start and kill the commit thread @@ -1886,6 +1887,7 @@ spin_unlock_irq(¤t->sigmask_lock); =20 sprintf(current->comm, "kreiserfsd") ; + current->flags |=3D PF_KERNTHREAD; lock_kernel() ; while(1) { =20 @@ -1899,7 +1901,12 @@ break ; } wake_up(&reiserfs_commit_thread_done) ; - interruptible_sleep_on_timeout(&reiserfs_commit_thread_wait, 5 * HZ)= ; +#ifdef CONFIG_SOFTWARE_SUSPEND + if (current->flags & PF_FREEZE) { + refrigerator(PF_IOTHREAD); + } else +#endif + interruptible_sleep_on_timeout(&reiserfs_commit_thread_wait, 5 * HZ= ) ; } unlock_kernel() ; wake_up(&reiserfs_commit_thread_done) ; --- clean/include/asm-generic/bitops.h Tue Nov 28 02:47:38 2000 +++ linux-swsusp/include/asm-generic/bitops.h Fri May 3 00:08:35 2002 @@ -51,6 +51,12 @@ return ((mask & *addr) !=3D 0); } =20 +/* + * fls: find last bit set. + */ + +#define fls(x) generic_fls(x) + #ifdef __KERNEL__ =20 /* --- clean/include/asm-i386/bitops.h Thu Apr 25 12:51:49 2002 +++ linux-swsusp/include/asm-i386/bitops.h Fri May 3 00:21:33 2002 @@ -414,6 +414,12 @@ return word; } =20 +/* + * fls: find last bit set. + */ + +#define fls(x) generic_fls(x) + #ifdef __KERNEL__ =20 /* --- clean/include/asm-i386/suspend.h Tue Feb 5 23:17:28 2002 +++ linux-swsusp/include/asm-i386/suspend.h Wed May 22 00:02:18 2002 @@ -0,0 +1,304 @@ +#ifndef __ASM_I386_SUSPEND_H +#define __ASM_I386_SUSPEND_H +#endif + +/* + * Copyright 2001-2002 Pavel Machek <pa...@su...> + * Based on code + * Copyright 2001 Patrick Mochel <mo...@os...> + */ +#if defined(SUSPEND_C) || defined(ACPI_C) +#include <asm/desc.h> +#include <asm/i387.h> + +static inline void +arch_prepare_suspend(void) +{ + if (!cpu_has_pse) + panic("pse required"); +} + +/* image of the saved processor state */ +struct saved_context { + u32 eax, ebx, ecx, edx; + u32 esp, ebp, esi, edi; + u16 es, fs, gs, ss; + u32 cr0, cr2, cr3, cr4; + u16 gdt_pad; + u16 gdt_limit; + u32 gdt_base; + u16 idt_pad; + u16 idt_limit; + u32 idt_base; + u16 ldt; + u16 tss; + u32 tr; + u32 safety; + u32 return_address; + u32 eflags; +} __attribute__((packed)); + +static struct saved_context saved_context; + +#define loaddebug(thread,register) \ + __asm__("movl %0,%%db" #register \ + : /* no output */ \ + :"r" ((thread)->debugreg[register])) + +=20 +/* + * save_processor_context + *=20 + * Save the state of the processor before we go to sleep. + * + * return_stack is the value of the stack pointer (%esp) as the caller s= ees it. + * A good way could not be found to obtain it from here (don't want to m= ake _too_ + * many assumptions about the layout of the stack this far down.) Also, = the=20 + * handy little __builtin_frame_pointer(level) where level > 0, is blata= ntly=20 + * buggy - it returns the value of the stack at the proper location, not= the=20 + * location, like it should (as of gcc 2.91.66) + *=20 + * Note that the context and timing of this function is pretty critical. + * With a minimal amount of things going on in the caller and in here, g= cc + * does a good job of being just a dumb compiler. Watch the assembly ou= tput + * if anything changes, though, and make sure everything is going in the= right + * place.=20 + */ +static inline void save_processor_context (void) +{ + kernel_fpu_begin(); + + /* + * descriptor tables + */ + asm volatile ("sgdt (%0)" : "=3Dm" (saved_context.gdt_limit)); + asm volatile ("sidt (%0)" : "=3Dm" (saved_context.idt_limit)); + asm volatile ("sldt (%0)" : "=3Dm" (saved_context.ldt)); + asm volatile ("str (%0)" : "=3Dm" (saved_context.tr)); + + /* + * save the general registers. + * note that gcc has constructs to specify output of certain registers, + * but they're not used here, because it assumes that you want to modif= y + * those registers, so it tries to be smart and save them beforehand. + * It's really not necessary, and kinda fishy (check the assembly outpu= t), + * so it's avoided.=20 + */ + asm volatile ("movl %%esp, (%0)" : "=3Dm" (saved_context.esp)); + asm volatile ("movl %%eax, (%0)" : "=3Dm" (saved_context.eax)); + asm volatile ("movl %%ebx, (%0)" : "=3Dm" (saved_context.ebx)); + asm volatile ("movl %%ecx, (%0)" : "=3Dm" (saved_context.ecx)); + asm volatile ("movl %%edx, (%0)" : "=3Dm" (saved_context.edx)); + asm volatile ("movl %%ebp, (%0)" : "=3Dm" (saved_context.ebp)); + asm volatile ("movl %%esi, (%0)" : "=3Dm" (saved_context.esi)); + asm volatile ("movl %%edi, (%0)" : "=3Dm" (saved_context.edi)); + + /* + * segment registers + */ + asm volatile ("movw %%es, %0" : "=3Dr" (saved_context.es)); + asm volatile ("movw %%fs, %0" : "=3Dr" (saved_context.fs)); + asm volatile ("movw %%gs, %0" : "=3Dr" (saved_context.gs)); + asm volatile ("movw %%ss, %0" : "=3Dr" (saved_context.ss)); + + /* + * control registers=20 + */ + asm volatile ("movl %%cr0, %0" : "=3Dr" (saved_context.cr0)); + asm volatile ("movl %%cr2, %0" : "=3Dr" (saved_context.cr2)); + asm volatile ("movl %%cr3, %0" : "=3Dr" (saved_context.cr3)); + asm volatile ("movl %%cr4, %0" : "=3Dr" (saved_context.cr4)); + + /* + * eflags + */ + asm volatile ("pushfl ; popl (%0)" : "=3Dm" (saved_context.eflags)); +} + +static void fix_processor_context(void) +{ + int nr =3D smp_processor_id(); + struct tss_struct * t =3D &init_tss[nr]; + + set_tss_desc(nr,t); /* This just modifies memory; should not be neccess= ary. But... This is neccessary, because 386 hardware has concept of busy = tsc or some similar stupidity. */ + gdt_table[__TSS(nr)].b &=3D 0xfffffdff; + + load_TR(nr); /* This does ltr */ + + load_LDT(¤t->mm->context); /* This does lldt */ + + /* + * Now maybe reload the debug registers + */ + if (current->thread.debugreg[7]){ + loaddebug(¤t->thread, 0); + loaddebug(¤t->thread, 1); + loaddebug(¤t->thread, 2); + loaddebug(¤t->thread, 3); + /* no 4 and 5 */ + loaddebug(¤t->thread, 6); + loaddebug(¤t->thread, 7); + } + +} + +static void +do_fpu_end(void) +{ + /* restore FPU regs if necessary */ + /* Do it out of line so that gcc does not move cr0 load to some stupid = place */ + kernel_fpu_end(); +} + +/* + * restore_processor_context + *=20 + * Restore the processor context as it was before we went to sleep + * - descriptor tables + * - control registers + * - segment registers + * - flags + *=20 + * Note that it is critical that this function is declared inline. =20 + * It was separated out from restore_state to make that function + * a little clearer, but it needs to be inlined because we won't have a + * stack when we get here (so we can't push a return address). + */ +static inline void restore_processor_context (void) +{ + /* + * first restore %ds, so we can access our data properly + */ + asm volatile (".align 4"); + asm volatile ("movw %0, %%ds" :: "r" ((u16)__KERNEL_DS)); + + + /* + * control registers + */ + asm volatile ("movl %0, %%cr4" :: "r" (saved_context.cr4)); + asm volatile ("movl %0, %%cr3" :: "r" (saved_context.cr3)); + asm volatile ("movl %0, %%cr2" :: "r" (saved_context.cr2)); + asm volatile ("movl %0, %%cr0" :: "r" (saved_context.cr0)); +=09 + /* + * segment registers + */ + asm volatile ("movw %0, %%es" :: "r" (saved_context.es)); + asm volatile ("movw %0, %%fs" :: "r" (saved_context.fs)); + asm volatile ("movw %0, %%gs" :: "r" (saved_context.gs)); + asm volatile ("movw %0, %%ss" :: "r" (saved_context.ss)); + + /* + * the other general registers + * + * note that even though gcc has constructs to specify memory=20 + * input into certain registers, it will try to be too smart + * and save them at the beginning of the function. This is esp. + * bad since we don't have a stack set up when we enter, and we=20 + * want to preserve the values on exit. So, we set them manually. + */ + asm volatile ("movl %0, %%esp" :: "m" (saved_context.esp)); + asm volatile ("movl %0, %%ebp" :: "m" (saved_context.ebp)); + asm volatile ("movl %0, %%eax" :: "m" (saved_context.eax)); + asm volatile ("movl %0, %%ebx" :: "m" (saved_context.ebx)); + asm volatile ("movl %0, %%ecx" :: "m" (saved_context.ecx)); + asm volatile ("movl %0, %%edx" :: "m" (saved_context.edx)); + asm volatile ("movl %0, %%esi" :: "m" (saved_context.esi)); + asm volatile ("movl %0, %%edi" :: "m" (saved_context.edi)); + + /* + * now restore the descriptor tables to their proper values + */ + asm volatile ("lgdt (%0)" :: "m" (saved_context.gdt_limit)); + asm volatile ("lidt (%0)" :: "m" (saved_context.idt_limit)); + asm volatile ("lldt (%0)" :: "m" (saved_context.ldt)); + +#if 0 + asm volatile ("ltr (%0)" :: "m" (saved_context.tr)); +#endif + + fix_processor_context(); + + /* + * the flags + */ + asm volatile ("pushl %0 ; popfl" :: "m" (saved_context.eflags)); + + do_fpu_end(); +} + +#endif +#ifdef SUSPEND_C +#if 1 +/* Local variables for do_magic */ +static int loop __nosavedata =3D 0; +static int loop2 __nosavedata =3D 0; + +/* + * (KG): Since we affect stack here, we make this function as flat and e= asy + * as possible in order to not provoke gcc to use local variables on the= stack. + * Note that on resume, all (expect nosave) variables will have the stat= e from + * the time of writing (suspend_save_image) and the registers (including= the + * stack pointer, but excluding the instruction pointer) will be loaded = with=20 + * the values saved at save_processor_context() time. + */ +static void do_magic(int resume) +{ + /* DANGER WILL ROBINSON! + * + * If this function is too difficult for gcc to optimize, it will crash= and burn! + * see above. + * + * DO NOT TOUCH. + */ + + if (!resume) { + do_magic_suspend_1(); + save_processor_context(); /* We need to capture registers and memory a= t "same time" */ + do_magic_suspend_2(); /* If everything goes okay, this function does = not return */ + return; + } + + /* We want to run from swapper_pg_dir, since swapper_pg_dir is stored i= n constant + * place in memory=20 + */ + + __asm__( "movl %%ecx,%%cr3\n" ::"c"(__pa(swapper_pg_dir))); + +/* + * Final function for resuming: after copying the pages to their origina= l + * position, it restores the register state. + */ + + do_magic_resume_1(); + + /* Critical section here: noone should touch memory from now */ + /* This works, because nr_copy_pages, pagedir_nosave, loop and loop2 ar= e nosavedata */ + for (loop=3D0; loop < nr_copy_pages; loop++) { + /* You may not call something (like copy_page) here: + We may absolutely not use stack at this point */ + for (loop2=3D0; loop2 < PAGE_SIZE; loop2++) { + *(((char *)((pagedir_nosave+loop)->orig_address))+loop2) =3D + *(((char *)((pagedir_nosave+loop)->address))+loop2); + __flush_tlb(); + } + } +/* FIXME: What about page tables? Writing data pages may toggle + accessed/dirty bits in our page tables. That should be no problems + with 4MB page tables. That's why we require have_pse. */ + +/* Danger: previous loop probably destroyed our current stack. Better ho= pe it did not use + any stack space, itself. + + When this function is entered at resume time, we move stack to _old_ = place. + This is means that this function must use no stack and no local varia= bles in registers. +*/ + restore_processor_context(); +/* Ahah, we now run with our old stack, and with registers copied from s= uspend time */ + + do_magic_resume_2(); +} +#endif +#endif=20 + --- clean/include/linux/bitops.h Mon Nov 5 21:42:13 2001 +++ linux-swsusp/include/linux/bitops.h Fri May 3 00:21:33 2002 @@ -1,6 +1,6 @@ #ifndef _LINUX_BITOPS_H #define _LINUX_BITOPS_H - +#include <asm/bitops.h> =20 /* * ffs: find first bit set. This is defined the same way as @@ -35,6 +35,47 @@ r +=3D 1; } return r; +} + +/* + * fls: find last bit set. + */ + +extern __inline__ int generic_fls(int x) +{ + int r =3D 32; + + if (!x) + return 0; + if (!(x & 0xffff0000)) { + x <<=3D 16; + r -=3D 16; + } + if (!(x & 0xff000000)) { + x <<=3D 8; + r -=3D 8; + } + if (!(x & 0xf0000000)) { + x <<=3D 4; + r -=3D 4; + } + if (!(x & 0xc0000000)) { + x <<=3D 2; + r -=3D 2; + } + if (!(x & 0x80000000)) { + x <<=3D 1; + r -=3D 1; + } + return r; +} + +extern __inline__ int get_bitmask_order(unsigned int count) +{ + int order; +=09 + order =3D fls(count); + return order; /* We could be slightly more clever with -1 here... */ } =20 /* --- clean/include/linux/init.h Thu Mar 21 11:36:09 2002 +++ linux-swsusp/include/linux/init.h Fri May 3 00:21:33 2002 @@ -169,6 +169,9 @@ =20 #endif =20 +/* Data marked not to be saved by software_suspend() */ +#define __nosavedata __attribute__ ((__section__ (".data.nosave"))) + #ifdef CONFIG_HOTPLUG #define __devinit #define __devinitdata --- clean/include/linux/page-flags.h Tue May 21 23:21:44 2002 +++ linux-swsusp/include/linux/page-flags.h Tue May 21 23:35:57 2002 @@ -64,6 +64,7 @@ =20 #define PG_private 12 /* Has something at ->private */ #define PG_writeback 13 /* Page is under writeback */ +#define PG_nosave 15 /* Used for system suspend/resume */ =20 /* * Global page accounting. One instance per CPU. @@ -206,6 +207,12 @@ dec_page_state(nr_writeback); \ ret; \ }) + +#define PageNosave(page) test_bit(PG_nosave, &(page)->flags) +#define SetPageNosave(page) set_bit(PG_nosave, &(page)->flags) +#define TestSetPageNosave(page) test_and_set_bit(PG_nosave, &(page)->fla= gs) +#define ClearPageNosave(page) clear_bit(PG_nosave, &(page)->flags) +#define TestClearPageNosave(page) test_and_clear_bit(PG_nosave, &(page)-= >flags) =20 /* * The PageSwapCache predicate doesn't use a PG_flag at this time, --- clean/include/linux/reboot.h Fri Feb 9 23:46:13 2001 +++ linux-swsusp/include/linux/reboot.h Fri May 3 00:21:36 2002 @@ -20,6 +20,7 @@ * CAD_OFF Ctrl-Alt-Del sequence sends SIGINT to init task. * POWER_OFF Stop OS and remove all power from system, if possible. * RESTART2 Restart system using given command string. + * SW_SUSPEND Suspend system using Software Suspend if compiled in */ =20 #define LINUX_REBOOT_CMD_RESTART 0x01234567 @@ -28,6 +29,7 @@ #define LINUX_REBOOT_CMD_CAD_OFF 0x00000000 #define LINUX_REBOOT_CMD_POWER_OFF 0x4321FEDC #define LINUX_REBOOT_CMD_RESTART2 0xA1B2C3D4 +#define LINUX_REBOOT_CMD_SW_SUSPEND 0xD000FCE2 =20 =20 #ifdef __KERNEL__ @@ -45,6 +47,13 @@ extern void machine_restart(char *cmd); extern void machine_halt(void); extern void machine_power_off(void); + +/* + * Architecture-independent suspend facility + */ + +extern void software_suspend(void); +extern unsigned char software_suspend_enabled; =20 #endif =20 --- clean/include/linux/sched.h Sun May 19 18:52:06 2002 +++ linux-swsusp/include/linux/sched.h Tue May 21 23:37:55 2002 @@ -388,6 +388,11 @@ #define PF_FLUSHER 0x00004000 /* responsible for disk writeback */ #define PF_RADIX_TREE 0x00008000 /* debug: performing radix tree alloc *= / =20 +#define PF_FREEZE 0x00010000 /* this task should be frozen for suspend *= / +#define PF_IOTHREAD 0x00020000 /* this thread is needed for doing I/O to= swap */ +#define PF_KERNTHREAD 0x00040000 /* this thread is a kernel thread that = cannot be sent signals to */ +#define PF_FROZEN 0x00080000 /* frozen for system suspend */ + /* * Ptrace flags */ --- clean/include/linux/suspend.h Tue Feb 5 23:17:31 2002 +++ linux-swsusp/include/linux/suspend.h Wed May 22 00:02:21 2002 @@ -0,0 +1,65 @@ +#ifndef _LINUX_SWSUSP_H +#define _LINUX_SWSUSP_H + +#include <asm/suspend.h> +#include <linux/swap.h> +#include <linux/notifier.h> +#include <linux/config.h> + +extern unsigned char software_suspend_enabled; + +#define NORESUME 1 +#define RESUME_SPECIFIED 2 + +#ifdef CONFIG_SOFTWARE_SUSPEND +/* page backup entry */ +typedef struct pbe { + unsigned long address; /* address of the copy */ + unsigned long orig_address; /* original address of page */ + swp_entry_t swap_address;=09 + swp_entry_t dummy; /* we need scratch space at=20 + * end of page (see link, diskpage) + */ +} suspend_pagedir_t; + +#define SWAP_FILENAME_MAXLENGTH 32 + +struct suspend_header { + __u32 version_code; + unsigned long num_physpages; + char machine[8]; + char version[20]; + int num_cpus; + int page_size; + unsigned long suspend_pagedir; + unsigned int num_pbes; + struct swap_location { + char filename[SWAP_FILENAME_MAXLENGTH]; + } swap_location[MAX_SWAPFILES]; +}; + +#define SUSPEND_PD_PAGES(x) (((x)*sizeof(struct pbe))/PAGE_SIZE+1) + =20 +extern struct tq_struct suspend_tq; + +/* mm/vmscan.c */ +extern int shrink_mem(void); + +/* kernel/suspend.c */ +extern void software_suspend(void); +extern void software_resume(void); +extern int resume_setup(char *str); + +extern int register_suspend_notifier(struct notifier_block *); +extern int unregister_suspend_notifier(struct notifier_block *); +extern void refrigerator(unsigned long); + +#else +#define software_suspend() do { } while(0) +#define software_resume() do { } while(0) +#define register_suspend_notifier(a) do { } while(0) +#define unregister_suspend_notifier(a) do { } while(0) +#define refrigerator(a) do { BUG(); } while(0) +#endif + +#endif /* _LINUX_SWSUSP_H */ --- clean/include/linux/tqueue.h Wed Apr 24 23:06:46 2002 +++ linux-swsusp/include/linux/tqueue.h Tue May 21 23:37:55 2002 @@ -66,7 +66,7 @@ #define DECLARE_TASK_QUEUE(q) LIST_HEAD(q) #define TQ_ACTIVE(q) (!list_empty(&q)) =20 -extern task_queue tq_timer, tq_immediate, tq_disk; +extern task_queue tq_timer, tq_immediate, tq_disk, tq_bdflush; =20 /* * To implement your own list of active bottom halfs, use the following --- clean/init/do_mounts.c Mon May 13 23:26:59 2002 +++ linux-swsusp/init/do_mounts.c Wed May 8 23:40:24 2002 @@ -10,6 +10,7 @@ #include <linux/fd.h> #include <linux/tty.h> #include <linux/init.h> +#include <linux/suspend.h> =20 #include <linux/nfs_fs.h> #include <linux/nfs_fs_sb.h> @@ -825,6 +826,11 @@ #endif =20 create_dev("/dev/root", ROOT_DEV, NULL); + + /* This has to be before mounting root, because even readonly mount of = reiserfs would replay + log corrupting stuff */ + software_resume(); + if (mount_initrd) { if (initrd_load() && !kdev_same(ROOT_DEV, mk_kdev(RAMDISK_MAJOR, 0))) = { handle_initrd(); --- clean/kernel/Makefile Thu Apr 18 22:46:18 2002 +++ linux-swsusp/kernel/Makefile Fri May 3 00:08:35 2002 @@ -10,7 +10,7 @@ O_TARGET :=3D kernel.o =20 export-objs =3D signal.o sys.o kmod.o context.o ksyms.o pm.o exec_domain= .o \ - printk.o platform.o=20 + printk.o platform.o suspend.o =20 obj-y =3D sched.o dma.o fork.o exec_domain.o panic.o printk.o \ module.o exit.o itimer.o info.o time.o softirq.o resource.o \ @@ -21,6 +21,7 @@ obj-$(CONFIG_MODULES) +=3D ksyms.o obj-$(CONFIG_PM) +=3D pm.o obj-$(CONFIG_BSD_PROCESS_ACCT) +=3D acct.o +obj-$(CONFIG_SOFTWARE_SUSPEND) +=3D suspend.o =20 ifneq ($(CONFIG_IA64),y) # According to Alan Modra <al...@li...>, the -fno-omit-frame-p= ointer is --- clean/kernel/context.c Tue Mar 5 21:52:50 2002 +++ linux-swsusp/kernel/context.c Fri May 3 00:08:35 2002 @@ -72,6 +72,7 @@ =20 daemonize(); strcpy(curtask->comm, "keventd"); + current->flags |=3D PF_IOTHREAD; keventd_running =3D 1; keventd_task =3D curtask; =20 --- clean/kernel/signal.c Mon May 13 23:27:11 2002 +++ linux-swsusp/kernel/signal.c Mon May 13 23:03:21 2002 @@ -493,7 +493,7 @@ * No need to set need_resched since signal event passing * goes through ->blocked */ -static inline void signal_wake_up(struct task_struct *t) +inline void signal_wake_up(struct task_struct *t) { set_tsk_thread_flag(t,TIF_SIGPENDING); =20 --- clean/kernel/softirq.c Thu Jan 31 23:42:30 2002 +++ linux-swsusp/kernel/softirq.c Fri May 3 00:08:35 2002 @@ -365,6 +365,7 @@ =20 daemonize(); set_user_nice(current, 19); + current->flags |=3D PF_IOTHREAD; sigfillset(¤t->blocked); =20 /* Migrate to the right CPU */ --- clean/kernel/suspend.c Sun Nov 11 20:26:28 2001 +++ linux-swsusp/kernel/suspend.c Tue May 21 23:49:20 2002 @@ -0,0 +1,1327 @@ +/* + * linux/kernel/swsusp.c + * + * This file is to realize architecture-independent + * machine suspend feature using pretty near only high-level routines + * + * Copyright (C) 1998-2001 Gabor Kuti <se...@fo...> + * Copyright (C) 1998,2001,2002 Pavel Machek <pa...@su...> + * + * I'd like to thank the following people for their work: + *=20 + * Pavel Machek <pa...@uc...>: + * Modifications, defectiveness pointing, being with me at the very begi= nning, + * suspend to swap space, stop all tasks. + * + * Steve Doddi <di...@lo...>:=20 + * Support the possibility of hardware state restoring. + * + * Raph <gre...@ea...>: + * Support for preserving states of network devices and virtual console + * (including X and svgatextmode) + * + * Kurt Garloff <ga...@su...>: + * Straightened the critical function in order to prevent compilers from + * playing tricks with local variables. + * + * Andreas Mohr <a....@ma...> + * + * Alex Badea <va...@go...>: + * Fixed runaway init + * + * More state savers are welcome. Especially for the scsi layer... + * + * For TODOs,FIXMEs also look in Documentation/swsusp.txt + */ + +/* + * TODO: + * + * - we should launch a kernel_thread to process suspend request, cleani= ng up + * bdflush from this task. (check apm.c for something similar). + */ + +/* FIXME: try to poison to memory */ + +#include <linux/module.h> +#include <linux/mm.h> +#include <linux/swapctl.h> +#include <linux/suspend.h> +#include <linux/smp_lock.h> +#include <linux/file.h> +#include <linux/utsname.h> +#include <linux/version.h> +#include <linux/compile.h> +#include <linux/delay.h> +#include <linux/reboot.h> +#include <linux/init.h> +#include <linux/vt_kern.h> +#include <linux/bitops.h> +#include <linux/interrupt.h> +#include <linux/kbd_kern.h> +#include <linux/... [truncated message content] |
From: Linus T. <tor...@tr...> - 2002-05-21 23:02:00
|
On Wed, 22 May 2002, Pavel Machek wrote: >=20 > Major parts are: process stopper, S3 specific code, S4 specific > code. What can I do to make this applied? Applied.=A0Nothing needed but some time for me to look through it. It still has a few too many #ifdef CONFIG_SUSPEND, and I get this feeling= =20 that the background deamons shouldn't need to do the "freeze()" by hand=20 but simply be automatically frozen and thawed when they sleep by looking=20 at the KERNTHREAD bit or something, but.. Linus |
From: Linus T. <tor...@tr...> - 2002-05-21 23:15:21
|
On Tue, 21 May 2002, Linus Torvalds wrote: >=20 > Applied.=A0Nothing needed but some time for me to look through it. Well, I may have to revert that. mm/mm.o: In function `rw_swap_page': mm/mm.o(.text+0xaeb2): undefined reference to `suspend_device' Please send me a fix asap. Linus |
From: Pavel M. <pa...@uc...> - 2002-05-21 23:28:37
|
Hi! > > Applied.=A0Nothing needed but some time for me to look through it. >=20 > Well, I may have to revert that. Sorry about that. Safety check that should not be needed. > mm/mm.o: In function `rw_swap_page': > mm/mm.o(.text+0xaeb2): undefined reference to `suspend_device' >=20 > Please send me a fix asap. This fixes it. I also broke compilation in ACPI but not SWSUSP case (but it ate disks before, so ... :-). Pavel --- linux-swsusp.linus/mm/page_io.c Tue May 21 23:33:38 2002 +++ linux-swsusp/mm/page_io.c Wed May 22 01:20:04 2002 @@ -86,15 +86,11 @@ * - it's marked as being swap-cache * - it's associated with the swap inode */ -extern long suspend_device; void rw_swap_page(int rw, struct page *page) { swp_entry_t entry; =20 entry.val =3D page->index; - - if (suspend_device) - panic("I refuse to corrupt memory/swap."); =20 if (!PageLocked(page)) PAGE_BUG(page); --=20 (about SSSCA) "I don't say this lightly. However, I really think that th= e U.S. no longer is classifiable as a democracy, but rather as a plutocracy." --= hpa |
From: Pavel M. <pa...@uc...> - 2002-05-21 23:41:34
|
Hi! > > Applied.=A0Nothing needed but some time for me to look through it. >=20 > Well, I may have to revert that. >=20 > mm/mm.o: In function `rw_swap_page': > mm/mm.o(.text+0xaeb2): undefined reference to `suspend_device' >=20 > Please send me a fix asap. One more build fix, this time for !CONFIG_SOFTWARE_SUSPEND but CONFIG_ACPI: I choosen this solution for now, as it is safest for ACPI people. I'll modify suspend.c so that freezing part can be included without whole suspend-to-disk support being included. Pavel --- linux-swsusp.linus/drivers/acpi/acpi_system.c Sun May 19 17:25:33 200= 2 +++ linux-swsusp/drivers/acpi/acpi_system.c Wed May 22 01:32:31 2002 @@ -34,6 +34,7 @@ #include <linux/sysrq.h> #include <linux/pm.h> #include <linux/device.h> +#include <linux/suspend.h> #include <asm/uaccess.h> #include <asm/acpi.h> #include "acpi_bus.h" --- linux-swsusp.linus/include/linux/suspend.h Wed May 22 00:02:21 2002 +++ linux-swsusp/include/linux/suspend.h Wed May 22 01:30:08 2002 @@ -60,6 +60,8 @@ #define register_suspend_notifier(a) do { } while(0) #define unregister_suspend_notifier(a) do { } while(0) #define refrigerator(a) do { BUG(); } while(0) +#define freeze_processes() do { panic("You need CONFIG_SOFTWARE_SUSPEND= to do sleeps."); } while(0) +#define thaw_processes() do { } while(0) #endif =20 #endif /* _LINUX_SWSUSP_H */ --=20 (about SSSCA) "I don't say this lightly. However, I really think that th= e U.S. no longer is classifiable as a democracy, but rather as a plutocracy." --= hpa |
From: Pavel M. <pa...@su...> - 2002-05-21 23:20:09
|
Hi! > > Major parts are: process stopper, S3 specific code, S4 specific > > code. What can I do to make this applied? > > Applied. Nothing needed but some time for me to look through it. Wow, good! > It still has a few too many #ifdef CONFIG_SUSPEND, and I get this > feeling I'll hunt them down. > that the background deamons shouldn't need to do the "freeze()" by > hand > but simply be automatically frozen and thawed when they sleep by looking > at the KERNTHREAD bit or something, but.. Do you think I should modify schedule() to do freezing automatically? I wanted to keep my hands off hot paths... I'd rather not do that. I guess adding maybe_refrigerator() macro should solve that without introducing overhead in schedule(). Pavel -- Casualities in World Trade Center: ~3k dead inside the building, cryptography in U.S.A. and free speech in Czech Republic. |
From: Linus T. <tor...@tr...> - 2002-05-21 23:27:15
|
On Wed, 22 May 2002, Pavel Machek wrote: > Do you think I should modify schedule() to do freezing automatically? > I wanted to keep my hands off hot paths... I'd rather not do that. No, I just suspect you could freeze them _while_ they sleep by just picking up their information from the normal save area. Yeah, I know, Linux tends to save a lot of the process stuff implicitly on the stack, so maybe that ends up being harder than it sounds, and you've done it for other tasks with the signal handler code instead, but you _should_ be able to do it without any signal handler hackery by just saving off their kernel stack and the stuff in the thread structure. That's just a gut feeling, not having actually looked at the real details. Linus |
From: Pavel M. <pa...@su...> - 2002-05-21 23:33:16
|
Hi! > > Do you think I should modify schedule() to do freezing automatically? > > I wanted to keep my hands off hot paths... I'd rather not do that. > > No, I just suspect you could freeze them _while_ they sleep by just > picking up their information from the normal save area. > > Yeah, I know, Linux tends to save a lot of the process stuff implicitly on > the stack, so maybe that ends up being harder than it sounds, and you've > done it for other tasks with the signal handler code instead, but you > _should_ be able to do it without any signal handler hackery by just > saving off their kernel stack and the stuff in the thread structure. I need to know more than they are sleeping. I also know they are sleeping *without holding any semaphores*. I need working system to be able to save state to disk. That's why I hacked it into signal handler. Pavel -- Casualities in World Trade Center: ~3k dead inside the building, cryptography in U.S.A. and free speech in Czech Republic. |
From: Linus T. <tor...@tr...> - 2002-05-22 00:09:08
|
On Wed, 22 May 2002, Pavel Machek wrote: > > I need to know more than they are sleeping. I also know they are > sleeping *without holding any semaphores*. I need working system to be > able to save state to disk. That's why I hacked it into signal > handler. Sorry, I should have been more clear. I think the signal handler approach is fine for user processes, I was just wondering why you needed anything like that for kernel threads.. When a kernel thread is sleeping, I don't see that it has much state at all: it will be re-started anyway on the next boot, and I don't see it having any "state". (I didn't think it through enough - never mind saving the stack page, because I don't think there is anything at all interesting there to save). Linus |
From: Pavel M. <pa...@su...> - 2002-05-22 00:15:29
|
Hi! > > I need to know more than they are sleeping. I also know they are > > sleeping *without holding any semaphores*. I need working system to be > > able to save state to disk. That's why I hacked it into signal > > handler. > > Sorry, I should have been more clear. I think the signal handler approach > is fine for user processes, I was just wondering why you needed anything > like that for kernel threads.. > > When a kernel thread is sleeping, I don't see that it has much state at > all: it will be re-started anyway on the next boot, and I don't see it > having any "state". If that kernel thread is sleeping because it waits for disk, it has some state, and I do not want to freeze it just now (because it might hold some lock). I only want to freeze them at safe point, and it seemed to me that for kernel threads it is easiest to mark safe points by hand. Does it compile for you for now? Pavel -- Casualities in World Trade Center: ~3k dead inside the building, cryptography in U.S.A. and free speech in Czech Republic. |
From: Martin D. <da...@ev...> - 2002-05-22 07:53:20
|
Uz.ytkownik Linus Torvalds napisa?: > On Wed, 22 May 2002, Pavel Machek wrote: > >>Major parts are: process stopper, S3 specific code, S4 specific >>code. What can I do to make this applied? > > > Applied. Nothing needed but some time for me to look through it. > > It still has a few too many #ifdef CONFIG_SUSPEND, and I get this feeling > that the background deamons shouldn't need to do the "freeze()" by hand > but simply be automatically frozen and thawed when they sleep by looking > at the KERNTHREAD bit or something, but.. Oh and please reject the idea of compressing the pages you are writing to disk for the following reaons: 1. compression is not deterministic in terms of the possible space savings, you will still have to provide the required amount of space. 2. every compression algorithm has theoretical cases where the compression mechanism is actually increasing the space requirements. 3. Compressing around 360 Mbytes of data will take quite a lot of time. 4. Point 3 will make the CPU go high - not nice if the suspend happens in case of battery emergency... Anyway it's time to repartition my notebook :-). |
From: Pavel M. <pa...@su...> - 2002-05-22 09:00:18
|
Hi! > >>Major parts are: process stopper, S3 specific code, S4 specific > >>code. What can I do to make this applied? > > > > > >Applied. Nothing needed but some time for me to look through it. > > > >It still has a few too many #ifdef CONFIG_SUSPEND, and I get this feeling > >that the background deamons shouldn't need to do the "freeze()" by hand > >but simply be automatically frozen and thawed when they sleep by looking > >at the KERNTHREAD bit or something, but.. > > Oh and please reject the idea of compressing the pages > you are writing to disk for the following reaons: [snip] It probably was not going to be implemented anyway. It was meant to speed up suspend process, and yes simple compression probably could achieve that, but it is not worth the trouble, probably. > 1. compression is not deterministic in terms of the possible space > savings, you will still have to provide the required amount of space. > > 2. every compression algorithm has theoretical cases where the > compression mechanism is actually increasing the space requirements. > > 3. Compressing around 360 Mbytes of data will take quite a lot > of time. > > 4. Point 3 will make the CPU go high - not nice if the suspend > happens in case of battery emergency... > > Anyway it's time to repartition my notebook :-). Yep. [Actually, if you have swap partition, you don't need to repartition anything.] Pavel -- Casualities in World Trade Center: ~3k dead inside the building, cryptography in U.S.A. and free speech in Czech Republic. |
From: Xavier B. <xav...@fr...> - 2002-05-22 10:04:21
|
Le mer 22/05/2002 =E0 08:49, Martin Dalecki a =E9crit : > Oh and please reject the idea of compressing the pages > you are writing to disk for the following reaons: >=20 > 1. compression is not deterministic in terms of the possible space > savings, you will still have to provide the required amount of space. >=20 > 2. every compression algorithm has theoretical cases where the > compression mechanism is actually increasing the space requirements. >=20 > 3. Compressing around 360 Mbytes of data will take quite a lot > of time. >=20 > 4. Point 3 will make the CPU go high - not nice if the suspend > happens in case of battery emergency... Compressing pages will speed up the process, and doing it on the fly will be more IO-bound than CPU-bound. I think trading some CPU power to gain HD time isn't so uninteresting. Concerning point 2, you could always compress by chunks (say 1M) and take the compressed version only if it's smaller. Xav |
From: Martin D. <da...@ev...> - 2002-05-22 10:07:12
|
Uz.ytkownik Xavier Bestel napisa?: > Compressing pages will speed up the process, and doing it on the fly Did you ever in you life tar czvf ./some_dir and have a look at top?! |
From: Carlos M. <ch...@ch...> - 2002-05-22 10:16:11
|
On 2002.05.22 10:03:48 +0100 Martin Dalecki wrote: > Uz.ytkownik Xavier Bestel napisa?: > >> Compressing pages will speed up the process, and doing it on the fly > > Did you ever in you life tar czvf ./some_dir and have a look at top?! > gzip is not alpha and omega of compression technology -- Carlos Morgado - chbm(at)chbm(dot)nu - http://chbm.nu/ -- gpgkey: 0x1FC57F0A http://wwwkeys.pgp.net/ FP:0A27 35D3 C448 3641 0573 6876 2A37 4BB2 1FC5 7F0A Software is like sex; it's better when it's free. - Linus Torvalds |
From: Albert D. C. <aca...@cs...> - 2002-05-22 10:35:55
|
Martin Dalecki writes: > Uz.ytkownik Xavier Bestel napisa?: >> Compressing pages will speed up the process, and doing it on the fly > > Did you ever in you life tar czvf ./some_dir and have a look at top?! lzo isn't such a CPU hog |
From: Xavier B. <xav...@fr...> - 2002-05-22 10:43:00
|
Le mer 22/05/2002 =E0 11:03, Martin Dalecki a =E9crit : > Uz.ytkownik Xavier Bestel napisa?: >=20 > > Compressing pages will speed up the process, and doing it on the fly >=20 > Did you ever in you life tar czvf ./some_dir and have a look at top?! I just tried to verify; on my laptop (Armada 1700 w/ pII 300 & IBM Travelstar) I have roughly 20% idle CPU during tar zcf. Laptop HDs are slow. |
From: Robert <rob...@sy...> - 2002-05-22 11:40:46
|
is there a patch for the 2.4.18 source with this suspend ??? Xavier Bestel wrote: >Le mer 22/05/2002 à 11:03, Martin Dalecki a écrit : > >>Uz.ytkownik Xavier Bestel napisa?: >> >>>Compressing pages will speed up the process, and doing it on the fly >>> >>Did you ever in you life tar czvf ./some_dir and have a look at top?! >> > >I just tried to verify; on my laptop (Armada 1700 w/ pII 300 & IBM >Travelstar) I have roughly 20% idle CPU during tar zcf. Laptop HDs are >slow. > > > >_______________________________________________________________ > >Don't miss the 2002 Sprint PCS Application Developer's Conference >August 25-28 in Las Vegas -- http://devcon.sprintpcs.com/adp/index.cfm > >_______________________________________________ >Acpi-devel mailing list >Acp...@li... >https://lists.sourceforge.net/lists/listinfo/acpi-devel > > -- _____________________________________ Robert Wörle Linux | Embedded Device Symplon AG ...touch the internet phone: +49 89 552 999 35 fax: +49 89 552 999 10 email: rob...@sy... <mailto:rob...@sy...> web: www.symplon.com <http://www.symplon.com/> _____________________________________ |
From: Ducrot B. <du...@po...> - 2002-05-22 14:34:21
|
On Wed, May 22, 2002 at 01:41:32PM +0200, Robert Wörle wrote: > is there a patch for the 2.4.18 source with this suspend ??? > This is (basically...) swsusp ported to 2.5.x., + suspend to ram added. If you don't want/need ram suspension, you should try swsusp. -- Ducrot Bruno http://www.poupinou.org Page profaissionelle http://toto.tu-me-saoules.com Haume page |
From: Pavel M. <pa...@su...> - 2002-05-23 21:36:30
|
Hi! > is there a patch for the 2.4.18 source with this suspend ??? swsusp is in 2.4.19-preX-ac Pavel -- Philips Velo 1: 1"x4"x8", 300gram, 60, 12MB, 40bogomips, linux, mutt, details at http://atrey.karlin.mff.cuni.cz/~pavel/velo/index.html. |
From: Frank v W. <fv...@va...> - 2002-05-22 12:55:03
|
On Wed, May 22, 2002 at 12:03:03PM +0200, Xavier Bestel wrote: > Concerning point 2, you could always compress by chunks (say 1M) and > take the compressed version only if it's smaller. which would mean you'd have to add a bit to determine if it's the compressed or the uncompressed chunk.. Which means you still have the increased maximum size... There really is no way of getting around the possible size increase.. (sorry to sound defeatist :) ) -- Frank v Waveren Fingerprint: 0EDB 8787 fvw@[var.cx|stack.nl|dse.nl|chello.nl] ICQ#10074100 09B9 6EF5 6425 B855 Public key: hkp://wwwkeys.pgp.net/fv...@va... 7179 3036 E136 B85D |
From: Linus T. <tor...@tr...> - 2002-05-22 15:59:52
|
On 22 May 2002, Xavier Bestel wrote: > > Compressing pages will speed up the process, and doing it on the fly > will be more IO-bound than CPU-bound. I think trading some CPU power to > gain HD time isn't so uninteresting. It's been a long time since disks were so slow that compression speeded things up. _uncompression_ is often faster than disk speeds, but that's a fundamentally easier problem to solve. That means that a mostly read-only medium tends to work better with compressed contents, but in this case we have a write-once, read-once thing where compression is likely to lose. Yes, laptops have slow disks, but they often have slow memory and seldom have the fastest CPU's available. Linus |
From: Geert U. <ge...@li...> - 2002-05-25 13:30:54
|
On Wed, 22 May 2002, Pavel Machek wrote: > Here's suspend-to-{RAM,disk} combined patch for > 2.5.17. Suspend-to-disk is pretty stable and was tested in > 2.4-ac. Suspend-to-RAM is little more experimental, but works for me, > and is certainly better than disk-eating version currently in kernel. > +#define LINUX_REBOOT_CMD_SW_SUSPEND 0xD000FCE2 ^^^^ Are you sure it's system suspend and not system reset? ;-) Nice to see the Commodore 64 special numbers live on in Linux... Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@li... In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds |
From: Pavel M. <pa...@su...> - 2002-05-26 17:20:12
|
Hi! > > Here's suspend-to-{RAM,disk} combined patch for > > 2.5.17. Suspend-to-disk is pretty stable and was tested in > > 2.4-ac. Suspend-to-RAM is little more experimental, but works for me, > > and is certainly better than disk-eating version currently in kernel. > > > +#define LINUX_REBOOT_CMD_SW_SUSPEND 0xD000FCE2 > ^^^^ > Are you sure it's system suspend and not system reset? ;-) > Nice to see the Commodore 64 special numbers live on in Linux... Credits go to Gabor Kuti for this one... I did not know there's a joke hidden there ;-). Pavel -- Casualities in World Trade Center: ~3k dead inside the building, cryptography in U.S.A. and free speech in Czech Republic. |
From: William L. I. I. <wl...@ho...> - 2002-05-27 19:40:46
|
On Wed, May 22, 2002 at 12:28:59AM +0200, Pavel Machek wrote: ... I foresee trouble here; you're doing list_entry(list, struct page, list) on &area->free_list. On Wed, May 22, 2002 at 12:28:59AM +0200, Pavel Machek wrote: > +#ifdef CONFIG_SOFTWARE_SUSPEND > +int is_head_of_free_region(struct page *p) > +{ > + pg_data_t *pgdat = pgdat_list; > + unsigned type; > + unsigned long flags; > + > + for (type=0;type < MAX_NR_ZONES; type++) { > + zone_t *zone = pgdat->node_zones + type; > + int order = MAX_ORDER - 1; > + free_area_t *area; > + struct list_head *head, *curr; > + spin_lock_irqsave(&zone->lock, flags); /* Should not matter as we need quiescent system for suspend anyway, but... */ > + > + do { > + area = zone->free_area + order; > + head = &area->free_list; > + curr = head; ^^^^^^^^^^^^ set right here On Wed, May 22, 2002 at 12:28:59AM +0200, Pavel Machek wrote: > + > + for(;;) { > + if(!curr) { > +// printk("FIXME: this should not happen but it does!!!"); > + break; > + } > + if(p != memlist_entry(curr, struct page, list)) { > + curr = memlist_next(curr); > + if (curr == head) > + break; > + continue; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ deep trouble here and in the if () On Wed, May 22, 2002 at 12:28:59AM +0200, Pavel Machek wrote: > + } > + return 1 << order; > + } > + } while(order--); > + spin_unlock_irqrestore(&zone->lock, flags); > + > + } > + return 0; > +} > +#endif /* CONFIG_SOFTWARE_SUSPEND */ The rest is okay... I'd try writing it this way, and though I've not tested it, I've walked buddy lists a few times in the past week or two: #ifdef CONFIG_SOFTWARE_SUSPEND int is_head_of_free_region(struct page *page) { zone_t *zone, *node_zones = pgdat_list->node_zones; unsigned long flags; for (zone = node_zones; zone - node_zones < MAX_NR_ZONES; ++zone) { int order; list_t *curr; /* * Should not matter as we need quiescent system for * suspend anyway, but... */ spin_lock_irqsave(&zone->lock, flags); for (order = MAX_ORDER - 1; order >= 0; --order) list_for_each(curr, &zone->free_area[order].free_list) if (page == list_entry(curr, struct page, list)) return 1 << order; spin_unlock_irqrestore(&zone->lock, flags); } return 0; } #endif /* CONFIG_SOFTWARE_SUSPEND */ Cheers, Bill |