summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authormpi <mpi@openbsd.org>2019-05-31 19:51:09 +0000
committermpi <mpi@openbsd.org>2019-05-31 19:51:09 +0000
commit4b91b74a18bc983f4cced5ae0e1d3b81f991786d (patch)
tree29d70291869a15eda0161c68981def08ec425f62 /sys
parentRe-enable frame pointer elimination for x86 and mips64 if optimizations are (diff)
downloadwireguard-openbsd-4b91b74a18bc983f4cced5ae0e1d3b81f991786d.tar.xz
wireguard-openbsd-4b91b74a18bc983f4cced5ae0e1d3b81f991786d.zip
Use a per-process mutex to protect time accounting instead of SCHED_LOCK().
Note that hardclock(9) still increments p_{u,s,i}ticks without holding a lock. ok visa@, cheloha@
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/init_main.c4
-rw-r--r--sys/kern/kern_acct.c4
-rw-r--r--sys/kern/kern_exec.c4
-rw-r--r--sys/kern/kern_exit.c6
-rw-r--r--sys/kern/kern_fork.c5
-rw-r--r--sys/kern/kern_resource.c55
-rw-r--r--sys/kern/kern_sched.c6
-rw-r--r--sys/kern/kern_sysctl.c4
-rw-r--r--sys/kern/kern_time.c14
-rw-r--r--sys/kern/sched_bsd.c6
-rw-r--r--sys/kern/tty.c4
-rw-r--r--sys/sys/proc.h26
-rw-r--r--sys/sys/resourcevar.h5
-rw-r--r--sys/sys/sysctl.h12
14 files changed, 101 insertions, 54 deletions
diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c
index 22a510c1f0d..0a4af1b1399 100644
--- a/sys/kern/init_main.c
+++ b/sys/kern/init_main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: init_main.c,v 1.285 2019/05/31 04:46:18 visa Exp $ */
+/* $OpenBSD: init_main.c,v 1.286 2019/05/31 19:51:09 mpi Exp $ */
/* $NetBSD: init_main.c,v 1.84.4.1 1996/06/02 09:08:06 mrg Exp $ */
/*
@@ -518,7 +518,9 @@ main(void *framep)
getnanotime(&pr->ps_start);
TAILQ_FOREACH(p, &pr->ps_threads, p_thr_link) {
nanouptime(&p->p_cpu->ci_schedstate.spc_runtime);
+ mtx_enter(&pr->ps_mtx);
timespecclear(&p->p_rtime);
+ mtx_leave(&pr->ps_mtx);
}
}
diff --git a/sys/kern/kern_acct.c b/sys/kern/kern_acct.c
index 3ce6831734d..862f94b19a6 100644
--- a/sys/kern/kern_acct.c
+++ b/sys/kern/kern_acct.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_acct.c,v 1.36 2018/04/28 03:13:04 visa Exp $ */
+/* $OpenBSD: kern_acct.c,v 1.37 2019/05/31 19:51:09 mpi Exp $ */
/* $NetBSD: kern_acct.c,v 1.42 1996/02/04 02:15:12 christos Exp $ */
/*-
@@ -179,7 +179,9 @@ acct_process(struct proc *p)
memcpy(acct.ac_comm, pr->ps_comm, sizeof acct.ac_comm);
/* (2) The amount of user and system time that was used */
+ mtx_enter(&pr->ps_mtx);
calctsru(&pr->ps_tu, &ut, &st, NULL);
+ mtx_leave(&pr->ps_mtx);
acct.ac_utime = encode_comp_t(ut.tv_sec, ut.tv_nsec);
acct.ac_stime = encode_comp_t(st.tv_sec, st.tv_nsec);
diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c
index 88d3b1b47f7..b732e48a167 100644
--- a/sys/kern/kern_exec.c
+++ b/sys/kern/kern_exec.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_exec.c,v 1.203 2019/02/08 12:51:57 bluhm Exp $ */
+/* $OpenBSD: kern_exec.c,v 1.204 2019/05/31 19:51:09 mpi Exp $ */
/* $NetBSD: kern_exec.c,v 1.75 1996/02/09 18:59:28 christos Exp $ */
/*-
@@ -661,8 +661,10 @@ sys_execve(struct proc *p, void *v, register_t *retval)
}
/* reset CPU time usage for the thread, but not the process */
+ mtx_enter(&pr->ps_mtx);
timespecclear(&p->p_tu.tu_runtime);
p->p_tu.tu_uticks = p->p_tu.tu_sticks = p->p_tu.tu_iticks = 0;
+ mtx_leave(&pr->ps_mtx);
km_free(argp, NCARGS, &kv_exec, &kp_pageable);
diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c
index bff9a2c5ef7..1c9a522ba14 100644
--- a/sys/kern/kern_exit.c
+++ b/sys/kern/kern_exit.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_exit.c,v 1.174 2019/05/13 19:21:31 bluhm Exp $ */
+/* $OpenBSD: kern_exit.c,v 1.175 2019/05/31 19:51:09 mpi Exp $ */
/* $NetBSD: kern_exit.c,v 1.39 1996/04/22 01:38:25 christos Exp $ */
/*
@@ -284,7 +284,7 @@ exit1(struct proc *p, int rv, int flags)
/* add thread's accumulated rusage into the process's total */
ruadd(rup, &p->p_ru);
- tuagg(pr, p);
+ tuagg(p, NULL);
/*
* clear %cpu usage during swap
@@ -296,7 +296,9 @@ exit1(struct proc *p, int rv, int flags)
* Final thread has died, so add on our children's rusage
* and calculate the total times
*/
+ mtx_enter(&pr->ps_mtx);
calcru(&pr->ps_tu, &rup->ru_utime, &rup->ru_stime, NULL);
+ mtx_leave(&pr->ps_mtx);
ruadd(rup, &pr->ps_cru);
/* notify interested parties of our demise and clean up */
diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c
index 0d7f58bf890..4bf393afb84 100644
--- a/sys/kern/kern_fork.c
+++ b/sys/kern/kern_fork.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_fork.c,v 1.210 2019/05/31 04:46:18 visa Exp $ */
+/* $OpenBSD: kern_fork.c,v 1.211 2019/05/31 19:51:09 mpi Exp $ */
/* $NetBSD: kern_fork.c,v 1.29 1996/02/09 18:59:34 christos Exp $ */
/*
@@ -55,6 +55,7 @@
#include <sys/sysctl.h>
#include <sys/pool.h>
#include <sys/mman.h>
+#include <sys/mutex.h>
#include <sys/ptrace.h>
#include <sys/atomic.h>
#include <sys/pledge.h>
@@ -210,6 +211,8 @@ process_initialize(struct process *pr, struct proc *p)
LIST_INIT(&pr->ps_kqlist);
LIST_INIT(&pr->ps_sigiolst);
+ mtx_init(&pr->ps_mtx, IPL_MPFLOOR);
+
timeout_set(&pr->ps_realit_to, realitexpire, pr);
timeout_set(&pr->ps_rucheck_to, rucheck, pr);
}
diff --git a/sys/kern/kern_resource.c b/sys/kern/kern_resource.c
index ffe560d7e38..4e972683eb7 100644
--- a/sys/kern/kern_resource.c
+++ b/sys/kern/kern_resource.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_resource.c,v 1.60 2019/05/31 04:46:18 visa Exp $ */
+/* $OpenBSD: kern_resource.c,v 1.61 2019/05/31 19:51:09 mpi Exp $ */
/* $NetBSD: kern_resource.c,v 1.38 1996/10/23 07:19:38 matthias Exp $ */
/*-
@@ -47,13 +47,13 @@
#include <sys/ktrace.h>
#include <sys/sched.h>
#include <sys/signalvar.h>
-
+#include <sys/mutex.h>
#include <sys/mount.h>
#include <sys/syscallargs.h>
#include <uvm/uvm_extern.h>
-void tuagg_sub(struct tusage *, struct proc *);
+void tuagg_sub(struct tusage *, struct tusage *);
/*
* Patchable maximum data and stack limits.
@@ -338,12 +338,12 @@ sys_getrlimit(struct proc *p, void *v, register_t *retval)
}
void
-tuagg_sub(struct tusage *tup, struct proc *p)
+tuagg_sub(struct tusage *ttup, struct tusage *ftup)
{
- timespecadd(&tup->tu_runtime, &p->p_rtime, &tup->tu_runtime);
- tup->tu_uticks += p->p_uticks;
- tup->tu_sticks += p->p_sticks;
- tup->tu_iticks += p->p_iticks;
+ timespecadd(&ttup->tu_runtime, &ftup->tu_runtime, &ttup->tu_runtime);
+ ttup->tu_uticks += ftup->tu_uticks;
+ ttup->tu_sticks += ftup->tu_sticks;
+ ttup->tu_iticks += ftup->tu_iticks;
}
/*
@@ -351,24 +351,26 @@ tuagg_sub(struct tusage *tup, struct proc *p)
* totals for the thread and process
*/
void
-tuagg_unlocked(struct process *pr, struct proc *p)
+tuagg(struct proc *p, struct timespec *tsp)
{
- tuagg_sub(&pr->ps_tu, p);
- tuagg_sub(&p->p_tu, p);
- timespecclear(&p->p_rtime);
+ struct process *pr = p->p_p;
+ struct tusage tu;
+
+ mtx_enter(&pr->ps_mtx);
+ tu.tu_uticks = p->p_uticks;
+ tu.tu_sticks = p->p_sticks;
+ tu.tu_iticks = p->p_iticks;
p->p_uticks = 0;
p->p_sticks = 0;
p->p_iticks = 0;
-}
-
-void
-tuagg(struct process *pr, struct proc *p)
-{
- int s;
+ if (tsp != NULL)
+ timespecadd(&p->p_rtime, tsp, &p->p_rtime);
+ tu.tu_runtime = p->p_rtime;
+ timespecclear(&p->p_rtime);
+ tuagg_sub(&pr->ps_tu, &tu);
+ tuagg_sub(&p->p_tu, &tu);
+ mtx_leave(&pr->ps_mtx);
- SCHED_LOCK(s);
- tuagg_unlocked(pr, p);
- SCHED_UNLOCK(s);
}
/*
@@ -461,15 +463,19 @@ dogetrusage(struct proc *p, int who, struct rusage *rup)
/* add on all living threads */
TAILQ_FOREACH(q, &pr->ps_threads, p_thr_link) {
ruadd(rup, &q->p_ru);
- tuagg(pr, q);
+ tuagg(q, NULL);
}
+ mtx_enter(&pr->ps_mtx);
calcru(&pr->ps_tu, &rup->ru_utime, &rup->ru_stime, NULL);
+ mtx_leave(&pr->ps_mtx);
break;
case RUSAGE_THREAD:
*rup = p->p_ru;
+ mtx_enter(&pr->ps_mtx);
calcru(&p->p_tu, &rup->ru_utime, &rup->ru_stime, NULL);
+ mtx_leave(&pr->ps_mtx);
break;
case RUSAGE_CHILDREN:
@@ -507,13 +513,12 @@ rucheck(void *arg)
struct process *pr = arg;
struct rlimit *rlim;
rlim_t runtime;
- int s;
KERNEL_ASSERT_LOCKED();
- SCHED_LOCK(s);
+ mtx_enter(&pr->ps_mtx);
runtime = pr->ps_tu.tu_runtime.tv_sec;
- SCHED_UNLOCK(s);
+ mtx_leave(&pr->ps_mtx);
rlim = &pr->ps_limit->pl_rlimit[RLIMIT_CPU];
if (runtime >= rlim->rlim_cur) {
diff --git a/sys/kern/kern_sched.c b/sys/kern/kern_sched.c
index 3eec06330ec..346c719d13b 100644
--- a/sys/kern/kern_sched.c
+++ b/sys/kern/kern_sched.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_sched.c,v 1.56 2019/03/26 04:24:22 visa Exp $ */
+/* $OpenBSD: kern_sched.c,v 1.57 2019/05/31 19:51:09 mpi Exp $ */
/*
* Copyright (c) 2007, 2008 Artur Grabowski <art@openbsd.org>
*
@@ -212,13 +212,17 @@ void
sched_exit(struct proc *p)
{
struct schedstate_percpu *spc = &curcpu()->ci_schedstate;
+ struct process *pr = p->p_p;
struct timespec ts;
struct proc *idle;
int s;
nanouptime(&ts);
timespecsub(&ts, &spc->spc_runtime, &ts);
+
+ mtx_enter(&pr->ps_mtx);
timespecadd(&p->p_rtime, &ts, &p->p_rtime);
+ mtx_leave(&pr->ps_mtx);
LIST_INSERT_HEAD(&spc->spc_deadproc, p, p_hash);
diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c
index 82f26655caf..adb4f166533 100644
--- a/sys/kern/kern_sysctl.c
+++ b/sys/kern/kern_sysctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_sysctl.c,v 1.356 2019/05/22 18:45:07 claudio Exp $ */
+/* $OpenBSD: kern_sysctl.c,v 1.357 2019/05/31 19:51:09 mpi Exp $ */
/* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */
/*-
@@ -1645,7 +1645,9 @@ fill_kproc(struct process *pr, struct kinfo_proc *ki, struct proc *p,
if ((pr->ps_flags & PS_ZOMBIE) == 0) {
if ((pr->ps_flags & PS_EMBRYO) == 0 && vm != NULL)
ki->p_vm_rssize = vm_resident_count(vm);
+ mtx_enter(&pr->ps_mtx);
calctsru(isthread ? &p->p_tu : &pr->ps_tu, &ut, &st, NULL);
+ mtx_leave(&pr->ps_mtx);
ki->p_uutime_sec = ut.tv_sec;
ki->p_uutime_usec = ut.tv_nsec/1000;
ki->p_ustime_sec = st.tv_sec;
diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c
index 730f489d582..42a7fb369c5 100644
--- a/sys/kern/kern_time.c
+++ b/sys/kern/kern_time.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_time.c,v 1.116 2019/05/21 08:30:35 stsp Exp $ */
+/* $OpenBSD: kern_time.c,v 1.117 2019/05/31 19:51:10 mpi Exp $ */
/* $NetBSD: kern_time.c,v 1.20 1996/02/18 11:57:06 fvdl Exp $ */
/*
@@ -106,6 +106,7 @@ settime(const struct timespec *ts)
int
clock_gettime(struct proc *p, clockid_t clock_id, struct timespec *tp)
{
+ struct process *pr = p->p_p;
struct bintime bt;
struct proc *q;
int error = 0;
@@ -126,14 +127,18 @@ clock_gettime(struct proc *p, clockid_t clock_id, struct timespec *tp)
case CLOCK_PROCESS_CPUTIME_ID:
nanouptime(tp);
timespecsub(tp, &curcpu()->ci_schedstate.spc_runtime, tp);
- timespecadd(tp, &p->p_p->ps_tu.tu_runtime, tp);
+ mtx_enter(&pr->ps_mtx);
+ timespecadd(tp, &pr->ps_tu.tu_runtime, tp);
timespecadd(tp, &p->p_rtime, tp);
+ mtx_leave(&pr->ps_mtx);
break;
case CLOCK_THREAD_CPUTIME_ID:
nanouptime(tp);
timespecsub(tp, &curcpu()->ci_schedstate.spc_runtime, tp);
+ mtx_enter(&pr->ps_mtx);
timespecadd(tp, &p->p_tu.tu_runtime, tp);
timespecadd(tp, &p->p_rtime, tp);
+ mtx_leave(&pr->ps_mtx);
break;
default:
/* check for clock from pthread_getcpuclockid() */
@@ -142,8 +147,11 @@ clock_gettime(struct proc *p, clockid_t clock_id, struct timespec *tp)
q = tfind(__CLOCK_PTID(clock_id) - THREAD_PID_OFFSET);
if (q == NULL || q->p_p != p->p_p)
error = ESRCH;
- else
+ else {
+ mtx_enter(&pr->ps_mtx);
*tp = q->p_tu.tu_runtime;
+ mtx_leave(&pr->ps_mtx);
+ }
KERNEL_UNLOCK();
} else
error = EINVAL;
diff --git a/sys/kern/sched_bsd.c b/sys/kern/sched_bsd.c
index 95c3bc23ef0..1cb5c91ce38 100644
--- a/sys/kern/sched_bsd.c
+++ b/sys/kern/sched_bsd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sched_bsd.c,v 1.51 2019/05/25 18:11:10 mpi Exp $ */
+/* $OpenBSD: sched_bsd.c,v 1.52 2019/05/31 19:51:10 mpi Exp $ */
/* $NetBSD: kern_synch.c,v 1.37 1996/04/22 01:38:37 christos Exp $ */
/*-
@@ -343,7 +343,6 @@ mi_switch(void)
struct schedstate_percpu *spc = &curcpu()->ci_schedstate;
struct proc *p = curproc;
struct proc *nextproc;
- struct process *pr = p->p_p;
struct timespec ts;
#ifdef MULTIPROCESSOR
int hold_count;
@@ -381,11 +380,10 @@ mi_switch(void)
#endif
} else {
timespecsub(&ts, &spc->spc_runtime, &ts);
- timespecadd(&p->p_rtime, &ts, &p->p_rtime);
}
/* add the time counts for this thread to the process's total */
- tuagg_unlocked(pr, p);
+ tuagg(p, &ts);
/*
* Process is about to yield the CPU; clear the appropriate
diff --git a/sys/kern/tty.c b/sys/kern/tty.c
index fd54b0fca75..5c4366e66a5 100644
--- a/sys/kern/tty.c
+++ b/sys/kern/tty.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tty.c,v 1.144 2019/05/13 19:21:31 bluhm Exp $ */
+/* $OpenBSD: tty.c,v 1.145 2019/05/31 19:51:10 mpi Exp $ */
/* $NetBSD: tty.c,v 1.68.4.2 1996/06/06 16:04:52 thorpej Exp $ */
/*-
@@ -2191,7 +2191,9 @@ update_pickpr:
rss = (pickpr->ps_flags & (PS_EMBRYO | PS_ZOMBIE)) ? 0 :
vm_resident_count(pickpr->ps_vmspace);
+ mtx_enter(&pickpr->ps_mtx);
calctsru(&pickpr->ps_tu, &utime, &stime, NULL);
+ mtx_leave(&pickpr->ps_mtx);
/* Round up and print user time. */
utime.tv_nsec += 5000000;
diff --git a/sys/sys/proc.h b/sys/sys/proc.h
index 1886a7d3826..dd2ea7c45cc 100644
--- a/sys/sys/proc.h
+++ b/sys/sys/proc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: proc.h,v 1.265 2019/05/13 19:21:31 bluhm Exp $ */
+/* $OpenBSD: proc.h,v 1.266 2019/05/31 19:51:10 mpi Exp $ */
/* $NetBSD: proc.h,v 1.44 1996/04/22 01:23:21 christos Exp $ */
/*-
@@ -154,6 +154,11 @@ RBT_HEAD(unvname_rbt, unvname);
struct futex;
LIST_HEAD(futex_list, futex);
struct unveil;
+
+/*
+ * Locks used to protect struct members in this file:
+ * m this process' `ps_mtx'
+ */
struct process {
/*
* ps_mainproc is the original thread in the process.
@@ -181,6 +186,7 @@ struct process {
struct futex_list ps_ftlist; /* futexes attached to this process */
LIST_HEAD(, kqueue) ps_kqlist; /* kqueues attached to this process */
+ struct mutex ps_mtx; /* per-process mutex */
/* The following fields are all zeroed upon creation in process_new. */
#define ps_startzero ps_klist
@@ -200,7 +206,7 @@ struct process {
struct ptrace_state *ps_ptstat;/* Ptrace state */
struct rusage *ps_ru; /* sum of stats for dead threads. */
- struct tusage ps_tu; /* accumulated times. */
+ struct tusage ps_tu; /* [m] accumulated times. */
struct rusage ps_cru; /* sum of stats for reaped children */
struct itimerval ps_timer[3]; /* timers, indexed by ITIMER_* */
struct timeout ps_rucheck_to; /* resource limit check timer */
@@ -301,12 +307,14 @@ struct lock_list_entry;
/*
* Locks used to protect struct members in this file:
* s scheduler lock
+ * I immutable after creation
+ * pm parent process `ps_mtx'
*/
struct proc {
TAILQ_ENTRY(proc) p_runq; /* [s] current run/sleep queue */
LIST_ENTRY(proc) p_list; /* List of all threads. */
- struct process *p_p; /* The process of this thread. */
+ struct process *p_p; /* [I] The process of this thread. */
TAILQ_ENTRY(proc) p_thr_link; /* Threads in a process linkage. */
TAILQ_ENTRY(proc) p_fut_link; /* Threads in a futex linkage. */
@@ -337,17 +345,17 @@ struct proc {
int p_cpticks; /* Ticks of cpu time. */
const volatile void *p_wchan; /* [s] Sleep address. */
struct timeout p_sleep_to;/* timeout for tsleep() */
+ struct cpu_info * volatile p_cpu; /* [s] CPU we're running on. */
const char *p_wmesg; /* [s] Reason for sleep. */
fixpt_t p_pctcpu; /* [s] %cpu for this thread */
u_int p_slptime; /* [s] Time since last blocked. */
- u_int p_uticks; /* Statclock hits in user mode. */
- u_int p_sticks; /* Statclock hits in system mode. */
- u_int p_iticks; /* Statclock hits processing intr. */
- struct cpu_info * volatile p_cpu; /* [s] CPU we're running on. */
+ u_int p_uticks; /* [pm] Statclock hits in user mode */
+ u_int p_sticks; /* [pm] Statclock hits in system mode */
+ u_int p_iticks; /* [pm] Statclock hits in intr. */
struct rusage p_ru; /* Statistics */
- struct tusage p_tu; /* accumulated times. */
- struct timespec p_rtime; /* Real time. */
+ struct tusage p_tu; /* [pm] accumulated times. */
+ struct timespec p_rtime; /* [pm] Real time. */
int p_siglist; /* Signals arrived but not delivered. */
diff --git a/sys/sys/resourcevar.h b/sys/sys/resourcevar.h
index a27ba30dee2..5a74fa715dc 100644
--- a/sys/sys/resourcevar.h
+++ b/sys/sys/resourcevar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: resourcevar.h,v 1.20 2019/05/31 04:46:18 visa Exp $ */
+/* $OpenBSD: resourcevar.h,v 1.21 2019/05/31 19:51:10 mpi Exp $ */
/* $NetBSD: resourcevar.h,v 1.12 1995/11/22 23:01:53 cgd Exp $ */
/*
@@ -58,8 +58,7 @@ do { \
#ifdef _KERNEL
void addupc_intr(struct proc *, u_long);
void addupc_task(struct proc *, u_long, u_int);
-void tuagg_unlocked(struct process *, struct proc *);
-void tuagg(struct process *, struct proc *);
+void tuagg(struct proc *, struct timespec *);
struct tusage;
void calctsru(struct tusage *, struct timespec *, struct timespec *,
struct timespec *);
diff --git a/sys/sys/sysctl.h b/sys/sys/sysctl.h
index 4599ca70ce6..b7c87ce9a71 100644
--- a/sys/sys/sysctl.h
+++ b/sys/sys/sysctl.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: sysctl.h,v 1.186 2019/05/13 19:21:31 bluhm Exp $ */
+/* $OpenBSD: sysctl.h,v 1.187 2019/05/31 19:51:10 mpi Exp $ */
/* $NetBSD: sysctl.h,v 1.16 1996/04/09 20:55:36 cgd Exp $ */
/*
@@ -536,6 +536,14 @@ struct kinfo_vmentry {
* p_tpgid, p_tsess, p_vm_rssize, p_u[us]time_{sec,usec}, p_cpuid
*/
+#if defined(_KERNEL)
+#define PR_LOCK(pr) mtx_enter(&(pr)->ps_mtx)
+#define PR_UNLOCK(pr) mtx_leave(&(pr)->ps_mtx)
+#else
+#define PR_LOCK(pr) /* nothing */
+#define PR_UNLOCK(pr) /* nothing */
+#endif
+
#define PTRTOINT64(_x) ((u_int64_t)(u_long)(_x))
#define FILL_KPROC(kp, copy_str, p, pr, uc, pg, paddr, \
@@ -574,6 +582,7 @@ do { \
(kp)->p_jobc = (pg)->pg_jobc; \
\
(kp)->p_estcpu = (p)->p_estcpu; \
+ PR_LOCK(pr); \
if (isthread) { \
(kp)->p_rtime_sec = (p)->p_tu.tu_runtime.tv_sec; \
(kp)->p_rtime_usec = (p)->p_tu.tu_runtime.tv_nsec/1000; \
@@ -589,6 +598,7 @@ do { \
(kp)->p_sticks = (pr)->ps_tu.tu_sticks; \
(kp)->p_iticks = (pr)->ps_tu.tu_iticks; \
} \
+ PR_UNLOCK(pr); \
(kp)->p_cpticks = (p)->p_cpticks; \
\
if (show_addresses) \