[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <DS0PR11MB637351B52E5F8752E7DA16A4DC309@DS0PR11MB6373.namprd11.prod.outlook.com>
Date: Wed, 26 Oct 2022 02:27:53 +0000
From: "Wang, Wei W" <wei.w.wang@...el.com>
To: Vipin Sharma <vipinsh@...gle.com>,
"Christopherson,, Sean" <seanjc@...gle.com>,
"pbonzini@...hat.com" <pbonzini@...hat.com>,
"dmatlack@...gle.com" <dmatlack@...gle.com>
CC: "andrew.jones@...ux.dev" <andrew.jones@...ux.dev>,
"kvm@...r.kernel.org" <kvm@...r.kernel.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: RE: [PATCH v6 5/5] KVM: selftests: Allowing running
dirty_log_perf_test on specific CPUs
On Saturday, October 22, 2022 5:18 AM, Vipin Sharma wrote:
> +static void pin_this_task_to_pcpu(uint32_t pcpu) {
> + cpu_set_t mask;
> + int r;
> +
> + CPU_ZERO(&mask);
> + CPU_SET(pcpu, &mask);
> + r = sched_setaffinity(0, sizeof(mask), &mask);
> + TEST_ASSERT(!r, "sched_setaffinity() failed for pCPU '%u'.\n", pcpu);
> +}
> +
> static void *vcpu_thread_main(void *data) {
> + struct perf_test_vcpu_args *vcpu_args;
> struct vcpu_thread *vcpu = data;
>
> + vcpu_args = &perf_test_args.vcpu_args[vcpu->vcpu_idx];
> +
> + if (perf_test_args.pin_vcpus)
> + pin_this_task_to_pcpu(vcpu_args->pcpu);
> +
I think it would be better to do the thread pinning at the time when the
thread is created by providing a pthread_attr_t attr, e.g. :
pthread_attr_t attr;
CPU_SET(vcpu->pcpu, &cpu_set);
pthread_attr_setaffinity_np(&attr, sizeof(cpu_set_t), &cpu_set);
pthread_create(thread, attr,...);
Also, pinning a vCPU thread to a pCPU is a general operation
which other users would need. I think we could make it more general and
put it to kvm_util, e.g. adding it to the helper function that I'm trying to create
+ * Create a vcpu thread with user provided attribute and the name in
+ * "vcpu-##id" format.
+ */
+void __vcpu_thread_create(struct kvm_vcpu *vcpu, const pthread_attr_t *attr,
+ void *(*start_routine)(void *), uint32_t private_data_size)
(https://lore.kernel.org/kvm/20221024113445.1022147-1-wei.w.wang@intel.com/T/#m0ceed820278a9deb199871ee6da7d6ec54d065f4)
Powered by blists - more mailing lists