Symbian3/SDK/Source/GUID-7B173E02-9697-51F4-A7E8-795AEF547109.dita
changeset 7 51a74ef9ed63
child 8 ae94777fff8f
equal deleted inserted replaced
6:43e37759235e 7:51a74ef9ed63
       
     1 <?xml version="1.0" encoding="utf-8"?>
       
     2 <!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
       
     3 <!-- This component and the accompanying materials are made available under the terms of the License 
       
     4 "Eclipse Public License v1.0" which accompanies this distribution, 
       
     5 and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
       
     6 <!-- Initial Contributors:
       
     7     Nokia Corporation - initial contribution.
       
     8 Contributors: 
       
     9 -->
       
    10 <!DOCTYPE concept
       
    11   PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
       
    12 <concept id="GUID-7B173E02-9697-51F4-A7E8-795AEF547109" xml:lang="en"><title>Thread
       
    13 Priority Scheme</title><shortdesc>Explains the factors involved in allocating thread priority.</shortdesc><prolog><metadata><keywords/></metadata></prolog><conbody>
       
    14 <p>At any given time, the thread running on Symbian platform is the one with
       
    15 the highest priority that is ready to run. The priority of a thread is simply
       
    16 a number; the value determines the priority; the greater the number, the higher
       
    17 the priority. We call this the <i>true</i> or <i>absolute</i> priority of
       
    18 the thread. </p>
       
    19 <p>The Kernel schedules a fixed amount of time called a <i>quantum</i> for
       
    20 a thread to run on the CPU, and the scheduler chooses the highest priority
       
    21 thread that is ready to run. Threads of equal priority are executed on a <i>round
       
    22 robin basis</i>. </p>
       
    23 <p>The <i>true</i> priority values range from 0 (lowest) to 63 (highest). </p>
       
    24 <p>The priority range divides into four broad categories: </p>
       
    25 <table id="GUID-1EAC04DE-B68F-5F95-887C-39E9926F2500">
       
    26 <tgroup cols="2"><colspec colname="col0"/><colspec colname="col1"/>
       
    27 <tbody>
       
    28 <row>
       
    29 <entry><p>0</p> </entry>
       
    30 <entry><p>This is reserved for the <i>null thread</i>, which puts the processor
       
    31 into idle mode to save power when no other threads are ready to run. </p> </entry>
       
    32 </row>
       
    33 <row>
       
    34 <entry><p>1 - 23 </p> </entry>
       
    35 <entry><p>Used by kernel side threads and user-side applications and servers </p> </entry>
       
    36 </row>
       
    37 <row>
       
    38 <entry><p>24 -31 </p> </entry>
       
    39 <entry><p>Used by kernel side threads and protected system servers, i.e. servers
       
    40 with the <codeph>ProtServ</codeph> capability. </p> </entry>
       
    41 </row>
       
    42 <row>
       
    43 <entry><p>32 - 63 </p> </entry>
       
    44 <entry><p>Reserved for real-time threads running on the kernel side. </p> </entry>
       
    45 </row>
       
    46 </tbody>
       
    47 </tgroup>
       
    48 </table>
       
    49 <fig id="GUID-5FFD4994-B20D-5095-8F6E-FB1151A4FF79">
       
    50 <image href="GUID-A95FEDD4-106A-5E14-8B64-3E2882C76666_d0e250125_href.png" placement="inline"/>
       
    51 </fig>
       
    52 <ul>
       
    53 <li id="GUID-2BCF03FE-C23E-5CCA-87CF-4AE9A91FD0D8"><p> <xref href="GUID-7B173E02-9697-51F4-A7E8-795AEF547109.dita#GUID-7B173E02-9697-51F4-A7E8-795AEF547109/GUID-0194B574-806B-5BA3-B65C-6DC5A80CAB86">Priority scheme for general user-side threads</xref>  </p> </li>
       
    54 <li id="GUID-000499D5-EE19-5838-90CD-8C13AC468A52"><p> <xref href="GUID-7B173E02-9697-51F4-A7E8-795AEF547109.dita#GUID-7B173E02-9697-51F4-A7E8-795AEF547109/GUID-23801A52-4E62-56F4-8D81-E0A417517FDA">Priority scheme for real-time user-side threads</xref>  </p> </li>
       
    55 <li id="GUID-1BA97FE4-F817-50E4-A6DA-6B0B64819811"><p> <xref href="GUID-7B173E02-9697-51F4-A7E8-795AEF547109.dita#GUID-7B173E02-9697-51F4-A7E8-795AEF547109/GUID-F5B98A28-EEDA-58BD-A6CC-62C1621D44DF">Thread priority value mapping table</xref>  </p> </li>
       
    56 <li id="GUID-2BB44CDE-B566-52C0-869C-C60FB8D6AD94"><p> <xref href="GUID-7B173E02-9697-51F4-A7E8-795AEF547109.dita#GUID-7B173E02-9697-51F4-A7E8-795AEF547109/GUID-E9AFB6A3-ED3E-5110-82C8-E5E15E0AF899">Platform security notes</xref>  </p> </li>
       
    57 </ul>
       
    58 <section id="GUID-0194B574-806B-5BA3-B65C-6DC5A80CAB86"><title>Priority scheme
       
    59 for general user-side threads</title> <p>User-side threads do not allocate <i>true</i> priority
       
    60 values directly. Instead, they allocate priorities using symbolic values defined
       
    61 by enums. Symbian platform maps these values to the <i>true</i> value. </p> <p>There
       
    62 are two priority allocation schemes: </p> <ul>
       
    63 <li id="GUID-6BE65AEC-DC54-5350-8704-538B5E425352"><p> <xref href="GUID-7B173E02-9697-51F4-A7E8-795AEF547109.dita#GUID-7B173E02-9697-51F4-A7E8-795AEF547109/GUID-B9022468-F4E7-536B-B1D4-58DAA9EA5914">Process-relative scheme</xref>  </p> </li>
       
    64 <li id="GUID-BBB502EA-950C-5F8C-8CA2-F5F339000A10"><p> <xref href="GUID-7B173E02-9697-51F4-A7E8-795AEF547109.dita#GUID-7B173E02-9697-51F4-A7E8-795AEF547109/GUID-7A38EE63-E955-5432-84E1-F35CB45C931E">Process-independent scheme for general user threads</xref>  </p> </li>
       
    65 </ul> <p id="GUID-B9022468-F4E7-536B-B1D4-58DAA9EA5914"><b>Process-relative scheme</b> </p> <p>This
       
    66 scheme bases the <i>true</i> priority of a thread on the priority of its owning
       
    67 process and the priority of the thread relative to the process. This means
       
    68 that changing the process priority results in a change to the <i>true</i> priority
       
    69 of the thread. </p> <p>A process can be assigned one of eight discrete priorities
       
    70 represented by the individual enumerators of <xref href="GUID-5D289F30-2C88-396D-9748-798055F0AF56.dita"><apiname>TProcessPriority</apiname></xref>,
       
    71 and range from <xref href="GUID-9B7922A7-6098-3BBD-9ADE-BC21AD6381C3.dita"><apiname>EPriorityLow</apiname></xref>, the lowest, to <xref href="GUID-A35268D0-7EFC-3D58-8C79-E4E619F762F5.dita"><apiname>EPrioritySupervisor</apiname></xref>,
       
    72 the highest. </p> <p>In practice, <i>user processes</i> can only be assigned
       
    73 priorities that are one of the values: </p> <ul>
       
    74 <li id="GUID-85AA4A1D-A168-5AEF-9D4C-DC14C28686B2"><p> <xref href="GUID-9B7922A7-6098-3BBD-9ADE-BC21AD6381C3.dita"><apiname>EPriorityLow</apiname></xref> <codeph/>  </p> </li>
       
    75 <li id="GUID-45B720BB-3696-545F-B966-A2EA4B37AE5D"><p> <xref href="GUID-8778A277-DA7F-34A0-8472-29226DEC2CCE.dita"><apiname>EPriorityBackground</apiname></xref>  </p> </li>
       
    76 <li id="GUID-DF2708D4-B670-5B15-B587-CB71EAC99045"><p> <xref href="GUID-A62CF9B2-63E3-31E0-A51E-E04F2E2EB38F.dita"><apiname>EPriorityForeGround</apiname></xref>  </p> </li>
       
    77 <li id="GUID-9C68DD95-2AB6-57D0-9966-D83144788458"><p> <xref href="GUID-8995D880-69B7-3C31-891B-7A2C57E372FE.dita"><apiname>EPriorityHigh</apiname></xref>  </p> </li>
       
    78 </ul> <p>There are a further four process priorities that a user process is
       
    79 not permitted to set: <codeph>EPriorityWindowServer</codeph>, <codeph>EPriorityFileServer</codeph>, <codeph>EPriorityRealTimeServer</codeph> and <codeph>EPrioritySupervisor</codeph>. </p> <p>A process priority can be assigned: </p> <ul>
       
    80 <li id="GUID-CC4FA12C-BFDD-5F75-BC18-B742BCACEECF"><p>when the associated <filepath>.exe</filepath> is
       
    81 built; this is done by specifying the value in the <filepath>.mmp</filepath> file
       
    82 that defines the project. </p> </li>
       
    83 <li id="GUID-B86220D9-B10D-5506-AD90-73E7F8D7A089"><p>by calling <xref href="GUID-9DD1EA2B-DC59-315C-8E9C-CE6D9461B695.dita#GUID-9DD1EA2B-DC59-315C-8E9C-CE6D9461B695/GUID-189A64CB-F2EA-3C8F-A7A7-01CBF8FDE67A"><apiname>RProcess::SetPriority()</apiname></xref> and
       
    84 passing one of the <xref href="GUID-5D289F30-2C88-396D-9748-798055F0AF56.dita"><apiname>TProcessPriority</apiname></xref> enum values. </p> </li>
       
    85 </ul> <p>See also : <xref href="GUID-8DB5E558-9774-5CC3-AF8C-6C50D9FE0496.dita">Using
       
    86 Makmake</xref> in the <xref href="GUID-B21141D4-3BFE-59C9-8D5F-147A93BE1C95.dita">Build
       
    87 Tools Guide</xref>. </p> <p>The priority of a thread <i>relative</i> to a
       
    88 process is assigned by calling <xref href="GUID-B0E661BC-4058-3256-B9C3-5A4FD52F6DE5.dita#GUID-B0E661BC-4058-3256-B9C3-5A4FD52F6DE5/GUID-8E412361-AE54-3585-AF2A-45D4A53F8B03"><apiname>RThread::SetPriority()</apiname></xref> and
       
    89 passing one of the five <xref href="GUID-8708AFB7-92CC-34FC-9FBB-E6B16472B99D.dita"><apiname>TThreadPriority</apiname></xref> enum values: </p> <ul>
       
    90 <li id="GUID-BCFFB27F-5CEB-58E8-A859-C82273CB7FDC"><p> <xref href="GUID-DF41A24C-6873-37E6-834A-98CDFC8D54FB.dita"><apiname>EPriorityMuchLess</apiname></xref>  </p> </li>
       
    91 <li id="GUID-21C1A24C-483D-579B-BA56-31B3694215CE"><p> <xref href="GUID-0429DE71-44B4-3764-A62B-AD937E6AD355.dita"><apiname> EPriorityLess</apiname></xref>  </p> </li>
       
    92 <li id="GUID-48747F5D-8F0E-5C57-8858-35D8881B1DB7"><p> <xref href="GUID-2ACE5CF0-7E8B-35FF-8ABC-6917B2F68BB1.dita"><apiname>EPriorityNormal</apiname></xref>  </p> </li>
       
    93 <li id="GUID-78DEBC15-DFD8-5384-8358-3744E2C1DDBE"><p> <xref href="GUID-34B6B121-2E45-36FE-B0FA-E8272E2F1D10.dita"><apiname>EPriorityMore</apiname></xref>  </p> </li>
       
    94 <li id="GUID-AE42DA32-09CA-5C8B-B9AF-2A68E66E6218"><p> <xref href="GUID-4F19A64D-FBBE-34F2-8387-1449E49DC923.dita"><apiname> EPriorityMuchMore</apiname></xref>  </p> </li>
       
    95 </ul> <p>The <xref href="GUID-7B173E02-9697-51F4-A7E8-795AEF547109.dita#GUID-7B173E02-9697-51F4-A7E8-795AEF547109/GUID-F5B98A28-EEDA-58BD-A6CC-62C1621D44DF">thread
       
    96 priority value mapping table</xref> shows the <i>true</i> priority of a thread
       
    97 based on the combination of process priority and process-relative thread priority </p> <p id="GUID-7A38EE63-E955-5432-84E1-F35CB45C931E"><b>Process-independent scheme
       
    98 for general user threads</b> </p> <p>In this scheme, the <i>true</i> priority
       
    99 of a thread is independent of the priority of its owning process. Changing
       
   100 the priority of the underlying process has no effect on the <i>true</i> priority
       
   101 of the thread. </p> <p>The priority of a thread is assigned by calling <xref href="GUID-B0E661BC-4058-3256-B9C3-5A4FD52F6DE5.dita#GUID-B0E661BC-4058-3256-B9C3-5A4FD52F6DE5/GUID-8E412361-AE54-3585-AF2A-45D4A53F8B03"><apiname>RThread::SetPriority()</apiname></xref> and
       
   102 passing one of the <xref href="GUID-8708AFB7-92CC-34FC-9FBB-E6B16472B99D.dita"><apiname>TThreadPriority</apiname></xref> enum values listed below.
       
   103 Note that the set of enum values splits into two logical groupings based on
       
   104 their equivalence to process-relative values. See the <xref href="GUID-7B173E02-9697-51F4-A7E8-795AEF547109.dita#GUID-7B173E02-9697-51F4-A7E8-795AEF547109/GUID-F5B98A28-EEDA-58BD-A6CC-62C1621D44DF">thread priority value mapping table</xref>. </p> <table id="GUID-A0397BB8-AAC7-5F79-B94F-68103B66132C">
       
   105 <tgroup cols="2"><colspec colname="col0"/><colspec colname="col1"/>
       
   106 <tbody>
       
   107 <row>
       
   108 <entry><p> <b> Group 1 </b>  </p> </entry>
       
   109 <entry><p> <b> Group 2 </b>  </p> </entry>
       
   110 </row>
       
   111 <row>
       
   112 <entry><ul>
       
   113 <li id="GUID-12430992-C96F-5006-85AD-A9308AB75B93"><p> <xref href="GUID-A131F0B9-C8D4-3F0D-A0CB-140DA8EA3288.dita"><apiname>EPriorityAbsoluteVeryLow</apiname></xref>  </p> </li>
       
   114 <li id="GUID-A5682ECF-DCAA-5E35-8294-613A30F416FD"><p> <xref href="GUID-280BFA0F-9A1C-3644-AF1C-B169B09D8834.dita"><apiname>EPriorityAbsoluteLow</apiname></xref>  </p> </li>
       
   115 <li id="GUID-1750EB5D-A22B-5838-9EB8-37B06A0D1F98"><p> <xref href="GUID-ECA0DFF8-106C-3D1C-963C-10708885797A.dita"><apiname>EPriorityAbsoluteBackground</apiname></xref>  </p> </li>
       
   116 <li id="GUID-A83FCD79-3B4C-51CC-A82A-BE8AAB9BEEC0"><p> <xref href="GUID-451D6DB5-C247-34BF-8D8A-288C03599B7E.dita"><apiname>EPriorityAbsoluteForeground</apiname></xref>  </p> </li>
       
   117 <li id="GUID-1EDD4765-F02A-56CD-882D-E4DD443CE410"><p> <xref href="GUID-B6EEA9DD-68AE-30FD-AEE1-9B227109750F.dita"><apiname>EPriorityAbsoluteHigh</apiname></xref>  </p> </li>
       
   118 </ul> </entry>
       
   119 <entry><ul>
       
   120 <li id="GUID-E03FCF50-F5B6-5885-B939-88B513F4AC2F"><p> <xref href="GUID-0070BA48-851D-36E2-9C4C-C11C0FF0BE46.dita"><apiname>EPriorityAbsoluteLowNormal</apiname></xref>  </p> </li>
       
   121 <li id="GUID-4C94D1D2-6B81-57D8-B44D-2FE19E9971F9"><p> <xref href="GUID-CD20880F-21EB-389C-A0A4-8DFFE714B102.dita"><apiname>EPriorityAbsoluteBackgroundNormal</apiname></xref>  </p> </li>
       
   122 <li id="GUID-6D3AA39B-AE42-575A-B63B-D109049ABFEF"><p> <xref href="GUID-1054385C-7168-31ED-89D9-4C33E28836A0.dita"><apiname>EPriorityAbsoluteForegroundNormal</apiname></xref>  </p> </li>
       
   123 <li id="GUID-E41572FD-0C50-54BC-98C6-857A8D86CCD7"><p> <xref href="GUID-E49C7DFA-4604-310C-915C-F278382A796A.dita"><apiname>EPriorityAbsoluteHighNormal</apiname></xref>  </p> </li>
       
   124 </ul> </entry>
       
   125 </row>
       
   126 </tbody>
       
   127 </tgroup>
       
   128 </table> <p>The <xref href="GUID-7B173E02-9697-51F4-A7E8-795AEF547109.dita#GUID-7B173E02-9697-51F4-A7E8-795AEF547109/GUID-F5B98A28-EEDA-58BD-A6CC-62C1621D44DF">thread
       
   129 priority value mapping table</xref> shows the resulting <i>true</i> priority
       
   130 of the thread. </p> </section>
       
   131 <section id="GUID-23801A52-4E62-56F4-8D81-E0A417517FDA"><title>Priority scheme
       
   132 for real-time user-side threads</title> <p>This scheme is the same as the <xref href="GUID-7B173E02-9697-51F4-A7E8-795AEF547109.dita#GUID-7B173E02-9697-51F4-A7E8-795AEF547109/GUID-7A38EE63-E955-5432-84E1-F35CB45C931E">process-independent
       
   133 scheme for general user threads</xref>, but with one essential difference
       
   134 - the range of <xref href="GUID-8708AFB7-92CC-34FC-9FBB-E6B16472B99D.dita"><apiname>TThreadPriority</apiname></xref> enum values to be passed
       
   135 to <xref href="GUID-B0E661BC-4058-3256-B9C3-5A4FD52F6DE5.dita#GUID-B0E661BC-4058-3256-B9C3-5A4FD52F6DE5/GUID-8E412361-AE54-3585-AF2A-45D4A53F8B03"><apiname>RThread::SetPriority()</apiname></xref> is as shown below. These priorities
       
   136 map to the <i>true</i> priority values in the range 24 -31, and can only be
       
   137 set by executables having the <codeph>ProtServ</codeph> capability. This range
       
   138 is referred to as the real time range. </p> <ul>
       
   139 <li id="GUID-78ACFC22-4FB7-5E90-B6E2-9EF39EA9A3F5"><p> <xref href="GUID-7574A754-ED28-3FE1-85BB-93F110DE8E50.dita"><apiname>EPriorityAbsoluteRealTime1</apiname></xref>  </p> </li>
       
   140 <li id="GUID-3ADBFE8D-E7D9-5316-B06E-E3C514F4221E"><p> <xref href="GUID-2561145A-9506-31F5-A0EA-24609EC71412.dita"><apiname>EPriorityAbsoluteRealTime2</apiname></xref>  </p> </li>
       
   141 <li id="GUID-90F0E400-AB37-52CC-B01E-2D7C3E589111"><p> <xref href="GUID-39A7F794-B7B1-3C0C-AFFF-956C71CE529F.dita"><apiname>EPriorityAbsoluteRealTime3</apiname></xref>  </p> </li>
       
   142 <li id="GUID-DDB4B69C-9BBD-5E4B-B87C-CF52B4BDAA85"><p> <xref href="GUID-DCDD7812-10F8-35A1-9DAD-EFDAC6EA874B.dita"><apiname> EPriorityAbsoluteRealTime4</apiname></xref>  </p> </li>
       
   143 <li id="GUID-91DEE716-6F45-51C2-8139-B9CB1AE5065B"><p> <xref href="GUID-F3872848-57CA-3682-80E2-39E87B7B3656.dita"><apiname>EPriorityAbsoluteRealTime5</apiname></xref>  </p> </li>
       
   144 <li id="GUID-01B2B0B9-4242-5D8E-83B2-2658CF68548F"><p> <xref href="GUID-D3FE9747-0CD8-3E0A-829E-3D7184AE8431.dita"><apiname>EPriorityAbsoluteRealTime6</apiname></xref>  </p> </li>
       
   145 <li id="GUID-6581842F-C83C-53A5-A567-F1D4BE97488C"><p> <xref href="GUID-A6BF84AA-2421-3DB0-A30D-B9D3B7E70B21.dita"><apiname>EPriorityAbsoluteRealTime7</apiname></xref>  </p> </li>
       
   146 <li id="GUID-C7AB328B-B910-51D2-ADB0-5E8A33AFCD69"><p> <xref href="GUID-84C4AED5-8AA8-31F0-9E77-6BBACE192763.dita"><apiname>EPriorityAbsoluteRealTime8</apiname></xref>  </p> </li>
       
   147 </ul> <p>The <xref href="GUID-7B173E02-9697-51F4-A7E8-795AEF547109.dita#GUID-7B173E02-9697-51F4-A7E8-795AEF547109/GUID-F5B98A28-EEDA-58BD-A6CC-62C1621D44DF">thread
       
   148 priority value mapping table</xref> shows the resulting <i>true</i> priority
       
   149 of the thread. </p> </section>
       
   150 <section id="GUID-F5B98A28-EEDA-58BD-A6CC-62C1621D44DF"><title>Thread priority
       
   151 value mapping table</title> <p>This table shows the effect of setting priorities,
       
   152 and the resulting <i>true</i> priority values. You need to be aware that this
       
   153 may change in the future, and you should never synchronise threads on the
       
   154 basis of thread priorities. If you need to synchronise threads, use mutexes
       
   155 or semaphores. </p> <p>Notes </p> <ul>
       
   156 <li id="GUID-CBC69A23-E3EF-56BC-A915-2770EBFB76C4"><p>True priority values
       
   157 in the shaded region can only be accessed by threads running in processes
       
   158 with the <codeph>ProtServ</codeph> capability. </p> </li>
       
   159 <li id="GUID-1F8FC263-3C39-5E3C-A186-6D5D4DF7D6D3"><p>The process-priority
       
   160 values : <xref href="GUID-972ADC0C-546E-3D24-9071-02B074DC1540.dita"><apiname>EPriorityWindowServer</apiname></xref>, <xref href="GUID-A19C5464-A1DA-3EEC-B81B-41690EBB3DB2.dita"><apiname>EPriorityFileServer</apiname></xref> and <xref href="GUID-A35268D0-7EFC-3D58-8C79-E4E619F762F5.dita"><apiname>EPrioritySupervisor</apiname></xref> all
       
   161 map to the same range of priorities. Along with <xref href="GUID-AAA610A8-48D8-3642-94E8-6C9747170DA9.dita"><apiname>EPriorityRealTimeServer</apiname></xref>,
       
   162 these have historically been used for system servers and other processes needing
       
   163 access to high priorities suitable for real-time tasks, and their use requires <codeph>ProtServ</codeph> capability. </p> </li>
       
   164 <li id="GUID-3256F08A-AD30-5378-BFA9-140688B1CDB6"><p>Note that <codeph>ProtServ</codeph> capability
       
   165 will not be granted to general applications for the purpose of gaining access
       
   166 to the very high thread priorities. This risks breaking important system functionality. </p> </li>
       
   167 </ul> <fig id="GUID-6BF93712-F8AA-5D08-A5D4-FEB6B22592D8">
       
   168 <image href="GUID-B9306D01-1DE5-511A-AC1A-6E3E9749BA89_d0e250728_href.png" placement="inline"/>
       
   169 </fig> <p>Note that we have used <i>E'</i> as an abbreviation for <i>EPriority</i> in
       
   170 this diagram. </p> </section>
       
   171 <section id="GUID-E9AFB6A3-ED3E-5110-82C8-E5E15E0AF899"><title>Platform security
       
   172 notes</title> <p>Platform security restrictions prevent thread and process
       
   173 priorities from being modified by another user process. There is one exception:
       
   174 by default, applications have “Priority Control” enabled for them which allows
       
   175 the window server to switch them between foreground and background process
       
   176 priorities depending on which has foreground focus. </p> </section>
       
   177 </conbody></concept>