\documentclass[table, usenames]{beamer}
\usetheme{lankton-keynote}
%\usetheme{CambridgeUS}

\usepackage{soul}
\usepackage{xcolor}

\usepackage{amsmath}
\usepackage{amssymb}

\usepackage{datetime}
\usepackage{enumerate}
\usepackage{fontspec}

\usepackage{graphicx}
\usepackage{listings}
\usepackage{makecell}
\usepackage{multicol}
\usepackage{multirow}

\usepackage{soul}
\usepackage{tabularx}
\usepackage{textcomp}
\usepackage{tikz}
\usetikzlibrary{arrows,arrows.meta,automata,calc,decorations.pathmorphing,backgrounds,positioning,fit,scopes,shapes.multipart,shapes.arrows,quotes}

\usepackage{drawstack}
\usepackage{xltxtra}

% define setlistspacing that works w/beamer (would love enumitem...)
\makeatletter
\newcommand{\setlistspacing}[2]{\def\@ld{#1}\expandafter\def\csname
@list\romannumeral\@ld \endcsname{\leftmargin\csname
leftmargin\romannumeral\@ld \endcsname
              \topsep    #2
              \parsep    0\p@   \@plus\p@
              \itemsep   #2}}
\makeatother

\defaultfontfeatures{Scale=MatchLowercase}
\setmainfont{Gentium Book Basic}
\setmonofont{JetBrainsMono Nerd Font} [
  Scale = 0.85,
  ]

\definecolor{commandlinebackground}{gray}{0.35}
\definecolor{commandlineforeground}{gray}{1.00}
\definecolor{commandpromptforeground}{gray}{0.75}

\lstset{language=c++,
  numbers=none,
  numberstyle=\tiny,
  stepnumber=1,
  numbersep=7pt,
  frame=none,
  framerule=0.8pt,
  framesep=5pt,
  captionpos=b,
  showstringspaces=false,
  showlines=true,
  literate={-}{{\texttt{-}}}1{--}{{\texttt{-{}-}}}2{---}{{\texttt{-{}-{}-}}}3,
  basicstyle=\ttfamily,
  rulecolor=\color{black}
}

% ----- Command-line "language" definition for listings -----
\lstdefinelanguage{cline}
{
}
\lstnewenvironment{commandline}[1][]
{\lstset{language=cline,numbers=none,frame=none,backgroundcolor=\color{commandlinebackground},basicstyle=\color{commandlineforeground}\ttfamily,nolol,#1}}
  {}

\title{CIS 310 Operating Systems}
\subtitle{Week 3:  What is an Operating System?}
\author{Dr. Brian C. Ladd}

\tikzset{
  abstractCPU/.pic={
    code={{[y=-1.0cm]
      \node[shape=rectangle, minimum width=5.0cm, minimum
      height=5.0cm, draw] (-cpu) {};

      \draw (-1.4, 2) node {\tiny Registers};
      \foreach \i [evaluate= \i as \y using (2 - (\i + 1)*0.5)] in {0,1,...,3} {
        \draw (-1.4, \y) node[draw, shape=rectangle, minimum width=1.5cm, minimum
        height=0.5cm] (reg\i) {};
      }

      \draw (-1.4, -0.5) node {...};

      \foreach \i [evaluate= \i as \y using (2 - (\i + 1)*0.5)] in {5,6,7} {
        \draw (-1.4, \y) node[draw, shape=rectangle, minimum width=1.5cm, minimum
        height=0.5cm] (reg\i) {};
      }
      \draw (reg6) node[shape=coordinate] (idr) {};
      \draw (reg7) node[shape=coordinate] (pc) {};

      \draw (idr) + (1.25, 0) node[align=left] {\texttt{idr}};
      \draw (reg7) + (1.25, 0) node[align=left] {\texttt{pc}};

      \draw (1, 1) node[shape=rectangle, minimum width=2cm, minimum
      height=1.25cm, draw] (-control) {Control};
      \draw (1, -0.25) node[shape=rectangle, minimum width=2cm, minimum
      height=1.25cm, draw] (-alu) {ALU};

      \coordinate (-out) at ($(-cpu.east) + (0, 1.25cm)$);
      \coordinate (-in) at ($(-cpu.east) + (0, -1.25cm)$);
    }}
  }
}
\tikzset{
  RAM/.pic = {
    code = {{[y=-1.0cm]
       \draw (-1, -0.5) node[anchor=south west,shape=rectangle,minimum width=2cm,
       minimum height=6cm,draw] (-ram) {};
       \foreach \a/\y in
       {0x0000/5.0,0x0001/4.5,0x0002/4.0,0x0003/3.5,0x0004/3.0} {
         \draw (0, \y) node[align=right,anchor=east]{{\tiny \texttt{\a}}}
               (0.25, \y) node[draw, shape=rectangle,minimum width =
               0.5cm, minimum height=0.5cm] {};
       }

       \draw (0.25, 2.5) node {...};

       \foreach \a/\y in
       {0xFFFB/2.0,0xFFFC/1.5,0xFFFD/1.0,0xFFFE/0.5,0xFFFF/0.0} {
         \draw (0, \y) node[align=right,anchor=east]{{\tiny \texttt{\a}}}
               (0.25, \y) node[draw, shape=rectangle,minimum width =
               0.5cm, minimum height=0.5cm] {};

      \coordinate (-out) at ($(-ram.west) + (0, 1.5cm)$);
      \coordinate (-in) at ($(-ram.west) + (0, -1.5cm)$);
       }
    }}
  }
}

\begin{document}
\begin{frame}
  \titlepage
\end{frame}

\begin{frame}
  \frametitle{Outline}
  \tableofcontents
\end{frame}


\section{Setting the Scene}

\begin{frame}
  \frametitle{Computer Architecture}

  \begin{itemize}
  \item CPU
    \begin{itemize}
    \item Registers
    \item Program Counter
    \item \lstinline|fetch|-\lstinline|decode|-\lstinline|execute|
    \end{itemize}
  \item RAM -- An array of bytes
  \item I/O devices
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Computing Resources}
  \begin{itemize}
  \item<+-> CPU \emph{cycles}
  \item<+-> RAM \emph{address spaces}
  \item<+-> RAM \emph{safe concurrent access}
  \item<+-> Device \emph{interaction}
  \item<+-> Persistent storage \emph{organization}
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Side Trip}
  \begin{definition}[Mechanism]
    A \emph{low-level} \alert{capability}. \textbf{How} the system
    works.

    For example: \emph{How} does the operating system switch the
    contexts of two processes?
  \end{definition}
  \begin{definition}[Policy]
    A \emph{high-level} \alert{strategy}. \textbf{Which} resources go
    to which process.

    For example: \emph{Which} process is next scheduled to have the
    CPU after we interrupt the current one?
  \end{definition}

  \vspace{0.5cm}
  \textbf{Policies} are implemented by making use of
  \textbf{mechanisms}. Most mechanisms could be used by
  \emph{different} policies.
\end{frame}

\begin{frame}
  \frametitle{Operating System}

  A \alert{resource manager} for one or more \emph{processes} using
  the computer hardware concurrently.

  \emph{Concurrent} -- Happening at the same time; overlapping
  \emph{duration}.
\end{frame}

\begin{frame}
  \frametitle{Operating System Services}
  \begin{itemize}
  \item<+-> Multiprocessing
  \item<+-> Safe Sharing
  \item<+-> Device Interface
  \item<+-> Persistence (files)
  \item<+-> Error detection/correction/recovery.
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Multiprocessing}
  \begin{itemize}
  \item<+-> Sharing of physical CPU/physical RAM
  \item<+-> Process management -- loading/unloading, starting/pausing/stopping
  \item<+-> Scheduling based on some criteria
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Safe Sharing}

  Uncontrolled access of a single physical resource is inherently
  unsafe.

  Think about a dorm hall with a single \emph{shower}.
\end{frame}

\begin{frame}
  \frametitle{Device Interface}

  Multiple different devices attach to the computer. Many different
  user programs want to use whatever devices are available.

  \begin{itemize}
  \item<+-> A \emph{facade} placed in front of all devices raises the
    level of abstraction at which they are used.
  \item<+-> \emph{Driver} code exposes the required interface while
    hiding the underlying details.
  \end{itemize}

  Think about all the music file formats and then using VLC.
\end{frame}

\begin{frame}
  \frametitle{A File}

  An example of a \alert{common interface}:
  \begin{itemize}
  \item<+-> A \textbf{sequence of bytes}
  \item<+-> Must be \textbf{opened} before/\textbf{closed} after
    interaction.
  \item<+-> A \textbf{naming scheme} is provided to find resources.
  \item<+-> Persists longer than one process execution.
  \end{itemize}

  Some features can be relaxed. \lstinline|/dev/null|, \lstinline|/dev/random|
\end{frame}

\section{Hardware Support for an OS}

\begin{frame}
  \frametitle{What Only Hardware Can Do}
  \begin{itemize}
  \item Interrupts (including Timers)
  \item Privilege Bit
  \item System Calls
  \item Address Translation
  \item Atomic Instructions
  \end{itemize}
\end{frame}


\section{Exploring}

\begin{frame}
  \frametitle{System Calls}
  \begin{itemize}
  \item \lstinline|strace|
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Virtualization}
  \begin{itemize}
  \item \lstinline|ps aux|
  \item \lstinline|htop|
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Looking at Memory}
  \begin{itemize}
  \item \lstinline|gdb|
  \end{itemize}
\end{frame}

\end{document}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:
