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/kern/ast.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  * Mach Operating System
    3  * Copyright (c) 1993-1987 Carnegie Mellon University
    4  * All Rights Reserved.
    5  * 
    6  * Permission to use, copy, modify and distribute this software and its
    7  * documentation is hereby granted, provided that both the copyright
    8  * notice and this permission notice appear in all copies of the
    9  * software, derivative works or modified versions, and any portions
   10  * thereof, and that both notices appear in supporting documentation.
   11  * 
   12  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
   13  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
   14  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
   15  * 
   16  * Carnegie Mellon requests users of this software to return to
   17  * 
   18  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
   19  *  School of Computer Science
   20  *  Carnegie Mellon University
   21  *  Pittsburgh PA 15213-3890
   22  * 
   23  * any improvements or extensions that they make and grant Carnegie Mellon
   24  * the rights to redistribute these changes.
   25  */
   26 /* 
   27  * HISTORY
   28  * $Log:        ast.c,v $
   29  * Revision 2.15  93/11/17  17:06:14  dbg
   30  *      Context_switch check is now a routine in run_queues.c.
   31  *      ast_taken and ast_check both use csw_needed.
   32  * 
   33  *      Added ast_kernel_taken to take ASTs for periodic kernel
   34  *      operations.  Added ANSI function prototypes.
   35  *      [93/05/21            dbg]
   36  * 
   37  * Revision 2.14  93/05/15  18:53:51  mrt
   38  *      machparam.h -> machspl.h
   39  * 
   40  * Revision 2.13  93/01/14  17:33:33  danner
   41  *      Proper spl typing.
   42  *      [92/11/30            af]
   43  * 
   44  * Revision 2.12  92/08/03  17:36:32  jfriedl
   45  *      removed silly prototypes
   46  *      [92/08/02            jfriedl]
   47  * 
   48  * Revision 2.11  92/05/21  17:12:45  jfriedl
   49  *      tried prototypes.
   50  *      [92/05/20            jfriedl]
   51  * 
   52  * Revision 2.10  91/08/28  11:14:16  jsb
   53  *      Renamed AST_CLPORT to AST_NETIPC.
   54  *      [91/08/14  21:39:25  jsb]
   55  * 
   56  * Revision 2.9  91/06/17  15:46:48  jsb
   57  *      Renamed NORMA conditionals.
   58  *      [91/06/17  10:48:46  jsb]
   59  * 
   60  * Revision 2.8  91/06/06  17:06:43  jsb
   61  *      Added AST_CLPORT.
   62  *      [91/05/13  17:34:31  jsb]
   63  * 
   64  * Revision 2.7  91/05/14  16:39:48  mrt
   65  *      Correcting copyright
   66  * 
   67  * Revision 2.6  91/05/08  12:47:06  dbg
   68  *      Add volatile declarations where needed.
   69  *      [91/04/18            dbg]
   70  * 
   71  *      Add missing argument to ast_on in assign/shutdown case.
   72  *      [91/03/21            dbg]
   73  * 
   74  * Revision 2.5  91/03/16  14:49:23  rpd
   75  *      Cleanup.
   76  *      [91/02/13            rpd]
   77  *      Changed the AST interface.
   78  *      [91/01/17            rpd]
   79  * 
   80  * Revision 2.4  91/02/05  17:25:33  mrt
   81  *      Changed to new Mach copyright
   82  *      [91/02/01  16:11:01  mrt]
   83  * 
   84  * Revision 2.3  90/06/02  14:53:30  rpd
   85  *      Updated with new processor/processor-set technology.
   86  *      [90/03/26  22:02:00  rpd]
   87  * 
   88  * Revision 2.2  90/02/22  20:02:37  dbg
   89  *      Remove lint.
   90  *      [90/01/29            dbg]
   91  * 
   92  * Revision 2.1  89/08/03  15:42:10  rwd
   93  * Created.
   94  * 
   95  *  2-Feb-89  David Golub (dbg) at Carnegie-Mellon University
   96  *      Moved swtch to this file.
   97  *
   98  * 23-Nov-88  David Black (dlb) at Carnegie-Mellon University
   99  *      Hack up swtch() again.  Drop priority just low enough to run
  100  *      something else if it's runnable.  Do missing priority updates.
  101  *      Make sure to lock thread and double check whether update is needed.
  102  *      Yet more cruft until I can get around to doing it right.
  103  *
  104  *  6-Sep-88  David Golub (dbg) at Carnegie-Mellon University
  105  *      Removed all non-MACH code.
  106  *
  107  * 11-Aug-88  David Black (dlb) at Carnegie-Mellon University
  108  *      csw_check is now the csw_needed macro in sched.h.  Rewrite
  109  *      ast_check for new ast mechanism.
  110  *
  111  *  9-Aug-88  David Black (dlb) at Carnegie-Mellon University
  112  *      Rewrote swtch to check runq counts directly.
  113  *
  114  *  9-Aug-88  David Black (dlb) at Carnegie-Mellon University
  115  *      Delete runrun.  Rewrite csw_check so it can become a macro.
  116  *
  117  *  4-May-88  David Black (dlb) at Carnegie-Mellon University
  118  *      Moved cpu not running check to ast_check().
  119  *      New preempt priority logic.
  120  *      Increment runrun if ast is for context switch.
  121  *      Give absolute priority to local run queues.
  122  *
  123  * 20-Apr-88  David Black (dlb) at Carnegie-Mellon University
  124  *      New signal check logic.
  125  *
  126  * 18-Nov-87  Avadis Tevanian (avie) at Carnegie-Mellon University
  127  *      Flushed conditionals, reset history.
  128  */ 
  129 
  130 /*
  131  *
  132  *      This file contains routines to check whether an ast is needed.
  133  *
  134  *      ast_check() - check whether ast is needed for interrupt or context
  135  *      switch.  Usually called by clock interrupt handler.
  136  *
  137  */
  138 
  139 #include <cpus.h>
  140 #include <norma_ipc.h>
  141 
  142 #include <kern/ast.h>
  143 #include <kern/counters.h>
  144 #include <kern/cpu_number.h>
  145 #include <kern/queue.h>
  146 #include <kern/run_queues.h>
  147 #include <kern/sched_prim.h>
  148 #include <kern/thread.h>
  149 #include <kern/processor.h>
  150 #include <kern/mach_timer.h>    /* timer_ast */
  151 #include <device/net_io.h>      /* net_ast */
  152 
  153 #include <machine/machspl.h>    /* for splsched */
  154 
  155 
  156 volatile ast_t need_ast[NCPUS];
  157 
  158 void
  159 ast_init(void)
  160 {
  161 #ifndef MACHINE_AST
  162         register int i;
  163 
  164         for (i=0; i<NCPUS; i++)
  165                 need_ast[i] = 0;
  166 #endif  /* MACHINE_AST */
  167 }
  168 
  169 void
  170 ast_taken(void)
  171 {
  172         register thread_t self = current_thread();
  173         register ast_t reasons;
  174 
  175         /*
  176          *      Interrupts are still disabled.
  177          *      We must clear need_ast and then enable interrupts.
  178          */
  179 
  180         reasons = need_ast[cpu_number()];
  181         need_ast[cpu_number()] = AST_ZILCH;
  182         (void) spl0();
  183 
  184         /*
  185          *      These actions must not block.
  186          */
  187 
  188         if (reasons & AST_TIMER)
  189                 timer_ast();
  190 
  191         if (reasons & AST_NETWORK)
  192                 net_ast();
  193 
  194 #if     NORMA_IPC
  195         if (reasons & AST_NETIPC)
  196                 netipc_ast();
  197 #endif  /* NORMA_IPC */
  198 
  199         /*
  200          *      Make darn sure that we don`t call thread_halt_self
  201          *      or thread_block from the idle thread.
  202          */
  203 
  204         if (self != current_processor()->idle_thread) {
  205 
  206                 if (self->ast & AST_HALT) {
  207                         thread_halt_self(thread_exception_return);
  208                         /*NOTREACHED*/
  209                 }
  210 
  211                 if (self->ast & AST_TERMINATE) {
  212                         thread_terminate_self();
  213                         /*NOTREACHED*/
  214                 }
  215 
  216                 /*
  217                  *      One of the previous actions might well have
  218                  *      woken a high-priority thread, so we use
  219                  *      csw_needed in addition to AST_BLOCK.
  220                  */
  221 
  222                 if ((reasons & AST_BLOCK) ||
  223                     csw_needed(self, current_processor())) {
  224                         counter(c_ast_taken_block++);
  225                         thread_block(thread_exception_return);
  226                 }
  227         }
  228 }
  229 
  230 /*
  231  * Take ASTs for periodic kernel activities.
  232  * Called at splsched.
  233  * Returns at spl0.
  234  */
  235 void
  236 ast_kernel_taken(void)
  237 {
  238         register int    mycpu = cpu_number();
  239         register ast_t  reasons;
  240 
  241         reasons = need_ast[mycpu];
  242         need_ast[mycpu] &= ~AST_KERNEL;
  243         (void) spl0();
  244 
  245         /*
  246          *      These actions must not block.
  247          */
  248 
  249         if (reasons & AST_TIMER)
  250                 timer_ast();
  251 
  252         if (reasons & AST_NETWORK)
  253                 net_ast();
  254 
  255 #if     NORMA_IPC
  256         if (reasons & AST_NETIPC)
  257                 netipc_ast();
  258 #endif  /* NORMA_IPC */
  259 }
  260 
  261 void
  262 ast_check(
  263         thread_t        thread,         /* always the current thread */
  264         boolean_t       end_quantum)
  265 {
  266         register int            mycpu = cpu_number();
  267         register processor_t    myprocessor;
  268         spl_t                   s = splsched();
  269 
  270         /*
  271          *      Check processor state for ast conditions.
  272          */
  273         myprocessor = cpu_to_processor(mycpu);
  274         switch (myprocessor->state) {
  275             case PROCESSOR_OFF_LINE:
  276             case PROCESSOR_IDLE:
  277             case PROCESSOR_DISPATCHING:
  278                 /*
  279                  *      No ast.
  280                  */
  281                 break;
  282 
  283 #if     NCPUS > 1
  284             case PROCESSOR_ASSIGN:
  285             case PROCESSOR_SHUTDOWN:
  286                 /*
  287                  *      Need ast to force action thread onto processor.
  288                  *
  289                  * XXX  Should check if action thread is already there.
  290                  */
  291                 ast_on(mycpu, AST_BLOCK);
  292                 break;
  293 #endif  /* NCPUS > 1 */
  294 
  295             case PROCESSOR_RUNNING:
  296 
  297                 /*
  298                  *      Propagate thread ast to processor.  If we already
  299                  *      need an ast, don't look for more reasons.
  300                  */
  301                 ast_propagate(thread, mycpu);
  302                 if (ast_needed(mycpu))
  303                         break;
  304 
  305                 /*
  306                  *      Check for context switch.
  307                  */
  308                 if ((thread->state & TH_SUSP) ||
  309                     csw_needed(thread, myprocessor))
  310                 {
  311                     ast_on(mycpu, AST_BLOCK);
  312                 }
  313                 break;
  314 
  315             default:
  316                 panic("ast_check: Bad processor state");
  317         }
  318 
  319         splx(s);
  320 }

Cache object: 573d284f8fe05fa76576da22932066cb


[ 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.