<?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_2020W_Lecture_17</id>
	<title>Operating Systems 2020W Lecture 17 - 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_2020W_Lecture_17"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2020W_Lecture_17&amp;action=history"/>
	<updated>2026-06-02T22:26:50Z</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_2020W_Lecture_17&amp;diff=22582&amp;oldid=prev</id>
		<title>Soma: Created page with &quot;==Video==  The video from the lecture given on March 13, 2020 [https://homeostasis.scs.carleton.ca/~soma/os-2020w/lectures/comp3000-2020w-lec17-20200313.m4v is now available]....&quot;</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2020W_Lecture_17&amp;diff=22582&amp;oldid=prev"/>
		<updated>2020-03-20T02:43:04Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;==Video==  The video from the lecture given on March 13, 2020 [https://homeostasis.scs.carleton.ca/~soma/os-2020w/lectures/comp3000-2020w-lec17-20200313.m4v is now available]....&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 video from the lecture given on March 13, 2020 [https://homeostasis.scs.carleton.ca/~soma/os-2020w/lectures/comp3000-2020w-lec17-20200313.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 17&lt;br /&gt;
----------&lt;br /&gt;
&lt;br /&gt;
- doing things remotely&lt;br /&gt;
- discuss /dev/ones&lt;br /&gt;
- discuss newgetpid&lt;br /&gt;
- clock algorithm?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Understanding user data in the kernel&lt;br /&gt;
 - the kernel, like any C program, deals with pointers all the time&lt;br /&gt;
 - most of the time, kernel pointers refer to kernel data structures&lt;br /&gt;
    - i.e., data that belongs to the kernel, residing in the kernel&amp;#039;s&lt;br /&gt;
      virtual address space&lt;br /&gt;
 - but, the kernel also has to be able to get data from userspace programs,&lt;br /&gt;
   particularly as parameters for system calls.  These pass in pointers,&lt;br /&gt;
   but these arguments are pointers to *userspace* data structures and&lt;br /&gt;
   functions - i.e., ones that are in the calling process&amp;#039;s address space&lt;br /&gt;
 - so the kernel has to keep track of userspace pointers and handle&lt;br /&gt;
   them specially (for safety and security reasons)&lt;br /&gt;
     - annotated with __user&lt;br /&gt;
     - accessed using special functions such as get_user, put_user&lt;br /&gt;
        - NEVER use userspace pointers like regular (kernel) pointers!&lt;br /&gt;
&lt;br /&gt;
Pointers to functions and data in the kernel work just like userspace&lt;br /&gt;
 - this includes ones in kernel modules&lt;br /&gt;
 - but, they are running in supervisor mode on the CPU so can access&lt;br /&gt;
   all hardware, all resources&lt;br /&gt;
&lt;br /&gt;
&amp;quot;current&amp;quot; is a special global variable available whenever the kernel&lt;br /&gt;
is processing a system call&lt;br /&gt;
 - refers to the task_struct associated with the process making&lt;br /&gt;
   the system call&lt;br /&gt;
 - many processes can be making system calls at the same time, so&lt;br /&gt;
   there are many &amp;quot;current&amp;quot; pointers at any time&lt;br /&gt;
 - we don&amp;#039;t have to think about current in a kernel module,&lt;br /&gt;
   the rest of the kernel takes care of it, it will magically be right&lt;br /&gt;
&lt;br /&gt;
Note that if you are writing a real device driver (dealing with&lt;br /&gt;
hardware), your module&amp;#039;s code will be called in response to events&lt;br /&gt;
(interrupts) generated by the hardware&lt;br /&gt;
 - functions called when servicing interrupts have no &amp;quot;current&amp;quot; as&lt;br /&gt;
   they aren&amp;#039;t being called in the context of a system call&lt;br /&gt;
&lt;br /&gt;
Why not build in code in the kernel?  Why put it in a module?&lt;br /&gt;
 - we want everything in a module that we can because modules&lt;br /&gt;
   can be removed&lt;br /&gt;
 - code that is just part of the initially loaded kernel is always present,&lt;br /&gt;
   so you should want it all the time&lt;br /&gt;
 - devices vary between systems, so it is natural for device drivers&lt;br /&gt;
   to be in kernel modules - but almost any kernel functionality can&lt;br /&gt;
   be in a module (and most is)&lt;br /&gt;
&lt;br /&gt;
Traditional UNIX kernels had no notion of modules&lt;br /&gt;
 - instead, you specify configuration options at compile time and&lt;br /&gt;
   build a single kernel image&lt;br /&gt;
 - different systems would have different specialized kernels&lt;br /&gt;
 - could work because those kernels ran on relatively few kinds of hardware&lt;br /&gt;
   (all proprietary, specific to one company generally)&lt;br /&gt;
&lt;br /&gt;
If you want to look at interrupts and how they work, look in the textbook&lt;br /&gt;
 - http://pages.cs.wisc.edu/~remzi/OSTEP/file-devices.pdf&lt;br /&gt;
 - look at for context!&lt;br /&gt;
&lt;br /&gt;
Kernel modules are kernel version specific&lt;br /&gt;
 - some source-level portability, but very little binary portability&lt;br /&gt;
 - new kernel -&amp;gt; compile modules from source&lt;br /&gt;
&lt;br /&gt;
What functionality cannot be put into a module?&lt;br /&gt;
 - well, anything needed to actualy load modules...&lt;br /&gt;
 - so basic processes, memory management, etc need to all be built in&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
What if modules have the code needed to get the root filesystem online?&lt;br /&gt;
 - filesystem drivers, hard drive drivers, others?&lt;br /&gt;
 - solution: initial ram disks (initrd)&lt;br /&gt;
&lt;br /&gt;
initrd allows you to limit what is in the base kernel&lt;br /&gt;
&lt;br /&gt;
Idea: boot loader loads a RAM disk with kernel modules along with&lt;br /&gt;
      main kernel image&lt;br /&gt;
&lt;br /&gt;
Note that kernel modules are mostly loaded and unloaded via userspace&lt;br /&gt;
 - but the kernel can generate events that cause userspace programs&lt;br /&gt;
   to load modules&lt;br /&gt;
 - example: insert a USB device, kernel will send an event to a userspace&lt;br /&gt;
   daemon to make sure the modules are loaded to handle the device&lt;br /&gt;
   (actually, that used to be the case, not sure if udev does that now...)&lt;br /&gt;
&lt;br /&gt;
Can kernel modules spawn processes?  Not quite, as a new process requires a system call.&lt;br /&gt;
 - there are kernel threads, you can see them in a process listing&lt;br /&gt;
   (the ones in [])&lt;br /&gt;
&lt;br /&gt;
The standard boot loader for Linux systems is GRUB&lt;br /&gt;
 - is the first thing that loads on boot&lt;br /&gt;
 - GRUB loads the chosen kernel and associated initrd&lt;br /&gt;
 - provides a menu interface so you can choose which kernel to boot&lt;br /&gt;
   (or on multi-os setups, another OS to boot)&lt;br /&gt;
&lt;br /&gt;
(Before GRUB there was LILO.  GRUB is better!)&lt;br /&gt;
&lt;br /&gt;
If you break GRUB your system won&amp;#039;t boot.  Remember that!&lt;br /&gt;
&lt;br /&gt;
Every OS has its own boot loader&lt;br /&gt;
 - Windows has its own&lt;br /&gt;
 - MacOS has its own&lt;br /&gt;
 - the *BSDs have their own&lt;br /&gt;
&lt;br /&gt;
Sometimes you have to use a boot loader to load a boot loader&lt;br /&gt;
 - use GRUB to load the windows boot loader which loads windows&lt;br /&gt;
 - can get...convoluted&lt;br /&gt;
&lt;br /&gt;
Linux tries to be flexible, but not all boot loaders can load it directly&lt;br /&gt;
&lt;br /&gt;
initrd is a small Linux system (minus the kernel), purpose is just to load&lt;br /&gt;
kernel modules&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Soma</name></author>
	</entry>
</feed>