Skip to content

Commit bdb3716

Browse files
chenhuacaijfvogel
authored andcommitted
LoongArch: Save and restore CSR.CNTC for hibernation
commit ceb9155d058a11242aa0572875c44e9713b1a2be upstream. Save and restore CSR.CNTC for hibernation which is similar to suspend. For host this is unnecessary because sched clock is ensured continuous, but for kvm guest sched clock isn't enough because rdtime.d should also be continuous. Host::rdtime.d = Host::CSR.CNTC + counter Guest::rdtime.d = Host::CSR.CNTC + Host::CSR.GCNTC + Guest::CSR.CNTC + counter so, Guest::rdtime.d = Host::rdtime.d + Host::CSR.GCNTC + Guest::CSR.CNTC To ensure Guest::rdtime.d continuous, Host::rdtime.d should be at first continuous, while Host::CSR.GCNTC / Guest::CSR.CNTC is maintained by KVM. Cc: [email protected] Signed-off-by: Xianglai Li <[email protected]> Signed-off-by: Huacai Chen <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> (cherry picked from commit 2135336574354e1de870015e2b39b5b793f131cb) Signed-off-by: Jack Vogel <[email protected]>
1 parent 63f4236 commit bdb3716

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

arch/loongarch/kernel/time.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ static unsigned long __init get_loops_per_jiffy(void)
111111
return lpj;
112112
}
113113

114-
static long init_offset __nosavedata;
114+
static long init_offset;
115115

116116
void save_counter(void)
117117
{

arch/loongarch/power/hibernate.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <asm/fpu.h>
33
#include <asm/loongson.h>
44
#include <asm/sections.h>
5+
#include <asm/time.h>
56
#include <asm/tlbflush.h>
67
#include <linux/suspend.h>
78

@@ -14,6 +15,7 @@ struct pt_regs saved_regs;
1415

1516
void save_processor_state(void)
1617
{
18+
save_counter();
1719
saved_crmd = csr_read32(LOONGARCH_CSR_CRMD);
1820
saved_prmd = csr_read32(LOONGARCH_CSR_PRMD);
1921
saved_euen = csr_read32(LOONGARCH_CSR_EUEN);
@@ -26,6 +28,7 @@ void save_processor_state(void)
2628

2729
void restore_processor_state(void)
2830
{
31+
sync_counter();
2932
csr_write32(saved_crmd, LOONGARCH_CSR_CRMD);
3033
csr_write32(saved_prmd, LOONGARCH_CSR_PRMD);
3134
csr_write32(saved_euen, LOONGARCH_CSR_EUEN);

0 commit comments

Comments
 (0)