操作系统实验10.docx

上传人:b****6 文档编号:6837451 上传时间:2023-01-11 格式:DOCX 页数:24 大小:153.53KB
下载 相关 举报
操作系统实验10.docx_第1页
第1页 / 共24页
操作系统实验10.docx_第2页
第2页 / 共24页
操作系统实验10.docx_第3页
第3页 / 共24页
操作系统实验10.docx_第4页
第4页 / 共24页
操作系统实验10.docx_第5页
第5页 / 共24页
点击查看更多>>
下载资源
资源描述

操作系统实验10.docx

《操作系统实验10.docx》由会员分享,可在线阅读,更多相关《操作系统实验10.docx(24页珍藏版)》请在冰豆网上搜索。

操作系统实验10.docx

操作系统实验10

操作系统

实验报告

课程名称

操作系统实验

实验项目名称

磁盘调度算法

学号

班级

姓名

专业

学生所在学院

指导教师

实验室名称地点

 

 

一、实验概述

1.实验名称

磁盘调度算法

2.实验目的

熟悉操作系统集成实验环境OSLab的基本使用方法。

练习编译、调试EOS操作系统内核以及EOS应用程序。

3.实验类型

验证

二、实验环境

OSLab

三、实验过程

3.2验证先来先服务磁盘调度算法

输入:

******Diskschedulestartworking******

StartCylinder:

10

TID:

31Cylinder:

8Offset:

2-

TID:

32Cylinder:

21Offset:

13+

TID:

33Cylinder:

9Offset:

12-

TID:

34Cylinder:

78Offset:

69+

TID:

35Cylinder:

0Offset:

78-

TID:

36Cylinder:

41Offset:

41+

TID:

37Cylinder:

10Offset:

31-

TID:

38Cylinder:

67Offset:

57+

TID:

39Cylinder:

12Offset:

55-

TID:

40Cylinder:

10Offset:

2-

Totaloffset:

360Transfertimes:

10Averageoffset:

36

******Diskschedulestopworking******

******Diskschedulestartworking******

StartCylinder:

10

TID:

41Cylinder:

8Offset:

2-

TID:

42Cylinder:

21Offset:

13+

TID:

43Cylinder:

9Offset:

12-

TID:

44Cylinder:

78Offset:

69+

TID:

45Cylinder:

0Offset:

78-

TID:

46Cylinder:

41Offset:

41+

TID:

47Cylinder:

10Offset:

31-

TID:

48Cylinder:

67Offset:

57+

TID:

49Cylinder:

12Offset:

55-

TID:

50Cylinder:

10Offset:

2-

Totaloffset:

360Transfertimes:

10Averageoffset:

36

******Diskschedulestopworking******

******Diskschedulestartworking******

StartCylinder:

10

TID:

51Cylinder:

8Offset:

2-

TID:

52Cylinder:

21Offset:

13+

TID:

53Cylinder:

9Offset:

12-

TID:

54Cylinder:

78Offset:

69+

TID:

55Cylinder:

0Offset:

78-

TID:

56Cylinder:

41Offset:

41+

TID:

57Cylinder:

10Offset:

31-

TID:

58Cylinder:

67Offset:

57+

TID:

59Cylinder:

12Offset:

55-

TID:

60Cylinder:

10Offset:

2-

Totaloffset:

360Transfertimes:

10Averageoffset:

36

******Diskschedulestopworking******

3.3验证最短寻道时间优先磁盘调度算法

输出窗口:

******Diskschedulestartworking******

StartCylinder:

10

TID:

37Cylinder:

10Offset:

0=

TID:

40Cylinder:

10Offset:

0=

TID:

33Cylinder:

9Offset:

1-

TID:

31Cylinder:

8Offset:

1-

TID:

39Cylinder:

12Offset:

4+

TID:

32Cylinder:

21Offset:

9+

TID:

36Cylinder:

41Offset:

20+

TID:

38Cylinder:

67Offset:

26+

TID:

34Cylinder:

78Offset:

11+

TID:

35Cylinder:

0Offset:

78-

Totaloffset:

150Transfertimes:

10Averageoffset:

15

******Diskschedulestopworking******

******Diskschedulestartworking******

StartCylinder:

10

TID:

47Cylinder:

10Offset:

0=

TID:

50Cylinder:

10Offset:

0=

TID:

43Cylinder:

9Offset:

1-

TID:

41Cylinder:

8Offset:

1-

TID:

49Cylinder:

12Offset:

4+

TID:

42Cylinder:

21Offset:

9+

TID:

46Cylinder:

41Offset:

20+

TID:

48Cylinder:

67Offset:

26+

TID:

44Cylinder:

78Offset:

11+

TID:

45Cylinder:

0Offset:

78-

Totaloffset:

150Transfertimes:

10Averageoffset:

15

******Diskschedulestopworking******

******Diskschedulestartworking******

StartCylinder:

10

TID:

57Cylinder:

10Offset:

0=

TID:

60Cylinder:

10Offset:

0=

TID:

53Cylinder:

9Offset:

1-

TID:

51Cylinder:

8Offset:

1-

TID:

59Cylinder:

12Offset:

4+

TID:

52Cylinder:

21Offset:

9+

TID:

56Cylinder:

41Offset:

20+

TID:

58Cylinder:

67Offset:

26+

TID:

54Cylinder:

78Offset:

11+

TID:

55Cylinder:

0Offset:

78-

Totaloffset:

150Transfertimes:

10Averageoffset:

15

******Diskschedulestopworking******

3.4验证SSTF算法造成的线程“饥饿”现象

修改代码:

输出窗口:

******Diskschedulestartworking******

StartCylinder:

10

TID:

37Cylinder:

10Offset:

0=

TID:

40Cylinder:

10Offset:

0=

TID:

33Cylinder:

9Offset:

1-

TID:

34Cylinder:

8Offset:

1-

TID:

35Cylinder:

11Offset:

3+

TID:

39Cylinder:

12Offset:

1+

TID:

32Cylinder:

21Offset:

9+

TID:

36Cylinder:

41Offset:

20+

TID:

38Cylinder:

67Offset:

26+

TID:

31Cylinder:

78Offset:

11+

Totaloffset:

72Transfertimes:

10Averageoffset:

7

******Diskschedulestopworking******

3.5验证扫描磁盘调度算法

输出窗口

******Diskschedulestartworking******

StartCylinder:

10

TID:

37Cylinder:

10Offset:

0=

TID:

40Cylinder:

10Offset:

0=

TID:

39Cylinder:

12Offset:

2+

TID:

32Cylinder:

21Offset:

9+

TID:

36Cylinder:

41Offset:

20+

TID:

38Cylinder:

67Offset:

26+

TID:

34Cylinder:

78Offset:

11+

TID:

33Cylinder:

9Offset:

69-

TID:

31Cylinder:

8Offset:

1-

TID:

35Cylinder:

0Offset:

8-

Totaloffset:

146Transfertimes:

10Averageoffset:

14

******Diskschedulestopworking******

******Diskschedulestartworking******

StartCylinder:

10

TID:

47Cylinder:

10Offset:

0=

TID:

50Cylinder:

10Offset:

0=

TID:

43Cylinder:

9Offset:

1-

TID:

41Cylinder:

8Offset:

1-

TID:

45Cylinder:

0Offset:

8-

TID:

49Cylinder:

12Offset:

12+

TID:

42Cylinder:

21Offset:

9+

TID:

46Cylinder:

41Offset:

20+

TID:

48Cylinder:

67Offset:

26+

TID:

44Cylinder:

78Offset:

11+

Totaloffset:

88Transfertimes:

10Averageoffset:

8

******Diskschedulestopworking******

******Diskschedulestartworking******

StartCylinder:

10

TID:

57Cylinder:

10Offset:

0=

TID:

60Cylinder:

10Offset:

0=

TID:

59Cylinder:

12Offset:

2+

TID:

52Cylinder:

21Offset:

9+

TID:

56Cylinder:

41Offset:

20+

TID:

58Cylinder:

67Offset:

26+

TID:

54Cylinder:

78Offset:

11+

TID:

53Cylinder:

9Offset:

69-

TID:

51Cylinder:

8Offset:

1-

TID:

55Cylinder:

0Offset:

8-

Totaloffset:

146Transfertimes:

10Averageoffset:

14

******Diskschedulestopworking******

验证解决饥饿现象

输出窗口:

******Diskschedulestartworking******

StartCylinder:

10

TID:

37Cylinder:

10Offset:

0=

TID:

40Cylinder:

10Offset:

0=

TID:

35Cylinder:

11Offset:

1+

TID:

39Cylinder:

12Offset:

1+

TID:

32Cylinder:

21Offset:

9+

TID:

36Cylinder:

41Offset:

20+

TID:

38Cylinder:

67Offset:

26+

TID:

31Cylinder:

78Offset:

11+

TID:

33Cylinder:

9Offset:

69-

TID:

34Cylinder:

8Offset:

1-

Totaloffset:

138Transfertimes:

10Averageoffset:

13

******Diskschedulestopworking******

3.6改写SCAN算法

源代码:

BOOLScanInside=TRUE;

PREQUEST

IopDiskSchedule(

VOID

{

PLIST_ENTRYpListEntry;

PREQUESTpRequest;

LONGOffset;

ULONGInsideShortestDistance=0xFFFFFFFF;

ULONGOutsideShortestDistance=0xFFFFFFFF;

PREQUESTpNextRequest=NULL;

PREQUESTINpNextRequest=NULL;

PREQUESTOUTpNextRequest=NULL;

//

//需要遍历请求队列一次或两次

//

for(pListEntry=RequestListHead.Next;//请求队列中的第一个请求是链表头指向的下一个请求。

pListEntry!

=&RequestListHead;//遍历到请求队列头时结束循环。

pListEntry=pListEntry->Next){

//

//根据链表项获得请求的指针

//

pRequest=CONTAINING_RECORD(pListEntry,REQUEST,ListEntry);

//

//计算请求对应的线程所访问的磁道与当前磁头所在磁道的偏移(方向由正负表示)

//

Offset=pRequest->Cylinder-CurrentCylinder;

if(0==Offset){

//

//如果线程要访问的磁道与当前磁头所在磁道相同,可立即返回。

//

pNextRequest=pRequest;

gotoRETURN;

}elseif(Offset>0){

//

//记录向内移动距离最短的线程

//

if(Offset

InsideShortestDistance=Offset;

INpNextRequest=pRequest;

}

}elseif(Offset<0){

//

//记录向外移动距离最短的线程

//

if(-Offset

OutsideShortestDistance=-Offset;

OUTpNextRequest=pRequest;

}

}

}

//

//如果第一次遍历没有线程访问指定方向上的磁道,就变换方向,

//进行第二次遍历。

在这两次遍历中一定能找到合适的线程。

//

if(ScanInside){

if(INpNextRequest)

{

returnINpNextRequest;

}

else

{

ScanInside=!

ScanInside;

returnOUTpNextRequest;

}

}

else

{

if(OUTpNextRequest)

{

returnOUTpNextRequest;

}

else

{

ScanInside=!

ScanInside;

returnINpNextRequest;

}

}

RETURN:

returnpNextRequest;

}

输出窗口:

******Diskschedulestartworking******

StartCylinder:

10

TID:

37Cylinder:

10Offset:

0=

TID:

40Cylinder:

10Offset:

0=

TID:

39Cylinder:

12Offset:

2+

TID:

32Cylinder:

21Offset:

9+

TID:

36Cylinder:

41Offset:

20+

TID:

38Cylinder:

67Offset:

26+

TID:

34Cylinder:

78Offset:

11+

TID:

33Cylinder:

9Offset:

69-

TID:

31Cylinder:

8Offset:

1-

TID:

35Cylinder:

0Offset:

8-

Totaloffset:

146Transfertimes:

10Averageoffset:

14

******Diskschedulestopworking******

3.7编写循环扫描磁盘调度算法

源代码:

PREQUEST

IopDiskSchedule(

VOID

{

PLIST_ENTRYpListEntry;

PREQUESTpRequest;

LONGOffset;

ULONGInsideShortestDistance=0xFFFFFFFF;

ULONGOutsideLongestDistance=0x00000000;

PREQUESTpNextRequest=NULL;

PREQUESTINpNextRequest=NULL;

PREQUESTOUTpNextRequest=NULL;

//

//需要遍历请求队列一次或两次

//

for(pListEntry=RequestListHead.Next;//请求队列中的第一个请求是链表头指向的下一个请求。

pListEntry!

=&RequestListHead;//遍历到请求队列头时结束循环。

pListEntry=pListEntry->Next){

//

//根据链表项获得请求的指针

//

pRequest=CONTAINING_RECORD(pListEntry,REQUEST,ListEntry);

//

//计算请求对应的线程所访问的磁道与当前磁头所在磁道的偏移(方向由正负表示)

//

Offset=pRequest->Cylinder-CurrentCylinder;

if(0==Offset){

//

//如果线程要访问的磁道与当前磁头所在磁道相同,可立即返回。

//

pNextRequest=pRequest;

gotoRETURN;

}elseif(Offset>0){

//

//记录向内移动距离最短的线程

//

if(Offset

InsideShortestDistance=Offset;

INpNextRequest=pRequest;

}

}elseif(Offset<0){

//

//记录向外移动距离最短的线程

//

if(-Offset>OutsideLongestDistance){

OutsideLongestDistance=-Offset;

OUTpNextRequest=pRequest;

}

}

}

//

//如果第一次遍历没有线程访问指定方向上的磁道,就变换方向,

//进行第二次遍历。

在这两次遍历中一定能找到合适的线程。

//

if(INpNextRequest)

returnINpNextRequest;

else

returnOUTpNextRequest;

RETURN:

returnpNextRequest;

}

输出窗口:

******Diskschedulestartworking******

StartCylinder:

10

TID:

37Cylinder:

10Offset:

0=

TID:

40Cylinder:

10Offset:

0=

TID:

39Cylinder:

12Offset:

2+

TID:

32Cylinder:

21Offset:

9+

TID:

36Cylinder:

41Offset:

20+

TID:

38Cylinder:

67Offset:

26+

TID:

34Cylinder:

78Offset:

1

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 幼儿教育 > 幼儿读物

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1