From 282f31945bc734def8c8d3c04ee7d57e25bdc77a Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Wed, 11 Jan 2017 09:47:56 -0800 Subject: [PATCH] kernel - Incidental MPLOCK removal * Remove misc #include statements that are no longer needed. * Replace mplock with acct_lock in kern_acct.c * Replace mplock with msg_token in sysv_msg.c * Replace mplock with p->p_token in the profiling code. --- sys/kern/kern_acct.c | 33 +++++++++++++++++++++++---------- sys/kern/kern_acl.c | 2 -- sys/kern/kern_clock.c | 3 ++- sys/kern/kern_ktrace.c | 7 +++---- sys/kern/kern_proc.c | 1 - sys/kern/kern_sensors.c | 2 -- sys/kern/kern_sysctl.c | 2 -- sys/kern/lwkt_thread.c | 1 - sys/kern/subr_diskiocom.c | 1 - sys/kern/subr_eventhandler.c | 2 -- sys/kern/subr_input.c | 1 - sys/kern/subr_prof.c | 6 +++--- sys/kern/sys_generic.c | 1 - sys/kern/sysv_msg.c | 22 ++++++++++------------ sys/kern/vfs_bio.c | 1 - sys/kern/vfs_cache.c | 1 - 16 files changed, 41 insertions(+), 45 deletions(-) diff --git a/sys/kern/kern_acct.c b/sys/kern/kern_acct.c index 4d116ddab3..982a3d2143 100644 --- a/sys/kern/kern_acct.c +++ b/sys/kern/kern_acct.c @@ -55,7 +55,7 @@ #include -#include +struct lock acct_lock = LOCK_INITIALIZER("acct_lock", 0, 0); /* * The routines implemented in this file are described in: @@ -106,7 +106,7 @@ SYSCTL_INT(_kern, OID_AUTO, acct_chkfreq, CTLFLAG_RW, static void acct_init(void *arg __unused) { - callout_init(&acctwatch_handle); + callout_init_lk(&acctwatch_handle, &acct_lock); } SYSINIT(acct, SI_SUB_DRIVERS, SI_ORDER_ANY, acct_init, NULL); @@ -130,7 +130,7 @@ sys_acct(struct acct_args *uap) if (error) return (error); - get_mplock(); + lockmgr(&acct_lock, LK_EXCLUSIVE); /* * If accounting is to be started to a file, open that file for @@ -181,7 +181,8 @@ sys_acct(struct acct_args *uap) acctp = vp; acctwatch(NULL); done: - rel_mplock(); + lockmgr(&acct_lock, LK_RELEASE); + return (error); } @@ -201,12 +202,21 @@ acct_process(struct proc *p) struct timeval tmp; struct rlimit rlim; int t; + int error; struct vnode *vp; - /* If accounting isn't enabled, don't bother */ + /* + * If accounting isn't enabled, don't bother. Lock acct_lock + * make sure. + */ + if (acctp == NULLVP) + return 0; + lockmgr(&acct_lock, LK_SHARED); vp = acctp; - if (vp == NULLVP) - return (0); + if (vp == NULLVP) { + lockmgr(&acct_lock, LK_RELEASE); + return 0; + } /* * Get process accounting information. @@ -262,9 +272,12 @@ acct_process(struct proc *p) /* * Write the accounting information to the file. */ - return (vn_rdwr(UIO_WRITE, vp, (caddr_t)&acct, sizeof (acct), - (off_t)0, UIO_SYSSPACE, IO_APPEND|IO_UNIT, p->p_ucred, - NULL)); + error = vn_rdwr(UIO_WRITE, vp, (caddr_t)&acct, sizeof (acct), + (off_t)0, UIO_SYSSPACE, IO_APPEND|IO_UNIT, p->p_ucred, + NULL); + lockmgr(&acct_lock, LK_RELEASE); + + return error; } /* diff --git a/sys/kern/kern_acl.c b/sys/kern/kern_acl.c index cdb9dfc28f..2794b15119 100644 --- a/sys/kern/kern_acl.c +++ b/sys/kern/kern_acl.c @@ -47,8 +47,6 @@ #include #include -#include - static int vacl_set_acl(struct vnode *vp, acl_type_t type, struct acl *aclp); static int vacl_get_acl(struct vnode *vp, acl_type_t type, struct acl *aclp); static int vacl_aclcheck(struct vnode *vp, acl_type_t type, struct acl *aclp); diff --git a/sys/kern/kern_clock.c b/sys/kern/kern_clock.c index b962009e1a..676827584a 100644 --- a/sys/kern/kern_clock.c +++ b/sys/kern/kern_clock.c @@ -94,7 +94,6 @@ #include #include -#include #include #include @@ -1078,6 +1077,8 @@ tstohz_low(struct timespec *ts) /* * Start profiling on a process. * + * Caller must hold p->p_token(); + * * Kernel profiling passes proc0 which never exits and hence * keeps the profile clock running constantly. */ diff --git a/sys/kern/kern_ktrace.c b/sys/kern/kern_ktrace.c index 4985d1b816..fdddb895a2 100644 --- a/sys/kern/kern_ktrace.c +++ b/sys/kern/kern_ktrace.c @@ -48,8 +48,6 @@ #include -#include - static MALLOC_DEFINE(M_KTRACE, "KTRACE", "KTRACE"); #ifdef KTRACE @@ -270,8 +268,9 @@ sys_ktrace(struct ktrace_args *uap) struct nlookupdata nd; ktrace_node_t tracenode = NULL; - get_mplock(); + lwkt_gettoken(&curp->p_token); curp->p_traceflag |= KTRFAC_ACTIVE; + if (ops != KTROP_CLEAR) { /* * an operation which requires a file argument. @@ -359,7 +358,7 @@ done: if (tracenode) ktrdestroy(&tracenode); curp->p_traceflag &= ~KTRFAC_ACTIVE; - rel_mplock(); + lwkt_reltoken(&curp->p_token); return (error); #else return ENOSYS; diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c index bbd00188ef..1f0513b350 100644 --- a/sys/kern/kern_proc.c +++ b/sys/kern/kern_proc.c @@ -51,7 +51,6 @@ #include #include -#include /* * Hash table size must be a power of two and is not currently dynamically diff --git a/sys/kern/kern_sensors.c b/sys/kern/kern_sensors.c index a3a4109acb..9fd5f4ed7e 100644 --- a/sys/kern/kern_sensors.c +++ b/sys/kern/kern_sensors.c @@ -35,8 +35,6 @@ #include #include -#include - static int sensordev_idmax; static TAILQ_HEAD(sensordev_list, ksensordev) sensordev_list = TAILQ_HEAD_INITIALIZER(sensordev_list); diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c index 2b420ae257..a7dc0953bc 100644 --- a/sys/kern/kern_sysctl.c +++ b/sys/kern/kern_sysctl.c @@ -48,8 +48,6 @@ #include #include -#include - #include #include diff --git a/sys/kern/lwkt_thread.c b/sys/kern/lwkt_thread.c index 267a9119b8..46faf9a76d 100644 --- a/sys/kern/lwkt_thread.c +++ b/sys/kern/lwkt_thread.c @@ -55,7 +55,6 @@ #include #include -#include #include diff --git a/sys/kern/subr_diskiocom.c b/sys/kern/subr_diskiocom.c index f4e2bfbb77..946c360857 100644 --- a/sys/kern/subr_diskiocom.c +++ b/sys/kern/subr_diskiocom.c @@ -55,7 +55,6 @@ #include #include -#include #include #include diff --git a/sys/kern/subr_eventhandler.c b/sys/kern/subr_eventhandler.c index 2edc3e3929..86a856f6c9 100644 --- a/sys/kern/subr_eventhandler.c +++ b/sys/kern/subr_eventhandler.c @@ -34,8 +34,6 @@ #include #include -#include - MALLOC_DEFINE(M_EVENTHANDLER, "eventhandler", "Event handler records"); /* List of 'slow' lists */ diff --git a/sys/kern/subr_input.c b/sys/kern/subr_input.c index f59f9f7a8d..f0e432a7a9 100644 --- a/sys/kern/subr_input.c +++ b/sys/kern/subr_input.c @@ -49,7 +49,6 @@ #include /* for device_printf() */ #include -#include #include MALLOC_DEFINE(M_INPUT, "input", "Input Event"); diff --git a/sys/kern/subr_prof.c b/sys/kern/subr_prof.c index 2fb80224bc..8eb3650c32 100644 --- a/sys/kern/subr_prof.c +++ b/sys/kern/subr_prof.c @@ -39,7 +39,6 @@ #include #include -#include #include @@ -351,7 +350,7 @@ sys_profil(struct profil_args *uap) if (uap->scale > (1 << 16)) return (EINVAL); - get_mplock(); + lwkt_gettoken(&p->p_token); if (uap->scale == 0) { stopprofclock(p); } else { @@ -366,7 +365,8 @@ sys_profil(struct profil_args *uap) startprofclock(p); crit_exit(); } - rel_mplock(); + lwkt_reltoken(&p->p_token); + return (0); } diff --git a/sys/kern/sys_generic.c b/sys/kern/sys_generic.c index c7dfd6e99c..5cc2fd136e 100644 --- a/sys/kern/sys_generic.c +++ b/sys/kern/sys_generic.c @@ -67,7 +67,6 @@ #include #include -#include #include #include diff --git a/sys/kern/sysv_msg.c b/sys/kern/sysv_msg.c index fff03a5e9b..afe478796d 100644 --- a/sys/kern/sysv_msg.c +++ b/sys/kern/sysv_msg.c @@ -33,8 +33,6 @@ #include #include -#include - static MALLOC_DEFINE(M_MSG, "msg", "SVID compatible message queues"); static void msginit (void *); @@ -118,6 +116,7 @@ static char *msgpool; /* MSGMAX byte long msg buffer pool */ static struct msgmap *msgmaps; /* MSGSEG msgmap structures */ static struct msg *msghdrs; /* MSGTQL msg headers */ static struct msqid_ds *msqids; /* MSGMNI msqid_ds struct's */ +static struct lwkt_token msg_token = LWKT_TOKEN_INITIALIZER(msg_token); static void msginit(void *dummy) @@ -219,7 +218,7 @@ sys_msgctl(struct msgctl_args *uap) if (!jail_sysvipc_allowed && td->td_ucred->cr_prison != NULL) return (ENOSYS); - get_mplock(); + lwkt_gettoken(&msg_token); msqid = IPCID_TO_IX(msqid); if (msqid < 0 || msqid >= msginfo.msgmni) { @@ -332,7 +331,7 @@ sys_msgctl(struct msgctl_args *uap) break; } done: - rel_mplock(); + lwkt_reltoken(&msg_token); if (eval == 0) uap->sysmsg_result = rval; return(eval); @@ -358,7 +357,7 @@ sys_msgget(struct msgget_args *uap) return (ENOSYS); eval = 0; - get_mplock(); + lwkt_gettoken(&msg_token); if (key != IPC_PRIVATE) { for (msqid = 0; msqid < msginfo.msgmni; msqid++) { @@ -441,7 +440,7 @@ sys_msgget(struct msgget_args *uap) } done: - rel_mplock(); + lwkt_reltoken(&msg_token); /* Construct the unique msqid */ if (eval == 0) uap->sysmsg_result = IXSEQ_TO_IPCID(msqid, msqptr->msg_perm); @@ -472,7 +471,7 @@ sys_msgsnd(struct msgsnd_args *uap) if (!jail_sysvipc_allowed && td->td_ucred->cr_prison != NULL) return (ENOSYS); - get_mplock(); + lwkt_gettoken(&msg_token); msqid = IPCID_TO_IX(msqid); if (msqid < 0 || msqid >= msginfo.msgmni) { @@ -773,7 +772,7 @@ sys_msgsnd(struct msgsnd_args *uap) wakeup((caddr_t)msqptr); eval = 0; done: - rel_mplock(); + lwkt_reltoken(&msg_token); if (eval == 0) uap->sysmsg_result = 0; return (eval); @@ -805,7 +804,7 @@ sys_msgrcv(struct msgrcv_args *uap) if (!jail_sysvipc_allowed && td->td_ucred->cr_prison != NULL) return (ENOSYS); - get_mplock(); + lwkt_gettoken(&msg_token); msqid = IPCID_TO_IX(msqid); if (msqid < 0 || msqid >= msginfo.msgmni) { @@ -1060,7 +1059,7 @@ sys_msgrcv(struct msgrcv_args *uap) wakeup((caddr_t)msqptr); eval = 0; done: - rel_mplock(); + lwkt_reltoken(&msg_token); if (eval == 0) uap->sysmsg_result = msgsz; return(eval); @@ -1069,9 +1068,8 @@ done: static int sysctl_msqids(SYSCTL_HANDLER_ARGS) { - return (SYSCTL_OUT(req, msqids, - sizeof(struct msqid_ds) * msginfo.msgmni)); + sizeof(struct msqid_ds) * msginfo.msgmni)); } TUNABLE_INT("kern.ipc.msgseg", &msginfo.msgseg); diff --git a/sys/kern/vfs_bio.c b/sys/kern/vfs_bio.c index 440a9f2ab3..a83d5fd79c 100644 --- a/sys/kern/vfs_bio.c +++ b/sys/kern/vfs_bio.c @@ -60,7 +60,6 @@ #include #include #include -#include #include #include "opt_ddb.h" diff --git a/sys/kern/vfs_cache.c b/sys/kern/vfs_cache.c index ccdd405f6e..624563b78f 100644 --- a/sys/kern/vfs_cache.c +++ b/sys/kern/vfs_cache.c @@ -83,7 +83,6 @@ #include #include -#include #define MAX_RECURSION_DEPTH 64 -- 2.11.4.GIT