Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp2055384ybm; Thu, 23 May 2019 10:38:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqwcgIqJeYIjZjRPGcm+tE5wOWpAobheJqtGU4q0Ld+lidMTQys870UtBv2MCmZNRWoIc6Re X-Received: by 2002:a17:90a:af8e:: with SMTP id w14mr2963355pjq.89.1558633092146; Thu, 23 May 2019 10:38:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558633092; cv=none; d=google.com; s=arc-20160816; b=kk5f59jiM8Oo/uP4zmbtuVkxMQXnrR/SaBpezQX/sSKO5Ruq971KUmcLF3yIadcvHq a/QW6+hVhwrJPGRyENaW3TYctj6gAxopobqERYKKJhLXqrv1XpwzkJpmoIJAptedUieN 29IcHikR1hh9grOe5S9pu/4q8KaxLaoGiUejNhtCiPVN5OM0Cs2ikt880LtG2ZDC9xcA 3Nm+4MS6EWudX91l+Y1kW4Bov++n1IjA73tycCBi0xpuIMNoXoOz/ArDa1g3B3+x1yy3 cTTVQJDfo/A3Id674Y10Wh7k89hjAhALohZAIFw00RqrPENg8ezuTfE3mW66z5/cbD2P fz6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=b2dG1rhH40Y3UTiRXmuGolQ5KNbWy2aQfhuv+A329S4=; b=SmFpic+bPT1AKw6WKUB9ZRG+6BQsCgY6KqustZaHLbsAEGy2b8/QZdiJyR0IQ/hoUl YJZK25gmq7h5ndg8L8y5vYMVdzK1opx9u8agylBT6LqitzI+rriPGeHsRx5Oam8RdKKW WwOZHmekdnaqlDvNUsn506aNXkKUJGWecrFwAhA7/b/ocSFwJNEkMwWx/dAF4p4+L1+T 48GgShVaMO6NTqXE1QfuunFX7HNxXOZQM7j6NKnnvlHGag8wFBAAUrcY9dIoGfoGU+m/ Pdnzb3efsgJiFwzP4J/WJ+jcuSTH4J32JQIy3c5p0boB7+plT1WIWmRGCepC2dCt7LMe SUhA== 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 j1si5746024pfa.164.2019.05.23.10.37.56; Thu, 23 May 2019 10:38:12 -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 S1731264AbfEWRgw (ORCPT + 99 others); Thu, 23 May 2019 13:36:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:49626 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731037AbfEWRgw (ORCPT ); Thu, 23 May 2019 13:36:52 -0400 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 41C892133D; Thu, 23 May 2019 17:36:50 +0000 (UTC) Date: Thu, 23 May 2019 13:36:48 -0400 From: Steven Rostedt To: Linus Torvalds Cc: LKML , Ben Skeggs , David Airlie , Daniel Vetter , Leon Romanovsky , Doug Ledford , Jason Gunthorpe , "Darrick J. Wong" , linux-xfs@vger.kernel.org, dri-devel , nouveau@lists.freedesktop.org, linux-rdma , Andrew Morton Subject: Re: [RFC][PATCH] kernel.h: Add generic roundup_64() macro Message-ID: <20190523133648.591f9e78@gandalf.local.home> In-Reply-To: References: <20190523100013.52a8d2a6@gandalf.local.home> <20190523112740.7167aba4@gandalf.local.home> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 23 May 2019 09:51:29 -0700 Linus Torvalds wrote: > On Thu, May 23, 2019 at 8:27 AM Steven Rostedt wrote: > > > > I haven't yet tested this, but what about something like the following: > > So that at least handles the constant case that the normal "roundup()" > case also handles. > > At the same time, in the case you are talking about, I really do > suspect that we have a (non-constant) power of two, and that you > should have just used "round_up()" which works fine regardless of > size, and is always efficient. I think you are correct in this. act_size = roundup_64(attr->length, MLX5_SW_ICM_BLOCK_SIZE(dm_db->dev)); Where we have: #define MLX5_SW_ICM_BLOCK_SIZE(dev) (1 << MLX5_LOG_SW_ICM_BLOCK_SIZE(dev)) Which pretty much guarantees that it is a power of two. Thus, the real fix here is simply to s/roundup/round_up/ as you suggest. > > On a slight tangent.. Maybe we should have something like this: > > #define size_fn(x, prefix, ...) ({ \ > typeof(x) __ret; \ > switch (sizeof(x)) { \ > case 1: __ret = prefix##8(__VA_ARGS__); break; \ > case 2: __ret = prefix##16(__VA_ARGS__); break; \ > case 4: __ret = prefix##32(__VA_ARGS__); break; \ > case 8: __ret = prefix##64(__VA_ARGS__); break; \ > default: __ret = prefix##bad(__VA_ARGS__); \ > } __ret; }) > > #define type_fn(x, prefix, ...) ({ \ > typeof(x) __ret; \ > if ((typeof(x))-1 > 1) \ > __ret = size_fn(x, prefix##_u, __VA_ARGS__); \ > else \ > __ret = size_fn(x, prefix##_s, __VA_ARGS__); \ > __ret; }) > > which would allow typed integer functions like this. So you could do > something like > > #define round_up(x, y) size_fn(x, round_up_size, x, y) > > and then you define functions for round_up_size8/16/32/64 (and you You mean define functions for round_up_size_{u|s}8/16/32/64 > have toi declare - but not define - round_up_sizebad()). > > Of course, you probably want the usual "at least use 'int'" semantics, > in which case the "type" should be "(x)+0": > > #define round_up(x, y) size_fn((x)+0, round_up_size, x, y) > > and the 8-bit and 16-bit cases will never be used. I'm curious to what the advantage of that is? > > We have a lot of cases where we end up using "type overloading" by > size. The most explicit case is perhaps "get_user()" and "put_user()", > but this whole round_up thing is another example. > > Maybe we never really care about "char" and "short", and always want > just the "int-vs-long-vs-longlong"? That would make the cases simpler > (32 and 64). And maybe we never care about sign. But we could try to > have some unified helper model like the above.. It may be simpler and perhaps more robust if we keep the char and short cases. I'm fine with adding something like this for round_up(), but do we want to have a generic roundup_64() as well? I'm also thinking that we perhaps should test for power of two on roundup(): #define roundup(x, y) ( \ { \ typeof(y) __y = y; \ typeof(x) __x; \ \ if (__y & (__y - 1)) \ __x = round_up(x, __y); \ else \ __x = (((x) + (__y - 1)) / __y) * __y; \ __x; \ }) -- Steve