From owner-freebsd-hackers@FreeBSD.ORG Tue Apr 17 17:19:18 2012 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 991B61065676 for ; Tue, 17 Apr 2012 17:19:18 +0000 (UTC) (envelope-from rysto32@gmail.com) Received: from mail-wg0-f50.google.com (mail-wg0-f50.google.com [74.125.82.50]) by mx1.freebsd.org (Postfix) with ESMTP id 2853B8FC0C for ; Tue, 17 Apr 2012 17:19:17 +0000 (UTC) Received: by wgbds12 with SMTP id ds12so6433087wgb.31 for ; Tue, 17 Apr 2012 10:19:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=HkvWBGGsZ70p9+zaDU7Y5kUTZSZsd89nz0ihqLnPJDQ=; b=BNkSrjRybqnM94y8e6euplVMJBvJTwRkc48lpIAxoVKBjpZymNbbxWU9UkG1SOE7HZ 3jqgkd/kZf4G4tM59PxSqMSoWlFBH+g1lCAKgulSfTowOcd4m7t1iQ7YhUEgMfAfXQkI eh1mQaQy0CAzA+mG71RfgFu7Hdp9HSwIdqPcjxnQozcaAU325YOsDzqcpBFzhssk0UIJ nFAnmDqCvdj3G3/A60kFsepxTgI05u/oUb3yZwB7Dzn0QYGtru1k/MbKDeJYr8GiWJG1 sC1EKTOMdqY+uDM+C6BizEDyNHxesr6OFPqd7qqJZY8NYHwgVlXeKce/w49idIUg8Ou2 CNDg== MIME-Version: 1.0 Received: by 10.216.132.226 with SMTP id o76mr9748579wei.93.1334683156009; Tue, 17 Apr 2012 10:19:16 -0700 (PDT) Received: by 10.180.85.71 with HTTP; Tue, 17 Apr 2012 10:19:15 -0700 (PDT) Date: Tue, 17 Apr 2012 13:19:15 -0400 Message-ID: From: Ryan Stone To: freebsd-hackers@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 Subject: [PATCH] Implement DTrace "cpu" variable X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 17 Apr 2012 17:19:18 -0000 Below I have a patch that implements the "cpu" variable in D, as documented here: https://wikis.oracle.com/display/DTrace/Variables#Variables-DTraceBuiltinVariables. I've implemented it as a new builtin variable that returns curcpu. This is different from how it works in OpenSolaris/Illumos -- in those, it's implemented by groping around in curthread. In FreeBSD there are some places deep in the scheduler where curthread->td_oncpu will be set to -1(in preparation for the thread being descheduled) so I prefer to go with an implementation that works in all cases, even if we diverge from upstream a little bit. If there are no objections I intend to commit this[rstone@rstone-laptop head]svn diff Index: cddl/contrib/opensolaris/lib/libdtrace/common/dt_open.c =================================================================== --- cddl/contrib/opensolaris/lib/libdtrace/common/dt_open.c (revision 234251) +++ cddl/contrib/opensolaris/lib/libdtrace/common/dt_open.c (working copy) @@ -497,6 +497,12 @@ { "zonename", DT_IDENT_SCALAR, 0, DIF_VAR_ZONENAME, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" }, #endif + +#if !defined(sun) +{ "cpu", DT_IDENT_SCALAR, 0, DIF_VAR_CPU, + DT_ATTR_STABCMN, DT_VERS_1_6_3, &dt_idops_type, "int" }, +#endif + { NULL, 0, 0, 0, { 0, 0, 0 }, 0, NULL, NULL } }; Index: sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c =================================================================== --- sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c (revision 234251) +++ sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c (working copy) @@ -3143,6 +3143,11 @@ return (curthread->td_errno); #endif } +#if !defined(sun) + case DIF_VAR_CPU: { + return curcpu; + } +#endif default: DTRACE_CPUFLAG_SET(CPU_DTRACE_ILLOP); return (0); Index: sys/cddl/contrib/opensolaris/uts/common/sys/dtrace.h =================================================================== --- sys/cddl/contrib/opensolaris/uts/common/sys/dtrace.h (revision 234251) +++ sys/cddl/contrib/opensolaris/uts/common/sys/dtrace.h (working copy) @@ -251,6 +251,10 @@ #define DIF_VAR_ERRNO 0x0120 /* thread errno */ #define DIF_VAR_EXECARGS 0x0121 /* process arguments */ +#if !defined(sun) +#define DIF_VAR_CPU 0x0200 +#endif + #define DIF_SUBR_RAND 0 #define DIF_SUBR_MUTEX_OWNED 1 #define DIF_SUBR_MUTEX_OWNER 2 to head in the next few days.