1 /*        $NetBSD: tprof_types.h,v 1.7 2023/04/11 10:07:12 msaitoh Exp $        */
2 
3 /*-
4  * Copyright (c)2010,2011 YAMAMOTO Takashi,
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 #ifndef _DEV_TPROF_TPROF_TYPES_H_
30 #define _DEV_TPROF_TPROF_TYPES_H_
31 
32 /*
33  * definitions used by both kernel and userland
34  */
35 
36 #if defined(_KERNEL)
37 #include <sys/types.h>
38 #else
39 #include <stdint.h>
40 #endif
41 
42 #define TPROF_MAXCOUNTERS     32
43 typedef uint32_t tprof_countermask_t;
44 #define TPROF_COUNTERMASK_ALL __BITS(31, 0)
45 
46 typedef struct {
47           uint32_t s_pid;               /* process id */
48           uint32_t s_lwpid;   /* lwp id */
49           uint32_t s_cpuid;   /* cpu id */
50           uint32_t s_flags;   /* flags and counterID */
51 #define TPROF_SAMPLE_INKERNEL 0x00000001 /* s_pc is in kernel address space */
52 #define   TPROF_SAMPLE_COUNTER_MASK 0xff000000 /* 0..(TPROF_MAXCOUNTERS-1) */
53           uintptr_t s_pc;               /* program counter */
54 } tprof_sample_t;
55 
56 typedef struct tprof_param {
57           u_int p_counter;    /* 0..(TPROF_MAXCOUNTERS-1) */
58           u_int p__unused;
59           uint64_t p_event;   /* event class */
60           uint64_t p_unit;    /* unit within the event class */
61           uint64_t p_flags;
62 #define   TPROF_PARAM_KERN              0x1
63 #define   TPROF_PARAM_USER              0x2
64 #define   TPROF_PARAM_PROFILE           0x4
65 #define   TPROF_PARAM_VALUE2_MASK                 __BITS(63, 60)
66 #define   TPROF_PARAM_VALUE2_SCALE      __SHIFTIN(1, TPROF_PARAM_VALUE2_MASK)
67 #define   TPROF_PARAM_VALUE2_TRIGGERCOUNT         __SHIFTIN(2, TPROF_PARAM_VALUE2_MASK)
68           uint64_t p_value;   /* initial value */
69           uint64_t p_value2;
70           /*
71            * p_value2 is an optional value. (p_flags & TPROF_PARAM_VALUE2_MASK)
72            * determines the usage.
73            *
74            * TPROF_PARAM_VALUE2_SCALE:
75            *   Specify the counter speed as the reciprocal of the cycle counter
76            *   speed ratio. if the counter is N times slower than the cycle
77            *   counter, p_value2 is (0x1_0000_0000 / N). 0 is treated as 1.0.
78            * TPROF_PARAM_VALUE2_TRIGGERCOUNT:
79            *   When the event counter counts up p_value2, an interrupt for
80            *   profile is generated. 0 is treated as 1.
81            */
82 } tprof_param_t;
83 
84 typedef struct tprof_counts {
85           uint32_t c_cpu;                                   /* W */
86           uint32_t c_ncounters;                             /* R */
87           tprof_countermask_t c_runningmask;      /* R */
88           uint32_t c__unused;
89           uint64_t c_count[TPROF_MAXCOUNTERS];    /* R */
90 } tprof_counts_t;
91 
92 /* ti_ident */
93 #define   TPROF_IDENT_NONE              0x00
94 #define   TPROF_IDENT_INTEL_GENERIC     0x01
95 #define   TPROF_IDENT_AMD_GENERIC                 0x02
96 #define   TPROF_IDENT_ARMV8_GENERIC     0x03
97 #define   TPROF_IDENT_ARMV7_GENERIC     0x04
98 
99 #endif /* _DEV_TPROF_TPROF_TYPES_H_ */
100