How logicalmonster/xv6-riscv-2020 works
Main components (“classes”) in xv6
• Process (found in kernel/proc.h and implemented in kernel/proc.c)
– Attributes: Process ID, state, context (stored in a context record), trapframe, scheduling information, etc.
– Methods (in a conceptual sense): creation, termination, context switching, scheduling.
• File (in kernel/file.h and kernel/file.c)
– Attributes: file type, reference counts, read/write pointers, inode reference (linked to the filesystem), etc.
– Methods: open, close, read, write.
• Filesystem & Inodes (coordinated by kernel/fs.h, kernel/fs.c)
– Inode “class”: Attributes related to file metadata, block pointers, etc.
– Filesystem “manager”: operations for file lookup, directory operations, etc.
• Memory Management (in kernel/vm.c and kernel/kalloc.c)
– “Memory Manager” class: handles virtual memory, page allocation, memory mapping.
• Locking Mechanisms:
– SpinLock (kernel/spinlock.h / .c) – with acquire and release functions.
– SleepLock (kernel/sleeplock.h / .c) – similar locking abstraction used during sleep–wakeup.
• Buffer Cache (from kernel/bio.c and associated header kernel/buf.h)
– “Buffer” class: encapsulates in-memory copies of disk blocks.
• System Call Interface (spread across kernel/syscall.h, syscall.c, sysfile.c, sysproc.c)
– “Syscall Manager”: interprets system calls from user programs and dispatches them to the appropriate kernel routines.
• Console/Device Handling:
– Console/Output (kernel/console.c) – handling basic I/O.
– Other device-related “classes”: UART (kernel/uart.c), Virtio disk (kernel/virtio_disk.c), PLIC (kernel/plic.c).
Relationships and interactions
• The Process “class” depends on the Scheduler (within proc.c and context-switch code in swtch.S) and uses the System Call Interface.
• The File “class” interacts with the Filesystem/Inode components and the Buffer Cache.
• The Filesystem “class” acts as a manager that ties together inodes, file structures, and disk buffers.
• Memory Management is a cross-cutting infrastructure that is used by process management, file caching, and device drivers.
• Locking “classes” (SpinLock and SleepLock) are utilized by nearly all other modules to secure critical sections.
• Clear class (or struct) names (e.g., Process, File, Inode, SpinLock, MemoryManager, Buffer).
• Attributes (fields) and operations (functions or “methods”) where it helps to understand responsibilities.