From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy1-f202.google.com (mail-dy1-f202.google.com [74.125.82.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5010D2FFDD5 for ; Mon, 18 May 2026 22:37:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779143865; cv=none; b=tfl/SLfZJGLrbnGKHj14VWZOqZ3yl5jL4IIcr0gzGWosCqVXDA45N/j5nbLrSagXW5NJuNke3MPGGdFxDDAOCOundTEPZnvEWzIowndVSqLhYlM8Iof2EGI8aDY+5MdvgogOLrZldY+dHGyP9UvQ+nSy6xBXVr/3vSVGgDOH8TU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779143865; c=relaxed/simple; bh=PrJeS5pOrMvDVW9prhG1ZdLgnyWfgZo1TSbC8C7U+j8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=GQy04TkA2VjMkbqbwuIYnICOBGIaEVEYqYxj7MNzKizW7peGaM/nCkjEKvFyNqXWaur2DQ1YpNPzj742bNqJWkjwYZhWJMGi3tuCQgwKjNWkEIDaYU8BUqHdogRIcysNncVI3+la5MCFDmRczQoPxsAAMw6U1mss40rvzTVR+eg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=R4aewL5C; arc=none smtp.client-ip=74.125.82.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="R4aewL5C" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-2fe1cf409a1so5595287eec.1 for ; Mon, 18 May 2026 15:37:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1779143863; x=1779748663; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=YGty+mNfP/r8NU1YUN9QiD+4rGzw8XBJGEVRJSP65lA=; b=R4aewL5CU1Oo9v5vtBtp9s+oKNQqm9EeNcJgSdF/UyofmfQdADqkLYBkOqeD46gGmL 4kPH5m3t9uxCitfXq0Nv3u5Es4+VX1GHxDuSaEc7u8N/a9rPt/cqBHBVkzULqD9/G0Co wi8FzrFo2wyt4+XSXGZrdRMrputugvBKrTm1zXcfaejR4d44rJhHfK1BUukKL4VnMWBG hzh6BK5Q2+pgMnz6k1bkI4xBghN3yP/3yztJKHFgWWMrgm3cWOVPMuha6yNcex4ddnH7 Sat5yUh8UuEAWoJ89fE5mkUNzRtrx3rRYTpwQUqTM4OGbWDsbZgAJy+xSThoUQbo7ncZ XVew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779143863; x=1779748663; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=YGty+mNfP/r8NU1YUN9QiD+4rGzw8XBJGEVRJSP65lA=; b=ik8CDow/5t0XqlH7pr3BzL1eK+fJctK7+SkyX3Q3a+KuzgDVbz6fsKTnbG3T2CcMle XJGdiMuhyh7w6C/7nVNtPOv5X4EKwm13hjDQbPILzpedrtYiQg6mCwUoFUL9pFx1vgM1 YvosBeOlNXZBnW4s2FrDrAOhNI7NRrhH4lMhTQSauA9BDoNB7bBsh+rzEYM7kHzonUg1 vLLz/A+iO3qZwZuBnoXqHCuwF5/uW8s8pBafI0ze/bAODSsGyZ4Zj5NfYhUxT7Nj7r10 9BmQokn+bHKfLBQYWPml62A9ojUiyiS2qVp05m5Zw5bxk4fF6BM7WlHDcNtANET4zopk Bncg== X-Forwarded-Encrypted: i=1; AFNElJ8zpt6CBLuEzt+A/HnxITz64r8GGkWI2guP1Fz5eP5bv6tgimgdg4m3AdAPInEmgb5ntoHV8aSgtClEkWw=@vger.kernel.org X-Gm-Message-State: AOJu0Yyx3rAdM+PBy5yYgmzxVyA4L7aQxh+juG0odn1LbCJFnRomEJeD G9JxzfHtLBrRoDq2C3hu4JTzgTbNK3GsGzGf6XbOGhr2b5ntMqnYP9byZS4GFxO+9xZugq+A6H3 8ABx9IDNFmQ== X-Received: from dyay16.prod.google.com ([2002:a05:693c:62d0:b0:303:9286:5378]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:7490:b0:2dd:c066:c02 with SMTP id 5a478bee46e88-30398677242mr7852686eec.22.1779143861820; Mon, 18 May 2026 15:37:41 -0700 (PDT) Date: Mon, 18 May 2026 15:37:31 -0700 In-Reply-To: <20260518201419.2943132-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260518201419.2943132-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.631.ge1b05301d1-goog Message-ID: <20260518223733.3034897-1-irogers@google.com> Subject: [PATCH v3 0/2] perf tool_pmu: Support enable/disable for tool PMU events From: Ian Rogers To: irogers@google.com, acme@kernel.org, namhyung@kernel.org Cc: adrian.hunter@intel.com, james.clark@linaro.org, jolsa@kernel.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, mingo@redhat.com, nigro.fra@gmail.com, peterz@infradead.org, tmricht@linux.ibm.com Content-Type: text/plain; charset="UTF-8" A regression in perf stat was reported where tool PMU events (like duration_time used in CPUs_utilized metric) incorrectly included the delay period when using the delay option (-D). This series fixes the regression by making tool PMU events (duration_time, user_time, system_time) behave more like regular counters by implementing proper enable and disable support. They now correctly accumulate values only when enabled. The first patch implements the core enable/disable support for tool PMU events, and the second patch adds a shell test to verify that duration_time correctly excludes the delay period. Changes in v3: - Refine group handling: only manually enable/disable group members when the leader or member is a non-perf-event open PMU, as the kernel allows grouping of software and hardware PMUs. - Fix a file descriptor leak in evsel__tool_pmu_open() on error paths by explicitly closing the successfully opened fd before exiting. - Synchronize the 'disabled' flag for all group members in enable/disable paths (both per-CPU and batch loops) to prevent stale disabled flags. - Add explicit early exits to evsel__tool_pmu_enable() and disable() based on evsel->disabled to protect internal metric state. - Add an upper bound check in test_stat_delay to verify that the delay was actually excluded. Changes in v2: - Implement evsel__tool_pmu_enable() and evsel__tool_pmu_disable() to avoid ioctl failures in batch evsel__enable() and evsel__disable() functions. - Correctly iterate and enable/disable tool PMU events configured as non-leader members of event groups. - Correct the lseek() arguments order in the read_stat helper: lseek(fd, 0, SEEK_SET) instead of lseek(fd, SEEK_SET, 0). - Introduce INVALID_START_TIME (~0ULL) to prevent erroneous large delta accumulation in evsel__tool_pmu_read() if /proc//stat fails to read in enable_cpu (e.g., process exited). - Improve test parsing to use LC_ALL=C and cut to be robust against different locales, and use awk to dynamically compare duration_time to time elapsed with a 200ms tolerance (avoiding loaded CI false failures). Also added a lower-bound check. - Fix style warnings from checkpatch.pl (line lengths, braces, and blank lines). Ian Rogers (2): perf tool_pmu: Make tool PMU events respect enable/disable perf tests: Add test for stat delay option with duration_time tools/perf/tests/shell/stat.sh | 53 +++++++ tools/perf/util/evlist.c | 10 +- tools/perf/util/evsel.c | 196 +++++++++++++++++++------ tools/perf/util/evsel.h | 15 +- tools/perf/util/tool_pmu.c | 253 ++++++++++++++++++++++++++------- tools/perf/util/tool_pmu.h | 4 + 6 files changed, 432 insertions(+), 99 deletions(-) -- 2.54.0.631.ge1b05301d1-goog