Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp4983445imm; Fri, 18 May 2018 14:15:13 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqB2ZkmHjwr6y+zlj3Bc1Gv6h23PynoEjzEBTGdDdoEuOeJcviJQ/QjMlq6ZNbuynX4Z0Ym X-Received: by 2002:a62:f24a:: with SMTP id y10-v6mr10948025pfl.75.1526678112947; Fri, 18 May 2018 14:15:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526678112; cv=none; d=google.com; s=arc-20160816; b=JkjprMebUr3T8F2L3VlHR4/+aq9DiTZowA27c7eyj2fyNt0/A3qrJkpsa8VW8WXl7B lZPPgSaX30mvXsHA/oiNR3KZnQHA5X9XVgGXyS3qNZGEMvxWkkaBao9hKBnutXxJNH/O P1ZnVXY4WBbTMeI291j6wx3LqALATZtcfTotqmVG5tyuWh72/ba9IKSQZF/ul80vnzfD xCGCcXj2NPzoC9MBUqqi7XKwe/qc6bHiiIJ6aPiX0gECYTWqtEOdt5ZHDkG8e3DNZBfO I7pSOS8wdkqqyyzzfkkylm2BLullqN7TLDb5drdl90/AlQ/9iAD3GCgxpQTU6kmDFVlu Hxmg== 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:in-reply-to :references:subject:cc:to:mime-version:user-agent:from:date :message-id:dmarc-filter:dkim-signature:dkim-signature :arc-authentication-results; bh=yxDcZzqqBQw1g6uU49iG0V2e29l3Dlq00X0VVw939cg=; b=El2rClGLsUVainzU09GS7QV4xa7hxDIzk9LQzJBgEWbcMioYOquDz6avRRmQC3lkpa GaXoKr5+pvxTW39AAMhdhPA9l+DrKTjYf+mi2SXpboJlgudImUhCxnoGd+LLcm3lXe8Y 7xmBdUAWa78Swpmm4vc+AmanQ0JWozcpmhFPRdTNrbvREpIKrGJ11Q0xNaAVSUhjy094 TkkRLuV9Bh0f0abZ0uKo4qnVVeRWekoRQFLDnK+oJ2Dd6iVtSanL4Ls39dWNYDST9hIl CqBCyUpFNdI9HRvC+SKQ0AHkqyMPCpS6ZMs1qahdcrBy4zX2rnV08R/3C0S7v9Scocl3 ae1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=kGXJ1HzU; dkim=pass header.i=@codeaurora.org header.s=default header.b=dLW4cJjy; 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 r5-v6si6620122pgp.379.2018.05.18.14.14.58; Fri, 18 May 2018 14:15:12 -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=@codeaurora.org header.s=default header.b=kGXJ1HzU; dkim=pass header.i=@codeaurora.org header.s=default header.b=dLW4cJjy; 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 S1751693AbeERVNs (ORCPT + 99 others); Fri, 18 May 2018 17:13:48 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:47838 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750763AbeERVNo (ORCPT ); Fri, 18 May 2018 17:13:44 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 3386D60AF9; Fri, 18 May 2018 21:13:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1526678024; bh=SLmLCp09QbWO+LM3UtTUeHHbAN0wvXvIw2x2nMgdUQg=; h=Date:From:To:CC:Subject:References:In-Reply-To:From; b=kGXJ1HzUflBTfgpVk5esw7SVdNKQHrpXhA1uZpUhdAoE2JpDuORlKyBTouG41BP2y 8c+moFPrb6B+smUN++XOMUQoqej4pvHj7IldHpIbXw785nae6VzJUqC1hZpL0s9s+f R90TQIzMqmjvb6Y2+kbd4Zgem65WD8OnCPYSliak= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from [10.134.64.210] (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: skannan@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 7CBB760131; Fri, 18 May 2018 21:13:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1526678011; bh=SLmLCp09QbWO+LM3UtTUeHHbAN0wvXvIw2x2nMgdUQg=; h=Date:From:To:CC:Subject:References:In-Reply-To:From; b=dLW4cJjy+BeC7r5uYsv45fy1blHXzClATrUqXqKug1ce01NKn+VD6Cz9pA7waXhmj lvvQ3YScQB5UZz+StF0EB51oXze+VyoJ86zpqkjm8NmBWujQX3A0RYs7X2Sb/GhZaq ssUNqu8V3vNmhXvTKnLkBLqhB13oKqlJCxdUWE8k= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 7CBB760131 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=skannan@codeaurora.org Message-ID: <5AFF41F9.6050300@codeaurora.org> Date: Fri, 18 May 2018 14:13:29 -0700 From: Saravana Kannan User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130329 Thunderbird/17.0.5 MIME-Version: 1.0 To: "Joel Fernandes (Google.)" CC: linux-kernel@vger.kernel.org, "Joel Fernandes (Google)" , Viresh Kumar , "Rafael J . Wysocki" , Peter Zijlstra , Ingo Molnar , Patrick Bellasi , Juri Lelli , Luca Abeni , Todd Kjos , claudio@evidence.eu.com, kernel-team@android.com, linux-pm@vger.kernel.org Subject: Re: [PATCH v2] schedutil: Allow cpufreq requests to be made even when kthread kicked References: <20180518185501.173552-1-joel@joelfernandes.org> In-Reply-To: <20180518185501.173552-1-joel@joelfernandes.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/18/2018 11:55 AM, Joel Fernandes (Google.) wrote: > From: "Joel Fernandes (Google)" > > Currently there is a chance of a schedutil cpufreq update request to be > dropped if there is a pending update request. This pending request can > be delayed if there is a scheduling delay of the irq_work and the wake > up of the schedutil governor kthread. > > A very bad scenario is when a schedutil request was already just made, > such as to reduce the CPU frequency, then a newer request to increase > CPU frequency (even sched deadline urgent frequency increase requests) > can be dropped, even though the rate limits suggest that its Ok to > process a request. This is because of the way the work_in_progress flag > is used. > > This patch improves the situation by allowing new requests to happen > even though the old one is still being processed. Note that in this > approach, if an irq_work was already issued, we just update next_freq > and don't bother to queue another request so there's no extra work being > done to make this happen. > > I had brought up this issue at the OSPM conference and Claudio had a > discussion RFC with an alternate approach [1]. I prefer the approach as > done in the patch below since it doesn't need any new flags and doesn't > cause any other extra overhead. > > [1] https://patchwork.kernel.org/patch/10384261/ > > LGTMed-by: Viresh Kumar > LGTMed-by: Juri Lelli > CC: Viresh Kumar > CC: Rafael J. Wysocki > CC: Peter Zijlstra > CC: Ingo Molnar > CC: Patrick Bellasi > CC: Juri Lelli > Cc: Luca Abeni > CC: Joel Fernandes > CC: Todd Kjos > CC: claudio@evidence.eu.com > CC: kernel-team@android.com > CC: linux-pm@vger.kernel.org > Signed-off-by: Joel Fernandes (Google) > --- > v1 -> v2: Minor style related changes. > > kernel/sched/cpufreq_schedutil.c | 34 ++++++++++++++++++++++++-------- > 1 file changed, 26 insertions(+), 8 deletions(-) > > diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c > index e13df951aca7..5c482ec38610 100644 > --- a/kernel/sched/cpufreq_schedutil.c > +++ b/kernel/sched/cpufreq_schedutil.c > @@ -92,9 +92,6 @@ static bool sugov_should_update_freq(struct sugov_policy *sg_policy, u64 time) > !cpufreq_can_do_remote_dvfs(sg_policy->policy)) > return false; > > - if (sg_policy->work_in_progress) > - return false; > - > if (unlikely(sg_policy->need_freq_update)) { > sg_policy->need_freq_update = false; > /* > @@ -128,7 +125,7 @@ static void sugov_update_commit(struct sugov_policy *sg_policy, u64 time, > > policy->cur = next_freq; > trace_cpu_frequency(next_freq, smp_processor_id()); > - } else { > + } else if (!sg_policy->work_in_progress) { Not really something you added, but if you are modifying it: Do we really need this work_in_progress flag? irq_work_queue() already checks if the work is pending and then returns true/false. Wouldn't the issue you are trying to fix be resolved just by dropping this flag check entirely? > sg_policy->work_in_progress = true; > irq_work_queue(&sg_policy->irq_work); > } > @@ -291,6 +288,13 @@ static void sugov_update_single(struct update_util_data *hook, u64 time, > > 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; > > @@ -382,13 +386,27 @@ sugov_update_shared(struct update_util_data *hook, u64 time, unsigned int flags) > static void sugov_work(struct kthread_work *work) > { > struct sugov_policy *sg_policy = container_of(work, struct sugov_policy, work); > + unsigned int freq; > + unsigned long flags; > + > + /* > + * 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 > + * 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 > + * request will be proceed before the sugov thread sleeps. > + */ > + raw_spin_lock_irqsave(&sg_policy->update_lock, flags); > + freq = sg_policy->next_freq; > + sg_policy->work_in_progress = false; > + raw_spin_unlock_irqrestore(&sg_policy->update_lock, flags); > > mutex_lock(&sg_policy->work_lock); > - __cpufreq_driver_target(sg_policy->policy, sg_policy->next_freq, > - CPUFREQ_RELATION_L); > + __cpufreq_driver_target(sg_policy->policy, freq, CPUFREQ_RELATION_L); > mutex_unlock(&sg_policy->work_lock); > - > - sg_policy->work_in_progress = false; > } > > static void sugov_irq_work(struct irq_work *irq_work) > -Saravana -- Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project