geniconvtbl: small cstyle fix
[unleashed.git] / kernel / syscall / profil.c
blob225d5590c544aeccca218e802d6e7f4970009981
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright (c) 1998, Sun Microsystems, Inc.
24 * All rights reserved.
25 * Copyright 2012 Milan Jurik. All rights reserved.
28 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
29 /* All Rights Reserved */
31 #include <sys/param.h>
32 #include <sys/types.h>
33 #include <sys/sysmacros.h>
34 #include <sys/systm.h>
35 #include <sys/errno.h>
36 #include <sys/proc.h>
37 #include <sys/debug.h>
40 * Profiling.
42 int
43 profil(unsigned short *bufbase, size_t bufsize, ulong_t pcoffset,
44 uint_t pcscale)
46 struct proc *p = ttoproc(curthread);
48 if (pcscale == 1)
49 pcscale = 0;
51 mutex_enter(&p->p_pflock);
52 p->p_prof.pr_base = bufbase;
53 p->p_prof.pr_size = bufsize;
54 p->p_prof.pr_off = pcoffset;
55 p->p_prof.pr_scale = pcscale;
57 /* pcsample and profil are mutually exclusive */
58 p->p_prof.pr_samples = 0;
60 mutex_exit(&p->p_pflock);
61 mutex_enter(&p->p_lock);
62 set_proc_post_sys(p); /* activate post_syscall profiling code */
63 mutex_exit(&p->p_lock);
64 return (0);
69 * PC Sampling
71 long
72 pcsample(void *buf, long nsamples)
74 struct proc *p = ttoproc(curthread);
75 long count = 0;
77 if (nsamples < 0 ||
78 ((get_udatamodel() != DATAMODEL_NATIVE) && (nsamples > INT32_MAX)))
79 return (set_errno(EINVAL));
81 mutex_enter(&p->p_pflock);
82 p->p_prof.pr_base = buf;
83 p->p_prof.pr_size = nsamples;
84 p->p_prof.pr_scale = 1;
85 count = p->p_prof.pr_samples;
86 p->p_prof.pr_samples = 0;
87 mutex_exit(&p->p_pflock);
89 mutex_enter(&p->p_lock);
90 set_proc_post_sys(p); /* activate post_syscall profiling code */
91 mutex_exit(&p->p_lock);
93 return (count);