Year: 2016

  • 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 的教材。…

  • Declaration and Definition in C

    Definition: 定義 occurs in only one place (只能出現一次) specifies the type of an object; reserves storage for it; is used to create new objects example:  int my_array[100]; Declaration: 宣告 can occur multiple times (可以出現多次) describes the type of an object; is used to refer to objects defined elsewhere (e.g., in another file) example:  extern int…

  • 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) 、…

  • 2016-08-08 SSE/AVX instruction set performance

    github: https://github.com/grapherd/sse-avx-instruction-set-performance 今天照著 Performance of SSE and AVX Instruction Sets 看了一遍,然後實作了3個論文中提到的最佳化辦法: * Data Packing* Data Reuse* Asynchronous Data Transfer (prefetch) 把 repo clone 下來之後,可以用 make 產生所有的執行檔。執行 main 可以看三種方式在 native / sse / avx 狀況下的執行速度。

  • 2016-08-02 epoll 與 timeout

    Sasha Pivovarova 翻譯 持續暫停中 Q_________Q 看了文章後才發現,原來大家英文都很好,可以直接看懂文章。 要不然怎麼會到現在都沒有翻譯的文章呢。 一定是我功力太弱了,要加強! Linux epoll epoll 是一個 Linux 上 select 與 poll 的替代品,其他平台可以參看 /dev/poll 與 kqueue。 會碰到這個是因為還在看昨天的 server-framework,目前大致上了解 epoll 的用途。 不過在搞懂用途之前,一直狀牆。原因有兩個,一個是對 socket 不熟,一個是因為對 http 不熟。 有關 socket 的部份,最後是靜下心來看了這篇文章後,跟著一個一個做才了解要怎麼在 Linux 上 控制 socket。 http://beej-zhtw.netdpi.net/05-system-call-or-bust/5-1-getaddrinfo-start 有關 http 的部份,看了一下 http keep-alive 的東西。 有關 epoll 的部份,參考了許多的文章如 https://banu.com/blog/2/how-to-use-epoll-a-complete-example-in-c/ (原文) http://www.oschina.net/translate/how-to-use-epoll-a-complete-example-in-c (簡中) http://man7.org/linux/man-pages/man2/epoll_wait.2.html http://man7.org/linux/man-pages/man7/epoll.7.html (參考程式碼) https://segmentfault.com/a/1190000003063859 (參考程式碼, 理解不同 I/O 模式)…

  • 2016-08-02 SIMD and SSE

    翻譯 暫停一天 (沒有進展) SIMD and SSE 2016q1h2: http://wiki.csie.ncku.edu.tw/embedded/2016q1h2 做 raytracing 作業,花了大約5~6個小時把 math-simd-toolkit.h  全修成 SIMD 版本,但是發現要把其他部份也一併改掉,要花更多時間,只能先放在這邊了。 參考資料有: SIMD optimized dot and cross product functions ストリーミング SIMD 拡張命令の算術演算 SIMD and SSE 中文資料很少,下次可以來補齊這部份。 Server Framework 2016q1h3: http://wiki.csie.ncku.edu.tw/embedded/2016q1h3 正在搞懂這程式怎麼運作以及效能比較。