Skip to content

Commit

Permalink
ht_affinity.c: fix ht_affinity test failure
Browse files Browse the repository at this point in the history
Running ht_affinity test fails:

	smt_smp_affinity    0  TINFO  :  Set affinity through system call
	smt_smp_affinity    0  TINFO  :  Set test process affinity.
	mask: 1
	smt_smp_affinity    0  TINFO  :  ...Error

	...

	smt_smp_affinity    0  TINFO  :  Set test process affinity.
	mask: c0000000
	smt_smp_affinity    0  TINFO  :  ...Error
	smt_smp_affinity    3  TFAIL  :  ht_affinity.c:240: System call setaffinity() is error.

The type of cpumask pointer used in set_affinity() is unsigned long, but
ht_affinity used a unsigned int pointer. When kernel copy cpumask from
user-space pointer, the high 32bit of cpumask is a random value. So the
process can't be bind to the cpu specified by users.

After using sizeof on the mask instead of sizeof(unsigned long), ht_affinity
test succeeds:

	smt_smp_affinity    0  TINFO  :  Set affinity through system call
	smt_smp_affinity    0  TINFO  :  Set test process affinity.
	mask: 1
	smt_smp_affinity    0  TINFO  :  ...OK

	...

	smt_smp_affinity    0  TINFO  :  Set test process affinity.
	mask: c0000000
	smt_smp_affinity    0  TINFO  :  ...OK
	smt_smp_affinity    3  TPASS  :  System call setaffinity() is OK.

Signed-off-by: Haifeng Xu <[email protected]>
Suggested-by: Cyril Hrubis <[email protected]>
Reviewed-by: Cyril Hrubis <[email protected]>
  • Loading branch information
hfxsp authored and metan-ucw committed Sep 23, 2024
1 parent 41cf526 commit 08cb938
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ int HT_SetAffinity(void)
tst_resm(TINFO, "Set test process affinity.");
printf("mask: %x\n", mask);

sched_setaffinity(pid, sizeof(unsigned long), &mask);
sched_setaffinity(pid, sizeof(mask), &mask);

for (j = 0; j < 10; j++) {
for (k = 0; k < 10; k++) {
Expand Down Expand Up @@ -95,7 +95,7 @@ int HT_SetAffinity(void)
tst_resm(TINFO, "Set test process affinity.");
printf("mask: %x\n", mask);

sched_setaffinity(pid, sizeof(unsigned long), &mask);
sched_setaffinity(pid, sizeof(mask), &mask);

for (j = 0; j < 10; j++) {
for (k = 0; k < 10; k++) {
Expand Down

0 comments on commit 08cb938

Please sign in to comment.