Module Name: src Committed By: thorpej Date: Wed Nov 3 14:49:21 UTC 2021
Modified Files: src/sys/kern [thorpej-futex2]: kern_lwp.c sys_futex.c src/sys/sys [thorpej-futex2]: futex.h Log Message: Cherry-pick this sys_futex.c revision and associated changes: revision 1.13 date: 2021-09-28 08:05:42 -0700; author: thorpej; state: Exp; lines: +11 -9; commitid: FPndTp2ZDjYuyJaD; 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. ...so make this easier to test this sys_futex.c with trunk. To generate a diff of this commit: cvs rdiff -u -r1.243 -r1.243.12.1 src/sys/kern/kern_lwp.c cvs rdiff -u -r1.12.4.6 -r1.12.4.7 src/sys/kern/sys_futex.c cvs rdiff -u -r1.4 -r1.4.14.1 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_lwp.c diff -u src/sys/kern/kern_lwp.c:1.243 src/sys/kern/kern_lwp.c:1.243.12.1 --- src/sys/kern/kern_lwp.c:1.243 Wed Jan 13 07:36:56 2021 +++ src/sys/kern/kern_lwp.c Wed Nov 3 14:49:21 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.243.12.1 2021/11/03 14:49:21 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.243.12.1 2021/11/03 14:49:21 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.4.6 src/sys/kern/sys_futex.c:1.12.4.7 --- src/sys/kern/sys_futex.c:1.12.4.6 Mon Nov 1 08:40:16 2021 +++ src/sys/kern/sys_futex.c Wed Nov 3 14:49:21 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: sys_futex.c,v 1.12.4.6 2021/11/01 08:40:16 chs Exp $ */ +/* $NetBSD: sys_futex.c,v 1.12.4.7 2021/11/03 14:49:21 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.4.6 2021/11/01 08:40:16 chs Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sys_futex.c,v 1.12.4.7 2021/11/03 14:49:21 thorpej Exp $"); /* * Futexes @@ -2199,7 +2199,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; @@ -2209,13 +2209,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; } @@ -2237,21 +2239,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.4.14.1 --- src/sys/sys/futex.h:1.4 Tue May 5 15:25:18 2020 +++ src/sys/sys/futex.h Wed Nov 3 14:49:21 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: futex.h,v 1.4 2020/05/05 15:25:18 riastradh Exp $ */ +/* $NetBSD: futex.h,v 1.4.14.1 2021/11/03 14:49:21 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);