???Linux???????????????
???????????? ???????[ 2013/7/3 11:26:27 ] ????????
???????
????Linux??????????????????????????洢??????????????????????????ж??????????????????????????????????????????????????????????Linux???????н??????????????????????????????????????????????????????????????????????Щ?????????????????????0??????idle???????1??????init???? ??????????????????????????????????????????????
???????????е???????????????洢???????????????ú??????????????????????????????????????????????е?????У????????????????????????????????CPU?????????????????????????????С?Linux???????????????????????????????????????——>?ж?——>?????л?——>??????У???????????????й?????
????????????????????????????????е????????A??????У??????????????????á????????????????ж????????????????????????У????????SAVE_ALL?????????ж??????????ж????????л???????????????????????????????????????????н?????????????????л??????????е??????????B?????RESTORE_ALL??iret??????????????????????????????л????????????switch_to?????漰???????????仯??????????
???????
?????洢????????
?????洢???????????????????????????????????У??洢????洢???У??洢???????????????????????????????????????洢???е???????????????????????????????????????????????????????????????????????????????????????????
??????????????????
??????????????????????????????
?????ж????
????????????????????????????????????????????????ж?????????????ж???????????????????????????????????????????????????????ж??????????CPU??????????????????????飬?????л???????μ???????????????????????????????????????????????eip??cs?????????????????????ж????????????????????????????С?
?????????л?
????????????????У?????????????????????CPU????е????????????????????????????У???????????л????????л????????????????????schedule()????????????????????????л???????????
????1.?л???????????????μ??????
????2.?л???????????????????????????????????????????????????????????????????CPU????????
????????????????????????????????????н????????CPU???????????????????????????????????????????????????????????????
?????????л?????????switch_to????У??ú???????????????????prev??next????last?????У?prev????滻???????????????next???????????????????last??????????y???????????????л????????
????????switch_to?????????linux-3.2.1/arch/x86/include/asm/system.h????????????????
/*
* Saving eflags is important. It switches not only IOPL between tasks??
* it also protects other tasks from NT leaking through sysenter etc.
*/
#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
" /* save flags */
"pushl %%ebp
" /* save EBP */
"movl %%esp??%[prev_sp]
" /* save ESP */
"movl %[next_sp]??%%esp
" /* restore ESP */
"movl $1f??%[prev_ip]
" /* save EIP */
"pushl %[next_ip]
" /* restore EIP */
__switch_canary
"jmp __switch_to
" /* regparm call */
"1: "
"popl %%ebp
" /* restore EBP */
"popfl
" /* 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)
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11