On Thu, Oct 27, 2022 at 8:56 AM Sean Christopherson <seanjc@xxxxxxxxxx> wrote: > > On Thu, Oct 27, 2022, Wang, Wei W wrote: > > On Wednesday, October 26, 2022 11:44 PM, Sean Christopherson wrote: > > > If we go this route in the future, we'd need to add a worker trampoline as the > > > pinning needs to happen in the worker task itself to guarantee that the pinning > > > takes effect before the worker does anything useful. That should be very > > > doable. > > > > The alternative way is the one I shared before, using this: > > > > /* Thread created with attribute ATTR will be limited to run only on > > the processors represented in CPUSET. */ > > extern int pthread_attr_setaffinity_np (pthread_attr_t *__attr, > > size_t __cpusetsize, > > const cpu_set_t *__cpuset) > > > > Basically, the thread is created on the pCPU as user specified. > > I think this is better than "creating the thread on an arbitrary pCPU > > and then pinning it to the user specified pCPU in the thread's start routine". > > Ah, yeah, that's better. > pthread_create() will internally call sched_setaffinity() syscall after creation of a thread on a random CPU. So, from the performance side there is not much difference between the two approaches. However, we will still need pin_this_task_to_pcpu()/sched_affinity() to move the main thread to a specific pCPU, therefore, I am thinking of keeping the current approach unless there is a strong objection to it. > > Probably we also don't need "bool pin_vcpus". > > Yeah, but for selftests shaving bytes is not exactly top priority, and having a > dedicated flag avoids the need for magic numbers. If Vipin had used -1, I'd > probably be fine with that, but I'm also totally fine using a dedicated flag too. > Same, it is not performance critical in this case to add a magical -1.