From nobody Fri Aug 14 15:49:49 2026 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 A0CE33446C4 for ; Fri, 14 Aug 2026 13:55:44 +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=1786715747; cv=none; b=Zv4DCsoObAL+yqV7MA31wBd2ZqIYouOp5QIX4mjSrmyXEFXwDEl+/Dk6lc8NUMIT+XU1NT6hU+6pmBCuiQaQ1aOWo9hyKGJ0Q68zFDssIrTHi2QZWaoH7wFVMWGuGE0Od0J7EmTAQcyCo6Tx+fPpOk2LIOye4l8oSWXdp8euOZU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786715747; c=relaxed/simple; bh=sc78Hk1btPXC49wnLAe1xrOecZn47e32z9aYl0gmmKk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oYlXtkCkH7abPV7WHRXjcwHRGppPAVXOKEsqshRMILWD7IV5BQFhMVNEcWYYe8d8JvwzQY2PTt9Z9kbXnFjReilFjwJUpDrBIupGeHznVz1M3nA27YMobE3557dgo+axEshR/ENWyl7GtZpXtgjO+fYStEwCqIk1HzrIOx0lauM= 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=et3zK/c2; 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="et3zK/c2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1786715742; 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=LpoJZM0WjsRFDkJiqJMu2NKVg5poGpYPGFQ5YIwFtG4=; b=et3zK/c2p1J0IAFY6iCOVNnZkMIxgr7BxcnkORFf7SN2U91FZkIM22bqSRLqmLpGGoksnW KkgikDZP55bC/JBRCvFY3yiZvqEXrjQEQ9vSNYGcMUb06pRJsI3vaHolR/RkXcrzmEQHks Hu4zGIB14YepsIQUNDN41o8qhXhNkco= Received: from mx-prod-mc-06.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-158-TxiFbgekOvCAkqrsDCZdgQ-1; Fri, 14 Aug 2026 09:55:38 -0400 X-MC-Unique: TxiFbgekOvCAkqrsDCZdgQ-1 X-Mimecast-MFC-AGG-ID: TxiFbgekOvCAkqrsDCZdgQ_1786715737 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 22FF21800747; Fri, 14 Aug 2026 13:55:37 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.44.33.92]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 84D131800347; Fri, 14 Aug 2026 13:55:33 +0000 (UTC) From: Tomas Glozar To: Steven Rostedt , Tomas Glozar Cc: John Kacur , Luis Goncalves , Crystal Wood , Costa Shulyupin , Wander Lairson Costa , LKML , linux-trace-kernel Subject: [PATCH 1/5] rtla: Replace get_nprocs_conf() with sysfs possible cpus Date: Fri, 14 Aug 2026 15:55:07 +0200 Message-ID: <20260814135511.2207190-2-tglozar@redhat.com> In-Reply-To: <20260814135511.2207190-1-tglozar@redhat.com> References: <20260814135511.2207190-1-tglozar@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.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" rtla uses get_nprocs_conf(), a standard libc routine, to retrieve the total number of CPUs for the purpose of processing per-CPU data. In some configurations, libc might return a different value than what is seen by the kernel. To cover for this situation, replace the call to get_nprocs_conf() with a newly added helper, get_possible_cpus(). get_possible_cpus() reads /sys/devices/system/cpu/possible and parses the CPU list, identically to what libbpf_num_possible_cpus() does. Additionally, it checks that the possible cpu list is zero-based and has no holes by computing both the cpu count and the maximum cpu number. Systems where /sys/.../cpu/possible is unreadable, is not zero-based, or has holes, now report an error instead of crashing later due to unmet assumptions. Note that parse_cpu_set() cannot be used to parse /sys/devices/system/cpu/possible, because it only supports CPU count of 1024 and lower. Higher CPU counts are not fully supported by rtla; nr_cpus > 1024 is, though, so it has to be covered by the new implementation in order to avoid a regression. A new function, cpu_list_iterate(), is added to utils.c to contain the cpu list parsing logic, which is now shared between the new function get_possible_cpus() and the pre-existing parse_cpu_set(). Assisted-by: Claude:claude-opus-4-6 Signed-off-by: Tomas Glozar --- tools/tracing/rtla/src/common.c | 16 +++- tools/tracing/rtla/src/utils.c | 165 +++++++++++++++++++++++++++----- tools/tracing/rtla/src/utils.h | 3 + 3 files changed, 156 insertions(+), 28 deletions(-) diff --git a/tools/tracing/rtla/src/common.c b/tools/tracing/rtla/src/commo= n.c index 8c7f5e75b2ec8..20fae1f19cacf 100644 --- a/tools/tracing/rtla/src/common.c +++ b/tools/tracing/rtla/src/common.c @@ -6,7 +6,6 @@ #include #include #include -#include =20 #include "common.h" =20 @@ -155,7 +154,20 @@ int run_tool(struct tool_ops *ops, int argc, char *arg= v[]) bool stopped; int retval; =20 - nr_cpus =3D get_nprocs_conf(); + nr_cpus =3D get_possible_cpus(); + if (nr_cpus =3D=3D -1) { + err_msg("Could not read number of possible cpus\n"); + goto out_exit; + } + if (nr_cpus =3D=3D -2) { + err_msg("Could not parse number of possible cpus\n"); + goto out_exit; + } + if (nr_cpus =3D=3D -3) { + err_msg("Unsupported non-contiguous or non-zero-based CPU topology\n"); + goto out_exit; + } + params =3D ops->parse_args(argc, argv); if (!params) exit(1); diff --git a/tools/tracing/rtla/src/utils.c b/tools/tracing/rtla/src/utils.c index cb187e7d48d1c..d65de511be9e1 100644 --- a/tools/tracing/rtla/src/utils.c +++ b/tools/tracing/rtla/src/utils.c @@ -108,57 +108,170 @@ void get_duration(time_t start_time, char *output, i= nt output_size) } =20 /* - * parse_cpu_set - parse a cpu_list filling cpu_set_t argument + * cpu_list_iterate - parse a cpu list and call a function on each element * - * Receives a cpu list, like 1-3,5 (cpus 1, 2, 3, 5), and then set - * filling cpu_set_t argument. + * If callback returns a non-zero value, the iteration is stopped. * - * Returns 0 on success, 1 otherwise. + * Returns the number of cpus in the list (including duplicates) on succes= s, + * callback return value on break, and -1 on error. */ -int parse_cpu_set(char *cpu_list, cpu_set_t *set) +int cpu_list_iterate(const char *cpu_list, int (*callback)(int, void *), v= oid *data) { const char *p; - int end_cpu; - int cpu; - int i; - - CPU_ZERO(set); + int i, cpu, end_cpu, count =3D 0, retval; =20 - for (p =3D cpu_list; *p; ) { + for (p =3D cpu_list; *p && *p !=3D '\n'; ) { cpu =3D atoi(p); - if (cpu < 0 || (!cpu && *p !=3D '0') || cpu >=3D nr_cpus) - goto err; + if (cpu < 0 || (!cpu && *p !=3D '0')) + return -1; =20 while (isdigit(*p)) p++; if (*p =3D=3D '-') { p++; end_cpu =3D atoi(p); - if (end_cpu < cpu || (!end_cpu && *p !=3D '0') || end_cpu >=3D nr_cpus) - goto err; + if (end_cpu < cpu || (!end_cpu && *p !=3D '0')) + return -1; while (isdigit(*p)) p++; } else end_cpu =3D cpu; =20 - if (cpu =3D=3D end_cpu) { - debug_msg("cpu_set: adding cpu %d\n", cpu); - CPU_SET(cpu, set); - } else { - for (i =3D cpu; i <=3D end_cpu; i++) { - debug_msg("cpu_set: adding cpu %d\n", i); - CPU_SET(i, set); - } + for (i =3D cpu; i <=3D end_cpu; i++) { + retval =3D callback(i, data); + if (retval) + return retval; + ++count; } =20 if (*p =3D=3D ',') p++; } =20 + return count; +} + +static int max_cpu_callback(int i, void *data) +{ + int *max_cpu =3D data; + + if (i > *max_cpu) + *max_cpu =3D i; + + return 0; +} + +static int tmp_cpu_set_callback(int i, void *data) +{ + bool *cpu_set =3D data; + + cpu_set[i] =3D true; + + return 0; +} + +/* + * get_possible_cpus - get the number of possible CPUs from sysfs + * + * Parse /sys/devices/system/cpu/possible to determine the number of + * possible CPUs. Only contiguous zero-based CPUs lists are accepted. + * + * Returns the number of possible CPUs, or a negative value on error: + * - -1 if the file is unreadable, + * - -2 if parsing failed, + * - -3 if the cpu list is non-zero-based or non-contiguous. + */ +int get_possible_cpus(void) +{ + char *str =3D NULL; + size_t len =3D 0; + int nr_cpus =3D 0, max_cpu =3D -1, i; + FILE *fp; + bool *cpu_set; + + fp =3D fopen("/sys/devices/system/cpu/possible", "r"); + if (!fp) + return -1; + + if (getline(&str, &len, fp) < 1) { + /* cpu string should be at least 1 character */ + if (str) + free(str); + fclose(fp); + return -1; + } + + fclose(fp); + + /* get maximum cpu number */ + if (cpu_list_iterate(str, max_cpu_callback, &max_cpu) < 0) { + free(str); + return -2; + } + + if (max_cpu < 0 || max_cpu =3D=3D INT_MAX) { + /* empty or bogus cpu list */ + free(str); + return -2; + } + + /* get max cpu using dynamic array, as nr_cpus might be > 1024 */ + cpu_set =3D calloc(max_cpu + 1, sizeof(bool)); + if (!cpu_set) { + free(str); + return -2; + } + if (cpu_list_iterate(str, tmp_cpu_set_callback, cpu_set) < 0) { + free(str); + free(cpu_set); + return -2; + } + for (i =3D 0; i <=3D max_cpu; i++) { + if (cpu_set[i]) + ++nr_cpus; + } + free(cpu_set); + + free(str); + + if (max_cpu >=3D nr_cpus) + /* rtla assumes cpu < nr_cpus for all cpus */ + return -3; + + return nr_cpus; +} + +static int cpu_set_callback(int i, void *data) +{ + cpu_set_t *set =3D data; + + if (i >=3D nr_cpus || i >=3D CPU_SETSIZE) + return -1; + + debug_msg("cpu_set: adding cpu %d\n", i); + CPU_SET(i, set); + + return 0; +} + +/* + * parse_cpu_set - parse a cpu_list filling cpu_set_t argument + * + * Receives a cpu list, like 1-3,5 (cpus 1, 2, 3, 5), and then set + * filling cpu_set_t argument. + * + * Returns 0 on success, 1 otherwise. + */ +int parse_cpu_set(char *cpu_list, cpu_set_t *set) +{ + CPU_ZERO(set); + + if (cpu_list_iterate(cpu_list, cpu_set_callback, set) < 0) { + debug_msg("Error parsing the cpu set %s\n", cpu_list); + return 1; + } + return 0; -err: - debug_msg("Error parsing the cpu set %s\n", cpu_list); - return 1; } =20 /* diff --git a/tools/tracing/rtla/src/utils.h b/tools/tracing/rtla/src/utils.h index 2ba3333669bb4..c26ba8827947a 100644 --- a/tools/tracing/rtla/src/utils.h +++ b/tools/tracing/rtla/src/utils.h @@ -47,6 +47,9 @@ void fatal(const char *fmt, ...); long parse_seconds_duration(char *val); void get_duration(time_t start_time, char *output, int output_size); =20 +int cpu_list_iterate(const char *cpu_list, int (*callback)(int, void *), v= oid *data); +int get_possible_cpus(void); + long long get_llong_from_str(char *start); =20 static inline void --=20 2.55.0 From nobody Fri Aug 14 15:49:49 2026 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 BFA0433B6D9 for ; Fri, 14 Aug 2026 13:55:57 +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=1786715762; cv=none; b=qod2wVzQqv5gsL3LPrKOTU/m9g/LODdDQVF996vIaSiVLRkNtPdL1BNbfmEXZG78zLSQPyWIokKkoPKlyVBvvYbFmHRmrCh7mjONVumE8s5ZMPNT6l6oBneiMmsSVmLg2IKEGcEDSDYmciXnnP+kYQTXsdt1+K4zgVOgpUlKhk0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786715762; c=relaxed/simple; bh=IRWyeDss8AzJXYcxQwjh6lwDI9oTvVnsq1azhn6lRHs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=d9jcDIvbitQ3eBykag3Odb8gpg9OA8CeKUwmQuT0ogoumNeoblwxp/FMI4aSiBbpalBhZCWzig3bc/GOPsRHvxRcEje/+PSvFrgAwia6dxCSoaPXJcC36w4qf/ya/Y/CUxIcR+4hGeuF85uwK0rElak96bua74/U5NGcuIbmoPw= 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=FZTnT4mY; 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="FZTnT4mY" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1786715755; 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=sQVggIH8ORhajW5nD23gxwpj3+1PtrZ19MQ1dN70VbM=; b=FZTnT4mYhivyg/gIxSApKM2N/BYKDyip6Lf6TINUomn2iuVdG8idEVA7pqwTvTNchaKZZq qngbhtG5qun9ffCDJ7PVK78CWeSr+99d+1BqAnOTHeQJs9Boopk85vXIcnvzhn5AMMzVD6 NWHLkefn9MyEpnerIUrCIOprYU4FWdk= Received: from mx-prod-mc-01.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-686-obtwRG-YPByfmqNbpuynIQ-1; Fri, 14 Aug 2026 09:55:41 -0400 X-MC-Unique: obtwRG-YPByfmqNbpuynIQ-1 X-Mimecast-MFC-AGG-ID: obtwRG-YPByfmqNbpuynIQ_1786715740 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8C710195605E; Fri, 14 Aug 2026 13:55:40 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.44.33.92]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 887671800347; Fri, 14 Aug 2026 13:55:37 +0000 (UTC) From: Tomas Glozar To: Steven Rostedt , Tomas Glozar Cc: John Kacur , Luis Goncalves , Crystal Wood , Costa Shulyupin , Wander Lairson Costa , LKML , linux-trace-kernel Subject: [PATCH 2/5] rtla: Discard trace entries with cpu >= nr_cpus Date: Fri, 14 Aug 2026 15:55:08 +0200 Message-ID: <20260814135511.2207190-3-tglozar@redhat.com> In-Reply-To: <20260814135511.2207190-1-tglozar@redhat.com> References: <20260814135511.2207190-1-tglozar@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.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" The "cpu" field of trace entries processed by rtla in tracefs mode is used as an index into an array of size nr_cpus. In case the cpu numbers mismatch because either the kernel or rtla reporting the number incorrectly, out-of-bounds read/write may occur. Guard against this by dropping trace entries with cpu >=3D nr_cpus in collect_registered_events(). A new counter, "invalid_events", is added to struct trace_instance, and printed (if non zero) next to the pre-existing missed events counter. Signed-off-by: Tomas Glozar --- tools/tracing/rtla/src/common.h | 2 -- tools/tracing/rtla/src/osnoise.c | 26 +++++++++++++++++++++++++- tools/tracing/rtla/src/osnoise.h | 2 ++ tools/tracing/rtla/src/osnoise_hist.c | 1 + tools/tracing/rtla/src/osnoise_top.c | 1 + tools/tracing/rtla/src/timerlat_hist.c | 1 + tools/tracing/rtla/src/timerlat_top.c | 1 + tools/tracing/rtla/src/trace.c | 7 +++++++ tools/tracing/rtla/src/trace.h | 1 + tools/tracing/rtla/src/utils.h | 2 ++ 10 files changed, 41 insertions(+), 3 deletions(-) diff --git a/tools/tracing/rtla/src/common.h b/tools/tracing/rtla/src/commo= n.h index 04b287a03f6d4..051d56182276b 100644 --- a/tools/tracing/rtla/src/common.h +++ b/tools/tracing/rtla/src/common.h @@ -114,8 +114,6 @@ struct common_params { struct timerlat_u_params user; }; =20 -extern int nr_cpus; - #define for_each_monitored_cpu(cpu, common) \ for (cpu =3D 0; cpu < nr_cpus; cpu++) \ if (!(common)->cpus || CPU_ISSET(cpu, &(common)->monitored_cpus)) diff --git a/tools/tracing/rtla/src/osnoise.c b/tools/tracing/rtla/src/osno= ise.c index 4ff5dad013b10..b9bcbf9ee430c 100644 --- a/tools/tracing/rtla/src/osnoise.c +++ b/tools/tracing/rtla/src/osnoise.c @@ -1224,6 +1224,29 @@ bool osnoise_trace_is_off(struct osnoise_tool *tool,= struct osnoise_tool *record return record && !tracefs_trace_is_on(record->trace.inst); } =20 +/* + * osnoise_report_invalid_events - report number of invalid events + */ +void +osnoise_report_invalid_events(struct osnoise_tool *tool) +{ + unsigned long long total_events; + + if (tool->trace.invalid_events > 0) { + if (tool->trace.missed_events !=3D UINT64_MAX) { + total_events =3D tool->trace.processed_events + tool->trace.invalid_eve= nts + + tool->trace.missed_events; + + printf("%lld (%.2f%%) invalid events, results might not be accurate\n", + tool->trace.invalid_events, + (double) tool->trace.invalid_events / total_events * 100.0); + } else { + printf("%lld invalid events, results might not be accurate\n", + tool->trace.invalid_events); + } + } +} + /* * osnoise_report_missed_events - report number of events dropped by trace * buffer @@ -1236,7 +1259,8 @@ osnoise_report_missed_events(struct osnoise_tool *too= l) if (tool->trace.missed_events =3D=3D UINT64_MAX) printf("unknown number of events missed, results might not be accurate\n= "); else if (tool->trace.missed_events > 0) { - total_events =3D tool->trace.processed_events + tool->trace.missed_event= s; + total_events =3D tool->trace.processed_events + tool->trace.invalid_even= ts + + tool->trace.missed_events; =20 printf("%lld (%.2f%%) events missed, results might not be accurate\n", tool->trace.missed_events, diff --git a/tools/tracing/rtla/src/osnoise.h b/tools/tracing/rtla/src/osno= ise.h index 340ff5a64e6e4..b54e9ebef7f27 100644 --- a/tools/tracing/rtla/src/osnoise.h +++ b/tools/tracing/rtla/src/osnoise.h @@ -56,6 +56,8 @@ void osnoise_restore_timerlat_align_us(struct osnoise_con= text *context); int osnoise_set_timerlat_align(struct osnoise_context *context, bool onoff= ); =20 int osnoise_set_irq_disable(struct osnoise_context *context, bool onoff); + +void osnoise_report_invalid_events(struct osnoise_tool *tool); void osnoise_report_missed_events(struct osnoise_tool *tool); int osnoise_apply_config(struct osnoise_tool *tool, struct osnoise_params = *params); =20 diff --git a/tools/tracing/rtla/src/osnoise_hist.c b/tools/tracing/rtla/src= /osnoise_hist.c index dfa91d0681f8f..bad0b8958ddb2 100644 --- a/tools/tracing/rtla/src/osnoise_hist.c +++ b/tools/tracing/rtla/src/osnoise_hist.c @@ -397,6 +397,7 @@ osnoise_print_stats(struct osnoise_tool *tool) trace_seq_reset(trace->seq); =20 osnoise_print_summary(params, trace, data); + osnoise_report_invalid_events(tool); osnoise_report_missed_events(tool); } =20 diff --git a/tools/tracing/rtla/src/osnoise_top.c b/tools/tracing/rtla/src/= osnoise_top.c index 512a6299cb018..3c0ff82a4b5c8 100644 --- a/tools/tracing/rtla/src/osnoise_top.c +++ b/tools/tracing/rtla/src/osnoise_top.c @@ -242,6 +242,7 @@ osnoise_print_stats(struct osnoise_tool *top) =20 trace_seq_do_printf(trace->seq); trace_seq_reset(trace->seq); + osnoise_report_invalid_events(top); osnoise_report_missed_events(top); } =20 diff --git a/tools/tracing/rtla/src/timerlat_hist.c b/tools/tracing/rtla/sr= c/timerlat_hist.c index df7b1398a966d..b6af5ba11340d 100644 --- a/tools/tracing/rtla/src/timerlat_hist.c +++ b/tools/tracing/rtla/src/timerlat_hist.c @@ -682,6 +682,7 @@ timerlat_print_stats(struct osnoise_tool *tool) =20 timerlat_print_summary(params, trace, data); timerlat_print_stats_all(params, trace, data); + osnoise_report_invalid_events(tool); osnoise_report_missed_events(tool); } =20 diff --git a/tools/tracing/rtla/src/timerlat_top.c b/tools/tracing/rtla/src= /timerlat_top.c index 6206a0a565ad3..2afd619c16059 100644 --- a/tools/tracing/rtla/src/timerlat_top.c +++ b/tools/tracing/rtla/src/timerlat_top.c @@ -456,6 +456,7 @@ timerlat_print_stats(struct osnoise_tool *top) =20 trace_seq_do_printf(trace->seq); trace_seq_reset(trace->seq); + osnoise_report_invalid_events(top); osnoise_report_missed_events(top); } =20 diff --git a/tools/tracing/rtla/src/trace.c b/tools/tracing/rtla/src/trace.c index e407447773d04..1c3e2b098ba81 100644 --- a/tools/tracing/rtla/src/trace.c +++ b/tools/tracing/rtla/src/trace.c @@ -138,6 +138,12 @@ collect_registered_events(struct tep_event *event, str= uct tep_record *record, struct trace_instance *trace =3D context; struct trace_seq *s =3D trace->seq; =20 + if (cpu >=3D nr_cpus) { + /* Kernel reports event on CPU we don't see, corrupt data? */ + trace->invalid_events++; + return 0; + } + trace->processed_events++; =20 if (!event->handler) @@ -236,6 +242,7 @@ int trace_instance_init(struct trace_instance *trace, c= har *tool_name) trace); =20 trace->processed_events =3D 0; + trace->invalid_events =3D 0; =20 return 0; =20 diff --git a/tools/tracing/rtla/src/trace.h b/tools/tracing/rtla/src/trace.h index 95b911a2228b2..715a3616fe45a 100644 --- a/tools/tracing/rtla/src/trace.h +++ b/tools/tracing/rtla/src/trace.h @@ -18,6 +18,7 @@ struct trace_instance { struct tep_handle *tep; struct trace_seq *seq; unsigned long long missed_events; + unsigned long long invalid_events; unsigned long long processed_events; }; =20 diff --git a/tools/tracing/rtla/src/utils.h b/tools/tracing/rtla/src/utils.h index c26ba8827947a..2579e7fa08be6 100644 --- a/tools/tracing/rtla/src/utils.h +++ b/tools/tracing/rtla/src/utils.h @@ -40,6 +40,8 @@ static inline bool str_has_prefix(const char *str, const = char *prefix) } =20 extern bool config_debug; +extern int nr_cpus; + void debug_msg(const char *fmt, ...); void err_msg(const char *fmt, ...); void fatal(const char *fmt, ...); --=20 2.55.0 From nobody Fri Aug 14 15:49:49 2026 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 BFFEA14883F for ; Fri, 14 Aug 2026 13:55:48 +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=1786715753; cv=none; b=Itc7N1wkbvdUqY4NEd6xM4p/qNg/8tSqLQm/q+PygveBn9nJ9Uppq4FUps7ScZLhEY2pk+dDmEUkxUI/5lvdkz3jVTJhf2bCbuiiZn2oi7qOywHeTTiq6tAk7EWCodbNLS19i8Zq+4Fk4ZhFNUC25G2/eE7OQuBt3S5IV/Nb/nY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786715753; c=relaxed/simple; bh=fCLTiOBENvUUe9H0p5H9gkzGaABR4ynPRP1JIHswk4o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=q99pQpyGqbic2SjuFq78XLuNCW1nm0ClQnuJMCcMypxC2ckXVj/6soeLI0i5ksLqEG4coab0Pxvk925SiAi9/XYuM+9QbLMU6k7qwvU+0qm4XiIsHFTn+Leuzz3ApFWWDvXAwbQ8ksox2mIUutPW9+3xWzF4T8Ss/+6vzEckm6I= 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=Th8a4wYz; 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="Th8a4wYz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1786715746; 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=OA6jv8a18DKvdeZ22MpfaNca4IXwtYVOTfHHp+Fdd64=; b=Th8a4wYzX4/0wVzrV4iD7FnXOtzVJvWKLR7aGg+oLBkqJy2Y89ahGPWSQyTw5vgOIZtQqh 1h1aM9FeUzCP33bvnmdk7yuGQinTSqle69qKDySZxMWg826XIZqPGLrDQZ5x517yHXOuFl hMXpoAPwTdWCCD+w/qlgeO3F56AJAAU= 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-90-bNAVD2RGNNGn42OWGE3QiA-1; Fri, 14 Aug 2026 09:55:45 -0400 X-MC-Unique: bNAVD2RGNNGn42OWGE3QiA-1 X-Mimecast-MFC-AGG-ID: bNAVD2RGNNGn42OWGE3QiA_1786715744 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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 10A3C180034C; Fri, 14 Aug 2026 13:55:44 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.44.33.92]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id F11C91800347; Fri, 14 Aug 2026 13:55:40 +0000 (UTC) From: Tomas Glozar To: Steven Rostedt , Tomas Glozar Cc: John Kacur , Luis Goncalves , Crystal Wood , Costa Shulyupin , Wander Lairson Costa , LKML , linux-trace-kernel Subject: [PATCH 3/5] rtla: Abort on nr_cpus mismatch with tracer Date: Fri, 14 Aug 2026 15:55:09 +0200 Message-ID: <20260814135511.2207190-4-tglozar@redhat.com> In-Reply-To: <20260814135511.2207190-1-tglozar@redhat.com> References: <20260814135511.2207190-1-tglozar@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.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" In rare situations, sysfs might report a different number of CPUs than the kernel sees, for example, when /sys is not real sysfs. In tracefs mode, RTLA will discard any samples that are reported on CPUs higher than the maximum in sysfs. However, in BPF mode, the incorrectly sized BPF_MAP_LOOKUP_ELEM syscall on percpu maps will cause a buffer overflow. To cover for this corner case, write "all" to osnoise/cpus, and read back the real kernel-side list of all possible cpus. If it doesn't match RTLA's nr_cpus (read from sysfs), abort with an error. Assisted-by: Claude:claude-opus-4-6 Signed-off-by: Tomas Glozar --- tools/tracing/rtla/src/common.c | 13 +++++++++- tools/tracing/rtla/src/common.h | 1 + tools/tracing/rtla/src/osnoise.c | 44 ++++++++++++++++++++++++++++++++ tools/tracing/rtla/src/utils.c | 16 ++++++++++++ tools/tracing/rtla/src/utils.h | 1 + 5 files changed, 74 insertions(+), 1 deletion(-) diff --git a/tools/tracing/rtla/src/common.c b/tools/tracing/rtla/src/commo= n.c index 20fae1f19cacf..2a5333270e035 100644 --- a/tools/tracing/rtla/src/common.c +++ b/tools/tracing/rtla/src/common.c @@ -62,11 +62,22 @@ static void unset_signals(struct common_params *params) int common_apply_config(struct osnoise_tool *tool, struct common_params *param= s) { - int retval, i; + int retval, i, tracer_cpus; =20 if (!params->sleep_time) params->sleep_time =3D 1; =20 + tracer_cpus =3D osnoise_get_cpu_count(); + if (tracer_cpus < 0) { + err_msg("Failed to get tracer cpu count from osnoise/cpus\n"); + goto out_err; + } + if (tracer_cpus !=3D nr_cpus) { + err_msg("Kernel reports %d cpus but rtla sees %d\n", + tracer_cpus, nr_cpus); + goto out_err; + } + retval =3D osnoise_set_cpus(tool->context, params->cpus ? params->cpus : = "all"); if (retval) { err_msg("Failed to apply CPUs config\n"); diff --git a/tools/tracing/rtla/src/common.h b/tools/tracing/rtla/src/commo= n.h index 051d56182276b..a7a9063c302b5 100644 --- a/tools/tracing/rtla/src/common.h +++ b/tools/tracing/rtla/src/common.h @@ -168,6 +168,7 @@ should_continue_tracing(const struct common_params *par= ams) int common_threshold_handler(const struct osnoise_tool *tool); =20 +int osnoise_get_cpu_count(void); int osnoise_set_cpus(struct osnoise_context *context, char *cpus); void osnoise_restore_cpus(struct osnoise_context *context); =20 diff --git a/tools/tracing/rtla/src/osnoise.c b/tools/tracing/rtla/src/osno= ise.c index b9bcbf9ee430c..5a746bc11f03b 100644 --- a/tools/tracing/rtla/src/osnoise.c +++ b/tools/tracing/rtla/src/osnoise.c @@ -124,6 +124,50 @@ void osnoise_put_cpus(struct osnoise_context *context) context->orig_cpus =3D NULL; } =20 +/* + * osnoise_get_cpu_count - get the number of CPUs as seen by the osnoise t= racer + * + * Write "all" to osnoise/cpus and read back the real kernel-side list + * of all possible cpus. Restore the original value afterwards. + * + * Returns the number of CPUs, or -1 on error. + */ +int osnoise_get_cpu_count(void) +{ + char *orig, *readback; + int max_cpu; + + orig =3D tracefs_instance_file_read(NULL, "osnoise/cpus", NULL); + if (!orig) + return -1; + + if (tracefs_instance_file_write(NULL, "osnoise/cpus", "all\n") < 0) { + free(orig); + return -1; + } + + readback =3D tracefs_instance_file_read(NULL, "osnoise/cpus", NULL); + if (!readback) { + tracefs_instance_file_write(NULL, "osnoise/cpus", orig); + free(orig); + return -1; + } + + max_cpu =3D get_max_cpu_from_list(readback); + free(readback); + + if (tracefs_instance_file_write(NULL, "osnoise/cpus", orig) < 0) { + free(orig); + return -1; + } + free(orig); + + if (max_cpu < 0) + return -1; + + return max_cpu + 1; +} + /* * osnoise_read_ll_config - read a long long value from a config * diff --git a/tools/tracing/rtla/src/utils.c b/tools/tracing/rtla/src/utils.c index d65de511be9e1..5d91c9151aa4a 100644 --- a/tools/tracing/rtla/src/utils.c +++ b/tools/tracing/rtla/src/utils.c @@ -161,6 +161,22 @@ static int max_cpu_callback(int i, void *data) return 0; } =20 +/* + * get_max_cpu_from_list - get the maximum CPU in a CPU list + * + * Returns maximum CPU number, or -1 on error + */ +int get_max_cpu_from_list(const char *cpu_list) +{ + int max_cpu =3D -1; + + if (cpu_list_iterate(cpu_list, max_cpu_callback, &max_cpu) < 0) + return -1; + + return max_cpu; +} + + static int tmp_cpu_set_callback(int i, void *data) { bool *cpu_set =3D data; diff --git a/tools/tracing/rtla/src/utils.h b/tools/tracing/rtla/src/utils.h index 2579e7fa08be6..44b450645ffb5 100644 --- a/tools/tracing/rtla/src/utils.h +++ b/tools/tracing/rtla/src/utils.h @@ -50,6 +50,7 @@ long parse_seconds_duration(char *val); void get_duration(time_t start_time, char *output, int output_size); =20 int cpu_list_iterate(const char *cpu_list, int (*callback)(int, void *), v= oid *data); +int get_max_cpu_from_list(const char *cpu_list); int get_possible_cpus(void); =20 long long get_llong_from_str(char *start); --=20 2.55.0 From nobody Fri Aug 14 15:49:49 2026 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 F21C9345EB4 for ; Fri, 14 Aug 2026 13:55:53 +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=1786715757; cv=none; b=CVnK7RgGfhO3CVe3+GqYNxIhGpASk/vBWa/9QVx7mjqb5oOQpZfgG+7tLh3bPG7cJgc5WNUdSRpuI6+KC0qB6x9uxcx9jlZEEylXnkVl+tsgBk9M/n0i7QKqxWa7SvItbB1nCq/jOaOkc70C7uRk0uht4iDJ+yqWg1NP3ak74nw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786715757; c=relaxed/simple; bh=Kq5E/r9tg+1yGMrhP87SYXj2ZfJSQrGUexdSTHbexAU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p5j/FTOF+2604Pz80QUDtkma9bwwapC9PRiFO+5I2XbAQSA10cAZXn+GBUCAfisZoSVkg7/YDIv+5OHTkYaQzPy5AT5y51f39s1DmV4bfduslDoUr3iLTZdzdzbE2BPz9QiqOA18ToexactbnWAip6DRidCt5VuiZvjRzP/KgcM= 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=Pict9MUe; 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="Pict9MUe" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1786715751; 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=XjtevNBfIqkJxOx4BwwiGXQRrfIgcwR4eI1yjAuHNrU=; b=Pict9MUe+Oaz6XmU64mltIWRldgUvGcSHfuvUjTqoaWcP5hZpqqyXs4KA2wJsVE5zxuhzY a0gGu9WrdgK9r2PkJt+DCsFuq2ciIz/kEbib7A+miRemmQGX0MpoXBjeiwxZGp8QjH9LJ8 4ZO9UhfUqqzArxgZdcWwfYKNYC0hnHs= Received: from mx-prod-mc-06.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-513-arhCGr2KOriDueH4imAo1w-1; Fri, 14 Aug 2026 09:55:48 -0400 X-MC-Unique: arhCGr2KOriDueH4imAo1w-1 X-Mimecast-MFC-AGG-ID: arhCGr2KOriDueH4imAo1w_1786715747 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8AD601800115; Fri, 14 Aug 2026 13:55:47 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.44.33.92]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 74629180049F; Fri, 14 Aug 2026 13:55:44 +0000 (UTC) From: Tomas Glozar To: Steven Rostedt , Tomas Glozar Cc: John Kacur , Luis Goncalves , Crystal Wood , Costa Shulyupin , Wander Lairson Costa , LKML , linux-trace-kernel Subject: [PATCH 4/5] rtla/tests: Add unit test for cpu_list_iterate() Date: Fri, 14 Aug 2026 15:55:10 +0200 Message-ID: <20260814135511.2207190-5-tglozar@redhat.com> In-Reply-To: <20260814135511.2207190-1-tglozar@redhat.com> References: <20260814135511.2207190-1-tglozar@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.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" cpu_list_iterate() was split out of parse_cpu_set() to hold shared code between it and the newly added function get_possible_cpus(). As its semantics are more complex than parse_cpu_set() - it calls a callback on each element of the list, with possible abort on failure, while parse_cpu_set() cares only about the set defined by the list - it deserves its own test. Test the callback being called correctly as well as the return value and early break on different combinations of comma-separated numbers and ranges. Signed-off-by: Tomas Glozar --- tools/tracing/rtla/tests/unit/utils.c | 62 +++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/tools/tracing/rtla/tests/unit/utils.c b/tools/tracing/rtla/tes= ts/unit/utils.c index ce53cab494575..0cb5e217c56eb 100644 --- a/tools/tracing/rtla/tests/unit/utils.c +++ b/tools/tracing/rtla/tests/unit/utils.c @@ -34,6 +34,67 @@ START_TEST(test_strtoi) } END_TEST =20 +struct cpu_list_iterate_cb_data { + int index; + int *values; +}; + +static int cpu_list_iterate_callback(int cpu, void *data) +{ + struct cpu_list_iterate_cb_data *cb_data =3D data; + + ck_assert_int_eq(cpu, cb_data->values[cb_data->index++]); + + return 0; +} + +static int cpu_list_iterate_callback_error(int cpu, void *data) +{ + struct cpu_list_iterate_cb_data *cb_data =3D data; + + if (cpu > 10) + return -42; + + ck_assert_int_eq(cpu, cb_data->values[cb_data->index++]); + + return 0; +} + +START_TEST(test_cpu_list_iterate) +{ + struct cpu_list_iterate_cb_data cb_data; + int test_data_1[] =3D {1, 2, 3, 4}; + int test_data_2[] =3D {1, 2, 10, 11, 12}; + + cb_data.index =3D 0; + + cb_data.values =3D test_data_1; + ck_assert_int_eq(cpu_list_iterate("1,2,3,4", cpu_list_iterate_callback, &= cb_data), 4); + ck_assert_int_eq(cb_data.index, 4); + cb_data.index =3D 0; + ck_assert_int_eq(cpu_list_iterate("1-4", cpu_list_iterate_callback, &cb_d= ata), 4); + ck_assert_int_eq(cb_data.index, 4); + cb_data.index =3D 0; + ck_assert_int_eq(cpu_list_iterate("1,2-3,4", cpu_list_iterate_callback, &= cb_data), 4); + ck_assert_int_eq(cb_data.index, 4); + cb_data.index =3D 0; + ck_assert_int_eq(cpu_list_iterate("1-3,4", cpu_list_iterate_callback, &cb= _data), 4); + ck_assert_int_eq(cb_data.index, 4); + cb_data.index =3D 0; + ck_assert_int_eq(cpu_list_iterate("1,2-4", cpu_list_iterate_callback, &cb= _data), 4); + ck_assert_int_eq(cb_data.index, 4); + + cb_data.index =3D 0; + ck_assert_int_eq(cpu_list_iterate("1,2-4", cpu_list_iterate_callback_erro= r, &cb_data), 4); + ck_assert_int_eq(cb_data.index, 4); + cb_data.index =3D 0; + cb_data.values =3D test_data_2; + ck_assert_int_eq(cpu_list_iterate("1,2,10-12", cpu_list_iterate_callback_= error, &cb_data), + -42); + ck_assert_int_eq(cb_data.index, 3); +} +END_TEST + START_TEST(test_parse_cpu_set) { cpu_set_t set; @@ -98,6 +159,7 @@ Suite *utils_suite(void) TCase *tc =3D tcase_create("core"); =20 tcase_add_test(tc, test_strtoi); + tcase_add_test(tc, test_cpu_list_iterate); tcase_add_test(tc, test_parse_cpu_set); tcase_add_test(tc, test_parse_prio); =20 --=20 2.55.0 From nobody Fri Aug 14 15:49:49 2026 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 4527734C98C for ; Fri, 14 Aug 2026 13:55:57 +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=1786715762; cv=none; b=byIG56RhF9tIUDmAJSFLFky8aGk+QF5egmaGQ/XiD6mJ0xogxZhdQLf+2xfuuSlpqvssxeMdy+i6Xl1mBsXYpOsmol5JdY7mRQCDV8NwWZ6ZACFdAD+zMUMIXcA2LzyqnAdJ1WOS0oWbc2ISURoNFIW6t6dCadowFtE22Msj1Rc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786715762; c=relaxed/simple; bh=Y/5SyS3gwj9KjuvhfhI5U5SNRgbHxgZHdzwTve78Emo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PuGPKAv88yhQ+toGMjFgi4+Cq5pE4QWQPxMlZqG5lS7k0EdCLuKdeZddHcOnWLYbT1Q+rYLP1Q4u1JmI8CBofxR8ZWo/HDnCxbFKT6lSMDz28JFgKD6y6sz6Ad2dc72cdtOAxWg8XyvF66xiKHBDzITq8wY76QS04Qy9mEawimM= 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=OtSxoXiu; 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="OtSxoXiu" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1786715756; 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=Qwll/rx1QVHE0RLr1ij+LcJY3pppLEwm58AIGj5D33k=; b=OtSxoXiufw/8EZqjoc11wHFgFxUocuROG1mYbmc1DiVPubxOe+sDh9oXxXYbrP/mxiFDuz msfTOoYWp9F1AGI1mB79oj/ndPPQFrqKhVBLzPgEvaHR5ZrMNGTB/MxB5oxnHpwBBaf+0i oxhGsil+q4+XOC5SRhiEi8Aj6dZ5+io= Received: from mx-prod-mc-01.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-634-T1c88Km9M9GqnCtG3iDVPQ-1; Fri, 14 Aug 2026 09:55:52 -0400 X-MC-Unique: T1c88Km9M9GqnCtG3iDVPQ-1 X-Mimecast-MFC-AGG-ID: T1c88Km9M9GqnCtG3iDVPQ_1786715751 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3D9A619560A5; Fri, 14 Aug 2026 13:55:51 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.44.33.92]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id ECBCA18005AC; Fri, 14 Aug 2026 13:55:47 +0000 (UTC) From: Tomas Glozar To: Steven Rostedt , Tomas Glozar Cc: John Kacur , Luis Goncalves , Crystal Wood , Costa Shulyupin , Wander Lairson Costa , LKML , linux-trace-kernel Subject: [PATCH 5/5] rtla/tests: Add unit test for get_max_cpu_from_list() Date: Fri, 14 Aug 2026 15:55:11 +0200 Message-ID: <20260814135511.2207190-6-tglozar@redhat.com> In-Reply-To: <20260814135511.2207190-1-tglozar@redhat.com> References: <20260814135511.2207190-1-tglozar@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.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" The get_max_cpu_from_list() function is used when parsing osnoise cpus "all" value. Furthermore, the callback used by it is also used in get_possible_cpus(). Add unit test to cover it. Signed-off-by: Tomas Glozar --- tools/tracing/rtla/tests/unit/utils.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tools/tracing/rtla/tests/unit/utils.c b/tools/tracing/rtla/tes= ts/unit/utils.c index 0cb5e217c56eb..cdd84ff895f86 100644 --- a/tools/tracing/rtla/tests/unit/utils.c +++ b/tools/tracing/rtla/tests/unit/utils.c @@ -95,6 +95,14 @@ START_TEST(test_cpu_list_iterate) } END_TEST =20 +START_TEST(test_get_max_cpu_from_list) +{ + ck_assert_int_eq(get_max_cpu_from_list("1,2,3,4-60"), 60); + ck_assert_int_eq(get_max_cpu_from_list("2,1-7,4"), 7); + ck_assert_int_eq(get_max_cpu_from_list("invalid"), -1); +} +END_TEST + START_TEST(test_parse_cpu_set) { cpu_set_t set; @@ -160,6 +168,7 @@ Suite *utils_suite(void) =20 tcase_add_test(tc, test_strtoi); tcase_add_test(tc, test_cpu_list_iterate); + tcase_add_test(tc, test_get_max_cpu_from_list); tcase_add_test(tc, test_parse_cpu_set); tcase_add_test(tc, test_parse_prio); =20 --=20 2.55.0