Skip to content

ajs7270/kernel_implementation

Repository files navigation

Kernel Module and User-Level Examples

This repository provides a collection of simple Linux kernel modules and user-space programs. Each directory contains a small example that focuses on a particular kernel feature or synchronization primitive.

Detailed README files inside each directory describe the implementation in more depth. These examples are intentionally small so that beginners can easily read and modify the code. Every kernel module directory includes a Makefile that builds against the currently running kernel.

Directory Overview

  • kernel_bit_operation - demonstrates bit operations inside a kernel module.
  • kernel_hashtable - shows how to use linux/hashtable.h for a hash table.
  • kernel_list - basic usage of the kernel list_head APIs.
  • kernel_list_clock - measures timing for list operations.
  • kernel_rbtree - example of the kernel red–black tree API.
  • kernel_rbtree_clock - measures timing for red–black tree operations.
  • list_spinlock - uses a spinlock to protect a list.
  • lockfree_kernel - simple lock‑free list implementation in kernel space.
  • lockfree_user - user-space test program for the lock‑free list.
  • mutex_global / mutex_struct - mutex usage with global and struct-scoped locks.
  • semaphore - demonstrates kernel semaphore APIs.
  • spinlock - basic spinlock usage.
  • thread_delay - uses a kernel thread with a delay (udelay).
  • thread_wait_queue - synchronizes threads with a wait queue.
  • struct_extern - references a structure declared in another source file.
  • persistent - experiments with file I/O and write synchronization.
  • makefile - example Makefile for building user-space C programs.
  • user_level - small examples using fork() and pthread.

Building Kernel Modules

To build any module, change into its directory and run make:

cd kernel_list     # for example
make               # builds hello_module.ko
sudo insmod hello_module.ko
sudo rmmod hello_module

The Makefile uses the KERNEL_DIR variable to automatically locate the build directory for your currently running kernel. Run make clean to remove build artifacts.

Building User-Space Examples

Inside the makefile directory is a simple Makefile for compiling C programs:

cd makefile
make
./example

Notes

  • .gitignore ignores build results such as result, dump, and editor backups (*.sw*).
  • Some examples (for instance, persistent) may require access to a real block device or file system.
  • Loading kernel modules requires root privileges; ensure your system is configured for module development.

These examples serve as a learning aid for experimenting with kernel data structures, synchronization, and threading. Adjust paths and permissions as necessary for your environment.

About

Linux Kernel algorithms in C (For Linux 5.1.5 version)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •