ImageVerifierCode 换一换
格式:DOC , 页数:9 ,大小:51KB ,
资源ID:11767348      下载积分:10 金币
快捷注册下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

开通VIP
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.zixin.com.cn/docdown/11767348.html】到电脑端继续下载(重复下载【60天内】不扣币)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

开通VIP折扣优惠下载文档

            查看会员权益                  [ 下载后找不到文档?]

填表反馈(24小时):  下载求助     关注领币    退款申请

开具发票请登录PC端进行申请

   平台协调中心        【在线客服】        免费申请共赢上传

权利声明

1、咨信平台为文档C2C交易模式,即用户上传的文档直接被用户下载,收益归上传人(含作者)所有;本站仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。所展示的作品文档包括内容和图片全部来源于网络用户和作者上传投稿,我们不确定上传用户享有完全著作权,根据《信息网络传播权保护条例》,如果侵犯了您的版权、权益或隐私,请联系我们,核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
2、文档的总页数、文档格式和文档大小以系统显示为准(内容中显示的页数不一定正确),网站客服只以系统显示的页数、文件格式、文档大小作为仲裁依据,个别因单元格分列造成显示页码不一将协商解决,平台无法对文档的真实性、完整性、权威性、准确性、专业性及其观点立场做任何保证或承诺,下载前须认真查看,确认无误后再购买,务必慎重购买;若有违法违纪将进行移交司法处理,若涉侵权平台将进行基本处罚并下架。
3、本站所有内容均由用户上传,付费前请自行鉴别,如您付费,意味着您已接受本站规则且自行承担风险,本站不进行额外附加服务,虚拟产品一经售出概不退款(未进行购买下载可退充值款),文档一经付费(服务费)、不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
4、如你看到网页展示的文档有www.zixin.com.cn水印,是因预览和防盗链等技术需要对页面进行转换压缩成图而已,我们并不对上传的文档进行任何编辑或修改,文档下载后都不会有水印标识(原文档上传前个别存留的除外),下载后原文更清晰;试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓;PPT和DOC文档可被视为“模板”,允许上传人保留章节、目录结构的情况下删减部份的内容;PDF文档不管是原文档转换或图片扫描而得,本站不作要求视为允许,下载前可先查看【教您几个在下载文档中可以更好的避免被坑】。
5、本文档所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用;网站提供的党政主题相关内容(国旗、国徽、党徽--等)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
6、文档遇到问题,请及时联系平台进行协调解决,联系【微信客服】、【QQ客服】,若有其他问题请点击或扫码反馈【服务填表】;文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“【版权申诉】”,意见反馈和侵权处理邮箱:1219186828@qq.com;也可以拔打客服电话:0574-28810668;投诉电话:18658249818。

注意事项

本文(linuxnohz下的timer机制和进程调度.doc)为本站上传会员【仙人****88】主动上传,咨信网仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知咨信网(发送邮件至1219186828@qq.com、拔打电话4009-655-100或【 微信客服】、【 QQ客服】),核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载【60天内】不扣币。 服务填表

linuxnohz下的timer机制和进程调度.doc

1、窗体顶端 nohz下的timer机制和进程调度 在2.6.21内核之前,时钟中断是周期的,即以HZ为频率,系统总是被动的接受时钟中断,然后运行中断处理程序。如果实在没有任务可以运行,那 么就执行idle,这也许也算一种创意,可 是时钟中断还是会周期性的打破idle,然后查询有没有需要做的事情,如果没有继续idle 以往的进程在特定的固定时间片内运行,时钟的定时中断提供了时间片的监督工作,一切显得十分和谐,可是系统内核本身就是没有主权,一切都在硬件的安排下进行。 随后的2.6.22以后,nohz才出现,nohz其实就是动态设置下一次的中断时间而不是使用系统无条件的默认的HZ中断。 这

2、样cfs调度器,再也不用受制于底层的时钟以及时间片分配特性,linux可以动态设置时间片长短,按照自己的方式来进行调度。   nohz其实就是托了抽象出来的clocksource和 clock_event_device的福,clocksource和 clock_event_device,这两个结构体就是时钟以及时钟行为的抽象。   先熟悉两个数据结构 struct timer_list :软件时钟,记录了软件时钟的到期时间以及到期后要执行的操作。 struct tvec_base :用于组织、管理软件时钟的结构。在 SMP 系统中,每个 CPU 有一个。     struc

3、t timer_list {     struct list_head entry;                //所在的链表     unsigned long expires;                //到期时间,以 tick 为单位     void (*function)(unsigned long);    //回调函数,到期后执行的操作     unsigned long data;                    //回调函数的参数     struct tvec_t_base_s *base;            //记录该软件时钟所在的 stru

4、ct tvec_base 变量 #ifdef CONFIG_TIMER_STATS     void *start_site;     char start_comm[16];     int start_pid; #endif }; struct tvec_t_base_s {     spinlock_t lock;     struct timer_list *running_timer;    //正在处理的软件时钟     unsigned long timer_jiffies;        //当前正在处理的软件时钟到期时间     tvec_root_t

5、tv1;                    //保存了到期时间从 timer_jiffies 到 timer_jiffies + 2的8次方 之间(包括边缘值)的所有软件时钟     tvec_t tv2;                            //保存了到期时间从 timer_jiffies + 2的8次方 到 timer_jiffies + 2的14次方 之间(包括边缘值)的 所有软件时钟     tvec_t tv3;                            //14~20     tvec_t tv4;                      

6、      //20~26     tvec_t tv5;                            //26~32 } ____cacheline_aligned; typedef struct tvec_t_base_s tvec_base_t; //下面开始跟踪内核中timer的代码,内核版本2.6.24 /*  * This function runs timers and the timer-tq in bottom half context.  */ static void run_timer_softirq(struct softirq_action

7、h)        //定时器中断下半部 {     tvec_base_t *base = __get_cpu_var(tvec_bases);        //取得CPU的tvec_base_t结构数据     hrtimer_run_queues();                                //这里有机会切换到nohz或者hres     if (time_after_eq(jiffies, base->timer_jiffies))    //如果当前jiffies >= 定时器到期base->timer_jiffies         __run

8、timers(base);                                //运行定时器回调函数 }   /*  * Called from timer softirq every jiffy, expire hrtimers:  *  * For HRT its the fall back code to run the softirq in the timer  * softirq context in case the hrtimer initialization failed or has  * not been done yet.  */ voi

9、d hrtimer_run_queues(void) {     struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);     int i;     if (hrtimer_hres_active())         return;     /*      * This _is_ ugly: We have to check in the softirq context,      * whether we can switch to highres and / or nohz mode. The

10、      * clocksource switch happens in the timer interrupt with      * xtime_lock held. Notification from there only sets the      * check bit in the tick_oneshot code, otherwise we might      * deadlock vs. xtime_lock.      */     if (tick_check_oneshot_change(!hrtimer_is_hres_enabled()))     

11、   //这个if判断就是具体切换到hres或者nohz的代码         if (hrtimer_switch_to_hres())             return;     hrtimer_get_softirq_time(cpu_base);     for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++)         run_hrtimer_queue(cpu_base, i); } /**  * Check, if a change happened, which makes oneshot possible.  *

12、  * Called cyclic from the hrtimer softirq (driven by the timer  * softirq) allow_nohz signals, that we can switch into low-res nohz  * mode, because high resolution timers are disabled (either compile  * or runtime).  */ int tick_check_oneshot_change(int allow_nohz) {     struct tick_sched *

13、ts = &__get_cpu_var(tick_cpu_sched);     if (!test_and_clear_bit(0, &ts->check_clocks))         return 0;     if (ts->nohz_mode != NOHZ_MODE_INACTIVE)         return 0;     if (!timekeeping_is_continuous() || !tick_is_oneshot_available())         return 0;     if (!allow_nohz)         return

14、 1;     tick_nohz_switch_to_nohz();                                //如果满足调节,切换到nohz     return 0; } /**  * tick_nohz_switch_to_nohz - switch to nohz mode  */ static void tick_nohz_switch_to_nohz(void) {     struct tick_sched *ts = &__get_cpu_var(tick_cpu_sched);     ktime_t next;     if (

15、tick_nohz_enabled)         return;     local_irq_disable();     if (tick_switch_to_oneshot(tick_nohz_handler)) {        //timer改成oneshot模式(一次性定时器),同时指定回调函数tick_nohz_handler         local_irq_enable();         return;     }     ts->nohz_mode = NOHZ_MODE_LOWRES;     /*      * Recycle the hrt

16、imer in ts, so we can share the      * hrtimer_forward with the highres code.      */     hrtimer_init(&ts->sched_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);     /* Get the next period */     next = tick_init_jiffy_update();     for (;;) {         ts->sched_timer.expires = next;         if (!

17、tick_program_event(next, 0))             break;         next = ktime_add(next, tick_period);     }     local_irq_enable();     printk(KERN_INFO "Switched to NOHz mode on CPU #%d\n",            smp_processor_id()); } /*  * The nohz low res interrupt handler  */ static void tick_nohz_handle

18、r(struct clock_event_device *dev) {     struct tick_sched *ts = &__get_cpu_var(tick_cpu_sched);     struct pt_regs *regs = get_irq_regs();     int cpu = smp_processor_id();     ktime_t now = ktime_get();     dev->next_event.tv64 = KTIME_MAX;     /*      * Check if the do_timer duty was dropp

19、ed. We don't care about      * concurrency: This happens only when the cpu in charge went      * into a long sleep. If two cpus happen to assign themself to      * this duty, then the jiffies update is still serialized by      * xtime_lock.      */     if (unlikely(tick_do_timer_cpu == -1))  

20、       tick_do_timer_cpu = cpu;     /* Check, if the jiffies need an update */     if (tick_do_timer_cpu == cpu)         tick_do_update_jiffies64(now);     /*      * When we are idle and the tick is stopped, we have to touch      * the watchdog as we might not schedule for a really long      

21、 time. This happens on complete idle SMP systems while      * waiting on the login prompt. We also increment the "start      * of idle" jiffy stamp so the idle accounting adjustment we      * do when we go busy again does not account too much ticks.      */     if (ts->tick_stopped) {         

22、                                   //idle的tick已经停止,替idle喂狗         touch_softlockup_watchdog();         ts->idle_jiffies++;     }     update_process_times(user_mode(regs));                            //在这里面调用进程调度的回调函数     profile_tick(CPU_PROFILING);     /* Do not restart, when we are in the i

23、dle loop */     if (ts->tick_stopped)         return;     while (tick_nohz_reprogram(ts, now)) {                            //重新设置定时器         now = ktime_get();         tick_do_update_jiffies64(now);                                //这里修改jiffies     } } //tick_sched结构 /**  * struct tick_sch

24、ed - sched tick emulation and no idle tick control/stats  * @sched_timer:    hrtimer to schedule the periodic tick in high  *            resolution mode  * @idle_tick:        Store the last idle tick expiry time when the tick  *            timer is modified for idle sleeps. This is necessary  *

25、            to resume the tick timer operation in the timeline  *            when the CPU returns from idle  * @tick_stopped:    Indicator that the idle tick has been stopped            //idle的tick已经停止  * @idle_jiffies:    jiffies at the entry to idle for idle time accounting  * @idle_calls:   

26、    Total number of idle calls  * @idle_sleeps:    Number of idle calls, where the sched tick was stopped  * @idle_entrytime:    Time when the idle call was entered  * @idle_sleeptime:    Sum of the time slept in idle with sched tick stopped  * @sleep_length:    Duration of the current idle slee

27、p  */ struct tick_sched {     struct hrtimer            sched_timer;     unsigned long            check_clocks;     enum tick_nohz_mode        nohz_mode;     ktime_t                idle_tick;     int                tick_stopped;     unsigned long            idle_jiffies;     unsigned long  

28、          idle_calls;     unsigned long            idle_sleeps;     ktime_t                idle_entrytime;     ktime_t                idle_sleeptime;     ktime_t                sleep_length;     unsigned long            last_jiffies;     unsigned long            next_jiffies;     ktime_t     

29、           idle_expires; }; /*  * Called from the timer interrupt handler to charge one tick to the current  * process.  user_tick is 1 if the tick is user time, 0 for system.  */ void update_process_times(int user_tick) {     struct task_struct *p = current;     int cpu = smp_processor_i

30、d();     /* Note: this timer irq context must be accounted for as well. */     account_process_tick(p, user_tick);     run_local_timers();     if (rcu_pending(cpu))         rcu_check_callbacks(cpu, user_tick);     scheduler_tick();                                                //每个tick一次进程调度

31、     run_posix_cpu_timers(p); } /*  * This function gets called by the timer code, with HZ frequency.  * We call it with interrupts disabled.  *  * It also gets called by the fork code, when changing the parent's  * timeslices.  */ void scheduler_tick(void) {     int cpu = smp_processor_i

32、d();     struct rq *rq = cpu_rq(cpu);     struct task_struct *curr = rq->curr;     u64 next_tick = rq->tick_timestamp + TICK_NSEC;     spin_lock(&rq->lock);     __update_rq_clock(rq);     /*      * Let rq->clock advance by at least TICK_NSEC:      */     if (unlikely(rq->clock < next_tick))

33、         rq->clock = next_tick;     rq->tick_timestamp = rq->clock;     update_cpu_load(rq);     if (curr != rq->idle) /* FIXME: needed? */         curr->sched_class->task_tick(rq, curr);        //普通进程tick调度:task_tick_fair;或者实时进程:task_tick_rt;或者task_tick_idle     spin_unlock(&rq->lock); #ifde

34、f CONFIG_SMP     rq->idle_at_tick = idle_cpu(cpu);     trigger_load_balance(rq, cpu); #endif } //每种进程调度策略都有这样一个结构体,下面是fair_sched_class,即普通进程调度策略 /*  * All the scheduling class methods:  */ static const struct sched_class fair_sched_class = {     .next            = &idle_sched_class,     .

35、enqueue_task        = enqueue_task_fair,     .dequeue_task        = dequeue_task_fair,     .yield_task        = yield_task_fair,     .check_preempt_curr    = check_preempt_wakeup,     .pick_next_task        = pick_next_task_fair,     .put_prev_task        = put_prev_task_fair, #ifdef CONFIG_SM

36、P     .load_balance        = load_balance_fair,     .move_one_task        = move_one_task_fair, #endif     .set_curr_task          = set_curr_task_fair,     .task_tick        = task_tick_fair,                //普通进程tick调度     .task_new        = task_new_fair, }; //就跟踪到这里。task_tick_fair和task_tick_rt以后再分析 窗体底端

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服