]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
dtrace: split arch-dependent parts out of fasttrap
authorNick Alcock <nick.alcock@oracle.com>
Fri, 12 Aug 2016 17:51:34 +0000 (18:51 +0100)
committerNick Alcock <nick.alcock@oracle.com>
Tue, 4 Oct 2016 16:17:07 +0000 (17:17 +0100)
This is much the same as what SDT is already doing.

No SPARC parts yet.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
Acked-by: Kris Van Hees <kris.van.hees@oracle.com>
Orabug: 24455245

dtrace/Kbuild
dtrace/fasttrap_dev.c
dtrace/fasttrap_impl.h
dtrace/fasttrap_x86_64.c [new file with mode: 0644]
dtrace/include/x86_64/dtrace/fasttrap_arch.h [new file with mode: 0644]

index ae8f15b81d9f8f856cc29c48970ef9b93dacd942..32a0ecf64a10df7e76e3296631012afe53385f2a 100644 (file)
@@ -46,7 +46,7 @@ dtrace-y                      := dtrace_mod.o dtrace_dev.o \
                                   dtrace_probe.o dtrace_probe_ctx.o \
                                   dtrace_ptofapi.o dtrace_predicate.o \
                                   dtrace_spec.o dtrace_state.o dtrace_util.o
-fasttrap-y                     := fasttrap_mod.o fasttrap_dev.o
+fasttrap-y                     := fasttrap_mod.o fasttrap_dev.o fasttrap_$(UTS_MACHINE).o
 profile-y                      := profile_mod.o profile_dev.o
 sdt-y                          := sdt_mod.o sdt_dev.o sdt_$(UTS_MACHINE).o
 systrace-y                     := systrace_mod.o systrace_dev.o
index c46ee71e1c72b9d2f0625f7dda0f13deb5ec86f1..28b75ac1fd515a146d0ff02cd172848b6d103349 100644 (file)
@@ -21,7 +21,7 @@
  *
  * CDDL HEADER END
  *
- * Copyright 2010, 2011, 2012, 2013 Oracle, Inc.  All rights reserved.
+ * Copyright 2010 -- 2016 Oracle, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -31,6 +31,7 @@
 #include <linux/slab.h>
 #include <linux/sort.h>
 #include <linux/uaccess.h>
+#include <linux/vmalloc.h>
 #include <linux/workqueue.h>
 
 #include "dtrace.h"
@@ -78,44 +79,6 @@ static volatile uint64_t     fasttrap_mod_gen;
 
 static void fasttrap_pid_cleanup(void);
 
-static void fasttrap_usdt_args64(fasttrap_probe_t *probe, struct pt_regs *regs,
-                                int argc, uintptr_t *argv) {
-       int             i, x, cap = min(argc, (int)probe->ftp_nargs);
-       uintptr_t       *st = (uintptr_t *)regs->sp;
-
-       for (i = 0; i < cap; i++) {
-               switch (x = probe->ftp_argmap[i]) {
-               case 0:
-                       argv[i] = regs->di;
-                       break;
-               case 1:
-                       argv[i] = regs->si;
-                       break;
-               case 2:
-                       argv[i] = regs->dx;
-                       break;
-               case 3:
-                       argv[i] = regs->cx;
-                       break;
-               case 4:
-                       argv[i] = regs->r8;
-                       break;
-               case 5:
-                       argv[i] = regs->r9;
-                       break;
-               default:
-                       ASSERT(x > 5);
-
-                       __copy_from_user_inatomic_nocache(&argv[i],
-                                                         (void *)&st[x - 6],
-                                                         sizeof(st[0]));
-               }
-       }
-
-       while (i < argc)
-               argv[i++] = 0;
-}
-
 static int fasttrap_pid_probe(fasttrap_machtp_t *mtp, struct pt_regs *regs) {
        fasttrap_tracepoint_t   *tp = container_of(mtp, fasttrap_tracepoint_t,
                                                   ftt_mtp);
@@ -143,25 +106,16 @@ static int fasttrap_pid_probe(fasttrap_machtp_t *mtp, struct pt_regs *regs) {
        for (id = tp->ftt_ids; id != NULL; id = id->fti_next) {
                fasttrap_probe_t        *ftp = id->fti_probe;
 
-               if (id->fti_ptype == DTFTP_IS_ENABLED) {
+               if (id->fti_ptype == DTFTP_IS_ENABLED)
                        is_enabled = 1;
-               } else if (ftp->ftp_argmap == NULL) {
-                       dtrace_probe(ftp->ftp_id, regs->di, regs->si, regs->dx,
-                                    regs->cx, regs->r8);
-               } else {
-                       uintptr_t       t[5];
-
-                       fasttrap_usdt_args64(ftp, regs,
-                                            sizeof(t) / sizeof(t[0]), t);
-                       dtrace_probe(ftp->ftp_id, t[0], t[1], t[2], t[3],
-                                    t[4]);
-               }
+               else
+                       fasttrap_pid_probe_arch(ftp, regs);
        }
 
        this_cpu_core->cpu_dtrace_regs = NULL;
 
        if (is_enabled)
-               regs->ax = 1;
+               fasttrap_set_enabled(regs);
 
        return 0;
 }
@@ -722,42 +676,6 @@ static void fasttrap_pid_getargdesc(void *arg, dtrace_id_t id, void *parg,
        strcpy(desc->dtargd_xlate, str);
 }
 
-static uint64_t fasttrap_usdt_getarg(void *arg, dtrace_id_t id, void *parg,
-                                    int argno, int aframes)
-{
-       struct pt_regs  *regs = this_cpu_core->cpu_dtrace_regs;
-       uint64_t        *st;
-       uint64_t        val;
-
-       if (regs == NULL)
-               return 0;
-
-       switch (argno) {
-       case 0:
-               return regs->di;
-       case 1:
-               return regs->si;
-       case 2:
-               return regs->dx;
-       case 3:
-               return regs->cx;
-       case 4:
-               return regs->r8;
-       case 5:
-               return regs->r9;
-       }
-
-       ASSERT(argno > 5);
-
-       st = (uint64_t *)regs->sp;
-       DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT);
-       __copy_from_user_inatomic_nocache(&val, (void *)&st[argno - 6],
-                                         sizeof(st[0]));
-       DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT);
-
-       return val;
-}
-
 static void fasttrap_pid_destroy(void *arg, dtrace_id_t id, void *parg)
 {
        fasttrap_probe_t        *probe = parg;
index d34aabf2a8ecb7bb0537f31ff8897d88e78cf130..d2992fa1f71e6a3edd37ce4c3a4f59d24f1e783d 100644 (file)
@@ -2,6 +2,7 @@
 #define _FASTTRAP_IMPL_H_
 
 #include <linux/dtrace/fasttrap.h>
+#include <dtrace/fasttrap_arch.h>
 
 /*
  * Fasttrap Providers, Probes and Tracepoints
@@ -120,7 +121,12 @@ extern fasttrap_hash_t                     fasttrap_tpoints;
        (((pc) / sizeof (fasttrap_instr_t) + (pid)) &                         \
         fasttrap_tpoints.fth_mask)
 
-#define FASTTRAP_OFFSET_AFRAMES                3
+extern void fasttrap_usdt_args64_arch(fasttrap_probe_t *probe, struct pt_regs *regs,
+                                     int argc, uintptr_t *argv);
+extern uint64_t fasttrap_usdt_getarg(void *arg, dtrace_id_t id, void *parg,
+                                    int argno, int aframes);
+extern void fasttrap_pid_probe_arch(fasttrap_probe_t *ftp, struct pt_regs *regs);
+extern void fasttrap_set_enabled(struct pt_regs *regs);
 
 extern void fasttrap_meta_create_probe(void *, void *,
                                       dtrace_helper_probedesc_t *);
diff --git a/dtrace/fasttrap_x86_64.c b/dtrace/fasttrap_x86_64.c
new file mode 100644 (file)
index 0000000..d48cf42
--- /dev/null
@@ -0,0 +1,127 @@
+/*
+ * FILE:       fasttrap_x86_64.c
+ * DESCRIPTION:        Fasttrap Tracing: arch support (x86_64)
+ *
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ * Copyright 2010, 2011, 2012, 2013, 2016 Oracle, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <linux/uaccess.h>
+
+#include "dtrace.h"
+#include "dtrace_dev.h"
+#include "fasttrap_impl.h"
+
+uint64_t fasttrap_usdt_getarg(void *arg, dtrace_id_t id, void *parg,
+                             int argno, int aframes)
+{
+       struct pt_regs  *regs = this_cpu_core->cpu_dtrace_regs;
+       uint64_t        *st;
+       uint64_t        val;
+
+       if (regs == NULL)
+               return 0;
+
+       switch (argno) {
+       case 0:
+               return regs->di;
+       case 1:
+               return regs->si;
+       case 2:
+               return regs->dx;
+       case 3:
+               return regs->cx;
+       case 4:
+               return regs->r8;
+       case 5:
+               return regs->r9;
+       }
+
+       ASSERT(argno > 5);
+
+       st = (uint64_t *)regs->sp;
+       DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT);
+       __copy_from_user_inatomic_nocache(&val, (void *)&st[argno - 6],
+                                         sizeof(st[0]));
+       DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT);
+
+       return val;
+}
+
+static void fasttrap_map_args(fasttrap_probe_t *probe, struct pt_regs *regs,
+                             int argc, uintptr_t *argv)
+{
+       int             i, x, cap = min(argc, (int)probe->ftp_nargs);
+       uintptr_t       *st = (uintptr_t *)regs->sp;
+
+       for (i = 0; i < cap; i++) {
+               switch (x = probe->ftp_argmap[i]) {
+               case 0:
+                       argv[i] = regs->di;
+                       break;
+               case 1:
+                       argv[i] = regs->si;
+                       break;
+               case 2:
+                       argv[i] = regs->dx;
+                       break;
+               case 3:
+                       argv[i] = regs->cx;
+                       break;
+               case 4:
+                       argv[i] = regs->r8;
+                       break;
+               case 5:
+                       argv[i] = regs->r9;
+                       break;
+               default:
+                       ASSERT(x > 5);
+
+                       __copy_from_user_inatomic_nocache(&argv[i],
+                                                         (void *)&st[x - 6],
+                                                         sizeof(st[0]));
+               }
+       }
+
+       while (i < argc)
+               argv[i++] = 0;
+}
+
+void fasttrap_pid_probe_arch(fasttrap_probe_t *ftp, struct pt_regs *regs)
+{
+       if (ftp->ftp_argmap == NULL)
+               dtrace_probe(ftp->ftp_id, regs->di, regs->si, regs->dx,
+                            regs->cx, regs->r8);
+       else {
+               uintptr_t       t[5];
+
+               fasttrap_map_args(ftp, regs, sizeof(t) / sizeof(t[0]), t);
+               dtrace_probe(ftp->ftp_id, t[0], t[1], t[2], t[3],
+                            t[4]);
+       }
+}
+
+void fasttrap_set_enabled(struct pt_regs *regs)
+{
+       regs->ax = 1;
+}
+
diff --git a/dtrace/include/x86_64/dtrace/fasttrap_arch.h b/dtrace/include/x86_64/dtrace/fasttrap_arch.h
new file mode 100644 (file)
index 0000000..a839c9e
--- /dev/null
@@ -0,0 +1,37 @@
+#ifndef _X86_64_FASTTRAP_ARCH_H
+#define _X86_64_FASTTRAP_ARCH_H
+
+/*
+ * Fasttrap Tracing Implementation defines
+ *
+ * Note: The contents of this file are private to the implementation of the
+ * DTrace subsystem and are subject to change at any time without notice.
+ */
+
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ * Copyright 2016 Oracle, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#define FASTTRAP_OFFSET_AFRAMES        3
+
+#endif /* _X86_64_FASTTRAP_ARCH_H */