mirror of
https://github.com/ebrandi/FDD-book.git
synced 2026-12-06 00:23:30 +00:00
4067 lines
182 KiB
Markdown
4067 lines
182 KiB
Markdown
---
|
|
title: "Final Thoughts and Next Steps"
|
|
description: "Concluding thoughts and guidance for continued learning"
|
|
partNumber: 7
|
|
partName: "Mastery Topics: Special Scenarios and Edge Cases"
|
|
chapter: 38
|
|
lastUpdated: "2026-04-20"
|
|
status: "complete"
|
|
author: "Edson Brandi"
|
|
reviewer: "TBD"
|
|
translator: "TBD"
|
|
estimatedReadTime: 165
|
|
---
|
|
|
|
# Final Thoughts and Next Steps
|
|
|
|
## Introduction
|
|
|
|
You have reached the final chapter of a long book. Before we begin,
|
|
take a moment to notice that simple fact. You are reading the
|
|
closing pages of a manuscript that started, many chapters ago, with
|
|
someone who may have had no kernel experience at all. You opened
|
|
the first chapter as a curious reader. You are closing the last
|
|
chapter as a person who can write, debug, and reason about FreeBSD
|
|
device drivers. That shift did not happen by accident. It happened
|
|
because you kept showing up, chapter after chapter, and put real
|
|
effort into material that most people never try to learn.
|
|
|
|
This chapter is not a technical chapter in the same way the others
|
|
were. You will not find new APIs to memorise, new `DEVMETHOD`
|
|
entries to study, or new bus attachments to trace. The preceding
|
|
thirty-seven chapters have given you a dense working vocabulary of
|
|
FreeBSD kernel practice. What you need now is not more of that. You
|
|
need a chance to step back, take stock of the ground you have
|
|
covered, understand what you can do with it, and choose where to
|
|
aim the skill you have built. The goal of this chapter is to give
|
|
you that space, in a structured and useful form.
|
|
|
|
Reading a technical book from cover to cover is harder than it
|
|
looks. By the end, many readers feel a curious mix of satisfaction
|
|
and uncertainty. Satisfaction, because the book is finished and
|
|
the work was real. Uncertainty, because the end of a book is not a
|
|
clear signal of arrival anywhere in particular. The last page
|
|
closes, the laptop goes back on the shelf, and the reader wonders
|
|
what happens next. If you are feeling that mix, you are in good
|
|
company. It is one of the most honest feelings in technical
|
|
learning, and it usually means you have learned more than you
|
|
realise. This chapter exists in part to help you see that clearly.
|
|
|
|
What happens next, practically, is up to you. The book has given
|
|
you a foundation. The world of FreeBSD is enormous, and there are
|
|
many directions you could take from here. You could pick one of
|
|
the book's drivers and turn it into something polished that you
|
|
submit upstream, bringing it through the workflow you learned in
|
|
Chapter 37. You could choose a new device you have always wanted
|
|
to write a driver for and start from scratch with the patterns you
|
|
now know. You could study one of the advanced areas that this
|
|
book only touched briefly, like deep filesystem work or the inner
|
|
mechanics of the network stack, and start working your way into
|
|
it. You could shift toward community contribution, where your
|
|
skills help other people rather than landing a specific driver.
|
|
Any of these paths is legitimate, and each of them will make you a
|
|
better engineer than the one who finished Chapter 37.
|
|
|
|
The distance between finishing the book and being able to work
|
|
confidently on your own is, in some sense, the theme of this
|
|
chapter. Those are not the same milestone. Finishing the book
|
|
means you have seen and practised enough to recognise the shapes
|
|
of the work. Being able to work on your own means that when you
|
|
sit down in front of a real problem, with no one else to lean on,
|
|
you can find your way through it. The gap between those two
|
|
milestones is closed mostly by practice. By writing drivers,
|
|
debugging them, breaking them, fixing them, reading other people's
|
|
code, and repeating those cycles over weeks and months. No book
|
|
can substitute for that, but a book can help you choose the right
|
|
practice to do next, and it can help you keep your bearings while
|
|
you do it. That is most of what the chapter is about.
|
|
|
|
We will spend time celebrating what you have accomplished, because
|
|
that is both honest and useful. An honest recognition of progress
|
|
is the ground from which the next cycle of learning grows. Without
|
|
it, it is easy to fall into the trap of measuring yourself against
|
|
distant experts rather than against the person you were when you
|
|
started the book. We will then step into a careful self-assessment
|
|
of where you stand now, using the technical material of the book
|
|
as the frame. You will see your own capabilities reflected back at
|
|
you in the language of FreeBSD practice. That is a different kind
|
|
of encouragement from the generic "you can do it" sort. It is the
|
|
kind of encouragement that comes from being able to point to
|
|
something specific you have learned and saying, yes, I can use
|
|
that.
|
|
|
|
From there we will look outward. FreeBSD is a large system, and
|
|
there are several important areas that this book did not cover in
|
|
full depth. Some of those areas are simply too large for any
|
|
single book to cover, and some are rich enough that each deserves
|
|
its own dedicated study. We will name them, explain briefly what
|
|
each is about and why it matters, and point you toward the real
|
|
sources you can use to learn more if you choose to go in that
|
|
direction. The intent here is not to teach you filesystems or
|
|
network-stack internals in a closing chapter. The intent is to
|
|
give you a map so that when you finish this book and start
|
|
thinking about where to go next, you have a clearer sense of the
|
|
landscape.
|
|
|
|
We will also spend meaningful time on the practical work of
|
|
building yourself a development toolkit that you can reuse across
|
|
projects. Every working driver developer accumulates a small
|
|
collection of personal artifacts over time: a driver skeleton
|
|
that captures the patterns they always use, a virtual lab that
|
|
boots quickly and lets them try things without breaking anything,
|
|
a set of scripts that automate the annoying parts of testing, and
|
|
a habit of writing regression tests before they submit changes.
|
|
You do not need to start from scratch with those. The chapter will
|
|
walk you through building a reusable toolkit that you can carry
|
|
forward into any future driver work, and the companion examples
|
|
for this chapter include starter templates you can adapt.
|
|
|
|
A significant part of the chapter turns to the FreeBSD community,
|
|
because much of the longer-term growth that follows a book like
|
|
this comes from community engagement. The community is where you
|
|
see code that was written by hundreds of different hands, where
|
|
you hear how people reason about problems that do not fit neatly
|
|
into a single chapter, and where you find the feedback that helps
|
|
you mature as an engineer. The chapter will show you concretely
|
|
how to engage: which mailing lists matter, how to use Bugzilla,
|
|
how code review happens, and how documentation contributions
|
|
work. It will also explain, more carefully than the earlier book
|
|
managed, what it means to mentor or be mentored in a community
|
|
like FreeBSD, and why contributing to documentation, review, and
|
|
testing is as valuable as contributing code.
|
|
|
|
And finally, because the FreeBSD kernel is a living system that
|
|
changes constantly, we will talk about how to stay current. The
|
|
kernel you learned to write drivers for is FreeBSD 14.3, and by
|
|
the time you read this book at a later date, there will already
|
|
be a newer release with a different set of internal APIs, new
|
|
subsystems, and small changes to the patterns you learned. That
|
|
is not a problem. It is how a healthy kernel evolves. The chapter
|
|
will show you how to follow the changes: through commit logs,
|
|
through mailing lists, through release-notes reading, through the
|
|
conference circuit, and through the habit of periodically
|
|
refreshing your understanding of a subsystem whose driver you
|
|
maintain.
|
|
|
|
The companion material for this chapter is a little different
|
|
from the companion material for earlier chapters. You will find
|
|
it under `examples/part-07/ch38-final-thoughts/`, and it contains
|
|
practical artifacts rather than buildable drivers. There is a
|
|
reusable driver project template that you can copy into any new
|
|
project as a starting point. There is a personal learning roadmap
|
|
template you can use to plan the next three to six months of your
|
|
study. There is a contribution checklist that you can apply the
|
|
first time you send a patch upstream, and every time after that.
|
|
There is a regression-test script skeleton that you can adapt to
|
|
any driver. There is a "stay current" checklist you can use to
|
|
track FreeBSD development on a monthly rhythm. And there is a
|
|
self-assessment worksheet that you can fill out at the end of this
|
|
chapter and keep, so that in six months, when you fill it out
|
|
again, you can see how far you have come.
|
|
|
|
One more framing note before we begin. Some readers will approach
|
|
this chapter as a kind of final exam: a last chance to test
|
|
themselves against the material of the book. That is not the
|
|
spirit of the chapter. There is no grade here and no final test.
|
|
The reflections and exercises in this chapter are not designed to
|
|
catch you out on anything you did not learn. They are designed to
|
|
help you see what you did learn, to see what you might want to
|
|
learn next, and to help you plan the practice that turns a reader
|
|
into an independent practitioner. Approach the chapter with that
|
|
attitude, and it will be useful. Approach it as an exam and you
|
|
will miss most of its purpose.
|
|
|
|
By the end of this chapter you will have a clear, written view of
|
|
what you accomplished during the book, a realistic picture of your
|
|
current skill set, a named and sorted list of advanced topics you
|
|
might want to pursue, a reusable personal development toolkit, a
|
|
clear sense of how to engage with the FreeBSD community, and a
|
|
concrete plan for how to stay connected to FreeBSD's continued
|
|
evolution. You will also, with any luck, feel the quiet confidence
|
|
that comes from having seen a long piece of work through. That
|
|
confidence is not the end of the work; it is the fuel for
|
|
whatever comes next.
|
|
|
|
Let us now begin that final reflection together.
|
|
|
|
## Reader Guidance: How to Use This Chapter
|
|
|
|
This chapter is different in texture from the ones that came
|
|
before it. The earlier chapters were technical: they built up a
|
|
body of concrete knowledge, layered on each other, and culminated
|
|
in Chapter 37's walkthrough of upstream submission. This chapter
|
|
is reflective. Its job is to help you consolidate what you
|
|
learned, plan what you will do with it, and end the book in a way
|
|
that prepares you for the next stage of your work.
|
|
|
|
Because the chapter is reflective rather than technical, the
|
|
reading rhythm is different. In the earlier chapters, a careful
|
|
reader might pause to type code, run a module, or inspect a
|
|
struct in the kernel source. In this chapter, the pauses will be
|
|
different. You will pause to think about what you learned. You
|
|
will pause to write in a notebook or in a Markdown file. You will
|
|
pause to look up a mailing-list archive, or to browse a part of
|
|
the source tree you have not visited, or to check a conference
|
|
schedule. The pauses are the point. If you read straight through
|
|
without stopping, you will lose most of the value of the chapter.
|
|
|
|
Plan to spend a longer block of uninterrupted time on this
|
|
chapter than you spent on most of the earlier ones. Not because
|
|
the reading itself is harder, but because the thinking is. A
|
|
single sitting of two or three hours, with a notebook at hand and
|
|
without interruptions, is the minimum for a useful first pass.
|
|
Some readers will find it more natural to spread the chapter
|
|
across several sessions, treating each section as its own
|
|
reflection exercise. Both approaches work; what matters is that
|
|
the reflection is real, not rushed.
|
|
|
|
The chapter contains labs, just as the earlier chapters did, but
|
|
they are reflection labs rather than coding labs. They will ask
|
|
you to look back at something you wrote during the book and
|
|
examine it with new eyes. They will ask you to write a one-page
|
|
summary of a topic. They will ask you to build a personal
|
|
learning plan. They will ask you to subscribe to a mailing list
|
|
and read a thread. These exercises are not filler. They are the
|
|
practice that turns the book's content into your own working
|
|
knowledge.
|
|
|
|
There are also challenge exercises, again adapted to the chapter's
|
|
reflective character. These are longer and more open-ended than
|
|
the chapter's labs. A reader who does all of them will invest
|
|
several weekends of work. A reader who does just one or two will
|
|
still get substantial value. The challenges are not graded, and
|
|
there is no single correct way to complete them. They are
|
|
invitations to extend the book's material into your own life and
|
|
your own projects.
|
|
|
|
A reasonable reading schedule looks like this. In the first
|
|
sitting, read the introduction and the first two sections. These
|
|
are the consolidation sections: what you accomplished and where
|
|
you stand now. Give yourself time to let the recognition settle.
|
|
In the second sitting, read Sections 3 and 4. These look outward
|
|
toward advanced topics and then back toward the practical toolkit
|
|
you can carry into any future project. In the third sitting, read
|
|
Sections 5 and 6. These are the community and currency sections,
|
|
the ones that matter most for your long-term engagement with
|
|
FreeBSD. Save the labs, the challenges, and the planning exercises
|
|
for a fourth block, or spread them across the week that follows.
|
|
By the time you finish, you will have not only read the chapter
|
|
but also produced a set of personal artifacts that will be useful
|
|
for months or years ahead.
|
|
|
|
If you are reading this book as part of a study group, this
|
|
chapter is especially valuable to discuss together. The technical
|
|
chapters can be read in parallel with relatively little
|
|
coordination. This chapter benefits from conversation. Two readers
|
|
comparing self-assessments will usually see something each one
|
|
missed. A group that sets shared learning goals for the three
|
|
months after finishing the book is more likely to actually pursue
|
|
those goals than individuals working alone.
|
|
|
|
If you are reading alone, keep a journal while you work through
|
|
this chapter. The journal can be paper or digital, whichever
|
|
suits you. Write down your reflections as you go, name the
|
|
advanced topics you want to pursue, list the practical habits you
|
|
want to build, and record the planning artifacts you produce. The
|
|
journal will be something you can return to in the months after
|
|
the book, as you begin the practice that turns reading into
|
|
independent skill.
|
|
|
|
One practical suggestion about the companion files. The chapter's
|
|
examples are not drivers that you compile and load. They are
|
|
templates and worksheets. Copy them out of the book repository
|
|
into a location you control, such as a personal git repository or
|
|
a folder in your home directory. Edit them to reflect your own
|
|
context. Date them. Save older versions when you revise them,
|
|
because a history of your own self-assessments is one of the most
|
|
motivating kinds of learning record. The templates are provided
|
|
so you do not have to start from a blank page, not so you will
|
|
use them verbatim.
|
|
|
|
Finally, give yourself permission to take this chapter seriously
|
|
even if it feels different from the rest of the book. A chapter
|
|
of reflection can feel, to a reader used to technical material,
|
|
like a soft or optional part of the curriculum. It is not. The
|
|
reflection is where the technical material is consolidated into
|
|
working capability, and consolidation is the stage of learning
|
|
that is most often skipped and most often missed. Skipping it
|
|
leaves a reader with many isolated facts and no particular sense
|
|
of what to do with them. Doing it well turns those facts into a
|
|
platform for the next phase of work.
|
|
|
|
With that framing in place, let us turn to the section where this
|
|
book is most explicit: a careful, honest celebration of what you
|
|
have accomplished.
|
|
|
|
## How to Get the Most Out of This Chapter
|
|
|
|
A few habits will help you get the most out of a chapter whose
|
|
material is reflective rather than procedural.
|
|
|
|
The first habit is to bring something to compare against. Find a
|
|
driver you wrote during the book, or a set of labs you worked
|
|
through, or a notebook of questions you noted while reading.
|
|
Bring something concrete that lets you measure your progress. The
|
|
reflections in this chapter become real when they are anchored to
|
|
specific artifacts you produced along the way, and they become
|
|
abstract when they are not. Open the earlier material beside the
|
|
chapter and refer back to it as you read.
|
|
|
|
The second habit is to write as you read. The labs in this
|
|
chapter will ask you to write, but you will get more out of the
|
|
prose sections if you also write informally as you go. Keep a
|
|
notebook or a text file open beside the chapter. Jot down the
|
|
skills you recognise in yourself. Jot down the topics you still
|
|
feel uncertain about. Jot down the questions that surface as you
|
|
read. Writing is where reflection becomes thinking, and thinking
|
|
is where thinking becomes planning. A chapter like this one done
|
|
entirely in your head leaves most of its value on the page.
|
|
|
|
The third habit is to slow down on the forward-looking sections.
|
|
This chapter spends time on advanced topics, the FreeBSD
|
|
community, and how to stay current with the kernel. Those
|
|
sections name specific resources: mailing lists, conferences,
|
|
parts of the source tree, tools you can use. The temptation is to
|
|
read past the names and return to the more comfortable prose. A
|
|
better habit is to actually open a browser tab, visit the
|
|
resource, and note down whether it is one you want to pursue. A
|
|
single hour of doing this during the reading is worth ten hours of
|
|
good intentions afterward.
|
|
|
|
The fourth habit is to be specific. Vague reflection is of
|
|
limited use. Writing "I want to learn more about the network
|
|
stack" is less useful than writing "I want to spend two weeks
|
|
reading `/usr/src/sys/net/if.c` and the `ifnet(9)` manual page,
|
|
and then write a short driver for a virtual network interface
|
|
using what I learn". Specificity makes plans achievable and
|
|
vagueness makes plans evaporate. When the chapter asks you to
|
|
identify next steps, identify them at a level of detail you could
|
|
actually start work on this weekend.
|
|
|
|
The fifth habit is to give yourself time. This chapter is the end
|
|
of a long book, and a common pattern at the end of long books is
|
|
a rush to finish. Resist that pattern. The reflections are worth
|
|
more than the speed. If you read the chapter in one sitting and
|
|
feel no different at the end, you probably moved too fast through
|
|
the parts that asked you to think. A good rule of thumb is that
|
|
if you did not stop to write at least twice during the chapter,
|
|
you did not engage with it in the way it was designed to be
|
|
engaged with.
|
|
|
|
The sixth habit is to avoid the comparison trap. When readers of
|
|
a technical book reach the end, they sometimes compare themselves
|
|
to imagined experts and find the comparison discouraging. This is
|
|
not useful. The right comparison is between the person you were
|
|
when you opened Chapter 1 and the person you are now. Measured
|
|
that way, almost every reader has made real progress. Measured
|
|
against a senior committer who has spent a decade inside the
|
|
FreeBSD tree, almost every reader falls short, and that is normal
|
|
and meaningless. Pick the useful comparison, not the discouraging
|
|
one.
|
|
|
|
The final habit is to plan to return to this chapter. Unlike the
|
|
technical chapters, which you will probably not reread in full,
|
|
this chapter benefits from rereading at natural checkpoints in
|
|
your post-book work. When you finish your first driver after the
|
|
book, revisit the self-assessment. When you send your first patch
|
|
upstream, revisit the contribution checklist. When you have been
|
|
following freebsd-hackers for six months, revisit the stay-current
|
|
section. The chapter is designed to be reusable in this way.
|
|
|
|
With those habits in mind, let us turn to the first section, where
|
|
we take an honest look at what you accomplished during the book.
|
|
|
|
## 1. Celebrating What You Have Accomplished
|
|
|
|
We begin with a section that asks you to pause and take stock,
|
|
honestly, of what you have done. This is not a pep talk. It is a
|
|
working part of the chapter. Many readers underestimate how much
|
|
they learned during a long technical book, especially a book that
|
|
requires as much sustained attention as this one. That
|
|
underestimation is costly. A reader who does not recognise their
|
|
own progress has a harder time deciding what to do next, because
|
|
they cannot see clearly what they already have to build on.
|
|
|
|
### 1.1 A Recap of What We Have Covered
|
|
|
|
Think back to the first chapter you read. The book opened with an
|
|
author's story about curiosity, a quick overview of why FreeBSD
|
|
matters, and an invitation to begin. The second chapter helped
|
|
you set up a lab environment. The third chapter introduced UNIX
|
|
as a working system. The fourth and fifth chapters taught you C,
|
|
first as a general language and then as a dialect shaped for
|
|
kernel use. The sixth chapter walked you through the anatomy of a
|
|
FreeBSD driver as a conceptual structure, before you had written
|
|
one yourself.
|
|
|
|
Part 2 of the book, spanning Chapters 7 through 10, is where you
|
|
started writing real code. You wrote your first kernel module. You
|
|
learned how device files work and how to create them. You
|
|
implemented read and write operations. You explored efficient
|
|
input and output patterns. Each of those chapters had its own
|
|
labs, and by the end of Part 2 you had produced several small
|
|
drivers that actually loaded, actually exposed device files, and
|
|
actually moved bytes between userland and kernel.
|
|
|
|
Part 3, Chapters 11 through 15, took you into concurrency. You
|
|
learned about mutexes, shared/exclusive locks, condition
|
|
variables, semaphores, callouts, and taskqueues. You worked
|
|
through synchronisation problems that newcomers to the kernel
|
|
often find intimidating, and you practised the discipline of
|
|
locking conventions that the rest of the book later depended on.
|
|
This part is where many readers report the steepest learning
|
|
curve, and if you made it through, you did real work.
|
|
|
|
Part 4, Chapters 16 through 22, was about hardware and
|
|
platform-level integration. You accessed registers directly. You
|
|
wrote simulated hardware for testing. You built a PCI driver. You
|
|
handled interrupts at a basic level and then at an advanced level.
|
|
You transferred data with DMA. You explored power management.
|
|
This is the part where the book changed from teaching you C with a
|
|
kernel flavour into teaching you how kernels talk to real
|
|
hardware. The gap between those two skills is large, and closing
|
|
it is one of the biggest jumps in the book.
|
|
|
|
Part 5, Chapters 23 through 25, turned to the practical side of
|
|
driver work: debugging, integration, and the habits that separate
|
|
a driver that works on a demo from a driver that holds up in real
|
|
use. You practised with `dtrace`, `kgdb`, `KASSERT`, and the other
|
|
tools the kernel provides for seeing inside itself. You learned
|
|
how to handle real-world problems that do not have textbook
|
|
answers.
|
|
|
|
Part 6, Chapters 26 through 28, covered three transport-specific
|
|
driver categories: USB and serial, storage and VFS, and network
|
|
drivers. Each of these is a specialised area in its own right, and
|
|
each introduced a new way of thinking about devices that was
|
|
quite different from the character drivers of Part 2. By the end
|
|
of Part 6, you had seen the major shapes that FreeBSD drivers
|
|
take, not just in the abstract but in working examples.
|
|
|
|
Part 7, the part that contains this chapter, has been the mastery
|
|
arc. You studied portability across architectures. You looked at
|
|
virtualisation and containerisation. You worked through security
|
|
best practices, the device tree and embedded systems, performance
|
|
tuning and profiling, advanced debugging, asynchronous I/O, and
|
|
reverse engineering. Finally, in Chapter 37, you walked through
|
|
the complete process of submitting a driver to the FreeBSD
|
|
Project, from the social dynamics of contribution to the practical
|
|
mechanics of `git format-patch`. And now, in Chapter 38, you are
|
|
closing the book.
|
|
|
|
Listed like this, what you have covered looks substantial, and it is. The
|
|
book has not been padding. Every chapter added something specific
|
|
to your working knowledge. Even chapters that felt familiar on
|
|
first reading probably taught you patterns of thinking that you
|
|
internalised without fully noticing. The patterns are the most
|
|
valuable part, because they are what let you apply the knowledge
|
|
in situations the book did not explicitly cover.
|
|
|
|
Take a moment, before moving on, to think about which chapters
|
|
felt the most challenging to you. Not in the abstract sense of
|
|
"which was the longest chapter" but in the personal sense of
|
|
"which chapter changed the most for me as I read it". For some
|
|
readers it is the jump from ordinary C to kernel C in Chapter 5.
|
|
For others it is the concurrency work in Part 3. For some it is
|
|
the interrupt and DMA material in Part 4, for others the network
|
|
or storage work in Part 6, and for some the reverse engineering of
|
|
Chapter 36. There is no single correct answer. The chapter that
|
|
changed the most for you is the one where you grew the most, and
|
|
noticing which one it was is useful information about your own
|
|
pattern of learning.
|
|
|
|
### 1.2 Skills You Have Developed
|
|
|
|
Your progress is measured not only in chapters read but in skills
|
|
acquired. Let us take a careful look at what you can now do, in
|
|
language that describes capability rather than content.
|
|
|
|
You can write and reason about C in the kernel dialect. That is
|
|
not the same skill as writing C for a command-line program. Kernel
|
|
C has its own set of constraints, its own preferred idioms, and
|
|
its own error-handling conventions. You know about the
|
|
`M_WAITOK` / `M_NOWAIT` choice. You understand why kernel allocations
|
|
must sometimes not sleep. You have seen the `goto out` style of
|
|
cleanup and understand why it fits the kernel's needs. You know
|
|
when to use `memcpy` and when to use `copyin`. You know why
|
|
kernel-to-userland and userland-to-kernel data transfer must go
|
|
through specific functions rather than ordinary pointer
|
|
dereferences. Each of those is a small habit, but together they
|
|
form a dialect that you now speak.
|
|
|
|
You can debug and trace kernel code. You know how `dtrace` works.
|
|
You know the difference between the function boundary tracing
|
|
provider and the statically defined tracing provider. You know how
|
|
`kgdb` attaches to a crash dump. You know what a `KASSERT` does,
|
|
how to read a panic message, and how to use `witness` to detect
|
|
lock-order violations. You know that `printf` in the kernel is a
|
|
legitimate tool but not a substitute for structured diagnostics.
|
|
You have built up the habit, over the course of Part 5 and later
|
|
parts, of using the right diagnostic tool for the situation rather
|
|
than defaulting to whatever is most familiar.
|
|
|
|
You can integrate a driver with the device tree and embedded
|
|
systems. You understand the FDT format and how FreeBSD parses it.
|
|
You know how to declare a driver that binds to a device-tree
|
|
compatible string. You know what an embedded target looks like in
|
|
practice: a slow boot, a small memory budget, a non-console
|
|
serial port as the primary interface, and a reliance on
|
|
hand-compiled kernels for each target board.
|
|
|
|
You know the basics of reverse engineering and embedded
|
|
development. You know how to identify a device with `pciconf` or
|
|
`usbconfig`, how to capture its initialisation sequence with
|
|
`usbdump`, and how to build a register map by experiment. You
|
|
know the legal and ethical framing of interoperability work.
|
|
You know the discipline of separating observation from hypothesis
|
|
from verified fact, and you know how to write a pseudo-datasheet
|
|
that records what you learned. You are not an expert reverse
|
|
engineer, and the book has been honest about that, but you know
|
|
enough to start and to stay safe while you learn.
|
|
|
|
You can build userland interfaces for your drivers. You know how
|
|
`devfs` publishes a device node. You know how to implement read,
|
|
write, ioctl, poll, kqueue, and mmap operations. You know the
|
|
standard `cdevsw` pattern. You know how to expose tunable
|
|
parameters through `sysctl(9)`. You know how to structure a driver
|
|
so that userspace programs can cooperate with it cleanly, and you
|
|
have seen how poor userland interfaces are one of the most common
|
|
reasons a driver is hard to maintain.
|
|
|
|
You understand concurrency and synchronization as it is practised
|
|
in the kernel, not just in the abstract. You know the difference
|
|
between an ordinary mutex and a spin mutex. You know when to
|
|
reach for an `sx` lock and when `rmlock` is the better choice.
|
|
You know what condition variables are for and how to use them
|
|
without introducing lost-wakeup bugs. You know how to structure a
|
|
taskqueue for deferred work. You know the `epoch(9)` interface for
|
|
RCU-style readers. Each of those is a tool you know by its proper
|
|
name and purpose, and you can apply it to a real problem without
|
|
needing to look up the basics.
|
|
|
|
You can interact with hardware through DMA, interrupts, and
|
|
register access. You have written code that sets up a DMA tag,
|
|
allocates a map, loads a map, and syncs a map before and after
|
|
transfers. You have written interrupt handlers that are careful
|
|
about what they can and cannot do. You have used `bus_space(9)`
|
|
to read and write registers on real hardware and on simulators.
|
|
You have handled both filter and ithread interrupts. These are
|
|
not abstract ideas for you any longer; they are practices you
|
|
have executed.
|
|
|
|
You are ready to think seriously about upstream submission. You
|
|
know the shape of a FreeBSD submission. You know `style(9)` and
|
|
`style.mdoc(5)`. You know the structure of `/usr/src/sys/dev/`
|
|
directories. You know how to write a manual page that lints
|
|
cleanly. You know the Phabricator workflow and the GitHub
|
|
workflow. You know what a reviewer will look for and how to
|
|
respond to review feedback productively. That is a substantial
|
|
body of knowledge, and most self-taught kernel developers never
|
|
reach it.
|
|
|
|
Each of these skills, taken alone, would be worth serious study.
|
|
Taken together, they describe a working FreeBSD device-driver
|
|
developer. You have all of them now. You may not be equally
|
|
confident in each one. That is normal. Part of the next section
|
|
will help you notice where you are strong and where you have room
|
|
to grow.
|
|
|
|
### 1.3 Reflection: What Has Actually Changed
|
|
|
|
Before moving on to self-assessment, take a moment to consider
|
|
what has actually changed about you as a technical reader since
|
|
you started this book.
|
|
|
|
When you first opened Chapter 1, a line of kernel code may have
|
|
looked opaque. The macros were unfamiliar. The structures felt
|
|
arbitrary. The control flow seemed impossibly indirect. Now, when
|
|
you open a driver in `/usr/src/sys/dev/`, you can read the shape
|
|
of it. You can find the probe and attach routines. You can
|
|
identify the method table. You can see where locks are acquired
|
|
and released. The text has become navigable. That change is
|
|
invisible until you pause to notice it, but it is among the most
|
|
important things the book has done for you.
|
|
|
|
When you first encountered a kernel panic, it may have been a
|
|
blank wall of fear. You did not know what to do with it, what to
|
|
read, or how to recover from it. Now a panic is a piece of
|
|
information. You know how to read the stack trace. You know what
|
|
a page fault means in the kernel. You know the difference between
|
|
a recoverable panic from a clean assertion and an unrecoverable
|
|
panic from memory corruption. A panic has gone from being a wall
|
|
to being a diagnostic tool, and that shift is a large one.
|
|
|
|
When you first heard the phrase "write a device driver," the
|
|
phrase may have felt impossibly advanced. Drivers were what other
|
|
people wrote, perhaps hardware engineers in large companies, and
|
|
the technical apparatus required seemed remote. Now, writing a
|
|
driver is a concrete activity. You know what you need: a FreeBSD
|
|
14.3 system, a text editor, a working knowledge of C, the set of
|
|
kernel APIs the book covered, a piece of hardware or a simulator,
|
|
and some time. That shift in perception is the difference between
|
|
treating drivers as a mystery and treating them as a craft.
|
|
|
|
When you first read a line referring to a lock order, it may have
|
|
seemed like an academic subtlety. Now you know what lock order
|
|
actually means, and why reversing it can crash a kernel, and how
|
|
`witness` detects the violation, and how to structure a driver so
|
|
that the violation never happens. This is not a theoretical
|
|
understanding any more. It is a working practice.
|
|
|
|
When you first encountered the FreeBSD source tree, it may have
|
|
felt like a vast undifferentiated forest. You knew there was
|
|
something in there somewhere, but you did not know how to navigate
|
|
to it. Now you have a feel for the tree. You know that
|
|
`/usr/src/sys/dev/` is where device drivers live, that
|
|
`/usr/src/sys/kern/` is where the core kernel code lives, that
|
|
`/usr/src/sys/net/` is the networking stack, and that
|
|
`/usr/src/share/man/man9/` is where the kernel API manual pages
|
|
live. You can navigate. You can find. You can follow a function
|
|
call from caller to callee and back. The tree has become a
|
|
workspace, not a maze.
|
|
|
|
These changes are the real measure of the book. They are not
|
|
about specific APIs you can recite from memory. They are about
|
|
the shape of the world you see when you sit down at a terminal
|
|
and open a driver. Take a moment to appreciate the shift. It is
|
|
real, and it is yours.
|
|
|
|
### 1.4 Why Celebrating Progress Matters
|
|
|
|
Technical cultures often underplay the importance of recognising
|
|
progress. The implicit assumption is that the work is its own
|
|
reward and that anything more than that is sentimental. This is
|
|
bad psychology, and it leads to burnout and to the curious
|
|
phenomenon of experienced engineers who do not recognise their
|
|
own expertise.
|
|
|
|
Recognising progress is not sentimental. It is functional. A
|
|
learner who can see their own progress chooses harder next steps
|
|
with confidence. A learner who cannot see their own progress
|
|
stays at the easy steps because they do not know they have
|
|
outgrown them. The point of celebrating is not to feel good, or
|
|
at least not only to feel good. It is to clear the fog from the
|
|
next decision about what to learn and what to build.
|
|
|
|
The book has been a long investment. Measured in hours, it is
|
|
probably a larger investment than you might notice in aggregate.
|
|
An honest accounting of the time you spent reading, working
|
|
through labs, and thinking between sessions would likely surprise
|
|
you. That time should produce outputs. One of the outputs is
|
|
skill. Another is the confidence to take on the next project.
|
|
Both outputs are easier to use when you have acknowledged them.
|
|
|
|
There is a specific kind of progress worth noting. You have built
|
|
up not only facts about FreeBSD but also a way of working. You
|
|
have learned to slow down before complex problems. You have
|
|
learned to write tests. You have learned to read source code
|
|
before writing your own. You have learned to decompose a
|
|
kernel-space task into manageable pieces. These are portable
|
|
habits. They apply to work outside FreeBSD, outside kernel
|
|
programming, and even outside systems software. Engineers who
|
|
have them are better engineers in many contexts, and engineers
|
|
who do not have them struggle even in familiar territory.
|
|
|
|
If you have been reading this section quickly and feel tempted to
|
|
skip past it, pause. Take five minutes. Think back through the
|
|
book. Notice one concrete thing you can do now that you could
|
|
not do before. Write it down. That is the exercise that makes the
|
|
section count.
|
|
|
|
### 1.5 Exercise: Write a Personal Reflection
|
|
|
|
This subsection's exercise is simple in structure and hard to do
|
|
well. Write a personal reflection on your experience working
|
|
through this book. It can be a blog post, a private notebook
|
|
entry, an email to a friend, or a personal journal page.
|
|
|
|
The reflection should not be a summary of what the book covered.
|
|
The book has done that for itself. The reflection should be about
|
|
what your experience was. What surprised you about kernel
|
|
development? Which chapter changed your understanding the most?
|
|
Where did you get stuck, and what got you unstuck? What do you
|
|
think about FreeBSD now that you did not think at the start?
|
|
|
|
Writing reflections like this is more valuable than it looks. It
|
|
is a form of learning-to-see. The act of writing forces a
|
|
specific articulation, and a specific articulation is
|
|
transferable in ways that a vague impression is not. Ten years
|
|
from now, if you are still writing FreeBSD drivers, you will
|
|
benefit from having written this reflection now. You will also
|
|
benefit from being able to read it, because your sense of what
|
|
was hard at this stage will shift as you grow, and the only way
|
|
to keep an honest record of where you were is to write it down
|
|
when you were there.
|
|
|
|
A good reflection is usually between five hundred and fifteen
|
|
hundred words. It does not need to be polished. It does not need
|
|
to be publishable. It needs to be honest. If you share it
|
|
publicly, the BSD community has a long tradition of welcoming
|
|
such reflections on mailing lists, on personal blogs, and at
|
|
conferences, and you may find that sharing your reflection
|
|
connects you with people who went through the same process at a
|
|
different time. If you keep it private, that is equally
|
|
legitimate, and the act of writing is still the point.
|
|
|
|
Date the reflection. Put it somewhere you can find it again. Keep
|
|
it for the future-you who will want to look back at the moment
|
|
when you finished this book.
|
|
|
|
### 1.6 Wrapping Up Section 1
|
|
|
|
This section asked you to pause and recognise what you have
|
|
accomplished. That recognition is not ornamental. It is the
|
|
ground from which informed next steps are chosen. A reader who
|
|
cannot point to specific skills gained, specific shifts in
|
|
perception, and specific artefacts produced by the book will
|
|
struggle to decide what to do next. A reader who can point to
|
|
those things will find the next decision easier.
|
|
|
|
We will now move into a more analytical section, where we look
|
|
carefully at what the accomplishment means in practical terms.
|
|
What, concretely, are you now capable of doing? Where are you
|
|
strong, and where do you have room to grow? Section 2 turns those
|
|
questions into a careful self-assessment. The answers will inform
|
|
the planning work that comes later in the chapter.
|
|
|
|
## 2. Understanding Where You Stand Now
|
|
|
|
Celebrating progress is one thing. Knowing where you stand is
|
|
another. This section asks you to look at your skill set with
|
|
engineer's eyes: not to judge yourself harshly, and not to flatter
|
|
yourself, but to form an accurate and specific picture of what
|
|
you can do, what you could do with a little more practice, and
|
|
what still lies ahead. That picture is what makes the later parts
|
|
of the chapter useful.
|
|
|
|
### 2.1 You Are Now Capable Of
|
|
|
|
Let us state it plainly, in the voice of someone describing a
|
|
capable colleague. If someone asked what you can do with FreeBSD
|
|
device drivers, here is an honest version of the answer.
|
|
|
|
You can write a kernel module for FreeBSD 14.3 that loads
|
|
cleanly, registers a device node, handles read and write
|
|
operations, and unloads without leaking resources. You can do this
|
|
starting from scratch, using a text editor and the FreeBSD source
|
|
tree as your only references, without needing to copy an existing
|
|
module verbatim. You have done that repeatedly throughout the
|
|
book, and the pattern is now in your hands.
|
|
|
|
You can debug that module when it crashes. If it panics, you can
|
|
interpret the stack trace. You can set up a crash-dump
|
|
configuration and attach `kgdb` to the resulting dump. You can
|
|
add `KASSERT` statements to catch invariant violations earlier.
|
|
You can run `dtrace` to see what the module actually did. You
|
|
can watch `vmstat -m` to catch memory leaks. None of these are
|
|
abstract to you; they are tools you have used.
|
|
|
|
You can interface with userland cleanly. You know how to implement
|
|
ioctls with the `_IO`, `_IOR`, `_IOW`, and `_IOWR` macros, and you
|
|
know why `ioctl` numbers matter for ABI stability. You know how
|
|
to use `copyin` and `copyout` to move data across the kernel/
|
|
userland boundary safely. You know how to expose state through
|
|
`sysctl(9)` so that administrators can see and change what the
|
|
driver is doing without needing to write a specialised tool.
|
|
|
|
You can interface with hardware. You know how to allocate memory
|
|
and IRQ resources from a Newbus bus. You know how to read and
|
|
write registers through `bus_space(9)`. You know how to set up
|
|
DMA transfers, including the tag, the map, and the synchronisation
|
|
calls. You know how to write an interrupt handler that does only
|
|
what an interrupt handler should do and defers the rest to a
|
|
taskqueue or an ithread. Each of these is a practical capability,
|
|
not just a topic you read about.
|
|
|
|
You can submit a patch to the FreeBSD Project. You know the
|
|
pre-submission hygiene: style check, manual-page lint, build
|
|
across architectures, load/unload cycle. You know how to generate
|
|
a patch that the project's tools can read. You know how to engage
|
|
with reviewers productively. You know the difference between
|
|
Phabricator and GitHub workflows and why the project has been
|
|
moving between them. You have not necessarily submitted a real
|
|
patch yet, but the workflow is no longer a mystery to you, and
|
|
the day you decide to submit will not be the day you first learn
|
|
how.
|
|
|
|
These are not ambitious claims. They are an honest accounting of
|
|
what finishing this book means.
|
|
|
|
### 2.2 Confidence With Core Technologies
|
|
|
|
Let us now look at specific technologies you have learned, and
|
|
let us ask about your confidence with each one. The purpose is
|
|
not to grade yourself but to locate where you are strong and where
|
|
you might want to invest some time.
|
|
|
|
**bus_space(9):** You have used it to read and write registers.
|
|
You know the difference between the tag, the handle, and the
|
|
offset. You know that `bus_space_read_4` and `bus_space_write_4`
|
|
are byte-order-respectful abstractions that work across
|
|
architectures. You probably do not yet have a deep sense of how
|
|
`bus_space` is implemented on different architectures, because
|
|
that is a deeper topic, but at the level the book covered, you
|
|
are comfortable.
|
|
|
|
**sysctl(9):** You have used it to expose tunable parameters. You
|
|
know the tree structure of sysctl names, how to add a leaf with
|
|
`SYSCTL_PROC`, and how to use the `OID_AUTO` pattern. You can
|
|
read the output of `sysctl -a` and understand where your driver's
|
|
entries live. This is one of the most approachable kernel
|
|
interfaces, and you have practised with it enough to reach for it
|
|
naturally.
|
|
|
|
**dtrace(1):** You have used it to observe kernel behaviour. You
|
|
know the `fbt` provider, the `syscall` provider, and the basics of
|
|
the D language. You have probably not written your own static
|
|
tracepoints yet, because that is a topic the book touched but did
|
|
not work through exhaustively. That is an excellent area for
|
|
continued learning, and the `dtrace(1)` manual page along with the
|
|
DTrace guide make it a pleasure to study.
|
|
|
|
**devfs(5):** You know that device nodes appear under `/dev/`
|
|
because `make_dev_s` was called at attach time. You know how
|
|
cloning device drivers work. You have not likely explored the
|
|
internals of devfs in full depth, because that is kernel internal
|
|
territory and not something most driver authors need. You know it
|
|
as a user: you know what it provides, and you have used it.
|
|
|
|
**poll(2), kqueue(2):** You implemented these for your async I/O
|
|
work in Chapter 35. You know how the poll and kqueue subsystems
|
|
interact with the kernel's wakeup mechanisms. You know when to
|
|
pick one over the other, and you know why kqueue is generally the
|
|
preferred interface for new code on FreeBSD. You have the working
|
|
knowledge to implement these for any new driver you write.
|
|
|
|
**Newbus, DEVMETHOD, DRIVER_MODULE:** These are the
|
|
registration mechanics of a FreeBSD driver. You have written them
|
|
enough times that they no longer feel unfamiliar. You know which
|
|
methods are standard, how to handle custom methods, and how the
|
|
registration order affects attach sequencing.
|
|
|
|
**Locking:** You have used mutexes, sx locks, rmlocks, condition
|
|
variables, and epoch protections. Your confidence with each of
|
|
these probably varies. Mutexes are likely the most natural to
|
|
you; epoch may still feel less so. That is typical, and it is
|
|
fine. Each of the more advanced synchronisation primitives has
|
|
its own set of patterns that become clearer with use.
|
|
|
|
**Upstream workflow:** You know the mechanics of generating a
|
|
patch, handling review, responding to feedback, and maintaining a
|
|
driver after merge. You probably have not yet done a real
|
|
submission, because doing one takes more than reading a chapter.
|
|
Your first submission will probably feel slow and uncertain, even
|
|
with all this preparation, and that is normal. The second and
|
|
third will be faster.
|
|
|
|
Take a moment to rate your confidence with each of these, not as
|
|
a formal exercise but as a quick mental map. Rate yourself from
|
|
one to five, where one is "I have heard of it" and five is "I
|
|
could teach it". The locations where you rate yourself at three
|
|
or four are probably your most productive next learning targets:
|
|
you know enough to practise, and a little more practice will turn
|
|
the skill into something you trust.
|
|
|
|
### 2.3 Review Exercise: Map the APIs You Used
|
|
|
|
This subsection contains a review exercise that is genuinely
|
|
valuable and only takes about an hour.
|
|
|
|
Pick a driver you wrote during the book. It can be the final async
|
|
driver from Chapter 35, the network driver from Chapter 28, a
|
|
Newbus driver from Part 6, or any other non-trivial piece of code
|
|
you produced. Open the source file. Go through it top to bottom.
|
|
Every time you see a function call, a macro, a structure, or an
|
|
API that came from the kernel, write it down.
|
|
|
|
When you are finished, you will have a list of somewhere between
|
|
twenty and eighty kernel identifiers. Each of them represents an
|
|
interface you invoked. Next to each one, write a one-sentence
|
|
summary of what it does and why you used it. For example:
|
|
|
|
- `make_dev_s(9)`: creates a device node under `/dev/`. I used it
|
|
in attach to expose the driver to userland.
|
|
- `bus_alloc_resource_any(9)`: allocates a resource of a given
|
|
type from the parent bus. I used it to get the memory window
|
|
for the device registers.
|
|
- `bus_dma_tag_create(9)`: creates a DMA tag with constraint
|
|
parameters. I used it to set up the DMA layer before loading
|
|
any maps.
|
|
|
|
The exercise has two benefits. The first is that it forces you to
|
|
articulate, in your own words, what each interface does. That
|
|
articulation is the difference between recognising an interface
|
|
and understanding it. The second benefit is that the resulting
|
|
list is a concrete record of what you know. You can keep it as a
|
|
reference, and you can compare it against the next driver you
|
|
write to see how your vocabulary has grown.
|
|
|
|
If you find an API on the list that you cannot explain in a
|
|
sentence, that is a signal to open the manual page and read it.
|
|
The exercise doubles as a diagnostic. The places where your
|
|
explanation is weak are the places where more practice will have
|
|
the most impact.
|
|
|
|
### 2.4 The Difference Between Having Followed the Book and Being Independent
|
|
|
|
There is an important distinction worth naming clearly. Finishing
|
|
this book is not the same thing as being able to work
|
|
independently, and it is worth understanding the distinction
|
|
because it shapes the rest of the chapter.
|
|
|
|
When you followed the book, you had a guided path. The chapters
|
|
introduced concepts in an order that had been thought about. The
|
|
labs built on each other. When you got stuck, the next paragraph
|
|
of the book often addressed the sticking point. The author had
|
|
anticipated many of your questions and answered them before you
|
|
asked. That structure is valuable, but it has limits.
|
|
|
|
Working independently means you no longer have that structure.
|
|
The problem in front of you is not organised in an order that was
|
|
designed for your learning. The APIs you need to use may be ones
|
|
that the book named but did not exercise in detail. The pitfalls
|
|
you hit may be ones the book did not warn you about specifically.
|
|
The time you spend stuck is not bounded by the length of a
|
|
chapter; it is bounded by your own persistence.
|
|
|
|
Readers who finish a book like this sometimes feel disappointed
|
|
when they sit down to their first independent project and
|
|
discover that it is harder than the labs were. That is not a sign
|
|
that the book failed them. It is the ordinary transition from
|
|
guided to independent practice. The book has given you the tools
|
|
to close the gap, but the closing is work that you do, not work
|
|
that the book does for you.
|
|
|
|
Several things help with this transition. The first is to pick
|
|
smaller independent projects than you think you need. An easy
|
|
win is worth more than an ambitious failure, especially early on.
|
|
A small pseudo-device driver that does one thing correctly is a
|
|
better first independent project than an ambitious network
|
|
driver that does not quite work. The second is to keep the book
|
|
open beside you while you work. You are not cheating by referring
|
|
back to it. You are using a reference, and that is what
|
|
references are for. The third is to expect the first project to
|
|
take longer than you think it should. That is not a bug. It is
|
|
the shape of the transition.
|
|
|
|
Over time, your independence grows through practice rather than
|
|
through reading. Each new driver you write, each bug you track
|
|
down alone, each patch you submit to the project, adds to the
|
|
pool of experience that lets you work without needing to look
|
|
everything up. The book is a starting point for that process. The
|
|
process itself is yours.
|
|
|
|
### 2.5 Identifying Your Strongest and Weakest Areas
|
|
|
|
A useful self-assessment exercise at this stage is to identify,
|
|
specifically, which areas you feel most confident in and which
|
|
areas you feel you still need to deepen.
|
|
|
|
Confidence comes from having applied the knowledge successfully
|
|
several times. If you wrote a character driver in Part 2 and
|
|
never again, your confidence in that area is single-instance. If
|
|
you handled interrupts in Chapter 19 and again in Chapter 20, and
|
|
in a lab in Chapter 35, your confidence in that area has been
|
|
exercised multiple times. The former is knowledge; the latter is
|
|
skill.
|
|
|
|
Go through the major topics of the book and, for each one, ask
|
|
yourself honestly: if someone handed me a new problem in this
|
|
area, could I start on it without looking things up? The topics
|
|
where the answer is a clear yes are your strongest areas. The
|
|
topics where the answer is "I would need to refresh" are your
|
|
next-level areas, the ones a little more practice will bring up
|
|
to strong. The topics where the answer is "I remember the idea
|
|
but not the specifics" are the ones that would benefit from more
|
|
serious study.
|
|
|
|
Be honest with yourself. There is no external standard you are
|
|
measuring against, and there is no grade. The value of the
|
|
exercise is the map it produces. A map that says "I am strong in
|
|
concurrency and character drivers, moderate in network drivers
|
|
and DMA, weak in VFS and storage" is more useful than a vague
|
|
impression of overall competence.
|
|
|
|
Write the map down. Save it. In six months, when you have done
|
|
some of the practice that the later sections of this chapter will
|
|
recommend, redo the exercise. You will probably find that several
|
|
topics have moved up a category. Seeing that movement, documented
|
|
from your own hand, is one of the most motivating things you can
|
|
do for yourself as a learner.
|
|
|
|
### 2.6 Calibrating Against Real FreeBSD Developers
|
|
|
|
There is a calibration question worth addressing, because readers
|
|
often wonder how their current skill level compares to the people
|
|
working in the FreeBSD community.
|
|
|
|
The answer, honestly, depends on who you compare yourself to. A
|
|
senior committer who has been working in the kernel for twenty
|
|
years will have a depth of understanding that a single book
|
|
cannot give you. A FreeBSD developer who has been writing drivers
|
|
professionally for five years will know idioms and pitfalls that
|
|
are rarely written down. A core-team member will have a broad
|
|
view of the project that only governance work produces. None of
|
|
those people are the right comparison, and measuring yourself
|
|
against them will only discourage you.
|
|
|
|
The useful comparison is to a working junior FreeBSD developer. A
|
|
person who can write drivers for specific hardware, respond to
|
|
reviewer feedback, maintain the drivers over time, and contribute
|
|
productively to the community. Most people at that level have
|
|
some overlap with you in experience. They know things you do not
|
|
know; you also know things they do not know, especially if the
|
|
book covered a topic they never formally studied. You are, at
|
|
this point, close to that junior-developer peer group. A little
|
|
more practice, a first upstream submission, and a few months of
|
|
maintenance will likely close the gap.
|
|
|
|
Another useful comparison is to the version of yourself that
|
|
started the book. This comparison is almost always favourable and
|
|
is therefore useful for motivation rather than for strategic
|
|
planning. Use it when you are tired and need to see your progress.
|
|
Use the junior-developer comparison when you are planning what
|
|
to work on next.
|
|
|
|
### 2.7 The Shape of Competence You Have Built
|
|
|
|
A final observation about where you stand. The competence you
|
|
have built from this book is shaped in a particular way. It is
|
|
deeply oriented toward FreeBSD-specific practice. It is strong on
|
|
the driver-writing side of kernel work and thinner on other areas
|
|
of the kernel that the book did not cover in depth. It is
|
|
grounded in real source-tree work rather than abstract
|
|
systems-programming principles.
|
|
|
|
This shape is the shape the book was designed to produce. It
|
|
means that you are well prepared for the kind of work that FreeBSD
|
|
drivers involve, and less prepared for adjacent areas like
|
|
filesystem internals or deep VM work. That is not a deficiency;
|
|
it is the boundary of the book's scope. The later sections of the
|
|
chapter will point you toward the resources for extending that
|
|
shape in the directions you choose, and the list of advanced
|
|
topics in Section 3 names the most common extensions.
|
|
|
|
The shape also means that your knowledge transfers reasonably
|
|
well to the other BSDs. OpenBSD and NetBSD share many idioms with
|
|
FreeBSD, and a driver developer who knows FreeBSD can read
|
|
OpenBSD or NetBSD drivers with effort but without feeling lost.
|
|
There are differences, and they matter, but the underlying craft
|
|
is recognisably the same. Readers who want to extend their
|
|
competence across the BSD family will find that the investment of
|
|
this book carries them a substantial part of the way.
|
|
|
|
### 2.8 Wrapping Up Section 2
|
|
|
|
You now have a clearer picture of where you stand: what you can
|
|
do, what you know well, where your strongest and weakest areas
|
|
are, and how your competence compares to the community you are
|
|
joining. That picture is practical. It informs the next part of
|
|
the chapter, where we look outward at the advanced topics that
|
|
lie beyond the book's scope.
|
|
|
|
The purpose of the next section is not to teach those advanced
|
|
topics. The book would need to double in length to do that
|
|
properly, and several of them are their own multi-year study
|
|
tracks. The purpose is to name them, explain briefly what each
|
|
one covers, and point you toward the resources where you can
|
|
pursue them seriously. A map, in other words, rather than a
|
|
curriculum.
|
|
|
|
## 3. Exploring Advanced Topics for Continued Learning
|
|
|
|
The FreeBSD kernel is a large system, and no single book can
|
|
cover all of it in depth. This book has concentrated on device
|
|
drivers, which is one of the most approachable entry points into
|
|
kernel work and one of the most useful. There are several
|
|
important areas of the kernel that intersect with driver work but
|
|
deserve their own dedicated study. This section names those
|
|
areas, describes briefly what each one covers, and points you
|
|
toward the sources you can use to pursue them.
|
|
|
|
The spirit of this section is pointing, not teaching. If you find
|
|
yourself wanting deeper treatment of any of these topics, that is
|
|
a sign of interest rather than a gap in this chapter. The
|
|
resources we name below are the next step. The chapter itself is
|
|
not going to turn into a file systems course or a network-stack
|
|
course. Each of those is a years-long study, and compressing them
|
|
into Chapter 38 would do justice to neither.
|
|
|
|
### 3.1 Filesystems and Deeper VFS Work
|
|
|
|
One of the most interesting areas beyond driver work is the
|
|
filesystem layer. The book touched filesystem-adjacent material in
|
|
Chapter 27, where we looked at storage devices and the VFS
|
|
integration that sits above them. That chapter showed you the
|
|
shape of a GEOM provider and the relationship between a storage
|
|
driver and the block layer. It did not teach you how to write a
|
|
filesystem.
|
|
|
|
A filesystem in FreeBSD is a kernel module that implements the
|
|
`vop_vector` set of operations on vnodes. The vnode is the
|
|
kernel's abstraction of an open file, and a filesystem provides
|
|
the backing for a family of vnodes. FreeBSD's native filesystems
|
|
include UFS, ZFS, ext2fs-compat, and several others. Writing a
|
|
new filesystem means implementing at least the core operations:
|
|
`lookup`, `create`, `read`, `write`, `getattr`, `setattr`,
|
|
`open`, `close`, `inactive`, and `reclaim`, along with
|
|
lesser-used operations for directory management, symbolic links,
|
|
and extended attributes.
|
|
|
|
Serious study of this area means reading the UFS source under
|
|
`/usr/src/sys/ufs/` and the `VFS(9)`, `vnode(9)`, and individual
|
|
`VOP_*(9)` manual pages such as `VOP_LOOKUP(9)` and `VOP_READ(9)`.
|
|
Marshall Kirk McKusick's book "The
|
|
Design and Implementation of the FreeBSD Operating System,"
|
|
second edition, contains a chapter on the VFS architecture that
|
|
is the single best starting point for serious study. The ZFS
|
|
code under `/usr/src/sys/contrib/openzfs/` is a second, very
|
|
different model: a copy-on-write filesystem with its own layered
|
|
abstraction and a history of Solaris origins.
|
|
|
|
Filesystems intersect with driver work in two directions. First,
|
|
storage drivers provide the block-layer backing that filesystems
|
|
consume, and a driver developer who understands filesystems will
|
|
write better storage drivers. Second, some drivers implement
|
|
filesystem-like interfaces directly, exposing a tree of virtual
|
|
files for user interaction. The `devfs` filesystem itself is an
|
|
example, and so is `procfs`.
|
|
|
|
If this area interests you, a productive starting project is to
|
|
read the entire source of one of FreeBSD's simpler filesystems,
|
|
such as the `nullfs` or `tmpfs` implementation. Both are small
|
|
enough to study in a week or two, and both illustrate the vnode
|
|
and VFS patterns clearly without the complications of on-disk
|
|
structures.
|
|
|
|
### 3.2 Network Stack Internals
|
|
|
|
A second major area is the FreeBSD network stack. The book
|
|
covered network drivers in Chapter 28, which taught you how to
|
|
write a driver that participates in the `ifnet` layer by
|
|
providing packet transmit and receive functions. That is the
|
|
driver side. The stack itself, which sits above `ifnet` and
|
|
implements the protocols you use every day, is a much larger
|
|
subject.
|
|
|
|
The FreeBSD network stack is among the most sophisticated code
|
|
in the kernel. It implements IPv4, IPv6, TCP, UDP, and a dozen
|
|
other protocols. It includes advanced features like VNET for
|
|
network-stack virtualisation, iflib for multi-queue network
|
|
interface frameworks, and hardware-offload interfaces for
|
|
devices that implement parts of the stack directly in silicon.
|
|
Reading this code is a substantial undertaking, and working in
|
|
it productively is a multi-year project.
|
|
|
|
Key starting points for study are the files under
|
|
`/usr/src/sys/net/`, `/usr/src/sys/netinet/`, and
|
|
`/usr/src/sys/netinet6/`. The core `ifnet` layer lives in
|
|
`/usr/src/sys/net/if.c`, and the interface-framework abstractions
|
|
used by modern drivers live in `/usr/src/sys/net/iflib.c`, whose
|
|
header credits Matthew Macy as the original author. BSDCan and
|
|
EuroBSDcon recordings from recent years are a well-regarded
|
|
starting point for the broader `iflib` and VNET story, and the
|
|
`iflib(9)` manual page pulls the in-tree reference material
|
|
together.
|
|
|
|
Adjacent to the core stack is netgraph, a framework for
|
|
composable network processing that sits apart from the normal IP
|
|
stack. Netgraph lets you build protocol pipelines out of small
|
|
nodes that exchange messages. It is useful for specialised
|
|
protocol work, PPP-style encapsulation, and network-device
|
|
prototyping. The documentation lives in `ng_socket(4)`, the
|
|
manual pages starting with `ng_`, and the source under
|
|
`/usr/src/sys/netgraph/`.
|
|
|
|
If the network stack interests you, a useful starting project
|
|
is to write a simple netgraph node that performs a
|
|
straightforward transformation on packets, such as a statistics
|
|
counter. That project lets you touch the netgraph interfaces,
|
|
the mbuf system, and the VNET mechanics without needing to
|
|
implement a protocol.
|
|
|
|
### 3.3 USB Composite Devices
|
|
|
|
A third area, narrower than the previous two, is USB composite
|
|
devices. The book covered USB drivers in Chapter 26, which
|
|
taught you how to write a driver for a single-function USB
|
|
device. Composite devices are USB devices that present multiple
|
|
interfaces on a single hardware connection, such as a printer
|
|
that also exposes a scanner, or a headset that exposes audio
|
|
output, audio input, and a HID control channel.
|
|
|
|
Writing a composite-device driver is significantly more complex
|
|
than writing a single-function USB driver. The main additional
|
|
complexity is in the interface-selection logic, in the
|
|
coordination between the different functional components of the
|
|
driver, and in the correct handling of USB configuration changes.
|
|
The FreeBSD USB stack under `/usr/src/sys/dev/usb/` supports
|
|
composite devices, and there are several composite drivers in
|
|
the tree that you can study as examples.
|
|
|
|
Serious study of this area means reading the USB specification,
|
|
the FreeBSD USB stack source, and the existing composite-device
|
|
drivers. The `usb(4)` manual page is the starting point, and
|
|
`/usr/src/sys/dev/usb/controller/` and
|
|
`/usr/src/sys/dev/usb/serial/` contain many examples of
|
|
real-world driver structure. The relevant USB specification is the
|
|
USB 2.0 specification from the USB Implementers Forum, which is
|
|
freely available and remarkably readable.
|
|
|
|
A useful starting project if this interests you is to pick up a
|
|
cheap composite USB device (many multi-function printers work)
|
|
and write a FreeBSD driver for its less-supported function. This
|
|
kind of project gives you a clear target, real hardware that you
|
|
can observe with `usbdump(8)`, and a concrete endpoint when the
|
|
driver works.
|
|
|
|
### 3.4 PCI Hotplug and Runtime Power Management
|
|
|
|
A fourth area is PCI hotplug and runtime power management. The
|
|
book covered PCI drivers in Chapter 18 and power management at
|
|
the level of suspend and resume in Chapter 22. Those chapters
|
|
prepared you for devices that appear at boot, remain throughout
|
|
the session, and disappear at shutdown. They did not fully cover
|
|
the case where devices come and go during runtime.
|
|
|
|
PCI hotplug has become important with the rise of PCI Express,
|
|
which supports physical hotplug of cards through connectors like
|
|
U.2, OCuLink, and the internal hotplug slots on server-class
|
|
hardware. A driver that needs to support hotplug must handle
|
|
detach at times other than shutdown, must reason about references
|
|
held by other subsystems, and must be robust against partial
|
|
detach.
|
|
|
|
Runtime power management is the companion topic. Modern PCI
|
|
devices support low-power states that the driver can enter when
|
|
the device is idle and exit when the device is needed again. The
|
|
ACPI subsystem in FreeBSD provides the underlying mechanism. A
|
|
driver that uses runtime power management can save significant
|
|
power, especially on laptops and battery-powered embedded
|
|
devices, but it needs careful reference-counting and state-
|
|
machine logic to work correctly.
|
|
|
|
The relevant FreeBSD sources are under `/usr/src/sys/dev/pci/`
|
|
and `/usr/src/sys/dev/acpica/`. The `pci(4)` manual page and the
|
|
`acpi(4)` manual page are the starting points. The ACPI
|
|
specification itself is a substantial document but is readable,
|
|
and it is worth at least a skim if runtime power management is an
|
|
area you want to work in.
|
|
|
|
A reasonable starting project is to take a driver you wrote
|
|
during the book and add runtime power management to it. Even
|
|
though the driver may not have a real hardware device to
|
|
exercise the low-power states on, the exercise of adding the
|
|
correct state machine, the reference counting, and the wake
|
|
handlers is valuable.
|
|
|
|
### 3.5 SMP and NUMA-Aware Drivers
|
|
|
|
A fifth area is the intersection of driver writing with
|
|
symmetric multiprocessing (SMP) and non-uniform memory access
|
|
(NUMA) tuning. The book has covered the basics of locking and
|
|
concurrency throughout Part 3, and you have been writing SMP-safe
|
|
drivers since then. What the book did not cover in depth is how
|
|
to write drivers that are not just SMP-safe but also SMP-
|
|
scalable, and how to handle NUMA topology explicitly.
|
|
|
|
An SMP-safe driver is one that will not crash or corrupt state
|
|
on a multiprocessor machine. That is a baseline requirement. An
|
|
SMP-scalable driver is one whose throughput grows reasonably as
|
|
you add more CPUs. That is a much harder target. It requires
|
|
careful attention to cache-line sharing, to the granularity of
|
|
locks, to per-CPU data structures, and to the flow of work
|
|
between processors. Most of the high-performance drivers in
|
|
FreeBSD, particularly network drivers for 10 gigabit and faster
|
|
interfaces, use advanced techniques to achieve scalability.
|
|
|
|
NUMA awareness is the next layer. On a NUMA machine, different
|
|
regions of physical memory are closer to different CPUs. A
|
|
driver that pins its DMA buffers and its interrupt handlers to
|
|
the same NUMA node will be faster than one that does not. The
|
|
FreeBSD NUMA subsystem under `/usr/src/sys/vm/` provides the
|
|
mechanisms, and the `numa_setaffinity(2)` system call and the
|
|
`cpuset(2)` interfaces are the starting points.
|
|
|
|
The advanced network drivers under `/usr/src/sys/dev/ixgbe/`,
|
|
`/usr/src/sys/dev/ixl/`, and related directories are good
|
|
examples of SMP-scalable and NUMA-aware driver design. Reading
|
|
them is a graduate course in this area. The `iflib` framework
|
|
under `/usr/src/sys/net/iflib.c` and the adjoining headers
|
|
provides the primary scaffolding for modern network drivers of
|
|
this class.
|
|
|
|
A useful starting project in this area is to take a driver you
|
|
wrote during the book, add per-CPU counters, and benchmark it on
|
|
a multi-CPU system. Even if the driver does not need SMP
|
|
scalability in practice, the exercise of adding per-CPU state
|
|
and measuring the difference is a valuable introduction to the
|
|
thinking.
|
|
|
|
### 3.6 Additional Areas Worth Naming
|
|
|
|
Beyond the five topics above, several other areas of the FreeBSD
|
|
kernel are worth knowing about, even if this chapter cannot
|
|
cover them in detail.
|
|
|
|
**Jails and bhyve integration.** The jail subsystem and the
|
|
bhyve hypervisor each have implications for driver work. A
|
|
driver that can be used inside a jail, or that participates in
|
|
bhyve's I/O virtualisation, has requirements that ordinary
|
|
drivers do not. The relevant sources are under
|
|
`/usr/src/sys/kern/kern_jail.c` and `/usr/src/sys/amd64/vmm/`.
|
|
|
|
**Audit and MAC frameworks.** FreeBSD has a sophisticated audit
|
|
framework, implemented through `auditd(8)`, and a mandatory
|
|
access control (MAC) framework implemented through MAC policy
|
|
modules. Drivers that need to participate in security audit
|
|
trails, or that need to enforce MAC policies, have additional
|
|
interfaces available. The `audit(8)` manual page and the
|
|
`mac(9)` manual page are the entry points.
|
|
|
|
**Cryptographic framework.** The FreeBSD kernel has a built-in
|
|
cryptographic framework under `/usr/src/sys/opencrypto/` that
|
|
drivers can register with to expose hardware cryptographic
|
|
acceleration. If your target hardware includes a crypto engine,
|
|
this is the integration path. The `crypto(9)` manual page
|
|
describes the interface.
|
|
|
|
**GPIO and I2C buses.** Embedded drivers often need to talk to
|
|
GPIO lines and I2C peripherals. FreeBSD has first-class support
|
|
for both, with manual pages `gpio(4)` and `iic(4)` and source
|
|
under `/usr/src/sys/dev/gpio/` and `/usr/src/sys/dev/iicbus/`.
|
|
|
|
**Sound drivers.** The audio subsystem has its own conventions,
|
|
defined in `/usr/src/sys/dev/sound/`. It is a bus-like framework
|
|
with its own concepts of a PCM stream, a mixer, and a virtual
|
|
sound card. Writing a sound driver is an interesting specialty
|
|
and a reasonable next step for someone who enjoyed the character
|
|
driver work of Part 2.
|
|
|
|
**DRM and graphics.** Graphics drivers in FreeBSD have
|
|
traditionally been ports of the Linux DRM framework, living in
|
|
the `drm-kmod` port. Writing or maintaining a graphics driver is
|
|
a very different activity from writing a typical device driver,
|
|
and it is a specialised field. The `drm-kmod` project has its
|
|
own documentation and its own mailing list.
|
|
|
|
Each of these areas is a direction you could go. None of them is
|
|
a required next step. The right next step is the one that
|
|
interests you enough to sustain the work.
|
|
|
|
### 3.7 Exercise: Pick One, Read One Manpage, Write One Paragraph
|
|
|
|
Here is a small exercise that has disproportionate value. Pick
|
|
one of the areas above, exactly one, that sounds interesting to
|
|
you. Read the relevant FreeBSD manual page. This means opening a
|
|
terminal, typing something like `man 9 vfs` or `man 4 usb`, and
|
|
reading what you find. Expect it to take twenty to forty minutes.
|
|
|
|
After you finish reading, close the manual page. On a blank page
|
|
in your notebook or on a fresh text file, write a one-paragraph
|
|
summary of what the interface is for, what the main data
|
|
structures are, and what a driver author would use it for. Do
|
|
not refer back to the manual page while writing. The point is to
|
|
test your own understanding, not to produce a polished
|
|
description.
|
|
|
|
Then open the manual page again and compare. The places where
|
|
your paragraph was vague or wrong are the places where you
|
|
actually did not understand yet. Revise. Write a better paragraph.
|
|
Save it.
|
|
|
|
This exercise is valuable for three reasons. First, it gives you
|
|
hands-on practice with FreeBSD manual pages, which are an
|
|
underused resource and one of the best technical documents in
|
|
the system. Second, it trains the skill of summarising a
|
|
technical interface in your own words, which is the foundation
|
|
of understanding. Third, the paragraph itself is something you
|
|
can keep as a reference. Over time, a collection of such
|
|
paragraphs becomes a personal glossary of the kernel areas you
|
|
have explored.
|
|
|
|
### 3.8 Wrapping Up Section 3
|
|
|
|
This section has given you a map of advanced topics rather than
|
|
a curriculum. The map shows where the book's coverage ends and
|
|
where further study begins. For each topic, we named the topic,
|
|
described briefly what it covers, pointed to the relevant parts
|
|
of the source tree and manual pages, and suggested a starting
|
|
project.
|
|
|
|
The most important thing about this section is the suggestion
|
|
that you not try to study all of these topics at once, and not
|
|
try to study any of them at all unless you actually find
|
|
yourself interested. Depth of understanding comes from sustained
|
|
attention to one topic over time, not from a whirlwind survey of
|
|
many topics. The list above is a menu, not a curriculum.
|
|
|
|
The next section turns from advanced topics to the practical work
|
|
of building yourself a reusable development toolkit. That toolkit
|
|
is the scaffolding that makes whatever specialised area you
|
|
pursue easier to pursue, because it frees you from the friction
|
|
of starting from scratch on every new project. The toolkit and
|
|
the advanced topics together are the practical engine of your
|
|
continued growth.
|
|
|
|
## 4. Building Your Own Development Toolkit
|
|
|
|
Every experienced driver developer has a set of tools and
|
|
templates they reach for reflexively. A starter driver project
|
|
that captures the patterns they always use. A virtual lab that
|
|
boots in seconds and lets them try things without fear of
|
|
breaking anything. A set of scripts that handle the tedious parts
|
|
of testing. A habit of writing regression tests before submitting
|
|
patches. These tools are not provided by the kernel, and they are
|
|
not covered in any specific chapter of the book. They are built
|
|
up over time by each developer, and they pay for themselves many
|
|
times over.
|
|
|
|
This section walks through building that toolkit. The examples
|
|
directory for this chapter contains starter templates, and you
|
|
should treat the templates as a first draft that you then modify
|
|
to suit your own working style. The point is not to use the
|
|
templates verbatim; the point is to have something to start from,
|
|
and then to evolve it over the next several projects into
|
|
something that fits how you actually work.
|
|
|
|
### 4.1 Setting Up a Reusable Driver Template
|
|
|
|
The first tool in your toolkit is a driver project template. When
|
|
you start a new driver, you should not begin with a blank file.
|
|
You should begin by copying a template that already contains the
|
|
copyright header you use, the standard includes, the Newbus
|
|
method table shape, the probe-attach-detach skeleton, the softc
|
|
convention, and the Makefile that builds it all into a loadable
|
|
module.
|
|
|
|
The template should be opinionated. It should reflect your own
|
|
style choices within the constraints of FreeBSD's `style(9)`
|
|
guidelines. If you always use a particular locking pattern, the
|
|
template should include it. If you always define a `*_debug`
|
|
sysctl, the template should include it. If you always keep your
|
|
register definitions in a separate header, the template should
|
|
include an empty one named correctly.
|
|
|
|
The template does not need to be sophisticated. Five files is
|
|
enough for most purposes: a main `.c` file with the driver
|
|
skeleton, a `.h` file for internal declarations, a `reg.h` file
|
|
for register definitions, a `Makefile` for the module build, and
|
|
a manual page stub. The whole thing fits in a few hundred lines.
|
|
You can iterate on it.
|
|
|
|
The companion directory for this chapter contains a working
|
|
template you can start from. Copy it, place it under version
|
|
control, date it, and start making it your own. Every time you
|
|
finish a driver project and notice a pattern you reached for
|
|
repeatedly, consider whether the pattern should go into the
|
|
template. Over the course of several projects, the template
|
|
becomes a compressed record of your accumulated style.
|
|
|
|
There is a subtle trap worth avoiding. The template should be
|
|
kept simple enough that you can type it from memory if you had
|
|
to. If the template becomes so elaborate that you depend on it
|
|
for patterns you could not reproduce manually, you have moved
|
|
from having a useful tool to having a crutch. The tool helps you
|
|
move faster; the crutch hides what you know and do not know. Keep
|
|
the template on the useful side of that line.
|
|
|
|
A second subtle consideration is licensing. Your template should
|
|
contain the copyright header you use for your own code. If you
|
|
typically write drivers under the BSD-2-Clause license, as is
|
|
standard in FreeBSD, the template should have that header. If
|
|
you sometimes write drivers under a different license for
|
|
professional reasons, keep separate templates for each license.
|
|
Getting the license right at the start of a project is easier
|
|
than changing it later, and a template that starts with the
|
|
correct license is one fewer thing to remember on each new
|
|
project.
|
|
|
|
### 4.2 Building a Reusable Virtual Lab
|
|
|
|
The second tool in your toolkit is a virtual lab. This is the
|
|
environment where you load your drivers, test them, crash them,
|
|
and iterate. It should be separate from any machine you care
|
|
about, it should be easy to rebuild, and it should be fast enough
|
|
that you do not dread turning it on.
|
|
|
|
FreeBSD provides two primary virtualisation paths for this
|
|
purpose: bhyve and QEMU. Bhyve is the native FreeBSD hypervisor,
|
|
and it is an excellent choice for a lab when your host is
|
|
FreeBSD. QEMU is a portable emulator that runs on many host
|
|
operating systems, and it is the right choice if your host is
|
|
Linux, macOS, or Windows. Both are capable of running FreeBSD
|
|
guests with good performance, and both have communities and
|
|
documentation around them.
|
|
|
|
A reasonable lab setup has the following properties. It boots in
|
|
under thirty seconds. It exposes a serial console rather than a
|
|
graphical one, because serial consoles are much easier to
|
|
automate and to log. It shares a source directory with the host
|
|
so that you can edit code on the host and build it in the guest
|
|
without transferring files manually. It has a snapshot of a
|
|
known-good state so that you can recover quickly after a panic.
|
|
It is configured to dump its memory on panic so that you can
|
|
attach `kgdb` to the crash dump.
|
|
|
|
Setting up such a lab is a one-time investment of a few hours,
|
|
and the payoff is an environment you will use for every future
|
|
driver project. The companion directory for this chapter
|
|
contains example bhyve and QEMU configurations, along with a
|
|
short script that creates a disk image, installs FreeBSD into
|
|
it, and configures the guest for driver development work.
|
|
|
|
For some drivers, you will want a slightly more elaborate lab.
|
|
If you are writing a GPIO driver, you will want an attached
|
|
simulator that can model GPIO transitions. If you are writing a
|
|
USB driver, you will want the ability to pass a USB device
|
|
through from the host to the guest, which both bhyve and QEMU
|
|
support. If you are writing a network driver, you will want
|
|
virtual network interfaces connecting the guest to the host and
|
|
possibly to other guests. Each of these is a refinement of the
|
|
base lab, and each of them takes an afternoon to set up properly.
|
|
|
|
One useful pattern is to keep your lab configuration in a
|
|
version-controlled repository. Write the bhyve or QEMU command
|
|
line in a script rather than typing it from memory each time.
|
|
Store the disk image and the snapshots somewhere you can find
|
|
them. Document the guest's network configuration in a README.
|
|
The lab is code, and it should be treated that way.
|
|
|
|
### 4.3 Loopback Testing With User-Mode Helpers
|
|
|
|
A particular lab pattern worth highlighting is loopback testing
|
|
with user-mode helpers. Many drivers can be exercised fully by a
|
|
userland program that exercises them. A network driver can be
|
|
tested by a program that opens a socket to the driver's
|
|
interface and sends packets. A character driver can be tested by
|
|
a program that opens the device node and performs a sequence of
|
|
operations. A sysctl-controlled driver can be tested by a script
|
|
that sets sysctl values and checks for expected behaviour.
|
|
|
|
The pattern is to pair every driver with a small testing helper.
|
|
The helper is usually a userland program in C or a shell script
|
|
that invokes `sysctl`, `devstat`, or custom userland tools. The
|
|
helper should cover at least the happy path: the driver loads,
|
|
responds to normal operations, and unloads cleanly. A more
|
|
thorough helper also covers edge cases: error paths, concurrent
|
|
access, resource exhaustion.
|
|
|
|
Writing the helper alongside the driver, rather than afterwards,
|
|
has a subtle benefit. It forces you to think about how the
|
|
driver will be used from userland as you design the driver. If
|
|
the helper is hard to write, that is a signal that the driver's
|
|
userland interface is hard to use, and the time to redesign the
|
|
interface is during development rather than after submission.
|
|
This is one of the small engineering habits that separates
|
|
drivers that are easy to maintain from drivers that are hard to
|
|
maintain.
|
|
|
|
The companion directory contains an example helper that uses the
|
|
standard character-driver operations. It is a template rather
|
|
than a complete test suite, but it illustrates the pattern and
|
|
gives you something to evolve.
|
|
|
|
### 4.4 Creating Regression Tests for Your Driver
|
|
|
|
The third tool in your toolkit is regression testing. A
|
|
regression test is an automated check that a specific driver
|
|
behaviour works correctly. You run the regression tests before
|
|
submitting a patch, you run them after pulling in upstream
|
|
changes, and you run them any time you are uncertain whether
|
|
something you changed broke something else.
|
|
|
|
FreeBSD has a first-class testing framework called `kyua(1)`,
|
|
defined under `/usr/src/tests/`. The framework provides a way to
|
|
declare test programs, group them into test suites, run them,
|
|
and report the results. Driver tests can be written as Kyua
|
|
tests, and the infrastructure handles all the plumbing: isolating
|
|
tests from each other, capturing their output, and producing
|
|
reports.
|
|
|
|
For a driver that exposes a userland interface through a device
|
|
node, a reasonable test suite covers the following kinds of
|
|
cases. It tests that the driver loads without warnings. It tests
|
|
that the device node appears in the expected location. It tests
|
|
that the standard operations produce the expected results. It
|
|
tests that edge cases (zero-length writes, reads at end-of-file,
|
|
concurrent opens) produce the expected errors rather than
|
|
panics. It tests that the driver unloads cleanly.
|
|
|
|
A more thorough test suite also covers stress cases. It might
|
|
run a hundred concurrent writers against a driver that is
|
|
supposed to serialise correctly. It might repeatedly load and
|
|
unload the driver to check for leaks. It might use `ktr(9)`
|
|
tracing or DTrace probes to verify that particular code paths
|
|
are exercised.
|
|
|
|
The companion directory contains a regression-test script
|
|
skeleton that illustrates the pattern. It is not a complete test
|
|
suite, but it is enough to show the structure. Extending it for
|
|
a specific driver is a matter of adding specific test cases, and
|
|
the Kyua documentation under `/usr/share/examples/atf/` shows
|
|
the idiomatic way to structure them.
|
|
|
|
One important habit to develop is to write the regression test
|
|
for a bug before you fix the bug. This is the discipline that
|
|
regression tests exist to support. A test that does not exist
|
|
before the fix is a test that may never exist, because once the
|
|
fix is in, the motivation to write the test is gone. A test
|
|
written first captures the bug in a concrete, reproducible form,
|
|
and then the fix turns the failing test into a passing test. The
|
|
test stays in the suite forever, and if the bug is ever
|
|
reintroduced, the test catches it. This is an old discipline in
|
|
software engineering, and it works as well in FreeBSD kernel
|
|
work as in any other setting.
|
|
|
|
### 4.5 Lightweight Continuous Integration
|
|
|
|
The fourth tool in your toolkit is lightweight continuous
|
|
integration. This does not need to be a complex system. A single
|
|
script that runs on each commit or each push, that builds your
|
|
driver and runs its regression tests, is enough for most
|
|
purposes.
|
|
|
|
The script can be as simple as a shell script that invokes the
|
|
build and the tests in sequence. If a step fails, the script
|
|
exits with a non-zero status, and you know to investigate. Over
|
|
time, the script can grow to include style checks, manual-page
|
|
linting, and cross-architecture builds. Each addition is
|
|
incremental, and each addition catches a class of mistake that
|
|
you would otherwise discover only in review.
|
|
|
|
If you have access to a continuous-integration system, such as
|
|
GitHub Actions, GitLab CI, or a self-hosted runner, you can wire
|
|
the script up to run on every push to your repository. The
|
|
feedback cycle becomes: push a change, wait a few minutes, see
|
|
whether it broke anything. This feedback cycle catches mistakes
|
|
much earlier than manual testing catches them, and it frees your
|
|
own time for thinking rather than rote checking.
|
|
|
|
A warning about CI complexity. It is tempting to build elaborate
|
|
CI pipelines with many stages, caches, artifacts, and
|
|
notification systems. For a solo developer on a small driver
|
|
project, elaborate CI is usually a time sink. Start with a
|
|
script that does the minimum. Add to it only when you notice a
|
|
specific mistake that the current pipeline missed. Let the
|
|
pipeline grow in response to real needs, not imagined ones.
|
|
|
|
The companion directory contains an example CI script that
|
|
builds a driver, runs the style check, lints the manual page,
|
|
and performs a basic load/unload cycle. You can adapt it to your
|
|
repository of choice.
|
|
|
|
### 4.6 Package Your Driver With Documentation and Test Scripts
|
|
|
|
A related habit worth cultivating is to package every driver
|
|
you write with its documentation and its test scripts from the
|
|
very beginning. Each driver in your repository should have the
|
|
following files, at minimum: the source code, a module Makefile,
|
|
a manual page, a README that explains what the driver does and
|
|
how to use it, and a set of test scripts. If the driver is for
|
|
specific hardware, the README should name the hardware. If the
|
|
driver has known limitations, the README should name them.
|
|
|
|
The habit of packaging takes a little extra discipline, but it
|
|
pays off in two ways. First, anyone who encounters your driver,
|
|
including future-you, can understand it and use it without
|
|
having to reconstruct the context. Second, the act of writing
|
|
the README forces you to articulate what the driver does, and
|
|
that articulation often reveals inconsistencies or missing
|
|
features that you would not have noticed otherwise.
|
|
|
|
A small tip about READMEs. Write them in the second person, as
|
|
instructions for a reader. "To load this driver, run
|
|
`kldload mydev`." This style is the standard for FreeBSD
|
|
documentation, and it is easier to read than other styles,
|
|
especially for someone skimming the file to learn how to use the
|
|
driver.
|
|
|
|
### 4.7 Exercise: Package a Driver End-to-End
|
|
|
|
Pick one of the drivers you wrote during the book. It should be
|
|
one that is substantial enough to be worth packaging but small
|
|
enough to finish the exercise in a weekend. The async character
|
|
driver from Chapter 35, or the network driver from Chapter 28,
|
|
or a Newbus driver from Part 6 are all reasonable candidates.
|
|
|
|
Create a new directory for the driver, separate from the book's
|
|
examples directory. Copy the driver source in. Build the
|
|
Makefile from scratch, using your driver template if you have
|
|
one. Write a short manual page. Write a README. Write at least
|
|
three regression tests. Write a load/unload script. Commit
|
|
everything to a git repository.
|
|
|
|
When you are done, the directory should be self-contained. Hand
|
|
it to a colleague and they should be able to build, load, test,
|
|
unload, and understand the driver without needing to ask you
|
|
questions. If they need to ask questions, those are gaps in your
|
|
packaging that you can address.
|
|
|
|
This exercise is valuable beyond the specific driver. It is a
|
|
rehearsal of the packaging habit, and packaging habits scale.
|
|
Once you have packaged one driver well, the second one is
|
|
easier, and the tenth one is automatic. Each time you do it, the
|
|
quality of your packaging improves, and so does your sense of
|
|
what makes a driver easy or hard to use.
|
|
|
|
### 4.8 Wrapping Up Section 4
|
|
|
|
This section has walked through the practical toolkit that
|
|
experienced FreeBSD developers build up over time: a driver
|
|
project template, a virtual lab, loopback testing, regression
|
|
tests, lightweight CI, and packaging habits. None of these is
|
|
strictly necessary for writing a driver, but each of them makes
|
|
the work easier, more reliable, and more durable.
|
|
|
|
The companion directory contains starter artifacts for all of
|
|
them. You can adopt them verbatim or use them as a reference for
|
|
building your own. Either path is valid, and the important thing
|
|
is that you take some version of this toolkit into whatever
|
|
driver work you do next.
|
|
|
|
The next section turns to the community of FreeBSD developers.
|
|
A toolkit makes you productive. A community connects your
|
|
productivity to the rest of the world and, over time, shapes you
|
|
into a better engineer than solo work alone would produce.
|
|
|
|
## 5. Giving Back to the FreeBSD Community
|
|
|
|
The FreeBSD Project is a community. It is not an abstraction; it
|
|
is a set of people who read each other's patches, answer each
|
|
other's questions, show up at conferences, argue about design
|
|
choices, and together produce an operating system that has been
|
|
evolving for over thirty years. This section is about how to
|
|
become part of that community, how to give back to it, and how
|
|
the engagement shapes you as a professional engineer.
|
|
|
|
### 5.1 Why Community Engagement Matters
|
|
|
|
Let us start with the question of why this is worth discussing
|
|
at all. A reader who has finished this book has the technical
|
|
skills to write and maintain drivers in relative isolation. Does
|
|
it really matter whether they engage with the community?
|
|
|
|
It does, and the reasons fall into several categories.
|
|
|
|
Community engagement is how your skills grow past the point a
|
|
book can take them. Books cover patterns that are well
|
|
understood enough to be written down. Community mailing lists,
|
|
code review threads, and conference talks cover patterns that
|
|
are emerging, controversial, or specialised. If you stop reading
|
|
after the book, you stop growing in a specific way that the
|
|
community would continue to develop in you.
|
|
|
|
Community engagement is how your work reaches other people. A
|
|
driver in your personal repository serves you and a few people
|
|
who happen to find your repository. A driver submitted upstream,
|
|
discussed on a mailing list, and maintained in the project
|
|
serves every FreeBSD user who encounters the hardware. The
|
|
amplification is enormous, and you unlock it through engagement.
|
|
|
|
Community engagement is how you find the work that matters. Some
|
|
of the most interesting projects in a large open-source ecosystem
|
|
are not visible from the outside. They are discussed on mailing
|
|
lists, at conferences, in IRC channels, and in informal chats.
|
|
If you are in those conversations, you will hear about them.
|
|
If you are not, you will miss them.
|
|
|
|
Community engagement is how you become someone the project
|
|
trusts. Commit rights, mentorship opportunities, and leadership
|
|
positions are not handed out; they are earned through a long
|
|
history of visible, substantive engagement. The technical skill
|
|
is the prerequisite. The community engagement is the path from
|
|
prerequisite to actual standing.
|
|
|
|
None of these are obligations. You can finish this book, write
|
|
drivers for your own purposes, and never engage with the
|
|
community in any way. That is a legitimate path. But if you are
|
|
curious about what deeper involvement looks like, the rest of
|
|
this section shows you how to start.
|
|
|
|
### 5.2 Participating in Mailing Lists
|
|
|
|
The primary forum for FreeBSD development discussions is mailing
|
|
lists. The project has many of them, each focused on a different
|
|
area or audience. The ones most relevant to a driver developer
|
|
are:
|
|
|
|
- **freebsd-hackers@**: general kernel development discussion.
|
|
Broader than driver-specific topics, and the best starting
|
|
point if you want a general sense of what the project is
|
|
working on.
|
|
- **freebsd-drivers@**: focused on device driver topics. Lower
|
|
volume than `freebsd-hackers` and more directly relevant if
|
|
your interests are in driver work.
|
|
- **freebsd-current@**: discussion about the development branch
|
|
of FreeBSD. Useful if you want to track recent changes and
|
|
the discussions around them.
|
|
- **freebsd-stable@**: discussion about the stable branches.
|
|
Lower volume, more release-focused.
|
|
- **freebsd-arch@**: architectural discussions about major
|
|
changes to the system. Low volume, high signal-to-noise.
|
|
|
|
Subscribing to one or two of these is a reasonable first step.
|
|
Start with `freebsd-hackers` or `freebsd-drivers`, and read for
|
|
a few weeks before posting. The goal of the initial reading is
|
|
to get a sense of the tone, the typical topics, and the people
|
|
who participate regularly. Once you have that sense, you will
|
|
know how to participate in a way that fits the culture.
|
|
|
|
Posting to a mailing list is a skill. A good post has a clear
|
|
subject line, a concise body, and a specific question or
|
|
contribution. A poor post wanders, asks several questions at
|
|
once, or lacks enough context for anyone to help. When you are
|
|
ready to post, take the time to draft the message carefully.
|
|
Most experienced mailing-list users spend more time on their
|
|
posts than newcomers expect, and the investment shows up as
|
|
higher-quality discussion.
|
|
|
|
A subtle skill is replying. Mailing list replies should quote
|
|
just enough of the previous message to provide context, should
|
|
address the specific point being made, and should avoid top-
|
|
posting. These are conventions, not rules, but following them
|
|
signals familiarity with the culture and makes your posts easier
|
|
to follow. The RFC-style quoting convention, where you reply
|
|
below each quoted paragraph, is the preferred style in FreeBSD
|
|
mailing lists.
|
|
|
|
There is an etiquette around asking for help that is worth
|
|
internalising. Before asking a question on a mailing list, you
|
|
should have already read the manual pages, checked the source
|
|
tree, searched the mailing list archives, and tried a few
|
|
obvious solutions. When you do ask, include the information a
|
|
reader would need: what FreeBSD version you are using, what
|
|
hardware, what you tried, what you expected, and what actually
|
|
happened. A well-formed question gets a helpful answer. A
|
|
poorly-formed question often gets no answer, not because the
|
|
community is hostile but because the community cannot help
|
|
without more information.
|
|
|
|
### 5.3 Using Bugzilla
|
|
|
|
FreeBSD tracks bugs in Bugzilla, which lives at
|
|
`https://bugs.freebsd.org/bugzilla/`. It is the project's primary
|
|
tool for recording defects, tracking progress, and coordinating
|
|
fixes. A driver developer will interact with Bugzilla in several
|
|
ways.
|
|
|
|
The first is reporting bugs. If you encounter a bug in a driver
|
|
or in the kernel, you can file a PR (problem report) in
|
|
Bugzilla. A good PR includes the FreeBSD version, the hardware,
|
|
a clear description of the problem, reproduction steps, and any
|
|
relevant output such as `dmesg` excerpts or crash dumps. The
|
|
clearer the report, the more likely someone can fix the bug.
|
|
|
|
The second is triaging existing bugs. Bugzilla has a backlog of
|
|
reports, some of which are not well-categorised or well-
|
|
understood. A new contributor can add value by reading through
|
|
unassigned PRs in the driver-related categories, reproducing the
|
|
bugs on their own systems, and adding clarifying information to
|
|
the reports. This kind of work is not glamorous, but it is
|
|
genuinely valuable, and the contributors who do it learn a great
|
|
deal about the shape of problems that drivers encounter in the
|
|
wild.
|
|
|
|
The third is fixing bugs. When you find a bug you can fix,
|
|
Bugzilla is the tool that coordinates the fix. You attach a
|
|
patch to the PR, mark it for review, and follow the review
|
|
through to commit. The process is not very different from the
|
|
upstream submission workflow you learned in Chapter 37, except
|
|
that it is targeted at a specific existing issue rather than at
|
|
a new feature.
|
|
|
|
One useful habit is to subscribe to the Bugzilla product that
|
|
covers drivers, or to a specific component you care about. The
|
|
subscription gives you email notifications when bugs are filed,
|
|
updated, or resolved. Over time, this subscription becomes a
|
|
lightweight way of staying aware of what is going wrong in the
|
|
area you maintain.
|
|
|
|
### 5.4 Contributing to Documentation
|
|
|
|
Not all contributions are code. FreeBSD's documentation is a
|
|
first-class part of the project, and it needs continuous work to
|
|
stay current. For a new contributor, documentation work is one
|
|
of the most accessible entry points.
|
|
|
|
The FreeBSD Handbook is the primary end-user document. It covers
|
|
installation, administration, development, and specific
|
|
subsystems. Its source lives in a separate Git repository at
|
|
`https://git.freebsd.org/doc.git`, which you can browse online
|
|
at `https://cgit.freebsd.org/doc/`. The documentation is
|
|
written in AsciiDoc and rendered into HTML by Hugo; earlier
|
|
generations of the documentation used DocBook XML, and you will
|
|
still find references to that history in some older material.
|
|
|
|
Contributing to the Handbook is as simple as identifying a
|
|
section that is outdated, incomplete, or confusing, writing an
|
|
improvement, and submitting it. The documentation team welcomes
|
|
such contributions and is usually quick to review them. The
|
|
workflow is similar to code submission: clone the repository,
|
|
make a change, generate a patch or pull request, and submit.
|
|
|
|
Manual pages are a second documentation target. Every driver
|
|
should have a manual page, and every new FreeBSD feature should
|
|
be documented in a manual page. The format is `mdoc`, defined in
|
|
`mdoc(7)`, and the style guide lives in `style.mdoc(5)`. Writing
|
|
good manual pages is a specialised skill, and a contributor who
|
|
develops it is valuable to the project beyond their code
|
|
contributions.
|
|
|
|
A specific area where manual-page work is always welcome is
|
|
fixing outdated examples. Over time, manual pages accumulate
|
|
references to options, files, or behaviours that have changed.
|
|
Walking through a manual page, testing each example, and
|
|
updating the ones that no longer work is useful, repeatable work
|
|
that does not require deep kernel knowledge. It also teaches you
|
|
the interfaces the manual page describes, which is its own
|
|
benefit.
|
|
|
|
### 5.5 Translating Documentation
|
|
|
|
A third form of documentation contribution is translation. The
|
|
FreeBSD Project maintains translations of the Handbook and
|
|
other documents into many languages, coordinated through
|
|
`https://docs.freebsd.org/` and the translation tools under
|
|
`https://translate-dev.freebsd.org/`. If you are fluent in a
|
|
language other than English and are willing to spend time on
|
|
translation, the project has real, unmet needs for this work.
|
|
|
|
Translation is not simple substitution. A good translation
|
|
requires understanding the technical content, understanding the
|
|
conventions of the target language, and understanding the
|
|
idiomatic expression of technical ideas in that language. It is
|
|
serious work, and good translators are appreciated in proportion
|
|
to how rare they are.
|
|
|
|
Working on translations puts you in contact with the FreeBSD
|
|
Documentation Engineering Team, a small group of committers who
|
|
maintain the documentation infrastructure. That contact is
|
|
valuable beyond the immediate work, because it connects you to
|
|
people who can help you understand the rest of the project.
|
|
|
|
### 5.6 Mentoring Other Beginners
|
|
|
|
A fourth form of contribution, and one that does not require
|
|
commit rights or any specific standing in the project, is
|
|
mentoring. Somewhere in the world, there is a reader who is at
|
|
Chapter 5 of this book, struggling with kernel C, and wondering
|
|
whether they should give up. If you can help that reader, you
|
|
are contributing to the project in a way that matters more than
|
|
almost any code patch could.
|
|
|
|
Mentoring happens in many forms. You can answer questions on
|
|
the forums at `https://forums.freebsd.org/`. You can respond to
|
|
questions on IRC in `#freebsd` or `#freebsd-hackers` on Libera
|
|
Chat. You can participate in the Discord or Telegram channels
|
|
that some parts of the community run. You can write blog posts
|
|
that answer questions you struggled with when you were at that
|
|
stage. You can give talks at local BSD user groups. You can
|
|
review someone else's first patch and offer suggestions in the
|
|
tone you would have wanted when you were first reviewed.
|
|
|
|
The specific channels matter less than the habit of being
|
|
available to help. Every person who finishes this book becomes,
|
|
by that fact alone, someone who can help a reader who has not
|
|
yet finished it. That is a real contribution to the
|
|
sustainability of the FreeBSD community. The community grows
|
|
when its senior members teach its junior members, and the
|
|
senior/junior distinction here is measured in chapters
|
|
completed, not in years of experience.
|
|
|
|
A useful pattern for mentoring is to focus on a specific channel
|
|
and be reliably present there. If you answer questions on
|
|
`freebsd-questions@` once a week for a year, you become a known
|
|
face to the people who ask questions. If you respond to every
|
|
driver-related question on the forums that you can answer, you
|
|
become someone that newcomers look for when they have questions.
|
|
Consistency matters more than intensity.
|
|
|
|
Be patient with beginners. Some of the questions will be things
|
|
you remember finding hard, and some will be things you no longer
|
|
remember finding hard because they have become obvious to you.
|
|
Answer the obvious-to-you questions with the same care as the
|
|
hard-for-you questions. That is what good mentoring looks like.
|
|
|
|
### 5.7 Contributing Driver Fixes
|
|
|
|
A fifth form of contribution is driver fixes specifically. The
|
|
FreeBSD tree contains hundreds of drivers, and at any given time
|
|
several of them have known bugs or limitations. A new
|
|
contributor with the skills from this book can fix some of these.
|
|
|
|
Finding driver bugs to fix is not hard. You can look at the open
|
|
PRs in Bugzilla filtered by the `kern` or driver-specific
|
|
products. You can read the mailing lists for reports of bugs
|
|
that have not been fixed. You can use drivers yourself and
|
|
report or fix the bugs you find. Any of these paths leads to
|
|
real work the project needs.
|
|
|
|
Fixing a driver bug has several benefits beyond the fix itself.
|
|
It teaches you how that particular driver works, which is an
|
|
education in itself. It gives you practice with the upstream
|
|
review workflow on real code that real users depend on. It
|
|
builds a small history of contributions that, over time, adds
|
|
up to a visible profile in the project.
|
|
|
|
One specific category of work worth mentioning is driver
|
|
cleanup. Many older drivers in the tree have accumulated
|
|
style issues, deprecated API usage, or missing manual pages over
|
|
the years. Cleaning them up is not glamorous work, but it is
|
|
exactly the kind of work the project needs and often welcomes.
|
|
A contributor who is willing to do careful cleanup work on
|
|
several older drivers develops a reputation for careful work
|
|
very quickly, because careful work is always scarce.
|
|
|
|
### 5.8 Translating Knowledge to Other BSDs
|
|
|
|
A sixth and less-commonly discussed form of contribution is
|
|
carrying knowledge between the BSDs. OpenBSD and NetBSD share
|
|
much of their ancestry with FreeBSD, and patterns that work in
|
|
one often work in the others with adjustments. A driver
|
|
developer who knows FreeBSD well can, with some additional
|
|
study, contribute to OpenBSD or NetBSD as well.
|
|
|
|
The idioms are different in important ways. OpenBSD has its own
|
|
locking conventions, its own interrupt handling patterns, and a
|
|
strong emphasis on security and simplicity. NetBSD shares many
|
|
patterns with FreeBSD but has its own approach to things like
|
|
device-tree integration and autoconfiguration. Each of these is a
|
|
living system with its own community, and each of them has driver
|
|
needs that a FreeBSD-trained developer can address.
|
|
|
|
The value of cross-BSD contribution goes beyond the individual
|
|
commits. It keeps the three projects aware of each other, spreads
|
|
good ideas between them, and prevents each from accumulating
|
|
bugs that the others have already fixed. In an era where the BSD
|
|
community is smaller than it once was, this cross-pollination is
|
|
particularly valuable.
|
|
|
|
If this interests you, the starting point is to pick a driver
|
|
you know well in FreeBSD and to look at whether OpenBSD or
|
|
NetBSD supports the same hardware. If they do not, you have a
|
|
clear porting target. If they do, you can still contribute by
|
|
reading their version of the driver, comparing, and noting any
|
|
improvements or fixes that could be shared. Either way, the
|
|
engagement deepens your understanding of all three systems.
|
|
|
|
### 5.9 Exercise: Write a Thank-You Message
|
|
|
|
This subsection's exercise is small and unusual. Send a thank-you
|
|
message to someone whose code or documentation helped you during
|
|
this book.
|
|
|
|
It could be the maintainer of a specific driver whose source you
|
|
read closely. It could be the author of a manual page that
|
|
clarified something for you. It could be a committer whose talk
|
|
at a conference you watched on YouTube. It could be the person
|
|
who wrote the book's foreword if one exists, or the person who
|
|
reviewed it. Whoever helped you, in whatever way, say thank you.
|
|
|
|
The message does not need to be long. A few sentences will do.
|
|
Name the specific piece of work that helped you. Explain briefly
|
|
how it helped. Say thank you. Send the message by email or post
|
|
it to the appropriate mailing list.
|
|
|
|
This exercise is valuable for two reasons. First, open-source
|
|
work is often thankless, and maintainers who receive thank-you
|
|
messages are more likely to keep contributing. You are, through
|
|
the act of thanking, investing in the ecosystem's sustainability.
|
|
Second, the act of writing the message will make you think
|
|
specifically about how someone else's work helped you. That
|
|
thinking, in turn, will make you more aware of how your own work
|
|
might help someone else, and that awareness is the foundation of
|
|
becoming a contributor yourself.
|
|
|
|
### 5.10 The Relationship Between Contribution and Growth
|
|
|
|
There is a deeper point about community engagement that is worth
|
|
naming explicitly. Contributing to the FreeBSD Project, in any of
|
|
the forms above, is not just a way of giving back. It is a way
|
|
of growing.
|
|
|
|
When you answer a beginner's question on a mailing list, you
|
|
learn what was unclear about the topic. When you review someone
|
|
else's patch, you learn patterns you would not have encountered
|
|
in your own code. When you fix a bug in an area you did not
|
|
write, you learn that area's conventions and history. When you
|
|
write a manual page, you learn the discipline of precise
|
|
technical explanation. Each act of contribution is also an act
|
|
of education, and over time the education accumulates into a
|
|
depth of understanding that solo work cannot produce.
|
|
|
|
The most senior FreeBSD developers are often the most prolific
|
|
contributors precisely because contribution is how they
|
|
continued to grow. They did not arrive at their current depth
|
|
and then start contributing. They started contributing, which
|
|
led to their current depth. If you want to continue growing in
|
|
the way they did, the path is visible and well-trodden.
|
|
|
|
This is not a moral argument. It is a practical observation
|
|
about how expertise develops in open-source ecosystems. The
|
|
people who engage deeply grow deeply. The people who stay on the
|
|
periphery stay at whatever level the materials they consume
|
|
took them to. Both paths are valid; if you want the former, the
|
|
chapter has now shown you how to start.
|
|
|
|
### 5.11 Wrapping Up Section 5
|
|
|
|
This section has walked through the many forms of community
|
|
contribution available to a reader of this book: mailing-list
|
|
participation, Bugzilla engagement, documentation work,
|
|
translation, mentoring, driver fixes, and cross-BSD
|
|
contribution. Each of these is a legitimate way to be part of
|
|
the FreeBSD community, and all of them are valuable beyond the
|
|
specific work they involve.
|
|
|
|
The key takeaway is that contribution is broader than committing
|
|
driver code. A reader who thinks of contribution only as "write
|
|
a driver and send it upstream" is missing most of the
|
|
contribution surface. Some of the most important work in the
|
|
project is done by people who rarely commit code but who
|
|
contribute in other ways.
|
|
|
|
The next and final major section of the chapter turns from the
|
|
community to the living system itself. The FreeBSD kernel is
|
|
under active development, and staying connected to that
|
|
development is its own skill. How do you follow changes? How do
|
|
you notice when something you rely on is about to change? How do
|
|
you stay current without drowning in the volume of daily
|
|
activity?
|
|
|
|
## 6. Staying Up to Date With FreeBSD Kernel Development
|
|
|
|
The FreeBSD kernel is a moving target. The version you learned
|
|
against was 14.3, and by the time you read this at a later date,
|
|
there will already be a 14.4, or a 15.0, or both. Each release
|
|
brings new subsystems, deprecates old ones, changes internal
|
|
APIs, and shifts conventions in small ways. A driver developer
|
|
who writes a driver once and walks away will find, returning a
|
|
few years later, that the driver may not build against the
|
|
current tree. A driver developer who stays engaged with the
|
|
kernel's development watches those changes happen in real time
|
|
and adjusts along the way.
|
|
|
|
This section is about how to stay engaged. Like the community
|
|
section before it, the advice here is optional. You can finish
|
|
this book, write drivers against FreeBSD 14.3, and never update
|
|
your knowledge; your drivers will work for a while and then
|
|
gradually stop working, and that is a legitimate relationship to
|
|
have with the kernel. But if you want your drivers to keep
|
|
working, or if you want to grow beyond the snapshot of knowledge
|
|
that this book gave you, the habits in this section are what
|
|
make that possible.
|
|
|
|
### 6.1 Where to Follow FreeBSD Development
|
|
|
|
There are several primary sources for following FreeBSD
|
|
development, and a well-calibrated developer watches a few of
|
|
them regularly without trying to watch them all.
|
|
|
|
**The FreeBSD Git repository.** The source tree itself lives at
|
|
`https://git.freebsd.org/src.git`. Every commit to the tree is
|
|
visible there, along with its commit message, its author, and
|
|
its review history. You can clone the repository and run
|
|
`git log` to see the recent activity. You can use `git log
|
|
--since=1.week` to filter to recent changes. You can use
|
|
`git log --grep=driver` to look at driver-related commits.
|
|
|
|
For most developers, the Git repository is the primary source of
|
|
truth. The commit logs are where the project's day-to-day
|
|
engineering happens, and reading them regularly is one of the
|
|
most direct ways to stay aware of what is changing and why.
|
|
|
|
**Commit notification mailing lists.** The project publishes
|
|
commit messages to mailing lists such as `svn-src-all@`
|
|
(historically, when the project used Subversion) and their
|
|
Git-era equivalents. Subscribing to these gives you a
|
|
high-volume stream of every commit to the tree. This is too
|
|
much information for most purposes, but it is useful for a
|
|
narrow audience: developers who want to watch every change.
|
|
|
|
A lower-volume alternative is to watch only the head branch's
|
|
commit messages for a specific subsystem. You can do this with
|
|
Git's `--author` or `--grep` flags, or by setting up a custom
|
|
filter on your mail client.
|
|
|
|
**freebsd-current@ and freebsd-stable@.** These mailing lists
|
|
are where discussions about the development and stable branches
|
|
take place. Subscribing to them gives you early awareness of
|
|
proposed changes, migration questions, and breakage. They are
|
|
moderate volume and often high signal.
|
|
|
|
**The Release Notes.** Every FreeBSD release has release notes
|
|
that describe significant changes since the previous release.
|
|
The notes are published on the project's website at
|
|
`https://www.freebsd.org/releases/`. Reading the release notes
|
|
for each new release is an efficient way to catch up on changes
|
|
you may have missed in the day-to-day volume.
|
|
|
|
**UPDATING.** The `/usr/src/UPDATING` file in the source tree
|
|
contains important notices about changes that may affect users
|
|
or developers. If a subsystem is being deprecated, or if an API
|
|
is changing incompatibly, UPDATING is where the notice lives.
|
|
Developers should check UPDATING after any significant tree
|
|
update, and specifically before updating from one major release
|
|
to another.
|
|
|
|
### 6.2 Developer Summits and BSD Conferences
|
|
|
|
FreeBSD has a rich conference culture, and attending or
|
|
watching recordings of these conferences is one of the most
|
|
efficient ways to stay connected to the project.
|
|
|
|
**BSDCan.** An annual conference held in Ottawa, Canada, usually
|
|
in June. It draws developers from FreeBSD, OpenBSD, NetBSD, and
|
|
DragonFly BSD. The presentations cover a mix of development
|
|
updates, architectural discussions, and deep technical talks.
|
|
Many of the talks are recorded and published on the conference
|
|
website.
|
|
|
|
**EuroBSDcon.** An annual European BSD conference, held at a
|
|
rotating location each September or October. The focus is
|
|
similar to BSDCan, with a more European-centric participant
|
|
list.
|
|
|
|
**Asia BSDCon.** An Asia-Pacific BSD conference, held annually
|
|
in Tokyo. Smaller than BSDCan or EuroBSDcon but with a distinct
|
|
set of participants and topics.
|
|
|
|
**The FreeBSD Developer Summit.** Held twice a year, once
|
|
co-located with BSDCan and once with EuroBSDcon. The summit is
|
|
where the project's committers meet face-to-face to discuss
|
|
architectural direction, plan releases, and coordinate on major
|
|
changes. Summaries of the summit sessions are published on the
|
|
wiki, and the summit is one of the places where the project's
|
|
internal planning becomes visible to the broader community.
|
|
|
|
**Regional BSD user groups.** Local BSD user groups exist in
|
|
many cities and often host talks, meetups, and workshops. These
|
|
are much lower-key than the international conferences but are
|
|
often the most accessible entry point for someone who is new to
|
|
the community.
|
|
|
|
For readers who cannot attend in person, many conference talks
|
|
are recorded and posted online. The BSD Channel on YouTube, the
|
|
BSDNow podcast, and the AsiaBSDCon recordings are all valuable
|
|
resources. A habit of watching one conference talk per month is
|
|
a low-effort way to stay connected to the project's current
|
|
thinking.
|
|
|
|
### 6.3 Tracking API and Driver Model Changes Across Releases
|
|
|
|
Beyond following commits and attending conferences, there is a
|
|
specific skill worth naming: tracking how the APIs and driver
|
|
model change from release to release. This is the skill that
|
|
keeps drivers buildable over time, and it is one of the least
|
|
discussed aspects of long-term kernel work.
|
|
|
|
The basic pattern is this. When a new FreeBSD release comes out,
|
|
you ask: what changed in the subsystem my driver touches? You
|
|
answer the question by diffing the relevant parts of the source
|
|
tree between the previous release and the new one. You read the
|
|
release notes for anything flagged. You check UPDATING. You
|
|
rebuild the driver against the new release and see what
|
|
warnings or errors appear.
|
|
|
|
The tools that help with this are the standard Unix tools. `git
|
|
log` with a path argument shows the history of a specific file
|
|
or directory. `git diff` between two tags shows the difference.
|
|
`grep` with the right patterns finds usage of a specific API.
|
|
Each of these is elementary, but putting them together into a
|
|
checking habit is a skill that repays itself many times over.
|
|
|
|
A specific example. Suppose your driver uses `bus_alloc_resource_any`
|
|
and you want to know whether its semantics have changed between
|
|
FreeBSD 14.0 and 14.3. You can run:
|
|
|
|
```console
|
|
$ git log --oneline releng/14.0..releng/14.3 -- sys/kern/subr_bus.c
|
|
```
|
|
|
|
in a clone of the FreeBSD source tree. The output is the list of
|
|
commits that modified `subr_bus.c` between those two releases.
|
|
You can read each commit message to see whether the changes
|
|
affect your usage. If something looks relevant, you can
|
|
investigate with `git show` to see the actual change.
|
|
|
|
This pattern is fundamental to long-term driver maintenance. It
|
|
is not glamorous, but it is reliable, and it catches problems
|
|
before they become silent breakage.
|
|
|
|
### 6.4 Tools for Comparing Kernel Trees
|
|
|
|
Beyond `git log` and `git diff`, a few other tools help with the
|
|
work of following kernel changes.
|
|
|
|
**diff -ruN.** The classic recursive diff between two
|
|
directories. Useful when you have checked out two versions of
|
|
the tree and want to compare them systematically. The output is
|
|
large but readable, and it catches changes that `git log` alone
|
|
might miss.
|
|
|
|
**git grep.** The Git-aware grep. Faster than external grep on
|
|
large repositories because it knows about Git's index. Useful
|
|
for finding all usages of a specific function or macro.
|
|
|
|
**diffoscope.** A more elaborate diffing tool that handles many
|
|
file formats intelligently. Useful when you want to compare
|
|
compiled objects, images, or other non-text artifacts.
|
|
|
|
**The FreeBSD source-code search at `https://cgit.freebsd.org/`.**
|
|
A web-based interface to the Git repository that lets you browse
|
|
the tree, view commits, and search for identifiers. Often faster
|
|
for casual browsing than a local clone.
|
|
|
|
**Bugzilla's search interface.** Useful for finding whether a
|
|
specific issue has been reported, and often for finding the
|
|
commit that fixed it.
|
|
|
|
Becoming fluent with these tools is a matter of a few hours of
|
|
practice. Once they are in your fingers, you can answer
|
|
questions about the tree's history that would otherwise take
|
|
days of manual reading.
|
|
|
|
### 6.5 A Monthly Rhythm for Staying Current
|
|
|
|
Readers often ask how to make "staying current" a sustainable
|
|
habit rather than a vague good intention. Here is a monthly
|
|
rhythm that works for many developers.
|
|
|
|
**Weekly.** Read the freebsd-hackers or freebsd-drivers mailing
|
|
list digest (or equivalent summary) once a week. Read one or
|
|
two threads that catch your interest. Reply to one if you have
|
|
something to contribute. This is an hour of work per week.
|
|
|
|
**Monthly.** Pull the latest FreeBSD source tree. Run your
|
|
personal driver's test suite against it. Investigate any
|
|
failures. Read the most recent conference talk you have not yet
|
|
watched. This is an afternoon per month.
|
|
|
|
**Quarterly.** Skim the commit log of the subsystem your driver
|
|
touches since the last time you looked. Check whether any of
|
|
the changes affect your driver. Read the most recent committer
|
|
summary or project update. Review your personal learning goals
|
|
and adjust them if the landscape has shifted. This is a day per
|
|
quarter.
|
|
|
|
**Annually.** Read the release notes for the latest FreeBSD
|
|
release, top to bottom. Consider whether you should upgrade your
|
|
development environment. Attend or watch at least one conference
|
|
worth of talks. Review your driver portfolio and consider
|
|
whether any of the older drivers need maintenance work.
|
|
|
|
This rhythm is not a rigid schedule. It is an illustration of
|
|
how regular, low-intensity attention can keep you current without
|
|
becoming a second job. Most developers who stay engaged long-term
|
|
follow something like this pattern, sometimes denser and
|
|
sometimes looser.
|
|
|
|
### 6.6 Exercise: Subscribe and Read
|
|
|
|
This subsection's exercise is a small commitment. Subscribe to
|
|
freebsd-hackers@ or freebsd-drivers@, whichever seems more
|
|
appropriate for your interests. Commit to reading one thread per
|
|
week for four weeks. At the end of the four weeks, decide
|
|
whether the subscription is worth keeping.
|
|
|
|
The point of the exercise is not to learn a specific technical
|
|
thing. It is to build the habit of being aware of what the
|
|
project is discussing. If after four weeks you find the traffic
|
|
unhelpful, unsubscribe. If you find it useful, keep reading. The
|
|
experiment is small and reversible.
|
|
|
|
A few practical tips. Filter the mailing-list messages into a
|
|
separate folder in your mail client, so they do not pollute your
|
|
regular inbox. Read in batches rather than as individual
|
|
messages arrive. Be willing to ignore threads that are not about
|
|
topics you care about. The goal is sustainable attention, not
|
|
exhaustive coverage.
|
|
|
|
### 6.7 Watching for Deprecation Notices
|
|
|
|
A particular skill worth cultivating is watching for deprecation
|
|
notices. Deprecation is how the project signals that a specific
|
|
API, subsystem, or behaviour is going to change or be removed in
|
|
a future release. Developers who miss deprecation notices find
|
|
out about the removal later, when their code no longer builds,
|
|
and the fix is often more painful at that point than it would
|
|
have been during the deprecation period.
|
|
|
|
Deprecation notices appear in several places. UPDATING is the
|
|
primary one. Release notes mention them. Commit messages for
|
|
deprecation changes often contain the word "deprecat" (with the
|
|
ambiguous spelling to catch both "deprecate" and "deprecated").
|
|
Mailing list discussions often precede deprecation changes and
|
|
give early warning.
|
|
|
|
A practical habit is to grep the recent commit log for
|
|
deprecation keywords once a month:
|
|
|
|
```console
|
|
$ git log --oneline --since=1.month --grep=deprecat
|
|
```
|
|
|
|
The output is usually short and scannable, and it catches most
|
|
deprecations before they become problems.
|
|
|
|
### 6.8 Engaging When You See a Change That Affects You
|
|
|
|
When you spot a change that affects code you maintain, you have
|
|
several options. You can adapt your code immediately, rebuilding
|
|
and testing against the new behaviour. You can comment on the
|
|
commit or the associated review, asking about the migration
|
|
path. You can engage with the author on the relevant mailing
|
|
list. You can file a PR in Bugzilla if you encounter a problem
|
|
you think needs tracking.
|
|
|
|
The engagement itself is valuable beyond the specific change.
|
|
Each time you reach out about a change, you are both contributing
|
|
to the project's awareness of downstream effects and building a
|
|
relationship with the author. Over time, those relationships are
|
|
one of the most valuable aspects of being part of the community.
|
|
|
|
One specific pattern worth highlighting. If a change is about to
|
|
break your driver, and you find the change while it is still
|
|
under review, commenting on the review is dramatically more
|
|
valuable than commenting after the change is committed. Reviewers
|
|
actively want to know about downstream effects, and a
|
|
well-formed comment at review time often leads to adjustments
|
|
that make the change less disruptive. Waiting until after commit
|
|
means the change lands, downstream users discover the breakage,
|
|
and the fix becomes a second patch that somebody else has to
|
|
coordinate.
|
|
|
|
### 6.9 A Curated Reading List for Continued Study
|
|
|
|
The single most common request from readers who finish a book
|
|
like this one is "what should I read next?" The honest answer
|
|
is that the best reading depends on where you want to go. A
|
|
reader headed toward filesystem work will have a very different
|
|
list from one headed toward network drivers or toward embedded
|
|
development. What follows is a curated starting list, organised
|
|
by area, with one or two recommendations in each direction. The
|
|
list is deliberately short. A long list would overwhelm. A
|
|
short list lets you finish what you start.
|
|
|
|
For general FreeBSD kernel background, the most useful
|
|
single source is still the FreeBSD source tree itself. Read
|
|
`/usr/src/sys/kern/kern_synch.c` for an example of careful
|
|
kernel engineering, read `/usr/src/sys/kern/vfs_subr.c` for
|
|
a sense of how a large subsystem organises its internal
|
|
interfaces, and read `/usr/src/sys/dev/null/null.c` once more
|
|
at the end of the book to see how much richer the file reads
|
|
now than it did in Chapter 1. The manual pages in section 9
|
|
remain the most authoritative reference for kernel interfaces;
|
|
skim the list of section-9 pages with `apropos -s 9 .` and
|
|
read anything that catches your eye.
|
|
|
|
For filesystem work, the classic reference is Kirk McKusick's
|
|
"The Design and Implementation of the FreeBSD Operating
|
|
System." Pay attention to the VFS chapters. Then read
|
|
`/usr/src/sys/ufs/ffs/` carefully, choosing one file at a time
|
|
and tracing how its functions are called from the layers above
|
|
and below. If you prefer talks to books, the BSDCan archive
|
|
contains several filesystem-focused talks from Kirk McKusick,
|
|
Chuck Silvers, and others; watch them in chronological order to
|
|
see how the system evolved.
|
|
|
|
For networking, start with the `netmap(4)` manual page and the
|
|
sources under `/usr/src/sys/dev/netmap/`, then widen out to the
|
|
stack proper under `/usr/src/sys/net/` and
|
|
`/usr/src/sys/netinet/`. Read `if.c`
|
|
first, then `if_ethersubr.c`, then pick a specific protocol
|
|
family and follow its packets through. The `iflib(9)` manual
|
|
page is essential for modern Ethernet drivers. For deeper
|
|
coverage, the TCP/IP Illustrated series by Stevens remains the
|
|
canonical reference; chapters 2 and 3 translate almost directly
|
|
to FreeBSD's implementation.
|
|
|
|
For embedded and ARM work, read through the Device Tree
|
|
sources under `/usr/src/sys/contrib/device-tree/src/` for
|
|
your board, then study `/usr/src/sys/dev/fdt/` to see how
|
|
FreeBSD consumes those trees. Warner Losh's conference talks on
|
|
arm64 and RISC-V support are excellent complements. The
|
|
`fdt(4)` manual page is short but dense; reread it after a
|
|
month's practice.
|
|
|
|
For debugging and profiling, read the kgdb(1), ddb(4),
|
|
dtrace(1), and hwpmc(4) manual pages in sequence. Then pick a
|
|
DTrace provider (io, vfs, sched) and write one meaningful
|
|
script using it. Brendan Gregg's DTrace book remains relevant;
|
|
most of its examples still apply to FreeBSD directly.
|
|
|
|
For security and hardening, read the `capsicum(4)`,
|
|
`mac(4)`, and `jail(8)` manual pages carefully. The Capsicum
|
|
papers from Watson and others are worth reading in full.
|
|
`/usr/src/sys/kern/sys_capability.c` and
|
|
`/usr/src/sys/kern/subr_capability.c` are the implementation
|
|
worth tracing. The FreeBSD security advisory archive on the
|
|
project website is a useful record of how real bugs have
|
|
played out.
|
|
|
|
For USB work, start with the USB controller drivers in
|
|
`/usr/src/sys/dev/usb/controller/` and the core files under
|
|
`/usr/src/sys/dev/usb/` such as `usb_process.c` and
|
|
`usb_request.c`. The USB specification is large but accessible;
|
|
read only the chapters you need when you need them, and use the
|
|
existing FreeBSD drivers as worked examples.
|
|
|
|
For virtualisation and bhyve, the bhyve manual page is the
|
|
starting point, followed by the bhyve source under
|
|
`/usr/src/usr.sbin/bhyve/`. John Baldwin's BSDCan talks provide
|
|
excellent context. If you plan to use bhyve as a test harness
|
|
for driver development, focus on the PCI passthrough and
|
|
virtio sections.
|
|
|
|
For general craft, three books are worth owning: Kernighan
|
|
and Ritchie's "The C Programming Language" for the
|
|
language itself, Kernighan and Pike's "The Practice of
|
|
Programming" for the habits, and McKusick and Neville-Neil's
|
|
"The Design and Implementation of the FreeBSD Operating
|
|
System" for the system. If you already know C well, the first
|
|
book can be skimmed. If you have ever felt that your code
|
|
"works but could be better," the second book will address
|
|
that feeling directly.
|
|
|
|
For community culture and history, read the FreeBSD Handbook's
|
|
introduction and then the archives of the FreeBSD project on
|
|
the Internet Archive. The project has existed for decades and
|
|
its culture is documented in its correspondence as much as in
|
|
its code. Understanding how the project thinks about itself
|
|
will help you contribute in a way the community welcomes.
|
|
|
|
One final recommendation: take the list above and mark, with
|
|
a pencil, the one item in each area that you are most likely
|
|
to actually complete in the next three months. Then close this
|
|
book and start on those items, not all of them, just the
|
|
marked ones. A small finished list beats a long unfinished
|
|
list every time.
|
|
|
|
### 6.10 Wrapping Up Section 6
|
|
|
|
This section has walked through how to stay connected to the
|
|
FreeBSD kernel's ongoing development: where to watch for changes,
|
|
which conferences to follow, how to track API drift, and what
|
|
habits turn "staying current" from a vague aspiration into a
|
|
sustainable practice.
|
|
|
|
The overarching idea is that staying current is not a task you
|
|
do once. It is a rhythm you develop. The rhythm does not need to
|
|
be intense; it needs to be regular. A weekly mailing-list
|
|
glance, a monthly build test, a quarterly review of your code,
|
|
and an annual walk through the release notes are together enough
|
|
to keep most driver maintainers in sync with the project.
|
|
|
|
We have now covered the six main sections of the chapter:
|
|
celebrating what you have accomplished, understanding where you
|
|
stand, exploring advanced topics, building your toolkit, giving
|
|
back to the community, and staying current. The remaining
|
|
material of the chapter is hands-on: labs to apply what you have
|
|
read, challenges to push your practice further, and planning
|
|
artifacts you can keep as a record of the reflection you did
|
|
here.
|
|
|
|
## 7. Hands-On Reflection Labs
|
|
|
|
The labs in this chapter are reflection labs rather than coding
|
|
labs. They ask you to apply what the chapter has discussed to
|
|
your own circumstances, using the companion files as templates
|
|
where helpful. Each lab produces a concrete artifact you can
|
|
keep, and the artifacts together form a record of where you were
|
|
at the moment you finished this book.
|
|
|
|
Treat the labs as time well spent. A reader who does the labs
|
|
will leave the book with a set of personal documents that shape
|
|
the next few months of their work. A reader who skips the labs
|
|
will have read the chapter but not applied it, and the
|
|
difference shows up three months later when the one reader has a
|
|
plan and the other is drifting.
|
|
|
|
### 7.1 Lab 1: Complete a Self-Assessment Worksheet
|
|
|
|
**Goal.** Produce a written self-assessment that captures where
|
|
you stand at the end of the book.
|
|
|
|
**Time.** Two to three hours, spread across one or two sittings.
|
|
|
|
**Materials.** The `self-assessment.md` template in
|
|
`examples/part-07/ch38-final-thoughts/`. A notebook or text
|
|
editor. Access to the book's chapters as a reference.
|
|
|
|
**Steps.**
|
|
|
|
1. Copy the self-assessment template into a directory you
|
|
control, such as a personal Git repository or a folder in
|
|
your home directory.
|
|
|
|
2. Date the file. Use ISO 8601 format (`YYYY-MM-DD`) in the
|
|
filename or in the header, so you can sort multiple
|
|
assessments chronologically when you redo the exercise later.
|
|
|
|
3. For each topic in the template, give yourself a confidence
|
|
rating on a one-to-five scale. The topics are drawn from the
|
|
book's coverage: C for kernels, debugging and profiling,
|
|
device tree integration, reverse engineering, userland
|
|
interfaces, concurrency and synchronisation, DMA and
|
|
interrupts, upstream submission, and the specific core APIs
|
|
like `bus_space(9)`, `sysctl(9)`, `dtrace(1)`, `devfs(5)`,
|
|
`poll(2)`, and `kqueue(2)`.
|
|
|
|
4. For each topic, write one sentence explaining why you chose
|
|
that rating. A rating without a reason is just a number. A
|
|
rating with a reason is a diagnosis.
|
|
|
|
5. At the end, identify the three topics where you most want to
|
|
invest more practice. Explain why for each.
|
|
|
|
6. Save the file. Back it up. Put a calendar reminder for six
|
|
months from now to redo the assessment and compare.
|
|
|
|
**Deliverable.** The completed self-assessment worksheet, saved
|
|
with the current date.
|
|
|
|
**What to notice.** The act of forcing a specific confidence
|
|
rating on each topic will reveal surprising distinctions. You
|
|
may find that you rate yourself higher than you expected on some
|
|
topics and lower on others. The surprises are where the
|
|
diagnostic value lives.
|
|
|
|
### 7.2 Lab 2: Draft a Personal Learning Roadmap
|
|
|
|
**Goal.** Produce a written plan for the next three to six
|
|
months of your FreeBSD learning.
|
|
|
|
**Time.** Two hours, in one focused sitting.
|
|
|
|
**Materials.** The `learning-roadmap.md` template in
|
|
`examples/part-07/ch38-final-thoughts/`. The output of Lab 1.
|
|
The advanced-topics section of this chapter.
|
|
|
|
**Steps.**
|
|
|
|
1. Copy the learning-roadmap template into your working directory.
|
|
|
|
2. Based on your self-assessment from Lab 1, choose the one
|
|
technical area you most want to deepen over the next three
|
|
months. The choice should be specific: not "the network
|
|
stack," but "the `ifnet` layer and its interaction with
|
|
`iflib`."
|
|
|
|
3. Break the three-month goal into monthly milestones. Each
|
|
milestone should be concrete enough to be recognisable when
|
|
it is done. Examples: "By end of month one, I have read
|
|
`/usr/src/sys/net/if.c` in full and can explain the
|
|
lifecycle of an `ifnet`." "By end of month two, I have
|
|
written a minimal pseudo-interface that implements the
|
|
`ifnet` API." "By end of month three, I have submitted the
|
|
pseudo-interface for review."
|
|
|
|
4. Identify the resources you will use. Manual pages. Specific
|
|
source files. Specific conference talks. Specific people
|
|
whose code you will read. Be concrete enough that you can
|
|
start immediately, without additional research.
|
|
|
|
5. Identify the practice cadence. Will you work on this every
|
|
day for an hour? Every weekend for a few hours? Twice a
|
|
week? The cadence matters more than the intensity, and a
|
|
sustainable cadence is better than an ambitious one.
|
|
|
|
6. Add secondary goals. A toolkit improvement. A community
|
|
engagement goal (join a mailing list, answer N questions on
|
|
the forums). A currency goal (watch M conference talks,
|
|
follow commit logs for a specific subsystem).
|
|
|
|
7. Commit the roadmap to a Git repository or save it somewhere
|
|
stable. Put a calendar reminder at the end of each month to
|
|
review progress and adjust.
|
|
|
|
**Deliverable.** The completed learning roadmap, saved with the
|
|
current date.
|
|
|
|
**What to notice.** A good roadmap feels slightly
|
|
uncomfortable. If it feels easy and safe, it is probably not
|
|
ambitious enough. If it feels impossible, it is probably not
|
|
sustainable. The sweet spot is a roadmap that is visibly more
|
|
than you can do in a weekend but visibly within reach over
|
|
three months of consistent practice.
|
|
|
|
### 7.3 Lab 3: Set Up Your Driver Template
|
|
|
|
**Goal.** Produce a personal driver template that reflects your
|
|
style choices.
|
|
|
|
**Time.** Two to four hours, in one or two sittings.
|
|
|
|
**Materials.** The `template-driver/` directory in
|
|
`examples/part-07/ch38-final-thoughts/`. The book's chapters on
|
|
Newbus, `bsd.kmod.mk`, and driver anatomy as reference. Your
|
|
text editor.
|
|
|
|
**Steps.**
|
|
|
|
1. Copy the template-driver directory into a personal Git
|
|
repository. Rename the files to something generic, such as
|
|
`skeleton.c`, `skeleton.h`, `skeletonreg.h`, and adjust the
|
|
Makefile accordingly.
|
|
|
|
2. Adjust the copyright header to match your name, email, and
|
|
preferred license.
|
|
|
|
3. Adjust the include ordering to match your preferences, while
|
|
still conforming to `style(9)`.
|
|
|
|
4. Add any standard patterns you reach for reflexively: a debug
|
|
sysctl, a locking macro, a module event handler skeleton, a
|
|
probe-attach-detach pattern you always use.
|
|
|
|
5. Remove any patterns you do not use. The goal is a minimal
|
|
template, not a comprehensive one.
|
|
|
|
6. Write a short README explaining what the template is for and
|
|
how to start a new driver from it. A paragraph or two is
|
|
enough.
|
|
|
|
7. Commit the template to your Git repository. Tag the commit
|
|
with a version number such as `template-v1.0`.
|
|
|
|
**Deliverable.** A personal, versioned driver template in a Git
|
|
repository you control.
|
|
|
|
**What to notice.** The first version of your template will
|
|
feel over- or under-specified in particular ways. That is
|
|
normal. The template will evolve over the next several projects
|
|
as you notice patterns you always add or patterns you always
|
|
remove. Version it. Let it grow.
|
|
|
|
### 7.4 Lab 4: Subscribe to a Mailing List
|
|
|
|
**Goal.** Establish a connection to the FreeBSD community
|
|
through a specific mailing list.
|
|
|
|
**Time.** Twenty minutes to subscribe; one hour per week for
|
|
four weeks to read.
|
|
|
|
**Materials.** A working email account. Internet access.
|
|
|
|
**Steps.**
|
|
|
|
1. Choose a mailing list. For driver-focused readers,
|
|
`freebsd-drivers@` is a natural choice. For readers who want
|
|
a broader view of kernel development, `freebsd-hackers@` is
|
|
appropriate. For readers who want to track the current
|
|
branch specifically, `freebsd-current@` is the list.
|
|
|
|
2. Visit the project's mailing-list page at
|
|
`https://lists.freebsd.org/` and follow the subscription
|
|
instructions for the list you chose.
|
|
|
|
3. Set up a mail filter that moves the list's messages to a
|
|
dedicated folder, so they do not overwhelm your inbox.
|
|
|
|
4. For each of the next four weeks, block out an hour to read
|
|
the list. Read at least one full thread per week. Take
|
|
notes on any threads that touch areas you care about or
|
|
surprise you.
|
|
|
|
5. If you have something to contribute to a thread (a
|
|
correction, a data point, an answer to a question), reply.
|
|
If not, just read. Lurking is fine.
|
|
|
|
6. At the end of four weeks, decide whether to keep the
|
|
subscription. If the list is not useful for your purposes,
|
|
unsubscribe. If it is useful, keep it and let it become
|
|
part of your routine.
|
|
|
|
**Deliverable.** A record of the subscription, a mail filter
|
|
set up, and four weeks of at least one thread read per week.
|
|
|
|
**What to notice.** Mailing lists are a slow medium. Nothing
|
|
happens quickly, and it can take several weeks for the value to
|
|
become clear. Give the exercise the full four weeks before
|
|
judging it.
|
|
|
|
### 7.5 Lab 5: Review a Manual Page You Have Not Read
|
|
|
|
**Goal.** Deepen your familiarity with FreeBSD's reference
|
|
documentation by reading a manual page you have not yet read.
|
|
|
|
**Time.** One hour.
|
|
|
|
**Materials.** Access to the FreeBSD manual pages, either through
|
|
`man(1)` on a FreeBSD system or through the web at
|
|
`https://man.freebsd.org/`. A notebook or text editor.
|
|
|
|
**Steps.**
|
|
|
|
1. Pick a manual page you have not read. It should be relevant
|
|
to areas you might want to study further. Good candidates:
|
|
`vnode(9)`, `crypto(9)`, `iflib(9)`, `audit(4)`, `mac(9)`,
|
|
`kproc(9)`.
|
|
|
|
2. Read the manual page in full. Expect it to take twenty to
|
|
forty minutes if the page is substantive.
|
|
|
|
3. After reading, close the manual page. On a blank piece of
|
|
paper or in a text file, write a one-paragraph summary in
|
|
your own words. Cover: what the interface is for, what its
|
|
main data structures and functions are, and what a
|
|
hypothetical driver would use it for.
|
|
|
|
4. Reopen the manual page and compare your paragraph to the
|
|
reference. Where is your paragraph vague or inaccurate?
|
|
Revise it.
|
|
|
|
5. Save the paragraph in your personal knowledge directory,
|
|
labelled by the manual page name and the date.
|
|
|
|
**Deliverable.** A written paragraph summarising a manual page
|
|
you have newly read, saved for future reference.
|
|
|
|
**What to notice.** Writing your own summary forces
|
|
understanding at a level that passive reading does not. A
|
|
paragraph you can write well is a topic you understand. A
|
|
paragraph you struggle with is a topic that needs more study.
|
|
The paragraphs accumulate over time into a personal glossary
|
|
of the kernel.
|
|
|
|
### 7.6 Lab 6: Build a Regression Test for a Driver You Wrote
|
|
|
|
**Goal.** Produce a regression test suite for one of your
|
|
drivers from the book.
|
|
|
|
**Time.** Three to four hours.
|
|
|
|
**Materials.** A driver you wrote during the book. The
|
|
`regression-test.sh` skeleton in
|
|
`examples/part-07/ch38-final-thoughts/scripts/`. A FreeBSD
|
|
development VM.
|
|
|
|
**Steps.**
|
|
|
|
1. Pick a driver. The async I/O driver from Chapter 35 is a
|
|
good candidate because it has enough complexity to make
|
|
regression testing worthwhile.
|
|
|
|
2. Copy the regression-test skeleton into a tests directory
|
|
alongside the driver.
|
|
|
|
3. Identify three behaviours that the driver should reliably
|
|
exhibit. Example for the async driver: "loads without
|
|
warnings," "accepts a write and allows it to be read back,"
|
|
"unloads cleanly after being loaded and exercised."
|
|
|
|
4. Translate each behaviour into an automated check. A check
|
|
is a shell command that produces a predictable output or
|
|
exit code if the behaviour holds, and an unpredictable one
|
|
if it does not. Use `kldload`, `kldunload`, `dd`,
|
|
`sysctl`, and similar tools as building blocks.
|
|
|
|
5. Wire the checks together in the script. A good script
|
|
runs each check, reports the result, and exits with a
|
|
non-zero status if any check failed.
|
|
|
|
6. Run the script. Verify it passes against the current
|
|
driver. Verify it fails when you deliberately break the
|
|
driver (add a line that aborts in the module init, for
|
|
example) and then remove the deliberate break.
|
|
|
|
7. Commit the script alongside the driver in your Git
|
|
repository.
|
|
|
|
**Deliverable.** A working regression-test script for a driver
|
|
you wrote, committed to your repository.
|
|
|
|
**What to notice.** Regression tests are often harder to write
|
|
than the code they test, especially for kernel modules. The
|
|
difficulty is exactly why they are valuable: they force you to
|
|
articulate what "correct behaviour" means in a way that can be
|
|
checked automatically. A driver without regression tests is a
|
|
driver whose correctness claims are verbal; a driver with
|
|
regression tests has those claims encoded in something
|
|
reproducible.
|
|
|
|
### 7.7 Lab 7: File or Triage a Bugzilla PR
|
|
|
|
**Goal.** Interact with the FreeBSD Bugzilla in a concrete,
|
|
small way.
|
|
|
|
**Time.** One to two hours.
|
|
|
|
**Materials.** A FreeBSD Bugzilla account (free to create).
|
|
Your FreeBSD 14.3 development system.
|
|
|
|
**Steps.**
|
|
|
|
1. Create a Bugzilla account at
|
|
`https://bugs.freebsd.org/bugzilla/` if you do not have
|
|
one.
|
|
|
|
2. Option A (triage path): Browse the open PRs in the `kern`
|
|
product or a driver component you care about. Find a PR
|
|
that has not been updated in at least six months and whose
|
|
status is unclear. Attempt to reproduce the issue on your
|
|
system. Add a comment to the PR with your findings: what
|
|
you tried, what you observed, whether you can reproduce
|
|
the issue.
|
|
|
|
3. Option B (reporting path): If you have encountered a bug
|
|
in a driver or in the kernel during the book, and you
|
|
have not yet reported it, file a PR. Include the FreeBSD
|
|
version, the hardware, clear reproduction steps, and any
|
|
relevant output from `dmesg`, `uname -a`, or the driver's
|
|
own diagnostics.
|
|
|
|
4. Whatever option you choose, write the PR or comment in
|
|
the clear, specific style that Bugzilla interactions
|
|
reward. Avoid vague statements. Be specific. Include
|
|
details someone else could act on.
|
|
|
|
5. Save the URL of the PR or comment. Add it to your
|
|
contribution log if you keep one.
|
|
|
|
**Deliverable.** A PR you filed or a comment you added on an
|
|
existing PR, in the FreeBSD Bugzilla.
|
|
|
|
**What to notice.** Bugzilla interactions have a specific
|
|
style that is different from mailing-list posts and different
|
|
from code-review comments. Clarity, reproducibility, and
|
|
specificity are the main virtues. A well-formed PR gets
|
|
attention; a poorly-formed one does not.
|
|
|
|
### 7.8 Lab 8: Set Up Your Virtual Lab
|
|
|
|
**Goal.** Produce a reproducible virtual lab you can boot
|
|
quickly for future driver work.
|
|
|
|
**Time.** Half a day.
|
|
|
|
**Materials.** A host system with bhyve (on FreeBSD) or QEMU
|
|
(on any host). A FreeBSD 14.3 installation image.
|
|
|
|
**Steps.**
|
|
|
|
1. Create a working directory for your lab. Initialise a Git
|
|
repository in it for the scripts and configuration files.
|
|
|
|
2. Write a shell script that creates a disk image of at
|
|
least 20 GB. Use `truncate(1)` or an equivalent to create
|
|
a sparse file.
|
|
|
|
3. Write a shell script that runs the chosen hypervisor
|
|
with the appropriate command-line arguments to boot from
|
|
the FreeBSD installation image and install FreeBSD into
|
|
the disk image. Document every flag.
|
|
|
|
4. After installation, take a snapshot of the disk image
|
|
(copy it, or use the hypervisor's snapshot mechanism).
|
|
Label the snapshot with the FreeBSD version and the date.
|
|
|
|
5. Write a shell script that boots the installed system. It
|
|
should use a serial console, mount a shared directory for
|
|
source code if your hypervisor supports it, and configure
|
|
networking so that you can SSH into the guest.
|
|
|
|
6. Boot the guest. SSH into it. Verify you can build a
|
|
trivial kernel module (a "hello world" module is fine) in
|
|
the guest.
|
|
|
|
7. Commit all the scripts and the documentation to your Git
|
|
repository. Tag the commit with the FreeBSD version and
|
|
the date.
|
|
|
|
**Deliverable.** A Git repository containing your lab's
|
|
configuration, along with a known-good snapshot of an
|
|
installed system.
|
|
|
|
**What to notice.** The lab setup is a one-time investment
|
|
that pays off on every subsequent project. If the lab takes
|
|
ten minutes to boot, you will reach for it only for serious
|
|
work. If it takes thirty seconds to boot, you will reach for
|
|
it constantly, and the pace of your driver work will be much
|
|
faster.
|
|
|
|
### 7.9 Wrapping Up the Reflection Labs
|
|
|
|
These eight labs have walked you through producing a set of
|
|
personal artifacts: a self-assessment, a learning roadmap, a
|
|
driver template, a mailing-list subscription, a manual-page
|
|
summary, a regression-test script, a Bugzilla interaction, and
|
|
a virtual lab. Together they constitute a snapshot of your
|
|
current state and a starting position for the next phase of
|
|
your work.
|
|
|
|
None of the artifacts is especially elaborate. Each one could
|
|
be produced by someone who had finished this book. But
|
|
together, they represent a surprisingly large amount of
|
|
infrastructure that supports ongoing FreeBSD driver work.
|
|
Without them, you start from zero every time. With them, you
|
|
start from ground already cleared.
|
|
|
|
Keep the artifacts. Revisit them. Evolve them. Over the course
|
|
of the next year, they will shape how your work proceeds in
|
|
ways that are easier to recognise in retrospect than in
|
|
prospect.
|
|
|
|
## 8. Challenge Exercises
|
|
|
|
The challenges in this section are longer, more open-ended
|
|
than the labs, and designed for readers who want to go further
|
|
than the main chapter material. There is no single correct way
|
|
to complete any of them, and you may find that your approach
|
|
differs substantially from another reader's. That is fine.
|
|
The challenges are invitations, not puzzles.
|
|
|
|
### 8.1 Challenge 1: Write a Real Driver for Real Hardware
|
|
|
|
**Description.** Pick a piece of hardware you own, verify that
|
|
FreeBSD does not already support it adequately, and write a
|
|
driver for it. Go through the full cycle: acquisition,
|
|
investigation, implementation, documentation, testing, and
|
|
consideration for upstream submission.
|
|
|
|
**Scope.** This is a multi-week or multi-month project. A
|
|
reasonable target is a relatively simple device: a USB serial
|
|
adapter using an unsupported chipset, a PCI card for a niche
|
|
application, a GPIO-connected sensor. Avoid ambitious targets
|
|
for a first independent project; graphics cards and wireless
|
|
chipsets are notoriously hard.
|
|
|
|
**Milestones.**
|
|
|
|
1. Identify the hardware. Confirm that FreeBSD does not
|
|
support it, or supports it incompletely.
|
|
|
|
2. Gather documentation. Vendor datasheets, Linux or NetBSD
|
|
drivers, chipset specs, whatever is available.
|
|
|
|
3. Set up a development environment. Configure your virtual
|
|
lab to talk to the real hardware if your hypervisor
|
|
supports passthrough, or plan to build and test on a
|
|
physical FreeBSD system.
|
|
|
|
4. Write an initial probe and attach sequence. Confirm that
|
|
FreeBSD can at least identify and attach to the hardware.
|
|
|
|
5. Implement the main driver functionality, one feature at a
|
|
time, with tests for each.
|
|
|
|
6. Write a manual page.
|
|
|
|
7. Consider submission. Follow the Chapter 37 workflow if you
|
|
decide to submit.
|
|
|
|
**What you will learn.** Independent driver development at a
|
|
level the book's exercises did not require. The experience of
|
|
a real, non-trivial project with its own friction and its own
|
|
surprises.
|
|
|
|
### 8.2 Challenge 2: Fix a Real Bug in a Real Driver
|
|
|
|
**Description.** Find an open bug in a driver in the FreeBSD
|
|
tree, reproduce it, understand it, fix it, and submit the fix
|
|
upstream.
|
|
|
|
**Scope.** A couple of weekends, depending on the bug. Some
|
|
bugs are one-line fixes; others require substantial
|
|
investigation.
|
|
|
|
**Milestones.**
|
|
|
|
1. Browse the FreeBSD Bugzilla for open driver bugs. Filter
|
|
by "kern" or by specific drivers. Look for bugs that have
|
|
clear reproduction steps and are not obviously abandoned.
|
|
|
|
2. Pick a bug that matches your skill level. A good first
|
|
bug is one where the reporter has already done some
|
|
investigation and where the fix is likely to be small.
|
|
|
|
3. Reproduce the bug on your system. This step is essential
|
|
and often takes longer than expected.
|
|
|
|
4. Investigate. Read the relevant driver source. Add
|
|
diagnostic printouts or `KTR` traces if needed. Form a
|
|
hypothesis about the cause.
|
|
|
|
5. Write a fix. Test it. Verify that the bug is resolved.
|
|
|
|
6. Check that you have not introduced new bugs.
|
|
|
|
7. Submit the fix, following the Chapter 37 workflow.
|
|
|
|
**What you will learn.** Reading and understanding code
|
|
written by other people, working within existing conventions,
|
|
and experiencing the full upstream workflow with a real,
|
|
accepted contribution.
|
|
|
|
### 8.3 Challenge 3: Port a Linux or NetBSD Driver to FreeBSD
|
|
|
|
**Description.** Pick a driver that exists in Linux or NetBSD
|
|
but not in FreeBSD (or is incomplete in FreeBSD). Study the
|
|
existing driver, understand the hardware interface, and write
|
|
an equivalent FreeBSD driver.
|
|
|
|
**Scope.** A serious multi-month project. Only attempt this if
|
|
you have a specific piece of hardware in mind and enough
|
|
interest to sustain the work.
|
|
|
|
**Milestones.**
|
|
|
|
1. Choose the target hardware and the source driver. Verify
|
|
the source driver's license is compatible with your
|
|
intended license for the FreeBSD driver.
|
|
|
|
2. Read the source driver in full. Understand what it does
|
|
at the interface level: how it probes, how it handles
|
|
interrupts, what data structures it uses, how it handles
|
|
DMA.
|
|
|
|
3. Design your FreeBSD driver architecture. It will not be a
|
|
line-by-line port. FreeBSD's conventions differ from
|
|
Linux's, and a well-ported driver respects FreeBSD's
|
|
conventions.
|
|
|
|
4. Write the driver, using the source driver as a reference
|
|
for what the hardware does but writing the code from
|
|
scratch in FreeBSD style.
|
|
|
|
5. Test against the real hardware.
|
|
|
|
6. Document the driver and submit.
|
|
|
|
**What you will learn.** Cross-system driver translation is a
|
|
serious craft. You will learn FreeBSD idioms more deeply by
|
|
contrasting them with Linux or NetBSD idioms. You will also
|
|
learn the discipline of writing fresh code from an
|
|
understanding of a specification rather than from cut-and-paste.
|
|
|
|
### 8.4 Challenge 4: Write a Deep Technical Blog Post
|
|
|
|
**Description.** Write a thorough, carefully researched blog
|
|
post about a FreeBSD kernel topic you want to understand
|
|
better. The goal is not to produce a perfect post for a large
|
|
audience; it is to use the act of writing to deepen your own
|
|
understanding.
|
|
|
|
**Scope.** A weekend or two. Longer if you have a particularly
|
|
complex topic.
|
|
|
|
**Milestones.**
|
|
|
|
1. Pick a topic. It should be something you partly understand
|
|
but want to understand better. Good examples: "How FreeBSD's
|
|
epoch interface works," "The lifecycle of an interrupt in
|
|
FreeBSD," "How `iflib` abstracts hardware for network
|
|
drivers."
|
|
|
|
2. Read everything you can find on the topic. Manual pages,
|
|
source code, previous blog posts, conference talks.
|
|
|
|
3. Draft the post. Aim for three to five thousand words.
|
|
|
|
4. Revise. Cut the parts that are wrong or unclear. Sharpen
|
|
the parts that are strong.
|
|
|
|
5. Ask a friend or colleague to read the draft. If they are
|
|
a FreeBSD developer, all the better. If they are not,
|
|
their questions will reveal gaps in your explanation.
|
|
|
|
6. Publish the post. Your own blog, the FreeBSD forum, or
|
|
dev.to are all reasonable venues.
|
|
|
|
**What you will learn.** Teaching is one of the deepest forms
|
|
of learning. The act of writing a careful explanation forces
|
|
you to confront everything you do not yet understand, and
|
|
resolving those gaps is how understanding grows.
|
|
|
|
### 8.5 Challenge 5: Become a Reviewer
|
|
|
|
**Description.** Pick a specific area of the FreeBSD tree
|
|
(driver-related for readers of this book) and commit to
|
|
reviewing every Phabricator review that touches that area for
|
|
one month.
|
|
|
|
**Scope.** Depending on the area's activity, this could be a
|
|
few reviews a week or several per day. A month of regular
|
|
reviewing will give you experience at the craft of review
|
|
without overwhelming other obligations.
|
|
|
|
**Milestones.**
|
|
|
|
1. Choose an area. A specific driver or subsystem is ideal.
|
|
|
|
2. Set up notifications for Phabricator reviews in that area.
|
|
The Phabricator interface supports this.
|
|
|
|
3. For each review, read the proposed change carefully.
|
|
Understand what it is trying to do. Test it locally if the
|
|
change is small enough.
|
|
|
|
4. Post your review comments. Be specific. Be constructive.
|
|
Ask questions when you are uncertain rather than asserting
|
|
things you are not sure of.
|
|
|
|
5. Respond to replies. Engage in the review discussion until
|
|
the review is resolved.
|
|
|
|
6. At the end of the month, reflect on what you learned.
|
|
|
|
**What you will learn.** Code review is a different skill from
|
|
code writing. It requires reading carefully, understanding
|
|
intent, and articulating suggestions productively. Developers
|
|
who review well are among the most valuable members of any
|
|
project, and the skill is one you can develop with practice.
|
|
|
|
### 8.6 Challenge 6: Run a Study Group
|
|
|
|
**Description.** Organise a small group of peers to work
|
|
through a challenging topic together. The topic should be
|
|
something none of you feel confident about individually, where
|
|
working together will produce a shared understanding faster
|
|
than working alone.
|
|
|
|
**Scope.** A group of three to six people, meeting weekly for
|
|
two to three months.
|
|
|
|
**Milestones.**
|
|
|
|
1. Find the peers. They can be former colleagues, members of
|
|
a local BSD user group, participants in an online forum.
|
|
Three to six is the right size.
|
|
|
|
2. Choose a topic together. The VFS layer, `iflib`, the ACPI
|
|
subsystem, or netgraph are all reasonable candidates.
|
|
|
|
3. Agree on a cadence and a format. A weekly video call with
|
|
a shared reading list is a standard format. Each member
|
|
prepares a section each week and presents it.
|
|
|
|
4. Meet regularly. Take notes. Share what you learn between
|
|
meetings.
|
|
|
|
5. Produce a group artifact at the end. A shared notes
|
|
document, a blog post summarising the study, or a
|
|
presentation to a local user group.
|
|
|
|
**What you will learn.** Collaborative study is among the most
|
|
effective ways to learn complex material. You will also learn
|
|
how to organise and sustain a group, which is a leadership
|
|
skill in its own right.
|
|
|
|
### 8.7 Challenge 7: Contribute a Non-Code Artifact
|
|
|
|
**Description.** Contribute something to the FreeBSD Project
|
|
that is not code and not driver-specific. A documentation
|
|
patch, a translation, a manual-page improvement, a test-case
|
|
addition, a diagram for the handbook, whatever has a clear
|
|
value.
|
|
|
|
**Scope.** A weekend.
|
|
|
|
**Milestones.**
|
|
|
|
1. Find a non-code artifact that needs improvement. Outdated
|
|
manual pages, incomplete handbook sections, missing
|
|
translations, or gaps in the test suite are common
|
|
candidates.
|
|
|
|
2. Improve it. Write the new version carefully. Test it if it
|
|
is testable.
|
|
|
|
3. Submit it through the appropriate workflow. For
|
|
documentation, this means the documentation Git
|
|
repository. For manual pages, the main source tree. For
|
|
translations, the translation system.
|
|
|
|
4. Respond to review feedback until the contribution is
|
|
accepted.
|
|
|
|
**What you will learn.** Non-code contributions have their own
|
|
submission flows and their own community expectations. Going
|
|
through one end-to-end broadens your sense of what it means to
|
|
contribute.
|
|
|
|
### 8.8 Challenge 8: Sustain a Personal Practice for Six Months
|
|
|
|
**Description.** The most difficult challenge in this chapter is
|
|
not technical. It is the challenge of sustaining your practice
|
|
after the book is closed. Many readers finish technical books
|
|
with enthusiasm and then let the momentum fade within weeks.
|
|
This challenge is to resist that pattern deliberately, by
|
|
committing to a specific, sustained practice for six months.
|
|
|
|
**Scope.** Commit to a small, regular practice. Not a heroic
|
|
one. Examples of a sustainable cadence: two hours of kernel work
|
|
every Saturday morning, or one hour every weekday evening, or
|
|
every second weekend dedicated to a single driver project.
|
|
Whatever you choose, write it down and stick to it.
|
|
|
|
**Milestones.**
|
|
|
|
1. Define the practice in a single sentence you can quote from
|
|
memory. If you cannot state it cleanly, it is not specific
|
|
enough.
|
|
|
|
2. Name a concrete project that will run through the full six
|
|
months. The project must be small enough to complete but
|
|
meaningful enough to sustain your interest.
|
|
|
|
3. Track your sessions in a plain log. Date, duration, one
|
|
sentence on what you did. The log's existence matters more
|
|
than its length.
|
|
|
|
4. At month three, review the log honestly. If you are behind,
|
|
adjust the cadence downward rather than giving up. A smaller
|
|
sustained practice is worth more than a larger abandoned
|
|
one.
|
|
|
|
5. At month six, write a short reflection on what you produced,
|
|
what you learned, and what you will do next.
|
|
|
|
**What you will learn.** Sustaining a practice is itself a
|
|
skill, and it compounds across every area of a long career.
|
|
Readers who learn to sustain their own practice in the months
|
|
after this book will, in the long run, go much further than
|
|
readers whose enthusiasm was bright but brief. This challenge
|
|
exists specifically to help you build that habit on the other
|
|
side of the book's last page.
|
|
|
|
### 8.9 Wrapping Up the Challenges
|
|
|
|
The challenges above range from small to substantial. None of
|
|
them is required. A reader who completes one will have
|
|
deepened their practice in a specific direction. A reader who
|
|
completes several will be approaching the level of a working
|
|
junior FreeBSD developer. A reader who completes all of them
|
|
will be approaching the level at which commit rights become a
|
|
meaningful possibility.
|
|
|
|
Pick the one or two that align with your interests and your
|
|
available time. Execute them carefully. Let them inform the
|
|
next iteration of your learning roadmap.
|
|
|
|
## 9. Personal Planning and Checklists
|
|
|
|
This section presents a few checklists and planning artifacts
|
|
that you can use as templates. They are deliberately short and
|
|
tactical, not elaborate frameworks. Each of them answers a
|
|
specific practical question.
|
|
|
|
### 9.1 A Contribution Checklist
|
|
|
|
Use this checklist the first time you send a patch to the
|
|
FreeBSD Project, and every time after that.
|
|
|
|
- [ ] My patch addresses a specific, well-defined issue or
|
|
adds a specific, well-defined feature.
|
|
- [ ] I have verified that the patch applies cleanly to the
|
|
current tip of the relevant branch.
|
|
- [ ] I have built the patch on amd64 and verified it
|
|
compiles without warnings.
|
|
- [ ] I have built the patch on at least one other
|
|
architecture (typically arm64) and verified it compiles
|
|
without warnings.
|
|
- [ ] I have run the pre-submission test script from
|
|
Chapter 37 and all steps pass.
|
|
- [ ] I have written or updated the relevant manual page.
|
|
- [ ] I have run `mandoc -Tlint` on the manual page and it
|
|
is silent.
|
|
- [ ] I have written a commit message that explains what the
|
|
change does and why.
|
|
- [ ] I have verified that no proprietary information,
|
|
internal company URLs, or private correspondence appear in
|
|
the patch.
|
|
- [ ] I have identified the reviewer(s) I will request.
|
|
- [ ] I have chosen the appropriate submission channel:
|
|
Phabricator for structured review, GitHub or mailing list
|
|
otherwise.
|
|
- [ ] I have a plan for responding to review feedback within
|
|
a reasonable time.
|
|
- [ ] I have subscribed to notifications for the review so I
|
|
will see comments quickly.
|
|
- [ ] I understand that merging the patch is a beginning, not
|
|
an end, and I am prepared to maintain the code.
|
|
|
|
### 9.2 A Stay-Current Checklist
|
|
|
|
Use this checklist on a monthly cadence to keep yourself
|
|
current with FreeBSD development.
|
|
|
|
- [ ] I have pulled the latest FreeBSD source tree.
|
|
- [ ] I have built my personal drivers against the latest
|
|
source and investigated any warnings or errors.
|
|
- [ ] I have run my regression tests against the latest
|
|
source and investigated any failures.
|
|
- [ ] I have read the commit log for the subsystems I care
|
|
about since the last time I looked.
|
|
- [ ] I have checked UPDATING for new notices.
|
|
- [ ] I have read at least one thread on freebsd-hackers@ or
|
|
freebsd-drivers@ since the last check.
|
|
- [ ] I have watched at least one conference talk or read at
|
|
least one blog post about FreeBSD development.
|
|
- [ ] I have thought about whether any of the changes I saw
|
|
affect my ongoing work.
|
|
- [ ] I have noted any TODO items for next month's review.
|
|
|
|
### 9.3 A Self-Assessment Worksheet
|
|
|
|
Use this worksheet every three to six months to track your
|
|
growth.
|
|
|
|
**Date:** ___________________
|
|
|
|
**FreeBSD version last built:** ___________________
|
|
|
|
**Confidence rating (1-5) and one-sentence rationale:**
|
|
|
|
- C for kernel programming: ___________________
|
|
- Kernel debugging and profiling: ___________________
|
|
- Device tree integration: ___________________
|
|
- Reverse engineering and embedded development: ___________________
|
|
- Userland interfaces (ioctl, sysctl, poll, kqueue): ___________________
|
|
- Concurrency and synchronisation: ___________________
|
|
- DMA, interrupts, and hardware interaction: ___________________
|
|
- Upstream submission and review readiness: ___________________
|
|
- bus_space(9): ___________________
|
|
- sysctl(9): ___________________
|
|
- dtrace(1): ___________________
|
|
- devfs(5): ___________________
|
|
- Newbus (device_t, DEVMETHOD, DRIVER_MODULE): ___________________
|
|
- Locking (mutexes, sx, rmlocks, condition variables): ___________________
|
|
|
|
**Three topics I most want to deepen in the next six months:**
|
|
|
|
1. ___________________
|
|
2. ___________________
|
|
3. ___________________
|
|
|
|
**One concrete project I will start this month:**
|
|
|
|
___________________
|
|
|
|
**One community action I will take this month:**
|
|
|
|
___________________
|
|
|
|
### 9.4 A Learning Roadmap Template
|
|
|
|
Use this template to plan each three-to-six-month learning
|
|
cycle.
|
|
|
|
**Period:** ___________________ to ___________________
|
|
|
|
**Primary focus area:** ___________________
|
|
|
|
**Why this area, now:** ___________________
|
|
|
|
**Monthly milestones:**
|
|
|
|
- Month 1: ___________________
|
|
- Month 2: ___________________
|
|
- Month 3: ___________________
|
|
|
|
**Resources I will use:**
|
|
|
|
- Manual pages: ___________________
|
|
- Source files: ___________________
|
|
- Conference talks: ___________________
|
|
- Books and papers: ___________________
|
|
- People I will learn from: ___________________
|
|
|
|
**Practice cadence:**
|
|
|
|
- Frequency: ___________________
|
|
- Duration per session: ___________________
|
|
|
|
**Secondary goals:**
|
|
|
|
- Toolkit improvement: ___________________
|
|
- Community engagement: ___________________
|
|
- Currency: ___________________
|
|
|
|
**Review date:** ___________________
|
|
|
|
### 9.5 A Code Review Checklist
|
|
|
|
Sooner or later, whether you are reviewing another developer's
|
|
patch or reviewing your own code before submitting it, you will
|
|
benefit from a consistent mental pass over the same set of
|
|
concerns. Use this checklist when you sit down to review a
|
|
change. It applies equally to your own work and to work you
|
|
review for others.
|
|
|
|
- [ ] I understand what the change is trying to accomplish and
|
|
can restate its purpose in one sentence.
|
|
- [ ] The change is scoped appropriately: not too large to
|
|
review carefully, not so small that the context is missing.
|
|
- [ ] The commit message explains the "why" clearly and will
|
|
still make sense in five years.
|
|
- [ ] The change does not mix unrelated concerns (cleanup plus
|
|
feature, refactor plus bug fix) without a strong reason.
|
|
- [ ] Every function added or modified has a clear
|
|
responsibility and a clear contract.
|
|
- [ ] Error paths are handled, not silently swallowed.
|
|
- [ ] Resources allocated in attach() are released in
|
|
detach() in reverse order.
|
|
- [ ] Any new locks are named clearly, their scope is explicit,
|
|
and their lock order is consistent with existing code.
|
|
- [ ] The change does not introduce potential use-after-free,
|
|
leaked references, or double-free paths.
|
|
- [ ] The change passes `checkstyle9.pl` without warnings.
|
|
- [ ] The change compiles on at least two architectures with
|
|
no new warnings.
|
|
- [ ] Any manual pages or documentation affected by the change
|
|
have been updated.
|
|
- [ ] Any `sysctl` or `dev.` names introduced are named
|
|
consistently with existing conventions.
|
|
- [ ] The change behaves correctly under load and unload cycles.
|
|
- [ ] The change does not break any in-tree test.
|
|
- [ ] The change has a test case or a clear reason why no test
|
|
is possible.
|
|
|
|
When reviewing other people's code, add one more item: have I
|
|
been respectful, specific, and helpful, rather than abrupt or
|
|
dismissive? Code review is one of the most visible forms of
|
|
community participation, and the tone matters as much as the
|
|
substance.
|
|
|
|
### 9.6 A Debugging Journal Entry Template
|
|
|
|
When you run into a hard bug, write it down before, during, and
|
|
after the debugging session. The journal serves two purposes:
|
|
it helps you think clearly while the bug is fresh, and it gives
|
|
you something to return to the next time you hit a similar
|
|
problem. Over time, these entries become a personal reference
|
|
that saves you hours.
|
|
|
|
Use this template for each bug you spend more than a single
|
|
short session on.
|
|
|
|
**Date:** ___________________
|
|
|
|
**Module or driver:** ___________________
|
|
|
|
**Kernel version:** ___________________
|
|
|
|
**One-line description of the symptom:**
|
|
|
|
___________________
|
|
|
|
**What I observed first:**
|
|
|
|
___________________
|
|
|
|
**First hypothesis:**
|
|
|
|
___________________
|
|
|
|
**How I tested the first hypothesis:**
|
|
|
|
___________________
|
|
|
|
**What happened instead:**
|
|
|
|
___________________
|
|
|
|
**Second hypothesis (if applicable):**
|
|
|
|
___________________
|
|
|
|
**What the root cause turned out to be:**
|
|
|
|
___________________
|
|
|
|
**What specifically fixed it:**
|
|
|
|
___________________
|
|
|
|
**What I learned that I did not know before:**
|
|
|
|
___________________
|
|
|
|
**What I would look at sooner next time:**
|
|
|
|
___________________
|
|
|
|
**Relevant source paths and line numbers:**
|
|
|
|
___________________
|
|
|
|
**Relevant mailing-list threads, commits, or bug IDs:**
|
|
|
|
___________________
|
|
|
|
The act of filling in the last two fields ("what I learned"
|
|
and "what I would look at sooner next time") is the most
|
|
valuable part. Those fields compound across entries and
|
|
gradually turn a developer who solves each bug individually
|
|
into one who recognises patterns across bugs.
|
|
|
|
### 9.7 A Driver Handoff Checklist
|
|
|
|
A driver is rarely owned by the same person forever. Whether
|
|
you are handing a driver off to a new maintainer, leaving a
|
|
company, or simply transferring stewardship to a colleague,
|
|
there is a short list of things that make the handoff
|
|
successful. Use this checklist when the handoff is planned,
|
|
and use it as a self-review when you suspect a handoff may
|
|
become necessary.
|
|
|
|
- [ ] The driver has a current manual page that reflects its
|
|
real behaviour.
|
|
- [ ] The driver has a short design document that explains the
|
|
non-obvious decisions and the hardware-specific quirks.
|
|
- [ ] The driver has a regression test suite that the new
|
|
maintainer can run on their own hardware.
|
|
- [ ] The driver has a working build from a clean tree, with
|
|
no local modifications required.
|
|
- [ ] The driver has been tested against at least two FreeBSD
|
|
releases, and the compatibility range is documented.
|
|
- [ ] All TODOs, known bugs, and planned work are recorded in
|
|
an issue tracker or a text file in the repository.
|
|
- [ ] The `sysctl` variables and `dev.` names are documented
|
|
with their meaning and their expected range of values.
|
|
- [ ] Any vendor-specific documentation, datasheets, or NDAs
|
|
that affect the driver are recorded, either with the driver
|
|
or in a known location.
|
|
- [ ] The hardware required to test the driver is described in
|
|
enough detail that the new maintainer can acquire or borrow
|
|
it.
|
|
- [ ] The new maintainer has been introduced to the relevant
|
|
mailing list discussions and to any community members who
|
|
have contributed.
|
|
- [ ] Any outstanding patches, reviews, or conversations have
|
|
been surfaced to the new maintainer.
|
|
- [ ] The commit history does not contain any proprietary
|
|
information that would prevent further public development.
|
|
|
|
If a driver cannot cleanly meet this checklist, the handoff
|
|
will leave debt for the next maintainer. Spend the time before
|
|
the handoff closing the gaps. The cleaner the handoff, the
|
|
more likely the driver continues to receive care after you
|
|
step away.
|
|
|
|
### 9.8 A Quarterly Review Template
|
|
|
|
Every three months, take an hour or two to review your
|
|
broader trajectory, not just your immediate projects. The
|
|
quarterly review is different from the monthly stay-current
|
|
rhythm. The monthly rhythm keeps you in touch with the kernel
|
|
as a living system. The quarterly review keeps you in touch
|
|
with your own growth as a developer.
|
|
|
|
Use this template for each quarterly review. Keep the filled
|
|
copies together in your `freebsd-learning` repository so you
|
|
can read them in sequence.
|
|
|
|
**Quarter:** Q___ of ____
|
|
|
|
**Start date:** ___________________
|
|
|
|
**End date:** ___________________
|
|
|
|
**What I worked on this quarter, at a glance:**
|
|
|
|
___________________
|
|
|
|
**What I consider the most significant thing I learned:**
|
|
|
|
___________________
|
|
|
|
**A specific moment I am proud of:**
|
|
|
|
___________________
|
|
|
|
**A specific moment that was harder than I expected:**
|
|
|
|
___________________
|
|
|
|
**Progress against my learning roadmap:**
|
|
|
|
- Milestones I completed: ___________________
|
|
- Milestones I missed: ___________________
|
|
- Milestones I changed or abandoned, and why:
|
|
___________________
|
|
|
|
**Community engagement this quarter:**
|
|
|
|
- Patches submitted: ___________________
|
|
- Reviews performed: ___________________
|
|
- Mailing-list replies: ___________________
|
|
- Conference talks watched: ___________________
|
|
- Bug reports filed or triaged: ___________________
|
|
|
|
**Toolkit improvements this quarter:**
|
|
|
|
- New scripts or templates I added: ___________________
|
|
- Existing scripts I improved: ___________________
|
|
- Scripts I retired: ___________________
|
|
|
|
**What I want to prioritise next quarter:**
|
|
|
|
1. ___________________
|
|
2. ___________________
|
|
3. ___________________
|
|
|
|
**What I want to stop doing, or do less of, next quarter:**
|
|
|
|
___________________
|
|
|
|
**Who I would like to learn from next quarter:**
|
|
|
|
___________________
|
|
|
|
**One small, concrete commitment for the coming month:**
|
|
|
|
___________________
|
|
|
|
Filling in this template takes real time. It is tempting to
|
|
skip it when you are busy with other work, but skipping it is
|
|
a false economy. A quarterly review is one of the cheapest
|
|
forms of long-term self-correction available to a working
|
|
engineer, and an hour of honest reflection prevents many hours
|
|
of drifted effort later.
|
|
|
|
### 9.9 Where to Keep These Artifacts
|
|
|
|
A practical question: where should these artifacts live? The
|
|
answer depends on your working style, but a few options work
|
|
well.
|
|
|
|
A personal Git repository is ideal. Create a repository called
|
|
something like `freebsd-learning` or `kernel-work` and commit
|
|
each artifact as you produce it. The version history becomes
|
|
its own record of your growth. If you use a hosted Git service,
|
|
make the repository private unless you are comfortable sharing
|
|
your progress publicly; both choices are legitimate.
|
|
|
|
A folder in your home directory works if you prefer not to use
|
|
Git. Organise it by date so that you can see the chronology.
|
|
Back it up regularly.
|
|
|
|
A paper notebook works for some readers. The constraint it
|
|
imposes (one-way revision, no text search) is a feature for
|
|
some kinds of thinking, and paper notebooks have their own
|
|
durability advantages. The downside is that you cannot easily
|
|
share the contents with others or sync them across devices.
|
|
|
|
Whatever you choose, choose consistently. Scattered artifacts
|
|
across multiple systems tend to become unreachable over time. A
|
|
single, stable location where your learning record lives is
|
|
much more useful.
|
|
|
|
### 9.10 Wrapping Up Section 9
|
|
|
|
The checklists and templates in this section are small
|
|
tactical tools. They will not change your life individually,
|
|
but used regularly, they help structure the ongoing work of
|
|
professional growth. Copy them, adapt them to your
|
|
circumstances, and treat them as living documents that evolve
|
|
as you learn.
|
|
|
|
The chapter is now approaching its end. What remains is the
|
|
wrapping-up material of the chapter itself, and the final
|
|
closing words of the book.
|
|
|
|
## Wrapping Up
|
|
|
|
This chapter has walked through the full reflective arc of the
|
|
book's ending: a recognition of what you accomplished, an honest
|
|
assessment of where you stand, a map of the advanced topics that
|
|
remain beyond the book, a practical toolkit for continued work,
|
|
a careful treatment of community engagement, a rhythm for
|
|
staying current with kernel development, hands-on reflection
|
|
labs, challenge exercises, and planning artifacts. Each section
|
|
has had its own closing bridge, and the reflection labs have
|
|
produced concrete artifacts that you will keep beyond the
|
|
book.
|
|
|
|
A few themes run through the chapter and deserve a final
|
|
explicit summary.
|
|
|
|
The first theme is that finishing the book is a milestone, not
|
|
an endpoint. The milestone is real. The journey from no kernel
|
|
experience to competent driver author is a substantial one, and
|
|
you have completed it. The endpoint is something different:
|
|
mastery is never reached in kernel work, because the kernel
|
|
keeps changing and the depth of understanding keeps deepening.
|
|
A finished book is a useful checkpoint, not a final destination.
|
|
|
|
The second theme is that independence grows from practice, not
|
|
from reading. You have the knowledge to write drivers. The
|
|
knowledge is necessary but not sufficient. What turns knowledge
|
|
into independent capability is repeated practice on real
|
|
problems, and the book can only gesture toward that practice;
|
|
it cannot substitute for it. The chapter has suggested many
|
|
specific paths for that practice, and the right one for you is
|
|
whichever you are most likely to follow through on.
|
|
|
|
The third theme is that the FreeBSD community is a resource, a
|
|
destination, and a teacher. You can finish this book and
|
|
continue as a solo developer, and that is a legitimate path. But
|
|
if you engage with the community, you will grow faster, reach
|
|
further, and encounter ideas you could not have found alone. The
|
|
community is not an obligation. It is an invitation, and the
|
|
chapter has shown you many specific doors through which you can
|
|
enter.
|
|
|
|
The fourth theme is that staying current is a rhythm, not a
|
|
task. The FreeBSD kernel changes constantly, and a developer
|
|
who stops paying attention will find their knowledge slowly
|
|
rotting. A developer who maintains a weekly glance, a monthly
|
|
rebuild, and a quarterly review will stay in step with the
|
|
project over decades. The rhythm is sustainable, the benefits
|
|
compound, and the chapter has shown you exactly what that
|
|
rhythm looks like in practice.
|
|
|
|
The fifth theme is that contribution takes many forms. A reader
|
|
who thinks of contribution only as committing driver code will
|
|
miss most of the ways to be useful to the project. Mailing list
|
|
help, documentation work, translations, mentoring, bug triage,
|
|
code review, and test-case contributions are all real
|
|
contributions, and all of them are valued. The chapter has named
|
|
each of them and pointed you toward the channels where they
|
|
happen.
|
|
|
|
The sixth theme is that a development toolkit pays for itself.
|
|
The driver template, the virtual lab, the regression tests, the
|
|
CI scripts, and the packaging habits are not glamorous. Each of
|
|
them takes a few hours to set up and a few more hours to
|
|
maintain. But together they turn each new driver project from a
|
|
clean-slate effort into a refinement of an existing pipeline,
|
|
and the compounding gain is large. The chapter has given you
|
|
starter artifacts for each part of the toolkit, and the
|
|
companion directory contains the templates.
|
|
|
|
The seventh and perhaps most important theme is that you are,
|
|
now, in the practical sense, a FreeBSD device-driver developer.
|
|
Not a senior one. Not yet a committer. But a working developer
|
|
who can write, debug, test, and submit drivers. That
|
|
identification is not a small one. It took work to earn it, and
|
|
it deserves to be acknowledged.
|
|
|
|
Take a moment to appreciate what has changed in your toolkit
|
|
over the course of the book. Before Chapter 1, the FreeBSD
|
|
kernel may have been an opaque system that ran below your
|
|
applications. Now it is a readable piece of software, with
|
|
familiar patterns, known subsystems, and a predictable layout.
|
|
Before Chapter 1, writing a driver may have been a distant
|
|
aspiration. Now it is a concrete activity with a known workflow.
|
|
Before Chapter 1, the FreeBSD community may have been an
|
|
abstraction. Now it is a set of specific channels where specific
|
|
kinds of work happen.
|
|
|
|
That transformation is the quiet kind of change that long books
|
|
produce. It is not the dramatic transformation of a single
|
|
chapter, but the slow accumulation of many chapters over many
|
|
hours. Its value is measured in the difference between the
|
|
person who started and the person who finished. By that measure,
|
|
you are not the same reader who opened Chapter 1, and neither is
|
|
the book.
|
|
|
|
Before the book closes, the final words are directed to the
|
|
larger journey of which this book has been only a part.
|
|
|
|
## Part 7 Checkpoint
|
|
|
|
Part 7 spent ten chapters turning a capable driver author into one
|
|
who can ship work into the wider FreeBSD world. Before the book's
|
|
final pages, it is worth pausing to confirm that the mastery topics
|
|
have settled, because nothing after Chapter 38 will remind you of
|
|
them again.
|
|
|
|
By the end of Part 7 you should be comfortable refactoring a driver
|
|
so that its hardware-facing code sits behind a small backend
|
|
interface, compiling it against both a simulation backend and a real
|
|
one, and running the resulting module under `bhyve`, inside a VNET
|
|
jail, or behind VirtIO without changing its core. You should be
|
|
comfortable hardening a driver against hostile or careless input,
|
|
which means bounds-checking every copy, zeroing buffers before
|
|
`copyout`, applying privilege checks through `priv_check`,
|
|
rate-limiting logs, and carrying a safe detach all the way through
|
|
`MOD_QUIESCE` and resource teardown. You should be able to measure a
|
|
driver's behaviour with the right instrument for the question at
|
|
hand: DTrace and SDT probes for function-level tracing, `pmcstat` and
|
|
`hwpmc` for CPU-level events, per-CPU counters and cache-aligned
|
|
softc fields for contention relief, and `kgdb` with a core dump or
|
|
the GDB stub for bugs that survive `INVARIANTS` and `WITNESS`. And
|
|
you should be able to extend a driver's user-space contract with
|
|
`poll(2)`, `kqueue(2)`, and `SIGIO` support, approach an undocumented
|
|
device through safe probing and reverse-engineering discipline, and
|
|
prepare a submission that reviewers will actually accept, from
|
|
KNF-clean source through the manual page to the cover letter and the
|
|
Phabricator review.
|
|
|
|
If any of those still feels soft, the labs to revisit are:
|
|
|
|
- Portability and backend separation: Lab 3 (Extract the Backend Interface) and Lab 5 (Add a Simulation Backend) in Chapter 29.
|
|
- Virtualisation and jails: Lab 3 (A Minimal Character Device Driver Inside a Jail) and Lab 6 (Building and Loading the vtedu Driver) in Chapter 30.
|
|
- Security discipline: Lab 2 (Bounds-Check the Buffer), Lab 4 (Add Privilege Checks), and Lab 6 (Safe Detach) in Chapter 31.
|
|
- Embedded and Device Tree work: Lab 2 (Build and Deploy an Overlay) and Lab 4 (Build the edled Driver End to End) in Chapter 32.
|
|
- Performance and profiling: Lab 2 (DTrace `perfdemo`) and Lab 4 (Cache Alignment and Per-CPU Counters) in Chapter 33.
|
|
- Advanced debugging: Lab 2 (Capturing and Analyzing a Panic With kgdb) and Lab 5 (Catching a Use-After-Free With memguard) in Chapter 34.
|
|
- Asynchronous I/O: Lab 2 (Adding poll() Support), Lab 3 (Adding kqueue Support), and Lab 6 (The Combined v2.5-async Driver) in Chapter 35.
|
|
- Reverse engineering: Lab 3 (Building a Safe Register Probing Module) and Lab 5 (Building a Safe Probing Wrapper) in Chapter 36.
|
|
- Upstreaming: Lab 1 (Prepare the File Layout), Lab 4 (Draft the Manual Page), and Lab 6 (Generate a Submission Patch) in Chapter 37.
|
|
|
|
Part 7 has no successor part. What it does have is the practice that
|
|
follows the book: real hardware, real review cycles, real bugs, and
|
|
the long-running rhythm of staying current that Chapter 38 has
|
|
already named. The baseline the rest of your career assumes is
|
|
exactly what these chapters taught, a driver that is portable,
|
|
hardened, measured, debuggable, and submittable, written by an
|
|
author who knows when to reach for each tool and when to step away
|
|
from the keyboard. If the ideas above feel like habits rather than
|
|
lookups, the book's work is done. What remains is yours.
|
|
|
|
## Final Closing Words for the Book
|
|
|
|
This book began with a story about a chemistry student in Brazil
|
|
in 1995, who found FreeBSD in a university library and slowly,
|
|
over years, turned that curiosity into a career. That story was
|
|
not offered as a model to follow; it was offered as evidence that
|
|
curiosity is enough to start, even when the starting conditions
|
|
are difficult.
|
|
|
|
Your starting conditions, whatever they were, brought you to the
|
|
last pages of a technical book about an operating system that is
|
|
now more than thirty years old. The operating system is still
|
|
being developed, still being used in places that matter, and
|
|
still welcoming new contributors. The ability to write device
|
|
drivers for it is a skill that remains valuable and will continue
|
|
to be valuable for as long as the project continues. By finishing
|
|
this book, you have acquired that skill to a working level. What
|
|
you do with it from here is entirely yours to decide.
|
|
|
|
There is a specific hope I have for the readers of this book, and
|
|
I want to name it clearly. The hope is that at least some of you
|
|
will find, in the months after finishing, that the book unlocked
|
|
something you did not know was possible. That you will write a
|
|
driver for a device you care about, or fix a bug that has been
|
|
bothering you, or answer a question on a mailing list that helps
|
|
a stranger, or begin a conversation with the project that leads
|
|
somewhere you could not have anticipated. That the skills this
|
|
book has given you become the beginning of a longer relationship
|
|
with FreeBSD than the book's pages can contain.
|
|
|
|
The kernel is not magic. Over the course of this book, you have
|
|
come to see that more clearly. A kernel is software, written by
|
|
people, available for anyone to read, and modifiable by anyone
|
|
with the patience to understand it. The difference between a
|
|
reader who finds kernels mysterious and a reader who finds them
|
|
approachable is, in the end, whether they have actually sat down
|
|
and looked. You have looked. You have looked carefully, across
|
|
many chapters and many hours, and the mystery has receded.
|
|
|
|
That receding is permanent. You cannot un-know the shape of a
|
|
driver now. You cannot un-know what a softc is, or what a
|
|
`device_method_t` array does, or what the `_IOWR` macro means.
|
|
Those pieces of knowledge will be with you for the rest of your
|
|
career. They will help you read other systems, write other
|
|
software, and reason about problems that are nothing like
|
|
drivers. The investment you made in learning them has a return
|
|
that extends well beyond FreeBSD.
|
|
|
|
There is also something the book has tried to convey without
|
|
saying it directly. Systems engineering is a craft, and crafts
|
|
are learned in a particular way: through long practice with
|
|
specific materials, under the guidance of people who have done
|
|
the work before. Books are one part of that guidance, but they
|
|
are not the whole of it. The rest of the guidance comes from
|
|
source code read carefully, from bugs debugged patiently, from
|
|
mailing-list threads followed through to their conclusions, from
|
|
conference talks watched with attention, and from the slow
|
|
accumulation of intuitions that cannot be explicitly written
|
|
down. This book has pointed you toward that larger guidance. The
|
|
larger guidance is what will carry you forward from here.
|
|
|
|
If you choose to engage with FreeBSD after this book, you will
|
|
find a community that has been remarkably stable across decades
|
|
of technology change. The faces change, but the culture
|
|
persists: an emphasis on careful engineering, on clear
|
|
documentation, on long-term thinking, on the value of doing
|
|
things well rather than quickly. Joining that culture is a
|
|
privilege, and the culture welcomes newcomers who approach it
|
|
with respect for its traditions.
|
|
|
|
If you do not choose to engage further, that is also fine. Many
|
|
readers of this book will use what they learned for their own
|
|
purposes, inside their own companies or on their own hardware,
|
|
and never contribute publicly. Those readers have not wasted
|
|
their time. They have acquired a skill, and the skill is useful
|
|
in many contexts. The FreeBSD community is large enough to
|
|
welcome those who engage and patient enough to let others benefit
|
|
from the work without engaging. Both relationships are
|
|
legitimate, and the book has tried not to pressure you toward
|
|
either one.
|
|
|
|
A few last specific things deserve to be said.
|
|
|
|
If you submit a driver upstream, and it takes three rounds of
|
|
review to land, that is normal. Do not be discouraged. Most
|
|
first submissions go through several rounds, and the reviewers
|
|
are helping you rather than judging you. Patience is the
|
|
discipline that completes a submission; impatience is the
|
|
discipline that abandons one. You have both disciplines
|
|
available to you. Choose the first.
|
|
|
|
If you hit a bug you cannot figure out, and you have looked at
|
|
it for an hour without progress, stop. Step away. Come back in a
|
|
few hours or the next day. Fresh eyes see what tired eyes miss.
|
|
The kernel is patient. Your bug will still be there tomorrow, and
|
|
you will likely see its cause within the first few minutes of
|
|
the next session. This is one of the most consistent patterns in
|
|
debugging work, and it applies to kernel work as fully as to any
|
|
other kind.
|
|
|
|
If you get discouraged, and at some point you probably will,
|
|
remember why you started. Most people who finish a book like
|
|
this finished it because something about FreeBSD caught their
|
|
imagination. Return to that something. Reread the chapter that
|
|
excited you most, or return to the driver you wrote that worked
|
|
first, or watch a conference talk about a topic that made you
|
|
curious. The return to the source of excitement is how you
|
|
sustain a long career, and the sustenance matters more than the
|
|
speed.
|
|
|
|
If you teach someone else what you learned, your own
|
|
understanding will deepen in ways that solitary practice cannot
|
|
produce. The slower, less efficient-feeling work of explaining to
|
|
a newcomer what a device-method table does, or how `copyin`
|
|
protects the kernel from userland pointers, or why locking order
|
|
matters, is one of the most potent forms of learning there is.
|
|
If you ever have the chance to help a future reader through the
|
|
material you just worked through, take it. You will be doing
|
|
them a favour, but you will be doing yourself a larger one.
|
|
|
|
This book has been a long journey, and every long one
|
|
deserves a formal ending. Thank you for reading it. Thank you
|
|
for working through the labs, the challenges, and the
|
|
reflections. Thank you for caring enough about your own learning
|
|
to see the book through. Your time is the most limited resource
|
|
you have, and you spent a substantial portion of it on the
|
|
pages of this book. I hope the return on that investment is
|
|
large, and I hope you carry forward both the technical knowledge
|
|
and the habits of thought that the book tried to convey.
|
|
|
|
The FreeBSD kernel is not going anywhere. It will still be here
|
|
next year, and the year after, and ten years from now. It will
|
|
still have drivers that need writing, bugs that need fixing, and
|
|
documentation that needs updating. Whenever you are ready to
|
|
return to the kernel, whether that is tomorrow or a decade from
|
|
now, it will be waiting for you, and the community around it
|
|
will still welcome the careful, curious work that you have
|
|
learned to do.
|
|
|
|
Close the book now. Take a moment to notice that you have done
|
|
something substantial. Then, when you are ready, open a
|
|
terminal, type `cd /usr/src/sys/dev/`, and look around. You know
|
|
what you are looking at. You know how to read it. You know how
|
|
to change it. You know how to make it your own.
|
|
|
|
Good luck, and welcome to the community.
|
|
|
|
The kernel was never magic.
|
|
|
|
You just learned how to work with it.
|