X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/143464d58d2bd6378e74eec636961ceb0d32fb91..fe8ab488e9161c46dd9885d58fc52996dc0249ff:/bsd/dev/dtrace/profile_prvd.c?ds=sidebyside diff --git a/bsd/dev/dtrace/profile_prvd.c b/bsd/dev/dtrace/profile_prvd.c index 60ebf9bd7..eb5ada1bb 100644 --- a/bsd/dev/dtrace/profile_prvd.c +++ b/bsd/dev/dtrace/profile_prvd.c @@ -25,21 +25,6 @@ /* #pragma ident "@(#)profile.c 1.7 07/01/10 SMI" */ -#if !defined(__APPLE__) -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#else #ifdef KERNEL #ifndef _KERNEL #define _KERNEL /* Solaris vs. Darwin */ @@ -77,7 +62,6 @@ extern x86_saved_state_t *find_kern_regs(thread_t); #define ASSERT(x) do {} while(0) extern void profile_init(void); -#endif /* __APPLE__ */ static dev_info_t *profile_devi; static dtrace_provider_id_t profile_id; @@ -176,16 +160,12 @@ profile_fire(void *arg) late = dtrace_gethrtime() - pcpu->profc_expected; pcpu->profc_expected += pcpu->profc_interval; -#if !defined(__APPLE__) - dtrace_probe(prof->prof_id, CPU->cpu_profile_pc, - CPU->cpu_profile_upc, late, 0, 0); -#else #if defined(__x86_64__) x86_saved_state_t *kern_regs = find_kern_regs(current_thread()); if (NULL != kern_regs) { /* Kernel was interrupted. */ - dtrace_probe(prof->prof_id, saved_state64(kern_regs)->isf.rip, 0x0, 0, 0, 0); + dtrace_probe(prof->prof_id, saved_state64(kern_regs)->isf.rip, 0x0, late, 0, 0); } else { pal_register_cache_state(current_thread(), VALID); @@ -195,21 +175,20 @@ profile_fire(void *arg) if (NULL == tagged_regs) { /* Too bad, so sad, no useful interrupt state. */ dtrace_probe(prof->prof_id, 0xcafebabe, - 0x0, 0, 0, 0); /* XXX_BOGUS also see profile_usermode() below. */ + 0x0, late, 0, 0); /* XXX_BOGUS also see profile_usermode() below. */ } else if (is_saved_state64(tagged_regs)) { x86_saved_state64_t *regs = saved_state64(tagged_regs); - dtrace_probe(prof->prof_id, 0x0, regs->isf.rip, 0, 0, 0); + dtrace_probe(prof->prof_id, 0x0, regs->isf.rip, late, 0, 0); } else { x86_saved_state32_t *regs = saved_state32(tagged_regs); - dtrace_probe(prof->prof_id, 0x0, regs->eip, 0, 0, 0); + dtrace_probe(prof->prof_id, 0x0, regs->eip, late, 0, 0); } } #else #error Unknown architecture #endif -#endif /* __APPLE__ */ } static void @@ -217,10 +196,6 @@ profile_tick(void *arg) { profile_probe_t *prof = arg; -#if !defined(__APPLE__) - dtrace_probe(prof->prof_id, CPU->cpu_profile_pc, - CPU->cpu_profile_upc, 0, 0, 0); -#else #if defined(__x86_64__) x86_saved_state_t *kern_regs = find_kern_regs(current_thread()); @@ -249,7 +224,6 @@ profile_tick(void *arg) #else #error Unknown architecture #endif -#endif /* __APPLE__ */ } static void @@ -269,14 +243,11 @@ profile_create(hrtime_t interval, const char *name, int kind) return; } -#if !defined(__APPLE__) - prof = kmem_zalloc(sizeof (profile_probe_t), KM_SLEEP); -#else if (PROF_TICK == kind) prof = kmem_zalloc(sizeof (profile_probe_t), KM_SLEEP); else prof = kmem_zalloc(sizeof (profile_probe_t) + NCPU*sizeof(profile_probe_percpu_t), KM_SLEEP); -#endif /* __APPLE__ */ + (void) strlcpy(prof->prof_name, name, sizeof(prof->prof_name)); prof->prof_interval = interval; prof->prof_cyclic = CYCLIC_NONE; @@ -295,38 +266,6 @@ profile_provide(void *arg, const dtrace_probedesc_t *desc) hrtime_t val = 0, mult = 1, len; const char *name, *suffix = NULL; -#if !defined(__APPLE__) - const struct { - char *prefix; - int kind; - } types[] = { - { PROF_PREFIX_PROFILE, PROF_PROFILE }, - { PROF_PREFIX_TICK, PROF_TICK }, - { NULL, NULL } - }; - - const struct { - char *name; - hrtime_t mult; - } suffixes[] = { - { "ns", NANOSEC / NANOSEC }, - { "nsec", NANOSEC / NANOSEC }, - { "us", NANOSEC / MICROSEC }, - { "usec", NANOSEC / MICROSEC }, - { "ms", NANOSEC / MILLISEC }, - { "msec", NANOSEC / MILLISEC }, - { "s", NANOSEC / SEC }, - { "sec", NANOSEC / SEC }, - { "m", NANOSEC * (hrtime_t)60 }, - { "min", NANOSEC * (hrtime_t)60 }, - { "h", NANOSEC * (hrtime_t)(60 * 60) }, - { "hour", NANOSEC * (hrtime_t)(60 * 60) }, - { "d", NANOSEC * (hrtime_t)(24 * 60 * 60) }, - { "day", NANOSEC * (hrtime_t)(24 * 60 * 60) }, - { "hz", 0 }, - { NULL } - }; -#else const struct { const char *prefix; int kind; @@ -357,8 +296,6 @@ profile_provide(void *arg, const dtrace_probedesc_t *desc) { "hz", 0 }, { NULL, 0 } }; -#endif /* __APPLE__ */ - if (desc == NULL) { char n[PROF_NAMELEN]; @@ -366,11 +303,7 @@ profile_provide(void *arg, const dtrace_probedesc_t *desc) /* * If no description was provided, provide all of our probes. */ -#if !defined(__APPLE__) - for (i = 0; i < sizeof (profile_rates) / sizeof (int); i++) { -#else for (i = 0; i < (int)(sizeof (profile_rates) / sizeof (int)); i++) { -#endif /* __APPLE__ */ if ((rate = profile_rates[i]) == 0) continue; @@ -379,11 +312,7 @@ profile_provide(void *arg, const dtrace_probedesc_t *desc) profile_create(NANOSEC / rate, n, PROF_PROFILE); } -#if !defined(__APPLE__) - for (i = 0; i < sizeof (profile_ticks) / sizeof (int); i++) { -#else for (i = 0; i < (int)(sizeof (profile_ticks) / sizeof (int)); i++) { -#endif /* __APPLE__ */ if ((rate = profile_ticks[i]) == 0) continue; @@ -440,17 +369,11 @@ profile_provide(void *arg, const dtrace_probedesc_t *desc) * Look-up the suffix to determine the multiplier. */ for (i = 0, mult = 0; suffixes[i].name != NULL; i++) { -#if !defined(__APPLE__) - if (strcasecmp(suffixes[i].name, suffix) == 0) { - mult = suffixes[i].mult; - break; - } -#else + /* APPLE NOTE: Darwin employs size bounded string operations */ if (strncasecmp(suffixes[i].name, suffix, strlen(suffixes[i].name) + 1) == 0) { mult = suffixes[i].mult; break; } -#endif /* __APPLE__ */ } if (suffixes[i].name == NULL && *suffix != '\0') @@ -476,14 +399,11 @@ profile_destroy(void *arg, dtrace_id_t id, void *parg) profile_probe_t *prof = parg; ASSERT(prof->prof_cyclic == CYCLIC_NONE); -#if !defined(__APPLE__) - kmem_free(prof, sizeof (profile_probe_t)); -#else + if (prof->prof_kind == PROF_TICK) kmem_free(prof, sizeof (profile_probe_t)); else kmem_free(prof, sizeof (profile_probe_t) + NCPU*sizeof(profile_probe_percpu_t)); -#endif /* __APPLE__ */ ASSERT(profile_total >= 1); atomic_add_32(&profile_total, -1); @@ -497,11 +417,7 @@ profile_online(void *arg, dtrace_cpu_t *cpu, cyc_handler_t *hdlr, cyc_time_t *wh profile_probe_t *prof = arg; profile_probe_percpu_t *pcpu; -#if !defined(__APPLE__) - pcpu = kmem_zalloc(sizeof (profile_probe_percpu_t), KM_SLEEP); -#else pcpu = ((profile_probe_percpu_t *)(&(prof[1]))) + cpu_number(); -#endif /* __APPLE__ */ pcpu->profc_probe = prof; hdlr->cyh_func = profile_fire; @@ -509,11 +425,7 @@ profile_online(void *arg, dtrace_cpu_t *cpu, cyc_handler_t *hdlr, cyc_time_t *wh hdlr->cyh_level = CY_HIGH_LEVEL; when->cyt_interval = prof->prof_interval; -#if !defined(__APPLE__) when->cyt_when = dtrace_gethrtime() + when->cyt_interval; -#else - when->cyt_when = 0; -#endif /* __APPLE__ */ pcpu->profc_expected = when->cyt_when; pcpu->profc_interval = when->cyt_interval; @@ -526,11 +438,7 @@ profile_offline(void *arg, dtrace_cpu_t *cpu, void *oarg) profile_probe_percpu_t *pcpu = oarg; ASSERT(pcpu->profc_probe == arg); -#if !defined(__APPLE__) - kmem_free(pcpu, sizeof (profile_probe_percpu_t)); -#else #pragma unused(pcpu,arg,cpu) /* __APPLE__ */ -#endif /* __APPLE__ */ } /*ARGSUSED*/ @@ -564,19 +472,12 @@ profile_enable(void *arg, dtrace_id_t id, void *parg) omni.cyo_arg = prof; } -#if !defined(__APPLE__) - if (prof->prof_kind == PROF_TICK) { - prof->prof_cyclic = cyclic_add(&hdlr, &when); - } else { - prof->prof_cyclic = cyclic_add_omni(&omni); - } -#else if (prof->prof_kind == PROF_TICK) { prof->prof_cyclic = cyclic_timer_add(&hdlr, &when); } else { prof->prof_cyclic = (cyclic_id_t)cyclic_add_omni(&omni); /* cast puns cyclic_id_list_t with cyclic_id_t */ } -#endif /* __APPLE__ */ + return(0); } @@ -589,34 +490,24 @@ profile_disable(void *arg, dtrace_id_t id, void *parg) ASSERT(prof->prof_cyclic != CYCLIC_NONE); ASSERT(MUTEX_HELD(&cpu_lock)); -#if !defined(__APPLE__) - cyclic_remove(prof->prof_cyclic); -#else #pragma unused(arg,id) if (prof->prof_kind == PROF_TICK) { cyclic_timer_remove(prof->prof_cyclic); } else { cyclic_remove_omni((cyclic_id_list_t)prof->prof_cyclic); /* cast puns cyclic_id_list_t with cyclic_id_t */ } -#endif /* __APPLE__ */ prof->prof_cyclic = CYCLIC_NONE; } -#if !defined(__APPLE__) -/*ARGSUSED*/ -static int -profile_usermode(void *arg, dtrace_id_t id, void *parg) -{ - return (CPU->cpu_profile_pc == 0); -} -#else +/* + * APPLE NOTE: profile_usermode call not supported. + */ static int profile_usermode(void *arg, dtrace_id_t id, void *parg) { #pragma unused(arg,id,parg) return 1; /* XXX_BOGUS */ } -#endif /* __APPLE__ */ static dtrace_pattr_t profile_attr = { { DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON }, @@ -651,19 +542,6 @@ profile_attach(dev_info_t *devi, ddi_attach_cmd_t cmd) return (DDI_FAILURE); } -#if !defined(__APPLE__) - if (ddi_create_minor_node(devi, "profile", S_IFCHR, 0, - DDI_PSEUDO, NULL) == DDI_FAILURE || - dtrace_register("profile", &profile_attr, - DTRACE_PRIV_KERNEL | DTRACE_PRIV_USER, NULL, - &profile_pops, NULL, &profile_id) != 0) { - ddi_remove_minor_node(devi, NULL); - return (DDI_FAILURE); - } - - profile_max = ddi_getprop(DDI_DEV_T_ANY, devi, DDI_PROP_DONTPASS, - "profile-max-probes", PROFILE_MAX_DEFAULT); -#else if (ddi_create_minor_node(devi, "profile", S_IFCHR, 0, DDI_PSEUDO, 0) == DDI_FAILURE || dtrace_register("profile", &profile_attr, @@ -674,13 +552,15 @@ profile_attach(dev_info_t *devi, ddi_attach_cmd_t cmd) } profile_max = PROFILE_MAX_DEFAULT; -#endif /* __APPLE__ */ ddi_report_dev(devi); profile_devi = devi; return (DDI_SUCCESS); } +/* + * APPLE NOTE: profile_detach not implemented + */ #if !defined(__APPLE__) static int profile_detach(dev_info_t *devi, ddi_detach_cmd_t cmd) @@ -700,100 +580,8 @@ profile_detach(dev_info_t *devi, ddi_detach_cmd_t cmd) ddi_remove_minor_node(devi, NULL); return (DDI_SUCCESS); } +#endif /* __APPLE__ */ -/*ARGSUSED*/ -static int -profile_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result) -{ - int error; - - switch (infocmd) { - case DDI_INFO_DEVT2DEVINFO: - *result = (void *)profile_devi; - error = DDI_SUCCESS; - break; - case DDI_INFO_DEVT2INSTANCE: - *result = (void *)0; - error = DDI_SUCCESS; - break; - default: - error = DDI_FAILURE; - } - return (error); -} - -/*ARGSUSED*/ -static int -profile_open(dev_t *devp, int flag, int otyp, cred_t *cred_p) -{ - return (0); -} - -static struct cb_ops profile_cb_ops = { - profile_open, /* open */ - nodev, /* close */ - nulldev, /* strategy */ - nulldev, /* print */ - nodev, /* dump */ - nodev, /* read */ - nodev, /* write */ - nodev, /* ioctl */ - nodev, /* devmap */ - nodev, /* mmap */ - nodev, /* segmap */ - nochpoll, /* poll */ - ddi_prop_op, /* cb_prop_op */ - 0, /* streamtab */ - D_NEW | D_MP /* Driver compatibility flag */ -}; - -static struct dev_ops profile_ops = { - DEVO_REV, /* devo_rev, */ - 0, /* refcnt */ - profile_info, /* get_dev_info */ - nulldev, /* identify */ - nulldev, /* probe */ - profile_attach, /* attach */ - profile_detach, /* detach */ - nodev, /* reset */ - &profile_cb_ops, /* driver operations */ - NULL, /* bus operations */ - nodev /* dev power */ -}; - -/* - * Module linkage information for the kernel. - */ -static struct modldrv modldrv = { - &mod_driverops, /* module type (this is a pseudo driver) */ - "Profile Interrupt Tracing", /* name of module */ - &profile_ops, /* driver ops */ -}; - -static struct modlinkage modlinkage = { - MODREV_1, - (void *)&modldrv, - NULL -}; - -int -_init(void) -{ - return (mod_install(&modlinkage)); -} - -int -_info(struct modinfo *modinfop) -{ - return (mod_info(&modlinkage, modinfop)); -} - -int -_fini(void) -{ - return (mod_remove(&modlinkage)); -} -#else d_open_t _profile_open; int _profile_open(dev_t dev, int flags, int devtype, struct proc *p) @@ -847,4 +635,3 @@ void profile_init( void ) panic("profile_init: called twice!\n"); } #undef PROFILE_MAJOR -#endif /* __APPLE__ */