Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 17 Apr 2012 13:19:15 -0400
From:      Ryan Stone <rysto32@gmail.com>
To:        freebsd-hackers@freebsd.org
Subject:   [PATCH] Implement DTrace "cpu" variable
Message-ID:  <CAFMmRNxQ3QKCXrF%2B1HiHBUj8=%2B3fjsXmQwrOavQv54XAqnM7Sw@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
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.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAFMmRNxQ3QKCXrF%2B1HiHBUj8=%2B3fjsXmQwrOavQv54XAqnM7Sw>