kernel - Add /dev/upmap and /dev/kpmap and sys/upmap.h
authorMatthew Dillon <dillon@apollo.backplane.com>
Thu, 16 Oct 2014 19:35:05 +0000 (12:35 -0700)
committerMatthew Dillon <dillon@apollo.backplane.com>
Thu, 16 Oct 2014 19:51:14 +0000 (12:51 -0700)
commit0adbcbd6bc12ddb6dccdf11bc0d5004c1831a619
tree0f14418fe3ad93ba23b0c920d556f5369b169529
parent6254283abf4cfaf10268fa2c04bacd44e8fb0ab2
kernel - Add /dev/upmap and /dev/kpmap and sys/upmap.h

* Add two memory-mappable devices for accessing a per-process and global
  kernel shared memory space.  These can be mapped to acquire certain
  information from the kernel that would normally require a system call
  in a more efficient manner.

  Userland programs using this feature should NOT directly map the sys_upmap
  and sys_kpmap structures (which is why they are in #ifdef _KERNEL sections
  in sys/upmap.h).  Instead, mmap the devices using UPMAP_MAPSIZE and
  KPMAP_MAPSIZE and parse the ukpheader[] array at the front of each area
  to locate the desired fields.  You can then simply cache a pointer to
  the desired field.

  The width of the field is encoded in the UPTYPE/KPTYPE elements and
  can be asserted if desired, user programs are not expected to handle
  integers of multiple sizes for the same field type.

* Add /dev/upmap.  A program can open and mmap() this device R+W and use
  it to access:

  header[...] - See sys/upmap.h.  An array of headers terminating with
  a type=0 header indicating where various fields are in
  the mapping.  This should be used by userland instead
  of directly mapping to the struct sys_upmap structure.

  version - The sys_upmap version, typically 1.

  runticks - Scheduler run ticks (aggregate, all threads).  This
  may be used by userland interpreters to determine
  when to soft-switch.

  forkid - A unique non-zero 64-bit fork identifier.  This is NOT a
  pid.  This may be used by userland libraries to determine
  if a fork has occurred by comparing against a stored
  value.

  pid - The current process pid.  This may be used to acquire the
  process pid without having to make further system calls.

  proc_title - This starts out as an empty buffer and may be used to set
  the process title.  To revert to the original process title,
  set proc_title[0] to 0.

  NOTE!  Userland may write to the entire buffer, but it is recommended
 that userland only write to fields intended to be writable.

  NOTE!  When a program forks, an area already mmap()d remains mmap()d but
 will point to the new process's area and not the old, so libraries
 do not need to do anything special atfork.

  NOTE!  Access to this structure is cpu localized.

* Add /dev/kpmap.  A program can open and mmap() this device RO and use
  it to access:

  header[...] - See sys/upmap.h.  An array of headers terminating with
  a type=0 header indicating where various fields are in
  the mapping.  This should be used by userland instead
  of directly mapping to the struct sys_upmap structure.

  version - The sys_kpmap version, typically 1.

  upticks - System uptime tick counter (32 bit integer).  Monotonic,
  uncompensated.

  ts_uptime - System uptime in struct timespec format at tick-resolution.
  Monotonic, uncompensated.

  ts_realtime - System realtime in struct timespec format at tick-resolution.
  This is compensated so reverse-indexing is possible.

  tsc_freq - If the system supports a TSC of some sort, the TSC
  frequency is recorded here, else 0.

  tick_freq - The tick resolution of ts_uptime and ts_realtime and
  approximate tick resolution for the scheduler.  Typically
  100.

  NOTE!  Userland may only read from this buffer.

  NOTE!  Access to this structure is NOT cpu localized.  A memory fence
 and double-check should be used when accessing non-atomic structures
 which might change such as ts_uptime and ts_realtime.

 XXX needs work.
30 files changed:
sys/dev/drm/i915/i915_gem.c
sys/emulation/linux/i386/imgact_linux.c
sys/emulation/linux/linux_misc.c
sys/kern/imgact_aout.c
sys/kern/imgact_elf.c
sys/kern/imgact_gzip.c
sys/kern/init_main.c
sys/kern/kern_clock.c
sys/kern/kern_exit.c
sys/kern/kern_fork.c
sys/kern/kern_memio.c
sys/kern/kern_proc.c
sys/kern/kern_slaballoc.c
sys/kern/link_elf_obj.c
sys/kern/sys_pipe.c
sys/kern/sys_process.c
sys/kern/sysv_shm.c
sys/kern/vfs_bio.c
sys/sys/device.h
sys/sys/globaldata.h
sys/sys/proc.h
sys/sys/upmap.h [new file with mode: 0644]
sys/vfs/procfs/procfs_status.c
sys/vm/vm.h
sys/vm/vm_fault.c
sys/vm/vm_kern.c
sys/vm/vm_map.c
sys/vm/vm_map.h
sys/vm/vm_mmap.c
sys/vm/vm_unix.c