int pm_autosleep_set_state(suspend_state_t state) { #ifndef CONFIG_HIBERNATION if (state >= PM_SUSPEND_MAX) return -EINVAL; #endif __pm_stay_awake(autosleep_ws); mutex_lock(&autosleep_lock); autosleep_state = state; __pm_relax(autosleep_ws); if (state > PM_SUSPEND_ON) { pm_wakep_autosleep_enabled(true); queue_up_suspend_work(); #ifndef CONFIG_PM_SYNC_BEFORE_SUSPEND printk(KERN_INFO "PM: Syncing filesystems ... "); sys_sync(); printk("done.\n"); #endif } else { pm_wakep_autosleep_enabled(false); } mutex_unlock(&autosleep_lock); return 0; }
/** * enter_state - Do common work of entering low-power state. * @state: pm_state structure for state we're entering. * * Make sure we're the only ones trying to enter a sleep state. Fail * if someone has beat us to it, since we don't want anything weird to * happen when we wake up. * Then, do the setup for suspend, enter the state, and cleaup (after * we've woken up). */ static int enter_state(suspend_state_t state) { int error; if (!valid_state(state)) return -ENODEV; if (!mutex_trylock(&pm_mutex)) return -EBUSY; printk(KERN_INFO "PM: Syncing filesystems ... "); sys_sync(); printk("done.\n"); pr_debug("PM: Preparing system for %s sleep\n", pm_states[state]); error = suspend_prepare(); if (error) goto Unlock; if (suspend_test(TEST_FREEZER)) goto Finish; pr_debug("PM: Entering %s sleep\n", pm_states[state]); error = suspend_devices_and_enter(state); Finish: pr_debug("PM: Finishing wakeup.\n"); suspend_finish(); Unlock: mutex_unlock(&pm_mutex); return error; }
static void lge_dump_kernel_log() { extern int log_buf_copy(char *dest, int idx, int len); char log_buf[1024]; int idx = 0; int cnt; int h_file = 0; mm_segment_t oldfs = get_fs(); set_fs(KERNEL_DS); h_file = sys_open("/data/panic.txt", O_RDWR|O_CREAT,0644); if(h_file >= 0) { for (;;) { cnt = log_buf_copy(log_buf, idx, 1023); if (cnt <= 0) break; // WBT 20110314 [START] log_buf[cnt] = 0; // WBT 20110314 [END] sys_write(h_file,log_buf,cnt); idx += cnt; } sys_close(h_file); } else { printk("Can't open log file ret = %d.\n",h_file); } sys_sync(); set_fs(oldfs); }
/** * hom_prepare - Do prep work before entering low-power state. * * This is common code that is called for each state that we're entering. * Run suspend notifiers, allocate a console and stop all processes. */ static int hom_prepare(void) { int error; pm_prepare_console(); error = pm_notifier_call_chain(PM_HIBERNATION_PREPARE); if (error) goto Exit; error = usermodehelper_disable(); if (error) goto Exit; pr_info("PM: Syncing filesystems ... "); sys_sync(); pr_info("done.\n"); error = prepare_processes(); if (!error) return 0; usermodehelper_enable(); Exit: pm_notifier_call_chain(PM_POST_HIBERNATION); pm_restore_console(); return error; }
int hibernate(void) { int error; mutex_lock(&pm_mutex); /* The snapshot device should not be opened while we're running */ if (!atomic_add_unless(&snapshot_device_available, -1, 0)) { error = -EBUSY; goto Unlock; } error = pm_notifier_call_chain(PM_HIBERNATION_PREPARE); if (error) goto Exit; /* Allocate memory management structures */ error = create_basic_memory_bitmaps(); if (error) goto Exit; printk("Syncing filesystems ... "); sys_sync(); printk("done.\n"); error = prepare_processes(); if (error) goto Finish; if (hibernation_mode == HIBERNATION_TESTPROC) { printk("swsusp debug: Waiting for 5 seconds.\n"); mdelay(5000); goto Thaw; } error = hibernation_snapshot(hibernation_mode == HIBERNATION_PLATFORM); if (in_suspend && !error) { unsigned int flags = 0; if (hibernation_mode == HIBERNATION_PLATFORM) flags |= SF_PLATFORM_MODE; pr_debug("PM: writing image.\n"); error = swsusp_write(flags); swsusp_free(); if (!error) power_down(); } else { pr_debug("PM: Image restored successfully.\n"); swsusp_free(); } Thaw: unprepare_processes(); Finish: free_basic_memory_bitmaps(); Exit: pm_notifier_call_chain(PM_POST_HIBERNATION); atomic_inc(&snapshot_device_available); Unlock: mutex_unlock(&pm_mutex); return error; }
static void poweroff(struct work_struct *work) { synchronous_emergency_remount(); sys_sync(); printk(KERN_EMERG "Filesystems synced.\n"); kernel_power_off(); }
static void do_restart(void) { #if defined(CONFIG_POWER_KEY_CLR_RESET) clear_hw_reset(); #endif sys_sync(); machine_restart("power-key-force-hard"); }
NORET_TYPE void panic(const char * fmt, ...) { static char buf[1024]; va_list args; #if defined(CONFIG_ARCH_S390) unsigned long caller = (unsigned long) __builtin_return_address(0); #endif bust_spinlocks(1); va_start(args, fmt); vsprintf(buf, fmt, args); va_end(args); printk(KERN_EMERG "Kernel panic: %s\n",buf); if (in_interrupt()) printk(KERN_EMERG "In interrupt handler - not syncing\n"); else if (!current->pid) printk(KERN_EMERG "In idle task - not syncing\n"); else sys_sync(); bust_spinlocks(0); #ifdef CONFIG_SMP smp_send_stop(); #endif notifier_call_chain(&panic_notifier_list, 0, NULL); if (panic_timeout > 0) { /* * Delay timeout seconds before rebooting the machine. * We can't use the "normal" timers since we just panicked.. */ printk(KERN_EMERG "Rebooting in %d seconds..",panic_timeout); mdelay(panic_timeout*1000); /* * Should we run the reboot notifier. For the moment Im * choosing not too. It might crash, be corrupt or do * more harm than good for other reasons. */ machine_restart(NULL); } #ifdef __sparc__ { extern int stop_a_enabled; /* Make sure the user can actually press L1-A */ stop_a_enabled = 1; printk("Press L1-A to return to the boot prom\n"); } #endif #if defined(CONFIG_ARCH_S390) disabled_wait(caller); #endif sti(); for(;;) { CHECK_EMERGENCY_SYNC } }
// 该函数用来显示内核中出现重大错误信息,并运行文件系统同步函数,然后进入 // 死循环——死机。如果当前进程是任务0的话,还说明是交换任务出错, // 并且还没有运行文件系统同步函数。函数名前的关键字 volatile 用于告诉编译器gcc // 该函数不会返回。这样可以让gcc产生更好的代码,更重要的是使用这个关键字可以避免 // 产生某些(未初始化变量的)假警告信息。 // 等同于现在gcc的函数属性说明:void panic(const char *s) __attribute__((noreturn)); volatile void panic(const char * s) { printk("Kernel panic: %s\n\r",s); if (current == task[0]) printk("In swapper task - not syncing\n\r"); else sys_sync(); for(;;); }
static void touchwake_touchoff(struct work_struct * touchoff_work) { pr_info("%s: %s +\n", __func__, "sys_sync"); sys_sync(); pr_info("%s: %s -\n", __func__, "sys_sync"); touchwake_disable_touch(); wake_unlock(&touchwake_wake_lock); return; }
static void do_restart(struct work_struct *unused) { #if defined(CONFIG_POWER_KEY_CLR_RESET) clear_hw_reset(); #endif sys_sync(); KEY_LOGI("[PWR] Show Blocked State -- long press power key\n"); show_state_filter(TASK_UNINTERRUPTIBLE); machine_restart("power-key-force-hard"); }
static int prepare_suspend_processes(void) { sys_sync(); /* Syncing needs pdflushd, so do it before stopping processes */ if (freeze_processes()) { printk( KERN_ERR "Suspend failed: Not all processes stopped!\n" ); thaw_processes(); return 1; } return 0; }
static void sync_system(struct work_struct *work) { if (power_suspended) msleep(5000); pr_info("%s +\n", __func__); wake_lock(&sync_wake_lock); sys_sync(); wake_unlock(&sync_wake_lock); pr_info("%s -\n", __func__); }
/* * process sync command, let all buffered modification to be written to the disk. */ static void rfs_sync(struct aipc_rfs_msg *msg) { int ret; ret = sys_sync(); if(ret < 0) { DMSG("rfs_sync error: %d\n", ret); } msg->parameter[0] = ret; msg->msg_type = AIPC_RFS_REPLY_OK; }
static void magic_reboot_wq_handler(struct work_struct *w) { /* Keep trying until it works, although the inital delay set * waiting for MMC to come up should be sufficient */ if (access_osip_record(osip_invalidate, (void *)magic_target)) schedule_delayed_work(&magic_reboot_wq, msecs_to_jiffies(100)); else { pr_info("Rebooting on behalf of magic key press\n"); sys_sync(); kernel_restart(NULL); } }
/** * enter_state - Do common work needed to enter system sleep state. * @state: System sleep state to enter. * * Make sure that no one else is trying to put the system into a sleep state. * Fail if that's not the case. Otherwise, prepare for system suspend, make the * system enter the given sleep state and clean up after wakeup. */ static int enter_state(suspend_state_t state) { int error; if (state == PM_SUSPEND_FREEZE) { #ifdef CONFIG_PM_DEBUG if (pm_test_level != TEST_NONE && pm_test_level <= TEST_CPUS) { pr_warning("PM: Unsupported test mode for freeze state," "please choose none/freezer/devices/platform.\n"); return -EAGAIN; } #endif } else if (!valid_state(state)) { return -EINVAL; } if (!mutex_trylock(&pm_mutex)) return -EBUSY; if (state == PM_SUSPEND_FREEZE) freeze_begin(); #ifdef CONFIG_HAS_EARLYSUSPEND if (suspendsync) suspend_sys_sync_queue(); #else if (suspendsync) { printk(KERN_INFO "PM: Syncing filesystems ... "); sys_sync(); printk("done.\n"); } #endif pr_debug("PM: Preparing system for %s sleep\n", pm_states[state].label); error = suspend_prepare(state); if (error) goto Unlock; if (suspend_test(TEST_FREEZER)) goto Finish; pr_debug("PM: Entering %s sleep\n", pm_states[state].label); pm_restrict_gfp_mask(); error = suspend_devices_and_enter(state); pm_restore_gfp_mask(); Finish: pr_debug("PM: Finishing wakeup.\n"); suspend_finish(); Unlock: mutex_unlock(&pm_mutex); return error; }
/** * enter_state - Do common work needed to enter system sleep state. * @state: System sleep state to enter. * * Make sure that no one else is trying to put the system into a sleep state. * Fail if that's not the case. Otherwise, prepare for system suspend, make the * system enter the given sleep state and clean up after wakeup. */ static int enter_state(suspend_state_t state) { int error; trace_suspend_resume(TPS("suspend_enter"), state, true); if (state == PM_SUSPEND_FREEZE) { #ifdef CONFIG_PM_DEBUG if (pm_test_level != TEST_NONE && pm_test_level <= TEST_CPUS) { pr_warn("PM: Unsupported test mode for suspend to idle, please choose none/freezer/devices/platform.\n"); return -EAGAIN; } #endif } else if (!valid_state(state)) { return -EINVAL; } if (!mutex_trylock(&pm_mutex)) return -EBUSY; if (state == PM_SUSPEND_FREEZE) freeze_begin(); #ifndef CONFIG_SUSPEND_SKIP_SYNC trace_suspend_resume(TPS("sync_filesystems"), 0, true); printk(KERN_INFO "PM: Syncing filesystems ... "); sys_sync(); printk("done.\n"); trace_suspend_resume(TPS("sync_filesystems"), 0, false); #endif pr_debug("PM: Preparing system for sleep (%s)\n", pm_states[state]); pm_suspend_clear_flags(); error = suspend_prepare(state); if (error) goto Unlock; if (suspend_test(TEST_FREEZER)) goto Finish; trace_suspend_resume(TPS("suspend_enter"), state, false); pr_debug("PM: Suspending system (%s)\n", pm_states[state]); pm_restrict_gfp_mask(); error = suspend_devices_and_enter(state); pm_restore_gfp_mask(); Finish: pr_debug("PM: Finishing wakeup.\n"); suspend_finish(); Unlock: mutex_unlock(&pm_mutex); return error; }
void sys_sync_debug(void) { mod_timer(&sys_sync_timer, jiffies + SYS_SYNC_TIMEOUT); /* To ensure the sync(writeback) function is triggered * we record the context switch counter at 1 second later */ mod_timer(&record_sync_timer, jiffies + 1*HZ); sys_sync_done = 0; sys_sync(); sys_sync_done = 1; del_timer(&record_sync_timer); del_timer(&sys_sync_timer); }
NORET_TYPE void panic(const char * fmt, ...) { static char buf[1024]; va_list args; va_start(args, fmt); vsprintf(buf, fmt, args); va_end(args); printk(KERN_EMERG "Kernel panic: %s\n",buf); if (current == task[0]) printk(KERN_EMERG "In swapper task - not syncing\n"); else sys_sync(); for(;;); }
static int ecryptfs_release(struct inode *inode, struct file *file) { #ifdef CONFIG_SDP struct ecryptfs_crypt_stat *crypt_stat; crypt_stat = &ecryptfs_inode_to_private(inode)->crypt_stat; if(crypt_stat->flags & ECRYPTFS_DEK_IS_SENSITIVE) { #if 0 #ifdef SYNC_ONLY_CURRENT_SB struct super_block *sb = inode->i_sb; sync_inodes_sb(sb); writeback_inodes_sb(sb, WB_REASON_SYNC); #else sys_sync(); #endif DEK_LOGD("%s() sensitive inode being closed. [ino:%lu, state:%lu ref_count:%d efs_flag:0x%0.8x]\n", __func__, inode->i_ino, inode->i_state, atomic_read(&inode->i_count), crypt_stat->flags); spin_lock(&inode->i_lock); if ((inode->i_state & (I_FREEING|I_WILL_FREE|I_NEW)) || (inode->i_mapping->nrpages == 0)) { spin_unlock(&inode->i_lock); } else { printk("freeing sensitive inode\n"); invalidate_mapping_pages(inode->i_mapping, 0, -1); } spin_unlock(&inode->i_lock); #else DEK_LOGD("%s() sensitive inode being closed. [ino:%lu, state:%lu ref_count:%d]\n", __func__, inode->i_ino, inode->i_state, atomic_read(&inode->i_count)); ecryptfs_clean_sdp_dek(crypt_stat); if(ecryptfs_is_persona_locked(crypt_stat->userid)) ecryptfs_mm_drop_cache(crypt_stat->userid); } #endif #endif ecryptfs_put_lower_file(inode); kmem_cache_free(ecryptfs_file_info_cache, ecryptfs_file_to_private(file)); return 0; }
int lx_write_misc(int index, char* buf, int size) { int h_file = 0; int ret = 0; int offset = 0; mm_segment_t oldfs; if(buf == NULL) return 0; if(size > MISC_MSG_LENGTH) return 0; oldfs = get_fs(); set_fs(KERNEL_DS); h_file = sys_open(MISC_PARTITION, O_RDWR,0); if(h_file >= 0) { offset = MISC_MSG_BASE_OFFSET + (MISC_MSG_LENGTH * index); pr_info("write MISC size = %d, offset = %d\n",size, offset); sys_lseek( h_file, offset, 0 ); ret = sys_write( h_file, buf, size); pr_info("write MISC ret = %d\n",ret); if( ret != size ) { pr_err("Can't write MISC partition.\n"); return ret; } sys_close(h_file); } else { pr_err("Can't open MISC partition handle = %d.\n", h_file); return 0; } set_fs(oldfs); sys_sync(); pr_info("write MISC index = %d, message = %s\n", index, buf); return ret; }
/** * enter_state - Do common work of entering low-power state. * @state: pm_state structure for state we're entering. * * Make sure we're the only ones trying to enter a sleep state. Fail * if someone has beat us to it, since we don't want anything weird to * happen when we wake up. * Then, do the setup for suspend, enter the state, and cleaup (after * we've woken up). */ int enter_state(suspend_state_t state) { int error; if (!valid_state(state)) return -ENODEV; if (!mutex_trylock(&pm_mutex)) return -EBUSY; printk(KERN_INFO "PM: Syncing filesystems ... "); sys_sync(); printk("done.\n"); pr_debug("PM: Preparing system for %s sleep\n", pm_states[state]); error = suspend_prepare(); if (error){ printk(KERN_ERR "PM: suspend prepare failed ... "); goto Unlock; } if (suspend_test(TEST_FREEZER)){ printk(KERN_ERR "PM: suspend test failed ... "); goto Finish; } pr_debug("PM: Entering %s sleep\n", pm_states[state]); error = suspend_devices_and_enter(state); Finish: pr_debug("PM: Finishing wakeup.\n"); suspend_finish(); Unlock: mutex_unlock(&pm_mutex); #ifdef CONFIG_SUSPEND_WATCHDOG { #ifdef CONFIG_HAS_EARLYSUSPEND extern void reset_watchdog(void); reset_watchdog(); #else extern void disable_watchdog(void); disable_watchdog(); #endif } #endif return error; }
/** * @brief Shutdowns the system. */ PUBLIC int sys_shutdown(void) { /* Not allowed. */ if (!IS_SUPERUSER(curr_proc)) return (-EPERM); shutting_down = 1; cdev_ioctl(kout, TTY_CLEAR, 0); kprintf("system is going to shutdown NOW"); kprintf("synchronizing data..."); sys_sync(); kprintf("asking process to terminate..."); sys_kill(-1, SIGKILL); return (0); }
void kernel_shutdown() { current_task->uid=0; shutting_down=1; /** Write the system-down stuffs */ /* Unload modules, unmount stuff, sync stuff, kill all tasks*/ kill_all_tasks(); kernel_task->next = current_task; current_task->next=0; current_task->prev = kernel_task; sys_sync(PRINT_LEVEL); unmount_all(); #if CONFIG_MODULES unload_all_modules(1); #endif kprintf("Everything under the sun is in tune, but the sun is eclipsed by the moon.\n"); }
/** * enter_state - Do common work needed to enter system sleep state. * @state: System sleep state to enter. * * Make sure that no one else is trying to put the system into a sleep state. * Fail if that's not the case. Otherwise, prepare for system suspend, make the * system enter the given sleep state and clean up after wakeup. */ static int enter_state(suspend_state_t state) { int error; if (!valid_state(state)) return -ENODEV; if (!mutex_trylock(&pm_mutex)) return -EBUSY; if (state == PM_SUSPEND_FREEZE) freeze_begin(); #ifndef CONFIG_ARCH_HI3630 printk(KERN_INFO "PM: Syncing filesystems ... "); sys_sync(); printk("done.\n"); #else hisi_sys_sync_queue(); #endif pr_debug("PM: Preparing system for %s sleep\n", pm_states[state]); error = suspend_prepare(state); if (error) goto Unlock; if (suspend_test(TEST_FREEZER)) goto Finish; pr_debug("PM: Entering %s sleep\n", pm_states[state]); pm_restrict_gfp_mask(); error = suspend_devices_and_enter(state); pm_restore_gfp_mask(); Finish: pr_debug("PM: Finishing wakeup.\n"); suspend_finish(); Unlock: mutex_unlock(&pm_mutex); return error; }
int lge_nvdata_raw_write(int offset, char* buf, int size) { if(size == 0) return 0; int h_file = 0; int ret = 0; mm_segment_t oldfs = get_fs(); set_fs(KERNEL_DS); h_file = sys_open(LGE_NVDATA_PARTITION, O_RDWR,0); if(h_file >= 0) { printk("write NV size = %d, offset = %d\n",size, offset); sys_lseek( h_file, offset, 0 ); ret = sys_write( h_file, buf, size); printk("write NV ret = %d\n",ret); if( ret != size ) { printk("Can't write NVDATA.\n"); return ret; } sys_close(h_file); } else { printk("Can't open NVDATA partition handle = %d.\n",h_file); return 0; } set_fs(oldfs); sys_sync(); if (size > 1) printk("write NV offset = %d, message = %s(%x)[%d]\n", offset, buf, *buf, *buf); else printk("write NV offset = %d, message = %x[%d]\n", offset, *buf, *buf); return size; }
static void oled_detection_work(struct work_struct *work) { struct lcd_info *lcd = container_of(work, struct lcd_info, oled_detection.work); struct file *fp; char name[128]; struct timespec ts; struct rtc_time tm; int oled_det_level = gpio_get_value(GPIO_OLED_DET); dev_info(&lcd->ld->dev, "%s, GPIO_OLED_DET is %s\n", __func__, oled_det_level ? "high" : "low"); if (!oled_det_level) { if (lcd->oled_detection_count < 3) { getnstimeofday(&ts); rtc_time_to_tm(ts.tv_sec, &tm); sprintf(name, "%s%02d-%02d_%02d:%02d:%02d_%02d", "/sdcard/", tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, lcd->oled_detection_count); fp = filp_open(name, O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO); if (IS_ERR_OR_NULL(fp)) dev_info(&lcd->ld->dev, "fail to create vgh detection log file, %s\n", name); schedule_delayed_work(&lcd->oled_detection, msecs_to_jiffies(10)); lcd->oled_detection_count++; } else { dev_info(&lcd->ld->dev, "VGH IS NOT OK! LCD SMASH!!!\n"); getnstimeofday(&ts); rtc_time_to_tm(ts.tv_sec, &tm); sprintf(name, "%s%02d-%02d_%02d:%02d:%02d_POWEROFF", "/sdcard/", tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); fp = filp_open(name, O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO); if (IS_ERR_OR_NULL(fp)) dev_info(&lcd->ld->dev, "fail to create vgh detection log file, %s\n", name); sys_sync(); kernel_power_off(); } } else dev_info(&lcd->ld->dev, "VGH IS OK\n"); }
static void internal_halt(int mode) { switch (mode) { case 0: printk("\nBye.\n"); break; case 1: printk("\nHalt.\n"); break; case 2: printk("\nPush RESET button to reboot the system.\n"); break; } sys_sync(); udelay(1000 * 1000); ps2_halt(mode); }
/** * freeze_processes - tell processes to enter the refrigerator * * Returns 0 on success, or the number of processes that didn't freeze, * although they were told to. */ int freeze_processes(void) { unsigned int nr_unfrozen; printk("Stopping tasks ... "); nr_unfrozen = try_to_freeze_tasks(FREEZER_USER_SPACE); if (nr_unfrozen) return nr_unfrozen; sys_sync(); nr_unfrozen = try_to_freeze_tasks(FREEZER_KERNEL_THREADS); if (nr_unfrozen) return nr_unfrozen; printk("done.\n"); BUG_ON(in_atomic()); return 0; }
static void bq27410_battery_update_work(struct work_struct *work) { struct file *filp; int retval; unsigned long len = sizeof(g_filename); struct bq27410_device_info *di = container_of(work, struct bq27410_device_info, work.work); retval = update_get_flen(g_filename); if(retval == 0){ printk("bq27410_battery_update_work:update_get_flen error.\n"); return; } mutex_lock(&g_bq27410_mutex); retval = bq27410_update_flash_data(filp, g_filename, len, NULL); mutex_unlock(&g_bq27410_mutex); if(retval == 0) { #if UPDATE_FIRMWARE_RESTART printk("bq27410_battery_update_work ,update success,restart the system.\n"); virtual_battery_enable = 0; //after update firmware ,restart the system. sys_sync(); msleep(200); kernel_restart(NULL); return; #else printk("bq27410_battery_update_work ,update success.\n"); #endif } else{ printk("bq27410_battery_update_work:update failed.\n"); return; } bq27410_write_batt_insert(g_client); msleep(2000); bq27410_write_batt_insert(g_client); INIT_DELAYED_WORK(&bq27410_di->work, bq27410_battery_work); schedule_delayed_work(&bq27410_di->work, bq27410_di->interval); }