From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 06D26366DC0 for ; Wed, 19 Nov 2025 17:27:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763573225; cv=none; b=KY7aO1cPA09sJ/kO0zoUqLjWjX9qBXvj6TlNbDkOSA0jaxdrpf5QYZ6PnrPZv0qasBDvNzc+CsyOTU6cJ0K+7WtNK8Vy0njeLs48ff6Q14395Z03xPREIZrp8lpMvXEYchDf+a0baNYQsgIcRr4W4Nv7eg+lgSmIChBsJ0wrP30= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763573225; c=relaxed/simple; bh=wqQW7vOjopMLziVQNe3a7FQvkyBB13YXv8h9cCRxMok=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=u5wCc85Gpg6B06utHauNbxW2OxxC+wd9qQI0J7pW92zuYAP2izNTdBfOdD1dPS5sUCHhIDLBsPMnzlYYYHgiRHT0HA2IOjvZNNf2y082mied0zfFl7H3MmdUVz72N/4epuc2rXnN/CJNvncKboHl5LoVkqtkAhL/YDmzrQ5AQfI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=c8LQOsA0; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=IeZBu3LA; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="c8LQOsA0"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="IeZBu3LA" Message-ID: <20251119172549.511736272@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1763573220; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=3XnzwM2fpXXfN1QOW7N5DDHzGWwxyhaI7iqPFL2Elm0=; b=c8LQOsA0h+e/Td6GfNO+SZhDeH3K1MZCt/x6ChwwkOs4jAe9OhnI0HpiW//AZuqyA24axT ct4tusVaCzFMW1LRy5d9jVjSPsxMqiQrpZNM/C8kNv03im+1bvI0khjBPwrcrxJSe6TqSO 5/KMWmtlfINojCv/rhw2DqIkAcqmEQRufXdEyCxuKd3N7NCq/J+ZzywIeGcgoq07ZyDHQe VuoVz9SjzgLUBj292bZnKSfSDNqlGguaSYtkijOnfYI1rYxcsuC7CFQC4mPCK/Aza0iBM8 IA0M+ij6aleWOeT62IPCGbOcFk2pEfoX5iCk63ocnpMCm15zvcb6nVbPuXt0Fw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1763573220; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=3XnzwM2fpXXfN1QOW7N5DDHzGWwxyhaI7iqPFL2Elm0=; b=IeZBu3LAm6FEBUcHooTXDv3dUimC9Dre/56k9KdiM71yAV0C+as1jsoEDILDM+oRa72Qie 7RxYlIZrGqqkeJAQ== From: Thomas Gleixner To: LKML Cc: Peter Zijlstra , Gabriele Monaco , Mathieu Desnoyers , Michael Jeanson , Jens Axboe , "Paul E. McKenney" , "Gautham R. Shenoy" , Florian Weimer , Tim Chen , Yury Norov , Shrikanth Hegde Subject: [patch V5 08/20] sched/mmcid: Use cpumask_weighted_or() References: <20251119171016.815482037@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Date: Wed, 19 Nov 2025 18:26:59 +0100 (CET) Use cpumask_weighted_or() instead of cpumask_or() and cpumask_weight() on the result, which walks the same bitmap twice. Results in 10-20% less cycles, which reduces the runqueue lock hold time. Signed-off-by: Thomas Gleixner Reviewed-by: Mathieu Desnoyers Acked-by: Yury Norov (NVIDIA) --- kernel/sched/core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -10377,6 +10377,7 @@ void call_trace_sched_update_nr_running( static inline void mm_update_cpus_allowed(struct mm_struct *mm, const struct cpumask *affmsk) { struct cpumask *mm_allowed; + unsigned int weight; if (!mm) return; @@ -10387,8 +10388,8 @@ static inline void mm_update_cpus_allowe */ guard(raw_spinlock)(&mm->mm_cid.lock); mm_allowed = mm_cpus_allowed(mm); - cpumask_or(mm_allowed, mm_allowed, affmsk); - WRITE_ONCE(mm->mm_cid.nr_cpus_allowed, cpumask_weight(mm_allowed)); + weight = cpumask_weighted_or(mm_allowed, mm_allowed, affmsk); + WRITE_ONCE(mm->mm_cid.nr_cpus_allowed, weight); } void sched_mm_cid_exit_signals(struct task_struct *t)