Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3211981pxb; Mon, 9 Nov 2020 05:43:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJwfQliXtLGhOqMQtPV92XOkoZDwOQimd/KJwW4OXxoReWoOzdgdW1F7sQP8xDdtwCU0dp46 X-Received: by 2002:a17:906:ca93:: with SMTP id js19mr14882953ejb.124.1604929408670; Mon, 09 Nov 2020 05:43:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604929408; cv=none; d=google.com; s=arc-20160816; b=yNbbYHRCJulTi3XduGf+hq5aJc/rranEtr4FN78Sb5gfuneaDmy8caCXzZNxNAdsz/ gt2WGXy4J4g+Y3JBsLvA7V1/DJ6SuDamwKV38aHV7DGdXkTNVa/SEbgGVq9EPEWp5jTX z6oBreu0CUVw882tyU3twRkHWp/D7DMvMH7hSE3oXfIa3f1mQj+785egYQuhXPUjBq+F upYGwCpOriKGP9/PvYbNz5XPvyP/505tUUOyfeLtBVxNM9kyC8UOdD4TZvVu1rK/ox7H zRgVjEF+ElxlwuvrARX9s25+QJCo/XXtx5jDTRqc4EbmmDeOBl4vPrgqqC24x9NMeIpf Sg2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=/8wdF3/CKEc06QLBib4qqvxlrqBujYVYytiPhMpbCYA=; b=HgOcKtMZeNCA2oIJKy6Ua7h4m8kLAk8tpar2bhMenGl6m6YMmDWVBfa40ITSUrmBV6 s7bAz0XoSTtKgI7czfIXU3Z5b272mvgSnn+CkZL6uYmtwk6rgiMGV4Ur5nlJS08C5vRZ oD/hcJaSnYB2FHsRUOE508YqvpyQZuNuMpmOZi+ZFX8mBerGuTb/jua58PO+ZCX1+qPg xCdJQu8nYUKyKp66i4Qcu270Uc8la5EvnF3eLUlmJywzgN8azOwCHwJSCXPEOvs3XsJJ xpPkEsqmmQin4QjHkESvStrJoBc3JpNQzN10HjuRpdRxUDcAzRFUqonojcwRO+sAn7dF obJg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h6si7171920ejd.632.2020.11.09.05.43.05; Mon, 09 Nov 2020 05:43:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730584AbgKINlp (ORCPT + 99 others); Mon, 9 Nov 2020 08:41:45 -0500 Received: from foss.arm.com ([217.140.110.172]:40634 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730421AbgKINlo (ORCPT ); Mon, 9 Nov 2020 08:41:44 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1200331B; Mon, 9 Nov 2020 05:41:43 -0800 (PST) Received: from e107158-lin.cambridge.arm.com (e107158-lin.cambridge.arm.com [10.1.194.78]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 2CEA83F719; Mon, 9 Nov 2020 05:41:42 -0800 (PST) Date: Mon, 9 Nov 2020 13:41:39 +0000 From: Qais Yousef To: Yun Hsiang Cc: Patrick Bellasi , dietmar.eggemann@arm.com, peterz@infradead.org, linux-kernel@vger.kernel.org, kernel test robot Subject: Re: [PATCH v5 1/1] sched/uclamp: add SCHED_FLAG_UTIL_CLAMP_RESET flag to reset uclamp Message-ID: <20201109134139.igx2slqwdhli2jdy@e107158-lin.cambridge.arm.com> References: <20201103023756.1012088-1-hsiang023167@gmail.com> <87blgag4an.derkling@matbug.net> <20201107191501.GB1056076@ubuntu> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20201107191501.GB1056076@ubuntu> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/08/20 03:15, Yun Hsiang wrote: > I think SCHED_FLAG_ALL is for internal kernel use. So I agree with not > exporting it to user. +1 for the #ifdef __kernel__ > > > + if (!(flags & SCHED_FLAG_UTIL_CLAMP_RESET)) > > > + return false; > > > + > > > + /* Only _UCLAMP_RESET flag set: reset both clamps */ > > > + if (!(flags & (SCHED_FLAG_UTIL_CLAMP_MIN | SCHED_FLAG_UTIL_CLAMP_MAX))) > > > + return true; > > > + > > > + /* Both _UCLAMP_RESET and _UCLAMP_MIN flags are set: reset only min */ > > > + if ((flags & SCHED_FLAG_UTIL_CLAMP_MIN) && clamp_id == UCLAMP_MIN) > > > + return true; > > > + > > > + /* Both _UCLAMP_RESET and _UCLAMP_MAX flags are set: reset only max */ > > > + if ((flags & SCHED_FLAG_UTIL_CLAMP_MAX) && clamp_id == UCLAMP_MAX) > > > + return true; > > > + > > > + return false; > > > > I was suggesting maybe we need READ_ONCE() in the if above but did not > > addressed previous Dietmar's question [2] on why. > > > > The function above has a correct semantics only when the ordering of the > > if statement is strictly observed. > > > > Now, since we don't have any data dependency on the multiple if cases, > > are we sure an overzealous compiler will never come up with some > > "optimized reordering" of the checks required? > > > > IOW, if the compiler could scramble the checks on an optimization, we > > would get a wrong semantics which is also very difficult do debug. > > Hence the idea to use READ_ONCE, to both tell the compiler to not > > even attempt reordering those checks and also to better document the > > code about the importance of the ordering on those checks. > > > > Is now more clear? Does that makes sense? > > I can undertand what your worries. But I'm not sure is it really needed. > If there is no other concern I can add it. I too don't think the compiler has a power to do such an optimization. It must preserve the order of the checks even if it found a more efficient way to perform them. Thanks -- Qais Yousef