[IA64] Fix perfmon sysctl directory modes
[safe/jmp/linux-2.6] / arch / ia64 / kernel / process.c
index 474d75f..2418289 100644 (file)
@@ -4,10 +4,10 @@
  * Copyright (C) 1998-2003 Hewlett-Packard Co
  *     David Mosberger-Tang <davidm@hpl.hp.com>
  * 04/11/17 Ashok Raj  <ashok.raj@intel.com> Added CPU Hotplug Support
+ *
+ * 2005-10-07 Keith Owens <kaos@sgi.com>
+ *           Add notify_die() hooks.
  */
-#define __KERNEL_SYSCALLS__    /* see <asm/unistd.h> */
-#include <linux/config.h>
-
 #include <linux/cpu.h>
 #include <linux/pm.h>
 #include <linux/elf.h>
 #include <linux/personality.h>
 #include <linux/sched.h>
 #include <linux/slab.h>
-#include <linux/smp_lock.h>
 #include <linux/stddef.h>
 #include <linux/thread_info.h>
 #include <linux/unistd.h>
 #include <linux/efi.h>
 #include <linux/interrupt.h>
 #include <linux/delay.h>
+#include <linux/kdebug.h>
 
 #include <asm/cpu.h>
 #include <asm/delay.h>
 #include <asm/elf.h>
 #include <asm/ia32.h>
 #include <asm/irq.h>
+#include <asm/kexec.h>
 #include <asm/pgalloc.h>
 #include <asm/processor.h>
 #include <asm/sal.h>
@@ -104,7 +105,8 @@ show_regs (struct pt_regs *regs)
        unsigned long ip = regs->cr_iip + ia64_psr(regs)->ri;
 
        print_modules();
-       printk("\nPid: %d, CPU %d, comm: %20s\n", current->pid, smp_processor_id(), current->comm);
+       printk("\nPid: %d, CPU %d, comm: %20s\n", task_pid_nr(current),
+                       smp_processor_id(), current->comm);
        printk("psr : %016lx ifs : %016lx ip  : [<%016lx>]    %s\n",
               regs->cr_ipsr, regs->cr_ifs, ip, print_tainted());
        print_symbol("ip is at %s\n", ip);
@@ -154,7 +156,7 @@ show_regs (struct pt_regs *regs)
 }
 
 void
-do_notify_resume_user (sigset_t *oldset, struct sigscratch *scr, long in_syscall)
+do_notify_resume_user (sigset_t *unused, struct sigscratch *scr, long in_syscall)
 {
        if (fsys_mode(current, &scr->pt)) {
                /* defer signal-handling etc. until we return to privilege-level 0.  */
@@ -169,8 +171,8 @@ do_notify_resume_user (sigset_t *oldset, struct sigscratch *scr, long in_syscall
 #endif
 
        /* deal with pending signal delivery */
-       if (test_thread_flag(TIF_SIGPENDING))
-               ia64_do_signal(oldset, scr, in_syscall);
+       if (test_thread_flag(TIF_SIGPENDING)||test_thread_flag(TIF_RESTORE_SIGMASK))
+               ia64_do_signal(scr, in_syscall);
 }
 
 static int pal_halt        = 1;
@@ -178,12 +180,12 @@ static int can_do_pal_halt = 1;
 
 static int __init nohalt_setup(char * str)
 {
-       pal_halt = 0;
+       pal_halt = can_do_pal_halt = 0;
        return 1;
 }
 __setup("nohalt", nohalt_setup);
 
-int
+void
 update_pal_halt_status(int status)
 {
        can_do_pal_halt = pal_halt && status;
@@ -195,13 +197,17 @@ update_pal_halt_status(int status)
 void
 default_idle (void)
 {
-       int can_do_pal;
-
-       while (!need_resched())
-               if (can_do_pal_halt)
-                       safe_halt();
-               else
+       local_irq_enable();
+       while (!need_resched()) {
+               if (can_do_pal_halt) {
+                       local_irq_disable();
+                       if (!need_resched()) {
+                               safe_halt();
+                       }
+                       local_irq_enable();
+               } else
                        cpu_relax();
+       }
 }
 
 #ifdef CONFIG_HOTPLUG_CPU
@@ -235,6 +241,7 @@ void cpu_idle_wait(void)
 {
        unsigned int cpu, this_cpu = get_cpu();
        cpumask_t map;
+       cpumask_t tmp = current->cpus_allowed;
 
        set_cpus_allowed(current, cpumask_of_cpu(this_cpu));
        put_cpu();
@@ -256,6 +263,7 @@ void cpu_idle_wait(void)
                }
                cpus_and(map, map, cpu_online_map);
        } while (!cpus_empty(map));
+       set_cpus_allowed(current, tmp);
 }
 EXPORT_SYMBOL_GPL(cpu_idle_wait);
 
@@ -263,16 +271,26 @@ void __attribute__((noreturn))
 cpu_idle (void)
 {
        void (*mark_idle)(int) = ia64_mark_idle;
+       int cpu = smp_processor_id();
 
        /* endless idle loop with no priority at all */
        while (1) {
+               if (can_do_pal_halt) {
+                       current_thread_info()->status &= ~TS_POLLING;
+                       /*
+                        * TS_POLLING-cleared state must be visible before we
+                        * test NEED_RESCHED:
+                        */
+                       smp_mb();
+               } else {
+                       current_thread_info()->status |= TS_POLLING;
+               }
+
+               if (!need_resched()) {
+                       void (*idle)(void);
 #ifdef CONFIG_SMP
-               if (!need_resched())
                        min_xtp();
 #endif
-               while (!need_resched()) {
-                       void (*idle)(void);
-
                        if (__get_cpu_var(cpu_idle_state))
                                __get_cpu_var(cpu_idle_state) = 0;
 
@@ -284,17 +302,17 @@ cpu_idle (void)
                        if (!idle)
                                idle = default_idle;
                        (*idle)();
-               }
-
-               if (mark_idle)
-                       (*mark_idle)(0);
-
+                       if (mark_idle)
+                               (*mark_idle)(0);
 #ifdef CONFIG_SMP
-               normal_xtp();
+                       normal_xtp();
 #endif
+               }
+               preempt_enable_no_resched();
                schedule();
+               preempt_disable();
                check_pgt_cache();
-               if (cpu_is_offline(smp_processor_id()))
+               if (cpu_is_offline(cpu))
                        play_dead();
        }
 }
@@ -319,7 +337,7 @@ ia64_save_extra (struct task_struct *task)
 #endif
 
 #ifdef CONFIG_IA32_SUPPORT
-       if (IS_IA32_PROCESS(ia64_task_regs(task)))
+       if (IS_IA32_PROCESS(task_pt_regs(task)))
                ia32_save_state(task);
 #endif
 }
@@ -344,7 +362,7 @@ ia64_load_extra (struct task_struct *task)
 #endif
 
 #ifdef CONFIG_IA32_SUPPORT
-       if (IS_IA32_PROCESS(ia64_task_regs(task)))
+       if (IS_IA32_PROCESS(task_pt_regs(task)))
                ia32_load_state(task);
 #endif
 }
@@ -479,14 +497,15 @@ copy_thread (int nr, unsigned long clone_flags,
         * If we're cloning an IA32 task then save the IA32 extra
         * state from the current task to the new task
         */
-       if (IS_IA32_PROCESS(ia64_task_regs(current))) {
+       if (IS_IA32_PROCESS(task_pt_regs(current))) {
                ia32_save_state(p);
                if (clone_flags & CLONE_SETTLS)
                        retval = ia32_clone_tls(p, child_ptregs);
 
                /* Copy partially mapped page list */
                if (!retval)
-                       retval = ia32_copy_partial_page_list(p, clone_flags);
+                       retval = ia32_copy_ia64_partial_page_list(p,
+                                                               clone_flags);
        }
 #endif
 
@@ -500,7 +519,8 @@ copy_thread (int nr, unsigned long clone_flags,
 static void
 do_copy_task_regs (struct task_struct *task, struct unw_frame_info *info, void *arg)
 {
-       unsigned long mask, sp, nat_bits = 0, ip, ar_rnat, urbs_end, cfm;
+       unsigned long mask, sp, nat_bits = 0, ar_rnat, urbs_end, cfm;
+       unsigned long uninitialized_var(ip);    /* GCC be quiet */
        elf_greg_t *dst = arg;
        struct pt_regs *pt;
        char nat;
@@ -692,7 +712,7 @@ int
 kernel_thread_helper (int (*fn)(void *), void *arg)
 {
 #ifdef CONFIG_IA32_SUPPORT
-       if (IS_IA32_PROCESS(ia64_task_regs(current))) {
+       if (IS_IA32_PROCESS(task_pt_regs(current))) {
                /* A kernel thread is always a 64-bit process. */
                current->thread.map_base  = DEFAULT_MAP_BASE;
                current->thread.task_size = DEFAULT_TASK_SIZE;
@@ -712,8 +732,13 @@ flush_thread (void)
        /* drop floating-point and debug-register state if it exists: */
        current->thread.flags &= ~(IA64_THREAD_FPH_VALID | IA64_THREAD_DBG_VALID);
        ia64_drop_fpu(current);
-       if (IS_IA32_PROCESS(ia64_task_regs(current)))
-               ia32_drop_partial_page_list(current);
+#ifdef CONFIG_IA32_SUPPORT
+       if (IS_IA32_PROCESS(task_pt_regs(current))) {
+               ia32_drop_ia64_partial_page_list(current);
+               current->thread.task_size = IA32_PAGE_OFFSET;
+               set_fs(USER_DS);
+       }
+#endif
 }
 
 /*
@@ -723,6 +748,7 @@ flush_thread (void)
 void
 exit_thread (void)
 {
+
        ia64_drop_fpu(current);
 #ifdef CONFIG_PERFMON
        /* if needed, stop monitoring and flush state to perfmon context */
@@ -733,8 +759,8 @@ exit_thread (void)
        if (current->thread.flags & IA64_THREAD_DBG_VALID)
                pfm_release_debug_registers(current);
 #endif
-       if (IS_IA32_PROCESS(ia64_task_regs(current)))
-               ia32_drop_partial_page_list(current);
+       if (IS_IA32_PROCESS(task_pt_regs(current)))
+               ia32_drop_ia64_partial_page_list(current);
 }
 
 unsigned long
@@ -744,6 +770,9 @@ get_wchan (struct task_struct *p)
        unsigned long ip;
        int count = 0;
 
+       if (!p || p == current || p->state == TASK_RUNNING)
+               return 0;
+
        /*
         * Note: p may not be a blocked task (it could be current or
         * another process running on some other CPU.  Rather than
@@ -754,6 +783,8 @@ get_wchan (struct task_struct *p)
         */
        unw_init_from_blocked_task(&info, p);
        do {
+               if (p->state == TASK_RUNNING)
+                       return 0;
                if (unw_unwind(&info) < 0)
                        return 0;
                unw_get_ip(&info, &ip);
@@ -786,22 +817,35 @@ cpu_halt (void)
                ia64_pal_halt(min_power_state);
 }
 
+void machine_shutdown(void)
+{
+#ifdef CONFIG_HOTPLUG_CPU
+       int cpu;
+
+       for_each_online_cpu(cpu) {
+               if (cpu != smp_processor_id())
+                       cpu_down(cpu);
+       }
+#endif
+#ifdef CONFIG_KEXEC
+       kexec_disable_iosapic();
+#endif
+}
+
 void
 machine_restart (char *restart_cmd)
 {
+       (void) notify_die(DIE_MACHINE_RESTART, restart_cmd, NULL, 0, 0, 0);
        (*efi.reset_system)(EFI_RESET_WARM, 0, 0, NULL);
 }
 
-EXPORT_SYMBOL(machine_restart);
-
 void
 machine_halt (void)
 {
+       (void) notify_die(DIE_MACHINE_HALT, "", NULL, 0, 0, 0);
        cpu_halt();
 }
 
-EXPORT_SYMBOL(machine_halt);
-
 void
 machine_power_off (void)
 {
@@ -810,4 +854,3 @@ machine_power_off (void)
        machine_halt();
 }
 
-EXPORT_SYMBOL(machine_power_off);