mirror of
https://github.com/CoderSherlock/CoderSherlock.github.io.git
synced 2026-06-13 08:08:10 -07:00
Update the post for cs350's lab.
This commit is contained in:
@@ -1,28 +0,0 @@
|
||||
---
|
||||
title: "Lab transcripts of CS350 in Spring 2022"
|
||||
date: 2022-02-22 17:08:17 -0400
|
||||
tags: ["Xv6", "Teaching", "Operating system", "Binghamton university"]
|
||||
author: Pengzhan Hao
|
||||
cover: '/static/2022-02/BU.jpeg'
|
||||
---
|
||||
|
||||
This will be a series regarding lab I gave during the spring 2022 semester.
|
||||
|
||||
The reason why I am writing this down is because it has been a week and no students ask for the solution of the last Lab.
|
||||
I realise that learning gap between students are huge, especially when a non-profit university is admitting more and more students.
|
||||
To help all students in understanding concepts of modern OS, I decided to write this post.
|
||||
|
||||
It starts with the past lab content I have (as the skelton), and will be amended with extra materials I think it helps.
|
||||
Remember, it's for helping in learning. DON'T COPY & PASTE CODE!
|
||||
|
||||
## Index
|
||||
[Lab1: Introduction of Makefile and Xv6.](#lab1-introduction)
|
||||
[Lab3: System calls for process management.](#lab3-process)
|
||||
[Lab4: Inter-processes communication.](#lab4-ipc)
|
||||
|
||||
## Lab1-Introduction
|
||||
|
||||
## Lab3-Process
|
||||
|
||||
## Lab4-IPC
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
---
|
||||
title: "Labs of CS350"
|
||||
date: 2022-02-22 17:08:17 -0400
|
||||
tags: ["Xv6", "Teaching", "Operating system", "Binghamton university"]
|
||||
author: Pengzhan Hao
|
||||
cover: '/static/2022-02/BU.jpeg'
|
||||
---
|
||||
|
||||
This will be a series regarding lab I gave during the spring 2022 semester.
|
||||
|
||||
The reason why I am writing this down is because it has been a week and no students ask for the solution of the last Lab.
|
||||
I realise that learning gap between students are huge, especially when a non-profit university is admitting more and more students.
|
||||
To help all students in understanding concepts of modern OS, I decided to write this post.
|
||||
|
||||
It starts with the past lab content I have (as the skelton), and will be amended with extra materials I think it helps.
|
||||
Remember, it's for helping in learning. DON'T COPY & PASTE CODE!
|
||||
|
||||
## Index
|
||||
[Lab1: Introduction of Makefile and Xv6.](#lab1-introduction)
|
||||
[Lab3: System calls for process management.](#lab3-process)
|
||||
[Lab4: Inter-processes communication.](#lab4-ipc)
|
||||
[Lab6/7: CPU scheduling.](#lab6-7-scheduling)
|
||||
|
||||
## Lab1-Introduction
|
||||
|
||||
## Lab3-Process
|
||||
|
||||
## Lab4-IPC
|
||||
|
||||
## Lab6-7-Scheduling
|
||||
|
||||
### First user process in xv6
|
||||
In xv6, as the same as conventional linux OS, the very first user level process is **init**.
|
||||
Before **init**'s running, all the OS bootstraps are happened in a high privileged mode(kernel level).
|
||||
|
||||
Xv6's kernel has the entry point as the main function located in the file *main.c*.
|
||||
The main function invokes 17 functions to set up kernel page tables, interrupt handlers, I/O devices and etc.
|
||||
When all kernel preparations are done, by calling the function ***userinit()***, kernel will boot up process init.
|
||||
~~~c
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
kinit1(end, P2V(4*1024*1024)); // phys page allocator
|
||||
kvmalloc(); // kernel page table
|
||||
mpinit(); // collect info about this machine
|
||||
lapicinit();
|
||||
seginit(); // set up segments
|
||||
cprintf("\ncpu%d: starting xv6\n\n", cpu->id);
|
||||
picinit(); // interrupt controller
|
||||
ioapicinit(); // another interrupt controller
|
||||
consoleinit(); // I/O devices & their interrupts
|
||||
uartinit(); // serial port
|
||||
pinit(); // process table
|
||||
tvinit(); // trap vectors
|
||||
binit(); // buffer cache
|
||||
fileinit(); // file table
|
||||
ideinit(); // disk
|
||||
if(!ismp)
|
||||
timerinit(); // uniprocessor timer
|
||||
startothers(); // start other processors
|
||||
kinit2(P2V(4*1024*1024), P2V(PHYSTOP)); // must come after startothers()
|
||||
userinit(); // first user process
|
||||
// Finish setting up this processor in mpmain.
|
||||
mpmain();
|
||||
}
|
||||
~~~
|
||||
It's tricky since that **init** is a user process, but kernel can't call any user level system calls to create it.
|
||||
Why? 1. Kernel has all privileges to create a user process. So it doesn't need to call system calls such as ***fork()***.
|
||||
And 2. All other user processes can be created by forking from its parent.
|
||||
Forking including clone the whole user virtual memory layout. However, first process have no parent to fork from.
|
||||
That's why its makes the creation of the first user process becomes so unique.
|
||||
|
||||
In *proc.c*, ***userinit()*** define there gives us the whole procedure of creating **init**.
|
||||
Similar to the ***fork()***, but more simple.
|
||||
Process control block(structures for storing the process status) was created at the very first by calling ***allocproc()***.
|
||||
After then, by invoking ***setupkvm()***(defined in *vm.c*), kernel memory map was setup for the process.
|
||||
During setting up kernel memory map, a page size virtual memory will assigned to the process as ready.
|
||||
And later, this page size memory will be used to store instructions of **init**.
|
||||
|
||||
Followed by setup kernel stack for the **init** process, calling ***inituvm()*** will load **init**'s text into the page that just being allocated.
|
||||
***inituvm()*** takes 3 arguments: a pointer to the process's page directory (p->pgdir),
|
||||
a char-type pointer declared from external which point to **init**'s text segment(_binary_initcode_start), and
|
||||
a char-type pointer which point to an external integer as the size of the **init**'s text segment(_binary_initcode_size).
|
||||
Simply put, it will load instructions of **init** into the memory.
|
||||
|
||||
So now, the problem becomes when and where did instructions for **init** has compiled into the kernel?
|
||||
~~~c
|
||||
void
|
||||
userinit(void)
|
||||
{
|
||||
struct proc *p;
|
||||
extern char _binary_initcode_start[], _binary_initcode_size[];
|
||||
|
||||
p = allocproc();
|
||||
initproc = p;
|
||||
if((p->pgdir = setupkvm()) == 0)
|
||||
panic("userinit: out of memory?");
|
||||
inituvm(p->pgdir, _binary_initcode_start, (int)_binary_initcode_size);
|
||||
p->sz = PGSIZE;
|
||||
memset(p->tf, 0, sizeof(*p->tf));
|
||||
p->tf->cs = (SEG_UCODE << 3) | DPL_USER;
|
||||
p->tf->ds = (SEG_UDATA << 3) | DPL_USER;
|
||||
p->tf->es = p->tf->ds;
|
||||
p->tf->ss = p->tf->ds;
|
||||
p->tf->eflags = FL_IF;
|
||||
p->tf->esp = PGSIZE;
|
||||
p->tf->eip = 0; // beginning of initcode.S
|
||||
|
||||
safestrcpy(p->name, "initcode", sizeof(p->name));
|
||||
p->cwd = namei("/");
|
||||
|
||||
p->state = RUNNABLE;
|
||||
}
|
||||
~~~
|
||||
If you search the keyword "_binary_initcode_start" in the source code, you can't find any references.
|
||||
The clue comes from the *Makefile*.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -460,7 +460,7 @@ c13 9 26 20 30 26 7 11 -9 26 -27 26 -5 0 -3 -5 5 -10 9 -6 10 -10 3 -10 -24
|
||||
</li></ul>
|
||||
</div>
|
||||
<div class="js-result layout--archive__result d-none"><div class="article-list items"><section><h2 class="article-list__group-header">2022</h2><ul class="items"><li class="item" itemscope itemtype="http://schema.org/BlogPosting" data-tags="Xv6,Teaching,Operating+system,Binghamton+university">
|
||||
<div class="item__content"><span class="item__meta">Feb 22</span><a itemprop="headline" class="item__header" href="/posts/22s-cs350-labs">Lab transcripts of CS350 in Spring 2022</a></div>
|
||||
<div class="item__content"><span class="item__meta">Feb 22</span><a itemprop="headline" class="item__header" href="/posts/cs350-labs">Labs of CS350</a></div>
|
||||
</li></ul></section><section><h2 class="article-list__group-header">2021</h2><ul class="items"><li class="item" itemscope itemtype="http://schema.org/BlogPosting" data-tags="Research,Edge+computing">
|
||||
<div class="item__content"><span class="item__meta">Oct 31</span><a itemprop="headline" class="item__header" href="/posts/eddl-how-do-we-train-on-limited-edge-devices-part2">EDDL: How do we train neural networks on limited edge devices - PART 2</a></div>
|
||||
</li><li class="item" itemscope itemtype="http://schema.org/BlogPosting" data-tags="Research,Edge+computing">
|
||||
|
||||
@@ -1 +1 @@
|
||||
window.TEXT_SEARCH_DATA={'posts':[{'title':"Stop Talking is the worst title of one blog",'url':"/posts/welcome-to-my-blog"},{'title':"Using charles proxy to monitor mobile SSL traffics",'url':"/posts/charles-is-not-a-good-tool"},{'title':"Some of my previews experiment works: 2016",'url':"/posts/some-of-my-previews-exper-work"},{'title':"Xv6 introduction",'url':"/posts/intro-xv6"},{'title':"Generate Word Cloud Figures with Chinese-Tokenization and WordCloud python libraries",'url':"/posts/generate-word-cloud-with-chinese-fenci"},{'title':"EDDL: How do we train neural networks on limited edge devices - PART 1",'url':"/posts/eddl-how-do-we-train-on-limited-edge-devices"},{'title':"EDDL: How do we train neural networks on limited edge devices - PART 2",'url':"/posts/eddl-how-do-we-train-on-limited-edge-devices-part2"},{'title':"Lab transcripts of CS350 in Spring 2022",'url':"/posts/22s-cs350-labs"}]};
|
||||
window.TEXT_SEARCH_DATA={'posts':[{'title':"Stop Talking is the worst title of one blog",'url':"/posts/welcome-to-my-blog"},{'title':"Using charles proxy to monitor mobile SSL traffics",'url':"/posts/charles-is-not-a-good-tool"},{'title':"Some of my previews experiment works: 2016",'url':"/posts/some-of-my-previews-exper-work"},{'title':"Xv6 introduction",'url':"/posts/intro-xv6"},{'title':"Generate Word Cloud Figures with Chinese-Tokenization and WordCloud python libraries",'url':"/posts/generate-word-cloud-with-chinese-fenci"},{'title':"EDDL: How do we train neural networks on limited edge devices - PART 1",'url':"/posts/eddl-how-do-we-train-on-limited-edge-devices"},{'title':"EDDL: How do we train neural networks on limited edge devices - PART 2",'url':"/posts/eddl-how-do-we-train-on-limited-edge-devices-part2"},{'title':"Labs of CS350",'url':"/posts/cs350-labs"}]};
|
||||
|
||||
+91
-4
File diff suppressed because one or more lines are too long
+2
-2
@@ -416,12 +416,12 @@ c13 9 26 20 30 26 7 11 -9 26 -27 26 -5 0 -3 -5 5 -10 9 -6 10 -10 3 -10 -24
|
||||
|
||||
<!-- end custom main top snippet -->
|
||||
<article itemscope itemtype="http://schema.org/WebPage"><header style="display:none;"><h1>Home</h1></header><meta itemprop="headline" content="Home"><meta itemprop="author" content="Pengzhan Hao"/><div class="js-article-content"><div class="layout--articles"><div class="article-list items items--divided"><article class="item" itemscope itemtype="http://schema.org/BlogPosting"><div class="item__image" style="vertical-align: middle"><img class="image" src="/static/2022-02/BU.jpeg" /></div><div class="item__content">
|
||||
<header><a href="/posts/22s-cs350-labs"><h2 itemprop="headline" class="item__header">Lab transcripts of CS350 in Spring 2022</h2></a></header>
|
||||
<header><a href="/posts/cs350-labs"><h2 itemprop="headline" class="item__header">Labs of CS350</h2></a></header>
|
||||
<div class="item__description"><div class="article__content" itemprop="description articleBody">This will be a series regarding lab I gave during the spring 2022 semester.
|
||||
|
||||
The reason why I am writing this down is because it has been a week and no students ask for the solution of the last Lab.
|
||||
I realise that learning gap between students are huge, especially when a non-profit university is admitting more and more students.
|
||||
To help all stud...</div><p><a href="/posts/22s-cs350-labs">Read more</a></p></div><div class="article__info clearfix"><ul class="left-col menu"><li>
|
||||
To help all stud...</div><p><a href="/posts/cs350-labs">Read more</a></p></div><div class="article__info clearfix"><ul class="left-col menu"><li>
|
||||
<a class="button button--secondary button--pill button--sm"
|
||||
href="/archive.html?tag=Xv6">Xv6</a>
|
||||
</li><li>
|
||||
|
||||
@@ -536,7 +536,7 @@ We chose the Dlib library because it is written in C/C++, and can be easily and
|
||||
<!-- end custom article footer snippet -->
|
||||
<div class="article__subscribe"><div class="subscribe"><i class="fas fa-rss"></i> <a type="application/rss+xml" href="/feed.xml">Subscribe</a></div>
|
||||
</div><div class="article__license"></div></footer>
|
||||
<div class="article__section-navigator clearfix"><div class="previous"><span>PREVIOUS</span><a href="/posts/eddl-how-do-we-train-on-limited-edge-devices">EDDL: How do we train neural networks on limited edge devices - PART 1</a></div><div class="next"><span>NEXT</span><a href="/posts/22s-cs350-labs">Lab transcripts of CS350 in Spring 2022</a></div></div></div>
|
||||
<div class="article__section-navigator clearfix"><div class="previous"><span>PREVIOUS</span><a href="/posts/eddl-how-do-we-train-on-limited-edge-devices">EDDL: How do we train neural networks on limited edge devices - PART 1</a></div><div class="next"><span>NEXT</span><a href="/posts/cs350-labs">Labs of CS350</a></div></div></div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@
|
||||
<lastmod>2021-10-31T13:01:14-04:00</lastmod>
|
||||
</url>
|
||||
<url>
|
||||
<loc>http://localhost:4000/posts/22s-cs350-labs</loc>
|
||||
<loc>http://localhost:4000/posts/cs350-labs</loc>
|
||||
<lastmod>2022-02-22T16:08:17-05:00</lastmod>
|
||||
</url>
|
||||
<url>
|
||||
|
||||
Reference in New Issue
Block a user