4031 |
4031 |
4032 size_t os::read_at(int fd, void *buf, unsigned int nBytes, jlong offset) { |
4032 size_t os::read_at(int fd, void *buf, unsigned int nBytes, jlong offset) { |
4033 return ::pread(fd, buf, nBytes, offset); |
4033 return ::pread(fd, buf, nBytes, offset); |
4034 } |
4034 } |
4035 |
4035 |
4036 // Short sleep, direct OS call. |
|
4037 // |
|
4038 // Note: certain versions of Linux CFS scheduler (since 2.6.23) do not guarantee |
|
4039 // sched_yield(2) will actually give up the CPU: |
|
4040 // |
|
4041 // * Alone on this pariticular CPU, keeps running. |
|
4042 // * Before the introduction of "skip_buddy" with "compat_yield" disabled |
|
4043 // (pre 2.6.39). |
|
4044 // |
|
4045 // So calling this with 0 is an alternative. |
|
4046 // |
|
4047 void os::naked_short_sleep(jlong ms) { |
|
4048 struct timespec req; |
|
4049 |
|
4050 assert(ms < 1000, "Un-interruptable sleep, short time use only"); |
|
4051 req.tv_sec = 0; |
|
4052 if (ms > 0) { |
|
4053 req.tv_nsec = (ms % 1000) * 1000000; |
|
4054 } else { |
|
4055 req.tv_nsec = 1; |
|
4056 } |
|
4057 |
|
4058 nanosleep(&req, NULL); |
|
4059 |
|
4060 return; |
|
4061 } |
|
4062 |
|
4063 // Sleep forever; naked call to OS-specific sleep; use with CAUTION |
4036 // Sleep forever; naked call to OS-specific sleep; use with CAUTION |
4064 void os::infinite_sleep() { |
4037 void os::infinite_sleep() { |
4065 while (true) { // sleep forever ... |
4038 while (true) { // sleep forever ... |
4066 ::sleep(100); // ... 100 seconds at a time |
4039 ::sleep(100); // ... 100 seconds at a time |
4067 } |
4040 } |
4070 // Used to convert frequent JVM_Yield() to nops |
4043 // Used to convert frequent JVM_Yield() to nops |
4071 bool os::dont_yield() { |
4044 bool os::dont_yield() { |
4072 return DontYieldALot; |
4045 return DontYieldALot; |
4073 } |
4046 } |
4074 |
4047 |
|
4048 // Linux CFS scheduler (since 2.6.23) does not guarantee sched_yield(2) will |
|
4049 // actually give up the CPU. Since skip buddy (v2.6.28): |
|
4050 // |
|
4051 // * Sets the yielding task as skip buddy for current CPU's run queue. |
|
4052 // * Picks next from run queue, if empty, picks a skip buddy (can be the yielding task). |
|
4053 // * Clears skip buddies for this run queue (yielding task no longer a skip buddy). |
|
4054 // |
|
4055 // An alternative is calling os::naked_short_nanosleep with a small number to avoid |
|
4056 // getting re-scheduled immediately. |
|
4057 // |
4075 void os::naked_yield() { |
4058 void os::naked_yield() { |
4076 sched_yield(); |
4059 sched_yield(); |
4077 } |
4060 } |
4078 |
4061 |
4079 //////////////////////////////////////////////////////////////////////////////// |
4062 //////////////////////////////////////////////////////////////////////////////// |