From: Reinette Chatre <reinette.chatre@intel.com>
To: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Cc: Shuah Khan <skhan@linuxfoundation.org>,
<linux-kselftest@vger.kernel.org>, Shuah Khan <shuah@kernel.org>,
Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>,
Fenghua Yu <fenghua.yu@intel.com>,
"Babu Moger" <babu.moger@amd.com>,
LKML <linux-kernel@vger.kernel.org>,
Shaopeng Tan <tan.shaopeng@jp.fujitsu.com>
Subject: Re: [PATCH v3 5/7] selftests/resctrl: Make benchmark command const and build it with pointers
Date: Wed, 30 Aug 2023 10:47:19 -0700 [thread overview]
Message-ID: <159d8e07-cab7-9430-b83f-9c6de4d519d4@intel.com> (raw)
In-Reply-To: <184bd8bb-5622-64f9-9f65-6674db935a21@linux.intel.com>
Hi Ilpo,
On 8/30/2023 1:59 AM, Ilpo Järvinen wrote:
> On Tue, 29 Aug 2023, Reinette Chatre wrote:
>> This is a tricky one. If I understand correctly this goto target makes
>> some assumptions about the state (no test plan created yet) and exit
>> reason (it has to be skipped). A temporary variable is also thrown into
>> the mix.
>
> So in the end the symmetry proved to be not as simple as was depicted
> earlier but "tricky"... I tried to warn about this and it's why I wished
> to avoid the allocation entirely. Without allocation, there would have not
> been need for the temporary variable nor adjusting the control flow with
> that label.
hmmm ... I do not see why an allocation forces the use of a temporary
variable and a change in control (more below).
>
>> Can this not be simplified by moving the snippet where
>> benchmark_cmd[] is initialized to fill_buf to be just before the tests
>> are run? Perhaps right before ksft_set_plan()?
>
> So I throw a temporary variable into the mix (has_ben) to keep track when
> benchmark_cmd needs to be initialized to the default command? It doesn't
> play well with what I've in queue after this when user parameters are
> collected into a struct which is initialized to default value by a helper
> function before any argument processing. That is, initializing the
> parameters to defaults needs to be split before and after the parameter
> parsing code.
No new temporary variable is needed. Of course, I do not have insight into
what is further down in your queue but based on this work I do think it
can be simplified. Since code is easier to consider, the snippet below
applies on top of this series and shows what I was proposing:
diff --git a/tools/testing/selftests/resctrl/resctrl_tests.c b/tools/testing/selftests/resctrl/resctrl_tests.c
index ae9001ef7b0a..8033eabb9aa8 100644
--- a/tools/testing/selftests/resctrl/resctrl_tests.c
+++ b/tools/testing/selftests/resctrl/resctrl_tests.c
@@ -170,11 +170,10 @@ static void run_cat_test(int cpu_no, int no_of_bits)
int main(int argc, char **argv)
{
bool mbm_test = true, mba_test = true, cmt_test = true;
+ const char *benchmark_cmd[BENCHMARK_ARGS] = {};
int c, cpu_no = 1, i, no_of_bits = 0;
- const char *benchmark_cmd[BENCHMARK_ARGS];
char *span_str = NULL;
bool cat_test = true;
- char *skip_reason;
int tests = 0;
int ret;
@@ -247,17 +246,6 @@ int main(int argc, char **argv)
}
}
- /* If no benchmark is given by "-b" argument, use fill_buf. */
- benchmark_cmd[0] = "fill_buf";
- ret = asprintf(&span_str, "%u", DEFAULT_SPAN);
- if (ret < 0)
- ksft_exit_fail_msg("Out of memory!\n");
- benchmark_cmd[1] = span_str;
- benchmark_cmd[2] = "1";
- benchmark_cmd[3] = "0";
- benchmark_cmd[4] = "false";
- benchmark_cmd[5] = NULL;
-
last_arg:
ksft_print_header();
@@ -267,23 +255,30 @@ int main(int argc, char **argv)
* 1. We write to resctrl FS
* 2. We execute perf commands
*/
- if (geteuid() != 0) {
- skip_reason = "Not running as root. Skipping...\n";
- goto free_span;
- }
+ if (geteuid() != 0)
+ return ksft_exit_skip("Not running as root. Skipping...\n");
- if (!check_resctrlfs_support()) {
- skip_reason = "resctrl FS does not exist. Enable X86_CPU_RESCTRL config option.\n";
- goto free_span;
- }
+ if (!check_resctrlfs_support())
+ return ksft_exit_skip("resctrl FS does not exist. Enable X86_CPU_RESCTRL config option.\n");
- if (umount_resctrlfs()) {
- skip_reason = "resctrl FS unmount failed.\n";
- goto free_span;
- }
+ if (umount_resctrlfs())
+ return ksft_exit_skip("resctrl FS unmount failed.\n");
filter_dmesg();
+ if (!benchmark_cmd[0]) {
+ /* If no benchmark is given by "-b" argument, use fill_buf. */
+ benchmark_cmd[0] = "fill_buf";
+ ret = asprintf(&span_str, "%u", DEFAULT_SPAN);
+ if (ret < 0)
+ ksft_exit_fail_msg("Out of memory!\n");
+ benchmark_cmd[1] = span_str;
+ benchmark_cmd[2] = "1";
+ benchmark_cmd[3] = "0";
+ benchmark_cmd[4] = "false";
+ benchmark_cmd[5] = NULL;
+ }
+
ksft_set_plan(tests ? : 4);
if (mbm_test)
@@ -300,8 +295,4 @@ int main(int argc, char **argv)
free(span_str);
ksft_finished();
-
-free_span:
- free(span_str);
- return ksft_exit_skip(skip_reason);
}
next prev parent reply other threads:[~2023-08-30 18:45 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-23 13:15 [PATCH v3 0/7] selftests/resctrl: Rework benchmark command handling Ilpo Järvinen
2023-08-23 13:15 ` [PATCH v3 1/7] selftests/resctrl: Ensure the benchmark commands fits to its array Ilpo Järvinen
2023-08-23 13:15 ` [PATCH v3 2/7] selftests/resctrl: Correct benchmark command help Ilpo Järvinen
2023-08-30 0:53 ` Reinette Chatre
2023-08-23 13:15 ` [PATCH v3 3/7] selftests/resctrl: Remove bw_report and bm_type from main() Ilpo Järvinen
2023-08-23 13:15 ` [PATCH v3 4/7] selftests/resctrl: Simplify span lifetime Ilpo Järvinen
2023-08-23 13:15 ` [PATCH v3 5/7] selftests/resctrl: Make benchmark command const and build it with pointers Ilpo Järvinen
2023-08-30 0:53 ` Reinette Chatre
2023-08-30 8:59 ` Ilpo Järvinen
2023-08-30 17:47 ` Reinette Chatre [this message]
2023-08-31 7:10 ` Ilpo Järvinen
2023-08-23 13:15 ` [PATCH v3 6/7] selftests/resctrl: Remove ben_count variable Ilpo Järvinen
2023-08-23 13:15 ` [PATCH v3 7/7] selftests/resctrl: Cleanup benchmark argument parsing Ilpo Järvinen
2023-08-29 12:48 ` Maciej Wieczór-Retman
2023-08-29 13:04 ` Ilpo Järvinen
2023-08-29 13:23 ` Maciej Wieczór-Retman
2023-08-25 8:36 ` [PATCH v3 0/7] selftests/resctrl: Rework benchmark command handling Shaopeng Tan (Fujitsu)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=159d8e07-cab7-9430-b83f-9c6de4d519d4@intel.com \
--to=reinette.chatre@intel.com \
--cc=babu.moger@amd.com \
--cc=fenghua.yu@intel.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=maciej.wieczor-retman@intel.com \
--cc=shuah@kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=tan.shaopeng@jp.fujitsu.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.