Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1285454rbb; Mon, 26 Feb 2024 04:59:58 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXNQbe2tRGpyX9f9bSGkr9EiCC6CWJIKw5ySSs/NLn/STCGCf+aIHUkis6Fx1H26+WiVOS11TJ7fVCF8TkIAOwCkGDbTLwS41A63g8e6g== X-Google-Smtp-Source: AGHT+IGdSZjdO5FP9yytQPVqXTeZMNfV66STIfEQcoca3x6gu730/8QD7w/6Zqa2ysG/d04pzQ0Z X-Received: by 2002:a17:902:e748:b0:1db:47bb:671b with SMTP id p8-20020a170902e74800b001db47bb671bmr8864814plf.19.1708952398131; Mon, 26 Feb 2024 04:59:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708952398; cv=pass; d=google.com; s=arc-20160816; b=Kmq88vRXUqnAKF+s4zbWjyYBblrkurYIx/gdBNeCG6XMceJ9mzGMIMJVvwjkhnvkrg SuNDDz7LJRS37u9t7DYNeey1O9HF0Qrnz84ZF2j24BKuiI2Bs1yI7oqgqcMHhA3EWQCX s/LZ2hE/bsd4JTEWddKdNmhD2OlUJCnS3YG7jLP98o/ZZJgZvsC4DN5nMkxCyW9t058p uIcpGclnszOlkpLyKm99dSn62ztoORpZ97sExkZ2GBNjvVCPDXyV7HEBon9r/5eHwYj3 6d+56ZpiPYH7x1OGGjqhq2cKMubQjG/dTXoqXvPSHsR4xxJEVpPpFxuAaNDxTiIBSZMA FXWw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=eShVtquyoy0+JCOXhGhjXsKMIzJigxwQr4w/KV+MpEA=; fh=Ig5PMjf9K5rN+DYbeplDNzoww1ayAttVuWylug1a0hM=; b=J4k2EpL+6TlMdmJTKFLk2QcKqE/3fM80Z7J5AO1zE/MHqhVgXERawJY7YCQ4gGPb4z s4XFdwyqVugQWdJ9KbymIMjpHTnAkfrsDlNyuqRIa47P2otPAiAwXqsFAP8jYOhogCW2 m1BfD5nkZ3lynzW3dl94L1sUpxbsqCHOP+dQ0H4w7AwCZYrcJvpZVfL4VXLHfkAEwufs i5w/kzFA1LI/kW3FULNO9NV3Wgodpnygjh07qXj1ItZ4Rmgno9bWlD8PLT60mJjaJ64h pYwjWTaJw11/6u8LAE2FEOVsmhKGnlNpvxWyc0KhUj/LWInCRB+BV/2KeYtlCs/mel4T VGUg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QyB8eRkG; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-81430-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81430-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id k4-20020a170902d58400b001dc5ae81752si3620938plh.559.2024.02.26.04.59.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 04:59:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-81430-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QyB8eRkG; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-81430-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81430-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id CA6AD289104 for ; Mon, 26 Feb 2024 12:59:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 44A87823A7; Mon, 26 Feb 2024 12:58:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="QyB8eRkG" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 62B577F7FB; Mon, 26 Feb 2024 12:58:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708952337; cv=none; b=S3ZxFup361Tt9+TGHoxBLX3zc4kRFjiKgDfJND5FTpOY/HG8bHbNj5HHYFrnd0p+EjsDMJHnhjIZcBYqGYkk4VVNJ5jxbysj85cuXs5arpCJUx6FtufxnBwvde1T8YOIXZC59qKEpa4JQKyCZmdyD7+qAzfYi2SmC0qPDwOz4Fk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708952337; c=relaxed/simple; bh=idV7OLDy+mbGz4M8S3DgS0wIv3UQ68q7P/tsruOyKso=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=G6DoAj4M3s+qtLW8QBVW2qEAD/I1RGrnkZhIa3dPIHnseO85EdwPGKMjrwc2uAZ+bAf62L4IJLAvaIMGy3APEDgROp88SgmOiBylKqAgEV5LYu3s/06V/z7CP00+QGftDA5R2xqwOVgTkSujFbv+2gSTWcGHiXS7N+xgKhesZi4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QyB8eRkG; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 41A02C43394; Mon, 26 Feb 2024 12:58:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708952337; bh=idV7OLDy+mbGz4M8S3DgS0wIv3UQ68q7P/tsruOyKso=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=QyB8eRkGR/5FQaU3uLi1rwHY4UQGxV8agSRelPI0a5aFSCrLd+T2o4kxQCJcS0CcN VvEjDbrBS6vgnpSIRUf3bbbjOhU1LXzbiqaiQdmPvuPMcpbLu1b+caHk4r/xOk8U2H bz7bOKE7UMaNSekhmqiCTG4gtCy8tvyPtSBul6TBoeRHJpeviyPuA46/gnbIr0nljN UNkomlcatazeIrMHZKOwLPQn8q5kezWfELVPY0VXZxv/rsoggSdbADClaNEd/AiHhM IkdM1c4CMdL1XZ9ub2W1u/5VUCBzAOkRBIPItIXZdV0ZrotcIYhzuln2rI8XRC+DiF WqY/0AaMI+2mQ== Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-a3e6f79e83dso324076566b.2; Mon, 26 Feb 2024 04:58:57 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVUzNQTBxSco23I+bwmOhzvJ9Y1kV8J8l2rbP7ubLesWv+PJKzc9dgVsRvzVpvcBKBOro2HvLVr6A8jBcfJQCcKi/0z6jtJRuEPaBUquKl6fIXZ4STSIFkzYnqsI+GtRnZA X-Gm-Message-State: AOJu0YySPZQGeEN3ZYeh0HQW4qbt5ylJCKYlx3qgHFTHTr+q7mettHrk 228OPcyrnC4ZMmwiUTktrP/9lHjBCcwZiWr2PsdZSJD/01xW4DGvTzAhzrynfaWoPSjsh4BDHs7 p0TeNY/o+5oszeKoRLj8LTEWTM5s= X-Received: by 2002:a17:906:f0cb:b0:a3e:c2de:2b9e with SMTP id dk11-20020a170906f0cb00b00a3ec2de2b9emr4144567ejb.39.1708952335539; Mon, 26 Feb 2024 04:58:55 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240130072238.2829831-1-maobibo@loongson.cn> <20240130072238.2829831-2-maobibo@loongson.cn> In-Reply-To: <20240130072238.2829831-2-maobibo@loongson.cn> From: Huacai Chen Date: Mon, 26 Feb 2024 20:58:43 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 1/2] LoongArch: KVM: Start SW timer only when vcpu is blocking To: Bibo Mao Cc: Tianrui Zhao , kvm@vger.kernel.org, loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Queued for loongarch-kvm, thanks. Huacai On Tue, Jan 30, 2024 at 3:22=E2=80=AFPM Bibo Mao wrot= e: > > SW timer is enabled when vcpu thread is scheduled out, and it is > to wake up vcpu from blocked queue. If vcpu thread is scheduled out > however is not blocked, such as it is preempted by other threads, > it is not necessary to enable SW timer. Since vcpu thread is still > on running queue if preempted and SW timer is only to wake up vcpu > on blocking queue, so SW timer is not useful in this situation. > > This patch enables SW timer only when vcpu is scheduled out and > is blocking. > > Signed-off-by: Bibo Mao > --- > arch/loongarch/kvm/timer.c | 22 ++++++++-------------- > 1 file changed, 8 insertions(+), 14 deletions(-) > > diff --git a/arch/loongarch/kvm/timer.c b/arch/loongarch/kvm/timer.c > index 111328f60872..a9125f0a12d1 100644 > --- a/arch/loongarch/kvm/timer.c > +++ b/arch/loongarch/kvm/timer.c > @@ -93,7 +93,8 @@ void kvm_restore_timer(struct kvm_vcpu *vcpu) > /* > * Freeze the soft-timer and sync the guest stable timer with it. > */ > - hrtimer_cancel(&vcpu->arch.swtimer); > + if (kvm_vcpu_is_blocking(vcpu)) > + hrtimer_cancel(&vcpu->arch.swtimer); > > /* > * From LoongArch Reference Manual Volume 1 Chapter 7.6.2 > @@ -168,26 +169,19 @@ static void _kvm_save_timer(struct kvm_vcpu *vcpu) > * Here judge one-shot timer fired by checking whether TVAL is la= rger > * than TCFG > */ > - if (ticks < cfg) { > + if (ticks < cfg) > delta =3D tick_to_ns(vcpu, ticks); > - expire =3D ktime_add_ns(ktime_get(), delta); > - vcpu->arch.expire =3D expire; > + else > + delta =3D 0; > + expire =3D ktime_add_ns(ktime_get(), delta); > + vcpu->arch.expire =3D expire; > + if (kvm_vcpu_is_blocking(vcpu)) { > > /* > * HRTIMER_MODE_PINNED is suggested since vcpu may run in > * the same physical cpu in next time > */ > hrtimer_start(&vcpu->arch.swtimer, expire, HRTIMER_MODE_A= BS_PINNED); > - } else if (vcpu->stat.generic.blocking) { > - /* > - * Inject timer interrupt so that halt polling can dectec= t and exit. > - * VCPU is scheduled out already and sleeps in rcuwait qu= eue and > - * will not poll pending events again. kvm_queue_irq() is= not enough, > - * hrtimer swtimer should be used here. > - */ > - expire =3D ktime_add_ns(ktime_get(), 10); > - vcpu->arch.expire =3D expire; > - hrtimer_start(&vcpu->arch.swtimer, expire, HRTIMER_MODE_A= BS_PINNED); > } > } > > -- > 2.39.3 >