Annotation of XNU/osfmk/kern/processor.h, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
        !             3:  *
        !             4:  * @APPLE_LICENSE_HEADER_START@
        !             5:  * 
        !             6:  * The contents of this file constitute Original Code as defined in and
        !             7:  * are subject to the Apple Public Source License Version 1.1 (the
        !             8:  * "License").  You may not use this file except in compliance with the
        !             9:  * License.  Please obtain a copy of the License at
        !            10:  * http://www.apple.com/publicsource and read it before using this file.
        !            11:  * 
        !            12:  * This Original Code and all software distributed under the License are
        !            13:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
        !            14:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
        !            15:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
        !            16:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
        !            17:  * License for the specific language governing rights and limitations
        !            18:  * under the License.
        !            19:  * 
        !            20:  * @APPLE_LICENSE_HEADER_END@
        !            21:  */
        !            22: /*
        !            23:  * @OSF_COPYRIGHT@
        !            24:  */
        !            25: /* 
        !            26:  * Mach Operating System
        !            27:  * Copyright (c) 1991,1990,1989 Carnegie Mellon University
        !            28:  * All Rights Reserved.
        !            29:  * 
        !            30:  * Permission to use, copy, modify and distribute this software and its
        !            31:  * documentation is hereby granted, provided that both the copyright
        !            32:  * notice and this permission notice appear in all copies of the
        !            33:  * software, derivative works or modified versions, and any portions
        !            34:  * thereof, and that both notices appear in supporting documentation.
        !            35:  * 
        !            36:  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
        !            37:  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
        !            38:  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
        !            39:  * 
        !            40:  * Carnegie Mellon requests users of this software to return to
        !            41:  * 
        !            42:  *  Software Distribution Coordinator  or  [email protected]
        !            43:  *  School of Computer Science
        !            44:  *  Carnegie Mellon University
        !            45:  *  Pittsburgh PA 15213-3890
        !            46:  * 
        !            47:  * any improvements or extensions that they make and grant Carnegie Mellon
        !            48:  * the rights to redistribute these changes.
        !            49:  */
        !            50: /*
        !            51:  */
        !            52: 
        !            53: /*
        !            54:  *     processor.h:    Processor and processor-set definitions.
        !            55:  */
        !            56: 
        !            57: #ifndef        _KERN_PROCESSOR_H_
        !            58: #define        _KERN_PROCESSOR_H_
        !            59: 
        !            60: /*
        !            61:  *     Data structures for managing processors and sets of processors.
        !            62:  */
        !            63: #include <mach/boolean.h>
        !            64: #include <mach/kern_return.h>
        !            65: #include <kern/kern_types.h>
        !            66: 
        !            67: extern struct processor_set    default_pset;
        !            68: extern processor_t     master_processor;
        !            69: 
        !            70: #ifdef MACH_KERNEL_PRIVATE
        !            71: 
        !            72: #include <cpus.h>
        !            73: #include <mach_host.h>
        !            74: 
        !            75: #include <mach/mach_types.h>
        !            76: #include <kern/cpu_number.h>
        !            77: #include <kern/lock.h>
        !            78: #include <kern/queue.h>
        !            79: #include <kern/sched.h>
        !            80: 
        !            81: #if    NCPUS > 1
        !            82: #include <machine/ast_types.h>
        !            83: #endif /* NCPUS > 1 */
        !            84: 
        !            85: struct processor_set {
        !            86:        struct  run_queue       runq;           /* runq for this set */
        !            87:        queue_head_t            idle_queue;     /* idle processors */
        !            88:        int                     idle_count;     /* how many ? */
        !            89:        decl_simple_lock_data(,idle_lock)       /* lock for above */
        !            90:        queue_head_t            processors;     /* all processors here */
        !            91:        int                     processor_count;        /* how many ? */
        !            92:        boolean_t               empty;          /* true if no processors */
        !            93:        queue_head_t            tasks;          /* tasks assigned */
        !            94:        int                     task_count;     /* how many */
        !            95:        queue_head_t            threads;        /* threads in this set */
        !            96:        int                     thread_count;   /* how many */
        !            97:        int                     ref_count;      /* structure ref count */
        !            98:        queue_chain_t           all_psets;      /* link for all_psets */
        !            99:        boolean_t               active;         /* is pset in use */
        !           100:        decl_mutex_data(,       lock)           /* lock for everything else */
        !           101:        struct ipc_port *       pset_self;      /* port for operations */
        !           102:        struct ipc_port *       pset_name_self; /* port for information */
        !           103:        int                     max_priority;   /* maximum priority */
        !           104:        int                     policies;       /* bit vector for policies */
        !           105:        int                     set_quantum;    /* current default quantum */
        !           106: #if    NCPUS > 1
        !           107:        int                     quantum_adj_index; /* runtime quantum adj. */
        !           108:        decl_simple_lock_data(,quantum_adj_lock)  /* lock for above */
        !           109:        int                     machine_quantum[NCPUS+1]; /* ditto */
        !           110: #endif /* NCPUS > 1 */
        !           111:        integer_t               mach_factor;    /* mach_factor */
        !           112:        integer_t               load_average;   /* load_average */
        !           113:        long                    sched_load;     /* load avg for scheduler */
        !           114:        policy_t                policy_default; /* per set default */
        !           115:        policy_base_data_t      policy_base;    /* base attributes */
        !           116:        policy_limit_data_t     policy_limit;   /* limit attributes */
        !           117: };
        !           118: 
        !           119: 
        !           120: struct processor {
        !           121: #if    NCPUS > 1
        !           122:        struct run_queue runq;          /* local runq for this processor */
        !           123: #endif /* NCPUS > 1*/
        !           124:        queue_chain_t   processor_queue; /* idle/assign/shutdown queue link */
        !           125:        int             state;          /* See below */
        !           126:        struct thread_shuttle
        !           127:                        *next_thread,   /* next thread to run if dispatched */
        !           128:                        *idle_thread;   /* this processor's idle thread. */
        !           129:        int             quantum;        /* quantum for current thread */
        !           130:        boolean_t       first_quantum;  /* first quantum in succession */
        !           131:        int             last_quantum;   /* last quantum assigned */
        !           132: 
        !           133:        processor_set_t processor_set;  /* processor set I belong to */
        !           134:        processor_set_t processor_set_next;     /* set I will belong to */
        !           135:        queue_chain_t   processors;     /* all processors in set */
        !           136:        decl_simple_lock_data(,lock)
        !           137:        struct ipc_port *processor_self;        /* port for operations */
        !           138:        int             slot_num;       /* machine-indep slot number */
        !           139: #if    NCPUS > 1
        !           140:        ast_check_t     ast_check_data; /* for remote ast_check invocation */
        !           141:        queue_chain_t   softclock_queue;/* cpus handling softclocks */
        !           142: #endif /* NCPUS > 1 */
        !           143:        /* punt id data temporarily */
        !           144: };
        !           145: 
        !           146: extern struct processor        processor_array[NCPUS];
        !           147: 
        !           148: /*
        !           149:  *     Chain of all processor sets.
        !           150:  */
        !           151: extern queue_head_t            all_psets;
        !           152: extern int                     all_psets_count;
        !           153: decl_mutex_data(extern,                all_psets_lock)
        !           154: 
        !           155: /*
        !           156:  *     XXX need a pointer to the master processor structure
        !           157:  */
        !           158: 
        !           159: 
        !           160: /*
        !           161:  *     NOTE: The processor->processor_set link is needed in one of the
        !           162:  *     scheduler's critical paths.  [Figure out where to look for another
        !           163:  *     thread to run on this processor.]  It is accessed without locking.
        !           164:  *     The following access protocol controls this field.
        !           165:  *
        !           166:  *     Read from own processor - just read.
        !           167:  *     Read from another processor - lock processor structure during read.
        !           168:  *     Write from own processor - lock processor structure during write.
        !           169:  *     Write from another processor - NOT PERMITTED.
        !           170:  *
        !           171:  */
        !           172: 
        !           173: /*
        !           174:  *     Processor state locking:
        !           175:  *
        !           176:  *     Values for the processor state are defined below.  If the processor
        !           177:  *     is off-line or being shutdown, then it is only necessary to lock
        !           178:  *     the processor to change its state.  Otherwise it is only necessary
        !           179:  *     to lock its processor set's idle_lock.  Scheduler code will
        !           180:  *     typically lock only the idle_lock, but processor manipulation code
        !           181:  *     will often lock both.
        !           182:  */
        !           183: 
        !           184: #define PROCESSOR_OFF_LINE             0       /* Not in system */
        !           185: #define        PROCESSOR_RUNNING               1       /* Running a normal thread */
        !           186: #define        PROCESSOR_IDLE                  2       /* idle */
        !           187: #define PROCESSOR_DISPATCHING  3       /* dispatching (idle -> running) */
        !           188: #define        PROCESSOR_ASSIGN                4       /* Assignment is changing */
        !           189: #define PROCESSOR_SHUTDOWN             5       /* Being shutdown */
        !           190: 
        !           191: /*
        !           192:  *     Use processor ptr array to find current processor's data structure.
        !           193:  *     This replaces a multiplication (index into processor_array) with
        !           194:  *     an array lookup and a memory reference.  It also allows us to save
        !           195:  *     space if processor numbering gets too sparse.
        !           196:  */
        !           197: 
        !           198: extern processor_t     processor_ptr[NCPUS];
        !           199: 
        !           200: #define cpu_to_processor(i)    (processor_ptr[i])
        !           201: 
        !           202: #define current_processor()    (processor_ptr[cpu_number()])
        !           203: #define current_processor_set()        (current_processor()->processor_set)
        !           204: 
        !           205: /* Compatibility -- will go away */
        !           206: 
        !           207: #define cpu_state(slot_num)    (processor_ptr[slot_num]->state)
        !           208: #define cpu_idle(slot_num)     (cpu_state(slot_num) == PROCESSOR_IDLE)
        !           209: 
        !           210: /* Useful lock macros */
        !           211: 
        !           212: #define        pset_lock(pset)         mutex_lock(&(pset)->lock)
        !           213: #define        pset_lock_try(pset)     mutex_try(&(pset)->lock)
        !           214: #define pset_unlock(pset)      mutex_unlock(&(pset)->lock)
        !           215: 
        !           216: #define processor_lock(pr)     simple_lock(&(pr)->lock)
        !           217: #define processor_unlock(pr)   simple_unlock(&(pr)->lock)
        !           218: 
        !           219: 
        !           220: extern void            pset_sys_bootstrap(void);
        !           221: 
        !           222: extern void            pset_sys_init(void);
        !           223: 
        !           224: extern void            action_thread(void);
        !           225: 
        !           226: /* Implemented by MD layer */
        !           227: 
        !           228: extern void            cpu_up(
        !           229:                                int             cpu);
        !           230: 
        !           231: extern kern_return_t   processor_shutdown(
        !           232:                                processor_t     processor);
        !           233: 
        !           234: #endif /* MACH_KERNEL_PRIVATE */
        !           235: 
        !           236: extern int             pset_max_priority(
        !           237:                                processor_set_t pset,
        !           238:                                policy_t        policy);
        !           239: 
        !           240: extern int             pset_base_priority(
        !           241:                                processor_set_t pset,
        !           242:                                policy_t        policy);
        !           243: 
        !           244: extern int             pset_sched_data(
        !           245:                                processor_set_t pset,
        !           246:                                policy_t        policy);
        !           247: 
        !           248: 
        !           249: extern void            pset_remove_processor(
        !           250:                                processor_set_t pset,
        !           251:                                processor_t     processor);
        !           252: 
        !           253: extern void            pset_add_processor(
        !           254:                                processor_set_t pset,
        !           255:                                processor_t     processor);
        !           256: 
        !           257: extern void            pset_remove_task(
        !           258:                                processor_set_t pset,
        !           259:                                task_t          task);
        !           260: 
        !           261: extern void            pset_add_task(
        !           262:                                processor_set_t pset,
        !           263:                                task_t          task);
        !           264: 
        !           265: extern void            pset_remove_thread(
        !           266:                                processor_set_t pset,
        !           267:                                thread_t        thread);
        !           268: 
        !           269: extern void            pset_add_thread(
        !           270:                                processor_set_t pset,
        !           271:                                thread_t        thread);
        !           272: 
        !           273: extern void            thread_change_psets(
        !           274:                                thread_t        thread,
        !           275:                                processor_set_t old_pset,
        !           276:                                processor_set_t new_pset);
        !           277: 
        !           278: extern void            pset_deallocate(
        !           279:                                processor_set_t pset);
        !           280: 
        !           281: extern void            pset_reference(
        !           282:                                processor_set_t pset);
        !           283: 
        !           284: extern kern_return_t   processor_assign(
        !           285:                                processor_t     processor,
        !           286:                                processor_set_t new_pset,
        !           287:                                boolean_t       wait);
        !           288: 
        !           289: extern kern_return_t   processor_start(
        !           290:                                processor_t     processor);
        !           291: 
        !           292: extern kern_return_t   processor_exit(
        !           293:                                processor_t     processor);
        !           294: 
        !           295: #endif /* _KERN_PROCESSOR_H_ */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.