Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp26799imm; Mon, 21 May 2018 01:30:32 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrwN7XS78CjU56amJQlmSQbp2rq9rIiCruGsgUlCIwGK4vQoCRcNbcoqLqZnLalYnscKbE0 X-Received: by 2002:a63:6742:: with SMTP id b63-v6mr15189582pgc.54.1526891432428; Mon, 21 May 2018 01:30:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526891432; cv=none; d=google.com; s=arc-20160816; b=sIsqv/u2MOt9yBuyGJu0hQztlIedAtmthMAUZab63jF+xHf6k3tooTXyvhHDALwLeD Ph74Xvby347GHTBVipuWBLPQ23chE0EZReGWhhO1RtYnHGuTzI5fZHSSW6O8FVZGOn5v H/DXHcrj1f/6BXn0sdfyejvoNrSCgTD6/MDim2vLl7AKpc5q29xpIOkDgp5Teevztvkb eyCvpMUfBgtpoqm1KkdbX6Usrybjf3h2Up2/GYa2aXxRSDzE8XDqJzb0X1Fh4+KjETFT t6dH0G9+TtSrIk3QeiQ2dBBMZn4G03hHveDsmFnhX7A2M864tCUWGJi9dgpRBaSoAFGz TGPQ== 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 :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=KG0yKMVRwOUL8ZhJtgHbs+EZt2vVELgwOlAhOuc634Q=; b=p74V/AFss+ydFd4WXU9roOqXSCGPkYWkbMjlWuPhe19Wv6PyH5kXADCvpj5abEWLG6 UJG+PQxygJSi44+nqvqR0yxSG9w7aETtHQiArKBWEZRpvN0ItY0zPBbdSSt+qgcywiM1 VMmfmczqOq605sCOAZZtW6VyqXSSpvgOUlIuw0lCbeNHCH9Xp0Z5DH2HnHbTlZtfCkX6 GVHa7CC/UInoTRP9ZnDGqDwT19EwCp5vRDk5BuQkdThmy/ZaJAdNPqdvfhreez51TWIw z5P6PMw5ZpnAyxlYivfU4c5pXeqwS0tS3ci+R00AVrgRPu5VrNjG7St6F3g63g0zVKag 7DUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=YR4KS9+M; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s3-v6si13661987plb.394.2018.05.21.01.30.05; Mon, 21 May 2018 01:30:32 -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=fail header.i=@gmail.com header.s=20161025 header.b=YR4KS9+M; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751126AbeEUI3z (ORCPT + 99 others); Mon, 21 May 2018 04:29:55 -0400 Received: from mail-ot0-f196.google.com ([74.125.82.196]:34697 "EHLO mail-ot0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751081AbeEUI3x (ORCPT ); Mon, 21 May 2018 04:29:53 -0400 Received: by mail-ot0-f196.google.com with SMTP id i5-v6so15994026otf.1; Mon, 21 May 2018 01:29:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=KG0yKMVRwOUL8ZhJtgHbs+EZt2vVELgwOlAhOuc634Q=; b=YR4KS9+MqjxHCrrVTIheAV/YZGFfBkVeJEQefwHsdeXG/4+/rOC05OEIBoaW9XcySG Ie/4ywCg0xVGDcaYuKr8B0Giat82KRqFs5aT0LYeOWW9kuqaZYRSA8iEWTtILJSmhhkh 3VPd7Y7O7iC14+P2MeSOg37LPQbrAcGnsz+Il3B9rR5J5JUOouh/iTu2PQu1AbvNxS0+ ZweBQlUmbbEWsXyPwKBkZ3JN+s4jgwYT1jcTmkGQE0fCZPHniQCH7L56gubvLdUS7hQ1 kVwPHKPqWvwF7e/5zRYMyzvlqg3JdUFl2th/Ttm10o06e2r/47dn+zV6sBx8O/dE0H5X DQoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=KG0yKMVRwOUL8ZhJtgHbs+EZt2vVELgwOlAhOuc634Q=; b=V2UHH2GibX5bvwBNhF5w4ClC+4aVyWHJ9EiBfupIT/QqYJqaUhJjQH0cnNGtJASjf9 9tkZDBC/n17utmVpnixcMudeREYGrjMmtRySyy+GSk07Ye/ZLYbe/Nh5Tydj1ffbgefy Wn8byyFEHz7JJp+lfThTiQDtkFMkc7M0NYuMuR3KBy0TajJGJtijM9A4tJIwiqCdtkTx pDW5UPtYvYxgSlZgpxPBwDI3qlBSEBs3/exVWSRqMYoncnKb8Xq4Kjsc8EgYZhwsHUx6 yJtnJ1tH/NawZl/lFt6UtQNrSyaB1Eg8gMd8tCPlWOqV0nyXmDDP2qRq0AiM9i+lBhy5 gLOg== X-Gm-Message-State: ALKqPwfQVeFaVEeELxWvgbIrWRNe1uy3H/lpBYO0lFybsTUCbTnqUV3i NB0N9MbMIgril61MyGxxzkOgeNcc+mogv6MVVXs= X-Received: by 2002:a9d:27a6:: with SMTP id c35-v6mr13465781otb.271.1526891393208; Mon, 21 May 2018 01:29:53 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a9d:1468:0:0:0:0:0 with HTTP; Mon, 21 May 2018 01:29:52 -0700 (PDT) In-Reply-To: <20180521051424.mljwmisvrvi6yyc4@vireshk-i7> References: <20180518185501.173552-1-joel@joelfernandes.org> <20180521051424.mljwmisvrvi6yyc4@vireshk-i7> From: "Rafael J. Wysocki" Date: Mon, 21 May 2018 10:29:52 +0200 X-Google-Sender-Auth: OdcCFDy7sovRJWFxIFzi1_XHStA Message-ID: Subject: Re: [PATCH v2] schedutil: Allow cpufreq requests to be made even when kthread kicked To: Viresh Kumar , "Joel Fernandes (Google.)" Cc: Linux Kernel Mailing List , "Joel Fernandes (Google)" , "Rafael J . Wysocki" , Peter Zijlstra , Ingo Molnar , Patrick Bellasi , Juri Lelli , Luca Abeni , Todd Kjos , Claudio Scordino , kernel-team@android.com, Linux PM 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 Mon, May 21, 2018 at 7:14 AM, Viresh Kumar wrote: > On 18-05-18, 11:55, 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. > > Now that this isn't an RFC anymore, you shouldn't have added below > paragraph here. It could go to the comments section though. > >> 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 > > Looks like a Tag you just invented ? :) Yeah. The LGTM from Juri can be converned into an ACK silently IMO. That said I have added Looks-good-to: tags to a couple of commits. :-) >> 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) { >> 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; >> + > > I would still want this to go away :) > > @Rafael, will it be fine to get locking in place for unshared policy > platforms ? As long as it doesn't affect the fast switch path in any way. > >> 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) > > Fix the commit log and you can add my I can fix it up. > Acked-by: Viresh Kumar Thanks, Rafael