BEST代写-线上编程学术专家

Best代写-最专业靠谱代写IT | CS | 留学生作业 | 编程代写Java | Python |C/C++ | PHP | Matlab | Assignment Project Homework代写

C语言代写 | CMPSC 311 – Introduction to Systems Programming

C语言代写 | CMPSC 311 – Introduction to Systems Programming

这个作业是用C语言实现一个LRU缓存来缓存已读/写的块

CMPSC 311 – Introduction
to Systems Programming

• Implement an LRU cache that caches read/written blocks.
• The API for the cache is provided in sg_cache.h and the starter code for the
implementation is in sg_cache.c.
• The cache should be fully associative (any block can go in any cache line). It should be
dynamically allocated when initSGCache() function is called. Each line should contain
the node/block and data.
• The size of the cache is defined as SG_MAX_CACHE_ELEMENTS (in sg_cache.h)
• Add code to call the functions from your driver implementation. Any place you need to
get a block from the SG system, you should check first if it is in the cache.
• You should collect statistics on how many hits and misses you have. On close, print
out the values and your hit ratio when you close the cache.

• Honors option: Create an independent LFU cache with its own interface
(perhaps creating a new .h and .c file. Modify the sg_sim file and add a
command line option to use the LFU cache instead of the LRU cache.
• You should provide an output showing the performance of each cache as
well as the total performance when you close the cache.
• The next assignment: You are to extend your
device driver that sits between the virtual
application and virtualized hardware devices.
• As before, the application makes use of the
abstraction you provide called the SG driver. You
will make modifications to the code to implement
several new features.
• You MUST use your code from assignment
#2 and modify its function. This is called
refactoring code, which is one of the most
important skills you will learn in 311.
• SgFHandle sgopen( const char *path ); – This function will open a file
(named path, e.g.,) in the filesystem. If the file does not exist, it should be created and set
to zero length. If it does exist, it should be opened and its read/write position should be
set to the first byte. Note that there are no subdirectories in the filesystem, just files (so
you can treat the path as a filename). The function should return a unique file handle
used for subsequent operations or -1 if a failure occurs.
• int sgclose( SgFHandle fh ); – This function closes the file referenced by the
file handle that was previously open. The function should fail (and return -1) if the file
handle is bad or the file was not previously open.
• int sgread( SgFHandle fh, char *buf, size_t len ); – This function
should read count bytes from the file referenced by the file handle at the current position.
Note that if there are not enough bytes left in the file, the function should read to the end
of the file and return the number of bytes read. If there are enough bytes to fulfill the
read, the function should return count. The function should fail (and return -1) if the file
handle is bad or the file was not previously open.

bestdaixie

评论已关闭。