Received: by 10.192.165.156 with SMTP id m28csp654627imm; Fri, 13 Apr 2018 05:45:47 -0700 (PDT) X-Google-Smtp-Source: AIpwx48kFM+zI1Cr6JxdA1zD3GgywgB8WzVz8Cq9M087wakEPoMCn2wGQSfe9vcsnzpWZSmm8Z/6 X-Received: by 10.98.220.86 with SMTP id t83mr11408835pfg.60.1523623547738; Fri, 13 Apr 2018 05:45:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523623547; cv=none; d=google.com; s=arc-20160816; b=S5Iv4yHkn8WWZZLLHzr9CeB0ixm7Q2Q0JouTIrH7BGjG9ENm2UMY3jLYgQ1OUQ7WhI E6G6W/CT/mv0H+QqT45CMalfGHNjplvmyrzFcjwSV4HxElNgZ3TBy74p28DbEbl4VSgd a40CeZKO74GhCTBXuF6njExeYX82KLxaQT4E8835nUgWb2lSyH5wjeLHPb7ii+WvkEVS J+IR378NwpAMoRQ2qm+qNCE9Mw03TKj5rgWNV+kMlJypgheA9szZL/kbuOZYPFeYvx13 ZZY6az3gWyMPqC8mYjBAWNz3PcbUma7x1TW3PJHNlZKufuB8yCgXsGfSjaMYk5M7ADb2 u3AQ== 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:arc-authentication-results; bh=aB9TjjoQX2wjTmdlF48DvFQFJLTTKTlf5M//3m6udRc=; b=H4YbcC57ZnvFwAPHw1bq3IyUxMfyJbVC4FSftLlycUzeH74CN8cxUIdvOz73Lgyvuw eLlyR8m4hb2f/V/thz+L64w+T+08n403awn29VCyz266SajqyG6caOwjYekX3428U084 /5Qs3PMTrLeXdwtIZs9kjQjAscVhVUyX2KXxF7GnVEaSj29k8HUlcNd5ves1S2ZvfZUx Tv65Xzw+xE+sPhxLJrhjS4JkV+qEfb/yhYXzBsGZstYIqNN79OShBCiSSwFPtaoCeJ34 GCyMFErkdCLAdf7Qt5mnKO3oegZqmOUKYiAeFD6F9EpxOb39KyUlo/MsQ/rsw9zRuIct iTmQ== ARC-Authentication-Results: i=1; mx.google.com; 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 a100-v6si5680114pli.20.2018.04.13.05.45.33; Fri, 13 Apr 2018 05:45:47 -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; 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 S1754002AbeDMLwg (ORCPT + 99 others); Fri, 13 Apr 2018 07:52:36 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:41832 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753306AbeDMLwe (ORCPT ); Fri, 13 Apr 2018 07:52:34 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4257F80D; Fri, 13 Apr 2018 04:52:34 -0700 (PDT) Received: from e110439-lin (e110439-lin.cambridge.arm.com [10.1.210.68]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D91433F592; Fri, 13 Apr 2018 04:52:31 -0700 (PDT) Date: Fri, 13 Apr 2018 12:52:29 +0100 From: Patrick Bellasi To: Peter Zijlstra 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: <20180413115229.GW14248@e110439-lin> 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> <20180413113650.GR4064@hirez.programming.kicks-ass.net> <20180413114745.GV14248@e110439-lin> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180413114745.GV14248@e110439-lin> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 13-Apr 12:47, Patrick Bellasi wrote: > On 13-Apr 13:36, Peter Zijlstra wrote: > > 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. > > Yes, actually I'm using task_rq_lock() from the cgroup callback to > update each task already queued. And I do the same from the > sched_setattr syscall... > > > It is actually really hard to make the syscall do it wrong. > > ... thus, I'll look better into this. > > Not sure now if there was some other corner-case. Actually, I've just remembered another use-case for that back-annotation. That's used when we have cgroups and per-task API asserting two different clamp values. For example, a task in a TG with max_clamp=50 is further clamped with a task specific max_clamp=10. The back annotation tracks the group_id in which we have been refcount right now, which is the task specific group in the previous example. -- #include Patrick Bellasi