From 1e3e7ec54f38e132cce357969d338ddc98d1d607 Mon Sep 17 00:00:00 2001 From: CoderSherlock Date: Thu, 24 Mar 2022 22:47:54 -0400 Subject: [PATCH] Update the post for cs350's lab. --- _posts/2022-02-22-22s-cs350-labs.md | 28 ---- _posts/2022-02-22-cs350-labs.md | 121 ++++++++++++++++++ _site/archive.html | 2 +- _site/assets/search.js | 2 +- _site/feed.xml | 95 +++++++++++++- _site/index.html | 4 +- ...e-train-on-limited-edge-devices-part2.html | 2 +- _site/sitemap.xml | 2 +- 8 files changed, 218 insertions(+), 38 deletions(-) delete mode 100644 _posts/2022-02-22-22s-cs350-labs.md create mode 100644 _posts/2022-02-22-cs350-labs.md diff --git a/_posts/2022-02-22-22s-cs350-labs.md b/_posts/2022-02-22-22s-cs350-labs.md deleted file mode 100644 index cbd6172..0000000 --- a/_posts/2022-02-22-22s-cs350-labs.md +++ /dev/null @@ -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 - diff --git a/_posts/2022-02-22-cs350-labs.md b/_posts/2022-02-22-cs350-labs.md new file mode 100644 index 0000000..a78dd84 --- /dev/null +++ b/_posts/2022-02-22-cs350-labs.md @@ -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*. + + + + + diff --git a/_site/archive.html b/_site/archive.html index aebc356..0aacefd 100644 --- a/_site/archive.html +++ b/_site/archive.html @@ -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

2022

2021

  • diff --git a/_site/assets/search.js b/_site/assets/search.js index aa3ec2e..3ff95fb 100644 --- a/_site/assets/search.js +++ b/_site/assets/search.js @@ -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"}]}; diff --git a/_site/feed.xml b/_site/feed.xml index e0a5d12..e64609d 100644 --- a/_site/feed.xml +++ b/_site/feed.xml @@ -1,5 +1,5 @@ -Jekyll2022-02-22T17:57:36-05:00http://localhost:4000/feed.xmlStop Talking, Start DoingMy personal blog, with some boring research staff and some tricks I was fancy to. I'll try my best to make this blog fun and useful. Not just a place I complain about all happens in my Lab. -Pengzhan Haohaopengzhan@gmail.comLab transcripts of CS350 in Spring 20222022-02-22T16:08:17-05:002022-02-22T16:08:17-05:00http://localhost:4000/posts/22s-cs350-labs<p>This will be a series regarding lab I gave during the spring 2022 semester.</p> +Jekyll2022-03-24T22:47:03-04:00http://localhost:4000/feed.xmlStop Talking, Start DoingMy personal blog, with some boring research staff and some tricks I was fancy to. I'll try my best to make this blog fun and useful. Not just a place I complain about all happens in my Lab. +Pengzhan Haohaopengzhan@gmail.comLabs of CS3502022-02-22T16:08:17-05:002022-02-22T16:08:17-05:00http://localhost:4000/posts/cs350-labs<p>This will be a series regarding lab I gave during the spring 2022 semester.</p> <p>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. @@ -11,13 +11,100 @@ Remember, it’s for helping in learning. DON’T COPY &amp; PASTE CODE!< <h2 id="index">Index</h2> <p><a href="#lab1-introduction">Lab1: Introduction of Makefile and Xv6.</a><br /> <a href="#lab3-process">Lab3: System calls for process management.</a><br /> -<a href="#lab4-ipc">Lab4: Inter-processes communication.</a></p> +<a href="#lab4-ipc">Lab4: Inter-processes communication.</a><br /> +<a href="#lab6-7-scheduling">Lab6/7: CPU scheduling.</a></p> <h2 id="lab1-introduction">Lab1-Introduction</h2> <h2 id="lab3-process">Lab3-Process</h2> -<h2 id="lab4-ipc">Lab4-IPC</h2>Pengzhan HaoThis 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 &amp; PASTE CODE! Index Lab1: Introduction of Makefile and Xv6. Lab3: System calls for process management. Lab4: Inter-processes communication. Lab1-Introduction Lab3-Process Lab4-IPCEDDL: How do we train neural networks on limited edge devices - PART 22021-10-31T13:01:14-04:002021-10-31T13:01:14-04:00http://localhost:4000/posts/eddl-how-do-we-train-on-limited-edge-devices-part2<p>In the last post, part1, our idea of distributed learning on edge environment was generally addressed. +<h2 id="lab4-ipc">Lab4-IPC</h2> + +<h2 id="lab6-7-scheduling">Lab6-7-Scheduling</h2> + +<h3 id="first-user-process-in-xv6">First user process in xv6</h3> +<p>In xv6, as the same as conventional linux OS, the very first user level process is <strong>init</strong>. +Before <strong>init</strong>’s running, all the OS bootstraps are happened in a high privileged mode(kernel level).</p> + +<p>Xv6’s kernel has the entry point as the main function located in the file <em>main.c</em>. +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 <strong><em>userinit()</em></strong>, kernel will boot up process init.</p> +<div class="language-c highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kt">int</span> +<span class="nf">main</span><span class="p">(</span><span class="kt">void</span><span class="p">)</span> +<span class="p">{</span> + <span class="n">kinit1</span><span class="p">(</span><span class="n">end</span><span class="p">,</span> <span class="n">P2V</span><span class="p">(</span><span class="mi">4</span><span class="o">*</span><span class="mi">1024</span><span class="o">*</span><span class="mi">1024</span><span class="p">));</span> <span class="c1">// phys page allocator</span> + <span class="n">kvmalloc</span><span class="p">();</span> <span class="c1">// kernel page table</span> + <span class="n">mpinit</span><span class="p">();</span> <span class="c1">// collect info about this machine</span> + <span class="n">lapicinit</span><span class="p">();</span> + <span class="n">seginit</span><span class="p">();</span> <span class="c1">// set up segments</span> + <span class="n">cprintf</span><span class="p">(</span><span class="s">"</span><span class="se">\n</span><span class="s">cpu%d: starting xv6</span><span class="se">\n\n</span><span class="s">"</span><span class="p">,</span> <span class="n">cpu</span><span class="o">-&gt;</span><span class="n">id</span><span class="p">);</span> + <span class="n">picinit</span><span class="p">();</span> <span class="c1">// interrupt controller</span> + <span class="n">ioapicinit</span><span class="p">();</span> <span class="c1">// another interrupt controller</span> + <span class="n">consoleinit</span><span class="p">();</span> <span class="c1">// I/O devices &amp; their interrupts</span> + <span class="n">uartinit</span><span class="p">();</span> <span class="c1">// serial port</span> + <span class="n">pinit</span><span class="p">();</span> <span class="c1">// process table</span> + <span class="n">tvinit</span><span class="p">();</span> <span class="c1">// trap vectors</span> + <span class="n">binit</span><span class="p">();</span> <span class="c1">// buffer cache</span> + <span class="n">fileinit</span><span class="p">();</span> <span class="c1">// file table</span> + <span class="n">ideinit</span><span class="p">();</span> <span class="c1">// disk</span> + <span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="n">ismp</span><span class="p">)</span> + <span class="n">timerinit</span><span class="p">();</span> <span class="c1">// uniprocessor timer</span> + <span class="n">startothers</span><span class="p">();</span> <span class="c1">// start other processors</span> + <span class="n">kinit2</span><span class="p">(</span><span class="n">P2V</span><span class="p">(</span><span class="mi">4</span><span class="o">*</span><span class="mi">1024</span><span class="o">*</span><span class="mi">1024</span><span class="p">),</span> <span class="n">P2V</span><span class="p">(</span><span class="n">PHYSTOP</span><span class="p">));</span> <span class="c1">// must come after startothers()</span> + <span class="n">userinit</span><span class="p">();</span> <span class="c1">// first user process</span> + <span class="c1">// Finish setting up this processor in mpmain.</span> + <span class="n">mpmain</span><span class="p">();</span> +<span class="p">}</span> +</code></pre></div></div> +<p>It’s tricky since that <strong>init</strong> 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 <strong><em>fork()</em></strong>. +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.</p> + +<p>In <em>proc.c</em>, <strong><em>userinit()</em></strong> define there gives us the whole procedure of creating <strong>init</strong>. +Similar to the <strong><em>fork()</em></strong>, but more simple. +Process control block(structures for storing the process status) was created at the very first by calling <strong><em>allocproc()</em></strong>. +After then, by invoking <strong><em>setupkvm()</em></strong>(defined in <em>vm.c</em>), 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 <strong>init</strong>.</p> + +<p>Followed by setup kernel stack for the <strong>init</strong> process, calling <strong><em>inituvm()</em></strong> will load <strong>init</strong>’s text into the page that just being allocated. +<strong><em>inituvm()</em></strong> takes 3 arguments: a pointer to the process’s page directory (p-&gt;pgdir), +a char-type pointer declared from external which point to <strong>init</strong>’s text segment(_binary_initcode_start), and +a char-type pointer which point to an external integer as the size of the <strong>init</strong>’s text segment(_binary_initcode_size). +Simply put, it will load instructions of <strong>init</strong> into the memory.</p> + +<p>So now, the problem becomes when and where did instructions for <strong>init</strong> has compiled into the kernel?</p> +<div class="language-c highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kt">void</span> +<span class="nf">userinit</span><span class="p">(</span><span class="kt">void</span><span class="p">)</span> +<span class="p">{</span> + <span class="k">struct</span> <span class="n">proc</span> <span class="o">*</span><span class="n">p</span><span class="p">;</span> + <span class="k">extern</span> <span class="kt">char</span> <span class="n">_binary_initcode_start</span><span class="p">[],</span> <span class="n">_binary_initcode_size</span><span class="p">[];</span> + + <span class="n">p</span> <span class="o">=</span> <span class="n">allocproc</span><span class="p">();</span> + <span class="n">initproc</span> <span class="o">=</span> <span class="n">p</span><span class="p">;</span> + <span class="k">if</span><span class="p">((</span><span class="n">p</span><span class="o">-&gt;</span><span class="n">pgdir</span> <span class="o">=</span> <span class="n">setupkvm</span><span class="p">())</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span> + <span class="n">panic</span><span class="p">(</span><span class="s">"userinit: out of memory?"</span><span class="p">);</span> + <span class="n">inituvm</span><span class="p">(</span><span class="n">p</span><span class="o">-&gt;</span><span class="n">pgdir</span><span class="p">,</span> <span class="n">_binary_initcode_start</span><span class="p">,</span> <span class="p">(</span><span class="kt">int</span><span class="p">)</span><span class="n">_binary_initcode_size</span><span class="p">);</span> + <span class="n">p</span><span class="o">-&gt;</span><span class="n">sz</span> <span class="o">=</span> <span class="n">PGSIZE</span><span class="p">;</span> + <span class="n">memset</span><span class="p">(</span><span class="n">p</span><span class="o">-&gt;</span><span class="n">tf</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="o">*</span><span class="n">p</span><span class="o">-&gt;</span><span class="n">tf</span><span class="p">));</span> + <span class="n">p</span><span class="o">-&gt;</span><span class="n">tf</span><span class="o">-&gt;</span><span class="n">cs</span> <span class="o">=</span> <span class="p">(</span><span class="n">SEG_UCODE</span> <span class="o">&lt;&lt;</span> <span class="mi">3</span><span class="p">)</span> <span class="o">|</span> <span class="n">DPL_USER</span><span class="p">;</span> + <span class="n">p</span><span class="o">-&gt;</span><span class="n">tf</span><span class="o">-&gt;</span><span class="n">ds</span> <span class="o">=</span> <span class="p">(</span><span class="n">SEG_UDATA</span> <span class="o">&lt;&lt;</span> <span class="mi">3</span><span class="p">)</span> <span class="o">|</span> <span class="n">DPL_USER</span><span class="p">;</span> + <span class="n">p</span><span class="o">-&gt;</span><span class="n">tf</span><span class="o">-&gt;</span><span class="n">es</span> <span class="o">=</span> <span class="n">p</span><span class="o">-&gt;</span><span class="n">tf</span><span class="o">-&gt;</span><span class="n">ds</span><span class="p">;</span> + <span class="n">p</span><span class="o">-&gt;</span><span class="n">tf</span><span class="o">-&gt;</span><span class="n">ss</span> <span class="o">=</span> <span class="n">p</span><span class="o">-&gt;</span><span class="n">tf</span><span class="o">-&gt;</span><span class="n">ds</span><span class="p">;</span> + <span class="n">p</span><span class="o">-&gt;</span><span class="n">tf</span><span class="o">-&gt;</span><span class="n">eflags</span> <span class="o">=</span> <span class="n">FL_IF</span><span class="p">;</span> + <span class="n">p</span><span class="o">-&gt;</span><span class="n">tf</span><span class="o">-&gt;</span><span class="n">esp</span> <span class="o">=</span> <span class="n">PGSIZE</span><span class="p">;</span> + <span class="n">p</span><span class="o">-&gt;</span><span class="n">tf</span><span class="o">-&gt;</span><span class="n">eip</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="c1">// beginning of initcode.S</span> + + <span class="n">safestrcpy</span><span class="p">(</span><span class="n">p</span><span class="o">-&gt;</span><span class="n">name</span><span class="p">,</span> <span class="s">"initcode"</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">p</span><span class="o">-&gt;</span><span class="n">name</span><span class="p">));</span> + <span class="n">p</span><span class="o">-&gt;</span><span class="n">cwd</span> <span class="o">=</span> <span class="n">namei</span><span class="p">(</span><span class="s">"/"</span><span class="p">);</span> + + <span class="n">p</span><span class="o">-&gt;</span><span class="n">state</span> <span class="o">=</span> <span class="n">RUNNABLE</span><span class="p">;</span> +<span class="p">}</span> +</code></pre></div></div> +<p>If you search the keyword “_binary_initcode_start” in the source code, you can’t find any references. +The clue comes from the <em>Makefile</em>.</p>Pengzhan HaoThis 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 &amp; PASTE CODE! Index Lab1: Introduction of Makefile and Xv6. Lab3: System calls for process management. Lab4: Inter-processes communication. Lab6/7: CPU 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. 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-&gt;id); picinit(); // interrupt controller ioapicinit(); // another interrupt controller consoleinit(); // I/O devices &amp; 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-&gt;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? void userinit(void) { struct proc *p; extern char _binary_initcode_start[], _binary_initcode_size[]; p = allocproc(); initproc = p; if((p-&gt;pgdir = setupkvm()) == 0) panic("userinit: out of memory?"); inituvm(p-&gt;pgdir, _binary_initcode_start, (int)_binary_initcode_size); p-&gt;sz = PGSIZE; memset(p-&gt;tf, 0, sizeof(*p-&gt;tf)); p-&gt;tf-&gt;cs = (SEG_UCODE &lt;&lt; 3) | DPL_USER; p-&gt;tf-&gt;ds = (SEG_UDATA &lt;&lt; 3) | DPL_USER; p-&gt;tf-&gt;es = p-&gt;tf-&gt;ds; p-&gt;tf-&gt;ss = p-&gt;tf-&gt;ds; p-&gt;tf-&gt;eflags = FL_IF; p-&gt;tf-&gt;esp = PGSIZE; p-&gt;tf-&gt;eip = 0; // beginning of initcode.S safestrcpy(p-&gt;name, "initcode", sizeof(p-&gt;name)); p-&gt;cwd = namei("/"); p-&gt;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.EDDL: How do we train neural networks on limited edge devices - PART 22021-10-31T13:01:14-04:002021-10-31T13:01:14-04:00http://localhost:4000/posts/eddl-how-do-we-train-on-limited-edge-devices-part2<p>In the last post, part1, our idea of distributed learning on edge environment was generally addressed. I introduced the reason why edge distributed learning is needed and what improvements it can achieve. In this post, I will talk about our motivation study and how our framework works.</p> diff --git a/_site/index.html b/_site/index.html index 672a28d..f9de27f 100644 --- a/_site/index.html +++ b/_site/index.html @@ -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

    Home

    -

    Lab transcripts of CS350 in Spring 2022

    +

    Labs of CS350

    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...

    Read more

    Read more

    +
    diff --git a/_site/sitemap.xml b/_site/sitemap.xml index 8301720..04d34b1 100644 --- a/_site/sitemap.xml +++ b/_site/sitemap.xml @@ -29,7 +29,7 @@ 2021-10-31T13:01:14-04:00 -http://localhost:4000/posts/22s-cs350-labs +http://localhost:4000/posts/cs350-labs 2022-02-22T16:08:17-05:00