Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp1901145rdd; Thu, 11 Jan 2024 12:44:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IGpochcbltGKmQlIYfZUsv4Z6UXWubB7rz/o2aGbUrvyKBMyw4kr0mCg8dD6kSm8HuFy3yE X-Received: by 2002:ac8:5916:0:b0:429:bccc:31ca with SMTP id 22-20020ac85916000000b00429bccc31camr594213qty.46.1705005842189; Thu, 11 Jan 2024 12:44:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705005842; cv=none; d=google.com; s=arc-20160816; b=JW5kt5w7qeCoQ4t+rQjC3x68UDlIQ+tPodvztyqB6d49Wj8ClHUBBFqXDJqsP3um7z 3zPvA2WyL8bO1x3V6t+BRxZmbyORQ7zMzBGAmT8h/tmlSDQFmOi0cZByf+MqkefLav7s U3zc2a0w+hxC3anSLKI9zbLl+TXznjKU8THHTQd2NrNw8XGK2PpJ74PcYV3DELnoX58W kDjKX4Jgxe7CfOdqQ7k6xbk1ZcgBtfABh9RLqB1i8mpHz6Z3pEcjdelpQM07bNlDER83 t7fFJm/64WBAaqFrY+KUPxy5Ufqc5mNrbyD+cL2Nmex9fxE2tsIiszFNQ4+IeNRj0+s3 YgjQ== 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:dkim-signature; bh=KFNOazD/U8KdFFAkCTECA4UZvIt+ln5xTnplery4JMY=; fh=Nt5aqmeMpERBIZQMfRO9Om+I9Fp7Yp2dDd9u0qNHvcY=; b=FaP8mSN2PGrVEVuOPAKIcyARIZqrKonVScov/PTJkOmOQSOS/inJNr9h2hw9Ch/3ty UdevFVnTrL/JUJ8ExwLZV1639idFG3c1jCXhDbRl4Om+57NpQubWfK0R7g0sA3YbMdE5 BvjzOkNK3Cu+npfObz9wxu6uL4EnDZTZIDJUwFobc4JcYaBMbdpQbKRs3hLFwA2ZK6+B pbIKm/tAIwlmknbVrJDKGd/Vc4ykgNT4rIQkfCegPLNlyyqlvZzm6KA1gVawP6zGQwIO H4UjJGhDcFM295KGDnKe7VgZtr7gRcTjLktz+V37XIkBWAmnwRe1WrAIhbyZLZeeVYcI alvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="oPc4/CVB"; spf=pass (google.com: domain of linux-kernel+bounces-24057-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24057-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id f5-20020a05622a1a0500b0042991063038si1740712qtb.21.2024.01.11.12.44.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 12:44:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-24057-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="oPc4/CVB"; spf=pass (google.com: domain of linux-kernel+bounces-24057-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24057-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id E94631C22A4C for ; Thu, 11 Jan 2024 20:44:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6CD5E58121; Thu, 11 Jan 2024 20:43:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="oPc4/CVB" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9D2165810F for ; Thu, 11 Jan 2024 20:43:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B87E1C433A6; Thu, 11 Jan 2024 20:43:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705005830; bh=A4VhAo2thc3VPIG5HMtbRNaNrF0RwGaTT512LSk8+14=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oPc4/CVBLd0WDTsE0CfRKBMLzKaJeYqEHgLAuo4IPCFvh2RmzP4+fv2iLEsKFJC2X ytStGdLBRCGiYpoeIvv6NEr98BoxG3yXGNAoS6TTFIqmLhhwy53zgp2wBUTRxiAsjP bgpqdpDzaeZk6rHBh+vqJsrINIaTU4mBzTZlYCaEoIrH02qIdZ8nSXFsWgaYla1vl0 cWb2wCdeaq4nrhRdV2rDB3Dqb3TdhGgr7lLu1KK8+cM3by12769l2pmuSJfb4YwfMT wsn6G07+eRM4zMStXioTAeguASBOxljBw+HoIMY4r6JwRt0X/aadSAoUBF3c/atWC5 /IOlL39X2X4uw== From: namhyung@kernel.org To: Peter Zijlstra , Ingo Molnar Cc: Mark Rutland , Alexander Shishkin , Arnaldo Carvalho de Melo , LKML , Mingwei Zhang , Namhyung Kim , Ian Rogers , Kan Liang Subject: [PATCH v2 2/2] perf/core: Reduce PMU access to adjust sample freq Date: Thu, 11 Jan 2024 12:43:48 -0800 Message-ID: <20240111204348.669673-2-namhyung@kernel.org> X-Mailer: git-send-email 2.43.0.275.g3460e3d667-goog In-Reply-To: <20240111204348.669673-1-namhyung@kernel.org> References: <20240111204348.669673-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 From: Namhyung Kim 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 e9ce79c8c145..243cd09ba7fe 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.275.g3460e3d667-goog