Skip to content

Commit d43f37b

Browse files
bibo-maochenhuacai
authored andcommitted
LoongArch: Implement constant timer shutdown interface
When a cpu is hot-unplugged, it is put in idle state and the function arch_cpu_idle_dead() is called. The timer interrupt for this processor should be disabled, otherwise there will be pending timer interrupt for the unplugged cpu, so that vcpu is prevented from giving up scheduling when system is running in vm mode. This patch implements the timer shutdown interface so that the constant timer will be properly disabled when a CPU is hot-unplugged. Reviewed-by: WANG Xuerui <[email protected]> Signed-off-by: Bibo Mao <[email protected]> Signed-off-by: Huacai Chen <[email protected]>
1 parent 19d86a4 commit d43f37b

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

arch/loongarch/kernel/time.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,43 +58,38 @@ static int constant_set_state_oneshot(struct clock_event_device *evt)
5858
return 0;
5959
}
6060

61-
static int constant_set_state_oneshot_stopped(struct clock_event_device *evt)
61+
static int constant_set_state_periodic(struct clock_event_device *evt)
6262
{
63+
unsigned long period;
6364
unsigned long timer_config;
6465

6566
raw_spin_lock(&state_lock);
6667

67-
timer_config = csr_read64(LOONGARCH_CSR_TCFG);
68-
timer_config &= ~CSR_TCFG_EN;
68+
period = const_clock_freq / HZ;
69+
timer_config = period & CSR_TCFG_VAL;
70+
timer_config |= (CSR_TCFG_PERIOD | CSR_TCFG_EN);
6971
csr_write64(timer_config, LOONGARCH_CSR_TCFG);
7072

7173
raw_spin_unlock(&state_lock);
7274

7375
return 0;
7476
}
7577

76-
static int constant_set_state_periodic(struct clock_event_device *evt)
78+
static int constant_set_state_shutdown(struct clock_event_device *evt)
7779
{
78-
unsigned long period;
7980
unsigned long timer_config;
8081

8182
raw_spin_lock(&state_lock);
8283

83-
period = const_clock_freq / HZ;
84-
timer_config = period & CSR_TCFG_VAL;
85-
timer_config |= (CSR_TCFG_PERIOD | CSR_TCFG_EN);
84+
timer_config = csr_read64(LOONGARCH_CSR_TCFG);
85+
timer_config &= ~CSR_TCFG_EN;
8686
csr_write64(timer_config, LOONGARCH_CSR_TCFG);
8787

8888
raw_spin_unlock(&state_lock);
8989

9090
return 0;
9191
}
9292

93-
static int constant_set_state_shutdown(struct clock_event_device *evt)
94-
{
95-
return 0;
96-
}
97-
9893
static int constant_timer_next_event(unsigned long delta, struct clock_event_device *evt)
9994
{
10095
unsigned long timer_config;
@@ -161,7 +156,7 @@ int constant_clockevent_init(void)
161156
cd->rating = 320;
162157
cd->cpumask = cpumask_of(cpu);
163158
cd->set_state_oneshot = constant_set_state_oneshot;
164-
cd->set_state_oneshot_stopped = constant_set_state_oneshot_stopped;
159+
cd->set_state_oneshot_stopped = constant_set_state_shutdown;
165160
cd->set_state_periodic = constant_set_state_periodic;
166161
cd->set_state_shutdown = constant_set_state_shutdown;
167162
cd->set_next_event = constant_timer_next_event;

0 commit comments

Comments
 (0)