Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp1890026ybm; Thu, 23 May 2019 08:12:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqwmIVQCbm3QHwsjCouOJyW5NqF/GmOkS4t2N5S8aqJJha+UO5c7T9tMmbpYcrlipyrDPkGp X-Received: by 2002:a17:902:9f83:: with SMTP id g3mr83144956plq.330.1558624360828; Thu, 23 May 2019 08:12:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558624360; cv=none; d=google.com; s=arc-20160816; b=Igp3OQT9PO9RzBdNKLNPvfYsxLKmK6u1sxPvdKxHnVdCMuWzvAX3C93iYqveKUSOFq AsgBhDAAfZ86XuAptUTtewhaUfejFIUlMMg4sEHHfa9LtNxU0coy5phHVbwZGC9DEvIc rrf21IgK65PgN2FZNppCLNfLfQIj4JANB1tNkW4w5XamdaMvH0dgqBiZQDCWoQqq49nJ Xc7WXi9TZ70PFMf7eCYpxc0CNUKq550U61upYG7+BkeOI0WnMuBiQCZp31aeZ5nej7to LUVjfKRwhF5LdpFjt0rB59z2KzT4nq+zA2CINKf8OvH2h5rCkrstxSxnoEeQvf5cdq2K 80iw== 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=+XRLAU6oU5E0/8gW3lY2rtdeODZlzcPWAFZA13HWTCU=; b=atDv0ngl9frfr+PaPYW6q5fRXQAitzGMY8q94VQV01L92bCKU6+JaVC/Mlf6n6hKbP RNliBtDVoIwJxsHno15kfDVZBIVs2vcdCWxz0kXXti8+8I/vlPwCaKYuAPFBQMKNb/dX 3MgKNlJmyauxYys0ialQ6Zf3d+701+/W+T+khclA/kp7URHxnd25CmoqqOka3rN1A2rh D9vWOnEbGLBPfWRhoTqh6DHfMJN2A+tXLuBeCntpVCf2iE9qTUKwRQfB+Vo6c5nzC9Di 5svH38vnyOCfa9TXRVUPluVc97x7zbCZoNSO2UtmV+iR0iqpAi+KZBnGL7kd6NovDdJS dCYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=A87Rf4qG; 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 v11si30952077pgi.568.2019.05.23.08.12.24; Thu, 23 May 2019 08:12:40 -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=A87Rf4qG; 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 S1731060AbfEWPLF (ORCPT + 99 others); Thu, 23 May 2019 11:11:05 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:34292 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731009AbfEWPLE (ORCPT ); Thu, 23 May 2019 11:11:04 -0400 Received: by mail-lj1-f195.google.com with SMTP id j24so5839122ljg.1 for ; Thu, 23 May 2019 08:11:02 -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=+XRLAU6oU5E0/8gW3lY2rtdeODZlzcPWAFZA13HWTCU=; b=A87Rf4qG4wn9ePdBXWK4S6A+i4fN/l2BHBriTyA/NV7md909J0ajFqoql7nafgIWFX zNeMu8SMtxpeDziW/96Gcai5LoSeFlFor/iwm8XXRysAwkMkqUmZRyYrQAC88L1pZlXU ZQKZDUd8/qaGGjTkJPmRfmYpeswXlH3T1V2Y0= 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=+XRLAU6oU5E0/8gW3lY2rtdeODZlzcPWAFZA13HWTCU=; b=g1ME4vproLsJAGQu+m18+6QerInQxw6i62wRMGAxjdfpHYnPNIjZ1eSCGjP+BrCQaD mYTE56amW10zuQ4j/pFUnLD8vw19IqhuNWH9IwJhS0bg2ByWswADovApBIkra0GUdRX2 Al3UFGMviB/C4dZ2N0O8gZ8zuEM5t+LonCgLO832F087EUVmNVGblrEhZO7pFXVChPl4 ngnzjmCS9EY1RNvtFw38g7hz1gj/aqipIFNf8AsREfK+PYBKDXatc24953RDANnLDfLA dBvjExjOTNrDhGmFXFqDdG2ek7kNdQbfgjuE+kPRw2zEcxC4Ic4/3S14sAPOukZe/t4z t8Tg== X-Gm-Message-State: APjAAAUvE1JW5UgQFbF6moMVApNwMj2bb7PK0HlpsA8nu9ALomS09e1V sRhAlGfY6biQ/nXpdB26xHC4NRbNK5c= X-Received: by 2002:a2e:9d09:: with SMTP id t9mr16250773lji.151.1558624261471; Thu, 23 May 2019 08:11:01 -0700 (PDT) Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com. [209.85.208.174]) by smtp.gmail.com with ESMTPSA id n10sm251492lfk.39.2019.05.23.08.11.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 May 2019 08:11:00 -0700 (PDT) Received: by mail-lj1-f174.google.com with SMTP id e13so5792457ljl.11 for ; Thu, 23 May 2019 08:11:00 -0700 (PDT) X-Received: by 2002:a2e:9b0c:: with SMTP id u12mr18999482lji.189.1558624260065; Thu, 23 May 2019 08:11:00 -0700 (PDT) MIME-Version: 1.0 References: <20190523100013.52a8d2a6@gandalf.local.home> In-Reply-To: <20190523100013.52a8d2a6@gandalf.local.home> From: Linus Torvalds Date: Thu, 23 May 2019 08:10:44 -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 7:00 AM Steven Rostedt wrote: > > +# define roundup_64(x, y) ( \ > +{ \ > + typeof(y) __y = y; \ > + typeof(x) __x = (x) + (__y - 1); \ > + do_div(__x, __y); \ > + __x * __y; \ > +} \ The thing about this is that it absolutely sucks for power-of-two arguments. The regular roundup() that uses division has the compiler at least optimize them to shifts - at least for constant cases. But do_div() is meant for "we already know it's not a power of two", and the compiler doesn't have any understanding of the internals. And it looks to me like the use case you want this for is very much probably a power of two. In which case division is all kinds of just stupid. And we already have a power-of-two round up function that works on u64. It's called "round_up()". I wish we had a better visual warning about the differences between "round_up()" (limited to powers-of-two, but efficient, and works with any size) and "roundup()" (generic, potentially horribly slow, and doesn't work for 64-bit on 32-bit). Side note: "round_up()" has the problem that it uses "x" twice. End result: somebody should look at this, but I really don't like the "force division" case that is likely horribly slow and nasty. Linus