Date: Sat, 27 May 2006 05:30:47 GMT From: John Birrell <jb@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 97923 for review Message-ID: <200605270530.k4R5Ul23089086@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=97923 Change 97923 by jb@jb_freebsd2 on 2006/05/27 05:30:09 Change all the references to the cpu id to the way that FreeBSD does it. My previous hack, although reducing diffs to OpenSolaris, cause an occasional NULL pointer reference which *always* ended in tears. To a FreeBSD developer this code will read the way it works now. Before you had to understand my hack to make sense of the code. Affected files ... .. //depot/projects/dtrace/src/sys/cddl/dev/dtrace/dtrace.c#24 edit .. //depot/projects/dtrace/src/sys/cddl/dev/dtrace/dtrace_action.c#3 edit .. //depot/projects/dtrace/src/sys/cddl/dev/dtrace/dtrace_buffer.c#7 edit .. //depot/projects/dtrace/src/sys/cddl/dev/dtrace/dtrace_context.c#5 edit .. //depot/projects/dtrace/src/sys/cddl/dev/dtrace/dtrace_dif.c#9 edit .. //depot/projects/dtrace/src/sys/cddl/dev/dtrace/dtrace_dynvar.c#5 edit .. //depot/projects/dtrace/src/sys/cddl/dev/dtrace/dtrace_hacks.c#14 edit .. //depot/projects/dtrace/src/sys/cddl/dev/dtrace/dtrace_helper.c#3 edit .. //depot/projects/dtrace/src/sys/cddl/dev/dtrace/dtrace_match.c#2 edit .. //depot/projects/dtrace/src/sys/cddl/dev/dtrace/dtrace_priv.c#3 edit .. //depot/projects/dtrace/src/sys/cddl/dev/dtrace/dtrace_probe.c#8 edit .. //depot/projects/dtrace/src/sys/cddl/dev/dtrace/dtrace_speculation.c#3 edit .. //depot/projects/dtrace/src/sys/cddl/dev/dtrace/dtrace_state.c#9 edit Differences ... ==== //depot/projects/dtrace/src/sys/cddl/dev/dtrace/dtrace.c#24 (text+ko) ==== @@ -358,7 +358,7 @@ #define DTRACE_ALIGNCHECK(addr, size, flags) \ if (addr & (size - 1)) { \ *flags |= CPU_DTRACE_BADALIGN; \ - cpu_core[CPU->cpu_id].cpuc_dtrace_illval = addr; \ + cpu_core[curcpu].cpuc_dtrace_illval = addr; \ return (0); \ } #else @@ -375,7 +375,7 @@ uint##bits##_t rval; \ int i; \ volatile uint16_t *flags = (volatile uint16_t *) \ - &cpu_core[CPU->cpu_id].cpuc_dtrace_flags; \ + &cpu_core[curcpu].cpuc_dtrace_flags; \ \ DTRACE_ALIGNCHECK(addr, size, flags); \ \ @@ -390,7 +390,7 @@ * This address falls within a toxic region; return 0. \ */ \ *flags |= CPU_DTRACE_BADADDR; \ - cpu_core[CPU->cpu_id].cpuc_dtrace_illval = addr; \ + cpu_core[curcpu].cpuc_dtrace_illval = addr; \ return (0); \ } \ \ ==== //depot/projects/dtrace/src/sys/cddl/dev/dtrace/dtrace_action.c#3 (text+ko) ==== @@ -146,7 +146,7 @@ if (dtrace_destructive_disallow) return; - flags = (volatile uint16_t *)&cpu_core[cpu->cpu_id].cpuc_dtrace_flags; + flags = (volatile uint16_t *)&cpu_core[curcpu].cpuc_dtrace_flags; now = dtrace_gethrtime(); @@ -194,7 +194,7 @@ char *str = (char *)&pcs[nframes]; int size, offs = 0, i, j; uintptr_t old = mstate->dtms_scratch_ptr, saved; - uint16_t *flags = &cpu_core[CPU->cpu_id].cpuc_dtrace_flags; + uint16_t *flags = &cpu_core[curcpu].cpuc_dtrace_flags; char *sym; /* ==== //depot/projects/dtrace/src/sys/cddl/dev/dtrace/dtrace_buffer.c#7 (text+ko) ==== @@ -49,7 +49,7 @@ dtrace_buffer_t *buf; dtrace_icookie_t cookie = dtrace_interrupt_disable(); - buf = &state->dts_buffer[CPU->cpu_id]; + buf = &state->dts_buffer[curcpu]; if (buf->dtb_tomax != NULL) { /* ==== //depot/projects/dtrace/src/sys/cddl/dev/dtrace/dtrace_context.c#5 (text+ko) ==== @@ -184,7 +184,7 @@ if (s1 == s2 || limit == 0) return (0); - flags = (volatile uint16_t *)&cpu_core[CPU->cpu_id].cpuc_dtrace_flags; + flags = (volatile uint16_t *)&cpu_core[curcpu].cpuc_dtrace_flags; do { if (s1 == NULL) { @@ -238,13 +238,13 @@ if (kaddr - taddr < tsize) { DTRACE_CPUFLAG_SET(CPU_DTRACE_BADADDR); - cpu_core[CPU->cpu_id].cpuc_dtrace_illval = kaddr; + cpu_core[curcpu].cpuc_dtrace_illval = kaddr; return (1); } if (taddr - kaddr < size) { DTRACE_CPUFLAG_SET(CPU_DTRACE_BADADDR); - cpu_core[CPU->cpu_id].cpuc_dtrace_illval = taddr; + cpu_core[curcpu].cpuc_dtrace_illval = taddr; return (1); } } @@ -328,7 +328,7 @@ { volatile uint16_t *flags; - flags = (volatile uint16_t *)&cpu_core[CPU->cpu_id].cpuc_dtrace_flags; + flags = (volatile uint16_t *)&cpu_core[curcpu].cpuc_dtrace_flags; if (s1 == s2) return (0); ==== //depot/projects/dtrace/src/sys/cddl/dev/dtrace/dtrace_dif.c#9 (text+ko) ==== @@ -60,7 +60,7 @@ if ((lwp = curthread->t_lwp) == NULL) { DTRACE_CPUFLAG_SET(CPU_DTRACE_BADADDR); - cpu_core[CPU->cpu_id].cpuc_dtrace_illval = NULL; + cpu_core[curcpu].cpuc_dtrace_illval = NULL; return (0); } @@ -331,8 +331,8 @@ dtrace_key_t *tupregs, int nargs, dtrace_mstate_t *mstate, dtrace_state_t *state) { - volatile uint16_t *flags = &cpu_core[CPU->cpu_id].cpuc_dtrace_flags; - volatile uintptr_t *illval = &cpu_core[CPU->cpu_id].cpuc_dtrace_illval; + volatile uint16_t *flags = &cpu_core[curcpu].cpuc_dtrace_flags; + volatile uintptr_t *illval = &cpu_core[curcpu].cpuc_dtrace_illval; #ifdef DOODAD union { @@ -1474,8 +1474,8 @@ dtrace_statvar_t *svar; dtrace_dstate_t *dstate = &vstate->dtvs_dynvars; dtrace_difv_t *v; - volatile uint16_t *flags = &cpu_core[CPU->cpu_id].cpuc_dtrace_flags; - volatile uintptr_t *illval = &cpu_core[CPU->cpu_id].cpuc_dtrace_illval; + volatile uint16_t *flags = &cpu_core[curcpu].cpuc_dtrace_flags; + volatile uintptr_t *illval = &cpu_core[curcpu].cpuc_dtrace_illval; dtrace_key_t tupregs[DIF_DTR_NREGS + 2]; /* +2 for thread and id */ uint64_t regs[DIF_DIR_NREGS]; @@ -1846,7 +1846,7 @@ sz += sizeof (uint64_t); ASSERT(svar->dtsv_size == NCPU * sz); - a += CPU->cpu_id * sz; + a += curcpu * sz; if (*(uint8_t *)a == UINT8_MAX) { /* @@ -1864,7 +1864,7 @@ ASSERT(svar->dtsv_size == NCPU * sizeof (uint64_t)); tmp = (uint64_t *)(uintptr_t)svar->dtsv_data; - regs[rd] = tmp[CPU->cpu_id]; + regs[rd] = tmp[curcpu]; break; case DIF_OP_STLS: @@ -1885,7 +1885,7 @@ sz += sizeof (uint64_t); ASSERT(svar->dtsv_size == NCPU * sz); - a += CPU->cpu_id * sz; + a += curcpu * sz; if (regs[rd] == 0) { *(uint8_t *)a = UINT8_MAX; @@ -1902,7 +1902,7 @@ ASSERT(svar->dtsv_size == NCPU * sizeof (uint64_t)); tmp = (uint64_t *)(uintptr_t)svar->dtsv_data; - tmp[CPU->cpu_id] = regs[rd]; + tmp[curcpu] = regs[rd]; break; case DIF_OP_LDTS: { ==== //depot/projects/dtrace/src/sys/cddl/dev/dtrace/dtrace_dynvar.c#5 (text+ko) ==== @@ -112,7 +112,7 @@ uint64_t hashval = DTRACE_DYNHASH_VALID; dtrace_dynhash_t *hash = dstate->dtds_hash; dtrace_dynvar_t *free, *new_free, *next, *dvar, *start, *prev = NULL; - processorid_t me = CPU->cpu_id, cpu = me; + processorid_t me = curcpu, cpu = me; dtrace_dstate_percpu_t *dcpu = &dstate->dtds_percpu[me]; size_t bucket, ksize; size_t chunksize = dstate->dtds_chunksize; ==== //depot/projects/dtrace/src/sys/cddl/dev/dtrace/dtrace_hacks.c#14 (text+ko) ==== @@ -16,6 +16,7 @@ dtrace_module_unloaded, dtrace_priv_proc_control, dtrace_speculation, + dtrace_speculation_clean, dtrace_state_clean, dtrace_state_deadman, dtrace_toxrange_add ==== //depot/projects/dtrace/src/sys/cddl/dev/dtrace/dtrace_helper.c#3 (text+ko) ==== @@ -8,7 +8,7 @@ { uint32_t size, next, nnext, i; dtrace_helptrace_t *ent; - uint16_t flags = cpu_core[CPU->cpu_id].cpuc_dtrace_flags; + uint16_t flags = cpu_core[curcpu].cpuc_dtrace_flags; if (!dtrace_helptrace_enabled) return; @@ -49,7 +49,7 @@ ent->dtht_fltoffs = (mstate->dtms_present & DTRACE_MSTATE_FLTOFFS) ? mstate->dtms_fltoffs : -1; ent->dtht_fault = DTRACE_FLAGS2FLT(flags); - ent->dtht_illval = cpu_core[CPU->cpu_id].cpuc_dtrace_illval; + ent->dtht_illval = cpu_core[curcpu].cpuc_dtrace_illval; for (i = 0; i < vstate->dtvs_nlocals; i++) { dtrace_statvar_t *svar; @@ -59,7 +59,7 @@ ASSERT(svar->dtsv_size >= NCPU * sizeof (uint64_t)); ent->dtht_locals[i] = - ((uint64_t *)(uintptr_t)svar->dtsv_data)[CPU->cpu_id]; + ((uint64_t *)(uintptr_t)svar->dtsv_data)[curcpu]; } } @@ -67,7 +67,7 @@ dtrace_helper(int which, dtrace_mstate_t *mstate, dtrace_state_t *state, uint64_t arg0, uint64_t arg1) { - uint16_t *flags = &cpu_core[CPU->cpu_id].cpuc_dtrace_flags; + uint16_t *flags = &cpu_core[curcpu].cpuc_dtrace_flags; uint64_t sarg0 = mstate->dtms_arg[0]; uint64_t sarg1 = mstate->dtms_arg[1]; uint64_t rval = 0; ==== //depot/projects/dtrace/src/sys/cddl/dev/dtrace/dtrace_match.c#2 (text+ko) ==== @@ -243,9 +243,9 @@ return (nmatched); } - template.dtpr_mod = (char *)pkp->dtpk_mod; - template.dtpr_func = (char *)pkp->dtpk_func; - template.dtpr_name = (char *)pkp->dtpk_name; + template.dtpr_mod = pkp->dtpk_mod; + template.dtpr_func = pkp->dtpk_func; + template.dtpr_name = pkp->dtpk_name; /* * We want to find the most distinct of the module name, function ==== //depot/projects/dtrace/src/sys/cddl/dev/dtrace/dtrace_priv.c#3 (text+ko) ==== @@ -92,7 +92,7 @@ return (1); bad: - cpu_core[CPU->cpu_id].cpuc_dtrace_flags |= CPU_DTRACE_UPRIV; + cpu_core[curcpu].cpuc_dtrace_flags |= CPU_DTRACE_UPRIV; return (0); } @@ -108,7 +108,7 @@ dtrace_priv_proc_common_nocd()) return (1); - cpu_core[CPU->cpu_id].cpuc_dtrace_flags |= CPU_DTRACE_UPRIV; + cpu_core[curcpu].cpuc_dtrace_flags |= CPU_DTRACE_UPRIV; return (0); } @@ -119,7 +119,7 @@ if (state->dts_cred.dcr_action & DTRACE_CRA_PROC) return (1); - cpu_core[CPU->cpu_id].cpuc_dtrace_flags |= CPU_DTRACE_UPRIV; + cpu_core[curcpu].cpuc_dtrace_flags |= CPU_DTRACE_UPRIV; return (0); } @@ -130,7 +130,7 @@ if (state->dts_cred.dcr_action & DTRACE_CRA_KERNEL) return (1); - cpu_core[CPU->cpu_id].cpuc_dtrace_flags |= CPU_DTRACE_KPRIV; + cpu_core[curcpu].cpuc_dtrace_flags |= CPU_DTRACE_KPRIV; return (0); } @@ -141,7 +141,7 @@ if (state->dts_cred.dcr_action & DTRACE_CRA_KERNEL_DESTRUCTIVE) return (1); - cpu_core[CPU->cpu_id].cpuc_dtrace_flags |= CPU_DTRACE_KPRIV; + cpu_core[curcpu].cpuc_dtrace_flags |= CPU_DTRACE_KPRIV; return (0); } ==== //depot/projects/dtrace/src/sys/cddl/dev/dtrace/dtrace_probe.c#8 (text+ko) ==== @@ -19,21 +19,16 @@ int vtime, onintr = 0; volatile uint16_t *flags; hrtime_t now; + struct pcpu *cpu = pcpu_find(curcpu); - /* - * Kick out immediately if this CPU is still being born (in which case - * curthread will be set to -1) - */ -#if defined(sun) - if ((uintptr_t)curthread & 1) + if (cpu == NULL) return; -#endif + + onintr = cpu->pc_intr_actv; + cpuid = curcpu; cookie = dtrace_interrupt_disable(); probe = dtrace_probes[id - 1]; - cpuid = CPU->cpu_id; - - onintr = CPU_ON_INTR(CPU); if (!onintr && probe->dtpr_predcache != DTRACE_CACHEIDNONE && probe->dtpr_predcache == curthread->t_predcache) { ==== //depot/projects/dtrace/src/sys/cddl/dev/dtrace/dtrace_speculation.c#3 (text+ko) ==== @@ -252,7 +252,7 @@ dtrace_speculation_clean_here(dtrace_state_t *state) { dtrace_icookie_t cookie; - processorid_t cpu = CPU->cpu_id; + processorid_t cpu = curcpu; dtrace_buffer_t *dest = &state->dts_buffer[cpu]; dtrace_specid_t i; ==== //depot/projects/dtrace/src/sys/cddl/dev/dtrace/dtrace_state.c#9 (text+ko) ==== @@ -735,7 +735,7 @@ * level) and to manually activate the buffer for this CPU. */ cookie = dtrace_interrupt_disable(); - *cpu = CPU->cpu_id; + *cpu = curcpu; ASSERT(state->dts_buffer[*cpu].dtb_flags & DTRACEBUF_INACTIVE); state->dts_buffer[*cpu].dtb_flags &= ~DTRACEBUF_INACTIVE; @@ -836,7 +836,7 @@ state->dts_reserve = 0; cookie = dtrace_interrupt_disable(); - *cpu = CPU->cpu_id; + *cpu = curcpu; dtrace_probe(dtrace_probeid_end, (uint64_t)(uintptr_t)state, 0, 0, 0, 0); dtrace_interrupt_enable(cookie);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200605270530.k4R5Ul23089086>