From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 0DFD74A3E for ; Mon, 2 Feb 2026 15:14:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770045250; cv=none; b=dmxO1rWPvnRn3JION+/2qZTnVViJIxD0dAevokjUS+sRtiuEMvWYxPd6GRC6EejDG/E+/goRqAxFWTliMaUlNZpAXgvZy/JGrjx0A418rsUPIjAwwdwZlSXlfb417gJXmYsGi+V6DpG9Z8Pt6p/gezKURSEP/6g2VpebjHP+TBE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770045250; c=relaxed/simple; bh=PsFNVm/zOEnav88BgZycKo4Yn1i3pZYk2gzUevL0c0U=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=NcZ8XLRK8nbDnKwkm2w1GPXkPF8jz0v5vIm2Zz82c5t3Nm++JUYw/3OPqCOjhKRM5L9lZZCTvhd1tIWWdGG2Me41LybyY3XyPHZOB61gjMiv3VkG1Ih3tw/3mYvfodFsmChB9fJTP5JwNr7vzHD1Jq4upBviNuQiHLLyUalcPCU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=QBPdY2eB; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="QBPdY2eB" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=bjUPL0iUec7jqtjgnp5NMyfXHr2tOIVP46u4nRjwdJY=; b=QBPdY2eBswqQtizDpT8A/XeXGv jHNpdJe+GsQIhti6KiybGDKuVuQ4VhBresh9CLSLeSOntTJMofegeibBIqTUHAgLr5/4Cl6GG9b4G VeN6HMde6xMqK2Seobq5Kr34jZT5906LesSHkiUP4hgNChoLQHH8Ec8srop0Iy+KP1dwvTuSPUiwy DpKzYw/ZUPxdf3/AKzPGOgAiVi6iJCoNIOqgJW4d2uBx5V3NI0yadoPEvjNuIqIOf6wDbFpBLEqmx RqP6GSmKds5k9oKUBDzvjo05hVLLPZDosdYtRpte5kFr3z+SNfhtmUKzcuKKJJESHj4w6+TdBJxUj N4r6NWVg==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1vmvcp-0000000Egp0-0FVV; Mon, 02 Feb 2026 15:14:03 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 907A4300BD2; Mon, 02 Feb 2026 16:14:02 +0100 (CET) Date: Mon, 2 Feb 2026 16:14:02 +0100 From: Peter Zijlstra To: Daniel Hodges Cc: Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , linux-kernel@vger.kernel.org Subject: Re: [PATCH] sched: Skip schedule() in sched_yield() when CPU has no other work Message-ID: <20260202151402.GE1282955@noisy.programming.kicks-ass.net> References: <20260202140039.1970735-1-hodgesd@meta.com> 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=us-ascii Content-Disposition: inline In-Reply-To: <20260202140039.1970735-1-hodgesd@meta.com> On Mon, Feb 02, 2026 at 06:00:38AM -0800, Daniel Hodges wrote: > When a task calls sched_yield() but is the only runnable task on its > CPU with no pending wakeups, there's nothing to yield to. In this case, > skip the schedule() overhead entirely and return immediately. > > The yield_task() callback is still invoked to preserve per-class > semantics (e.g., SCHED_DEADLINE's dl_yielded flag for bandwidth > reclamation). The early exit only occurs after yield_task() completes > and only if nr_running == 1 and ttwu_pending is false. > > Testing performed in a 32-CPU VM using virtme-ng: > > stress-ng --yield 8, unpinned workers, 10s each, 30 runs: > Baseline: 10.18M yields/sec > Optimized: 11.58M yields/sec > > The optimization benefits lightly-loaded systems and CPU-pinned > workloads where tasks are often alone on their CPUs. On loaded systems > where CPUs have multiple runnable tasks, the check fails and we fall > through to the normal schedule() path with no regression. What is calling sched_yield() enough for this to matter? Calling sched_yield() outside of FIFO/DL is basically UB.