Re: [PATCH v4 4/4] KVM: selftests: Run dirty_log_perf_test on specific CPUs

Sean Christopherson
2022-10-06T20:27:10Z

On Thu, Oct 06, 2022, Sean Christopherson wrote:
> On Thu, Oct 06, 2022, Vipin Sharma wrote:
> > +{
> > + cpu_set_t cpuset;
> > + int err;
> > +
> > + CPU_ZERO(&cpuset);
> > + CPU_SET(pcpu, &cpuset);
>
> To save user pain:
>
> r = sched_getaffinity(0, sizeof(allowed_mask), &allowed_mask);
> TEST_ASSERT(!r, "sched_getaffinity failed, errno = %d (%s)", errno,
> strerror(errno));

Forgot TEST_ASSERT() already provides errno, this can just be:

TEST_ASSERT(!r, "sched_getaffinity() failed");

>
> TEST_ASSERT(CPU_ISSET(pcpu, &allowed_mask),
> "Task '%d' not allowed to run on pCPU '%d'\n");
>
> CPU_ZERO(&allowed_mask);
> CPU_SET(cpu, &allowed_mask);
>
> that way the user will get an explicit error message if they try to pin a vCPU/task
> that has already been affined by something else. And then, in theory,
> sched_setaffinity() should never fail.
>
> Or you could have two cpu_set_t objects and use CPU_AND(), but that seems
> unnecessarily complex.
>
> > + err = sched_setaffinity(0, sizeof(cpu_set_t), &cpuset);
> > + TEST_ASSERT(err == 0, "sched_setaffinity() errored out for pcpu: %d\n", pcpu);
>
> !err is the preferred style, though I vote to use "r" instead of "err". And print
> the errno so that the user can debug.

As above, ignore the last, forgot TEST_ASSERT() provides errno.

>
> r = sched_setaffinity(0, sizeof(allowed_mask), &allowed_mask);
> TEST_ASSERT(!r, "sched_setaffinity failed, errno = %d (%s)",
> errno, strerror(errno));