8000 Add Qs / Assignments · kaiwan/Linux-Kernel-Programming@c6cdac5 · GitHub
[go: up one dir, main page]

Skip to content

Commit c6cdac5

Browse files
committed
Add Qs / Assignments
1 parent 3d3bb6b commit c6cdac5

14 files changed

+573
-0
lines changed
File renamed without changes.

questions/ch10_qs_assignments.txt

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
As we conclude, here is a list of questions for you to test your knowledge
2+
regarding this chapter's material. You will find answers to selected
3+
questions here:
4+
https://github.com/PacktPublishing/Linux-Kernel-Programming/tree/master/solutions_to_assgn
5+
6+
Chapter 10 : Questions and/or Assignments
7+
8+
1. The KSE on Linux is ________; this implies that the application developer
9+
can specify and control the scheduling policy and priority of each _______
10+
in an application!
11+
a. a thread, thread
12+
b. a process, process
13+
c. a process group, process group
14+
d. a user's processes, user
15+
16+
2. The Linux kernel supports __ (or more) scheduling policies; it is/they are
17+
__________ and the default is always _____.
18+
a. 1; SCHED_NORMAL; SCHED_NORMAL
19+
b. 3; SCHED_FIFO, SCHED_RR, and SCHED_OTHER (or SCHED_NORMAL); SCHED_OTHER
20+
c. 2; SCHED_FIFO and SCHED_RR; SCHED_FIFO
21+
d. None of the above
22+
23+
3. SCHED_FIFO and SCHED_RR are considered to be ________ policies, with
24+
_______ being the aggressive one.
25+
a. hard real-time; SCHED_RR
26+
b. hard real-time; SCHED_FIFO
27+
c. soft real-time; SCHED_FIFO
28+
d. soft real-time; SCHED_RR
29+
30+
4. The (soft) real-time priority range supported by mainline Linux is _____,
31+
with __ being the highest priority (with regard to user space).
32+
a. 0 to 99; 99
33+
b. 1 to 4; 4
34+
c. -20 to +20; 20
35+
d. 1 to 99; 99
36+
37+
5. A soft real-time task will run until ________.
38+
a. a higher-priority real-time task becomes runnable
39+
b. it is stopped or dies
40+
c. it gets blocked (sleeps) on a blocking call
41+
d. any of the preceding options occur
42+
43+
6. Modern Linux kernels use a "modular" scheduler where every process or
44+
thread will belong to exactly one scheduling _____. This implies that you
45+
can replace the default scheduling policies within the OS with your own
46+
kernel module for scheduling purposes (true or false?)
47+
a. class; True
48+
b. runqueue; True
49+
c. runqueue; False
50+
d. class; False
51+
52+
7. The CFS implementation has an important member within the kernel called
53+
vruntime; it represents the ________. Its units are ____.
54+
a. weighted cumulative amount of the time spent on the CPU by the task in
55+
this scheduling cycle; nanoseconds
56+
b. variable individual runtime spent on the CPU; milliseconds
57+
c. per-cycle amount of time spent on the CPU by the task; milliseconds
58+
d. total runtime accumulated by all tasks in the runqueue; seconds
59+
60+
8. On a modern Linux system with four CPU cores, there will be ___
61+
runqueue(s) for SMP scalability. How many waitqueues can it have?
62+
a. 1; 4
63+
b. 4; Any number
64+
c. 4; 1
65+
d. any number of; Any number
66+
67+
9. Consider a modern Linux system with one CPU core: user space process A,
68+
whose only code is while(1);. Thus, when it runs, no other process will
69+
ever get the CPU (true or false?) Why?
70+
a. True; Linux is a fair-share OS but the process is running while(1);.
71+
b. False; Linux is a user-mode preemptive OS. It will preempt A, allowing
72+
other tasks to run.
73+
74+
10. Consider a modern Linux system with one CPU core: a kernel thread K
75+
whose only code is while(1);. Thus, when it runs, no other process will
76+
ever get the CPU (true or false?) Why?
77+
a. False; >= 2.6 Linux can be configured to be kernel-preemptible. If
78+
so, it will preempt K, allowing other tasks to run.
79+
b. True; the kernel can never be preempted.
80+
81+
11. Find the bug(s) in the the following pseudo-code snippet:
82+
83+
if (!in_task()) { /* in interrupt ctx now */
84+
do_task_x();
85+
if (<no-data-available>) {
86+
schedule(); /* no data; block until it arrives */
87+
if (<data-now-available>)
88+
// ... do work ...
89+
90+
a. The "golden rule" is violated! You cannot call schedule()
91+
directly or indirectly in the process context.
92+
b. in_task(): No such function or macro exists.
93+
c. The "golden rule" is violated! You cannot call schedule()
94+
directly or indirectly in any kind of atomic or interrupt context.
95+
You cannot schedule in an atomic context!
96+
d. There's no bug; it's fine.
97+

questions/ch11_qs_assignments.txt

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
As we conclude, here is a list of questions for you to test your knowledge
2+
regarding this chapter's material. You will find answers to selected
3+
questions here:
4+
https://github.com/PacktPublishing/Linux-Kernel-Programming/tree/master/solutions_to_assgn
5+
6+
Chapter 11 : Questions and/or Assignments
7+
8+
1. A Linux CLI utility to query/set process or thread scheduling policy and
9+
priorities is ____; a CLI utility to query/set a process’s CPU affinity mask
10+
is ___.
11+
a. psprio, cpumask
12+
b. chrt, taskset
13+
c. psl, maskcpu
14+
d. Any of the above work
15+
16+
2. Consider a Linux system with 8 CPU cores (numbered from 0 to 7); on it, a
17+
process’s CPU affinity mask shows up as 0xed; this implies that the process
18+
is not allowed to execute on CPU cores _____.
19+
a. 0, 3, and 5
20+
b. 0,2,3,5,6, and 7
21+
c. 1 and 4
22+
d. 1,2,3,5,6, and 7
23+
24+
3. On modern Linux systems, resource bandwidth allocation is properly done
25+
by leveraging the kernel feature called _____.
26+
a. c-groups (CPU groups)
27+
b. Nice values
28+
c. CPU resource limits
29+
d. cgroups (control groups)
30+
31+
4. This feature (from Q 3) has a pseudo filesystem typically mounted at ______.
32+
a. /cgr/fs
33+
b. /sys/fs
34+
c. /proc/cgroup_cpu
35+
d. /sys/fs/cgroup
36+
37+
5. Vanilla or standard Linux is an OS that is ____.
38+
a. good on occasion
39+
b. only general-purpose (GPOS; no form of real time)
40+
c. hard real time (RTOS)
41+
d. general-purpose and can easily take on soft real-time workloads
42+
43+
6. By applying a patch, Linux can be run as a hard real-time OS (an RTOS):
44+
True/False: ___ ; if true, this effort is now called _______ and is a Linux
45+
Foundation project.
46+
a. True, Preempt-RT
47+
b. True, RTL (Real-Time Linux)
48+
c. False, <it’s not possible>
49+
d. True, HardLinux
50+
51+
7. Build the realtime Linux (RTL) kernel (as explained in the section
52+
'Converting mainline Linux into an RTOS'); boot from it and test using:
53+
a. the cyclictest app
54+
b. some of the [e]BPF frontends (as explained in the section 'Measuring
55+
scheduler latency via modern BPF tools').
56+

questions/ch12_qs_assignments.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
As we conclude, here is a list of questions for you to test your knowledge
2+
regarding this chapter's material. You will find answers to selected
3+
questions here:
4+
https://github.com/PacktPublishing/Linux-Kernel-Programming/tree/master/solutions_to_assgn
5+
6+
Chapter 12 : Questions and/or Assignments
7+
8+
1. miscdrv_rdwr_mutextrylock:
9+
10+
Modify the book's
11+
ch12/1_miscdrv_rdwr_mutexlock/miscdrv_rdwr_mutexlock.c
12+
device driver so that it uses the *trylock* variant of the mutex lock in
13+
the driver's write() method. If the lock is not acquired, perform some
14+
"work" – a hex dump of the driver "context" structure, perhaps ("busy-loop"
15+
over this).
16+
17+
2. (If you haven't already done so) Prepare a "debug" kernel (go back to
18+
Chapter 5, Writing Your First Kernel Module – LKMs Part 2, the
19+
'Configuring a "debug" kernel' section) and, as explained in the
20+
'Testing on a 5.4 "debug" kernel' section, run our
21+
ch12/2_miscdrv_rdwr_spinlock buggy driver test case on it (by setting
22+
the module parameter 'buggy' to 1).
23+

questions/ch13_qs_assignments.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
As we conclude, here is a list of questions for you to test your knowledge
2+
regarding this chapter's material. You will find answers to selected
3+
questions here:
4+
https://github.com/PacktPublishing/Linux-Kernel-Programming/tree/master/solutions_to_assgn
5+
6+
Chapter 13 : Questions and/or Assignments
7+
8+
1. miscdrv_rdwr_refcount
9+
Modify our earlier ch12/2_miscdrv_rdwr_spinlock/miscdrv_rdwr_spinlock.c
10+
driver code. It has the integers ga and gb, which, when being read or
11+
written, are protected via a spinlock.
12+
Now, make them refcount_t variables and use the appropriate refcount_t APIs
13+
when working on them. Test by deliberately making a refcount variable go out
14+
of the allowed range, [0..INT_MAX].
15+
16+
2. If you haven't already, configure and build a "debug" kernel (ensure you
17+
have the Lock Debugging config options enabled, as we explained in
18+
the 'Configuring a debug kernel for lock debugging' section of this chapter.)
19+
20+
Now, boot from it and try out a buggy kernel module (that has locking/deadlock
21+
bugs); lockdep should catch and report this.
22+

questions/ch1_qs_assignments.txt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
As we conclude, here is a list of questions for you to test your knowledge
2+
regarding this chapter's material. You will find answers to selected
3+
questions here:
4+
https://github.com/PacktPublishing/Linux-Kernel-Programming/tree/master/solutions_to_assgn
5+
6+
Chapter 1 : Questions and/or Assignments
7+
8+
1. VM is a common abbreviation used in virtualization technology for a
9+
"guest" system. What does it stand for?
10+
a) Virtual Monkey
11+
b) Virtual Mac
12+
c) Virtual Machine
13+
d) Very very Maddening
14+
15+
2. On Linux, can you name a directory *,hey,whatacoolname,huh? (yes or
16+
no)?
17+
18+
INFO:
19+
Hang on before you try it out! Why, you may ask? In general,
20+
should you not do so. (Okay, try it out now, but on a VM, and be
21+
careful!)
22+
23+
3. Let's say we are running on an x86-64 host system running Linux and have
24+
a 32-bit ARM "target" board (perhaps a Raspberry Pi 3). The job of a cross
25+
compiler is to do what?
26+
a) Compile code that's on the target system into an x86-64 binary
27+
executable that can run on the host system.
28+
b) Compile code that's on the host system into an ARM-32 binary
29+
executable that can run on the target system.
30+
c) Perform an entertaining console game on the target.
31+
d) None of the above.
32+
33+
4. With respect to the Linux man pages, answer the following questions:
34+
a) True or false: They are divided into nine sections.
35+
b) Which section represents system call APIs?
36+
c) Which section represents kernel APIs? How up to date is it?
37+

questions/ch2_qs_assignments.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
As we conclude, here is a list of questions for you to test your knowledge
2+
regarding this chapter's material. You will find answers to selected
3+
questions here:
4+
https://github.com/PacktPublishing/Linux-Kernel-Programming/tree/master/solutions_to_assgn
5+
6+
Chapter 2 : Questions and/or Assignments
7+
8+
1. (If you haven't already done so) follow this chapter's directions to do the
9+
following:
10+
a. Download the v5.4 Linux kernel source tree.
11+
b. Extract it.
12+
c. Configure the kernel (begin by using the localmodconfig approach,
13+
then tweak as required).
14+
d. Show the "delta" – the differences between the old (or original) and the
15+
new kernel config file (tip: use the diffconfig script to do so).
16+
17+
2. On the kernel code base, build support for both the ctags and cscope
18+
code browsing tools; use them in an interactive fashion
19+
(tip: using make help reveals the relevant targets for ctags/cscope.)
20+
21+
3. A bit more ambitious: clone Linus Torvalds's Git tree and configure it.
22+

questions/ch3_qs_assignments.txt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
As we conclude, here is a list of questions for you to test your knowledge
2+
regarding this chapter's material. You will find answers to selected
3+
questions here:
4+
https://github.com/PacktPublishing/Linux-Kernel-Programming/tree/master/solutions_to_assgn
5+
6+
Chapter 3 : Questions and/or Assignments
7+
8+
1. If you haven't already done so, follow this chapter's directions (and the
9+
previous chapter as required) to build the kernel from source on your guest
10+
Linux VM, installing the kernel modules and setting up the initramfs (or
11+
initrd) image and GRUB bootloader to boot into it as well. Do verify that
12+
it actually works!
13+
14+
2. Make a copy and extract the content of your x86_64 initramfs image to a
15+
temporary directory and check out its content (using the tree(1) utility,
16+
perhaps).
17+
18+
3. On your Ubuntu guest VM, using the GRUB menu, boot into your new kernel
19+
in single-user mode (and then change the root password).
20+
21+
4. (A bit advanced, for when you're feeling adventurous!) Refer ahead
22+
to Chapter 5, Writing Your First Kernel Module – LKMs Part 2, in
23+
the Configuring a debug kernel section. It details the kernel config options to
24+
be minimally set up for a very useful thing indeed – a debug kernel!
25+
26+
Running your code on a debug kernel can help you uncover hard-to-spot
27+
bugs and issues. Your job here is to configure another kernel with these
28+
debug options, then build and run it.
29+

questions/ch4_qs_assignments.txt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
As we conclude, here is a list of questions for you to test your knowledge
2+
regarding this chapter's material. You will find answers to selected
3+
questions here:
4+
https://github.com/PacktPublishing/Linux-Kernel-Programming/tree/master/solutions_to_assgn
5+
6+
Chapter 4 : Questions and/or Assignments
7+
8+
1. Does the Linux kernel follow the monolithic or microkernel architecture?
9+
10+
2. Name a few of the subsystems within the kernel.
11+
12+
3. Would you architect a device driver as a separate kernel module or build it
13+
into the kernel itself, and why?
14+
15+
4. Can a kernel module be used to create a new CPU scheduler on Linux?
16+
17+
5. (a) Spot the error in the following line of code:
18+
printk(KERN_CRIT, "Goodbye, world, am burning up...\n");
19+
(b) What's the fix?
20+
21+
6. How does the kernel build system know the location of the kernel headers?
22+
23+
7. (a) Spot the errors in the following lines of code:
24+
static int __init wow_an_lkm_init(void *msg)
25+
{
26+
pr_inform("Am intializing...[%d]\n");
27+
}
28+
(b) What're the fixes?
29+
30+
8. Why don't insmod or rmmod work unless we run with root privileges?
31+
32+
9. Is there an alternate way to use the insmod or rmmod kernel modules (that
33+
is, without root)?
34+
35+
10. Running in the Linux graphical environment, we don't see the output
36+
of printk but can see the output of printf; how come? Where has the
37+
printk output gone?
38+
39+
11. How can we guarantee seeing printk output on the console device?
40+

questions/ch5_qs_assignments.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
As we conclude, here is a list of questions for you to test your knowledge
2+
regarding this chapter's material. You will find answers to selected
3+
questions here:
4+
https://github.com/PacktPublishing/Linux-Kernel-Programming/tree/master/solutions_to_assgn
5+
6+
Chapter 5 : Questions and/or Assignments
7+
8+
Assignment 5.1: libtest
9+
Write a kernel module called mycaller.c. It must invoke a library routine
10+
called product that lives within another C file (mylib.c), whose signature
11+
is:
12+
int product(int a, int b);
13+
and will return the value (a*b).
14+

questions/ch6_qs_assignments.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
As we conclude, here is a list of questions for you to test your knowledge
2+
regarding this chapter's material. You will find answers to selected
3+
questions here:
4+
https://github.com/PacktPublishing/Linux-Kernel-Programming/tree/master/solutions_to_assgn
5+
6+
Chapter 6 : Questions and/or Assignments
7+
8+
1. Consider the following system scenario: there are a total of 125 processes,
9+
and 164 threads alive, of which 79 are kernel threads. Given this snapshot:
10+
1. How many task structures will there be in the kernel memory?
11+
2. How many user space stacks will there be in the user memory?
12+
3. How many kernel-mode stacks will there be in the kernel
13+
memory?
14+
15+
2. Looking up user-mode VAS details: take a user-mode C application (even just
16+
a Hello, world program would suffice; if it's such a simple app, insert a
17+
pause(2) system call so that it remains alive); build it, run it and peek into
18+
its user VAS using the following means:
19+
1. The 'raw' view, via /proc/PID/maps
20+
2. Via the pmap(1) utility; try out various option switches
21+
including -X and -XX
22+
3. Via the procmap utility (https://github.com/kaiwan/procmap) (this utility
23+
is pretty powerful; by default, it will show you both the kernel and user
24+
space process VASes; you can ignore the kernel VAS for now, as coverage of
25+
that is a key part of the next chapter!).
26+
27+
3. taskdtl:
28+
Write a kernel module (named taskdtl) that, given a PID as a parameter
29+
(validate it!), prints as many details as possible regarding the given
30+
task.
31+
Tip: Take a look at this screenshot
32+
https://github.com/kaiwan/L2_kernel_trg/blob/master/taskdtl/taskdtl.png
33+
showing some sample output; try and imitate it.
34+

0 commit comments

Comments
 (0)
0