Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 11 Nov 2017 11:01:50 +0000 (UTC)
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r325708 - in head/sys/compat/linuxkpi/common: include/linux src
Message-ID:  <201711111101.vABB1oXM057147@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: hselasky
Date: Sat Nov 11 11:01:50 2017
New Revision: 325708
URL: https://svnweb.freebsd.org/changeset/base/325708

Log:
  Remove release and acquire semantics when accessing the "state" field of the
  LinuxKPI task struct. Change type of "state" variable from "int" to
  "atomic_t" to simplify code and avoid unneccessary casting.
  
  MFC after:	1 week
  Sponsored by:	Mellanox Technologies

Modified:
  head/sys/compat/linuxkpi/common/include/linux/sched.h
  head/sys/compat/linuxkpi/common/src/linux_current.c
  head/sys/compat/linuxkpi/common/src/linux_schedule.c

Modified: head/sys/compat/linuxkpi/common/include/linux/sched.h
==============================================================================
--- head/sys/compat/linuxkpi/common/include/linux/sched.h	Sat Nov 11 10:46:12 2017	(r325707)
+++ head/sys/compat/linuxkpi/common/include/linux/sched.h	Sat Nov 11 11:01:50 2017	(r325708)
@@ -67,7 +67,7 @@ struct task_struct {
 	void   *task_data;
 	int	task_ret;
 	atomic_t usage;
-	int	state;
+	atomic_t state;
 	atomic_t kthread_flags;
 	pid_t	pid;	/* BSD thread ID */
 	const char    *comm;
@@ -92,9 +92,8 @@ struct task_struct {
 #define	put_pid(x)		do { } while (0)
 #define	current_euid()	(curthread->td_ucred->cr_uid)
 
-#define	set_task_state(task, x)		\
-	atomic_store_rel_int((volatile int *)&task->state, (x))
-#define	__set_task_state(task, x)	(task->state = (x))
+#define	set_task_state(task, x)		atomic_set(&(task)->state, (x))
+#define	__set_task_state(task, x)	((task)->state.counter = (x))
 #define	set_current_state(x)		set_task_state(current, x)
 #define	__set_current_state(x)		__set_task_state(current, x)
 

Modified: head/sys/compat/linuxkpi/common/src/linux_current.c
==============================================================================
--- head/sys/compat/linuxkpi/common/src/linux_current.c	Sat Nov 11 10:46:12 2017	(r325707)
+++ head/sys/compat/linuxkpi/common/src/linux_current.c	Sat Nov 11 11:01:50 2017	(r325708)
@@ -68,7 +68,7 @@ linux_alloc_current(struct thread *td, int flags)
 	ts->comm = td->td_name;
 	ts->pid = td->td_tid;
 	atomic_set(&ts->usage, 1);
-	ts->state = TASK_RUNNING;
+	atomic_set(&ts->state, TASK_RUNNING);
 	init_completion(&ts->parked);
 	init_completion(&ts->exited);
 

Modified: head/sys/compat/linuxkpi/common/src/linux_schedule.c
==============================================================================
--- head/sys/compat/linuxkpi/common/src/linux_schedule.c	Sat Nov 11 10:46:12 2017	(r325707)
+++ head/sys/compat/linuxkpi/common/src/linux_schedule.c	Sat Nov 11 11:01:50 2017	(r325708)
@@ -78,7 +78,7 @@ wake_up_task(struct task_struct *task, unsigned int st
 
 	ret = wakeup_swapper = 0;
 	sleepq_lock(task);
-	if ((atomic_load_acq_int(&task->state) & state) != 0) {
+	if ((atomic_read(&task->state) & state) != 0) {
 		set_task_state(task, TASK_WAKING);
 		wakeup_swapper = sleepq_signal(task, SLEEPQ_SLEEP, 0, 0);
 		ret = 1;
@@ -234,7 +234,7 @@ linux_wait_event_common(wait_queue_head_t *wqh, wait_q
 	 */
 	PHOLD(task->task_thread->td_proc);
 	sleepq_lock(task);
-	if (atomic_load_acq_int(&task->state) != TASK_WAKING) {
+	if (atomic_read(&task->state) != TASK_WAKING) {
 		ret = linux_add_to_sleepqueue(task, "wevent", timeout, state);
 	} else {
 		sleepq_release(task);
@@ -269,7 +269,7 @@ linux_schedule_timeout(int timeout)
 	DROP_GIANT();
 
 	sleepq_lock(task);
-	state = atomic_load_acq_int(&task->state);
+	state = atomic_read(&task->state);
 	if (state != TASK_WAKING)
 		(void)linux_add_to_sleepqueue(task, "sched", timeout, state);
 	else



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201711111101.vABB1oXM057147>