From nobody Sun Feb 8 08:36:39 2026 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 7E14D149C55 for ; Wed, 18 Dec 2024 17:15:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734542161; cv=none; b=Fdu6okKMzk1TTo7GTlh6G+Yxx72DB3632OLuc5HmkuU4I9pEuDnFjojA7wdFj91sYBRmVjxociZvc1LURfTpfSS5GBAfsjThPAk6c2kZX6Thl3v69K6LCeukia+7uPhQfw/Hbgr7ocpblbkC8g0buYvbqIUuus0oM6HTVy4JYYs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734542161; c=relaxed/simple; bh=3HvoFUnwQjQO5hVVjJ0Zn0J4y5QVBYJleQAXtnNWpBU=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=E3R+PPw1TRaY2/dDSa/mho7mmnvu/Yf+PjFJy0otFnyjcbwcAcbl+75bYs6/xgLw2UcuLaZhbBK1F14BCojqM7YPTGRqkeBKx3IwaYAglc4WWNRDL6mbNjcw+IxBWRhLp8h2TwOWZ9MVRZ2aXrF5CbByJsDnbzmUqENtjPYNWqg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-432d86a3085so45436955e9.2 for ; Wed, 18 Dec 2024 09:15:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734542158; x=1735146958; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dVLUFNdD2hSRpyQ7z8WPzSvdlIeXi5sf8wQ4T0oNvTY=; b=fxSbSosATAF36I/S0pelCOKYvFvnYNYa7D7vc6m+fDk7gdRA9D+9H7y4U6MAI6I+9U T/1768mV+Q1PDoaPxw2lr4yqrVy/p6JDi0bZdVuOMEIYRaCC8lLgh3H/L2UxILw+8y+q JyQJHKjP9LCuc5ttJwN36m5g/rMF06yhdiOnjM7piUodcd2qU9AtrgP/g5QOZwcb1wrb E7Ablm4mbG4Zlga/eyIXpqGh/lf/r842gbCh/w8PDw1WYj3AAz57bF6vyyTu4Oqhg3Wy Cb3MChDPbH4xBIvcOAD9yTv85Mhz1symLhfzHA2zwKFOSZhPCl9lb+vUv25fmh20txJf oG4Q== X-Forwarded-Encrypted: i=1; AJvYcCWhggqCzckYjpjM06lvOALS4z9SiXZzyDr76mefKHTcjPhgv9ckKYn91bYU8Q94vrzJZBIHqrHMiULU2S4=@vger.kernel.org X-Gm-Message-State: AOJu0YxQpFq4TUeZYlaPTVwg0cmudutQz//3l+qsrY6li6SR1Yn4MdrC Bb8uAUBjXptBw5q9dIzNFPzJG7NCON3g/3BG750XNtegi+YjvIUJlFHquL2L1QU= X-Gm-Gg: ASbGncsEqSUYJmxT0tvrhuSVdrcNDDzT4k7rQn5f/ou2CHijVxv94h2XZzIfKDrzDXl I8OzJgcE7p2Jlw57hhptylzgAyUq9T7H9GnEaQBOqxgcIK9+se8ViFJjLLh9DDyZeGYvOENz9l/ WDyjesgAjtK6lBKRGXleNyM86KeE4v7USfi7zJM5GXDquGDYdYsIkv9fp4MNQzCE7Ch0qKENpt7 TfhsUCryRC2Mk4il785wHb8I7eYeYPub+P2HShRmne1wXxinAahGIy2uGo2mLxdxI8wwtBTag== X-Google-Smtp-Source: AGHT+IEVJXMwrCdVQm/2uE7h3d+EwAJkfvCimJ92c4bw4SOb+dsHM/1LJhcgCNQWZanAZndzMTe1Kw== X-Received: by 2002:a05:600c:4f91:b0:434:a4fe:cd71 with SMTP id 5b1f17b1804b1-4365c7845bcmr1011615e9.12.1734542157426; Wed, 18 Dec 2024 09:15:57 -0800 (PST) Received: from costa-tp.redhat.com ([2a00:a041:e280:5300:9068:704e:a31a:c135]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43656b119ccsm26034695e9.24.2024.12.18.09.15.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Dec 2024 09:15:56 -0800 (PST) From: Costa Shulyupin To: Thomas Gleixner , Peter Zijlstra , Yury Norov , Andrew Morton , Costa Shulyupin , Valentin Schneider , Frederic Weisbecker , Neeraj Upadhyay , linux-kernel@vger.kernel.org, Waiman Long , x86@kernel.org Subject: [RFC PATCH v1] stop_machine: Add stop_housekeeping_cpuslocked() Date: Wed, 18 Dec 2024 19:15:31 +0200 Message-ID: <20241218171531.2217275-1-costa.shul@redhat.com> X-Mailer: git-send-email 2.47.0 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 Content-Type: text/plain; charset="utf-8" CPU hotplug interferes with CPU isolation and introduces latency to real-time tasks. The test: rtla timerlat hist -c 1 -a 500 & echo 0 > /sys/devices/system/cpu/cpu2/online The RTLA tool reveals the following blocking thread stack trace: -> multi_cpu_stop -> cpu_stopper_thread -> smpboot_thread_fn This happens because multi_cpu_stop() disables interrupts for EACH online CPU since takedown_cpu() indirectly invokes take_cpu_down() through stop_machine_cpuslocked(). I'm omitting the detailed description of the call chain. Proposal: Limit the stop operation to housekeeping CPUs. take_cpu_down() invokes with cpuhp_invoke_callback_range_nofail: - tick_cpu_dying() - hrtimers_cpu_dying() - smpcfd_dying_cpu() - x86_pmu_dying_cpu() - rcutree_dying_cpu() - sched_cpu_dying() - cache_ap_offline() Which synchronizations do these functions require instead of stop_machine? Passed standard regression tests: - https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/mer= ge_requests/6042 - https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-10/-/me= rge_requests/89 Passes primitive CPU hotplug test without warnings. What tests and test suites do you recommend? Signed-off-by: Costa Shulyupin --- include/linux/stop_machine.h | 12 ++++++++++++ kernel/cpu.c | 2 +- kernel/stop_machine.c | 23 +++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/include/linux/stop_machine.h b/include/linux/stop_machine.h index 3132262a404dc..4c9e709f174c8 100644 --- a/include/linux/stop_machine.h +++ b/include/linux/stop_machine.h @@ -140,6 +140,18 @@ int stop_machine_cpuslocked(cpu_stop_fn_t fn, void *da= ta, const struct cpumask * */ int stop_core_cpuslocked(unsigned int cpu, cpu_stop_fn_t fn, void *data); =20 +/** + * stop_housekeeping_cpuslocked: freeze housekeeping CPUs and run specifie= d function. + * Unlike stop_machine_cpuslocked, it doesn't stop isolated CPUs. + * @fn: the function to run + * @data: the data ptr for the @fn() + * @cpus: the cpus to run the @fn() on (NULL =3D any online cpu) + * + * Must be called from with in a cpus_read_lock() protected + * region. Avoids nested calls to cpus_read_lock(). + */ +int stop_housekeeping_cpuslocked(cpu_stop_fn_t fn, void *data, const struc= t cpumask *cpus); + int stop_machine_from_inactive_cpu(cpu_stop_fn_t fn, void *data, const struct cpumask *cpus); #else /* CONFIG_SMP || CONFIG_HOTPLUG_CPU */ diff --git a/kernel/cpu.c b/kernel/cpu.c index 6d7c51e7c366c..052f48bebf816 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -1310,7 +1310,7 @@ static int takedown_cpu(unsigned int cpu) /* * So now all preempt/rcu users must observe !cpu_active(). */ - err =3D stop_machine_cpuslocked(take_cpu_down, NULL, cpumask_of(cpu)); + err =3D stop_housekeeping_cpuslocked(take_cpu_down, NULL, cpumask_of(cpu)= ); if (err) { /* CPU refused to die */ irq_unlock_sparse(); diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c index da821ce258ea7..1f36e44d42476 100644 --- a/kernel/stop_machine.c +++ b/kernel/stop_machine.c @@ -22,6 +22,7 @@ #include #include #include +#include =20 /* * Structure to determine completion condition and record errors. May @@ -619,6 +620,28 @@ int stop_machine_cpuslocked(cpu_stop_fn_t fn, void *da= ta, return stop_cpus(cpu_online_mask, multi_cpu_stop, &msdata); } =20 +int stop_housekeeping_cpuslocked(cpu_stop_fn_t fn, void *data, const struc= t cpumask *cpus) +{ + struct multi_stop_data msdata =3D { .fn =3D fn, .data =3D data, .active_c= pus =3D cpus }; + cpumask_var_t stop_mask; + int ret; + + lockdep_assert_cpus_held(); + + if (!alloc_cpumask_var(&stop_mask, GFP_KERNEL)) + return -ENOMEM; + cpumask_and(stop_mask, cpu_online_mask, housekeeping_cpumask(HK_TYPE_MANA= GED_IRQ)); + cpumask_or(stop_mask, stop_mask, cpus); + msdata.num_threads =3D cpumask_weight(stop_mask); + + /* Set the initial state and stop online housekeeping cpus. */ + set_state(&msdata, MULTI_STOP_PREPARE); + ret =3D stop_cpus(stop_mask, multi_cpu_stop, &msdata); + free_cpumask_var(stop_mask); + + return ret; +} + int stop_machine(cpu_stop_fn_t fn, void *data, const struct cpumask *cpus) { int ret; --=20 2.47.0