3366 os::yield_all(attempts); 3367 } 3368 3369 //////////////////////////////////////////////////////////////////////////////// 3370 // thread priority support 3371 3372 // Note: Normal Linux applications are run with SCHED_OTHER policy. SCHED_OTHER 3373 // only supports dynamic priority, static priority must be zero. For real-time 3374 // applications, Linux supports SCHED_RR which allows static priority (1-99). 3375 // However, for large multi-threaded applications, SCHED_RR is not only slower 3376 // than SCHED_OTHER, but also very unstable (my volano tests hang hard 4 out 3377 // of 5 runs - Sep 2005). 3378 // 3379 // The following code actually changes the niceness of kernel-thread/LWP. It 3380 // has an assumption that setpriority() only modifies one kernel-thread/LWP, 3381 // not the entire user process, and user level threads are 1:1 mapped to kernel 3382 // threads. It has always been the case, but could change in the future. For 3383 // this reason, the code should not be used as default (ThreadPriorityPolicy=0). 3384 // It is only used when ThreadPriorityPolicy=1 and requires root privilege. 3385 3386 int os::java_to_os_priority[MaxPriority + 1] = { 3387 19, // 0 Entry should never be used 3388 3389 4, // 1 MinPriority 3390 3, // 2 3391 2, // 3 3392 3393 1, // 4 3394 0, // 5 NormPriority 3395 -1, // 6 3396 3397 -2, // 7 3398 -3, // 8 3399 -4, // 9 NearMaxPriority 3400 3401 -5 // 10 MaxPriority 3402 }; 3403 3404 static int prio_init() { 3405 if (ThreadPriorityPolicy == 1) { 3406 // Only root can raise thread priority. Don't allow ThreadPriorityPolicy=1 3407 // if effective uid is not root. Perhaps, a more elegant way of doing 3408 // this is to test CAP_SYS_NICE capability, but that will require libcap.so 3409 if (geteuid() != 0) { 3410 if (!FLAG_IS_DEFAULT(ThreadPriorityPolicy)) { 3411 warning("-XX:ThreadPriorityPolicy requires root privilege on Linux"); 3412 } 3413 ThreadPriorityPolicy = 0; 3414 } 3415 } 3416 return 0; 3417 } 3418 3419 OSReturn os::set_native_priority(Thread* thread, int newpri) { 3420 if ( !UseThreadPriorities || ThreadPriorityPolicy == 0 ) return OS_OK; 3421 | 3366 os::yield_all(attempts); 3367 } 3368 3369 //////////////////////////////////////////////////////////////////////////////// 3370 // thread priority support 3371 3372 // Note: Normal Linux applications are run with SCHED_OTHER policy. SCHED_OTHER 3373 // only supports dynamic priority, static priority must be zero. For real-time 3374 // applications, Linux supports SCHED_RR which allows static priority (1-99). 3375 // However, for large multi-threaded applications, SCHED_RR is not only slower 3376 // than SCHED_OTHER, but also very unstable (my volano tests hang hard 4 out 3377 // of 5 runs - Sep 2005). 3378 // 3379 // The following code actually changes the niceness of kernel-thread/LWP. It 3380 // has an assumption that setpriority() only modifies one kernel-thread/LWP, 3381 // not the entire user process, and user level threads are 1:1 mapped to kernel 3382 // threads. It has always been the case, but could change in the future. For 3383 // this reason, the code should not be used as default (ThreadPriorityPolicy=0). 3384 // It is only used when ThreadPriorityPolicy=1 and requires root privilege. 3385 3386 int os::java_to_os_priority[CriticalPriority + 1] = { 3387 19, // 0 Entry should never be used 3388 3389 4, // 1 MinPriority 3390 3, // 2 3391 2, // 3 3392 3393 1, // 4 3394 0, // 5 NormPriority 3395 -1, // 6 3396 3397 -2, // 7 3398 -3, // 8 3399 -4, // 9 NearMaxPriority 3400 3401 -5, // 10 MaxPriority 3402 3403 -5 // 11 CriticalPriority 3404 }; 3405 3406 static int prio_init() { 3407 if (ThreadPriorityPolicy == 1) { 3408 // Only root can raise thread priority. Don't allow ThreadPriorityPolicy=1 3409 // if effective uid is not root. Perhaps, a more elegant way of doing 3410 // this is to test CAP_SYS_NICE capability, but that will require libcap.so 3411 if (geteuid() != 0) { 3412 if (!FLAG_IS_DEFAULT(ThreadPriorityPolicy)) { 3413 warning("-XX:ThreadPriorityPolicy requires root privilege on Linux"); 3414 } 3415 ThreadPriorityPolicy = 0; 3416 } 3417 } 3418 return 0; 3419 } 3420 3421 OSReturn os::set_native_priority(Thread* thread, int newpri) { 3422 if ( !UseThreadPriorities || ThreadPriorityPolicy == 0 ) return OS_OK; 3423 |