Received: by 10.192.165.148 with SMTP id m20csp5264085imm; Wed, 9 May 2018 02:04:13 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrh8QI+sYmrUDAf/jUzTW2jh2K1p7qCx0BIsMn8jvR7T7e6ibV2X7m0A7MCVtA2YKC4uoCf X-Received: by 10.98.204.8 with SMTP id a8mr42985166pfg.219.1525856653491; Wed, 09 May 2018 02:04:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525856653; cv=none; d=google.com; s=arc-20160816; b=bq7DfEDXspevvr6kHGkvyuAcH8e10+raFzfTnjwpv288nWEtovHvSETZYs1C0sVz1H tFOvFlJk1y0ZTHkvOGlRbleGCuWZ6KJvJQ7ODmYqp+c1sdHvyGHBvMdlK10vSwK+Kp3B JrYDX8zUonRj80TAfuivrR60cy5nZowJ99ZrJDr/WLsLFPtSQYoOUS7oH1ndGTpjmekZ Wio2RwkfxjcKrDDMLIfa3+eyp8ao/ccNmHpS1dleL/AB9xafI+J6CoKlesFr7ngshukr NjNAqk5qh4vpTl8hcnDzVqX6iELghAWt9mk0qKkO7/+t1ypHJiy2xtXdz5M2Hh5THalw zdgA== 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=CM0TZubTqjMITMP5+MXgEtKOk+bWWbosOt032/hXWQg=; b=SFBYASXuXgxdT6qAYYSgP5OdjyH3Qe7E18Gap4ookut1y+Xcdy5IXvPx0nZWs9LHAA OQrSsB59Q5JSCUxUT8OtePfrLvhDM9kARxRP70WBz4HranORtkOwlA9ej1WwID53Zwwx D/YW7V3pL0bxTVA4eAbq+0Ga08iqQW8wbiHZv07AQAnh+VfdJHrOQwLicMkXNicfCyMU broamcde0f9NdW5eTGNnsiyaqJcuxDYhkMkObcHCgqpN1wjSoX1eBx+aa3FksrKRhQ/m njKIGoplWRpHGjLoW4ldYeFPG37hD2aTR73uRLcr7YZd+agq2We8kz3LxaSduh5psLkj f1ZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes-org.20150623.gappssmtp.com header.s=20150623 header.b=G45Dk0jm; 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 k18si26009965pfe.13.2018.05.09.02.03.58; Wed, 09 May 2018 02:04:13 -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=@joelfernandes-org.20150623.gappssmtp.com header.s=20150623 header.b=G45Dk0jm; 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 S934583AbeEIJDE (ORCPT + 99 others); Wed, 9 May 2018 05:03:04 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:40046 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934569AbeEIJDB (ORCPT ); Wed, 9 May 2018 05:03:01 -0400 Received: by mail-pg0-f66.google.com with SMTP id l2-v6so22379731pgc.7 for ; Wed, 09 May 2018 02:03:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=CM0TZubTqjMITMP5+MXgEtKOk+bWWbosOt032/hXWQg=; b=G45Dk0jm87RvsKoCKcUUwvD4Fb9CtHz6Qu/ZTaM4kjQC8sJLO8hd1mxjIVMNpfE9J7 89oIrf6xGnrIfwkjZkoIgzdZ0xBJ/fTCidGreZQy/HKjcxN4Q5FHR/0AM9fq8BcuBvO8 bOYOx9ke8NIlFIAbWnNvS2u3/i0GCOtaliRa/ldjmdnX3ZNGz3PtXs35dS+6zTve1tlb +BYlG5B+81sLYfZV4ZEBKpGF8ut9jhC4y3OVROMJyiY/Mye5uWk26jaNc13jzs4CHCdo fWN8JCFWNPMuZ3fcBTAH+QIawwbKr5358gb+UpHMC6eHWdno098BS5Uc+onyQYzvUdER bIMg== 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=CM0TZubTqjMITMP5+MXgEtKOk+bWWbosOt032/hXWQg=; b=FqRcjzGnj9rS7YbiU3sLh3PLpbDzWHyfDhe4PeYhwnq3NzRNPCeODU4WGnIGCFxedi QP3rTpd/UWZ7rBEktMUK2l7t49hnpsy4pJ+CDxkaMz2VnlEQPESTR0mvq2OeB8m0qlga f0Npsm/rpmJVQdD/v44zfor/FHHm1q/tb/erEoEMs05ufGEzBDAFivuX2pT+8aRd494O UUK1HrLS8v8Xwb7w2VUDERZ5g80uewx7kU58R9yyg7Ecx807WzNCGAmJ8JISefo9W3j5 wfiNBCM4ngn4MrS8rpiKqgGa795p/dBJd8212M+29FYdQC5evUicnTM+0jB9Qzo5oh+/ I8PA== X-Gm-Message-State: ALQs6tDD0Nk1sLQTTzx58XYHs8v8qD2PgNaOcd55rXh9ksEYYvm+QTzr G75/7H4pTc9UTalWf+t8qN575w== X-Received: by 2002:a65:4601:: with SMTP id v1-v6mr23555698pgq.237.1525856581014; Wed, 09 May 2018 02:03:01 -0700 (PDT) Received: from localhost ([2620:0:1000:1600:3122:ea9c:d178:eb]) by smtp.gmail.com with ESMTPSA id d72sm40961563pfe.150.2018.05.09.02.03.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 09 May 2018 02:03:00 -0700 (PDT) Date: Wed, 9 May 2018 02:02:59 -0700 From: Joel Fernandes To: Viresh Kumar Cc: "Rafael J. Wysocki" , Juri Lelli , Claudio Scordino , Linux Kernel Mailing List , "Rafael J . Wysocki" , Peter Zijlstra , Ingo Molnar , Patrick Bellasi , Luca Abeni , Joel Fernandes , Linux PM Subject: Re: [RFC PATCH] sched/cpufreq/schedutil: handling urgent frequency requests Message-ID: <20180509090259.GD76874@joelaf.mtv.corp.google.com> References: <1525704215-8683-1-git-send-email-claudio@evidence.eu.com> <20180508065435.bcht6dyb3rpp6gk5@vireshk-i7> <20180509045425.GA158882@joelaf.mtv.corp.google.com> <20180509064530.GA1681@localhost.localdomain> <20180509080644.GA76874@joelaf.mtv.corp.google.com> <20180509084001.bghnwpv3a3xnuxce@vireshk-i7> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180509084001.bghnwpv3a3xnuxce@vireshk-i7> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 09, 2018 at 02:10:01PM +0530, Viresh Kumar wrote: > On 09-05-18, 10:30, Rafael J. Wysocki wrote: > > On Wed, May 9, 2018 at 10:06 AM, Joel Fernandes wrote: > > > How about this? Will use the latest request, and also doesn't do unnecessary > > > irq_work_queue: > > I almost wrote the same stuff before I went for lunch :) Oh :) > > > (untested) > > > -----8<-------- > > > diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c > > > index d2c6083304b4..6a3e42b01f52 100644 > > > --- a/kernel/sched/cpufreq_schedutil.c > > > +++ b/kernel/sched/cpufreq_schedutil.c > > > @@ -38,7 +38,7 @@ struct sugov_policy { > > > struct mutex work_lock; > > > struct kthread_worker worker; > > > struct task_struct *thread; > > > - bool work_in_progress; > > > + bool work_in_progress; /* Has kthread been kicked */ > > > > > > bool need_freq_update; > > > }; > > > @@ -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; > > > - > > > > Why this change? > > > > Doing the below is rather pointless if work_in_progress is set, isn't it? > > > > You'll drop the results of it on the floor going forward anyway then AFAICS. > > > > > if (unlikely(sg_policy->need_freq_update)) { > > > sg_policy->need_freq_update = false; > > > /* > > > @@ -129,8 +126,11 @@ 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 { > > > - sg_policy->work_in_progress = true; > > > - irq_work_queue(&sg_policy->irq_work); > > > + /* work_in_progress helps us not queue unnecessarily */ > > > + if (!sg_policy->work_in_progress) { > > > + sg_policy->work_in_progress = true; > > > + irq_work_queue(&sg_policy->irq_work); > > > + } > > > } > > > } > > Right, none of the above changes are required now. I didn't follow what you mean the changes are not required? I was developing against Linus mainline. Also I replied to Rafael's comment in the other thread. > > > > @@ -381,13 +381,23 @@ 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; > > > + > > > + /* > > > + * Hold sg_policy->update_lock just enough to handle the case where: > > > + * if sg_policy->next_freq is updated before work_in_progress is set to > > > + * false, we may miss queueing the new update request since > > > + * work_in_progress would appear to be true. > > > + */ > > > + raw_spin_lock(&sg_policy->update_lock); > > > + freq = sg_policy->next_freq; > > > + sg_policy->work_in_progress = false; > > > + raw_spin_unlock(&sg_policy->update_lock); > > One problem we still have is that sg_policy->update_lock is only used > in the shared policy case and not in the single CPU per policy case, > so the race isn't solved there yet. True.. I can make the single CPU case acquire the update_lock very briefly around sugov_update_commit call in sugov_update_single. Also I think the lock acquiral from sugov_work running in the kthread context should be a raw_spin_lock_irqsave.. thanks, - Joel