Skip to content

Commit

Permalink
sh: Split out the idle loop for reuse between _32/_64 variants.
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Mundt <lethal@linux-sh.org>
  • Loading branch information
Paul Mundt committed Dec 22, 2008
1 parent eb67cf1 commit 1da1180
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 123 deletions.
2 changes: 1 addition & 1 deletion arch/sh/kernel/Makefile_32
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ifdef CONFIG_FUNCTION_TRACER
CFLAGS_REMOVE_ftrace.o = -pg
endif

obj-y := debugtraps.o disassemble.o io.o io_generic.o irq.o \
obj-y := debugtraps.o disassemble.o idle.o io.o io_generic.o irq.o \
machvec.o process_32.o ptrace_32.o setup.o signal_32.o \
sys_sh.o sys_sh32.o syscalls_32.o time_32.o topology.o \
traps.o traps_32.o
Expand Down
2 changes: 1 addition & 1 deletion arch/sh/kernel/Makefile_64
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
extra-y := head_64.o init_task.o vmlinux.lds

obj-y := debugtraps.o io.o io_generic.o irq.o machvec.o process_64.o \
obj-y := debugtraps.o idle.o io.o io_generic.o irq.o machvec.o process_64.o \
ptrace_64.o setup.o signal_64.o sys_sh.o sys_sh64.o \
syscalls_64.o time_64.o topology.o traps.o traps_64.o

Expand Down
81 changes: 81 additions & 0 deletions arch/sh/kernel/idle.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* The idle loop for all SuperH platforms.
*
* Copyright (C) 2002 - 2008 Paul Mundt
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file "COPYING" in the main directory of this archive
* for more details.
*/
#include <linux/module.h>
#include <linux/init.h>
#include <linux/mm.h>
#include <linux/pm.h>
#include <linux/tick.h>
#include <linux/preempt.h>
#include <linux/thread_info.h>
#include <linux/irqflags.h>
#include <asm/pgalloc.h>
#include <asm/system.h>
#include <asm/atomic.h>

static int hlt_counter;
void (*pm_idle)(void);
void (*pm_power_off)(void);
EXPORT_SYMBOL(pm_power_off);

static int __init nohlt_setup(char *__unused)
{
hlt_counter = 1;
return 1;
}
__setup("nohlt", nohlt_setup);

static int __init hlt_setup(char *__unused)
{
hlt_counter = 0;
return 1;
}
__setup("hlt", hlt_setup);

static void default_idle(void)
{
if (!hlt_counter) {
clear_thread_flag(TIF_POLLING_NRFLAG);
smp_mb__after_clear_bit();
set_bl_bit();
stop_critical_timings();

while (!need_resched())
cpu_sleep();

start_critical_timings();
clear_bl_bit();
set_thread_flag(TIF_POLLING_NRFLAG);
} else
while (!need_resched())
cpu_relax();
}

void cpu_idle(void)
{
set_thread_flag(TIF_POLLING_NRFLAG);

/* endless idle loop with no priority at all */
while (1) {
void (*idle)(void) = pm_idle;

if (!idle)
idle = default_idle;

tick_nohz_stop_sched_tick(1);
while (!need_resched())
idle();
tick_nohz_restart_sched_tick();

preempt_enable_no_resched();
schedule();
preempt_disable();
check_pgt_cache();
}
}
61 changes: 0 additions & 61 deletions arch/sh/kernel/process_32.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,69 +32,8 @@
#include <asm/fpu.h>
#include <asm/syscalls.h>

static int hlt_counter;
int ubc_usercnt = 0;

void (*pm_idle)(void);
void (*pm_power_off)(void);
EXPORT_SYMBOL(pm_power_off);

static int __init nohlt_setup(char *__unused)
{
hlt_counter = 1;
return 1;
}
__setup("nohlt", nohlt_setup);

static int __init hlt_setup(char *__unused)
{
hlt_counter = 0;
return 1;
}
__setup("hlt", hlt_setup);

static void default_idle(void)
{
if (!hlt_counter) {
clear_thread_flag(TIF_POLLING_NRFLAG);
smp_mb__after_clear_bit();
set_bl_bit();
stop_critical_timings();

while (!need_resched())
cpu_sleep();

start_critical_timings();
clear_bl_bit();
set_thread_flag(TIF_POLLING_NRFLAG);
} else
while (!need_resched())
cpu_relax();
}

void cpu_idle(void)
{
set_thread_flag(TIF_POLLING_NRFLAG);

/* endless idle loop with no priority at all */
while (1) {
void (*idle)(void) = pm_idle;

if (!idle)
idle = default_idle;

tick_nohz_stop_sched_tick(1);
while (!need_resched())
idle();
tick_nohz_restart_sched_tick();

preempt_enable_no_resched();
schedule();
preempt_disable();
check_pgt_cache();
}
}

void machine_restart(char * __unused)
{
/* SR.BL=1 and invoke address error to let CPU reset (manual reset) */
Expand Down
60 changes: 0 additions & 60 deletions arch/sh/kernel/process_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,56 +33,6 @@

struct task_struct *last_task_used_math = NULL;

static int hlt_counter = 1;

#define HARD_IDLE_TIMEOUT (HZ / 3)

static int __init nohlt_setup(char *__unused)
{
hlt_counter = 1;
return 1;
}

static int __init hlt_setup(char *__unused)
{
hlt_counter = 0;
return 1;
}

__setup("nohlt", nohlt_setup);
__setup("hlt", hlt_setup);

static inline void hlt(void)
{
__asm__ __volatile__ ("sleep" : : : "memory");
}

/*
* The idle loop on a uniprocessor SH..
*/
void cpu_idle(void)
{
/* endless idle loop with no priority at all */
while (1) {
if (hlt_counter) {
while (!need_resched())
cpu_relax();
} else {
local_irq_disable();
while (!need_resched()) {
local_irq_enable();
hlt();
local_irq_disable();
}
local_irq_enable();
}
preempt_enable_no_resched();
schedule();
preempt_disable();
}

}

void machine_restart(char * __unused)
{
extern void phys_stext(void);
Expand All @@ -97,13 +47,6 @@ void machine_halt(void)

void machine_power_off(void)
{
#if 0
/* Disable watchdog timer */
ctrl_outl(0xa5000000, WTCSR);
/* Configure deep standby on sleep */
ctrl_outl(0x03, STBCR);
#endif

__asm__ __volatile__ (
"sleep\n\t"
"synci\n\t"
Expand All @@ -113,9 +56,6 @@ void machine_power_off(void)
panic("Unexpected wakeup!\n");
}

void (*pm_power_off)(void) = machine_power_off;
EXPORT_SYMBOL(pm_power_off);

void show_regs(struct pt_regs * regs)
{
unsigned long long ah, al, bh, bl, ch, cl;
Expand Down

0 comments on commit 1da1180

Please sign in to comment.