Skip to content

Commit

Permalink
update grades and todos.
Browse files Browse the repository at this point in the history
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
  • Loading branch information
Certseeds committed Jul 4, 2020
1 parent 45fcb4c commit ad3a8fd
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 10 deletions.
2 changes: 2 additions & 0 deletions lab05_report03/src/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <fcntl.h>
#include <time.h>
#include "job.h"
// TODO, only get 0 of 20 points.
// if you know why,plase create issues.
void pid_to_name(int pid, char *ret);
void pid_to_name_2(int pid, char *ret);

Expand Down
4 changes: 2 additions & 2 deletions lab06_report04/src/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @Author: nanoseeds
* @Date: 2020-04-07 14:54:54
* @LastEditors: nanoseeds
* @LastEditTime: 2020-04-07 20:17:46
* @LastEditTime: 2020-07-04 17:57:46
*/
#include <fcntl.h>
#include <pthread.h>
Expand All @@ -13,6 +13,6 @@
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>

// 拿到了50/50.
extern sem_t db, rc;
extern int readcount;
1 change: 1 addition & 0 deletions lab08_report05/src/banker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* @Date: 2020-04-13 19:19:15
* @LastEditors : nanoseeds
*/
// TODO, 只拿到了40分中的20分.
#include <iostream>
#include <string>
#include <vector>
Expand Down
4 changes: 2 additions & 2 deletions lab09_report06/report06.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @Author: nanoseeds
* @Date: 2020-04-23 10:26:20
* @LastEditors: nanoseeds
* @LastEditTime: 2020-06-04 22:51:05
* @LastEditTime: 2020-07-04 17:54:08
* @License: CC-BY-NC-SA_V4_0 or any later version
-->
0.
Expand All @@ -20,7 +20,7 @@

3. What is the segmentation mechanism and its advantages & disadvantages:
1. 分段机制将内存分成长度不定的段,并将每一段中的虚拟地址空间映射到物理地址空间(每一段中对应的物理地址是连续的).
2. 分段机制的优点:将地址空间隔离,进程之间不会互相影响;运行时地址较为确定,方便使用.
2. 分段机制的优点:将地址空间隔离,进程之间不会互相影响;运行时地址较为确定,方便使用;可以方便的与其他用户共享代码和数据.
3. 缺点:由于段的长度不确定,所以会产生碎片.

4. What is the paging mechanism and its advantages & disadvantages:
Expand Down
2 changes: 1 addition & 1 deletion lab09_report06/src/mm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* 实现了相邻free_block的merge.
* 每次打印出的free_block均为排序后的顺序.(BF为size小到大,WF为size大到小,FF为地址低位->高位)
* */

// 完成了基本功能,60分拿到了50.

using std::cout;
using std::cin;
Expand Down
9 changes: 6 additions & 3 deletions report_07/report_07.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
* @Author: nanoseeds
* @Date: 2020-05-10 18:42:40
* @LastEditors: nanoseeds
* @LastEditTime: 2020-06-04 22:51:20
* @LastEditTime: 2020-07-04 17:48:25
* @License: CC-BY-NC-SA_V4_0 or any later version
-->

1. FIFO
FIFO算法,每次先查看是否在内存中,如果在内存中则不变;
若不在内存中,如果队列已满,就踢走队列头部的页面,将页面调入队尾
Expand All @@ -31,8 +32,10 @@ FIFO算法,每次先查看是否在内存中,如果在内存中则不变;
直到发现页为0,置换此页.节约了在两个列表之间转换的成本.
但是每次还是需要遍历,需要O(n)的时间复杂度.

1. second-chance算法:
5. second-chance算法:
为了避免FIFO把经常使用的页面踢出的弊端,使用一个检查位,
给经常使用的,检查位为1的页面重新加入列表,给第二次机会.从而提升了效率.
换言之,使用了FIFO模式和LRU模式相结合.
从实现上来看,每次都要遍历需要O(n)的时间复杂度.
从实现上来看,每次都要遍历需要O(n)的时间复杂度.

PS:由于不知名原因,这个report没有被评分,不知道具体情况.
3 changes: 2 additions & 1 deletion report_07/src/pr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ static std::unordered_map<Algorithm, std::function<void()>> umap = {
{MIN, MIN_F},
{CLOCK, CLOCK_F},
{SECOND_CHANCE, SECOND_CHANCE_F}};

// TODO, this do not get any scores, i do not know why.
// If you know, please create issues.
int main() {
read_input();
umap[algorithm]();
Expand Down
3 changes: 2 additions & 1 deletion report_08/report_08.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @Author: nanoseeds
* @Date: 2020-05-19 17:14:20
* @LastEditors: nanoseeds
* @LastEditTime: 2020-05-24 21:25:24
* @LastEditTime: 2020-07-04 17:41:00
* @License: CC-BY-NC-SA_V4_0 or any later version
-->
[Toc]
Expand Down Expand Up @@ -88,4 +88,5 @@ Answer:
2. 总共需要的时间为寻道时间+旋转等待时间,旋转等待时间中,每分钟12000转,平均每秒200转,每转平均5ms.而需要进行的旋转有五次,所以一共30ms.如果将199到0的过程认为消耗寻道时间的话,一共消耗(199-100)+(90-0)+(199-0)=388ms,如果不认为的话,一共小号(199-100)+(90-0) =189ms.
所以如果不认为从最高磁道到最低磁道消耗时间需要计算的话,一共消耗219ms,如果认为需要消耗的话(实际上,这个观点来自Lab10 Disk Scheduling guide的样例,在资料中C-look就计算了这个时间,并且CLook作为C-Scan的改进,很难想象花费的时间比C-Scan还多),一共需要418ms.
PS:另一种思路是每转平均需要2.5ms,所以是388+15=403.
fix: 正确答案为403ms.
2. 如果使用SSD,当然要使用FIFO算法,因为SSD的寻道时间几乎可以忽略不计,所以这些优化方式都没有必要进行.
4 changes: 4 additions & 0 deletions report_08/src/disk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,12 @@ void LOOK(deque<int32_t> track) {
output("LOOK", track, distance);
}

// TODO, needed is only C_LOOK algorith.
// BUT i only get 26/40 scores, why?
// IF you know why, please create issue for repo.
void C_LOOK(deque<int32_t> track) {
// TODO , infact, distance of lowest back to highest is hard to decide to calcaute or not.
// this refer the example.in.txt and example.out.txt.
std::sort(std::begin(track), std::end(track), std::greater<int32_t>());
int32_t dis = S + 2 * track.front() - 2 * track.back();
while (track.back() <= S) {
Expand Down

0 comments on commit ad3a8fd

Please sign in to comment.