Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp543635pxb; Mon, 25 Oct 2021 13:24:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx6hdUEdNKz2PYSbhuTCHEIj5aeeqOLkRyqW205VGHkBvWbfDroQ2x+lwyJBGgCOB358Jgx X-Received: by 2002:a05:6a00:2181:b0:44d:c18d:7af9 with SMTP id h1-20020a056a00218100b0044dc18d7af9mr21432853pfi.16.1635193472328; Mon, 25 Oct 2021 13:24:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635193472; cv=none; d=google.com; s=arc-20160816; b=a6U3I06wHR9IXN7BhHh9WRKc+Ds/AqqM83JqBE+rPXDtcSgUacn96ERudnaV9KhT1R jZw9JTSDhc/an01e2+WEG+wdLqKiaKD7xVnmmZ7na26PttTh2WrIWnVsRscBWshWDIYn 9tugF8hXhSWGAANUbYvjuEfgFkBfR/kW58fugYAla7Jx1wC+fo0j6QnC8BbqBT7I2AqD CojcN8q8S3ujeOFFskv2HQ03nrVQdxy3dRXTZNZT6SKYphlaoSlKCWaxn5kxeuACYgkQ uuremUwaTqb2J0+wP/4b33GVsEMLowZ2WbUMnE61WUgHP9sjIPzIQu0dAwcPcJ3ChFV7 33VA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:cc:from:subject:mime-version:message-id:date :dkim-signature; bh=yVyWdyfXHZ3pBBwGK5eO+moipbm7bhYPbjTGw1dCfng=; b=RoPWue9s/mpEHT2zEfdMNXmUGDHriUQGdzdvBA3ywOo9Xiw5NBC/Nc6pS+4yNSXrjy XqH46ySBErGdVfEOxgqcvdcovfhRbQYQ1iKoD6IlWkMLLvnWIwQmzQ2r+LnzMzzMlbLh MKRuKUPn7Q5ToTkBspiUIJvzGy0+QnE60IOeAL/PAA8pNWAvhK+zrwN1wi3/Akvc61i3 aa3LQTsB1stAOFCPjIsK8TgLXTYjA0VBzGEyNaL72JSe3z0oVVC3GQ2f5CNWA/XgzG1+ 8FfXkCWzAtvQ9VumPz7gVivTscCzY4TM/rst4QWaqRY/zsyvz1TsPQ3zyhwBSkR1zlMA M68g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=paU2f9WA; 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 17si6362776pgw.322.2021.10.25.13.24.13; Mon, 25 Oct 2021 13:24:32 -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=paU2f9WA; 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 S237176AbhJYUZ2 (ORCPT + 99 others); Mon, 25 Oct 2021 16:25:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236792AbhJYUZV (ORCPT ); Mon, 25 Oct 2021 16:25:21 -0400 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E676BC04640E for ; Mon, 25 Oct 2021 13:09:00 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id u1-20020a170903124100b0013fd0e97269so4239440plh.10 for ; Mon, 25 Oct 2021 13:09:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:cc; bh=yVyWdyfXHZ3pBBwGK5eO+moipbm7bhYPbjTGw1dCfng=; b=paU2f9WAMWO8SuGFnY/Kf+ctPro0KZXFza3R2Go6L1ENoF+xpIVaiQv4dgzruOjST0 yeqxlawObXEBfUtTYms0QSZvEhpZMK3cL1EIi9bIXJW6RYt20TIBwkzpMBaMhrtC8D4l giVB1OC1OlMV84o9DFVWF6CH6j+1KgLU+hLaCnQ4xN8po4KWpRePDpZvdUrWJ0wQiWWk huc6vEISE+lYfJLS2Ib3sT8eDtopwh4XbczD452jbp6UDRPJ0cdDwCE5LTUgHAEBsaOL To3KR/ygMlCO+QpCkSHq4iAa/miQNd9z3zdt6AatGyrFTlAsNri1Ph98OXJyHSdjfPPD qRBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:cc; bh=yVyWdyfXHZ3pBBwGK5eO+moipbm7bhYPbjTGw1dCfng=; b=k0GkDfhK4LSIw2bQtA7he0KjIowcGCBGoVznLevRsfTfUdDaMIr9EOGrZfHywdC4pr HNfHM2uOMrsjGrpqof3DprFwJHfFlZrj1Rekq7KgtQH8IY2mGHIgXIB//Qd01Xvisot8 7+FOhr6f4JuJZH6n+E32dECjbm90jej1cQ80eM6SfjzIHhgQ37A/OMPaVKvEbKB6j0Fj iTkUIcIdyMNmDBbH0wRHh25Fv14+he9Z3Ck4sICn0zfO/DMv4bo66yM/z0VUZTLU6fuS 9oVWG3LYZqrqzXshVVmkezbYECNBM3ENJYLtUj9ZsY8Yn7jsefg01U2vfvW0a7TFuIg2 MO/g== X-Gm-Message-State: AOAM533NhshESc0K39ZBGAZjASuY0QzPSp6vXFtbqbqS+RYhv946MYcc dkAklIjt26KXp4o5+61QKNlkrbr+Pb761akdSw== X-Received: from kaleshsingh.mtv.corp.google.com ([2620:15c:211:200:b783:5702:523e:d435]) (user=kaleshsingh job=sendgmr) by 2002:a05:6a00:216f:b0:44b:6212:4967 with SMTP id r15-20020a056a00216f00b0044b62124967mr21060858pff.23.1635192540392; Mon, 25 Oct 2021 13:09:00 -0700 (PDT) Date: Mon, 25 Oct 2021 13:08:32 -0700 Message-Id: <20211025200852.3002369-1-kaleshsingh@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.33.0.1079.g6e70778dc9-goog Subject: [PATCH v4 0/8] tracing: Extend histogram triggers expression parsing From: Kalesh Singh Cc: surenb@google.com, hridya@google.com, namhyung@kernel.org, kernel-team@android.com, Kalesh Singh , Jonathan Corbet , Steven Rostedt , Ingo Molnar , Shuah Khan , Masami Hiramatsu , Tom Zanussi , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Content-Type: text/plain; charset="UTF-8" To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi all, The v4 of the extending histogram exprssions series. The previous versions were posted at: v3: https://lore.kernel.org/r/20211025192330.2992076-1-kaleshsingh@google.com/ v2: https://lore.kernel.org/r/20211020013153.4106001-1-kaleshsingh@google.com/ v1: https://lore.kernel.org/r/20210915195306.612966-1-kaleshsingh@google.com/ Patches 4 through 6 are new and adds some optimizations/improvements suggested by Steven Rostedt. Removes the Change-Id tags that were inadvertently added in v3. The cover letter is copied below for convenience. Thanks, Kalesh --- The frequency of the rss_stat trace event is known to be of the same magnitude as that of the sched_switch event on Android devices. This can cause flooding of the trace buffer with rss_stat traces leading to a decreased trace buffer capacity and loss of data. If it is not necessary to monitor very small changes in rss (as is the case in Android) then the rss_stat tracepoint can be throttled to only emit the event once there is a large enough change in the rss size. The original patch that introduced the rss_stat tracepoint also proposed a fixed throttling mechanism that only emits the rss_stat event when the rss size crosses a 512KB boundary. It was concluded that more generic support for this type of filtering/throttling was need, so that it can be applied to any trace event. [1] From the discussion in [1], histogram triggers seemed the most likely candidate to support this type of throttling. For instance to achieve the same throttling as was proposed in [1]: (1) Create a histogram variable to save the 512KB bucket of the rss size (2) Use the onchange handler to generate a synthetic event when the rss size bucket changes. The only missing pieces to support such a hist trigger are: (1) Support for setting a hist variable to a specific value -- to set the bucket size / granularity. (2) Support for division arithmetic operation -- to determine the corresponding bucket for an rss size. This series extends histogram trigger expressions to: (1) Allow assigning numeric literals to hist variable (eg. x=1234) and using literals directly in expressions (eg. x=size/1234) (2) Support division and multiplication in hist expressions. (eg. a=$x/$y*z); and (3) Fixes expression parsing for non-associative operators: subtraction and division. (eg. 8-4-2 should be 2 not 6) The rss_stat event can then be throttled using histogram triggers as below: # Create a synthetic event to monitor instead of the high frequency # rss_stat event echo 'rss_stat_throttled unsigned int mm_id; unsigned int curr; int member; long size' >> tracing/synthetic_events # Create a hist trigger that emits the synthetic rss_stat_throttled # event only when the rss size crosses a 512KB boundary. echo 'hist:keys=mm_id,member:bucket=size/0x80000:onchange($bucket) .rss_stat_throttled(mm_id,curr,member,size)' >> events/kmem/rss_stat/trigger ------ Test Results ------ Histograms can also be used to evaluate the effectiveness of this throttling by noting the Total Hits on each trigger: echo 'hist:keys=common_pid' >> events/sched/sched_switch/trigger echo 'hist:keys=common_pid' >> events/kmem/rss_stat/trigger echo 'hist:keys=common_pid' >> events/synthetic/rss_stat_throttled/trigger Allowing the above example (512KB granularity) run for 5 minutes on an arm64 device with 5.10 kernel: sched_switch : total hits = 147153 rss_stat : total hits = 38863 rss_stat_throttled: total hits = 2409 The synthetic rss_stat_throttled event is ~16x less frequent than the rss_stat event when using a 512KB granularity. The results are more pronounced when rss size is changing at a higher rate in small increments. For instance the following results were obtained by recording the hits on the above events for a run of Android's lmkd_unit_test [2], which continually forks processes that map anonymous memory until there is an oom kill: sched_switch : total hits = 148832 rss_stat : total hits = 4754802 rss_stat_throttled: total hits = 96214 In this stress test, the synthetic rss_stat_throttled event is ~50x less frequent than the rss_stat event when using a 512KB granularity. [1] https://lore.kernel.org/lkml/20190903200905.198642-1-joel@joelfernandes.org/ [2] https://cs.android.com/android/platform/superproject/+/master:system/memory/lmkd/tests/lmkd_test.cpp Kalesh Singh (8): tracing: Add support for creating hist trigger variables from literal tracing: Add division and multiplication support for hist triggers tracing: Fix operator precedence for hist triggers expression tracing/histogram: Simplify handling of .sym-offset in expressions tracing/histogram: Covert expr to const if both operands are constants tracing/histogram: Optimize division by a power of 2 tracing/selftests: Add tests for hist trigger expression parsing tracing/histogram: Document expression arithmetic and constants Documentation/trace/histogram.rst | 14 + kernel/trace/trace_events_hist.c | 400 ++++++++++++++---- .../testing/selftests/ftrace/test.d/functions | 4 +- .../trigger/trigger-hist-expressions.tc | 72 ++++ 4 files changed, 412 insertions(+), 78 deletions(-) create mode 100644 tools/testing/selftests/ftrace/test.d/trigger/trigger-hist-expressions.tc base-commit: ac8a6eba2a117e0fdc04da62ab568d1b7ca4c8f6 -- 2.33.0.1079.g6e70778dc9-goog