From nobody Wed Oct 8 07:40:24 2025 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8E6EB18D; Tue, 1 Jul 2025 06:03:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751349843; cv=none; b=UvT7GMMAc/Oc+rf4v1CUuk+nJYInVRhGN/VFMDQtMTMtQLLaHayEkQutBddowzttwJiX3lUeAn8uCYeKV1XPnvw8S32+QheAoRFu9vOHvAwyO2inUK/t7m1ZKH/OZSVeS/TAL4u87v5CWDF5jjxQjrlF7iASSkmsDpxhgwAvYw4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751349843; c=relaxed/simple; bh=aam3jqa0fO/VRzRpiRG8saL2ppQvVEt3VefmrmsXiTw=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=mXY1kQj//lmcmuH1ldpDIF7KIDZi60KP+kNnMUq2KKLI/r55fCzUTjG/tvQuOKNidSz22fMeWCFjo+ZXuxhDSOSbTrXVmNTmNiNNSrpCHAfKN+CojQtajBqUDWnb3iYSelLeckGEfhK0MWJ1PU4car9OFzdnuVDuyz2bQCMJdTM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.221.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-3a6e8b1fa37so2489624f8f.2; Mon, 30 Jun 2025 23:03:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751349836; x=1751954636; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=IlSY4PfFnZ+QFyRwPRdbpv456tvzDvOamZooLk66mD0=; b=YtDi+VLRkaYignxAgnKI8YqvrB8WLxXS+B5Lwr66nmTfXB9j0rr/i/1t6v01XaIqUw l20UJ4x5avCEnaEX68iwYIigLTPlu0Sfbf0YQzTCy0yVfaFp6pOPHzOZc4NTXP+bgkiF DigUWh3mWZPm0kOO+skk1C1JX2mFqR61mpzCR/s9EEflIbL+1cHqVSXh+b3oLGVkEqfG KiWAt77WeHkuGz6fsCXJnRO14J02R3VffSYDcdBvNLjSHd6nmAXvM65KKO0U8wQPHDvh 6Tzayvt0prAmZ8yXIRbQrvf/RHMqOyhheftaXaZhCCguP26lWi9wbNsIFcl2B/JYKvho W8Pg== X-Forwarded-Encrypted: i=1; AJvYcCUbHHOFL1A5qf29n+Nt+DlTutsxKqu2jndPMIYpn6Gv+PPwZChJpuSib2krjku5F2c+1O0=@vger.kernel.org, AJvYcCWFogdAP9M479yRCy0uP+JCI3jg7LNWf5t5RO/kBeLo4lWJ3NXPnD98PdI24F9gs6AAtqYFZg79xC9fdgAgr28OFCT7@vger.kernel.org, AJvYcCWivbRpxT4G7+oZ5ajBXl/E5sc+hHRGQUZLRkXJ/JcCCW5y6yRvds0V8nuSUZGIcZaVb20Yh7KS3qpqtl3v@vger.kernel.org X-Gm-Message-State: AOJu0YyOIZZgIbm14jlXFzf3KE1CbPoN+5ZkLgiMOn+g5NMPlPtByJPl Ka18GJKU7U2SAHyioJPcIf5ycKvQ4qwoNwH1IOBto3U2/9QsSdePGTZ/ X-Gm-Gg: ASbGncvwSn6UgerSVxdAJ4CqdlW//GVlSlafdRsGWkCyQ954pMVM+zBv/zv8lQuaCt0 7MxMIxnGg53PlEJSCwKQbKN2aqUPKY6VrY7qbaUb1MyaulDIthiyXdjiqYD5xJ2lzd0QTLZ4Egv AKz9EirlT/C4oZUm60RjNSCrBzsLttIiqP/C7W83mpZof7IGt1XmqyP8lxUUgcrsTi7HvVN3j+1 yJc9z2z6COawlhuKukPlF7Gt3HYlKs2pZF+0u9hdzvky6i5AmVj/VfpYh8eVVP7UWC3A6yvYP// UAdRYO+RDXyxLJzpqjY14h6Ph9/hI/51Xv8aljYVI/WlxoWXBRMS3TLKOeGzg9ses7fp7xK341n dLeU= X-Google-Smtp-Source: AGHT+IEHQyqdwApVbMRtuJMXxBKETvubLza93fiHNs3j/xEoD2BIhF2g9HLON2rqMR9E4/QZYQmgKQ== X-Received: by 2002:a05:6000:2083:b0:3a4:dc32:6cbb with SMTP id ffacd0b85a97d-3a8fee64e3amr13908001f8f.31.1751349835114; Mon, 30 Jun 2025 23:03:55 -0700 (PDT) Received: from costa-tp.redhat.com ([2a00:a041:e280:5300:9068:704e:a31a:c135]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a88c7e71dfsm11970260f8f.7.2025.06.30.23.03.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jun 2025 23:03:54 -0700 (PDT) From: Costa Shulyupin To: Steven Rostedt , Tomas Glozar , John Kacur , Costa Shulyupin , Eder Zulian , Dan Carpenter , Gabriele Monaco , Jan Stancek , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH v1] tools/rtla: Consolidate common parameters into shared structure Date: Tue, 1 Jul 2025 09:03:14 +0300 Message-ID: <20250701060337.648475-1-costa.shul@redhat.com> X-Mailer: git-send-email 2.48.1 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" timerlat_params and osnoise_params structures contain 17 identical fields. Introduce a common_params structure and move those fields into it to eliminate the code duplication and improve maintainability. Signed-off-by: Costa Shulyupin Reviewed-by: Tomas Glozar reviewed-by from Tomas and/or Gabriele. --- tools/tracing/rtla/src/osnoise.c | 24 ++--- tools/tracing/rtla/src/osnoise.h | 19 +--- tools/tracing/rtla/src/osnoise_hist.c | 112 ++++++++++----------- tools/tracing/rtla/src/osnoise_top.c | 102 +++++++++---------- tools/tracing/rtla/src/timerlat.c | 24 ++--- tools/tracing/rtla/src/timerlat.h | 19 +--- tools/tracing/rtla/src/timerlat_bpf.c | 4 +- tools/tracing/rtla/src/timerlat_hist.c | 129 +++++++++++++------------ tools/tracing/rtla/src/timerlat_top.c | 121 +++++++++++------------ tools/tracing/rtla/src/utils.h | 31 ++++++ 10 files changed, 292 insertions(+), 293 deletions(-) diff --git a/tools/tracing/rtla/src/osnoise.c b/tools/tracing/rtla/src/osno= ise.c index 2dc3e4539e99..f8a323a6614e 100644 --- a/tools/tracing/rtla/src/osnoise.c +++ b/tools/tracing/rtla/src/osnoise.c @@ -1127,18 +1127,18 @@ osnoise_apply_config(struct osnoise_tool *tool, str= uct osnoise_params *params) { int retval; =20 - if (!params->sleep_time) - params->sleep_time =3D 1; + if (!params->common.sleep_time) + params->common.sleep_time =3D 1; =20 - retval =3D osnoise_set_cpus(tool->context, params->cpus ? params->cpus : = "all"); + retval =3D osnoise_set_cpus(tool->context, params->common.cpus ? params->= common.cpus : "all"); if (retval) { err_msg("Failed to apply CPUs config\n"); goto out_err; } =20 - if (params->runtime || params->period) { + if (params->common.runtime || params->period) { retval =3D osnoise_set_runtime_period(tool->context, - params->runtime, + params->common.runtime, params->period); } else { retval =3D osnoise_set_runtime_period(tool->context, @@ -1151,13 +1151,13 @@ osnoise_apply_config(struct osnoise_tool *tool, str= uct osnoise_params *params) goto out_err; } =20 - retval =3D osnoise_set_stop_us(tool->context, params->stop_us); + retval =3D osnoise_set_stop_us(tool->context, params->common.stop_us); if (retval) { err_msg("Failed to set stop us\n"); goto out_err; } =20 - retval =3D osnoise_set_stop_total_us(tool->context, params->stop_total_us= ); + retval =3D osnoise_set_stop_total_us(tool->context, params->common.stop_t= otal_us); if (retval) { err_msg("Failed to set stop total us\n"); goto out_err; @@ -1169,14 +1169,14 @@ osnoise_apply_config(struct osnoise_tool *tool, str= uct osnoise_params *params) goto out_err; } =20 - if (params->hk_cpus) { - retval =3D sched_setaffinity(getpid(), sizeof(params->hk_cpu_set), - ¶ms->hk_cpu_set); + if (params->common.hk_cpus) { + retval =3D sched_setaffinity(getpid(), sizeof(params->common.hk_cpu_set), + ¶ms->common.hk_cpu_set); if (retval =3D=3D -1) { err_msg("Failed to set rtla to the house keeping CPUs\n"); goto out_err; } - } else if (params->cpus) { + } else if (params->common.cpus) { /* * Even if the user do not set a house-keeping CPU, try to * move rtla to a CPU set different to the one where the user @@ -1184,7 +1184,7 @@ osnoise_apply_config(struct osnoise_tool *tool, struc= t osnoise_params *params) * * No need to check results as this is an automatic attempt. */ - auto_house_keeping(¶ms->monitored_cpus); + auto_house_keeping(¶ms->common.monitored_cpus); } =20 retval =3D osnoise_set_workload(tool->context, true); diff --git a/tools/tracing/rtla/src/osnoise.h b/tools/tracing/rtla/src/osno= ise.h index ac1c99910744..a887c95a9809 100644 --- a/tools/tracing/rtla/src/osnoise.h +++ b/tools/tracing/rtla/src/osnoise.h @@ -10,26 +10,9 @@ enum osnoise_mode { }; =20 struct osnoise_params { - /* Common params */ - char *cpus; - cpu_set_t monitored_cpus; - char *trace_output; - char *cgroup_name; - unsigned long long runtime; + struct common_params common; unsigned long long period; long long threshold; - long long stop_us; - long long stop_total_us; - int sleep_time; - int duration; - int set_sched; - int cgroup; - int hk_cpus; - cpu_set_t hk_cpu_set; - struct sched_attr sched_param; - struct trace_events *events; - int warmup; - int buffer_size; union { struct { /* top only */ diff --git a/tools/tracing/rtla/src/osnoise_hist.c b/tools/tracing/rtla/src= /osnoise_hist.c index 8d579bcee709..9e1277357c96 100644 --- a/tools/tracing/rtla/src/osnoise_hist.c +++ b/tools/tracing/rtla/src/osnoise_hist.c @@ -243,7 +243,7 @@ static void osnoise_hist_header(struct osnoise_tool *to= ol) trace_seq_printf(s, "Index"); =20 for (cpu =3D 0; cpu < data->nr_cpus; cpu++) { - if (params->cpus && !CPU_ISSET(cpu, ¶ms->monitored_cpus)) + if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpu= s)) continue; =20 if (!data->hist[cpu].count) @@ -274,7 +274,7 @@ osnoise_print_summary(struct osnoise_params *params, trace_seq_printf(trace->seq, "count:"); =20 for (cpu =3D 0; cpu < data->nr_cpus; cpu++) { - if (params->cpus && !CPU_ISSET(cpu, ¶ms->monitored_cpus)) + if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpu= s)) continue; =20 if (!data->hist[cpu].count) @@ -288,7 +288,7 @@ osnoise_print_summary(struct osnoise_params *params, trace_seq_printf(trace->seq, "min: "); =20 for (cpu =3D 0; cpu < data->nr_cpus; cpu++) { - if (params->cpus && !CPU_ISSET(cpu, ¶ms->monitored_cpus)) + if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpu= s)) continue; =20 if (!data->hist[cpu].count) @@ -303,7 +303,7 @@ osnoise_print_summary(struct osnoise_params *params, trace_seq_printf(trace->seq, "avg: "); =20 for (cpu =3D 0; cpu < data->nr_cpus; cpu++) { - if (params->cpus && !CPU_ISSET(cpu, ¶ms->monitored_cpus)) + if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpu= s)) continue; =20 if (!data->hist[cpu].count) @@ -321,7 +321,7 @@ osnoise_print_summary(struct osnoise_params *params, trace_seq_printf(trace->seq, "max: "); =20 for (cpu =3D 0; cpu < data->nr_cpus; cpu++) { - if (params->cpus && !CPU_ISSET(cpu, ¶ms->monitored_cpus)) + if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpu= s)) continue; =20 if (!data->hist[cpu].count) @@ -357,7 +357,7 @@ osnoise_print_stats(struct osnoise_params *params, stru= ct osnoise_tool *tool) bucket * data->bucket_size); =20 for (cpu =3D 0; cpu < data->nr_cpus; cpu++) { - if (params->cpus && !CPU_ISSET(cpu, ¶ms->monitored_cpus)) + if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cp= us)) continue; =20 if (!data->hist[cpu].count) @@ -395,7 +395,7 @@ osnoise_print_stats(struct osnoise_params *params, stru= ct osnoise_tool *tool) trace_seq_printf(trace->seq, "over: "); =20 for (cpu =3D 0; cpu < data->nr_cpus; cpu++) { - if (params->cpus && !CPU_ISSET(cpu, ¶ms->monitored_cpus)) + if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpu= s)) continue; =20 if (!data->hist[cpu].count) @@ -537,13 +537,13 @@ static struct osnoise_params switch (c) { case 'a': /* set sample stop to auto_thresh */ - params->stop_us =3D get_llong_from_str(optarg); + params->common.stop_us =3D get_llong_from_str(optarg); =20 /* set sample threshold to 1 */ params->threshold =3D 1; =20 /* set trace */ - params->trace_output =3D "osnoise_trace.txt"; + params->common.trace_output =3D "osnoise_trace.txt"; =20 break; case 'b': @@ -552,27 +552,27 @@ static struct osnoise_params osnoise_hist_usage("Bucket size needs to be > 0 and <=3D 1000000\n"); break; case 'c': - retval =3D parse_cpu_set(optarg, ¶ms->monitored_cpus); + retval =3D parse_cpu_set(optarg, ¶ms->common.monitored_cpus); if (retval) osnoise_hist_usage("\nInvalid -c cpu list\n"); - params->cpus =3D optarg; + params->common.cpus =3D optarg; break; case 'C': - params->cgroup =3D 1; + params->common.cgroup =3D 1; if (!optarg) { /* will inherit this cgroup */ - params->cgroup_name =3D NULL; + params->common.cgroup_name =3D NULL; } else if (*optarg =3D=3D '=3D') { /* skip the =3D */ - params->cgroup_name =3D ++optarg; + params->common.cgroup_name =3D ++optarg; } break; case 'D': config_debug =3D 1; break; case 'd': - params->duration =3D parse_seconds_duration(optarg); - if (!params->duration) + params->common.duration =3D parse_seconds_duration(optarg); + if (!params->common.duration) osnoise_hist_usage("Invalid -D duration\n"); break; case 'e': @@ -582,10 +582,10 @@ static struct osnoise_params exit(EXIT_FAILURE); } =20 - if (params->events) - tevent->next =3D params->events; + if (params->common.events) + tevent->next =3D params->common.events; =20 - params->events =3D tevent; + params->common.events =3D tevent; break; case 'E': params->entries =3D get_llong_from_str(optarg); @@ -597,8 +597,8 @@ static struct osnoise_params osnoise_hist_usage(NULL); break; case 'H': - params->hk_cpus =3D 1; - retval =3D parse_cpu_set(optarg, ¶ms->hk_cpu_set); + 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); @@ -610,21 +610,21 @@ static struct osnoise_params osnoise_hist_usage("Period longer than 10 s\n"); break; case 'P': - retval =3D parse_prio(optarg, ¶ms->sched_param); + retval =3D parse_prio(optarg, ¶ms->common.sched_param); if (retval =3D=3D -1) osnoise_hist_usage("Invalid -P priority"); - params->set_sched =3D 1; + params->common.set_sched =3D 1; break; case 'r': - params->runtime =3D get_llong_from_str(optarg); - if (params->runtime < 100) + params->common.runtime =3D get_llong_from_str(optarg); + if (params->common.runtime < 100) osnoise_hist_usage("Runtime shorter than 100 us\n"); break; case 's': - params->stop_us =3D get_llong_from_str(optarg); + params->common.stop_us =3D get_llong_from_str(optarg); break; case 'S': - params->stop_total_us =3D get_llong_from_str(optarg); + params->common.stop_total_us =3D get_llong_from_str(optarg); break; case 'T': params->threshold =3D get_llong_from_str(optarg); @@ -632,13 +632,13 @@ static struct osnoise_params case 't': if (optarg) { if (optarg[0] =3D=3D '=3D') - params->trace_output =3D &optarg[1]; + params->common.trace_output =3D &optarg[1]; else - params->trace_output =3D &optarg[0]; + params->common.trace_output =3D &optarg[0]; } else if (optind < argc && argv[optind][0] !=3D '0') - params->trace_output =3D argv[optind]; + params->common.trace_output =3D argv[optind]; else - params->trace_output =3D "osnoise_trace.txt"; + params->common.trace_output =3D "osnoise_trace.txt"; break; case '0': /* no header */ params->no_header =3D 1; @@ -653,8 +653,8 @@ static struct osnoise_params params->with_zeros =3D 1; break; case '4': /* trigger */ - if (params->events) { - retval =3D trace_event_add_trigger(params->events, optarg); + 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); @@ -664,8 +664,8 @@ static struct osnoise_params } break; case '5': /* filter */ - if (params->events) { - retval =3D trace_event_add_filter(params->events, optarg); + 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); @@ -675,10 +675,10 @@ static struct osnoise_params } break; case '6': - params->warmup =3D get_llong_from_str(optarg); + params->common.warmup =3D get_llong_from_str(optarg); break; case '7': - params->buffer_size =3D get_llong_from_str(optarg); + params->common.buffer_size =3D get_llong_from_str(optarg); break; default: osnoise_hist_usage("Invalid option"); @@ -755,9 +755,9 @@ static void osnoise_hist_set_signals(struct osnoise_params *params) { signal(SIGINT, stop_hist); - if (params->duration) { + if (params->common.duration) { signal(SIGALRM, stop_hist); - alarm(params->duration); + alarm(params->common.duration); } } =20 @@ -798,37 +798,37 @@ int osnoise_hist_main(int argc, char *argv[]) if (retval) goto out_destroy; =20 - if (params->set_sched) { - retval =3D set_comm_sched_attr("osnoise/", ¶ms->sched_param); + if (params->common.set_sched) { + retval =3D set_comm_sched_attr("osnoise/", ¶ms->common.sched_param); if (retval) { err_msg("Failed to set sched parameters\n"); goto out_free; } } =20 - if (params->cgroup) { - retval =3D set_comm_cgroup("timerlat/", params->cgroup_name); + if (params->common.cgroup) { + retval =3D set_comm_cgroup("timerlat/", params->common.cgroup_name); if (!retval) { err_msg("Failed to move threads to cgroup\n"); goto out_free; } } =20 - if (params->trace_output) { + if (params->common.trace_output) { record =3D osnoise_init_trace_tool("osnoise"); if (!record) { err_msg("Failed to enable the trace instance\n"); goto out_free; } =20 - if (params->events) { - retval =3D trace_events_enable(&record->trace, params->events); + if (params->common.events) { + retval =3D trace_events_enable(&record->trace, params->common.events); if (retval) goto out_hist; } =20 - if (params->buffer_size > 0) { - retval =3D trace_set_buffer_size(&record->trace, params->buffer_size); + if (params->common.buffer_size > 0) { + retval =3D trace_set_buffer_size(&record->trace, params->common.buffer_= size); if (retval) goto out_hist; } @@ -841,13 +841,13 @@ int osnoise_hist_main(int argc, char *argv[]) * tracing while enabling other instances. The trace instance is the * one with most valuable information. */ - if (params->trace_output) + if (params->common.trace_output) trace_instance_start(&record->trace); trace_instance_start(trace); =20 - if (params->warmup > 0) { - debug_msg("Warming up for %d seconds\n", params->warmup); - sleep(params->warmup); + if (params->common.warmup > 0) { + debug_msg("Warming up for %d seconds\n", params->common.warmup); + sleep(params->common.warmup); if (stop_tracing) goto out_hist; =20 @@ -868,7 +868,7 @@ int osnoise_hist_main(int argc, char *argv[]) osnoise_hist_set_signals(params); =20 while (!stop_tracing) { - sleep(params->sleep_time); + sleep(params->common.sleep_time); =20 retval =3D tracefs_iterate_raw_events(trace->tep, trace->inst, @@ -894,13 +894,13 @@ int osnoise_hist_main(int argc, char *argv[]) if (osnoise_trace_is_off(tool, record)) { printf("rtla osnoise hit stop tracing\n"); save_trace_to_file(record ? record->trace.inst : NULL, - params->trace_output); + params->common.trace_output); return_value =3D FAILED; } =20 out_hist: - trace_events_destroy(&record->trace, params->events); - params->events =3D NULL; + trace_events_destroy(&record->trace, params->common.events); + params->common.events =3D NULL; out_free: osnoise_free_histogram(tool->data); out_destroy: diff --git a/tools/tracing/rtla/src/osnoise_top.c b/tools/tracing/rtla/src/= osnoise_top.c index 2c12780c8aa9..a69e79c6ca02 100644 --- a/tools/tracing/rtla/src/osnoise_top.c +++ b/tools/tracing/rtla/src/osnoise_top.c @@ -238,7 +238,7 @@ osnoise_print_stats(struct osnoise_params *params, stru= ct osnoise_tool *top) osnoise_top_header(top); =20 for (i =3D 0; i < nr_cpus; i++) { - if (params->cpus && !CPU_ISSET(i, ¶ms->monitored_cpus)) + if (params->common.cpus && !CPU_ISSET(i, ¶ms->common.monitored_cpus)) continue; osnoise_top_print(top, i); } @@ -335,7 +335,7 @@ struct osnoise_params *osnoise_top_parse_args(int argc,= char **argv) /* * Reduce CPU usage for 75% to avoid killing the system. */ - params->runtime =3D 750000; + params->common.runtime =3D 750000; params->period =3D 1000000; } =20 @@ -377,37 +377,37 @@ struct osnoise_params *osnoise_top_parse_args(int arg= c, char **argv) switch (c) { case 'a': /* set sample stop to auto_thresh */ - params->stop_us =3D get_llong_from_str(optarg); + params->common.stop_us =3D get_llong_from_str(optarg); =20 /* set sample threshold to 1 */ params->threshold =3D 1; =20 /* set trace */ - params->trace_output =3D "osnoise_trace.txt"; + params->common.trace_output =3D "osnoise_trace.txt"; =20 break; case 'c': - retval =3D parse_cpu_set(optarg, ¶ms->monitored_cpus); + retval =3D parse_cpu_set(optarg, ¶ms->common.monitored_cpus); if (retval) osnoise_top_usage(params, "\nInvalid -c cpu list\n"); - params->cpus =3D optarg; + params->common.cpus =3D optarg; break; case 'C': - params->cgroup =3D 1; + params->common.cgroup =3D 1; if (!optarg) { /* will inherit this cgroup */ - params->cgroup_name =3D NULL; + params->common.cgroup_name =3D NULL; } else if (*optarg =3D=3D '=3D') { /* skip the =3D */ - params->cgroup_name =3D ++optarg; + params->common.cgroup_name =3D ++optarg; } break; case 'D': config_debug =3D 1; break; case 'd': - params->duration =3D parse_seconds_duration(optarg); - if (!params->duration) + params->common.duration =3D parse_seconds_duration(optarg); + if (!params->common.duration) osnoise_top_usage(params, "Invalid -d duration\n"); break; case 'e': @@ -417,9 +417,9 @@ struct osnoise_params *osnoise_top_parse_args(int argc,= char **argv) exit(EXIT_FAILURE); } =20 - if (params->events) - tevent->next =3D params->events; - params->events =3D tevent; + if (params->common.events) + tevent->next =3D params->common.events; + params->common.events =3D tevent; =20 break; case 'h': @@ -427,8 +427,8 @@ struct osnoise_params *osnoise_top_parse_args(int argc,= char **argv) osnoise_top_usage(params, NULL); break; case 'H': - params->hk_cpus =3D 1; - retval =3D parse_cpu_set(optarg, ¶ms->hk_cpu_set); + 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); @@ -440,42 +440,42 @@ struct osnoise_params *osnoise_top_parse_args(int arg= c, char **argv) osnoise_top_usage(params, "Period longer than 10 s\n"); break; case 'P': - retval =3D parse_prio(optarg, ¶ms->sched_param); + retval =3D parse_prio(optarg, ¶ms->common.sched_param); if (retval =3D=3D -1) osnoise_top_usage(params, "Invalid -P priority"); - params->set_sched =3D 1; + params->common.set_sched =3D 1; break; case 'q': params->quiet =3D 1; break; case 'r': - params->runtime =3D get_llong_from_str(optarg); - if (params->runtime < 100) + params->common.runtime =3D get_llong_from_str(optarg); + if (params->common.runtime < 100) osnoise_top_usage(params, "Runtime shorter than 100 us\n"); break; case 's': - params->stop_us =3D get_llong_from_str(optarg); + params->common.stop_us =3D get_llong_from_str(optarg); break; case 'S': - params->stop_total_us =3D get_llong_from_str(optarg); + params->common.stop_total_us =3D get_llong_from_str(optarg); break; case 't': if (optarg) { if (optarg[0] =3D=3D '=3D') - params->trace_output =3D &optarg[1]; + params->common.trace_output =3D &optarg[1]; else - params->trace_output =3D &optarg[0]; + params->common.trace_output =3D &optarg[0]; } else if (optind < argc && argv[optind][0] !=3D '-') - params->trace_output =3D argv[optind]; + params->common.trace_output =3D argv[optind]; else - params->trace_output =3D "osnoise_trace.txt"; + params->common.trace_output =3D "osnoise_trace.txt"; break; case 'T': params->threshold =3D get_llong_from_str(optarg); break; case '0': /* trigger */ - if (params->events) { - retval =3D trace_event_add_trigger(params->events, optarg); + 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); @@ -485,8 +485,8 @@ struct osnoise_params *osnoise_top_parse_args(int argc,= char **argv) } break; case '1': /* filter */ - if (params->events) { - retval =3D trace_event_add_filter(params->events, optarg); + 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); @@ -496,10 +496,10 @@ struct osnoise_params *osnoise_top_parse_args(int arg= c, char **argv) } break; case '2': - params->warmup =3D get_llong_from_str(optarg); + params->common.warmup =3D get_llong_from_str(optarg); break; case '3': - params->buffer_size =3D get_llong_from_str(optarg); + params->common.buffer_size =3D get_llong_from_str(optarg); break; default: osnoise_top_usage(params, "Invalid option"); @@ -583,9 +583,9 @@ static void stop_top(int sig) static void osnoise_top_set_signals(struct osnoise_params *params) { signal(SIGINT, stop_top); - if (params->duration) { + if (params->common.duration) { signal(SIGALRM, stop_top); - alarm(params->duration); + alarm(params->common.duration); } } =20 @@ -622,37 +622,37 @@ int osnoise_top_main(int argc, char **argv) goto out_free; } =20 - if (params->set_sched) { - retval =3D set_comm_sched_attr("osnoise/", ¶ms->sched_param); + if (params->common.set_sched) { + retval =3D set_comm_sched_attr("osnoise/", ¶ms->common.sched_param); if (retval) { err_msg("Failed to set sched parameters\n"); goto out_free; } } =20 - if (params->cgroup) { - retval =3D set_comm_cgroup("osnoise/", params->cgroup_name); + if (params->common.cgroup) { + retval =3D set_comm_cgroup("osnoise/", params->common.cgroup_name); if (!retval) { err_msg("Failed to move threads to cgroup\n"); goto out_free; } } =20 - if (params->trace_output) { + if (params->common.trace_output) { record =3D osnoise_init_trace_tool("osnoise"); if (!record) { err_msg("Failed to enable the trace instance\n"); goto out_free; } =20 - if (params->events) { - retval =3D trace_events_enable(&record->trace, params->events); + if (params->common.events) { + retval =3D trace_events_enable(&record->trace, params->common.events); if (retval) goto out_top; } =20 - if (params->buffer_size > 0) { - retval =3D trace_set_buffer_size(&record->trace, params->buffer_size); + if (params->common.buffer_size > 0) { + retval =3D trace_set_buffer_size(&record->trace, params->common.buffer_= size); if (retval) goto out_top; } @@ -665,13 +665,13 @@ int osnoise_top_main(int argc, char **argv) * tracing while enabling other instances. The trace instance is the * one with most valuable information. */ - if (params->trace_output) + if (params->common.trace_output) trace_instance_start(&record->trace); trace_instance_start(trace); =20 - if (params->warmup > 0) { - debug_msg("Warming up for %d seconds\n", params->warmup); - sleep(params->warmup); + if (params->common.warmup > 0) { + debug_msg("Warming up for %d seconds\n", params->common.warmup); + sleep(params->common.warmup); if (stop_tracing) goto out_top; =20 @@ -692,7 +692,7 @@ int osnoise_top_main(int argc, char **argv) osnoise_top_set_signals(params); =20 while (!stop_tracing) { - sleep(params->sleep_time); + sleep(params->common.sleep_time); =20 retval =3D tracefs_iterate_raw_events(trace->tep, trace->inst, @@ -720,13 +720,13 @@ int osnoise_top_main(int argc, char **argv) if (osnoise_trace_is_off(tool, record)) { printf("osnoise hit stop tracing\n"); save_trace_to_file(record ? record->trace.inst : NULL, - params->trace_output); + params->common.trace_output); return_value =3D FAILED; } =20 out_top: - trace_events_destroy(&record->trace, params->events); - params->events =3D NULL; + trace_events_destroy(&record->trace, params->common.events); + params->common.events =3D NULL; out_free: osnoise_free_top(tool->data); osnoise_destroy_tool(record); diff --git a/tools/tracing/rtla/src/timerlat.c b/tools/tracing/rtla/src/tim= erlat.c index c29e2ba2d7d8..d1b6f8150781 100644 --- a/tools/tracing/rtla/src/timerlat.c +++ b/tools/tracing/rtla/src/timerlat.c @@ -26,27 +26,27 @@ timerlat_apply_config(struct osnoise_tool *tool, struct= timerlat_params *params) { int retval, i; =20 - if (!params->sleep_time) - params->sleep_time =3D 1; + if (!params->common.sleep_time) + params->common.sleep_time =3D 1; =20 - retval =3D osnoise_set_cpus(tool->context, params->cpus ? params->cpus : = "all"); + retval =3D osnoise_set_cpus(tool->context, params->common.cpus ? params->= common.cpus : "all"); if (retval) { err_msg("Failed to apply CPUs config\n"); goto out_err; } =20 - if (!params->cpus) { + if (!params->common.cpus) { for (i =3D 0; i < sysconf(_SC_NPROCESSORS_CONF); i++) - CPU_SET(i, ¶ms->monitored_cpus); + CPU_SET(i, ¶ms->common.monitored_cpus); } =20 - retval =3D osnoise_set_stop_us(tool->context, params->stop_us); + retval =3D osnoise_set_stop_us(tool->context, params->common.stop_us); if (retval) { err_msg("Failed to set stop us\n"); goto out_err; } =20 - retval =3D osnoise_set_stop_total_us(tool->context, params->stop_total_us= ); + retval =3D osnoise_set_stop_total_us(tool->context, params->common.stop_t= otal_us); if (retval) { err_msg("Failed to set stop total us\n"); goto out_err; @@ -69,14 +69,14 @@ timerlat_apply_config(struct osnoise_tool *tool, struct= timerlat_params *params) goto out_err; } =20 - if (params->hk_cpus) { - retval =3D sched_setaffinity(getpid(), sizeof(params->hk_cpu_set), - ¶ms->hk_cpu_set); + if (params->common.hk_cpus) { + retval =3D sched_setaffinity(getpid(), sizeof(params->common.hk_cpu_set), + ¶ms->common.hk_cpu_set); if (retval =3D=3D -1) { err_msg("Failed to set rtla to the house keeping CPUs\n"); goto out_err; } - } else if (params->cpus) { + } else if (params->common.cpus) { /* * Even if the user do not set a house-keeping CPU, try to * move rtla to a CPU set different to the one where the user @@ -84,7 +84,7 @@ timerlat_apply_config(struct osnoise_tool *tool, struct t= imerlat_params *params) * * No need to check results as this is an automatic attempt. */ - auto_house_keeping(¶ms->monitored_cpus); + auto_house_keeping(¶ms->common.monitored_cpus); } =20 /* diff --git a/tools/tracing/rtla/src/timerlat.h b/tools/tracing/rtla/src/tim= erlat.h index 73045aef23fa..e9c385a01da3 100644 --- a/tools/tracing/rtla/src/timerlat.h +++ b/tools/tracing/rtla/src/timerlat.h @@ -2,34 +2,17 @@ #include "osnoise.h" =20 struct timerlat_params { - /* Common params */ - char *cpus; - cpu_set_t monitored_cpus; - char *trace_output; - char *cgroup_name; - unsigned long long runtime; - long long stop_us; - long long stop_total_us; + struct common_params common; long long timerlat_period_us; long long print_stack; - int sleep_time; int output_divisor; - int duration; - int set_sched; int dma_latency; int no_aa; int dump_tasks; - int cgroup; - int hk_cpus; int user_workload; int kernel_workload; int user_data; - int warmup; - int buffer_size; int deepest_idle_state; - cpu_set_t hk_cpu_set; - struct sched_attr sched_param; - struct trace_events *events; union { struct { /* top only */ diff --git a/tools/tracing/rtla/src/timerlat_bpf.c b/tools/tracing/rtla/src= /timerlat_bpf.c index 0bc44ce5d69b..4a78afa9f3b2 100644 --- a/tools/tracing/rtla/src/timerlat_bpf.c +++ b/tools/tracing/rtla/src/timerlat_bpf.c @@ -23,8 +23,8 @@ int timerlat_bpf_init(struct timerlat_params *params) /* Pass common options */ bpf->rodata->output_divisor =3D params->output_divisor; bpf->rodata->entries =3D params->entries; - bpf->rodata->irq_threshold =3D params->stop_us; - bpf->rodata->thread_threshold =3D params->stop_total_us; + bpf->rodata->irq_threshold =3D params->common.stop_us; + bpf->rodata->thread_threshold =3D params->common.stop_total_us; bpf->rodata->aa_only =3D params->aa_only; =20 if (params->entries !=3D 0) { diff --git a/tools/tracing/rtla/src/timerlat_hist.c b/tools/tracing/rtla/sr= c/timerlat_hist.c index 36d2294c963d..72fe55592d3d 100644 --- a/tools/tracing/rtla/src/timerlat_hist.c +++ b/tools/tracing/rtla/src/timerlat_hist.c @@ -303,7 +303,7 @@ static void timerlat_hist_header(struct osnoise_tool *t= ool) trace_seq_printf(s, "Index"); =20 for (cpu =3D 0; cpu < data->nr_cpus; cpu++) { - if (params->cpus && !CPU_ISSET(cpu, ¶ms->monitored_cpus)) + if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpu= s)) continue; =20 if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count) @@ -357,7 +357,7 @@ timerlat_print_summary(struct timerlat_params *params, trace_seq_printf(trace->seq, "count:"); =20 for (cpu =3D 0; cpu < data->nr_cpus; cpu++) { - if (params->cpus && !CPU_ISSET(cpu, ¶ms->monitored_cpus)) + if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpu= s)) continue; =20 if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count) @@ -381,7 +381,7 @@ timerlat_print_summary(struct timerlat_params *params, trace_seq_printf(trace->seq, "min: "); =20 for (cpu =3D 0; cpu < data->nr_cpus; cpu++) { - if (params->cpus && !CPU_ISSET(cpu, ¶ms->monitored_cpus)) + if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpu= s)) continue; =20 if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count) @@ -411,7 +411,7 @@ timerlat_print_summary(struct timerlat_params *params, trace_seq_printf(trace->seq, "avg: "); =20 for (cpu =3D 0; cpu < data->nr_cpus; cpu++) { - if (params->cpus && !CPU_ISSET(cpu, ¶ms->monitored_cpus)) + if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpu= s)) continue; =20 if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count) @@ -441,7 +441,7 @@ timerlat_print_summary(struct timerlat_params *params, trace_seq_printf(trace->seq, "max: "); =20 for (cpu =3D 0; cpu < data->nr_cpus; cpu++) { - if (params->cpus && !CPU_ISSET(cpu, ¶ms->monitored_cpus)) + if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpu= s)) continue; =20 if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count) @@ -488,7 +488,7 @@ timerlat_print_stats_all(struct timerlat_params *params, sum.min_user =3D ~0; =20 for (cpu =3D 0; cpu < data->nr_cpus; cpu++) { - if (params->cpus && !CPU_ISSET(cpu, ¶ms->monitored_cpus)) + if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpu= s)) continue; =20 if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count) @@ -636,7 +636,7 @@ timerlat_print_stats(struct timerlat_params *params, st= ruct osnoise_tool *tool) bucket * data->bucket_size); =20 for (cpu =3D 0; cpu < data->nr_cpus; cpu++) { - if (params->cpus && !CPU_ISSET(cpu, ¶ms->monitored_cpus)) + if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cp= us)) continue; =20 if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count) @@ -676,7 +676,7 @@ timerlat_print_stats(struct timerlat_params *params, st= ruct osnoise_tool *tool) trace_seq_printf(trace->seq, "over: "); =20 for (cpu =3D 0; cpu < data->nr_cpus; cpu++) { - if (params->cpus && !CPU_ISSET(cpu, ¶ms->monitored_cpus)) + if (params->common.cpus && !CPU_ISSET(cpu, ¶ms->common.monitored_cpu= s)) continue; =20 if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count) @@ -856,30 +856,30 @@ static struct timerlat_params auto_thresh =3D get_llong_from_str(optarg); =20 /* set thread stop to auto_thresh */ - params->stop_total_us =3D auto_thresh; - params->stop_us =3D auto_thresh; + params->common.stop_total_us =3D auto_thresh; + params->common.stop_us =3D auto_thresh; =20 /* get stack trace */ params->print_stack =3D auto_thresh; =20 /* set trace */ - params->trace_output =3D "timerlat_trace.txt"; + params->common.trace_output =3D "timerlat_trace.txt"; =20 break; case 'c': - retval =3D parse_cpu_set(optarg, ¶ms->monitored_cpus); + retval =3D parse_cpu_set(optarg, ¶ms->common.monitored_cpus); if (retval) timerlat_hist_usage("\nInvalid -c cpu list\n"); - params->cpus =3D optarg; + params->common.cpus =3D optarg; break; case 'C': - params->cgroup =3D 1; + params->common.cgroup =3D 1; if (!optarg) { /* will inherit this cgroup */ - params->cgroup_name =3D NULL; + params->common.cgroup_name =3D NULL; } else if (*optarg =3D=3D '=3D') { /* skip the =3D */ - params->cgroup_name =3D ++optarg; + params->common.cgroup_name =3D ++optarg; } break; case 'b': @@ -891,8 +891,8 @@ static struct timerlat_params config_debug =3D 1; break; case 'd': - params->duration =3D parse_seconds_duration(optarg); - if (!params->duration) + params->common.duration =3D parse_seconds_duration(optarg); + if (!params->common.duration) timerlat_hist_usage("Invalid -D duration\n"); break; case 'e': @@ -902,10 +902,10 @@ static struct timerlat_params exit(EXIT_FAILURE); } =20 - if (params->events) - tevent->next =3D params->events; + if (params->common.events) + tevent->next =3D params->common.events; =20 - params->events =3D tevent; + params->common.events =3D tevent; break; case 'E': params->entries =3D get_llong_from_str(optarg); @@ -917,15 +917,15 @@ static struct timerlat_params timerlat_hist_usage(NULL); break; case 'H': - params->hk_cpus =3D 1; - retval =3D parse_cpu_set(optarg, ¶ms->hk_cpu_set); + 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); } break; case 'i': - params->stop_us =3D get_llong_from_str(optarg); + params->common.stop_us =3D get_llong_from_str(optarg); break; case 'k': params->kernel_workload =3D 1; @@ -939,27 +939,27 @@ static struct timerlat_params timerlat_hist_usage("Period longer than 1 s\n"); break; case 'P': - retval =3D parse_prio(optarg, ¶ms->sched_param); + retval =3D parse_prio(optarg, ¶ms->common.sched_param); if (retval =3D=3D -1) timerlat_hist_usage("Invalid -P priority"); - params->set_sched =3D 1; + params->common.set_sched =3D 1; break; case 's': params->print_stack =3D get_llong_from_str(optarg); break; case 'T': - params->stop_total_us =3D get_llong_from_str(optarg); + params->common.stop_total_us =3D get_llong_from_str(optarg); break; case 't': if (optarg) { if (optarg[0] =3D=3D '=3D') - params->trace_output =3D &optarg[1]; + params->common.trace_output =3D &optarg[1]; else - params->trace_output =3D &optarg[0]; + params->common.trace_output =3D &optarg[0]; } else if (optind < argc && argv[optind][0] !=3D '-') - params->trace_output =3D argv[optind]; + params->common.trace_output =3D argv[optind]; else - params->trace_output =3D "timerlat_trace.txt"; + params->common.trace_output =3D "timerlat_trace.txt"; break; case 'u': params->user_workload =3D 1; @@ -986,8 +986,8 @@ static struct timerlat_params params->with_zeros =3D 1; break; case '6': /* trigger */ - if (params->events) { - retval =3D trace_event_add_trigger(params->events, optarg); + 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); @@ -997,8 +997,8 @@ static struct timerlat_params } break; case '7': /* filter */ - if (params->events) { - retval =3D trace_event_add_filter(params->events, optarg); + 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); @@ -1021,10 +1021,10 @@ static struct timerlat_params params->dump_tasks =3D 1; break; case '\2': - params->warmup =3D get_llong_from_str(optarg); + params->common.warmup =3D get_llong_from_str(optarg); break; case '\3': - params->buffer_size =3D get_llong_from_str(optarg); + params->common.buffer_size =3D get_llong_from_str(optarg); break; case '\4': params->deepest_idle_state =3D get_llong_from_str(optarg); @@ -1048,7 +1048,7 @@ static struct timerlat_params /* * Auto analysis only happens if stop tracing, thus: */ - if (!params->stop_us && !params->stop_total_us) + if (!params->common.stop_us && !params->common.stop_total_us) params->no_aa =3D 1; =20 if (params->kernel_workload && params->user_workload) @@ -1130,9 +1130,9 @@ static void timerlat_hist_set_signals(struct timerlat_params *params) { signal(SIGINT, stop_hist); - if (params->duration) { + if (params->common.duration) { signal(SIGALRM, stop_hist); - alarm(params->duration); + alarm(params->common.duration); } } =20 @@ -1199,16 +1199,16 @@ int timerlat_hist_main(int argc, char *argv[]) goto out_free; } =20 - if (params->set_sched) { - retval =3D set_comm_sched_attr("timerlat/", ¶ms->sched_param); + if (params->common.set_sched) { + retval =3D set_comm_sched_attr("timerlat/", ¶ms->common.sched_param); if (retval) { err_msg("Failed to set sched parameters\n"); goto out_free; } } =20 - if (params->cgroup && !params->user_workload) { - retval =3D set_comm_cgroup("timerlat/", params->cgroup_name); + if (params->common.cgroup && !params->user_workload) { + retval =3D set_comm_cgroup("timerlat/", params->common.cgroup_name); if (!retval) { err_msg("Failed to move threads to cgroup\n"); goto out_free; @@ -1232,7 +1232,7 @@ int timerlat_hist_main(int argc, char *argv[]) nr_cpus =3D sysconf(_SC_NPROCESSORS_CONF); =20 for (i =3D 0; i < nr_cpus; i++) { - if (params->cpus && !CPU_ISSET(i, ¶ms->monitored_cpus)) + if (params->common.cpus && !CPU_ISSET(i, ¶ms->common.monitored_cpus= )) continue; if (save_cpu_idle_disable_state(i) < 0) { err_msg("Could not save cpu idle state.\n"); @@ -1245,21 +1245,21 @@ int timerlat_hist_main(int argc, char *argv[]) } } =20 - if (params->trace_output) { + if (params->common.trace_output) { record =3D osnoise_init_trace_tool("timerlat"); if (!record) { err_msg("Failed to enable the trace instance\n"); goto out_free; } =20 - if (params->events) { - retval =3D trace_events_enable(&record->trace, params->events); + if (params->common.events) { + retval =3D trace_events_enable(&record->trace, params->common.events); if (retval) goto out_hist; } =20 - if (params->buffer_size > 0) { - retval =3D trace_set_buffer_size(&record->trace, params->buffer_size); + if (params->common.buffer_size > 0) { + retval =3D trace_set_buffer_size(&record->trace, params->common.buffer_= size); if (retval) goto out_hist; } @@ -1289,22 +1289,22 @@ int timerlat_hist_main(int argc, char *argv[]) /* all threads left */ params_u.stopped_running =3D 0; =20 - params_u.set =3D ¶ms->monitored_cpus; - if (params->set_sched) - params_u.sched_param =3D ¶ms->sched_param; + params_u.set =3D ¶ms->common.monitored_cpus; + if (params->common.set_sched) + params_u.sched_param =3D ¶ms->common.sched_param; else params_u.sched_param =3D NULL; =20 - params_u.cgroup_name =3D params->cgroup_name; + params_u.cgroup_name =3D params->common.cgroup_name; =20 retval =3D pthread_create(&timerlat_u, NULL, timerlat_u_dispatcher, &par= ams_u); if (retval) err_msg("Error creating timerlat user-space threads\n"); } =20 - if (params->warmup > 0) { - debug_msg("Warming up for %d seconds\n", params->warmup); - sleep(params->warmup); + if (params->common.warmup > 0) { + debug_msg("Warming up for %d seconds\n", params->common.warmup); + sleep(params->common.warmup); if (stop_tracing) goto out_hist; } @@ -1316,7 +1316,7 @@ int timerlat_hist_main(int argc, char *argv[]) * tracing while enabling other instances. The trace instance is the * one with most valuable information. */ - if (params->trace_output) + if (params->common.trace_output) trace_instance_start(&record->trace); if (!params->no_aa) trace_instance_start(&aa->trace); @@ -1335,7 +1335,7 @@ int timerlat_hist_main(int argc, char *argv[]) =20 if (no_bpf) { while (!stop_tracing) { - sleep(params->sleep_time); + sleep(params->common.sleep_time); =20 retval =3D tracefs_iterate_raw_events(trace->tep, trace->inst, @@ -1384,10 +1384,11 @@ int timerlat_hist_main(int argc, char *argv[]) printf("rtla timerlat hit stop tracing\n"); =20 if (!params->no_aa) - timerlat_auto_analysis(params->stop_us, params->stop_total_us); + timerlat_auto_analysis(params->common.stop_us, + params->common.stop_total_us); =20 save_trace_to_file(record ? record->trace.inst : NULL, - params->trace_output); + params->common.trace_output); return_value =3D FAILED; } =20 @@ -1397,13 +1398,13 @@ int timerlat_hist_main(int argc, char *argv[]) close(dma_latency_fd); if (params->deepest_idle_state >=3D -1) { for (i =3D 0; i < nr_cpus; i++) { - if (params->cpus && !CPU_ISSET(i, ¶ms->monitored_cpus)) + if (params->common.cpus && !CPU_ISSET(i, ¶ms->common.monitored_cpus= )) continue; restore_cpu_idle_disable_state(i); } } - trace_events_destroy(&record->trace, params->events); - params->events =3D NULL; + trace_events_destroy(&record->trace, params->common.events); + params->common.events =3D NULL; out_free: timerlat_free_histogram(tool->data); osnoise_destroy_tool(aa); diff --git a/tools/tracing/rtla/src/timerlat_top.c b/tools/tracing/rtla/src= /timerlat_top.c index 7365e08fe986..bd811ff1130f 100644 --- a/tools/tracing/rtla/src/timerlat_top.c +++ b/tools/tracing/rtla/src/timerlat_top.c @@ -457,7 +457,7 @@ timerlat_print_stats(struct timerlat_params *params, st= ruct osnoise_tool *top) timerlat_top_header(params, top); =20 for (i =3D 0; i < nr_cpus; i++) { - if (params->cpus && !CPU_ISSET(i, ¶ms->monitored_cpus)) + if (params->common.cpus && !CPU_ISSET(i, ¶ms->common.monitored_cpus)) continue; timerlat_top_print(top, i); timerlat_top_update_sum(top, i, &summary); @@ -607,22 +607,22 @@ static struct timerlat_params auto_thresh =3D get_llong_from_str(optarg); =20 /* set thread stop to auto_thresh */ - params->stop_total_us =3D auto_thresh; - params->stop_us =3D auto_thresh; + params->common.stop_total_us =3D auto_thresh; + params->common.stop_us =3D auto_thresh; =20 /* get stack trace */ params->print_stack =3D auto_thresh; =20 /* set trace */ - params->trace_output =3D "timerlat_trace.txt"; + params->common.trace_output =3D "timerlat_trace.txt"; break; case '5': /* it is here because it is similar to -a */ auto_thresh =3D get_llong_from_str(optarg); =20 /* set thread stop to auto_thresh */ - params->stop_total_us =3D auto_thresh; - params->stop_us =3D auto_thresh; + params->common.stop_total_us =3D auto_thresh; + params->common.stop_us =3D auto_thresh; =20 /* get stack trace */ params->print_stack =3D auto_thresh; @@ -631,27 +631,27 @@ static struct timerlat_params params->aa_only =3D 1; break; case 'c': - retval =3D parse_cpu_set(optarg, ¶ms->monitored_cpus); + retval =3D parse_cpu_set(optarg, ¶ms->common.monitored_cpus); if (retval) timerlat_top_usage("\nInvalid -c cpu list\n"); - params->cpus =3D optarg; + params->common.cpus =3D optarg; break; case 'C': - params->cgroup =3D 1; + params->common.cgroup =3D 1; if (!optarg) { /* will inherit this cgroup */ - params->cgroup_name =3D NULL; + params->common.cgroup_name =3D NULL; } else if (*optarg =3D=3D '=3D') { /* skip the =3D */ - params->cgroup_name =3D ++optarg; + params->common.cgroup_name =3D ++optarg; } break; case 'D': config_debug =3D 1; break; case 'd': - params->duration =3D parse_seconds_duration(optarg); - if (!params->duration) + params->common.duration =3D parse_seconds_duration(optarg); + if (!params->common.duration) timerlat_top_usage("Invalid -d duration\n"); break; case 'e': @@ -661,24 +661,24 @@ static struct timerlat_params exit(EXIT_FAILURE); } =20 - if (params->events) - tevent->next =3D params->events; - params->events =3D tevent; + if (params->common.events) + tevent->next =3D params->common.events; + params->common.events =3D tevent; break; case 'h': case '?': timerlat_top_usage(NULL); break; case 'H': - params->hk_cpus =3D 1; - retval =3D parse_cpu_set(optarg, ¶ms->hk_cpu_set); + 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); } break; case 'i': - params->stop_us =3D get_llong_from_str(optarg); + params->common.stop_us =3D get_llong_from_str(optarg); break; case 'k': params->kernel_workload =3D true; @@ -692,10 +692,10 @@ static struct timerlat_params timerlat_top_usage("Period longer than 1 s\n"); break; case 'P': - retval =3D parse_prio(optarg, ¶ms->sched_param); + retval =3D parse_prio(optarg, ¶ms->common.sched_param); if (retval =3D=3D -1) timerlat_top_usage("Invalid -P priority"); - params->set_sched =3D 1; + params->common.set_sched =3D 1; break; case 'q': params->quiet =3D 1; @@ -704,18 +704,18 @@ static struct timerlat_params params->print_stack =3D get_llong_from_str(optarg); break; case 'T': - params->stop_total_us =3D get_llong_from_str(optarg); + params->common.stop_total_us =3D get_llong_from_str(optarg); break; case 't': if (optarg) { if (optarg[0] =3D=3D '=3D') - params->trace_output =3D &optarg[1]; + params->common.trace_output =3D &optarg[1]; else - params->trace_output =3D &optarg[0]; + params->common.trace_output =3D &optarg[0]; } else if (optind < argc && argv[optind][0] !=3D '-') - params->trace_output =3D argv[optind]; + params->common.trace_output =3D argv[optind]; else - params->trace_output =3D "timerlat_trace.txt"; + params->common.trace_output =3D "timerlat_trace.txt"; =20 break; case 'u': @@ -725,8 +725,8 @@ static struct timerlat_params params->user_data =3D true; break; case '0': /* trigger */ - if (params->events) { - retval =3D trace_event_add_trigger(params->events, optarg); + 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); @@ -736,8 +736,8 @@ static struct timerlat_params } break; case '1': /* filter */ - if (params->events) { - retval =3D trace_event_add_filter(params->events, optarg); + 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); @@ -760,10 +760,10 @@ static struct timerlat_params params->dump_tasks =3D 1; break; case '6': - params->warmup =3D get_llong_from_str(optarg); + params->common.warmup =3D get_llong_from_str(optarg); break; case '7': - params->buffer_size =3D get_llong_from_str(optarg); + params->common.buffer_size =3D get_llong_from_str(optarg); break; case '8': params->deepest_idle_state =3D get_llong_from_str(optarg); @@ -781,7 +781,7 @@ static struct timerlat_params /* * Auto analysis only happens if stop tracing, thus: */ - if (!params->stop_us && !params->stop_total_us) + if (!params->common.stop_us && !params->common.stop_total_us) params->no_aa =3D 1; =20 if (params->no_aa && params->aa_only) @@ -869,9 +869,9 @@ static void timerlat_top_set_signals(struct timerlat_params *params) { signal(SIGINT, stop_top); - if (params->duration) { + if (params->common.duration) { signal(SIGALRM, stop_top); - alarm(params->duration); + alarm(params->common.duration); } } =20 @@ -888,7 +888,7 @@ timerlat_top_main_loop(struct osnoise_tool *top, int retval; =20 while (!stop_tracing) { - sleep(params->sleep_time); + sleep(params->common.sleep_time); =20 if (params->aa_only && !osnoise_trace_is_off(top, record)) continue; @@ -954,7 +954,7 @@ timerlat_top_bpf_main_loop(struct osnoise_tool *top, =20 /* Pull and display data in a loop */ while (!stop_tracing) { - wait_retval =3D timerlat_bpf_wait(params->sleep_time); + wait_retval =3D timerlat_bpf_wait(params->common.sleep_time); =20 retval =3D timerlat_top_bpf_pull_data(top); if (retval) { @@ -1044,16 +1044,16 @@ int timerlat_top_main(int argc, char *argv[]) goto out_free; } =20 - if (params->set_sched) { - retval =3D set_comm_sched_attr("timerlat/", ¶ms->sched_param); + if (params->common.set_sched) { + retval =3D set_comm_sched_attr("timerlat/", ¶ms->common.sched_param); if (retval) { err_msg("Failed to set sched parameters\n"); goto out_free; } } =20 - if (params->cgroup && !params->user_data) { - retval =3D set_comm_cgroup("timerlat/", params->cgroup_name); + if (params->common.cgroup && !params->user_data) { + retval =3D set_comm_cgroup("timerlat/", params->common.cgroup_name); if (!retval) { err_msg("Failed to move threads to cgroup\n"); goto out_free; @@ -1077,7 +1077,7 @@ int timerlat_top_main(int argc, char *argv[]) nr_cpus =3D sysconf(_SC_NPROCESSORS_CONF); =20 for (i =3D 0; i < nr_cpus; i++) { - if (params->cpus && !CPU_ISSET(i, ¶ms->monitored_cpus)) + if (params->common.cpus && !CPU_ISSET(i, ¶ms->common.monitored_cpus= )) continue; if (save_cpu_idle_disable_state(i) < 0) { err_msg("Could not save cpu idle state.\n"); @@ -1090,21 +1090,21 @@ int timerlat_top_main(int argc, char *argv[]) } } =20 - if (params->trace_output) { + if (params->common.trace_output) { record =3D osnoise_init_trace_tool("timerlat"); if (!record) { err_msg("Failed to enable the trace instance\n"); goto out_free; } =20 - if (params->events) { - retval =3D trace_events_enable(&record->trace, params->events); + if (params->common.events) { + retval =3D trace_events_enable(&record->trace, params->common.events); if (retval) goto out_top; } =20 - if (params->buffer_size > 0) { - retval =3D trace_set_buffer_size(&record->trace, params->buffer_size); + if (params->common.buffer_size > 0) { + retval =3D trace_set_buffer_size(&record->trace, params->common.buffer_= size); if (retval) goto out_top; } @@ -1137,22 +1137,22 @@ int timerlat_top_main(int argc, char *argv[]) /* all threads left */ params_u.stopped_running =3D 0; =20 - params_u.set =3D ¶ms->monitored_cpus; - if (params->set_sched) - params_u.sched_param =3D ¶ms->sched_param; + params_u.set =3D ¶ms->common.monitored_cpus; + if (params->common.set_sched) + params_u.sched_param =3D ¶ms->common.sched_param; else params_u.sched_param =3D NULL; =20 - params_u.cgroup_name =3D params->cgroup_name; + params_u.cgroup_name =3D params->common.cgroup_name; =20 retval =3D pthread_create(&timerlat_u, NULL, timerlat_u_dispatcher, &par= ams_u); if (retval) err_msg("Error creating timerlat user-space threads\n"); } =20 - if (params->warmup > 0) { - debug_msg("Warming up for %d seconds\n", params->warmup); - sleep(params->warmup); + if (params->common.warmup > 0) { + debug_msg("Warming up for %d seconds\n", params->common.warmup); + sleep(params->common.warmup); } =20 /* @@ -1162,7 +1162,7 @@ int timerlat_top_main(int argc, char *argv[]) * tracing while enabling other instances. The trace instance is the * one with most valuable information. */ - if (params->trace_output) + if (params->common.trace_output) trace_instance_start(&record->trace); if (!params->no_aa) trace_instance_start(&aa->trace); @@ -1203,10 +1203,11 @@ int timerlat_top_main(int argc, char *argv[]) printf("rtla timerlat hit stop tracing\n"); =20 if (!params->no_aa) - timerlat_auto_analysis(params->stop_us, params->stop_total_us); + timerlat_auto_analysis(params->common.stop_us, + params->common.stop_total_us); =20 save_trace_to_file(record ? record->trace.inst : NULL, - params->trace_output); + params->common.trace_output); return_value =3D FAILED; } else if (params->aa_only) { /* @@ -1226,13 +1227,13 @@ int timerlat_top_main(int argc, char *argv[]) close(dma_latency_fd); if (params->deepest_idle_state >=3D -1) { for (i =3D 0; i < nr_cpus; i++) { - if (params->cpus && !CPU_ISSET(i, ¶ms->monitored_cpus)) + if (params->common.cpus && !CPU_ISSET(i, ¶ms->common.monitored_cpus= )) continue; restore_cpu_idle_disable_state(i); } } - trace_events_destroy(&record->trace, params->events); - params->events =3D NULL; + trace_events_destroy(&record->trace, params->common.events); + params->common.events =3D NULL; out_free: timerlat_free_top(top->data); if (aa && aa !=3D top) diff --git a/tools/tracing/rtla/src/utils.h b/tools/tracing/rtla/src/utils.h index a2a6f89f342d..ea3ce1b59ac5 100644 --- a/tools/tracing/rtla/src/utils.h +++ b/tools/tracing/rtla/src/utils.h @@ -59,6 +59,37 @@ struct sched_attr { }; #endif /* SCHED_ATTR_SIZE_VER0 */ =20 +/* + * common_params - Parameters shared between timerlat_params and osnoise_p= arams + * + * This structure contains all the fields that are identical in both + * timerlat_params and osnoise_params structures, eliminating duplication. + */ +struct common_params { + /* trace configuration */ + char *cpus; + cpu_set_t monitored_cpus; + struct trace_events *events; + int buffer_size; + char *trace_output; + + /* Timing parameters */ + int warmup; + unsigned long long runtime; + long long stop_us; + long long stop_total_us; + int sleep_time; + int duration; + + /* Scheduling parameters */ + int set_sched; + struct sched_attr sched_param; + int cgroup; + char *cgroup_name; + int hk_cpus; + cpu_set_t hk_cpu_set; +}; + int parse_prio(char *arg, struct sched_attr *sched_param); int parse_cpu_set(char *cpu_list, cpu_set_t *set); int __set_sched_attr(int pid, struct sched_attr *attr); --=20 2.48.1