Received: by 2002:ab2:687:0:b0:1f4:6588:b3a7 with SMTP id s7csp204949lqe; Tue, 9 Apr 2024 21:57:57 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVTFAlradBZ2X+7benVNv/8h+qx3+DzlGuDugvdAiA7k3uS6zvnq81sz2qejPWuo7UNfupGInmPZ9uDVDYJ03c1YO4pQkW6215fL/VP9g== X-Google-Smtp-Source: AGHT+IF5jegpmz/87XqQuZR+UsapAU+O9vN3SqGwCuir3/lwU0Jxp7ekr/uskkOPxDgsn5DRxPRf X-Received: by 2002:aca:1a18:0:b0:3c6:29b:fe7a with SMTP id a24-20020aca1a18000000b003c6029bfe7amr1517334oia.18.1712725076756; Tue, 09 Apr 2024 21:57:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712725076; cv=pass; d=google.com; s=arc-20160816; b=C00POiOeE4OQYsAudZGf1XuJAc+SSAV0ZBc6DDs/Mj2jROUKweuGskfHP8yQqCrSJm 2bc+ixLRfnsguhzoCDfMtFd0RqHR3L8hoMLqcYhWRBOjC9pM2xzOYquAfgw33/VCO7YY EtPPdoJpSWs/dJS+JErDRlmPSWEF78E+y2dreNEq6M4PvBJfh+7yk8kd19JNv4iQj/Sm 4XcKcprkkwtf3kU86G7zJ5rE1GJCPDYexrDT+HbBVbD3dhd3mgnmrRo+W0CN/Jnobir/ 4wRsb+C+oBxIaW50n1VsSG+Bd+0JrKtq85eR/BdmQp1X2kGlDd2Vo3EurstUjYwSxEUJ gMJw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:precedence:robot-unsubscribe:robot-id :message-id:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:in-reply-to:cc:subject:to:reply-to:sender :from:dkim-signature:dkim-signature:date; bh=aosX2fNfJOBQQfZWyqTitQc7wrM7/1Fev40KqiYoNVU=; fh=AwANW0s9hMdGqYxNwPNbFPRbaftIfTo+pTAePJFk8Ug=; b=E/jZbOykSoK1ewXKnC7Z3m3fuyV1zic1NScLMlEAUMVclLKKq4C1ETFcYDWpp0/Eo8 D3lPQSBVSOlUeY15ERY43LEoDRkg36nkmV0sCj1At1JGpAJN5QkGfEk/B6YXrQedVe/5 /UjXBC9V+8fj6srMrOnIZQGC1ANU1gH4XgEFjLbY+wzwanfoaoJyCKGP2SHIt28ZSKXx m3uqgc8+VNFeLx66FFMpeKqyvI9DIRHatrgwuoj+WSkC0Cm92i2/3Jr5g0VVCXUDqvvX AH5dh8l4OZWuyInZ8PokV/+BFZnEr6EoV1e80UPjqBAHsvh1JGi/VmLPtvYE5pt349rB KXYA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=QcDjJXYO; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-137908-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-137908-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id ey3-20020a056a0038c300b006eada9fe237si9958294pfb.188.2024.04.09.21.57.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 21:57:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-137908-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=QcDjJXYO; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-137908-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-137908-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 64E1428540C for ; Wed, 10 Apr 2024 04:57:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A76F610A3E; Wed, 10 Apr 2024 04:57:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="QcDjJXYO"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="GYRC7ShE" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 328C9D51A; Wed, 10 Apr 2024 04:57:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712725069; cv=none; b=K0l/GbToE2SO3y6RDRCXapfW2IpyyC3OEo6iNFbDJzmhu1lz+gmpYhla7vmo375Y/fxmM74McOSPDwK1T1QaIcH+Yqt0nYs3T8fZ1gekMW0Zg0KR0Vl3m6nCy30tiXb+3ILj/ByoeYb1lDJhbrTtFbUywTnJ2lRVK4YEWVoJMg8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712725069; c=relaxed/simple; bh=1bg2ed1fxDBgKsreFSBIR/3aeKLchbspFsok4PUJNzY=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=mzhCoeg1bRNRp27QUkCY3x+3DmDCluuCK5pG9GdRYKXMKv2oSD26LNXeCwYucSqtcDlyLTNYh6KI3ypwOCgLsSVr6s30NYUD0lTDjRYVdTIOHLuIfIpoFsuTxsmeDjTM3wAu90c+6D/AQ6JvrPyM6dqd/fFIwwvwCKtY+L1Ps5E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=QcDjJXYO; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=GYRC7ShE; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Date: Wed, 10 Apr 2024 04:57:45 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1712725066; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aosX2fNfJOBQQfZWyqTitQc7wrM7/1Fev40KqiYoNVU=; b=QcDjJXYOo68zeSiGXAhobMi147ADKU7RLAWBffqhaF3rayda8uXevX483faoYd6oKIOk0t r+d/+W6r0YO376dgX9H+bg2dTND8jdmSp0toIMwn3OGD2poaYQmmcG3yeoMNKkOZ7ybpR2 9ycWLEJ8FDS5fHfWDK59gDvkEy8sNJ92zzwXwWoLhMhAdHUxXgplzDN/0VUEw/IIOpTO5v 7MEYg2DBZHkaOGXhbU1tpAfqVTPhQ4IrekuuuUm9L1pDFCaICjPAzOG9Hgs4dzCXRnXU5a 7+91BHNiUsA4VjsdKRTZVpBkHrPdl+NDWyc3Dvvl46FcX+xFqRpmCP3oGTxLVw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1712725066; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aosX2fNfJOBQQfZWyqTitQc7wrM7/1Fev40KqiYoNVU=; b=GYRC7ShE4q6r0QVhSGx2R1kM+ADY0IGcn504cce3Ldq6RrmntLVQHP17usbkkeT6WsbwDC 250qw+dUUX1FKpBg== From: "tip-bot2 for Namhyung Kim" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: perf/core] perf/core: Reduce PMU access to adjust sample freq Cc: Namhyung Kim , Ingo Molnar , Ian Rogers , Kan Liang , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20240207050545.2727923-2-namhyung@kernel.org> References: <20240207050545.2727923-2-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <171272506512.10875.6886742044570226022.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit The following commit has been merged into the perf/core branch of tip: Commit-ID: f38628b06c36222367e26820879789ae59e49f60 Gitweb: https://git.kernel.org/tip/f38628b06c36222367e26820879789ae59e49f60 Author: Namhyung Kim AuthorDate: Tue, 06 Feb 2024 21:05:45 -08:00 Committer: Ingo Molnar CommitterDate: Wed, 10 Apr 2024 06:13:57 +02:00 perf/core: Reduce PMU access to adjust sample freq In perf_adjust_freq_unthr_context(), it first starts the event and then stop unnecessarily to adjust the sampling frequency if the event is throttled. For a throttled non-frequency event, it doesn't have a freq so no need to adjust. Just starting the event would be ok. For a frequency event, whether it's throttled or not, it needs to stop before adjusting the frequency. That means it should not start the even if it was throttled. I tried to skip calling the stop callback, but it didn't work well since the event count might not be up to date. It should call the stop callback with PERF_EF_UPDATE anyway. However not calling start would prevent unnecessary MSR accesses (which can be costly) for already stopped events as stop state is saved in the hw config. Signed-off-by: Namhyung Kim Signed-off-by: Ingo Molnar Reviewed-by: Ian Rogers Reviewed-by: Kan Liang Link: https://lore.kernel.org/r/20240207050545.2727923-2-namhyung@kernel.org --- kernel/events/core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/events/core.c b/kernel/events/core.c index 9566cfb..fd94e45 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -4146,7 +4146,8 @@ 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) + event->pmu->start(event, 0); } if (!event->attr.freq || !event->attr.sample_freq)