Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp594078pxb; Wed, 27 Oct 2021 08:41:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwxl2mY2KCHjSvwMM+j1X2Xe/mxsGIHAlIcA01AEOWqHruyJBoNEEJ2KKhzKL0HPo1mNbol X-Received: by 2002:a17:90a:bb12:: with SMTP id u18mr6627025pjr.44.1635349316895; Wed, 27 Oct 2021 08:41:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635349316; cv=none; d=google.com; s=arc-20160816; b=jACNkd8gfnFwXZlWrfTJmRICeTuP8tz5vX9xov5C+QgVaqTWO9+4z+Cve1HlQF8/Ux 3nerqX5JqMTNhZgWZEa7yjDFCVCoCVCJdi8mnqt2yecDmQKo6vzkTHF/8pgi1+1re1SH sIMfawz1ADGgFGEgWi70XK84xjHjTKdo88CAYC0fiwX8X2DuYIEtONk6QAAWjcPQ5q2k H/JKW+GSLa6ChMVwmVx8Gp8iBcVgP51BpAqdLKK3KHsHBDyGKmcZPN1bPs9KaQvgbQSM e1eVZpdEOIQd7fRWY8gU/owDzr/bDqo7UKR9j90jKH1rnU2X50qtHlk9e3ZocapWZTrD fe+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=VtP2hWPxiqRH+hYgKYjr2SMCody0mSAxZP2Px2vEx3M=; b=TreHck42zgJvWQ4XxKvVQr7ITRPW/VndlsCraEknapZdUu3YqnfLV+Lu8gGndg5JjD P0T/h4sMXZTdrrAeyd/hUtt80h7UcpNO5E7KjeETcL0d4qF/dJVOoyGvwsBxzVHlvkV/ 88nwBPipAmR0yhr2mcLzF4Xb5ZbY2a4xz+Ly7wcjU9fpmwQbIKVQ57M99M0Hp/BRnXZm uyGwWC5csvjlMUtJv8mQ6F+XmsM8lzdobh/WEkssY3EdEUBVmbjDa2s3p/YbYP4g7dbJ FaO3QzQhrUANQkkBNNvdwUMBz+rwKsfcFjtiYIDOupd6fRDQCNfOKjvruH1aR3xbw0no Dy0w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d28si340574pgb.511.2021.10.27.08.41.13; Wed, 27 Oct 2021 08:41:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237782AbhJ0CXw (ORCPT + 99 others); Tue, 26 Oct 2021 22:23:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:54714 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230243AbhJ0CXv (ORCPT ); Tue, 26 Oct 2021 22:23:51 -0400 Received: from rorschach.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 66E42610CB; Wed, 27 Oct 2021 02:21:25 +0000 (UTC) Date: Tue, 26 Oct 2021 22:21:23 -0400 From: Steven Rostedt To: Kalesh Singh Cc: surenb@google.com, hridya@google.com, namhyung@kernel.org, kernel-team@android.com, Jonathan Corbet , Ingo Molnar , Shuah Khan , Masami Hiramatsu , Tom Zanussi , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH v4 6/8] tracing/histogram: Optimize division by a power of 2 Message-ID: <20211026222123.5e206fcf@rorschach.local.home> In-Reply-To: References: <20211025200852.3002369-1-kaleshsingh@google.com> <20211025200852.3002369-7-kaleshsingh@google.com> <20211026151451.7f3e09a4@gandalf.local.home> <20211026201846.08990d1d@rorschach.local.home> <20211026211511.403d76ca@rorschach.local.home> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 26 Oct 2021 18:31:21 -0700 Kalesh Singh wrote: > And IIUC max_div is an arbitrary value we decide on that's <= 2^shift? > Is there a rule of thumb for choosing this? The way I came up with the max was to figure out at what point is it no longer guaranteed to be accurate. That is, what number can make the mult/shift no longer match the division. If we have some number div that is not a power of two. At some point: (X * mult) >> shift != X / div Now I simply picked max = 1 << shift / (mult * div - (1 << shift)) Because that will always be within the precision of the actual number. But I believe we can make max bigger, but because that deals with truncation, it's not simple math. That is, the above X / div is truncated and not the real number. I'm sure there's an algorithm somewhere that can give as the real max. -- Steve