Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp647374imm; Wed, 23 May 2018 03:17:02 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqQ9pmX7GYCVs1BGZltXASAambn2aiNT0DdJpsy4ur/LJJZxxu/kLdPj+9aKB5XLCFLpOyq X-Received: by 2002:a63:6b43:: with SMTP id g64-v6mr1815777pgc.337.1527070622894; Wed, 23 May 2018 03:17:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527070622; cv=none; d=google.com; s=arc-20160816; b=Wf+HrV6dSU/WCXtCjLgGaQWZJWI4V5P6Nq+wSSsZ5k3B0TbI2rXAO8JLq6XLyPa+rT h8sbI2H8nHnjVLjKwQJPQf/8RMWHQkL/cbrWdC6B02UCJzUPES6PsnVGl4v//GkQxC6k 8uH1Fnu9LAvNSWHMP0tGYS/m0CNcUn5bLj2XM+lMEDRy3mbzic75Vylwm8ZdcfT+D5aI xc8buA0Lb4oLR8OIj8QDij97c3zFOiWBfpZOJfGkkjJERQ1a1T8ivkqe3mbUDfPJETjF A01fcl8A7KHtPassIELLVAvgrmzHyIA/GHcQcNJ+qHrHUACGmHGs92Y+AuhXZGRPjHzA Phsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=nlgeUbrUnSGjsJ1OCFTQxdL2inJ4pHCbmXENYhIswJA=; b=ci9v+54yXNN15Z4wnK01Sj5Y+O1SotABE2YpaM/lPMUB+yja+pAkDuB+nMDTQQ2MAl bfFRZLcq/cXW/UW4s4TFTdqKRQPFgeJP7Rj1DAPhVAG5WwDGWeHRt9qT4WmowMC7YkB8 ZxzyXtNfVeCs7AU2CPgRsw+waeHsnEaHy34NDzbQxYTlNdgr+3JKcLvsS0zz67RcRsVN jP9dz7ZIe8113JUzgaC6GFhB5uO1ereP49dD14DV/9PFJ7YZHUhkccsKKa8a15H2UwQi NeK3ihgSzOgxKjiR5+IudZdAnpCb8dvphMFzGh1UT3eWanqs9wpGsqDAxJvLavvVtzDc GrDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cOmtBq8j; 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=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q66-v6si18346178pfi.235.2018.05.23.03.16.47; Wed, 23 May 2018 03:17:02 -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=@linaro.org header.s=google header.b=cOmtBq8j; 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=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932423AbeEWKO0 (ORCPT + 99 others); Wed, 23 May 2018 06:14:26 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:38646 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932326AbeEWKOV (ORCPT ); Wed, 23 May 2018 06:14:21 -0400 Received: by mail-pf0-f194.google.com with SMTP id o76-v6so10263767pfi.5 for ; Wed, 23 May 2018 03:14:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=nlgeUbrUnSGjsJ1OCFTQxdL2inJ4pHCbmXENYhIswJA=; b=cOmtBq8jYhzkwlXeGOcB+128MD6SZAKRqzzMSW+/1FW4j3d7YscjtvJ1Jp0YYMiQrt NHq5VSteDoGJD5nxOojyYNRJjgdSaonwnbUI0Cr4eZ5G5iZ+X2I4pct+KVU/caBhY88O ZnRzFa32b+FqucSRlkMXlM0nGAKrZ4/gWRhuw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=nlgeUbrUnSGjsJ1OCFTQxdL2inJ4pHCbmXENYhIswJA=; b=Yil5wrIL8duCIrxPBYtM2AtJ5JnoR2z4wll3PAIWbb0RNSkCm2szOnJl6XCjFbX/yN 3zoRW1pBqr9E87tFqcKiXU3kZFeVo+SsAydj+rwXvaK9Sf6zDh57KQUWxOCbB9Whs/ff tqBc0sl88DNMwzYw98ufMxHnLZ0trlT7PBvSfY8TWKFo0gGca9obA1bIw8/QNZmUTcic IPdgJWggEkkS5C/Hrtl9zz8Vf7+km5LQMnwQwdR0qnsgZBVEu+1nG3GdG2aq50l0LT9k K3t+iBKQzxYEM8VZ5/BZWY3NA8XpLQGrns4W469lmPYP2pxhsq/X/Z3hg8G6ase8/nJB RNgw== X-Gm-Message-State: ALKqPweOO3cdgl7onpZK57EpTtm4keFPcFAxM6IRbMZ9L0Ckj15Bczu+ 76rw/7XA58v4snWbTLtFsuVxMA== X-Received: by 2002:a63:7159:: with SMTP id b25-v6mr1792498pgn.390.1527070460623; Wed, 23 May 2018 03:14:20 -0700 (PDT) Received: from localhost ([122.167.129.138]) by smtp.gmail.com with ESMTPSA id c7-v6sm52639993pfg.81.2018.05.23.03.14.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 May 2018 03:14:20 -0700 (PDT) Date: Wed, 23 May 2018 15:44:18 +0530 From: Viresh Kumar To: "Rafael J. Wysocki" Cc: Linux PM , LKML , Peter Zijlstra , Juri Lelli , Joel Fernandes , Patrick Bellasi , claudio@evidence.eu.com, Todd Kjos Subject: Re: [PATCH] cpufreq: schedutil: Avoid missing updates for one-CPU policies Message-ID: <20180523101418.s4zg5mr3ycxm4vi5@vireshk-i7> References: <1672734.JYOlA1IWnU@aspire.rjw.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1672734.JYOlA1IWnU@aspire.rjw.lan> User-Agent: NeoMutt/20180323-120-3dd1ac Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 23-05-18, 11:47, Rafael J. Wysocki wrote: > From: Rafael J. Wysocki > > Commit 152db033d775 (schedutil: Allow cpufreq requests to be made > even when kthread kicked) made changes to prevent utilization updates > from being discarded during processing a previous request, but it > left a small window in which that still can happen in the one-CPU > policy case. Namely, updates coming in after setting work_in_progress > in sugov_update_commit() and clearing it in sugov_work() will still > be dropped due to the work_in_progress check in sugov_update_single(). > > To close that window, rearrange the code so as to acquire the update > lock around the deferred update branch in sugov_update_single() > and drop the work_in_progress check from it. > > Signed-off-by: Rafael J. Wysocki > --- > kernel/sched/cpufreq_schedutil.c | 70 ++++++++++++++++++++++++++------------- > 1 file changed, 47 insertions(+), 23 deletions(-) > > Index: linux-pm/kernel/sched/cpufreq_schedutil.c > =================================================================== > --- linux-pm.orig/kernel/sched/cpufreq_schedutil.c > +++ linux-pm/kernel/sched/cpufreq_schedutil.c > @@ -100,25 +100,41 @@ static bool sugov_should_update_freq(str > return delta_ns >= sg_policy->freq_update_delay_ns; > } > > -static void sugov_update_commit(struct sugov_policy *sg_policy, u64 time, > - unsigned int next_freq) > +static bool sugov_update_next_freq(struct sugov_policy *sg_policy, u64 time, > + unsigned int next_freq) > { > - struct cpufreq_policy *policy = sg_policy->policy; > - > if (sg_policy->next_freq == next_freq) > - return; > + return false; > > sg_policy->next_freq = next_freq; > sg_policy->last_freq_update_time = time; > > - if (policy->fast_switch_enabled) { > - next_freq = cpufreq_driver_fast_switch(policy, next_freq); > - if (!next_freq) > - return; > + return true; > +} > + > +static void sugov_fast_switch(struct sugov_policy *sg_policy, u64 time, > + unsigned int next_freq) > +{ > + struct cpufreq_policy *policy = sg_policy->policy; > + > + if (!sugov_update_next_freq(sg_policy, time, next_freq)) > + return; > + > + next_freq = cpufreq_driver_fast_switch(policy, next_freq); > + if (!next_freq) > + return; > > - policy->cur = next_freq; > - trace_cpu_frequency(next_freq, smp_processor_id()); > - } else if (!sg_policy->work_in_progress) { > + policy->cur = next_freq; > + trace_cpu_frequency(next_freq, smp_processor_id()); > +} > + > +static void sugov_deferred_update(struct sugov_policy *sg_policy, u64 time, > + unsigned int next_freq) > +{ > + if (!sugov_update_next_freq(sg_policy, time, next_freq)) > + return; > + > + if (!sg_policy->work_in_progress) { > sg_policy->work_in_progress = true; > irq_work_queue(&sg_policy->irq_work); > } > @@ -363,13 +379,6 @@ static void sugov_update_single(struct u > > ignore_dl_rate_limit(sg_cpu, sg_policy); > > - /* > - * For slow-switch systems, single policy requests can't run at the > - * moment if update is in progress, unless we acquire update_lock. > - */ > - if (sg_policy->work_in_progress) > - return; > - > if (!sugov_should_update_freq(sg_policy, time)) > return; > > @@ -391,7 +400,18 @@ static void sugov_update_single(struct u > sg_policy->cached_raw_freq = 0; > } > > - sugov_update_commit(sg_policy, time, next_f); > + /* > + * This code runs under rq->lock for the target CPU, so it won't run > + * concurrently on two different CPUs for the same target and it is not > + * necessary to acquire the lock in the fast switch case. > + */ > + if (sg_policy->policy->fast_switch_enabled) { > + sugov_fast_switch(sg_policy, time, next_f); > + } else { > + raw_spin_lock(&sg_policy->update_lock); > + sugov_deferred_update(sg_policy, time, next_f); > + raw_spin_unlock(&sg_policy->update_lock); > + } > } > > static unsigned int sugov_next_freq_shared(struct sugov_cpu *sg_cpu, u64 time) > @@ -435,7 +455,11 @@ sugov_update_shared(struct update_util_d > > if (sugov_should_update_freq(sg_policy, time)) { > next_f = sugov_next_freq_shared(sg_cpu, time); > - sugov_update_commit(sg_policy, time, next_f); > + > + if (sg_policy->policy->fast_switch_enabled) > + sugov_fast_switch(sg_policy, time, next_f); > + else > + sugov_deferred_update(sg_policy, time, next_f); > } > > raw_spin_unlock(&sg_policy->update_lock); > @@ -450,11 +474,11 @@ static void sugov_work(struct kthread_wo > /* > * Hold sg_policy->update_lock shortly to handle the case where: > * incase sg_policy->next_freq is read here, and then updated by > - * sugov_update_shared just before work_in_progress is set to false > + * sugov_deferred_update() just before work_in_progress is set to false > * here, we may miss queueing the new update. > * > * Note: If a work was queued after the update_lock is released, > - * sugov_work will just be called again by kthread_work code; and the > + * sugov_work() will just be called again by kthread_work code; and the > * request will be proceed before the sugov thread sleeps. > */ > raw_spin_lock_irqsave(&sg_policy->update_lock, flags); Acked-by: Viresh Kumar -- viresh