git: kernel - Add /dev/upmap and /dev/kpmap and sys/upmap.h

Matthew Dillon dillon at crater.dragonflybsd.org
Thu Oct 16 12:51:21 PDT 2014


commit 0adbcbd6bc12ddb6dccdf11bc0d5004c1831a619
Author: Matthew Dillon <dillon at apollo.backplane.com>
Date:   Thu Oct 16 12:35:05 2014 -0700

    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.

Summary of changes:
 sys/dev/drm/i915/i915_gem.c             |  15 +-
 sys/emulation/linux/i386/imgact_linux.c |   6 +-
 sys/emulation/linux/linux_misc.c        |  14 +-
 sys/kern/imgact_aout.c                  |   8 +-
 sys/kern/imgact_elf.c                   |   8 +-
 sys/kern/imgact_gzip.c                  |   7 +-
 sys/kern/init_main.c                    |  31 ++-
 sys/kern/kern_clock.c                   |  16 ++
 sys/kern/kern_exit.c                    |   3 +
 sys/kern/kern_fork.c                    |   2 +
 sys/kern/kern_memio.c                   | 132 ++++++++++--
 sys/kern/kern_proc.c                    |  75 ++++++-
 sys/kern/kern_slaballoc.c               |  11 +-
 sys/kern/link_elf_obj.c                 |   5 +-
 sys/kern/sys_pipe.c                     |   9 +-
 sys/kern/sys_process.c                  |  18 +-
 sys/kern/sysv_shm.c                     |   9 +-
 sys/kern/vfs_bio.c                      |   4 +-
 sys/sys/device.h                        |   4 +-
 sys/sys/globaldata.h                    |   5 +-
 sys/sys/proc.h                          |  10 +-
 sys/sys/upmap.h                         | 133 ++++++++++++
 sys/vfs/procfs/procfs_status.c          |  25 ++-
 sys/vm/vm.h                             |   7 +
 sys/vm/vm_fault.c                       |  95 +++++++--
 sys/vm/vm_kern.c                        |  67 +++---
 sys/vm/vm_map.c                         | 357 +++++++++++++++++++++-----------
 sys/vm/vm_map.h                         |  24 ++-
 sys/vm/vm_mmap.c                        |  50 ++++-
 sys/vm/vm_unix.c                        |   8 +-
 30 files changed, 876 insertions(+), 282 deletions(-)
 create mode 100644 sys/sys/upmap.h

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/0adbcbd6bc12ddb6dccdf11bc0d5004c1831a619


-- 
DragonFly BSD source repository



More information about the Commits mailing list