1100844Sjake/*-
2100844Sjake * Copyright (c) 1996 Bruce D. Evans.
3100844Sjake * Copyright (c) 2002 by Thomas Moestl <tmm@FreeBSD.org>.
4100844Sjake * All rights reserved.
5100844Sjake *
6100844Sjake * Redistribution and use in source and binary forms, with or without
7100844Sjake * modification, are permitted provided that the following conditions
8100844Sjake * are met:
9100844Sjake * 1. Redistributions of source code must retain the above copyright
10100844Sjake *    notice, this list of conditions and the following disclaimer.
11100844Sjake * 2. Redistributions in binary form must reproduce the above copyright
12100844Sjake *    notice, this list of conditions and the following disclaimer in the
13100844Sjake *    documentation and/or other materials provided with the distribution.
14100844Sjake *
15100844Sjake * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16100844Sjake * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17100844Sjake * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18100844Sjake * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19100844Sjake * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20100844Sjake * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21100844Sjake * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22100844Sjake * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23100844Sjake * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24100844Sjake * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25100844Sjake * SUCH DAMAGE.
26100844Sjake *
27100844Sjake *	from: src/sys/i386/isa/prof_machdep.c,v 1.16 2000/07/04 11:25:19
28100844Sjake */
29100844Sjake
30181701Smarius#include <sys/cdefs.h>
31181701Smarius__FBSDID("$FreeBSD$");
32181701Smarius
33100844Sjake#ifdef GUPROF
34100844Sjake
35100844Sjake#include <sys/param.h>
36100844Sjake#include <sys/systm.h>
37100844Sjake#include <sys/gmon.h>
38100844Sjake#include <sys/kernel.h>
39100844Sjake#include <sys/sysctl.h>
40100844Sjake
41100844Sjake#include <machine/profile.h>
42100844Sjake
43100844Sjakeint	cputime_bias;
44100844Sjake
45100844Sjake/*
46100844Sjake * Return the time elapsed since the last call.  The units are machine-
47100844Sjake * dependent.
48181701Smarius * XXX: this is not SMP-safe.  It should use per-CPU variables; %tick can be
49100844Sjake * used though.
50100844Sjake */
51100844Sjakeint
52100844Sjakecputime(void)
53100844Sjake{
54100844Sjake	u_long count;
55181701Smarius	static u_long prev_count;
56100844Sjake	int delta;
57100844Sjake
58100844Sjake	count = rd(tick);
59100844Sjake	delta = (int)(count - prev_count);
60100844Sjake	prev_count = count;
61100844Sjake	return (delta);
62100844Sjake}
63100844Sjake
64100844Sjake/*
65100844Sjake * The start and stop routines need not be here since we turn off profiling
66100844Sjake * before calling them.  They are here for convenience.
67100844Sjake */
68100844Sjakevoid
69100844Sjakestartguprof(struct gmonparam *gp)
70100844Sjake{
71100844Sjake
72100844Sjake	gp->profrate = tick_freq;
73100844Sjake	cputime_bias = 0;
74100844Sjake	cputime();
75100844Sjake}
76100844Sjake
77100844Sjakevoid
78100844Sjakestopguprof(struct gmonparam *gp)
79100844Sjake{
80181701Smarius
81100844Sjake	/* Nothing to do. */
82100844Sjake}
83100844Sjake
84100844Sjake#endif /* GUPROF */
85