Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better fonts and syntax highlighting #41

Open
wants to merge 1 commit into
base: xv6-riscv
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SRC=xv6-riscv-src/

T=latex.out

TEX=$(wildcard $(T)/*.tex)
TEX=$(foreach file, $(SPELLTEX), $(T)/$(file))
SPELLTEX=$(wildcard *.tex)

all: book.pdf
Expand Down
36 changes: 25 additions & 11 deletions book.tex
Original file line number Diff line number Diff line change
@@ -1,37 +1,51 @@
\documentclass[12pt]{book}
\usepackage[T1]{fontenc}
\usepackage{times}
\usepackage{helvet}
\renewcommand{\familydefault}{\sfdefault}
\usepackage{sourcecodepro}
\usepackage{listings}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{url}
% \usepackage{showidx}
\usepackage{imakeidx}
\usepackage{booktabs}
\usepackage{url}
\usepackage{etoolbox} % for showidx
\usepackage{fullpage}
\usepackage{soul}
\usepackage[utf8]{inputenc}
\usepackage{minted}

\usepackage{hyperref} % should be last

% One space after periods
\frenchspacing

\hypersetup{pdfauthor={Russ Cox, Frans Kaashoek, Robert Morris},
pdftitle={xv6: a simple, Unix-like teaching operating system},}

\lstset{basicstyle=\small\ttfamily}
pdftitle={xv6: a simple, Unix-like teaching operating system},
colorlinks=true,
linkcolor=blue,
filecolor=magenta,
urlcolor=cyan,}
\urlstyle{same}


\lstset{basicstyle=\normalsize\ttfamily}
\lstset{morecomment=[is]{[[[}{]]]}}
\lstset{escapeinside={(*@}{@*)}}
\lstset{xleftmargin=5.0ex}
\setminted{
fontsize=\normalsize,
fontfamily=tt
}
\setmintedinline{fontsize=\normalsize}
\usemintedstyle{vs}

\newcommand{\github}{https://github.com/mit-pdos/xv6-riscv/blob/riscv/}
\newcommand{\github}{https://github.com/mit-pdos/xv6-riscv/blob/riscv}

\newcommand{\fileref}[1]{\href{\github/#1}{\small{(#1)}}}
\newcommand{\lineref}[2]{\href{\github/#1\#L#2}{\small{(#1:#2)}}}
\newcommand{\linerefs}[3]{\href{\github/#1\#L#2-L#3}{\small(#1:#2-#3)}}
\newcommand{\fileref}[1]{\href{\github/#1}{\normalsize{(#1)}}}
\renewcommand{\lineref}[2]{\href{\github/#1\#L#2}{\normalsize{(#1:#2)}}}
\newcommand{\linerefs}[3]{\href{\github/#1\#L#2-L#3}{\normalsize(#1:#2-#3)}}

\newcommand{\indextext}[1]{\textit{#1}\index{#1}}
\newcommand{\indextextx}[1]{{#1}\index{#1}}
Expand Down Expand Up @@ -69,11 +83,11 @@
\input{latex.out/sum}

{
% The following prevents latex from splitting a bibliography entry with a page
% The following prevents LaTeX from splitting a bibliography entry with a page
% break
\interlinepenalty=10000
% Since we're using natbib in numbers mode, we don't need plainnat,
% which exists to feed authors and years back in to natbib. As a
% which exists to feed authors and years back into natbib. As a
% result, it complains about entries without years, which we don't
% care about.
%\bibliographystyle{plainnat}
Expand Down
8 changes: 4 additions & 4 deletions fs.tex
Original file line number Diff line number Diff line change
Expand Up @@ -454,15 +454,15 @@ \section{Log design}
\section{Code: logging}

A typical use of the log in a system call looks like this:
\begin{lstlisting}[]
\begin{minted}{c}
begin_op();
...
bp = bread(...);
bp->data[...] = ...;
log_write(bp);
...
end_op();
\end{lstlisting}
\end{minted}

\indexcode{begin_op}
\lineref{kernel/log.c:/^begin.op/}
Expand Down Expand Up @@ -552,13 +552,13 @@ \section{Code: logging}
\indexcode{filewrite}
\lineref{kernel/file.c:/^filewrite/}.
The transaction looks like this:
\begin{lstlisting}[]
\begin{minted}{c}
begin_op();
ilock(f->ip);
r = writei(f->ip, ...);
iunlock(f->ip);
end_op();
\end{lstlisting}
\end{minted}
This code is wrapped in a loop that breaks up large writes into individual
transactions of just a few sectors at a time, to avoid overflowing
the log. The call to
Expand Down
20 changes: 10 additions & 10 deletions lock.tex
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ \section{Races}
If there were no concurrent
requests, you might implement a list \lstinline{push} operation as
follows:
\begin{lstlisting}[numbers=left,firstnumber=1]
\begin{minted}[linenos,firstnumber=1]{c}
struct element {
int data;
struct element *next;
Expand All @@ -119,7 +119,7 @@ \section{Races}
l->next = list; (*@\label{line:next}@*)
list = l; (*@\label{line:list}@*)
}
\end{lstlisting}
\end{minted}

\begin{figure}[t]
\center
Expand Down Expand Up @@ -175,7 +175,7 @@ \section{Races}
this makes the scenario above impossible.
The correctly locked version of the above code
adds just a few lines (highlighted in yellow):
\begin{lstlisting}[numbers=left,firstnumber=6]
\begin{minted}[linenos,firstnumber=6]{c}
struct element *list = 0;
(*@\hl{struct lock listlock;}@*)

Expand All @@ -191,7 +191,7 @@ \section{Races}
list = l; (*@\label{line:list1}@*)
(*@\hl{release(\&listlock)}; @*)
}
\end{lstlisting}
\end{minted}
The sequence of instructions between
\lstinline{acquire}
and
Expand Down Expand Up @@ -291,7 +291,7 @@ \section{Code: Locks}
a word that is zero when the lock is available
and non-zero when it is held.
Logically, xv6 should acquire a lock by executing code like
\begin{lstlisting}[numbers=left,firstnumber=21]
\begin{minted}[linenos,firstnumber=21]{c}
void
acquire(struct spinlock *lk) // does not work!
{
Expand All @@ -302,7 +302,7 @@ \section{Code: Locks}
}
}
}
\end{lstlisting}
\end{minted}
Unfortunately, this implementation does not
guarantee mutual exclusion on a multiprocessor.
It could happen that two CPUs simultaneously
Expand Down Expand Up @@ -569,7 +569,7 @@ \section{Re-entrant locks}
sections. Consider the following two functions \lstinline{f} and
\lstinline{g}:

\begin{lstlisting}
\begin{minted}{c}
struct spinlock lock;
int data = 0; // protected by lock

Expand All @@ -591,7 +591,7 @@ \section{Re-entrant locks}
}
release(&lock);
}
\end{lstlisting}
\end{minted}

Looking at this code fragment, the intuition is that
\lstinline{call_once} will be called
Expand Down Expand Up @@ -743,14 +743,14 @@ \section{Instruction and memory ordering}
line~\ref{line:next2} to a point after the
\lstinline{release}
on line~\ref{line:release}:
\begin{lstlisting}[numbers=left,firstnumber=1]
\begin{minted}[linenos,firstnumber=1]{c}
l = malloc(sizeof *l);
l->data = data;
acquire(&listlock);
l->next = list; (*@\label{line:next2}@*)
list = l;
release(&listlock); (*@\label{line:release}@*)
\end{lstlisting}
\end{minted}
If such a re-ordering occurred, there would be a window during
which another CPU could acquire the lock and
observe the updated
Expand Down
24 changes: 12 additions & 12 deletions sched.tex
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ \section{Sleep and wakeup}
and they executed on different CPUs,
and the compiler didn't optimize too aggressively,
this implementation would be correct:
\begin{lstlisting}[numbers=left,firstnumber=100]
\begin{minted}[linenos,firstnumber=100]{c}
struct semaphore {
struct spinlock lock;
int count;
Expand All @@ -564,7 +564,7 @@ \section{Sleep and wakeup}
s->count -= 1;
release(&s->lock);
}
\end{lstlisting}
\end{minted}

The implementation above
is expensive. If the producer acts
Expand Down Expand Up @@ -612,7 +612,7 @@ \section{Sleep and wakeup}
\lstinline{sleep}
and
\lstinline{wakeup} (changes highlighted in yellow):
\begin{lstlisting}[numbers=left,firstnumber=200]
\begin{minted}[linenos,firstnumber=200]{c}
void
V(struct semaphore *s)
{
Expand All @@ -631,7 +631,7 @@ \section{Sleep and wakeup}
s->count -= 1;
release(&s->lock);
}
\end{lstlisting}
\end{minted}

% \begin{figure}[t]
% \center
Expand Down Expand Up @@ -697,7 +697,7 @@ \section{Sleep and wakeup}
\lstinline{P}
so that its check of the count and its call to \lstinline{sleep}
are atomic:
\begin{lstlisting}[numbers=left,firstnumber=300]
\begin{minted}[linenos,firstnumber=300]{c}
void
V(struct semaphore *s)
{
Expand All @@ -716,7 +716,7 @@ \section{Sleep and wakeup}
s->count -= 1;
release(&s->lock);
}
\end{lstlisting}
\end{minted}
One might hope that this version of
\lstinline{P}
would avoid the lost wakeup because the lock prevents
Expand Down Expand Up @@ -746,7 +746,7 @@ \section{Sleep and wakeup}
reacquires the lock before returning.
Our new correct sleep/wakeup scheme is usable as follows (change
highlighted in yellow):
\begin{lstlisting}[numbers=left,firstnumber=400]
\begin{minted}[linenos,firstnumber=400]{c}
void
V(struct semaphore *s)
{
Expand All @@ -765,7 +765,7 @@ \section{Sleep and wakeup}
s->count -= 1;
release(&s->lock);
}
\end{lstlisting}
\end{minted}

The fact that
\lstinline{P}
Expand Down Expand Up @@ -1543,17 +1543,17 @@ \section{Exercises}
\linerefs{kernel/proc.c:/DOC: sleeplock0/,/^..}/}.
Suppose the special case were eliminated by
replacing
\begin{lstlisting}[]
\begin{minted}{c}
if(lk != &p->lock){
acquire(&p->lock);
release(lk);
}
\end{lstlisting}
\end{minted}
with
\begin{lstlisting}[]
\begin{minted}{c}
release(lk);
acquire(&p->lock);
\end{lstlisting}
\end{minted}
Doing this would break
\lstinline{sleep}.
How?
Expand Down
Loading