Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3015769imu;
        Wed, 7 Nov 2018 03:39:34 -0800 (PST)
X-Google-Smtp-Source: AJdET5drj40RcSZtVTBUsdNm+G7NIShFOTgeyPfD1qUOVAtnY4hqVkRFDEiGLobk22OkC9CpjDcg
X-Received: by 2002:a63:1e5c:: with SMTP id p28mr1268470pgm.376.1541590774474;
        Wed, 07 Nov 2018 03:39:34 -0800 (PST)
ARC-Seal: i=1; a=rsa-sha256; t=1541590774; cv=none;
        d=google.com; s=arc-20160816;
        b=PGOd3wdUftKlISrokUsjKmwv3LWOKj/4agMySoTekAMIs+AuG/od6Qha7liDkGbXO8
         0qMCeVyiXyF5KK/rp5Xp1z8VQMK94aztuLAlGJJYitxBLK7xVg8+sfLMboomHqSrmdXe
         2Xt98c5HEEP8G0kT8WfeJzID/HdV5vZMePT0xUIEmck0u6k3E/cSYmUSOp4T5FzD7vB1
         mOCbrMU9yCk1axsA5E5CnzYqHzHn5o4f1dIIuythu1VU6MhTH8pD30QnXfqJ7u8AtSk8
         gjaPwpgQHTxpfaR1xy1yw4cDq9HEajc3morWTlSvj5CKlXdRSYrQgg3NRVRFVmhHze3h
         vf+A==
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;
        bh=hy1gVx5CE9qmN9br+A2B28t+5hecVMOlAykjErorkhY=;
        b=FvuOpf6ip+Z5zubS80ZcuRZ56QIfqbZVGnsw/qxAkGnyaj1jK/7Ohty7CpCJJfr2xP
         3mSD7o1VQJBCIpxKPmChVmVP5jAbczQVrHqSZi8x449j3rKqbNMHbJ4CkXuY4rmdAwJY
         SmNzOFZk+UUuqyt8UWdCIKar05OwOkDc7N8UL6SEldFZLD2gXJDqEuhrM43j8BBwajON
         skny2bbGYtRZZ/zbE2Q5UASxSBvBCH1beaS9rTn9+FZPPM6nypEHtHs5HkBIMla+GBPq
         8IwRIFAAbthpgwkmrpunTmcLPzhaAoU8Nrujh2mEMtJClKaEEqXrnaYZZFUJnCPBXk7X
         uueQ==
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: <linux-kernel-owner@vger.kernel.org>
Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67])
        by mx.google.com with ESMTP id x68-v6si393484pfc.0.2018.11.07.03.39.17;
        Wed, 07 Nov 2018 03:39:34 -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;
       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 S1726641AbeKGVIy (ORCPT <rfc822;noahbdev@gmail.com> + 99 others);
        Wed, 7 Nov 2018 16:08:54 -0500
Received: from foss.arm.com ([217.140.101.70]:49404 "EHLO foss.arm.com"
        rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP
        id S1726241AbeKGVIy (ORCPT <rfc822;linux-kernel@vger.kernel.org>);
        Wed, 7 Nov 2018 16:08:54 -0500
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 4B7F780D;
        Wed,  7 Nov 2018 03:38:55 -0800 (PST)
Received: from e110439-lin (e110439-lin.cambridge.arm.com [10.1.194.43])
        by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7CA533F5CF;
        Wed,  7 Nov 2018 03:38:52 -0800 (PST)
Date:   Wed, 7 Nov 2018 11:38:49 +0000
From:   Patrick Bellasi <patrick.bellasi@arm.com>
To:     linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org
Cc:     Ingo Molnar <mingo@redhat.com>,
        Peter Zijlstra <peterz@infradead.org>,
        Tejun Heo <tj@kernel.org>,
        "Rafael J . Wysocki" <rafael.j.wysocki@intel.com>,
        Vincent Guittot <vincent.guittot@linaro.org>,
        Viresh Kumar <viresh.kumar@linaro.org>,
        Paul Turner <pjt@google.com>,
        Quentin Perret <quentin.perret@arm.com>,
        Dietmar Eggemann <dietmar.eggemann@arm.com>,
        Morten Rasmussen <morten.rasmussen@arm.com>,
        Juri Lelli <juri.lelli@redhat.com>,
        Todd Kjos <tkjos@google.com>,
        Joel Fernandes <joelaf@google.com>,
        Steve Muckle <smuckle@google.com>,
        Suren Baghdasaryan <surenb@google.com>
Subject: Re: [PATCH v5 09/15] sched/cpufreq: uclamp: add utilization clamping
 for FAIR tasks
Message-ID: <20181107113849.GC14309@e110439-lin>
References: <20181029183311.29175-1-patrick.bellasi@arm.com>
 <20181029183311.29175-11-patrick.bellasi@arm.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20181029183311.29175-11-patrick.bellasi@arm.com>
User-Agent: Mutt/1.5.24 (2015-08-30)
Sender: linux-kernel-owner@vger.kernel.org
Precedence: bulk
List-ID: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-kernel@vger.kernel.org

On 29-Oct 18:33, Patrick Bellasi wrote:

[...]

> +#ifdef CONFIG_UCLAMP_TASK
> +/**
> + * clamp_util: clamp a utilization value for a specified CPU
> + * @rq: the CPU's RQ to get the clamp values from
> + * @util: the utilization signal to clamp
> + *
> + * Each CPU tracks util_{min,max} clamp values depending on the set of its
> + * currently RUNNABLE tasks. Given a utilization signal, i.e a signal in
> + * the [0..SCHED_CAPACITY_SCALE] range, this function returns a clamped
> + * utilization signal considering the current clamp values for the
> + * specified CPU.
> + *
> + * Return: a clamped utilization signal for a given CPU.
> + */
> +static inline unsigned int uclamp_util(struct rq *rq, unsigned int util)
> +{
> +	unsigned int min_util = rq->uclamp.value[UCLAMP_MIN];
> +	unsigned int max_util = rq->uclamp.value[UCLAMP_MAX];

Just notice here we can have an issue.

For each scheduling entity, we always ensure that:

    util_min <= util_max

However, since CPU's {min,max}_util clamps are always MAX aggregated
considering the corresponding clamps of RUNNABLE tasks with
_different_ clamps, we can end up with CPU clamps where:

    util_min > util_max

Thus, we need to add the following sanity check here:

+       if (unlikely(min_util > max_util))
+               return min_util;

> +
> +	return clamp(util, min_util, max_util);
> +}

-- 
#include <best/regards.h>

Patrick Bellasi