Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp597416rdd; Tue, 9 Jan 2024 13:36:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IEVQpKS8PnZZYIwIP1F/rX5Aza7Sv69ZVcxixrwd0DXkxfsySpuQC1l7yrRXQym9I+y1zpm X-Received: by 2002:a17:907:7890:b0:a27:c86a:b79f with SMTP id ku16-20020a170907789000b00a27c86ab79fmr57351ejc.123.1704836207635; Tue, 09 Jan 2024 13:36:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704836207; cv=none; d=google.com; s=arc-20160816; b=GI1HFZXMI/PDv8Kp973r+sLGHuGwrp6nb+8U9nzlA5LEvPrH195r+Qnh4FGWRouuqx /QBzh/9K+fZWVn7Qj7liMpEldnumOhR1MfpGw96OV+5FCLjIa6i6vBb4bc/zmO1N4aL0 0wl/3QVF1VPU18e0/lCKCoTz8NrXq3bww4NHS0nCSXZe1RuOCtdAAImPkJYKFfaX5xN3 3MvOjzJ3QOem1SfeS/NUOlcyPwyQXz+nt7b2qUjVS8phYlfGjiWdWAwpJNvxKN73nx5K 4rTVc5/GXBdPZM499BeE4T8L0o3I2C/MXxBSZqNG/R8SGycNXSKVAtVf5RjkHgeKeIAH +heg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:sender:dkim-signature; bh=WOz0ul5eLLG1EnWl4tq9lX0YDnXeDhj2Cx7kAjJRFmk=; fh=td8d7Q3pJYoWHD6S/3a8pi2tnOfKOxJmnp57S18GF7U=; b=iWnqJjq15xWBaiYKfkwLo/DPNpwiPEIMOwCaNbjxag2VSzCocNrIAdlPUIY3ddrKkT HKjcZ4si07vC2CwwURs0o5ztA87mazB4QlqeCZQwWXyqB9AeKfDUHLMLTThQMWfFAIav ZXKmqX0jg841mzPPJHCXsMBXa9UYZKWf37tEwxH65rD2T9uKyHUFH/SGdo/pA77ZtIhJ KevK+9+R12yb5sA/s7Ho0RrpYWB++jUKg1Iw5yOG3vTAkLobkvsKjSIwatkd1WPYoWrm 82lE1nzCy+DT37+PIqtgbLkjIxLOB3f1TiS0nAZKQqf+0rP4cqdLpkOKHUP9nHsCGy3b MCLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=dGoUBh5m; spf=pass (google.com: domain of linux-kernel+bounces-21424-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21424-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id qk11-20020a170906d9cb00b00a22ef7f1041si1141169ejb.578.2024.01.09.13.36.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 13:36:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-21424-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=dGoUBh5m; spf=pass (google.com: domain of linux-kernel+bounces-21424-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21424-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 375161F25F38 for ; Tue, 9 Jan 2024 21:36:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D750B3DBA8; Tue, 9 Jan 2024 21:36:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dGoUBh5m" Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) (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 C49FB3DB88 for ; Tue, 9 Jan 2024 21:36:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-f179.google.com with SMTP id 41be03b00d2f7-5cddc5455aeso1434801a12.1 for ; Tue, 09 Jan 2024 13:36:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704836186; x=1705440986; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=WOz0ul5eLLG1EnWl4tq9lX0YDnXeDhj2Cx7kAjJRFmk=; b=dGoUBh5mYQxqDMyZVD7ybz5sLuXmdZgY7Fu9ANMC6haJAcd6mq7tajD6bG78VvhaF8 GOn4xaV03AU7pO/Irk0E5kAVm311/ymWgLUIdoLSVPI+l0EaHp4FcxUJil2PZ+U5SEuA dzDkP4zqAywHiC4Sr7XRTFoeIh89hRlnJbsv5bqebW4LxGNCn678gecXsUDu06KY9xbT evzqhdHKrj+/qwGPlHN0W5gNWe9JA1zT7uxQ3GS27PeWvP1Iq1ykaz+3sKo4ZmO7Cf6l MCjRtcyhc8j5F3wCKrUE7mamggQs1y3oMkbdd4XXc93jPyIHMU5VdeRJsI3l/ms3CMyd BOjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704836186; x=1705440986; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=WOz0ul5eLLG1EnWl4tq9lX0YDnXeDhj2Cx7kAjJRFmk=; b=g3zCaSXQfGu2o5LBFZhUtUZbiPBLczQyLuHZozJ1IEQapbeSOBxifAHBzv20ybaXk+ u8RnSUsCPwmp3GJPqO/YNTUgFG/RJRYuRjufsdsT/uvsB8hCxGvtYQcwOSA9taNLZ/py pqsm4G7Xd0TwjVU9b33iYzb94y+35J1XF/n9pkdyNzkedyApm7qU0MuOWqaMfNVaK90n dORTfb9y2gUmPEc/MDTKP5YsjNtGmvCqpiHbZ5vAVxSdjBjvWN8+T05Tf0XhWVsZisGm P2DhzJeEYJ0Eiio5c6Wz+W6WX1FWnTDoypVJ5/IV6LZVUZLQ2/wbuK+hreFx8M/5Myzu rfAA== X-Gm-Message-State: AOJu0Yyh9ENScmG7TDPk+Ow3xr23sIp9Ss8EGcdMHKjpSWvqhzvIonux P/wELCFmuatbzpWYievtkGs= X-Received: by 2002:a05:6a20:aa4:b0:199:9385:b783 with SMTP id b36-20020a056a200aa400b001999385b783mr2717087pzf.62.1704836185999; Tue, 09 Jan 2024 13:36:25 -0800 (PST) Received: from bangji.corp.google.com ([2620:15c:2c0:5:b4e:5c78:a5b3:ef5b]) by smtp.gmail.com with ESMTPSA id bj2-20020a170902850200b001d55717179asm1957471plb.288.2024.01.09.13.36.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 13:36:25 -0800 (PST) Sender: Namhyung Kim From: Namhyung Kim To: Peter Zijlstra , Ingo Molnar Cc: Mark Rutland , Alexander Shishkin , Arnaldo Carvalho de Melo , LKML , Mingwei Zhang , Ian Rogers , Kan Liang Subject: [PATCH RESEND 2/2] perf/core: Reduce PMU access to adjust sample freq Date: Tue, 9 Jan 2024 13:36:23 -0800 Message-ID: <20240109213623.449371-2-namhyung@kernel.org> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog In-Reply-To: <20240109213623.449371-1-namhyung@kernel.org> References: <20240109213623.449371-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit For throttled events, it first starts the event and then stop unnecessarily. As it's already stopped, it can directly adjust the frequency and then move on. Reviewed-by: Ian Rogers Reviewed-by: Kan Liang Signed-off-by: Namhyung Kim --- kernel/events/core.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/kernel/events/core.c b/kernel/events/core.c index ce9db9dbfd4c..c80b6aa0e354 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -4121,10 +4121,15 @@ static void perf_adjust_freq_unthr_events(struct list_head *event_list) if (hwc->interrupts == MAX_INTERRUPTS) { hwc->interrupts = 0; perf_log_throttle(event, 1); - event->pmu->start(event, 0); - } - if (!event->attr.freq || !event->attr.sample_freq) + if (!event->attr.freq || !event->attr.sample_freq) { + delta = 0; + goto next; + } + + if (event->hw.state & PERF_HES_STOPPED) + goto adjust; + } else if (!event->attr.freq || !event->attr.sample_freq) continue; /* @@ -4132,6 +4137,7 @@ static void perf_adjust_freq_unthr_events(struct list_head *event_list) */ event->pmu->stop(event, PERF_EF_UPDATE); +adjust: now = local64_read(&event->count); delta = now - hwc->freq_count_stamp; hwc->freq_count_stamp = now; @@ -4146,6 +4152,7 @@ static void perf_adjust_freq_unthr_events(struct list_head *event_list) if (delta > 0) perf_adjust_period(event, period, delta, false); +next: event->pmu->start(event, delta > 0 ? PERF_EF_RELOAD : 0); } } -- 2.43.0.472.g3155946c3a-goog