The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/mips/rmi/perfmon_kern.c

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 2003-2009 RMI Corporation
    3  * All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    8  * 1. Redistributions of source code must retain the above copyright
    9  *    notice, this list of conditions and the following disclaimer.
   10  * 2. Redistributions in binary form must reproduce the above copyright
   11  *    notice, this list of conditions and the following disclaimer in the
   12  *    documentation and/or other materials provided with the distribution.
   13  * 3. Neither the name of RMI Corporation, nor the names of its contributors,
   14  *    may be used to endorse or promote products derived from this software
   15  *    without specific prior written permission.
   16  *
   17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   27  * SUCH DAMAGE.
   28  *
   29  * RMI_BSD */
   30 
   31 #include <sys/param.h>
   32 #include <sys/systm.h>
   33 #include <sys/kernel.h>
   34 #include <sys/malloc.h>
   35 #include <sys/pcpu.h>
   36 #include <sys/proc.h>
   37 #include <sys/smp.h>
   38 #include <sys/sysctl.h>
   39 #include <machine/smp.h>
   40 #include <mips/rmi/perfmon.h>
   41 #include <mips/rmi/pic.h>
   42 #include <sys/mutex.h>
   43 #include <mips/rmi/clock.h>
   44 
   45 
   46 int xlr_perfmon_started = 0;
   47 struct perf_area *xlr_shared_config_area = NULL;
   48 uint32_t *xlr_perfmon_timer_loc;
   49 uint32_t *xlr_cpu_sampling_interval;
   50 uint32_t xlr_perfmon_kernel_version = 1;        /* Future use */
   51 uint32_t xlr_perfmon_ticks;
   52 extern int mips_cpu_online_mask;
   53 extern uint32_t cpu_ltop_map[MAXCPU];
   54 
   55 #ifdef SMP
   56 static __inline__ void 
   57 pic_send_perfmon_ipi(int cpu)
   58 {
   59         xlr_reg_t *mmio = xlr_io_mmio(XLR_IO_PIC_OFFSET);
   60         int tid, pid;
   61         uint32_t ipi;
   62 
   63         tid = cpu & 0x3;
   64         pid = (cpu >> 2) & 0x7;
   65         ipi = (pid << 20) | (tid << 16) | IPI_PERFMON;
   66 
   67         mtx_lock_spin(&xlr_pic_lock);
   68         xlr_write_reg(mmio, PIC_IPI, ipi);
   69         mtx_unlock_spin(&xlr_pic_lock);
   70 }
   71 
   72 #endif
   73 
   74 
   75 void
   76 xlr_perfmon_clockhandler(void)
   77 {
   78 #ifdef SMP
   79         int cpu;
   80         int i;
   81 
   82 #endif
   83 
   84         if (xlr_perfmon_ticks++ >= (*xlr_cpu_sampling_interval) / (XLR_PIC_HZ / (hz * 1024))) {
   85 
   86                 /* update timer */
   87                 *xlr_perfmon_timer_loc += *xlr_cpu_sampling_interval;
   88                 xlr_perfmon_ticks = 0;
   89                 xlr_perfmon_sampler(NULL);
   90 #ifdef SMP
   91                 for (i = 0; i < NCPUS; i = i + NTHREADS) {      /* oly thread 0 */
   92                         cpu = cpu_ltop_map[i];
   93                         if ((mips_cpu_online_mask & (1 << i)) &&
   94                             xlr_shared_config_area[cpu / NTHREADS].perf_config.magic ==
   95                             PERFMON_ACTIVE_MAGIC)
   96                                 pic_send_perfmon_ipi(cpu);
   97                 }
   98 
   99 #endif
  100 
  101         }
  102 }
  103 
  104 static void
  105 xlr_perfmon_start(void)
  106 {
  107         size_t size;
  108 
  109         size = (NCORES * sizeof(*xlr_shared_config_area)) +
  110             sizeof(*xlr_perfmon_timer_loc) +
  111             sizeof(*xlr_cpu_sampling_interval);
  112 
  113         xlr_shared_config_area = malloc(size, M_TEMP, M_WAITOK);
  114         if (!xlr_shared_config_area) {
  115                 /* ERROR */
  116                 return;
  117         }
  118         xlr_perfmon_timer_loc = (uint32_t *) (xlr_shared_config_area + NCORES);
  119         xlr_cpu_sampling_interval = (uint32_t *) (xlr_perfmon_timer_loc + 1);
  120 
  121         *xlr_cpu_sampling_interval = DEFAULT_CPU_SAMPLING_INTERVAL;
  122         *xlr_perfmon_timer_loc = 0;
  123         xlr_perfmon_ticks = 0;
  124 
  125         xlr_perfmon_init_cpu(NULL);
  126 #ifdef SMP
  127         smp_call_function(xlr_perfmon_init_cpu, NULL,
  128             PCPU_GET(other_cpus) & 0x11111111);
  129 #endif
  130         xlr_perfmon_started = 1;
  131 
  132 }
  133 
  134 static void
  135 xlr_perfmon_stop(void)
  136 {
  137         xlr_perfmon_started = 0;
  138         free(xlr_shared_config_area, M_TEMP);
  139         xlr_shared_config_area = NULL;
  140 }
  141 
  142 static int
  143 sysctl_xlr_perfmon_start_stop(SYSCTL_HANDLER_ARGS)
  144 {
  145         int error, val = xlr_perfmon_started;
  146 
  147         error = sysctl_handle_int(oidp, &val, 0, req);
  148         if (error != 0 || req->newptr == NULL)
  149                 return (error);
  150 
  151         if (!xlr_perfmon_started && val != 0)
  152                 xlr_perfmon_start();
  153         else if (xlr_perfmon_started && val == 0)
  154                 xlr_perfmon_stop();
  155 
  156         return (0);
  157 }
  158 
  159 
  160 SYSCTL_NODE(_debug, OID_AUTO, xlrperf, CTLFLAG_RW, NULL, "XLR PERF Nodes");
  161 SYSCTL_PROC(_debug_xlrperf, OID_AUTO, start, CTLTYPE_INT | CTLFLAG_RW,
  162     &xlr_perfmon_started, 0, sysctl_xlr_perfmon_start_stop, "I", "set/unset to start/stop "
  163     "performance monitoring");

Cache object: 31e80bf21d4d6fd57acb4714899d05c8


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.