MIT 6.828 jos/xv6 LAB4-PARTC

Source: Internet
Author: User

This section is for preemptive scheduling and interprocess communication

The preceding schedule is that the process resource discards the CPU, but in practice no process will do so, and in order to not let a process run out of CPU resources, preemptive scheduling is required, and hardware timing is required.

But the external hardware timing was closed during the bootloader, so far it has not been opened

The Jos strategy is that when the kernel is in the external interrupt is always closed, while in the user state, you need to turn on the interrupt

So first we need to change IDT, but I've got 256 of them before.

So now only need to enter the user state, to ensure that the external interrupt is enabled, in order to do this, the external interrupt can be enabled at the time each process is initialized to the location bit

In the Env_alloc of KERN/ENV.C

Now that the interrupt is enabled, the external interrupt will be generated and entered into the kernel while the user-state process is running, but there is no such interruption to handle now.

So we need to modify the Trap_dispatch to call the scheduler and dispatch another running process in the event of an external timing interrupt.

When running make Run-spin, always encountered a bug, found that the parent process call Sys_env_destroy failed to kill the process

Looking for a long while, found that the parameter passed in Sys_env_destroy is the process ID of the child process, and in the kernel system call Sys_env_destroy, but somehow became the process ID of the parent process, and finally found that the Syscall function was incorrectly written

The argument of this sentence should be A1, but I wrote the curenv->env_id

The problem is obviously self-lab3, but it's only now that it's wrong, and there's been no mistakes ...

Implementing IPC

IPC is a very important part of a computer system, and Jos chose a seemingly awkward way to achieve

Two processes need to communicate, one side to initiate recv, and then block until a process calls send information to the process being accepted, the blocked process will be awakened

In Jos, two kinds of information can be passed, one is a 32-bit integer, and the other is the mapping of the delivery page, in which the receiver and the sender are mapped to the same physical page at the same time, and memory sharing is realized.

These two functions are then implemented in the same system call

First look at the SYS_IPC_RECV function in the kernel. When a process tries to receive information, it should mark itself as receiving information, and in order not to waste CPU resources, it should also mark itself as env_not_runnable, and only if a process has sent the message to itself will it be resumed to run

After you mark yourself as not running, call the scheduler to run other processes

The implementation of the kernel in the sys_ipc_try_send is relatively troublesome, because there are a lot of detection items, including whether the permission to meet the requirements, to be transferred to the page is not, can you map this page to the other page table and so on

If SRCVA is under Utop, then to share memory, it is first to find the SRCVA corresponding page table entry in the sender's page table, and then insert the page table entry at the given virtual address of the receiving party.

Once received, re-set the current process to run and set env_ipc_recving to 0 to prevent other processes from being sent, overwriting the current content

The above two functions are system calls, and the function calls under the user state need to be implemented separately

At this point, the whole LAB4 to achieve the completion, good tired ...

MIT 6.828 jos/xv6 LAB4-PARTC

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.