Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2212761pxb; Thu, 28 Oct 2021 19:02:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTaqoFppnIg1DtOEZ1NLG4Mdz5CMdVIsr9qv7q4NMfaVcPWd2ogo54knowH04U9jLmsPVd X-Received: by 2002:a05:6a00:150d:b0:47c:1d28:4ef5 with SMTP id q13-20020a056a00150d00b0047c1d284ef5mr7951244pfu.6.1635472968223; Thu, 28 Oct 2021 19:02:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635472968; cv=none; d=google.com; s=arc-20160816; b=BaPGEdhCFa+WqJCH1KWNQ5hMFvQumEwo2RbcUbbE7MU8KGWzh5Pw9gv7FKrtAVledM ROw47L9fNiEoeAZ2i2Q+h98xucztxFW6oTh/8Wn6Dvcd/hvpDR1ZYRj7SXdCMVj4tXIk ct+M87iX/cgdhcwkRSO4pzE4u2ME7Y0UqIsgHHSA0jrzpfSCXQyuiGonKN1a+sa7FofT QKKKA6XXmGHkxOBR6BXP+G6BLF/yZIThXoRo+1gDHCWkfHw8b0c0Y1h4MNh2gSY7RbN+ JM8gSwsGy4/UorV+HC/4HYAqdeCOa43i7TNXHNPR9R6S47SsEHuwJxGF3S9AcCYjStP0 xhKw== 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=tL9kJ+Wdab1kFdHA7bwHnT54SW4o7NJeWm9+pWtVIfI=; b=RcsP7RAXD73BHWU3VKTcX/AO6h/L1x9f8RA057fWolDvamYnLOl+Q2JfsN+RPbtqiq mKcItTCWRvKKQha6OfTGKUyX7D+Q7XTW6v6gtzPwDPuPsk/XE9fBcggPIqWGd2yq8U5c Pqj9wI/YjfrFhJXm30DSgaVz3uSoEU7Z9+tFVyE6/OdqpIm5s5V2GZwfYaSkA2eD8FOm 5+fwLOv8wS2dVfJD9kHzoqLknRWYDnyPQWYVzjBcJCv4lkRRqHYue2Ubyw4vmlje7bKG zEZ/fgTer8BnOkyXZzWlNadnX32sYiqrtaifYvGBpW9HOmYd6SFcajAO0+I9KmeLSEmx fPAw== 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 d184si6032852pgc.536.2021.10.28.19.02.34; Thu, 28 Oct 2021 19:02:48 -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 S231448AbhJ2CEG (ORCPT + 99 others); Thu, 28 Oct 2021 22:04:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:37570 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229950AbhJ2CEE (ORCPT ); Thu, 28 Oct 2021 22:04:04 -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 3550460C40; Fri, 29 Oct 2021 02:01:36 +0000 (UTC) Date: Thu, 28 Oct 2021 22:01:34 -0400 From: Steven Rostedt To: Kalesh Singh Cc: surenb@google.com, hridya@google.com, namhyung@kernel.org, kernel-team@android.com, mhiramat@kernel.org, zanussi@kernel.org, Ingo Molnar , linux-kernel@vger.kernel.org Subject: Re: [PATCH] tracing/histogram: Optimize division by constants Message-ID: <20211028220134.23e2d840@rorschach.local.home> In-Reply-To: <20211028032854.2458440-1-kaleshsingh@google.com> References: <20211028032854.2458440-1-kaleshsingh@google.com> 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 Wed, 27 Oct 2021 20:28:54 -0700 Kalesh Singh wrote: > +/* > + * Returns the specific division function to use if the divisor > + * is constant. This avoids extra branches when the trigger is hit. > + */ > +static hist_field_fn_t hist_field_get_div_fn(struct hist_field *divisor) > +{ > + u64 div; > + > + if (divisor->flags & HIST_FIELD_FL_VAR_REF) { > + struct hist_field *var; > + > + var = find_var_field(divisor->var.hist_data, divisor->name); > + div = var->constant; > + } else > + div = divisor->constant; > + > + if (!div) > + return div_by_zero; Do we really need a div_by_zero constant function? What about just erroring here and perhaps return -EDOM? -- Steve > + > + if (!(div & (div - 1))) > + return div_by_power_of_two; > + > + /* If the divisor is too large, do a regular division */ > + if (div > (1 << HIST_DIV_SHIFT)) > + return div_by_not_power_of_two; > + > + divisor->div_multiplier = div64_u64((u64)(1 << HIST_DIV_SHIFT), div); > + return div_by_mult_and_shift; > +} > +