Category: Linux

  • Linux kernel 更新至 4.8.0-rc5

    Linus 在今天發佈了 4.8.0-rc5,Linus 說,rc5 的整體變動量看起來是還是略大於 rc4,他上禮拜期望變動愈來愈少看起來還是為時過早。不過雖然變動的多,但多數都是小的細碎的變動而不是大改動。總之呢,事情看起來是愈來愈糟糕啦,要是變動再繼續下去齁,我們大概需要跑到 rc8 吧,等著瞧。

  • gdb 顯示 FLAGS register

    假設有這樣的程式碼 > cat eflags.c #include <stdint.h> int main(void) { int32_t n = 2147483647; n = n + 1; printf(“%dn”, n); return 0; } 在 int32_t 的情況下,2147483647 是最大值,加上 1 之後預期 variable n 會 overflow。 我們都知道 CPU 裏面有 FLAGS register 可以表示處理器現在的狀況,那要怎麼在 gdb 裏面顯示呢? 只要在 gdb 裏面打這個指令就會顯示出 FLAGS register 目前的數值。 (gdb) info reg eflags eflags 0xa96 [ PF…

  • Linux Reading List

    Books 現在正在讀的 Linux 相關的書 Kernel http://www.dedoimedo.com/computers/crash-book.html Debugging Linux System Yocto Linux Dev  Linux Inside 4 path to being a kernel hacker

  • 現在正在讀的 Linux 相關的書

    Linux kernel Linux Kernel Development / 3e (精通 Linux 核心開發) Linux Device Drivers / 3e (Linux 驅動程式) Linux Kernel and Driver Development Training – free electrons (PDF) Debug Hacks 除錯駭客:極致除錯的技巧與工具 Advanced Programming in the UNIX Environment / 3e C Expert C Programming – Deep C Debugging with gdb – The gnu Source-Level Debugger 透視 C…

  • 4.x Linux kernel procfs guide (continue)

    今天正在釐清在 4.x 上可行的 procfs 應用方式,使用的範例是來自 crashcourse.ca 的 Introduction linux kernel programming,裏面系統的介紹了 procfs 與 seq_file 的使用方式,一共有三節可以看。 做完上面的練習之後,目前正在更新舊的 Linux kernel procfs guide,proting 成新版的 4.x Linux kernel procfs guide,整理之後,希望可以幫助到其他人學習這個地方。

  • Linux procfs example (4.x 可用的)

    網路上很多有關 Linux kernel 的 snippet 或是 tutorial 其實都已經過期很久了… 例如說今天想要找 procfs 的範例: Documents/Kernel-Docbooks Linux Kernel Procfs Guide http://www2.mta.ac.il/~carmi/Teaching/OSLinux/Slides/Lec08/procfs-1.c http://www.ittc.ku.edu/kusp/new/howto/kmods/setup.html …etc 以上都是過期的範例,大約是在 kernel 2.6 時候的 code. 目前 (2016/08/24) 的 kernel version 已經來到 4.8.0-rc3,而 create_proc_entry() 是在 3.10 版的時候被拋棄掉的。但是很多的 example 都還留在 2.6 的時代,連目前市面上的書也是如此,像是 LDD3,LKD等,在版本上都已經過期許久。 目前有找到的新的 procfs 範例有這些: http://www.cs.fsu.edu/~cop4610t/lectures/project2/procfs_module/proc_module.pdf http://www.lifl.fr/~lipari/courses/ase_lkp/ase_lkp.html https://chengyihe.wordpress.com/2015/11/03/android-kernel-procfs-seq_file-the-simplest-way-to-export-to-user-space/ 在 kernel newbies mailing list 的這串討論串也可以看看, 裏面有提到比較新的 kernel develop 的教材。…

  • Linux time difference in nano-second persision

    在 Linux 中算出 nano-second 級時差 當你在需要跟時間差有高精確度的需求的時候,可能會先想到用 gettimeofday 來處理,像是這樣: gettimeofday #include <sys/time.h> struct timeval start, end; gettimeofday(&start, NULL); … gettimeofday(&end, NULL); /* print diff in time */ diff(start, end); 那如果要更高的精確度呢?例如說到 nano-seconds? 就必須要使用 clock_gettime 來處理。 nano-second diff #include <time.h> static long diff_in_ns(struct timespec t1, struct timespec t2) { struct timespec diff; if (t2.tv_nsec-t1.tv_nsec < 0) { diff.tv_sec…

  • [COSCUP 2016] Day2 Lightning Talk: 三分鐘送 first kernel patch

    今天的 ‪#‎COSCUP2016‬ ‪#‎LightningTalk‬ 講的是「三分鐘送 first kernel patch」,本來是在 OOP in C 跟 patch 想要用哪個,後來想說這個標題比較竦動就用這個了。 本方法只是讓新手(如我)有個進門的機會,了解 Linux kernel patching 的機制與方法。 這也是為什麼在 kernel staging tree 的這些 driver 沒有用 automation 的方式把錯誤都處理乾淨。  最後誠徵加入翻譯,目前正在翻譯 Object-oriented design patterns in the kernel, part 1/part 2,歡迎一起翻譯! 三分鐘送 first kernel patch (for 新手) from Louie Lu

  • LWN – File permissions in the kernel [August 3, 2016 by corbet]

    Linux kernel 中的檔案權限設計 LWN – File permissions in the kernel [August 3, 2016 by corbet] from: http://lwn.net/Articles/696227/ permission bits in linux 在 8/2 號的時候,Baole Ni 為了把 kernel 中有關 file permission 的 code 從八進位修改成 macro 的樣式,送了高達 1285 個 patch。David Miller 直接說這是「patch 史上最糟的一個 submit」。更猛的是,他的 patch 信還送給了不只一位的 developer… 會有這樣的改動是因為,kernel 中有關權限的部份,其實已經在 linux/stat.h 已經有 macro 可以使用,像是 S_IRWXUGO 或是 S_IRUGO 這種表示方式,但大多數在 kernel code 的實作,還是使用 0444 這樣的八進位表示方式。 一場大戰就此開打,首先大家在看到這個 patch 之後,先不論他直接送上 1285…

  • 2016-08-09 Operating Systems: Three Easy Pieces – Virtualization part

    今天在看從 CS537 – Spring 2013 介紹的參考書籍:Operating Systems: Three Easy Pieces 一整天看了 Virtualization 的部份,從 Process 到 Segmentation 的部份。(中間跳過 9 跟 10) Virtualization 主要分成兩個部份,第一是 CPU 的虛擬化,首先談到有關 CPU 虛擬化 mechanisms (機制) 的部份,同時也提到 mechanisms 跟 policies (法則) 在設計的時候會將其脫勾,以便於後續的設計順利,這個部份在 LDD3e 開頭的時候也有提到。 CPU 虛擬化在設計的時候,首先要面對到 exception / interrupt handler 與 context switch 的機制設計,接著提到排程的設計,CPU想要確保所有的程式都能夠公平且有效的被執行,因此發展了許多的排程方式,從 FIFO、SJF、RR 到 Multi-Level Feedback Queue 等排班方式,現代的 Linux 則使用了 O(1) 、…