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.
kernel - Add /dev/upmap and /dev/kpmap and sys/upmap.h (2)

* Disallow writing to kpmap.

* Handle cpu read/update races against ts_uptime and ts_realtime by
  making these arrays[2] and using kpmap->upticks to tell userland
  which one is stable.

  The procedure is as follows:

	struct timespec ts_uptime;
	struct timespec ts_realtime;
	int w;

        do {
                w = kpmap->upticks;
                cpu_lfence();
                ts_uptime = kpmap->ts_uptime[w & 1];
                ts_realtime = kpmap->ts_realtime[w & 1];
                cpu_lfence();
                w = kpmap->upticks - w;
        } while (w > 1);

  This procedure avoids having to loop in all standard cases including
  the nominal kernel update / userland read race.  It will only loop if
  the kernel deschedules the user process for > 1 tick during the access
  sequence.
kernel - fixup buildworld after recent commits