ubuntu 在 R40e 上 還有 Debian 在 Sempron 2600 上

顯示具有 hibernation 標籤的文章。 顯示所有文章
顯示具有 hibernation 標籤的文章。 顯示所有文章

2011年9月30日 星期五

說要加上 Will Deacon 的 cpu_reset patch。
查一下,在 arch/arm/mm

誰用到?

宣告的地方:./arch/arm/include/asm/cpu-single.h #ifdef __STDC__ #define __catify_fn(name,x) name##x #else #define __catify_fn(name,x) name/**/x #endif #define __cpu_fn(name,x) __catify_fn(name,x) /* * If we are supporting multiple CPUs, then we must use a table of * function pointers for this lot. Otherwise, we can optimise the * table away. */ #define cpu_proc_init __cpu_fn(CPU_NAME,_proc_init) #define cpu_proc_fin __cpu_fn(CPU_NAME,_proc_fin) #define cpu_reset __cpu_fn(CPU_NAME,_reset) #define cpu_do_idle __cpu_fn(CPU_NAME,_do_idle) #define cpu_dcache_clean_area __cpu_fn(CPU_NAME,_dcache_clean_area) #define cpu_do_switch_mm __cpu_fn(CPU_NAME,_switch_mm) #define cpu_set_pte_ext __cpu_fn(CPU_NAME,_set_pte_ext) #include struct mm_struct; /* declare all the functions as extern */ extern void cpu_proc_init(void); extern void cpu_proc_fin(void); extern int cpu_do_idle(void); extern void cpu_dcache_clean_area(void *, int); extern void cpu_do_switch_mm(unsigned long pgd_phys, struct mm_struct *mm); extern void cpu_set_pte_ext(pte_t *ptep, pte_t pte, unsigned int ext); extern void cpu_reset(unsigned long addr) __attribute__((noreturn)); 所以 cpu_reset( ) 會變成 CPU_NAME_reset

CPU_NAME 定義在 ./arch/arm/include/asm/proc-fns.h # ifdef CONFIG_CPU_V6 # ifdef CPU_NAME # undef MULTI_CPU # define MULTI_CPU # else # define CPU_NAME cpu_v6 # endif # endif # ifdef CONFIG_CPU_V7 # ifdef CPU_NAME # undef MULTI_CPU # define MULTI_CPU # else # define CPU_NAME cpu_v7 # endif # endif 所以 cortext A8 的 kernel config 是: CONFIG_CPU_V7=y 也就是會變成 cpu_v7_reset( )

所以 assembly 的部份要看 cpu_v7_reset, c source 的部份要看 cpu_reset ().
.. 有一堆 source call cpu_reset...



ref:
  1. http://comments.gmane.org/gmane.linux.ports.arm.kernel/119552
  2. http://lists.infradead.org/pipermail/linux-arm-kernel/2011-July/057302.html

2011年9月29日 星期四

build TINY_ANDROID && some worklog on hibernate

問題應該還是在 kernel,android framework 在 suspend/resume 好像沒有限制,只有在特殊的情況會用 wakelock 防止suspend (跟hardware 相關,或是 charging)。
其他部份好像都無關 (pure software component ?)



BUILD_TINY_ANDROID
用make -j4 BUILD_TINY_ANDROID=true TARGET_NO_RECOVERY=true showcommands 來 build TINY_ANDROID。
 TINY_ANDROID 不會rebuild recovery,但是 Makefile 卻還是去 make recoveryimage,所以要手動加上 TARGET_NO_RECOVERY=true

build 出來後,到 out 去看 installed-files,果然有一堆沒包 (vimdiff with original build result)


兩個問題:
  1. pmic_adc 在 resume 的時候會 hang 住一陣子
  2. resume 後,shell , rx 沒動作 ,tx好像還 OK,-- 從 shell 的 output 來看

about pmic_adc:
  1. 先回到 resume OK 版本 -- 至少 screen 恢復
  2. 移除 pmic_backlight 和 pmic_XXX (?) -- 看看是否OK
  3. pmic_adc 的 suspend/resume 似乎是以 adc wq 不終止的情況 考慮....

2011年9月27日 星期二

early_printk, DEBUG_LL

承 http://r40eubuntu.blogspot.com/2011/09/initcall.html

單看 console 的部份。

在 start_kernel 的最後 reset_init 用 kernel_thread 執行 kernel_init

console 好像是 kernel 中很重要的東西(?),在 kerne/printk.c 中。
說明 cosole 依照開機的階段,分為兩種,這說明寫在 regisgter_console( ) 的前面: /* * The console driver calls this routine during kernel initialization * to register the console printing procedure with printk() and to * print any messages that were printed by the kernel before the * console driver was initialized. * * This can happen pretty early during the boot process (because of * early_printk) - sometimes before setup_arch() completes - be careful * of what kernel features are used - they may not be initialised yet. * * There are two types of consoles - bootconsoles (early_printk) and * "real" consoles (everything which is not a bootconsole) which are * handled differently. * - Any number of bootconsoles can be registered at any time. * - As soon as a "real" console is registered, all bootconsoles * will be unregistered automatically. * - Once a "real" console is registered, any attempt to register a * bootconsoles will be rejected */ 大概翻譯一下:
為了要讓 printk, early_printk能正常送出 message,要儘早 call register_console( ) 把 console 掛起來。
console 分為兩種:
1. bootconsole : 為了應付kernel boot 前段,真正的 (real) console 還沒決定的時候,所使用的 console
2. real consol : 就真正的 console。
在real console 被 register 後,bootconsole 就會自動被 unregister,然後就再也不允許有人註冊 boot_console 了。
在 arch/arm/kernal/ 下有 early_prink.c,但是要 obj-$(CONFIG_EARLY_PRINTK) += early_printk.o 才會 build 進去。

在 arch/arm/Kconfig include 的 Kconfig.debug 有option:
config EARLY_PRINTK
 bool "Early printk"
 depends on DEBUG_LL
 help
   Say Y here if you want to have an early console using the
   kernel low-level debugging functions. Add earlyprintk to your
   kernel parameters to enable this console.
所以要 enable DEBUG_LL (Kernel low-level debugging functions),才會顯示出來。

2011年9月23日 星期五

hibernate . code trace

echo disk > /sys/power/state 收到的是
kernek/power/main.c : static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t n) suspend to disk 部份超快,就.. if (len == 4 && !strncmp(buf, "disk", len)) { error = hibernate(); goto Exit; } 直接 call kernel/power/hibernate.c 的 hibernate( )



snapshot_device_available 被用作 snaphot 的 mutex,初始是 1,使用時 -1。
也就是說: 1 可用,0 不行。
所以 kernel code 要操作 snapshot 時,都要先作: atomic_add_unless(&snapshot_device_available, -1 ,0) 用來確認 snaphot_device_available 是不是 1 (available),
再繼續動作。

實際上依靠 snaphost_device_avaiable 的 function 有:
  1. hibernate()
  2. software_resume( )
  3. snapshot_open( ) -- user interface of device "snapshot'
pm_notifier_call_chain : call blocking_notifier_call_chain( ).
好像有以下幾個 chain:
  1. PM_HIBERNATION_PREPARE
  2. PM_POST_HIBERNATION
  3. PM_RESTORE_PREPARE
  4. PM_POST_RESTORE

定義在:notifier.h /* Hibernation and suspend events */ #define PM_HIBERNATION_PREPARE 0x0001 /* Going to hibernate */ #define PM_POST_HIBERNATION 0x0002 /* Hibernation finished */ #define PM_SUSPEND_PREPARE 0x0003 /* Going to suspend the system */ #define PM_POST_SUSPEND 0x0004 /* Suspend finished */ #define PM_RESTORE_PREPARE 0x0005 /* Going to restore a saved image */ #define PM_POST_RESTORE 0x0006 /* Restore failed */
RCU : Read-Copy-Update



static int orig_fgconsole, orig_kmsg; int pm_prepare_console(void) { orig_fgconsole = vt_move_to_console(SUSPEND_CONSOLE, 1); if (orig_fgconsole < 0) return 1; orig_kmsg = vt_kmsg_redirect(SUSPEND_CONSOLE); return 0; } void pm_restore_console(void) { if (orig_fgconsole >= 0) { vt_move_to_console(orig_fgconsole, 0); vt_kmsg_redirect(orig_kmsg); } }

2011年9月21日 星期三

initcall, & hibernate, resume, console.

在 include/linux/init.h 有定義: #define early_initcall(fn) __define_initcall("early",fn,early) /* * A "pure" initcall has no dependencies on anything else, and purely * initializes variables that couldn't be statically initialized. * * This only exists for built-in code, not for modules. */ #define pure_initcall(fn) __define_initcall("0",fn,0) #define core_initcall(fn) __define_initcall("1",fn,1) #define core_initcall_sync(fn) __define_initcall("1s",fn,1s) #define postcore_initcall(fn) __define_initcall("2",fn,2) #define postcore_initcall_sync(fn) __define_initcall("2s",fn,2s) #define arch_initcall(fn) __define_initcall("3",fn,3) #define arch_initcall_sync(fn) __define_initcall("3s",fn,3s) #define subsys_initcall(fn) __define_initcall("4",fn,4) #define subsys_initcall_sync(fn) __define_initcall("4s",fn,4s) #define fs_initcall(fn) __define_initcall("5",fn,5) #define fs_initcall_sync(fn) __define_initcall("5s",fn,5s) #define rootfs_initcall(fn) __define_initcall("rootfs",fn,rootfs) #define device_initcall(fn) __define_initcall("6",fn,6) #define device_initcall_sync(fn) __define_initcall("6s",fn,6s) #define late_initcall(fn) __define_initcall("7",fn,7) #define late_initcall_sync(fn) __define_initcall("7s",fn,7s) 其中 __define_initcall 是: #define __define_initcall(level,fn,id) \ static initcall_t __initcall_##fn##id __used \ __attribute__((__section__(".initcall" level ".init"))) = fn 會把 function 放在 .initcall + level 這個section..

在 init/main.c : kernel_init 會 do_basic_setup( ) --> do_initcalls() static void __init do_initcalls(void) { initcall_t *fn; for (fn = __early_initcall_end; fn < __initcall_end; fn++) do_one_initcall(*fn); /* Make sure there is no pending stuff from the initcall sequence */ flush_scheduled_work(); } 在 vmlinux.lds : . = ALIGN(16); __setup_start = .; *(.init.setup) __setup_end = .; __initcall_start = .; *(.initcallearly.init) __early_initcall_end = .; *(.initcall0.init) *(.initcall0s.init) *(.initcall1.init) *(.initcall1s.init) *(.initcall2.init) *(.initcall2s.init) *(.initcall3.init) *(.initcall3s.init) *(.initcall4.init) *(.initcall4s.init) *(.initcall5.init) *(.initcall5s.init) *(.initcallrootfs.init) *(.initcall6.init) *(.initcall6s.init) *(.initcall7.init) *(.initcall7s.init) __initcall_end = .; ? 為什摩中間有一個 initcallrootfs ?
.. 也就是說各 kernel module 中宣告 xxx_initcall( ) 的 function ,都會以上面 define 的次序,在 start_kernel( ) 時,一一被呼叫..


hibernate.c : late_initcall(software_resume); 因為在 開完後,手動 resume , sh console 是 OK 的,所以改一下 software_resume( ) 的位置...
從 late_initcall( ) 拿出來,在做完 /* Open the /dev/console on the rootfs, this should never fail */ if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0) printk(KERN_WARNING "Warning: unable to open an initial console.\n"); 以後再 call,就 OK 了
----> why ?



init/main.c : start_kernel( ) ----> console_init() ----> reset_init( ) -------->kernel_thread(kernel_init, NULL, CLONE_FS | CLONE_SIGHAND); ------------>sys_open("/dev/console",..) console_init( ) 跟 上面的 initcall 一樣: void __init console_init(void) { initcall_t *call; /* Setup the default TTY line discipline. */ tty_ldisc_begin(); /* * set up the console device so that later boot sequences can * inform about problems etc.. */ call = __con_initcall_start; while (call < __con_initcall_end) { (*call)(); call++; printk("*"); } } 可以打開 System.map 看 symbol:
800301c4 T __con_initcall_start
800301c4 t __initcall_con_init
800301c4 T __initcall_end
800301c8 t __initcall_mxcuart_console_init
800301cc T __con_initcall_end
其中 __initcall_con_init 和 __initcall_end 是同一個位置,所以實際上只有兩個 function
boot log 會有兩個 *.

2011年9月19日 星期一

swsusp for imx51 : worklog

software_resume ( ) 進行 image check, image restore 後,就做 hiberate_restore( ),然後就不會回來了 (?) ...
/** * hibernation_restore - quiesce devices and restore the hibernation * snapshot image. If successful, control returns in hibernation_snaphot() * @platform_mode - if set, use the platform driver, if available, to * prepare the platform firmware for the transition. * * Must be called with pm_mutex held */ int hibernation_restore(int platform_mode) { int error; gfp_t saved_mask; pm_prepare_console(); suspend_console(); saved_mask = clear_gfp_allowed_mask(GFP_IOFS); error = dpm_suspend_start(PMSG_QUIESCE); if (!error) { error = resume_target_kernel(platform_mode); dpm_resume_end(PMSG_RECOVER); } set_gfp_allowed_mask(saved_mask); resume_console(); pm_restore_console(); return error; } 根據 comment, run 完會回到 hibernate_snapshot( ) , 猜是 stack 變更,所以這個 function return 回去會到 hibnation_snapshot( ).



卡在 kernel_imx/driver/base/power/main.c 的 dpm_resume( ) 的: while (!list_empty(&dpm_list)) { dev = to_device(dpm_list.next); get_device(dev); if (dev->power.status >= DPM_OFF && !is_async(dev)) { int error; mutex_unlock(&dpm_list_mtx); error = device_resume(dev, state, false); mutex_lock(&dpm_list_mtx); if (error) pm_dev_err(dev, state, "", error); } else if (dev->power.status == DPM_SUSPENDING) { /* Allow new children of the device to be registered */ dev->power.status = DPM_RESUMING; } if (!list_empty(&dev->power.entry)) list_move_tail(&dev->power.entry, &list); put_device(dev); } 中間有 mmc0: error -110 during reumse (card was remved?) 的 error.
==> 拿掉 mmc0 的 driver ,雖然 error 不再發生了,但是還是一樣卡住...約 48 sec 後才完成這個section。

拿掉 使用 dma 的 uart 後,經過 48 sec 的 resume後,沒有 core dump 了, kernel msg 可以正常的輸出,但是 console input 還是沒回應。
==> 將所有uart 的 DMA 都關掉後,雖然還是要 48 sec,但是 resume 後已經沒有 core dump 了 .... console 依然不回應 ..

在 get_device( )後印出 device 的 init_name,還有 dev->driver->name。發現好像是 pmic_adc 和 pmic_leds 卡住。

拿掉 pmic_led, pmic_backlight (從 menuconfig 拿掉).
==> 剩下 pmic_adc 需要 10 幾秒的 resume 時間,而且是卡在 pmic_adc_resume( ) 中..

拿掉 pmic_adc_resume( ) 中 對 register 的 read/write code 後,就沒有卡住了。
==> 但是 console 還是沒反應..

拿到 uboot 的 resume=? 參數,等開機進入 kernel 後,再用手動 echo 179:4 > /sys/power/resume
==> console 有反應.....所以原因是? .. root 是 ramdisk ?.. console not setup correctly ?

因為 android dev 在 mmcblk 加入一層 block,和kernel 不一樣。
所以,在kernel boot phase,要用以前的 /dev/mmcblk0p4,而不是開機完後的,/dev/block/mmcblk0p4

2011年9月14日 星期三

Android, imx51 , swsusp -- hibernation .Worklog

grep 一下 *defconfig 的 HIBERNATION。
mips, ppc, sh, x86 都有,但是 ARM 沒有。

在 kernel/power/ 下就有 hibernate.c 等需要的 source code。

在 kernel/power/Makefile 中可以看到: obj-$(CONFIG_HIBERNATION) += hibernate.o snapshot.o swap.o user.o \ block_io.o 所以只要在 .config 中 開啟 CONFIG_HIBERNATION=y 就可以了(?)

但是在 make menuconfig 中,沒有 hiberanation 可以選 (Power Management)。

找一下 kernel/power/Kconfig: config HIBERNATION bool "Hibernation (aka 'suspend to disk')" depends on PM && SWAP && ARCH_HIBERNATION_POSSIBLE select SUSPEND_NVS if HAS_IOMEM 所以要找 PM 跟 SWAP 跟 ARCH_HIBERNATION_POSSIBLE。
find . -type f -name 'Kconfig' | xargs grep --color ARCH_HIBERNATION_POSSIBLE 結果 arch 下的 mips, sh, x86, s390, powerpc, 都有 這個選項, arm 沒有。
所以修改一下 arch/arm/Kconfig,抄一下其他 arch 的 ARCH_HIBERNATION_POSSIBLE 選項,,
大概就是... config ARCH_HIBERNATION_POSSIBLE bool default y 學一下,寫在 ARCH_SUSPEND_POSSIBLE 後面,因為是在 Power management options ,所以待會 make menuconfig 在 Powermanagement 中會有 hibernation 可以選
因為 default y,所以是 checked

這樣做完就 build 的話,會有 error: kernel/power/hibernate.c:27:25: error: asm/suspend.h: No such file or directory kernel/power/hibernate.c: In function 'create_image': kernel/power/hibernate.c:245: error: implicit declaration of function 'arch_prepare_suspend' make[2]: *** [kernel/power/hibernate.o] Error 1 make[1]: *** [kernel/power] Error 2 make: *** [kernel] Error 2 make: *** Waiting for unfinished jobs.... 缺 asm/suspend.h,就學簡單的,create 一個 arch/arm/include/suspend.h ,宣告一下.. static inline int arch_prepare_suspend(void) { return 0; } 接著 build,出現的 error 是: arm-eabi-4.4.3/bin/arm-eabi-ld: kernel/built-in.o: in function hibernation_restore:elfcore.c(.text+0x349a8): error: undefined reference to 'save_processor_state' arm-eabi-4.4.3/bin/arm-eabi-ld: kernel/built-in.o: in function hibernation_restore:elfcore.c(.text+0x349b8): error: undefined reference to 'swsusp_arch_resume' arm-eabi-4.4.3/bin/arm-eabi-ld: kernel/built-in.o: in function hibernation_restore:elfcore.c(.text+0x349d8): error: undefined reference to 'restore_processor_state' arm-eabi-ld: kernel/built-in.o: in function hibernation_snapshot:elfcore.c(.text+0x34d40): error: undefined reference to 'save_processor_state' arm-eabi-ld: kernel/built-in.o: in function hibernation_snapshot:elfcore.c(.text+0x34d44): error: undefined reference to 'swsusp_arch_suspend' arm-eabi-ld: kernel/built-in.o: in function hibernation_snapshot:elfcore.c(.text+0x34d5c): error: undefined reference to 'restore_processor_state' arm-eabi-ld: kernel/built-in.o: in function saveable_page:snapshot.c(.text+0x36458): error: undefined reference to 'pfn_is_nosave' make: *** [.tmp_vmlinux1] Error 1 沒作的有:
save_processor_state,restore_processor_state ---- kernel/power/hibernate.c使用
swsusp_arch_suspend, swsusp_arch_resume ---- kernel/power/hibernate.c 使用
pfn_is_nosave --- kernel/power/snapshot.c 使用

就抄那個 HIYOSHI 的 patch。
其中 NOSAVEDATA section in lds.S 上了 build 會有錯 (MACRO的原因?)。
ok 後,把 busybox 放上root。開始測試..

開機,make swap ...
# busybox mkswap /dev/block/mmcblk0p4 #busybox swapon /dev/block/mmcblk0p4 開始 hiberate.. # echo disk > /sys/power/state 會看到進suspend, user process 進 refrigerator. write image into partition..
最後是 manually power off ..

斷電,開機進入 uboot command console, 修改 boot argument..
要加上resume=???告訴 kernel 從哪一個 partition 拿 image。
原來想用resume=/dev/block/mmcblk0p4 但是這樣 resume 會說 "/dev/block/mmcblk0p4" 是 null device。
查一下是 init/do_mount.c : name_to_dev_t( ) 的問題,好像不 support 兩層 path。
funciton 的說明是: /* * Convert a name into device number. We accept the following variants: * * 1) device number in hexadecimal represents itself * 2) /dev/nfs represents Root_NFS (0xff) * 3) /dev/ represents the device number of disk * 4) /dev/ represents the device number * of partition - device number of disk plus the partition number * 5) /dev/p - same as the above, that form is * used when disk name of partitioned disk ends on a digit. * * If name doesn't have fall into the categories above, we return (0,0). * block_class is used to check if something is a disk name. If the disk * name contains slashes, the device name has them replaced with * bangs. */只好用第一項 device number in hexdecimal represets itself
ls -l /dev/block 來看,
/dev/block/mmcblk0p4 是 179:4
所以改一下 boot argument.. resume=179:4 就可以正確找到 resume partition, restor

但是 resume 後...卡住...停很久....然後才出現 left refrigerator 的 message。
然後出現 console prompt...但是沒反應..

標籤

網誌存檔