Files
kernel/kernel-rt/debian/patches/0003-affine-compute-kernel-threads.patch
Li Zhou 79e7b8794c kernel-rt: upgrade to 6.6.7
Update kernel source to 6.6.7 from linux-yocto upstream.
Update "debian" folder source to 6.1.27-1~bpo11+1 from debian upstream,
because kernel 6.6.7 is ported to our bullseye platform now and
the newest "debian" folder from debian upstream for bullseye platform
is for 6.1.

Add an optimization for the StarlingX debian kernel building framework:
We used to always maintain kernel with patches on "debian" folder
and they are put at kernel/kernel-std(rt)/debian/deb_patches dir.
Most of these patches are about "changelog" (debian/changelog) and
"config" (debian/config/amd64/none/config). The patches in "deb_patches"
dir increased rapidly.
Next We will put "changelog" and "config" at the dir
kernel/kernel-std(rt)/debian/source and use them to replace
debian/changelog and debian/config/amd64/none/config
after the upstream "debian" folder is extracted. This can not only
keep a clean "deb_patches" folder, but also avoid using a big patch to
remove the "changelog" file in the upstream "debian" folder before any
kernel build.

Below are changes about "deb_patches"/"patches" for kernel-rt:
(We use the patches' serial number in their name to represent them
becuase so many patches are involved here.)

(1)about "deb_patches" folder:

(1.1)Because of the optimization, all the patches about changelog
and config for 5.10 can be abandoned and they will be changed directly
in the files under "source" dir for 6.6.
Patches for 5.10 that are abandoned because they are about config:
0003/0005/0006/0007/0008/0010/0011/0016/0018/0022/0026/0028
Patches for 5.10 that are abandoned because they are about changelog:
0001/0002/0007/0013/0020/0023/0024/0025/0027/0029/0030/0032/0033/0034

The "changelog" and "config" under "source" dir for 6.6 are verified
to be aligned with those for 5.10 build.
CONFIG_FANOTIFY is enabled in "config" as a new request.

(1.2)Patch 0017 for 5.10 is abandoned because the new commit
<Use parallel XZ for source tar generation> is available in new
version "debian" folder, which does the same work.
Refer to: https://salsa.debian.org/kernel-team/linux/-/commit/
50b61a14e6dbc50b19dfe938c4679ecda50b83ee

(1.3)Below patches for 5.10 are ported to 6.6:
0004/0009/0015 (0009/0015 are merged into 0004) compose patch 0001
for 6.6;
0014 is ported to 0002 for 6.6;
0021 is ported to 0003 for 6.6;
0005/0019 (0005 is merged into 0019) compose patch 0004 for 6.6;
0012 is ported to 0005 for 6.6;
0031 is ported to 0006 for 6.6.

List the new patches for 6.6:
New patches 0001-0006 are ported from "deb_patches" for 5.10;
New patches 0007-0010 are added for building kernel 6.6.7 with
6.1.27-1~bpo11+1 "debian" folder.

(2)about "patches" folder:

(2.1)Patches for 5.10 that are abandoned because they are already in
6.6.7 include:
0017-0027/0031-0038/0041-0056/0058-0071/0073-0081/0083

(2.2)Patch 0011 for 5.10 is abandoned for new upstream commit
<scsi: smartpqi: Expose SAS address for SATA drives> in 6.6.
Refer to: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/
linux.git/commit/?id=00598b056aa6d46c7a6819efa850ec9d0d690d76
The new upstream commit has done what 0011 does.

(2.3)Patch 0039 for 5.10 is abandoned for new upstream commit
<samples/bpf: replace broken overhead microbenchmark with
fib_table_lookup> in 6.6.
Refer to: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/
linux.git/commit/?id=58e975d014e1e31bd1586be7d2be6d61bd3e3ada
0038 isn't needed any more with the new commit merged.

(2.4)Patch 0030 for 5.10 is abandoned because the related code has
been changed in 6.6 and the issue was verified to disappear.

(2.5)Patch 0010 for 5.10 is abandoned and the issue will be fixed by
setting /config/target/iscsi/cpus_allowed_list to be same with kernel
parameter "kthread_cpus". Because the new patch
<scsi: target: Add iscsi/cpus_allowed_list in configfs>
adds iscsi/cpus_allowed_list in configfs. The available CPU set of
iSCSI connection RX/TX threads is allowed_cpus & online_cpus.
This will do the same thing with patch 0010 so long as we set
cpus_allowed_list properly.
Refer to: <https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/
linux.git/commit/?id=d72d827f2f2636d8d72f0f3ebe5b661c9a24d343>
This issue will be addressed by later patches on stx framework part.

(2.6)Patch 0015-0016 are abandoned because the issue has been fixed
from the user space side by using the stable /dev/disk/by-path/...
symbolic links instead of names like /dev/sda that can change
(confirmed by M. Vefa Bicakci).

(2.7)Below patches for 5.10 are ported to 6.6:
0001-0009/0012/0028-0029/0040/0057/0082

(3)about kernel config:
(3.1) Enable CONFIG_GNSS for the ice driver.

Test plan:
 The out of tree kernel modules for 6.6 aren't ready by now.
 So many tests can't be done yet because the related test environments
 need those OOT drivers. Here list the tests which have been done with
 a test patch to remove the OOT drivers from the ISO temporarily.
 There are also 2 patches as workaround for solving 2 issues met when
 installing lab in jenkins job.
 PASS: Build linux/linux-rt OK.
 PASS: Build ISO OK.
 PASS: Install and boot up OK on a AIO-SX lab with std/rt kernel.
 PASS: The 12 hours cyclictest result for rt kernel is:
       samples:  259199998	avg:   1658	max:   5455
       99.9999th percentile: 3725	overflows: 0

Story: 2011000
Task: 49365

Signed-off-by: Li Zhou <li.zhou@windriver.com>
Change-Id: I6601fd2d7be4fc314ef2bc03b46f851eabebe3ea
(cherry picked from commit 06f53ed8e2)
Signed-off-by: Jiping Ma <jiping.ma2@windriver.com>
2024-07-09 23:59:50 +00:00

177 lines
6.9 KiB
Diff

From 004708f2e02a4ae97672d2c618effa7cdbbe38a6 Mon Sep 17 00:00:00 2001
From: Chris Friesen <chris.friesen@windriver.com>
Date: Tue, 24 Nov 2015 16:27:28 -0500
Subject: [PATCH] affine compute kernel threads
This is a kernel enhancement to configure the cpu affinity of kernel
threads via kernel boot option kthread_cpus=<cpulist>. The compute
kickstart file and compute-huge.sh scripts will update grub with the
new option.
With kthread_cpus specified, the cpumask is immediately applied upon
thread launch. This does not affect kernel threads that specify cpu
and node.
Note: this is based off of Christoph Lameter's patch at
https://lwn.net/Articles/565932/ with the only difference being
the kernel parameter changed from kthread to kthread_cpus.
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Chris Friesen <chris.friesen@windriver.com>
[VT: The existing "isolcpus"
kernel bootarg, cgroup/cpuset, and taskset might provide the some
way to have cpu isolation. However none of them satisfies the requirements.
Replacing spaces with tabs. Combine two calls of set_cpus_allowed_ptr()
in kernel_init_freeable() in init/main.c into one. Performed tests]
Signed-off-by: Vu Tran <vu.tran@windriver.com>
Signed-off-by: Jim Somerville <Jim.Somerville@windriver.com>
Signed-off-by: Zhang Zhiguo <zhangzhg@neusoft.com>
Signed-off-by: Vefa Bicakci <vefa.bicakci@windriver.com>
[jm: Adapted the patch for context changes.]
Signed-off-by: Jiping Ma <jiping.ma2@windriver.com>
[lz: Adapted the patch for upgrading kernel from 5.10 to 6.6]
Signed-off-by: Li Zhou <li.zhou@windriver.com>
---
.../admin-guide/kernel-parameters.txt | 10 ++++++++
include/linux/cpumask.h | 3 +++
init/main.c | 2 ++
kernel/cpu.c | 23 +++++++++++++++++++
kernel/kthread.c | 4 ++--
kernel/umh.c | 3 +++
6 files changed, 43 insertions(+), 2 deletions(-)
diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index 59f7b400d..acc7025c1 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -2473,6 +2473,16 @@
See also Documentation/trace/kprobetrace.rst "Kernel
Boot Parameter" section.
+ kthread_cpus= [KNL, SMP] Only run kernel threads on the specified
+ list of processors. The kernel will start threads
+ on the indicated processors only (unless there
+ are specific reasons to run a thread with
+ different affinities). This can be used to make
+ init start on certain processors and also to
+ control where kmod and other user space threads
+ are being spawned. Allows to keep kernel threads
+ away from certain cores unless absoluteluy necessary.
+
kpti= [ARM64] Control page table isolation of user
and kernel address spaces.
Default: enabled on cores which need mitigation.
diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
index c2aa0aa26..2919c2aef 100644
--- a/include/linux/cpumask.h
+++ b/include/linux/cpumask.h
@@ -61,6 +61,7 @@ static inline void set_nr_cpu_ids(unsigned int nr)
* cpu_present_mask - has bit 'cpu' set iff cpu is populated
* cpu_online_mask - has bit 'cpu' set iff cpu available to scheduler
* cpu_active_mask - has bit 'cpu' set iff cpu available to migration
+ * cpu_kthread_mask - has bit 'cpu' set iff general kernel threads allowed
*
* If !CONFIG_HOTPLUG_CPU, present == possible, and active == online.
*
@@ -93,11 +94,13 @@ extern struct cpumask __cpu_possible_mask;
extern struct cpumask __cpu_online_mask;
extern struct cpumask __cpu_present_mask;
extern struct cpumask __cpu_active_mask;
+extern struct cpumask __cpu_kthread_mask;
extern struct cpumask __cpu_dying_mask;
#define cpu_possible_mask ((const struct cpumask *)&__cpu_possible_mask)
#define cpu_online_mask ((const struct cpumask *)&__cpu_online_mask)
#define cpu_present_mask ((const struct cpumask *)&__cpu_present_mask)
#define cpu_active_mask ((const struct cpumask *)&__cpu_active_mask)
+#define cpu_kthread_mask ((const struct cpumask *)&__cpu_kthread_mask)
#define cpu_dying_mask ((const struct cpumask *)&__cpu_dying_mask)
extern atomic_t __num_online_cpus;
diff --git a/init/main.c b/init/main.c
index bd4ce7345..c40b2c441 100644
--- a/init/main.c
+++ b/init/main.c
@@ -1633,6 +1633,8 @@ static noinline void __init kernel_init_freeable(void)
do_basic_setup();
+ set_cpus_allowed_ptr(current, cpu_kthread_mask);
+
kunit_run_all_tests();
wait_for_initramfs();
diff --git a/kernel/cpu.c b/kernel/cpu.c
index 98a7a7b14..d051b4097 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -2651,6 +2651,29 @@ EXPORT_SYMBOL(__cpu_dying_mask);
atomic_t __num_online_cpus __read_mostly;
EXPORT_SYMBOL(__num_online_cpus);
+struct cpumask __cpu_kthread_mask __read_mostly
+ = {CPU_BITS_ALL};
+EXPORT_SYMBOL(__cpu_kthread_mask);
+
+static int __init kthread_setup(char *str)
+{
+ cpumask_var_t tmp_mask;
+ int err;
+
+ alloc_bootmem_cpumask_var(&tmp_mask);
+
+ err = cpulist_parse(str, tmp_mask);
+ if (!err)
+ cpumask_copy(&__cpu_kthread_mask, tmp_mask);
+ else
+ pr_err("Cannot parse 'kthread_cpus=%s'; error %d\n", str, err);
+
+ free_bootmem_cpumask_var(tmp_mask);
+
+ return 1;
+}
+__setup("kthread_cpus=", kthread_setup);
+
void init_cpu_present(const struct cpumask *src)
{
cpumask_copy(&__cpu_present_mask, src);
diff --git a/kernel/kthread.c b/kernel/kthread.c
index f97fd01a2..2bd5d136e 100644
--- a/kernel/kthread.c
+++ b/kernel/kthread.c
@@ -355,7 +355,7 @@ static int kthread(void *_create)
* back to default in case they have been changed.
*/
sched_setscheduler_nocheck(current, SCHED_NORMAL, &param);
- set_cpus_allowed_ptr(current, housekeeping_cpumask(HK_TYPE_KTHREAD));
+ set_cpus_allowed_ptr(current, cpu_kthread_mask);
/* OK, tell user we're spawned, wait for stop or wakeup */
__set_current_state(TASK_UNINTERRUPTIBLE);
@@ -722,7 +722,7 @@ int kthreadd(void *unused)
/* Setup a clean context for our children to inherit. */
set_task_comm(tsk, "kthreadd");
ignore_signals(tsk);
- set_cpus_allowed_ptr(tsk, housekeeping_cpumask(HK_TYPE_KTHREAD));
+ set_cpus_allowed_ptr(tsk, cpu_kthread_mask);
set_mems_allowed(node_states[N_MEMORY]);
current->flags |= PF_NOFREEZE;
diff --git a/kernel/umh.c b/kernel/umh.c
index fbf872c62..43e3f4567 100644
--- a/kernel/umh.c
+++ b/kernel/umh.c
@@ -82,6 +82,9 @@ static int call_usermodehelper_exec_async(void *data)
*/
current->fs->umask = 0022;
+ /* We can run only where init is allowed to run. */
+ set_cpus_allowed_ptr(current, cpu_kthread_mask);
+
/*
* Our parent (unbound workqueue) runs with elevated scheduling
* priority. Avoid propagating that into the userspace child.
--
2.17.1