Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp106254pxb; Wed, 11 Nov 2020 21:47:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJxX029ngh6m38TLnw81Ls4zCllGl2TRznVPt+qtflfYB+Ug/atQ3uCNh4SB6W8pz53Ukac3 X-Received: by 2002:a05:6402:22af:: with SMTP id cx15mr3247599edb.207.1605160077284; Wed, 11 Nov 2020 21:47:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605160077; cv=none; d=google.com; s=arc-20160816; b=TjnYp7OUjkbEXXWgoKrNE9VSvn7D1i3g3lp+bUslHq2VtCx1b9yaOsahHbEhcjIotQ r6+k5ShW1MO6+2BKRwnup9/4iSJWLPsHuzIWZXKWl5JiediIqIhQZEjOm7QqYxfaxwSM h+kPl4ASodUEcAiraLOVJANcAQtXJc9tX9PkHONxBxDOQSSxl1Tyfr60vDmGbyiVJp4+ 1RIB309bIlIOH+m9hestCtV2lAx6HFLBPnJr77aonXkdnzDtSa5rTjJImIjOpdhbS1d4 16aQgm9sO7gOeW8CfhCSvVwDwI75AGlUxmEO/PHYSybkm7BtAG+XWaWG2zSyOx+OAwn8 FONQ== 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:dkim-signature; bh=8Wrc8fiOuZuXNhL9f/svgjNc/c8x+1+TBbfywF036g8=; b=Dxjd8aChzrpR+YlOENaER+tHHRxIxjFhVseZ5n++Cx0LrqsyiQb5l+S1Kg8325vIXq 2fcjXWZ1szIsmgOOJXvJ+AUU5YwzyHxC20Rn6B8cYGQtDTraTXLC4hW0Apk1HY0AAjtg 21rJN4XkvnJ6qPwgahzH81/+yQaNbEKDyNVvXYqoqVKhF8KHLe+jIzdiEYYx4sND2WBX RRKdqQ+9d2IjIhrJ/7TXt0+/aMjf1LbV0WqAMwiIzuNiT2ufJZELIs6ynLN4T4KmWu58 WfUl0YJSBLajTDu4U4hzNEMUaHCwuLgAtFYpeuC0gYW9SL4hMoukjzOMrK4UzuyNg0Pu G0Ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=MQQqnLvB; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ce29si3368265edb.220.2020.11.11.21.47.34; Wed, 11 Nov 2020 21:47:57 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=MQQqnLvB; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725983AbgKLFp1 (ORCPT + 99 others); Thu, 12 Nov 2020 00:45:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725920AbgKLFoy (ORCPT ); Thu, 12 Nov 2020 00:44:54 -0500 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1FE4C0613D4 for ; Wed, 11 Nov 2020 21:44:53 -0800 (PST) Received: by mail-pf1-x444.google.com with SMTP id q10so3508396pfn.0 for ; Wed, 11 Nov 2020 21:44:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=8Wrc8fiOuZuXNhL9f/svgjNc/c8x+1+TBbfywF036g8=; b=MQQqnLvBftHCd1FuGxyTbfHb860FMPoBMVR7ahUHQ6DoMzCZaEHvpZeN9naV/pNTPH CFTIynWOxYXM/u33qSJktyfSyXPW5Oa1YazC9X8trfncnfskLZWO0UTTHUFTYBsgsUdb 5f5Cf9NyKGSgrLWHNSA7Vikldysgyna9lMTZR87mRxbQrqir9F5aIDJI/Ot5wcJ5bIQI Q3gkLhhKech6ErlAwks6gS7xMG2r/EHQdGCzFIvOx4CHqy1uViG71r7LGc+L1klxxLdf lc/u4616rx+YQawZro2amrTZkOEk+1l819822V/cCMtiESNNpcKofhwEY+nL8wkgVXSd 1VqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=8Wrc8fiOuZuXNhL9f/svgjNc/c8x+1+TBbfywF036g8=; b=kldrrd7lKBQsocHGQm/VT5t6R58FomPeM4Hkg1zpSQBD9h6nxiS6/1hs6qRiHVqEfL hk1YfsMEbf4VsPVgH24CK1JOZ6Vfk1JD26mASf4x2RJAIB8OAOfiNmiXsmYfG2RtGqyg WTeh/qCNEKhhklknJtkOiBGEtdYcULvN4nucDk1jtkuCcGlRin2YbDhADx7xN/GLiHV/ cm2N04cUyCd1hJu5sh0qGT/Uxk3YUM77egSDbtfqhwxSEHcRBWi+qT1nYoZtrkCERMGL Ge9pBWM1R9QscEfe0rvu1g3UoF5J26s+qlyXPIxIz8YSYpvvZcoN+hYNIkIVd3bQkOYh GTew== X-Gm-Message-State: AOAM531d94q9AbfV1Uu6ZOQxutBEWZnZvJ/IEQl0ELkiVIrdqoUCuQfQ AZ5YYd4lbmKiUl/Gir6/XX0= X-Received: by 2002:a62:19c6:0:b029:18b:5c6a:2ae6 with SMTP id 189-20020a6219c60000b029018b5c6a2ae6mr26055115pfz.14.1605159893469; Wed, 11 Nov 2020 21:44:53 -0800 (PST) Received: from ubuntu (42-73-56-209.emome-ip.hinet.net. [42.73.56.209]) by smtp.gmail.com with ESMTPSA id e8sm4622027pjr.30.2020.11.11.21.44.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Nov 2020 21:44:52 -0800 (PST) Date: Thu, 12 Nov 2020 13:44:45 +0800 From: Yun Hsiang To: Peter Zijlstra Cc: Dietmar Eggemann , linux-kernel@vger.kernel.org, qais.yousef@arm.com, patrick.bellasi@matbug.net, kernel test robot Subject: Re: [PATCH v5 1/1] sched/uclamp: add SCHED_FLAG_UTIL_CLAMP_RESET flag to reset uclamp Message-ID: <20201112054445.GA1257287@ubuntu> References: <20201103023756.1012088-1-hsiang023167@gmail.com> <20201110122108.GG2594@hirez.programming.kicks-ass.net> <20201111180441.GJ2628@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201111180441.GJ2628@hirez.programming.kicks-ass.net> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 11, 2020 at 07:04:41PM +0100, Peter Zijlstra wrote: > On Wed, Nov 11, 2020 at 06:41:07PM +0100, Dietmar Eggemann wrote: > > diff --git a/include/uapi/linux/sched/types.h b/include/uapi/linux/sched/types.h > > index c852153ddb0d..b9165f17dddc 100644 > > --- a/include/uapi/linux/sched/types.h > > +++ b/include/uapi/linux/sched/types.h > > @@ -115,8 +115,8 @@ struct sched_attr { > > __u64 sched_period; > > > > /* Utilization hints */ > > - __u32 sched_util_min; > > - __u32 sched_util_max; > > + __s32 sched_util_min; > > + __s32 sched_util_max; > > So that's UAPI, not sure we can change the type here. +1 I am also concerned about changing UAPI. But if we can chage sched_util_{min/max} to __s32, use -1 to reset is better than adding flags. > > > }; > > > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > > index 3dc415f58bd7..caaa2a8434b9 100644 > > --- a/kernel/sched/core.c > > +++ b/kernel/sched/core.c > > @@ -1413,17 +1413,24 @@ int sysctl_sched_uclamp_handler(struct ctl_table *table, int write, > > static int uclamp_validate(struct task_struct *p, > > const struct sched_attr *attr) > > { > > - unsigned int lower_bound = p->uclamp_req[UCLAMP_MIN].value; > > - unsigned int upper_bound = p->uclamp_req[UCLAMP_MAX].value; > > + int util_min = p->uclamp_req[UCLAMP_MIN].value; > > + int util_max = p->uclamp_req[UCLAMP_MAX].value; > > > > - if (attr->sched_flags & SCHED_FLAG_UTIL_CLAMP_MIN) > > - lower_bound = attr->sched_util_min; > > - if (attr->sched_flags & SCHED_FLAG_UTIL_CLAMP_MAX) > > - upper_bound = attr->sched_util_max; > > + if (attr->sched_flags & SCHED_FLAG_UTIL_CLAMP_MIN) { > > + util_min = attr->sched_util_min; > > > > - if (lower_bound > upper_bound) > > - return -EINVAL; > > - if (upper_bound > SCHED_CAPACITY_SCALE) > > + if (util_min < -1 || util_min > SCHED_CAPACITY_SCALE) > > + return -EINVAL; > > + } > > + > > + if (attr->sched_flags & SCHED_FLAG_UTIL_CLAMP_MAX) { > > + util_max = attr->sched_util_max; > > + > > + if (util_max < -1 || util_max > SCHED_CAPACITY_SCALE) > > + return -EINVAL; > > + } > > Luckily we can write that range as a single branch like: > > if (util_{min,max} + 1 > SCHED_CAPACITY_SCALE+1) > > which assumes u32 :-) > > > + > > + if (util_min != -1 && util_max != -1 && util_min > util_max) > > return -EINVAL; > > I think that will compile as is, otherwise write it like ~0u, which is > the same bit pattern. >