From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9AA7F450903 for ; Fri, 31 Jul 2026 17:06:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.69 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785517592; cv=none; b=qa+QZe+s/f96g4lzXyMNU+9XXxkXomGCMUPOfvdqRLGA5qo1Y8x46KgINhgL6Je8GLMXhaFRXnXHO46BtesfoQwzOua8fqUSP87nRaX9UNAiwsL+wNoUcgbz279Ckoh7ljbf3AmCgGJegUnqqkbEhVazZJzt0t9Mgdu8lNGJY1Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785517592; c=relaxed/simple; bh=/TJjnxpVpH8WmXNaVzrS2AeOgP3QdjHKxDY/CbjUI8M=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=I7VDF+h1nlMBjos9uT7OU6T9DaIJodservAGBeUh/fY+C17raYAbsdzsRbaczljHykzPkAQCbOo0BK0nSec56IrktrP3y8QzAkdblhm10yA+FRTGriqI9KtClpLcjt2aOJO9cftmr8PrljD+bfYDejB1yzSanRrOiiSWJsM/tMc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=sBpjwgH0; arc=none smtp.client-ip=209.85.216.69 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="sBpjwgH0" Received: by mail-pj1-f69.google.com with SMTP id 98e67ed59e1d1-38e475f83a2so1958132a91.1 for ; Fri, 31 Jul 2026 10:06:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1785517589; x=1786122389; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:reply-to:from:to:cc:subject:date:message-id :reply-to:content-type; bh=Bs3K8CpV0aK6wpGyTBasGbTbkVQEzOsTzupfjJkDnT8=; b=sBpjwgH0BJQ7t5AMeGgcn+r24SRarQbNJ44LgZWRwtAMWXyiYklgl99llQh5aLpw4/ 7XKZYN9V1Pqg1f60JIjfEPPAqL5flMF5/2FEBA2h6MkYU2gqXulCJUmx28N7C1gqPF0R 1mLA4LQmfSm/YxvD2gz7dR/OfZ614j95o+KBuP6vKcsBeQIFEF9jZCcU6K1faGBOcpTT sPnZ+3jH0U5XHzhYyk/sfVwy4ZKbg5AMU/CWV7SWjG/tOkTUGHx47p5LDaMgLpr3wOy/ QAXVnzErJKqsd0715jAfqpzQqvdKn3KjpZCUtpbIEGCuxYoFi8XjeooMD9bA3q/U4tXs dvDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785517589; x=1786122389; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:reply-to:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=Bs3K8CpV0aK6wpGyTBasGbTbkVQEzOsTzupfjJkDnT8=; b=BngVREZ0rVN1XyhnCoJDrpVM7gtx3DyEwbtpPj0GRHp+jcvada/6gOYMVuWL4obusr cv0sRDksKTo49fowKRZW4u7GMAf+Y71tEQbYi/i7eX+rjYtnfYRBCyztSCuL/vF29JQM jtLs8DqoVSLvpkBlL3KAMAP+dRQ4/HHe29mPohuH46Dtz2Mo4gqPnNrh6q0pzte7xisj g4rtJ0555dLl5MIcYQg85Sl39ip1BbMFIvtDrQpKV1V95O7NGSoHVTThLb8N9jA64qGd ikg0lHNMW6vNsEy2pt2qudV9ak4Kl+0LSnkQA0o2gfr2NK4mlQASDGdYKtC2DkzqBtP2 oACA== X-Forwarded-Encrypted: i=1; AHgh+RruxTjsslsr81vv4S2c9IEo1fWuyTLkSu8jmyxrJxrgCioFU3fZymNrkYcLAlfLTgq+YcRxMML9aBihfuQ=@vger.kernel.org X-Gm-Message-State: AOJu0YzAl8lyUNXwjdq3nvIPMNFC0Xops77nKPLt4/ORnqvec0yMenIc xFXrUvtl4m2KR9C3lIANrT6yhS+XborNMZeAUKCLscwfoLrGZAFPVdgKoIdimF0mQCLAzmRFJ9+ 0Prpvfw== X-Received: from pjbee14.prod.google.com ([2002:a17:90a:fc4e:b0:384:7daf:f48a]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:5605:b0:37f:9ce3:ca95 with SMTP id 98e67ed59e1d1-38fbc560e9amr564372a91.30.1785517588641; Fri, 31 Jul 2026 10:06:28 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 31 Jul 2026 10:06:12 -0700 In-Reply-To: <20260731170619.2620845-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260731170619.2620845-1-seanjc@google.com> X-Mailer: git-send-email 2.55.0.508.g3f0d502094-goog Message-ID: <20260731170619.2620845-6-seanjc@google.com> Subject: [PATCH v2 05/12] KVM: selftests: Extract picking of random CPU from cpu_set_t to separate API From: Sean Christopherson To: Paolo Bonzini , Marc Zyngier , Oliver Upton , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Sean Christopherson Cc: Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , David Hildenbrand , kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Extract kvm_pick_random_cpu() out of pin_task_to_random_cpu() so that tests can choose a random CPU without having to immediately pin a task to that CPU. No functional change intended. Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/include/kvm_util.h | 11 ++++++++++- tools/testing/selftests/kvm/lib/kvm_util.c | 7 ++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h index 61d72e1e7601..5a7a455b5387 100644 --- a/tools/testing/selftests/kvm/include/kvm_util.h +++ b/tools/testing/selftests/kvm/include/kvm_util.h @@ -1084,6 +1084,8 @@ struct kvm_vcpu *vm_recreate_with_one_vcpu(struct kvm_vm *vm); void kvm_set_files_rlimit(u32 nr_vcpus); +int kvm_pick_random_cpu(cpu_set_t *possible_cpus); + int __pin_task_to_cpu(pthread_t task, int cpu); static inline void pin_task_to_cpu(pthread_t task, int cpu) @@ -1094,7 +1096,14 @@ static inline void pin_task_to_cpu(pthread_t task, int cpu) TEST_ASSERT(!r, "Failed to set thread affinity to pCPU '%u'", cpu); } -int pin_task_to_random_cpu(pthread_t task, cpu_set_t *possible_cpus); +static inline int pin_task_to_random_cpu(pthread_t task, cpu_set_t *possible_cpus) +{ + int cpu; + + cpu = kvm_pick_random_cpu(possible_cpus); + pin_task_to_cpu(task, cpu); + return cpu; +} static inline int pin_task_to_any_cpu(pthread_t task) { diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index af2bad0553f9..9ddc047d5c27 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -668,7 +668,7 @@ void kvm_print_vcpu_pinning_help(void) " (default: no pinning)\n", name, name); } -int pin_task_to_random_cpu(pthread_t task, cpu_set_t *possible_cpus) +int kvm_pick_random_cpu(cpu_set_t *possible_cpus) { int target_idx; int nr_cpus; @@ -680,12 +680,9 @@ int pin_task_to_random_cpu(pthread_t task, cpu_set_t *possible_cpus) target_idx = kvm_random_u64(&kvm_rng) % nr_cpus; for (cpu = 0; cpu < CPU_SETSIZE; cpu++) { - if (CPU_ISSET(cpu, possible_cpus) && target_idx-- == 0) { - pin_task_to_cpu(task, cpu); + if (CPU_ISSET(cpu, possible_cpus) && target_idx-- == 0) return cpu; - } } - TEST_FAIL("Failed to find random CPU in possible_cpus"); return -1; } -- 2.55.0.508.g3f0d502094-goog