From 143ee5ccb0784437710350558acf55938bb075ca Mon Sep 17 00:00:00 2001
From: hedmo <hedmoo@yahoo.com>
Date: Mon, 31 Aug 2020 16:30:19 +0200
Subject: [PATCH] sys-kernel/xanmod-sources-5.8.5 add
 Cachy-CPU-scheduler-v5.8.patch with useflag

---
 sys-kernel/xanmod-sources/Manifest            |  1 +
 .../xanmod-sources/files/Strong_Stack.patch   | 65 -------------------
 sys-kernel/xanmod-sources/metadata.xml        | 11 ++--
 .../xanmod-sources-5.8.5.ebuild               | 13 +++-
 4 files changed, 18 insertions(+), 72 deletions(-)
 delete mode 100644 sys-kernel/xanmod-sources/files/Strong_Stack.patch

diff --git a/sys-kernel/xanmod-sources/Manifest b/sys-kernel/xanmod-sources/Manifest
index eb6ba6d..fffa53a 100644
--- a/sys-kernel/xanmod-sources/Manifest
+++ b/sys-kernel/xanmod-sources/Manifest
@@ -1,3 +1,4 @@
+DIST 0001-sched-Introduce-the-Cachy-CPU-scheduler-v5.8.patch 287677 BLAKE2B ac74298043f43f74c780dd63e5abcf86294e831145c653eedd28a1b39959bdcfdbcdbee0071da47ad9e6bb6f837e04fbc0e93c232c82995731f957ce27d09361 SHA512 bdad88da6cf16722b0cd4f9c162ccdef83a2a92ee8767e35eb973b0c988dcd761146df5121e3202fdb68cfac03804dfa3ad44dc6fed50cb0794e0ea9fc389b90
 DIST linux-5.7.tar.xz 112690468 BLAKE2B b2b71e231507429b178b6b89be546c4a3ee2757f5d2c58b6137d383f16034a587225a75a9dbca6a01a433056ebe078487132c224e909a2971c9634687e47b1d1 SHA512 45bde01593f6147c8c169b9e46b4b56eee998142552ae0ff82f1dd21b1fd54f3b32f6283f6bd77ea717d374672167849e468c157f235d2f12f7d7816e4623bf6
 DIST linux-5.8.tar.xz 114459324 BLAKE2B 7bd97f8fa4527840754434414c07283e89731dc8ebb1e95fa5bc1469a60af1122582c0d3b6e262e77882f023190068df3537bd8b65964b3caa820bb2c8e579c7 SHA512 45a53ecf351096ef6e98242cca4228b8da9b9139ecc6963695791ea6fb7a9484a4e1c19dcca7ce7cbfdfa49de0451b70973bb078f12bdae9cbaddbc3f8092556
 DIST patch-5.7.12-xanmod1.xz 877072 BLAKE2B faabf0c524961dfb9edf8b8c3948520f08f0a86d76de8b097684247604b9ade43d90da467d8ae9e6a928a92bb41e944a64055641f0cd328264c889b51c222c53 SHA512 7866100c4361850c9a4802841d7698aea3c7ceaddaac659b324efca16459231d6cb5739481f024e1645d03239d5ebcd00dd1d1857ce654431d555aa94d89ab93
diff --git a/sys-kernel/xanmod-sources/files/Strong_Stack.patch b/sys-kernel/xanmod-sources/files/Strong_Stack.patch
deleted file mode 100644
index 07ad1ed..0000000
--- a/sys-kernel/xanmod-sources/files/Strong_Stack.patch
+++ /dev/null
@@ -1,65 +0,0 @@
-diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
-index 91e29b6..9804a79 100644
---- a/arch/x86/include/asm/stackprotector.h
-+++ b/arch/x86/include/asm/stackprotector.h
-@@ -55,8 +55,13 @@
- /*
-  * Initialize the stackprotector canary value.
-  *
-- * NOTE: this must only be called from functions that never return,
-+ * NOTE: this must only be called from functions that never return
-  * and it must always be inlined.
-+ *
-+ * In addition, it should be called from a compilation unit for which
-+ * stack protector is disabled. Alternatively, the caller should not end
-+ * with a function call which gets tail-call optimized as that would
-+ * lead to checking a modified canary value.
-  */
- static __always_inline void boot_init_stack_canary(void)
- {
-diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
-index fe3ab96..4f275ac 100644
---- a/arch/x86/kernel/smpboot.c
-+++ b/arch/x86/kernel/smpboot.c
-@@ -266,6 +266,14 @@ static void notrace start_secondary(void *unused)
- 
- 	wmb();
- 	cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
-+
-+	/*
-+	 * Prevent tail call to cpu_startup_entry() because the stack protector
-+	 * guard has been changed a couple of function calls up, in
-+	 * boot_init_stack_canary() and must not be checked before tail calling
-+	 * another function.
-+	 */
-+	prevent_tail_call_optimization();
- }
- 
- /**
-diff --git a/arch/x86/xen/smp_pv.c b/arch/x86/xen/smp_pv.c
-index 8fb8a50..f2adb63 100644
---- a/arch/x86/xen/smp_pv.c
-+++ b/arch/x86/xen/smp_pv.c
-@@ -93,6 +93,7 @@ asmlinkage __visible void cpu_bringup_and_idle(void)
- 	cpu_bringup();
- 	boot_init_stack_canary();
- 	cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
-+	prevent_tail_call_optimization();
- }
- 
- void xen_smp_intr_free_pv(unsigned int cpu)
-diff --git a/include/linux/compiler.h b/include/linux/compiler.h
-index 034b0a6..732754d 100644
---- a/include/linux/compiler.h
-+++ b/include/linux/compiler.h
-@@ -356,4 +356,10 @@ static inline void *offset_to_ptr(const int *off)
- /* &a[0] degrades to a pointer: a different type from an array */
- #define __must_be_array(a)	BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
- 
-+/*
-+ * This is needed in functions which generate the stack canary, see
-+ * arch/x86/kernel/smpboot.c::start_secondary() for an example.
-+ */
-+#define prevent_tail_call_optimization()	asm("")
-+
- #endif /* __LINUX_COMPILER_H */
diff --git a/sys-kernel/xanmod-sources/metadata.xml b/sys-kernel/xanmod-sources/metadata.xml
index f3f76f8..3f75cf2 100644
--- a/sys-kernel/xanmod-sources/metadata.xml
+++ b/sys-kernel/xanmod-sources/metadata.xml
@@ -1,7 +1,10 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
 <pkgmetadata>
-   <upstream>
-     <remote-id type="github">xanmod/linux</remote-id>
-   </upstream>
- </pkgmetadata>
+	<use>
+		<flag name="cachy">Enable cachy as a new cpu scheduler experimental patch.</flag>
+	</use>
+	<upstream>
+		<remote-id type="github">xanmod/linux</remote-id>
+	</upstream>
+</pkgmetadata>
diff --git a/sys-kernel/xanmod-sources/xanmod-sources-5.8.5.ebuild b/sys-kernel/xanmod-sources/xanmod-sources-5.8.5.ebuild
index 945d327..38288a3 100644
--- a/sys-kernel/xanmod-sources/xanmod-sources-5.8.5.ebuild
+++ b/sys-kernel/xanmod-sources/xanmod-sources-5.8.5.ebuild
@@ -12,15 +12,22 @@ detect_version
 DESCRIPTION="A general-purpose kernel with custom settings and new features"
 HOMEPAGE="https://xanmod.org"
 LICENSE+=" CDDL"
-SRC_URI="${KERNEL_BASE_URI}/linux-${KV_MAJOR}.${KV_MINOR}.tar.xz https://github.com/xanmod/linux/releases/download/${OKV}-xanmod${XANMOD_VERSION}/patch-${OKV}-xanmod${XANMOD_VERSION}.xz"
+KEYWORDS="~amd64"
+CACHY_URI="https://dl.xanmod.org/experimental/cachy_cpu_sched/0001-sched-Introduce-the-Cachy-CPU-scheduler-v5.8.patch"
+IUSE="cachy"
+SRC_URI="${KERNEL_BASE_URI}/linux-${KV_MAJOR}.${KV_MINOR}.tar.xz https://github.com/xanmod/linux/releases/download/${OKV}-xanmod${XANMOD_VERSION}/patch-${OKV}-xanmod${XANMOD_VERSION}.xz
+( ${CACHY_URI} )
+"
 
 UNIPATCH_LIST_DEFAULT=""
 UNIPATCH_LIST="${DISTDIR}/patch-${OKV}-xanmod${XANMOD_VERSION}.xz"
 
-KEYWORDS="~amd64"
-
 src_prepare() {
 
+	if use cachy; then
+		eapply "${DISTDIR}/0001-sched-Introduce-the-Cachy-CPU-scheduler-v5.8.patch"
+	fi
+
 	kernel-2-src-prepare-overlay_src_prepare
 
 	rm "${S}"/.config || die