进程调度API之cond_resched
来源:互联网 发布:蜂窝网络 编辑:程序博客网 时间:2024/06/17 01:35
cond_resched() 用于让出cpu给其他进程运行,相对于yield函数,这个函数使用更为广泛一点.其使用的例程如下:void *hpfs_map_sector(struct super_block *s, unsigned secno, struct buffer_head **bhp, int ahead){struct buffer_head *bh;hpfs_lock_assert(s);hpfs_prefetch_sectors(s, secno, ahead);cond_resched();#让出cpu后,下一次执行时从这里开始.*bhp = bh = sb_bread(s, hpfs_search_hotfix_map(s, secno));if (bh != NULL)return bh->b_data;else {pr_err("%s(): read error\n", __func__);return NULL;}}其源码分析如下:#define cond_resched() ({\___might_sleep(__FILE__, __LINE__, 0);\ #调用这个函数的thread 不能sleep,如果发生sleep的时候,___might_sleep 会打印处callstack_cond_resched();\ #调用此函数让出cpu})_cond_resched 成功让出cpu,返回1,失败的返回0,但是我们一般不关心这个返回值int __sched _cond_resched(void){#检测此thread 是否符合被抢占的条件,这个函数之前的博文分析过if (should_resched(0)) {#让出cpupreempt_schedule_common();return 1;}return 0;}static void __sched notrace preempt_schedule_common(void){do {preempt_disable_notrace();preempt_latency_start(1);#核心是通过时调用__schedule 来让出cpu__schedule(true);preempt_latency_stop(1);preempt_enable_no_resched_notrace();/* * Check again in case we missed a preemption opportunity * between schedule and now. */} while (need_resched());}
阅读全文
0 0
- 进程调度API之cond_resched
- 进程调度API之__wake_up
- 进程调度API之__wake_up_sync
- 进程调度API之preempt_count_dec_and_test
- 进程调度API之should_resched
- 进程调度API之preempt_schedule
- 进程调度API之add_wait_queue_exclusive
- 进程调度API之autoremove_wake_function
- 进程调度API之complete
- 进程调度API之complete_all
- 进程调度API之completion_done
- 进程调度API之wait_for_completion_x
- 进程调度API之finish_wait
- 进程调度API之init_waitqueue_entry
- 进程调度API之init_waitqueue_head
- 进程调度API之prepare_to_wait
- 进程调度API之set_cpus_allowed_ptr
- 进程调度API之set_user_nice
- 分页条
- IO流
- 两行 CSS 代码实现图片任意颜色赋色技术
- MyBatis(第一天环境搭建)
- LeetCode Roman to Integer解题报告
- 进程调度API之cond_resched
- android开发中的各种Util
- 线性代数之七:矩阵的微分
- 2000年分区联赛提高组之四 方格取数
- 在C# WebBrowser控件插入JS代码并执行,可以修改js就能对html执行任意操作
- 3.8 If-then-else表达式
- Java http处理get请求,参数中带特殊字符处理方式
- MYSQL WHERE语句
- c++入门笔记(14)指针