PERFORCE change 128606 for review
John Birrell
jb at FreeBSD.org
Sat Nov 3 20:32:11 PDT 2007
http://perforce.freebsd.org/chv.cgi?CH=128606
Change 128606 by jb at jb_freebsd1 on 2007/11/04 03:31:54
Revise the extra memory allocation for DTrace struct proc and
struct thread data based on advice from rwatson and jhb that
adding an extra pointer to struct proc and struct thread won't
break the kernel ABI.
This adds event handlers to allocate and free proc/thread
data for DTrace plus a memory allocation type for DTrace
hooks.
Note that adding the event handler definitions to proc.h tended
to expose all the event handler junk everywhere in the kernel
that references proc.h. It turned out to be cleaner to add
proc_event.h and just include that where _really_ needed.
Affected files ...
.. //depot/projects/dtrace/src/sys/conf/files#49 edit
.. //depot/projects/dtrace/src/sys/kern/init_main.c#19 edit
.. //depot/projects/dtrace/src/sys/kern/kern_dtrace.c#1 add
.. //depot/projects/dtrace/src/sys/kern/kern_thread.c#14 edit
.. //depot/projects/dtrace/src/sys/sys/dtrace_bsd.h#2 edit
.. //depot/projects/dtrace/src/sys/sys/proc.h#24 edit
.. //depot/projects/dtrace/src/sys/sys/proc_event.h#1 add
Differences ...
==== //depot/projects/dtrace/src/sys/conf/files#49 (text+ko) ====
@@ -1416,6 +1416,7 @@
kern/kern_cpu.c standard
kern/kern_context.c standard
kern/kern_descrip.c standard
+kern/kern_dtrace.c standard
kern/kern_environment.c standard
kern/kern_event.c standard
kern/kern_exec.c standard
==== //depot/projects/dtrace/src/sys/kern/init_main.c#19 (text+ko) ====
@@ -98,15 +98,6 @@
struct vmspace vmspace0;
struct proc *initproc;
-/* DTrace data for the primary thread in proc0. */
-char kdtrace_thread0[KDTRACE_THREAD_SIZE];
-
-/* Offset from 'struct thread *' to the opaque DTrace fields. */
-int kdtrace_thread_offset;
-
-/* Overall per-thread allocation size. */
-int kdtrace_thread_size;
-
int boothowto = 0; /* initialized so that it can be patched */
SYSCTL_INT(_debug, OID_AUTO, boothowto, CTLFLAG_RD, &boothowto, 0, "");
int bootverbose;
@@ -186,18 +177,6 @@
int verbose;
#endif
- /* Get the size of 'struct thread' plus 'struct td_sched' */
- kdtrace_thread_offset = sched_sizeof_thread();
-
- /*
- * Allow for the DTrace-specific thread data after
- * struct td_sched. This space is allocated opaquely to
- * avoid license issues. The value of KDTRACE_THREAD_SIZE
- * set in sys/proc.h must be larger than that required by
- * the DTrace kernel modules.
- */
- kdtrace_thread_size = kdtrace_thread_offset + KDTRACE_THREAD_SIZE;
-
if (sysinit == NULL) {
sysinit = SET_BEGIN(sysinit_set);
sysinit_end = SET_LIMIT(sysinit_set);
==== //depot/projects/dtrace/src/sys/kern/kern_thread.c#14 (text+ko) ====
@@ -35,6 +35,7 @@
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/proc.h>
+#include <sys/proc_event.h>
#include <sys/resourcevar.h>
#include <sys/smp.h>
#include <sys/sysctl.h>
@@ -186,6 +187,7 @@
td->td_sleepqueue = sleepq_alloc();
td->td_turnstile = turnstile_alloc();
td->td_sched = (struct td_sched *)&td[1];
+ EVENTHANDLER_INVOKE(thread_ctor, td);
sched_newthread(td);
umtx_thread_init(td);
return (0);
@@ -200,6 +202,7 @@
struct thread *td;
td = (struct thread *)mem;
+ EVENTHANDLER_INVOKE(thread_dtor, td);
turnstile_free(td->td_turnstile);
sleepq_free(td->td_sleepqueue);
umtx_thread_fini(td);
@@ -243,7 +246,7 @@
mtx_init(&tid_lock, "TID lock", NULL, MTX_DEF);
tid_unrhdr = new_unrhdr(PID_MAX + 1, INT_MAX, &tid_lock);
- thread_zone = uma_zcreate("THREAD", kdtrace_thread_size,
+ thread_zone = uma_zcreate("THREAD", sched_sizeof_thread(),
thread_ctor, thread_dtor, thread_init, thread_fini,
16 - 1, 0);
#ifdef KSE
==== //depot/projects/dtrace/src/sys/sys/dtrace_bsd.h#2 (text+ko) ====
@@ -37,4 +37,12 @@
/* Global variable in trap.c */
extern dtrace_invop_func_t dtrace_invop_func;
+/*
+ * Functions which allow the dtrace module to check that the kernel
+ * hooks have been compiled with sufficient space for it's private
+ * structures.
+ */
+size_t kdtrace_proc_size(void);
+size_t kdtrace_thread_size(void);
+
#endif /* _SYS_DTRACE_BSD_H */
==== //depot/projects/dtrace/src/sys/sys/proc.h#24 (text+ko) ====
@@ -163,6 +163,8 @@
struct trapframe;
struct turnstile;
struct mqueue_notifier;
+struct kdtrace_proc;
+struct kdtrace_thread;
/*
* Here we define the two structures used for process information.
@@ -298,6 +300,7 @@
struct td_sched *td_sched; /* (*) Scheduler-specific data. */
struct kaudit_record *td_ar; /* (k) Active audit record, if any. */
int td_syscalls; /* per-thread syscall count (used by NFS :)) */
+ struct kdtrace_thread *td_dtrace; /* (*) DTrace-specific data. */
};
struct mtx *thread_lock_block(struct thread *);
@@ -587,6 +590,7 @@
struct p_sched *p_sched; /* (*) Scheduler-specific data. */
STAILQ_HEAD(, ktr_request) p_ktr; /* (o) KTR event queue. */
LIST_HEAD(, mqueue_notifier) p_mqnotifier; /* (c) mqueue notifiers.*/
+ struct kdtrace_proc *p_dtrace; /* (*) DTrace-specific data. */
};
#define p_session p_pgrp->pg_session
@@ -804,21 +808,6 @@
extern int maxprocperuid; /* Max procs per uid. */
extern u_long ps_arg_cache_limit;
-/*
- * Space to append to struct thread for DTrace specific thread
- * variables. This space is after the 'struct td_sched'.
- */
-#define KDTRACE_THREAD_SIZE 128
-
-/* Offset from 'struct thread *' to the opaque DTrace fields. */
-extern int kdtrace_thread_offset;
-
-/* Overall per-thread allocation size. */
-extern int kdtrace_thread_size;
-
-/* DTrace data for the primary thread in proc0. */
-extern char kdtrace_thread0[];
-
LIST_HEAD(proclist, proc);
TAILQ_HEAD(procqueue, proc);
TAILQ_HEAD(threadqueue, thread);
More information about the p4-projects
mailing list