Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1584775pxb; Wed, 20 Oct 2021 07:57:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx82z3AeETva5waU2+btcK7U4MlPo/mqLBdFYk64IBi4l2Zq5Wrm+ZBCao4hDUiixxe5o+Y X-Received: by 2002:a17:906:4793:: with SMTP id cw19mr103034ejc.200.1634741856543; Wed, 20 Oct 2021 07:57:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634741856; cv=none; d=google.com; s=arc-20160816; b=jq/YDDxzYaBWI06m0ZVxmvkS/Dmq4FlwQI5DZKNZYzCU2GUaOmkFRpsiFq5hksAlGa 8K7F2ycBZB98RdLWTVDdGvp6G4uOXGe74GjoZjsJ5t8KnnATViGprSow+PzEA4meiZ6t lZ+HwxfWVTotalTxRHuYyhjYdK0/fA5Wvr3Yp4fWFzJZwkbKLJXPrE+6Jdr4Hy6bGeYI 3GkyOAnW8x6CA3rxJEAthYuXWCKcTMZRG9dwwo419zd/7T7W7/QLTmaLMWRK6leR2Qwh Y0d1URSHDTQkMcILy0Kfgj5viiQBTBqpUbcd0jrHAOAs/jV2rksnRRJwk6uQlH8+LPv/ 2GDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=2NT+VI0Pymfgi6KrPfEOh2aqPixHFbwmQSZYnbq0Cs8=; b=ZBbBcGQw2iNVSpDY2jkmvPBPg7Axrfs9LyGuSw3VbEcpGZtEkAP1WoOUnUTFdhXMs1 pFomOYxMoKPoc0PYjDrtGdXesWilKlyHZChuRXXFL+OPznbXeX9OZLxqLsyYNoOtXbCZ Z4nqEt98/1J7eWDqBvm6bXV1d59Qh4YCW0gg6zuN3X6ZWXyFAJntO7F64FFCxOI9gO9E HsqWE4yeW6zUmyDWX2ItPvWHPjv9i25Q5aMeCxhl+8n+/E1EgxL+U91qkH7iLC1q0TC5 nRqKjjcafJomxSJXqszSlmBGM3eDVY8+5XREO8hiOtLDqlEDGJVidZAgFbjLPsWhzba1 nctg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=VgKpw9rB; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u15si3821765edt.211.2021.10.20.07.57.08; Wed, 20 Oct 2021 07:57:36 -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; dkim=pass header.i=@google.com header.s=20210112 header.b=VgKpw9rB; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230089AbhJTO5a (ORCPT + 99 others); Wed, 20 Oct 2021 10:57:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230072AbhJTO5Z (ORCPT ); Wed, 20 Oct 2021 10:57:25 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4A08C061749 for ; Wed, 20 Oct 2021 07:55:10 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id s61-20020a17090a69c300b0019f663cfcd1so711636pjj.1 for ; Wed, 20 Oct 2021 07:55:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=2NT+VI0Pymfgi6KrPfEOh2aqPixHFbwmQSZYnbq0Cs8=; b=VgKpw9rBhIl9RgSTHOjvXPIBuB/3bKcIuicn3KbBJkWLJC9PScz/RQOUPKGAs2+Wf8 Lmtc88UjoeFw2ZjzncYMNMq62hYATOHb9LamR82sNaVY6GWzAy4lCsslUBQWmONdEIp/ um/E6qs9qGGSa55H8O5DjF4uSrQO8aGK4bxZOAqzO/QjnezVR0TDwKJ5qWq+CwSyFnuo qkg5qkl1ezQ0tW/XgDQnlouKgBz+uMIKnk4nNV6uMrA6AdMKI321FUFlufT4R5IU0LED xu2e61fNfS0wc6F0mGrAgYrISF4LHyvQmIbpAqIjNBo9gaxwPSnXpYXH9oqzKHyg+eJ4 mEjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=2NT+VI0Pymfgi6KrPfEOh2aqPixHFbwmQSZYnbq0Cs8=; b=4pBUz3rqG/0McipT0jtCjJ8cHFukQn1lYPGjSxwPtrP3zMRi1csno1UmribocdF5Fl kFndYrXAqZK0jh6iev0BRYSXKLtoOXoyWsF7Fta2RV95ilhHn6b4UZp6IPHzhYaCzbW7 KGmUEH6UfFQ7fQQUvFT/jQxrNZBq9adX1vbz2qlOLM5hGOiGv2RHyziumNDhkuT7pJ7y 4xPwtUIp+/CEC28ActPOJzanVlDdzMVp0BB4IGq2y9HEMlQm7ZdR0xo7CXqxKBdi/ILm 50M30XQxvc+AZavuQNpV48Kw6EBpQiU9b7X212C/cYLJVdv9FT7hVJ2+24qk7pkjK2ed JO+A== X-Gm-Message-State: AOAM533Eofuh6XNsXQrVE7+zz9ehMG8VpxaEHels0oFP/KThliihChw8 lYVu25KOsAZAKjLaqHJ4VufA43Z9XEcRDjRrivz7lg== X-Received: by 2002:a17:903:18d:b0:13f:ada:9df4 with SMTP id z13-20020a170903018d00b0013f0ada9df4mr39582515plg.69.1634741710041; Wed, 20 Oct 2021 07:55:10 -0700 (PDT) MIME-Version: 1.0 References: <20211020013153.4106001-1-kaleshsingh@google.com> <20211020013153.4106001-3-kaleshsingh@google.com> <20211019222756.1fde436b@gandalf.local.home> In-Reply-To: <20211019222756.1fde436b@gandalf.local.home> From: Kalesh Singh Date: Wed, 20 Oct 2021 07:54:59 -0700 Message-ID: Subject: Re: [PATCH v2 2/5] tracing: Add division and multiplication support for hist triggers To: Steven Rostedt Cc: Suren Baghdasaryan , Hridya Valsaraju , Namhyung Kim , "Cc: Android Kernel" , Jonathan Corbet , Ingo Molnar , Shuah Khan , Masami Hiramatsu , Tom Zanussi , "open list:DOCUMENTATION" , LKML , "open list:KERNEL SELFTEST FRAMEWORK" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 19, 2021 at 7:28 PM Steven Rostedt wrote: > > On Tue, 19 Oct 2021 18:31:39 -0700 > Kalesh Singh wrote: > > > +static u64 hist_field_div(struct hist_field *hist_field, > > + struct tracing_map_elt *elt, > > + struct trace_buffer *buffer, > > + struct ring_buffer_event *rbe, > > + void *event) > > +{ > > + struct hist_field *operand1 = hist_field->operands[0]; > > + struct hist_field *operand2 = hist_field->operands[1]; > > + > > + u64 val1 = operand1->fn(operand1, elt, buffer, rbe, event); > > + u64 val2 = operand2->fn(operand2, elt, buffer, rbe, event); > > + > > + /* Return -1 for the undefined case */ > > + if (!val2) > > + return -1; > > + > > + return div64_u64(val1, val2); > > +} > > + > > I wonder if you should add a shift operator as well? > > I mean, if for some reason you want to divide by a power of two, then why > us the division. Especially if this is on a 32 bit machine. > > Of course, the parsing could detect that. If the divisor is a constant. Or > we could even optimize the above with: > > if (!val2) > return -1; > > if (!(val2 & (val2 - 1)) > return val1 >> __ffs64(val2); > > Which should be faster than a divide, and even if it isn't a power of two, > the subtract and & should be in the noise compared to the divide. > > Note, the above can be added to this. I'm not suggesting changing this > patch. Is it worth adding something like this for the multiplication case as well? - Kalesh > > -- Steve