Module Name:    src
Committed By:   riastradh
Date:           Sat Aug  1 02:05:45 UTC 2020

Modified Files:
        src/sys/kern: subr_pcu.c

Log Message:
Teach pcu(9) about LW_SYSTEM_FPU -- kthreads with fpu enabled.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/kern/subr_pcu.c

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/subr_pcu.c
diff -u src/sys/kern/subr_pcu.c:1.22 src/sys/kern/subr_pcu.c:1.23
--- src/sys/kern/subr_pcu.c:1.22	Sat Jun  6 18:13:01 2020
+++ src/sys/kern/subr_pcu.c	Sat Aug  1 02:05:45 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_pcu.c,v 1.22 2020/06/06 18:13:01 thorpej Exp $	*/
+/*	$NetBSD: subr_pcu.c,v 1.23 2020/08/01 02:05:45 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2011, 2014 The NetBSD Foundation, Inc.
@@ -52,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_pcu.c,v 1.22 2020/06/06 18:13:01 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_pcu.c,v 1.23 2020/08/01 02:05:45 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/cpu.h>
@@ -89,6 +89,17 @@ typedef struct {
 extern const pcu_ops_t * const pcu_ops_md_defs[];
 
 /*
+ * pcu_available_p: true if lwp is allowed to use PCU state.
+ */
+static inline bool
+pcu_available_p(struct lwp *l)
+{
+
+	/* XXX Not sure this is safe unless l is locked!  */
+	return (l->l_flag & (LW_SYSTEM|LW_SYSTEM_FPU)) != LW_SYSTEM;
+}
+
+/*
  * pcu_switchpoint: release PCU state if the LWP is being run on another CPU.
  * This routine is called on each context switch by by mi_switch().
  */
@@ -135,7 +146,7 @@ pcu_discard_all(lwp_t *l)
 	 * due to an error in the LWP creation path before it ever runs.
 	 */
 	KASSERT(l == curlwp || l->l_stat == LSIDL ||
-		((l->l_flag & LW_SYSTEM) && pcu_valid == 0));
+		(!pcu_available_p(l) && pcu_valid == 0));
 
 	if (__predict_true(pcu_valid == 0)) {
 		/* PCUs are not in use. */
@@ -174,7 +185,7 @@ pcu_save_all(lwp_t *l)
 	 * with a different LWP (forking a system LWP or doing a coredump of
 	 * a process with multiple threads) and we need to deal with that.
 	 */
-	KASSERT(l == curlwp || (((l->l_flag & LW_SYSTEM) ||
+	KASSERT(l == curlwp || ((!pcu_available_p(l) ||
 	    (curlwp->l_proc == l->l_proc && l->l_stat == LSSUSPENDED)) &&
 	    pcu_valid == 0));
 

Reply via email to