Try   HackMD

2024q1 Homework6 (integration)

contributed by <Hualing-Chiu>

開發環境

$ gcc --version
gcc (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0

$ lscpu
Architecture:           x86_64
  CPU op-mode(s):       32-bit, 64-bit
  Address sizes:        39 bits physical, 48 bits virtual
  Byte Order:           Little Endian
CPU(s):                 8
  On-line CPU(s) list:  0-7
Vendor ID:              GenuineIntel
  Model name:           Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz
    CPU family:         6
    Model:              158
    Thread(s) per core: 2
    Core(s) per socket: 4
    Socket(s):          1
    Stepping:           9
    CPU max MHz:        4200.0000
    CPU min MHz:        800.0000
    BogoMIPS:           7200.00
    Flags:              fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca
                         cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht
                         tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art ar
                        ch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc 
                        cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl smx
                         est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_
                        2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f
                        16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault invpcid
                        _single pti ssbd ibrs ibpb stibp fsgsbase tsc_adjust bmi
                        1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflus
                        hopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida 
                        arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_cl
                        ear flush_l1d arch_capabilities
Caches (sum of all):    
  L1d:                  128 KiB (4 instances)
  L1i:                  128 KiB (4 instances)
  L2:                   1 MiB (4 instances)
  L3:                   8 MiB (1 instance)
NUMA:                   
  NUMA node(s):         1
  NUMA node0 CPU(s):    0-7

自我檢查清單

  • 研讀前述 Linux 效能分析描述,在自己的實體電腦運作 GNU/Linux
  • 閱讀〈Linux 核心模組運作原理〉並對照 Linux 核心原始程式碼 (v6.1+),解釋 insmod 後,Linux 核心模組的符號 (symbol) 如何被 Linux 核心找到 (使用 List API)、MODULE_LICENSE 巨集指定的授權條款又對核心有什麼影響 (GPL 與否對於可用的符號列表有關),以及藉由 strace 追蹤 Linux 核心的掛載,涉及哪些系統呼叫和子系統?
  • 建構核心模組
    執行以下指令進行編譯:
    ​​​​$ make -C /lib/modules/`uname -r`/build M=`pwd` modules
    
    編譯過程出現以下錯誤訊息:
    ​​​​warning: the compiler differs from the one used to build the kernel
    ​​The kernel was built by: x86_64-linux-gnu-gcc-12 (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0
    ​​You are using:           
    ​​CC [M]  /home/sheena/hello/hello.o
    ​​​​/bin/sh: 1: gcc-12: not found
    
    表示編譯器版本與 kernel 開發套件所用的編譯器版本不一致導致出錯,將編譯器版本升為 gcc-12 即可。
    ​​​​$ sudo apt install --reinstall gcc-12
    
    ​​​​$ sudo ln -s -f /usr/bin/gcc-12 /usr/bin/gcc
    
  • 掛載核心模組
    掛載後執行 dmesg 會出現以下錯誤:
    ​​​​dmesg: read kernel buffer failed: Operation not permitted
    
    會出現這個錯誤是因為 kernel 預設的限制是不可以讓 root 以外的人去讀取,輸入以下指令即可順利讀取內容:
    ​​​​$ sudo sysctl kernel.dmesg_restrict=0