Skip to content

Commit

Permalink
upload: organized projects of PD511
Browse files Browse the repository at this point in the history
  • Loading branch information
PraveenKumar-Rajendran committed Aug 15, 2024
0 parents commit af2b1b2
Show file tree
Hide file tree
Showing 21 changed files with 160 additions and 0 deletions.
Binary file added Project0-Adding-System-Calls/Project0.pdf
Binary file not shown.
1 change: 1 addition & 0 deletions Project0-Adding-System-Calls/xv6
Submodule xv6 added at fd7629
Binary file added Project1-Kernel-Threading/Project1.pdf
Binary file not shown.
1 change: 1 addition & 0 deletions Project1-Kernel-Threading/xv6
Submodule xv6 added at 9e0340
Binary file added Project2-Process-Scheduler/Project2.pdf
Binary file not shown.
14 changes: 14 additions & 0 deletions Project2-Process-Scheduler/pstat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef _PSTAT_H_
#define _PSTAT_H_

#include "param.h"

struct pstat {
int inuse[NPROC]; // whether this slot of the process process table is in use (1 or 0)
int pid[NPROC]; // the PID of each process
int hticks[NPROC]; // the number of ticks each process has accumulated at priority 2
int lticks[NPROC]; // the number of ticks each process has accumulated at priority 1
};


#endif // _PSTAT_H_
1 change: 1 addition & 0 deletions Project2-Process-Scheduler/xv6
Submodule xv6 added at 122cfd
Binary file not shown.
1 change: 1 addition & 0 deletions Project3-NullPtr-Dereferences-and-Shared-Memory/xv6
Submodule xv6 added at 30629a
Binary file added Project4-Filesystem-Optimization/Project4.pdf
Binary file not shown.
69 changes: 69 additions & 0 deletions Project4-Filesystem-Optimization/fspatch.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
--- ./kernel/fs.c
+++ ./kernel/fs.c
@@ -53,15 +53,22 @@
static uint
balloc(uint dev)
{
- int b, bi, m;
+ int b, bi, m, bound;
struct buf *bp;
struct superblock sb;
-
+
bp = 0;
readsb(dev, &sb);
for(b = 0; b < sb.size; b += BPB){
bp = bread(dev, BBLOCK(b, sb.ninodes));
- for(bi = 0; bi < BPB; bi++){
+
+ if(b+BPB > sb.size){ //last bitmap block
+ bound = sb.size % BPB;
+ } else {
+ bound = BPB;
+ }
+
+ for(bi = 0; bi < bound; bi++){
m = 1 << (bi % 8);
if((bp->data[bi/8] & m) == 0){ // Is block free?
bp->data[bi/8] |= m; // Mark block in use on disk.
@@ -72,7 +79,9 @@
}
brelse(bp);
}
- panic("balloc: out of blocks");
+
+ //panic("balloc: out of blocks");
+ return 0;
}

// Free a disk block.
@@ -409,7 +418,12 @@
n = ip->size - off;

for(tot=0; tot<n; tot+=m, off+=m, dst+=m){
- bp = bread(ip->dev, bmap(ip, off/BSIZE));
+ uint sector_number = bmap(ip, off/BSIZE);
+ if(sector_number == 0){ //failed to find block
+ panic("readi: trying to read a block that was never allocated");
+ }
+
+ bp = bread(ip->dev, sector_number);
m = min(n - tot, BSIZE - off%BSIZE);
memmove(dst, bp->data + off%BSIZE, m);
brelse(bp);
@@ -436,7 +450,13 @@
n = MAXFILE*BSIZE - off;

for(tot=0; tot<n; tot+=m, off+=m, src+=m){
- bp = bread(ip->dev, bmap(ip, off/BSIZE));
+ uint sector_number = bmap(ip, off/BSIZE);
+ if(sector_number == 0){ //failed to find block
+ n = tot; //return number of bytes written so far
+ break;
+ }
+
+ bp = bread(ip->dev, sector_number);
m = min(n - tot, BSIZE - off%BSIZE);
memmove(bp->data + off%BSIZE, src, m);
bwrite(bp);

1 change: 1 addition & 0 deletions Project4-Filesystem-Optimization/xv6
Submodule xv6 added at e02ce6
72 changes: 72 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Operating Systems and System Programming: A Deep Dive into xv6

## Overview

This repository showcases a series of projects developed as part of an Operating Systems course at KAIST, using the xv6 teaching operating system. Each project focuses on enhancing or extending various components of xv6, providing hands-on experience with operating system concepts.

## Projects

### 00. [Introduction to xv6](./Project0-Adding-System-Calls)
![Introduction to xv6](assets/images/system-call.png)

*Image sourced from [Guru99](https://www.guru99.com/system-call-operating-system.html)*

Refer to the [project instructions](Project0-Adding-System-Calls/Project0.pdf) to view the list of tasks to be completed.
<details>
<summary>Project Description</summary>
This initial project introduces xv6, a teaching operating system used in the MIT Operating Systems course. The project involved gaining familiarity with the xv6 architecture and adding basic system calls to extend its functionality.
</details>

### 01. [Kernel Threading](./Project1-Kernel-Threading)
![Kernel Threading](assets/images/OS-Kernel-Threading.png)

*Image sourced from [Scaler](https://www.scaler.com/topics/user-level-threads-and-kernel-level-threads/)*

Refer to the [project instructions](Project1-Kernel-Threading/Project1.pdf) to view the list of tasks to be completed.
<details>
<summary>Project Description</summary>
Implemented kernel threading in xv6 by creating kernel threads using `clone()` and `join()` system calls. Additionally, a user-level thread library was developed with functions such as `thread_create()`, `lock_acquire()`, and `lock_release()`.
</details>

### 02. [Process Scheduler](./Project2-Process-Scheduler)
![Process Scheduler](assets/images/OS-Process-Scheduler.png)

*Image sourced from [Scaler](https://www.scaler.com/topics/operating-system/cpu-scheduling/)*

Refer to the [project instructions](Project2-Process-Scheduler/Project2.pdf) to view the list of tasks to be completed.
<details>
<summary>Project Description</summary>
Developed a priority-based process scheduler for xv6. This scheduler assigns different priority levels to processes, ensuring higher-priority processes receive more CPU time compared to those with lower priority.
</details>

### 03. [Null Pointer Dereferences and Shared Memory](./Project3-NullPtr-Dereferences-and-Shared-Memory)
![Nullptr Dereferences and Shared Memory](assets/images/OS-Nullptr-Dereferences-Shared-Memory.png)

*Image sourced from [MITRE CWE](https://cwe.mitre.org/data/definitions/476.html)*

Refer to the [project instructions](Project3-NullPtr-Dereferences-and-Shared-Memory/Project3.pdf) to view the list of tasks to be completed.
<details>
<summary>Project Description</summary>
Enhanced xv6 by adding mechanisms to handle null pointer dereferences, ensuring that any process attempting to dereference a null pointer is terminated immediately. Also implemented shared memory functionality, complete with system calls for managing and tracking shared memory usage across processes.
</details>

### 04. [Filesystem Optimization](./Project4-Filesystem-Optimization)
![Filesystem Optimization](assets/images/OS-Filesystem-Optimization.png)

*Image sourced from [UNIX v6/xv6 Book](https://pekopeko11.sakura.ne.jp/unix_v6/xv6-book/en/File_system.html)*

Refer to the [project instructions](Project4-Filesystem-Optimization/Project4.pdf) to view the list of tasks to be completed.
<details>
<summary>Project Description</summary>
Optimized the xv6 filesystem to enhance performance when handling small files. This project involved modifying the filesystem's data structures and algorithms to reduce overhead and improve efficiency for operations involving small files.
</details>

## Resources

- [Book of xv6 (PDF)](assets/xv6book.pdf)
- [Operating System Lecture Slides - KAIST (Merged PDF)](assets/EE415_Operating_Systems_Slides_merged.pdf)
- [Course Syllabus](./assets/Syllabus.pdf)

### Note

This project was organized with the aim of demonstrating my past experience with operating systems and their low-level operations, both as a reference for myself and to showcase my skills to potential future employers. Although I uploaded this after graduation, ***the work reflects projects I completed during my master's studies.*** I believe it's important to maintain a well-documented digital footprint, especially since a recruiter once inquired about my experience with low-level concepts.
Binary file added assets/EE415_Operating_Systems_Slides_merged.pdf
Binary file not shown.
Binary file added assets/Syllabus.pdf
Binary file not shown.
Binary file added assets/images/OS-Filesystem-Optimization.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/OS-Kernel-Threading.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/OS-Process-Scheduler.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/system-call.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/xv6book.pdf
Binary file not shown.

0 comments on commit af2b1b2

Please sign in to comment.