home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / mach / doc / unpublished / promanual.doc.Z / promanual.doc
Encoding:
Text File  |  1992-08-18  |  72.3 KB  |  2,084 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.                          MACH KERNEL INTERFACE MANUAL
  16.  
  17.                  Robert V. Baron, David Black, William Bolosky
  18.                Jonathan Chew, Richard P. Draves, David B. Golub
  19.               Ted Lehr, Richard F. Rashid, Avadis Tevanian, Jr.,
  20.                               Michael Wayne Young
  21.  
  22.                            Editor: Mary R. Thompson
  23.  
  24.                         Department of Computer Science
  25.                           Carnegie-Mellon University
  26.                              Pittsburgh, PA 15213
  27.                                   Version of:
  28.                                 13 August 1990
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.                                    ABSTRACT
  38.  
  39. MACH  is  an  operating  system  kernel  under  development  at Carnegie-Mellon
  40. University to support distributed and parallel computation.  MACH  is  designed
  41. to  support  computing environments consisting of networks of uniprocessors and
  42. multiprocessors.  This manual describes the interface to  the  MACH  kernel  in
  43. detail.    The MACH system currently runs on a wide variety of uniprocessor and
  44. multiprocessor architectures.
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.   This research was sponsored by the Defense Advanced Research Projects  Agency
  53. (DOD),  ARPA  Order  No. 4864, monitored by the Space and Naval Warfare Systems
  54. Command under contract N00039-84-C-0467.
  55.  
  56.   The views and conclusions contained in this document are those of the authors
  57. and  should  not  be  interpreted  as  representing  official  policies, either
  58. expressed or implied, of the Defense Advanced Research Projects  Agency  or  of
  59. the U.S.  Government.
  60. 1. Processor allocation primitives
  61.  
  62.  
  63.  
  64. 1.1. Concepts
  65.   The  processor  allocation  interface  supports  control  over  processors by
  66. user-mode programs.  Application areas  include  gang  scheduling  and  speedup
  67. measurement;  both  of these require allocating a specific number of processors
  68. to an application for the exclusive use of that application.
  69.  
  70.   This interface introduces three new entities in  addition  to  those  already
  71. exported by the MACH kernel:
  72.  
  73.    - processor  - This corresponds to a hardware processor.  Internally it
  74.      corresponds to a data structure containing a local run queue.   There
  75.      is  a  distinguished  processor,  known  as  the  master  (until  the
  76.      kernelized system gets  rid  of  it).  There  is  a  privileged  port
  77.      exported  by  the processor object to privileged servers which allows
  78.      control of the physical processor.
  79.  
  80.    - processor_set  -  This  is  a  set  of  processors.    Internally  it
  81.      corresponds  to  a data structure containing a "global" run queue and
  82.      an idle queue.  There is a distinguished set known as the default set
  83.      to  which  all tasks, threads, and processors are initially assigned.
  84.      Two ports are exported by a processor_set, a name port for  obtaining
  85.      information  about  the  set,  and  an  control  port  for performing
  86.      operations on it. Neither of these ports are privileged.
  87.  
  88.    - host - This represents the host.  There are  two  ports  exported  by
  89.      this  object:  a  non-privileged port, host, for information queries,
  90.      and a privileged port, host_priv,  port  that  grants  the  right  to
  91.      manipulate  physical  resources.    Other  resource  operations (e.g.
  92.      making memory non-pageable)  will  be  added  in  the  future.    The
  93.      non-privileged port should be used to name the host.
  94.  
  95. Every  processor  is  always assigned to exactly one processor set; a processor
  96. only executes threads that are assigned to its processor set.  Every thread  is
  97. always  assigned  to exactly one processor set, and only executes on processors
  98.                                    tm
  99. assigned to that processor set[Unix   system calls are an exception;  they  may
  100. force  a  thread  to  the  master  processor].  Each task is also assigned to a
  101. processor set, but this assignment is only for the purposes of determining  the
  102. initial  assignment  of  newly  created  tasks and threads; tasks inherit their
  103. initial assignment  from  their  parent,  and  threads  inherit  their  initial
  104. assignment  from the task that contains them.  These assignments may be changed
  105. subsequently.
  106.  
  107.   The host concept is introduced to isolate authentication  concerns  from  the
  108. processor  allocation  interface.    The  host_priv  and  processor  ports  are
  109. privileged and only available to privileged servers.  The kernel only  provides
  110. allocation  mechanisms  for  processors;  policy  is  the responsibility of the
  111. server(s).  In addition the servers may understand more about the  topology  of
  112. the  machine  (e.g. clustering of processors) than the kernel (the kernel makes
  113. no  distinctions  among  processors  internally).    Processor  sets  are   not
  114. privileged, and are intended to form a basis for the interfaces exported by the
  115. privileged servers.  (Note that non-privileged users cannot  obtain  ports  for
  116. the  processors  assigned  to user-created processor sets even though they have
  117. the processor set  control  port.)  The  use  of  unprivileged  processor  sets
  118. exported  by  the  kernel  allows users to do scheduling (i.e.  task and thread
  119. assignment) directly without having any resource control privileges.
  120.  
  121.   This interface will exist on  all  machines,  even  uniprocessors;  a  kernel
  122. configuration  switch deletes the code required to support processor allocation
  123. internally and returns failure codes.  On a uniprocessor,  the  only  processor
  124. set  that  exists  is the default processor set; its control port is privileged
  125. and not available to most users.  The calls to retrieve information  about  the
  126. processors and the default processor set are useful even on such machines.
  127.  
  128.  
  129.  
  130. 1.2. Functionality
  131.   This  interface  supports  partitioning  of  the  processing  capability of a
  132. multiprocessor among applications in a fixed fashion.  The granularity of  this
  133. division  is at the processor level.  Processor sets are assembled by assigning
  134. processors to sets; a processor assigned to a set will only  run  threads  that
  135. have  been  assigned  to that set.  Binding threads to individual processors is
  136. accomplished by creating processor sets containing exactly one processor.   The
  137. master  processor  must always be assigned to the default set.  Future versions
  138. of MACH intend to remove the need for a master processor. At that time the  the
  139. default set must always be assigned at least one processor.
  140.  
  141.   Binding  of threads to individual processors can be achieved by assigning the
  142. threads to processor sets  that  contain  exactly  one  processor.    A  kernel
  143. configuration switch is available to keep threads on the same processor in most
  144. situations where at most n threads are assigned to a processor set to which  at
  145. least n processors are assigned.
  146.  
  147.   All  of  the primitives except two are implemented via the ipc interface, and
  148. are therefore available over the network.  This allows  a  long-term  scheduler
  149. for a multiprocessor to reside on another machine.  The two primitives that are
  150. implemented as traps are host_self and host_priv_self. The  latter  is  only  a
  151. trap pending implementation of an authorization/authentication mechanisms.
  152.  
  153.  
  154.  
  155. 1.3. Uses
  156.  
  157.    - Gang  Scheduling  - A gang scheduler can be written externally to the
  158.      kernel.  The scheduler can be  implemented  by  shuffling  processors
  159.      among  processor sets, thus avoiding any interaction with application
  160.      use of task and thread control primitives.
  161.  
  162.    - Speedup Measurement - A single  processor  set  of  k  processors  is
  163.      sufficient  to  measure  the performance of a parallel application on
  164.      that many processors.  The application may have more than k threads.
  165.  
  166.    - User-Mode Scheduling -  Assigning  a  single  processor  to  each  of
  167.      several processor sets allows user applications complete control over
  168.      the threads that execute on these processors.   In  addition  to  the
  169.      assign  primitives, the existing suspend and resume primitives are of
  170.      potential utility.
  171.  
  172.    - Application binding - Portions of an  application  can  be  bound  to
  173.      dedicated  processors to optimize performance characteristics.  Users
  174.      may choose among many alternatives ranging  from  one  processor  set
  175.      with  all  the  dedicated processors and corresponding threads to one
  176.      processor set for each dedicated processor.
  177.  
  178.    - Load Balancing for Non-Uniform Memory Access (NUMA) Multiprocessors -
  179.      Assigning  each cluster of processors (i.e. processors with identical
  180.      memory access characteristics) to a separate processor_set allows the
  181.      kernel  to  perform load balancing only within clusters.  A user-mode
  182.      load balancer  can  then  perform  load  balancing  across  clusters.
  183.      Additional  primitives to make load information available efficiently
  184.      to support this are under design.
  185.  
  186.   It should be noted that Speedup Measurement and Application  Binding  of  Ada
  187. applications  will  usually  require  assigning  a  group  of  k  threads  to n
  188. processors, where k > n > 1,  for  best  performance.    This  is  due  to  the
  189. synchronous  nature  of  Ada's  rendezvous,  and  is  also true of applications
  190. structured using remote procedure call.  This functionality is not supported by
  191. a simpler interface that can only bind threads to dedicated processors.
  192. host_self
  193.  
  194. #include <mach.h>
  195.  
  196. host_t host_self()
  197.  
  198. host_priv_t host_priv_self()
  199.  
  200.  
  201. Description
  202.  
  203.   host_self returns send rights to the host port for the host on which the call
  204. is executed.  This port can only be used to obtain information about the host.
  205.  
  206.   host_priv_self returns send rights to the privileged host port for  the  host
  207. on which the call is executed.  This port is used to control physical resources
  208. on that host. It is needed for the operations that wire-down memory pagaes  and
  209. the  call  that  returns  the  processor  ports  which in turn allow control of
  210. specific processors.  Currently, this port is only returned if  the  caller  is
  211. the Unix super-user. Otherwise PORT_NULL is returned.
  212.  
  213. See Also
  214.  
  215.   host_processors, host_info, host_kernel_version
  216.  
  217. Notes
  218.  
  219.   Availability   limited.     host_priv_self  should  be  replaced  by  a  real
  220. authentication mechanism.
  221. host_processors
  222.  
  223. #include <mach.h>
  224.  
  225. kern_return_t host_processors(host_priv, processor_list, processor_count)
  226.     host_priv_t         host_priv;
  227.     processor_array_t   *processor_list;        /* out, ptr to array */
  228.     int                 *processor_count;       /* out */
  229.  
  230.  
  231. Arguments
  232.  
  233.   host_priv       Privileged host port for the desired host.
  234.  
  235.   processor_list  The set of processors existing on  host_priv,  no  particular
  236.                   ordering is guaranteed.
  237.  
  238.   processor_count The number of threads in the processor_list.
  239.  
  240. Description
  241.  
  242.   host_processors  gets  send  rights  to the processor port for each processor
  243. existing on host_priv. This is the privileged port that allows  its  holder  to
  244. control  a processor. processor_list is an array that is created as a result of
  245. this call. The caller may wish to vm_deallocate this array when the data is  no
  246. longer needed.
  247.  
  248. Returns
  249.  
  250.   KERN_SUCCESS    The call succeeded.
  251.  
  252.   KERN_INVALID_ARGUMENT
  253.                   host_priv is not a privileged host port.
  254.  
  255.   KERN_INVALID_ADDRESS
  256.                   processor_count points to inaccessible memory.
  257.  
  258. See Also
  259.  
  260.   processor_start, processor_exit, processor_info, processor_control
  261.  
  262. Notes
  263.  
  264.   Availability limited.
  265. host_processor_sets
  266.  
  267. #include <mach.h>
  268.  
  269. kern_return_t
  270. host_processor_sets(host, processor_set_list, processor_set_count)
  271.     host_t                 host;
  272.     processor_set_array_t  *processor_set_list; /* out, ptr to array */
  273.     int                    *processor_set_count;        /* out */
  274.  
  275.  
  276.  
  277. Arguments
  278.  
  279.   host            The  host  for which the list of processor sets is requested.
  280.                   Either the host port or the privileged host port may be used.
  281.  
  282.   processor_set_list
  283.                   The  set  of  processor_sets  currently  existing on host; no
  284.                   particular ordering is guaranteed.
  285.  
  286.   processor_set_count
  287.                   The number of processor_sets in the processor_set_list.
  288.  
  289. Description
  290.  
  291.   host_processor_sets  gets send rights to the name port for each processor_set
  292. currently assigned to host. host_processor_set_priv can be used to  obtain  the
  293. object  ports  from  these  if desired.  processor_set_list is an array that is
  294. created as a result of this call. The caller may  wish  to  vm_deallocate  this
  295. array when the data is no longer needed.
  296.  
  297. Returns
  298.  
  299.   KERN_SUCCESS    The call succeeded.
  300.  
  301.   KERN_INVALID_ARGUMENT
  302.                   host is not a host.
  303.  
  304. Notes
  305.  
  306.   Availability limited.
  307.  
  308. See Also
  309.  
  310.   host_processor_set_priv,      processor_set_create,      processor_set_tasks,
  311. processor_set_threads
  312. host_processor_set_priv
  313.  
  314. #include <mach.h>
  315. kern_return_t host_processor_set_priv(host_priv, set_name, set);
  316.         host_priv_t             host_priv;
  317.         processor_set_name_t    set_name;
  318.         processor_set_t         *set;
  319.  
  320.  
  321. Arguments
  322.  
  323.   host_priv       The privileged host port for the host on which this processor
  324.                   set resides.
  325.  
  326.   set_name        The name port for this set.
  327.  
  328.   set             Returns the control port for this set.
  329.  
  330. Description
  331.  
  332.   This call allows a privileged application to obtain the control port  for  an
  333. existing  processor  set  from  its  name  port.    The privileged host port is
  334. required.
  335.  
  336. Notes
  337.  
  338.   Availability limited.
  339.  
  340. See Also
  341.  
  342.   host_ports, processor_set_default, processor_set_create
  343. host_info
  344.  
  345. #include <mach.h>
  346.  
  347. /* the definition of host_info_t from mach.h - sys/host_info.h is */
  348.  
  349. typedef int     *host_info_t;           /* variable length array of int */
  350.  
  351. /* two  interpretations of info are: */
  352.  
  353.    struct host_basic_info {
  354.         int             max_cpus;       /* maximum possible cpus for
  355.                                            which kernel is configured */
  356.         int             avail_cpus;     /* number of cpus now available */
  357.         vm_size_t       memory_size;    /* size of memory in bytes */
  358.         cpu_type_t      cpu_type;       /* cpu type */
  359.         cpu_subtype_t   cpu_subtype;    /* cpu subtype */
  360.    };
  361. typedef struct host_basic_info          *host_basic_info_t;
  362.  
  363.  
  364. struct host_sched_info {
  365.         int             min_timeout;    /* minimum timeout in milliseconds */
  366.         int             min_quantum;    /* minimum quantum in milliseconds */
  367. };
  368. typedef struct host_sched_info *host_sched_info_t
  369.  
  370.  
  371. kern_return_t host_info(host, flavor, host_info, host_infoCnt)
  372.         host_t          host;
  373.         int             flavor;
  374.         host_info_t     host_info;      /* in and out */
  375.         unsigned int    *host_infoCnt;  /* in and out */
  376.  
  377.  
  378. Arguments
  379.  
  380.   host            The host for which information is to be obtained
  381.  
  382.   flavor          The  type  of  statistics  that  are   wanted.      Currently
  383.                   HOST_BASIC_INFO,  HOST_PROCESSOR_SLOTS,  and  HOST_SCHED_INFO
  384.                   are implemented.
  385.  
  386.   host_info       Statistics about the host specified by host.
  387.  
  388.   host_infoCnt    Size of the info structure. Should  be  HOST_BASIC_INFO_COUNT
  389.                   for  HOST_BASIC_INFO.    Should  be  the  max  number of cpus
  390.                   returned by HOST_BASIC_INFO for HOST_PROCESSOR_SLOTS.  Should
  391.                   be HOST_SCHED_INFO_COUNT for HOST_SCHED_INFO.
  392.  
  393. Description
  394.  
  395.   Returns  the  selected  information array for a host, as specified by flavor.
  396. host_info is an array of integers that is supplied by the  caller,  and  filled
  397. with  specified information.  host_infoCnt is supplied as the maximum number of
  398. integers in host_info. On return, it contains the actual number of integers  in
  399. host_info.  The host may be specified by either the host port or the privileged
  400. host port.
  401.  
  402.   Basic information is defined by HOST_BASIC_INFO. The size of this information
  403. is defined by HOST_BASIC_INFO_COUNT.  Processor slots of the active (available)
  404. processors is defined by HOST_PROCESSOR_SLOTS.  The size  of  this  information
  405. should  be  obtained  from  the  max_cpus  field  of  the structure returned by
  406. HOST_BASIC_INFO.  Additional information of interest to schedulers  is  defined
  407. by   HOST_SCHED_INFO.   The   size   of   this   information   is   defined  by
  408. HOST_SCHED_INFO_COUNT.
  409.  
  410. Returns
  411.  
  412.   KERN_SUCCESS    The call succeeded.
  413.  
  414.   KERN_INVALID_ARGUMENT
  415.                   host is not a host or flavor is not recognized.
  416.  
  417.   MIG_ARRAY_TOO_LARGE
  418.                   Returned info array is too large for host_info. host_info  is
  419.                   filled  as  much  as  possible.    host_infoCnt is set to the
  420.                   number of elements that  would  be  returned  if  there  were
  421.                   enough room.
  422.  
  423. Notes
  424.  
  425.   Availability  limited.    Systems  without this call support a host_info call
  426. with an incompatible calling sequence.
  427.  
  428. See Also
  429.  
  430.   host_ports, host_kernel_version, host_processors, processor_info
  431. host_kernel_version
  432.  
  433. #include <mach.h>
  434.  
  435. kern_return_t host_kernel_version(host, version)
  436.         host_t host;
  437.         kernel_version_t *version;              /* out */
  438.  
  439.  
  440.  
  441. Arguments
  442.  
  443.   host            The host for which information is being  requested.    Either
  444.                   the host port or the privileged host port may be used.
  445.  
  446.   version         Character  string  describing the kernel version executing on
  447.                   host.
  448.  
  449. Description
  450.  
  451.   host_kernel_version returns the  version  string  compiled  into  the  kernel
  452. executing  on host at the time it was built.  This describes the version of the
  453. kernel.  The constant KERNEL_VERSION_MAX should be used  to  dimension  storage
  454. for the returned string if the kernel_version_t declaration is not used.
  455.  
  456. Returns
  457.  
  458.   KERN_SUCCESS    The call succeeded.
  459.  
  460.   KERN_INVALID_ARGUMENT
  461.                   host was not a host.
  462.  
  463.   KERN_INVALID_ADDRESS
  464.                   version points to inaccessible memory.
  465.  
  466. Notes
  467.  
  468.   Availability limited.
  469.  
  470. See Also
  471.  
  472.   host_info, host_processors, host_ports, processor_info
  473. processor_assign
  474.  
  475. #include <mach.h>
  476.  
  477. kern_return_t processor_assign(processor, processor_set, wait)
  478.         processor_t     processor;
  479.         processor_set_t processor_set;
  480.         boolean_t       wait;
  481.  
  482. kern_return_t processor_get_assignment(processor, assigned_set_name)
  483.         processor_t     processor;
  484.         processor_set_name_t assigned_set_name;
  485.  
  486.  
  487. Arguments
  488.  
  489.   processor       The processor to be assigned.
  490.  
  491.   processor_set   The processor set to assign it to.
  492.  
  493.   wait            Whether to wait for the assignment to complete.
  494.  
  495.   assigned_set_name
  496.                   Name port for  processor  set  that  processor  is  currently
  497.                   assigned to
  498.  
  499. Description
  500.  
  501.   processor_assign  assigns  processor to the the set processor_set.  After the
  502. assignment is completed, the processor only executes threads that are  assigned
  503. to  that processor set.  Any previous assignment of the processor is nullified.
  504. The  master  processor  cannot  be  reassigned.    All  processors  take  clock
  505. interrupts at all times.  The wait argument indicates whether the caller should
  506. wait  for  the  assignment  to  be  completed  or  should  return  immediately.
  507. Dedicated  kernel  threads are used to perform processor assignment, so setting
  508. wait to FALSE allows assignment requests to be  queued  and  performed  faster,
  509. especially  if  the  kernel  has  more  than  one dedicated internal thread for
  510. processor assignment.    Redirection  of  other  device  interrupts  away  from
  511. processors   assigned   to   other   than   the   default   processor   set  is
  512. machine-dependent.  Intermediaries that interpose on  ports  must  be  sure  to
  513. interpose on both ports involved in this call if they interpose on either.
  514.  
  515.   processor_get_assignment  Obtains the current assignment of a processor.  The
  516. name port of the processor set is returned.
  517.  
  518. Returns
  519.  
  520.   KERN_SUCCESS    The assignment has been performed.
  521.  
  522.   KERN_INVALID_ARGUMENT
  523.                   processor  is  not  a  processor,  or  processor_set is not a
  524.                   processor_set on the same host as processor.
  525.  
  526. Notes
  527.  
  528.   Availability limited.
  529.  
  530. See Also
  531.  
  532.   processor_set_create,   processor_set_info,    task_assign,    thread_assign,
  533. host_processor_set_priv
  534. processor_control
  535.  
  536. #include <mach.h>
  537.  
  538. kern_return_t processor_start(processor)
  539.         processor_t             processor;
  540.  
  541. kern_return_t processor_exit(processor)
  542.         processor_t             processor;
  543.  
  544. kern_return_t processor_control(processor, cmd, count)
  545.         processor_t             processor;
  546.         int                     *cmd;  /* array of ints */
  547.         int                     count;
  548.  
  549.  
  550. Arguments
  551.  
  552.   processor       Specifies the processor.
  553.  
  554.   cmd             Contains the command to be applied to the processor.
  555.  
  556.   count           Specifies the length of the command as a number of ints.
  557.  
  558. Description
  559.  
  560.   Some  multiprocessors  may  allow  privileged software to control processors.
  561. The processor_start, processor_exit, and processor_control operations implement
  562. this.   The interpretation of the command in cmd is machine dependent.  A newly
  563. started processor is  assigned  to  the  default  processor  set.    An  exited
  564. processor is removed from the processor set to which it was assigned and ceases
  565. to be active.
  566.  
  567. Returns
  568.  
  569.   KERN_SUCCESS    The operation was performed.
  570.  
  571.   KERN_FAILURE    The operation was not performed.  A likely reason is that  it
  572.                   is not supported on this processor.
  573.  
  574.   KERN_INVALID_ARGUMENT
  575.                   processor is not a processor.
  576.  
  577.   KERN_INVALID_ADDRESS
  578.                   data points to inaccessible memory.
  579.  
  580. See Also
  581.  
  582.   processor_info, host_processors
  583.  
  584. Notes
  585.  
  586.   Availability  limited.   All of these operations are machine-dependent.  They
  587. may  do  nothing.    The  ability  to  restart  an  exited  processor  is  also
  588. machine-dependent.
  589. processor_info
  590.  
  591. #include <mach.h>
  592.  
  593. /* the definition of processor_info_t from mach.h - sys/processor_info.h is */
  594.  
  595. typedef int     *processor_info_t;      /* variable length array of int */
  596.  
  597. /* one interpretation of info is */
  598.  
  599.    struct processor_basic_info {
  600.         cpu_type_t      cpu_type;       /* cpu type */
  601.         cpu_subtype_t   cpu_subtype;    /* cpu subtype */
  602.         boolean_t       running;        /* is processor running? */
  603.         int             slot_num;       /* slot number */
  604.         boolean_t       is_master;      /* is this the master processor */
  605.    };
  606. typedef struct processor_basic_info             *processor_basic_info_t;
  607.  
  608.  
  609.  
  610. kern_return_t
  611. processor_info(processor, flavor, host, processor_info, processor_infoCnt)
  612.         processor_t             processor;
  613.         int                     flavor;
  614.         host_t                  *host;
  615.         processor_info_t        processor_info; /* in and out */
  616.         unsigned int            *processor_infoCnt;     /* in and out */
  617.  
  618.  
  619. Arguments
  620.  
  621.   processor       The processor for which information is to be obtained
  622.  
  623.   flavor          The  type  of  information  that  is  wanted.  Currently only
  624.                   PROCESSOR_BASIC_INFO is implemented.
  625.  
  626.   host            The host on  which  the  processor  resides.    This  is  the
  627.                   non-privileged host port.
  628.  
  629.   processor_info  Information about the processor specified by processor.
  630.  
  631.   processor_infoCnt
  632.                   Size     of     the     info     structure.     Should     be
  633.                   PROCESSOR_BASIC_INFO_COUNT for flavor PROCESSOR_BASIC_INFO.
  634.  
  635. Description
  636.  
  637.   Returns  the  selected  information  array  for  a processor, as specified by
  638. flavor. processor_info is an array of integers that is supplied by the  caller,
  639. and  filled  with  specified information.  processor_infoCnt is supplied as the
  640. maximum number of integers in processor_info. On return, it contains the actual
  641. number of integers in processor_info.
  642.  
  643.   Basic  information  is  defined  by  PROCESSOR_BASIC_INFO.   The size of this
  644. information is defined by PROCESSOR_BASIC_INFO_COUNT.  Machines  which  require
  645. more  configuration  information  beyond the slot number are expected to define
  646. additional (machine-dependent) flavors.
  647.  
  648. Returns
  649.  
  650.   KERN_SUCCESS    The call succeeded.
  651.  
  652.   KERN_INVALID_ARGUMENT
  653.                   processor is not a processor or flavor is not recognized.
  654.  
  655.   MIG_ARRAY_TOO_LARGE
  656.                   Returned  info  array  is  too  large   for   processor_info.
  657.                   processor_info    is    filled    as    much   as   possible.
  658.                   processor_infoCnt is set to the number of elements that would
  659.                   be returned if there were enough room.
  660.  
  661. Notes
  662.  
  663.   Availability limited.
  664.  
  665. See Also
  666.  
  667.   processor_start, processor_exit, processor_control, host_processors host_info
  668. processor_set_create
  669.  
  670. #include <mach.h>
  671.  
  672. kern_return_t processor_set_create(host, new_set, new_name)
  673.         host_t                  host;
  674.         processor_set_t         *new_set;
  675.         processor_set_name_t    *new_name;
  676.  
  677.  
  678. Arguments
  679.  
  680.   host            The  host  on which the new set is to be created.  Either the
  681.                   host port or the privileged host port may be used.
  682.  
  683.   new_set         Port used for performing operations on the new set.
  684.  
  685.   new_name        Port used to identify the  new  set  and  obtain  information
  686.                   about it.
  687.  
  688. Description
  689.  
  690.   processor_set_create  creates  a  new processor set and returns the two ports
  691. associated with  it.    The  port  returned  in  new_set  is  the  actual  port
  692. representing  the  set.    It  is  used to perform operations such as assigning
  693. processors, tasks, or threads.  The port returned in  new_name  identifies  the
  694. set, and is used to obtain information about the set.
  695.  
  696. Returns
  697.  
  698.   KERN_SUCCESS    The call succeeded.
  699.  
  700.   KERN_INVALID_ARGUMENT
  701.                   host was not a host.
  702.  
  703.   KERN_INVALID_ADDRESS
  704.                   new_set and/or new_name point to inaccessible memory.
  705.  
  706.   KERN_FAILURE    The operating system does not support processor allocation.
  707.  
  708. Notes
  709.  
  710.   Availability limited.
  711.  
  712. See Also
  713.  
  714.   processor_set_destroy,   processor_set_info,  processor_assign,  task_assign,
  715. thread_assign
  716. processor_set_default
  717.  
  718. #include <mach.h>
  719.  
  720. kern_return_t processor_set_default(host, default_set);
  721.         host_t                  host;
  722.         processor_set_t         *default_set;
  723.  
  724.  
  725.  
  726. Arguments
  727.  
  728.   host            Specifies the host whose default processor set is  requested.
  729.                   Either the host port or the privileged host port may be used.
  730.  
  731.   default_set     Returns the name port for the default processor set.
  732.  
  733. Description
  734.  
  735.   The  default processor set is used by all threads, tasks, and processors that
  736. are not explicitly assigned to other sets. processor_set_default returns a port
  737. that  can  be  used to obtain information about this set (e.g. how many threads
  738. are assigned to it).  This port cannot be used to perform  operations  on  that
  739. set.
  740.  
  741. Notes
  742.  
  743.   Availability limited.
  744.  
  745. See Also
  746.  
  747.   processor_set_info, thread_assign, task_assign
  748. processor_set_destroy
  749.  
  750. #include <mach.h>
  751.  
  752. kern_return_t processor_set_destroy(processor_set)
  753.         processor_set_t         processor_set;
  754.  
  755.  
  756.  
  757.  
  758. Arguments
  759.  
  760.   processor_set   Specifies the processor_set to be exited.
  761.  
  762. Description
  763.  
  764.   Destroys  the  specified  processor  set.  Any assigned processors, tasks, or
  765. threads are reassigned to the default set.  The object port for  the  processor
  766. set  is  required  (not  the  name  port).  The default processor set cannot be
  767. destroyed.
  768.  
  769. Returns
  770.  
  771.   KERN_SUCCESS    The set was destroyed.
  772.  
  773.   KERN_FAILURE    An attempt was made to destroy the default processor set,  or
  774.                   the operating system does not support processor allocation.
  775.  
  776.   KERN_INVALID_ARGUMENT
  777.                   processor_set is not a processor set.
  778.  
  779. Notes
  780.  
  781.   Availability limited.
  782.  
  783. See Also
  784.  
  785.   processor_set_create, processor_assign, task_assign, thread_assign
  786. processor_set_info
  787.  
  788. #include <mach.h>
  789.  
  790. /* the definition of processor_set_info_ from mach/processor_info.h  */
  791.  
  792. typedef int     *processor_set_info_t;  /* variable length array of int */
  793.  
  794. /* one interpretation of info is */
  795.  
  796.    struct processor_set_basic_info {
  797.         int             processor_count;        /* number of processors */
  798.         int             task_count;             /* number of tasks */
  799.         int             thread_count;           /* number of threads */
  800.         int             load_average;           /* scaled load average */
  801.         int             mach_factor;            /* scaled mach factor */
  802.    };
  803. typedef struct processor_set_basic_info         *processor_set_basic_info_t;
  804.  
  805. /* another interpretation of info is */
  806.  
  807. struct processor_set_sched_info {
  808.         int             policies;       /* allowed policies */
  809.         int             max_priority;   /* max priority for new threads */
  810. };
  811.  
  812. typedef struct processor_set_sched_info *processor_set_sched_info_t;
  813.  
  814.  
  815. kern_return_t
  816. processor_set_info(processor_set, flavor, host, processor_set_info,
  817.     processor_set_infoCnt)
  818.         processor_set_name_t    processor_set;
  819.         int                     flavor;
  820.         host_t                  *host;
  821.         processor_set_info_t    processor_set_info;     /* in and out */
  822.         unsigned int            *processor_set_infoCnt; /* in and out */
  823.  
  824.  
  825.  
  826. Arguments
  827.  
  828.   processor_set   The processor_set for which information is  to  be  obtained.
  829.                   Either  the  processor  set  name  port  or the processor set
  830.                   control port may be used.
  831.  
  832.   flavor          The type of information that is wanted.
  833.  
  834.   host            The host on which the processor set resides.    This  is  the
  835.                   non-privileged host port.
  836.  
  837.   processor_set_info
  838.                   Information   about   the   processor   set   specified    by
  839.                   processor_set.
  840.  
  841.   processor_set_infoCnt
  842.                   Size     of     the     info     structure.     Should     be
  843.                   PROCESSOR_SET_BASIC_INFO_COUNT           for           flavor
  844.                   PROCESSOR_SET_BASIC_INFO , and PROCESSOR_SET_SCHED_INFO_COUNT
  845.                   for flavor PROCESSOR_SET_SCHED_INFO.
  846.  
  847. Description
  848.  
  849.   Returns  the  selected information array for a processor_set, as specified by
  850. flavor. processor_set_info is an array of integers  that  is  supplied  by  the
  851. caller,  and  filled  with  specified  information.    processor_set_infoCnt is
  852. supplied as the maximum number of integers in processor_set_info. On return, it
  853. contains the actual number of integers in processor_set_info.
  854.  
  855.   Basic  information  is defined by PROCESSOR_SET_BASIC_INFO.  The size of this
  856. information is defined by PROCESSOR_SET_BASIC_INFO_COUNT. The load_average  and
  857. mach_factor  arguments  are scaled by the constant LOAD_SCALE (i.e. the integer
  858. value returned is the actual value multiplied by LOAD_SCALE.
  859.  
  860.   Scheduling information is defined by PROCESSOR_SET_SCHED_INFO.  The  size  of
  861. this information is given by PROCESSOR_SET_SCHED_INFO_COUNT.  Some machines may
  862. define machine-dependent information flavors.
  863.  
  864. Returns
  865.  
  866.   KERN_SUCCESS    The call succeeded.
  867.  
  868.   KERN_INVALID_ARGUMENT
  869.                   processor_set  is  not  a  processor  set  or  flavor  is not
  870.                   recognized.
  871.  
  872.   MIG_ARRAY_TOO_LARGE
  873.                   Returned  info  array  is  too  large for processor_set_info.
  874.                   processor_set_info   is   filled   as   much   as   possible.
  875.                   processor_set_infoCnt  is  set to the number of elements that
  876.                   would be returned if there were enough room.
  877.  
  878. Notes
  879.  
  880.   Availability limited.
  881.  
  882. See Also
  883.  
  884.   processor_set_create, processor_set_default,  processor_assign,  task_assign,
  885. thread_assign
  886. processor_set_tasks
  887.  
  888. #include <mach.h>
  889.  
  890. kern_return_t processor_set_tasks(processor_set, task_list, task_count)
  891.         processor_set_t processor_set;
  892.         task_array_t    *task_list;     /* out, ptr to array */
  893.         int             *task_count;    /* out */
  894.  
  895.  
  896. Arguments
  897.  
  898.   processor_set   The processor_set to be affected.
  899.  
  900.   task_list       The  set  of  tasks  currently  assigned to processor_set; no
  901.                   particular ordering is guaranteed.
  902.  
  903.   task_count      The number of tasks in the task_list.
  904.  
  905. Description
  906.  
  907.   processor_set_tasks gets send  rights  to  the  kernel  port  for  each  task
  908. currently assigned to processor_set. task_list is an array that is created as a
  909. result of this call. The caller may wish to vm_deallocate this array  when  the
  910. data is no longer needed.
  911.  
  912. Returns
  913.  
  914.   KERN_SUCCESS    The call succeeded.
  915.  
  916.   KERN_INVALID_ARGUMENT
  917.                   processor_set is not a processor_set.
  918.  
  919. Notes
  920.  
  921.   Availability limited.
  922.  
  923. See Also
  924.  
  925.   task_assign, thread_assign, processor_set_threads
  926. processor_set_threads
  927.  
  928. #include <mach.h>
  929.  
  930. kern_return_t processor_set_threads(processor_set, thread_list, thread_count)
  931.         processor_set_t processor_set;
  932.         thread_array_t  *thread_list;   /* out, ptr to array */
  933.         int             *thread_count;  /* out */
  934.  
  935.  
  936. Arguments
  937.  
  938.   processor_set   The processor_set to be affected.
  939.  
  940.   thread_list     The set of threads currently assigned  to  processor_set;  no
  941.                   particular ordering is guaranteed.
  942.  
  943.   thread_count    The number of threads in the thread_list.
  944.  
  945. Description
  946.  
  947.   processor_set_threads  gets  send  rights  to the kernel port for each thread
  948. currently assigned to processor_set.  thread_list is an array that  is  created
  949. as  a result of this call. The caller may wish to vm_deallocate this array when
  950. the data is no longer needed.
  951.  
  952. Returns
  953.  
  954.   KERN_SUCCESS    The call succeeded.
  955.  
  956.   KERN_INVALID_ARGUMENT
  957.                   processor_set is not a processor_set.
  958.  
  959. Notes
  960.  
  961.   Availability limited.
  962.  
  963. See Also
  964.  
  965.   thread_assign, thread_assign, processor_set_threads
  966. task_assign
  967.  
  968. #include <mach.h>
  969.  
  970. kern_return_t
  971. task_assign(task, processor_set, assign_threads)
  972.         task_t task;
  973.         processor_set_t processor_set;
  974.         boolean_t       assign_threads;
  975.  
  976. kern_return_t
  977. task_assign_default(task, assign_threads)
  978.         task_t          task;
  979.         boolean_t       assign_threads;
  980.  
  981. kern_return_t
  982. task_get_assignment(task, processor_set)
  983.         task_t          task;
  984.         processor_set_name_t    *processor_set;
  985.  
  986.  
  987. Arguments
  988.  
  989.   task            The task to be affected.
  990.  
  991.   processor_set   The  processor  set  to assign it to, or the processor set to
  992.                   which it is assigned.
  993.  
  994.   assign_threads  Boolean  indicating  whether  this  assignment   applies   to
  995.                   existing threads in the task.
  996.  
  997. Description
  998.  
  999.   task_assign  assigns  task the the set processor_set.  This assignment is for
  1000. the purposes of determining the initial assignment of newly created threads  in
  1001. task.  Any  previous  assignment  of  the  task is nullified.  Existing threads
  1002. within the task are also reassigned if assign_threads is TRUE.   They  are  not
  1003. affected if it is FALSE.
  1004.  
  1005.   task_assign_default  is a variant of task_assign that assigns the task to the
  1006. default processor set on that task's host.  This  variant  exists  because  the
  1007. control  port  for  the  default  processor  set is privileged and not ususally
  1008. available to users.
  1009.  
  1010.   task_get_assignment returns the current assignment of the task.
  1011.  
  1012. Returns
  1013.  
  1014.   KERN_SUCCESS    The assignment has been performed.
  1015.  
  1016.   KERN_INVALID_ARGUMENT
  1017.                   task  is  not a task, or processor_set is not a processor_set
  1018.                   on the same host as task.
  1019.  
  1020. Notes
  1021.  
  1022.   Availability limited
  1023.  
  1024. See Also
  1025.  
  1026.   processor_set_create,  processor_set_info,  processor_assign,  thread_assign,
  1027. host_processor_set_priv
  1028. thread_assign
  1029.  
  1030. #include <mach.h>
  1031.  
  1032. kern_return_t thread_assign(thread, processor_set)
  1033.         thread_t        thread;
  1034.         processor_set_t processor_set;
  1035.  
  1036. kern_return_t thread_assign_default(thread)
  1037.         thread_t        thread;
  1038.  
  1039. kern_return_t thread_get_assignment(thread, processor_set)
  1040.         thread_t                thread;
  1041.         processor_set_name_t    *processor_set;
  1042.  
  1043.  
  1044.  
  1045. Arguments
  1046.  
  1047.   thread          The thread to be assigned.
  1048.  
  1049.   processor_set   The processor set to assign it to.
  1050.  
  1051. Description
  1052.  
  1053.   thread_assign assigns thread the the set processor_set.  After the assignment
  1054. is completed, the thread only executes on processors assigned to the designated
  1055. processor  set.   If there are no such processors, then the thread is unable to
  1056. execute.  Any previous assignment of the thread is nullified.  Unix system call
  1057. compatibility  code  may  temporarily  force  threads  to execute on the master
  1058. processor.
  1059.  
  1060.   thread_assign_default is a variant of thread_assign that assigns  the  thread
  1061. to the default processor set.  This variant exists because the control port for
  1062. the default processor set is privileged and therefore  not  available  to  most
  1063. users.
  1064.  
  1065.   thread_get_assignment  returns  the  name  of  the processor set to which the
  1066. thread is currently assigned.  This port can only be used to obtain information
  1067. about the processor set.
  1068.  
  1069. Returns
  1070.  
  1071.   KERN_SUCCESS    The assignment has been performed.
  1072.  
  1073.   KERN_INVALID_ARGUMENT
  1074.                   thread  is  not  a  thread,  or  processor_set   is   not   a
  1075.                   processor_set on the same host as thread.
  1076.  
  1077.   KERN_INVALID_ADDRESS
  1078.                   processor_set     points     to      inaccessible      memory
  1079.                   (thread_get_assignment only).
  1080.  
  1081. Notes
  1082.  
  1083.   Availability limited.
  1084.  
  1085. See Also
  1086.  
  1087.   processor_set_create,   processor_set_info,   processor_assign,  task_assign,
  1088. host_processor_set_priv
  1089. 2. Scheduling primitives
  1090.  
  1091.  
  1092.  
  1093. 2.1. Introduction
  1094.   This section of the manual describes primitives that control three aspects of
  1095. thread scheduling.
  1096.  
  1097.    1. Priority   -  These  primitives  export  priorities  for  individual
  1098.       threads.  The notion of scheduling  policies  is  introduced,  along
  1099.       with support for fixed-priority threads.  threads.
  1100.  
  1101.    2. Handoff  -  Handoff  Scheduling  (specify  thread  to  run next) and
  1102.       related mechanisms.
  1103.  
  1104.    3. Wiring - Lock data and threads into memory  to  prevent  paging  and
  1105.       swapping.
  1106.  
  1107.   The  priority  primitives  are  connected  with  the  processor set managment
  1108. primitives and rely on presentation of processor set control ports  to  enforce
  1109. protection.  The overriding model is that a task that has rights to a processor
  1110. set control  port  may  exercise  complete  control  over  scheduling  on  that
  1111. processor set.
  1112.  
  1113.  
  1114.  
  1115. 2.2. Priority
  1116.   The priority primitives:
  1117.  
  1118.    1. Export priorities for individual threads to users.
  1119.  
  1120.    2. Support fixed priorities for real-time and other uses.
  1121.  
  1122.    3. Produce a clean interface for users as well as kernel clients.
  1123.  
  1124. Threads  have  both  a priority and a maximum priority:  priority cannot exceed
  1125. maximum priority, but the maximum priority  can  be  reset  by  presenting  the
  1126. appropriate  processor_set  object  port.    Since  the default processor set's
  1127. object port is privileged, ordinary users who do not  do  their  own  processor
  1128. allocation  cannot raise thread priorities above their initial maximum. Initial
  1129. priority is inherited from the task at creation (of both  threads  and  tasks),
  1130. and  the initial maximum priority is inherited from the processor set at thread
  1131. creation.
  1132.  
  1133.   Scheduling  policy  can  be  set  on  a  per  thread   basis;   the   current
  1134. implementation  has  two  policies, time sharing and fixed priority.  For fixed
  1135. priority, a quantum can be specified (again on a per thread basis); this is the
  1136. quantum  that  the  thread will receive before being eligible for preemption at
  1137. the same priority.  A processor set may forbid scheduling policies  other  than
  1138. time sharing.
  1139.  
  1140.   The ranges of priority correspond to scheduler internals, but Unix interfaces
  1141. will continue to deal with Unix  priorities.    Two  notions  of  priority  are
  1142. supported;  a base priority and a scheduled priority.  The base priority ranges
  1143. from 0 to 31 and is the  priority  assigned  to  the  thread  by  the  user  or
  1144. user-mode  scheduler.    The  scheduled priority also has the same range; it is
  1145. identical to the base priority for fixed priority threads, but for  timesharing
  1146. threads  it  is  the  base priority plus some increment derived from usage.  In
  1147. both cases low numbers are  the  highest  priorities.    The  traditional  Unix
  1148. priority  (range  0-127)  can  be  obtained  from these numbers (range 0-31) by
  1149. multiplying by 4.
  1150.  
  1151.   Preemption normally occurs  when  a  thread  becomes  runnable  at  a  higher
  1152. priority  than  a  currently running thread and there are no idle processors in
  1153. the processor set.   It  may  take  as  long  as  a  (machine-dependent)  clock
  1154. interrupt  period  for  a  multiprocessor  kernel  to notice that preemption is
  1155. needed (interprocessor interrupts are not used for preemption events).    There
  1156. is  one  major  exception  to  this rule that delays preemption of time-sharing
  1157. threads.  The reason for this is that time-sharing threads have their  priority
  1158. recalculated  as  they run; if these new priorities were always put into effect
  1159. immediately, the result would be additional (unneeded) context  switches.    To
  1160. avoid  this,  running  timesharing threads usually delay preemption due to this
  1161. priority recalculation until the end of their current quantum  (typically  1/10
  1162. of a second).
  1163.  
  1164.   The  policy  for  threads defaults to time sharing in the absence of explicit
  1165. specification.   Similarly,  processor  sets  default  to  only  allowing  time
  1166. sharing.
  1167.  
  1168.   I/O  drivers  may  prioritize  requests  placed  by  fixed  priority  threads
  1169. according to the priorities of the threads; this behavior is machine-dependent.
  1170. Any  such  prioritizing  applies  only  to  I/O explicitly requested by a fixed
  1171. priority thread; implicit I/O  (e.g.  that  requested  by  an  external  memory
  1172. manager on behalf of a thread) will only be prioritized according to the thread
  1173. that actually requested it (e.g. the thread in the  external  memory  manager).
  1174. As  a  result, systems that care about the priority of implicitly requested I/O
  1175. should provide their own external memory managers to perform  that  I/O.    The
  1176. notion  of  priority  may  not  be meaningful to some potential future policies
  1177. (e.g. round-robin).
  1178.  
  1179.   The timesharing  policy  must  be  allowed  to  simplify  the  semantics  and
  1180. implementation  of  the  thread  and  task  assign operations.  Assignment of a
  1181. thread whose policy is forbidden by the target processor set succeeds, but  its
  1182. policy  is reset to timesharing; the policy for newly created threads similarly
  1183. defaults to timesharing.  This avoids the need to introduce a notion of default
  1184. policy  for  processor  sets  and  the additional logic needed to make sure the
  1185. default policy is permitted and at least one policy is permitted at all  times.
  1186. Timesharing  can still be avoided on user-created and managed processor sets by
  1187. resetting the  thread's  policy  after  creation  or  assignment;  a  real-time
  1188. scheduler will surely want to do this in any case.
  1189.  
  1190.   When a thread is assigned to a processor set, its priorities (both actual and
  1191. max) will be reduced if either is above the target set's maximum priority.   In
  1192. addition  its  scheduling  policy  will  be reset to time sharing if the target
  1193. processor set does not permit its current policy.  Default values  of  priority
  1194. and max priority are 12 for historical reasons.
  1195.  
  1196.   processor_set_max_priority  may be used as a boot-time mechanism to clear out
  1197. high-level priorities for a real-time subsystem by indicating the  max_priority
  1198. for time sharing threads and setting change_threads to TRUE.
  1199.  
  1200.  
  1201.  
  1202. 2.3. Handoff Scheduling
  1203.   Handoff scheduling refers to the technique of transferring the processor from
  1204. one thread to another with as little operating system involvement as  possible.
  1205. The  kernel  already  uses this technique for message operations. The primitive
  1206. thread_switch makes it and related operations available to  the  user.    These
  1207. primitives  allow  the  user to take advantage of knowledge about which threads
  1208. should or should not be run to influence operating system scheduling  decisions
  1209. without requiring the user to write a complete scheduler.
  1210.  
  1211.   This  call  is  independent  of  the  priority  manipulation  calls; they are
  1212. motivated  by  situations  encountered  in  doing  locking  on  multiprogrammed
  1213. systems.  thread_switch is a trap that operates on the thread that invokes it.
  1214.  
  1215.   Two options to thread_switch are supported:
  1216.  
  1217.    1. WAIT  - option_time is a time period during which the current thread
  1218.       should be suspended internally.  An internal mechanism will be  used
  1219.       that  cannot be released by thread_resume; thread_abort must be used
  1220.       to abort this wait. This option is designed for situations in  which
  1221.       there  is  a significant minimum time for which the thread should be
  1222.       blocked.
  1223.  
  1224.    2. DEPRESS - option_time is a  time_period  during  which  the  current
  1225.       thread's  priority  should  be reduced to the lowest possible value.
  1226.       Priority is restored by expiration of  the  timeout,  the  scheduler
  1227.       choosing  to  run  the  thread  again,  or  a  call to thread_abort.
  1228.       Experience with  parallel  applications  at  CMU  indicates  that  a
  1229.       primitive  that only context switches (and implicitly surrenders the
  1230.       remainder of the quantum) is not sufficient; two threads  performing
  1231.       this  operation  can  hog  the processor to the exclusion of threads
  1232.       that should run.  It is necessary to severely depress  the  priority
  1233.       of the threads that should not be run so that the other threads will
  1234.       be run even if their priority is below that of the  waiting  threads
  1235.       due to actions of the timesharing scheduler.  The advantage of using
  1236.       depression over blocking is that an explicit  unblock  operation  is
  1237.       not  needed  to  resume  the  thread  before  the  timeout  expires.
  1238.       Implementors should be warned that large number of threads  spinning
  1239.       through  thread_switch  or thread_switch with the DEPRESS option can
  1240.       effectively thrash a multiprocessor scheduler.
  1241.  
  1242.   The specification of the next thread to run is designed to handle  situations
  1243. in  which  the user is keeping explicit or implicit scheduling information that
  1244. can be taken advantage of by the kernel.  An example of explicit information is
  1245. tagging  locks with the identity of the thread that holds them (this is easy to
  1246. do if the hardware supports an atomic compare and swap if  0  operation).    An
  1247. example  of  implicit information is that in a functionally partitioned program
  1248. with one thread per component, knowing the component that is being  waited  for
  1249. immediately identified the thread that should run.
  1250.  
  1251.   The current quantum is transferred to the new thread by thread_switch only if
  1252. both thread and new_thread are time-sharing threads.  If  either  or  both  are
  1253. fixed-priority threads, the new_thread gets a new quantum.
  1254.  
  1255.   Fixed  priority  threads do not get special treatment for any of these calls.
  1256. This means that thread_switch  will  run  the  new  thread  regardless  of  its
  1257. priority, and can be used to implement the implicit priority elevation required
  1258. when a critical section is accessed by both  low  and  high  priority  threads.
  1259. Similarly,  the  calls  involving  depression operate identically on both fixed
  1260. priority and time sharing threads.
  1261.  
  1262.  
  1263.  
  1264. 2.4. Wiring
  1265.   There are two wiring primitives: vm_wire and thread_wire.  vm_wire allows the
  1266. user to keep memory from pagefaulting on specified types of access. thread_wire
  1267. causes a thread's internal kernel state to be non-pageable so that thread  will
  1268. always be able to execute immediately when run. The system has an overall limit
  1269. on wired down memory; these calls fail if the  requested  wiring  would  exceed
  1270. that limit.
  1271.  
  1272.   NOTE: These calls have not been implemented yet.
  1273. task_priority
  1274.  
  1275. #include <mach.h>
  1276.  
  1277. kern_return_t task_priority(task, priority, change_threads)
  1278.         task_t          task;
  1279.         int             priority;
  1280.         boolean_t       change_threads;
  1281.  
  1282.  
  1283.  
  1284. Arguments
  1285.  
  1286.   task            Task to set priority for.
  1287.  
  1288.   priority        New priority.
  1289.  
  1290.   change_threads  Change priority of existing threads if TRUE.
  1291.  
  1292. Description
  1293.  
  1294.   The  priority  of  a  task  is  used  only for creation of new threads; a new
  1295. thread's priority is  set  to  the  enclosing  task's  priority.  task_priority
  1296. changes  this task priority.  It also sets the priorities of all threads in the
  1297. task to this new priority if change_threads is TRUE.  Existing threads are  not
  1298. affected  otherwise.   If this priority change violates the maximum priority of
  1299. some threads, as many threads as possible will be changed  and  an  error  code
  1300. will be returned.
  1301.  
  1302. Returns
  1303.  
  1304.   KERN_SUCCESS    The call succeeded.
  1305.  
  1306.   KERN_INVALID_ARGUMENT
  1307.                   task is not a task, or priority is not a valid priority.
  1308.  
  1309.   KERN_FAILURE    change_threads  was  TRUE  and  the  attempt  to  change  the
  1310.                   priority  of  at least one existing thread failed because the
  1311.                   new  priority  would  have  exceeded  that  thread's  maximum
  1312.                   priority.
  1313.  
  1314. Notes
  1315.  
  1316.   Availability limited.
  1317.  
  1318. See Also
  1319.  
  1320.   thread_priority, processor_set_max_priority
  1321. thread_priority
  1322.  
  1323. #include <mach.h>
  1324.  
  1325. kern_return_t thread_priority(thread, priority, set_max)
  1326.         thread_t        thread;
  1327.         int             priority;
  1328.         boolean_t       set_max
  1329.  
  1330. kern_return_t thread_max_priority(thread, processor_set, priority)
  1331.         thread_t        thread;
  1332.         processor_set_t processor_set;
  1333.         int             priority;
  1334.  
  1335.  
  1336. Arguments
  1337.  
  1338.   thread          The thread whose priority is to be changed.
  1339.  
  1340.   priority        The new priority to change it to.
  1341.  
  1342.   set_max         Also set thread's maximum priority if TRUE.
  1343.  
  1344.   processor_set   The control port for the processor set to which the thread is
  1345.                   currently assigned.
  1346.  
  1347. Description
  1348.  
  1349.   Threads have three priorities associated with them by the system, a priority,
  1350. a  maximum  priority, and a scheduled priority.  The scheduled priority is used
  1351. to make scheduling decisions about the thread.    It  is  determined  from  the
  1352. priority by the policy (for timesharing, this means adding an increment derived
  1353. from cpu usage).  The priority can be set under user  control,  but  may  never
  1354. exceed   the   maximum  priority.    Changing  the  maximum  priority  requires
  1355. presentation of the control port for the  thread's  processor  set;  since  the
  1356. control  port  for  the default processor set is privileged, users cannot raise
  1357. their maximum priority to unfairly compete with other users on that set.  Newly
  1358. created  threads  obtain  their priority from their task and their max priority
  1359. from the thread.
  1360.  
  1361.   thread_priority changes the priority and optionally the maximum  priority  of
  1362. thread.  Priorities  range  from  0  to  31,  where lower numbers denote higher
  1363. priorities.  If the new priority is higher than the  priority  of  the  current
  1364. thread, preemption may occur as a result of this call.  The maximum priority of
  1365. the thread is also set if set_max is TRUE.  This call will fail if priority  is
  1366. greater  than  the  current  maximum priority of the thread.  As a result, this
  1367. call can only lower the value of a thread's maximum priority.
  1368.  
  1369.   thread_max_priority changes the maximum priority of the thread.   Because  it
  1370. requires  presentation  of  the corresponding processor set port, this call can
  1371. reset the maximum priority to any legal value.
  1372.  
  1373. Returns
  1374.  
  1375.   KERN_SUCCESS    Operation completed successfully
  1376.  
  1377.   KERN_INVALID_ARGUMENT
  1378.                   thread  is  not  a  thread, or processor_set is not a control
  1379.                   port for a processor set, or priority is out of range (not in
  1380.                   0..31).
  1381.  
  1382.   KERN_FAILURE    The  requested  operation  would violate the thread's maximum
  1383.                   priority (thread_priority) or the thread is not  assigned  to
  1384.                   the processor set whose control port was presented.
  1385.  
  1386. Notes
  1387.  
  1388.   Availability limited.
  1389.  
  1390. See Also
  1391.  
  1392.   thread_policy, task_priority, processor_set_priority
  1393. thread_policy
  1394.  
  1395. #include <mach.h>
  1396.  
  1397. kern_return_t thread_policy(thread, policy, data)
  1398.         thread_t        thread;
  1399.         int             policy;
  1400.         int             data;
  1401.  
  1402.  
  1403. Arguments
  1404.  
  1405.   thread          Thread to set policy for.
  1406.  
  1407.   policy          Policy to set.
  1408.  
  1409.   data            Policy-specific data.
  1410.  
  1411. Description
  1412.  
  1413.   thread_policy  changes  the  scheduling  policy for thread to policy. data is
  1414. policy-dependent scheduling information.  There  are  currently  two  supported
  1415. policies: POLICY_TIMESHARE and POLICY_FIXEDPRI defined in <mach/policy.h>; this
  1416. file is included by mach.h.  data is meaningless for timesharing,  but  is  the
  1417. quantum  to  be  used  (in  milliseconds) for the fixed priority policy.  To be
  1418. meaningful, this quantum must  be  a  multiple  of  the  basic  system  quantum
  1419. (min_quantum)  which  can  be  obtained from host_info.  The system will always
  1420. round up to the next multiple of the quantum.
  1421.  
  1422.   Processor sets may restrict the allowed policies, so this call will  fail  if
  1423. the processor set to which thread is currently assigned does not permit policy.
  1424.  
  1425. Returns
  1426.  
  1427.   KERN_SUCCESS    The call succeeded.
  1428.  
  1429.   KERN_INVALID_ARGUMENT
  1430.                   thread is not a thread, or policy is not a recognized policy.
  1431.  
  1432.   KERN_FAILURE    The processor set to which thread is currently assigned  does
  1433.                   not permit policy.
  1434.  
  1435. Notes
  1436.  
  1437.   Availability limited.  Fixed priority not supported on all systems.
  1438.  
  1439. See Also
  1440.  
  1441.   task_policy, processor_set_policy, host_info
  1442. processor_set_max_priority
  1443.  
  1444. #include <mach.h>
  1445.  
  1446. kern_return_t
  1447. processor_set_max_priority(processor_set, priority, change_threads)
  1448.         processor_set_t         task;
  1449.         int                     priority;
  1450.         boolean_t               change_threads;
  1451.  
  1452.  
  1453. Arguments
  1454.  
  1455.   processor_set   Processor set to set maximum priority for.
  1456.  
  1457.   priority        New priority.
  1458.  
  1459.   change_threads  Change maximum priority of existing threads if TRUE.
  1460.  
  1461. Description
  1462.  
  1463.   The  priority  of  a  processor  set  is  used only for newly created threads
  1464. (thread's maximum priority is set to processor set's)  and  the  assignment  of
  1465. threads  to  the  set  (thread's  maximum priority is reduced if it exceeds the
  1466. set's   maximum   priority,   thread's   priority   is   similarly    reduced).
  1467. processor_set_max_priority  changes  this  priority.   It also sets the maximum
  1468. priority of all threads assigned to the processor set to this new  priority  if
  1469. change_threads  is  TRUE.  If this maximum priority is less than the priorities
  1470. of any of these threads, their priorities will also be set to this new value.
  1471.  
  1472. Returns
  1473.  
  1474.   KERN_SUCCESS    The call succeeded.
  1475.  
  1476.   KERN_INVALID_ARGUMENT
  1477.                   task is not a task, or priority is not a valid priority.
  1478.  
  1479. Notes
  1480.  
  1481.   Availability limited.  This call was referred to as processor_set_priority in
  1482. some previous documentation.
  1483.  
  1484. See Also
  1485.  
  1486.   thread_priority, task_priority, thread_assign
  1487. processor_set_policy_enable
  1488.  
  1489. #include <mach.h>
  1490.  
  1491. kern_return_t
  1492. processor_set_policy_enable(processor_set, policy)
  1493.         processor_set_t processor_set;
  1494.         int             policy;
  1495.  
  1496. kern_return_t
  1497. processor_set_policy_disable(processor_set, policy, change_threads)
  1498.         thread_t        thread;
  1499.         processor_set_t processor_set;
  1500.         int             change_threads;
  1501.  
  1502.  
  1503.  
  1504.  
  1505. Arguments
  1506.  
  1507.   processor_set   The processor set whose allowed policies are to be changed.
  1508.  
  1509.   policy          The policy to enable or disable
  1510.  
  1511.   change_threads  Reset the policies of any threads with  the  newly-disallowed
  1512.                   policy to timesharing.
  1513.  
  1514. Description
  1515.  
  1516.   Processor  sets  may  restrict the scheduling policies to be used for threads
  1517. assigned to them.  These  two  calls  provide  the  mechanism  for  designating
  1518. permitted and forbidden policies.  The current set of permitted policies can be
  1519. obtained from processor_set_info.  Timesharing may  not  be  forbidden  by  any
  1520. processor_set.    This  is  a compromise to reduce the complexity of the assign
  1521. operation; any thread whose policy is forbidden by the target processor set has
  1522. its   policy   reset  to  timesharing.    If  the  change_threads  argument  to
  1523. processor_set_policy_disable  is  true,  threads  currently  assigned  to  this
  1524. processor  set and using the newly disabled policy will have their policy reset
  1525. to timesharing.
  1526.  
  1527.   <mach/policy.h> contains the allowed policies; it is included by mach.h.
  1528.  
  1529. Returns
  1530.  
  1531.   KERN_SUCCESS    Operation completed successfully
  1532.  
  1533.   KERN_INVALID_ARGUMENT
  1534.                   processor_set  is  not  a  processor  set, or policy is not a
  1535.                   valid policy, or an attempt was made to disable timesharing.
  1536.  
  1537. Notes
  1538.  
  1539.   Availability limited.  Not all policies (e.g. fixed priority)  are  supported
  1540. by all systems.
  1541.  
  1542. See Also
  1543.  
  1544.   thread_policy, task_policy
  1545. thread_switch
  1546.  
  1547. #include <mach.h>
  1548.  
  1549. kern_return_t thread_switch(new_thread, option, time)
  1550.         thread_t        new_thread;
  1551.         int             option;
  1552.         int             time;
  1553.  
  1554.  
  1555. Arguments
  1556.  
  1557.   new_thread      Thread to context switch to.
  1558.  
  1559.   option          Specifies options associated with context switch.
  1560.  
  1561.   time            Time duration for options
  1562.  
  1563.   thread          Thread to be affected.
  1564.  
  1565. Description
  1566.  
  1567.   thread_switch  provides low-level access to the scheduler's context switching
  1568. code.  new_thread is a hint that implements handoff scheduling.  The  operating
  1569. system  will attempt to switch directly to the new thread (bypassing the normal
  1570. logic that selects the next thread to run) if possible.  Since this is a  hint,
  1571. it  may  be incorrect; it is ignored if it doesn't specify a thread on the same
  1572. host as the current thread or if that thread can't be switched to (not runnable
  1573. or  already  running  on another processor).  In this case, the normal logic to
  1574. select the next thread to run is used; the current thread may continue  running
  1575. if there is no other appropriate thread to run.
  1576.  
  1577.   Options  for option are defined in <mach/thread_switch.h>.  Three options are
  1578. recognized:  SWITCH_OPTION_NONE No  options,  the  time  argument  is  ignored.
  1579. SWITCH_OPTION_WAIT  The  thread is blocked for the specified time.  This can be
  1580. aborted by  thread_abort.    SWITCH_OPTION_DEPRESS  The  thread's  priority  is
  1581. depressed   to  the  lowest  possible  value  for  time.  This  is  aborted  by
  1582. thread_abort, or by the  scheduler  choosing  to  run  the  thread  again.    A
  1583. consequence  of this is that a depressed thread must be queued (on a run queue)
  1584. waiting for the scheduler to choose it to run; once chosen, the  depression  is
  1585. aborted.  This depression is independent of operations that change the thread's
  1586. priority (e.g. thread_priority will not abort the  depression).    The  minimum
  1587. time and units of time can be obtained as the min_timeout value from host_info.
  1588.  
  1589.   thread_switch   is  an  optimized  trap  that  affects  the  current  thread.
  1590. thread_depress_abort is an rpc to the kernel that may affect any thread.
  1591.  
  1592.   thread_switch is often called when the current thread can proceed no  further
  1593. for some reason; the various options and arguments allow information about this
  1594. reason to be transmitted to the  kernel.    The  new_thread  argument  (handoff
  1595. scheduling)  is  useful when the identity of the thread that must make progress
  1596. before the current thread runs again is known.  The WAIT option  is  used  when
  1597. the  amount of time that the current thread must wait before it can do anything
  1598. useful can be estimated and is fairly long.  The DEPRESS option  is  used  when
  1599. the  amount  of  time  that must be waited is fairly short, especially when the
  1600. identity of the thread that is being waited for is not known.
  1601.  
  1602.   Users should beware of calling  thread_switch  with  an  invalid  hint  (e.g.
  1603. THREAD_NULL  )  and  no  option.  Because the time-sharing scheduler varies the
  1604. priority of threads based on usage, this may result in a waste of cpu  time  if
  1605. the  thread  that  must  be  run  is of lower priority.  The use of the DEPRESS
  1606. option in this situation is highly recommended.
  1607.  
  1608.   thread_switch ignores policies.  Users relying on the preemption semantics of
  1609. a fixed time policy should be aware that thread_switch ignores these semantics;
  1610. it will run the specified new_thread indepent of its priority and the  priority
  1611. of any other threads that could be run instead.
  1612.  
  1613. Returns
  1614.  
  1615.   KERN_SUCCESS    The call succeeded.  thread_restore_priority always succeeds,
  1616.                   and does not have a defined return value as a result.
  1617.  
  1618.   KERN_INVALID_ARGUMENT
  1619.                   thread is not a thread, or option is not a recognized option.
  1620.  
  1621.   KERN_FAILURE    kern_depress_abort   failed   because   the  thread  was  not
  1622.                   depressed.
  1623.  
  1624. Notes
  1625.  
  1626.   Availability limited.
  1627.  
  1628. See Also
  1629.  
  1630.   host_info
  1631. thread_wire
  1632.  
  1633. #include <mach.h>
  1634.  
  1635. kern_return_t thread_wire(host_priv, thread, wired)
  1636.         host_priv_t     host_priv;
  1637.         thread_t        thread;
  1638.         boolean_t       wired;
  1639.  
  1640.  
  1641. Arguments
  1642.  
  1643.   host_priv       The privileged host port for the thread's host.
  1644.  
  1645.   thread          The thread to be affected
  1646.  
  1647.   wired           Make thread unswappable if TRUE, swappable if FALSE.
  1648.  
  1649. Description
  1650.  
  1651.   thread_wire allows privileged to restrict the swappability  of  threads.    A
  1652. unswappable  thread has its kernel stack wired (made non-pageable) so it cannot
  1653. be swapped out.  This counts against the limit of wired  memory  maintained  by
  1654. the kernel (see vm_wire).  The number of pages that is consumed can be obtained
  1655. from vm_wire_statistics.
  1656.  
  1657. Returns
  1658.  
  1659.   KERN_SUCCESS    The call succeeded
  1660.  
  1661.   KERN_INVALID_ARGUMENT
  1662.                   host_priv  is not the privileged host port for thread's host,
  1663.                   or thread is not a thread.
  1664.  
  1665.   KERN_RESOURCE_SHORTAGE
  1666.                   Some kernel resource limit, most likely that on the amount of
  1667.                   memory that can be wired down, has been exceeded.
  1668.  
  1669. Notes
  1670.  
  1671.   Statistics interface to obtain  wire  limit  and  count  against  that  limit
  1672. (vm_wire_statistics) not available yet.  Availability limited.
  1673.  
  1674. See Also
  1675.  
  1676.   vm_wire, vm_wire_statistics, host_priv_self
  1677. vm_wire
  1678.  
  1679. #include <mach.h>
  1680.  
  1681. kern_return_t vm_wire (host_priv, task, start, end, prot)
  1682.         host_priv_t     host_priv;
  1683.         task_t          task;
  1684.         vm_address_t    start,end;
  1685.         vm_prot_t       prot;
  1686.  
  1687.  
  1688. Arguments
  1689.  
  1690.   host_priv       The privileged host port for the host on which task resides
  1691.  
  1692.   task            The task whose memory is to be affected
  1693.  
  1694.   start,end       First and last addresses of the memory region to be affected.
  1695.  
  1696.   prot            Types of accesses that must not cause page faults.
  1697.  
  1698. Description
  1699.  
  1700.   vm_wire  allows  privileged  applications to control memory pageability.  The
  1701. semantics of a successful vm_wire operation are that memory in the  range  from
  1702. start  to  end  in task will not cause page faults for any accesses included in
  1703. prot.  Data memory can be made non-pageable (wired) with  a  prot  argument  of
  1704. VM_PROT_READ|VM_PROT_WRITE.    A  special  case  is that VM_PROT_NONE makes the
  1705. memory pageable.  Machines with hardware restrictions on address aliasing (e.g.
  1706. IBM  PC/RT, HP-PA) may have to reload mappings to wired memory and flush caches
  1707. if more than one virtual mapping corresponding to the same physical  memory  is
  1708. used.  The mappings will usually be reloaded from a fast software cache, but if
  1709. this overhead is a problem aliasing of wired memory should be avoided on  these
  1710. architectures.
  1711.  
  1712.   The  kernel  maintains  an  internal limit on how much memory may be wired to
  1713. protect  itself  from  attempts  to  wire  all  of  physical  memory  or  more.
  1714. Attempting  to wire more memory than this limit allows will fail.  The limit is
  1715. a limit on address space, so wiring shared  memory  twice  counts  against  the
  1716. limit twice.
  1717.  
  1718. Returns
  1719.  
  1720.   KERN_SUCCESS    The call succeeded.
  1721.  
  1722.   KERN_INVALID_ARGUMENT
  1723.                   host_priv is not the privileged host port for task's host, or
  1724.                   task  is  not  a task, or start and end do not define a valid
  1725.                   address range  in  task,  or  prot  is  not  a  valid  memory
  1726.                   protection.
  1727.  
  1728.   KERN_RESOURCE_SHORTAGE
  1729.                   Some kernel resource limit, most likely that on the amount of
  1730.                   memory that can be wired down, has been exceeded.
  1731.  
  1732.   KERN_FAILURE    Some memory in the range from start to end does not exist.
  1733.  
  1734.   KERN_PROTECTION_FAILURE
  1735.                   Some memory in the range from start to end does not allow all
  1736.                   accesses specified by prot
  1737.  
  1738. Notes
  1739.  
  1740.   The limit on wired memory should discount for sharing.  The kernel may choose
  1741. to wire for write access  even  if  that  is  not  specified  in  prot  causing
  1742. unexpected  copies  to  be  made.   This behavior can be avoided by setting the
  1743. maximum protection on the memory to read-only.  Statistics interface to  obtain
  1744. wire limit and count against that limit (vm_wire_statistics) not available yet.
  1745. Availability limited.
  1746.  
  1747. See Also
  1748.  
  1749.   thread_wire, vm_wire_statistics, host_priv_self
  1750.                                Table of Contents
  1751. 1. Processor allocation primitives                                            1
  1752.      1.1. Concepts                                                            1
  1753.      1.2. Functionality                                                       1
  1754.      1.3. Uses                                                                1
  1755. 2. Scheduling primitives                                                     19
  1756.      2.1. Introduction                                                       19
  1757.      2.2. Priority                                                           19
  1758.      2.3. Handoff Scheduling                                                 19
  1759.      2.4. Wiring                                                             19
  1760. I. Summary of Kernel Calls
  1761.  
  1762.   The following is a summary of calls to the MACH kernel.  The  page  on  which
  1763. the operation is fully described appears within square brackets.
  1764.  
  1765.  
  1766. [2]  host_t host_self()
  1767.  
  1768.  
  1769.  
  1770.  
  1771. [2]  host_priv_t host_priv_self()
  1772.  
  1773.  
  1774.  
  1775.  
  1776. [3]  kern_return_t host_processors(host_priv, processor_list, processor_count)
  1777.          host_priv_t         host_priv;
  1778.          processor_array_t   *processor_list;        /* out, ptr to array */
  1779.          int                 *processor_count;       /* out */
  1780.  
  1781.  
  1782.  
  1783.  
  1784. [4]  kern_return_t
  1785.      host_processor_sets(host, processor_set_list, processor_set_count)
  1786.          host_t                 host;
  1787.          processor_set_array_t  *processor_set_list; /* out, ptr to array */
  1788.          int                    *processor_set_count;        /* out */
  1789.  
  1790.  
  1791.  
  1792.  
  1793.  
  1794. [5]  kern_return_t host_processor_set_priv(host_priv, set_name, set);
  1795.              host_priv_t             host_priv;
  1796.              processor_set_name_t    set_name;
  1797.              processor_set_t         *set;
  1798.  
  1799.  
  1800.  
  1801.  
  1802. [6]  kern_return_t host_info(host, flavor, host_info, host_infoCnt)
  1803.              host_t          host;
  1804.              int             flavor;
  1805.              host_info_t     host_info;      /* in and out */
  1806.              unsigned int    *host_infoCnt;  /* in and out */
  1807.  
  1808.  
  1809.  
  1810.  
  1811. [7]  kern_return_t host_kernel_version(host, version)
  1812.              host_t host;
  1813.              kernel_version_t *version;              /* out */
  1814.  
  1815.  
  1816.  
  1817.  
  1818.  
  1819. [8]  kern_return_t processor_assign(processor, processor_set, wait)
  1820.              processor_t     processor;
  1821.              processor_set_t processor_set;
  1822.              boolean_t       wait;
  1823.  
  1824.  
  1825.  
  1826.  
  1827. [8]  kern_return_t processor_get_assignment(processor, assigned_set_name)
  1828.              processor_t     processor;
  1829.              processor_set_name_t assigned_set_name;
  1830.  
  1831.  
  1832.  
  1833.  
  1834. [9]  kern_return_t processor_start(processor)
  1835.              processor_t             processor;
  1836.  
  1837.  
  1838.  
  1839.  
  1840. [9]  kern_return_t processor_exit(processor)
  1841.              processor_t             processor;
  1842.  
  1843.  
  1844.  
  1845.  
  1846. [9]  kern_return_t processor_control(processor, cmd, count)
  1847.              processor_t             processor;
  1848.              int                     *cmd;  /* array of ints */
  1849.              int                     count;
  1850.  
  1851.  
  1852.  
  1853.  
  1854. [10] /* the definition of processor_info_t from mach.h - sys/processor_info.h i
  1855.  
  1856.      typedef int     *processor_info_t;      /* variable length array of int */
  1857.  
  1858.      /* one interpretation of info is */
  1859.  
  1860.         struct processor_basic_info {
  1861.              cpu_type_t      cpu_type;       /* cpu type */
  1862.              cpu_subtype_t   cpu_subtype;    /* cpu subtype */
  1863.              boolean_t       running;        /* is processor running? */
  1864.              int             slot_num;       /* slot number */
  1865.              boolean_t       is_master;      /* is this the master processor */
  1866.         };
  1867.      typedef struct processor_basic_info             *processor_basic_info_t;
  1868.  
  1869.  
  1870.  
  1871.      kern_return_t
  1872.      processor_info(processor, flavor, host, processor_info, processor_infoCnt)
  1873.              processor_t             processor;
  1874.              int                     flavor;
  1875.              host_t                  *host;
  1876.              processor_info_t        processor_info; /* in and out */
  1877.              unsigned int            *processor_infoCnt;     /* in and out */
  1878.  
  1879.  
  1880.  
  1881.  
  1882. [11] kern_return_t processor_set_create(host, new_set, new_name)
  1883.              host_t                  host;
  1884.              processor_set_t         *new_set;
  1885.              processor_set_name_t    *new_name;
  1886.  
  1887.  
  1888.  
  1889.  
  1890. [12] kern_return_t processor_set_default(host, default_set);
  1891.              host_t                  host;
  1892.              processor_set_t         *default_set;
  1893.  
  1894.  
  1895.  
  1896.  
  1897.  
  1898. [13] kern_return_t processor_set_destroy(processor_set)
  1899.              processor_set_t         processor_set;
  1900.  
  1901.  
  1902.  
  1903.  
  1904.  
  1905.  
  1906. [14] /* the definition of processor_set_info_ from mach/processor_info.h  */
  1907.  
  1908.      typedef int     *processor_set_info_t;  /* variable length array of int */
  1909.  
  1910.      /* one interpretation of info is */
  1911.  
  1912.         struct processor_set_basic_info {
  1913.              int             processor_count;        /* number of processors */
  1914.              int             task_count;             /* number of tasks */
  1915.              int             thread_count;           /* number of threads */
  1916.              int             load_average;           /* scaled load average */
  1917.              int             mach_factor;            /* scaled mach factor */
  1918.         };
  1919.      typedef struct processor_set_basic_info         *processor_set_basic_info_
  1920.  
  1921.      /* another interpretation of info is */
  1922.  
  1923.      struct processor_set_sched_info {
  1924.              int             policies;       /* allowed policies */
  1925.              int             max_priority;   /* max priority for new threads */
  1926.      };
  1927.  
  1928.      typedef struct processor_set_sched_info *processor_set_sched_info_t;
  1929.  
  1930.  
  1931.      kern_return_t
  1932.      processor_set_info(processor_set, flavor, host, processor_set_info,
  1933.          processor_set_infoCnt)
  1934.              processor_set_name_t    processor_set;
  1935.              int                     flavor;
  1936.              host_t                  *host;
  1937.              processor_set_info_t    processor_set_info;     /* in and out */
  1938.              unsigned int            *processor_set_infoCnt; /* in and out */
  1939.  
  1940.  
  1941.  
  1942.  
  1943.  
  1944. [15] kern_return_t processor_set_tasks(processor_set, task_list, task_count)
  1945.              processor_set_t processor_set;
  1946.              task_array_t    *task_list;     /* out, ptr to array */
  1947.              int             *task_count;    /* out */
  1948.  
  1949.  
  1950.  
  1951.  
  1952. [16] kern_return_t processor_set_threads(processor_set, thread_list, thread_cou
  1953.              processor_set_t processor_set;
  1954.              thread_array_t  *thread_list;   /* out, ptr to array */
  1955.              int             *thread_count;  /* out */
  1956. [17] kern_return_t
  1957.      task_assign(task, processor_set, assign_threads)
  1958.              task_t task;
  1959.              processor_set_t processor_set;
  1960.              boolean_t       assign_threads;
  1961.  
  1962.  
  1963.  
  1964.  
  1965. [17] kern_return_t
  1966.      task_assign_default(task, assign_threads)
  1967.              task_t          task;
  1968.              boolean_t       assign_threads;
  1969.  
  1970.  
  1971.  
  1972.  
  1973. [17] kern_return_t
  1974.      task_get_assignment(task, processor_set)
  1975.              task_t          task;
  1976.              processor_set_name_t    *processor_set;
  1977.  
  1978.  
  1979.  
  1980.  
  1981. [18] kern_return_t thread_assign(thread, processor_set)
  1982.              thread_t        thread;
  1983.              processor_set_t processor_set;
  1984.  
  1985.  
  1986.  
  1987.  
  1988. [18] kern_return_t thread_assign_default(thread)
  1989.              thread_t        thread;
  1990.  
  1991.  
  1992.  
  1993.  
  1994. [18] kern_return_t thread_get_assignment(thread, processor_set)
  1995.              thread_t                thread;
  1996.              processor_set_name_t    *processor_set;
  1997.  
  1998.  
  1999.  
  2000.  
  2001.  
  2002. [20] kern_return_t task_priority(task, priority, change_threads)
  2003.              task_t          task;
  2004.              int             priority;
  2005.              boolean_t       change_threads;
  2006.  
  2007.  
  2008.  
  2009.  
  2010.  
  2011. [21] kern_return_t thread_priority(thread, priority, set_max)
  2012.              thread_t        thread;
  2013.              int             priority;
  2014.              boolean_t       set_max
  2015.  
  2016.  
  2017.  
  2018.  
  2019. [21] kern_return_t thread_max_priority(thread, processor_set, priority)
  2020.              thread_t        thread;
  2021.              processor_set_t processor_set;
  2022.              int             priority;
  2023.  
  2024.  
  2025.  
  2026.  
  2027. [22] kern_return_t thread_policy(thread, policy, data)
  2028.              thread_t        thread;
  2029.              int             policy;
  2030.              int             data;
  2031.  
  2032.  
  2033.  
  2034.  
  2035. [23] kern_return_t
  2036.      processor_set_max_priority(processor_set, priority, change_threads)
  2037.              processor_set_t         task;
  2038.              int                     priority;
  2039.              boolean_t               change_threads;
  2040.  
  2041.  
  2042.  
  2043.  
  2044. [24] kern_return_t
  2045.      processor_set_policy_enable(processor_set, policy)
  2046.              processor_set_t processor_set;
  2047.              int             policy;
  2048.  
  2049.  
  2050.  
  2051.  
  2052. [24] kern_return_t
  2053.      processor_set_policy_disable(processor_set, policy, change_threads)
  2054.              thread_t        thread;
  2055.              processor_set_t processor_set;
  2056.              int             change_threads;
  2057.  
  2058.  
  2059.  
  2060.  
  2061.  
  2062.  
  2063. [25] kern_return_t thread_switch(new_thread, option, time)
  2064.              thread_t        new_thread;
  2065.              int             option;
  2066.              int             time;
  2067.  
  2068.  
  2069.  
  2070.  
  2071. [26] kern_return_t thread_wire(host_priv, thread, wired)
  2072.              host_priv_t     host_priv;
  2073.              thread_t        thread;
  2074.              boolean_t       wired;
  2075.  
  2076.  
  2077.  
  2078.  
  2079. [27] kern_return_t vm_wire (host_priv, task, start, end, prot)
  2080.              host_priv_t     host_priv;
  2081.              task_t          task;
  2082.              vm_address_t    start,end;
  2083.              vm_prot_t       prot;
  2084.