Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1654259pxb; Wed, 20 Oct 2021 09:13:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy67OZ7PzO037VN8Ql7N2Xh4F22sDsACTAH5af1FBmQXxN+F2BH7A9o6zl08T85xUH1cC6m X-Received: by 2002:a17:902:9b8d:b0:13e:b693:c23d with SMTP id y13-20020a1709029b8d00b0013eb693c23dmr408098plp.11.1634746395296; Wed, 20 Oct 2021 09:13:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634746395; cv=none; d=google.com; s=arc-20160816; b=Hugh4Snccniwu0QWeMi9ZKxTwIQbdvjJw+6E/F/ovZMsJixrgS3UmZFSLJBEsMXlNX T08HtFUlGFUiMGzWk9E0UNmjegPXkMZBHDqPFp1rHY7CasNVsbaBV2eBNnhQfHf2uVxG 8ViAsn8V9RziDb1pRNHeyTLkE/K/F919WZjRes4ra+YCoiTk8t1Ehgto25sDLvebo/C/ hVO1JpaaSW1AN95+Ec2EqBIs2tFcsxhYzueS7bvYXvmUh86rxVR3OpfLnA3wG/pj4RZQ 28ASAAfck+Fharl67iuqCTNLM57VC21fol2CCywRuiSDLQQ7Jse3GNW9XA04Sc9d0LBk jHAg== 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=ag+GDBPpay2LLVEOcsq5SOiTi6gV4/I9D3ibJJFrk1A=; b=RCL4bfs7T/5n6cY1Uwa5eB6BlmzDhw6iAudeseg1/Ykgs8Fnv+ehSQ4E6HOe5bBnIm 8uwHNCOPqhXE+obvqUqxxpxn9drsrPYuqYmBfQvqQCI+H4JDWqJdYk00CVgpgq6EtUVV jGTaAGUgV5/AVb1xdnT0CxywVLaBa8FkK3KXK/6C+gI7JACMDmU+Yp/r3uwfNz6ikd1g gQZH+/91acpE5MQp507tSswAmyGZfOFIRlSLTmDsZUIx14OR6aj7iozCcmUUyml7wDYV PpbQs8m3whddxg3TK9m3DlMlPl6E9kUxSthK7vDLKAFyyetFL0VcsEOiwSI9RitAHApb pKyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="UPvgsF/K"; 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 b7si3619152pgm.415.2021.10.20.09.12.53; Wed, 20 Oct 2021 09:13:15 -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="UPvgsF/K"; 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 S231297AbhJTQNz (ORCPT + 99 others); Wed, 20 Oct 2021 12:13:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231293AbhJTQNx (ORCPT ); Wed, 20 Oct 2021 12:13:53 -0400 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31465C06174E for ; Wed, 20 Oct 2021 09:11:39 -0700 (PDT) Received: by mail-pl1-x632.google.com with SMTP id v20so16475467plo.7 for ; Wed, 20 Oct 2021 09:11:39 -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=ag+GDBPpay2LLVEOcsq5SOiTi6gV4/I9D3ibJJFrk1A=; b=UPvgsF/KSmvVLsT058wiAnaMCJJnIK5jUpt/Vbdo/c3R5ZHZayk6RFGfriajB8akct 8rdsPUNMPNbNXCUU4KiauB4L9vrv+VgpELyMVKdtieIeGJCsBbZUCPkBQpubgwvmKG68 hkU/jFxrQ8FJ8TaybVmO3Ss01Bwo6pMD9cdBwgHbg6FO/GvnKJ9GdPGlvXnWr/yEHZxL /BNdki9qHTrm3+leXF7NMMH2b/ti/uB/B+LSk/hYBgO1Tl1tyLPafYBXbEP+OJ3WFmuN CusBF6lh00zHbGVA4Sn1x5vxSoUglZJ9CJlK+mctEz5pPjNU33HMMM5jdgG8pRvtpVYL p/JA== 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=ag+GDBPpay2LLVEOcsq5SOiTi6gV4/I9D3ibJJFrk1A=; b=ScEbjVEE3WeBu4y8xDFDNAOTwEjlWG4LdPZ3tCagCjXmTduEl3GmbbnQxFeEqjALj3 MtpcApxTlFzhJ8lGTZ9ha2Pod4G0feHhZ6/YquNQhMZQxDJ3hR6uIbaF4w7qRAhasFK1 raZ7la+JvIT7WzS7DkDJr5LFKapeI9PzLOzu2srNzPMX2D4iuG+YZTQA9tIZXv2nlHgV hWEgsjQFTcaceFCJNBhdqTKYwHpToZYPBQK1zsDtISLhKyPhIg6bs0pKyE5bcORyd8qJ xjHO38WmlO4lSRYCgI1FoaZQ5QqOqpSaIEcIZGDN9kaPOGpLR0xi4jYs9v6eU7TkRrXk pX0g== X-Gm-Message-State: AOAM533goZIZR351SnOjilEX4gt/AnHnMFCuFlHZu/Pozaz4V5wF7tIU k0+GyngzQvQZ9SMpe2rlmDO8iMZh1sxlapRXopyU3Q== X-Received: by 2002:a17:902:6ac4:b0:13f:52e1:8840 with SMTP id i4-20020a1709026ac400b0013f52e18840mr2577plt.15.1634746298265; Wed, 20 Oct 2021 09:11:38 -0700 (PDT) MIME-Version: 1.0 References: <20211020013153.4106001-1-kaleshsingh@google.com> <20211020013153.4106001-4-kaleshsingh@google.com> <20211020114805.3fbb7d94@gandalf.local.home> In-Reply-To: <20211020114805.3fbb7d94@gandalf.local.home> From: Kalesh Singh Date: Wed, 20 Oct 2021 09:11:27 -0700 Message-ID: Subject: Re: [PATCH v2 3/5] tracing: Fix operator precedence for hist triggers expression 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 Wed, Oct 20, 2021 at 8:48 AM Steven Rostedt wrote: > > On Tue, 19 Oct 2021 18:31:40 -0700 > Kalesh Singh wrote: > > > @@ -2391,60 +2460,61 @@ static int check_expr_operands(struct trace_array *tr, > > static struct hist_field *parse_expr(struct hist_trigger_data *hist_data, > > struct trace_event_file *file, > > char *str, unsigned long flags, > > - char *var_name, unsigned int level) > > + char *var_name, unsigned int *n_subexprs) > > { > > struct hist_field *operand1 = NULL, *operand2 = NULL, *expr = NULL; > > unsigned long operand_flags; > > int field_op, ret = -EINVAL; > > char *sep, *operand1_str; > > > > - if (level > 3) { > > + if (*n_subexprs > 3) { > > Why limit the sub expressions, and not just keep the limit of the level of > recursion. We allow 3 levels of recursion, but we could have more than 3 > sub expressions. The main reason for this is that it's predictable behavior form the user's perspective. Before this patch the recursion always walked down a single branch so limiting by level worked out the same as limiting by sub expressions and is in line with the error the user would see ("Too many sub-expressions (3 max)"). Now that we take multiple paths in the recursion, using the level to reflect the number of sub-expressions would lead to only seeing the error in some of the cases (Sometimes we allow 4, 5, 6 sub-expressions depending on how balanced the tree is, and sometimes we error out on 4 - when the tree is list-like). Limiting by sub-expression keeps this consistent (always error out if we have more than 3 sub-expressions) and is in line with the previous behavior. - Kalesh > > > If we have: a * b + c / d - e * f / h > > It would break down into: > - > + / > * / * h > a b c d e f > > > Which I believe is 6 "sub expressions", but never goes more than three deep > in recursion: > > "a * b + c / d - e * f / h" > > Step 1: > > op = "-" > operand1 = "a * b + c / d" > operand2 = "e * f / h" > > Process operand1: (recursion level 1) > > op = "+" > operand1a = "a * b" > operand2a = "c / d" > > Process operand1a: (recursion level 2) > > op = "*" > operand1b = "a" > operand2b = "b" > > return; > > Process operand1b: (recursion level 2) > > op = "/" > operand1b = "c" > operand2b = "d" > > return; > > return; > > Process operand2: (recursion level 1) > > op = "/" > operand1c = "e * f" > operand2c = "h" > > Process operand1c: (recursion level 2) > > op = "*" > operand1c = "e" > operand2c = "f" > > return; > > return; > > > > > + > > + /* LHS of string is an expression e.g. a+b in a+b+c */ > > + operand1 = parse_expr(hist_data, file, operand1_str, operand_flags, NULL, n_subexprs); > > if (IS_ERR(operand1)) { > > ret = PTR_ERR(operand1); > > operand1 = NULL; > > I wonder if we should look for optimizations, in case of operand1 and > operand2 are both constants? > > Just perform the function, and convert it into a constant as well. > > -- Steve