The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/osfmk/i386/hardclock.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*
    2  * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
    3  *
    4  * @APPLE_LICENSE_HEADER_START@
    5  * 
    6  * Copyright (c) 1999-2003 Apple Computer, Inc.  All Rights Reserved.
    7  * 
    8  * This file contains Original Code and/or Modifications of Original Code
    9  * as defined in and that are subject to the Apple Public Source License
   10  * Version 2.0 (the 'License'). You may not use this file except in
   11  * compliance with the License. Please obtain a copy of the License at
   12  * http://www.opensource.apple.com/apsl/ and read it before using this
   13  * file.
   14  * 
   15  * The Original Code and all software distributed under the License are
   16  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
   17  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
   18  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
   19  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
   20  * Please see the License for the specific language governing rights and
   21  * limitations under the License.
   22  * 
   23  * @APPLE_LICENSE_HEADER_END@
   24  */
   25 /*
   26  * @OSF_COPYRIGHT@
   27  */
   28 /* 
   29  * Mach Operating System
   30  * Copyright (c) 1991,1990 Carnegie Mellon University
   31  * All Rights Reserved.
   32  * 
   33  * Permission to use, copy, modify and distribute this software and its
   34  * documentation is hereby granted, provided that both the copyright
   35  * notice and this permission notice appear in all copies of the
   36  * software, derivative works or modified versions, and any portions
   37  * thereof, and that both notices appear in supporting documentation.
   38  * 
   39  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
   40  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
   41  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
   42  * 
   43  * Carnegie Mellon requests users of this software to return to
   44  * 
   45  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
   46  *  School of Computer Science
   47  *  Carnegie Mellon University
   48  *  Pittsburgh PA 15213-3890
   49  * 
   50  * any improvements or extensions that they make and grant Carnegie Mellon
   51  * the rights to redistribute these changes.
   52  */
   53 /*
   54  */
   55 
   56 /*
   57  * Clock interrupt.
   58  */
   59 #include <cpus.h>
   60 #include <time_stamp.h>
   61 #include <mach_kdb.h>
   62 #include <kern/cpu_number.h>
   63 #include <kern/cpu_data.h>
   64 #include <kern/kern_types.h>
   65 #include <platforms.h>
   66 #include <mach_kprof.h>
   67 #include <mach_mp_debug.h>
   68 #include <mach/std_types.h>
   69 
   70 #include <mach/clock_types.h>
   71 #include <mach/boolean.h>
   72 #include <i386/thread.h>
   73 #include <i386/eflags.h>
   74 #include <kern/assert.h>
   75 #include <kern/misc_protos.h>
   76 #include <i386/misc_protos.h>
   77 #include <kern/time_out.h>
   78 #include <kern/processor.h>
   79 
   80 #include <i386/ipl.h>
   81 
   82 #include <i386/hardclock_entries.h>
   83 #include <i386/rtclock_entries.h>
   84 
   85 #if     MACH_MP_DEBUG
   86 #include <i386/mach_param.h>    /* for HZ */
   87 #endif  /* MACH_MP_DEBUG */
   88 
   89 extern  char    return_to_iret[];
   90 
   91 #if     TIME_STAMP && NCPUS > 1
   92 extern  unsigned time_stamp;
   93 unsigned old_time_stamp, time_stamp_cum, nstamps;
   94 
   95 /*
   96  *      If H/W provides a counter, record number of ticks and cumulated
   97  *      time stamps to know timestamps rate.
   98  *      This should go away when ALARMCLOCKS installed
   99  */
  100 #define time_stamp_stat()                                       \
  101         if (my_cpu == 0)                                        \
  102         if (!old_time_stamp) {                                  \
  103                 old_time_stamp = time_stamp;                    \
  104                 nstamps = 0;                                    \
  105         } else {                                                \
  106                 nstamps++;                                      \
  107                 time_stamp_cum = (time_stamp - old_time_stamp); \
  108         }
  109 #else   /* TIME_STAMP && AT386 && NCPUS > 1 */
  110 #define time_stamp_stat()
  111 #endif  /* TIME_STAMP && AT386 && NCPUS > 1 */
  112 
  113 #if     MACH_KPROF
  114 int     masked_pc[NCPUS];
  115 int     missed_clock[NCPUS];
  116 int     detect_lost_tick = 0;
  117 #endif  /* MACH_KPROF */
  118 
  119 #if     MACH_MP_DEBUG
  120 int     masked_state_cnt[NCPUS];
  121 int     masked_state_max = 10*HZ;
  122 #endif  /* MACH_MP_DEBUG */
  123 
  124 /*
  125  * In the interest of a fast clock interrupt service path,
  126  * this routine should be folded into assembly language with
  127  * a direct interrupt vector on the i386. The "pit" interrupt
  128  * should always call the rtclock_intr() routine on the master
  129  * processor. The return value of the rtclock_intr() routine
  130  * indicates whether HZ rate clock processing should be
  131  * performed. (On the Sequent, all slave processors will
  132  * run at HZ rate). For now, we'll leave this routine in C
  133  * (with TIME_STAMP, MACH_MP_DEBUG and MACH_KPROF code this
  134  * routine is way too large for assembler anyway).
  135  */
  136 
  137 #ifdef  PARANOID_KDB
  138 int paranoid_debugger = TRUE;
  139 int paranoid_count = 1000;
  140 int paranoid_current = 0;
  141 int paranoid_cpu = 0;
  142 #endif  /* PARANOID_KDB */
  143 
  144 void
  145 hardclock(struct i386_interrupt_state   *regs) /* saved registers */
  146 {
  147         int mycpu;
  148         register unsigned pc;
  149         register boolean_t usermode;
  150 
  151         mp_disable_preemption();
  152         mycpu = cpu_number();
  153 
  154 #ifdef  PARANOID_KDB
  155         if (paranoid_cpu == mycpu &&
  156             paranoid_current++ >= paranoid_count) {
  157                 paranoid_current = 0;
  158                 if (paranoid_debugger)
  159                     Debugger("hardclock");
  160         }
  161 #endif  /* PARANOID_KDB */
  162 
  163 #if     MACH_KPROF
  164         /*
  165          * If we were masked against the clock skip call
  166          * to rtclock_intr(). When MACH_KPROF is set, the
  167          * clock frequency of the master-cpu is confined
  168          * to the HZ rate.
  169          */
  170         if (SPL_CMP_GE((old_ipl & 0xFF), SPL7)) {
  171                 usermode = (regs->efl & EFL_VM) || ((regs->cs & 0x03) != 0);
  172                 pc = (unsigned)regs->eip;
  173                 assert(!usermode);
  174                 if (missed_clock[mycpu]++ && detect_lost_tick > 1)
  175                         Debugger("Mach_KPROF");
  176                 masked_pc[mycpu] = pc;
  177         } else
  178 #endif  /* MACH_KPROF */
  179         /*
  180          * The master processor executes the rtclock_intr() routine
  181          * on every clock tick. The rtclock_intr() routine returns
  182          * a zero value on a HZ tick boundary.
  183          */
  184         if (mycpu == master_cpu) {
  185                 if (rtclock_intr(regs) != 0) {
  186                         mp_enable_preemption();
  187                         return;
  188                 }
  189         } else {
  190                 usermode = (regs->efl & EFL_VM) || ((regs->cs & 0x03) != 0);
  191                 pc = (unsigned)regs->eip;
  192                 hertz_tick(usermode, pc);
  193         }
  194 
  195         /*
  196          * The following code is executed at HZ rate by all processors
  197          * in the system. This implies that the clock rate on slave
  198          * processors must be HZ rate.
  199          */
  200 
  201         time_stamp_stat();
  202 
  203 #if     NCPUS >1 
  204         /*
  205          * Instead of having the master processor interrupt
  206          * all active processors, each processor in turn interrupts
  207          * the next active one. This avoids all slave processors
  208          * accessing the same R/W data simultaneously.
  209          */
  210         slave_clock();
  211 #endif  /* NCPUS >1 && AT386 */
  212 
  213         mp_enable_preemption();
  214 }
  215 
  216 #if     MACH_KPROF
  217 void
  218 delayed_clock(void)
  219 {
  220         int     i;
  221         int     my_cpu;
  222 
  223         mp_disable_preemption();
  224         my_cpu = cpu_number();
  225 
  226         if (missed_clock[my_cpu] > 1 && detect_lost_tick)
  227                 printf("hardclock: missed %d clock interrupt(s) at %x\n",
  228                        missed_clock[my_cpu]-1, masked_pc[my_cpu]);
  229         if (my_cpu == master_cpu) {
  230                 i = rtclock_intr();
  231                 assert(i == 0);
  232         }
  233         hertz_tick(0, masked_pc[my_cpu]);
  234         missed_clock[my_cpu] = 0;
  235 
  236         mp_enable_preemption();
  237 }
  238 #endif  /* MACH_KPROF */

Cache object: 9f00099dfc877b428b8a99baa51e71e6


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.