Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7425612imu; Tue, 22 Jan 2019 05:59:08 -0800 (PST) X-Google-Smtp-Source: ALg8bN4q8M7jbfM7gEPc7+2sZFhLXzc//sAEq86V7afOPLfrdh8n+q5DhUFNs2OviY+unMq/1f0N X-Received: by 2002:a17:902:3383:: with SMTP id b3mr33553846plc.170.1548165548742; Tue, 22 Jan 2019 05:59:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548165548; cv=none; d=google.com; s=arc-20160816; b=lrVfjsVJjcvUuK60g53J5235Ev/8i7F5WL4DCdF8h8Wmy7O2/wmnoi1qWQsp/hZaQd U88xjik3C3v3ITbHhoZB+Wd/6oPfd8ozgCopjQcLT0jcqrJpyiIJ75ZE3XBMxnTfyG+V FdT3IcCCVYmi5iX7at+qt9ax5xlB3JFe3fDj37QwcECid4knaI5Vsq6jPW/1U0Ho2CFV ITlXbrW7UWhyzXpI1bDjPl9Y2EfQEiKKLTbc+1p8H91JFkkPryjiL4mc63CTG5lBuz0g 0MEWyCvAAff+OYEggz9PQt8Cg2yVVXbxmiSzpD3GcaGsO1mESuAy04hYzKi9d8Q8v3/s eITQ== 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=/yGAsqBQmq+378K3Ed7uGS+TjYfgRXBZD5L47WVukvY=; b=T8UmpZe4+RjitXwxIvybVLexkwdokt7OBdLrIbjprsLMOIYXvmCw3VtKx4rFV9Ei4E Zmm0RaN8fsfMgjAzQoUm67g4/U2Pujelqj7Cq8uwHqdCTQ4QOlwzJaJ1/s4FVV7bkcoK 4H4LBDYjMIdewhMKYQjH9umuz27lAAzaqdrVWUo7FCPlqZ1kiWKiqZbB3+pyX7OjYFJ8 DN2ipz7DHPHygU6xBkFEPLSbFKIWKJhf45PyYHpK+bSHQRiVk5Hlkp7J9shyHHYnZIQE PAyXZr+lnPgpcA+weckAzXZeYGtAwS4MV5v7Nx6W6gjbuVPrBxoMHMEcxpjV3QGFN3Vd 7iWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b="o/TtZkm3"; 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 c139si16037738pfb.281.2019.01.22.05.58.52; Tue, 22 Jan 2019 05:59:08 -0800 (PST) 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="o/TtZkm3"; 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 S1728601AbfAVN46 (ORCPT + 99 others); Tue, 22 Jan 2019 08:56:58 -0500 Received: from merlin.infradead.org ([205.233.59.134]:60388 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728529AbfAVN45 (ORCPT ); Tue, 22 Jan 2019 08:56:57 -0500 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=/yGAsqBQmq+378K3Ed7uGS+TjYfgRXBZD5L47WVukvY=; b=o/TtZkm3dr+ThaWKQ2MKXniZ/ KJnSsK4snnd1r5dUNjTBoIfIVlMuzlf6usPlCCvKilz0MWzPbVl7HVTvVwOZYWVYKw10ZOkKV3xwg 4B9XUg01CPPipJjK/Ah8865TK+YRWW9Lq8gqDSIcSehz+hyX1m/Z/MfeadkABp7U7HRc/hBgsV+qO cDsEuEAUfvgidb3eEnTvPysOVKXRkOahpl85BDIMyARJjgJeIbBVkFr0ljJJ+tsZLNlaCazNvbB7U 99/qGuySnvTGb+NgkYRrbFY4D805uhjBVgimNJz4YStRDqqCjKOtwG0qEKiabgxAk7vs0ISKq0gyO xHV4FrFNA==; 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 1glwXm-00024M-Td; Tue, 22 Jan 2019 13:56:47 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 4B5462042CFC2; Tue, 22 Jan 2019 14:56:44 +0100 (CET) Date: Tue, 22 Jan 2019 14:56:44 +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 v6 07/16] sched/core: uclamp: Add system default clamps Message-ID: <20190122135644.GP27931@hirez.programming.kicks-ass.net> References: <20190115101513.2822-1-patrick.bellasi@arm.com> <20190115101513.2822-8-patrick.bellasi@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190115101513.2822-8-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 Tue, Jan 15, 2019 at 10:15:04AM +0000, Patrick Bellasi wrote: > diff --git a/include/linux/sched.h b/include/linux/sched.h > index 84294925d006..c8f391d1cdc5 100644 > --- a/include/linux/sched.h > +++ b/include/linux/sched.h > @@ -625,6 +625,11 @@ struct uclamp_se { > unsigned int bucket_id : bits_per(UCLAMP_BUCKETS); > unsigned int mapped : 1; > unsigned int active : 1; > + /* Clamp bucket and value actually used by a RUNNABLE task */ > + struct { > + unsigned int value : bits_per(SCHED_CAPACITY_SCALE); > + unsigned int bucket_id : bits_per(UCLAMP_BUCKETS); > + } effective; I am confuzled by this thing.. so uclamp_se already has a value,bucket, which per the prior code is the effective one. Now; I think I see why you want another value; you need the second to store the original value for when the system limits change and we must re-evaluate. So why are you not adding something like: unsigned int orig_value : bits_per(SCHED_CAPACITY_SCALE); > +unsigned int sysctl_sched_uclamp_util_min; > +unsigned int sysctl_sched_uclamp_util_max = SCHED_CAPACITY_SCALE; > +static inline void > +uclamp_effective_get(struct task_struct *p, unsigned int clamp_id, > + unsigned int *clamp_value, unsigned int *bucket_id) > +{ > + /* Task specific clamp value */ > + *clamp_value = p->uclamp[clamp_id].value; > + *bucket_id = p->uclamp[clamp_id].bucket_id; > + > + /* System default restriction */ > + if (unlikely(*clamp_value < uclamp_default[UCLAMP_MIN].value || > + *clamp_value > uclamp_default[UCLAMP_MAX].value)) { > + /* Keep it simple: unconditionally enforce system defaults */ > + *clamp_value = uclamp_default[clamp_id].value; > + *bucket_id = uclamp_default[clamp_id].bucket_id; > + } > +} That would then turn into something like: unsigned int high = READ_ONCE(sysctl_sched_uclamp_util_max); unsigned int low = READ_ONCE(sysctl_sched_uclamp_util_min); uclamp_se->orig_value = value; uclamp_se->value = clamp(value, low, high); And then determine bucket_id based on value. > +int sched_uclamp_handler(struct ctl_table *table, int write, > + void __user *buffer, size_t *lenp, > + loff_t *ppos) > +{ > + int old_min, old_max; > + int result = 0; > + > + mutex_lock(&uclamp_mutex); > + > + old_min = sysctl_sched_uclamp_util_min; > + old_max = sysctl_sched_uclamp_util_max; > + > + result = proc_dointvec(table, write, buffer, lenp, ppos); > + if (result) > + goto undo; > + if (!write) > + goto done; > + > + if (sysctl_sched_uclamp_util_min > sysctl_sched_uclamp_util_max || > + sysctl_sched_uclamp_util_max > SCHED_CAPACITY_SCALE) { > + result = -EINVAL; > + goto undo; > + } > + > + if (old_min != sysctl_sched_uclamp_util_min) { > + uclamp_bucket_inc(NULL, &uclamp_default[UCLAMP_MIN], > + UCLAMP_MIN, sysctl_sched_uclamp_util_min); > + } > + if (old_max != sysctl_sched_uclamp_util_max) { > + uclamp_bucket_inc(NULL, &uclamp_default[UCLAMP_MAX], > + UCLAMP_MAX, sysctl_sched_uclamp_util_max); > + } Should you not update all tasks?