Skip to content

Kernel Threads implementation in the xv6 operating system. It consists of adding kernel level support for threads and various system calls in xv6 along with the user land threading library with one to one mappings and synchronization using locks. The changes were built on top of MIT's xv6-public repository.

License

Notifications You must be signed in to change notification settings

kushalnl7/xv6-Kernel-Threads-Implementation-In-C

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

xv6-Kernel-Threads

Kernel Threads in the xv6 Operating System are implemented in this project. This is implemented on top of this repository. Support for threads (lightweight processes) at the kernel level is provided, and semaphore implementation serves as a primitive synchronisation mechanism. One-to-one mapping and ticket-lock synchronisation are also added to the userland threading library.

The following System Calls are added:

CLONE:

int clone(void(*function)(void *, void *), void *stack, int flags, void *arg1, void *arg2);
  • Userland threading library wrapper function calls the clone system call to construct a thread of a process.
  • function - Function pointer which runs in the created thread.
  • flags - Flags for the clone system call.
  • stack - Child stack to pass the function(fcn) arguments.
  • arg1 & arg2 - Arguments to function fcn.

JOIN:

int join(int threadId);  
  • Join system call to block other threads while it waits for the current thread to finish, and then release thread resources once it has.
  • threadId - thread Id of the executing thread.

GETTID:

int gettid();
  • gettid system call to get the thread Id of currently executing thread

TGKILL:

int tgkill(int tgid, int tid, int sig);
  • tgkill system call to terminate the thread from the thread group with the thread group id and thread id as the tgid and tid, respectively.
  • tgid - thread group id (parent id)
  • tid - thread id to be killed
  • sig - signal number to be sent

The following System Calls are modified:

FORK:

  • Setting up tgid for the process.
  • Setting additional fields that were added to the proc structure to implement threads

EXIT:

  • If it's a thread and the CLONE FILE flag is set, changing one condition will result in shutting all file descriptors.

KILL:

  • Adding a clause that says a parent process can only be killed if all of its child threads have been killed using tgkill.

Userland Threading Library:

Functions implemented for userland threading library are:

  • thread_create - Malloc the stack for thread and then calls clone system call.
  • thread_join - Free the stack for the thread and call join system call.
  • tlock_acquire - Acquires a ticket lock
  • tlock_release - Reelease the ticket lock
  • tlock_init - Initialize the ticket lock

Tests:

Added testing code to evaluate Kernel thread functionality across a variety of test cases.

References:

About

Kernel Threads implementation in the xv6 operating system. It consists of adding kernel level support for threads and various system calls in xv6 along with the user land threading library with one to one mappings and synchronization using locks. The changes were built on top of MIT's xv6-public repository.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published