slides: https://zarak.fr/resources/ANSY.pdf
Linux kernel mailing lists: https://lkml.org/
Linux sources: https://elixir.bootlin.com/linux/v6.11.1/source
The submissions will be done by email at ansy@zarak.fr, tag [ANSY]
.
You can submit each part individually.
There is no restriction on the language used or the submission architecture, but please make it clear, and readable. The easier it is for me to correct you, the more likely I will be to fully appreaciate your work.
Recommended languages however includes:
I will also accept "normal" languages for the kind of tasks I'm asking you to do, but I reserve myself the right of refusing a submission if it's an obvious troll like brainfuck or ook!.
Please send files like:
TP<number>-<login>.zip
└── TP<number>-<login>/
├── README
└── ...
I'd need everybody to follow these simple instructions to avoid making me loose time reshaping your submitted files, thanks !
If you have any question, or if you're stuck, please reach out to me !
Please track the time you're spending on each part and provide the information in the submission's README. This will allow me to better estimate the workload of those subjets and possibly adapt it for next year
Elle devra contenir :
La date max de rendu est fixée au début du cours n°2
Je vous demanderai aussi de conserver votre bash history (ou zsh history ou équivalent) pour me montrer les commandes et la réflexion que vous avez pu avoir pour ce TP
Le binaire à analyser est disponible sur https://zarak.fr/resources/straceme
Je vous demande de n'utiliser que strace pour l'analyse et pour le comprendre.
Vous pouvez modifier l'environment d'execution du binaire, ou bien (et surtout) modifier le comportement des syscalls avec strace -e
. Prenez le temps de regarder la man page, de lire un peu les exemples et de voir les possibilités.
For this part, we're going to mess up with the scheduler a bit.
For the moment, let's keep the changes simple, we'll focus on bringing our own linux kernel alive, to explore the linux toolchain and build process.
For this subject, you need to have a Debian 12 VM (this is the recommended way, as I'm going to guide you with such setup. You may do this subject with another setup, but it might be harder for you, and I may not be able to debug you).
You can install a debian 12 VM with virtualbox or libvirt. If you're running AMD64, you can download it here : https://cloud.debian.org/images/release/current-live/amd64/iso-hybrid/ (debian-live-12.7.0-amd64-standard.iso)
Install the VM, install a few tools you might find useful, like vim or a ssh server.
You can follow guides like this: https://phoenixnap.com/kb/build-linux-kernel
But here are the things needed for this subject:
$ sudo apt-get install -y git fakeroot build-essential ncurses-dev xz-utils libssl-dev bc flex libelf-dev bison dwarves
$ uname -a
Linux ANSY 6.1.0-12-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.52-1 (2023-09-07) x86_64 GNU/Linux
$ echo Our current kernel is in version 6.1.0. Let's download the Linux source for this version
$ git clone https://github.com/torvalds/linux.git -b v6.1 --depth 1
$ cd linux
$ echo generate your own base kernel config with `make defconfig`
$ make defconfig
$ echo maybe you will need or want to change the configuration. Either edit the .config file newly created, or run make menuconfig
$ echo you can also copy your current linux config, but compilation will take more time
$ #cp /boot/config-6.1.0-12-amd64 .config
You are now ready to compile linux. Simply run make -j$(nproc)
to build the kernel.
You will also need the compressed version. You can get it with make bzImage -j$(nproc)
. You can actually use exclusively this one to compile and build.
The kernel you just built may be slightly incorrect, and report itself as 6.1.0-dirty
(uname(2)
). This is because you have built from a git repository with dirty changes – non committed changed. To make your new kernel compatible, we'll add another build option:
$ uname -a
Linux ANSY 6.1.0-12-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.52-1 (2023-09-07) x86_64 GNU/Linux
My current kernel reports itself as 6.1.0-12-amd64. I'll force the kernel I'm building to report to this as well:
$ touch .scmversion && make bzImage -j$(nproc) LOCALVERSION="-12-amd64"
The first build will take quite some time. You may need some amounts of RAM and CPU. Be patient.
You should have in the end something like this in the output:
BUILD arch/x86/boot/bzImage
Kernel: arch/x86/boot/bzImage is ready (#3)
You need to copy your newly built kernel in /boot:
$ cp arch/x86/boot/bzImage /boot/vmlinuz-custom
You don't want to replace the real kernel debian-provided youre currently using, as your newly built kernel may be broken. Instead, we're going to add an option in grub, when booting, to choose to boot from this kernel.
Edit the file /boot/grub/grub.cfg
Find the default menu entry. Mine looks like this:
menuentry 'Debian GNU/Linux' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-e06573ef-48b6-4890-b5c6-622eedf914b0' {
load_video
insmod gzio
if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
insmod part_msdos
insmod ext2
search --no-floppy --fs-uuid --set=root e06573ef-48b6-4890-b5c6-622eedf914b0
echo 'Loading Linux 6.1.0-12-amd64 ...'
linux /boot/vmlinuz-6.1.0-12-amd64 root=UUID=e06573ef-48b6-4890-b5c6-622eedf914b0 ro quiet
echo 'Loading initial ramdisk ...'
initrd /boot/initrd.img-6.1.0-12-amd64
}
Copy your own menu entry (not mine ! it will not work) to have a second one right under the default with a few differences:
1c1
< menuentry 'Debian GNU/Linux' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-e06573ef-48b6-4890-b5c6-622eedf914b0' {
---
> menuentry 'Debian GNU/Linux with custom kernel' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-e06573ef-48b6-4890-b5c6-622eedf914b0' {
9c9
< linux /boot/vmlinuz-6.1.0-12-amd64 root=UUID=e06573ef-48b6-4890-b5c6-622eedf914b0 ro quiet
---
> linux /boot/vmlinuz-custom root=UUID=e06573ef-48b6-4890-b5c6-622eedf914b0 ro quiet
Change the name of the entry to show which one is yours and which one is the default one. Change the linux argument path to your own kernel.
Now, on reboot of the VM you should see a new entry in your grub menu to boot from your own kernel
You will have to write a patch for linux. We're going to add a new behavior to the scheduler. We've been wondering in class how many times the scheduler was waken up to make a decision, to schedule.
Let's make our kernel expose this information. We're not going to do anything fancy yet as this is not the point of the exercise.
Hints:
printk
ktime_to_ns(ktime_get())
You will provide a .patch
that contains the patch you've just written (i.e. the git diffs)
You will also provide a README with information you deem interesting to mention, but with at least:
- the amount of time spent on this
- an output of dmesg to show your scheduler logs
The deadline is for the 27th of october, 23h59.
Write a program than can creates situations to prove how the niceness of 2 different processes interferes within each other.
The idea is to be able to provide an answer for such problem:
I have process A with a niceness of X. I have process B with a niceness of Y.
Both processes are started at the same time, and require the same amount of CPU in total. But they're fightining each other for said CPU. How much more real time A (or B) will need compared to the amount of time it needed if it were to run alone ?
Answer can be summed up in an array like:
Niceness of A (X) | Niceness of B (Y) | Extra time needed for A | Extra time needed for B |
---|---|---|---|
0 | 10 | 0% (as fast as if it was alone) | 100% (needed twice more time) |
0 | 0 | 50% | 50% |
Of course those values are example.
Create a program that takes as an input X and Y (argv), runs two processes in parallel with given niceness, measure how much time it needed to execute the two and output the % of extra time needed in comparison of a single execution.
This challenge is a bonus, it's quite difficult and may take quite some time to achieve. Don't feel forced to do it if you don't have the time.
Create a program that can create a very high cpu load – let's say twice the amount of cores – without using the CPU (CPU usage % shall remain below ~10%).
The deadline is set to the 5th of december, 23h59.
As usual, the submission will be done by email, with a .zip described above.
I'm expecting a README with the amount of time spent, an array providing answer for (X=0,Y=0),(X=0,Y=10),(X=0,Y=15), and ofc the program(s)
This subject is a bonus, either to help you boost your grade if you believe you did not perform well on other subjects, or to help compensate a missing submission.
The deadline for this exercise will be the 18th of January 23:59.
The point of this exercise will be to write a small program/script to manipulate block devices, kernel modules related to block devices, filesystems and famous userland tools.
The suggested language is bash.
You will have to create a few scenarios and run benchmark to test them out.
The benchmark will be run with fio
: fio --name=random-write --rw=randwrite --bs=4k --numjobs=1 --size=1g --iodepth=256 --runtime=60 --time_based --end_fsync=1
As you can read, you'll need a GiB of free space to run this test. It is therefore recommended to create each situation with 5 GiB to begin with, to be sure to have enough room in the end.
The core of your program will:
-f --show
--path
(defaults to /mnt/final
if not specified)--bench
, run a benchmark on the final filesystemHere are a list of flags your program can take and that will apply transformation to the block device at the step 3:
--loop
will take a number X as argument (default: 0) and will repeat the core of the program X times, meaning repeating steps 1 to 4 included, and step 5 with a path of /mnt/loop-$i
.
/mnt/final
--loop 0
(the default), one has one /mnt/final
--loop 1
, one has /mnt/loop-1
for the first iteration of the core loop, and /mnt/final
for the last iteration--basic-lvm
will create a LVM PV, VG and single LV taking all the space possible of the block device.
--crypt
will create a LUKS2 encrypted block device with cryptsetup. The password will be very secure of course, as it's going to be password
--dm-linear
will create a block device from your whole block device in a linear way
--dm-delay
will perform as --dm-linear
, but will add a delay of 1000 ms
--md
will create 2 block devices from your block device (split it in half with dmsetup
's linear option), and then a RAID 1 disk from the two block devices
Each transformation shall take as an input 1 block device, and provide as an output 1 block device. They can be chained this way.
It is recommended to start simple. Create the core
part of the program, and test it well.
Add a --cleanup
flag to not do anything but remove what your program has created, this will help you a lot
Gradually add the transformations support. They may seems complex, but each one taken individually is actually fairly straight forward with the appropriate documentation
Reach me for help if things are unclear, or not working as expected.
You can use argbash.dev to simplify development if you choose bash