xref: /dflybsd-src/share/man/man4/upmap.4 (revision fb3c2c0caaaa0e5d800e088b7dd7983e9ab009ec)
11ec97b1eSSascha Wildner.\"
21ec97b1eSSascha Wildner.\" Copyright (c) 2014 The DragonFly Project.  All rights reserved.
31ec97b1eSSascha Wildner.\"
41ec97b1eSSascha Wildner.\" Redistribution and use in source and binary forms, with or without
51ec97b1eSSascha Wildner.\" modification, are permitted provided that the following conditions
61ec97b1eSSascha Wildner.\" are met:
71ec97b1eSSascha Wildner.\"
81ec97b1eSSascha Wildner.\" 1. Redistributions of source code must retain the above copyright
91ec97b1eSSascha Wildner.\"    notice, this list of conditions and the following disclaimer.
101ec97b1eSSascha Wildner.\" 2. Redistributions in binary form must reproduce the above copyright
111ec97b1eSSascha Wildner.\"    notice, this list of conditions and the following disclaimer in
121ec97b1eSSascha Wildner.\"    the documentation and/or other materials provided with the
131ec97b1eSSascha Wildner.\"    distribution.
141ec97b1eSSascha Wildner.\" 3. Neither the name of The DragonFly Project nor the names of its
151ec97b1eSSascha Wildner.\"    contributors may be used to endorse or promote products derived
161ec97b1eSSascha Wildner.\"    from this software without specific, prior written permission.
171ec97b1eSSascha Wildner.\"
181ec97b1eSSascha Wildner.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
191ec97b1eSSascha Wildner.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
201ec97b1eSSascha Wildner.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
211ec97b1eSSascha Wildner.\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
221ec97b1eSSascha Wildner.\" COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
231ec97b1eSSascha Wildner.\" INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
241ec97b1eSSascha Wildner.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
251ec97b1eSSascha Wildner.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
261ec97b1eSSascha Wildner.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
271ec97b1eSSascha Wildner.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
281ec97b1eSSascha Wildner.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
291ec97b1eSSascha Wildner.\" SUCH DAMAGE.
301ec97b1eSSascha Wildner.\"
311ec97b1eSSascha Wildner.Dd October 25, 2014
321ec97b1eSSascha Wildner.Dt UPMAP 4
331ec97b1eSSascha Wildner.Os
341ec97b1eSSascha Wildner.Sh NAME
351ec97b1eSSascha Wildner.Nm upmap ,
361ec97b1eSSascha Wildner.Nm kpmap
371ec97b1eSSascha Wildner.Nd character device files
381ec97b1eSSascha Wildner.Sh DESCRIPTION
391ec97b1eSSascha WildnerThe special files
401ec97b1eSSascha Wildner.Pa /dev/upmap
411ec97b1eSSascha Wildnerand
421ec97b1eSSascha Wildner.Pa /dev/kpmap
431ec97b1eSSascha Wildnerare memory-mappable devices for accessing per-process and global kernel shared
441ec97b1eSSascha Wildnermemory space respectively.
451ec97b1eSSascha WildnerThey can be mapped to acquire certain information from the kernel that would
461ec97b1eSSascha Wildnernormally require a system call in a more efficient manner.
471ec97b1eSSascha Wildner.Pp
481ec97b1eSSascha WildnerUserland programs should not directly map the
491ec97b1eSSascha Wildner.Vt sys_upmap
501ec97b1eSSascha Wildnerand
511ec97b1eSSascha Wildner.Vt sys_kpmap
521ec97b1eSSascha Wildnerstructures.
531ec97b1eSSascha WildnerInstead, use
541ec97b1eSSascha Wildner.Xr mmap 2
551ec97b1eSSascha Wildnerusing
561ec97b1eSSascha Wildner.Dv UPMAP_MAPSIZE
571ec97b1eSSascha Wildnerand
581ec97b1eSSascha Wildner.Dv KPMAP_MAPSIZE
591ec97b1eSSascha Wildnerand parse the
601ec97b1eSSascha Wildner.Fa ukpheader[]
611ec97b1eSSascha Wildnerarray at the front of each area to locate the desired fields.
621ec97b1eSSascha Wildner.Pp
631ec97b1eSSascha WildnerThe width of the field is encoded in the UPTYPE/KPTYPE elements and can be
641ec97b1eSSascha Wildnerasserted if desired.
651ec97b1eSSascha WildnerUser programs are not expected to handle integers of multiple sizes for
661ec97b1eSSascha Wildnerthe same field type.
671ec97b1eSSascha Wildner.Sh INTERFACE
681ec97b1eSSascha WildnerDeclarations and data types are to be found in
691ec97b1eSSascha Wildner.In sys/upmap.h .
701ec97b1eSSascha Wildner.Pp
711ec97b1eSSascha WildnerA program can open and
721ec97b1eSSascha Wildner.Xr mmap 2
731ec97b1eSSascha Wildner.Pa /dev/upmap
741ec97b1eSSascha Wildnerread/write and use it to access fields from
751ec97b1eSSascha Wildner.Vt struct sys_upmap :
761ec97b1eSSascha Wildner.Bl -tag -width ".Fa proc_title"
771ec97b1eSSascha Wildner.It Fa header[]
781ec97b1eSSascha WildnerAn array of headers terminating with a type of 0 indicating where
791ec97b1eSSascha Wildnervarious fields are in the mapping.
801ec97b1eSSascha WildnerThis should be used by userland instead of directly mapping to the
811ec97b1eSSascha Wildner.Vt struct sys_upmap .
821ec97b1eSSascha Wildner.It Fa version
831ec97b1eSSascha WildnerThe
841ec97b1eSSascha Wildner.Vt struct sys_upmap
851ec97b1eSSascha Wildnerversion, typically 1.
861ec97b1eSSascha Wildner.It Fa runticks
871ec97b1eSSascha WildnerScheduler run ticks (aggregate, all threads).
881ec97b1eSSascha WildnerThis may be used by userland interpreters to determine when to soft-switch.
891ec97b1eSSascha Wildner.It Fa forkid
901ec97b1eSSascha WildnerA unique non-zero 64-bit fork identifier.
911ec97b1eSSascha WildnerThis is not a PID.
921ec97b1eSSascha WildnerIt may be used by userland libraries to determine if a
931ec97b1eSSascha Wildner.Fn fork
941ef3b4caSSascha Wildnerhas occurred by comparing against a stored value.
951ec97b1eSSascha Wildner.It Fa invfork
961ec97b1eSSascha WildnerAllows to determine whether this is a vforked child accessing the
971ec97b1eSSascha Wildnerparent's map.
981ec97b1eSSascha Wildner.It Fa pid
991ec97b1eSSascha WildnerThe current process PID.
1001ec97b1eSSascha WildnerThis may be used to acquire the process pid without having to make
1011ec97b1eSSascha Wildnerfurther system calls.
1021ec97b1eSSascha Wildner.It Fa proc_title
1031ec97b1eSSascha WildnerThis starts out as an empty buffer and may be used to set the
1041ec97b1eSSascha Wildnerprocess title.
1051ec97b1eSSascha WildnerTo revert to the original process title, set
1061ec97b1eSSascha Wildner.Fa proc_title[0]
1071ec97b1eSSascha Wildnerto 0.
1081ec97b1eSSascha Wildner.El
1091ec97b1eSSascha Wildner.Pp
1101ec97b1eSSascha WildnerA program can open and
1111ec97b1eSSascha Wildner.Xr mmap 2
1121ec97b1eSSascha Wildner.Pa /dev/kpmap
1131ec97b1eSSascha Wildnerread-only and use it to access fields from
1141ec97b1eSSascha Wildner.Vt struct sys_kpmap :
1151ec97b1eSSascha Wildner.Bl -tag -width ".Fa ts_realtime"
1161ec97b1eSSascha Wildner.It Fa header[]
1171ec97b1eSSascha WildnerAn array of headers terminating with a header of type 0 indicating
1181ec97b1eSSascha Wildnerwhere various fields are in the mapping.
1191ec97b1eSSascha WildnerThis should be used by userland instead of directly mapping to the
1201ec97b1eSSascha Wildner.Vt struct sys_kpmap .
1211ec97b1eSSascha Wildner.It Fa version
1221ec97b1eSSascha WildnerThe
1231ec97b1eSSascha Wildner.Vt struct sys_kpmap
1241ec97b1eSSascha Wildnerversion, typically 1.
1251ec97b1eSSascha Wildner.It Fa upticks
1261ec97b1eSSascha WildnerSystem uptime tick counter (32 bit integer).
1271ec97b1eSSascha WildnerMonotonic and uncompensated.
1281ec97b1eSSascha Wildner.It Fa ts_uptime
1291ec97b1eSSascha WildnerSystem uptime in
1301ec97b1eSSascha Wildner.Vt struct timespec
1311ec97b1eSSascha Wildnerformat at tick-resolution.
1321ec97b1eSSascha WildnerMonotonic and uncompensated.
1331ec97b1eSSascha Wildner.It Fa ts_realtime
1341ec97b1eSSascha WildnerSystem realtime in
1351ec97b1eSSascha Wildner.Vt struct timespec
1361ec97b1eSSascha Wildnerformat at tick-resolution.
1371ec97b1eSSascha WildnerThis is compensated so reverse-indexing is possible.
1381ec97b1eSSascha Wildner.It Va tsc_freq
1391ec97b1eSSascha WildnerIf the system supports a TSC of some sort, the TSC frequency is
1401ec97b1eSSascha Wildnerrecorded here, else 0.
1411ec97b1eSSascha Wildner.It Va tick_freq
1421ec97b1eSSascha WildnerThe tick resolution of
1431ec97b1eSSascha Wildner.Fa ts_uptime
1441ec97b1eSSascha Wildnerand
1451ec97b1eSSascha Wildner.Fa ts_realtime
1461ec97b1eSSascha Wildnerand approximate tick resolution for the scheduler, typically 100.
147*b227f3f5SMatthew Dillon.It Va fast_gtod
148*b227f3f5SMatthew DillonThis integer reflects the state of the "kern.gettimeofday_quick"
149*b227f3f5SMatthew Dillonsysctl.  When set to 1, gettimeofday(&tv, NULL) calls will access
150*b227f3f5SMatthew Dillonthe tick-resolution ts_realtime[] fields instead of executing the
151*b227f3f5SMatthew Dillonsystem call.  Changes in the sysctl are immediately reflected in
152*b227f3f5SMatthew Dillonprograms that are already running.
1538ffa5452SSascha Wildner.El
1541ec97b1eSSascha Wildner.Sh NOTES
1551ec97b1eSSascha WildnerWith
1561ec97b1eSSascha Wildner.Pa /dev/upmap ,
1571ec97b1eSSascha Wildneruserland may write to the entire buffer, but it is recommended that userland
1581ec97b1eSSascha Wildneronly write to fields intended to be writable.
1591ec97b1eSSascha WildnerWhen a program forks, an area already
1601ec97b1eSSascha Wildner.Fn mmap Ns ed
1611ec97b1eSSascha Wildnerremains
1621ec97b1eSSascha Wildner.Fn mmap Ns ed
1631ec97b1eSSascha Wildnerbut will point to the area of the new process and not the old.
1641ec97b1eSSascha WildnerSo libraries do not need to do anything special at
1651ec97b1eSSascha Wildner.Fn fork .
1661ec97b1eSSascha WildnerAccess to the
1671ec97b1eSSascha Wildner.Vt sys_upmap
1681ec97b1eSSascha Wildnerstructure is CPU localized.
1691ec97b1eSSascha Wildner.Pp
1701ec97b1eSSascha WildnerWith
1711ec97b1eSSascha Wildner.Pa /dev/kpmap ,
1721ec97b1eSSascha Wildneruserland may only read from this buffer.
1731ec97b1eSSascha WildnerAccess to the
1741ec97b1eSSascha Wildner.Vt struct sys_kpmap
1751ec97b1eSSascha Wildneris NOT CPU localized.
1761ec97b1eSSascha WildnerA memory fence and double-check should be used when accessing
1771ec97b1eSSascha Wildnernon-atomic structures which might change such as
1781ec97b1eSSascha Wildner.Fa ts_uptime
1791ec97b1eSSascha Wildnerand
1801ec97b1eSSascha Wildner.Fa ts_realtime .
1811ec97b1eSSascha Wildner.Sh SEE ALSO
1821ec97b1eSSascha Wildner.Xr mmap 2
1831ec97b1eSSascha Wildner.Sh HISTORY
1841ec97b1eSSascha WildnerThe
1851ec97b1eSSascha Wildner.Nm upmap
1861ec97b1eSSascha Wildnerand
1871ec97b1eSSascha Wildner.Nm kpmap
1881ec97b1eSSascha Wildnerfiles appeared in
1891ec97b1eSSascha Wildner.Dx 3.9 .
190