Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp7231099imm; Sun, 20 May 2018 22:14:57 -0700 (PDT) X-Google-Smtp-Source: AB8JxZryXOx0Y/Jw92cMK4Lva8Q0qQIkRCq5Ru0V+XaTZbSKYgwa95gTEGWJ5WWyLYF6aviYVQ6Y X-Received: by 2002:a65:5d8e:: with SMTP id f14-v6mr14965179pgt.25.1526879697598; Sun, 20 May 2018 22:14:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526879697; cv=none; d=google.com; s=arc-20160816; b=gIHN7ESIkCk9YBuuta52808jqf2ggwVnMCaCs003vHO1W9+czjO9uqgk7F9iNxaXe9 ZHpwYwGYCqsdaj+8uM5igBi9BSi+kriq1rlJdP9OGGB8HslraYU/Oh5uPTB1Hn5z4aXJ UgXE0c07vuUn4zXV/7yUQZfC4vz1GZBdvxxrUvMCgQThyLdDSV294tdzsvSOg81HckMy su9jhA4iW99WE968uY4BDb5Ag0OuYPbmJ1FY/wzuJoKGhcPUXvc9JgtCZBYUN0+RGmfV y0dWnM8nkSDtZWzSFWjyWwSsG2s7LsRS9S0kOl9KoYJ+pfySNktjVX9vApWWyOfSV7UM JlLw== 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=2BMIDbVeJKToau12cw21YglPK5xNSXLVKbHJUMXkR+0=; b=Yg6VafrHFR9bJN/3qhQay2mM0lUHo93rv9F+ef5wweYRU66GzB2JGEpNofnbJFUe+8 KSmy4UY2wRNXh5V2BLFIsFPN8HLv7A0u4F6yJ4B/YtLARs73r53gMM5T7+YujinG+fg1 cIr0YqL+NDaZoAWtVEH337Vro26o9vc2A09FCXGpfGvSqd+vzZmRUmeukCMffi6qfmYd OFPPeO46K1IKS7dgckf1CVaocP1vEITNkImK3e7BB/KCM4rlSNK1W6F5oQVxjLoSA1Ie ZvFkI1m7QKPKLg8Bt98/ErieNUkSxM6ffWaCw/dsn8K75h+JOpoy1O5idbCZFto9hB8f KQ6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZWJ6c0aH; 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 e3-v6si13377508pfc.336.2018.05.20.22.14.42; Sun, 20 May 2018 22:14:57 -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=ZWJ6c0aH; 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 S1750978AbeEUFOb (ORCPT + 99 others); Mon, 21 May 2018 01:14:31 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:43544 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750867AbeEUFO2 (ORCPT ); Mon, 21 May 2018 01:14:28 -0400 Received: by mail-pg0-f66.google.com with SMTP id p8-v6so5831103pgq.10 for ; Sun, 20 May 2018 22:14:27 -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=2BMIDbVeJKToau12cw21YglPK5xNSXLVKbHJUMXkR+0=; b=ZWJ6c0aHxepyND3G8rTWHIzp/cwjS6tOmVd8fkKlXKbTzMv74yKaQfNvlka++yhEmD j/pqcII45KN8rFdNaj/EwuEDcFNT6jkTPjRk38RXNs5Ni9ML+lfPcsOSrlz+A/LSl7Gx 10xuVG2fzO3PMEpZKUULPtph31bsWhp/x+a7w= 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=2BMIDbVeJKToau12cw21YglPK5xNSXLVKbHJUMXkR+0=; b=qLLakQdPX4qz1VN4NpSButjcyWSgndHNJ8/O/O7XujzQOpYltXX+9Y67LEzKzMV0NK S2jLMFxmn+erD6TUCu80CyPvaYJBVkL7CzzZqrdkv/vcIhPOg+a35upf1iyiJx+0bS7u ckm7wf39O3EV/I867Bhj8g7jxiORsaJba7yA4ZuyczdufUS0Ocy7xaAvBWJseS+welSm JFk32a5mLOXwewfqLf343s7WsXKQ5UO8nOgJoG8I6kD4eyi1JWJLiO3FjNEXA3EIv9LP fvxhhQL8zHMpYqc2p3SNMrbeP4US2YVOZqGsOonkpoDwQw9yOm0j3CN502Phi9UPe+mb oVPQ== X-Gm-Message-State: ALKqPwdd2t3QYE+Mmg8M6A7i3FAkzR8pZPEC+dEWAypVd9sf5jyBu7c1 AYzabr0aL4bhEM8g0NCWO/czeg== X-Received: by 2002:a62:22db:: with SMTP id p88-v6mr18664472pfj.239.1526879667311; Sun, 20 May 2018 22:14:27 -0700 (PDT) Received: from localhost ([122.167.163.112]) by smtp.gmail.com with ESMTPSA id 16-v6sm27036087pfq.115.2018.05.20.22.14.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 20 May 2018 22:14:26 -0700 (PDT) Date: Mon, 21 May 2018 10:44:24 +0530 From: Viresh Kumar To: "Joel Fernandes (Google.)" Cc: linux-kernel@vger.kernel.org, "Joel Fernandes (Google)" , "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 Message-ID: <20180521051424.mljwmisvrvi6yyc4@vireshk-i7> References: <20180518185501.173552-1-joel@joelfernandes.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180518185501.173552-1-joel@joelfernandes.org> 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 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 ? :) > 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 ? > 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 Acked-by: Viresh Kumar -- viresh