- 论坛徽章:
- 8
|
靠,抓源码,看来是我记错了:
首先。2.4内核,小于2ms、且current->policy != SCHED_OTHER会忙等,而且不会出现任务切换:
(current->policy != SCHED_OTHER的意思是检查当前进程是否实时进程,只有是实时进程才会忙等,否则仍然发生任务切换。)
http://students.mimuw.edu.pl/SO/Linux/Kod/kernel/sched.c.html
asmlinkage int sys_nanosleep(struct timespec *rqtp, struct timespec *rmtp)
{
int error;
struct timespec t;
unsigned long expire;
error = verify_area(VERIFY_READ, rqtp, sizeof(struct timespec));
if (error)
return error;
memcpy_fromfs(&t, rqtp, sizeof(struct timespec));
if (rmtp) {
error = verify_area(VERIFY_WRITE, rmtp,
sizeof(struct timespec));
if (error)
return error;
}
if (t.tv_nsec >= 1000000000L || t.tv_nsec < 0 || t.tv_sec < 0)
return -EINVAL;
if (t.tv_sec == 0 && t.tv_nsec <= 2000000L &&
current->policy != SCHED_OTHER) {
/*
* Short delay requests up to 2 ms will be handled with
* high precision by a busy wait for all real-time processes.
*/
udelay((t.tv_nsec + 999) / 1000);
return 0;
}
expire = timespectojiffies(&t) + (t.tv_sec || t.tv_nsec) + jiffies;
current->timeout = expire;
current->state = TASK_INTERRUPTIBLE;
schedule();
if (expire > jiffies) {
if (rmtp) {
jiffiestotimespec(expire - jiffies -
(expire > jiffies + 1), &t);
memcpy_tofs(rmtp, &t, sizeof(struct timespec));
}
return -EINTR;
}
return 0;
}
libc的sleep/usleep实现,其实就是直接调用了sys_nanosleep,所以分析sys_nanosleep就行了:
http://cristi.indefero.net/p/uCl ... libc/unistd/sleep.c
http://cristi.indefero.net/p/uCl ... ibc/unistd/usleep.c
总之,看来我之前看到那篇文章是错的。2.4的改变,除了更好的支持了实时程序外,其实并不会造成任何可见影响。 |
|