Module Name:    src
Committed By:   thorpej
Date:           Tue Sep 28 15:05:42 UTC 2021

Modified Files:
        src/sys/kern: kern_exec.c kern_lwp.c sys_futex.c
        src/sys/sys: futex.h

Log Message:
futex_release_all_lwp(): No need to pass the "tid" argument separately; that
is a vestige of an older version of the code.  Also, move a KASSERT() that
both futex_release_all_lwp() call sites had inside of futex_release_all_lwp()
itself.


To generate a diff of this commit:
cvs rdiff -u -r1.507 -r1.508 src/sys/kern/kern_exec.c
cvs rdiff -u -r1.243 -r1.244 src/sys/kern/kern_lwp.c
cvs rdiff -u -r1.12 -r1.13 src/sys/kern/sys_futex.c
cvs rdiff -u -r1.4 -r1.5 src/sys/sys/futex.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_exec.c
diff -u src/sys/kern/kern_exec.c:1.507 src/sys/kern/kern_exec.c:1.508
--- src/sys/kern/kern_exec.c:1.507	Tue Sep 28 14:52:22 2021
+++ src/sys/kern/kern_exec.c	Tue Sep 28 15:05:42 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_exec.c,v 1.507 2021/09/28 14:52:22 thorpej Exp $	*/
+/*	$NetBSD: kern_exec.c,v 1.508 2021/09/28 15:05:42 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2019, 2020 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.507 2021/09/28 14:52:22 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.508 2021/09/28 15:05:42 thorpej Exp $");
 
 #include "opt_exec.h"
 #include "opt_execfmt.h"
@@ -1211,8 +1211,7 @@ execve_runproc(struct lwp *l, struct exe
 	 * to dispose of.  Do that now.
 	 */
 	if (__predict_false(l->l_robust_head != 0)) {
-		KASSERT((l->l_lid & FUTEX_TID_MASK) == l->l_lid);
-		futex_release_all_lwp(l, l->l_lid);
+		futex_release_all_lwp(l);
 	}
 
 	/* Destroy any lwpctl info. */

Index: src/sys/kern/kern_lwp.c
diff -u src/sys/kern/kern_lwp.c:1.243 src/sys/kern/kern_lwp.c:1.244
--- src/sys/kern/kern_lwp.c:1.243	Wed Jan 13 07:36:56 2021
+++ src/sys/kern/kern_lwp.c	Tue Sep 28 15:05:42 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_lwp.c,v 1.243 2021/01/13 07:36:56 skrll Exp $	*/
+/*	$NetBSD: kern_lwp.c,v 1.244 2021/09/28 15:05:42 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008, 2009, 2019, 2020
@@ -217,7 +217,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.243 2021/01/13 07:36:56 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.244 2021/09/28 15:05:42 thorpej Exp $");
 
 #include "opt_ddb.h"
 #include "opt_lockdebug.h"
@@ -2060,11 +2060,8 @@ lwp_setprivate(struct lwp *l, void *ptr)
 void
 lwp_thread_cleanup(struct lwp *l)
 {
-	const lwpid_t tid = l->l_lid;
 
-	KASSERT((tid & FUTEX_TID_MASK) == tid);
 	KASSERT(mutex_owned(l->l_proc->p_lock));
-
 	mutex_exit(l->l_proc->p_lock);
 
 	/*
@@ -2072,7 +2069,7 @@ lwp_thread_cleanup(struct lwp *l)
 	 * now.
 	 */
 	if (__predict_false(l->l_robust_head != 0)) {
-		futex_release_all_lwp(l, tid);
+		futex_release_all_lwp(l);
 	}
 }
 

Index: src/sys/kern/sys_futex.c
diff -u src/sys/kern/sys_futex.c:1.12 src/sys/kern/sys_futex.c:1.13
--- src/sys/kern/sys_futex.c:1.12	Wed Jul 21 06:35:45 2021
+++ src/sys/kern/sys_futex.c	Tue Sep 28 15:05:42 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: sys_futex.c,v 1.12 2021/07/21 06:35:45 skrll Exp $	*/
+/*	$NetBSD: sys_futex.c,v 1.13 2021/09/28 15:05:42 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2018, 2019, 2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_futex.c,v 1.12 2021/07/21 06:35:45 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_futex.c,v 1.13 2021/09/28 15:05:42 thorpej Exp $");
 
 /*
  * Futexes
@@ -1966,7 +1966,7 @@ futex_fetch_robust_entry(uintptr_t const
  *	the i's and cross the t's.
  */
 void
-futex_release_all_lwp(struct lwp * const l, lwpid_t const tid)
+futex_release_all_lwp(struct lwp * const l)
 {
 	u_long rhead[_FUTEX_ROBUST_HEAD_NWORDS];
 	int limit = 1000000;
@@ -1976,13 +1976,15 @@ futex_release_all_lwp(struct lwp * const
 	if (l->l_robust_head == 0)
 		return;
 
+	KASSERT((l->l_lid & FUTEX_TID_MASK) == l->l_lid);
+
 	/* Read the final snapshot of the robust list head. */
 	error = futex_fetch_robust_head(l->l_robust_head, rhead);
 	if (error) {
-		printf("WARNING: pid %jd (%s) lwp %jd tid %jd:"
+		printf("WARNING: pid %jd (%s) lwp %jd:"
 		    " unmapped robust futex list head\n",
 		    (uintmax_t)l->l_proc->p_pid, l->l_proc->p_comm,
-		    (uintmax_t)l->l_lid, (uintmax_t)tid);
+		    (uintmax_t)l->l_lid);
 		return;
 	}
 
@@ -2004,21 +2006,21 @@ futex_release_all_lwp(struct lwp * const
 	while (next != l->l_robust_head && limit-- > 0) {
 		/* pending handled below. */
 		if (next != pending)
-			release_futex(next + offset, tid, is_pi, false);
+			release_futex(next + offset, l->l_lid, is_pi, false);
 		error = futex_fetch_robust_entry(next, &next, &is_pi);
 		if (error)
 			break;
 		preempt_point();
 	}
 	if (limit <= 0) {
-		printf("WARNING: pid %jd (%s) lwp %jd tid %jd:"
+		printf("WARNING: pid %jd (%s) lwp %jd:"
 		    " exhausted robust futex limit\n",
 		    (uintmax_t)l->l_proc->p_pid, l->l_proc->p_comm,
-		    (uintmax_t)l->l_lid, (uintmax_t)tid);
+		    (uintmax_t)l->l_lid);
 	}
 
 	/* If there's a pending futex, it may need to be released too. */
 	if (pending != 0) {
-		release_futex(pending + offset, tid, pending_is_pi, true);
+		release_futex(pending + offset, l->l_lid, pending_is_pi, true);
 	}
 }

Index: src/sys/sys/futex.h
diff -u src/sys/sys/futex.h:1.4 src/sys/sys/futex.h:1.5
--- src/sys/sys/futex.h:1.4	Tue May  5 15:25:18 2020
+++ src/sys/sys/futex.h	Tue Sep 28 15:05:42 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: futex.h,v 1.4 2020/05/05 15:25:18 riastradh Exp $	*/
+/*	$NetBSD: futex.h,v 1.5 2021/09/28 15:05:42 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2018, 2019 The NetBSD Foundation, Inc.
@@ -174,7 +174,7 @@ struct futex_robust_list_head {
 struct lwp;
 
 int	futex_robust_head_lookup(struct lwp *, lwpid_t, void **);
-void	futex_release_all_lwp(struct lwp *, lwpid_t);
+void	futex_release_all_lwp(struct lwp *);
 int	do_futex(int *, int, int, const struct timespec *, int *, int,
 	    int, register_t *);
 void	futex_sys_init(void);

Reply via email to