Commit 0eb217f9 authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] generalise system_running

From: Olof Johansson <olof@austin.ibm.com>

It's currently a boolean, but that means that system_running goes to zero
again when shutting down.  So we then use code (in the page allocator) which
is only designed to be used during bootup - it is marked __init.

So we need to be able to distinguish early boot state from late shutdown
state.  Rename system_running to system_state and give it the three
appropriate states.
parent 243c64b2
...@@ -154,11 +154,11 @@ static unsigned char __pmac pmu_nvram_read_byte(int addr) ...@@ -154,11 +154,11 @@ static unsigned char __pmac pmu_nvram_read_byte(int addr)
struct adb_request req; struct adb_request req;
DECLARE_COMPLETION(req_complete); DECLARE_COMPLETION(req_complete);
req.arg = system_running ? &req_complete : NULL; req.arg = system_state == SYSTEM_RUNNING ? &req_complete : NULL;
if (pmu_request(&req, pmu_nvram_complete, 3, PMU_READ_NVRAM, if (pmu_request(&req, pmu_nvram_complete, 3, PMU_READ_NVRAM,
(addr >> 8) & 0xff, addr & 0xff)) (addr >> 8) & 0xff, addr & 0xff))
return 0xff; return 0xff;
if (system_running) if (system_state == SYSTEM_RUNNING)
wait_for_completion(&req_complete); wait_for_completion(&req_complete);
while (!req.complete) while (!req.complete)
pmu_poll(); pmu_poll();
...@@ -170,11 +170,11 @@ static void __pmac pmu_nvram_write_byte(int addr, unsigned char val) ...@@ -170,11 +170,11 @@ static void __pmac pmu_nvram_write_byte(int addr, unsigned char val)
struct adb_request req; struct adb_request req;
DECLARE_COMPLETION(req_complete); DECLARE_COMPLETION(req_complete);
req.arg = system_running ? &req_complete : NULL; req.arg = system_state == SYSTEM_RUNNING ? &req_complete : NULL;
if (pmu_request(&req, pmu_nvram_complete, 4, PMU_WRITE_NVRAM, if (pmu_request(&req, pmu_nvram_complete, 4, PMU_WRITE_NVRAM,
(addr >> 8) & 0xff, addr & 0xff, val)) (addr >> 8) & 0xff, addr & 0xff, val))
return; return;
if (system_running) if (system_state == SYSTEM_RUNNING)
wait_for_completion(&req_complete); wait_for_completion(&req_complete);
while (!req.complete) while (!req.complete)
pmu_poll(); pmu_poll();
......
...@@ -109,9 +109,15 @@ static inline void console_verbose(void) ...@@ -109,9 +109,15 @@ static inline void console_verbose(void)
extern void bust_spinlocks(int yes); extern void bust_spinlocks(int yes);
extern int oops_in_progress; /* If set, an oops, panic(), BUG() or die() is in progress */ extern int oops_in_progress; /* If set, an oops, panic(), BUG() or die() is in progress */
extern int panic_on_oops; extern int panic_on_oops;
extern int system_running; extern int system_state; /* See values below */
extern int tainted; extern int tainted;
extern const char *print_tainted(void); extern const char *print_tainted(void);
/* Values used for system_state */
#define SYSTEM_BOOTING 0
#define SYSTEM_RUNNING 1
#define SYSTEM_SHUTDOWN 2
#define TAINT_PROPRIETARY_MODULE (1<<0) #define TAINT_PROPRIETARY_MODULE (1<<0)
#define TAINT_FORCED_MODULE (1<<1) #define TAINT_FORCED_MODULE (1<<1)
#define TAINT_UNSAFE_SMP (1<<2) #define TAINT_UNSAFE_SMP (1<<2)
......
...@@ -94,11 +94,7 @@ extern void driver_init(void); ...@@ -94,11 +94,7 @@ extern void driver_init(void);
extern void tc_init(void); extern void tc_init(void);
#endif #endif
/* int system_state; /* SYSTEM_BOOTING/RUNNING/SHUTDOWN */
* Are we up and running (ie do we have all the infrastructure
* set up)
*/
int system_running;
/* /*
* Boot command-line arguments * Boot command-line arguments
...@@ -613,7 +609,7 @@ static int init(void * unused) ...@@ -613,7 +609,7 @@ static int init(void * unused)
*/ */
free_initmem(); free_initmem();
unlock_kernel(); unlock_kernel();
system_running = 1; system_state = SYSTEM_RUNNING;
if (sys_open("/dev/console", O_RDWR, 0) < 0) if (sys_open("/dev/console", O_RDWR, 0) < 0)
printk("Warning: unable to open an initial console.\n"); printk("Warning: unable to open an initial console.\n");
......
...@@ -249,7 +249,7 @@ int call_usermodehelper(char *path, char **argv, char **envp, int wait) ...@@ -249,7 +249,7 @@ int call_usermodehelper(char *path, char **argv, char **envp, int wait)
}; };
DECLARE_WORK(work, __call_usermodehelper, &sub_info); DECLARE_WORK(work, __call_usermodehelper, &sub_info);
if (!system_running) if (system_state != SYSTEM_RUNNING)
return -EBUSY; return -EBUSY;
if (path[0] == '\0') if (path[0] == '\0')
......
...@@ -522,7 +522,8 @@ asmlinkage int printk(const char *fmt, ...) ...@@ -522,7 +522,8 @@ asmlinkage int printk(const char *fmt, ...)
log_level_unknown = 1; log_level_unknown = 1;
} }
if (!cpu_online(smp_processor_id()) && !system_running) { if (!cpu_online(smp_processor_id()) &&
system_state != SYSTEM_RUNNING) {
/* /*
* Some console drivers may assume that per-cpu resources have * Some console drivers may assume that per-cpu resources have
* been allocated. So don't allow them to be called by this * been allocated. So don't allow them to be called by this
......
...@@ -2982,7 +2982,8 @@ void __might_sleep(char *file, int line) ...@@ -2982,7 +2982,8 @@ void __might_sleep(char *file, int line)
#if defined(in_atomic) #if defined(in_atomic)
static unsigned long prev_jiffy; /* ratelimiting */ static unsigned long prev_jiffy; /* ratelimiting */
if ((in_atomic() || irqs_disabled()) && system_running) { if ((in_atomic() || irqs_disabled()) &&
system_state == SYSTEM_RUNNING) {
if (time_before(jiffies, prev_jiffy + HZ) && prev_jiffy) if (time_before(jiffies, prev_jiffy + HZ) && prev_jiffy)
return; return;
prev_jiffy = jiffies; prev_jiffy = jiffies;
......
...@@ -436,7 +436,7 @@ asmlinkage long sys_reboot(int magic1, int magic2, unsigned int cmd, void __user ...@@ -436,7 +436,7 @@ asmlinkage long sys_reboot(int magic1, int magic2, unsigned int cmd, void __user
switch (cmd) { switch (cmd) {
case LINUX_REBOOT_CMD_RESTART: case LINUX_REBOOT_CMD_RESTART:
notifier_call_chain(&reboot_notifier_list, SYS_RESTART, NULL); notifier_call_chain(&reboot_notifier_list, SYS_RESTART, NULL);
system_running = 0; system_state = SYSTEM_SHUTDOWN;
device_shutdown(); device_shutdown();
printk(KERN_EMERG "Restarting system.\n"); printk(KERN_EMERG "Restarting system.\n");
machine_restart(NULL); machine_restart(NULL);
...@@ -452,7 +452,7 @@ asmlinkage long sys_reboot(int magic1, int magic2, unsigned int cmd, void __user ...@@ -452,7 +452,7 @@ asmlinkage long sys_reboot(int magic1, int magic2, unsigned int cmd, void __user
case LINUX_REBOOT_CMD_HALT: case LINUX_REBOOT_CMD_HALT:
notifier_call_chain(&reboot_notifier_list, SYS_HALT, NULL); notifier_call_chain(&reboot_notifier_list, SYS_HALT, NULL);
system_running = 0; system_state = SYSTEM_SHUTDOWN;
device_shutdown(); device_shutdown();
printk(KERN_EMERG "System halted.\n"); printk(KERN_EMERG "System halted.\n");
machine_halt(); machine_halt();
...@@ -462,7 +462,7 @@ asmlinkage long sys_reboot(int magic1, int magic2, unsigned int cmd, void __user ...@@ -462,7 +462,7 @@ asmlinkage long sys_reboot(int magic1, int magic2, unsigned int cmd, void __user
case LINUX_REBOOT_CMD_POWER_OFF: case LINUX_REBOOT_CMD_POWER_OFF:
notifier_call_chain(&reboot_notifier_list, SYS_POWER_OFF, NULL); notifier_call_chain(&reboot_notifier_list, SYS_POWER_OFF, NULL);
system_running = 0; system_state = SYSTEM_SHUTDOWN;
device_shutdown(); device_shutdown();
printk(KERN_EMERG "Power down.\n"); printk(KERN_EMERG "Power down.\n");
machine_power_off(); machine_power_off();
...@@ -478,7 +478,7 @@ asmlinkage long sys_reboot(int magic1, int magic2, unsigned int cmd, void __user ...@@ -478,7 +478,7 @@ asmlinkage long sys_reboot(int magic1, int magic2, unsigned int cmd, void __user
buffer[sizeof(buffer) - 1] = '\0'; buffer[sizeof(buffer) - 1] = '\0';
notifier_call_chain(&reboot_notifier_list, SYS_RESTART, buffer); notifier_call_chain(&reboot_notifier_list, SYS_RESTART, buffer);
system_running = 0; system_state = SYSTEM_SHUTDOWN;
device_shutdown(); device_shutdown();
printk(KERN_EMERG "Restarting system with command '%s'.\n", buffer); printk(KERN_EMERG "Restarting system with command '%s'.\n", buffer);
machine_restart(buffer); machine_restart(buffer);
......
...@@ -734,7 +734,7 @@ fastcall unsigned long __get_free_pages(unsigned int gfp_mask, unsigned int orde ...@@ -734,7 +734,7 @@ fastcall unsigned long __get_free_pages(unsigned int gfp_mask, unsigned int orde
struct page * page; struct page * page;
#ifdef CONFIG_NUMA #ifdef CONFIG_NUMA
if (unlikely(!system_running)) if (unlikely(system_state == SYSTEM_BOOTING))
return get_boot_pages(gfp_mask, order); return get_boot_pages(gfp_mask, order);
#endif #endif
page = alloc_pages(gfp_mask, order); page = alloc_pages(gfp_mask, order);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment