FreeBSD changes to vendor source.

This commit is contained in:
John Birrell 2008-05-22 07:33:39 +00:00
parent 17c2fc0cc7
commit 5a1b490d50
9 changed files with 1294 additions and 244 deletions

File diff suppressed because it is too large Load Diff

View File

@ -20,7 +20,7 @@
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@ -390,7 +390,7 @@ fasttrap_pid_cleanup(void)
/*
* This is called from cfork() via dtrace_fasttrap_fork(). The child
* process's address space is a (roughly) a copy of the parent process's so
* process's address space is (roughly) a copy of the parent process's so
* we have to remove all the instrumentation we had previously enabled in the
* parent.
*/
@ -437,6 +437,15 @@ fasttrap_fork(proc_t *p, proc_t *cp)
tp->ftt_proc->ftpc_acount != 0) {
int ret = fasttrap_tracepoint_remove(cp, tp);
ASSERT(ret == 0);
/*
* The count of active providers can only be
* decremented (i.e. to zero) during exec,
* exit, and removal of a meta provider so it
* should be impossible to drop the count
* mid-fork.
*/
ASSERT(tp->ftt_proc->ftpc_acount != 0);
}
}
mutex_exit(&bucket->ftb_mtx);
@ -517,6 +526,12 @@ fasttrap_tracepoint_enable(proc_t *p, fasttrap_probe_t *probe, uint_t index)
again:
mutex_enter(&bucket->ftb_mtx);
for (tp = bucket->ftb_data; tp != NULL; tp = tp->ftt_next) {
/*
* Note that it's safe to access the active count on the
* associated proc structure because we know that at least one
* provider (this one) will still be around throughout this
* operation.
*/
if (tp->ftt_pid != pid || tp->ftt_pc != pc ||
tp->ftt_proc->ftpc_acount == 0)
continue;
@ -1157,6 +1172,7 @@ fasttrap_proc_lookup(pid_t pid)
mutex_exit(&bucket->ftb_mtx);
fprc->ftpc_rcount++;
atomic_add_64(&fprc->ftpc_acount, 1);
ASSERT(fprc->ftpc_acount <= fprc->ftpc_rcount);
mutex_exit(&fprc->ftpc_mtx);
return (fprc);
@ -1186,6 +1202,7 @@ fasttrap_proc_lookup(pid_t pid)
mutex_exit(&bucket->ftb_mtx);
fprc->ftpc_rcount++;
atomic_add_64(&fprc->ftpc_acount, 1);
ASSERT(fprc->ftpc_acount <= fprc->ftpc_rcount);
mutex_exit(&fprc->ftpc_mtx);
kmem_free(new_fprc, sizeof (fasttrap_proc_t));
@ -1212,6 +1229,7 @@ fasttrap_proc_release(fasttrap_proc_t *proc)
mutex_enter(&proc->ftpc_mtx);
ASSERT(proc->ftpc_rcount != 0);
ASSERT(proc->ftpc_acount <= proc->ftpc_rcount);
if (--proc->ftpc_rcount != 0) {
mutex_exit(&proc->ftpc_mtx);
@ -1390,6 +1408,16 @@ fasttrap_provider_free(fasttrap_provider_t *provider)
ASSERT(provider->ftp_ccount == 0);
ASSERT(provider->ftp_mcount == 0);
/*
* If this provider hasn't been retired, we need to explicitly drop the
* count of active providers on the associated process structure.
*/
if (!provider->ftp_retired) {
atomic_add_64(&provider->ftp_proc->ftpc_acount, -1);
ASSERT(provider->ftp_proc->ftpc_acount <
provider->ftp_proc->ftpc_rcount);
}
fasttrap_proc_release(provider->ftp_proc);
kmem_free(provider, sizeof (fasttrap_provider_t));
@ -1461,6 +1489,8 @@ fasttrap_provider_retire(pid_t pid, const char *name, int mprov)
* table.
*/
atomic_add_64(&fp->ftp_proc->ftpc_acount, -1);
ASSERT(fp->ftp_proc->ftpc_acount < fp->ftp_proc->ftpc_rcount);
fp->ftp_retired = 1;
fp->ftp_marked = 1;
provid = fp->ftp_provid;
@ -2014,6 +2044,13 @@ fasttrap_ioctl(dev_t dev, int cmd, intptr_t arg, int md, cred_t *cr, int *rv)
tp->ftt_proc->ftpc_acount != 0)
break;
/*
* The count of active providers can only be
* decremented (i.e. to zero) during exec, exit, and
* removal of a meta provider so it should be
* impossible to drop the count during this operation().
*/
ASSERT(tp->ftt_proc->ftpc_acount != 0);
tp = tp->ftt_next;
}

View File

@ -668,7 +668,7 @@ void cpu_destroy_bound_threads(cpu_t *cp);
extern int cpu_bind_thread(kthread_t *tp, processorid_t bind,
processorid_t *obind, int *error);
extern int cpu_unbind(processorid_t cpu_id);
extern int cpu_unbind(processorid_t cpu_id, boolean_t force);
extern void thread_affinity_set(kthread_t *t, int cpu_id);
extern void thread_affinity_clear(kthread_t *t);
extern void affinity_set(int cpu_id);

View File

@ -27,7 +27,9 @@
#ifndef _CTF_H
#define _CTF_H
#if defined(sun)
#pragma ident "%Z%%M% %I% %E% SMI"
#endif
#include <sys/types.h>

View File

@ -65,10 +65,14 @@ typedef long ctf_id_t;
* filling in ctf_sect_t structures and passing them to ctf_bufopen():
*/
typedef struct ctf_sect {
const char *cts_name; /* section name (if any) */
char *cts_name; /* section name (if any) */
ulong_t cts_type; /* section type (ELF SHT_... value) */
ulong_t cts_flags; /* section flags (ELF SHF_... value) */
#if defined(sun)
const void *cts_data; /* pointer to section data */
#else
void *cts_data; /* pointer to section data */
#endif
size_t cts_size; /* size of data in bytes */
size_t cts_entsize; /* size of each section entry (symtab only) */
off64_t cts_offset; /* file offset of this section (if any) */

View File

@ -49,7 +49,7 @@ extern "C" {
#if defined(__STDC__)
extern int assfail(const char *, const char *, int);
#define VERIFY(EX) ((void)((EX) || assfail(#EX, __FILE__, __LINE__)))
#if DEBUG
#ifdef DEBUG
#define ASSERT(EX) VERIFY(EX)
#else
#define ASSERT(x) ((void)0)
@ -57,7 +57,7 @@ extern int assfail(const char *, const char *, int);
#else /* defined(__STDC__) */
extern int assfail();
#define VERIFY(EX) ((void)((EX) || assfail("EX", __FILE__, __LINE__)))
#if DEBUG
#ifdef DEBUG
#define ASSERT(EX) VERIFY(EX)
#else
#define ASSERT(x) ((void)0)
@ -97,7 +97,7 @@ _NOTE(CONSTCOND) } while (0)
#define VERIFY3S(x, y, z) VERIFY3_IMPL(x, y, z, int64_t)
#define VERIFY3U(x, y, z) VERIFY3_IMPL(x, y, z, uint64_t)
#define VERIFY3P(x, y, z) VERIFY3_IMPL(x, y, z, uintptr_t)
#if DEBUG
#ifdef DEBUG
#define ASSERT3S(x, y, z) VERIFY3S(x, y, z)
#define ASSERT3U(x, y, z) VERIFY3U(x, y, z)
#define ASSERT3P(x, y, z) VERIFY3P(x, y, z)

View File

@ -49,10 +49,22 @@ extern "C" {
#include <sys/types.h>
#include <sys/modctl.h>
#include <sys/processor.h>
#if defined(sun)
#include <sys/systm.h>
#else
#include <sys/param.h>
#include <sys/linker.h>
#include <sys/ioccom.h>
#include <sys/ucred.h>
typedef int model_t;
#endif
#include <sys/ctf_api.h>
#include <sys/cyclic.h>
#if defined(sun)
#include <sys/int_limits.h>
#else
#include <sys/stdint.h>
#endif
/*
* DTrace Universal Constants and Typedefs
@ -237,6 +249,7 @@ typedef enum dtrace_probespec {
#define DIF_VAR_UID 0x011e /* process user ID */
#define DIF_VAR_GID 0x011f /* process group ID */
#define DIF_VAR_ERRNO 0x0120 /* thread errno */
#define DIF_VAR_EXECARGS 0x0121 /* process arguments */
#define DIF_SUBR_RAND 0
#define DIF_SUBR_MUTEX_OWNED 1
@ -282,8 +295,13 @@ typedef enum dtrace_probespec {
#define DIF_SUBR_INET_NTOP 41
#define DIF_SUBR_INET_NTOA 42
#define DIF_SUBR_INET_NTOA6 43
#define DIF_SUBR_MEMREF 44
#define DIF_SUBR_TYPEREF 45
#define DIF_SUBR_SX_SHARED_HELD 46
#define DIF_SUBR_SX_EXCLUSIVE_HELD 47
#define DIF_SUBR_SX_ISEXCLUSIVE 48
#define DIF_SUBR_MAX 43 /* max subroutine value */
#define DIF_SUBR_MAX 48 /* max subroutine value */
typedef uint32_t dif_instr_t;
@ -392,6 +410,8 @@ typedef struct dtrace_difv {
#define DTRACEACT_PRINTF 3 /* printf() action */
#define DTRACEACT_PRINTA 4 /* printa() action */
#define DTRACEACT_LIBACT 5 /* library-controlled action */
#define DTRACEACT_PRINTM 6 /* printm() action */
#define DTRACEACT_PRINTT 7 /* printt() action */
#define DTRACEACT_PROC 0x0100
#define DTRACEACT_USTACK (DTRACEACT_PROC + 1)
@ -497,7 +517,7 @@ typedef struct dtrace_difv {
((((uint64_t)(y)) << 32) | ((x) & UINT32_MAX))
#ifndef _LP64
#ifndef _LITTLE_ENDIAN
#if BYTE_ORDER == _BIG_ENDIAN
#define DTRACE_PTR(type, name) uint32_t name##pad; type *name
#else
#define DTRACE_PTR(type, name) type *name; uint32_t name##pad
@ -607,7 +627,7 @@ typedef struct dof_hdr {
#define DOF_ENCODE_LSB 1
#define DOF_ENCODE_MSB 2
#ifdef _BIG_ENDIAN
#if BYTE_ORDER == _BIG_ENDIAN
#define DOF_ENCODE_NATIVE DOF_ENCODE_MSB
#else
#define DOF_ENCODE_NATIVE DOF_ENCODE_LSB
@ -1171,6 +1191,7 @@ typedef struct dtrace_providerdesc {
* pseudodevice driver. These ioctls comprise the user-kernel interface to
* DTrace.
*/
#if defined(sun)
#define DTRACEIOC (('d' << 24) | ('t' << 16) | ('r' << 8))
#define DTRACEIOC_PROVIDER (DTRACEIOC | 1) /* provider query */
#define DTRACEIOC_PROBES (DTRACEIOC | 2) /* probe query */
@ -1188,6 +1209,44 @@ typedef struct dtrace_providerdesc {
#define DTRACEIOC_FORMAT (DTRACEIOC | 16) /* get format str */
#define DTRACEIOC_DOFGET (DTRACEIOC | 17) /* get DOF */
#define DTRACEIOC_REPLICATE (DTRACEIOC | 18) /* replicate enab */
#else
#define DTRACEIOC_PROVIDER _IOWR('x',1,dtrace_providerdesc_t)
/* provider query */
#define DTRACEIOC_PROBES _IOWR('x',2,dtrace_probedesc_t)
/* probe query */
#define DTRACEIOC_BUFSNAP _IOW('x',4,dtrace_bufdesc_t *)
/* snapshot buffer */
#define DTRACEIOC_PROBEMATCH _IOWR('x',5,dtrace_probedesc_t)
/* match probes */
typedef struct {
void *dof; /* DOF userland address written to driver. */
int n_matched; /* # matches returned by driver. */
} dtrace_enable_io_t;
#define DTRACEIOC_ENABLE _IOWR('x',6,dtrace_enable_io_t)
/* enable probes */
#define DTRACEIOC_AGGSNAP _IOW('x',7,dtrace_bufdesc_t *)
/* snapshot agg. */
#define DTRACEIOC_EPROBE _IOW('x',8,dtrace_eprobedesc_t)
/* get eprobe desc. */
#define DTRACEIOC_PROBEARG _IOWR('x',9,dtrace_argdesc_t)
/* get probe arg */
#define DTRACEIOC_CONF _IOR('x',10,dtrace_conf_t)
/* get config. */
#define DTRACEIOC_STATUS _IOR('x',11,dtrace_status_t)
/* get status */
#define DTRACEIOC_GO _IOR('x',12,processorid_t)
/* start tracing */
#define DTRACEIOC_STOP _IOWR('x',13,processorid_t)
/* stop tracing */
#define DTRACEIOC_AGGDESC _IOW('x',15,dtrace_aggdesc_t *)
/* get agg. desc. */
#define DTRACEIOC_FORMAT _IOWR('x',16,dtrace_fmtdesc_t)
/* get format str */
#define DTRACEIOC_DOFGET _IOW('x',17,dof_hdr_t *)
/* get DOF */
#define DTRACEIOC_REPLICATE _IOW('x',18,dtrace_repldesc_t)
/* replicate enab */
#endif
/*
* DTrace Helpers
@ -1350,7 +1409,7 @@ typedef struct dof_helper {
* DTrace routines, including dtrace_probe_create(), dtrace_probe_lookup(),
* and dtrace_probe_arg().
*
* 1.3 void dtps_provide_module(void *arg, struct modctl *mp)
* 1.3 void dtps_provide_module(void *arg, modctl_t *mp)
*
* 1.3.1 Overview
*
@ -1955,8 +2014,8 @@ typedef struct dof_helper {
* routines.
*/
typedef struct dtrace_pops {
void (*dtps_provide)(void *arg, const dtrace_probedesc_t *spec);
void (*dtps_provide_module)(void *arg, struct modctl *mp);
void (*dtps_provide)(void *arg, dtrace_probedesc_t *spec);
void (*dtps_provide_module)(void *arg, modctl_t *mp);
void (*dtps_enable)(void *arg, dtrace_id_t id, void *parg);
void (*dtps_disable)(void *arg, dtrace_id_t id, void *parg);
void (*dtps_suspend)(void *arg, dtrace_id_t id, void *parg);
@ -1976,8 +2035,8 @@ extern int dtrace_register(const char *, const dtrace_pattr_t *, uint32_t,
extern int dtrace_unregister(dtrace_provider_id_t);
extern int dtrace_condense(dtrace_provider_id_t);
extern void dtrace_invalidate(dtrace_provider_id_t);
extern dtrace_id_t dtrace_probe_lookup(dtrace_provider_id_t, const char *,
const char *, const char *);
extern dtrace_id_t dtrace_probe_lookup(dtrace_provider_id_t, char *,
char *, char *);
extern dtrace_id_t dtrace_probe_create(dtrace_provider_id_t, const char *,
const char *, const char *, int, void *);
extern void *dtrace_probe_arg(dtrace_provider_id_t, dtrace_id_t);
@ -2150,7 +2209,9 @@ typedef enum dtrace_vtime_state {
DTRACE_VTIME_ACTIVE_TNF /* DTrace virtual time _and_ TNF */
} dtrace_vtime_state_t;
#if defined(sun)
extern dtrace_vtime_state_t dtrace_vtime_active;
#endif
extern void dtrace_vtime_switch(kthread_t *next);
extern void dtrace_vtime_enable_tnf(void);
extern void dtrace_vtime_disable_tnf(void);
@ -2159,12 +2220,14 @@ extern void dtrace_vtime_disable(void);
struct regs;
#if defined(sun)
extern int (*dtrace_pid_probe_ptr)(struct regs *);
extern int (*dtrace_return_probe_ptr)(struct regs *);
extern void (*dtrace_fasttrap_fork_ptr)(proc_t *, proc_t *);
extern void (*dtrace_fasttrap_exec_ptr)(proc_t *);
extern void (*dtrace_fasttrap_exit_ptr)(proc_t *);
extern void dtrace_fasttrap_fork(proc_t *, proc_t *);
#endif
typedef uintptr_t dtrace_icookie_t;
typedef void (*dtrace_xcall_t)(void *);
@ -2176,18 +2239,22 @@ extern void dtrace_membar_producer(void);
extern void dtrace_membar_consumer(void);
extern void (*dtrace_cpu_init)(processorid_t);
extern void (*dtrace_modload)(struct modctl *);
extern void (*dtrace_modunload)(struct modctl *);
extern void (*dtrace_helpers_cleanup)();
extern void (*dtrace_modload)(modctl_t *);
extern void (*dtrace_modunload)(modctl_t *);
extern void (*dtrace_helpers_cleanup)(void);
extern void (*dtrace_helpers_fork)(proc_t *parent, proc_t *child);
extern void (*dtrace_cpustart_init)();
extern void (*dtrace_cpustart_fini)();
extern void (*dtrace_cpustart_init)(void);
extern void (*dtrace_cpustart_fini)(void);
extern void (*dtrace_debugger_init)();
extern void (*dtrace_debugger_fini)();
extern void (*dtrace_debugger_init)(void);
extern void (*dtrace_debugger_fini)(void);
extern dtrace_cacheid_t dtrace_predcache_id;
#if defined(sun)
extern hrtime_t dtrace_gethrtime(void);
#else
void dtrace_debug_printf(const char *, ...) __printflike(1, 2);
#endif
extern void dtrace_sync(void);
extern void dtrace_toxic_ranges(void (*)(uintptr_t, uintptr_t));
extern void dtrace_xcall(processorid_t, dtrace_xcall_t, void *);
@ -2213,13 +2280,13 @@ extern void dtrace_getfsr(uint64_t *);
#endif
#define DTRACE_CPUFLAG_ISSET(flag) \
(cpu_core[CPU->cpu_id].cpuc_dtrace_flags & (flag))
(cpu_core[curcpu].cpuc_dtrace_flags & (flag))
#define DTRACE_CPUFLAG_SET(flag) \
(cpu_core[CPU->cpu_id].cpuc_dtrace_flags |= (flag))
(cpu_core[curcpu].cpuc_dtrace_flags |= (flag))
#define DTRACE_CPUFLAG_CLEAR(flag) \
(cpu_core[CPU->cpu_id].cpuc_dtrace_flags &= ~(flag))
(cpu_core[curcpu].cpuc_dtrace_flags &= ~(flag))
#endif /* _KERNEL */

View File

@ -45,6 +45,14 @@ extern "C" {
*/
#include <sys/dtrace.h>
#if !defined(sun)
#ifdef __sparcv9
typedef uint32_t pc_t;
#else
typedef uintptr_t pc_t;
#endif
typedef u_long greg_t;
#endif
/*
* DTrace Implementation Constants and Typedefs
@ -114,13 +122,13 @@ struct dtrace_probe {
typedef int dtrace_probekey_f(const char *, const char *, int);
typedef struct dtrace_probekey {
const char *dtpk_prov; /* provider name to match */
char *dtpk_prov; /* provider name to match */
dtrace_probekey_f *dtpk_pmatch; /* provider matching function */
const char *dtpk_mod; /* module name to match */
char *dtpk_mod; /* module name to match */
dtrace_probekey_f *dtpk_mmatch; /* module matching function */
const char *dtpk_func; /* func name to match */
char *dtpk_func; /* func name to match */
dtrace_probekey_f *dtpk_fmatch; /* func matching function */
const char *dtpk_name; /* name to match */
char *dtpk_name; /* name to match */
dtrace_probekey_f *dtpk_nmatch; /* name matching function */
dtrace_id_t dtpk_id; /* identifier to match */
} dtrace_probekey_t;
@ -1099,7 +1107,11 @@ typedef struct dtrace_cred {
* dtrace_state structure.
*/
struct dtrace_state {
#if defined(sun)
dev_t dts_dev; /* device */
#else
struct cdev *dts_dev; /* device */
#endif
int dts_necbs; /* total number of ECBs */
dtrace_ecb_t **dts_ecbs; /* array of ECBs */
dtrace_epid_t dts_epid; /* next EPID to allocate */
@ -1113,7 +1125,11 @@ struct dtrace_state {
int dts_nspeculations; /* number of speculations */
int dts_naggregations; /* number of aggregations */
dtrace_aggregation_t **dts_aggregations; /* aggregation array */
#if defined(sun)
vmem_t *dts_aggid_arena; /* arena for aggregation IDs */
#else
struct unrhdr *dts_aggid_arena; /* arena for aggregation IDs */
#endif
uint64_t dts_errors; /* total number of errors */
uint32_t dts_speculations_busy; /* number of spec. busy */
uint32_t dts_speculations_unavail; /* number of spec unavail */
@ -1238,7 +1254,7 @@ extern greg_t dtrace_getfp(void);
extern int dtrace_getipl(void);
extern uintptr_t dtrace_caller(int);
extern uint32_t dtrace_cas32(uint32_t *, uint32_t, uint32_t);
extern void *dtrace_casptr(void *, void *, void *);
extern void *dtrace_casptr(volatile void *, volatile void *, volatile void *);
extern void dtrace_copyin(uintptr_t, uintptr_t, size_t, volatile uint16_t *);
extern void dtrace_copyinstr(uintptr_t, uintptr_t, size_t, volatile uint16_t *);
extern void dtrace_copyout(uintptr_t, uintptr_t, size_t, volatile uint16_t *);
@ -1259,7 +1275,9 @@ extern void dtrace_probe_error(dtrace_state_t *, dtrace_epid_t, int, int,
int, uintptr_t);
extern int dtrace_assfail(const char *, const char *, int);
extern int dtrace_attached(void);
extern hrtime_t dtrace_gethrestime();
#if defined(sun)
extern hrtime_t dtrace_gethrestime(void);
#endif
#ifdef __sparc
extern void dtrace_flush_windows(void);

View File

@ -206,6 +206,9 @@
* This indicates that the implementation uses a dynamically
* linked unix + krtld to form the core kernel image at boot
* time, or (in the absence of this symbol) a prelinked kernel image.
*
* _OBP
* This indicates the firmware interface is OBP.
*/
#ifdef __cplusplus
@ -216,7 +219,7 @@ extern "C" {
* The following set of definitions characterize Solaris on AMD's
* 64-bit systems.
*/
#if defined(__x86_64) || defined(__amd64)
#if defined(__x86_64) || defined(__amd64) || defined(__ia64__)
#if !defined(__amd64)
#define __amd64 /* preferred guard */
@ -336,6 +339,51 @@ extern "C" {
#define _DONT_USE_1275_GENERIC_NAMES
#define _HAVE_CPUID_INSN
#elif defined(__arm__)
/*
* Define the appropriate "processor characteristics"
*/
#define _STACK_GROWS_DOWNWARD
#define _LONG_LONG_LTOH
#define _BIT_FIELDS_LTOH
#define _IEEE_754
#define _CHAR_IS_SIGNED
#define _BOOL_ALIGNMENT 1
#define _CHAR_ALIGNMENT 1
#define _SHORT_ALIGNMENT 2
#define _INT_ALIGNMENT 4
#define _FLOAT_ALIGNMENT 4
#define _FLOAT_COMPLEX_ALIGNMENT 4
#define _LONG_ALIGNMENT 4
#define _LONG_LONG_ALIGNMENT 4
#define _DOUBLE_ALIGNMENT 4
#define _DOUBLE_COMPLEX_ALIGNMENT 4
#define _LONG_DOUBLE_ALIGNMENT 4
#define _LONG_DOUBLE_COMPLEX_ALIGNMENT 4
#define _POINTER_ALIGNMENT 4
#define _MAX_ALIGNMENT 4
#define _ALIGNMENT_REQUIRED 0
#define _LONG_LONG_ALIGNMENT_32 _LONG_LONG_ALIGNMENT
/*
* Define the appropriate "implementation choices".
*/
#define _ILP32
#if !defined(_I32LPx) && defined(_KERNEL)
#define _I32LPx
#endif
#define _SUNOS_VTOC_16
#define _DMA_USES_PHYSADDR
#define _FIRMWARE_NEEDS_FDISK
#define _PSM_MODULES
#define _RTC_CONFIG
#define _DONT_USE_1275_GENERIC_NAMES
#define _HAVE_CPUID_INSN
#elif defined(__powerpc__)
/*
* The following set of definitions characterize the Solaris on SPARC systems.
*
@ -408,7 +456,7 @@ extern "C" {
#define _DMA_USES_VIRTADDR
#define _NO_FDISK_PRESENT
#define _HAVE_TEM_FIRMWARE
#define _UNIX_KRTLD
#define _OBP
/*
* The following set of definitions characterize the implementation of