svn commit: r272539 - in projects/random_number_generator: lib/libc/stdtime sys/conf sys/dev/vt sys/kern sys/sys sys/vm
Mark Murray
markm at FreeBSD.org
Sat Oct 4 19:32:51 UTC 2014
Author: markm
Date: Sat Oct 4 19:32:46 2014
New Revision: 272539
URL: https://svnweb.freebsd.org/changeset/base/272539
Log:
MFC
Merging r272528 through r272538
Modified:
projects/random_number_generator/lib/libc/stdtime/strptime.3
projects/random_number_generator/sys/conf/NOTES
projects/random_number_generator/sys/conf/options
projects/random_number_generator/sys/dev/vt/vt_core.c
projects/random_number_generator/sys/kern/imgact_elf.c
projects/random_number_generator/sys/kern/kern_event.c
projects/random_number_generator/sys/kern/kern_intr.c
projects/random_number_generator/sys/kern/kern_sig.c
projects/random_number_generator/sys/kern/vfs_vnops.c
projects/random_number_generator/sys/sys/event.h
projects/random_number_generator/sys/sys/systm.h
projects/random_number_generator/sys/sys/vnode.h
projects/random_number_generator/sys/vm/vm_glue.c
Directory Properties:
projects/random_number_generator/ (props changed)
projects/random_number_generator/lib/libc/ (props changed)
projects/random_number_generator/lib/libc/stdtime/ (props changed)
projects/random_number_generator/sys/ (props changed)
projects/random_number_generator/sys/conf/ (props changed)
Modified: projects/random_number_generator/lib/libc/stdtime/strptime.3
==============================================================================
--- projects/random_number_generator/lib/libc/stdtime/strptime.3 Sat Oct 4 18:51:55 2014 (r272538)
+++ projects/random_number_generator/lib/libc/stdtime/strptime.3 Sat Oct 4 19:32:46 2014 (r272539)
@@ -79,7 +79,8 @@ and
.Fa \&%D ,
are now interpreted as beginning at 1969 per POSIX requirements.
Years 69-00 are interpreted in the 20th century (1969-2000), years
-01-68 in the 21st century (2001-2068). The
+01-68 in the 21st century (2001-2068).
+The
.Fa \&%U
and
.Fa %W
Modified: projects/random_number_generator/sys/conf/NOTES
==============================================================================
--- projects/random_number_generator/sys/conf/NOTES Sat Oct 4 18:51:55 2014 (r272538)
+++ projects/random_number_generator/sys/conf/NOTES Sat Oct 4 19:32:46 2014 (r272539)
@@ -2958,6 +2958,7 @@ options SC_RENDER_DEBUG # syscons rende
options VFS_BIO_DEBUG # VFS buffer I/O debugging
options KSTACK_MAX_PAGES=32 # Maximum pages to give the kernel stack
+options KSTACK_USAGE_PROF
# Adaptec Array Controller driver options
options AAC_DEBUG # Debugging levels:
Modified: projects/random_number_generator/sys/conf/options
==============================================================================
--- projects/random_number_generator/sys/conf/options Sat Oct 4 18:51:55 2014 (r272538)
+++ projects/random_number_generator/sys/conf/options Sat Oct 4 19:32:46 2014 (r272539)
@@ -136,6 +136,7 @@ KDTRACE_FRAME opt_kdtrace.h
KN_HASHSIZE opt_kqueue.h
KSTACK_MAX_PAGES
KSTACK_PAGES
+KSTACK_USAGE_PROF
KTRACE
KTRACE_REQUEST_POOL opt_ktrace.h
LIBICONV
Modified: projects/random_number_generator/sys/dev/vt/vt_core.c
==============================================================================
--- projects/random_number_generator/sys/dev/vt/vt_core.c Sat Oct 4 18:51:55 2014 (r272538)
+++ projects/random_number_generator/sys/dev/vt/vt_core.c Sat Oct 4 19:32:46 2014 (r272539)
@@ -1269,7 +1269,8 @@ vtterm_cnprobe(struct terminal *tm, stru
* that we have the real viewable size, fix it in the static
* buffer.
*/
- vt_termsize(vd, vw->vw_font, &vw->vw_buf.vb_scr_size);
+ if (vd->vd_width != 0 && vd->vd_height != 0)
+ vt_termsize(vd, vw->vw_font, &vw->vw_buf.vb_scr_size);
vtbuf_init_early(&vw->vw_buf);
vt_winsize(vd, vw->vw_font, &wsz);
Modified: projects/random_number_generator/sys/kern/imgact_elf.c
==============================================================================
--- projects/random_number_generator/sys/kern/imgact_elf.c Sat Oct 4 18:51:55 2014 (r272538)
+++ projects/random_number_generator/sys/kern/imgact_elf.c Sat Oct 4 19:32:46 2014 (r272539)
@@ -1112,8 +1112,8 @@ core_output(struct vnode *vp, void *base
#endif
} else {
error = vn_rdwr_inchunks(UIO_WRITE, vp, base, len, offset,
- UIO_USERSPACE, IO_UNIT | IO_DIRECT, active_cred, file_cred,
- NULL, td);
+ UIO_USERSPACE, IO_UNIT | IO_DIRECT | IO_RANGELOCKED,
+ active_cred, file_cred, NULL, td);
}
return (error);
}
@@ -1160,8 +1160,8 @@ sbuf_drain_core_output(void *arg, const
#endif
error = vn_rdwr_inchunks(UIO_WRITE, p->vp,
__DECONST(void *, data), len, p->offset, UIO_SYSSPACE,
- IO_UNIT | IO_DIRECT, p->active_cred, p->file_cred, NULL,
- p->td);
+ IO_UNIT | IO_DIRECT | IO_RANGELOCKED, p->active_cred,
+ p->file_cred, NULL, p->td);
if (locked)
PROC_LOCK(p->td->td_proc);
if (error != 0)
Modified: projects/random_number_generator/sys/kern/kern_event.c
==============================================================================
--- projects/random_number_generator/sys/kern/kern_event.c Sat Oct 4 18:51:55 2014 (r272538)
+++ projects/random_number_generator/sys/kern/kern_event.c Sat Oct 4 19:32:46 2014 (r272539)
@@ -569,9 +569,10 @@ filt_timerexpire(void *knx)
if ((kn->kn_flags & EV_ONESHOT) != EV_ONESHOT) {
calloutp = (struct callout *)kn->kn_hook;
- callout_reset_sbt_on(calloutp,
- timer2sbintime(kn->kn_sdata, kn->kn_sfflags), 0,
- filt_timerexpire, kn, PCPU_GET(cpuid), 0);
+ *kn->kn_ptr.p_nexttime += timer2sbintime(kn->kn_sdata,
+ kn->kn_sfflags);
+ callout_reset_sbt_on(calloutp, *kn->kn_ptr.p_nexttime, 0,
+ filt_timerexpire, kn, PCPU_GET(cpuid), C_ABSOLUTE);
}
}
@@ -607,11 +608,13 @@ filt_timerattach(struct knote *kn)
kn->kn_flags |= EV_CLEAR; /* automatically set */
kn->kn_status &= ~KN_DETACHED; /* knlist_add clears it */
+ kn->kn_ptr.p_nexttime = malloc(sizeof(sbintime_t), M_KQUEUE, M_WAITOK);
calloutp = malloc(sizeof(*calloutp), M_KQUEUE, M_WAITOK);
callout_init(calloutp, CALLOUT_MPSAFE);
kn->kn_hook = calloutp;
- callout_reset_sbt_on(calloutp, to, 0,
- filt_timerexpire, kn, PCPU_GET(cpuid), 0);
+ *kn->kn_ptr.p_nexttime = to + sbinuptime();
+ callout_reset_sbt_on(calloutp, *kn->kn_ptr.p_nexttime, 0,
+ filt_timerexpire, kn, PCPU_GET(cpuid), C_ABSOLUTE);
return (0);
}
@@ -625,6 +628,7 @@ filt_timerdetach(struct knote *kn)
calloutp = (struct callout *)kn->kn_hook;
callout_drain(calloutp);
free(calloutp, M_KQUEUE);
+ free(kn->kn_ptr.p_nexttime, M_KQUEUE);
old = atomic_fetch_sub_explicit(&kq_ncallouts, 1, memory_order_relaxed);
KASSERT(old > 0, ("Number of callouts cannot become negative"));
kn->kn_status |= KN_DETACHED; /* knlist_remove sets it */
Modified: projects/random_number_generator/sys/kern/kern_intr.c
==============================================================================
--- projects/random_number_generator/sys/kern/kern_intr.c Sat Oct 4 18:51:55 2014 (r272538)
+++ projects/random_number_generator/sys/kern/kern_intr.c Sat Oct 4 19:32:46 2014 (r272539)
@@ -28,6 +28,7 @@
__FBSDID("$FreeBSD$");
#include "opt_ddb.h"
+#include "opt_kstack_usage_prof.h"
#include <sys/param.h>
#include <sys/bus.h>
@@ -1385,6 +1386,10 @@ intr_event_handle(struct intr_event *ie,
td = curthread;
+#ifdef KSTACK_USAGE_PROF
+ intr_prof_stack_use(td, frame);
+#endif
+
/* An interrupt with no event or handlers is a stray interrupt. */
if (ie == NULL || TAILQ_EMPTY(&ie->ie_handlers))
return (EINVAL);
Modified: projects/random_number_generator/sys/kern/kern_sig.c
==============================================================================
--- projects/random_number_generator/sys/kern/kern_sig.c Sat Oct 4 18:51:55 2014 (r272538)
+++ projects/random_number_generator/sys/kern/kern_sig.c Sat Oct 4 19:32:46 2014 (r272539)
@@ -3214,8 +3214,8 @@ coredump(struct thread *td)
struct flock lf;
struct vattr vattr;
int error, error1, locked;
- struct mount *mp;
char *name; /* name of corefile */
+ void *rl_cookie;
off_t limit;
int compress;
@@ -3248,39 +3248,33 @@ coredump(struct thread *td)
}
PROC_UNLOCK(p);
-restart:
error = corefile_open(p->p_comm, cred->cr_uid, p->p_pid, td, compress,
&vp, &name);
if (error != 0)
return (error);
- /* Don't dump to non-regular files or files with links. */
+ /*
+ * Don't dump to non-regular files or files with links.
+ * Do not dump into system files.
+ */
if (vp->v_type != VREG || VOP_GETATTR(vp, &vattr, cred) != 0 ||
- vattr.va_nlink != 1) {
+ vattr.va_nlink != 1 || (vp->v_vflag & VV_SYSTEM) != 0) {
VOP_UNLOCK(vp, 0);
error = EFAULT;
goto close;
}
VOP_UNLOCK(vp, 0);
+
+ /* Postpone other writers, including core dumps of other processes. */
+ rl_cookie = vn_rangelock_wlock(vp, 0, OFF_MAX);
+
lf.l_whence = SEEK_SET;
lf.l_start = 0;
lf.l_len = 0;
lf.l_type = F_WRLCK;
locked = (VOP_ADVLOCK(vp, (caddr_t)p, F_SETLK, &lf, F_FLOCK) == 0);
- if (vn_start_write(vp, &mp, V_NOWAIT) != 0) {
- lf.l_type = F_UNLCK;
- if (locked)
- VOP_ADVLOCK(vp, (caddr_t)p, F_UNLCK, &lf, F_FLOCK);
- if ((error = vn_close(vp, FWRITE, cred, td)) != 0)
- goto out;
- if ((error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH)) != 0)
- goto out;
- free(name, M_TEMP);
- goto restart;
- }
-
VATTR_NULL(&vattr);
vattr.va_size = 0;
if (set_core_nodump_flag)
@@ -3288,7 +3282,6 @@ restart:
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
VOP_SETATTR(vp, &vattr, cred);
VOP_UNLOCK(vp, 0);
- vn_finished_write(mp);
PROC_LOCK(p);
p->p_acflag |= ACORE;
PROC_UNLOCK(p);
@@ -3304,11 +3297,11 @@ restart:
lf.l_type = F_UNLCK;
VOP_ADVLOCK(vp, (caddr_t)p, F_UNLCK, &lf, F_FLOCK);
}
+ vn_rangelock_unlock(vp, rl_cookie);
close:
error1 = vn_close(vp, FWRITE, cred, td);
if (error == 0)
error = error1;
-out:
#ifdef AUDIT
audit_proc_coredump(td, name, error);
#endif
Modified: projects/random_number_generator/sys/kern/vfs_vnops.c
==============================================================================
--- projects/random_number_generator/sys/kern/vfs_vnops.c Sat Oct 4 18:51:55 2014 (r272538)
+++ projects/random_number_generator/sys/kern/vfs_vnops.c Sat Oct 4 19:32:46 2014 (r272539)
@@ -504,13 +504,16 @@ vn_rdwr(enum uio_rw rw, struct vnode *vp
error = 0;
if ((ioflg & IO_NODELOCKED) == 0) {
- if (rw == UIO_READ) {
- rl_cookie = vn_rangelock_rlock(vp, offset,
- offset + len);
- } else {
- rl_cookie = vn_rangelock_wlock(vp, offset,
- offset + len);
- }
+ if ((ioflg & IO_RANGELOCKED) == 0) {
+ if (rw == UIO_READ) {
+ rl_cookie = vn_rangelock_rlock(vp, offset,
+ offset + len);
+ } else {
+ rl_cookie = vn_rangelock_wlock(vp, offset,
+ offset + len);
+ }
+ } else
+ rl_cookie = NULL;
mp = NULL;
if (rw == UIO_WRITE) {
if (vp->v_type != VCHR &&
@@ -2234,12 +2237,10 @@ vn_utimes_perm(struct vnode *vp, struct
{
int error;
- error = VOP_ACCESSX(vp, VWRITE_ATTRIBUTES, cred, td);
-
/*
- * From utimes(2):
- * Grant permission if the caller is the owner of the file or
- * the super-user. If the time pointer is null, then write
+ * Grant permission if the caller is the owner of the file, or
+ * the super-user, or has ACL_WRITE_ATTRIBUTES permission on
+ * on the file. If the time pointer is null, then write
* permission on the file is also sufficient.
*
* From NFSv4.1, draft 21, 6.2.1.3.1, Discussion of Mask Attributes:
@@ -2247,6 +2248,7 @@ vn_utimes_perm(struct vnode *vp, struct
* will be allowed to set the times [..] to the current
* server time.
*/
+ error = VOP_ACCESSX(vp, VWRITE_ATTRIBUTES, cred, td);
if (error != 0 && (vap->va_vaflags & VA_UTIMES_NULL) != 0)
error = VOP_ACCESS(vp, VWRITE, cred, td);
return (error);
Modified: projects/random_number_generator/sys/sys/event.h
==============================================================================
--- projects/random_number_generator/sys/sys/event.h Sat Oct 4 18:51:55 2014 (r272538)
+++ projects/random_number_generator/sys/sys/event.h Sat Oct 4 19:32:46 2014 (r272539)
@@ -221,6 +221,7 @@ struct knote {
struct proc *p_proc; /* proc pointer */
struct aiocblist *p_aio; /* AIO job pointer */
struct aioliojob *p_lio; /* LIO job pointer */
+ sbintime_t *p_nexttime; /* next timer event fires at */
void *p_v; /* generic other pointer */
} kn_ptr;
struct filterops *kn_fop;
Modified: projects/random_number_generator/sys/sys/systm.h
==============================================================================
--- projects/random_number_generator/sys/sys/systm.h Sat Oct 4 18:51:55 2014 (r272538)
+++ projects/random_number_generator/sys/sys/systm.h Sat Oct 4 19:32:46 2014 (r272539)
@@ -443,4 +443,6 @@ bitcount16(uint32_t x)
return (x);
}
+void intr_prof_stack_use(struct thread *td, struct trapframe *frame);
+
#endif /* !_SYS_SYSTM_H_ */
Modified: projects/random_number_generator/sys/sys/vnode.h
==============================================================================
--- projects/random_number_generator/sys/sys/vnode.h Sat Oct 4 18:51:55 2014 (r272538)
+++ projects/random_number_generator/sys/sys/vnode.h Sat Oct 4 19:32:46 2014 (r272539)
@@ -305,6 +305,7 @@ struct vattr {
#define IO_NORMAL 0x0800 /* operate on regular data */
#define IO_NOMACCHECK 0x1000 /* MAC checks unnecessary */
#define IO_BUFLOCKED 0x2000 /* ffs flag; indir buf is locked */
+#define IO_RANGELOCKED 0x4000 /* range locked */
#define IO_SEQMAX 0x7F /* seq heuristic max value */
#define IO_SEQSHIFT 16 /* seq heuristic in upper 16 bits */
Modified: projects/random_number_generator/sys/vm/vm_glue.c
==============================================================================
--- projects/random_number_generator/sys/vm/vm_glue.c Sat Oct 4 18:51:55 2014 (r272538)
+++ projects/random_number_generator/sys/vm/vm_glue.c Sat Oct 4 19:32:46 2014 (r272539)
@@ -62,6 +62,7 @@ __FBSDID("$FreeBSD$");
#include "opt_vm.h"
#include "opt_kstack_pages.h"
#include "opt_kstack_max_pages.h"
+#include "opt_kstack_usage_prof.h"
#include <sys/param.h>
#include <sys/systm.h>
@@ -98,6 +99,8 @@ __FBSDID("$FreeBSD$");
#include <vm/vm_pager.h>
#include <vm/swap_pager.h>
+#include <machine/cpu.h>
+
#ifndef NO_SWAPPING
static int swapout(struct proc *);
static void swapclear(struct proc *);
@@ -486,6 +489,52 @@ kstack_cache_init(void *nulll)
SYSINIT(vm_kstacks, SI_SUB_KTHREAD_INIT, SI_ORDER_ANY, kstack_cache_init, NULL);
+#ifdef KSTACK_USAGE_PROF
+/*
+ * Track maximum stack used by a thread in kernel.
+ */
+static int max_kstack_used;
+
+SYSCTL_INT(_debug, OID_AUTO, max_kstack_used, CTLFLAG_RD,
+ &max_kstack_used, 0,
+ "Maxiumum stack depth used by a thread in kernel");
+
+void
+intr_prof_stack_use(struct thread *td, struct trapframe *frame)
+{
+ vm_offset_t stack_top;
+ vm_offset_t current;
+ int used, prev_used;
+
+ /*
+ * Testing for interrupted kernel mode isn't strictly
+ * needed. It optimizes the execution, since interrupts from
+ * usermode will have only the trap frame on the stack.
+ */
+ if (TRAPF_USERMODE(frame))
+ return;
+
+ stack_top = td->td_kstack + td->td_kstack_pages * PAGE_SIZE;
+ current = (vm_offset_t)(uintptr_t)&stack_top;
+
+ /*
+ * Try to detect if interrupt is using kernel thread stack.
+ * Hardware could use a dedicated stack for interrupt handling.
+ */
+ if (stack_top <= current || current < td->td_kstack)
+ return;
+
+ used = stack_top - current;
+ for (;;) {
+ prev_used = max_kstack_used;
+ if (prev_used >= used)
+ break;
+ if (atomic_cmpset_int(&max_kstack_used, prev_used, used))
+ break;
+ }
+}
+#endif /* KSTACK_USAGE_PROF */
+
#ifndef NO_SWAPPING
/*
* Allow a thread's kernel stack to be paged out.
More information about the svn-src-projects
mailing list