Author: kib
Date: Sat Sep 22 12:32:00 2012
New Revision: 240815
URL: http://svn.freebsd.org/changeset/base/240815

Log:
  MFC r237433:
  Implement mechanism to export some kernel timekeeping data to
  usermode, using shared page.
  
  MFC r237474:
  Stop updating the struct vdso_timehands from even handler executed in
  the scheduled task from tc_windup(). Do it directly from tc_windup in
  interrupt context.

Added:
  stable/9/sys/amd64/include/vdso.h
     - copied unchanged from r237433, head/sys/amd64/include/vdso.h
  stable/9/sys/arm/include/vdso.h
     - copied unchanged from r237433, head/sys/arm/include/vdso.h
  stable/9/sys/i386/include/vdso.h
     - copied unchanged from r237433, head/sys/i386/include/vdso.h
  stable/9/sys/ia64/include/vdso.h
     - copied unchanged from r237433, head/sys/ia64/include/vdso.h
  stable/9/sys/kern/subr_dummy_vdso_tc.c
     - copied unchanged from r237433, head/sys/kern/subr_dummy_vdso_tc.c
  stable/9/sys/mips/include/vdso.h
     - copied unchanged from r237433, head/sys/mips/include/vdso.h
  stable/9/sys/pc98/include/vdso.h
     - copied unchanged from r237433, head/sys/pc98/include/vdso.h
  stable/9/sys/powerpc/include/vdso.h
     - copied unchanged from r237433, head/sys/powerpc/include/vdso.h
  stable/9/sys/sparc64/include/vdso.h
     - copied unchanged from r237433, head/sys/sparc64/include/vdso.h
  stable/9/sys/sys/vdso.h
     - copied, changed from r237433, head/sys/sys/vdso.h
  stable/9/sys/x86/include/vdso.h
     - copied unchanged from r237433, head/sys/x86/include/vdso.h
Modified:
  stable/9/sys/conf/files.arm
  stable/9/sys/conf/files.ia64
  stable/9/sys/conf/files.mips
  stable/9/sys/conf/files.powerpc
  stable/9/sys/conf/files.sparc64
  stable/9/sys/kern/imgact_elf.c
  stable/9/sys/kern/kern_exec.c
  stable/9/sys/kern/kern_tc.c
  stable/9/sys/sys/sysent.h
  stable/9/sys/x86/x86/tsc.c
Directory Properties:
  stable/9/sys/   (props changed)
  stable/9/sys/conf/   (props changed)

Copied: stable/9/sys/amd64/include/vdso.h (from r237433, 
head/sys/amd64/include/vdso.h)
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/9/sys/amd64/include/vdso.h   Sat Sep 22 12:32:00 2012        
(r240815, copy of r237433, head/sys/amd64/include/vdso.h)
@@ -0,0 +1,6 @@
+/*-
+ * This file is in the public domain.
+ */
+/* $FreeBSD$ */
+
+#include <x86/vdso.h>

Copied: stable/9/sys/arm/include/vdso.h (from r237433, 
head/sys/arm/include/vdso.h)
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/9/sys/arm/include/vdso.h     Sat Sep 22 12:32:00 2012        
(r240815, copy of r237433, head/sys/arm/include/vdso.h)
@@ -0,0 +1,34 @@
+/*-
+ * Copyright 2012 Konstantin Belousov <[email protected]>.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _ARM_VDSO_H
+#define        _ARM_VDSO_H
+
+#define        VDSO_TIMEHANDS_MD                       \
+       uint32_t        th_res[8];
+
+#endif

Modified: stable/9/sys/conf/files.arm
==============================================================================
--- stable/9/sys/conf/files.arm Sat Sep 22 12:27:50 2012        (r240814)
+++ stable/9/sys/conf/files.arm Sat Sep 22 12:32:00 2012        (r240815)
@@ -76,3 +76,5 @@ libkern/umoddi3.c             standard
 #XXX: We can't use these versions, as strcmp.c is included conf/files
 #libkern/arm/strcmp.S          standard
 #libkern/arm/strncmp.S         standard
+#
+kern/subr_dummy_vdso_tc.c      standard

Modified: stable/9/sys/conf/files.ia64
==============================================================================
--- stable/9/sys/conf/files.ia64        Sat Sep 22 12:27:50 2012        
(r240814)
+++ stable/9/sys/conf/files.ia64        Sat Sep 22 12:32:00 2012        
(r240815)
@@ -137,3 +137,4 @@ libkern/ia64/bswap16.S              standard
 libkern/ia64/bswap32.S         standard
 libkern/memmove.c              standard
 libkern/memset.c               standard
+kern/subr_dummy_vdso_tc.c      standard

Modified: stable/9/sys/conf/files.mips
==============================================================================
--- stable/9/sys/conf/files.mips        Sat Sep 22 12:27:50 2012        
(r240814)
+++ stable/9/sys/conf/files.mips        Sat Sep 22 12:32:00 2012        
(r240815)
@@ -89,6 +89,8 @@ libkern/umoddi3.c             optional        isa_mips32
 #libkern/mips/strcmp.S         standard
 #libkern/mips/strncmp.S                standard
 
+kern/subr_dummy_vdso_tc.c              standard
+
 kern/kern_clocksource.c                standard
 kern/link_elf_obj.c            standard
 

Modified: stable/9/sys/conf/files.powerpc
==============================================================================
--- stable/9/sys/conf/files.powerpc     Sat Sep 22 12:27:50 2012        
(r240814)
+++ stable/9/sys/conf/files.powerpc     Sat Sep 22 12:32:00 2012        
(r240815)
@@ -58,6 +58,7 @@ dev/tsec/if_tsec.c            optional        tsec
 dev/tsec/if_tsec_fdt.c         optional        tsec fdt
 dev/uart/uart_cpu_powerpc.c    optional        uart aim
 kern/kern_clocksource.c                standard
+kern/subr_dummy_vdso_tc.c      standard
 kern/syscalls.c                        optional        ktr
 libkern/ashldi3.c              optional        powerpc
 libkern/ashrdi3.c              optional        powerpc

Modified: stable/9/sys/conf/files.sparc64
==============================================================================
--- stable/9/sys/conf/files.sparc64     Sat Sep 22 12:27:50 2012        
(r240814)
+++ stable/9/sys/conf/files.sparc64     Sat Sep 22 12:32:00 2012        
(r240815)
@@ -60,6 +60,7 @@ dev/syscons/scvtb.c           optional        sc
 dev/uart/uart_cpu_sparc64.c    optional        uart
 dev/uart/uart_kbd_sun.c                optional        uart sc
 kern/kern_clocksource.c                standard
+kern/subr_dummy_vdso_tc.c      standard
 kern/syscalls.c                        optional        ktr
 libkern/ffs.c                  standard
 libkern/ffsl.c                 standard

Copied: stable/9/sys/i386/include/vdso.h (from r237433, 
head/sys/i386/include/vdso.h)
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/9/sys/i386/include/vdso.h    Sat Sep 22 12:32:00 2012        
(r240815, copy of r237433, head/sys/i386/include/vdso.h)
@@ -0,0 +1,6 @@
+/*-
+ * This file is in the public domain.
+ */
+/* $FreeBSD$ */
+
+#include <x86/vdso.h>

Copied: stable/9/sys/ia64/include/vdso.h (from r237433, 
head/sys/ia64/include/vdso.h)
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/9/sys/ia64/include/vdso.h    Sat Sep 22 12:32:00 2012        
(r240815, copy of r237433, head/sys/ia64/include/vdso.h)
@@ -0,0 +1,41 @@
+/*-
+ * Copyright 2012 Konstantin Belousov <[email protected]>.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _IA64_VDSO_H
+#define        _IA64_VDSO_H
+
+#define        VDSO_TIMEHANDS_MD                       \
+       uint32_t        th_res[8];
+
+#ifdef _KERNEL
+#ifdef COMPAT_FREEBSD32
+
+#define        VDSO_TIMEHANDS_MD32     VDSO_TIMEHANDS_MD
+
+#endif
+#endif
+#endif

Modified: stable/9/sys/kern/imgact_elf.c
==============================================================================
--- stable/9/sys/kern/imgact_elf.c      Sat Sep 22 12:27:50 2012        
(r240814)
+++ stable/9/sys/kern/imgact_elf.c      Sat Sep 22 12:32:00 2012        
(r240815)
@@ -1015,6 +1015,10 @@ __elfN(freebsd_fixup)(register_t **stack
                AUXARGS_ENTRY(pos, AT_PAGESIZES, imgp->pagesizes);
                AUXARGS_ENTRY(pos, AT_PAGESIZESLEN, imgp->pagesizeslen);
        }
+       if (imgp->sysent->sv_timekeep_base != 0) {
+               AUXARGS_ENTRY(pos, AT_TIMEKEEP,
+                   imgp->sysent->sv_timekeep_base);
+       }
        AUXARGS_ENTRY(pos, AT_STACKPROT, imgp->sysent->sv_shared_page_obj
            != NULL && imgp->stack_prot != 0 ? imgp->stack_prot :
            imgp->sysent->sv_stackprot);

Modified: stable/9/sys/kern/kern_exec.c
==============================================================================
--- stable/9/sys/kern/kern_exec.c       Sat Sep 22 12:27:50 2012        
(r240814)
+++ stable/9/sys/kern/kern_exec.c       Sat Sep 22 12:32:00 2012        
(r240815)
@@ -28,6 +28,7 @@
 __FBSDID("$FreeBSD$");
 
 #include "opt_capsicum.h"
+#include "opt_compat.h"
 #include "opt_hwpmc_hooks.h"
 #include "opt_kdtrace.h"
 #include "opt_ktrace.h"
@@ -64,6 +65,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/sysent.h>
 #include <sys/shm.h>
 #include <sys/sysctl.h>
+#include <sys/vdso.h>
 #include <sys/vnode.h>
 #include <sys/stat.h>
 #ifdef KTRACE
@@ -1517,42 +1519,13 @@ exec_unregister(execsw_arg)
 static struct sx shared_page_alloc_sx;
 static vm_object_t shared_page_obj;
 static int shared_page_free;
-
-struct sf_buf *
-shared_page_write_start(int base)
-{
-       vm_page_t m;
-       struct sf_buf *s;
-
-       VM_OBJECT_LOCK(shared_page_obj);
-       m = vm_page_grab(shared_page_obj, OFF_TO_IDX(base), VM_ALLOC_RETRY);
-       VM_OBJECT_UNLOCK(shared_page_obj);
-       s = sf_buf_alloc(m, SFB_DEFAULT);
-       return (s);
-}
-
-void
-shared_page_write_end(struct sf_buf *sf)
-{
-       vm_page_t m;
-
-       m = sf_buf_page(sf);
-       sf_buf_free(sf);
-       VM_OBJECT_LOCK(shared_page_obj);
-       vm_page_wakeup(m);
-       VM_OBJECT_UNLOCK(shared_page_obj);
-}
+char *shared_page_mapping;
 
 void
 shared_page_write(int base, int size, const void *data)
 {
-       struct sf_buf *sf;
-       vm_offset_t sk;
 
-       sf = shared_page_write_start(base);
-       sk = sf_buf_kva(sf);
-       bcopy(data, (void *)(sk + (base & PAGE_MASK)), size);
-       shared_page_write_end(sf);
+       bcopy(data, shared_page_mapping + base, size);
 }
 
 static int
@@ -1596,6 +1569,7 @@ static void
 shared_page_init(void *dummy __unused)
 {
        vm_page_t m;
+       vm_offset_t addr;
 
        sx_init(&shared_page_alloc_sx, "shpsx");
        shared_page_obj = vm_pager_allocate(OBJT_PHYS, 0, PAGE_SIZE,
@@ -1605,15 +1579,95 @@ shared_page_init(void *dummy __unused)
            VM_ALLOC_ZERO);
        m->valid = VM_PAGE_BITS_ALL;
        VM_OBJECT_UNLOCK(shared_page_obj);
+       addr = kmem_alloc_nofault(kernel_map, PAGE_SIZE);
+       pmap_qenter(addr, &m, 1);
+       shared_page_mapping = (char *)addr;
 }
 
 SYSINIT(shp, SI_SUB_EXEC, SI_ORDER_FIRST, (sysinit_cfunc_t)shared_page_init,
     NULL);
 
+static void
+timehands_update(struct sysentvec *sv)
+{
+       struct vdso_timehands th;
+       struct vdso_timekeep *tk;
+       uint32_t enabled, idx;
+
+       enabled = tc_fill_vdso_timehands(&th);
+       tk = (struct vdso_timekeep *)(shared_page_mapping +
+           sv->sv_timekeep_off);
+       idx = sv->sv_timekeep_curr;
+       atomic_store_rel_32(&tk->tk_th[idx].th_gen, 0);
+       if (++idx >= VDSO_TH_NUM)
+               idx = 0;
+       sv->sv_timekeep_curr = idx;
+       if (++sv->sv_timekeep_gen == 0)
+               sv->sv_timekeep_gen = 1;
+       th.th_gen = 0;
+       if (enabled)
+               tk->tk_th[idx] = th;
+       tk->tk_enabled = enabled;
+       atomic_store_rel_32(&tk->tk_th[idx].th_gen, sv->sv_timekeep_gen);
+       tk->tk_current = idx;
+}
+
+#ifdef COMPAT_FREEBSD32
+static void
+timehands_update32(struct sysentvec *sv)
+{
+       struct vdso_timekeep32 *tk;
+       struct vdso_timehands32 th;
+       uint32_t enabled, idx;
+
+       enabled = tc_fill_vdso_timehands32(&th);
+       tk = (struct vdso_timekeep32 *)(shared_page_mapping +
+           sv->sv_timekeep_off);
+       idx = sv->sv_timekeep_curr;
+       atomic_store_rel_32(&tk->tk_th[idx].th_gen, 0);
+       if (++idx >= VDSO_TH_NUM)
+               idx = 0;
+       sv->sv_timekeep_curr = idx;
+       if (++sv->sv_timekeep_gen == 0)
+               sv->sv_timekeep_gen = 1;
+       th.th_gen = 0;
+       if (enabled)
+               tk->tk_th[idx] = th;
+       tk->tk_enabled = enabled;
+       atomic_store_rel_32(&tk->tk_th[idx].th_gen, sv->sv_timekeep_gen);
+       tk->tk_current = idx;
+}
+#endif
+
+/*
+ * This is hackish, but easiest way to avoid creating list structures
+ * that needs to be iterated over from the hardclock interrupt
+ * context.
+ */
+static struct sysentvec *host_sysentvec;
+#ifdef COMPAT_FREEBSD32
+static struct sysentvec *compat32_sysentvec;
+#endif
+
+void
+timekeep_push_vdso(void)
+{
+
+       if (host_sysentvec != NULL && host_sysentvec->sv_timekeep_base != 0)
+               timehands_update(host_sysentvec);
+#ifdef COMPAT_FREEBSD32
+       if (compat32_sysentvec != NULL &&
+           compat32_sysentvec->sv_timekeep_base != 0)
+               timehands_update32(compat32_sysentvec);
+#endif
+}
+
 void
 exec_sysvec_init(void *param)
 {
        struct sysentvec *sv;
+       int tk_base;
+       uint32_t tk_ver;
 
        sv = (struct sysentvec *)param;
 
@@ -1622,4 +1676,32 @@ exec_sysvec_init(void *param)
        sv->sv_shared_page_obj = shared_page_obj;
        sv->sv_sigcode_base = sv->sv_shared_page_base +
            shared_page_fill(*(sv->sv_szsigcode), 16, sv->sv_sigcode);
+       if ((sv->sv_flags & SV_ABI_MASK) != SV_ABI_FREEBSD)
+               return;
+       tk_ver = VDSO_TK_VER_CURR;
+#ifdef COMPAT_FREEBSD32
+       if ((sv->sv_flags & SV_ILP32) != 0) {
+               tk_base = shared_page_alloc(sizeof(struct vdso_timekeep32) +
+                   sizeof(struct vdso_timehands32) * VDSO_TH_NUM, 16);
+               KASSERT(tk_base != -1, ("tk_base -1 for 32bit"));
+               shared_page_write(tk_base + offsetof(struct vdso_timekeep32,
+                   tk_ver), sizeof(uint32_t), &tk_ver);
+               KASSERT(compat32_sysentvec == 0,
+                   ("Native compat32 already registered"));
+               compat32_sysentvec = sv;
+       } else {
+#endif
+               tk_base = shared_page_alloc(sizeof(struct vdso_timekeep) +
+                   sizeof(struct vdso_timehands) * VDSO_TH_NUM, 16);
+               KASSERT(tk_base != -1, ("tk_base -1 for native"));
+               shared_page_write(tk_base + offsetof(struct vdso_timekeep,
+                   tk_ver), sizeof(uint32_t), &tk_ver);
+               KASSERT(host_sysentvec == 0, ("Native already registered"));
+               host_sysentvec = sv;
+#ifdef COMPAT_FREEBSD32
+       }
+#endif
+       sv->sv_timekeep_base = sv->sv_shared_page_base + tk_base;
+       sv->sv_timekeep_off = tk_base;
+       timekeep_push_vdso();
 }

Modified: stable/9/sys/kern/kern_tc.c
==============================================================================
--- stable/9/sys/kern/kern_tc.c Sat Sep 22 12:27:50 2012        (r240814)
+++ stable/9/sys/kern/kern_tc.c Sat Sep 22 12:32:00 2012        (r240815)
@@ -10,6 +10,7 @@
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
+#include "opt_compat.h"
 #include "opt_ntp.h"
 
 #include <sys/param.h>
@@ -20,6 +21,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/timepps.h>
 #include <sys/timetc.h>
 #include <sys/timex.h>
+#include <sys/vdso.h>
 
 /*
  * A large step happens on boot.  This constant detects such steps.
@@ -544,6 +546,7 @@ tc_windup(void)
        time_second = th->th_microtime.tv_sec;
        time_uptime = th->th_offset.sec;
        timehands = th;
+       timekeep_push_vdso();
 }
 
 /* Report or change the active timecounter hardware. */
@@ -570,6 +573,7 @@ sysctl_kern_timecounter_hardware(SYSCTL_
                (void)newtc->tc_get_timecount(newtc);
 
                timecounter = newtc;
+               timekeep_push_vdso();
                return (0);
        }
        return (EINVAL);
@@ -960,3 +964,63 @@ cputick2usec(uint64_t tick)
 }
 
 cpu_tick_f     *cpu_ticks = tc_cpu_ticks;
+
+static int vdso_th_enable = 1;
+static int
+sysctl_fast_gettime(SYSCTL_HANDLER_ARGS)
+{
+       int old_vdso_th_enable, error;
+
+       old_vdso_th_enable = vdso_th_enable;
+       error = sysctl_handle_int(oidp, &old_vdso_th_enable, 0, req);
+       if (error != 0)
+               return (error);
+       vdso_th_enable = old_vdso_th_enable;
+       timekeep_push_vdso();
+       return (0);
+}
+SYSCTL_PROC(_kern_timecounter, OID_AUTO, fast_gettime,
+    CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE,
+    NULL, 0, sysctl_fast_gettime, "I", "Enable fast time of day");
+
+uint32_t
+tc_fill_vdso_timehands(struct vdso_timehands *vdso_th)
+{
+       struct timehands *th;
+       uint32_t enabled;
+
+       th = timehands;
+       vdso_th->th_algo = VDSO_TH_ALGO_1;
+       vdso_th->th_scale = th->th_scale;
+       vdso_th->th_offset_count = th->th_offset_count;
+       vdso_th->th_counter_mask = th->th_counter->tc_counter_mask;
+       vdso_th->th_offset = th->th_offset;
+       vdso_th->th_boottime = boottimebin;
+       enabled = cpu_fill_vdso_timehands(vdso_th);
+       if (!vdso_th_enable)
+               enabled = 0;
+       return (enabled);
+}
+
+#ifdef COMPAT_FREEBSD32
+uint32_t
+tc_fill_vdso_timehands32(struct vdso_timehands32 *vdso_th32)
+{
+       struct timehands *th;
+       uint32_t enabled;
+
+       th = timehands;
+       vdso_th32->th_algo = VDSO_TH_ALGO_1;
+       *(uint64_t *)&vdso_th32->th_scale[0] = th->th_scale;
+       vdso_th32->th_offset_count = th->th_offset_count;
+       vdso_th32->th_counter_mask = th->th_counter->tc_counter_mask;
+       vdso_th32->th_offset.sec = th->th_offset.sec;
+       *(uint64_t *)&vdso_th32->th_offset.frac[0] = th->th_offset.frac;
+       vdso_th32->th_boottime.sec = boottimebin.sec;
+       *(uint64_t *)&vdso_th32->th_boottime.frac[0] = boottimebin.frac;
+       enabled = cpu_fill_vdso_timehands32(vdso_th32);
+       if (!vdso_th_enable)
+               enabled = 0;
+       return (enabled);
+}
+#endif

Copied: stable/9/sys/kern/subr_dummy_vdso_tc.c (from r237433, 
head/sys/kern/subr_dummy_vdso_tc.c)
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/9/sys/kern/subr_dummy_vdso_tc.c      Sat Sep 22 12:32:00 2012        
(r240815, copy of r237433, head/sys/kern/subr_dummy_vdso_tc.c)
@@ -0,0 +1,49 @@
+/*-
+ * Copyright 2012 Konstantin Belousov <[email protected]>.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include "opt_compat.h"
+
+#include <sys/param.h>
+#include <sys/vdso.h>
+
+uint32_t
+cpu_fill_vdso_timehands(struct vdso_timehands *vdso_th)
+{
+
+       return (0);
+}
+
+#ifdef COMPAT_FREEBSD32
+uint32_t
+cpu_fill_vdso_timehands32(struct vdso_timehands32 *vdso_th32)
+{
+
+       return (0);
+}
+#endif

Copied: stable/9/sys/mips/include/vdso.h (from r237433, 
head/sys/mips/include/vdso.h)
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/9/sys/mips/include/vdso.h    Sat Sep 22 12:32:00 2012        
(r240815, copy of r237433, head/sys/mips/include/vdso.h)
@@ -0,0 +1,41 @@
+/*-
+ * Copyright 2012 Konstantin Belousov <[email protected]>.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _MIPS_VDSO_H
+#define        _MIPS_VDSO_H
+
+#define        VDSO_TIMEHANDS_MD                       \
+       uint32_t        th_res[8];
+
+#ifdef _KERNEL
+#ifdef COMPAT_FREEBSD32
+
+#define        VDSO_TIMEHANDS_MD32     VDSO_TIMEHANDS_MD
+
+#endif
+#endif
+#endif

Copied: stable/9/sys/pc98/include/vdso.h (from r237433, 
head/sys/pc98/include/vdso.h)
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/9/sys/pc98/include/vdso.h    Sat Sep 22 12:32:00 2012        
(r240815, copy of r237433, head/sys/pc98/include/vdso.h)
@@ -0,0 +1,6 @@
+/*-
+ * This file is in the public domain.
+ */
+/* $FreeBSD$ */
+
+#include <x86/vdso.h>

Copied: stable/9/sys/powerpc/include/vdso.h (from r237433, 
head/sys/powerpc/include/vdso.h)
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/9/sys/powerpc/include/vdso.h Sat Sep 22 12:32:00 2012        
(r240815, copy of r237433, head/sys/powerpc/include/vdso.h)
@@ -0,0 +1,41 @@
+/*-
+ * Copyright 2012 Konstantin Belousov <[email protected]>.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _POWERPC_VDSO_H
+#define        _POWERPC_VDSO_H
+
+#define        VDSO_TIMEHANDS_MD                       \
+       uint32_t        th_res[8];
+
+#ifdef _KERNEL
+#ifdef COMPAT_FREEBSD32
+
+#define        VDSO_TIMEHANDS_MD32     VDSO_TIMEHANDS_MD
+
+#endif
+#endif
+#endif

Copied: stable/9/sys/sparc64/include/vdso.h (from r237433, 
head/sys/sparc64/include/vdso.h)
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/9/sys/sparc64/include/vdso.h Sat Sep 22 12:32:00 2012        
(r240815, copy of r237433, head/sys/sparc64/include/vdso.h)
@@ -0,0 +1,34 @@
+/*-
+ * Copyright 2012 Konstantin Belousov <[email protected]>.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _SPARC64_VDSO_H
+#define        _SPARC64_VDSO_H
+
+#define        VDSO_TIMEHANDS_MD                       \
+       uint32_t        th_res[8];
+
+#endif

Modified: stable/9/sys/sys/sysent.h
==============================================================================
--- stable/9/sys/sys/sysent.h   Sat Sep 22 12:27:50 2012        (r240814)
+++ stable/9/sys/sys/sysent.h   Sat Sep 22 12:32:00 2012        (r240815)
@@ -124,6 +124,10 @@ struct sysentvec {
        vm_offset_t     sv_shared_page_base;
        vm_offset_t     sv_shared_page_len;
        vm_offset_t     sv_sigcode_base;
+       vm_offset_t     sv_timekeep_base;
+       int             sv_timekeep_off;
+       int             sv_timekeep_curr;
+       uint32_t        sv_timekeep_gen;
        void            *sv_shared_page_obj;
        void            (*sv_schedtail)(struct thread *);
 };
@@ -261,8 +265,6 @@ int shared_page_alloc(int size, int alig
 int shared_page_fill(int size, int align, const void *data);
 void shared_page_write(int base, int size, const void *data);
 void exec_sysvec_init(void *param);
-struct sf_buf *shared_page_write_start(int base);
-void shared_page_write_end(struct sf_buf *sf);
 
 #define INIT_SYSENTVEC(name, sv)                                       \
     SYSINIT(name, SI_SUB_EXEC, SI_ORDER_ANY,                           \

Copied and modified: stable/9/sys/sys/vdso.h (from r237433, head/sys/sys/vdso.h)
==============================================================================
--- head/sys/sys/vdso.h Fri Jun 22 07:06:40 2012        (r237433, copy source)
+++ stable/9/sys/sys/vdso.h     Sat Sep 22 12:32:00 2012        (r240815)
@@ -29,7 +29,6 @@
 #define        _SYS_VDSO_H
 
 #include <sys/types.h>
-#include <sys/eventhandler.h>
 #include <machine/vdso.h>
 
 struct vdso_timehands {
@@ -74,6 +73,8 @@ u_int __vdso_gettc(const struct vdso_tim
 
 #ifdef _KERNEL
 
+void timekeep_push_vdso(void);
+
 uint32_t tc_fill_vdso_timehands(struct vdso_timehands *vdso_th);
 
 /*
@@ -86,9 +87,6 @@ uint32_t tc_fill_vdso_timehands(struct v
  */
 uint32_t cpu_fill_vdso_timehands(struct vdso_timehands *vdso_th);
 
-typedef void (*tc_windup_fn)(void *);
-EVENTHANDLER_DECLARE(tc_windup, tc_windup_fn);
-
 #define        VDSO_TH_NUM     4
 
 #ifdef COMPAT_FREEBSD32

Copied: stable/9/sys/x86/include/vdso.h (from r237433, 
head/sys/x86/include/vdso.h)
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/9/sys/x86/include/vdso.h     Sat Sep 22 12:32:00 2012        
(r240815, copy of r237433, head/sys/x86/include/vdso.h)
@@ -0,0 +1,42 @@
+/*-
+ * Copyright 2012 Konstantin Belousov <[email protected]>.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _X86_VDSO_H
+#define        _X86_VDSO_H
+
+#define        VDSO_TIMEHANDS_MD                       \
+       uint32_t        th_x86_shift;           \
+       uint32_t        th_res[7];
+
+#ifdef _KERNEL
+#ifdef COMPAT_FREEBSD32
+
+#define        VDSO_TIMEHANDS_MD32     VDSO_TIMEHANDS_MD
+
+#endif
+#endif
+#endif

Modified: stable/9/sys/x86/x86/tsc.c
==============================================================================
--- stable/9/sys/x86/x86/tsc.c  Sat Sep 22 12:27:50 2012        (r240814)
+++ stable/9/sys/x86/x86/tsc.c  Sat Sep 22 12:32:00 2012        (r240815)
@@ -27,6 +27,7 @@
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
+#include "opt_compat.h"
 #include "opt_clock.h"
 
 #include <sys/param.h>
@@ -41,6 +42,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/kernel.h>
 #include <sys/power.h>
 #include <sys/smp.h>
+#include <sys/vdso.h>
 #include <machine/clock.h>
 #include <machine/cputypes.h>
 #include <machine/md_var.h>
@@ -606,3 +608,23 @@ tsc_get_timecount_low(struct timecounter
        : "=a" (rv) : "c" ((int)(intptr_t)tc->tc_priv) : "edx");
        return (rv);
 }
+
+uint32_t
+cpu_fill_vdso_timehands(struct vdso_timehands *vdso_th)
+{
+
+       vdso_th->th_x86_shift = (int)(intptr_t)timecounter->tc_priv;
+       bzero(vdso_th->th_res, sizeof(vdso_th->th_res));
+       return (timecounter == &tsc_timecounter);
+}
+
+#ifdef COMPAT_FREEBSD32
+uint32_t
+cpu_fill_vdso_timehands32(struct vdso_timehands32 *vdso_th32)
+{
+
+       vdso_th32->th_x86_shift = (int)(intptr_t)timecounter->tc_priv;
+       bzero(vdso_th32->th_res, sizeof(vdso_th32->th_res));
+       return (timecounter == &tsc_timecounter);
+}
+#endif
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to