SlideShare a Scribd company logo
1 of 31
Download to read offline
PORTING ANDROID TO
BRAND-NEW CPU ARCHITECTURE
新規CPUアーキテクチャにアンドロイドの移植




          Luse Cheng <lusecheng@gmail.com>
          August 21, 2011 @ COSCUP
自我介紹
 Experience
   Compiler Lead at An Embedded CPU IP Company
   Compiler Engineer at An Embedded CPU IP Company


 Quick summary
   Full-time Open-Source Developer
   Part-time Open-Source Contributor


 國民革命軍軍人(DIRDS:國四無雙)
 專長: 屠龍之技 (Compiler)
An Embedded CPU IP Company
 Andes Technology Corporation
   32-bit Embedded CPU IP Company
   Brand-new 32/16 mixed ISA
   本土 32-bit 嵌入式處理系智財
   簡單的說就是台灣的 ARM
   或者說 ARM 就是英國 Andes (笑)


 EEtimes 的 scouting report
   Taiwan nurtures the next ARM
About This Session
 Android = Armdroid
   Android is arm-awareness product
 Porting to non-ARM platform
   x86 in not included: Android-x86 is very good project
   x86 is a faster CPU than ARM
   It’s good reference for us
 Reference platform at this session
   Andes architecture
Agenda
 Brand new CPU architecture?
   Platform quick-review
 OK, let go !
   Pre-requirement, bring up
 Life is not fair, get used to it
   Android porting guideline
 How do you do your best?
   Optimization
Brand new CPU architecture?
 Andes ADP-AG102
   N1233-F * 2 (533 MHz)
     With Single/Double FPU
     With SW cache-coherence
   RAM: DDR-II 512 MB
   GPU: XG22 2D-Only GPU
     Output: D-SUB
     800x600
   ROOTFS: SDCARD
   USB Keyboard, Mouse
Target Android Version
 We use Froyo with tag 2.2.1


 Why Froyo?
   Andes BSP: Linux kernel 2.6.32
   ADP-AG102 lack of 3D GPU
   Can use over 80% Android AP

                                     Version               API level   Distribution
 Why tag 2.2.1?                     3.x.x Honeycomb       11-13       0.9%
                                     2.3.x Gingerbread     9-10        18.6%
   Can use 32-bit host              2.2.x Froyo
                                     2.0.x /2.1.x Eclair
                                                           8
                                                           5-7
                                                                       59.4%
                                                                       17.5%
                                     1.6 Donut             4           2.2%
                                     1.5 Cupcake           3           1.4%
                                                            From: Wikipedia (Android)
Agenda
 Brand new CPU architecture?
   Platform quick-review
 OK, let go !
   Pre-requirement, bring up
 Life is not fair, get used to it
   Android porting guideline
 How do you do your best?
   Optimization
OK, let go !
 bring up 的最高指導原則: 先求有再求好


 Pre-requirement
  1. A Workable Environment (Real-Board or Virtual-Board)
      至少要有開發板或模擬器
  2. A Workable GNU-Toolchain
      Froyo need : GCC 4.4 + Binutils 2.19
      如果沒有怎麼辦?
          如果有別的版本 (like GCC-4.2), 就使用別的版本
  3. A Workable BSP (Board support package)
      最好的情況: BSP 也是使用 2.6.32 系列的 Linux Kernel
      事實上能找到一個動得很好的 BSP 其實不是簡單的事
A Workable BSP
 Make sure BSP is workable on Linux environment
 From Linux to Android-Linux
    We must think then as two similar platform, but different
 Reference change
    Linux kernel
       TLS system call
       Integrate Android driver (No-ASM)
       Linux kernel Bug Fix
         Deadlock in page fault handling
       arch/<arch-name>/kernel/time.c
         Add function save_time_delta to support android wakelock
 Make sure Android-Linux BSP is workable
Porting Android Build System
 Folder <ROOT>/build
   Arm-awareness !!
      EX: core/binary.mk


 Reference change
   Add TARGET_linux-<arch>.mk
   Add Linker scirpt <arch>elf.x and <arch>elf.xsc
   Toolchain path in core/envsetup.mk
   MISC Change:
       Fix build message with hard-coding “ARM” or “Thumb”
       Add TARGET_ARCH variable
   Use <Vendor-board>.mk
Porting Android Libc (bionic)
 Porting Bionic
    如果已經有 uclibc 或 glibc 的 port, 應該不是件難事
    非得需要使用組合語言的地方
       System call Wrapper, Startup code
       Setjmp / Longjmp, Atomic operation


 Reference change
    Libc : Syscall, Kernel Header
       libc/tools/bionic_utils.py
       libc/tools/gensyscalls.py
       MISC change
    Libm : fenv.h
    Libdl: Add Architecture define (#if defined(<arch_name>))
    Linker : Reference to ld.so (glibc)
Porting Dalvik VM
 非常幸運, 如果只是要能動, 幾乎不用 Porting
   Dalvik VM 已經包含了一個 generic 用 c 寫的直譯器
   非得需要 Porting 的部分 : JNI
     使用組合語言來實作
       需要再寫一個 Hint 的產生方式
     Alternative: Porting libffi (foreign function interface library)
   以上兩種方法其實都需要寫組合語言
 DVM Optimization
   Fast Interpreter: 使用組語來處理 Dalvik 指令
   JITTER: 使用動態編譯器來最佳化熱區 (快取機制)
Porting External Package
 <ROOT>/external
 其實不太需要 Porting
 Fix misc compilation error and makefile change
    Like external/webkit


 Elfutils :
    Sync EM number and RELOC type of Architecture
Build Whole Android Image
   make TARGET_ARCH=nds32 -j4
   Waiting for build complete ….


Finding NOTICE files: out/target/product/generic/obj/NOTICE_FILES/hash-timestamp
Combining NOTICE files: out/target/product/generic/obj/NOTICE.html
Target system fs image:
out/target/product/generic/obj/PACKAGING/systemimage_unopt_intermediates/system.img
Install system fs image: out/target/product/generic/system.img
Installed file list: out/target/product/generic/installed-files.txt


   OK, We can compile whole android for brand-new
     CPU Architecture now
Configuration !
 Configuration! You can porting android to
 brand-new CPU architecture now!

 不過如果你是工程師, 就會知道這一切才剛開始


 If you are an engineer, you know that everything is
 just beginning

 あなたがエンジニアである場合, すべてはただ今始
 まったばかりです
Agenda
 Brand new CPU architecture?
   Platform quick-review
 OK, let go !
   Pre-requirement, bring up
 Life is not fair, get used to it
   Android porting guideline
 How do you do your best?
   Optimization
身為一個 non-ARM 的 Android Porter …




         +           =?

                         ・´
                          ェ`・
Life is not fair, get used to it
 Battery Problem
   基本上是一個 Porting 到 non-Phone 的platform 最容易
    遇到也必須要解決的一個問題
   Google 上答案很多, 挑一個喜歡的帶回家 (!?)


 10 秒鐘的幸福
   Android Activity Manager Service 預設的 Timeout
   很可惜台灣的CPU 不能享受這個奢華的幸福
Life is not fair, get used to it
 電源管理
   一看就知道很手機, 不改就會死人
   Hack 掉一些很手機的 code


 我很低調, 我不愛GPS !
   老是喜歡讓大家使用beta產品的某公司首頁改版後, 沒
    有GPS 的Android上某公司首頁後瀏覽器會 crash!
   只好使用 那家公司唯一不是 beta 的產品 : Search
     改 framework/base 的
      location/java/android/location/LocationManager.java
使用者介面
 這些問題都解決後, 大概就可以正常運作了
  Android 要跑起來很簡單, 可是要跑的順很困難
  這都是使用者介面的陰謀 !
    因為 Android App 開發者很愛 OpenGL
    這是一個3D的時代,開發者很愛 OpenGL不為過


 我們台灣人一向勤儉, IC裡面有個殘廢的GPU也是
很正常的事情
  或者GPU只有2D engine, 沒有 OpenGL 也不意外
  很剛好, 我們的開發版也是這樣
Agenda
 Brand new CPU architecture?
   Platform quick-review
 OK, let go !
   Pre-requirement, bring up
 Life is not fair, get used to it
   Android porting guideline
 How do you do your best?
   Optimization
Why Don't You Do Your Best?




                    Source: http://yoake-kibo.jugem.jp/?eid=1671
How do you do your best?
 Q:Why Don't You Do Your Best?
 A: Life is not fair, get used to it


 Era of Time-to-Market
   能不能做到最好還要問有沒有時間做到最好


 所以我們在這邊探討不探討”為何不”,只探討”如何”
   身為產品洪流下, 工程師的宿命
Compile once, Compiler Everywhere!
 這是一個無所不在Compiler的時代

 Android 裡面存在多個 Dynamic Compiler (JITTER)
    Dalvik VM
    Pixelflinger : CodeflingerJIT (Graphics 相關)
    WebKit (V8)
    Render Script


 Dynamic Compiler 都需要 Porting, 而且要真的能動的是需要
  蠻大的功夫的
     Porting Dynamic Compiler 需要的背景和熟悉度很高
     所以要 Porting 到 brand-new CPU 越來越不利了
     雖然我的專長是 Compiler 領域, 可是我選擇不弄這些東西
     因為Dynamic Compiler會動是一回事, 可是沒有錯又是另一回事
How do you do your best?
 修身齊家治國平天下
   欲爭服 Android 必先征服 GUI


 Optimization Guideline
   Q: 如果不要 Porting Pixelflinger 中的 Dynamic Compiler,
    那還能取得讓使用者可以接受的加速嗎?
   A: 雖然Google的字典裡只有放棄, 可是我們的字典裡
    沒有放棄, 確實還是有辦法的
Optimization Guideline: Library
 在圖形系統當中,複製是非常常見的事情,而他們通
 常也是一個最簡單可以效果很好的施力點
  memcpy … etc


 參考一下ARM平台中,那些其他的 Library Function
 有使用組合語言
  通常要把那些 Library Function 用組合語言重寫並不太
   困難, 這也是一個不用自己去 profile 出瓶頸點的簡單
   解法
Optimization Guideline: GUI
 從 Surfaceflinger 下手
   Surfaceflinger 還有一些最佳化的空間
   可以參考其他Project的修正 (android-x86 and 0xdroid)


 動不動就刷新整個畫面是有問題的
   不過 Android 常常這麼做
   可以去找出那些元凶


 從 Scanline shortcut 下手
   打開 LOGW("using generic (slow) pixel-pipeline");
   觀察為什麼會使用到 generic pixel-pipeline
   新增新的 shortcut
       Tips: Back port 新的 shortcut
Experimental result of Scanline shortcut
Summary
 Andes Android 的 Demo Video
    http://www.youtube.com/watch?v=-XxlP55v2is&feature=related


 Special Thanks
    0xlab and Andorid-x86 project


 Summary (Porting android to brand-new CPU architecture)
    Bring-up
       BSP (Kernel & Driver)
       Android System
    Optimization
       GUI Optimization with Surfaceflinger
       GUI Optimization with Scanline shortcut
Any Question ?

More Related Content

What's hot

icecream / icecc:分散式編譯系統簡介
icecream / icecc:分散式編譯系統簡介icecream / icecc:分散式編譯系統簡介
icecream / icecc:分散式編譯系統簡介Kito Cheng
 
嵌入式平台移植技巧概說
嵌入式平台移植技巧概說嵌入式平台移植技巧概說
嵌入式平台移植技巧概說Joseph Lu
 
開放原始碼作為新事業: 台灣本土經驗談 (COSCUP 2011)
開放原始碼作為新事業: 台灣本土經驗談 (COSCUP 2011)開放原始碼作為新事業: 台灣本土經驗談 (COSCUP 2011)
開放原始碼作為新事業: 台灣本土經驗談 (COSCUP 2011)National Cheng Kung University
 
Recycle Open Source Projects
Recycle Open Source ProjectsRecycle Open Source Projects
Recycle Open Source ProjectsGeorge Ang
 
NCURSES Programming HOWTO
NCURSES Programming HOWTONCURSES Programming HOWTO
NCURSES Programming HOWTOeastsky
 
FreeBSD documentation translation
FreeBSD documentation translationFreeBSD documentation translation
FreeBSD documentation translationRaycherng Yu
 
.net framework from 1.0 -> 4.0
.net framework from 1.0 -> 4.0.net framework from 1.0 -> 4.0
.net framework from 1.0 -> 4.0ligaoren
 
C++工程实践
C++工程实践C++工程实践
C++工程实践Shuo Chen
 
Regular expression
Regular expressionRegular expression
Regular expressioncri fan
 
系統程式 -- 第 1 章 系統軟體
系統程式 -- 第 1 章 系統軟體系統程式 -- 第 1 章 系統軟體
系統程式 -- 第 1 章 系統軟體鍾誠 陳鍾誠
 
Introduction To Direct Show
Introduction To Direct ShowIntroduction To Direct Show
Introduction To Direct Showguestce3937
 

What's hot (19)

icecream / icecc:分散式編譯系統簡介
icecream / icecc:分散式編譯系統簡介icecream / icecc:分散式編譯系統簡介
icecream / icecc:分散式編譯系統簡介
 
Taiwanese Experience in IT
Taiwanese Experience in ITTaiwanese Experience in IT
Taiwanese Experience in IT
 
嵌入式平台移植技巧概說
嵌入式平台移植技巧概說嵌入式平台移植技巧概說
嵌入式平台移植技巧概說
 
開放原始碼作為新事業: 台灣本土經驗談 (COSCUP 2011)
開放原始碼作為新事業: 台灣本土經驗談 (COSCUP 2011)開放原始碼作為新事業: 台灣本土經驗談 (COSCUP 2011)
開放原始碼作為新事業: 台灣本土經驗談 (COSCUP 2011)
 
回顧 GNU/Linux 中文資訊化進展與未來機會
回顧 GNU/Linux 中文資訊化進展與未來機會回顧 GNU/Linux 中文資訊化進展與未來機會
回顧 GNU/Linux 中文資訊化進展與未來機會
 
Recycle Open Source Projects
Recycle Open Source ProjectsRecycle Open Source Projects
Recycle Open Source Projects
 
2016 年春季嵌入式作業系統課程說明
2016 年春季嵌入式作業系統課程說明2016 年春季嵌入式作業系統課程說明
2016 年春季嵌入式作業系統課程說明
 
NCURSES Programming HOWTO
NCURSES Programming HOWTONCURSES Programming HOWTO
NCURSES Programming HOWTO
 
C#
C#C#
C#
 
軟體工程(總結篇)
軟體工程(總結篇)軟體工程(總結篇)
軟體工程(總結篇)
 
系統程式 -- 第 5 章
系統程式 -- 第 5 章系統程式 -- 第 5 章
系統程式 -- 第 5 章
 
FreeBSD documentation translation
FreeBSD documentation translationFreeBSD documentation translation
FreeBSD documentation translation
 
.net framework from 1.0 -> 4.0
.net framework from 1.0 -> 4.0.net framework from 1.0 -> 4.0
.net framework from 1.0 -> 4.0
 
Jni文档
Jni文档Jni文档
Jni文档
 
C++工程实践
C++工程实践C++工程实践
C++工程实践
 
Regular expression
Regular expressionRegular expression
Regular expression
 
系統程式 -- 第 1 章 系統軟體
系統程式 -- 第 1 章 系統軟體系統程式 -- 第 1 章 系統軟體
系統程式 -- 第 1 章 系統軟體
 
Android JNI
Android JNIAndroid JNI
Android JNI
 
Introduction To Direct Show
Introduction To Direct ShowIntroduction To Direct Show
Introduction To Direct Show
 

Viewers also liked

Android nougat
Android nougatAndroid nougat
Android nougatBeApp
 
CPU Architectures for Mobile Phone Devices
CPU Architectures for Mobile Phone DevicesCPU Architectures for Mobile Phone Devices
CPU Architectures for Mobile Phone Devicessagar chansaulia
 
Nougat 7.0 seminar
Nougat 7.0 seminarNougat 7.0 seminar
Nougat 7.0 seminarVen Esh
 
Android Nougat- Sweet Treat for Users
Android Nougat- Sweet Treat for UsersAndroid Nougat- Sweet Treat for Users
Android Nougat- Sweet Treat for Userstechugo
 
What is Android OS in ppt ?
What is Android OS in ppt ? What is Android OS in ppt ?
What is Android OS in ppt ? SoonTips.com
 
Android OS Presentation
Android OS PresentationAndroid OS Presentation
Android OS Presentationhession25819
 
Model Template Presentation PowerPoint
Model Template Presentation PowerPointModel Template Presentation PowerPoint
Model Template Presentation PowerPointHoai Nam NGUYEN
 
My presentation on Android in my college
My presentation on Android in my collegeMy presentation on Android in my college
My presentation on Android in my collegeSneha Lata
 
Android seminar-presentation
Android seminar-presentationAndroid seminar-presentation
Android seminar-presentationconnectshilpa
 
Android Entwicklung
Android EntwicklungAndroid Entwicklung
Android Entwicklungfranky1888
 
Presentation on Android operating system
Presentation on Android operating systemPresentation on Android operating system
Presentation on Android operating systemSalma Begum
 
Designing Teams for Emerging Challenges
Designing Teams for Emerging ChallengesDesigning Teams for Emerging Challenges
Designing Teams for Emerging ChallengesAaron Irizarry
 
TEDx Manchester: AI & The Future of Work
TEDx Manchester: AI & The Future of WorkTEDx Manchester: AI & The Future of Work
TEDx Manchester: AI & The Future of WorkVolker Hirsch
 
How to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your NicheHow to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your NicheLeslie Samuel
 

Viewers also liked (19)

Android 7.0 Nougat
Android 7.0 NougatAndroid 7.0 Nougat
Android 7.0 Nougat
 
Android nougat
Android nougatAndroid nougat
Android nougat
 
CPU Architectures for Mobile Phone Devices
CPU Architectures for Mobile Phone DevicesCPU Architectures for Mobile Phone Devices
CPU Architectures for Mobile Phone Devices
 
Nougat 7.0 seminar
Nougat 7.0 seminarNougat 7.0 seminar
Nougat 7.0 seminar
 
Android Nougat- Sweet Treat for Users
Android Nougat- Sweet Treat for UsersAndroid Nougat- Sweet Treat for Users
Android Nougat- Sweet Treat for Users
 
Cpu scheduling
Cpu schedulingCpu scheduling
Cpu scheduling
 
What is Android OS in ppt ?
What is Android OS in ppt ? What is Android OS in ppt ?
What is Android OS in ppt ?
 
Android OS Presentation
Android OS PresentationAndroid OS Presentation
Android OS Presentation
 
Model Template Presentation PowerPoint
Model Template Presentation PowerPointModel Template Presentation PowerPoint
Model Template Presentation PowerPoint
 
My presentation on Android in my college
My presentation on Android in my collegeMy presentation on Android in my college
My presentation on Android in my college
 
Android seminar ppt
Android seminar pptAndroid seminar ppt
Android seminar ppt
 
Android seminar-presentation
Android seminar-presentationAndroid seminar-presentation
Android seminar-presentation
 
Android ppt
Android pptAndroid ppt
Android ppt
 
Android Entwicklung
Android EntwicklungAndroid Entwicklung
Android Entwicklung
 
Presentation on Android operating system
Presentation on Android operating systemPresentation on Android operating system
Presentation on Android operating system
 
Android ppt
Android ppt Android ppt
Android ppt
 
Designing Teams for Emerging Challenges
Designing Teams for Emerging ChallengesDesigning Teams for Emerging Challenges
Designing Teams for Emerging Challenges
 
TEDx Manchester: AI & The Future of Work
TEDx Manchester: AI & The Future of WorkTEDx Manchester: AI & The Future of Work
TEDx Manchester: AI & The Future of Work
 
How to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your NicheHow to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your Niche
 

Similar to Coscup2011: porting android to brand-new cpu architecture

容器驅動開發 - .NET Conf 2017 @ 台中
容器驅動開發 - .NET Conf 2017 @ 台中容器驅動開發 - .NET Conf 2017 @ 台中
容器驅動開發 - .NET Conf 2017 @ 台中Andrew Wu
 
Uc gui中文手册
Uc gui中文手册Uc gui中文手册
Uc gui中文手册호연 최
 
用 Drone 打造 輕量級容器持續交付平台
用 Drone 打造輕量級容器持續交付平台用 Drone 打造輕量級容器持續交付平台
用 Drone 打造 輕量級容器持續交付平台Bo-Yi Wu
 
基于Cocos2 d x二次开发的自有引擎方案分享-mobile 2d framework en
基于Cocos2 d x二次开发的自有引擎方案分享-mobile 2d framework en基于Cocos2 d x二次开发的自有引擎方案分享-mobile 2d framework en
基于Cocos2 d x二次开发的自有引擎方案分享-mobile 2d framework en增强 杜
 
程式人雜誌 -- 2013 年 2 月號
程式人雜誌 -- 2013 年 2 月號程式人雜誌 -- 2013 年 2 月號
程式人雜誌 -- 2013 年 2 月號鍾誠 陳鍾誠
 
容器與 Gitlab CI 應用
容器與 Gitlab CI 應用容器與 Gitlab CI 應用
容器與 Gitlab CI 應用Philip Zheng
 
大话Php之性能
大话Php之性能大话Php之性能
大话Php之性能liqiang xu
 
和Android源代码一起工作 | 海豚浏览器 胡继堂
和Android源代码一起工作 | 海豚浏览器 胡继堂和Android源代码一起工作 | 海豚浏览器 胡继堂
和Android源代码一起工作 | 海豚浏览器 胡继堂imShining @DevCamp
 
Bluemix Node-Red Part II
Bluemix Node-Red Part IIBluemix Node-Red Part II
Bluemix Node-Red Part IIJoseph Chang
 
TI702_Android_MID
TI702_Android_MIDTI702_Android_MID
TI702_Android_MIDguestd2ec7f
 
CICD Workshop 20180922
CICD Workshop 20180922CICD Workshop 20180922
CICD Workshop 20180922Earou Huang
 
Firefox OS Overview
Firefox OS OverviewFirefox OS Overview
Firefox OS OverviewYan-ren Tsai
 
Android gradle 从入门到gg 1
Android gradle 从入门到gg 1Android gradle 从入门到gg 1
Android gradle 从入门到gg 1Jun Liu
 
Micro2440 manual 20100609
Micro2440 manual 20100609Micro2440 manual 20100609
Micro2440 manual 20100609jrogulj
 
Docker 基礎介紹與實戰
Docker 基礎介紹與實戰Docker 基礎介紹與實戰
Docker 基礎介紹與實戰Bo-Yi Wu
 
ARM ® mbed™ 平台之研究及實作
ARM ® mbed™ 平台之研究及實作ARM ® mbed™ 平台之研究及實作
ARM ® mbed™ 平台之研究及實作艾鍗科技
 

Similar to Coscup2011: porting android to brand-new cpu architecture (20)

Build Your Own Android Toolchain from scratch
Build Your Own Android Toolchain from scratchBuild Your Own Android Toolchain from scratch
Build Your Own Android Toolchain from scratch
 
容器驅動開發 - .NET Conf 2017 @ 台中
容器驅動開發 - .NET Conf 2017 @ 台中容器驅動開發 - .NET Conf 2017 @ 台中
容器驅動開發 - .NET Conf 2017 @ 台中
 
Uc gui中文手册
Uc gui中文手册Uc gui中文手册
Uc gui中文手册
 
用 Drone 打造 輕量級容器持續交付平台
用 Drone 打造輕量級容器持續交付平台用 Drone 打造輕量級容器持續交付平台
用 Drone 打造 輕量級容器持續交付平台
 
基于Cocos2 d x二次开发的自有引擎方案分享-mobile 2d framework en
基于Cocos2 d x二次开发的自有引擎方案分享-mobile 2d framework en基于Cocos2 d x二次开发的自有引擎方案分享-mobile 2d framework en
基于Cocos2 d x二次开发的自有引擎方案分享-mobile 2d framework en
 
程式人雜誌 -- 2013 年 2 月號
程式人雜誌 -- 2013 年 2 月號程式人雜誌 -- 2013 年 2 月號
程式人雜誌 -- 2013 年 2 月號
 
容器與 Gitlab CI 應用
容器與 Gitlab CI 應用容器與 Gitlab CI 應用
容器與 Gitlab CI 應用
 
大话Php之性能
大话Php之性能大话Php之性能
大话Php之性能
 
和Android源代码一起工作 | 海豚浏览器 胡继堂
和Android源代码一起工作 | 海豚浏览器 胡继堂和Android源代码一起工作 | 海豚浏览器 胡继堂
和Android源代码一起工作 | 海豚浏览器 胡继堂
 
Bluemix Node-Red Part II
Bluemix Node-Red Part IIBluemix Node-Red Part II
Bluemix Node-Red Part II
 
TI702_Android_MID
TI702_Android_MIDTI702_Android_MID
TI702_Android_MID
 
Android ADK
Android ADKAndroid ADK
Android ADK
 
CICD Workshop 20180922
CICD Workshop 20180922CICD Workshop 20180922
CICD Workshop 20180922
 
Windows 8.1 app 研習營三小時
Windows 8.1 app 研習營三小時Windows 8.1 app 研習營三小時
Windows 8.1 app 研習營三小時
 
Firefox OS Overview
Firefox OS OverviewFirefox OS Overview
Firefox OS Overview
 
LinkIt 7697 IoT tutorial
LinkIt 7697 IoT tutorialLinkIt 7697 IoT tutorial
LinkIt 7697 IoT tutorial
 
Android gradle 从入门到gg 1
Android gradle 从入门到gg 1Android gradle 从入门到gg 1
Android gradle 从入门到gg 1
 
Micro2440 manual 20100609
Micro2440 manual 20100609Micro2440 manual 20100609
Micro2440 manual 20100609
 
Docker 基礎介紹與實戰
Docker 基礎介紹與實戰Docker 基礎介紹與實戰
Docker 基礎介紹與實戰
 
ARM ® mbed™ 平台之研究及實作
ARM ® mbed™ 平台之研究及實作ARM ® mbed™ 平台之研究及實作
ARM ® mbed™ 平台之研究及實作
 

Coscup2011: porting android to brand-new cpu architecture

  • 1. PORTING ANDROID TO BRAND-NEW CPU ARCHITECTURE 新規CPUアーキテクチャにアンドロイドの移植 Luse Cheng <lusecheng@gmail.com> August 21, 2011 @ COSCUP
  • 2. 自我介紹  Experience  Compiler Lead at An Embedded CPU IP Company  Compiler Engineer at An Embedded CPU IP Company  Quick summary  Full-time Open-Source Developer  Part-time Open-Source Contributor  國民革命軍軍人(DIRDS:國四無雙)  專長: 屠龍之技 (Compiler)
  • 3. An Embedded CPU IP Company  Andes Technology Corporation  32-bit Embedded CPU IP Company  Brand-new 32/16 mixed ISA  本土 32-bit 嵌入式處理系智財  簡單的說就是台灣的 ARM  或者說 ARM 就是英國 Andes (笑)  EEtimes 的 scouting report  Taiwan nurtures the next ARM
  • 4. About This Session  Android = Armdroid  Android is arm-awareness product  Porting to non-ARM platform  x86 in not included: Android-x86 is very good project  x86 is a faster CPU than ARM  It’s good reference for us  Reference platform at this session  Andes architecture
  • 5. Agenda  Brand new CPU architecture?  Platform quick-review  OK, let go !  Pre-requirement, bring up  Life is not fair, get used to it  Android porting guideline  How do you do your best?  Optimization
  • 6. Brand new CPU architecture?  Andes ADP-AG102  N1233-F * 2 (533 MHz)  With Single/Double FPU  With SW cache-coherence  RAM: DDR-II 512 MB  GPU: XG22 2D-Only GPU  Output: D-SUB  800x600  ROOTFS: SDCARD  USB Keyboard, Mouse
  • 7. Target Android Version  We use Froyo with tag 2.2.1  Why Froyo?  Andes BSP: Linux kernel 2.6.32  ADP-AG102 lack of 3D GPU  Can use over 80% Android AP Version API level Distribution  Why tag 2.2.1? 3.x.x Honeycomb 11-13 0.9% 2.3.x Gingerbread 9-10 18.6%  Can use 32-bit host 2.2.x Froyo 2.0.x /2.1.x Eclair 8 5-7 59.4% 17.5% 1.6 Donut 4 2.2% 1.5 Cupcake 3 1.4% From: Wikipedia (Android)
  • 8. Agenda  Brand new CPU architecture?  Platform quick-review  OK, let go !  Pre-requirement, bring up  Life is not fair, get used to it  Android porting guideline  How do you do your best?  Optimization
  • 9. OK, let go !  bring up 的最高指導原則: 先求有再求好  Pre-requirement 1. A Workable Environment (Real-Board or Virtual-Board)  至少要有開發板或模擬器 2. A Workable GNU-Toolchain  Froyo need : GCC 4.4 + Binutils 2.19  如果沒有怎麼辦?  如果有別的版本 (like GCC-4.2), 就使用別的版本 3. A Workable BSP (Board support package)  最好的情況: BSP 也是使用 2.6.32 系列的 Linux Kernel  事實上能找到一個動得很好的 BSP 其實不是簡單的事
  • 10. A Workable BSP  Make sure BSP is workable on Linux environment  From Linux to Android-Linux  We must think then as two similar platform, but different  Reference change  Linux kernel  TLS system call  Integrate Android driver (No-ASM)  Linux kernel Bug Fix  Deadlock in page fault handling  arch/<arch-name>/kernel/time.c  Add function save_time_delta to support android wakelock  Make sure Android-Linux BSP is workable
  • 11. Porting Android Build System  Folder <ROOT>/build  Arm-awareness !!  EX: core/binary.mk  Reference change  Add TARGET_linux-<arch>.mk  Add Linker scirpt <arch>elf.x and <arch>elf.xsc  Toolchain path in core/envsetup.mk  MISC Change:  Fix build message with hard-coding “ARM” or “Thumb”  Add TARGET_ARCH variable  Use <Vendor-board>.mk
  • 12. Porting Android Libc (bionic)  Porting Bionic  如果已經有 uclibc 或 glibc 的 port, 應該不是件難事  非得需要使用組合語言的地方  System call Wrapper, Startup code  Setjmp / Longjmp, Atomic operation  Reference change  Libc : Syscall, Kernel Header  libc/tools/bionic_utils.py  libc/tools/gensyscalls.py  MISC change  Libm : fenv.h  Libdl: Add Architecture define (#if defined(<arch_name>))  Linker : Reference to ld.so (glibc)
  • 13. Porting Dalvik VM  非常幸運, 如果只是要能動, 幾乎不用 Porting  Dalvik VM 已經包含了一個 generic 用 c 寫的直譯器  非得需要 Porting 的部分 : JNI  使用組合語言來實作  需要再寫一個 Hint 的產生方式  Alternative: Porting libffi (foreign function interface library)  以上兩種方法其實都需要寫組合語言  DVM Optimization  Fast Interpreter: 使用組語來處理 Dalvik 指令  JITTER: 使用動態編譯器來最佳化熱區 (快取機制)
  • 14. Porting External Package  <ROOT>/external  其實不太需要 Porting  Fix misc compilation error and makefile change  Like external/webkit  Elfutils :  Sync EM number and RELOC type of Architecture
  • 15. Build Whole Android Image  make TARGET_ARCH=nds32 -j4  Waiting for build complete …. Finding NOTICE files: out/target/product/generic/obj/NOTICE_FILES/hash-timestamp Combining NOTICE files: out/target/product/generic/obj/NOTICE.html Target system fs image: out/target/product/generic/obj/PACKAGING/systemimage_unopt_intermediates/system.img Install system fs image: out/target/product/generic/system.img Installed file list: out/target/product/generic/installed-files.txt  OK, We can compile whole android for brand-new CPU Architecture now
  • 16. Configuration !  Configuration! You can porting android to brand-new CPU architecture now!  不過如果你是工程師, 就會知道這一切才剛開始  If you are an engineer, you know that everything is just beginning  あなたがエンジニアである場合, すべてはただ今始 まったばかりです
  • 17. Agenda  Brand new CPU architecture?  Platform quick-review  OK, let go !  Pre-requirement, bring up  Life is not fair, get used to it  Android porting guideline  How do you do your best?  Optimization
  • 18. 身為一個 non-ARM 的 Android Porter … + =? ・´ ェ`・
  • 19. Life is not fair, get used to it  Battery Problem  基本上是一個 Porting 到 non-Phone 的platform 最容易 遇到也必須要解決的一個問題  Google 上答案很多, 挑一個喜歡的帶回家 (!?)  10 秒鐘的幸福  Android Activity Manager Service 預設的 Timeout  很可惜台灣的CPU 不能享受這個奢華的幸福
  • 20. Life is not fair, get used to it  電源管理  一看就知道很手機, 不改就會死人  Hack 掉一些很手機的 code  我很低調, 我不愛GPS !  老是喜歡讓大家使用beta產品的某公司首頁改版後, 沒 有GPS 的Android上某公司首頁後瀏覽器會 crash!  只好使用 那家公司唯一不是 beta 的產品 : Search  改 framework/base 的 location/java/android/location/LocationManager.java
  • 21. 使用者介面  這些問題都解決後, 大概就可以正常運作了  Android 要跑起來很簡單, 可是要跑的順很困難  這都是使用者介面的陰謀 !  因為 Android App 開發者很愛 OpenGL  這是一個3D的時代,開發者很愛 OpenGL不為過  我們台灣人一向勤儉, IC裡面有個殘廢的GPU也是 很正常的事情  或者GPU只有2D engine, 沒有 OpenGL 也不意外  很剛好, 我們的開發版也是這樣
  • 22. Agenda  Brand new CPU architecture?  Platform quick-review  OK, let go !  Pre-requirement, bring up  Life is not fair, get used to it  Android porting guideline  How do you do your best?  Optimization
  • 23. Why Don't You Do Your Best? Source: http://yoake-kibo.jugem.jp/?eid=1671
  • 24. How do you do your best?  Q:Why Don't You Do Your Best?  A: Life is not fair, get used to it  Era of Time-to-Market  能不能做到最好還要問有沒有時間做到最好  所以我們在這邊探討不探討”為何不”,只探討”如何”  身為產品洪流下, 工程師的宿命
  • 25. Compile once, Compiler Everywhere!  這是一個無所不在Compiler的時代  Android 裡面存在多個 Dynamic Compiler (JITTER)  Dalvik VM  Pixelflinger : CodeflingerJIT (Graphics 相關)  WebKit (V8)  Render Script  Dynamic Compiler 都需要 Porting, 而且要真的能動的是需要 蠻大的功夫的  Porting Dynamic Compiler 需要的背景和熟悉度很高  所以要 Porting 到 brand-new CPU 越來越不利了  雖然我的專長是 Compiler 領域, 可是我選擇不弄這些東西  因為Dynamic Compiler會動是一回事, 可是沒有錯又是另一回事
  • 26. How do you do your best?  修身齊家治國平天下  欲爭服 Android 必先征服 GUI  Optimization Guideline  Q: 如果不要 Porting Pixelflinger 中的 Dynamic Compiler, 那還能取得讓使用者可以接受的加速嗎?  A: 雖然Google的字典裡只有放棄, 可是我們的字典裡 沒有放棄, 確實還是有辦法的
  • 27. Optimization Guideline: Library  在圖形系統當中,複製是非常常見的事情,而他們通 常也是一個最簡單可以效果很好的施力點  memcpy … etc  參考一下ARM平台中,那些其他的 Library Function 有使用組合語言  通常要把那些 Library Function 用組合語言重寫並不太 困難, 這也是一個不用自己去 profile 出瓶頸點的簡單 解法
  • 28. Optimization Guideline: GUI  從 Surfaceflinger 下手  Surfaceflinger 還有一些最佳化的空間  可以參考其他Project的修正 (android-x86 and 0xdroid)  動不動就刷新整個畫面是有問題的  不過 Android 常常這麼做  可以去找出那些元凶  從 Scanline shortcut 下手  打開 LOGW("using generic (slow) pixel-pipeline");  觀察為什麼會使用到 generic pixel-pipeline  新增新的 shortcut  Tips: Back port 新的 shortcut
  • 29. Experimental result of Scanline shortcut
  • 30. Summary  Andes Android 的 Demo Video  http://www.youtube.com/watch?v=-XxlP55v2is&feature=related  Special Thanks  0xlab and Andorid-x86 project  Summary (Porting android to brand-new CPU architecture)  Bring-up  BSP (Kernel & Driver)  Android System  Optimization  GUI Optimization with Surfaceflinger  GUI Optimization with Scanline shortcut