VirtualBox

Ignore:
Timestamp:
Mar 27, 2019 11:33:01 AM (6 years ago)
Author:
vboxsync
Message:

Main: bugref:7929: Added ability to change the priority of the VM process

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/darwin/sched-darwin.cpp

    r76553 r77910  
    9999{
    100100    {
     101        RTPROCPRIORITY_DEFAULT, "Default",
     102        {
     103            { RTTHREADTYPE_INVALID,                 INT_MIN, INT_MIN },
     104            { RTTHREADTYPE_INFREQUENT_POLLER,       29, 29 },
     105            { RTTHREADTYPE_MAIN_HEAVY_WORKER,       30, 30 },
     106            { RTTHREADTYPE_EMULATION,               31, 31 }, /* the default priority */
     107            { RTTHREADTYPE_DEFAULT,                 32, 32 },
     108            { RTTHREADTYPE_GUI,                     32, 32 },
     109            { RTTHREADTYPE_MAIN_WORKER,             32, 32 },
     110            { RTTHREADTYPE_VRDP_IO,                 39, 39 },
     111            { RTTHREADTYPE_DEBUGGER,                42, 42 },
     112            { RTTHREADTYPE_MSG_PUMP,                47, 47 },
     113            { RTTHREADTYPE_IO,                      52, 52 },
     114            { RTTHREADTYPE_TIMER,                   55, 55 }
     115        }
     116    },
     117    {
    101118        RTPROCPRIORITY_LOW, "Low",
    102119        {
     
    207224 *
    208225 * @returns The base priority
    209  */
    210 static int rtSchedDarwinGetBasePriority(void)
     226 * @param   pThread     The thread to get it for.  NULL for current.
     227 */
     228static int rtSchedDarwinGetBasePriority(PRTTHREADINT pThread)
    211229{
    212230    /* the base_priority. */
    213     mach_msg_type_number_t              Count = POLICY_TIMESHARE_INFO_COUNT;
    214     struct policy_timeshare_info        TSInfo = {0,0,0,0,0};
    215     kern_return_t                       krc;
    216     krc = thread_info(mach_thread_self(), THREAD_SCHED_TIMESHARE_INFO, (thread_info_t)&TSInfo, &Count);
     231    mach_msg_type_number_t       Count = POLICY_TIMESHARE_INFO_COUNT;
     232    struct policy_timeshare_info TSInfo = {0,0,0,0,0};
     233    kern_return_t krc = thread_info(!pThread ? mach_thread_self() : pthread_mach_thread_np((pthread_t)pThread->Core.Key),
     234                                    THREAD_SCHED_TIMESHARE_INFO, (thread_info_t)&TSInfo, &Count);
    217235    Assert(krc == KERN_SUCCESS);
    218236
     
    228246     * Get the current priority.
    229247     */
    230     int iBasePriority = rtSchedDarwinGetBasePriority();
     248    int iBasePriority = rtSchedDarwinGetBasePriority(NULL);
    231249    Assert(iBasePriority >= 0 && iBasePriority <= 63);
    232250
     
    277295DECLHIDDEN(int) rtThreadNativeSetPriority(PRTTHREADINT pThread, RTTHREADTYPE enmType)
    278296{
    279     Assert(pThread->Core.Key == pthread_self());
    280297    Assert(enmType > RTTHREADTYPE_INVALID && enmType < RTTHREADTYPE_END);
    281298    AssertMsg(g_pProcessPriority && g_pProcessPriority->aTypes[enmType].enmType == enmType,
     
    305322        {
    306323            int i = 0;
    307             int iBasePriority = rtSchedDarwinGetBasePriority();
    308 
    309             while (!err && iBasePriority < iDesiredBasePriority && i++ < 256)
     324            int iBasePriority = rtSchedDarwinGetBasePriority(pThread);
     325
     326            while (   !err
     327                   && iBasePriority < iDesiredBasePriority
     328                   && i++ < 256)
    310329            {
    311330                SchedParam.sched_priority = ++iPriority;
    312331                err = pthread_setschedparam((pthread_t)pThread->Core.Key, iSchedPolicy, &SchedParam);
    313                 iBasePriority = rtSchedDarwinGetBasePriority();
     332                iBasePriority = rtSchedDarwinGetBasePriority(pThread);
    314333            }
    315334
    316             while (!err && iBasePriority > iDesiredBasePriority && i++ < 256)
     335            while (   !err
     336                   && iPriority > 0
     337                   && iBasePriority > iDesiredBasePriority
     338                   && i++ < 256)
    317339            {
    318340                SchedParam.sched_priority = --iPriority;
    319341                err = pthread_setschedparam((pthread_t)pThread->Core.Key, iSchedPolicy, &SchedParam);
    320                 iBasePriority = rtSchedDarwinGetBasePriority();
     342                iBasePriority = rtSchedDarwinGetBasePriority(pThread);
    321343            }
     344
     345            return VINF_SUCCESS;
    322346        }
    323347    }
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette