Reaves.dev

v0.1.0

built using

Phoenix v1.7.17

OS 101

What is an OS?

and why should I care?

Who am I?

  • Software Engineer
    • Red Hat for 3 years
    • BHS for 3 years
  • Bachelor’s from USC
  • OMSCS @ GT
    • GIOS
    • AOS

What is an OS?

An operating system (OS) is system software that manages computer hardware and software resources, and provides common services for computer programs.
The Almighty Wikipedia

Diagram

Geditoreditorososeditor->osstoragestorageos->storagecpucpuos->cpugpugpuos->gpumemorymemoryos->memorynetworknetworkos->networkfirefoxfirefoxfirefox->ossteamsteamsteam->os

Goals

  • Abstraction

Goals

  • Abstraction
  • Flexibility
    • Extensibility

Goals

  • Abstraction
  • Flexibility
    • Extensibility
  • Performance

Goals

  • Abstraction
  • Flexibility
    • Extensibility
  • Performance
  • Protection
    • Within and across app/os boundaries

Goals

  • Abstraction
  • Flexibility
    • Extensibility
  • Performance
  • Protection
    • Within and across app/os boundaries
  • Scalability

Goals

  • Abstraction
  • Flexibility
    • Extensibility
  • Performance
  • Protection
    • Within and across app/os boundaries
  • Scalability
  • Responsiveness

The Big 3

  • Linux
  • MacOS
  • Windows

Components

  • VMM
  • Scheduler
  • Drivers

Components

Geditoreditorososeditor->osmemorymemoryos->memorycpucpuos->cpustoragestorageos->storagenetworknetworkos->networkgpugpuos->gpufirefoxfirefoxfirefox->ossteamsteamsteam->os

Components

Gossyscall interfacevmmschedulerdriversstoragenetworkgraphicsmemorymemoryos:2->memorycpucpuos:3->cpustoragestorageos:4->storagenetworknetworkos:5->networkgpugpuos:6->gpueditoreditoreditor->os:1firefoxfirefoxfirefox->os:1steamsteamsteam->os:1

Components

Gossyscall interfacevmmschedulerdriversstoragenetworkgraphicsgpufirmwaregpuos:6->gpunetworkfirmwarenicos:5->networkstoragefirmwaredisksos:4->storagememorymemoryos:2->memorycpucpuos:3->cpueditoreditoreditor->os:1firefoxfirefoxfirefox->os:1steamsteamsteam->os:1

Component Overview

What are the responsibilities of the components?

Drivers

> ls /usr/src/linux/drivers/ | wc -l
145

Drivers

/usr/src/linux/drivers/scsi/wd719x.h

/* timeout delays in microsecs */
#define WD719X_WAIT_FOR_CMD_READY	500
#define WD719X_WAIT_FOR_RISC		2000
#define WD719X_WAIT_FOR_SCSI_RESET	3000000

/* All commands except 0x00 generate an interrupt */
#define WD719X_CMD_READY        0x00 /* Command    register ready (or noop) */
#define WD719X_CMD_INIT_RISC    0x01 /* Initialize RISC     */
/* 0x02 is reserved */
#define WD719X_CMD_BUSRESET	    0x03 /* Assert SCSI bus reset */
#define WD719X_CMD_READ_FIRMVER	0x04 /* Read the Firmware Revision */
#define WD719X_CMD_ECHO_BYTES	  0x05 /* Echo command bytes (DW) */
/* 0x06 is reserved */
/* 0x07 is reserved */
#define WD719X_CMD_GET_PARAM	  0x08 /* Get programmable parameters */
#define WD719X_CMD_SET_PARAM	  0x09 /* Set programmable parameters */
#define WD719X_CMD_SLEEP	      0x0a /* Put SPIDER to sleep */
#define WD719X_CMD_READ_INIT	  0x0b /* Read initialization parameters */
#define WD719X_CMD_RESTORE_INIT	0x0c /* Restore initialization parameters */
/* 0x0d is reserved */
/* 0x0e is reserved */
/* 0x0f is reserved */
#define WD719X_CMD_ABORT_TAG	  0x10 /* Send Abort tag message to target */
#define WD719X_CMD_ABORT	      0x11 /* Send Abort message to target */
#define WD719X_CMD_RESET	      0x12 /* Send Reset message to target */
#define WD719X_CMD_INIT_SCAM	  0x13 /* Initiate SCAM */
#define WD719X_CMD_GET_SYNC	    0x14 /* Get synchronous rates */
#define WD719X_CMD_SET_SYNC	    0x15 /* Set synchronous rates */
#define WD719X_CMD_GET_WIDTH	  0x16 /* Get SCSI bus width */
#define WD719X_CMD_SET_WIDTH	  0x17 /* Set SCSI bus width */
#define WD719X_CMD_GET_TAGS	    0x18 /* Get tag flags */
#define WD719X_CMD_SET_TAGS	    0x19 /* Set tag flags */
#define WD719X_CMD_GET_PARAM2	  0x1a /* Get programmable params (format 2) */
#define WD719X_CMD_SET_PARAM2	  0x1b /* Set programmable params (format 2) */

Drivers

Provide hardware-level abstraction

ret = fread(buffer, sizeof(*buffer), ARRAY_SIZE(buffer), fp);
if (ret != ARRAY_SIZE(buffer)) {
  fprintf(stderr, "fread() failed: %zu\n", ret);
  exit(EXIT_FAILURE);
}

corresponds to rotating the platter and moving the needle

Kernel

The kernel is responsible for scheduling processes, managing memory, and orchestrating drivers

It is also typically loaded entirely into memory

Kernel

Gossyscall interfacevmmschedulerdriversstoragenetworkgraphics

Kernel

Gossyscall interfacekernelstoragenetworkgraphics

Scheduler

Run a thread for a while, block for IO, run a different thread in the meantime

Scheduler

Run a thread for a while, block for IO, run a different thread in the meantime

ret = fread(buffer, sizeof(*buffer), ARRAY_SIZE(buffer), fp);
if (ret != ARRAY_SIZE(buffer)) {
  fprintf(stderr, "fread() failed: %zu\n", ret);
  exit(EXIT_FAILURE);
}

Scheduling Policies

  • First Come First Serve (FCFS)
    • Ignores affinity for fairness
  • Fixed processor
    • Predetermined processor
  • Last processor
    • Prefer last processor that thread ran on
  • Minimum Intervening
    • Similar to Last Processor, but lower affinity the more threads that ran on processor since last time this thread ran

Virtual Memory Manager

Key benefit is to trick process into thinking it has a memory space all to itself

Virtual Memory Manager

Key benefit is to trick process into thinking it has a memory space all to itself

Also allow for more “memory” than hardware allows

Virtual Memory Manager

Ga1app1vmmvmma1->vmma2app2a2->vmmaNappNaN->vmmcachecachevmm->cacheramramvmm->ramswapswapvmm->swap

Virtual Memory Manager

Contiguous Memory Allocation

std::vector<int> arr = {0, 1, 2, 4, 5};
int sum = 0;

for (int i = 0; i < arr.size(); i++) {
	sum += arr[i];
}

Virtual Memory Manager

Gru012345678910

Virtual Memory Manager

Gru012345678910

Virtual Memory Manager

Gru012345678910

Virtual Memory Manager

Gru012345678910

Virtual Memory Manager

Gru012345678910

Virtual Memory Manager

Gp1012mem012345678910p1:0->mem:0p1:1->mem:1p1:s->mem:2p2012p2:0->mem:6p2:1->mem:7p2:2->mem:8p30123p3:0->mem:3p3:1->mem:4p3:2->mem:5p3:3->mem:9

Structures

  • Monolithic
  • DOS-like
  • Microkernel

Monolithic

Each app has its own hardware address/memory space

OS in its own hardware address space

Malfuntioning of an app shouldn’t affect integrity of OS nor other apps

Monolithic

Grec_osApp1App2...AppNKernelHardware

DOS-like

Monolithic structure where there is no protection between the apps and the OS

  • Application code can make syscalls directly, like they would any other library

This was in a time where multitasking didn’t really exists and PCs were meant for single users

Microkernel

Microkernels were designed to focus around customization for a specific application

The microkernel itself handles simple abstractions like address space, IPC, etc.

Grec_osApp1App2...AppNFile SystemMemory Manager...CPU SchedulermicrokernelHardware

Thanks!