Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp4321202ybc; Fri, 15 Nov 2019 02:46:34 -0800 (PST) X-Google-Smtp-Source: APXvYqy960Imh3eZTbkIx+ipex32+U9YVkzPqdpp8WoBitcZHsGw/dFqbzNyYO/WwU2xnmSjXLzT X-Received: by 2002:a17:906:8307:: with SMTP id j7mr12482513ejx.171.1573814794844; Fri, 15 Nov 2019 02:46:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573814794; cv=none; d=google.com; s=arc-20160816; b=BVsKzB1oZmqQCCKeEj8dT+2y3T7gv1HJgOPUG5qARPMBsSFrW3/AW5bDRcUZ4rDDkx qktKQqgGpnVf4D3xHij5tImL9Vr0RWvYQOqEFJ+HB8NZ1SoHrfKy6i2lc9D7oPBJS3R+ uMWoiC+Nr2Pa6eoJpSiZrFTLgggfKQwEAPBUUVRktiQq879xkZISRUC4inf4yWJaiXfP OkzmEtiReU+MphI2kS+z7/p9zeLs3XfS0sQ7cAbM7h131ww3BimqyEPx25L2z4WzxDUJ 09URVG3j4ykgcCpn078FLiL/UAWluJmggEFODjo6jDLApDuInqBaXHrPw7Wd+nhTBeBi 2t2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=x9ApSg0ZKV2UF+sYSUFvy/37xK0MDI9mse0JtigrzNE=; b=ruJW7Ai7bXYAm1o5VDEbgmZYnh4U4u2x69xUqBoG2IfBzL2HKI4f0TFkycPrhDcZye RRzceYJ6yVtslYtHiyC9NsvBUla5jWly/wWZOAu1rV7F/T2h6/NM9a+ClDumB9tu+x3V PXM9y+HFuhMVy5Z51keiobL61Q24tyq1pQ/d4IqaAOQ5Z3oXnR/01siTiXj/8mNpo/C4 vYGgkgOMfh/p3j4QebOsdM3p5jvJTbbCn2JmLsN1hSgE32+yDHcpRHyfDUdxVde3h7i/ aLmOFLXbWj9+EnQOYUdkJKgbodM5QTONmnNED0Ldl7/AUQV4bmfnp3uDfmoS3xVeriBc Pfaw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k11si5222358ejv.152.2019.11.15.02.46.09; Fri, 15 Nov 2019 02:46:34 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727249AbfKOKpF (ORCPT + 99 others); Fri, 15 Nov 2019 05:45:05 -0500 Received: from cloudserver094114.home.pl ([79.96.170.134]:42681 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727022AbfKOKpF (ORCPT ); Fri, 15 Nov 2019 05:45:05 -0500 Received: from 79.184.253.153.ipv4.supernova.orange.pl (79.184.253.153) (HELO kreacher.localnet) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.83.292) id fddc515768e678ae; Fri, 15 Nov 2019 11:45:02 +0100 From: "Rafael J. Wysocki" To: Zhenzhong Duan Cc: linux-kernel@vger.kernel.org, pbonzini@redhat.com, rkrcmar@redhat.com, rafael.j.wysocki@intel.com, joao.m.martins@oracle.com, mtosatti@redhat.com, kvm@vger.kernel.org, linux-pm@vger.kernel.org Subject: Re: [PATCH RESEND v2 3/4] cpuidle-haltpoll: ensure cpu_halt_poll_us in right scope Date: Fri, 15 Nov 2019 11:45:01 +0100 Message-ID: <6161954.sKiXg2khOt@kreacher> In-Reply-To: <1573041302-4904-4-git-send-email-zhenzhong.duan@oracle.com> References: <1573041302-4904-1-git-send-email-zhenzhong.duan@oracle.com> <1573041302-4904-4-git-send-email-zhenzhong.duan@oracle.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wednesday, November 6, 2019 12:55:01 PM CET Zhenzhong Duan wrote: > As user can adjust guest_halt_poll_grow_start and guest_halt_poll_ns > which leads to cpu_halt_poll_us beyond the two boundaries. This patch > ensures cpu_halt_poll_us in that scope. > > If guest_halt_poll_shrink is 0, shrink the cpu_halt_poll_us to > guest_halt_poll_grow_start instead of 0. To disable poll we can set > guest_halt_poll_ns to 0. > > If user wrongly set guest_halt_poll_grow_start > guest_halt_poll_ns > 0, > guest_halt_poll_ns take precedency and poll time is a fixed value of > guest_halt_poll_ns. > > Signed-off-by: Zhenzhong Duan > --- > drivers/cpuidle/governors/haltpoll.c | 28 +++++++++++++--------------- > 1 file changed, 13 insertions(+), 15 deletions(-) > > diff --git a/drivers/cpuidle/governors/haltpoll.c b/drivers/cpuidle/governors/haltpoll.c > index 660859d..4a39df4 100644 > --- a/drivers/cpuidle/governors/haltpoll.c > +++ b/drivers/cpuidle/governors/haltpoll.c > @@ -97,32 +97,30 @@ static int haltpoll_select(struct cpuidle_driver *drv, > > static void adjust_poll_limit(struct cpuidle_device *dev, unsigned int block_us) > { > - unsigned int val; > + unsigned int val = dev->poll_limit_ns; Not necessary to initialize it here. > u64 block_ns = block_us*NSEC_PER_USEC; > > /* Grow cpu_halt_poll_us if > - * cpu_halt_poll_us < block_ns < guest_halt_poll_us > + * cpu_halt_poll_us < block_ns <= guest_halt_poll_us You could update the comment to say "dev->poll_limit_ns" instead of "cpu_halt_poll_us" while at it. > */ > - if (block_ns > dev->poll_limit_ns && block_ns <= guest_halt_poll_ns) { > + if (block_ns > dev->poll_limit_ns && block_ns <= guest_halt_poll_ns && > + guest_halt_poll_grow) The "{" brace is still needed as per the coding style and I'm not sure why to avoid guest_halt_poll_grow equal to zero here? > val = dev->poll_limit_ns * guest_halt_poll_grow; > - > - if (val < guest_halt_poll_grow_start) > - val = guest_halt_poll_grow_start; > - if (val > guest_halt_poll_ns) > - val = guest_halt_poll_ns; > - > - dev->poll_limit_ns = val; > - } else if (block_ns > guest_halt_poll_ns && > - guest_halt_poll_allow_shrink) { > + else if (block_ns > guest_halt_poll_ns && > + guest_halt_poll_allow_shrink) { > unsigned int shrink = guest_halt_poll_shrink; > > - val = dev->poll_limit_ns; > if (shrink == 0) > - val = 0; > + val = guest_halt_poll_grow_start; That's going to be corrected below, so the original code would be fine. > else > val /= shrink; Here you can do val = dev->poll_limit_ns / shrink; > - dev->poll_limit_ns = val; > } > + if (val < guest_halt_poll_grow_start) > + val = guest_halt_poll_grow_start; Note that guest_halt_poll_grow_start is in us (as per the comment next to its definition and the initial value). That is a bug in the original code too, but anyway. > + if (val > guest_halt_poll_ns) > + val = guest_halt_poll_ns; > + > + dev->poll_limit_ns = val; > } > > /** >