Received: by 10.192.165.156 with SMTP id m28csp650107imm; Fri, 13 Apr 2018 05:40:27 -0700 (PDT) X-Google-Smtp-Source: AIpwx49+iaJLE0VKl+do25Qdv1A2fYUUCe4m/Ew21O5jQCkQXUEhwY0RgY74sNMKDcKqmbM4dunh X-Received: by 10.99.119.133 with SMTP id s127mr3962005pgc.441.1523623227308; Fri, 13 Apr 2018 05:40:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523623227; cv=none; d=google.com; s=arc-20160816; b=KuApL3nygvlXOvpW6nwkT9EbUdNq5pD8zGF8zq3vXGZ5Z1sy/TMIUehGjpJquFmFJF kucJUKVNhvofQDbp3u1hjc63GYtz58nCbs5/7MC7AXJ851gEEVy+cOh7eVmVHHbDt/Tu eB6dhLYbbOb/BqA7YOXscYJLkt9RgDGdr9gLTRN0600Uu2j8LMke98YadnSRotCbOTXA ekLkUQRfvB/TLTEzvV4X1rxhwo333bo3R6dwJZiSSgtGnAsRzudAZ1zKT1bb4Sq9qJOR 5q9INtmRDPq6e4OwuQAn+4j2MNMOstcgFU6gNlc0HZQIR3uc8ea4WJL7vRantDgiOmRi KxLQ== 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=XWH/3FiQCMDhwkzdvROnFobU5tI0uKzXv/fz2phSbYM=; b=unIS/FbEAAPF7B6l19GH3BcRWzwDTCqM/y6RUj5OnZosLR4Npe8dYo/tKObusG4Guv wd92zvKYIGaPkitCQDM1Oc3qGm1+pLn2kixx/yYCejEp5UCUkb5r2QHEiYUelz2yrbue 7fRTRS8Jytfly0MO9uK99htFTdM7SBOM3viQHoxkiHXg/JNivuGPHBELtdfwghgb2ve/ i2/rZ5YCz7SI6w5dcf5AqrOJTKjF+iwAt+mPo+UCYVcpW8vFiI8tpTwWrrtTTuiApIB4 JDmfap7CW5zv0BhbG6HR9Ulo4l2YEIy4recqPV1uxG4i3dwtNzRXE2ELSOYFlmNQ9rln s6Ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=lmrEaGIy; 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 d127si3929468pga.201.2018.04.13.05.40.12; Fri, 13 Apr 2018 05:40:27 -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=@infradead.org header.s=merlin.20170209 header.b=lmrEaGIy; 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 S1754724AbeDMLhE (ORCPT + 99 others); Fri, 13 Apr 2018 07:37:04 -0400 Received: from merlin.infradead.org ([205.233.59.134]:36716 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753541AbeDMLhC (ORCPT ); Fri, 13 Apr 2018 07:37:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=XWH/3FiQCMDhwkzdvROnFobU5tI0uKzXv/fz2phSbYM=; b=lmrEaGIyHoONkE8sE0ZxJ70Kk FFy74soZaffovkXr5uxhAhvox4J35/xTgnwIIvdDIIsLKfukr5kiJAiskz2Nl1ebiKG06/sB1zB32 MX0t8wpGZuUq7GweFAsd2aUGctgf29ZFu6BhXULtgKxn52puTDs0kfWsXeXXeheC+BuDccwL/IlbR vKom2Hz4S58aj9HtpC1nXKPSlAp6Cbz2CMad04eSbUPmDEqhjF97jiHk9IZWv6h0MeR9MLnu0kCSH tBnL/tV40vueulI9nqWPeHQ9Ixh8+9pXDLAoxAnv/LgSsmJc00NkdaPRFMteCuMc9fjkrqYcWuzQu 6VkxzLMVg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1f6x0e-0004TH-5V; Fri, 13 Apr 2018 11:36:52 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 7157F202A29FD; Fri, 13 Apr 2018 13:36:50 +0200 (CEST) Date: Fri, 13 Apr 2018 13:36:50 +0200 From: Peter Zijlstra To: Patrick Bellasi Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Ingo Molnar , Tejun Heo , "Rafael J . Wysocki" , Viresh Kumar , Vincent Guittot , Paul Turner , Dietmar Eggemann , Morten Rasmussen , Juri Lelli , Joel Fernandes , Steve Muckle Subject: Re: [PATCH 1/7] sched/core: uclamp: add CPU clamp groups accounting Message-ID: <20180413113650.GR4064@hirez.programming.kicks-ass.net> References: <20180409165615.2326-1-patrick.bellasi@arm.com> <20180409165615.2326-2-patrick.bellasi@arm.com> <20180413084302.GR4043@hirez.programming.kicks-ass.net> <20180413111510.GS14248@e110439-lin> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180413111510.GS14248@e110439-lin> User-Agent: Mutt/1.9.3 (2018-01-21) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Apr 13, 2018 at 12:15:10PM +0100, Patrick Bellasi wrote: > On 13-Apr 10:43, Peter Zijlstra wrote: > > On Mon, Apr 09, 2018 at 05:56:09PM +0100, Patrick Bellasi wrote: > > > +static inline void uclamp_task_update(struct rq *rq, struct task_struct *p) > > > +{ > > > + int cpu = cpu_of(rq); > > > + int clamp_id; > > > + > > > + /* The idle task does not affect CPU's clamps */ > > > + if (unlikely(p->sched_class == &idle_sched_class)) > > > + return; > > > + /* DEADLINE tasks do not affect CPU's clamps */ > > > + if (unlikely(p->sched_class == &dl_sched_class)) > > > + return; > > > + > > > + for (clamp_id = 0; clamp_id < UCLAMP_CNT; ++clamp_id) { > > > + if (uclamp_task_affects(p, clamp_id)) > > > + uclamp_cpu_put(p, cpu, clamp_id); > > > + else > > > + uclamp_cpu_get(p, cpu, clamp_id); > > > + } > > > +} > > > > Is that uclamp_task_affects() thing there to fix up the fact you failed > > to propagate the calling context (enqueue/dequeue) ? > > Not really, it's intended by design: we back annotate the clamp_group > a task has been refcounted in. > > The uclamp_task_affects() tells if we are refcounted now and then we > know from the back-annotation from which refcounter we need to remove > the task. > > I found this solution much less racy and effective in avoiding to > screw up the refcounter whenever we look at a task at either > dequeue/migration time and these operations can overlaps with the > slow-path. Meaning, when we change the task specific clamp_group > either via syscall or cgroups attributes. > > IOW, the back annotation allows to decouple refcounting from > clamp_group configuration in a lockless way. But it adds extra state and logic, to a fastpath, for no reason. I suspect you messed up the cgroup side; because the syscall should already have done task_rq_lock() and hold both p->pi_lock and rq->lock and have dequeued the task when changing the attribute. It is actually really hard to make the syscall do it wrong.