src/os/linux/vm/os_linux.cpp

Print this page




3802 }
3803 
3804 // Sleep forever; naked call to OS-specific sleep; use with CAUTION
3805 void os::infinite_sleep() {
3806   while (true) {    // sleep forever ...
3807     ::sleep(100);   // ... 100 seconds at a time
3808   }
3809 }
3810 
3811 // Used to convert frequent JVM_Yield() to nops
3812 bool os::dont_yield() {
3813   return DontYieldALot;
3814 }
3815 
3816 void os::yield() {
3817   sched_yield();
3818 }
3819 
3820 os::YieldResult os::NakedYield() { sched_yield(); return os::YIELD_UNKNOWN ;}
3821 
3822 void os::yield_all(int attempts) {
3823   // Yields to all threads, including threads with lower priorities
3824   // Threads on Linux are all with same priority. The Solaris style
3825   // os::yield_all() with nanosleep(1ms) is not necessary.
3826   sched_yield();
3827 }
3828 
3829 // Called from the tight loops to possibly influence time-sharing heuristics
3830 void os::loop_breaker(int attempts) {
3831   os::yield_all(attempts);
3832 }
3833 
3834 ////////////////////////////////////////////////////////////////////////////////
3835 // thread priority support
3836 
3837 // Note: Normal Linux applications are run with SCHED_OTHER policy. SCHED_OTHER
3838 // only supports dynamic priority, static priority must be zero. For real-time
3839 // applications, Linux supports SCHED_RR which allows static priority (1-99).
3840 // However, for large multi-threaded applications, SCHED_RR is not only slower
3841 // than SCHED_OTHER, but also very unstable (my volano tests hang hard 4 out
3842 // of 5 runs - Sep 2005).
3843 //
3844 // The following code actually changes the niceness of kernel-thread/LWP. It
3845 // has an assumption that setpriority() only modifies one kernel-thread/LWP,
3846 // not the entire user process, and user level threads are 1:1 mapped to kernel
3847 // threads. It has always been the case, but could change in the future. For
3848 // this reason, the code should not be used as default (ThreadPriorityPolicy=0).
3849 // It is only used when ThreadPriorityPolicy=1 and requires root privilege.
3850 
3851 int os::java_to_os_priority[CriticalPriority + 1] = {
3852   19,              // 0 Entry should never be used
3853 




3802 }
3803 
3804 // Sleep forever; naked call to OS-specific sleep; use with CAUTION
3805 void os::infinite_sleep() {
3806   while (true) {    // sleep forever ...
3807     ::sleep(100);   // ... 100 seconds at a time
3808   }
3809 }
3810 
3811 // Used to convert frequent JVM_Yield() to nops
3812 bool os::dont_yield() {
3813   return DontYieldALot;
3814 }
3815 
3816 void os::yield() {
3817   sched_yield();
3818 }
3819 
3820 os::YieldResult os::NakedYield() { sched_yield(); return os::YIELD_UNKNOWN ;}
3821 
3822 void os::yield_all() {
3823   // Yields to all threads, including threads with lower priorities
3824   // Threads on Linux are all with same priority. The Solaris style
3825   // os::yield_all() with nanosleep(1ms) is not necessary.
3826   sched_yield();
3827 }
3828 





3829 ////////////////////////////////////////////////////////////////////////////////
3830 // thread priority support
3831 
3832 // Note: Normal Linux applications are run with SCHED_OTHER policy. SCHED_OTHER
3833 // only supports dynamic priority, static priority must be zero. For real-time
3834 // applications, Linux supports SCHED_RR which allows static priority (1-99).
3835 // However, for large multi-threaded applications, SCHED_RR is not only slower
3836 // than SCHED_OTHER, but also very unstable (my volano tests hang hard 4 out
3837 // of 5 runs - Sep 2005).
3838 //
3839 // The following code actually changes the niceness of kernel-thread/LWP. It
3840 // has an assumption that setpriority() only modifies one kernel-thread/LWP,
3841 // not the entire user process, and user level threads are 1:1 mapped to kernel
3842 // threads. It has always been the case, but could change in the future. For
3843 // this reason, the code should not be used as default (ThreadPriorityPolicy=0).
3844 // It is only used when ThreadPriorityPolicy=1 and requires root privilege.
3845 
3846 int os::java_to_os_priority[CriticalPriority + 1] = {
3847   19,              // 0 Entry should never be used
3848