diff --git a/README.adoc b/README.adoc index 7b0b27f..a3547fe 100644 --- a/README.adoc +++ b/README.adoc @@ -54,45 +54,45 @@ which are `printk` messages from `init` and `cleanup` methods of those modules. Once you use <> and <>, your terminal will look a bit like this: .... -[ 1.451857] input: AT Translated Set 2 keyboard as /devices/platform/i8042/s1│loading @0xffffffffc0000000: ../kernel_module-1.0//timer.ko -[ 1.454310] ledtrig-cpu: registered to indicate activity on CPUs │(gdb) b lkmc_timer_callback +[ 1.451857] input: AT Translated Set 2 keyboard as /devices/platform/i8042/s1│loading @0xffffffffc0000000: ../kernel_module-1.0//timer.ko +[ 1.454310] ledtrig-cpu: registered to indicate activity on CPUs │(gdb) b lkmc_timer_callback [ 1.455621] usbcore: registered new interface driver usbhid │Breakpoint 1 at 0xffffffffc0000000: file /home/ciro/bak/git/linux-kernel-module -[ 1.455811] usbhid: USB HID core driver │-cheat/out/x86_64/buildroot/build/kernel_module-1.0/./timer.c, line 28. -[ 1.462044] NET: Registered protocol family 10 │(gdb) c -[ 1.467911] Segment Routing with IPv6 │Continuing. +[ 1.455811] usbhid: USB HID core driver │-cheat/out/x86_64/buildroot/build/kernel_module-1.0/./timer.c, line 28. +[ 1.462044] NET: Registered protocol family 10 │(gdb) c +[ 1.467911] Segment Routing with IPv6 │Continuing. [ 1.468407] sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver │ -[ 1.470859] NET: Registered protocol family 17 │Breakpoint 1, lkmc_timer_callback (data=0xffffffffc0002000 ) +[ 1.470859] NET: Registered protocol family 17 │Breakpoint 1, lkmc_timer_callback (data=0xffffffffc0002000 ) [ 1.472017] 9pnet: Installing 9P2000 support │ at /home/ciro/bak/git/linux-kernel-module-cheat/out/x86_64/buildroot/build/ -[ 1.475461] sched_clock: Marking stable (1473574872, 0)->(1554017593, -80442)│kernel_module-1.0/./timer.c:28 -[ 1.479419] ALSA device list: │28 { -[ 1.479567] No soundcards found. │(gdb) c -[ 1.619187] ata2.00: ATAPI: QEMU DVD-ROM, 2.5+, max UDMA/100 │Continuing. +[ 1.475461] sched_clock: Marking stable (1473574872, 0)->(1554017593, -80442)│kernel_module-1.0/./timer.c:28 +[ 1.479419] ALSA device list: │28 { +[ 1.479567] No soundcards found. │(gdb) c +[ 1.619187] ata2.00: ATAPI: QEMU DVD-ROM, 2.5+, max UDMA/100 │Continuing. [ 1.622954] ata2.00: configured for MWDMA2 │ -[ 1.644048] scsi 1:0:0:0: CD-ROM QEMU QEMU DVD-ROM 2.5+ P5│Breakpoint 1, lkmc_timer_callback (data=0xffffffffc0002000 ) +[ 1.644048] scsi 1:0:0:0: CD-ROM QEMU QEMU DVD-ROM 2.5+ P5│Breakpoint 1, lkmc_timer_callback (data=0xffffffffc0002000 ) [ 1.741966] tsc: Refined TSC clocksource calibration: 2904.010 MHz │ at /home/ciro/bak/git/linux-kernel-module-cheat/out/x86_64/buildroot/build/ -[ 1.742796] clocksource: tsc: mask: 0xffffffffffffffff max_cycles: 0x29dc0f4s│kernel_module-1.0/./timer.c:28 -[ 1.743648] clocksource: Switched to clocksource tsc │28 { -[ 2.072945] input: ImExPS/2 Generic Explorer Mouse as /devices/platform/i8043│(gdb) bt -[ 2.078641] EXT4-fs (vda): couldn't mount as ext3 due to feature incompatibis│#0 lkmc_timer_callback (data=0xffffffffc0002000 ) +[ 1.742796] clocksource: tsc: mask: 0xffffffffffffffff max_cycles: 0x29dc0f4s│kernel_module-1.0/./timer.c:28 +[ 1.743648] clocksource: Switched to clocksource tsc │28 { +[ 2.072945] input: ImExPS/2 Generic Explorer Mouse as /devices/platform/i8043│(gdb) bt +[ 2.078641] EXT4-fs (vda): couldn't mount as ext3 due to feature incompatibis│#0 lkmc_timer_callback (data=0xffffffffc0002000 ) [ 2.080350] EXT4-fs (vda): mounting ext2 file system using the ext4 subsystem│ at /home/ciro/bak/git/linux-kernel-module-cheat/out/x86_64/buildroot/build/ -[ 2.088978] EXT4-fs (vda): mounted filesystem without journal. Opts: (null) │kernel_module-1.0/./timer.c:28 -[ 2.089872] VFS: Mounted root (ext2 filesystem) readonly on device 254:0. │#1 0xffffffff810ab494 in call_timer_fn (timer=0xffffffffc0002000 , -[ 2.097168] devtmpfs: mounted │ fn=0xffffffffc0000000 ) at kernel/time/timer.c:1326 -[ 2.126472] Freeing unused kernel memory: 1264K │#2 0xffffffff810ab71f in expire_timers (head=, -[ 2.126706] Write protecting the kernel read-only data: 16384k │ base=) at kernel/time/timer.c:1363 -[ 2.129388] Freeing unused kernel memory: 2024K │#3 __run_timers (base=) at kernel/time/timer.c:1666 -[ 2.139370] Freeing unused kernel memory: 1284K │#4 run_timer_softirq (h=) at kernel/time/timer.c:1692 -[ 2.246231] EXT4-fs (vda): warning: mounting unchecked fs, running e2fsck isd│#5 0xffffffff81a000cc in __do_softirq () at kernel/softirq.c:285 -[ 2.259574] EXT4-fs (vda): re-mounted. Opts: block_validity,barrier,user_xatr│#6 0xffffffff810577cc in invoke_softirq () at kernel/softirq.c:365 -hello S98 │#7 irq_exit () at kernel/softirq.c:405 - │#8 0xffffffff818021ba in exiting_irq () at ./arch/x86/include/asm/apic.h:541 -Apr 15 23:59:23 login[49]: root login on 'console' │#9 smp_apic_timer_interrupt (regs=) -hello /root/.profile │ at arch/x86/kernel/apic/apic.c:1052 -# insmod /timer.ko │#10 0xffffffff8180190f in apic_timer_interrupt () -[ 6.791945] timer: loading out-of-tree module taints kernel. │ at arch/x86/entry/entry_64.S:857 -# [ 7.821621] 4294894248 │#11 0xffffffff82003df8 in init_thread_union () -[ 8.851385] 4294894504 │#12 0x0000000000000000 in ?? () - │(gdb) +[ 2.088978] EXT4-fs (vda): mounted filesystem without journal. Opts: (null) │kernel_module-1.0/./timer.c:28 +[ 2.089872] VFS: Mounted root (ext2 filesystem) readonly on device 254:0. │#1 0xffffffff810ab494 in call_timer_fn (timer=0xffffffffc0002000 , +[ 2.097168] devtmpfs: mounted │ fn=0xffffffffc0000000 ) at kernel/time/timer.c:1326 +[ 2.126472] Freeing unused kernel memory: 1264K │#2 0xffffffff810ab71f in expire_timers (head=, +[ 2.126706] Write protecting the kernel read-only data: 16384k │ base=) at kernel/time/timer.c:1363 +[ 2.129388] Freeing unused kernel memory: 2024K │#3 __run_timers (base=) at kernel/time/timer.c:1666 +[ 2.139370] Freeing unused kernel memory: 1284K │#4 run_timer_softirq (h=) at kernel/time/timer.c:1692 +[ 2.246231] EXT4-fs (vda): warning: mounting unchecked fs, running e2fsck isd│#5 0xffffffff81a000cc in __do_softirq () at kernel/softirq.c:285 +[ 2.259574] EXT4-fs (vda): re-mounted. Opts: block_validity,barrier,user_xatr│#6 0xffffffff810577cc in invoke_softirq () at kernel/softirq.c:365 +hello S98 │#7 irq_exit () at kernel/softirq.c:405 + │#8 0xffffffff818021ba in exiting_irq () at ./arch/x86/include/asm/apic.h:541 +Apr 15 23:59:23 login[49]: root login on 'console' │#9 smp_apic_timer_interrupt (regs=) +hello /root/.profile │ at arch/x86/kernel/apic/apic.c:1052 +# insmod /timer.ko │#10 0xffffffff8180190f in apic_timer_interrupt () +[ 6.791945] timer: loading out-of-tree module taints kernel. │ at arch/x86/entry/entry_64.S:857 +# [ 7.821621] 4294894248 │#11 0xffffffff82003df8 in init_thread_union () +[ 8.851385] 4294894504 │#12 0x0000000000000000 in ?? () + │(gdb) .... All available modules can be found in the link:kernel_module/[`kernel_module` directory]. @@ -425,6 +425,18 @@ Not all packages have an alias, when they don't, just use the form: ./build -- -reconfigure .... +==== Rebuild a package with different build options + +For example, if you decide to <> after an initial build is finished, you must first clean the build before rebuilding: + +.... +./build -B 'BR2_OPTIMIZE_3=y' kernel_module-dirclean kernel_module-reconfigure +.... + +as explained at: https://buildroot.org/downloads/manual/manual.html#rebuild-pkg + +The clean is necessary because the source files didn't change, so `make` would just check the timestamps and not build anything. + [[retype]] === Don't retype arguments all the time @@ -2447,7 +2459,7 @@ TODO: why does this produce no output? .... >>> kernel_module 1.0 Building /usr/bin/make -j8 -C '/home/ciro/bak/git/linux-kernel-module-cheat/out/aarch64/buildroot/build/kernel_module-1.0/user' BR2_PACKAGE_OPENBLAS="" CC="/home/ciro/bak/git/linux-kernel-module-cheat/out/aarch64/buildroot/host/bin/aarch64-buildroot-linux-uclibc-gcc" LD="/home/ciro/bak/git/linux-kernel-module-cheat/out/aarch64/buildroot/host/bin/aarch64-buildroot-linux-uclibc-ld" -/home/ciro/bak/git/linux-kernel-module-cheat/out/aarch64/buildroot/host/bin/aarch64-buildroot-linux-uclibc-gcc -ggdb3 -fopenmp -O0 -std=c99 -Wall -Werror -Wextra -o 'proc_events.out' 'proc_events.c' +/home/ciro/bak/git/linux-kernel-module-cheat/out/aarch64/buildroot/host/bin/aarch64-buildroot-linux-uclibc-gcc -ggdb3 -fopenmp -O0 -std=c99 -Wall -Werror -Wextra -o 'proc_events.out' 'proc_events.c' In file included from /home/ciro/bak/git/linux-kernel-module-cheat/out/aarch64/buildroot/host/aarch64-buildroot-linux-uclibc/sysroot/usr/include/signal.h:329:0, from proc_events.c:12: /home/ciro/bak/git/linux-kernel-module-cheat/out/aarch64/buildroot/host/aarch64-buildroot-linux-uclibc/sysroot/usr/include/sys/ucontext.h:50:16: error: field ‘uc_mcontext’ has incomplete type @@ -2486,8 +2498,8 @@ msgfmt.c:(.text+0xc2b): undefined reference to `poparser_finish' collect2: error: ld returned 1 exit status Makefile.in:120: recipe for target '../utils/msgfmt.host' failed make[2]: *** [../utils/msgfmt.host] Error 1 -package/pkg-generic.mk:227: recipe for target '/data/git/linux-kernel-module-cheat/out/aarch64/buildroot/build/uclibc-custom/.stamp_built' failed -make[1]: *** [/data/git/linux-kernel-module-cheat/out/aarch64/buildroot/build/uclibc-custom/.stamp_built] Error 2 +package/pkg-generic.mk:227: recipe for target '/data/git/linux-kernel-module-cheat/out/aarch64/buildroot/build/uclibc-custom/.stamp_built' failed +make[1]: *** [/data/git/linux-kernel-module-cheat/out/aarch64/buildroot/build/uclibc-custom/.stamp_built] Error 2 Makefile:79: recipe for target '_all' failed make: *** [_all] Error 2 .... @@ -4538,9 +4550,29 @@ You will likely want to change that to: BR2_OPTIMIZE_3=y .... -and do a full rebuild. +Our link:kernel_module/user[] package correctly forwards the Buildroot options to the build with `$(TARGET_CONFIGURE_OPTS)`, so you don't have to do any extra work. -TODO is it possible to compile a single package with optimizations enabled? In any case, this wouldn't be very representative, since calls to an unoptimized libc will also have an impact on performance. Kernel-wise it should be fine though due to: <> +Don't forget to do that if you are <> with your own build system. + +Then, you have two choices: + +* if you already have a full `-O0` build, you can choose to rebuild just your package of interest to save some time as described at: <> ++ +.... +./build -B 'BR2_OPTIMIZE_3=y' kernel_module-dirclean kernel_module-reconfigure +.... ++ +However, this approach might not be representative since calls to an unoptimized libc and other libraries will have a negative performance impact. ++ +Maybe you can get away with rebuilding libc, but I'm not sure that it will work properly. ++ +Kernel-wise it should be fine though due to: <> +* <> and rebuild from scratch: ++ +.... +mv out out~ +./build -B 'BR2_OPTIMIZE_3=y' +.... === Find Buildroot options with make menuconfig diff --git a/kernel_module/external.mk b/kernel_module/external.mk index 539782d..97bbe44 100644 --- a/kernel_module/external.mk +++ b/kernel_module/external.mk @@ -13,17 +13,17 @@ ifeq ($(BR2_PACKAGE_OPENBLAS),y) endif define KERNEL_MODULE_BUILD_CMDS - $(MAKE) -C '$(@D)/user' BR2_PACKAGE_OPENBLAS="$(BR2_PACKAGE_OPENBLAS)" CC="$(TARGET_CC)" LD="$(TARGET_LD)" + $(MAKE) -C '$(@D)/user' $(TARGET_CONFIGURE_OPTS) BR2_PACKAGE_OPENBLAS="$(BR2_PACKAGE_OPENBLAS)" endef define KERNEL_MODULE_INSTALL_TARGET_CMDS - # The modules are already installed by the kernel-module package type - # under /lib/modules/**, but let's also copy the modules to the root - # for insmod convenience. - # - # Modules can be still be easily inserted with "modprobe module" however. - $(INSTALL) -D -m 0655 $(@D)/*.ko '$(TARGET_DIR)' - $(INSTALL) -D -m 0755 $(@D)/user/*.out '$(TARGET_DIR)' + # The modules are already installed by the kernel-module package type + # under /lib/modules/**, but let's also copy the modules to the root + # for insmod convenience. + # + # Modules can be still be easily inserted with "modprobe module" however. + $(INSTALL) -D -m 0655 $(@D)/*.ko '$(TARGET_DIR)' + $(INSTALL) -D -m 0755 $(@D)/user/*.out '$(TARGET_DIR)' endef $(eval $(kernel-module)) diff --git a/kernel_module/user/Makefile b/kernel_module/user/Makefile index 6345391..b20328e 100644 --- a/kernel_module/user/Makefile +++ b/kernel_module/user/Makefile @@ -1,6 +1,6 @@ .PHONY: all clean -CFLAGS_EXTRA ?= -ggdb3 -fopenmp -O0 -std=c99 -Wall -Werror -Wextra +CFLAGS_EXTRA ?= -fopenmp -std=c99 -Wall -Werror -Wextra IN_EXT ?= .c LIBS := OUT_EXT ?= .out diff --git a/sample_package/Makefile b/sample_package/Makefile index b1bed7d..3a0b40c 100644 --- a/sample_package/Makefile +++ b/sample_package/Makefile @@ -1,6 +1,6 @@ .PHONY: all clean -CFLAGS_EXTRA ?= -ggdb3 -fopenmp -O0 -std=c99 -Wall -Werror -Wextra +CFLAGS_EXTRA ?= -fopenmp -std=c99 -Wall -Werror -Wextra IN_EXT ?= .c LIBS := OUT_EXT ?= .out diff --git a/sample_package/external.mk b/sample_package/external.mk index 34725a8..a5d99f1 100644 --- a/sample_package/external.mk +++ b/sample_package/external.mk @@ -9,8 +9,9 @@ SAMPLE_PACKAGE_SITE = $(BR2_EXTERNAL_SAMPLE_PACKAGE_PATH) SAMPLE_PACKAGE_SITE_METHOD = local define SAMPLE_PACKAGE_BUILD_CMDS - # D contains the source code of this package. - $(MAKE) -C '$(@D)' CC="$(TARGET_CC)" LD="$(TARGET_LD)" + # D contains the source code of this package. + # TARGET_CONFIGURE_OPTS contains several common options such as CFLAGS and LDFLAGS. + $(MAKE) -C '$(@D)' $(TARGET_CONFIGURE_OPTS) endef define SAMPLE_PACKAGE_INSTALL_TARGET_CMDS