From nobody Thu Oct 2 14:13:38 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 2D9CB3376BC for ; Mon, 15 Sep 2025 14:59:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757948400; cv=none; b=FRFEI3PpKariggqVuQiK1RT4rR9JkaR9JXp+WcHPk0fG5HHtM0cnviH0/JaYLc5Ay+yldYPsTly/fq6ZxxuZXUd8owggb1cQbX972rAYDyKIhJjv0iJ9V9TMeCEMP8egOI2rkN6FQfaGy8cB0Vz8XkbmPy7jycweb8X1zronnPI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757948400; c=relaxed/simple; bh=W5HeOLn53bkMXvyginmPkrpggXzunizSPk+ErNBEFcE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gfukrODS/Kl3lvPhuLesVv1w90EDqqsb1rv+kNLc7rn4RVq88Bq4xsNit9/tMxPWdKNLE+C0pTGx/hB6xX3ed/TH+MfkJlvivsNW229/68KO7ogoYNTtAENr8X/yghUNHcQTjIqG1FYaVzRsXUGMTeWqyAh7Ccsl/XH46dGl3tI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=ZxEuTA62; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ZxEuTA62" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757948398; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IqHoqHbNdw3xd89Dbu+aPXkrTjTEf+IBAZgrCZ/KQ7A=; b=ZxEuTA62N8mXVfCRIr1zpDZZqrkww7gtBtCqOSjsjioDD8zb46rgwaLT8MBoyjzGmO7i0j h5JAEEOPrWdrRfqqQHxcFB8OQBrZSf0ceplSeA9tgUMR7RvwiyGyZqZ40FZqA7en0isR+n Wwmlk1/PXWoaWNYU7GZJjMBghyM8ow4= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-492-P7BWnZZBME22xg8ozkWN_A-1; Mon, 15 Sep 2025 10:59:56 -0400 X-MC-Unique: P7BWnZZBME22xg8ozkWN_A-1 X-Mimecast-MFC-AGG-ID: P7BWnZZBME22xg8ozkWN_A_1757948395 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 70F2219560BD; Mon, 15 Sep 2025 14:59:55 +0000 (UTC) Received: from gmonaco-thinkpadt14gen3.rmtit.com (unknown [10.44.32.63]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 096371800447; Mon, 15 Sep 2025 14:59:52 +0000 (UTC) From: Gabriele Monaco To: linux-kernel@vger.kernel.org, Anna-Maria Behnsen , Thomas Gleixner Cc: Frederic Weisbecker , Gabriele Monaco Subject: [PATCH v12 1/9] timers/migration: Postpone online/offline callbacks registration to late initcall Date: Mon, 15 Sep 2025 16:59:22 +0200 Message-ID: <20250915145920.140180-12-gmonaco@redhat.com> In-Reply-To: <20250915145920.140180-11-gmonaco@redhat.com> References: <20250915145920.140180-11-gmonaco@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" From: Frederic Weisbecker During the early boot process, the default clocksource used for timekeeping is the jiffies. Better clocksources can only be selected once clocksource_done_booting() is called as an fs initcall. NOHZ can only be enabled after that stage, making global timer migration irrelevant up to that point. The tree remains inactive before NOHZ is enabled anyway. Therefore it makes sense to enable each CPUs to the tree only once that is setup. Make the CPUs available to the tree on late initcall, after the right clocksource had a chance to be selected. This will also simplify the handling of domain isolated CPUs on further patches. Signed-off-by: Frederic Weisbecker Signed-off-by: Gabriele Monaco --- kernel/time/timer_migration.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/kernel/time/timer_migration.c b/kernel/time/timer_migration.c index c0c54dc5314c..891891794b92 100644 --- a/kernel/time/timer_migration.c +++ b/kernel/time/timer_migration.c @@ -1481,6 +1481,16 @@ static int tmigr_cpu_online(unsigned int cpu) return 0; } =20 +/* + * NOHZ can only be enabled after clocksource_done_booting(). Don't + * bother trashing the cache in the tree before. + */ +static int __init tmigr_late_init(void) +{ + return cpuhp_setup_state(CPUHP_AP_TMIGR_ONLINE, "tmigr:online", + tmigr_cpu_online, tmigr_cpu_offline); +} + static void tmigr_init_group(struct tmigr_group *group, unsigned int lvl, int node) { @@ -1843,18 +1853,10 @@ static int __init tmigr_init(void) =20 ret =3D cpuhp_setup_state(CPUHP_TMIGR_PREPARE, "tmigr:prepare", tmigr_cpu_prepare, NULL); - if (ret) - goto err; - - ret =3D cpuhp_setup_state(CPUHP_AP_TMIGR_ONLINE, "tmigr:online", - tmigr_cpu_online, tmigr_cpu_offline); - if (ret) - goto err; - - return 0; - err: - pr_err("Timer migration setup failed\n"); + if (ret) + pr_err("Timer migration setup failed\n"); return ret; } early_initcall(tmigr_init); +late_initcall(tmigr_late_init); --=20 2.51.0 From nobody Thu Oct 2 14:13:38 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 DA9C83376BC for ; Mon, 15 Sep 2025 15:00:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757948405; cv=none; b=tGLcTjoiAb9U5YiRds/HSK7MoEzJQRjp6WAqTlXIO/mlQF3IQaYqRmt/GCRpNaYwYr8cIFk8tw/ypqdW6ZYVHNWmgMpzAhoIq9kZbc0lTpJMzAZrbP13ffh3d5ifWwi2tVAjGu41TZMD7mvd+h5TZecp4zP3VI11hpLN4XYZXRo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757948405; c=relaxed/simple; bh=K0ElDsTm2ArSyphsFcxUA253o3pMHPe9E9UYvTFwGY0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=E6ImSA/dq3iR8dedtJTsR/cOJk30F56Spb70qjZJuHpkG5jM+1dpmLwP/JHxkIjpj4V9eg5293kC4o3oE254hXevEwxSClU0FAHpmPOMHyvFeWElazCsnNOfh8VAZoeRNB85FYuPVCdzvJys/i0e2oKyDTrc9YS6KiOoM6jfCQg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Xt/25N01; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Xt/25N01" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757948402; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iFkTi56GeHkgOO3HQJUs680Pme7PW2l5lL1fNlMRCTY=; b=Xt/25N01VzPtrGeDxEIoc8JFgqOfGWtkT07fo+dL8XgXgl50ZOB1ytRYeSodNc7yTpnH9w al/qVWBcRiZZO81VdBlcStf/0bbwOnTygGRtxy+sNOotATs9Yi9xF5OMMX2FImqFXGzhYD ZB9UQOIS/mp5o1wZvRiAeAL8T99Er+U= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-564-O7BuJkY-NXazP4-dy88Asg-1; Mon, 15 Sep 2025 11:00:01 -0400 X-MC-Unique: O7BuJkY-NXazP4-dy88Asg-1 X-Mimecast-MFC-AGG-ID: O7BuJkY-NXazP4-dy88Asg_1757948400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 010B819560B0; Mon, 15 Sep 2025 15:00:00 +0000 (UTC) Received: from gmonaco-thinkpadt14gen3.rmtit.com (unknown [10.44.32.63]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AD1B81800446; Mon, 15 Sep 2025 14:59:56 +0000 (UTC) From: Gabriele Monaco To: linux-kernel@vger.kernel.org, Anna-Maria Behnsen , Thomas Gleixner , Steven Rostedt , Masami Hiramatsu , linux-trace-kernel@vger.kernel.org Cc: Gabriele Monaco , Frederic Weisbecker Subject: [PATCH v12 2/9] timers: Rename tmigr 'online' bit to 'available' Date: Mon, 15 Sep 2025 16:59:23 +0200 Message-ID: <20250915145920.140180-13-gmonaco@redhat.com> In-Reply-To: <20250915145920.140180-11-gmonaco@redhat.com> References: <20250915145920.140180-11-gmonaco@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" The timer migration hierarchy excludes offline CPUs via the tmigr_is_not_available function, which is essentially checking the online bit for the CPU. Rename the online bit to available and all references in function names and tracepoint to generalise the concept of available CPUs. Reviewed-by: Frederic Weisbecker Signed-off-by: Gabriele Monaco --- include/trace/events/timer_migration.h | 4 ++-- kernel/time/timer_migration.c | 22 +++++++++++----------- kernel/time/timer_migration.h | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/include/trace/events/timer_migration.h b/include/trace/events/= timer_migration.h index 47db5eaf2f9a..61171b13c687 100644 --- a/include/trace/events/timer_migration.h +++ b/include/trace/events/timer_migration.h @@ -173,14 +173,14 @@ DEFINE_EVENT(tmigr_cpugroup, tmigr_cpu_active, TP_ARGS(tmc) ); =20 -DEFINE_EVENT(tmigr_cpugroup, tmigr_cpu_online, +DEFINE_EVENT(tmigr_cpugroup, tmigr_cpu_available, =20 TP_PROTO(struct tmigr_cpu *tmc), =20 TP_ARGS(tmc) ); =20 -DEFINE_EVENT(tmigr_cpugroup, tmigr_cpu_offline, +DEFINE_EVENT(tmigr_cpugroup, tmigr_cpu_unavailable, =20 TP_PROTO(struct tmigr_cpu *tmc), =20 diff --git a/kernel/time/timer_migration.c b/kernel/time/timer_migration.c index 891891794b92..55b186fd146c 100644 --- a/kernel/time/timer_migration.c +++ b/kernel/time/timer_migration.c @@ -427,7 +427,7 @@ static DEFINE_PER_CPU(struct tmigr_cpu, tmigr_cpu); =20 static inline bool tmigr_is_not_available(struct tmigr_cpu *tmc) { - return !(tmc->tmgroup && tmc->online); + return !(tmc->tmgroup && tmc->available); } =20 /* @@ -926,7 +926,7 @@ static void tmigr_handle_remote_cpu(unsigned int cpu, u= 64 now, * updated the event takes care when hierarchy is completely * idle. Otherwise the migrator does it as the event is enqueued. */ - if (!tmc->online || tmc->remote || tmc->cpuevt.ignore || + if (!tmc->available || tmc->remote || tmc->cpuevt.ignore || now < tmc->cpuevt.nextevt.expires) { raw_spin_unlock_irq(&tmc->lock); return; @@ -973,7 +973,7 @@ static void tmigr_handle_remote_cpu(unsigned int cpu, u= 64 now, * (See also section "Required event and timerqueue update after a * remote expiry" in the documentation at the top) */ - if (!tmc->online || !tmc->idle) { + if (!tmc->available || !tmc->idle) { timer_unlock_remote_bases(cpu); goto unlock; } @@ -1432,19 +1432,19 @@ static long tmigr_trigger_active(void *unused) { struct tmigr_cpu *tmc =3D this_cpu_ptr(&tmigr_cpu); =20 - WARN_ON_ONCE(!tmc->online || tmc->idle); + WARN_ON_ONCE(!tmc->available || tmc->idle); =20 return 0; } =20 -static int tmigr_cpu_offline(unsigned int cpu) +static int tmigr_clear_cpu_available(unsigned int cpu) { struct tmigr_cpu *tmc =3D this_cpu_ptr(&tmigr_cpu); int migrator; u64 firstexp; =20 raw_spin_lock_irq(&tmc->lock); - tmc->online =3D false; + tmc->available =3D false; WRITE_ONCE(tmc->wakeup, KTIME_MAX); =20 /* @@ -1452,7 +1452,7 @@ static int tmigr_cpu_offline(unsigned int cpu) * offline; Therefore nextevt value is set to KTIME_MAX */ firstexp =3D __tmigr_cpu_deactivate(tmc, KTIME_MAX); - trace_tmigr_cpu_offline(tmc); + trace_tmigr_cpu_unavailable(tmc); raw_spin_unlock_irq(&tmc->lock); =20 if (firstexp !=3D KTIME_MAX) { @@ -1463,7 +1463,7 @@ static int tmigr_cpu_offline(unsigned int cpu) return 0; } =20 -static int tmigr_cpu_online(unsigned int cpu) +static int tmigr_set_cpu_available(unsigned int cpu) { struct tmigr_cpu *tmc =3D this_cpu_ptr(&tmigr_cpu); =20 @@ -1472,11 +1472,11 @@ static int tmigr_cpu_online(unsigned int cpu) return -EINVAL; =20 raw_spin_lock_irq(&tmc->lock); - trace_tmigr_cpu_online(tmc); + trace_tmigr_cpu_available(tmc); tmc->idle =3D timer_base_is_idle(); if (!tmc->idle) __tmigr_cpu_activate(tmc); - tmc->online =3D true; + tmc->available =3D true; raw_spin_unlock_irq(&tmc->lock); return 0; } @@ -1488,7 +1488,7 @@ static int tmigr_cpu_online(unsigned int cpu) static int __init tmigr_late_init(void) { return cpuhp_setup_state(CPUHP_AP_TMIGR_ONLINE, "tmigr:online", - tmigr_cpu_online, tmigr_cpu_offline); + tmigr_set_cpu_available, tmigr_clear_cpu_available); } =20 static void tmigr_init_group(struct tmigr_group *group, unsigned int lvl, diff --git a/kernel/time/timer_migration.h b/kernel/time/timer_migration.h index ae19f70f8170..70879cde6fdd 100644 --- a/kernel/time/timer_migration.h +++ b/kernel/time/timer_migration.h @@ -97,7 +97,7 @@ struct tmigr_group { */ struct tmigr_cpu { raw_spinlock_t lock; - bool online; + bool available; bool idle; bool remote; struct tmigr_group *tmgroup; --=20 2.51.0 From nobody Thu Oct 2 14:13:38 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 0ADEC329F00 for ; Mon, 15 Sep 2025 15:00:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757948410; cv=none; b=TvccChzD7nA+t1cTbhauGWM2IZJqdVvhbpVcZqvw6hgzubFhhxZmjXGjm8S6Kiijz9ReM2k3DQdMSBfyrWMT+Bg16aqRu7LaEd6qzwajdGMwLwmCwo9KQ9RyAxh6jabVbVPhW4ag9+PHX01H83kbo1MO900GmX6TEE+7FO2bZW0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757948410; c=relaxed/simple; bh=s6DRgB4ZQLXuz3fHRKmP5K1mXf4BGuPX0q56iGqgbA0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EfDoTnZzPteC9uoZglPCl9i+GMXPe5UUA3lDNue7pPyG8Q5k+gg7UW/hFNhLvAtfRoVmRfPb3u04/WsuDII6DnpsPb45byCyrdi65vGyPIuGv5BTuuF/xvsvt/kEbeA7ao0GJjjFVCB+qXzyj0DjC9oquAsDIBcIw9QpkTyEVIw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=A1wk+RMp; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="A1wk+RMp" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757948408; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dEaNsn6JuCXOUjQ0A/OCwJlHT770BY8Sx/uuyjZom0E=; b=A1wk+RMptX87SZas2YQFtFiHaFS/6BdzR0SlymtC3i4lZQM1IL3YGeNli6pCIkeJp1MNXm bFXal3OTI1Kv/N1lE9/298TqNScqaPvTJDYUJV3wevDRMPdGbK1TBtUgE3OQFazN1EzGJk 4v45+7eKUxJVIq3ghRptWK0lOfsqdtg= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-311-4INGbQaEObe7N7MYmbroIQ-1; Mon, 15 Sep 2025 11:00:04 -0400 X-MC-Unique: 4INGbQaEObe7N7MYmbroIQ-1 X-Mimecast-MFC-AGG-ID: 4INGbQaEObe7N7MYmbroIQ_1757948403 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A91DF180029D; Mon, 15 Sep 2025 15:00:03 +0000 (UTC) Received: from gmonaco-thinkpadt14gen3.rmtit.com (unknown [10.44.32.63]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 034681800446; Mon, 15 Sep 2025 15:00:00 +0000 (UTC) From: Gabriele Monaco To: linux-kernel@vger.kernel.org, Anna-Maria Behnsen , Thomas Gleixner Cc: Gabriele Monaco , Frederic Weisbecker Subject: [PATCH v12 3/9] timers: Add the available mask in timer migration Date: Mon, 15 Sep 2025 16:59:24 +0200 Message-ID: <20250915145920.140180-14-gmonaco@redhat.com> In-Reply-To: <20250915145920.140180-11-gmonaco@redhat.com> References: <20250915145920.140180-11-gmonaco@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" Keep track of the CPUs available for timer migration in a cpumask. This prepares the ground to generalise the concept of unavailable CPUs. Reviewed-by: Frederic Weisbecker Signed-off-by: Gabriele Monaco --- kernel/time/timer_migration.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/kernel/time/timer_migration.c b/kernel/time/timer_migration.c index 55b186fd146c..865071ab5062 100644 --- a/kernel/time/timer_migration.c +++ b/kernel/time/timer_migration.c @@ -422,6 +422,12 @@ static unsigned int tmigr_crossnode_level __read_mostl= y; =20 static DEFINE_PER_CPU(struct tmigr_cpu, tmigr_cpu); =20 +/* + * CPUs available for timer migration. + * Protected by cpuset_mutex (with cpus_read_lock held) or cpus_write_lock. + */ +static cpumask_var_t tmigr_available_cpumask; + #define TMIGR_NONE 0xFF #define BIT_CNT 8 =20 @@ -1443,6 +1449,7 @@ static int tmigr_clear_cpu_available(unsigned int cpu) int migrator; u64 firstexp; =20 + cpumask_clear_cpu(cpu, tmigr_available_cpumask); raw_spin_lock_irq(&tmc->lock); tmc->available =3D false; WRITE_ONCE(tmc->wakeup, KTIME_MAX); @@ -1456,7 +1463,7 @@ static int tmigr_clear_cpu_available(unsigned int cpu) raw_spin_unlock_irq(&tmc->lock); =20 if (firstexp !=3D KTIME_MAX) { - migrator =3D cpumask_any_but(cpu_online_mask, cpu); + migrator =3D cpumask_any(tmigr_available_cpumask); work_on_cpu(migrator, tmigr_trigger_active, NULL); } =20 @@ -1471,6 +1478,7 @@ static int tmigr_set_cpu_available(unsigned int cpu) if (WARN_ON_ONCE(!tmc->tmgroup)) return -EINVAL; =20 + cpumask_set_cpu(cpu, tmigr_available_cpumask); raw_spin_lock_irq(&tmc->lock); trace_tmigr_cpu_available(tmc); tmc->idle =3D timer_base_is_idle(); @@ -1808,6 +1816,11 @@ static int __init tmigr_init(void) if (ncpus =3D=3D 1) return 0; =20 + if (!zalloc_cpumask_var(&tmigr_available_cpumask, GFP_KERNEL)) { + ret =3D -ENOMEM; + goto err; + } + /* * Calculate the required hierarchy levels. Unfortunately there is no * reliable information available, unless all possible CPUs have been --=20 2.51.0 From nobody Thu Oct 2 14:13:38 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 81901327A1C for ; Mon, 15 Sep 2025 15:00:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757948416; cv=none; b=L/26CTiazB65gQ4kDusGmZ0tPFaGAIX9t7szatOorT+2mMyX3+6P+gQHugBDGf5OSGzdDpQJclio4b9kv3F/AGBGc4f4hAIg4QyvI++QtTCZKx3GoB+e1um5SOFPKTwvdecM0ScZ7mXw+MP8xIzUrcmgbL7ZSMkbmaHRx9B9/ng= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757948416; c=relaxed/simple; bh=UMsHu+w8EEtkyNcFKkFqgEeOYSGG/E/cfqNjj48Uvek=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YkIahAtm1oxK1yFbVRKoKVZY1hEl9Gj6gZx3qrVxyk0jV2ActXUisfVK4hOzKgnPm4NRQPOO46dKnTrBotEhESuAdkgDUa1UXW2jDv+rsf7iaN+EQ0CqUc05tcx3K/4D5E3HCmjxUiNTE4G2XUAYUui6A6+GLX/QXy1VJQmFcvM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=eyllpHLb; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="eyllpHLb" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757948413; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nneiESOQSRs1JNr8iGSFvq05p9vDY3T+UnNzRYLtsEk=; b=eyllpHLbzLg8FzID/F6Mwm1x0EmAe/UavaIdthqvFGsi1fHyU0bg9hFmN4lK9mEP5OpRWE P8RZRTVAreYhpLw+UJ3iphPk3/PVmpW7zyg1bBvOi8c+ptbH9DOXrmMyWqWV+VlZZU003S 1JWdlAZUpP0ojlbQCp5Qnc11Rwr3Qmc= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-655-h3aGPfcfOCCwN0GXgFc6fw-1; Mon, 15 Sep 2025 11:00:08 -0400 X-MC-Unique: h3aGPfcfOCCwN0GXgFc6fw-1 X-Mimecast-MFC-AGG-ID: h3aGPfcfOCCwN0GXgFc6fw_1757948407 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 11920180035C; Mon, 15 Sep 2025 15:00:07 +0000 (UTC) Received: from gmonaco-thinkpadt14gen3.rmtit.com (unknown [10.44.32.63]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C375E1800446; Mon, 15 Sep 2025 15:00:04 +0000 (UTC) From: Gabriele Monaco To: linux-kernel@vger.kernel.org, Anna-Maria Behnsen , Thomas Gleixner Cc: Gabriele Monaco , Frederic Weisbecker Subject: [PATCH v12 4/9] timers: Use scoped_guard when setting/clearing the tmigr available flag Date: Mon, 15 Sep 2025 16:59:25 +0200 Message-ID: <20250915145920.140180-15-gmonaco@redhat.com> In-Reply-To: <20250915145920.140180-11-gmonaco@redhat.com> References: <20250915145920.140180-11-gmonaco@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" Cleanup tmigr_clear_cpu_available() and tmigr_set_cpu_available() to prepare for easier checks on the available flag. Reviewed-by: Frederic Weisbecker Signed-off-by: Gabriele Monaco --- kernel/time/timer_migration.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/kernel/time/timer_migration.c b/kernel/time/timer_migration.c index 865071ab5062..0a3a26e766d0 100644 --- a/kernel/time/timer_migration.c +++ b/kernel/time/timer_migration.c @@ -1450,17 +1450,17 @@ static int tmigr_clear_cpu_available(unsigned int c= pu) u64 firstexp; =20 cpumask_clear_cpu(cpu, tmigr_available_cpumask); - raw_spin_lock_irq(&tmc->lock); - tmc->available =3D false; - WRITE_ONCE(tmc->wakeup, KTIME_MAX); + scoped_guard(raw_spinlock_irq, &tmc->lock) { + tmc->available =3D false; + WRITE_ONCE(tmc->wakeup, KTIME_MAX); =20 - /* - * CPU has to handle the local events on his own, when on the way to - * offline; Therefore nextevt value is set to KTIME_MAX - */ - firstexp =3D __tmigr_cpu_deactivate(tmc, KTIME_MAX); - trace_tmigr_cpu_unavailable(tmc); - raw_spin_unlock_irq(&tmc->lock); + /* + * CPU has to handle the local events on his own, when on the way to + * offline; Therefore nextevt value is set to KTIME_MAX + */ + firstexp =3D __tmigr_cpu_deactivate(tmc, KTIME_MAX); + trace_tmigr_cpu_unavailable(tmc); + } =20 if (firstexp !=3D KTIME_MAX) { migrator =3D cpumask_any(tmigr_available_cpumask); @@ -1479,13 +1479,13 @@ static int tmigr_set_cpu_available(unsigned int cpu) return -EINVAL; =20 cpumask_set_cpu(cpu, tmigr_available_cpumask); - raw_spin_lock_irq(&tmc->lock); - trace_tmigr_cpu_available(tmc); - tmc->idle =3D timer_base_is_idle(); - if (!tmc->idle) - __tmigr_cpu_activate(tmc); - tmc->available =3D true; - raw_spin_unlock_irq(&tmc->lock); + scoped_guard(raw_spinlock_irq, &tmc->lock) { + trace_tmigr_cpu_available(tmc); + tmc->idle =3D timer_base_is_idle(); + if (!tmc->idle) + __tmigr_cpu_activate(tmc); + tmc->available =3D true; + } return 0; } =20 --=20 2.51.0 From nobody Thu Oct 2 14:13:38 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 DEC50342CA3 for ; Mon, 15 Sep 2025 15:00:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757948417; cv=none; b=RCTY+hDG4La602z22QDTmkmXjWiFXixOhRJNU2W0q5QR20P4tBXvWxg5Le+pXl+G6wyJbnb9qj2h/e21pRv9kYBwBv+y266ckVYRlTu49Dxm4EyAtvN1s1XXJMmjjV371YPsAu6TG/zmPDPWwByk+InitVyIZwqe7IO5jwM/5ug= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757948417; c=relaxed/simple; bh=CVcxBN3yBi2+KF9nsuc5ygifXUn/J8ZoLLY8fUb/2IQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y4Ejp2UTc9TNWDx+TnG21x9qVYgdJWyG3ICFajRzPY5NIPKti8WYIX6JGJikBamp+0x5Q49ybTbo/DbJuwHa8ipKVGMGjFkg5PnJ0Xc008Cj5tHuhMMAE2VGDSicMJYvpufJsClbyLjov78xZnN10H5YIzoTxy5hSTDVUo8uMmI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=CePmwMy/; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="CePmwMy/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757948414; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8d/8dosrELDy6fCndqrJ6GJCaJmUKepAV3zv1L8i3og=; b=CePmwMy/bQEXv7Pk2KRUinZY36/sAjOXkrkhFwRqpt4yNhgdd8fR2peuQ6cWNbfXYVrFBB ABiqVn8bikcbWqVXlqgZhxxCMKh/R/dvY9SwKYFHwc+avEUViM5aXsxmSN6xWn1ERG6fJq g+inQZRrN8BuoGr5vMtXCGWfA4f12YE= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-541-YYITePQIPJWz0erSeFmpWA-1; Mon, 15 Sep 2025 11:00:13 -0400 X-MC-Unique: YYITePQIPJWz0erSeFmpWA-1 X-Mimecast-MFC-AGG-ID: YYITePQIPJWz0erSeFmpWA_1757948412 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A5BDD1800359; Mon, 15 Sep 2025 15:00:11 +0000 (UTC) Received: from gmonaco-thinkpadt14gen3.rmtit.com (unknown [10.44.32.63]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 12A961800446; Mon, 15 Sep 2025 15:00:07 +0000 (UTC) From: Gabriele Monaco To: linux-kernel@vger.kernel.org, Waiman Long , Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= , cgroups@vger.kernel.org Cc: Gabriele Monaco , Frederic Weisbecker Subject: [PATCH v12 5/9] cgroup/cpuset: Rename update_unbound_workqueue_cpumask() to update_exclusion_cpumasks() Date: Mon, 15 Sep 2025 16:59:26 +0200 Message-ID: <20250915145920.140180-16-gmonaco@redhat.com> In-Reply-To: <20250915145920.140180-11-gmonaco@redhat.com> References: <20250915145920.140180-11-gmonaco@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" update_unbound_workqueue_cpumask() updates unbound workqueues settings when there's a change in isolated CPUs, but it can be used for other subsystems requiring updated when isolated CPUs change. Generalise the name to update_exclusion_cpumasks() to prepare for other functions unrelated to workqueues to be called in that spot. Acked-by: Frederic Weisbecker Acked-by: Waiman Long Signed-off-by: Gabriele Monaco --- kernel/cgroup/cpuset.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 27adb04df675..81a9239053a7 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1339,7 +1339,7 @@ static bool partition_xcpus_del(int old_prs, struct c= puset *parent, return isolcpus_updated; } =20 -static void update_unbound_workqueue_cpumask(bool isolcpus_updated) +static void update_exclusion_cpumasks(bool isolcpus_updated) { int ret; =20 @@ -1470,7 +1470,7 @@ static int remote_partition_enable(struct cpuset *cs,= int new_prs, list_add(&cs->remote_sibling, &remote_children); cpumask_copy(cs->effective_xcpus, tmp->new_cpus); spin_unlock_irq(&callback_lock); - update_unbound_workqueue_cpumask(isolcpus_updated); + update_exclusion_cpumasks(isolcpus_updated); cpuset_force_rebuild(); cs->prs_err =3D 0; =20 @@ -1511,7 +1511,7 @@ static void remote_partition_disable(struct cpuset *c= s, struct tmpmasks *tmp) compute_effective_exclusive_cpumask(cs, NULL, NULL); reset_partition_data(cs); spin_unlock_irq(&callback_lock); - update_unbound_workqueue_cpumask(isolcpus_updated); + update_exclusion_cpumasks(isolcpus_updated); cpuset_force_rebuild(); =20 /* @@ -1580,7 +1580,7 @@ static void remote_cpus_update(struct cpuset *cs, str= uct cpumask *xcpus, if (xcpus) cpumask_copy(cs->exclusive_cpus, xcpus); spin_unlock_irq(&callback_lock); - update_unbound_workqueue_cpumask(isolcpus_updated); + update_exclusion_cpumasks(isolcpus_updated); if (adding || deleting) cpuset_force_rebuild(); =20 @@ -1943,7 +1943,7 @@ static int update_parent_effective_cpumask(struct cpu= set *cs, int cmd, WARN_ON_ONCE(parent->nr_subparts < 0); } spin_unlock_irq(&callback_lock); - update_unbound_workqueue_cpumask(isolcpus_updated); + update_exclusion_cpumasks(isolcpus_updated); =20 if ((old_prs !=3D new_prs) && (cmd =3D=3D partcmd_update)) update_partition_exclusive_flag(cs, new_prs); @@ -2968,7 +2968,7 @@ static int update_prstate(struct cpuset *cs, int new_= prs) else if (isolcpus_updated) isolated_cpus_update(old_prs, new_prs, cs->effective_xcpus); spin_unlock_irq(&callback_lock); - update_unbound_workqueue_cpumask(isolcpus_updated); + update_exclusion_cpumasks(isolcpus_updated); =20 /* Force update if switching back to member & update effective_xcpus */ update_cpumasks_hier(cs, &tmpmask, !new_prs); --=20 2.51.0 From nobody Thu Oct 2 14:13:38 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 ADA2534321A for ; Mon, 15 Sep 2025 15:00:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757948424; cv=none; b=TYa+sdxjnrFPkbgcrVp5xIGET+YHk03vQkyGvLSvJl1LuOxPO++fV7BsK+A0HpTndQn04jFwbAh1/Dk9E5XxbIYNotuVU+OwJ5rcusklgCetj3RR5m+7Npj47DDg05Mly0Myfmc+hOt4tjhG0/50Q6ewvbZy1Um49WqwAUZd0dQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757948424; c=relaxed/simple; bh=orl97ADICI4ifLLSRLAlatiFb35y7EONMQ1cCnXv80k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sGOLc92cN1+h2Bq8wW/jEbjYHlpa41LlY6/IE+knDp+2irtoOir6I8bevDi3KWHkppQ4q6jljFGY+bPLl+GAZiOLutVLNK6iFxJC2eHcnWoEapyslR2HCaPiJROoOK/72X1hpEu0t4mEHWN1yNYJ8MkslQ7eBTMQ5Sya0i5LXiI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=gw/uQZm+; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="gw/uQZm+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757948421; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gYezNvw2JXA2eYKqYkaBQbpJb87hLMjOLjuBiAHIOFM=; b=gw/uQZm+J6Ns2m/RLDIymcbBkNrc07JU7NDhVdrOPMA82qcZvUjrwxfi28+tuz8MJn4lyw B1vdNKYemHHAWkobvBaxdsKEixYhQ+/QJD25ILsGEQPAAI+xGDQOzknCInXKFtQIfiGFf3 x5+DAEQwdTtrfpEp1KUXAaI7jbmPo6E= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-623-a8maHv_bMTi7j2ShgmnP9w-1; Mon, 15 Sep 2025 11:00:17 -0400 X-MC-Unique: a8maHv_bMTi7j2ShgmnP9w-1 X-Mimecast-MFC-AGG-ID: a8maHv_bMTi7j2ShgmnP9w_1757948415 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8BCCE180057A; Mon, 15 Sep 2025 15:00:15 +0000 (UTC) Received: from gmonaco-thinkpadt14gen3.rmtit.com (unknown [10.44.32.63]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8F66B1800447; Mon, 15 Sep 2025 15:00:12 +0000 (UTC) From: Gabriele Monaco To: linux-kernel@vger.kernel.org, Ingo Molnar , Peter Zijlstra Cc: Gabriele Monaco , Waiman Long , Frederic Weisbecker Subject: [PATCH v12 6/9] sched/isolation: Force housekeeping if isolcpus and nohz_full don't leave any Date: Mon, 15 Sep 2025 16:59:27 +0200 Message-ID: <20250915145920.140180-17-gmonaco@redhat.com> In-Reply-To: <20250915145920.140180-11-gmonaco@redhat.com> References: <20250915145920.140180-11-gmonaco@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" Currently the user can set up isolcpus and nohz_full in such a way that leaves no housekeeping CPU (i.e. no CPU that is neither domain isolated nor nohz full). This can be a problem for other subsystems (e.g. the timer wheel imgration). Prevent this configuration by invalidating the last setting in case the union of isolcpus (domain) and nohz_full covers all CPUs. Reviewed-by: Waiman Long Reviewed-by: Frederic Weisbecker Signed-off-by: Gabriele Monaco --- kernel/sched/isolation.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/kernel/sched/isolation.c b/kernel/sched/isolation.c index a4cf17b1fab0..3ad0d6df6a0a 100644 --- a/kernel/sched/isolation.c +++ b/kernel/sched/isolation.c @@ -167,6 +167,29 @@ static int __init housekeeping_setup(char *str, unsign= ed long flags) } } =20 + /* + * Check the combination of nohz_full and isolcpus=3Ddomain, + * necessary to avoid problems with the timer migration + * hierarchy. managed_irq is ignored by this check since it + * isn't considered in the timer migration logic. + */ + iter_flags =3D housekeeping.flags & (HK_FLAG_KERNEL_NOISE | HK_FLAG_DOMA= IN); + type =3D find_first_bit(&iter_flags, HK_TYPE_MAX); + /* + * Pass the check if none of these flags were previously set or + * are not in the current selection. + */ + iter_flags =3D flags & (HK_FLAG_KERNEL_NOISE | HK_FLAG_DOMAIN); + first_cpu =3D (type =3D=3D HK_TYPE_MAX || !iter_flags) ? 0 : + cpumask_first_and_and(cpu_present_mask, + housekeeping_staging, housekeeping.cpumasks[type]); + if (first_cpu >=3D min(nr_cpu_ids, setup_max_cpus)) { + pr_warn("Housekeeping: must include one present CPU " + "neither in nohz_full=3D nor in isolcpus=3Ddomain, " + "ignoring setting %s\n", str); + goto free_housekeeping_staging; + } + iter_flags =3D flags & ~housekeeping.flags; =20 for_each_set_bit(type, &iter_flags, HK_TYPE_MAX) --=20 2.51.0 From nobody Thu Oct 2 14:13:38 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 EA4AE33A00A for ; Mon, 15 Sep 2025 15:00:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757948427; cv=none; b=m2zc1VNQ08dq84wTyjt4Ryp4FtRmqQFu+uZbIlJgVU1mjAUfMHwgIGoRGy7OMSNRv93WpImraYlRnnS3ZmrtybQ2wf+e6CToyjhtlZjy9K9HiV/scBLu/rugqpnR3omwybOqrPg6DUydi9tumemFGjLAlCLdMEJCHBM/rRShwfo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757948427; c=relaxed/simple; bh=FcB0J8nJCnkbAgJIwOIOkaEq/mdhOTYIfX59kkgSpCQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dCyo3WVyVyExtWKbsnj3v+pELnGYjdia/PwBvBUyCv+O3TUBbsTrE6/ydUBTZ3o0si7amX+dGXTu7eCY4NlRe75zhn3nI5OD3HTsywgxAl+7QPHQpcJZ7xtndhepSpMQGWagfZTLB6eXKiKbXYrO03gvauiMO8s+w3SQVqKt0FQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=O1M3ARFv; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="O1M3ARFv" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757948425; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hO1qmSi6Kg3GkGFkEhZd0Wm3EYi6+PyxTTG9VegyOck=; b=O1M3ARFvQY7kAdD8IIX1fBXwJU1rPrrIMBuH7xOjJSdHMFPbwyqWlJa0EAgNsRCgQ1lvCo whGaEiXUABA1+g11Ez3RFqQnu53J97ViwC53BBX74bSpTw4d1BqAazy8A1rLcX86I6SEdT 923ZtS/omqxDYkCBZDWufwGraDFqgo0= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-175-JlrRSjkXMIiztQWPewZJ_g-1; Mon, 15 Sep 2025 11:00:21 -0400 X-MC-Unique: JlrRSjkXMIiztQWPewZJ_g-1 X-Mimecast-MFC-AGG-ID: JlrRSjkXMIiztQWPewZJ_g_1757948420 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2D9471953952; Mon, 15 Sep 2025 15:00:20 +0000 (UTC) Received: from gmonaco-thinkpadt14gen3.rmtit.com (unknown [10.44.32.63]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8EFC11800446; Mon, 15 Sep 2025 15:00:16 +0000 (UTC) From: Gabriele Monaco To: linux-kernel@vger.kernel.org, Waiman Long , Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= , cgroups@vger.kernel.org Cc: Gabriele Monaco , Frederic Weisbecker Subject: [PATCH v12 7/9] cgroup/cpuset: Fail if isolated and nohz_full don't leave any housekeeping Date: Mon, 15 Sep 2025 16:59:28 +0200 Message-ID: <20250915145920.140180-18-gmonaco@redhat.com> In-Reply-To: <20250915145920.140180-11-gmonaco@redhat.com> References: <20250915145920.140180-11-gmonaco@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" Currently the user can set up isolated cpus via cpuset and nohz_full in such a way that leaves no housekeeping CPU (i.e. no CPU that is neither domain isolated nor nohz full). This can be a problem for other subsystems (e.g. the timer wheel imgration). Prevent this configuration by blocking any assignation that would cause the union of domain isolated cpus and nohz_full to covers all CPUs. Acked-by: Frederic Weisbecker Signed-off-by: Gabriele Monaco Reviewed-by: Waiman Long --- kernel/cgroup/cpuset.c | 63 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 81a9239053a7..3cedc3580373 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1275,6 +1275,19 @@ static void isolated_cpus_update(int old_prs, int ne= w_prs, struct cpumask *xcpus cpumask_andnot(isolated_cpus, isolated_cpus, xcpus); } =20 +/* + * isolated_cpus_should_update - Returns if the isolated_cpus mask needs u= pdate + * @prs: new or old partition_root_state + * @parent: parent cpuset + * Return: true if isolated_cpus needs modification, false otherwise + */ +static bool isolated_cpus_should_update(int prs, struct cpuset *parent) +{ + if (!parent) + parent =3D &top_cpuset; + return prs !=3D parent->partition_root_state; +} + /* * partition_xcpus_add - Add new exclusive CPUs to partition * @new_prs: new partition_root_state @@ -1339,6 +1352,42 @@ static bool partition_xcpus_del(int old_prs, struct = cpuset *parent, return isolcpus_updated; } =20 +/* + * isolated_cpus_can_update - check for isolated & nohz_full conflicts + * @add_cpus: cpu mask for cpus that are going to be isolated + * @del_cpus: cpu mask for cpus that are no longer isolated, can be NULL + * Return: false if there is conflict, true otherwise + * + * If nohz_full is enabled and we have isolated CPUs, their combination mu= st + * still leave housekeeping CPUs. + */ +static bool isolated_cpus_can_update(struct cpumask *add_cpus, + struct cpumask *del_cpus) +{ + cpumask_var_t full_hk_cpus; + int res =3D true; + + if (!housekeeping_enabled(HK_TYPE_KERNEL_NOISE)) + return true; + + if (del_cpus && cpumask_weight_and(del_cpus, + housekeeping_cpumask(HK_TYPE_KERNEL_NOISE))) + return true; + + if (!alloc_cpumask_var(&full_hk_cpus, GFP_KERNEL)) + return false; + + cpumask_and(full_hk_cpus, housekeeping_cpumask(HK_TYPE_KERNEL_NOISE), + housekeeping_cpumask(HK_TYPE_DOMAIN)); + cpumask_andnot(full_hk_cpus, full_hk_cpus, isolated_cpus); + cpumask_and(full_hk_cpus, full_hk_cpus, cpu_active_mask); + if (!cpumask_weight_andnot(full_hk_cpus, add_cpus)) + res =3D false; + + free_cpumask_var(full_hk_cpus); + return res; +} + static void update_exclusion_cpumasks(bool isolcpus_updated) { int ret; @@ -1464,6 +1513,9 @@ static int remote_partition_enable(struct cpuset *cs,= int new_prs, if (!cpumask_intersects(tmp->new_cpus, cpu_active_mask) || cpumask_subset(top_cpuset.effective_cpus, tmp->new_cpus)) return PERR_INVCPUS; + if (isolated_cpus_should_update(new_prs, NULL) && + !isolated_cpus_can_update(tmp->new_cpus, NULL)) + return PERR_HKEEPING; =20 spin_lock_irq(&callback_lock); isolcpus_updated =3D partition_xcpus_add(new_prs, NULL, tmp->new_cpus); @@ -1563,6 +1615,9 @@ static void remote_cpus_update(struct cpuset *cs, str= uct cpumask *xcpus, else if (cpumask_intersects(tmp->addmask, subpartitions_cpus) || cpumask_subset(top_cpuset.effective_cpus, tmp->addmask)) cs->prs_err =3D PERR_NOCPUS; + else if (isolated_cpus_should_update(prs, NULL) && + !isolated_cpus_can_update(tmp->addmask, tmp->delmask)) + cs->prs_err =3D PERR_HKEEPING; if (cs->prs_err) goto invalidate; } @@ -1914,6 +1969,12 @@ static int update_parent_effective_cpumask(struct cp= uset *cs, int cmd, return err; } =20 + if (deleting && isolated_cpus_should_update(new_prs, parent) && + !isolated_cpus_can_update(tmp->delmask, tmp->addmask)) { + cs->prs_err =3D PERR_HKEEPING; + return PERR_HKEEPING; + } + /* * Change the parent's effective_cpus & effective_xcpus (top cpuset * only). @@ -2934,6 +2995,8 @@ static int update_prstate(struct cpuset *cs, int new_= prs) * Need to update isolated_cpus. */ isolcpus_updated =3D true; + if (!isolated_cpus_can_update(cs->effective_xcpus, NULL)) + err =3D PERR_HKEEPING; } else { /* * Switching back to member is always allowed even if it --=20 2.51.0 From nobody Thu Oct 2 14:13:38 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 BA21F340DB3 for ; Mon, 15 Sep 2025 15:00:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757948429; cv=none; b=ejSAf7ljQ/V/iWIZeGB4s+hIZ3YQyjM/u90aGGsbo198853nlBe8raeYgBkZz7jnpnpOLWmeeJHwIeMC4NARVCRpiHldBFlZfiKvOoo+YdLpw6IJVdFUAxIx5re+17F5gXmF63iT7Vs7FlZr/kL8bFsjlgxlNUi7rWu1UXlCGVo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757948429; c=relaxed/simple; bh=DAEJnz1PYrrsRnE2T7/7GUldQyKxaAsfp+XTjj5m3Fo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g0lX/QSBJ2Rfjxarvbtfy0HGay2dM3IKMqSEJR0I27phuQmEJhhcouX4cDArLqwivaY4NVHWb7OjqqxiQ4/p8aXD89pDCOQLtw3GoWYXSr29QeLRn1pPVsQSykNoRdqxtj65NOf8LKo48pQPmOIJQviLmnQfiJLOLHiQAcm/ZH8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=jV43ZEqs; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="jV43ZEqs" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757948426; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Glcz1Zqa3Xm+SpxWCco2Yz++SUVZfeI6p0+BeU5K0tE=; b=jV43ZEqs1iSkpg8GYAzoHduaC1GEKoS49iVd3Sih1bBs2tenxFrAYkyVdW8RVTsxoWs+j/ wei2vl+7XyAazpNdv+1T7iWSdFUY0lpM1w/djOyw6cFEkWb39hMXwjBrW+MrjPpiO7ytEa HCCxMxgFAa3r93p1yVd5Aa6OIAjOkt4= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-606-dHz9H-g8MKik48a7PXRIbQ-1; Mon, 15 Sep 2025 11:00:24 -0400 X-MC-Unique: dHz9H-g8MKik48a7PXRIbQ-1 X-Mimecast-MFC-AGG-ID: dHz9H-g8MKik48a7PXRIbQ_1757948423 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E70AF180057E; Mon, 15 Sep 2025 15:00:22 +0000 (UTC) Received: from gmonaco-thinkpadt14gen3.rmtit.com (unknown [10.44.32.63]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5EEF1180044F; Mon, 15 Sep 2025 15:00:20 +0000 (UTC) From: Gabriele Monaco To: linux-kernel@vger.kernel.org, Yury Norov Cc: Gabriele Monaco Subject: [PATCH v12 8/9] cpumask: Add initialiser CPUMASK_NULL to use cleanup helpers Date: Mon, 15 Sep 2025 16:59:29 +0200 Message-ID: <20250915145920.140180-19-gmonaco@redhat.com> In-Reply-To: <20250915145920.140180-11-gmonaco@redhat.com> References: <20250915145920.140180-11-gmonaco@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" The cleanup helper __free(free_cpumask_var) works only if the function returns after alloc_cpumask_var, this can complicate the code in case there are multiple cpumasks using the cleanup helper. Define a cpumask initialiser that is NULL if the cpumask is a pointer and {} if it's on stack. This allows users of the cleanup helper to use it freely on initialised cpumasks as the actual free will be called only if the mask is not NULL (and of course if it's a pointer). This solution was first used in [1], dropped as eventually a single mask was sufficient. [1] - https://lore.kernel.org/lkml/20240120025053.684838-8-yury.norov@gmail= .com Signed-off-by: Gabriele Monaco --- include/linux/cpumask.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h index ff8f41ab7ce6..5fb9c3fe4256 100644 --- a/include/linux/cpumask.h +++ b/include/linux/cpumask.h @@ -1005,6 +1005,7 @@ static __always_inline unsigned int cpumask_size(void) =20 #define this_cpu_cpumask_var_ptr(x) this_cpu_read(x) #define __cpumask_var_read_mostly __read_mostly +#define CPUMASK_NULL NULL =20 bool alloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags, int node); =20 @@ -1051,6 +1052,7 @@ static __always_inline bool cpumask_available(cpumask= _var_t mask) =20 #define this_cpu_cpumask_var_ptr(x) this_cpu_ptr(x) #define __cpumask_var_read_mostly +#define CPUMASK_NULL {} =20 static __always_inline bool alloc_cpumask_var(cpumask_var_t *mask, gfp_t f= lags) { --=20 2.51.0 From nobody Thu Oct 2 14:13:38 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 AC7B3341661 for ; Mon, 15 Sep 2025 15:00:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757948437; cv=none; b=LVXad5YmV0gXZ0Z6LbTm/13WuPg0g0VTyGdCWWTPu2YYFkICdvpSxherjzH6mwyXo+WtDJqM7/TRf87q13CbJIQ2unDxu96BoUpFCeku8yUm0wBzRBqYCSw/3u/ZyMIxbmANAOmJ4eD4pUwMV3fDEzsa60m8hONLS7cOikT+/EU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757948437; c=relaxed/simple; bh=Gje1a6MuxbQRqJJjVBWFqMGNjvc5qcBa8yIEEkD8wWQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tP21c3AmiLJkAnt5QI4WjExsRKq6HXM7fbbH7Vhx/IVNwadKLgg26Pn4yXN4WEHa6JdjQRQNDuwg+VXOBWL1Pi4WMcLgh+n9NlhwRDRRNkGz/yzACrzN7mRJwU8s64yQz0zo4iGZQeaSxiFMnkn4Uo/kIbesuAfkumlpNBqkBWI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=f9SQ7rCz; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="f9SQ7rCz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757948434; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SLP0rl8cKBQmenYpN/sNhONBZ/EaXWDugv9JYiXlVuM=; b=f9SQ7rCzpEMQECoAdGribDJWYfHXC7ybWgIif7rW3Gz4dC6s0+uriO7AvvLHDYWHImdnW4 pNipDuaEtYEGHT9bAwjrodwUnCPqnvFTxq3poH32ZRdHWLr+RA/DFpLYH/oK/AI89Zx/q7 H0PmZNo79H2W06mw2615gxYW1DR0KUc= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-687-4BA_leHXP1ml6STXCRd0wQ-1; Mon, 15 Sep 2025 11:00:30 -0400 X-MC-Unique: 4BA_leHXP1ml6STXCRd0wQ-1 X-Mimecast-MFC-AGG-ID: 4BA_leHXP1ml6STXCRd0wQ_1757948428 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8C8A418002C4; Mon, 15 Sep 2025 15:00:28 +0000 (UTC) Received: from gmonaco-thinkpadt14gen3.rmtit.com (unknown [10.44.32.63]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 264F21800446; Mon, 15 Sep 2025 15:00:23 +0000 (UTC) From: Gabriele Monaco To: linux-kernel@vger.kernel.org, Anna-Maria Behnsen , Thomas Gleixner , Waiman Long , Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= , cgroups@vger.kernel.org Cc: Gabriele Monaco , "John B. Wyatt IV" , "John B. Wyatt IV" Subject: [PATCH v12 9/9] timers: Exclude isolated cpus from timer migration Date: Mon, 15 Sep 2025 16:59:30 +0200 Message-ID: <20250915145920.140180-20-gmonaco@redhat.com> In-Reply-To: <20250915145920.140180-11-gmonaco@redhat.com> References: <20250915145920.140180-11-gmonaco@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" The timer migration mechanism allows active CPUs to pull timers from idle ones to improve the overall idle time. This is however undesired when CPU intensive workloads run on isolated cores, as the algorithm would move the timers from housekeeping to isolated cores, negatively affecting the isolation. Exclude isolated cores from the timer migration algorithm, extend the concept of unavailable cores, currently used for offline ones, to isolated ones: * A core is unavailable if isolated or offline; * A core is available if non isolated and online; A core is considered unavailable as isolated if it belongs to: * the isolcpus (domain) list * an isolated cpuset Except if it is: * in the nohz_full list (already idle for the hierarchy) * the nohz timekeeper core (must be available to handle global timers) CPUs are added to the hierarchy during late boot, excluding isolated ones, the hierarchy is also adapted when the cpuset isolation changes. Due to how the timer migration algorithm works, any CPU part of the hierarchy can have their global timers pulled by remote CPUs and have to pull remote timers, only skipping pulling remote timers would break the logic. For this reason, prevent isolated CPUs from pulling remote global timers, but also the other way around: any global timer started on an isolated CPU will run there. This does not break the concept of isolation (global timers don't come from outside the CPU) and, if considered inappropriate, can usually be mitigated with other isolation techniques (e.g. IRQ pinning). This effect was noticed on a 128 cores machine running oslat on the isolated cores (1-31,33-63,65-95,97-127). The tool monopolises CPUs, and the CPU with lowest count in a timer migration hierarchy (here 1 and 65) appears as always active and continuously pulls global timers, from the housekeeping CPUs. This ends up moving driver work (e.g. delayed work) to isolated CPUs and causes latency spikes: before the change: # oslat -c 1-31,33-63,65-95,97-127 -D 62s ... Maximum: 1203 10 3 4 ... 5 (us) after the change: # oslat -c 1-31,33-63,65-95,97-127 -D 62s ... Maximum: 10 4 3 4 3 ... 5 (us) Tested-by: John B. Wyatt IV Tested-by: John B. Wyatt IV Signed-off-by: Gabriele Monaco --- include/linux/timer.h | 9 +++ kernel/cgroup/cpuset.c | 3 + kernel/time/timer_migration.c | 108 +++++++++++++++++++++++++++++++++- 3 files changed, 119 insertions(+), 1 deletion(-) diff --git a/include/linux/timer.h b/include/linux/timer.h index 0414d9e6b4fc..62e1cea71125 100644 --- a/include/linux/timer.h +++ b/include/linux/timer.h @@ -188,4 +188,13 @@ int timers_dead_cpu(unsigned int cpu); #define timers_dead_cpu NULL #endif =20 +#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON) +extern int tmigr_isolated_exclude_cpumask(struct cpumask *exclude_cpumask); +#else +static inline int tmigr_isolated_exclude_cpumask(struct cpumask *exclude_c= pumask) +{ + return 0; +} +#endif + #endif diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 3cedc3580373..6e9d86fab27e 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1399,6 +1399,9 @@ static void update_exclusion_cpumasks(bool isolcpus_u= pdated) =20 ret =3D workqueue_unbound_exclude_cpumask(isolated_cpus); WARN_ON_ONCE(ret < 0); + + ret =3D tmigr_isolated_exclude_cpumask(isolated_cpus); + WARN_ON_ONCE(ret < 0); } =20 /** diff --git a/kernel/time/timer_migration.c b/kernel/time/timer_migration.c index 0a3a26e766d0..08e29fc01479 100644 --- a/kernel/time/timer_migration.c +++ b/kernel/time/timer_migration.c @@ -10,6 +10,7 @@ #include #include #include +#include =20 #include "timer_migration.h" #include "tick-internal.h" @@ -436,6 +437,29 @@ static inline bool tmigr_is_not_available(struct tmigr= _cpu *tmc) return !(tmc->tmgroup && tmc->available); } =20 +/* + * Returns true if @cpu should be excluded from the hierarchy as isolated. + * Domain isolated CPUs don't participate in timer migration, nohz_full CP= Us + * are still part of the hierarchy but become idle (from a tick and timer + * migration perspective) when they stop their tick. This lets the timekee= ping + * CPU handle their global timers. Marking also isolated CPUs as idle woul= d be + * too costly, hence they are completely excluded from the hierarchy. + * This check is necessary, for instance, to prevent offline isolated CPUs= from + * being incorrectly marked as available once getting back online. + * + * Additionally, the tick CPU can be isolated at boot, however + * we cannot mark it as unavailable to avoid having no global migrator + * for the nohz_full CPUs. This check is only necessary at boot time. + */ +static inline bool tmigr_is_isolated(int cpu) +{ + if (!tick_nohz_cpu_hotpluggable(cpu)) + return false; + return (!housekeeping_cpu(cpu, HK_TYPE_DOMAIN) || + cpuset_cpu_is_isolated(cpu)) && + housekeeping_cpu(cpu, HK_TYPE_KERNEL_NOISE); +} + /* * Returns true, when @childmask corresponds to the group migrator or when= the * group is not active - so no migrator is set. @@ -1451,6 +1475,8 @@ static int tmigr_clear_cpu_available(unsigned int cpu) =20 cpumask_clear_cpu(cpu, tmigr_available_cpumask); scoped_guard(raw_spinlock_irq, &tmc->lock) { + if (!tmc->available) + return 0; tmc->available =3D false; WRITE_ONCE(tmc->wakeup, KTIME_MAX); =20 @@ -1478,8 +1504,12 @@ static int tmigr_set_cpu_available(unsigned int cpu) if (WARN_ON_ONCE(!tmc->tmgroup)) return -EINVAL; =20 + if (tmigr_is_isolated(cpu)) + return 0; cpumask_set_cpu(cpu, tmigr_available_cpumask); scoped_guard(raw_spinlock_irq, &tmc->lock) { + if (tmc->available) + return 0; trace_tmigr_cpu_available(tmc); tmc->idle =3D timer_base_is_idle(); if (!tmc->idle) @@ -1489,6 +1519,81 @@ static int tmigr_set_cpu_available(unsigned int cpu) return 0; } =20 +static void tmigr_cpu_isolate(struct work_struct *ignored) +{ + tmigr_clear_cpu_available(smp_processor_id()); +} + +static void tmigr_cpu_unisolate(struct work_struct *ignored) +{ + tmigr_set_cpu_available(smp_processor_id()); +} + +/** + * tmigr_isolated_exclude_cpumask - Exclude given CPUs from hierarchy + * @exclude_cpumask: the cpumask to be excluded from timer migration hiera= rchy + * + * This function can be called from cpuset code to provide the new set of + * isolated CPUs that should be excluded from the hierarchy. + * Online CPUs not present in exclude_cpumask but already excluded are bro= ught + * back to the hierarchy. + * Functions to isolate/unisolate need to be called locally and can sleep. + */ +int tmigr_isolated_exclude_cpumask(struct cpumask *exclude_cpumask) +{ + struct work_struct __percpu *works __free(free_percpu) =3D + alloc_percpu(struct work_struct); + cpumask_var_t cpumask_unisol __free(free_cpumask_var) =3D CPUMASK_NULL; + cpumask_var_t cpumask_isol __free(free_cpumask_var) =3D CPUMASK_NULL; + int cpu; + + lockdep_assert_cpus_held(); + + if (!alloc_cpumask_var(&cpumask_isol, GFP_KERNEL)) + return -ENOMEM; + if (!alloc_cpumask_var(&cpumask_unisol, GFP_KERNEL)) + return -ENOMEM; + if (!works) + return -ENOMEM; + + cpumask_andnot(cpumask_unisol, cpu_online_mask, exclude_cpumask); + cpumask_andnot(cpumask_unisol, cpumask_unisol, tmigr_available_cpumask); + /* Set up the mask earlier to avoid races with the migrator CPU */ + cpumask_or(tmigr_available_cpumask, tmigr_available_cpumask, cpumask_unis= ol); + for_each_cpu(cpu, cpumask_unisol) { + struct work_struct *work =3D per_cpu_ptr(works, cpu); + + INIT_WORK(work, tmigr_cpu_unisolate); + schedule_work_on(cpu, work); + } + + cpumask_and(cpumask_isol, exclude_cpumask, tmigr_available_cpumask); + cpumask_and(cpumask_isol, cpumask_isol, housekeeping_cpumask(HK_TYPE_KERN= EL_NOISE)); + /* + * Handle this here and not in the cpuset code because exclude_cpumask + * might include also the tick CPU if included in isolcpus. + */ + for_each_cpu(cpu, cpumask_isol) { + if (!tick_nohz_cpu_hotpluggable(cpu)) { + cpumask_clear_cpu(cpu, cpumask_isol); + break; + } + } + /* Set up the mask earlier to avoid races with the migrator CPU */ + cpumask_andnot(tmigr_available_cpumask, tmigr_available_cpumask, cpumask_= isol); + for_each_cpu(cpu, cpumask_isol) { + struct work_struct *work =3D per_cpu_ptr(works, cpu); + + INIT_WORK(work, tmigr_cpu_isolate); + schedule_work_on(cpu, work); + } + + for_each_cpu_or(cpu, cpumask_isol, cpumask_unisol) + flush_work(per_cpu_ptr(works, cpu)); + + return 0; +} + /* * NOHZ can only be enabled after clocksource_done_booting(). Don't * bother trashing the cache in the tree before. @@ -1496,7 +1601,8 @@ static int tmigr_set_cpu_available(unsigned int cpu) static int __init tmigr_late_init(void) { return cpuhp_setup_state(CPUHP_AP_TMIGR_ONLINE, "tmigr:online", - tmigr_set_cpu_available, tmigr_clear_cpu_available); + tmigr_set_cpu_available, + tmigr_clear_cpu_available); } =20 static void tmigr_init_group(struct tmigr_group *group, unsigned int lvl, --=20 2.51.0