From owner-p4-projects@FreeBSD.ORG Mon Jan 7 07:33:40 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 3CC9A16A421; Mon, 7 Jan 2008 07:33:40 +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 DE44416A418 for ; Mon, 7 Jan 2008 07:33:39 +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 CB52413C457 for ; Mon, 7 Jan 2008 07:33:39 +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 m077Xd3i029787 for ; Mon, 7 Jan 2008 07:33:39 GMT (envelope-from jb@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id m077XdT0029784 for perforce@freebsd.org; Mon, 7 Jan 2008 07:33:39 GMT (envelope-from jb@freebsd.org) Date: Mon, 7 Jan 2008 07:33:39 GMT Message-Id: <200801070733.m077XdT0029784@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 132683 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: Mon, 07 Jan 2008 07:33:40 -0000 http://perforce.freebsd.org/chv.cgi?CH=132683 Change 132683 by jb@jb_freebsd1 on 2008/01/07 07:33:25 Add the amd64 code to the Function Boundary Trace (fbt) provider. This is just OpenSolaris code rearranged to suit FreeBSD's linker sets. Affected files ... .. //depot/projects/dtrace/src/sys/cddl/dev/fbt/fbt.c#6 edit Differences ... ==== //depot/projects/dtrace/src/sys/cddl/dev/fbt/fbt.c#6 (text+ko) ==== @@ -93,7 +93,7 @@ #define FBT_RET_IMM16 0xc2 #define FBT_LEAVE 0xc9 -#ifdef __amd64 +#ifdef __amd64__ #define FBT_PATCHVAL 0xcc #else #define FBT_PATCHVAL 0xf0 @@ -198,6 +198,19 @@ cpu->cpu_dtrace_caller = 0; } else { +#ifdef __amd64__ + /* + * On amd64, we instrument the ret, not the + * leave. We therefore need to set the caller + * to assure that the top frame of a stack() + * action is correct. + */ + DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT); + cpu->cpu_dtrace_caller = stack[0]; + DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT | + CPU_DTRACE_BADADDR); +#endif + dtrace_probe(fbt->fbtp_id, fbt->fbtp_roffset, rval, 0, 0, 0); cpu->cpu_dtrace_caller = 0; @@ -231,46 +244,6 @@ return (0); } -#ifdef DOODAD - /* - * Still trying to narrow down why some of these things are - * being called from the probe context. At the moment I suspect - * there is some call which executes witness code and that - * is *certain* to end in tears. - */ - if (name[0] == '_' || - strcmp(name, "trap") == 0 || - strcmp(name, "userret") == 0 || - strncmp(name, "realtimer", 9) == 0 || - strncmp(name, "ithread", 7) == 0 || - strncmp(name, "itimer", 6) == 0 || - strncmp(name, "ioapic", 6) == 0 || - strncmp(name, "isitmy", 6) == 0 || - strncmp(name, "db_", 3) == 0 || - strncmp(name, "gdb_", 4) == 0 || - strncmp(name, "kdb_", 4) == 0 || - strncmp(name, "intr_", 5) == 0 || - - strncmp(name, "X_", 2) == 0 || - strncmp(name, "vm", 2) == 0 || - strncmp(name, "th", 2) == 0 || - strncmp(name, "sh", 2) == 0 || - strncmp(name, "fi", 2) == 0 || - strncmp(name, "fd", 2) == 0 || - strncmp(name, "elf", 3) == 0 || - strncmp(name, "str", 3) == 0 || - strncmp(name, "nfs", 3) == 0 || - strncmp(name, "ata_", 4) == 0 || - strncmp(name, "acpi", 4) == 0 || - strncmp(name, "link_", 5) == 0 || - strncmp(name, "bufobj", 6) == 0 || - strncmp(name, "linker", 6) == 0 || - strncmp(name, "witness", 7) == 0 || - strncmp(name, "spinlock", 8) == 0 || - strcmp(name, "pcpu_find") == 0) /* used in stack() impl */ - return (0); -#endif - /* * These filters are set by sysctl to help debugging the initial * port of this provider. Normally the wildcard would be @@ -309,6 +282,26 @@ instr = (u_int8_t *) symval->value; limit = (u_int8_t *) symval->value + symval->size; +#ifdef __amd64__ + while (instr < limit) { + if (*instr == FBT_PUSHL_EBP) + break; + + if ((size = dtrace_instr_size(instr)) <= 0) + break; + + instr += size; + } + + if (instr >= limit || *instr != FBT_PUSHL_EBP) { + /* + * We either don't save the frame pointer in this + * function, or we ran into some disassembly + * screw-up. Either way, we bail. + */ + return (0); + } +#else if (instr[0] != FBT_PUSHL_EBP) return (0); @@ -317,6 +310,7 @@ !(instr[1] == FBT_MOVL_ESP_EBP0_V1 && instr[2] == FBT_MOVL_ESP_EBP1_V1)) return (0); +#endif fbt = malloc(sizeof (fbt_probe_t), M_FBT, M_WAITOK | M_ZERO); fbt->fbtp_name = name; @@ -347,6 +341,17 @@ if ((size = dtrace_instr_size(instr)) <= 0) return (0); +#ifdef __amd64__ + /* + * We only instrument "ret" on amd64 -- we don't yet instrument + * ret imm16, largely because the compiler doesn't seem to + * (yet) emit them in the kernel... + */ + if (*instr != FBT_RET) { + instr += size; + goto again; + } +#else if (!(size == 1 && (*instr == FBT_POPL_EBP || *instr == FBT_LEAVE) && (*(instr + 1) == FBT_RET || @@ -354,6 +359,7 @@ instr += size; goto again; } +#endif /* * We (desperately) want to avoid erroneously instrumenting a @@ -403,6 +409,7 @@ fbt->fbtp_ctl = lf; fbt->fbtp_loadcnt = lf->loadcnt; +#ifndef __amd64__ if (*instr == FBT_POPL_EBP) { fbt->fbtp_rval = DTRACE_INVOP_POPL_EBP; } else { @@ -412,6 +419,13 @@ fbt->fbtp_roffset = (uintptr_t)(instr - (uint8_t *) symval->value) + 1; +#else + ASSERT(*instr == FBT_RET); + fbt->fbtp_rval = DTRACE_INVOP_RET; + fbt->fbtp_roffset = + (uintptr_t)(instr - (uint8_t *) symval->value); +#endif + fbt->fbtp_savedval = *instr; fbt->fbtp_patchval = FBT_PATCHVAL; fbt->fbtp_hashnext = fbt_probetab[FBT_ADDR2NDX(instr)]; @@ -471,7 +485,7 @@ /* * List the functions in the module and the symbol values. */ - linker_file_function_listall(lf, fbt_provide_module_function, modname); + (void) linker_file_function_listall(lf, fbt_provide_module_function, modname); } /* ARGSUSED */