2 * Copyright (c) 2014 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 #include <sys/types.h>
45 #define UPMAP_MAXPROCTITLE 1024
46 #define LPMAP_MAXTHREADTITLE 1024
47 #define LPMAP_MAPSIZE 65536
48 #define UPMAP_MAPSIZE 65536
49 #define KPMAP_MAPSIZE 65536
51 #define LPMAP_VERSION 1
52 #define UPMAP_VERSION 1
53 #define KPMAP_VERSION 1
55 typedef uint64_t forkid_t;
57 typedef struct ukpheader {
58 uint16_t type; /* element type */
59 uint16_t offset; /* offset from map base, max 65535 */
62 #define UKPLEN_MASK 0x0F00
63 #define UKPLEN_1 0x0000
64 #define UKPLEN_2 0x0100
65 #define UKPLEN_4 0x0200
66 #define UKPLEN_8 0x0300
67 #define UKPLEN_16 0x0400
68 #define UKPLEN_32 0x0500
69 #define UKPLEN_64 0x0600
70 #define UKPLEN_128 0x0700
71 #define UKPLEN_256 0x0800
72 #define UKPLEN_512 0x0900
73 #define UKPLEN_1024 0x0A00
75 #define UKPLEN_TS ((sizeof(struct timespec) == 8) ? \
76 UKPLEN_16 : UKPLEN_32)
77 #define UKPLEN_DECODE(type) (1 << ((type >> 8) & 0x0F))
80 * Global types - may exist in all three mapping types
82 #define UKPTYPE_VERSION (0x0001 | UKPLEN_4) /* always first */
85 * /dev/lpmap - per-thread
87 #define LPTYPE_RESERVEDINT0 (0x4010 | UKPLEN_4)
88 #define LPTYPE_RESERVEDINT1 (0x4011 | UKPLEN_4)
89 #define LPTYPE_BLOCKALLSIGS (0x4012 | UKPLEN_4)
90 #define LPTYPE_THREAD_TITLE (0x4013 | UKPLEN_1024)
91 #define LPTYPE_THREAD_TID (0x4014 | UKPLEN_4)
94 * /dev/upmap - per-process
96 #define UPTYPE_RUNTICKS (0x0010 | UKPLEN_4)
97 #define UPTYPE_FORKID (0x0011 | UKPLEN_8)
98 #define UPTYPE_PID (0x0012 | UKPLEN_4)
99 #define UPTYPE_PROC_TITLE (0x0013 | UKPLEN_1024)
100 #define UPTYPE_INVFORK (0x0014 | UKPLEN_4)
103 * /dev/kpmap - kernel-wide
105 #define KPTYPE_UPTICKS (0x8000 | UKPLEN_4)
106 #define KPTYPE_TS_UPTIME (0x8001 | UKPLEN_TS)
107 #define KPTYPE_TS_REALTIME (0x8002 | UKPLEN_TS)
108 #define KPTYPE_TSC_FREQ (0x8003 | UKPLEN_8)
109 #define KPTYPE_TICK_FREQ (0x8004 | UKPLEN_8)
110 #define KPTYPE_FAST_GTOD (0x8005 | UKPLEN_4)
112 #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
115 * (writable) user per-thread map via /dev/lpmap.
117 * ABSOLUTE LOCATIONS CAN CHANGE, ITERATE HEADERS FOR THE TYPE YOU DESIRE
118 * UNTIL YOU HIT TYPE 0, THEN CACHE THE RESULTING POINTER.
120 * If you insist, at least check that the version matches LPMAP_VERSION.
124 * The current thread can block all blockable signals by (atomically)
125 * incrementing blockallsigs. If the kernel receives a signal while
126 * the low 31 bits of blockallsigs are non-zero, the received signal
127 * will be made pending but not acted upon and bit 31 of blockallsigs
128 * will be set. The signal mask is not affected.
130 * Upon decrementing blockallsigs to 0 (low 31 bits to 0), again atomically,
131 * userland should then check to see if bit 31 is set, clear it, and then
132 * issue any real system call to force the kernel to re-check pending signals
136 ukpheader_t header[64];
140 uint32_t blockallsigs;
141 char thread_title[LPMAP_MAXTHREADTITLE];
145 * (writable) user per-process map via /dev/upmap.
147 * ABSOLUTE LOCATIONS CAN CHANGE, ITERATE HEADERS FOR THE TYPE YOU DESIRE
148 * UNTIL YOU HIT TYPE 0, THEN CACHE THE RESULTING POINTER.
150 * If you insist, at least check that the version matches UPMAP_VERSION.
153 ukpheader_t header[64];
155 uint32_t runticks; /* running scheduler ticks */
156 forkid_t forkid; /* unique 2^64 (fork detect) NOT MONO */
157 uint32_t invfork; /* vfork active */
158 pid_t pid; /* process id */
159 uint32_t reserved[16];
160 char proc_title[UPMAP_MAXPROCTITLE];
164 * (read-only) kernel per-cpu map via /dev/kpmap.
166 * ABSOLUTE LOCATIONS CAN CHANGE, ITERATE HEADERS FOR THE TYPE YOU DESIRE
167 * UNTIL YOU HIT TYPE 0, THEN CACHE THE RESULTING POINTER.
169 * If you insist, at least check that the version matches KPMAP_VERSION.
171 * Procedure for reading stable values from ts_uptime/ts_realtime. This
172 * avoids looping in nearly all cases, including during a kernel update.
173 * The only case where this might loop is if the kernel deschedules
174 * the user thread for more than 1 tick.
179 * load ts_uptime[w & 1] or ts_realtime[w & 1]
185 ukpheader_t header[64];
187 int32_t upticks; /* userland reads ts_*[upticks & 1] */
188 struct timespec ts_uptime[2]; /* mono uptime @ticks (uncompensated) */
189 struct timespec ts_realtime[2]; /* realtime @ticks resolution */
190 int64_t tsc_freq; /* (if supported by cpu) */
191 int32_t tick_freq; /* scheduler tick frequency */
192 int32_t fast_gtod; /* fast gettimeofday() */
198 extern struct sys_kpmap *kpmap;