커널에서 콘텍스트 스위칭에 대해서 질문있습니다.
A 프로세스가 B 프로세스로 전환하려고 할때
A프로세스가 사용하던 레지스터들을 모두 저장하고
B프로세스의 저장한 레지스터값을 다시 세팅해줘야 되는걸로 알고있습니다.
그리고 요즘(2.4부터인가...)에는 이런 코드를 소프트웨어적으로 구현한다고 알고있는데요..
mov를 사용한 코드를 찾지 못하겠네요..
schedule() -> context_switch() ->switch_to()->__switch_to()
이렇게 봤는데 없습니다....
__switch_to 도 mov같은건 없구요......
어디서 찾을수있을까요?
아니면 아직까지 하드웨어에 의존하나요??
574 struct task_struct fastcall * __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
575 {
576 struct thread_struct *prev = &prev_p->thread,
577 *next = &next_p->thread;
578 int cpu = smp_processor_id();
579 struct tss_struct *tss = &per_cpu(init_tss, cpu);
580
581 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
582
583 __unlazy_fpu(prev_p);
584
585 /*
586 * Reload esp0, LDT and the page table pointer:
587 */
588 load_esp0(tss, next);
589
590 /*
591 * Load the per-thread Thread-Local Storage descriptor.
592 */
593 load_TLS(next, cpu);
594
595 /*
596 * Save away %fs and %gs. No need to save %es and %ds, as
597 * those are always kernel segments while inside the kernel.
598 */
599 asm volatile("movl %%fs,%0":"=m" (*(int *)&prev->fs));
600 asm volatile("movl %%gs,%0":"=m" (*(int *)&prev->gs));
601
602 /*
603 * Restore %fs and %gs if needed.
604 */
605 if (unlikely(prev->fs | prev->gs | next->fs | next->gs)) {
606 loadsegment(fs, next->fs);
607 loadsegment(gs, next->gs);
608 }
609
610 /*
611 * Now maybe reload the debug registers
612 */
613 if (unlikely(next->debugreg[7])) {
614 loaddebug(next, 0);
615 loaddebug(next, 1);
616 loaddebug(next, 2);
617 loaddebug(next, 3);
618 /* no 4 and 5 */
619 loaddebug(next, 6);
620 loaddebug(next, 7);
621 }
622
623 if (unlikely(prev->io_bitmap_ptr || next->io_bitmap_ptr))
624 handle_io_bitmap(next, tss);
625
626 return prev_p;
627 }
댓글 달기