Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3698870imm; Mon, 15 Oct 2018 02:37:03 -0700 (PDT) X-Google-Smtp-Source: ACcGV639BvMsInnwKqZW0/uBQix6UNBuAzYlw83AGUs2hFl9D7lmU6IscQJqH5rr6SgS26x1xsfY X-Received: by 2002:a17:902:e81:: with SMTP id 1-v6mr1086096plx.314.1539596223893; Mon, 15 Oct 2018 02:37:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539596223; cv=none; d=google.com; s=arc-20160816; b=eq3WmE+Bkrr6GLG5uAdxECnnnPRc/H7RhlJcYacsxyzRAohu4OsPsktspNPikikvUi laRpb7veue87vc1GqC4XZZ9DfXqfXrh2CSGGy4ppDz0StwE0jRqs6McRUC9bkvCKVGdB 6FXsy6JH3z259dBGcTz2PeJxw/VR4G+LpnQpQdGeQ5fW7b7nQFdWE6/pRBGBevuZpBVO 4ngU3elmtqJxWpoUIx1Lt3CtR1V92NMSQPbRHeAK6brRLj7abqie6aat9bVD6RoKjQ72 HGK3q5l5R1YD3pFYT4Nn4EvtYdTlPjH/rIue4xUpNMQYvqPxEjPf6kkIcKaJT9ndfFPY MXag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=LIt39AmKbuYF9Xi9L0PcQxoFRc9uQgSZbtOQG0mHCmI=; b=n1DpELfqUcsyIPeNmBEUws7TrITPETfEBZEZnO6d2alI6gabJwpQExBHYDSqUfcNs9 Hu0kgiPRbRU/jKIXw9dLEko7AAB0OhbQWfP5cNQ2qvKdV3SOaGcpHR3Gb9sYyhvHFP+r fhwd4fSh3fygSCZaXfKaO0fla4QaHu414t99qPkG80cE2eRX6b79FyGpDIL2y7jDJ95C 9GTc+lF9a0/6esnNFkIuSLklJKppRpR8I+fOAvBbdsSPwaOz0ktG8Db3HhXBlkTtg80/ Jir3yBKyDjKULngacHmLDBrSXVXMEhK15cisbpA/XehWF4KUaO2AW4UswmTdgEL9GMn/ gP3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Cbt9dIBF; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o68-v6si6396519pfb.203.2018.10.15.02.36.49; Mon, 15 Oct 2018 02:37:03 -0700 (PDT) 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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Cbt9dIBF; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726631AbeJORTl (ORCPT + 99 others); Mon, 15 Oct 2018 13:19:41 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:35201 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726421AbeJORTk (ORCPT ); Mon, 15 Oct 2018 13:19:40 -0400 Received: by mail-lj1-f194.google.com with SMTP id o14-v6so16879350ljj.2; Mon, 15 Oct 2018 02:35:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=LIt39AmKbuYF9Xi9L0PcQxoFRc9uQgSZbtOQG0mHCmI=; b=Cbt9dIBFiC6QiTlzgRsmRXLPOIJD06FpCQ2GNmaMFDFP2LLnATXjraSJsI3jnjSJZM ZlfT4budsmA4oe98oqnXnGEa418thWqSRaNVG8xipt2aPLAOA1Hja0keFZjbUnM199MU KdZcRC95oqP0FFAoAwJ0Ui9VfkqLKK4X1CzVd5OC89VMBWIbx87TkO5Zkdj+yq+A+pQE 9JS353K+xECDSYQ5gIAQkXtynl1IijPo3P3X3sBg0nypyLpB573SLCBUDgzGDbZW3Kqb CS6UpgabrVKg+VCUZLJMMrjYexOLoRTiwjb+YThL0MFkG4r5H3jijzgVfNIyh3NTLzT1 md2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=LIt39AmKbuYF9Xi9L0PcQxoFRc9uQgSZbtOQG0mHCmI=; b=G56AM9tkiFFPJJN48E+Y2BgsHVGtkuOX8HN75SaWjsMH0v1vOhNUofapq0LW9hsU3l EhXwbsusvQI4QYgowQ29l00oyVtu4R9LOAci02aT7m1CCBAA/kMz606Swmsf0yFokYmR xA0WXbfwseg8i2u2igv54p53KWFPwlzh3HYJa7TnEGY1a2S89DMHhyG4RMa/c1LRrsRz tQZHsbJD6jxXnzvlVEk2CHcqaG3FZ1Lu+yjjdu+8S1Ze/9jrnMLfC+3XKM50zqrvOxQI YenmO0PZP6vT+CJdGrpn5eSeEXKF6mwDLJyNRra6Pb3Ew3En8XlHPGseJ6/RiZqdB4Ib iH0Q== X-Gm-Message-State: ABuFfogmpIeZ6dT5QdrHRMkYGncoOoKz4kI49xuaRt7zh7NhrSTj1Q7/ HS018Jz0paNavXRvFLAzV33lBCIPBnWC54HCphs= X-Received: by 2002:a2e:6353:: with SMTP id x80-v6mr9933954ljb.11.1539596110390; Mon, 15 Oct 2018 02:35:10 -0700 (PDT) MIME-Version: 1.0 References: <20181008150901.19667-1-waldemar.rymarkiewicz@gmail.com> <2671493.AgiGORq3CZ@aspire.rjw.lan> In-Reply-To: <2671493.AgiGORq3CZ@aspire.rjw.lan> From: Waldemar Rymarkiewicz Date: Mon, 15 Oct 2018 11:34:33 +0200 Message-ID: Subject: Re: [PATCH] cpufreq: conservative: Fix requested_freq handling To: "Rafael J. Wysocki" Cc: Viresh Kumar , Waldemar Rymarkiewicz , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, "Bartholomae, Thomas" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 11 Oct 2018 at 23:10, Rafael J. Wysocki wrote: > > On Tuesday, October 9, 2018 6:06:08 PM CEST Waldemar Rymarkiewicz wrote: > > On Tue, 9 Oct 2018 at 09:47, Rafael J. Wysocki wrote: > > > > > > On Mon, Oct 8, 2018 at 5:11 PM Waldemar Rymarkiewicz > > > wrote: > > > > > > > > From: Waldemar Rymarkiewicz > > > > > > > > The governor updates dbs_info->requested_freq only after increasing or > > > > decreasing frequency. There is, however, an use case when this is not > > > > sufficient. > > > > > > > > Imagine, external module constraining cpufreq policy in a way that policy->max > > > > > > Is the "external module" here a utility or a demon running in user space? > > > > No, this is a driver that communicates with a firmware and makes sure > > CPU is running at the highest rate in specific time. > > It uses verify_within_limits and update_policy, a standard way to > > constraint cpufreq policy limits. > > > > > > @@ -136,10 +135,10 @@ static unsigned int cs_dbs_update(struct cpufreq_policy *policy) > > > > requested_freq = policy->min; > > > > > > > > __cpufreq_driver_target(policy, requested_freq, CPUFREQ_RELATION_L); > > > > - dbs_info->requested_freq = requested_freq; > > > > } > > > > > > > > out: > > > > + dbs_info->requested_freq = requested_freq; > > > > > > This will have a side effect when requested_freq is updated before the > > > thresholds checks due to the policy_dbs->idle_periods < UINT_MAX > > > check. > > > > > > Shouldn't that be avoided? > > > > I would say we should. > > > > A hardware design I use is running 4.9 kernel where the check does not > > exist yet, so there is not a problem. > > Anyway, the check policy_dbs->idle_periods < UINT_MAX can change > > requested_freq either to requested_freq = policy->min or > > requested_freq -= freq_steps;. The first case will not change anything > > for us as policy->max=min=cur. The second, however, will force to > > update freq which is definitely not expected when limits are set to > > min=max. Simply it will not go out here: > > > > if (load < cs_tuners->down_threshold) { > > if (requested_freq == policy->min) > > goto out; <--- > > ... > > } > > > > Am I right here? If so, shouldn't we check explicitly > > > > /* > > * If requested_freq is out of range, it is likely that the limits > > * changed in the meantime, so fall back to current frequency in that > > * case. > > */ > > if (requested_freq > policy->max || requested_freq < policy->min) > > requested_freq = policy->cur; > > > > +/* > > +* If the the new limits min,max are equal, there is no point to process further > > +*/ > > + > > +if (requested_freq == policy->max && requested_freq == policy->min) > > + goto out; > > If my understanding of the problem is correct, it would be better to simply > update dbs_info->requested_freq along with requested_freq when that is found > to be out of range. IOW, something like the appended patch (untested). Yes, this will solve the original problem as well. I think there could also be a problem with policy_dbs->idle_periods < UINT_MAX check. It it's true it can modify requested_freq ( requested_freq -= freq_steps) and further it can result in a change of the freq, requested_freq == policy->max is not anymore true. I would expect governor not to change freq (requested_freq) when policy->max=policy->min=policy->cur. Thanks, /Waldek