aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMateusz Guzik <mjg@FreeBSD.org>2022-02-01 13:13:13 +0000
committerMateusz Guzik <mjg@FreeBSD.org>2022-02-11 11:44:07 +0000
commit32114b639fa1ad777312eebe14a9f677bd7be2ea (patch)
tree0a533fccf0aec1fa72a2aca2c59da4db905e5ddb
parent8a0cb04df4ff9902b17c9cb4b2e7413354fb630d (diff)
downloadsrc-32114b639fa1ad777312eebe14a9f677bd7be2ea.tar.gz
src-32114b639fa1ad777312eebe14a9f677bd7be2ea.zip
Add PROC_COW_CHANGECOUNT and thread_cow_synced
Combined they can be used to avoid a proc lock/unlock cycle in the syscall handler for curthread, see upcoming examples.
-rw-r--r--sys/kern/kern_thread.c13
-rw-r--r--sys/sys/proc.h9
2 files changed, 22 insertions, 0 deletions
diff --git a/sys/kern/kern_thread.c b/sys/kern/kern_thread.c
index dcb52b137b58..bb724a17803e 100644
--- a/sys/kern/kern_thread.c
+++ b/sys/kern/kern_thread.c
@@ -868,6 +868,19 @@ thread_cow_update(struct thread *td)
lim_free(oldlimit);
}
+void
+thread_cow_synced(struct thread *td)
+{
+ struct proc *p;
+
+ p = td->td_proc;
+ PROC_LOCK_ASSERT(p, MA_OWNED);
+ MPASS(td->td_cowgen != p->p_cowgen);
+ MPASS(td->td_ucred == p->p_ucred);
+ MPASS(td->td_limit == p->p_limit);
+ td->td_cowgen = p->p_cowgen;
+}
+
/*
* Discard the current thread and exit from its context.
* Always called with scheduler locked.
diff --git a/sys/sys/proc.h b/sys/sys/proc.h
index ff97bfbd54a9..0e33192303f4 100644
--- a/sys/sys/proc.h
+++ b/sys/sys/proc.h
@@ -1009,6 +1009,14 @@ extern pid_t pid_max;
(p)->p_cowgen++; \
} while (0)
+#define PROC_COW_CHANGECOUNT(td, p) ({ \
+ struct thread *_td = (td); \
+ struct proc *_p = (p); \
+ MPASS(_td == curthread); \
+ PROC_LOCK_ASSERT(_p, MA_OWNED); \
+ _p->p_cowgen - _td->td_cowgen; \
+})
+
/* Check whether a thread is safe to be swapped out. */
#define thread_safetoswapout(td) ((td)->td_flags & TDF_CANSWAP)
@@ -1200,6 +1208,7 @@ void thread_cow_get_proc(struct thread *newtd, struct proc *p);
void thread_cow_get(struct thread *newtd, struct thread *td);
void thread_cow_free(struct thread *td);
void thread_cow_update(struct thread *td);
+void thread_cow_synced(struct thread *td);
int thread_create(struct thread *td, struct rtprio *rtp,
int (*initialize_thread)(struct thread *, void *), void *thunk);
void thread_exit(void) __dead2;