免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
楼主: blake326

[进程管理] switch_to 之前不需要保存 寄存器么,eax,ebx,edx,之类的。 [复制链接]

论坛徽章:
0
发表于 2012-05-29 17:20 |显示全部楼层
本帖最后由 blake326 于 2012-05-29 17:22 编辑

回复 10# 瀚海书香

switch的源码是这个:
它定义了ebx, ecx, edx, esi, edi几个局部变量(prev的内核栈上),然后output写到了这些上面。是不是这样保存的?
但是具体这个内联汇编的流程看得不懂我。
到底什么时候写这个局部变量的?
1:标记之前。prev还在cpu上执行。
1:标记之后,prev恢复cpu执行了。

很纠结的样子。


    #define switch_to(prev, next, last)                                        \
do {                                                                        \
        /*                                                                \
         * Context-switching clobbers all registers, so we clobber        \
         * them explicitly, via unused output variables.                \
         * (EAX and EBP is not listed because EBP is saved/restored        \
         * explicitly for wchan access and EAX is the return value of        \
         * __switch_to())                                                \
         */                                                                \
        unsigned long ebx, ecx, edx, esi, edi;                                \
                                                                        \
        asm volatile("pushfl\n\t"                /* save    flags */        \
                     "pushl %%ebp\n\t"                /* save    EBP   */        \
                     "movl %%esp,%[prev_sp]\n\t"        /* save    ESP   */ \
                     "movl %[next_sp],%%esp\n\t"        /* restore ESP   */ \
                     "movl $1f,%[prev_ip]\n\t"        /* save    EIP   */        \
                     "pushl %[next_ip]\n\t"        /* restore EIP   */        \
                     __switch_canary                                        \
                     "jmp __switch_to\n"        /* regparm call  */        \
                     "1:\t"                                                \
                     "popl %%ebp\n\t"                /* restore EBP   */        \
                     "popfl\n"                        /* restore flags */        \
                                                                        \
                     /* output parameters */                                \
                     : [prev_sp] "=m" (prev->thread.sp),                \
                       [prev_ip] "=m" (prev->thread.ip),                \
                       "=a" (last),                                        \
                                                                        \
                       /* clobbered output registers: */                \
                       "=b" (ebx), "=c" (ecx), "=d" (edx),                \
                       "=S" (esi), "=D" (edi)                                \
                                                                               \
                       __switch_canary_oparam                                \
                                                                        \
                       /* input parameters: */                                \
                     : [next_sp]  "m" (next->thread.sp),                \
                       [next_ip]  "m" (next->thread.ip),                \
                                                                               \
                       /* regparm parameters for __switch_to(): */        \
                       [prev]     "a" (prev),                                \
                       [next]     "d" (next)                                \
                                                                        \
                       __switch_canary_iparam                                \
                                                                        \
                     : /* reloaded segment registers */                        \
                        "memory");                                        \
} while (0)


另外我objdump -S sched.o 的结果, 没有看到这个输出ebx, ecx, edx, esi, edi的过程:
45658 #ifndef __ARCH_WANT_UNLOCKED_CTXSW
45659     spin_release(&rq->lock.dep_map, 1, _THIS_IP_);
45660  8d2:   8d 43 10                lea    0x10(%ebx),%eax
45661  8d5:   b9 d2 08 00 00          mov    $0x8d2,%ecx
45662  8da:   ba 01 00 00 00          mov    $0x1,%edx
45663  8df:   e8 fc ff ff ff          call   8e0 <schedule+0x624>
45664 #endif
45665
45666     /* Here we just switch the register state and the stack. */
45667     switch_to(prev, next, prev);
45668  8e4:   8b 45 a8                mov    -0x58(%ebp),%eax
45669  8e7:   89 fa                   mov    %edi,%edx
45670  8e9:   9c                      pushf
45671  8ea:   55                      push   %ebp
45672  8eb:   89 a0 08 03 00 00       mov    %esp,0x308(%eax)
45673  8f1:   8b a7 08 03 00 00       mov    0x308(%edi),%esp
45674  8f7:   c7 80 10 03 00 00 0c    movl   $0x90c,0x310(%eax)
45675  8fe:   09 00 00
45676  901:   ff b7 10 03 00 00       pushl  0x310(%edi)
45677  907:   e9 fc ff ff ff          jmp    908 <schedule+0x64c>
45678  90c:   5d                      pop    %ebp
45679  90d:   9d                      popf
45680  90e:   89 45 a0                mov    %eax,-0x60(%ebp)
45681     /*
45682      * this_rq must be evaluated again because prev may have moved
45683      * CPUs since it called schedule(), thus the 'rq' on its stack
45684      * frame will be invalid.
45685      */
45686     finish_task_switch(this_rq(), prev);

论坛徽章:
0
发表于 2012-05-30 15:14 |显示全部楼层
死锁了吗?
sleep了一天都没有回复~~~~~~~~~~~~~~

论坛徽章:
0
发表于 2012-05-31 18:09 |显示全部楼层
顶~
顶~顶~
顶~顶~顶~

论坛徽章:
16
2015亚冠之吉达阿赫利
日期:2015-08-17 11:21:462015年迎新春徽章
日期:2015-03-04 09:58:11酉鸡
日期:2014-12-07 09:06:19水瓶座
日期:2014-11-04 14:23:29天秤座
日期:2014-03-02 08:57:52双鱼座
日期:2014-02-22 13:07:56午马
日期:2014-02-14 11:08:18双鱼座
日期:2014-02-13 11:09:37卯兔
日期:2014-02-06 15:10:34子鼠
日期:2014-01-20 14:48:19戌狗
日期:2013-12-19 09:37:46射手座
日期:2013-12-19 09:33:47
发表于 2012-05-31 22:22 |显示全部楼层
友情帮顶!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP