xref: /freebsd/sys/kern/kern_pmc.c (revision 36c0fd9d0fb62e50ec668ba7c50c5bffaf9464d6)
1ebccf1e3SJoseph Koshy /*-
236c0fd9dSJoseph Koshy  * Copyright (c) 2003-2005, Joseph Koshy
3ebccf1e3SJoseph Koshy  *
4ebccf1e3SJoseph Koshy  * Redistribution and use in source and binary forms, with or without
5ebccf1e3SJoseph Koshy  * modification, are permitted provided that the following conditions
6ebccf1e3SJoseph Koshy  * are met:
7ebccf1e3SJoseph Koshy  * 1. Redistributions of source code must retain the above copyright
8ebccf1e3SJoseph Koshy  *    notice, this list of conditions and the following disclaimer.
9ebccf1e3SJoseph Koshy  * 2. Redistributions in binary form must reproduce the above copyright
10ebccf1e3SJoseph Koshy  *    notice, this list of conditions and the following disclaimer in the
11ebccf1e3SJoseph Koshy  *    documentation and/or other materials provided with the distribution.
12ebccf1e3SJoseph Koshy  *
13ebccf1e3SJoseph Koshy  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
14ebccf1e3SJoseph Koshy  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15ebccf1e3SJoseph Koshy  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16ebccf1e3SJoseph Koshy  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
17ebccf1e3SJoseph Koshy  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18ebccf1e3SJoseph Koshy  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19ebccf1e3SJoseph Koshy  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20ebccf1e3SJoseph Koshy  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21ebccf1e3SJoseph Koshy  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22ebccf1e3SJoseph Koshy  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23ebccf1e3SJoseph Koshy  * SUCH DAMAGE.
24ebccf1e3SJoseph Koshy  */
25ebccf1e3SJoseph Koshy 
26ebccf1e3SJoseph Koshy #include <sys/cdefs.h>
27ebccf1e3SJoseph Koshy __FBSDID("$FreeBSD$");
28ebccf1e3SJoseph Koshy 
29ebccf1e3SJoseph Koshy #include <sys/pmckern.h>
30ebccf1e3SJoseph Koshy #include <sys/smp.h>
31ebccf1e3SJoseph Koshy 
32ebccf1e3SJoseph Koshy struct sx pmc_sx;
33ebccf1e3SJoseph Koshy 
34ebccf1e3SJoseph Koshy /* Hook variable. */
35ebccf1e3SJoseph Koshy int (*pmc_hook)(struct thread *td, int function, void *arg) = NULL;
36ebccf1e3SJoseph Koshy 
37ebccf1e3SJoseph Koshy /* Interrupt handler */
3836c0fd9dSJoseph Koshy int (*pmc_intr)(int cpu, uintptr_t pc, int usermode) = NULL;
3936c0fd9dSJoseph Koshy 
4036c0fd9dSJoseph Koshy cpumask_t pmc_cpumask;
41ebccf1e3SJoseph Koshy 
42ebccf1e3SJoseph Koshy /*
43ebccf1e3SJoseph Koshy  * Since PMC(4) may not be loaded in the current kernel, the
44ebccf1e3SJoseph Koshy  * convention followed is that a non-NULL value of 'pmc_hook' implies
45ebccf1e3SJoseph Koshy  * the presence of this kernel module.
46ebccf1e3SJoseph Koshy  *
47ebccf1e3SJoseph Koshy  * This requires us to protect 'pmc_hook' with a
48ebccf1e3SJoseph Koshy  * shared (sx) lock -- thus making the process of calling into PMC(4)
49ebccf1e3SJoseph Koshy  * somewhat more expensive than a simple 'if' check and indirect call.
50ebccf1e3SJoseph Koshy  */
51ebccf1e3SJoseph Koshy 
52ebccf1e3SJoseph Koshy 
53ebccf1e3SJoseph Koshy SX_SYSINIT(pmc, &pmc_sx, "pmc shared lock");
54ebccf1e3SJoseph Koshy 
55ebccf1e3SJoseph Koshy /*
56ebccf1e3SJoseph Koshy  * pmc_cpu_is_disabled
57ebccf1e3SJoseph Koshy  *
58ebccf1e3SJoseph Koshy  * return TRUE if the cpu specified has been disabled.
59ebccf1e3SJoseph Koshy  */
60ebccf1e3SJoseph Koshy 
61ebccf1e3SJoseph Koshy int
62ebccf1e3SJoseph Koshy pmc_cpu_is_disabled(int cpu)
63ebccf1e3SJoseph Koshy {
64ebccf1e3SJoseph Koshy #ifdef	SMP
65ebccf1e3SJoseph Koshy 	return ((hlt_cpus_mask & (1 << cpu)) != 0);
66ebccf1e3SJoseph Koshy #else
67ebccf1e3SJoseph Koshy 	return 0;
68ebccf1e3SJoseph Koshy #endif
69ebccf1e3SJoseph Koshy }
70ebccf1e3SJoseph Koshy 
71ebccf1e3SJoseph Koshy int
72ebccf1e3SJoseph Koshy pmc_cpu_is_logical(int cpu)
73ebccf1e3SJoseph Koshy {
74ebccf1e3SJoseph Koshy #ifdef	SMP
75ebccf1e3SJoseph Koshy 	return ((logical_cpus_mask & (1 << cpu)) != 0);
76ebccf1e3SJoseph Koshy #else
77ebccf1e3SJoseph Koshy 	return 0;
78ebccf1e3SJoseph Koshy #endif
79ebccf1e3SJoseph Koshy }
80