所謂的atomic operation在這邊有說明
簡單來說一個 atomic operation 就是不會被打斷的操作
一般來說可以看成是組語的一道CPU指令
一個指令不是做完就是沒做 不會有做到一半的情形
而有時候看到 atomic 用來形容一個 function
就表示該 function 同一時間內只有一個 thread 可以進入
例如 linux 的 open system call
2010年12月26日 星期日
2010年12月20日 星期一
android boot process
1.power on and boot ROM code execution
一開始可用的 ram 只有 internal ram
電源 ok 時會從 boot ROM code 開始執行 這是在 CPU 硬體內建的 code
boot ROM code 會偵測 boot media 中的 boot loader 並把它 load 到 internal ram 中
跳到 boot loader 執行
2.boot loader
boot loader 是用來設定及初始化 memory 並且 load kernel 到 memory 中
boot loader first stage 一開始偵測並設定 external ram (boot loader 太大時就會分為兩份 1st stage boot loader 會塞到 MBR 中的前 446 bytes)
設定完成便 load main boot loader(second stage boot loader) 到 external ram
second stage boot loader 會設定 file system, memory, network support, 還有可能設定 low level memory protections and security options
接著就從 boot media 中把 kernel load 到 ram 中
load kernel 完成便跳到 kernel 執行
3.linux kernel
kernel 設定系統要 run 起來一切所需的事情, interrupt controllers, memory protections, cache and scheduling
等到 MMU and cache 初始化之後系統可以用 virtual memory 和 啟動 user space process
kernel 去 system/core/init 下找 init process 並且啟動它成為第一個 user space process
4.init process
init process 是系統裡所有 process 的祖先
init process 會去找 init.rc 檔 這是一個 描述一些system service, file system, 或是參數的 script
init process 去 parse init.rc 並且啟動 system service processes
5.Zygote and Dalvik
Zygote 被 init process 啟動並且初始化 Dalvik VM
6.the system server
system server 是系統中第一個跑起來的 java 元件
他會啟動一些 android service 像是 telephony service 和 bluetooth
啟動的 service 都寫在 system server 的 run method 裡面 system server 的 source code 就在 frameworks/base/service/java/com/android/server/SystemServer.java
7.boot complete
一但 system server 跑起來而且系統 boot 完成就會有一個 broadcast action 叫做 ACTION_BOOT_COMPLETE
在你的 application 中 register 要接收這個 broadcast 就可以在系統 boot 完成後啟動你自己的 service
資料來源:
http://www.androidenea.com/2009/06/android-boot-process-from-power-on.html
一開始可用的 ram 只有 internal ram
電源 ok 時會從 boot ROM code 開始執行 這是在 CPU 硬體內建的 code
boot ROM code 會偵測 boot media 中的 boot loader 並把它 load 到 internal ram 中
跳到 boot loader 執行
2.boot loader
boot loader 是用來設定及初始化 memory 並且 load kernel 到 memory 中
boot loader first stage 一開始偵測並設定 external ram (boot loader 太大時就會分為兩份 1st stage boot loader 會塞到 MBR 中的前 446 bytes)
設定完成便 load main boot loader(second stage boot loader) 到 external ram
second stage boot loader 會設定 file system, memory, network support, 還有可能設定 low level memory protections and security options
接著就從 boot media 中把 kernel load 到 ram 中
load kernel 完成便跳到 kernel 執行
3.linux kernel
kernel 設定系統要 run 起來一切所需的事情, interrupt controllers, memory protections, cache and scheduling
等到 MMU and cache 初始化之後系統可以用 virtual memory 和 啟動 user space process
kernel 去 system/core/init 下找 init process 並且啟動它成為第一個 user space process
4.init process
init process 是系統裡所有 process 的祖先
init process 會去找 init.rc 檔 這是一個 描述一些system service, file system, 或是參數的 script
init process 去 parse init.rc 並且啟動 system service processes
5.Zygote and Dalvik
Zygote 被 init process 啟動並且初始化 Dalvik VM
6.the system server
system server 是系統中第一個跑起來的 java 元件
他會啟動一些 android service 像是 telephony service 和 bluetooth
啟動的 service 都寫在 system server 的 run method 裡面 system server 的 source code 就在 frameworks/base/service/java/com/android/server/SystemServer.java
7.boot complete
一但 system server 跑起來而且系統 boot 完成就會有一個 broadcast action 叫做 ACTION_BOOT_COMPLETE
在你的 application 中 register 要接收這個 broadcast 就可以在系統 boot 完成後啟動你自己的 service
資料來源:
http://www.androidenea.com/2009/06/android-boot-process-from-power-on.html
2010年12月16日 星期四
android 的 service
android 的 service 有分為兩類(這裡討論的不是在寫 android 應用程式時用的 service)
1. android service
2. native service
在 jollen 的 blog 還有 android1.net 都有說明
此外 android 在 booting 時會啟動一些 service
android 的啟動流程在這裡也講得很清楚
依照 init.rc 所寫 init process 啟動 service manager 和 zygote 之後
似乎還會啟動很多 native service (eq: dbus)
只是這些 service 應該 application 的開發者是完全不需要關心的
zygote 會啟動 system server
在這裡可以看到 system server 是用 java 實做 run 在一個叫 system_process 的 process 裡
system server 首先載入 android_servers 這個 library (c++實做 code 在 frameworks/base/cmds/system_server/library/system_init.cpp)
然後用 init1() 這個 jni method 去呼叫 system_init() 函式
system_init() 函式會啟動一些 native service 然後呼叫 system server 的 init2() 函式
init2() 函式接著啟動 android service 例如 power manager window manager
從這張圖可以看到 被 init2() 函式啟動的 android service 都是 run 在 system_process 中的一條 thread 裡
1. android service
2. native service
在 jollen 的 blog 還有 android1.net 都有說明
此外 android 在 booting 時會啟動一些 service
android 的啟動流程在這裡也講得很清楚
依照 init.rc 所寫 init process 啟動 service manager 和 zygote 之後
似乎還會啟動很多 native service (eq: dbus)
只是這些 service 應該 application 的開發者是完全不需要關心的
zygote 會啟動 system server
在這裡可以看到 system server 是用 java 實做 run 在一個叫 system_process 的 process 裡
system server 首先載入 android_servers 這個 library (c++實做 code 在 frameworks/base/cmds/system_server/library/system_init.cpp)
然後用 init1() 這個 jni method 去呼叫 system_init() 函式
system_init() 函式會啟動一些 native service 然後呼叫 system server 的 init2() 函式
init2() 函式接著啟動 android service 例如 power manager window manager
從這張圖可以看到 被 init2() 函式啟動的 android service 都是 run 在 system_process 中的一條 thread 裡
2010年11月23日 星期二
android 的 user space HAL
網路上一個有關user space HAL的問題
Q:
Hi All,
A:
I would suggest you to have a look of the overlay code in
hardware/libhardware/moudule/overlay.
In the new HAL architecutre, it introduced a "stub" concept which replaced
the legacy architecture which load the c/c++ library from java
application/service directly. In "stub", you need to implement some
interfaces and provide them to hardware service. For example if you wanna
implement a LED, the architecture will be:
Kernel Driver (driver to control the LED hardware) <-> syscall (open, close,
ioctl for LED, etc.) <-> hardware/libhardware/module/led (the led HAL
interfaces or "stub" ) <-> framework/base/services/jni/
com_android_server_LedService.cpp (the java native interface for LED )<->
framework/base/service/java/com/android/server/LedService.java (the java
interface of LED service <-> framwork/base/core/java
/android/hardware/LedManager (the java code of LED manager) and
ILedService.aidl (the android interface description language file for LED)
<-> LED application
這裡有一個文章連結
jollen的blog也有相關介紹文章
Q:
Hi All,
I would like to know if there is any documents or related web links
for device driver development on "User Space Abstraction Layer ".
I would appreciate if anyone can give me how this really works in
real world scenario.
A:
I would suggest you to have a look of the overlay code in
hardware/libhardware/moudule/overlay.
In the new HAL architecutre, it introduced a "stub" concept which replaced
the legacy architecture which load the c/c++ library from java
application/service directly. In "stub", you need to implement some
interfaces and provide them to hardware service. For example if you wanna
implement a LED, the architecture will be:
Kernel Driver (driver to control the LED hardware) <-> syscall (open, close,
ioctl for LED, etc.) <-> hardware/libhardware/module/led (the led HAL
interfaces or "stub" ) <-> framework/base/services/jni/
com_android_server_LedService.cpp (the java native interface for LED )<->
framework/base/service/java/com/android/server/LedService.java (the java
interface of LED service <-> framwork/base/core/java
/android/hardware/LedManager (the java code of LED manager) and
ILedService.aidl (the android interface description language file for LED)
<-> LED application
這裡有一個文章連結
jollen的blog也有相關介紹文章
2010年11月16日 星期二
android 的 local service 與 thread 的差別
android 官網中提到要執行 background 的 long running 動作時 最好要用 service
但是 service 既然也是在同一個 process 中 create 一個 thread 來做這些 long running 的動作
為什麼不直接在 activity 裡直接 create thread 來做就好了
在官網最下面有解答
1.
一個有 service 在跑的 process 權限會比只有 background activity 在跑的 process高
也就是當系統要砍 process 的時候比較不容易砍到你
2.
用 service 的話 不管 activity 發生什麼事 都不會影響到 service, process 最少可以是 "service process" priority
但是 service 既然也是在同一個 process 中 create 一個 thread 來做這些 long running 的動作
為什麼不直接在 activity 裡直接 create thread 來做就好了
在官網最下面有解答
1.
一個有 service 在跑的 process 權限會比只有 background activity 在跑的 process高
也就是當系統要砍 process 的時候比較不容易砍到你
2.
用 service 的話 不管 activity 發生什麼事 都不會影響到 service, process 最少可以是 "service process" priority
android的application component是run在哪個thread
依照 android 官網所說 android 的 application component 包括 activity service broadcast receiver 等等
都是 run 在同一個 linux process 之中(除非這些 component 有特別指名要 run 在其他 process, 可以在 androidmanifest.xml 中指定)
官網又有說到 所有這些 component object 的實例化都發生在 process 的 main thread 中
而且有關 life cycle 的 method (例如 onCreate) 也都是在 main thread 中執行
所以在這些 method 中不能執行太花費時間的動作 免得阻擋到其他 component 的執行
如果需要作這些動作 應該 create 其他 thread 來做
都是 run 在同一個 linux process 之中(除非這些 component 有特別指名要 run 在其他 process, 可以在 androidmanifest.xml 中指定)
官網又有說到 所有這些 component object 的實例化都發生在 process 的 main thread 中
而且有關 life cycle 的 method (例如 onCreate) 也都是在 main thread 中執行
所以在這些 method 中不能執行太花費時間的動作 免得阻擋到其他 component 的執行
如果需要作這些動作 應該 create 其他 thread 來做
2010年11月7日 星期日
vim 的自動完成
vim 也可以有自動完成的功能
在ubuntu 10.04下面裝的 vim 7 有預設支援自動完成的語言的資訊在 /usr/share/vim/vim72/autoload/ 下面
以php 為例 要開啟 php 自動完成功能 只要在 .vimrc 裡加上一行
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
就可以了
接下來在編輯 php 檔案時 只要用 ctrl+x ctrl+o 就可以使用自動完成
但是我最需要的 C/C++ 語言似乎需要額外的套件支援才能使用自動完成
C 的話有關鍵字自動完成可以用 不用在 .vimrc 中設定任何選項
只要在編輯 c 檔案時有 include 任何標頭檔 例如 stdio.h
在打入 print 時按下 ctrl+p 就會從 stdio.h 中找出符合的函式供你挑選
C++的話就沒有了 完全需要額外套件的支援
不知道為什麼 vim 不預設支援標準函式庫的自動完成 明明這是最需要的
關於 C/C++ 的自動完成之後再研究
在ubuntu 10.04下面裝的 vim 7 有預設支援自動完成的語言的資訊在 /usr/share/vim/vim72/autoload/ 下面
以php 為例 要開啟 php 自動完成功能 只要在 .vimrc 裡加上一行
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
就可以了
接下來在編輯 php 檔案時 只要用 ctrl+x ctrl+o 就可以使用自動完成
但是我最需要的 C/C++ 語言似乎需要額外的套件支援才能使用自動完成
C 的話有關鍵字自動完成可以用 不用在 .vimrc 中設定任何選項
只要在編輯 c 檔案時有 include 任何標頭檔 例如 stdio.h
在打入 print 時按下 ctrl+p 就會從 stdio.h 中找出符合的函式供你挑選
C++的話就沒有了 完全需要額外套件的支援
不知道為什麼 vim 不預設支援標準函式庫的自動完成 明明這是最需要的
關於 C/C++ 的自動完成之後再研究
訂閱:
文章 (Atom)