From: Hisam Mehboob <hisamshar@gmail.com>
To: pbonzini@redhat.com
Cc: shuah@kernel.org, seanjc@google.com, kvm@vger.kernel.org,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
aqibaf@amazon.com, Hisam Mehboob <hisamshar@gmail.com>
Subject: [PATCH] KVM: selftests: Use KVM's task pinning APIs in steal_time
Date: Mon, 6 Jul 2026 21:36:49 +0500 [thread overview]
Message-ID: <20260706163649.155548-1-hisamshar@gmail.com> (raw)
From: Sean Christopherson <seanjc@google.com>
Use pin_self_to_cpu() and pin_task_to_cpu() to pin the vCPU thread and
the stealer thread to pCPU0 in the steal_time test. Eliminating the usage
of pthread_attr_setaffinity_np() in particular allows building the test
against non-glibc C libraries.
Reported-by: Aqib Faruqui <aqibaf@amazon.com>
Closes: https://lore.kernel.org/all/20250829142556.72577-4-aqibaf@amazon.com/
Signed-off-by: Sean Christopherson <seanjc@google.com>
Link: https://lore.kernel.org/all/aLIroyJSWQ26wnY4@google.com/
[hisamshar@gmail.com: resend, fix changelog typos; original series was never reposted]
Signed-off-by: Hisam Mehboob <hisamshar@gmail.com>
---
tools/testing/selftests/kvm/steal_time.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/tools/testing/selftests/kvm/steal_time.c b/tools/testing/selftests/kvm/steal_time.c
index 76fcdd1fd3cb..19a97d6a3607 100644
--- a/tools/testing/selftests/kvm/steal_time.c
+++ b/tools/testing/selftests/kvm/steal_time.c
@@ -508,9 +508,7 @@ int main(int ac, char **av)
{
struct kvm_vcpu *vcpus[NR_VCPUS];
struct kvm_vm *vm;
- pthread_attr_t attr;
pthread_t thread;
- cpu_set_t cpuset;
unsigned int gpages;
long stolen_time;
long run_delay;
@@ -520,11 +518,7 @@ int main(int ac, char **av)
verbose = ac > 1 && (!strncmp(av[1], "-v", 3) || !strncmp(av[1], "--verbose", 10));
/* Set CPU affinity so we can force preemption of the VCPU */
- CPU_ZERO(&cpuset);
- CPU_SET(0, &cpuset);
- pthread_attr_init(&attr);
- pthread_attr_setaffinity_np(&attr, sizeof(cpu_set_t), &cpuset);
- pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);
+ pin_self_to_cpu(0);
/* Create a VM and an identity mapped memslot for the steal time structure */
vm = vm_create_with_vcpus(NR_VCPUS, guest_code, vcpus);
@@ -558,7 +552,9 @@ int main(int ac, char **av)
/* Steal time from the VCPU. The steal time thread has the same CPU affinity as the VCPUs. */
run_delay = get_run_delay();
- pthread_create(&thread, &attr, do_steal_time, NULL);
+ pthread_create(&thread, NULL, do_steal_time, NULL);
+ pin_task_to_cpu(thread, 0);
+
do
sched_yield();
while (get_run_delay() - run_delay < MIN_RUN_DELAY_NS);
--
2.51.0
next reply other threads:[~2026-07-06 16:38 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-06 16:36 Hisam Mehboob [this message]
2026-07-06 16:49 ` [PATCH] KVM: selftests: Use KVM's task pinning APIs in steal_time sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260706163649.155548-1-hisamshar@gmail.com \
--to=hisamshar@gmail.com \
--cc=aqibaf@amazon.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox