From owner-svn-src-head@freebsd.org Thu Apr 5 16:07:41 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 23332F900B5; Thu, 5 Apr 2018 16:07:41 +0000 (UTC) (envelope-from royger@gmail.com) Received: from mail-wm0-x235.google.com (mail-wm0-x235.google.com [IPv6:2a00:1450:400c:c09::235]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 8CADE83B98; Thu, 5 Apr 2018 16:07:40 +0000 (UTC) (envelope-from royger@gmail.com) Received: by mail-wm0-x235.google.com with SMTP id b127so7156184wmf.5; Thu, 05 Apr 2018 09:07:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=Z0b91rhCRGZ1zQOMu/vTjTE7YhkSU99B1x+iPm20ReU=; b=tI77K8KsvFgTS9MCWUUVV2uPFpa4d+qm+/MMrdXN3RQsUVi16O8d72hBWbzU+l80ij lpp9qrX6E3CPfwek/FQJFKysJvHPCUxYeZHkqD8yoYfErDZZIbd9tIOsny2N4n1BiwzO /buyQua1AvNh2MbhRWPbx8O5YyRr9QLKo87FoI/AdxMIgi7M9/oaSUNPoBpFGcH/Lnd0 uG5n8PDo7NRg0JDS3TTV0VCwk1C8ZFIc//EuqQZZnGQQgRtmY8jq7xOzy16DDeghTAeG BT4jYZuPP2JBSWl186XTZfQCakakMWPzjpawboto5qOEEYgerG73tF+zULPTD8EEvohu rZrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=Z0b91rhCRGZ1zQOMu/vTjTE7YhkSU99B1x+iPm20ReU=; b=UISoxshLgtTks60qNJ+/z6TXm4otzAKZUUvpfCtTkbxXJMYWjS4+UYe9OOD2gA0NdS IRZRLKY6nMpDTi1trWgP1/yYSzfmbiXpoaMPs8CIXHmrhvKp1AjBL812BNfZNxHmJj/d uv0gHmjp2vr3MRHfV2QZBIx1FCy+7jxCxuIXpi15rLSOfHbxWujG058pSnjRaYvbC8Qn K3acLTvys4vf0sy10tFVPKp/IFHgld1Rx0wFcLTmaD51btYQq9+aDIWIA27HHqb2emEt j9CKyjUYsKL70aK6GNhEEpVvxrMo2+kiBKBBnDHO9rluJVvtaZRAfWMfaZ3NeeSor/pk 2pfg== X-Gm-Message-State: ALQs6tBEPYqgbyVd/bDE31LiD+yHWuegwcrnonrszuKNJVY6m8wj0dnK HO+CVLuASBJuHnn/jQ7Ug+YhAA== X-Google-Smtp-Source: AIpwx49nJLP4KjsODhBvbPCZfzMBt7PFywSWZ8WT33mWPk38Qi4iMzNWxDKWE/L0SSeR1/i82NfkVA== X-Received: by 10.80.242.135 with SMTP id f7mr3485546edm.169.1522944459508; Thu, 05 Apr 2018 09:07:39 -0700 (PDT) Received: from localhost (default-46-102-197-194.interdsl.co.uk. [46.102.197.194]) by smtp.gmail.com with ESMTPSA id n21sm4387374eda.73.2018.04.05.09.07.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Apr 2018 09:07:38 -0700 (PDT) Sender: =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= Date: Thu, 5 Apr 2018 17:07:35 +0100 From: Roger Pau =?utf-8?B?TW9ubsOp?= To: Warner Losh Cc: Ian Lepore , src-committers , svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r332072 - head/sys/sys Message-ID: <20180405160735.wkpsqqiyoyh7ewuk@MacBook-Pro-de-Roger.local> References: <201804051431.w35EVtg4047897@repo.freebsd.org> <1522942377.49673.245.camel@freebsd.org> <20180405154619.q3blip266qa3z5ut@MacBook-Pro-de-Roger.local> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20180323 X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Apr 2018 16:07:41 -0000 On Thu, Apr 05, 2018 at 09:58:36AM -0600, Warner Losh wrote: > On Thu, Apr 5, 2018 at 9:46 AM, Roger Pau Monné wrote: > > > On Thu, Apr 05, 2018 at 09:32:57AM -0600, Ian Lepore wrote: > > > On Thu, 2018-04-05 at 14:31 +0000, Roger Pau Monné wrote: > > > > Author: royger > > > > Date: Thu Apr 5 14:31:54 2018 > > > > New Revision: 332072 > > > > URL: https://svnweb.freebsd.org/changeset/base/332072 > > > > > > > > Log: > > > > introduce GiB and MiB macros > > > > > > > > This macros convert from GiB or MiB into bytes. > > > > > > > > Sponsored by: Citrix Systems R&D > > > > > > > > Modified: > > > > head/sys/sys/param.h > > > > > > > > Modified: head/sys/sys/param.h > > > > ============================================================ > > ================== > > > > --- head/sys/sys/param.h Thu Apr 5 14:25:39 2018 (r332071) > > > > +++ head/sys/sys/param.h Thu Apr 5 14:31:54 2018 (r332072) > > > > @@ -362,4 +362,8 @@ __END_DECLS > > > > */ > > > > #define __PAST_END(array, offset) (((__typeof__(*(array)) > > *)(array))[offset]) > > > > > > > > +/* Unit conversion macros. */ > > > > +#define GiB(v) (v ## ULL << 30) > > > > +#define MiB(v) (v ## ULL << 20) > > > > + > > > > #endif /* _SYS_PARAM_H_ */ > > > > > > > > > > These names don't make it clear whether the conversion is bytes->GiB or > > > GiB->bytes. The names seem way too generic for a public namespace in a > > > file as heavily included behind your back as param.h is. > > > > > > Also, this completely reasonable usage won't work, likely with > > > confusing compile error messages: > > > > > > int bytes, gibytes; > > > ... > > > bytes = GiB(gibytes); > > > > I find those helpful for their specific usage. I could introduce > > static inline functions like: > > > > size_t gb_to_bytes(size_t)... > > > > But I assume this is also going to cause further discussion. > > > > Yea, traditional macro names would be "gibtob" and "btogib" but I didn't > just reply to bikeshed a name: > > But you don't need to specify a type, consider the current btodb macro: > #define btodb(bytes) /* calculates (bytes / DEV_BSIZE) > */ \ > (sizeof (bytes) > sizeof(long) \ > ? (daddr_t)((unsigned long long)(bytes) >> DEV_BSHIFT) \ > : (daddr_t)((unsigned long)(bytes) >> DEV_BSHIFT)) > > which shows how to do this in a macro, which is orthogonal to any name you > may choose. I can also bikeshed function vs macro :) I was just going to remove those from here and place them in the files where I use them, but I can also change them to: #define gibtob(gib) ((unsigned long long)(gib) << 30) #define mibtob(mib) ((unsigned long long)(mib) << 20) If it's not going to start a bikeshed. Thanks, Roger.