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/kern/sys_pmc.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: sys_pmc.c,v 1.10 2008/04/21 12:56:31 ad Exp $  */
    2 
    3 /*
    4  * Copyright (c) 2002 Wasabi Systems, Inc.
    5  * All rights reserved.
    6  *
    7  * Written by Allen Briggs for Wasabi Systems, Inc.
    8  *
    9  * Redistribution and use in source and binary forms, with or without
   10  * modification, are permitted provided that the following conditions
   11  * are met:
   12  * 1. Redistributions of source code must retain the above copyright
   13  *    notice, this list of conditions and the following disclaimer.
   14  * 2. Redistributions in binary form must reproduce the above copyright
   15  *    notice, this list of conditions and the following disclaimer in the
   16  *    documentation and/or other materials provided with the distribution.
   17  * 3. All advertising materials mentioning features or use of this software
   18  *    must display the following acknowledgement:
   19  *      This product includes software developed for the NetBSD Project by
   20  *      Wasabi Systems, Inc.
   21  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
   22  *    or promote products derived from this software without specific prior
   23  *    written permission.
   24  *
   25  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
   26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   27  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   28  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
   29  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   30  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   32  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   33  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   34  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   35  * POSSIBILITY OF SUCH DAMAGE.
   36  */
   37 
   38 #include <sys/cdefs.h>
   39 __KERNEL_RCSID(0, "$NetBSD: sys_pmc.c,v 1.10 2008/04/21 12:56:31 ad Exp $");
   40 
   41 #include "opt_perfctrs.h"
   42 
   43 #include <sys/param.h>
   44 #include <sys/proc.h>
   45 #include <sys/mount.h>
   46 #include <sys/systm.h>
   47 #include <sys/syscallargs.h>
   48 #include <sys/types.h>
   49 
   50 #if defined(PERFCTRS)
   51 #include <sys/pmc.h>
   52 #endif
   53 
   54 /*
   55  * XXX We need a multiprocessor locking protocol!
   56  */
   57 
   58 int
   59 sys_pmc_control(struct lwp *l, const struct sys_pmc_control_args *uap, register_t *retval)
   60 {
   61         /* {
   62                 syscallarg(int) ctr;
   63                 syscallarg(int) op;
   64                 syscallarg(void *) args;
   65         } */
   66 #ifndef PERFCTRS
   67         return ENXIO;
   68 #else
   69         struct pmc_counter_cfg cfg;
   70         void *args;
   71         int ctr, operation, error=0;
   72 
   73         ctr = SCARG(uap, ctr);
   74         operation = SCARG(uap, op);
   75 
   76         KERNEL_LOCK(1, NULL);
   77         switch (operation) {
   78         case PMC_OP_START:
   79                 if (!pmc_counter_isconfigured(l->l_proc, ctr)) {
   80                         error = ENXIO;
   81                 } else if (pmc_counter_isrunning(l->l_proc, ctr)) {
   82                         error = EINPROGRESS;
   83                 } else {
   84                         pmc_enable_counter(l->l_proc, ctr);
   85                 }
   86                 break;
   87         case PMC_OP_STOP:
   88                 if (!pmc_counter_isconfigured(l->l_proc, ctr)) {
   89                         error = ENXIO;
   90                 } else if (pmc_counter_isrunning(l->l_proc, ctr)) {
   91                         pmc_disable_counter(l->l_proc, ctr);
   92                 }
   93                 break;
   94         case PMC_OP_CONFIGURE:
   95                 args = SCARG(uap, args);
   96 
   97                 if (pmc_counter_isrunning(l->l_proc, ctr)) {
   98                         pmc_disable_counter(l->l_proc, ctr);
   99                 }
  100                 error = copyin(args, &cfg, sizeof(struct pmc_counter_cfg));
  101                 if (error == 0) {
  102                         error = pmc_configure_counter(l->l_proc, ctr, &cfg);
  103                 }
  104                 break;
  105         case PMC_OP_PROFSTART:
  106                 args = SCARG(uap, args);
  107 
  108                 error = copyin(args, &cfg, sizeof(struct pmc_counter_cfg));
  109                 if (error == 0) {
  110                         error = pmc_start_profiling(ctr, &cfg);
  111                 }
  112                 break;
  113         case PMC_OP_PROFSTOP:
  114                 error = pmc_stop_profiling(ctr);
  115                 break;
  116         default:
  117                 error = EINVAL;
  118                 break;
  119         }
  120         KERNEL_UNLOCK_ONE(NULL);
  121         return error;
  122 #endif
  123 }
  124 
  125 int
  126 sys_pmc_get_info(struct lwp *l, const struct sys_pmc_get_info_args *uap, register_t *retval)
  127 {
  128         /* {
  129                 syscallarg(int) ctr;
  130                 syscallarg(int) op;
  131                 syscallarg(void *) args;
  132         } */
  133 #ifndef PERFCTRS
  134         return ENXIO;
  135 #else
  136         uint64_t val;
  137         void *args;
  138         int nctrs, ctr, ctrt, request, error=0, flags=0;
  139 
  140         ctr = SCARG(uap, ctr);
  141         request = SCARG(uap, op);
  142         args = SCARG(uap, args);
  143 
  144         KERNEL_LOCK(1, NULL);
  145         nctrs = pmc_get_num_counters();
  146         switch (request) {
  147         case PMC_INFO_NCOUNTERS:        /* args should be (int *) */
  148                 error = copyout(&nctrs, args, sizeof(int));
  149                 break;
  150 
  151         case PMC_INFO_CPUCTR_TYPE:      /* args should be (int *) */
  152                 ctrt = pmc_get_counter_type(ctr);
  153                 error = copyout(&ctrt, args, sizeof(int));
  154                 break;
  155                                         /* args should be (pmc_ctr_t *) */
  156         case PMC_INFO_ACCUMULATED_COUNTER_VALUE:
  157                 flags = PMC_VALUE_FLAGS_CHILDREN;
  158                 /*FALLTHROUGH*/
  159         case PMC_INFO_COUNTER_VALUE:
  160                 if (ctr < 0 || ctr >= nctrs) {
  161                         error = EINVAL;
  162                         break;
  163                 }
  164                 error = pmc_get_counter_value(l->l_proc, ctr, flags, &val);
  165                 if (error == 0) {
  166                         error = copyout(&val, args, sizeof(uint64_t));
  167                 }
  168                 break;
  169         default:
  170                 error = EINVAL;
  171                 break;
  172         }
  173         KERNEL_UNLOCK_ONE(NULL);
  174         return error;
  175 #endif
  176 }

Cache object: 2ad8a79a63b53600e0d871d280044b8f


[ 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.