Date: Tue, 7 Nov 2017 15:13:33 +0000 (UTC) From: Bartek Rutkowski <robak@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r325516 - in head: lib/libc/gen sys/kern Message-ID: <201711071513.vA7FDXHa035038@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: robak (ports committer) Date: Tue Nov 7 15:13:32 2017 New Revision: 325516 URL: https://svnweb.freebsd.org/changeset/base/325516 Log: Make sysctl_kern_proc_umask execute fast path when requested pid in curproc->p_pid or 0, avoiding unnecessary locking. Update libc consumer to skip calling getpid(). Submitted by: Pawel Biernacki <pawel.biernacki@gmail.com> Reviewed by: mjg, robak Approved by: mjg Sponsored by: Mysterious Code Ltd. Differential Revision: D12972 Modified: head/lib/libc/gen/setmode.c head/sys/kern/kern_proc.c Modified: head/lib/libc/gen/setmode.c ============================================================================== --- head/lib/libc/gen/setmode.c Tue Nov 7 15:01:38 2017 (r325515) +++ head/lib/libc/gen/setmode.c Tue Nov 7 15:13:32 2017 (r325516) @@ -356,7 +356,7 @@ getumask(void) * security.bsd.unprivileged_proc_debug is set to 0. */ len = sizeof(smask); - if (sysctl((int[4]){ CTL_KERN, KERN_PROC, KERN_PROC_UMASK, getpid() }, + if (sysctl((int[4]){ CTL_KERN, KERN_PROC, KERN_PROC_UMASK, 0 }, 4, &smask, &len, NULL, 0) == 0) return (smask); Modified: head/sys/kern/kern_proc.c ============================================================================== --- head/sys/kern/kern_proc.c Tue Nov 7 15:01:38 2017 (r325515) +++ head/sys/kern/kern_proc.c Tue Nov 7 15:13:32 2017 (r325516) @@ -2770,18 +2770,25 @@ sysctl_kern_proc_umask(SYSCTL_HANDLER_ARGS) struct proc *p; int error; u_short fd_cmask; + pid_t pid; if (namelen != 1) return (EINVAL); - error = pget((pid_t)name[0], PGET_WANTREAD, &p); + pid = (pid_t)name[0]; + p = curproc; + if (pid == p->p_pid || pid == 0) { + fd_cmask = p->p_fd->fd_cmask; + goto out; + } + + error = pget(pid, PGET_WANTREAD, &p); if (error != 0) return (error); - FILEDESC_SLOCK(p->p_fd); fd_cmask = p->p_fd->fd_cmask; - FILEDESC_SUNLOCK(p->p_fd); PRELE(p); +out: error = SYSCTL_OUT(req, &fd_cmask, sizeof(fd_cmask)); return (error); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201711071513.vA7FDXHa035038>