From owner-p4-projects@FreeBSD.ORG Tue Feb 5 07:20:14 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id BDEFC16A46B; Tue, 5 Feb 2008 07:20:13 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6ABA316A417 for ; Tue, 5 Feb 2008 07:20:13 +0000 (UTC) (envelope-from jb@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 5C5F713C46E for ; Tue, 5 Feb 2008 07:20:13 +0000 (UTC) (envelope-from jb@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id m157KD3F006969 for ; Tue, 5 Feb 2008 07:20:13 GMT (envelope-from jb@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id m157KD1e006963 for perforce@freebsd.org; Tue, 5 Feb 2008 07:20:13 GMT (envelope-from jb@freebsd.org) Date: Tue, 5 Feb 2008 07:20:13 GMT Message-Id: <200802050720.m157KD1e006963@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to jb@freebsd.org using -f From: John Birrell To: Perforce Change Reviews Cc: Subject: PERFORCE change 134826 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Feb 2008 07:20:14 -0000 http://perforce.freebsd.org/chv.cgi?CH=134826 Change 134826 by jb@jb_freebsd1 on 2008/02/05 07:20:02 WIP. Perforce is my backup server. :-P Affected files ... .. //depot/projects/dtrace/src/sys/cddl/dev/fasttrap/fasttrap.c#7 edit Differences ... ==== //depot/projects/dtrace/src/sys/cddl/dev/fasttrap/fasttrap.c#7 (text+ko) ==== @@ -158,9 +158,7 @@ #define FASTTRAP_PID_NAME "pid" -#ifdef DOODAD -static struct callout_handle fasttrap_timeout; -#endif +static struct callout_handle fasttrap_timeout = CALLOUT_HANDLE_INITIALIZER(&fasttrap_timeout); static struct mtx fasttrap_cleanup_mtx; MTX_SYSINIT(fasttrap_cleanup_mtx, &fasttrap_cleanup_mtx, "Fasttrap cleanup", MTX_DEF); static uint_t fasttrap_cleanup_work; @@ -177,22 +175,16 @@ #define FASTTRAP_ENABLE_FAIL 1 #define FASTTRAP_ENABLE_PARTIAL 2 -#ifdef DOODAD static int fasttrap_tracepoint_enable(proc_t *, fasttrap_probe_t *, uint_t); static void fasttrap_tracepoint_disable(proc_t *, fasttrap_probe_t *, uint_t); -#endif -#ifdef DOODAD static fasttrap_provider_t *fasttrap_provider_lookup(pid_t, const char *, const dtrace_pattr_t *); -#endif static void fasttrap_provider_free(fasttrap_provider_t *); static void fasttrap_provider_retire(pid_t, const char *, int); -#ifdef DOODAD static fasttrap_proc_t *fasttrap_proc_lookup(pid_t); static void fasttrap_proc_release(fasttrap_proc_t *); -#endif #define FASTTRAP_PROVS_INDEX(pid, name) \ ((fasttrap_hash_str(name) + (pid)) & fasttrap_provs.fth_mask) @@ -264,7 +256,6 @@ #endif } -#ifdef DOODAD /* * This function ensures that no threads are actively using the memory * associated with probes that were formerly live. @@ -272,6 +263,8 @@ static void fasttrap_mod_barrier(uint64_t gen) { +printf("%s(%d): DOODAD\n",__func__,__LINE__); +#ifdef DOODAD int i; if (gen < fasttrap_mod_gen) @@ -283,10 +276,9 @@ mtx_lock(&cpu_core[i].cpuc_pid_lock); mtx_unlock(&cpu_core[i].cpuc_pid_lock); } +#endif } -#endif -#ifdef DOODAD /* * This is the timeout's callback for cleaning up the providers and their * probes. @@ -297,7 +289,7 @@ fasttrap_provider_t **fpp, *fp; fasttrap_bucket_t *bucket; dtrace_provider_id_t provid; - int i, later; + int i, later = 0; static volatile int in = 0; ASSERT(in == 0); @@ -385,19 +377,16 @@ * get a chance to do that work if and when the timeout is reenabled * (if detach fails). */ -#ifdef DOODAD - if (later > 0 && fasttrap_timeout != (struct callout_handle)1) + if (later > 0 && fasttrap_timeout.callout != (struct callout *)(uintptr_t)1) fasttrap_timeout = timeout(&fasttrap_pid_cleanup_cb, NULL, hz); else if (later > 0) fasttrap_cleanup_work = 1; else - fasttrap_timeout = 0; -#endif + fasttrap_timeout.callout = NULL; mtx_unlock(&fasttrap_cleanup_mtx); in = 0; } -#endif /* * Activates the asynchronous cleanup mechanism. @@ -405,13 +394,10 @@ static void fasttrap_pid_cleanup(void) { -printf("%s(%d): DOODAD\n",__func__,__LINE__); mtx_lock(&fasttrap_cleanup_mtx); fasttrap_cleanup_work = 1; -#ifdef DOODAD - if (fasttrap_timeout == 0) + if (fasttrap_timeout.callout == NULL) fasttrap_timeout = timeout(&fasttrap_pid_cleanup_cb, NULL, 1); -#endif mtx_unlock(&fasttrap_cleanup_mtx); } @@ -422,7 +408,11 @@ pid_t ppid = p->p_pid; int i; +#ifdef DOODAD ASSERT(curproc == p); +#else + if (curproc != p) printf("%s(%d): Warning curproc != p\n",__func__,__LINE__); +#endif /* * This would be simpler and faster if we maintained per-process @@ -477,9 +467,9 @@ /* * There are no "default" pid probes. */ +printf("%s(%d): There are no default pid probes\n",__func__,__LINE__); } -#ifdef DOODAD static int fasttrap_tracepoint_enable(proc_t *p, fasttrap_probe_t *probe, uint_t index) { @@ -497,8 +487,6 @@ ASSERT(probe->ftp_tps[index].fit_tp->ftt_pid == pid); - ASSERT(!(p->p_flag & SVFORK)); - /* * Before we make any modifications, make sure we've imposed a barrier * on the generation in which this probe was last modified. @@ -516,7 +504,9 @@ * * A tracepoint whose process is defunct is also considered defunct. */ +#ifdef DOODAD again: +#endif mtx_lock(&bucket->ftb_mtx); for (tp = bucket->ftb_data; tp != NULL; tp = tp->ftt_next) { if (tp->ftt_pid != pid || tp->ftt_pc != pc || @@ -544,17 +534,25 @@ case DTFTP_OFFSETS: case DTFTP_IS_ENABLED: id->fti_next = tp->ftt_ids; +#ifdef DOODAD membar_producer(); +#endif tp->ftt_ids = id; +#ifdef DOODAD membar_producer(); +#endif break; case DTFTP_RETURN: case DTFTP_POST_OFFSETS: id->fti_next = tp->ftt_retids; +#ifdef DOODAD membar_producer(); +#endif tp->ftt_retids = id; +#ifdef DOODAD membar_producer(); +#endif break; default: @@ -579,9 +577,13 @@ int rc = 0; new_tp->ftt_next = bucket->ftb_data; +#ifdef DOODAD membar_producer(); +#endif bucket->ftb_data = new_tp; +#ifdef DOODAD membar_producer(); +#endif mtx_unlock(&bucket->ftb_mtx); /* @@ -597,8 +599,10 @@ * Increment the count of the number of tracepoints active in * the victim process. */ +#ifdef DOODAD ASSERT(p->p_proc_flag & P_PR_LOCK); p->p_dtrace_count++; +#endif return (rc); } @@ -634,21 +638,22 @@ ASSERT(0); } +printf("%s(%d): DOODAD\n",__func__,__LINE__); +#ifdef DOODAD /* * If the ISA-dependent initialization goes to plan, go back to the * beginning and try to install this freshly made tracepoint. */ if (fasttrap_tracepoint_init(p, new_tp, pc, id->fti_ptype) == 0) goto again; +#endif new_tp->ftt_ids = NULL; new_tp->ftt_retids = NULL; return (FASTTRAP_ENABLE_FAIL); } -#endif -#ifdef DOODAD static void fasttrap_tracepoint_disable(proc_t *p, fasttrap_probe_t *probe, uint_t index) { @@ -709,7 +714,9 @@ id = *idp; *idp = id->fti_next; +#ifdef DOODAD membar_producer(); +#endif ASSERT(id->fti_probe == probe); @@ -792,8 +799,10 @@ * Decrement the count of the number of tracepoints active * in the victim process. */ +#ifdef DOODAD ASSERT(p->p_proc_flag & P_PR_LOCK); p->p_dtrace_count--; +#endif } /* @@ -808,7 +817,9 @@ } *pp = tp->ftt_next; +#ifdef DOODAD membar_producer(); +#endif mtx_unlock(&bucket->ftb_mtx); @@ -817,10 +828,8 @@ */ probe->ftp_gen = fasttrap_mod_gen; } -#endif -#ifdef DOODAD -static void +static void __unused fasttrap_enable_callbacks(void) { /* @@ -830,6 +839,8 @@ * function pointer yet. */ mtx_lock(&fasttrap_count_mtx); +printf("%s(%d): DOODAD\n",__func__,__LINE__); +#ifdef DOODAD if (fasttrap_pid_count == 0) { ASSERT(dtrace_pid_probe_ptr == NULL); ASSERT(dtrace_return_probe_ptr == NULL); @@ -838,18 +849,19 @@ } ASSERT(dtrace_pid_probe_ptr == &fasttrap_pid_probe); ASSERT(dtrace_return_probe_ptr == &fasttrap_return_probe); +#endif fasttrap_pid_count++; mtx_unlock(&fasttrap_count_mtx); } -#endif -#ifdef DOODAD -static void +static void __unused fasttrap_disable_callbacks(void) { ASSERT(MUTEX_HELD(&cpu_lock)); mtx_lock(&fasttrap_count_mtx); +printf("%s(%d): DOODAD\n",__func__,__LINE__); +#ifdef DOODAD ASSERT(fasttrap_pid_count > 0); fasttrap_pid_count--; if (fasttrap_pid_count == 0) { @@ -868,15 +880,13 @@ rw_exit(&cur->cpu_ft_lock); } } +#endif mtx_unlock(&fasttrap_count_mtx); } -#endif static void fasttrap_pid_enable(void *arg, dtrace_id_t id, void *parg) { -printf("%s(%d): DOODAD\n",__func__,__LINE__); -#ifdef DOODAD fasttrap_probe_t *probe = parg; proc_t *p; int i, rc; @@ -904,6 +914,8 @@ if (probe->ftp_prov->ftp_retired) return; +printf("%s(%d): DOODAD\n",__func__,__LINE__); +#ifdef DOODAD /* * If we can't find the process, it may be that we're in the context of * a fork in which the traced process is being born and we're copying @@ -932,6 +944,9 @@ ASSERT(!(p->p_flag & SVFORK)); mtx_unlock(&p->p_lock); +#else + p = pfind(probe->ftp_pid); +#endif /* * We have to enable the trap entry point before any user threads have @@ -965,8 +980,10 @@ i--; } +#ifdef DOODAD mtx_lock(&p->p_lock); sprunlock(p); +#endif /* * Since we're not actually enabling this probe, @@ -977,11 +994,12 @@ } } +#ifdef DOODAD mtx_lock(&p->p_lock); sprunlock(p); +#endif probe->ftp_enabled = 1; -#endif } static void @@ -1135,7 +1153,7 @@ { DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN }, }; -static dtrace_pops_t pid_pops __unused = { +static dtrace_pops_t pid_pops = { fasttrap_pid_provide, NULL, fasttrap_pid_enable, @@ -1143,12 +1161,12 @@ NULL, NULL, fasttrap_pid_getargdesc, - fasttrap_pid_getarg, + NULL /*fasttrap_pid_getarg*/, NULL, fasttrap_pid_destroy }; -static dtrace_pops_t usdt_pops __unused = { +static dtrace_pops_t usdt_pops = { fasttrap_pid_provide, NULL, fasttrap_pid_enable, @@ -1156,12 +1174,11 @@ NULL, NULL, fasttrap_pid_getargdesc, - fasttrap_usdt_getarg, + NULL /*fasttrap_usdt_getarg*/, NULL, fasttrap_pid_destroy }; -#ifdef DOODAD static fasttrap_proc_t * fasttrap_proc_lookup(pid_t pid) { @@ -1221,9 +1238,7 @@ return (new_fprc); } -#endif -#ifdef DOODAD static void fasttrap_proc_release(fasttrap_proc_t *proc) { @@ -1270,9 +1285,7 @@ kmem_free(fprc, sizeof (fasttrap_proc_t)); } -#endif -#ifdef DOODAD /* * Lookup a fasttrap-managed provider based on its name and associated pid. * If the pattr argument is non-NULL, this function instantiates the provider @@ -1287,7 +1300,9 @@ fasttrap_bucket_t *bucket; char provname[DTRACE_PROVNAMELEN]; proc_t *p; +#ifdef DOODAD cred_t *cred; +#endif ASSERT(strlen(name) < sizeof (fp->ftp_name)); ASSERT(pattr != NULL); @@ -1313,6 +1328,7 @@ */ mtx_unlock(&bucket->ftb_mtx); +#ifdef DOODAD /* * Make sure the process exists, isn't a child created as the result * of a vfork(2), and isn't a zombie (but may be in fork). @@ -1345,6 +1361,9 @@ cred = p->p_cred; mtx_unlock(&p->p_crlock); mtx_unlock(&p->p_lock); +#else + p = pfind(pid); +#endif new_fp = kmem_zalloc(sizeof (fasttrap_provider_t), KM_SLEEP); new_fp->ftp_pid = pid; @@ -1364,7 +1383,9 @@ mtx_lock(&fp->ftp_mtx); mtx_unlock(&bucket->ftb_mtx); fasttrap_provider_free(new_fp); +#ifdef DOODAD crfree(cred); +#endif return (fp); } } @@ -1378,15 +1399,19 @@ * the full provider name -- we keep it in pieces in the provider * structure. */ +printf("%s(%d): provname '%s%u'\n", __func__, __LINE__, name, (uint_t)pid); if (snprintf(provname, sizeof (provname), "%s%u", name, (uint_t)pid) >= sizeof (provname) || dtrace_register(provname, pattr, - DTRACE_PRIV_PROC | DTRACE_PRIV_OWNER | DTRACE_PRIV_ZONEOWNER, cred, + DTRACE_PRIV_PROC | DTRACE_PRIV_OWNER | DTRACE_PRIV_ZONEOWNER, NULL /*cred*/, pattr == &pid_attr ? &pid_pops : &usdt_pops, new_fp, &new_fp->ftp_provid) != 0) { +printf("%s(%d): could not register!\n",__func__,__LINE__); mtx_unlock(&bucket->ftb_mtx); fasttrap_provider_free(new_fp); +#ifdef DOODAD crfree(cred); +#endif return (NULL); } @@ -1396,10 +1421,11 @@ mtx_lock(&new_fp->ftp_mtx); mtx_unlock(&bucket->ftb_mtx); +#ifdef DOODAD crfree(cred); +#endif return (new_fp); } -#endif static void fasttrap_provider_free(fasttrap_provider_t *provider) @@ -1408,6 +1434,7 @@ #ifdef DOODAD pid_t pid = provider->ftp_pid; proc_t *p; +#endif /* * There need to be no associated enabled probes, no consumers @@ -1421,6 +1448,7 @@ kmem_free(provider, sizeof (fasttrap_provider_t)); +#ifdef DOODAD /* * Decrement p_dtrace_probes on the process whose provider we're * freeing. We don't have to worry about clobbering somone else's @@ -1506,25 +1534,20 @@ fasttrap_pid_cleanup(); } -#ifdef DOODAD -static int +static int __unused fasttrap_uint32_cmp(const void *ap, const void *bp) { return (*(const uint32_t *)ap - *(const uint32_t *)bp); } -#endif -#ifdef DOODAD static int fasttrap_uint64_cmp(const void *ap, const void *bp) { return (*(const uint64_t *)ap - *(const uint64_t *)bp); } -#endif -#ifdef DOODAD -static int -fasttrap_add_probe(fasttrap_probe_spec_t *pdata) +static int __unused +fasttrap_add_probe (fasttrap_probe_spec_t *pdata) { fasttrap_provider_t *provider; fasttrap_probe_t *pp; @@ -1704,13 +1727,10 @@ return (ENOMEM); } -#endif static void * fasttrap_meta_provide(void *arg, dtrace_helper_provdesc_t *dhpv, pid_t pid) { -printf("%s(%d): DOODAD\n",__func__,__LINE__); -#ifdef DOODAD fasttrap_provider_t *provider; /* @@ -1720,8 +1740,7 @@ */ if (strlen(dhpv->dthpv_provname) + 10 >= sizeof (provider->ftp_name)) { - cmn_err(CE_WARN, "failed to instantiate provider %s: " - "name too long to accomodate pid", dhpv->dthpv_provname); + printf("failed to instantiate provider %s: name too long to accomodate pid\n", dhpv->dthpv_provname); return (NULL); } @@ -1729,8 +1748,7 @@ * Don't let folks spoof the true pid provider. */ if (strcmp(dhpv->dthpv_provname, FASTTRAP_PID_NAME) == 0) { - cmn_err(CE_WARN, "failed to instantiate provider %s: " - "%s is an invalid name", dhpv->dthpv_provname, + printf("failed to instantiate provider %s: %s is an invalid name\n", dhpv->dthpv_provname, FASTTRAP_PID_NAME); return (NULL); } @@ -1752,8 +1770,7 @@ if ((provider = fasttrap_provider_lookup(pid, dhpv->dthpv_provname, &dhpv->dthpv_pattr)) == NULL) { - cmn_err(CE_WARN, "failed to instantiate provider %s for " - "process %u", dhpv->dthpv_provname, (uint_t)pid); + printf("failed to instantiate provider %s for process %u\n", dhpv->dthpv_provname, (uint_t)pid); return (NULL); } @@ -1766,8 +1783,6 @@ mtx_unlock(&provider->ftp_mtx); return (provider); -#endif - return (NULL); } static void @@ -2000,10 +2015,8 @@ { int error = 0; int i, fail = 0; + struct callout_handle tmp; -#ifdef DOODAD - struct callout_handle tmp; -#endif /* Reset our calback hooks. */ dtrace_fasttrap_fork = NULL; dtrace_fasttrap_exec = NULL; @@ -2020,8 +2033,6 @@ dtrace_meta_unregister(fasttrap_meta_id) != 0) return (ENOENT); -printf("%s(%d): DOODAD\n",__func__,__LINE__); -#ifdef DOODAD /* * Prevent any new timeouts from running by setting fasttrap_timeout * to a non-zero value, and wait for the current timeout to complete. @@ -2029,20 +2040,19 @@ mtx_lock(&fasttrap_cleanup_mtx); fasttrap_cleanup_work = 0; - while (fasttrap_timeout != (struct callout_handle)1) { + while (fasttrap_timeout.callout != (struct callout *)(uintptr_t)1) { tmp = fasttrap_timeout; - fasttrap_timeout = (struct callout_handle)1; + fasttrap_timeout.callout = (struct callout *)(uintptr_t)1; - if (tmp != 0) { + if (tmp.callout != NULL) { mtx_unlock(&fasttrap_cleanup_mtx); - (void) untimeout(tmp); + (void) untimeout(&fasttrap_pid_cleanup_cb, NULL, tmp); mtx_lock(&fasttrap_cleanup_mtx); } } fasttrap_cleanup_work = 0; mtx_unlock(&fasttrap_cleanup_mtx); -#endif /* * Iterate over all of our providers. If there's still a process @@ -2085,9 +2095,7 @@ * we've been unsuccessfully trying to detach. */ mtx_lock(&fasttrap_cleanup_mtx); -#ifdef DOODAD - fasttrap_timeout = 0; -#endif + fasttrap_timeout.callout = NULL; work = fasttrap_cleanup_work; mtx_unlock(&fasttrap_cleanup_mtx);