From nobody Tue Dec 2 02:33:07 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 C78FF2F39BF for ; Tue, 18 Nov 2025 15:58:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763481525; cv=none; b=BbtjW5OUgA38QDGvrgPATL7R1WZtrDKbhp8N7F4adoGUBnXGmxoluxv2sqvSN7iRoUjNgoweRReF7XPexCq+QXFUUBLzAR4aKpagRA2uOP80X7TTM7XB4Ok3f5oT2DDYhrB8WTiwlAp9uUe1BZ+GwbVTbgY6iRLRYkDr5ksIIpk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763481525; c=relaxed/simple; bh=wIUoNUCEuvQTrUQzeUDqqXYnIdaQhe00Yf7UiH84tro=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ICzcHg6iCdvLh3Wyj8QqqjRrddyy5zMSL8/HtjhSFf0kFep20fc/qAhNIRU37gyVrkU3LYOHAlme/Get64Wt1LpqUgir0ja/q44WN7hQATSBWFWyCAbcnVnf0TkUuLCNqqtdArCni3fEKZ5sfUD5BXZkfeae4ryhIknfdOrWaus= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=WIujA2zG; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="WIujA2zG" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763481522; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GjDlL6LfBuoQ9QHJ2vIOgbDqD00HSi6hGNS6MkE8ovE=; b=WIujA2zGe8QHOHobY5WDkcLntJ6QK81mIt+ZIk9thPuq6ZZyEG8mFQcU46mgKbHwPwTnTR 0SssKnf767bNoe9d7/2ckz1BKVrc/QKjvRJTm/e+VHQpK5ch33LnThMv2fSaVASMMlnNdR iO4i0jegTq0gQDqnzCCYFyFP5MQfw0w= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-644-oi6_SwwPMdeaklMth0AJnQ-1; Tue, 18 Nov 2025 10:58:34 -0500 X-MC-Unique: oi6_SwwPMdeaklMth0AJnQ-1 X-Mimecast-MFC-AGG-ID: oi6_SwwPMdeaklMth0AJnQ_1763481512 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3F6EA18002F4; Tue, 18 Nov 2025 15:58:32 +0000 (UTC) Received: from darcari-thinkpadt14sgen1.bos.com (unknown [10.22.64.106]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 17C5C19560B0; Tue, 18 Nov 2025 15:58:30 +0000 (UTC) From: David Arcari To: lenb@kernel.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, David Arcari Subject: [PATCH 1/3] tools/power turbostat: avoid segfault referencing fd_instr_count_percpu Date: Tue, 18 Nov 2025 10:58:11 -0500 Message-ID: <20251118155813.533424-2-darcari@redhat.com> In-Reply-To: <20251118155813.533424-1-darcari@redhat.com> References: <20251118155813.533424-1-darcari@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" The problem is that fd_instr_count_percpu is allocated based on the value of has_aperf. If has_aperf=3D0 then fd_instr_count_percpu remains NULL. However, get_instr_count_fd() is called from turbostat_init() based on the value of has_aperf_access. On some VM systems has_aperf can be 0, while has_aperf_access can be 1. In order to resolve the issue simply check for to see if fd_instr_count_percpu is NULL and return -1 if it is. Accordingly, the has_aperf_access check can be removed from turbostat_init. Signed-off-by: David Arcari Cc: Len Brown Cc: linux-kernel@vger.kernel.org --- tools/power/x86/turbostat/turbostat.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbos= tat/turbostat.c index f2512d78bcbd..584b0f7f9067 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c @@ -2463,6 +2463,9 @@ static long open_perf_counter(int cpu, unsigned int t= ype, unsigned int config, i =20 int get_instr_count_fd(int cpu) { + if (!fd_instr_count_percpu) + return -1; + if (fd_instr_count_percpu[cpu]) return fd_instr_count_percpu[cpu]; =20 @@ -10027,7 +10030,7 @@ void turbostat_init() for_all_cpus(get_cpu_type, ODD_COUNTERS); for_all_cpus(get_cpu_type, EVEN_COUNTERS); =20 - if (BIC_IS_ENABLED(BIC_IPC) && has_aperf_access && get_instr_count_fd(bas= e_cpu) !=3D -1) + if (BIC_IS_ENABLED(BIC_IPC) && get_instr_count_fd(base_cpu) !=3D -1) BIC_PRESENT(BIC_IPC); =20 /* --=20 2.51.0 From nobody Tue Dec 2 02:33:07 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 E9407368282 for ; Tue, 18 Nov 2025 15:58:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763481522; cv=none; b=h/3uRh8b8L6KECE20gs5nRrJ/5X0KV0LNNdSX3eNOSkmz3w0i6gcLkiFfLoKSHMHyHMdeAOs0eDWJqh2egvsGme2CXM8csRw6QRp0ckExbhuUrzKi7sqqKtrs/nBVuckhwXFMjr1mGhJb1wMyD7QnKSSfOPCzuymHze/AyrQk9E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763481522; c=relaxed/simple; bh=k2FbFcd0nL4y984F/1vM+kZdevZalF76kgkmobPrCBY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GcSPWpm6xvw1LA2gAdrax5cBQKXfbwPRsVf5Eoe5NrGnDTTbtuSSZB/RR/fn36r/stb6MWX75aCgr6tITs24H14N6ZcpzhAUfiib+TlhOwa1EtHuYD6ASwgKFB239IkDhQhZjdK6EUty/Td+CH0CrrnEy201kjqxrbeODeQZLTs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=EJFrI7LF; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="EJFrI7LF" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763481519; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=g7baWOeqXS427/Tvfn93lfXLCFO4X6y/YXuAu6Og1xw=; b=EJFrI7LFkglTPJfyEhJ83KeFvYdKzUdXBLvkDGH0zOuEMlgbaVsRM9d9k6bTTXDqNrYQHl eCE07pZg9CRyvLbS+r6lTvlDFM2IVizI1bsLHEJDTqa3efqcdZ3WYhLoYwohlSOGazcpXf 3HiZ+kjll9N7Bc/DoA1vMd0cBuGQuIM= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-108-jWROcCY4Oe6khJJXesY2IA-1; Tue, 18 Nov 2025 10:58:36 -0500 X-MC-Unique: jWROcCY4Oe6khJJXesY2IA-1 X-Mimecast-MFC-AGG-ID: jWROcCY4Oe6khJJXesY2IA_1763481515 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9CA94180034D; Tue, 18 Nov 2025 15:58:35 +0000 (UTC) Received: from darcari-thinkpadt14sgen1.bos.com (unknown [10.22.64.106]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7A02E19560B0; Tue, 18 Nov 2025 15:58:34 +0000 (UTC) From: David Arcari To: lenb@kernel.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, David Arcari Subject: [PATCH 2/3] tools/power turbostat: avoid an infinite loop of restarts Date: Tue, 18 Nov 2025 10:58:12 -0500 Message-ID: <20251118155813.533424-3-darcari@redhat.com> In-Reply-To: <20251118155813.533424-1-darcari@redhat.com> References: <20251118155813.533424-1-darcari@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" There are some error cases where turbostat will attempt to reinitialize by calling the re_initialize() function. The code attempts to avoid an infinite loop by checking the value of 'restarted' in one case, but not others. It should be checked in all cases of restart. Additonally, the 'restarted' is reset to zero at the start of the loop which also needs to be removed. Signed-off-by: David Arcari Cc: Len Brown Cc: linux-kernel@vger.kernel.org --- tools/power/x86/turbostat/turbostat.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbos= tat/turbostat.c index 584b0f7f9067..5567b9ecd516 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c @@ -6722,7 +6722,11 @@ void turbostat_loop() set_my_sched_priority(-20); =20 restart: - restarted++; + if (restarted++ > 10) { + if (!retval) + retval =3D -1; + exit(retval); + } =20 snapshot_proc_sysfs_files(); retval =3D for_all_cpus(get_counters, EVEN_COUNTERS); @@ -6730,13 +6734,9 @@ void turbostat_loop() if (retval < -1) { exit(retval); } else if (retval =3D=3D -1) { - if (restarted > 10) { - exit(retval); - } re_initialize(); goto restart; } - restarted =3D 0; done_iters =3D 0; gettimeofday(&tv_even, (struct timezone *)NULL); =20 --=20 2.51.0 From nobody Tue Dec 2 02:33:07 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 651E535CB74 for ; Tue, 18 Nov 2025 15:58:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763481528; cv=none; b=UD1rro4ukz3pIqSAuBZ1LY7xHcvSQKANg8fKi7TLr5AdxMGGMvvUB3yPK3/j7IacDUt1db0sBtrgH/jzr8lfbDLS6X7R8rcphVVLwFhk/i0W4doF3zl7GLwzpeZnao2riPyx/UXuYVPl0FRRUkWf+MiQeBNHFsfMEvvVzZuGLb0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763481528; c=relaxed/simple; bh=w/IZMKw3JZlQsVeZkGgKBw6RsNQiyGUgrwYveTjVUIo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tqeECYEuL2zCHq/j8E5Qa9OYHjD1LtMYARsyxowAVDqKaTUOi9HZZcozfZlwvn5S0RT79PmTd1dg0IBFjvquin63Bw+i68+6Q4admWMDUg+4t5Sg0DoP1Kdm2FFGJx+gI6M4OvQQfhiXHgpsqjcLtpR6gY/ZpgMKrBaCz6EEdfY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=arF9vD32; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="arF9vD32" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763481526; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VR6q9nN6tLl0OjvkimuaeaYQsj1H42Iqp2Su1pl+Lbk=; b=arF9vD32gW1+kIs+fAnoX9QOZMHi3zEZNv7lvUw9TEAmhOaNcXRHE+Hi2Nl9P/x0JUOE2j J+4AFDbjdwvfRfa6JNFXYQMwxujGlNf7GcpcGHDFvxpkax4Q9RHBqkGKVOQuWbO1uSDyxX PUhiyfcTLLvyOgt5zEDC0mY1dFL8YYA= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-157-dplfiAZ1MWy2ktaNS09uKQ-1; Tue, 18 Nov 2025 10:58:39 -0500 X-MC-Unique: dplfiAZ1MWy2ktaNS09uKQ-1 X-Mimecast-MFC-AGG-ID: dplfiAZ1MWy2ktaNS09uKQ_1763481518 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 18A581955F68; Tue, 18 Nov 2025 15:58:38 +0000 (UTC) Received: from darcari-thinkpadt14sgen1.bos.com (unknown [10.22.64.106]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DA7C819560B0; Tue, 18 Nov 2025 15:58:36 +0000 (UTC) From: David Arcari To: lenb@kernel.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, David Arcari Subject: [PATCH 3/3] tools/power turbostat: allow turbostat to work when aperf is not available Date: Tue, 18 Nov 2025 10:58:13 -0500 Message-ID: <20251118155813.533424-4-darcari@redhat.com> In-Reply-To: <20251118155813.533424-1-darcari@redhat.com> References: <20251118155813.533424-1-darcari@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" Currently when aperf is not available the function has_amperf() still returns true. The end result is that the program gets an error in delta_thread() which causes turbostat to restart. We can avoid this by not setting msr_counter_arch_infos[MSR_ARCH_INFO_APERF_INDEX].present when aperf is not available allowing turbostat to execute normally. Signed-off-by: David Arcari Cc: Len Brown Cc: linux-kernel@vger.kernel.org --- tools/power/x86/turbostat/turbostat.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbos= tat/turbostat.c index 5567b9ecd516..b3f1e4ae5813 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c @@ -8592,6 +8592,10 @@ void msr_perf_init_(void) continue; =20 if (cai->needed) { + /* check to see if APERF is available */ + if (cidx =3D=3D MSR_ARCH_INFO_APERF_INDEX && !has_aperf) + continue; + /* Use perf API for this counter */ if (add_msr_perf_counter(cpu, cci, cai) !=3D -1) { cci->source[cai->rci_index] =3D COUNTER_SOURCE_PERF; --=20 2.51.0