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/sched_policy/bg.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:        bg.c,v $
   29  * Revision 2.2  93/11/17  18:35:57  dbg
   30  *      Add per-policy scheduling parameters.
   31  *      [93/05/11            dbg]
   32  * 
   33  *      Moved common operations to kern/run_queues.c.
   34  *      [93/04/10            dbg]
   35  * 
   36  *      Created.
   37  *      [93/04/09            dbg]
   38  * 
   39  */
   40 
   41 /*
   42  *      Background thread scheduling.
   43  *
   44  *      Also provides 'null' parameter/limit routines, for policies
   45  *      that do not have parameters or limits.
   46  */
   47 
   48 #include <mach/boolean.h>
   49 
   50 #include <kern/macro_help.h>
   51 #include <kern/ast.h>
   52 #include <kern/kalloc.h>
   53 #include <kern/run_queues.h>
   54 #include <kern/sched_policy.h>
   55 #include <kern/processor.h>
   56 #include <kern/thread.h>
   57 
   58 /*
   59  *      Uses a single run queue.
   60  */
   61 struct bg_run_queue {
   62         struct run_queue rq;            /* common structure */
   63         queue_head_t    bg_queue;
   64 };
   65 typedef struct bg_run_queue *   bg_run_queue_t;
   66 
   67 #define bg_runq(rq)     ((struct bg_run_queue *)(rq))
   68 #define bg_count        rq.rq_count
   69 
   70 /*
   71  *      The background policy must have NO per-thread scheduling
   72  *      parameters.  Using background policy for thread depression
   73  *      assumes that the thread`s per-policy scheduling parameters
   74  *      will be untouched.
   75  */
   76 
   77 /*
   78  *      Choose thread.
   79  */
   80 thread_t
   81 bg_thread_dequeue(
   82         run_queue_t     runq)
   83 {
   84         bg_run_queue_t  rq = bg_runq(runq);
   85         queue_entry_t   elt;
   86         processor_t     processor;
   87 
   88         assert(rq->bg_count > 0);
   89         assert(!queue_empty(&rq->bg_queue));
   90 
   91         dequeue_head_macro(&rq->bg_queue, elt);
   92         rq->bg_count--;
   93 
   94         processor = current_processor();
   95         processor->quantum = processor->processor_set->set_quantum;
   96                                                         /* XXX */
   97         processor->first_quantum = TRUE;
   98 
   99         return (thread_t) elt;
  100 }
  101 
  102 /*
  103  *      Put a thread onto a run queue in priority order.
  104  *      Return whether it can preempt the current thread.
  105  */
  106 boolean_t bg_thread_enqueue(
  107         run_queue_t     runq,
  108         thread_t        thread,
  109         boolean_t       may_preempt)
  110 {
  111         register bg_run_queue_t rq;
  112         register queue_t        q;
  113 
  114         rq = bg_runq(runq);
  115 
  116         q = &rq->bg_queue;
  117         enqueue_tail_macro(q, (queue_entry_t) thread);
  118         rq->bg_count++;
  119 
  120         return FALSE;   /* never preempts */
  121 }
  122 
  123 void bg_thread_remqueue(
  124         run_queue_t     runq,
  125         thread_t        thread)
  126 {
  127         bg_run_queue_t  rq = bg_runq(runq);
  128                 
  129         remqueue(&rq->bg_queue, (queue_entry_t) thread);
  130         rq->bg_count--;
  131 }
  132 
  133 /*
  134  *      Context switch check for background threads.
  135  *      Schedule processor round-robin among background
  136  *      threads.
  137  */
  138 boolean_t bg_csw_needed(
  139         run_queue_t     runq,
  140         thread_t        thread)
  141 {
  142         if (current_processor()->first_quantum)
  143             return FALSE;
  144 
  145         return TRUE;
  146 }
  147 
  148 kern_return_t
  149 null_runq_set_limit(
  150         run_queue_t     runq,
  151         policy_param_t  limit,
  152         natural_t       count)
  153 {
  154         if (count == 0)
  155             return KERN_SUCCESS;
  156         return KERN_FAILURE;    /* no parameters */
  157 }
  158 
  159 kern_return_t
  160 null_runq_get_limit(
  161         run_queue_t     runq,
  162         policy_param_t  limit,
  163         natural_t       *count)
  164 {
  165         *count = 0;
  166         return KERN_SUCCESS;
  167 }
  168 
  169 kern_return_t
  170 null_thread_set_limit(
  171         thread_t        thread,
  172         policy_param_t  limit,
  173         natural_t       count)
  174 {
  175         if (count == 0)
  176             return KERN_SUCCESS;
  177         return KERN_FAILURE;            /* no parameters */
  178 }
  179 
  180 kern_return_t
  181 null_thread_set_param(
  182         thread_t        thread,
  183         policy_param_t  param,
  184         natural_t       count,
  185         boolean_t       new_policy,
  186         boolean_t       check_limits)
  187 {
  188         if (count == 0)
  189             return KERN_SUCCESS;
  190         return KERN_FAILURE;            /* no parameters */
  191 }
  192 
  193 kern_return_t
  194 null_thread_get_param(
  195         thread_t        thread,
  196         policy_param_t  param,
  197         natural_t       *count)
  198 {
  199         *count = 0;
  200         return KERN_SUCCESS;
  201 }
  202 
  203 kern_return_t
  204 null_task_set_param(
  205         task_t          task,
  206         policy_param_t  param,
  207         natural_t       count)
  208 {
  209         if (count == 0)
  210             return KERN_SUCCESS;
  211         return KERN_FAILURE;            /* no parameters */
  212 }
  213 
  214 kern_return_t
  215 null_task_get_param(
  216         task_t          task,
  217         policy_param_t  param,
  218         natural_t       *count)
  219 {
  220         *count = 0;
  221         return KERN_SUCCESS;
  222 }
  223 
  224 extern struct sched_policy      bg_sched_policy;        /* forward */
  225 
  226 run_queue_t
  227 bg_run_queue_alloc(void)
  228 {
  229         bg_run_queue_t rq;
  230 
  231         rq = (bg_run_queue_t) kalloc(sizeof(struct bg_run_queue));
  232 
  233         run_queue_init(&rq->rq, &bg_sched_policy);
  234 
  235         queue_init(&rq->bg_queue);
  236 
  237         return &rq->rq;
  238 }
  239 
  240 void
  241 bg_run_queue_free(
  242         run_queue_t     runq)
  243 {
  244         kfree((vm_offset_t) runq, sizeof(struct bg_run_queue));
  245 }
  246 
  247 #if     MACH_KDB
  248 #include <ddb/db_output.h>
  249 void bg_thread_db_print(
  250         thread_t        thread)
  251 {
  252         db_printf("BG     ");
  253 }
  254 #endif
  255 
  256 /*
  257  *      Statically allocated policy structure.
  258  */
  259 struct sched_policy     bg_sched_policy = {
  260     {
  261         /* sched_ops */
  262         bg_thread_dequeue,
  263         bg_thread_enqueue,
  264         bg_thread_remqueue,
  265 
  266         bg_csw_needed,
  267         ast_check,
  268         0,                      /* no update_priority */
  269 
  270         bg_run_queue_alloc,
  271         bg_run_queue_free,
  272 
  273         null_runq_set_limit,
  274         null_runq_get_limit,
  275         null_thread_set_limit,
  276         null_thread_set_param,
  277         null_thread_get_param,
  278         null_task_set_param,
  279         null_task_get_param,
  280 
  281 #if     MACH_KDB
  282         bg_thread_db_print
  283 #endif
  284     },
  285         POLICY_BACKGROUND,
  286         "background"
  287 };
  288 

Cache object: a7e10503a885211a1987031acaa1d586


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