LCOV - code coverage report
Current view: top level - arch/arm/oprofile - common.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 33 0.0 %
Date: 2014-02-18 Functions: 0 6 0.0 %
Branches: 0 20 0.0 %

           Branch data     Line data    Source code
       1                 :            : /**
       2                 :            :  * @file common.c
       3                 :            :  *
       4                 :            :  * @remark Copyright 2004 Oprofile Authors
       5                 :            :  * @remark Copyright 2010 ARM Ltd.
       6                 :            :  * @remark Read the file COPYING
       7                 :            :  *
       8                 :            :  * @author Zwane Mwaikambo
       9                 :            :  * @author Will Deacon [move to perf]
      10                 :            :  */
      11                 :            : 
      12                 :            : #include <linux/cpumask.h>
      13                 :            : #include <linux/init.h>
      14                 :            : #include <linux/mutex.h>
      15                 :            : #include <linux/oprofile.h>
      16                 :            : #include <linux/perf_event.h>
      17                 :            : #include <linux/platform_device.h>
      18                 :            : #include <linux/slab.h>
      19                 :            : #include <asm/stacktrace.h>
      20                 :            : #include <linux/uaccess.h>
      21                 :            : 
      22                 :            : #include <asm/perf_event.h>
      23                 :            : #include <asm/ptrace.h>
      24                 :            : 
      25                 :            : #ifdef CONFIG_HW_PERF_EVENTS
      26                 :            : 
      27                 :            : /*
      28                 :            :  * OProfile has a curious naming scheme for the ARM PMUs, but they are
      29                 :            :  * part of the user ABI so we need to map from the perf PMU name for
      30                 :            :  * supported PMUs.
      31                 :            :  */
      32                 :            : static struct op_perf_name {
      33                 :            :         char *perf_name;
      34                 :            :         char *op_name;
      35                 :            : } op_perf_name_map[] = {
      36                 :            :         { "xscale1",          "arm/xscale1" },
      37                 :            :         { "xscale1",          "arm/xscale2" },
      38                 :            :         { "v6",                       "arm/armv6"   },
      39                 :            :         { "v6mpcore",         "arm/mpcore"  },
      40                 :            :         { "ARMv7 Cortex-A8",  "arm/armv7"   },
      41                 :            :         { "ARMv7 Cortex-A9",  "arm/armv7-ca9"       },
      42                 :            : };
      43                 :            : 
      44                 :          0 : char *op_name_from_perf_id(void)
      45                 :            : {
      46                 :            :         int i;
      47                 :            :         struct op_perf_name names;
      48                 :          0 :         const char *perf_name = perf_pmu_name();
      49                 :            : 
      50         [ #  # ]:          0 :         for (i = 0; i < ARRAY_SIZE(op_perf_name_map); ++i) {
      51                 :          0 :                 names = op_perf_name_map[i];
      52         [ #  # ]:          0 :                 if (!strcmp(names.perf_name, perf_name))
      53                 :            :                         return names.op_name;
      54                 :            :         }
      55                 :            : 
      56                 :            :         return NULL;
      57                 :            : }
      58                 :            : #endif
      59                 :            : 
      60                 :          0 : static int report_trace(struct stackframe *frame, void *d)
      61                 :            : {
      62                 :            :         unsigned int *depth = d;
      63                 :            : 
      64         [ #  # ]:          0 :         if (*depth) {
      65                 :          0 :                 oprofile_add_trace(frame->pc);
      66                 :          0 :                 (*depth)--;
      67                 :            :         }
      68                 :            : 
      69                 :          0 :         return *depth == 0;
      70                 :            : }
      71                 :            : 
      72                 :            : /*
      73                 :            :  * The registers we're interested in are at the end of the variable
      74                 :            :  * length saved register structure. The fp points at the end of this
      75                 :            :  * structure so the address of this struct is:
      76                 :            :  * (struct frame_tail *)(xxx->fp)-1
      77                 :            :  */
      78                 :            : struct frame_tail {
      79                 :            :         struct frame_tail *fp;
      80                 :            :         unsigned long sp;
      81                 :            :         unsigned long lr;
      82                 :            : } __attribute__((packed));
      83                 :            : 
      84                 :          0 : static struct frame_tail* user_backtrace(struct frame_tail *tail)
      85                 :            : {
      86                 :            :         struct frame_tail buftail[2];
      87                 :            : 
      88                 :            :         /* Also check accessibility of one struct frame_tail beyond */
      89         [ #  # ]:          0 :         if (!access_ok(VERIFY_READ, tail, sizeof(buftail)))
      90                 :            :                 return NULL;
      91         [ #  # ]:          0 :         if (__copy_from_user_inatomic(buftail, tail, sizeof(buftail)))
      92                 :            :                 return NULL;
      93                 :            : 
      94                 :          0 :         oprofile_add_trace(buftail[0].lr);
      95                 :            : 
      96                 :            :         /* frame pointers should strictly progress back up the stack
      97                 :            :          * (towards higher addresses) */
      98         [ #  # ]:          0 :         if (tail + 1 >= buftail[0].fp)
      99                 :            :                 return NULL;
     100                 :            : 
     101                 :          0 :         return buftail[0].fp-1;
     102                 :            : }
     103                 :            : 
     104                 :          0 : static void arm_backtrace(struct pt_regs * const regs, unsigned int depth)
     105                 :            : {
     106                 :          0 :         struct frame_tail *tail = ((struct frame_tail *) regs->ARM_fp) - 1;
     107                 :            : 
     108         [ #  # ]:          0 :         if (!user_mode(regs)) {
     109                 :            :                 struct stackframe frame;
     110                 :          0 :                 frame.fp = regs->ARM_fp;
     111                 :          0 :                 frame.sp = regs->ARM_sp;
     112                 :          0 :                 frame.lr = regs->ARM_lr;
     113                 :          0 :                 frame.pc = regs->ARM_pc;
     114                 :          0 :                 walk_stackframe(&frame, report_trace, &depth);
     115                 :          0 :                 return;
     116                 :            :         }
     117                 :            : 
     118 [ #  # ][ #  # ]:          0 :         while (depth-- && tail && !((unsigned long) tail & 3))
                 [ #  # ]
     119                 :          0 :                 tail = user_backtrace(tail);
     120                 :            : }
     121                 :            : 
     122                 :          0 : int __init oprofile_arch_init(struct oprofile_operations *ops)
     123                 :            : {
     124                 :            :         /* provide backtrace support also in timer mode: */
     125                 :          0 :         ops->backtrace               = arm_backtrace;
     126                 :            : 
     127                 :          0 :         return oprofile_perf_init(ops);
     128                 :            : }
     129                 :            : 
     130                 :          0 : void oprofile_arch_exit(void)
     131                 :            : {
     132                 :          0 :         oprofile_perf_exit();
     133                 :          0 : }

Generated by: LCOV version 1.9