First assignment: In-depth source analysis XV6 Process model

Source: Internet
Author: User

1. Process

1.1 Concept of the process

1) narrowly defined: a process is an instance of a running program.

2) Generalized definition: A process is a program with a certain independent function on a data set of a running activity. It is the basic unit of the operating system dynamic execution, in the traditional operating system, the process is not only the basic allocation unit, but also the basic execution unit.

1.2 Composition of the process

1.3 Process Control block


Citations from: 54847732

2. How the operating system organizes processes

    • The organization process is understood here as the management and control process
    • The operating system manages and controls processes through the PCB, and each process is created with a PCB generated by the operating system and a unique process through a unique PID, the status of the process can be understood through the PCB, and when the process ends, the operating system destroys the PCB for the process.
    • XV6PCB structure, see appendix

3. How process status is converted

4. How the process is scheduled

The current process switches the process by calling the yield function. The yield function calls the Sched function, and the Sched function starts the Swtch function to complete the process switch. The whole process is this:

yield = Sched => Swtch

Sched is a dead loop that constantly scans the process table and selects a runnable process schedule, which is the transition from the scheduler switch to the newly selected process

Swatch function Task: 1. Saves the context of the current (old) process. 2. Load the new process context into the machine register.

Reference URL: 61615603

function See appendix

5. Talk about your view of the operating system process model

In the learning process part, did not pay attention to the job requirements, more focus on the machine power to the process of creating parts, real mode and protection mode and other parts of the computer's general situation has a further understanding, and did not pay attention to the process of scheduling this piece, so hastily supplemented this piece of knowledge, the dispatch has no profound experience.

Attach some reading notes, see Appendix.

6. References

    • Https://legacy.gitbook.com/book/th0ar/xv6-chinese/details
    • Https://pdos.csail.mit.edu/6.828/2012/xv6/xv6-rev7.pdf
    • Https://pdos.csail.mit.edu/6.828/2012/xv6/book-rev7.pdf

7. Appendix

    • PCB Structure

struct Proc {

UINT SZ; Memory size of the process (in bytes)
pde_t* Pgdir; The linear address of the process page path.
Char *kstack; Kernel stack bottom of the process
Enum Procstate State; Process status
volatile int pid; Process ID
struct proc *parent; Parent process
struct Trapframe *tf; Interrupt frame for current system call
struct context *context; The entry for the process to run
int killed; When not 0 o'clock, indicates that it has ended
struct file *ofile[nofile]; List of open files
struct Inode *cwd; Process current Path
Char name[16]; Process Name
};

    • void Scheduler (void)

{

struct proc *p;

for (;;)

{

Enable interrupts on the this processor.

STI ();

Loop over process table looking for process to run.

Acquire (&ptable.lock);

For (p = ptable. Proc P < &ptable. Proc[nproc]; p++)

{

if (p->state! = RUNNABLE)

Continue

Switch to chosen process. It is the process ' s job

To release Ptable.lock and then reacquire it

< Span class= "hljs-comment" >< Span class= "Hljs-keyword" >< Span class= "hljs-comment" >//before jumping back to us. proc = p;

< Span class= "hljs-comment" >< Span class= "Hljs-keyword" >< Span class= "hljs-comment" > SWITCHUVM (p); p->state = RUNNING;

< Span class= "hljs-comment" >< Span class= "Hljs-keyword" >< Span class= "hljs-comment" >swtch (&cpu->scheduler, Span class= "Hljs-keyword" >proc->context);

< Span class= "hljs-comment" >< Span class= "Hljs-keyword" >< Span class= "hljs-comment" > SWITCHKVM (); //Process is do running for now.

< Span class= "hljs-comment" >< Span class= "Hljs-keyword" >< Span class= "hljs-comment" >< Span class= "hljs-comment" > //It should has changed its p->state before coming back.

< Span class= "hljs-comment" >< Span class= "Hljs-keyword" >< Span class= "hljs-comment" >< Span class= "hljs-comment" >proc = 0;

< Span class= "hljs-comment" >< Span class= "Hljs-keyword" >< Span class= "hljs-comment" >< Span class= "hljs-comment" >}

< Span class= "hljs-comment" >< Span class= "Hljs-keyword" >< Span class= "hljs-comment" >< Span class= "hljs-comment" > Release (&ptable.lock);

< Span class= "hljs-comment" >< Span class= "Hljs-keyword" >< Span class= "hljs-comment" >< Span class= "hljs-comment" >}

}

    • The function code for Swtch is as follows

First assignment: In-depth source analysis XV6 Process model

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.