<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://homeostasis.scs.carleton.ca/wiki/index.php?action=history&amp;feed=atom&amp;title=Operating_Systems_2019W_Lecture_13</id>
	<title>Operating Systems 2019W Lecture 13 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://homeostasis.scs.carleton.ca/wiki/index.php?action=history&amp;feed=atom&amp;title=Operating_Systems_2019W_Lecture_13"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2019W_Lecture_13&amp;action=history"/>
	<updated>2026-04-05T17:00:48Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2019W_Lecture_13&amp;diff=22221&amp;oldid=prev</id>
		<title>Soma: Created page with &quot;==Video==  The lecture given on March 4, 2019 [https://homeostasis.scs.carleton.ca/~soma/os-2019w/lectures/comp3000-2019w-lec13-20190304.m4v is now available].  ==Notes==  &lt;pr...&quot;</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2019W_Lecture_13&amp;diff=22221&amp;oldid=prev"/>
		<updated>2019-03-06T15:33:16Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;==Video==  The lecture given on March 4, 2019 [https://homeostasis.scs.carleton.ca/~soma/os-2019w/lectures/comp3000-2019w-lec13-20190304.m4v is now available].  ==Notes==  &amp;lt;pr...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
The lecture given on March 4, 2019 [https://homeostasis.scs.carleton.ca/~soma/os-2019w/lectures/comp3000-2019w-lec13-20190304.m4v is now available].&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Lecture 13&lt;br /&gt;
----------&lt;br /&gt;
&lt;br /&gt;
What&amp;#039;s in an OS kernel?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
What&amp;#039;s a process?&lt;br /&gt;
 - &amp;quot;running program&amp;quot;&lt;br /&gt;
 - an instance of a virtual computer&lt;br /&gt;
   - virtual RAM  (must mmap or sbrk it, or started via execve)&lt;br /&gt;
   - virtual CPUs (get one, must clone for more threads)&lt;br /&gt;
   - I/O capabilities (system calls)&lt;br /&gt;
&lt;br /&gt;
How do you make a thread?&lt;br /&gt;
 - clone&lt;br /&gt;
 - pthread&lt;br /&gt;
&lt;br /&gt;
Kernel provides the infrastructure that enables processes&lt;br /&gt;
&lt;br /&gt;
Key features&lt;br /&gt;
 - runs in supervisor mode on the CPU&lt;br /&gt;
   (processes run in user mode)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
CPU modes:&lt;br /&gt;
  user mode - restricted access to system&lt;br /&gt;
  supervisor mode - full access to system resources&lt;br /&gt;
&lt;br /&gt;
the kernel is just what you run in supervisor mode&lt;br /&gt;
processes run in user mode&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do I keep a kernel from crashing?&lt;br /&gt;
 - well, you can&amp;#039;t&lt;br /&gt;
 - test a lot&lt;br /&gt;
 - formal verification (part or whole)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Linux is a monolithic kernel&lt;br /&gt;
 - everything&amp;#039;s in there&lt;br /&gt;
&lt;br /&gt;
But other OS kernels are &amp;quot;microkernels&amp;quot;&lt;br /&gt;
 - make as little as possible run in supervisor mode&lt;br /&gt;
 - less code -&amp;gt; less bugs&lt;br /&gt;
 - bugs in non-supervisor code has lower impact&lt;br /&gt;
&lt;br /&gt;
What *has* to be in a kernel&lt;br /&gt;
 - enough to implement processes&lt;br /&gt;
   - including controlling access to hardware devices&lt;br /&gt;
&lt;br /&gt;
 - code to create&lt;br /&gt;
   - virtual CPUs/execution contexts&lt;br /&gt;
   - memory maps&lt;br /&gt;
   - per-process (or other) access control to other devices&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To make virtual CPUs, you just need a timer that interrupts programs&lt;br /&gt;
and returns control to the kernel (supervisor mode)&lt;br /&gt;
  - multiplexing over time&lt;br /&gt;
  - each process gets a &amp;quot;time slice&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;quot;preemptive multitasking&amp;quot;&lt;br /&gt;
&lt;br /&gt;
there exists in all modern CPUs clocks that can generate &amp;quot;interrupts&amp;quot;&lt;br /&gt;
 - an interrupt causes pre-specified supervisor code to run&lt;br /&gt;
&lt;br /&gt;
Most I/O devices can generate interrupts&lt;br /&gt;
 - video cards&lt;br /&gt;
 - mass storage (HD/SSD)&lt;br /&gt;
 - networking interfaces&lt;br /&gt;
 - keyboard, mouse, etc&lt;br /&gt;
&lt;br /&gt;
(If you don&amp;#039;t have an interrupt, you must &amp;quot;poll&amp;quot; - CPU asks device periodically if it has any data)&lt;br /&gt;
&lt;br /&gt;
Data can also go direct to and from memory via DMA (direct memory access)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For timer interrupts&lt;br /&gt;
--------------------&lt;br /&gt;
&lt;br /&gt;
User space (CPU running in user mode)&lt;br /&gt;
 1. running a regular process&lt;br /&gt;
 5. another process runs (or the same process)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Kernel space (CPU running in supervisor mode)&lt;br /&gt;
 3. timer interrupt handler runs&lt;br /&gt;
    - keeps track of the time, updates counters&lt;br /&gt;
 4. run process scheduler, decide next process to run&lt;br /&gt;
&lt;br /&gt;
Hardware&lt;br /&gt;
 2. timer interrupt goes off&lt;br /&gt;
 &lt;br /&gt;
clocks generate hardware interrupts&lt;br /&gt;
system calls generate software interrupts&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For system calls&lt;br /&gt;
----------------&lt;br /&gt;
&lt;br /&gt;
User space (CPU running in user mode)&lt;br /&gt;
 1. running a regular process&lt;br /&gt;
 2. regular process executed &amp;quot;syscall&amp;quot; instruction&lt;br /&gt;
 5. another process runs (or the same process)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Kernel space (CPU running in supervisor mode)&lt;br /&gt;
 3. syscall handler runs&lt;br /&gt;
    - figures out the system call&lt;br /&gt;
    - does the work of the syscall&lt;br /&gt;
 4. run process scheduler, decide next process to run&lt;br /&gt;
&lt;br /&gt;
Hardware&lt;br /&gt;
 3. hardware notices special instruction, switches to supervisor&lt;br /&gt;
    mode and calls syscall &amp;quot;interrupt&amp;quot; handler&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
callbacks for I/O in node &amp;lt;=&amp;gt; blocked processes in a UNIX system&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
putting a process to sleep =&amp;gt; remove from queue of processes getting CPU time&lt;br /&gt;
&lt;br /&gt;
But what about RAM?&lt;br /&gt;
-------------------&lt;br /&gt;
&lt;br /&gt;
You could just partition it&lt;br /&gt;
 - every process gets a different range of addresses&lt;br /&gt;
 - but what addresses do you use for variables and code?  They&lt;br /&gt;
   would change depending on where the process is loaded&lt;br /&gt;
&lt;br /&gt;
Instead, use virtual addresses&lt;br /&gt;
 - on every memory access, translate virtual addresses to physical addresses&lt;br /&gt;
 - physical addresses are disjoint, virtual addresses can be the same&lt;br /&gt;
   between processes&lt;br /&gt;
&lt;br /&gt;
What do you kick out of the kernel with a microkernel?&lt;br /&gt;
------------------------------------------------------&lt;br /&gt;
* device drivers&lt;br /&gt;
* filesystems&lt;br /&gt;
* networking stacks (TCP/IP)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Real-time operating systems&lt;br /&gt;
---------------------------&lt;br /&gt;
 - gives time-based guarantees for actions&lt;br /&gt;
   &amp;quot;deadlines&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Soma</name></author>
	</entry>
</feed>