Print this page
OS-2366 ddi_periodic_add(9F) is entirely rubbish


   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T     */
  22 /*        All Rights Reserved   */
  23 
  24 /*
  25  * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
  26  * Copyright (c) 2011, Joyent, Inc. All rights reserved.
  27  */
  28 
  29 #include <sys/param.h>
  30 #include <sys/t_lock.h>
  31 #include <sys/types.h>
  32 #include <sys/tuneable.h>
  33 #include <sys/sysmacros.h>
  34 #include <sys/systm.h>
  35 #include <sys/cpuvar.h>
  36 #include <sys/lgrp.h>
  37 #include <sys/user.h>
  38 #include <sys/proc.h>
  39 #include <sys/callo.h>
  40 #include <sys/kmem.h>
  41 #include <sys/var.h>
  42 #include <sys/cmn_err.h>
  43 #include <sys/swap.h>
  44 #include <sys/vmsystm.h>
  45 #include <sys/class.h>
  46 #include <sys/time.h>


 930          */
 931         if (wake_sched) {
 932                 t = &t0;
 933                 thread_lock(t);
 934                 if (t->t_state == TS_STOPPED) {
 935                         runin = runout = 0;
 936                         wake_sched = 0;
 937                         t->t_whystop = 0;
 938                         t->t_whatstop = 0;
 939                         t->t_schedflag &= ~TS_ALLSTART;
 940                         THREAD_TRANSITION(t);
 941                         setfrontdq(t);
 942                 }
 943                 thread_unlock(t);
 944         }
 945 }
 946 
 947 void
 948 clock_init(void)
 949 {
 950         cyc_handler_t clk_hdlr, timer_hdlr, lbolt_hdlr;
 951         cyc_time_t clk_when, lbolt_when;
 952         int i, sz;
 953         intptr_t buf;
 954 
 955         /*
 956          * Setup handler and timer for the clock cyclic.
 957          */
 958         clk_hdlr.cyh_func = (cyc_func_t)clock;
 959         clk_hdlr.cyh_level = CY_LOCK_LEVEL;
 960         clk_hdlr.cyh_arg = NULL;
 961 
 962         clk_when.cyt_when = 0;
 963         clk_when.cyt_interval = nsec_per_tick;
 964 
 965         /*
 966          * cyclic_timer is dedicated to the ddi interface, which
 967          * uses the same clock resolution as the system one.
 968          */
 969         timer_hdlr.cyh_func = (cyc_func_t)cyclic_timer;
 970         timer_hdlr.cyh_level = CY_LOCK_LEVEL;
 971         timer_hdlr.cyh_arg = NULL;
 972 
 973         /*
 974          * The lbolt cyclic will be reprogramed to fire at a nsec_per_tick
 975          * interval to satisfy performance needs of the DDI lbolt consumers.
 976          * It is off by default.
 977          */
 978         lbolt_hdlr.cyh_func = (cyc_func_t)lbolt_cyclic;
 979         lbolt_hdlr.cyh_level = CY_LOCK_LEVEL;
 980         lbolt_hdlr.cyh_arg = NULL;
 981 
 982         lbolt_when.cyt_interval = nsec_per_tick;
 983 
 984         /*
 985          * Allocate cache line aligned space for the per CPU lbolt data and
 986          * lbolt info structures, and initialize them with their default
 987          * values. Note that these structures are also cache line sized.
 988          */
 989         sz = sizeof (lbolt_info_t) + CPU_CACHE_COHERENCE_SIZE;
 990         buf = (intptr_t)kmem_zalloc(sz, KM_SLEEP);
 991         lb_info = (lbolt_info_t *)P2ROUNDUP(buf, CPU_CACHE_COHERENCE_SIZE);
 992 
 993         if (hz != HZ_DEFAULT)


1028          * lbolt_hybrid points at lbolt_bootstrap until now. The LBOLT_* macros
1029          * and lbolt_debug_{enter,return} use this value as an indication that
1030          * the initializaion above hasn't been completed. Setting lbolt_hybrid
1031          * to either lbolt_{cyclic,event}_driven here signals those code paths
1032          * that the lbolt related structures can be used.
1033          */
1034         if (lbolt_cyc_only) {
1035                 lbolt_when.cyt_when = 0;
1036                 lbolt_hybrid = lbolt_cyclic_driven;
1037         } else {
1038                 lbolt_when.cyt_when = CY_INFINITY;
1039                 lbolt_hybrid = lbolt_event_driven;
1040         }
1041 
1042         /*
1043          * Grab cpu_lock and install all three cyclics.
1044          */
1045         mutex_enter(&cpu_lock);
1046 
1047         clock_cyclic = cyclic_add(&clk_hdlr, &clk_when);
1048         ddi_timer_cyclic = cyclic_add(&timer_hdlr, &clk_when);
1049         lb_info->id.lbi_cyclic_id = cyclic_add(&lbolt_hdlr, &lbolt_when);
1050 
1051         mutex_exit(&cpu_lock);
1052 }
1053 
1054 /*
1055  * Called before calcloadavg to get 10-sec moving loadavg together
1056  */
1057 
1058 static int
1059 genloadavg(struct loadavg_s *avgs)
1060 {
1061         int avg;
1062         int spos; /* starting position */
1063         int cpos; /* moving current position */
1064         int i;
1065         int slen;
1066         hrtime_t hr_avg;
1067 
1068         /* 10-second snapshot, calculate first positon */




   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T     */
  22 /*        All Rights Reserved   */
  23 
  24 /*
  25  * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
  26  * Copyright (c) 2013, Joyent, Inc.  All rights reserved.
  27  */
  28 
  29 #include <sys/param.h>
  30 #include <sys/t_lock.h>
  31 #include <sys/types.h>
  32 #include <sys/tuneable.h>
  33 #include <sys/sysmacros.h>
  34 #include <sys/systm.h>
  35 #include <sys/cpuvar.h>
  36 #include <sys/lgrp.h>
  37 #include <sys/user.h>
  38 #include <sys/proc.h>
  39 #include <sys/callo.h>
  40 #include <sys/kmem.h>
  41 #include <sys/var.h>
  42 #include <sys/cmn_err.h>
  43 #include <sys/swap.h>
  44 #include <sys/vmsystm.h>
  45 #include <sys/class.h>
  46 #include <sys/time.h>


 930          */
 931         if (wake_sched) {
 932                 t = &t0;
 933                 thread_lock(t);
 934                 if (t->t_state == TS_STOPPED) {
 935                         runin = runout = 0;
 936                         wake_sched = 0;
 937                         t->t_whystop = 0;
 938                         t->t_whatstop = 0;
 939                         t->t_schedflag &= ~TS_ALLSTART;
 940                         THREAD_TRANSITION(t);
 941                         setfrontdq(t);
 942                 }
 943                 thread_unlock(t);
 944         }
 945 }
 946 
 947 void
 948 clock_init(void)
 949 {
 950         cyc_handler_t clk_hdlr, lbolt_hdlr;
 951         cyc_time_t clk_when, lbolt_when;
 952         int i, sz;
 953         intptr_t buf;
 954 
 955         /*
 956          * Setup handler and timer for the clock cyclic.
 957          */
 958         clk_hdlr.cyh_func = (cyc_func_t)clock;
 959         clk_hdlr.cyh_level = CY_LOCK_LEVEL;
 960         clk_hdlr.cyh_arg = NULL;
 961 
 962         clk_when.cyt_when = 0;
 963         clk_when.cyt_interval = nsec_per_tick;
 964 
 965         /*








 966          * The lbolt cyclic will be reprogramed to fire at a nsec_per_tick
 967          * interval to satisfy performance needs of the DDI lbolt consumers.
 968          * It is off by default.
 969          */
 970         lbolt_hdlr.cyh_func = (cyc_func_t)lbolt_cyclic;
 971         lbolt_hdlr.cyh_level = CY_LOCK_LEVEL;
 972         lbolt_hdlr.cyh_arg = NULL;
 973 
 974         lbolt_when.cyt_interval = nsec_per_tick;
 975 
 976         /*
 977          * Allocate cache line aligned space for the per CPU lbolt data and
 978          * lbolt info structures, and initialize them with their default
 979          * values. Note that these structures are also cache line sized.
 980          */
 981         sz = sizeof (lbolt_info_t) + CPU_CACHE_COHERENCE_SIZE;
 982         buf = (intptr_t)kmem_zalloc(sz, KM_SLEEP);
 983         lb_info = (lbolt_info_t *)P2ROUNDUP(buf, CPU_CACHE_COHERENCE_SIZE);
 984 
 985         if (hz != HZ_DEFAULT)


1020          * lbolt_hybrid points at lbolt_bootstrap until now. The LBOLT_* macros
1021          * and lbolt_debug_{enter,return} use this value as an indication that
1022          * the initializaion above hasn't been completed. Setting lbolt_hybrid
1023          * to either lbolt_{cyclic,event}_driven here signals those code paths
1024          * that the lbolt related structures can be used.
1025          */
1026         if (lbolt_cyc_only) {
1027                 lbolt_when.cyt_when = 0;
1028                 lbolt_hybrid = lbolt_cyclic_driven;
1029         } else {
1030                 lbolt_when.cyt_when = CY_INFINITY;
1031                 lbolt_hybrid = lbolt_event_driven;
1032         }
1033 
1034         /*
1035          * Grab cpu_lock and install all three cyclics.
1036          */
1037         mutex_enter(&cpu_lock);
1038 
1039         clock_cyclic = cyclic_add(&clk_hdlr, &clk_when);

1040         lb_info->id.lbi_cyclic_id = cyclic_add(&lbolt_hdlr, &lbolt_when);
1041 
1042         mutex_exit(&cpu_lock);
1043 }
1044 
1045 /*
1046  * Called before calcloadavg to get 10-sec moving loadavg together
1047  */
1048 
1049 static int
1050 genloadavg(struct loadavg_s *avgs)
1051 {
1052         int avg;
1053         int spos; /* starting position */
1054         int cpos; /* moving current position */
1055         int i;
1056         int slen;
1057         hrtime_t hr_avg;
1058 
1059         /* 10-second snapshot, calculate first positon */