Skip to content

Commit efffa8c

Browse files
rchatreshuahkh
authored andcommitted
selftests/resctrl: Make wraparound handling obvious
Within mba_setup() the programmed bandwidth delay value starts at the maximum (100, or rather ALLOCATION_MAX) and progresses towards ALLOCATION_MIN by decrementing with ALLOCATION_STEP. The programmed bandwidth delay should never be negative, so representing it with an unsigned int is most appropriate. This may introduce confusion because of the "allocation > ALLOCATION_MAX" check used to check wraparound of the subtraction. Modify the mba_setup() flow to start at the minimum, ALLOCATION_MIN, and incrementally, with ALLOCATION_STEP steps, adjust the bandwidth delay value. This avoids wraparound while making the purpose of "allocation > ALLOCATION_MAX" clear and eliminates the need for the "allocation < ALLOCATION_MIN" check. Reported-by: Ilpo Järvinen <[email protected]> Closes: https://lore.kernel.org/lkml/[email protected]/ Signed-off-by: Reinette Chatre <[email protected]> Reviewed-by: Ilpo Järvinen <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent 4605843 commit efffa8c

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

tools/testing/selftests/resctrl/mba_test.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ static int mba_setup(const struct resctrl_test *test,
3939
const struct user_params *uparams,
4040
struct resctrl_val_param *p)
4141
{
42-
static int runs_per_allocation, allocation = 100;
42+
static unsigned int allocation = ALLOCATION_MIN;
43+
static int runs_per_allocation;
4344
char allocation_str[64];
4445
int ret;
4546

@@ -50,7 +51,7 @@ static int mba_setup(const struct resctrl_test *test,
5051
if (runs_per_allocation++ != 0)
5152
return 0;
5253

53-
if (allocation < ALLOCATION_MIN || allocation > ALLOCATION_MAX)
54+
if (allocation > ALLOCATION_MAX)
5455
return END_OF_TESTS;
5556

5657
sprintf(allocation_str, "%d", allocation);
@@ -59,7 +60,7 @@ static int mba_setup(const struct resctrl_test *test,
5960
if (ret < 0)
6061
return ret;
6162

62-
allocation -= ALLOCATION_STEP;
63+
allocation += ALLOCATION_STEP;
6364

6465
return 0;
6566
}
@@ -72,8 +73,9 @@ static int mba_measure(const struct user_params *uparams,
7273

7374
static bool show_mba_info(unsigned long *bw_imc, unsigned long *bw_resc)
7475
{
75-
int allocation, runs;
76+
unsigned int allocation;
7677
bool ret = false;
78+
int runs;
7779

7880
ksft_print_msg("Results are displayed in (MB)\n");
7981
/* Memory bandwidth from 100% down to 10% */
@@ -103,7 +105,7 @@ static bool show_mba_info(unsigned long *bw_imc, unsigned long *bw_resc)
103105
avg_diff_per > MAX_DIFF_PERCENT ?
104106
"Fail:" : "Pass:",
105107
MAX_DIFF_PERCENT,
106-
ALLOCATION_MAX - ALLOCATION_STEP * allocation);
108+
ALLOCATION_MIN + ALLOCATION_STEP * allocation);
107109

108110
ksft_print_msg("avg_diff_per: %d%%\n", avg_diff_per);
109111
ksft_print_msg("avg_bw_imc: %lu\n", avg_bw_imc);

0 commit comments

Comments
 (0)