Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp2016471ybm; Thu, 23 May 2019 10:02:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqyUg8izW2h/jFeCnF3lTxRjgsfWjc5YIMSx+lj9jdGWH50L2ARxGfRKYJGiSs5MR6XytgYi X-Received: by 2002:a17:902:5983:: with SMTP id p3mr97149679pli.224.1558630927031; Thu, 23 May 2019 10:02:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558630927; cv=none; d=google.com; s=arc-20160816; b=jeI1EDQtqio2y2mYDWsdhAYV2vi+Y1Tor8O2TJhySlsjxS2XDu6xKksG+ZRUbfkJb2 tDRCM+rSaqfqpmLKrMfw8CD9VUlX5CFgA7u3/A1ODX+Ae6cQ9IUulsakdA0TaXmiUWc5 AmPlPVDmysgCuNbQ5AdUa+JyNZ1unJPbrt/CE1890vQ9sdvsIOlNVj+drFIurpyirw00 NTM7II7k4uWMLuWSsV2YuJdj4L/tH11RFTcMz8a8MJDD5ChttfaD7iMpq4FPfPO0Smm3 JV9vfMKaZXrsriMbwF557XoRIes942ldll88WErh77JqGcqkcipt4QFSvXGmZAW7SfMW oW/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=ks/LH2oyTEaijoOzEMOK4qT05od1mgbLgD6IvZvC3ac=; b=O81AoHKNNGwFefcxFiZsxhlafLRXKzbvOWRiHXmavFnC6zs7qoV/HZirJD8sj+yMYQ fy5MAt4fTbVsJNW+8eiIiCu7sgUh/Amp0Uhj9vNpaEMrBnz/zPkUD7q5CMTdNcjNzG76 d7bIq6onFCyhiPBk46NzcS5/82UHEWo7leC4HHB5aoUeSE7TFpwLp2IqaP5uSXSgIiSw Dwa7o7iVUfakifkLOxqJGHUCyOKUsDQJdFJaqMR9GDIuLDbQnD9dvBlYHqX0joUXrtlk gXI6VNkBzUju9kmW2z/R1Ai1whC9FRsCYq5KjlAhlh6YzlTfoKDvikWgRjKYED9SPeY2 NotA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=UrcFcbzE; 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 z19si20937pgi.180.2019.05.23.10.01.51; Thu, 23 May 2019 10:02:07 -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; dkim=pass header.i=@linux-foundation.org header.s=google header.b=UrcFcbzE; 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 S1731119AbfEWQ7g (ORCPT + 99 others); Thu, 23 May 2019 12:59:36 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:41276 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730867AbfEWQ7g (ORCPT ); Thu, 23 May 2019 12:59:36 -0400 Received: by mail-lj1-f196.google.com with SMTP id q16so6147835ljj.8 for ; Thu, 23 May 2019 09:59:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ks/LH2oyTEaijoOzEMOK4qT05od1mgbLgD6IvZvC3ac=; b=UrcFcbzEFPGggz1NPXakVDUiIg5mDqTO4045eBb7udfHenM+Veb+rBZ0tlbryVNdJc qa5A4P3tgF5XCLb7D69n65wDt2yEO3fr0UKE7SehnvIvMriAPEG9xpGYM5u8gpQLeOdX 1vpQBx74HKkfDoRasFV6IFoGOt3sYNk7jzZac= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ks/LH2oyTEaijoOzEMOK4qT05od1mgbLgD6IvZvC3ac=; b=NVtm6kZZv24dG/jWhH8SXxeDU2JFpBBWdVwcCdvQEF5T5UWns/JtYAHOfjx8wpbdw4 +bpxxAc4Qfbc8MND/rUEIzJ/x5nuPe1EPHBOMx5PQZjBalsjNHFEYiIudcebiSyWeUat RAu425XX32jQVTkoPDQYyobs16uzydNxp5r3xRYXXJVO9Wx7yb6ycetjlT/EbCrMtOsG HiCYFg93d8UvNl7kSnJ8M3MM1l3GIu3znoqPPVEd515AhP6PyhO8352CYdyi9nEOwejl L52xYWTT8dJGrJO36NcARAbuCT8/c9xu6CRfcog/sACLUrBe1MutFqoeecuaCzL58ZdY cwfg== X-Gm-Message-State: APjAAAXlY6oTYB0vDEj95laEyVMgrgefDFkI+UG8aXmz3MTyv7KWFU5O X//25wRghmvy2g3CE0dsrDWA4FD6sjk= X-Received: by 2002:a2e:8954:: with SMTP id b20mr3865040ljk.10.1558630307848; Thu, 23 May 2019 09:51:47 -0700 (PDT) Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com. [209.85.167.50]) by smtp.gmail.com with ESMTPSA id d195sm15396lfd.10.2019.05.23.09.51.46 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 May 2019 09:51:46 -0700 (PDT) Received: by mail-lf1-f50.google.com with SMTP id n22so4896442lfe.12 for ; Thu, 23 May 2019 09:51:46 -0700 (PDT) X-Received: by 2002:a19:7d42:: with SMTP id y63mr41221787lfc.54.1558630305849; Thu, 23 May 2019 09:51:45 -0700 (PDT) MIME-Version: 1.0 References: <20190523100013.52a8d2a6@gandalf.local.home> <20190523112740.7167aba4@gandalf.local.home> In-Reply-To: <20190523112740.7167aba4@gandalf.local.home> From: Linus Torvalds Date: Thu, 23 May 2019 09:51:29 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC][PATCH] kernel.h: Add generic roundup_64() macro To: Steven Rostedt 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 Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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 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. 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.. Linus