Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp219729ybe; Sun, 1 Sep 2019 23:57:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqznjjf41AFSd2YlzhmF5s3K6tFX9D1/qqD+zotiqIk3uLTmNSCn0FUv+4Bpa8uuiGLYENA8 X-Received: by 2002:a17:902:2be6:: with SMTP id l93mr28930165plb.0.1567407468377; Sun, 01 Sep 2019 23:57:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567407468; cv=none; d=google.com; s=arc-20160816; b=aMQv+DOau33XUgSp2sIIGQFOSZdwZKOBjHyljXwDPXwUoVUQ8BdzHtfBGJPofUfrbL vhyc+zunIYvbaRUHtPBu57AiTNDHEgPPTlrh//vUn7QwdvN5fKurldjGhLyh1siCeT0y t3QYh8e5Z1f3it3lr21O5724K254VCzPcrSloCa9REAOeFLSJZJMlT70YXP1EWIeFirb H+zAFD8jLEWen2i3rEXPWxD/Xl9IAGGl6MLfb/Su1VMkbL8IHPo5LVXqwzag8PrJLeGR 07kvR8H3c2x0Syu41vLm57+sVTGLgYKwO/POGTMc40MCzhy1TIRVZciyUrBZJxQbvRTo YFRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:date:in-reply-to:message-id :subject:cc:to:from:user-agent:references; bh=cao6gJ+P4+CY4WEI8wusd6MHC/sp7pLCUt0DCW7jkZE=; b=zCH+4PCDHuEqBFPE2U0Y8eholOI6u1KKFHiBpOWSR4udzKx/cpXwklGSQJ+QgbB6Qc NqSCzjAPXoWgh2Wdr/nTBY5UP3TIBjDPs+wf0CK0LRdTbQcpyvo1k8zxz1u60YyD42Dx fni+bg2FZw653/fc16vL2RTT5NWvkfp85ghvGmDD0miC+d+95AklwOuoQKG/tPtxt27f 8PKYR+a0buc43OSAIM1Lr4fpIWoMS6ylDJJyTN9eehZ2kfoVHY+zPOA7WHN6UeK2Eve1 +g4x2AVesLcbyppNkgIk1B++3tpcVZlzqAls1ERM9wAQXW7LvpwPr11/PfYF0zVrB814 ga9w== 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: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j4si10837023pgq.375.2019.09.01.23.57.31; Sun, 01 Sep 2019 23:57:48 -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; 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 S1729496AbfIBGlP (ORCPT + 99 others); Mon, 2 Sep 2019 02:41:15 -0400 Received: from foss.arm.com ([217.140.110.172]:48880 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726375AbfIBGlP (ORCPT ); Mon, 2 Sep 2019 02:41:15 -0400 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 05ADF337; Sun, 1 Sep 2019 23:41:14 -0700 (PDT) Received: from darkstar (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 088393F71A; Sun, 1 Sep 2019 23:43:05 -0700 (PDT) References: <20190822132811.31294-1-patrick.bellasi@arm.com> <20190822132811.31294-2-patrick.bellasi@arm.com> <20190830094505.GA2369@hirez.programming.kicks-ass.net> User-agent: mu4e 1.3.3; emacs 25.3.1 From: Patrick Bellasi To: Peter Zijlstra Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, linux-api@vger.kernel.org, cgroups@vger.kernel.org, Ingo Molnar , Tejun Heo , "Rafael J . Wysocki" , Vincent Guittot , Viresh Kumar , Paul Turner , Michal Koutny , Quentin Perret , Dietmar Eggemann , Morten Rasmussen , Juri Lelli , Todd Kjos , Joel Fernandes , Steve Muckle , Suren Baghdasaryan , Alessio Balsini Subject: Re: [PATCH v14 1/6] sched/core: uclamp: Extend CPU's cgroup controller Message-ID: <87zhjnnqz2.fsf@arm.com> In-reply-to: <20190830094505.GA2369@hirez.programming.kicks-ass.net> Date: Mon, 02 Sep 2019 07:38:53 +0100 MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 30, 2019 at 09:45:05 +0000, Peter Zijlstra wrote... > On Thu, Aug 22, 2019 at 02:28:06PM +0100, Patrick Bellasi wrote: >> +#define _POW10(exp) ((unsigned int)1e##exp) >> +#define POW10(exp) _POW10(exp) > > What is this magic? You're forcing a float literal into an integer. > Surely that deserves a comment! Yes, I'm introducing the two constants: UCLAMP_PERCENT_SHIFT, UCLAMP_PERCENT_SCALE similar to what we have for CAPACITY. Moreover, I need both 100*100 (for the scale) and 100 further down in the code for the: percent = div_u64_rem(percent, POW10(UCLAMP_PERCENT_SHIFT), &rem); used in cpu_uclamp_print(). That's why adding a compile time support to compute a 10^N is useful. C provides the "1eN" literal, I just convert it to integer and to do that at compile time I need a two level macros. What if I add this comment just above the macro definitions: /* * Integer 10^N with a given N exponent by casting to integer the literal "1eN" * C expression. Since there is no way to convert a macro argument (N) into a * character constant, use two levels of macros. */ is this clear enough? > >> +struct uclamp_request { >> +#define UCLAMP_PERCENT_SHIFT 2 >> +#define UCLAMP_PERCENT_SCALE (100 * POW10(UCLAMP_PERCENT_SHIFT)) >> + s64 percent; >> + u64 util; >> + int ret; >> +}; >> + >> +static inline struct uclamp_request >> +capacity_from_percent(char *buf) >> +{ >> + struct uclamp_request req = { >> + .percent = UCLAMP_PERCENT_SCALE, >> + .util = SCHED_CAPACITY_SCALE, >> + .ret = 0, >> + }; >> + >> + buf = strim(buf); >> + if (strncmp("max", buf, 4)) { > > That is either a bug, and you meant to write: strncmp(buf, "max", 3), > or it is not, and then you could've written: strcmp(buf, "max") I don't think it's a bug. The usage of 4 is intentional, to force a '\0' check while using strncmp(). Otherwise, strncmp(buf, "max", 3) would accept also strings starting by "max", which we don't want. > But as written it doesn't make sense. The code is safe but I agree that strcmp() does just the same and it does not generate confusion. That's actually a pretty good example on how it's not always better to use strncmp() instead of strcmp(). Cheers, Patrick