Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp3005000imc; Wed, 13 Mar 2019 06:41:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqzteqeIJxUAn+zNd0pn6u1r+MlwheI9LEWlP+YhwOqjB2rO4cM5bTGFDSwtF1I9rQoL9E4v X-Received: by 2002:aa7:8b93:: with SMTP id r19mr6022169pfd.163.1552484480335; Wed, 13 Mar 2019 06:41:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552484480; cv=none; d=google.com; s=arc-20160816; b=ugotxCKgjxggQHXkMZF5Z/FBSGdWOQLhoShmfa0q8sKO9QHOwTvxW4pNHdzrBar4CX yx/gFoEZjmlRX3BSo7/V+u7DNT8FTq+XPFKlqD5Zw82qHU0y3kj5/H6amyNl9iRPtIhq jawq0OWx7TRS31KqmJbxbKG+QLZUhY6acsQDYS4iHRj2iCAF7pnutDGHZsRh+R/22aqY SKjWi4N47ywIKtwS7TQEMwc2Kd6oFtLb0bAoskkJQ/3TRsx4DKtS+DE1+ENegdCcPX4n FOhoPeAa0wyD13Q+JqxOHEip01Mtib7G23Cou3ddc/QBowhv7C4KLAoOl8GdE/3eQ6/C qzVg== 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; bh=sLBbsxetkWlLWSyLKbfNbHStCqosiSducrzxoQYCUAE=; b=yQNs/lqERvyt9GgcirIUXn6XR4RwNXOrciI3AbAiSKlPuYQ6bEagwb1eilxeAeOJvX c+ipUyu7CXBHaWqoSQ8A5tU73W+gAILmHcoW/0pP2x1V47Y8XqSY/V0RlAFbEwHmkHM8 e8AJ3DUhNsb/GuoqXCrRLGKaGYSqh1gls9OyCcBICGjC4DNtHPtxfC5XZwTo8XRlUCbW UKqAtikcw71VhHKp/HdO4IquWlHteramn9xufWJHU0Qtq//h7pfDDFRXFuJZOuLpfAk1 fxhzWF4lhzlii+k5VBb8EjvnuAvFkxUNrpLLUIG3KDqgtGNKX9+RKHr+uoBhql7ebgTK 7JvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=smmxmC4g; 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 u62si2892759pgc.204.2019.03.13.06.41.04; Wed, 13 Mar 2019 06:41:20 -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=smmxmC4g; 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 S1726684AbfCMNkg (ORCPT + 99 others); Wed, 13 Mar 2019 09:40:36 -0400 Received: from merlin.infradead.org ([205.233.59.134]:49026 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725883AbfCMNkf (ORCPT ); Wed, 13 Mar 2019 09:40:35 -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=sLBbsxetkWlLWSyLKbfNbHStCqosiSducrzxoQYCUAE=; b=smmxmC4gTIGZLwVqPRb6R77Le 010XND4sT3oLXcrZALneO8oLF80SgV73/+FEm4KpqYsoPY/6fz8zHX4Fo2EBszjAEEx1nO4ve3w49 8rY6cW3Lw1qj07mHGdzYNWI80408pUcY4Bgk153uAE8DRUXMvaVjNi5RvpjYhfj2Cgl4eT1cNTSie SMZ6neKe/PVk8W6wDZrnat2tHYrleLBLZabCX/YyvMxkyXUWpSrSu1SncWMtRPuRVTsEQFZe4ZW/o S3LsFpxVl95qKmTKF2yt4y+ysjRTMfeydWybZRuxNU451Vwh/h2CkMhYNcde0m3wZY1PR3F1QfU7/ pTzCG1QjQ==; 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 1h447M-0002vW-Qc; Wed, 13 Mar 2019 13:40:25 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 3A8282028B0E8; Wed, 13 Mar 2019 14:40:22 +0100 (CET) Date: Wed, 13 Mar 2019 14:40:22 +0100 From: Peter Zijlstra To: Patrick Bellasi Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, linux-api@vger.kernel.org, Ingo Molnar , Tejun Heo , "Rafael J . Wysocki" , Vincent Guittot , Viresh Kumar , Paul Turner , Quentin Perret , Dietmar Eggemann , Morten Rasmussen , Juri Lelli , Todd Kjos , Joel Fernandes , Steve Muckle , Suren Baghdasaryan Subject: Re: [PATCH v7 01/15] sched/core: uclamp: Add CPU's clamp buckets refcounting Message-ID: <20190313134022.GB5922@hirez.programming.kicks-ass.net> References: <20190208100554.32196-1-patrick.bellasi@arm.com> <20190208100554.32196-2-patrick.bellasi@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190208100554.32196-2-patrick.bellasi@arm.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 08, 2019 at 10:05:40AM +0000, Patrick Bellasi wrote: > +static inline unsigned int uclamp_bucket_id(unsigned int clamp_value) > +{ > + return clamp_value / UCLAMP_BUCKET_DELTA; > +} > + > +static inline unsigned int uclamp_bucket_value(unsigned int clamp_value) > +{ > + return UCLAMP_BUCKET_DELTA * uclamp_bucket_id(clamp_value); return clamp_value - (clamp_value % UCLAMP_BUCKET_DELTA); might generate better code; just a single division, instead of a div and mult. > +} > + > +static inline unsigned int uclamp_none(int clamp_id) > +{ > + if (clamp_id == UCLAMP_MIN) > + return 0; > + return SCHED_CAPACITY_SCALE; > +} > + > +static inline void uclamp_rq_update(struct rq *rq, unsigned int clamp_id) > +{ > + struct uclamp_bucket *bucket = rq->uclamp[clamp_id].bucket; > + unsigned int max_value = uclamp_none(clamp_id); > + unsigned int bucket_id; > + > + /* > + * Both min and max clamps are MAX aggregated, thus the topmost > + * bucket with some tasks defines the rq's clamp value. > + */ > + bucket_id = UCLAMP_BUCKETS; > + do { > + --bucket_id; > + if (!rq->uclamp[clamp_id].bucket[bucket_id].tasks) > + continue; > + max_value = bucket[bucket_id].value; > + break; If you flip the if condition the code will be nicer. > + } while (bucket_id); But you can also use a for loop: for (i = UCLAMP_BUCKETS-1; i>=0; i--) { if (rq->uclamp[clamp_id].bucket[i].tasks) { max_value = bucket[i].value; break; } } > + WRITE_ONCE(rq->uclamp[clamp_id].value, max_value); > +}