selftests/resctrl: Fixes to error handling logic
Subsystems (2)
cover selftests/resctrl: Fixes to error handling logic
This series fixes a few cleanup/error handling problems.
Fenghua Yu (1):
selftests/resctrl: Return error if memory is not allocated
Ilpo Järvinen (3):
selftests/resctrl: Move ->setup() call outside of test specific
branches
selftests/resctrl: Allow ->setup() to return errors selftests/resctrl: Check for return value after write_schemata()
tools/testing/selftests/resctrl/cache.c | 4 +++- tools/testing/selftests/resctrl/cat_test.c | 2 +- tools/testing/selftests/resctrl/cmt_test.c | 2 +- tools/testing/selftests/resctrl/fill_buf.c | 2 ++ tools/testing/selftests/resctrl/mba_test.c | 9 ++++++-- tools/testing/selftests/resctrl/mbm_test.c | 2 +- tools/testing/selftests/resctrl/resctrl.h | 2 ++ tools/testing/selftests/resctrl/resctrl_val.c | 21 +++++++------------ 8 files changed, 25 insertions(+), 19 deletions(-)
Signature · 1 line
2.30.2
PATCH 1/4 selftests/resctrl: Return error if memory is not allocated
From: Fenghua Yu <[email protected]>
malloc_and_init_memory() in fill_buf isn't checking if memalign() successfully allocated memory or not before accessing the memory.
Check the return value of memalign() and return NULL if allocating aligned memory fails.
--- tools/testing/selftests/resctrl/fill_buf.c | 2 ++ 1 file changed, 2 insertions(+)
tools/testing/selftests/resctrl/fill_buf.c +2 -0
@@ -68,6 +68,8 @@ static void *malloc_and_init_memory(size_t s)size_t s64;void *p =memalign (PAGE_SIZE , s); +if (!p) +return p; p64 = (uint64_t *)p; s64 = s /sizeof (uint64_t );
Signature · 1 line
2.30.2
Reinette Chatre
maintainerRe: [PATCH 1/4] selftests/resctrl: Return error if memory is not allocated
Hi Ilpo,
I do not see a why two patch series are needed for the resctrl fixes. It may make it easier for everybody if it is handled as one patch series (with fixes first)?
Quoted 10 lines · Ilpo Järvinen
From: Fenghua Yu <[email protected]>
malloc_and_init_memory()infill_bufisn't checking ifmemalign()successfully allocated memory or not before accessing the memory.Check the return value of
memalign()and return NULL if allocating aligned memory fails.Fixes a2561b12fe39 ("selftests/resctrl: Add built in benchmark")Signed-off-by Fenghua Yu <[email protected]>
Missing your Signed-off-by?
tools/testing/selftests/resctrl/fill_buf.c static void *malloc_and_init_memory(size_t s) · line 70
Quoted 12 lines
--- tools/testing/selftests/resctrl/fill_buf.c | 2 ++ 1 file changed, 2 insertions(+)tools/testing/selftests/resctrl/fill_buf.c +0
-0@@ -68,6 +68,8 @@ static void *malloc_and_init_memory(size_t s)size_t s64;void *p =memalign (PAGE_SIZE , s);
This may also be a good time to stop using an obsolete call?
tools/testing/selftests/resctrl/fill_buf.c static void *malloc_and_init_memory(size_t s) · line 72
Quoted 2 lines
tools/testing/selftests/resctrl/fill_buf.c +2
-0+if (!p) +return p;
Could you please return NULL explicitly?
tools/testing/selftests/resctrl/fill_buf.c static void *malloc_and_init_memory(size_t s) · line 75
Quoted 3 lines
tools/testing/selftests/resctrl/fill_buf.c +0
-0p64 = (uint64_t *)p; s64 = s /sizeof (uint64_t );
Reinette
Re: [PATCH 1/4] selftests/resctrl: Return error if memory is not allocated
Quoted 3 lines · Reinette Chatre
I do not see a why two patch series are needed for the resctrl fixes. It may make it easier for everybody if it is handled as one patch series (with fixes first)?
Ok, I can put the fixes and cleanups into one series.
Quoted 6 lines · Ilpo Järvinen
Quoted 5 lines
From: Fenghua Yu <[email protected]>
malloc_and_init_memory()infill_bufisn't checking ifmemalign()successfully allocated memory or not before accessing the memory.
Quoted 7 lines
Quoted 5 lines
Check the return value of
memalign()and return NULL if allocating aligned memory fails.Fixes a2561b12fe39 ("selftests/resctrl: Add built in benchmark")Signed-off-by Fenghua Yu <[email protected]>Missing your Signed-off-by?
These were intentionally. When I didn't modify the original patch at all during forward porting it, I just kept the original From and SoB as is. But from the doc you pointed me to, I see now x86 wants also handlers sobs.
Quoted 11 lines
Quoted 11 lines
--- tools/testing/selftests/resctrl/fill_buf.c | 2 ++ 1 file changed, 2 insertions(+)tools/testing/selftests/resctrl/fill_buf.c +0
-0@@ -68,6 +68,8 @@ static void *malloc_and_init_memory(size_t s)size_t s64;
Quoted 3 lines
tools/testing/selftests/resctrl/fill_buf.c static void *malloc_and_init_memory(size_t s) · line 70
Quoted 1 line
tools/testing/selftests/resctrl/fill_buf.c +0
-0void *p =memalign (PAGE_SIZE , s);This may also be a good time to stop using an obsolete call?
Sure, I can add another patch to change that to posix_memalign().
Quoted 4 lines
tools/testing/selftests/resctrl/fill_buf.c static void *malloc_and_init_memory(size_t s) · line 72
Quoted 2 lines
tools/testing/selftests/resctrl/fill_buf.c +2
-0+if (!p) +return p;Could you please return NULL explicitly?
I'll change it.
Thanks for you comments.
Signature · 1 line
i.
Reinette Chatre
maintainerRe: [PATCH 1/4] selftests/resctrl: Return error if memory is not allocated
Hi Ilpo,
Quoted 8 lines · Ilpo Järvinen
Quoted 1 line · Reinette Chatre
Missing your Signed-off-by?
These were intentionally. When I didn't modify the original patch at all during forward porting it, I just kept the original From and SoB as is. But from the doc you pointed me to, I see now x86 wants also handlers sobs.
I do not think this is x86 specific. Documentation/process/submitting-patches.rst states:
"Any further SoBs (Signed-off-by:'s) following the author's SoB are from people handling and transporting the patch, but were not involved in its development. SoB chains should reflect the **real** route a patch took as it was propagated to the maintainers and ultimately to Linus, with the first SoB entry signalling primary authorship of a single author."
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
--- tools/testing/selftests/resctrl/fill_buf.c | 2 ++ 1 file changed, 2 insertions(+)tools/testing/selftests/resctrl/fill_buf.c +0
-0@@ -68,6 +68,8 @@ static void *malloc_and_init_memory(size_t s)size_t s64;
Quoted 5 lines
Quoted 3 lines
tools/testing/selftests/resctrl/fill_buf.c static void *malloc_and_init_memory(size_t s) · line 70
Quoted 1 line
tools/testing/selftests/resctrl/fill_buf.c +0
-0void *p =memalign (PAGE_SIZE , s);This may also be a good time to stop using an obsolete call?
Sure, I can add another patch to change that to
posix_memalign().
You can also consider aligned_alloc().
Reinette
PATCH 2/4 selftests/resctrl: Move ->setup() call outside of test specific branches
In reply to Ilpo Järvinenresctrl_val() function is called only by mbm, mba, and cmt tests which means the else branch is never used and can be removed.
Presently, both of the the test branches call param->setup(). Thus, the call can be placed outside of the test specific branches reducing code duplication.
--- tools/testing/selftests/resctrl/resctrl_val.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-)
tools/testing/selftests/resctrl/resctrl_val.c +6 -13
@@ -734,29 +734,22 @@ int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param)/* Test runs until the callback setup() tells the test to stop. */ while (1 ) { + ret = param->setup (1 , param); +if (ret) { + ret =0 ; +break ; + } +if (!strncmp (resctrl_val,MBM_STR ,sizeof (MBM_STR )) || !strncmp (resctrl_val,MBA_STR ,sizeof (MBA_STR ))) { - ret = param->setup (1 , param); -if (ret) { - ret =0 ; -break ; - } - ret =measure_vals (param, &bw_resc_start);if (ret)break ; }else if (!strncmp (resctrl_val,CMT_STR ,sizeof (CMT_STR ))) { - ret = param->setup (1 , param); -if (ret) { - ret =0 ; -break ; - }sleep (1 ); ret =measure_cache_vals (param, bm_pid);if (ret)break ; - }else { -break ; } }
Signature · 1 line
2.30.2
PATCH 3/4 selftests/resctrl: Allow ->setup() to return errors
In reply to Ilpo JärvinenCurrently resctrl_val() assumes ->setup() always returns either 0 to continue tests or < 0 in case of the normal termination of tests after x runs. The latter overlaps with normal error returns.
Define END_OF_TESTS (=1) to differentiate the normal termination of tests and return errors as negative values. Alter callers of ->setup() to handle errors properly.
--- tools/testing/selftests/resctrl/cache.c | 4 +++- tools/testing/selftests/resctrl/cat_test.c | 2 +- tools/testing/selftests/resctrl/cmt_test.c | 2 +- tools/testing/selftests/resctrl/mba_test.c | 2 +- tools/testing/selftests/resctrl/mbm_test.c | 2 +- tools/testing/selftests/resctrl/resctrl.h | 2 ++ tools/testing/selftests/resctrl/resctrl_val.c | 4 +++- 7 files changed, 12 insertions(+), 6 deletions(-)
tools/testing/selftests/resctrl/cache.c +3 -1
@@ -244,10 +244,12 @@ int cat_val(struct resctrl_val_param *param)while (1 ) {if (!strncmp (resctrl_val,CAT_STR ,sizeof (CAT_STR ))) { ret = param->setup (1 , param); -if (ret) { +if (ret ==END_OF_TESTS ) { ret =0 ;break ; } +if (ret <0 ) +break ; ret =reset_enable_llc_perf (bm_pid, param->cpu_no);if (ret)break ;
tools/testing/selftests/resctrl/cat_test.c +1 -1
@@ -40,7 +40,7 @@ static int cat_setup(int num, ...)/* Run NUM_OF_RUNS times */ if (p->num_of_runs >=NUM_OF_RUNS ) -return -1 ; +return END_OF_TESTS ;if (p->num_of_runs ==0 ) {sprintf (schemata,"%lx" , p->mask);
tools/testing/selftests/resctrl/cmt_test.c +1 -1
@@ -32,7 +32,7 @@ static int cmt_setup(int num, ...)/* Run NUM_OF_RUNS times */ if (p->num_of_runs >=NUM_OF_RUNS ) -return -1 ; +return END_OF_TESTS ; p->num_of_runs++;
tools/testing/selftests/resctrl/mba_test.c +1 -1
@@ -41,7 +41,7 @@ static int mba_setup(int num, ...)return 0 ;if (allocation <ALLOCATION_MIN || allocation >ALLOCATION_MAX ) -return -1 ; +return END_OF_TESTS ;sprintf (allocation_str,"%d" , allocation);
tools/testing/selftests/resctrl/mbm_test.c +1 -1
@@ -95,7 +95,7 @@ static int mbm_setup(int num, ...)/* Run NUM_OF_RUNS times */ if (num_of_runs++ >=NUM_OF_RUNS ) -return -1 ; +return END_OF_TESTS ;va_start (param, num); p = va_arg(param, struct resctrl_val_param *);
tools/testing/selftests/resctrl/resctrl.h +2 -0
@@ -37,6 +37,8 @@#define ARCH_INTEL 1#define ARCH_AMD 2 +#define END_OF_TESTS 1 +#define PARENT_EXIT (err_msg) \ do { \ perror(err_msg); \
tools/testing/selftests/resctrl/resctrl_val.c +3 -1
@@ -735,10 +735,12 @@ int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param)/* Test runs until the callback setup() tells the test to stop. */ while (1 ) { ret = param->setup (1 , param); -if (ret) { +if (ret ==END_OF_TESTS ) { ret =0 ;break ; } +if (ret <0 ) +break ;if (!strncmp (resctrl_val,MBM_STR ,sizeof (MBM_STR )) || !strncmp (resctrl_val,MBA_STR ,sizeof (MBA_STR ))) {
Signature · 1 line
2.30.2
PATCH 4/4 selftests/resctrl: Check for return value after write_schemata()
In reply to Ilpo JärvinenMBA test case writes schemata but it forgets to check if the write is successful or not. Hence, add the check and return error properly.
--- tools/testing/selftests/resctrl/mba_test.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
tools/testing/selftests/resctrl/mba_test.c +6 -1
@@ -28,6 +28,7 @@ static int mba_setup(int num, ...)struct resctrl_val_param *p;char allocation_str[64 ];va_list param; +int ret;va_start (param, num); p = va_arg(param, struct resctrl_val_param *);
@@ -45,7 +46,11 @@ static int mba_setup(int num, ...)sprintf (allocation_str,"%d" , allocation); -write_schemata (p->ctrlgrp, allocation_str, p->cpu_no, p->resctrl_val); + ret =write_schemata (p->ctrlgrp, allocation_str, p->cpu_no, + p->resctrl_val); +if (ret <0 ) +return ret; + allocation -=ALLOCATION_STEP ;return 0 ;
Signature · 1 line
2.30.2