Skip to contentSkip to conversation

sched_pair_cpu: Introduce scheduler task pairing system call

RFC PATCH Superseded Mathieu Desnoyers 2 participants 6 messages Jun 15, 2020 – Jun 17, 2020

Subsystems (8)
x86 VFS MM core Scheduler +4 more subsystems

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 sched_pair_cpu: Introduce scheduler task pairing system call

There is an important use-case which is not possible with the "rseq" (Restartable Sequences) system call, which was left as future work.

That use-case is to modify user-space per-cpu data structures belonging to specific CPUs which may be brought offline and online again by CPU hotplug. This can be used by memory allocators to migrate free memory pools when CPUs are brought offline, or by ring buffer consumers to target specific per-CPU buffers, even when CPUs are brought offline.

A few rather complex prior attempts were made to solve this. Those were based on in-kernel interpreters (cpu_opv, do_on_cpu). That complexity was generally frowned upon, even by their author.

This patch fulfills this use-case in a simpler way: it introduces a "sched_pair_cpu" system call, which allows user-space threads to ask to run "as if" it was running on the runqueue of a specific CPU, but without being migrated to that cpu, until that pairing is cleared.

"But this can already be done with sched_setaffinity", some would rightfully reply. However, sched_setaffinity is not safe with respect to concurrent cpu hotplug and cpusets changes. This new "cpu pairing" concept addresses those limitations.

The key idea behind "sched_pair_cpu" is to let a worker thread eat CPU time on the target CPU while the user-space thread is provided access to user-space per-cpu data of that CPU, even though it is running on another CPU. If any of the thread or the worker thread are preempted, both get preempted.

For instance, this allows implementing this userspace library API for incrementing a per-cpu counter for a specific cpu number received as parameter:

static inline __attribute__((always_inline)) int percpu_addv(intptr_t *v, intptr_t count, int cpu)

{
        int ret;

        ret = rseq_addv(v, count, cpu);
check:
        if (rseq_unlikely(ret)) {
                sched_pair_cpu_set(cpu);
                ret = rseq_addv(v, count, percpu_current_cpu());
                sched_pair_cpu_clear();
                goto check;
        }
        return 0;
}
CC Thomas Gleixner <[email protected]>
CC Peter Zijlstra <[email protected]>
CC Joel Fernandes <[email protected]>
CC "H . Peter Anvin" <[email protected]>
CC Paul Turner <[email protected]>
CC Boqun Feng <[email protected]>
CC Steven Rostedt <[email protected]>
CC Andy Lutomirski <[email protected]>
CC "Paul E. McKenney" <[email protected]>
---
 arch/x86/entry/common.c                |   1 +
 arch/x86/entry/syscalls/syscall_32.tbl |   1 +
 arch/x86/entry/syscalls/syscall_64.tbl |   1 +
 fs/exec.c                              |   3 +
 include/linux/kthread.h                |  25 --
 include/linux/sched.h                  |  64 +++++
 include/linux/syscalls.h               |   1 +
 include/uapi/asm-generic/unistd.h      |   4 +-
 include/uapi/linux/sched.h             |   6 +
 init/init_task.c                       |   1 +
 kernel/fork.c                          |   1 +
 kernel/sched/core.c                    | 368 +++++++++++++++++++++++++
 kernel/sys_ni.c                        |   1 +
 13 files changed, 451 insertions(+), 26 deletions(-)
arch/x86/entry/common.c +1 -0
index 76735ec813e6..6bcdceba8e00 100644
@@ -164,6 +164,7 @@ static void exit_to_usermode_loop(struct pt_regs *regs, u32 cached_flags)
 			clear_thread_flag(TIF_NOTIFY_RESUME);
 			tracehook_notify_resume(regs);
 			rseq_handle_notify_resume(NULL, regs);
+			sched_pair_cpu_handle_notify_resume(NULL, regs);
 		}
 
 		if (cached_flags & _TIF_USER_RETURN_NOTIFY)
arch/x86/entry/syscalls/syscall_32.tbl +1 -0
index 54581ac671b4..334c24293555 100644
@@ -442,3 +442,4 @@
 435	i386	clone3			sys_clone3
 437	i386	openat2			sys_openat2
 438	i386	pidfd_getfd		sys_pidfd_getfd
+439	i386	sched_pair_cpu		sys_sched_pair_cpu
arch/x86/entry/syscalls/syscall_64.tbl +1 -0
index 37b844f839bc..6c8d19605a73 100644
@@ -359,6 +359,7 @@
 435	common	clone3			sys_clone3
 437	common	openat2			sys_openat2
 438	common	pidfd_getfd		sys_pidfd_getfd
+439	common	sched_pair_cpu		sys_sched_pair_cpu
 
 #
 # x32-specific system call numbers start at 512 to avoid cache impact
fs/exec.c +3 -0
index 2c465119affc..849fbd537d5c 100644
@@ -1886,6 +1886,9 @@ static int __do_execve_file(int fd, struct filename *filename,
 	current->fs->in_exec = 0;
 	current->in_execve = 0;
 	rseq_execve(current);
+#ifdef CONFIG_SMP
+	current->pair_cpu = -1;
+#endif
 	acct_update_integrals(current);
 	task_numa_free(current, false);
 	free_bprm(bprm);
include/linux/kthread.h +0 -25
index 8bbcaad7ef0f..78d5d693d4e7 100644
@@ -75,31 +75,6 @@ extern int tsk_fork_get_node(struct task_struct *tsk);
  * respectively.  Queued kthread_works are processed by a kthread
  * running kthread_worker_fn().
  */
-struct kthread_work;
-typedef void (*kthread_work_func_t)(struct kthread_work *work);
-void kthread_delayed_work_timer_fn(struct timer_list *t);
-
-enum {
-	KTW_FREEZABLE		= 1 << 0,	/* freeze during suspend */
-};
-
-struct kthread_worker {
-	unsigned int		flags;
-	raw_spinlock_t		lock;
-	struct list_head	work_list;
-	struct list_head	delayed_work_list;
-	struct task_struct	*task;
-	struct kthread_work	*current_work;
-};
-
-struct kthread_work {
-	struct list_head	node;
-	kthread_work_func_t	func;
-	struct kthread_worker	*worker;
-	/* Number of canceling calls that are running at the moment. */
-	int			canceling;
-};
-
 struct kthread_delayed_work {
 	struct kthread_work work;
 	struct timer_list timer;
include/linux/sched.h +64 -0

82 lines not on this page · raw message

include/linux/syscalls.h +1 -0
index 1815065d52f3..bdddabd7698d 100644
@@ -1003,6 +1003,7 @@ asmlinkage long sys_pidfd_send_signal(int pidfd, int sig,
 				       siginfo_t __user *info,
 				       unsigned int flags);
 asmlinkage long sys_pidfd_getfd(int pidfd, int fd, unsigned int flags);
+asmlinkage long sys_sched_pair_cpu(int cmd, int flags, int cpu);
 
 /*
  * Architecture-specific system calls
include/uapi/asm-generic/unistd.h +3 -1
index 3a3201e4618e..8e8baad77d48 100644
@@ -855,9 +855,11 @@ __SYSCALL(__NR_clone3, sys_clone3)
 __SYSCALL(__NR_openat2, sys_openat2)
 #define __NR_pidfd_getfd 438
 __SYSCALL(__NR_pidfd_getfd, sys_pidfd_getfd)
+#define __NR_sched_pair_cpu 439
+__SYSCALL(__NR_sched_pair_cpu, sys_sched_pair_cpu)
 
 #undef __NR_syscalls
-#define __NR_syscalls 439
+#define __NR_syscalls 440
 
 /*
  * 32 bit systems traditionally used different
include/uapi/linux/sched.h +6 -0
index 3bac0a8ceab2..0e2c413fb280 100644
@@ -145,4 +145,10 @@ struct clone_args {
 			 SCHED_FLAG_KEEP_ALL		| \
 			 SCHED_FLAG_UTIL_CLAMP)
 
+enum sched_pair_cpu_cmd {
+	SCHED_PAIR_CPU_CMD_QUERY			= 0,
+	SCHED_PAIR_CPU_CMD_SET				= (1 << 0),
+	SCHED_PAIR_CPU_CMD_CLEAR			= (1 << 1),
+};
+
 #endif /* _UAPI_LINUX_SCHED_H */
init/init_task.c +1 -0
index bd403ed3e418..ea589ccbd2ad 100644
@@ -89,6 +89,7 @@ struct task_struct init_task
 	.tasks		= LIST_HEAD_INIT(init_task.tasks),
 #ifdef CONFIG_SMP
 	.pushable_tasks	= PLIST_NODE_INIT(init_task.pushable_tasks, MAX_PRIO),
+	.pair_cpu	= -1,
 #endif
 #ifdef CONFIG_CGROUP_SCHED
 	.sched_task_group = &root_task_group,
kernel/fork.c +1 -0
index 48ed22774efa..eb6ee55eb9b2 100644
@@ -2225,6 +2225,7 @@ static __latent_entropy struct task_struct *copy_process(
 	copy_seccomp(p);
 
 	rseq_fork(p, clone_flags);
+	sched_pair_cpu_fork(p, clone_flags);
 
 	/* Don't start children in a dying pid namespace */
 	if (unlikely(!(ns_of_pid(pid)->pid_allocated & PIDNS_ADDING))) {
kernel/sched/core.c +368 -0

410 lines not on this page · raw message

kernel/sys_ni.c +1 -0
index 3b69a560a7ac..54dd5e7af53a 100644
@@ -472,3 +472,4 @@ COND_SYSCALL(setuid16);
 
 /* restartable sequence */
 COND_SYSCALL(rseq);
+COND_SYSCALL(sched_pair_cpu);
Signature · 1 line
2.17.1
#1 lore raw
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please…

Hi Mathieu,

[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on tip/x86/asm]
[also build test ERROR on tip/sched/core]
[cannot apply to linus/master linux/master v5.8-rc1 next-20200615] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Mathieu-Desnoyers/sched_pair_cpu-Introduce-scheduler-task-pairing-system-call/20200616-042458
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git 2ce0d7f9766f0e49bb54f149c77bae89464932fb
config: alpha-allyesconfig (attached as .config)
compiler: alpha-linux-gcc (GCC) 9.3.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=alpha

If you fix the issue, kindly add following tag as appropriate

All error/warnings (new ones prefixed by >>, old ones prefixed by <<):

kernel/sched/core.c:2246:6: warning: no previous prototype for 'sched_set_stop_task' [-Wmissing-prototypes] 2246 | void sched_set_stop_task(int cpu, struct task_struct *stop)
| ^~~~~~~~~~~~~~~~~~~
In file included from include/linux/printk.h:6,
from include/linux/kernel.h:15,
from include/asm-generic/bug.h:19,
from arch/alpha/include/asm/bug.h:23,
from include/linux/bug.h:5,
from include/linux/thread_info.h:12,
from include/asm-generic/current.h:5,
from ./arch/alpha/include/generated/asm/current.h:1,
from include/linux/sched.h:12,
from kernel/sched/sched.h:5,
from kernel/sched/core.c:9:

>> kernel/sched/core.c:8218:15: error: initialization of 'initcall_t' {aka 'int (*)(void)'} from incompatible pointer type 'void (*)(void)' [-Werror=incompatible-pointer-types]

8218 | late_initcall(pair_cpu_spawn_workers);
| ^~~~~~~~~~~~~~~~~~~~~~
include/linux/init.h:197:50: note: in definition of macro '___define_initcall'
197 | __attribute__((__section__(#__sec ".init"))) = fn;
| ^~
include/linux/init.h:231:28: note: in expansion of macro '__define_initcall' 231 | #define late_initcall(fn) __define_initcall(fn, 7)
| ^~~~~~~~~~~~~~~~~

>> kernel/sched/core.c:8218:1: note: in expansion of macro 'late_initcall'

8218 | late_initcall(pair_cpu_spawn_workers);
| ^~~~~~~~~~~~~
cc1: some warnings being treated as errors
--
<stdin>:1511:2: warning: #warning syscall clone3 not implemented [-Wcpp]

>> <stdin>:1520:2: warning: #warning syscall sched_pair_cpu not implemented [-Wcpp]
--
<stdin>:1511:2: warning: #warning syscall clone3 not implemented [-Wcpp]
>> <stdin>:1520:2: warning: #warning syscall sched_pair_cpu not implemented [-Wcpp]

--
arch/alpha/kernel/asm-offsets.c:15:6: warning: no previous prototype for 'foo' [-Wmissing-prototypes] 15 | void foo(void)
| ^~~
<stdin>:1511:2: warning: #warning syscall clone3 not implemented [-Wcpp]

>> <stdin>:1520:2: warning: #warning syscall sched_pair_cpu not implemented [-Wcpp]

vim +8218 kernel/sched/core.c

8217

> 8218	late_initcall(pair_cpu_spawn_workers);

8219

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#2 lore raw
In reply to Mathieu Desnoyers
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please…

Hi Mathieu,

[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on tip/x86/asm]
[also build test ERROR on tip/sched/core]
[cannot apply to linus/master linux/master v5.8-rc1 next-20200616] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Mathieu-Desnoyers/sched_pair_cpu-Introduce-scheduler-task-pairing-system-call/20200616-042458
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git 2ce0d7f9766f0e49bb54f149c77bae89464932fb
config: x86_64-allnoconfig (attached as .config)
compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project 487ca07fcc75d52755c9fe2ee05bcb3b6eeeec44)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>, old ones prefixed by <<):

In file included from arch/x86/kernel/asm-offsets.c:9:
In file included from include/linux/crypto.h:21:
In file included from include/linux/uaccess.h:5:

>> include/linux/sched.h:1913:15: error: no member named 'pair_cpu' in 'struct task_struct'

if (current->pair_cpu >= 0)
~~~~~~~ ^
include/linux/sched.h:1928:15: error: no member named 'pair_cpu' in 'struct task_struct' if (current->pair_cpu >= 0)
~~~~~~~ ^
include/linux/sched.h:1938:5: error: no member named 'pair_cpu' in 'struct task_struct' t->pair_cpu = -1;
~ ^

>> include/linux/sched.h:1939:5: error: no member named 'pair_cpu_need_worker' in 'struct task_struct'
t->pair_cpu_need_worker = 0;
~  ^
>> include/linux/sched.h:1940:5: error: no member named 'pair_cpu_worker_active' in 'struct task_struct'
t->pair_cpu_worker_active = 0;
~  ^
>> include/linux/sched.h:1941:5: error: no member named 'pair_cpu_queued_work' in 'struct task_struct'
t->pair_cpu_queued_work = 0;
~  ^
>> include/linux/sched.h:1942:13: error: no member named 'pair_cpu_work' in 'struct task_struct'

memset(&t->pair_cpu_work, 0, sizeof(t->pair_cpu_work));
~ ^
include/linux/sched.h:1942:41: error: no member named 'pair_cpu_work' in 'struct task_struct' memset(&t->pair_cpu_work, 0, sizeof(t->pair_cpu_work));
~ ^
In file included from arch/x86/kernel/asm-offsets.c:13:
In file included from include/linux/suspend.h:5:
In file included from include/linux/swap.h:9:
In file included from include/linux/memcontrol.h:13:
In file included from include/linux/cgroup.h:17:
In file included from include/linux/fs.h:34:
In file included from include/linux/percpu-rwsem.h:7:
In file included from include/linux/rcuwait.h:6:
In file included from include/linux/sched/signal.h:6:
include/linux/signal.h:87:11: warning: array index 3 is past the end of the array (which contains 1 element) [-Warray-bounds] return (set->sig[3] | set->sig[2] |
^ ~
arch/x86/include/asm/signal.h:24:2: note: array 'sig' declared here
unsigned long sig[_NSIG_WORDS];
^
In file included from arch/x86/kernel/asm-offsets.c:13:
In file included from include/linux/suspend.h:5:
In file included from include/linux/swap.h:9:
In file included from include/linux/memcontrol.h:13:
In file included from include/linux/cgroup.h:17:
In file included from include/linux/fs.h:34:
In file included from include/linux/percpu-rwsem.h:7:
In file included from include/linux/rcuwait.h:6:
In file included from include/linux/sched/signal.h:6:
include/linux/signal.h:87:25: warning: array index 2 is past the end of the array (which contains 1 element) [-Warray-bounds] return (set->sig[3] | set->sig[2] |
^ ~
arch/x86/include/asm/signal.h:24:2: note: array 'sig' declared here
unsigned long sig[_NSIG_WORDS];
^
In file included from arch/x86/kernel/asm-offsets.c:13:
In file included from include/linux/suspend.h:5:
In file included from include/linux/swap.h:9:
In file included from include/linux/memcontrol.h:13:
In file included from include/linux/cgroup.h:17:
In file included from include/linux/fs.h:34:
In file included from include/linux/percpu-rwsem.h:7:
In file included from include/linux/rcuwait.h:6:
In file included from include/linux/sched/signal.h:6:
include/linux/signal.h:88:4: warning: array index 1 is past the end of the array (which contains 1 element) [-Warray-bounds] set->sig[1] | set->sig[0]) == 0;
^ ~
arch/x86/include/asm/signal.h:24:2: note: array 'sig' declared here
unsigned long sig[_NSIG_WORDS];
^
In file included from arch/x86/kernel/asm-offsets.c:13:
In file included from include/linux/suspend.h:5:
In file included from include/linux/swap.h:9:
In file included from include/linux/memcontrol.h:13:
In file included from include/linux/cgroup.h:17:
In file included from include/linux/fs.h:34:
In file included from include/linux/percpu-rwsem.h:7:
In file included from include/linux/rcuwait.h:6:
In file included from include/linux/sched/signal.h:6:
include/linux/signal.h:90:11: warning: array index 1 is past the end of the array (which contains 1 element) [-Warray-bounds] return (set->sig[1] | set->sig[0]) == 0;
^ ~
arch/x86/include/asm/signal.h:24:2: note: array 'sig' declared here
unsigned long sig[_NSIG_WORDS];
^
In file included from arch/x86/kernel/asm-offsets.c:13:
In file included from include/linux/suspend.h:5:
In file included from include/linux/swap.h:9:
In file included from include/linux/memcontrol.h:13:
In file included from include/linux/cgroup.h:17:
In file included from include/linux/fs.h:34:
In file included from include/linux/percpu-rwsem.h:7:
In file included from include/linux/rcuwait.h:6:
In file included from include/linux/sched/signal.h:6:
include/linux/signal.h:103:11: warning: array index 3 is past the end of the array (which contains 1 element) [-Warray-bounds] return (set1->sig[3] == set2->sig[3]) &&
^ ~
arch/x86/include/asm/signal.h:24:2: note: array 'sig' declared here
unsigned long sig[_NSIG_WORDS];
^
In file included from arch/x86/kernel/asm-offsets.c:13:
In file included from include/linux/suspend.h:5:
In file included from include/linux/swap.h:9:
In file included from include/linux/memcontrol.h:13:
In file included from include/linux/cgroup.h:17:
In file included from include/linux/fs.h:34:
In file included from include/linux/percpu-rwsem.h:7:
In file included from include/linux/rcuwait.h:6:
In file included from include/linux/sched/signal.h:6:
include/linux/signal.h:103:27: warning: array index 3 is past the end of the array (which contains 1 element) [-Warray-bounds] return (set1->sig[3] == set2->sig[3]) &&
^ ~
arch/x86/include/asm/signal.h:24:2: note: array 'sig' declared here
unsigned long sig[_NSIG_WORDS];
^
In file included from arch/x86/kernel/asm-offsets.c:13:
In file included from include/linux/suspend.h:5:
In file included from include/linux/swap.h:9:
In file included from include/linux/memcontrol.h:13:
In file included from include/linux/cgroup.h:17:

vim +1913 include/linux/sched.h

1910
1911 static inline void sched_pair_cpu_set_notify_resume(struct task_struct *t)
1912 {

> 1913		if (current->pair_cpu >= 0)
  1914			set_tsk_thread_flag(t, TIF_NOTIFY_RESUME);
  1915	}
  1916	
  1917	static inline void sched_pair_cpu_preempt(struct task_struct *t)
  1918	{
  1919		sched_pair_cpu_set_notify_resume(t);
  1920	}
  1921	
  1922	void __sched_pair_cpu_handle_notify_resume(struct ksignal *sig,
  1923						   struct pt_regs *regs);
  1924	
  1925	static inline void sched_pair_cpu_handle_notify_resume(struct ksignal *ksig,
  1926							       struct pt_regs *regs)
  1927	{
  1928		if (current->pair_cpu >= 0)
  1929			__sched_pair_cpu_handle_notify_resume(ksig, regs);
  1930	}
  1931	
  1932	/*
  1933	 * Clear paired cpu on clone.
  1934	 */
  1935	static inline void sched_pair_cpu_fork(struct task_struct *t,
  1936					       unsigned long clone_flags)
  1937	{
  1938		t->pair_cpu = -1;
> 1939		t->pair_cpu_need_worker = 0;
> 1940		t->pair_cpu_worker_active = 0;
> 1941		t->pair_cpu_queued_work = 0;
> 1942		memset(&t->pair_cpu_work, 0, sizeof(t->pair_cpu_work));

1943 }
1944

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#3 lore raw
In reply to Mathieu Desnoyers
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please…

Hi Mathieu,

[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on tip/x86/asm]
[also build test WARNING on tip/sched/core]
[cannot apply to linus/master linux/master v5.8-rc1 next-20200616] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Mathieu-Desnoyers/sched_pair_cpu-Introduce-scheduler-task-pairing-system-call/20200616-042458
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git 2ce0d7f9766f0e49bb54f149c77bae89464932fb
config: nds32-randconfig-c023-20200615 (attached as .config)
compiler: nds32le-linux-gcc (GCC) 9.3.0

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>, old ones prefixed by <<):

In file included from include/linux/kernel.h:11,
from include/linux/list.h:9,
from include/linux/rculist.h:10,
from include/linux/pid.h:5,
from include/linux/sched.h:14,
from arch/nds32/kernel/asm-offsets.c:4:
include/linux/sched.h: In function 'sched_pair_cpu_set_notify_resume':
include/linux/sched.h:1913:13: error: 'struct task_struct' has no member named 'pair_cpu' 1913 | if (current->pair_cpu >= 0)
| ^~
include/linux/compiler.h:58:52: note: in definition of macro '__trace_if_var'
58 | #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
| ^~~~
<< from include/linux/sched.h:14,

>> include/linux/sched.h:1913:2: note: in expansion of macro 'if'

1913 | if (current->pair_cpu >= 0)
| ^~
include/linux/sched.h:1913:13: error: 'struct task_struct' has no member named 'pair_cpu' 1913 | if (current->pair_cpu >= 0)
| ^~
include/linux/compiler.h:58:61: note: in definition of macro '__trace_if_var'
58 | #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
| ^~~~
<< from include/linux/sched.h:14,

>> include/linux/sched.h:1913:2: note: in expansion of macro 'if'

1913 | if (current->pair_cpu >= 0)
| ^~
include/linux/sched.h:1913:13: error: 'struct task_struct' has no member named 'pair_cpu' 1913 | if (current->pair_cpu >= 0)
| ^~
include/linux/compiler.h:69:3: note: in definition of macro '__trace_if_value'
69 | (cond) ? | ^~~~
include/linux/compiler.h:56:28: note: in expansion of macro '__trace_if_var' 56 | #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
| ^~~~~~~~~~~~~~
<< from include/linux/sched.h:14,

>> include/linux/sched.h:1913:2: note: in expansion of macro 'if'

1913 | if (current->pair_cpu >= 0)
| ^~
include/linux/sched.h: In function 'sched_pair_cpu_handle_notify_resume':
include/linux/sched.h:1928:13: error: 'struct task_struct' has no member named 'pair_cpu' 1928 | if (current->pair_cpu >= 0)
| ^~
include/linux/compiler.h:58:52: note: in definition of macro '__trace_if_var'
58 | #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
| ^~~~
include/linux/sched.h:1928:2: note: in expansion of macro 'if'
1928 | if (current->pair_cpu >= 0)
| ^~
include/linux/sched.h:1928:13: error: 'struct task_struct' has no member named 'pair_cpu' 1928 | if (current->pair_cpu >= 0)
| ^~
include/linux/compiler.h:58:61: note: in definition of macro '__trace_if_var'
58 | #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
| ^~~~
include/linux/sched.h:1928:2: note: in expansion of macro 'if'
1928 | if (current->pair_cpu >= 0)
| ^~
include/linux/sched.h:1928:13: error: 'struct task_struct' has no member named 'pair_cpu' 1928 | if (current->pair_cpu >= 0)
| ^~
include/linux/compiler.h:69:3: note: in definition of macro '__trace_if_value'
69 | (cond) ? | ^~~~
include/linux/compiler.h:56:28: note: in expansion of macro '__trace_if_var'
56 | #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
| ^~~~~~~~~~~~~~
include/linux/sched.h:1928:2: note: in expansion of macro 'if'
1928 | if (current->pair_cpu >= 0)
| ^~
In file included from arch/nds32/kernel/asm-offsets.c:4:
include/linux/sched.h: In function 'sched_pair_cpu_fork':
include/linux/sched.h:1938:3: error: 'struct task_struct' has no member named 'pair_cpu' 1938 | t->pair_cpu = -1;
| ^~
include/linux/sched.h:1939:3: error: 'struct task_struct' has no member named 'pair_cpu_need_worker' 1939 | t->pair_cpu_need_worker = 0;
| ^~
include/linux/sched.h:1940:3: error: 'struct task_struct' has no member named 'pair_cpu_worker_active' 1940 | t->pair_cpu_worker_active = 0;
| ^~
include/linux/sched.h:1941:3: error: 'struct task_struct' has no member named 'pair_cpu_queued_work' 1941 | t->pair_cpu_queued_work = 0;
| ^~
include/linux/sched.h:1942:11: error: 'struct task_struct' has no member named 'pair_cpu_work' 1942 | memset(&t->pair_cpu_work, 0, sizeof(t->pair_cpu_work));
| ^~
include/linux/sched.h:1942:39: error: 'struct task_struct' has no member named 'pair_cpu_work' 1942 | memset(&t->pair_cpu_work, 0, sizeof(t->pair_cpu_work));
| ^~
make[2]: *** [scripts/Makefile.build:100: arch/nds32/kernel/asm-offsets.s] Error 1 make[2]: Target '__build' not remade because of errors.
make[1]: *** [Makefile:1141: prepare0] Error 2
make[1]: Target 'prepare' not remade because of errors.
make: *** [Makefile:180: sub-make] Error 2
make: Target 'prepare' not remade because of errors.

vim +/if +1913 include/linux/sched.h

1910
1911 static inline void sched_pair_cpu_set_notify_resume(struct task_struct *t)
1912 {

> 1913		if (current->pair_cpu >= 0)

1914 set_tsk_thread_flag(t, TIF_NOTIFY_RESUME);
1915 }
1916

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#4 lore raw
In reply to Mathieu Desnoyers
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please…

Hi Mathieu,

[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on tip/x86/asm]
[cannot apply to tip/sched/core linus/master linux/master v5.8-rc1 next-20200616] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Mathieu-Desnoyers/sched_pair_cpu-Introduce-scheduler-task-pairing-system-call/20200616-042458
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git 2ce0d7f9766f0e49bb54f149c77bae89464932fb
config: x86_64-randconfig-s022-20200615 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-13) 9.3.0
reproduce:
        # apt-get install sparse
        # sparse version: v0.6.2-rc1-3-g55607964-dirty
        # save the attached .config to linux build tree
        make W=1 C=1 ARCH=x86_64 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'

If you fix the issue, kindly add following tag as appropriate

sparse warnings: (new ones prefixed by >>)

>> kernel/sched/core.c:50:1: sparse: sparse: symbol '__pcpu_scope_pair_cpu' was not declared. Should it be static?

kernel/sched/core.c:260:48: sparse: sparse: incorrect type in argument 2 (different address spaces) @@ expected struct task_struct *p @@ got struct task_struct [noderef] <asn:4> *curr @@
kernel/sched/core.c:260:48: sparse: expected struct task_struct *p
kernel/sched/core.c:260:48: sparse: got struct task_struct [noderef] <asn:4> *curr
kernel/sched/core.c:518:38: sparse: sparse: incorrect type in initializer (different address spaces) @@ expected struct task_struct *curr @@ got struct task_struct [noderef] <asn:4> *curr @@
kernel/sched/core.c:518:38: sparse: expected struct task_struct *curr
kernel/sched/core.c:518:38: sparse: got struct task_struct [noderef] <asn:4> *curr
kernel/sched/core.c:573:9: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct sched_domain *[assigned] sd @@ got struct sched_domain [noderef] <asn:4> *parent @@
kernel/sched/core.c:573:9: sparse: expected struct sched_domain *[assigned] sd
kernel/sched/core.c:573:9: sparse: got struct sched_domain [noderef] <asn:4> *parent
kernel/sched/core.c:1450:33: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected struct task_struct *p @@ got struct task_struct [noderef] <asn:4> *curr @@
kernel/sched/core.c:1450:33: sparse: expected struct task_struct *p
kernel/sched/core.c:1450:33: sparse: got struct task_struct [noderef] <asn:4> *curr
kernel/sched/core.c:1450:68: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected struct task_struct *tsk @@ got struct task_struct [noderef] <asn:4> *curr @@
kernel/sched/core.c:1450:68: sparse: expected struct task_struct *tsk
kernel/sched/core.c:1450:68: sparse: got struct task_struct [noderef] <asn:4> *curr
kernel/sched/core.c:2305:17: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct sched_domain *[assigned] sd @@ got struct sched_domain [noderef] <asn:4> *parent @@
kernel/sched/core.c:2305:17: sparse: expected struct sched_domain *[assigned] sd
kernel/sched/core.c:2305:17: sparse: got struct sched_domain [noderef] <asn:4> *parent
kernel/sched/core.c:2490:36: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected struct task_struct const *p @@ got struct task_struct [noderef] <asn:4> *curr @@
kernel/sched/core.c:2490:36: sparse: expected struct task_struct const *p
kernel/sched/core.c:2490:36: sparse: got struct task_struct [noderef] <asn:4> *curr
kernel/sched/core.c:3799:38: sparse: sparse: incorrect type in initializer (different address spaces) @@ expected struct task_struct *curr @@ got struct task_struct [noderef] <asn:4> *curr @@
kernel/sched/core.c:3799:38: sparse: expected struct task_struct *curr
kernel/sched/core.c:3799:38: sparse: got struct task_struct [noderef] <asn:4> *curr
kernel/sched/core.c:4223:14: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct task_struct *prev @@ got struct task_struct [noderef] <asn:4> *curr @@
kernel/sched/core.c:4223:14: sparse: expected struct task_struct *prev
kernel/sched/core.c:4223:14: sparse: got struct task_struct [noderef] <asn:4> *curr
kernel/sched/core.c:4646:17: sparse: sparse: incompatible types in comparison expression (different address spaces):
kernel/sched/core.c:4646:17: sparse: struct task_struct *
kernel/sched/core.c:4646:17: sparse: struct task_struct [noderef] <asn:4> *
kernel/sched/core.c:4845:22: sparse: sparse: incompatible types in comparison expression (different address spaces):
kernel/sched/core.c:4845:22: sparse: struct task_struct [noderef] <asn:4> *
kernel/sched/core.c:4845:22: sparse: struct task_struct *
kernel/sched/core.c:8302:25: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected struct task_struct *p @@ got struct task_struct [noderef] <asn:4> *curr @@
kernel/sched/core.c:8302:25: sparse: expected struct task_struct *p
kernel/sched/core.c:8302:25: sparse: got struct task_struct [noderef] <asn:4> *curr
kernel/sched/pelt.h:80:13: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected struct task_struct const *p @@ got struct task_struct [noderef] <asn:4> *curr @@
kernel/sched/pelt.h:80:13: sparse: expected struct task_struct const *p
kernel/sched/pelt.h:80:13: sparse: got struct task_struct [noderef] <asn:4> *curr
kernel/sched/core.c:260:11: sparse: sparse: dereference of noderef expression kernel/sched/core.c:1433:33: sparse: sparse: dereference of noderef expression kernel/sched/core.c:1434:19: sparse: sparse: dereference of noderef expression kernel/sched/core.c:1437:40: sparse: sparse: dereference of noderef expression kernel/sched/sched.h:1664:25: sparse: sparse: incompatible types in comparison expression (different address spaces):
kernel/sched/sched.h:1664:25: sparse: struct task_struct [noderef] <asn:4> *
kernel/sched/sched.h:1664:25: sparse: struct task_struct *
kernel/sched/sched.h:1809:9: sparse: sparse: incompatible types in comparison expression (different address spaces):
kernel/sched/sched.h:1809:9: sparse: struct task_struct [noderef] <asn:4> *
kernel/sched/sched.h:1809:9: sparse: struct task_struct *
kernel/sched/sched.h:1815:9: sparse: sparse: incompatible types in comparison expression (different address spaces):
kernel/sched/sched.h:1815:9: sparse: struct task_struct [noderef] <asn:4> *
kernel/sched/sched.h:1815:9: sparse: struct task_struct *
kernel/sched/core.c:1406:38: sparse: sparse: incompatible types in comparison expression (different address spaces):
kernel/sched/core.c:1406:38: sparse: struct task_struct [noderef] <asn:4> *
kernel/sched/core.c:1406:38: sparse: struct task_struct const *
kernel/sched/sched.h:1664:25: sparse: sparse: incompatible types in comparison expression (different address spaces):
kernel/sched/sched.h:1664:25: sparse: struct task_struct [noderef] <asn:4> *
kernel/sched/sched.h:1664:25: sparse: struct task_struct *
kernel/sched/sched.h:1809:9: sparse: sparse: incompatible types in comparison expression (different address spaces):
kernel/sched/sched.h:1809:9: sparse: struct task_struct [noderef] <asn:4> *
kernel/sched/sched.h:1809:9: sparse: struct task_struct *
kernel/sched/sched.h:1809:9: sparse: sparse: incompatible types in comparison expression (different address spaces):
kernel/sched/sched.h:1809:9: sparse: struct task_struct [noderef] <asn:4> *
kernel/sched/sched.h:1809:9: sparse: struct task_struct *
kernel/sched/sched.h:1664:25: sparse: sparse: incompatible types in comparison expression (different address spaces):
kernel/sched/sched.h:1664:25: sparse: struct task_struct [noderef] <asn:4> *
kernel/sched/sched.h:1664:25: sparse: struct task_struct *
kernel/sched/sched.h:1809:9: sparse: sparse: incompatible types in comparison expression (different address spaces):
kernel/sched/sched.h:1809:9: sparse: struct task_struct [noderef] <asn:4> *
kernel/sched/sched.h:1809:9: sparse: struct task_struct *
kernel/sched/sched.h:1815:9: sparse: sparse: incompatible types in comparison expression (different address spaces):
kernel/sched/sched.h:1815:9: sparse: struct task_struct [noderef] <asn:4> *
kernel/sched/sched.h:1815:9: sparse: struct task_struct *
kernel/sched/sched.h:1664:25: sparse: sparse: incompatible types in comparison expression (different address spaces):
kernel/sched/sched.h:1664:25: sparse: struct task_struct [noderef] <asn:4> *
kernel/sched/sched.h:1664:25: sparse: struct task_struct *
kernel/sched/sched.h:1809:9: sparse: sparse: incompatible types in comparison expression (different address spaces):
kernel/sched/sched.h:1809:9: sparse: struct task_struct [noderef] <asn:4> *
kernel/sched/sched.h:1809:9: sparse: struct task_struct *
kernel/sched/sched.h:1815:9: sparse: sparse: incompatible types in comparison expression (different address spaces):
kernel/sched/sched.h:1815:9: sparse: struct task_struct [noderef] <asn:4> *
kernel/sched/sched.h:1815:9: sparse: struct task_struct *
kernel/sched/sched.h:1664:25: sparse: sparse: incompatible types in comparison expression (different address spaces):
kernel/sched/sched.h:1664:25: sparse: struct task_struct [noderef] <asn:4> *
kernel/sched/sched.h:1664:25: sparse: struct task_struct *
kernel/sched/sched.h:1809:9: sparse: sparse: incompatible types in comparison expression (different address spaces):
kernel/sched/sched.h:1809:9: sparse: struct task_struct [noderef] <asn:4> *
kernel/sched/sched.h:1809:9: sparse: struct task_struct *
kernel/sched/sched.h:1815:9: sparse: sparse: incompatible types in comparison expression (different address spaces):
kernel/sched/sched.h:1815:9: sparse: struct task_struct [noderef] <asn:4> *
kernel/sched/sched.h:1815:9: sparse: struct task_struct *

Please review and possibly fold the followup patch.

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#5 lore raw

[RFC PATCH] sched_pair_cpu: __pcpu_scope_pair_cpu can be static

In reply to Mathieu Desnoyers
Signed-off-by: kernel test robot <[email protected]>
---
 core.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/core.c +1 -1
index 36e429298a33e..eae0d2efc7410 100644
@@ -47,7 +47,7 @@ struct pair_cpu {
 	struct task_struct *running;
 };
 
-DEFINE_PER_CPU(struct pair_cpu, pair_cpu);
+static DEFINE_PER_CPU(struct pair_cpu, pair_cpu);
 static enum cpuhp_state pair_cpu_hp_online;
 
 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_JUMP_LABEL)