小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

怎樣向Android社區(qū)提交代碼

 老匹夫 2015-01-03

怎樣向Android社區(qū)提交代碼




原創(chuàng)文章,轉(zhuǎn)載請(qǐng)注明出處.轉(zhuǎn)載自: Li Haifeng's Blog
本文鏈接地址: 怎樣向Android社區(qū)提交代碼



注:[2014-3-13] 向android提交patch的方式已經(jīng)更新,本文所敘述的方式不再完全匹配,請(qǐng)參考 
http://source./source/submit-patches.html


向開源社區(qū)貢獻(xiàn)代碼的方式很多,Android采用repo的方式。


由于在提交patch的時(shí)候,必須使用repo upload命令,所以,首先要安裝repo在自己的項(xiàng)目中。安裝repo在自己項(xiàng)目的步驟分兩步:
1-1.
$ curl http://android.git./repo > ~/bin/repo
$ chmod a+x ~/bin/repo


1-2.然后把~/bin加入到PATH環(huán)境變量中,如果不加的話,用repo就需要全路徑,比較麻煩,不管怎樣,下面這一步是可選的:


$ export PATH=~/bin:$PATH


2.安裝repo到自己的項(xiàng)目中,只有安裝到自己項(xiàng)目中后,才可以使用repo,即使是repo help也不例外。


$ repo init -u git://android.git./platform/manifest.git


題外話:使用repo比使用git更麻煩,在教育網(wǎng)中,repo platform幾乎是不能完成的任務(wù),當(dāng)然,可以使用git proxy,不過這種方法并不好使,一個(gè)簡(jiǎn)單且方便的方法是搞一個(gè)VPS 。


如果自己要提交的project沒有在manifest管轄的范圍內(nèi),那就需要自己去修改.repo/manifest.xml文件了。
比如,我要修改的Project項(xiàng)目名稱是kernel/common,路徑是kernel/common,而這個(gè)Project并沒有在manifest.xml,所以在.repo/mainfest.xml文件中添加這么一行:


  <project path=”kernel/common” name=”kernel/common/” />


  然后運(yùn)行repo sync去下載整個(gè)platform,整個(gè)platform的容量基本上2GB左右,如果沒有必要下載那么多的項(xiàng)目,修改.repo/manifest.xml,只保留自己的項(xiàng)目就可以了。
  比如,我只需要其中的platform/build項(xiàng)目,那么在.repo/manifest.xml中只保留<project path=”build”>的條目就可以了,更改.repo/manifest.xml修改為:



   <?xml version=”1.0″ encoding=”UTF-8″?>



    <manifest>
    <remote  name=”korg”
    fetch=”git://android.git./
    review=”review.source.” />
    <default revision=”master”
    remote=”korg” />
    <project path=”build” name=”platform/build”>
    <copyfile src=”core/root.mk” dest=”Makefile” />
    </project>
    </manifest>




  在repo sync的時(shí)候,可能會(huì)彈出如下的錯(cuò)誤:


  error: revision master in kernel/common not found


  這是因?yàn)椋趍anifest.xml中,默認(rèn)的revision為master。因此,需要在相關(guān)的項(xiàng)目中設(shè)置revision。 例如:我需要kernel/common項(xiàng)目中的android-2.6.27分支,那么,應(yīng)該在manifest.xml中寫為:
  <project path=”kernel/common” name=”kernel/common” revision=”android-2.6.27″/>


  repo sync完成后,進(jìn)入相關(guān)的項(xiàng)目,建立一個(gè)分支,修改后,并提交.



   例如,
   $cd kernel/common #進(jìn)入項(xiàng)目目錄中
   $repo start goldfish . #建立一個(gè)新的goldfish分支
   $git checkout goldfish #切換到goldfish分支上
   完成修改任務(wù)
   $git add .
   $git commit




Android社區(qū)要求提交的commit:



  •    Start with a one-line summary (60 characters max), followed by a blank line.


  •    The description should focus on what issue it solves, and how it solves it. The second part is somewhat optional when implementing new features, though desirable.


  •    Include a brief note of any assumptions or background information that may be important when another contributor works on this feature next year.




  然后就可以repo upload了,不過在upload的時(shí)候,需要在https://review.source./中注冊(cè)并提交自己的ssh public keys.
  提交完成ssh public keys后,就OK啦,成功后,會(huì)自動(dòng)返回一個(gè)review。然后等待人工review,這一切,都可以在https://review.source. 中看到。


  友情提示:歡迎轉(zhuǎn)載,轉(zhuǎn)載請(qǐng)說明出處。如果有任何問題,歡迎批評(píng),交流,指正。




<全文完>



Post Footer automatically generated by wp-posturl plugin for wordpress.





May 28th, 2011 in
Uncategorized |
暫無評(píng)論





Android 與Linux Kernel




原創(chuàng)文章,轉(zhuǎn)載請(qǐng)注明出處.轉(zhuǎn)載自: Li Haifeng's Blog
本文鏈接地址: Android 與Linux Kernel




在kernel子目錄下存放的就是Android的Linux Kernel了, 通過和標(biāo)準(zhǔn)的Linux 2.6.25 Kernel的對(duì)比,我們可以發(fā)現(xiàn),其主要增加了以下的內(nèi)容:

1. 基于ARM架構(gòu)增加Gold-Fish平臺(tái),相應(yīng)增加的目錄如下:

kernel/arch/arm/mach-goldfish

kernel/include/asm-arm/arch-goldfish

Gold-Fish平臺(tái)采用的是ARM926T CPU作為BaseBand處理器, 該CPU主頻至少為200M HZ. 采用MSM7201A CPU(ARM 11)作為主CPU, 其主頻為528M HZ.

2. 增加了yaffs2 FLASH文件系統(tǒng),相應(yīng)增加的目錄為:

kernel/fs/yaffs2

實(shí)際上,Android包經(jīng)過編譯后生成的system.img和ramdisk.img文件就是yaffs2格式的包.

3. 增加了Android的相關(guān)Driver,相應(yīng)目錄為:

kernel/drivers/android

主要分為:

Android IPC系統(tǒng): Binder

Android 日志系統(tǒng): Logger

Android 電源管理: Power

Android 鬧鐘管理: Alarm

Android 內(nèi)存控制臺(tái): Ram_console

Android 時(shí)鐘控制的gpio: Timed_gpio

4. 增加了switch處理, 相應(yīng)的目錄為:

kernel/drivers/switch/

5. 增加了一種新的共享內(nèi)存處理方式, 相應(yīng)增加的文件為:

kernel/mm/ashmem.c

6. 其他為L(zhǎng)inux-2.6.25內(nèi)核所做的補(bǔ)丁等等,例如BlueTooth, 在此不做詳細(xì)分析

另外GoldFish平臺(tái)相關(guān)的驅(qū)動(dòng)文件如下:

1. 字符輸出設(shè)備:

kernel/drivers/char/goldfish_tty.c

2. 圖象顯示設(shè)備: (Frame Buffer)

kernel/drivers/video/goldfishfb.c

3. 鍵盤輸入設(shè)備:

kernel/drivers/input/keyboard/goldfish_events.c

4. RTC設(shè)備: (Real Time Clock)

kernel/drivers/rtc/rtc-goldfish.c

. USB Device設(shè)備:

kernel/drivers/usb/gadget/android_adb.c

6. SD卡設(shè)備:

kernel/drivers/mmc/host/goldfish.c

7. FLASH設(shè)備:

kernel/drivers/mtd/devices/goldfish_nand.c

kernel/drivers/mtd/devices/goldfish_nand_reg.h

8. LED設(shè)備:

kernel/drivers/leds/ledtrig-sleep.c

9. 電源設(shè)備:

kernel/drivers/power/goldfish_battery.c

10. 音頻設(shè)備:

kernel/arch/arm/mach-goldfish/audio.c

11. 電源管理:

kernel/arch/arm/mach-goldfish/pm.c

12. 時(shí)鐘管理:

kernel/arch/arm/mach-goldfish/timer.c

以上為Android內(nèi)核的大致分析,希望能給有興趣的人員以簡(jiǎn)單幫助



—————摘自程廣輝博客:http://hi.baidu.com/l4os/home









Goldfish Audio <-> arch/arm/mach-goldfish/audio.c
Goldfish pdev-bus <-> arch/arm/mach-goldfish/board-goldfish.c
                                        arch/arm/mach-goldfish/pdev_bus.c
Goldfish power management
                                <-> arch/arm/mach-goldfish/pm.c
Goldfish switch device(我覺得這是一個(gè)test device)
                                <-> arch/arm/mach-goldfish/switch.c
Goldfish timer         <-> arch/arm/mach-goldfish/timer.c
Goldfish tty             <-> drivers/char/goldfish_tty.c
Goldfish mmc(multi-media card)         
                               <-> drivers/mmc/host/goldfish.c
Goldfish keyboard <->drivers/input/keyboard/goldfish_events.c
Goldfish Nand        <-> drivers/mtd/devices/goldfish_nand.c
goldfish battery    <-> drivers/power/goldfish_battery.c
Goldfish rtc <-> drivers/rtc/rtc-goldfish.c
Goldfish framebuffer <-> drivers/video/goldfishfb.c 
And others:
        drivers/leds/ledtrig-sleep.c
        drivers/misc/lowmemorykiller.c
        drivers/misc/qemutrace/*
        drivers/switch/*
        
        
       

         Normally we can find all the device hardware info in the android-emulator/qemu/hw directory including goldfish_audio, goldfish_mmc, goldfish_nand, goldfish_tty, goldfish_events_device, goldfish_battery, goldfish_fb, goldfish_timer,goldfish_switch.

Android / Anonymous Shared Memory Subsystem, ashmem <-> mm/ashmem.c

drivers/android/(alarm.c binder.c logger.c power.c ram_console.c timed_gpio.c)


From android-emulator boot log
goldfish_add_device: goldfish_interrupt_controller, base ff000000 1000, irq 0 0
goldfish_add_device: goldfish_device_bus, base ff001000 1000, irq 1 1
goldfish_add_device: goldfish_timer, base ff003000 1000, irq 3 1
goldfish_add_device: goldfish_rtc, base ff010000 1000, irq 10 1
goldfish_add_device: goldfish_tty, base ff002000 1000, irq 4 1
goldfish_add_device: goldfish_tty, base ff011000 1000, irq 11 1
goldfish_add_device: smc91x, base ff012000 1000, irq 12 1
goldfish_add_device: goldfish_fb, base ff013000 1000, irq 13 1
goldfish_add_device: goldfish_memlog, base ff006000 1000, irq 0 0
goldfish_add_device: goldfish-battery, base ff014000 1000, irq 14 1
goldfish_add_device: goldfish_events, base ff015000 1000, irq 15 1
goldfish_add_device: goldfish_nand, base ff016000 1000, irq 0 0
goldfish_add_device: goldfish-switch, base ff017000 1000, irq 16 1
goldfish_add_device: goldfish-switch, base ff018000 1000, irq 17 1

In the end the Google Android use YAFFS2 file system which is a NAND file system, more info is here (http://discuz-android./2008/01/yaffsyaffs2-and-jffs2-comparison.html)


drivers/char/goldfish_tty.c
drivers/char/Kconfig
config GOLDFISH_TTY
        tristate “Goldfish TTY Driver”
        default n
        help
                TTY driver for Goldfish Virtual Platform.

drivers/mmc/host/goldfish.c
drivers/mmc/host/Kconfig
config MMC_GOLDFISH
        tristate “goldfish qemu Multimedia Card Interface support”
        depends on ARCH_ANDROIDSIM
        help
                This selects the Goldfish Multimedia card Interface emulation.

                If unsure, say N.

drivers/input/keyboard/goldfish_events.c
drivers/input/keyboard/Kconfig
config KEYBOARD_GOLDFISH_EVENTS
        tristate “Generic Input Event device for Goldfish”
        help
                no help
                
drivers/mtd/devices/goldfish_nand.c
drivers/mtd/devices/goldfish_nand_reg.h
drivers/mtd/devices/Kconfig
config MTD_GOLDFISH_NAND
        tristate “Goldfish NAND device”
        help
                none

drivers/power/goldfish_battery.c
drivers/power/Kconfig
config BATTERY_GOLDFISH
        tristate “Goldfish battery driver”
        help
                Say Y to enable support for the battery and AC power in the Goldfish emulator.
                
drivers/rtc/rtc-goldfish.c
drivers/rtc/Kconfig
config RTC_DRV_GOLDFISH
        tristate “GOLDFISH”
        depends on RTC_CLASS
        help
          RTC driver for Goldfish Virtual Platform
          
drivers/video/goldfishfb.c 
drivers/video/Kconfig
config FB_GOLDFISH
        tristate “Goldfish Framebuffer
        depends on FB
        select FB_CFB_FILLRECT
        select FB_CFB_COPYAREA
        select FB_CFB_IMAGEBLIT
        —help—
                Framebuffer driver for Goldfish Virtual Platform
                
mm/ashmem.c
mm/Makefile
        obj-$(CONFIG_ASHMEM) += ashmem.o

drivers/android/(alarm.c binder.c logger.c power.c ram_console.c timed_gpio.c)
drivers/Kconfig
source “drivers/android/Kconfig”
drivers/Makefile
obj-y                           += android/




Post Footer automatically generated by wp-posturl plugin for wordpress.





May 26th, 2011 in
Uncategorized |
暫無評(píng)論





Linux進(jìn)程調(diào)度中隊(duì)列的使用




原創(chuàng)文章,轉(zhuǎn)載請(qǐng)注明出處.轉(zhuǎn)載自: Li Haifeng's Blog
本文鏈接地址: Linux進(jìn)程調(diào)度中隊(duì)列的使用




Linux進(jìn)程調(diào)度中隊(duì)列的使用




作者:西郵 王聰



Linux內(nèi)核中大量使用了隊(duì)列,這里僅列舉它在進(jìn)程調(diào)度中的幾處應(yīng)用。Linux內(nèi)核中的隊(duì)列是以雙鏈表的形式連接起來的,include/linux/list.h中定義了隊(duì)列并提供了一些接口,詳細(xì)的介紹可以參考[1]中的附錄。



Linux中的進(jìn)程有如下幾個(gè)主要狀態(tài):




































進(jìn)程狀態(tài)



說明



TASK_RUNNING



進(jìn)程正在運(yùn)行或?qū)⒁贿\(yùn)行。



TASK_INTERRUPTIBLE



進(jìn)程正在睡眠,等待某個(gè)條件的完成。



TASK_UNINTERRUPTIBLE



深度睡眠,不會(huì)被信號(hào)打擾。



TASK_STOPPED



進(jìn)程運(yùn)行被停止。



TASK_TRACED



進(jìn)程被調(diào)試程序停止,被另一個(gè)進(jìn)程跟蹤。



兩個(gè)額外的狀態(tài)是EXIT_ZOMBIEEXIT_DEAD,表示進(jìn)程處于僵死狀態(tài)還是真正死亡。處于僵死狀態(tài)的進(jìn)程會(huì)等待其父進(jìn)程的收養(yǎng)(否則就會(huì)被init進(jìn)程收養(yǎng)),而真正死亡的進(jìn)程會(huì)被直接刪除。



狀態(tài)為TASK_RUNNING的進(jìn)程都會(huì)被放入運(yùn)行隊(duì)列(runqueue)中,這是通過task_struct(定義在include/linux/sched.h)中的run_list成員來鏈接的。不過,為了讓內(nèi)核每次都能選取優(yōu)先級(jí)最合適的進(jìn)程,Linux為每個(gè)優(yōu)先級(jí)構(gòu)建了一個(gè)queue。這是通過struct prio_array來實(shí)現(xiàn)的,struct prio_array的定義在kernel/sched.c,大致如下:



struct prio_array {


int nr_active;


unsigned long bitmap[BITMAP_SIZE];


struct list_head queue[MAX_PRIO];


};



queue成員就是隊(duì)列數(shù)組。每個(gè)CPU有各自的runqueue,每一個(gè)runqueue又有包含兩個(gè)prio_array,一個(gè)是活動(dòng)隊(duì)列,一個(gè)是時(shí)間片耗盡的隊(duì)列。當(dāng)運(yùn)行隊(duì)列空時(shí),內(nèi)核便會(huì)交換兩個(gè)隊(duì)列的指針,原來的耗盡隊(duì)列就成了新的活動(dòng)隊(duì)列!這和prio_array中的bitmap是決定調(diào)度算法為O(1)的關(guān)鍵。



狀態(tài)為TASK_STOPPED,EXIT_ZOMBIEEXIT_DEAD的進(jìn)程不會(huì)被放入專門的隊(duì)列中,它們直接通過pid或者通過父進(jìn)程的孩子隊(duì)列來訪問。



TASK_INTERRUPTIBLETASK_UNINTERRUPTIBLE狀態(tài)的進(jìn)程會(huì)被放入等待隊(duì)列。不同的是,每個(gè)等待事件都會(huì)有一個(gè)等待隊(duì)列,該隊(duì)列中的進(jìn)程等待同一事件的完成。(“事件”一個(gè)動(dòng)態(tài)的過程,不好通過具體的結(jié)構(gòu)來定義一個(gè)“事件”。這里等待一個(gè)事件就是查看某個(gè)條件是否為真,比如某個(gè)標(biāo)志變量是否為真。)wait_queue_head_t的定義在include/linux/wait.h中,如下:



typedef struct _ _wait_queue_head {


spinlock_t lock;


struct list_head task_list;


}wait_queue_head_t;



wait_queue_t的定義如下:



typedef struct _ _wait_queue {


unsigned int flags;


struct task_struct * task;


wait_queue_func_t func;


struct list_head task_list;


}wait_queue_t;



進(jìn)入等待狀態(tài)的接口有兩類:



prepare_to_wait*()/finish_wait()


wait_event*()



其實(shí)wait_event*()內(nèi)部也是調(diào)用prepare_to_wait*(),把它放入一個(gè)循環(huán)中。而且wait_event*()在事件完成時(shí)會(huì)自動(dòng)調(diào)用finish_wait()。決定使用哪個(gè)要看情況而定。(sleep_on*()是遺棄的接口,現(xiàn)在已經(jīng)不再使用,雖然還支持。)等待隊(duì)列中的進(jìn)程有兩種,一種是exclusive的進(jìn)程,另一種是nonexclusive的進(jìn)程。所謂exclusive是指喚醒的進(jìn)程等待的資源是互斥的,每次只喚醒一個(gè)(喚醒多個(gè)也可以,不過最后還是只有一個(gè)會(huì)被喚醒,其余的又被重新添加到等待隊(duì)列中,這樣效率會(huì)大打折扣)。一般,等待函數(shù)會(huì)把進(jìn)程設(shè)為nonexclusiveuninterruptible,帶“interruptible”的會(huì)專門指定狀態(tài)為interruptible;而帶“timeout”的會(huì)在超時(shí)后退出,因?yàn)樗鼤?huì)調(diào)用schedule_timeout();帶“exclusive”的則會(huì)把進(jìn)程設(shè)為exclusive。



喚醒的接口雖然只有wake_up*(),但它內(nèi)部也分成好幾種。帶“interruptible”的喚醒函數(shù)只會(huì)喚醒狀態(tài)是TASK_INTERRUPTIBLE的進(jìn)程,而不帶的則會(huì)喚醒TASK_INTERRUPTIBLETASK_UNINTERRUPTIBLE的進(jìn)程;所有喚醒函數(shù)都會(huì)把等待同一事件的nonexclusive進(jìn)程全部喚醒,或者把其中一個(gè)exclusive的進(jìn)程喚醒;而帶“nr”的則會(huì)喚醒指定個(gè)數(shù)的exclusive的進(jìn)程,帶“all”的會(huì)把全部exclusive進(jìn)程喚醒。帶“sync”會(huì)忽略優(yōu)先級(jí)的檢查,高優(yōu)先級(jí)的進(jìn)程可能會(huì)被延遲。最后,持有自旋鎖時(shí)只能調(diào)用wait_up_locked()



進(jìn)程管理是Linux內(nèi)核中最關(guān)鍵的部分,它的性能幾乎直接決定著內(nèi)核的好壞,其中使用的一些設(shè)計(jì)和算法非常復(fù)雜。這里僅僅是介紹了隊(duì)列在其中的使用情況,更深入的探索還有待繼續(xù)去探索。





參考資料:





  1. Linux Kernel Development, Second Edition, Robert Love, Sam Publishing.




  2. Understanding the Linux Kernel, 3rd Edition, Daniel P. Bovet, Marco Cesati, O'Reilly.




  3. The Linux Kernel Primer: A Top-Down Approach for x86 and PowerPC ArchitecturesClaudia Salzberg Rodriguez, Gordon Fischer, Steven Smolski, Prentice Hall PTR.






Post Footer automatically generated by wp-posturl plugin for wordpress.





May 23rd, 2011 in
Uncategorized |
暫無評(píng)論





關(guān)于內(nèi)核搶占




原創(chuàng)文章,轉(zhuǎn)載請(qǐng)注明出處.轉(zhuǎn)載自: Li Haifeng's Blog
本文鏈接地址: 關(guān)于內(nèi)核搶占



內(nèi)核搶占
—————————————————
    與其他大部分Unix變體和其他大部分的操作系統(tǒng)不同, Linux完整地支持內(nèi)核搶占。
    在不支持內(nèi)核搶占的內(nèi)核中,內(nèi)核代碼可以一直執(zhí)行,到它完成為止。也就是說,調(diào)度程序沒有辦法在一個(gè)內(nèi)核級(jí)的任務(wù)正在執(zhí)行的時(shí)候重新調(diào)度 — 內(nèi)核中的各任務(wù)是協(xié)作方式調(diào)度的,不具備搶占性。
    在2.6版的內(nèi)核中,內(nèi)核引人了搶占能力;現(xiàn)在,只要重新調(diào)度是安全的,那么內(nèi)核就可以在任何時(shí)間搶占正在執(zhí)行的任務(wù)。
    那么,什么時(shí)候重新調(diào)度才是安全的呢?只要沒有持有鎖,內(nèi)核就可以進(jìn)行搶占。鎖是非搶占區(qū)域的標(biāo)志。由于內(nèi)核是支持SMP的,所以,如果沒有持有鎖,那么正在執(zhí)行的代碼就是可重新導(dǎo)入的,也就是可以搶占的。
    為了支持內(nèi)核搶占所作的第一處變動(dòng)就是每個(gè)進(jìn)程的thread_info引入了preempt_count(thread_info.preempt_count)計(jì)數(shù)器。該計(jì)數(shù)器初始值為0,每當(dāng)使用鎖的時(shí)候數(shù)值加1,釋放鎖的時(shí)候數(shù)值減1。當(dāng)數(shù)值為0的時(shí)候,內(nèi)核就可執(zhí)行搶占。從中斷返回內(nèi)核空間的時(shí)候,內(nèi)核會(huì)檢查need_resched和preempt_count的值。如果need_resched被設(shè)置,并且preempt_count為0的話,這說明有一個(gè)更為重要的任務(wù)需要執(zhí)行并且可以安全地?fù)屨迹藭r(shí),調(diào)度程序就會(huì)調(diào)度(搶占當(dāng)前進(jìn)程)。如果preempt_count不為0,說明當(dāng)前任務(wù)持有鎖,所以搶占是不安全的。這時(shí),就會(huì)像通常那樣直接從中斷返回當(dāng)前執(zhí)行進(jìn)程。如果當(dāng)前進(jìn)程所持有的所有的鎖都被釋放了。那么preempt_count就會(huì)重新為0。此時(shí),釋放鎖的代碼會(huì)檢查need_resched是否被設(shè)置。如果是的話,就會(huì)調(diào)用調(diào)度程序。有些內(nèi)核代碼需要允許或禁止內(nèi)核搶占。
    如果內(nèi)核中的進(jìn)程被阻塞了,或它顯式地調(diào)用了schedule(),內(nèi)核搶占也會(huì)顯式地發(fā)生。這種形式的內(nèi)核代碼從來都是受支持的,因?yàn)楦緹o需額外的邏輯來保證內(nèi)核可以安全地發(fā)生被搶占。如果代碼顯式的調(diào)用了schedule(),那么它應(yīng)該清楚自己是可以安全地被搶占的。
    內(nèi)核搶占發(fā)生在:
    (1) 當(dāng)"從中斷處理程序"正在執(zhí)行,且返回內(nèi)核空間之前
    (2) 內(nèi)核代碼再一次具有可搶占性的時(shí)候
    (3) 如果內(nèi)核中的任務(wù)顯式的調(diào)用schedule()
    (4) 如果內(nèi)核中的任務(wù)阻塞(這同樣也會(huì)導(dǎo)致調(diào)用schedule())


對(duì)應(yīng)的英文:
Kernel Preemption
The Linux kernel, unlike most other Unix variants and many other operating systems, is a fully preemptive kernel. In non-preemptive kernels, kernel code runs until completion. That is, the scheduler is not capable of rescheduling a task while it is in the kernelkernel code is scheduled cooperatively, not preemptively. Kernel code runs until it finishes (returns to user-space) or explicitly blocks. In the 2.6 kernel, however, the Linux kernel became preemptive: It is now possible to preempt a task at any point, so long as the kernel is in a state in which it is safe to reschedule.
So when is it safe to reschedule? The kernel is capable of preempting a task running in the kernel so long as it does not hold a lock. That is, locks are used as markers of regions of non-preemptibility. Because the kernel is SMP-safe, if a lock is not held, the current code is reentrant and capable of being preempted.
The first change in supporting kernel preemption was the addition of a preemption counter, preempt_count, to each process's thread_info. This counter begins at zero and increments once for each lock that is acquired and decrements once for each lock that is released. When the counter is zero, the kernel is preemptible. Upon return from interrupt, if returning to kernel-space, the kernel checks the values of need_resched and preempt_count. If need_resched is set and preempt_count is zero, then a more important task is runnable and it is safe to preempt. Thus, the scheduler is invoked. If preempt_count is nonzero, a lock is held and it is unsafe to reschedule. In that case, the interrupt returns as usual to the currently executing task. When all the locks that the current task is holding are released, preempt_count returns to zero. At that time, the unlock code checks whether need_resched is set. If so, the scheduler is invoked. Enabling and disabling kernel preemption is sometimes required in kernel code and is discussed in Chapter 9.
Kernel preemption can also occur explicitly, when a task in the kernel blocks or explicitly calls schedule(). This form of kernel preemption has always been supported because no additional logic is required to ensure that the kernel is in a state that is safe to preempt. It is assumed that the code that explicitly calls schedule() knows it is safe to reschedule.
Kernel preemption can occur
When an interrupt handler exits, before returning to kernel-space
When kernel code becomes preemptible again
If a task in the kernel explicitly calls schedule()
If a task in the kernel blocks (which results in a call to schedule())



Post Footer automatically generated by wp-posturl plugin for wordpress.





May 12th, 2011 in
Uncategorized |
暫無評(píng)論





關(guān)于Makefile




原創(chuàng)文章,轉(zhuǎn)載請(qǐng)注明出處.轉(zhuǎn)載自: Li Haifeng's Blog
本文鏈接地址: 關(guān)于Makefile



幾乎所有的Linux項(xiàng)目都是使用make來進(jìn)行項(xiàng)目管理的.make是依據(jù)Makefile來進(jìn)行工作的.因此書寫和閱讀Makefile就是Linux程序員必備的一項(xiàng)基本功.


對(duì)于像我這樣的newbie,寫一個(gè)稍微復(fù)雜的Makefile必定會(huì)錯(cuò)誤百出,原因是Makefile的命令語法與bash有相似之處,但是還有許多細(xì)節(jié)上的差別,比如



  • 賦值bash要求"="兩邊是不能有空格的,但是Makefile就允許.

  • 在bash中用if條件判斷,就像VB一樣,但是如果要在Makefile中使用的話,需要寫到一行中,如果寫不下,需要用""來告訴make,下面的一行和上面的這一行屬于一個(gè)邏輯行.

  • Makefile還對(duì)TAB,空格有嚴(yán)格的要求,這個(gè)仿佛就像是Python.如果你不TAB就寫一個(gè)命令,make不認(rèn)為是一個(gè)命令,而如果寫個(gè)ifdef而用了TAB的話,make會(huì)把ifdef當(dāng)作一個(gè)命令來執(zhí)行,而不是一個(gè)條件判斷.

  • exit在Makefile中貌似起不到Bash中的效果,你要在Makefile中控制其執(zhí)行情況必須用error才可以.



讀Makefile就是執(zhí)果索因(這是別人總結(jié)的),根據(jù)結(jié)果順瓜摸藤,就比較容易了.而對(duì)于Makefile的語法如果單單能夠要求讀懂的話,也是比較簡(jiǎn)單。


一般情況,在一個(gè)項(xiàng)目中,用Makefile就完全能夠進(jìn)行項(xiàng)目管理了。但一些項(xiàng)目會(huì)由像Rules.mk,Post.mk之類的東西讓我們感到望而生畏,仿佛Make是一項(xiàng)深不可測(cè)的東西。其實(shí)Rules.mk和Post.mk1.mk 2.mk沒有什么區(qū)別。在一個(gè)論壇里面有下面一句話:


IIRC, traditionally, when people set up Makefiles and used files named rules.mk and make.mk, they put all the platform-independent stuff in make.mk, and all the platform-specific stuff in rules.mk. And then their Makefiles just included those, and each Makefile contained the things specific to each thing that was being built (like source filenames and such).





關(guān)于Makefile的學(xué)習(xí),有一本介紹Makefile的電子書,寫得非常好,它是由陳皓撰寫,內(nèi)容與文筆一樣的優(yōu)秀的–《跟我一起寫Makefile》。需要下載的朋友,可以google之。BTW,能夠表達(dá)能力極強(qiáng)的程序員著實(shí)太少,倘若都能夠像陳皓這樣,我們國(guó)家的計(jì)算機(jī)事業(yè)應(yīng)該比印度高不少了吧。他的主頁:http://。


<!—全文完—>


附錄:

關(guān)于項(xiàng)目上的東西,以后時(shí)間久了,看它就可以了。

xenarm中的Makefile

Makefile生成的目標(biāo)文件有4個(gè): xen-bin xen xen.gz xen-syms


xen-bin 

arch/arm/Makefile 

17 $(TARGET): $(TARGET)-bin $(TARGET)-syms

18     @cp $(TARGET)-syms $@

fuck,xen-syms和xen原來是一個(gè)東西!




… 

29 $(TARGET)-bin: $(TARGET)-syms

30     $(OBJCOPY) $(OBJCOPYFLAGS) $< $@


xen-syms

 20 $(TARGET)-syms: arch-$(TARGET_MACHINE)/start.o $(ALL_OBJS) xen.lds


 21     $(OBJCOPY) -I binary -O elf32-littlearm -B arm 24.bmp image.o

 22     $(OBJCOPY) -I binary -O elf32-littlearm -B arm 8×16 en.o

 23     #$(OBJCOPY) -I binary -O elf32-littlearm -B arm shut.wav sound.o

 24     #$(OBJCOPY) -I binary -O elf32-littlearm -B arm mini mini.o

 25     $(LD) $(LDFLAGS) -N -T xen.lds arch-$(TARGET_MACHINE)/start.o $(ALL_OBJS    ) en.o image.o -o $@ 



xen


./Rules.mk

 30 TARGET  := $(BASEDIR)/xen


xen.gz

./Makefile


 18 $(TARGET).gz: $(TARGET)

 19     gzip -f -9 < $< > $@.new

 20     mv $@.new $@




Li Haifeng
Laboratory of Service Computing Technology and System
Home page:http://




Post Footer automatically generated by wp-posturl plugin for wordpress.





May 7th, 2011 in
Uncategorized |
暫無評(píng)論






 

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多