All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yanteng Si <si.yanteng@linux.dev>
To: Huacai Chen <chenhuacai@loongson.cn>,
	Huacai Chen <chenhuacai@kernel.org>
Cc: loongarch@lists.linux.dev, Xuefeng Li <lixuefeng@loongson.cn>,
	Guo Ren <guoren@kernel.org>, Xuerui Wang <kernel@xen0n.name>,
	Jiaxun Yang <jiaxun.yang@flygoat.com>,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org,
	Xianglai Li <lixianglai@loongson.cn>
Subject: Re: [PATCH] LoongArch: Save and restore CSR.CNTC for hibernation
Date: Thu, 15 May 2025 09:30:36 +0800	[thread overview]
Message-ID: <7135de9f-4372-4e12-994d-ecdc234bff28@linux.dev> (raw)
In-Reply-To: <20250514144643.1620870-1-chenhuacai@loongson.cn>

在 5/14/25 10:46 PM, Huacai Chen 写道:
> 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: stable@vger.kernel.org
> Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Reviewed-by: Yanteng Si <si.yanteng@linux.dev>

Thanks,
Yanteng
> ---
>   arch/loongarch/kernel/time.c     | 2 +-
>   arch/loongarch/power/hibernate.c | 3 +++
>   2 files changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/loongarch/kernel/time.c b/arch/loongarch/kernel/time.c
> index e2d3bfeb6366..bc75a3a69fc8 100644
> --- a/arch/loongarch/kernel/time.c
> +++ b/arch/loongarch/kernel/time.c
> @@ -111,7 +111,7 @@ static unsigned long __init get_loops_per_jiffy(void)
>   	return lpj;
>   }
>   
> -static long init_offset __nosavedata;
> +static long init_offset;
>   
>   void save_counter(void)
>   {
> diff --git a/arch/loongarch/power/hibernate.c b/arch/loongarch/power/hibernate.c
> index 1e0590542f98..e7b7346592cb 100644
> --- a/arch/loongarch/power/hibernate.c
> +++ b/arch/loongarch/power/hibernate.c
> @@ -2,6 +2,7 @@
>   #include <asm/fpu.h>
>   #include <asm/loongson.h>
>   #include <asm/sections.h>
> +#include <asm/time.h>
>   #include <asm/tlbflush.h>
>   #include <linux/suspend.h>
>   
> @@ -14,6 +15,7 @@ struct pt_regs saved_regs;
>   
>   void save_processor_state(void)
>   {
> +	save_counter();
>   	saved_crmd = csr_read32(LOONGARCH_CSR_CRMD);
>   	saved_prmd = csr_read32(LOONGARCH_CSR_PRMD);
>   	saved_euen = csr_read32(LOONGARCH_CSR_EUEN);
> @@ -26,6 +28,7 @@ void save_processor_state(void)
>   
>   void restore_processor_state(void)
>   {
> +	sync_counter();
>   	csr_write32(saved_crmd, LOONGARCH_CSR_CRMD);
>   	csr_write32(saved_prmd, LOONGARCH_CSR_PRMD);
>   	csr_write32(saved_euen, LOONGARCH_CSR_EUEN);


      reply	other threads:[~2025-05-15  1:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-14 14:46 [PATCH] LoongArch: Save and restore CSR.CNTC for hibernation Huacai Chen
2025-05-15  1:30 ` Yanteng Si [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7135de9f-4372-4e12-994d-ecdc234bff28@linux.dev \
    --to=si.yanteng@linux.dev \
    --cc=chenhuacai@kernel.org \
    --cc=chenhuacai@loongson.cn \
    --cc=guoren@kernel.org \
    --cc=jiaxun.yang@flygoat.com \
    --cc=kernel@xen0n.name \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lixianglai@loongson.cn \
    --cc=lixuefeng@loongson.cn \
    --cc=loongarch@lists.linux.dev \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.