From nobody Tue Dec 2 02:05:05 2025 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 41EE930DEDA for ; Thu, 20 Nov 2025 23:26:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763681196; cv=none; b=kR2g3wGQIF3WZtrgwrDOCmPv1dYxW1hQ9lxk0Teztx1GKe1YTUTKaR6lkzZCySJLfjLJ3EnQj5mkH8DnmpTXa5bPcYTx/SdOLoxqGDGbPqeGs9ggSUHOFQwyPZ4KB2Yh5WvVbSlX5acBJBclfiIcVlD7VV3uVHGCjeW5dBpaD9U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763681196; c=relaxed/simple; bh=l8YdlGSfYeDzi08psyKsFgI5OUrS901LyOtTIHZxdlw=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=Ax7avqtbWtuva7bGMZajzcgWioL0DPmQfvuo0DOt3AMZ8VlQ/b5yyLFge0xRVKLRkhZ8MAcZUXu4x+C+T4/n9j8WCETDM5dHrKiFCO+6ynVJECsDYGjqPDY/mtn2BlBnCSf963uzSOzolGKKma1HMk0xgMqJlVv2MQQPvgX6d6w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WmQ1nD7k; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="WmQ1nD7k" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A751BC113D0; Thu, 20 Nov 2025 23:26:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1763681195; bh=l8YdlGSfYeDzi08psyKsFgI5OUrS901LyOtTIHZxdlw=; h=Date:From:To:Cc:Subject:References:From; b=WmQ1nD7kJ/HaFnLaxmKEVByf9SwotfzEgzejI2zUqJPF7aS4Vgt8zqIA7q1Ldr1fA 3TGjLP2ZfT+JFb0ccq2fm0f/cdFWlTDHR8RKDoDAs9xKnNcjBJyUYlInK7T/amoowR 4we2zaA/ctZ8HrBDKUwo7j7dHY7wU8rw5O8Hcs2hUlpdCGIJDfeD+QLhAc6Bv1MZpT lmHh3/pZHmwfMSLJ5GYb2X0mJyC75PkUyX8hwkSSJ7OrPkC8MDQTZfAG97tTqTmXrI dyj+RHa9IpZzZ4X2xTgYyYQVN3NNhswCPQuEeQKnPK4+hBwxL+d2IHXykQmWEo8urU B5qbn2tW03tNQ== Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1vME3Q-000000041uA-3CVN; Thu, 20 Nov 2025 18:27:08 -0500 Message-ID: <20251120232708.614239181@kernel.org> User-Agent: quilt/0.68 Date: Thu, 20 Nov 2025 18:23:31 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Tomas Glozar , John Kacur , Costa Shulyupin Subject: [for-next][PATCH 08/16] tools/rtla: Add fatal() and replace error handling pattern References: <20251120232323.271532418@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: quoted-printable Content-Type: text/plain; charset="utf-8" From: Costa Shulyupin The code contains some technical debt in error handling, which complicates the consolidation of duplicated code. Introduce an fatal() function to replace the common pattern of err_msg() followed by exit(EXIT_FAILURE), reducing the length of an already long function. Further patches using fatal() follow. Signed-off-by: Costa Shulyupin Reviewed-by: Tomas Glozar Link: https://lore.kernel.org/r/20251011082738.173670-2-costa.shul@redhat.c= om Signed-off-by: Tomas Glozar --- tools/tracing/rtla/src/osnoise_hist.c | 42 ++++++++-------------- tools/tracing/rtla/src/osnoise_top.c | 42 ++++++++-------------- tools/tracing/rtla/src/timerlat_hist.c | 50 +++++++++----------------- tools/tracing/rtla/src/timerlat_top.c | 48 +++++++++---------------- tools/tracing/rtla/src/timerlat_u.c | 12 +++---- tools/tracing/rtla/src/utils.c | 15 ++++++++ tools/tracing/rtla/src/utils.h | 1 + 7 files changed, 81 insertions(+), 129 deletions(-) diff --git a/tools/tracing/rtla/src/osnoise_hist.c b/tools/tracing/rtla/src= /osnoise_hist.c index df0657b78980..d30a9a03b764 100644 --- a/tools/tracing/rtla/src/osnoise_hist.c +++ b/tools/tracing/rtla/src/osnoise_hist.c @@ -575,10 +575,8 @@ static struct common_params break; case 'e': tevent =3D trace_event_alloc(optarg); - if (!tevent) { - err_msg("Error alloc trace event"); - exit(EXIT_FAILURE); - } + if (!tevent) + fatal("Error alloc trace event"); =20 if (params->common.events) tevent->next =3D params->common.events; @@ -598,10 +596,8 @@ static struct common_params case 'H': params->common.hk_cpus =3D 1; retval =3D parse_cpu_set(optarg, ¶ms->common.hk_cpu_set); - if (retval) { - err_msg("Error parsing house keeping CPUs\n"); - exit(EXIT_FAILURE); - } + if (retval) + fatal("Error parsing house keeping CPUs"); break; case 'p': params->period =3D get_llong_from_str(optarg); @@ -654,10 +650,8 @@ static struct common_params case '4': /* trigger */ if (params->common.events) { retval =3D trace_event_add_trigger(params->common.events, optarg); - if (retval) { - err_msg("Error adding trigger %s\n", optarg); - exit(EXIT_FAILURE); - } + if (retval) + fatal("Error adding trigger %s", optarg); } else { osnoise_hist_usage("--trigger requires a previous -e\n"); } @@ -665,10 +659,8 @@ static struct common_params case '5': /* filter */ if (params->common.events) { retval =3D trace_event_add_filter(params->common.events, optarg); - if (retval) { - err_msg("Error adding filter %s\n", optarg); - exit(EXIT_FAILURE); - } + if (retval) + fatal("Error adding filter %s", optarg); } else { osnoise_hist_usage("--filter requires a previous -e\n"); } @@ -682,18 +674,14 @@ static struct common_params case '8': retval =3D actions_parse(¶ms->common.threshold_actions, optarg, "osnoise_trace.txt"); - if (retval) { - err_msg("Invalid action %s\n", optarg); - exit(EXIT_FAILURE); - } + if (retval) + fatal("Invalid action %s", optarg); break; case '9': retval =3D actions_parse(¶ms->common.end_actions, optarg, "osnoise_trace.txt"); - if (retval) { - err_msg("Invalid action %s\n", optarg); - exit(EXIT_FAILURE); - } + if (retval) + fatal("Invalid action %s", optarg); break; default: osnoise_hist_usage("Invalid option"); @@ -703,10 +691,8 @@ static struct common_params if (trace_output) actions_add_trace_output(¶ms->common.threshold_actions, trace_output= ); =20 - if (geteuid()) { - err_msg("rtla needs root permission\n"); - exit(EXIT_FAILURE); - } + if (geteuid()) + fatal("rtla needs root permission"); =20 if (params->common.hist.no_index && !params->common.hist.with_zeros) osnoise_hist_usage("no-index set and with-zeros not set - it does not ma= ke sense"); diff --git a/tools/tracing/rtla/src/osnoise_top.c b/tools/tracing/rtla/src/= osnoise_top.c index 1b5181e66b17..487daac8908c 100644 --- a/tools/tracing/rtla/src/osnoise_top.c +++ b/tools/tracing/rtla/src/osnoise_top.c @@ -421,10 +421,8 @@ struct common_params *osnoise_top_parse_args(int argc,= char **argv) break; case 'e': tevent =3D trace_event_alloc(optarg); - if (!tevent) { - err_msg("Error alloc trace event"); - exit(EXIT_FAILURE); - } + if (!tevent) + fatal("Error alloc trace event"); =20 if (params->common.events) tevent->next =3D params->common.events; @@ -438,10 +436,8 @@ struct common_params *osnoise_top_parse_args(int argc,= char **argv) case 'H': params->common.hk_cpus =3D 1; retval =3D parse_cpu_set(optarg, ¶ms->common.hk_cpu_set); - if (retval) { - err_msg("Error parsing house keeping CPUs\n"); - exit(EXIT_FAILURE); - } + if (retval) + fatal("Error parsing house keeping CPUs"); break; case 'p': params->period =3D get_llong_from_str(optarg); @@ -485,10 +481,8 @@ struct common_params *osnoise_top_parse_args(int argc,= char **argv) case '0': /* trigger */ if (params->common.events) { retval =3D trace_event_add_trigger(params->common.events, optarg); - if (retval) { - err_msg("Error adding trigger %s\n", optarg); - exit(EXIT_FAILURE); - } + if (retval) + fatal("Error adding trigger %s", optarg); } else { osnoise_top_usage(params, "--trigger requires a previous -e\n"); } @@ -496,10 +490,8 @@ struct common_params *osnoise_top_parse_args(int argc,= char **argv) case '1': /* filter */ if (params->common.events) { retval =3D trace_event_add_filter(params->common.events, optarg); - if (retval) { - err_msg("Error adding filter %s\n", optarg); - exit(EXIT_FAILURE); - } + if (retval) + fatal("Error adding filter %s", optarg); } else { osnoise_top_usage(params, "--filter requires a previous -e\n"); } @@ -513,18 +505,14 @@ struct common_params *osnoise_top_parse_args(int argc= , char **argv) case '4': retval =3D actions_parse(¶ms->common.threshold_actions, optarg, "osnoise_trace.txt"); - if (retval) { - err_msg("Invalid action %s\n", optarg); - exit(EXIT_FAILURE); - } + if (retval) + fatal("Invalid action %s", optarg); break; case '5': retval =3D actions_parse(¶ms->common.end_actions, optarg, "osnoise_trace.txt"); - if (retval) { - err_msg("Invalid action %s\n", optarg); - exit(EXIT_FAILURE); - } + if (retval) + fatal("Invalid action %s", optarg); break; default: osnoise_top_usage(params, "Invalid option"); @@ -534,10 +522,8 @@ struct common_params *osnoise_top_parse_args(int argc,= char **argv) if (trace_output) actions_add_trace_output(¶ms->common.threshold_actions, trace_output= ); =20 - if (geteuid()) { - err_msg("osnoise needs root permission\n"); - exit(EXIT_FAILURE); - } + if (geteuid()) + fatal("osnoise needs root permission"); =20 return ¶ms->common; } diff --git a/tools/tracing/rtla/src/timerlat_hist.c b/tools/tracing/rtla/sr= c/timerlat_hist.c index c432ef5f59e7..f98deb16b452 100644 --- a/tools/tracing/rtla/src/timerlat_hist.c +++ b/tools/tracing/rtla/src/timerlat_hist.c @@ -894,10 +894,8 @@ static struct common_params break; case 'e': tevent =3D trace_event_alloc(optarg); - if (!tevent) { - err_msg("Error alloc trace event"); - exit(EXIT_FAILURE); - } + if (!tevent) + fatal("Error alloc trace event"); =20 if (params->common.events) tevent->next =3D params->common.events; @@ -917,10 +915,8 @@ static struct common_params case 'H': params->common.hk_cpus =3D 1; retval =3D parse_cpu_set(optarg, ¶ms->common.hk_cpu_set); - if (retval) { - err_msg("Error parsing house keeping CPUs\n"); - exit(EXIT_FAILURE); - } + if (retval) + fatal("Error parsing house keeping CPUs"); break; case 'i': params->common.stop_us =3D get_llong_from_str(optarg); @@ -986,10 +982,8 @@ static struct common_params case '6': /* trigger */ if (params->common.events) { retval =3D trace_event_add_trigger(params->common.events, optarg); - if (retval) { - err_msg("Error adding trigger %s\n", optarg); - exit(EXIT_FAILURE); - } + if (retval) + fatal("Error adding trigger %s", optarg); } else { timerlat_hist_usage("--trigger requires a previous -e\n"); } @@ -997,20 +991,16 @@ static struct common_params case '7': /* filter */ if (params->common.events) { retval =3D trace_event_add_filter(params->common.events, optarg); - if (retval) { - err_msg("Error adding filter %s\n", optarg); - exit(EXIT_FAILURE); - } + if (retval) + fatal("Error adding filter %s", optarg); } else { timerlat_hist_usage("--filter requires a previous -e\n"); } break; case '8': params->dma_latency =3D get_llong_from_str(optarg); - if (params->dma_latency < 0 || params->dma_latency > 10000) { - err_msg("--dma-latency needs to be >=3D 0 and < 10000"); - exit(EXIT_FAILURE); - } + if (params->dma_latency < 0 || params->dma_latency > 10000) + fatal("--dma-latency needs to be >=3D 0 and < 10000"); break; case '9': params->no_aa =3D 1; @@ -1030,31 +1020,25 @@ static struct common_params case '\5': retval =3D actions_parse(¶ms->common.threshold_actions, optarg, "timerlat_trace.txt"); - if (retval) { - err_msg("Invalid action %s\n", optarg); - exit(EXIT_FAILURE); - } + if (retval) + fatal("Invalid action %s", optarg); break; case '\6': retval =3D actions_parse(¶ms->common.end_actions, optarg, "timerlat_trace.txt"); - if (retval) { - err_msg("Invalid action %s\n", optarg); - exit(EXIT_FAILURE); - } + if (retval) + fatal("Invalid action %s", optarg); break; default: - timerlat_hist_usage("Invalid option"); + fatal("Invalid option"); } } =20 if (trace_output) actions_add_trace_output(¶ms->common.threshold_actions, trace_output= ); =20 - if (geteuid()) { - err_msg("rtla needs root permission\n"); - exit(EXIT_FAILURE); - } + if (geteuid()) + fatal("rtla needs root permission"); =20 if (params->common.hist.no_irq && params->common.hist.no_thread) timerlat_hist_usage("no-irq and no-thread set, there is nothing to do he= re"); diff --git a/tools/tracing/rtla/src/timerlat_top.c b/tools/tracing/rtla/src= /timerlat_top.c index 82e227d27af7..9664b8af727e 100644 --- a/tools/tracing/rtla/src/timerlat_top.c +++ b/tools/tracing/rtla/src/timerlat_top.c @@ -666,10 +666,8 @@ static struct common_params break; case 'e': tevent =3D trace_event_alloc(optarg); - if (!tevent) { - err_msg("Error alloc trace event"); - exit(EXIT_FAILURE); - } + if (!tevent) + fatal("Error alloc trace event"); =20 if (params->common.events) tevent->next =3D params->common.events; @@ -682,10 +680,8 @@ static struct common_params case 'H': params->common.hk_cpus =3D 1; retval =3D parse_cpu_set(optarg, ¶ms->common.hk_cpu_set); - if (retval) { - err_msg("Error parsing house keeping CPUs\n"); - exit(EXIT_FAILURE); - } + if (retval) + fatal("Error parsing house keeping CPUs"); break; case 'i': params->common.stop_us =3D get_llong_from_str(optarg); @@ -736,10 +732,8 @@ static struct common_params case '0': /* trigger */ if (params->common.events) { retval =3D trace_event_add_trigger(params->common.events, optarg); - if (retval) { - err_msg("Error adding trigger %s\n", optarg); - exit(EXIT_FAILURE); - } + if (retval) + fatal("Error adding trigger %s", optarg); } else { timerlat_top_usage("--trigger requires a previous -e\n"); } @@ -747,20 +741,16 @@ static struct common_params case '1': /* filter */ if (params->common.events) { retval =3D trace_event_add_filter(params->common.events, optarg); - if (retval) { - err_msg("Error adding filter %s\n", optarg); - exit(EXIT_FAILURE); - } + if (retval) + fatal("Error adding filter %s", optarg); } else { timerlat_top_usage("--filter requires a previous -e\n"); } break; case '2': /* dma-latency */ params->dma_latency =3D get_llong_from_str(optarg); - if (params->dma_latency < 0 || params->dma_latency > 10000) { - err_msg("--dma-latency needs to be >=3D 0 and < 10000"); - exit(EXIT_FAILURE); - } + if (params->dma_latency < 0 || params->dma_latency > 10000) + fatal("--dma-latency needs to be >=3D 0 and < 10000"); break; case '3': /* no-aa */ params->no_aa =3D 1; @@ -780,18 +770,14 @@ static struct common_params case '9': retval =3D actions_parse(¶ms->common.threshold_actions, optarg, "timerlat_trace.txt"); - if (retval) { - err_msg("Invalid action %s\n", optarg); - exit(EXIT_FAILURE); - } + if (retval) + fatal("Invalid action %s", optarg); break; case '\1': retval =3D actions_parse(¶ms->common.end_actions, optarg, "timerlat_trace.txt"); - if (retval) { - err_msg("Invalid action %s\n", optarg); - exit(EXIT_FAILURE); - } + if (retval) + fatal("Invalid action %s", optarg); break; default: timerlat_top_usage("Invalid option"); @@ -801,10 +787,8 @@ static struct common_params if (trace_output) actions_add_trace_output(¶ms->common.threshold_actions, trace_output= ); =20 - if (geteuid()) { - err_msg("rtla needs root permission\n"); - exit(EXIT_FAILURE); - } + if (geteuid()) + fatal("rtla needs root permission"); =20 /* * Auto analysis only happens if stop tracing, thus: diff --git a/tools/tracing/rtla/src/timerlat_u.c b/tools/tracing/rtla/src/t= imerlat_u.c index 01dbf9a6b5a5..ce68e39d25fd 100644 --- a/tools/tracing/rtla/src/timerlat_u.c +++ b/tools/tracing/rtla/src/timerlat_u.c @@ -51,10 +51,8 @@ static int timerlat_u_main(int cpu, struct timerlat_u_pa= rams *params) =20 if (!params->sched_param) { retval =3D sched_setscheduler(0, SCHED_FIFO, &sp); - if (retval < 0) { - err_msg("Error setting timerlat u default priority: %s\n", strerror(err= no)); - exit(1); - } + if (retval < 0) + fatal("Error setting timerlat u default priority: %s", strerror(errno)); } else { retval =3D __set_sched_attr(getpid(), params->sched_param); if (retval) { @@ -78,10 +76,8 @@ static int timerlat_u_main(int cpu, struct timerlat_u_pa= rams *params) snprintf(buffer, sizeof(buffer), "osnoise/per_cpu/cpu%d/timerlat_fd", cpu= ); =20 timerlat_fd =3D tracefs_instance_file_open(NULL, buffer, O_RDONLY); - if (timerlat_fd < 0) { - err_msg("Error opening %s:%s\n", buffer, strerror(errno)); - exit(1); - } + if (timerlat_fd < 0) + fatal("Error opening %s:%s", buffer, strerror(errno)); =20 debug_msg("User-space timerlat pid %d on cpu %d\n", gettid(), cpu); =20 diff --git a/tools/tracing/rtla/src/utils.c b/tools/tracing/rtla/src/utils.c index d6ab15dcb490..54334c676a22 100644 --- a/tools/tracing/rtla/src/utils.c +++ b/tools/tracing/rtla/src/utils.c @@ -56,6 +56,21 @@ void debug_msg(const char *fmt, ...) fprintf(stderr, "%s", message); } =20 +/* + * fatal - print an error message and EOL to stderr and exit with ERROR + */ +void fatal(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + fprintf(stderr, "\n"); + + exit(ERROR); +} + /* * get_llong_from_str - get a long long int from a string */ diff --git a/tools/tracing/rtla/src/utils.h b/tools/tracing/rtla/src/utils.h index a2a6f89f342d..1be095f9a7e6 100644 --- a/tools/tracing/rtla/src/utils.h +++ b/tools/tracing/rtla/src/utils.h @@ -19,6 +19,7 @@ extern int config_debug; void debug_msg(const char *fmt, ...); void err_msg(const char *fmt, ...); +void fatal(const char *fmt, ...); =20 long parse_seconds_duration(char *val); void get_duration(time_t start_time, char *output, int output_size); --=20 2.51.0