mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
your inits are belongz to uz
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -9,3 +9,4 @@
|
|||||||
/rootfs_overlay/etc/init.d/S99
|
/rootfs_overlay/etc/init.d/S99
|
||||||
Module.symvers
|
Module.symvers
|
||||||
modules.order
|
modules.order
|
||||||
|
trace*
|
||||||
|
|||||||
39
README.md
39
README.md
@@ -258,6 +258,18 @@ and they will be run automatically before the login prompt.
|
|||||||
|
|
||||||
For convenience, we also setup a symlink from `S99` to `rootfs_overlay/etc/init.d/S99`.
|
For convenience, we also setup a symlink from `S99` to `rootfs_overlay/etc/init.d/S99`.
|
||||||
|
|
||||||
|
### Custom init
|
||||||
|
|
||||||
|
Is the default BusyBox `/init` too bloated for you, minimalism freak?
|
||||||
|
|
||||||
|
No problem, just use the `init` kernel boot parameter:
|
||||||
|
|
||||||
|
./runqemu -e 'init=/init_hello.out'
|
||||||
|
|
||||||
|
Remember that shell scripts can also be used for `init`:
|
||||||
|
|
||||||
|
./runqemu -e 'init=/init.sh'
|
||||||
|
|
||||||
## Debugging
|
## Debugging
|
||||||
|
|
||||||
To GDB the Linux kernel, first run:
|
To GDB the Linux kernel, first run:
|
||||||
@@ -562,7 +574,7 @@ says:
|
|||||||
|
|
||||||
(EE) Failed to load module "modesetting" (module does not exist, 0)
|
(EE) Failed to load module "modesetting" (module does not exist, 0)
|
||||||
|
|
||||||
## Count instructions
|
## Count boot instructions
|
||||||
|
|
||||||
- <https://www.quora.com/How-many-instructions-does-a-typical-Linux-kernel-boot-take>
|
- <https://www.quora.com/How-many-instructions-does-a-typical-Linux-kernel-boot-take>
|
||||||
- <https://github.com/cirosantilli/chat/issues/31>
|
- <https://github.com/cirosantilli/chat/issues/31>
|
||||||
@@ -570,17 +582,21 @@ says:
|
|||||||
- `qemu/docs/tracing.txt` and `qemu/docs/replay.txt`
|
- `qemu/docs/tracing.txt` and `qemu/docs/replay.txt`
|
||||||
- <https://stackoverflow.com/questions/39149446/how-to-use-qemus-simple-trace-backend/46497873#46497873>
|
- <https://stackoverflow.com/questions/39149446/how-to-use-qemus-simple-trace-backend/46497873#46497873>
|
||||||
|
|
||||||
Naive attempt: add to `S99`:
|
Best attempt so far:
|
||||||
|
|
||||||
poweroff
|
time ./runqemu -n -e 'init=/init_poweroff.out' -- -trace exec_tb,file=trace && \
|
||||||
|
time ./qemu/scripts/simpletrace.py qemu/trace-events trace >trace.txt && \
|
||||||
|
wc -l trace.txt
|
||||||
|
|
||||||
Then run as:
|
Parameter notes:
|
||||||
|
|
||||||
time ./runqemu -n -- -trace exec_tb,file=trace
|
- `-n` is a good idea to reduce the chances that you send unwanted non-deterministic mouse or keyboard clicks to the VM.
|
||||||
./qemu/scripts/simpletrace.py qemu/trace-events trace >trace.txt
|
|
||||||
wc -l trace
|
|
||||||
|
|
||||||
This requires:
|
- `-e 'init=/init_poweroff.out'` is crucial as it reduces the instruction count from 40 million to 20 million, so most instructions were actually running on the VM.
|
||||||
|
|
||||||
|
Without it, the bulk of the time seems to be spent in setting up the network with `ifup` that gets called from `/etc/init.d/S40network` from the default Buildroot BusyBox setup.
|
||||||
|
|
||||||
|
This works because we have already done the following with QEMU:
|
||||||
|
|
||||||
- `./configure --enable-trace-backends=simple`. This logs in a binary format to the trace file.
|
- `./configure --enable-trace-backends=simple`. This logs in a binary format to the trace file.
|
||||||
|
|
||||||
@@ -588,13 +604,14 @@ This requires:
|
|||||||
|
|
||||||
This also alters the actual execution, and reduces the instruction count by 10M TODO understand exactly why, possibly due to the `All QSes seen` thing.
|
This also alters the actual execution, and reduces the instruction count by 10M TODO understand exactly why, possibly due to the `All QSes seen` thing.
|
||||||
|
|
||||||
- the simple QEMU patch mentioned at: <https://rwmj.wordpress.com/2016/03/17/tracing-qemu-guest-execution/>
|
- the simple QEMU patch mentioned at: <https://rwmj.wordpress.com/2016/03/17/tracing-qemu-guest-execution/> of removing the `disable` from `exec_tb` in the `trace-events` template file in the QEMU source
|
||||||
|
|
||||||
Possible improvements:
|
Possible improvements:
|
||||||
|
|
||||||
- replace init with our own C program that immediately does a `shutdown` system call
|
- to disable networking. Is replacing `init` enough?
|
||||||
|
|
||||||
- disable networking. Is replacing `init` enough?
|
- <https://superuser.com/questions/181254/how-do-you-boot-linux-with-networking-disabled>
|
||||||
|
- <https://superuser.com/questions/684005/how-does-one-permanently-disable-gnu-linux-networking/1255015#1255015>
|
||||||
|
|
||||||
- logging with the default backend `log` greatly slows down the CPU, and in particular leads to this during kernel boot:
|
- logging with the default backend `log` greatly slows down the CPU, and in particular leads to this during kernel boot:
|
||||||
|
|
||||||
|
|||||||
@@ -11,9 +11,11 @@ These programs can also be compiled and used on host.
|
|||||||
1. Standalone
|
1. Standalone
|
||||||
1. [myinsmod](myinsmod.c)
|
1. [myinsmod](myinsmod.c)
|
||||||
1. [myrmmod](myrmmod.c)
|
1. [myrmmod](myrmmod.c)
|
||||||
1. [init_hello](init_hello.c)
|
|
||||||
1. [usermem](usermem.c)
|
1. [usermem](usermem.c)
|
||||||
1. [pagemap_dump](pagemap_dump.c)
|
1. [pagemap_dump](pagemap_dump.c)
|
||||||
|
1. inits
|
||||||
|
1. [init_hello](init_hello.c)
|
||||||
|
1. [init_poweroff](init_poweroff.c)
|
||||||
1. [uio_read](uio_read.c)
|
1. [uio_read](uio_read.c)
|
||||||
1. Module tests
|
1. Module tests
|
||||||
1. [anonymous_inode](anonymous_inode.c)
|
1. [anonymous_inode](anonymous_inode.c)
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
puts("hello world");
|
puts(__FILE__);
|
||||||
while (1)
|
while (1)
|
||||||
sleep(0xFFFFFFFF);
|
sleep(0xFFFFFFFF);
|
||||||
}
|
}
|
||||||
|
|||||||
11
kernel_module/user/init_poweroff.c
Normal file
11
kernel_module/user/init_poweroff.c
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
/* Userspace is for the weak. Die.
|
||||||
|
* https://stackoverflow.com/questions/28812514/how-to-shutdown-linux-using-c-or-qt-without-call-to-system */
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/reboot.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
puts(__FILE__);
|
||||||
|
reboot(RB_POWER_OFF);
|
||||||
|
}
|
||||||
@@ -7,6 +7,6 @@ We use it to for things like:
|
|||||||
- customized configuration files
|
- customized configuration files
|
||||||
- userland module test scripts
|
- userland module test scripts
|
||||||
|
|
||||||
Most tests correspond clearly to a given kernel module, but the following ones don't, e.g. they correspond to mainline tree features:
|
Most tests correspond clearly to a given kernel module, but the following ones don't:
|
||||||
|
|
||||||
- [gpio](gpio.sh)
|
- [gpio](gpio.sh)
|
||||||
|
|||||||
7
rootfs_overlay/init.sh
Executable file
7
rootfs_overlay/init.sh
Executable file
@@ -0,0 +1,7 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# Can init be a sh script? Yes.
|
||||||
|
# Sure, why not: https://unix.stackexchange.com/questions/174062/init-as-a-shell-script/395375#395375
|
||||||
|
echo 'hello init.sh'
|
||||||
|
while true; do
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
Reference in New Issue
Block a user