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 8F9BB377EA1 for ; Fri, 22 May 2026 10:08:44 +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=1779444526; cv=none; b=NrJ03Z4QVgUD+oXLn8Yyy5IrDQSWqPkxHV03w3+rbRoNAX/8tlpRmNCP5NS47W7J/kRCngr6qKU9EIzcHt5icIvySn6+heJscHMZC93PeBUrSGNJtNtRwxBqNPLyeiqEA2Hz+cwUYZRBLuD+bZ5DsOsvEOJaV4Ugytsl3IaI660= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779444526; c=relaxed/simple; bh=8CiUrew4ZKOX+qUbxUDMlOgrGWj4Gq7sR33gnbjthSw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=aNgglSotapTwyXZ8as5T3Rbs8kyY8oogo6qxycA4PqkBci0W4mzKmMMPlb67i9kowkzxAc8VrW468ui5h8N53BP31DB78JV/UTQ3VLrQ3Sdx9Aese/Dy4l9LStq/rEsxan/UTEoFkKd6d7sppwwvKCqFyUvDtDVEVdhMRR5dA3w= 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=ZqQVpRtA; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=nrqPvaMH; 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="ZqQVpRtA"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="nrqPvaMH" Date: Fri, 22 May 2026 12:08:35 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779444517; 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: in-reply-to:in-reply-to:references:references; bh=kMmb0N9QTPS4AnfEbbUTAQ/zIAMFI8qInsrMJpeAm+g=; b=ZqQVpRtAHScP29l+vXddSFSmLvbzCbs732oFkDtVxs80jLlrJk2/vSdMse15sMliDY7sX8 6zTVtqItTCzakp99/W3VJfVMUifblI+OwdNuwSjuZ25rxWFGsJtrpAjtVHBwvlPrCi7mwa dyHJoOUU7b9PRQDLsrA5PsGDdzQjy4LLLjIgGSk/a20ypiBWCj56R5kEj74W9VR1D23gCW 3FB8/Y9UsmxJmk8SZW7/RlvlMr5Ml452nCdhknaYiH0pNKHP+7LOx1TntyrdHjDsoXj0Hj 7ZuqDOzbHtRDXOm4OsvaTUxecXDCr8O1DcLX3dSWEgZuNDY2nCiucVc7Pdk7Gw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779444517; 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: in-reply-to:in-reply-to:references:references; bh=kMmb0N9QTPS4AnfEbbUTAQ/zIAMFI8qInsrMJpeAm+g=; b=nrqPvaMHBCQHMW/TfAr/L7r2NtwiIwpH9pcVQZIUgAe4QVaOGf/qK0l1jgHnnDZTCQmARb MoAY4JEp8Ls1b3Ag== From: Sebastian Andrzej Siewior To: Chuyi Zhou Cc: tglx@linutronix.de, mingo@redhat.com, luto@kernel.org, peterz@infradead.org, paulmck@kernel.org, muchun.song@linux.dev, bp@alien8.de, dave.hansen@linux.intel.com, pbonzini@redhat.com, clrkwllms@kernel.org, rostedt@goodmis.org, nadav.amit@gmail.com, linux-kernel@vger.kernel.org Subject: Re: [RESEND PATCH v5 06/12] smp: Enable preemption early in smp_call_function_many_cond Message-ID: <20260522100835.rgqCLkwa@linutronix.de> References: <20260513124524.2569867-1-zhouchuyi@bytedance.com> <20260513124524.2569867-7-zhouchuyi@bytedance.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=utf-8 Content-Disposition: inline In-Reply-To: <20260513124524.2569867-7-zhouchuyi@bytedance.com> On 2026-05-13 20:45:18 [+0800], Chuyi Zhou wrote: > --- a/kernel/smp.c > +++ b/kernel/smp.c > @@ -861,10 +861,10 @@ static void smp_call_function_many_cond(const struct cpumask *mask, > int nr_cpus = 0; > bool run_remote = false; > > - lockdep_assert_preemption_disabled(); > - > task_mask = smp_task_ipi_mask(current); > - preemptible_wait = task_mask; > + preemptible_wait = task_mask && preemptible(); Now that I stare at this again, why is preemptible() a thing here? You care about doing put_cpu() below before csd_lock_wait(). This can only be done if you get a cpumask from smp_task_ipi_mask(). If preemption or interrupts is/are disabled then you still can use the "private" cpumask and do the early put_cpu(). It simply is no optimisation. This basically reduces the check to a CONFIG_PREEMPTION=y kernel because otherwise you have no cpumask. And this is not done on !SMP kernels. smp_task_ipi_mask() is only used here so there is no need to export it via headers. > + > + this_cpu = get_cpu(); > cfd = this_cpu_ptr(&cfd_data); > cpumask = preemptible_wait ? task_mask : cfd->cpumask; > > @@ -946,6 +946,19 @@ static void smp_call_function_many_cond(const struct cpumask *mask, > local_irq_restore(flags); > } > > + /* > + * We may block in csd_lock_wait() for a significant amount of time, > + * especially when interrupts are disabled or with a large number of > + * remote CPUs. Try to enable preemption before csd_lock_wait(). If interrupts are disabled there is no gain. Also we sort of expect interrupts to be enabled here. Waiting for completion can take time especially with many CPUs. On a PREEMPTIBLE kernel a per-task cpumask is used to track CPUs with pending IPI request. This allows to enable preemption and potentially wait while allowing task preemption. On a !PREEMPTIBLE the cpumask is shared and the call must block until completion to avoid modifications by a another caller on this CPU. > + * > + * Use the task_mask instead of cfd->cpumask to avoid concurrency > + * modification from tasks on the same cpu. If preemption occurs during > + * csd_lock_wait, other concurrent smp_call_function_many_cond() calls > + * will simply block until the previous csd->func() completes. > + */ > + if (preemptible_wait) > + put_cpu(); > + > if (run_remote && wait) { > for_each_cpu(cpu, cpumask) { > call_single_data_t *csd; > @@ -954,6 +967,9 @@ static void smp_call_function_many_cond(const struct cpumask *mask, > csd_lock_wait(csd); > } > } > + > + if (!preemptible_wait) > + put_cpu(); > } > > /** Sebastian