SlideShare uma empresa Scribd logo
1 de 82
Baixar para ler offline
實作輕量級 RTOS 網路堆疊
                            Apr 24, 2009


             Jim Huang( 黃敬群 /jserv)
       Email: <jserv.tw@gmail.com>
  Blog: http://blog.linux.org.tw/jserv/
自我介紹

Phone/PDA, GPS, Mobile TV/Digital TV 代工設計
參與自由軟體開發 / 社群組織
 新酷音輸入法
                 Xenomai           Debian Taiwan
 Kaffe.org
                 Orz Microkernel   KDE Taiwan
 GNU Classpath
                 pcmanx            TOSSUG
 FreeDesktop
                 LXDE              0xlab (4/27)
 OpenMoko
                 OpenAVS
 ...
                 ...

  警告:本議程僅探討實務面,忽略理論部份
提綱
動機
Bell 定律:每十年運算型態的移轉
RTOS 與嵌入式裝置的角色
實現 TCP/IP 的難題
回歸現實:剪裁與調適
技術討論
動機

每年寫一套作業系統
當作業 ( 對不起,遲交 )
 JK (2001)
 Orz Microkernel (2006)
 RT nanokernel (2007)
 Jamei RTOS (2007)
 CuRT (2009)
 ??? (2009)
動機   (1)


Everything can
be Orz.
 Orz Microkernel
動機   (2)


Orz Microkernel
的啟發
 學習作業系統與相關的系統程
 式該如何設計
 建立自信:原來一個作業系統
 只需幾 kb 的空間就實做出來
動機   (3)


設計作業系統也
可很有趣
 以實體的機器人設計作為主軸
 體驗如何親手打造嵌入式系統
 並著手設計相關軟硬體建設
動機   (4)

從零到有,設計即時
作業系統
 杜威博士:「作中學」
 RT nanokernel (OSDC.tw 2007)
 Jamei (COSCUP 2007)
 模仿 Linux 經典設計並建構具體而微的
 RTOS
動機   (5)


滿足自動控制系
統需求
 即時處理
 建構嵌入式環境
 網路通訊能力
應用型態
國防軍事
科學搜救探索
彷生物型態
機器人足球賽
動機   (6)

簡化設計,適用更廣
範圍的硬體
 CuRT (2009)
 硬體: Marvell/Intel PXA255
 特徵
     Preemptive Multi-threading
     Priority-base Round-Robin Scheduling
     Thread Management
     Semaphore Management Support
     IPC: mailbox, message queue
Bell 定律:每十年運算
型態的移轉
1980 年代: PC revolution
1990 年代: Internet revolution
2000 年代: embedded revolution
2010 年代: embedded Internet revolution
RTOS 與嵌入式
裝置
enocean.com




Building automation
streetlinenetworks.com




Wirelss parking management
嵌入式無線網路

 Star networks




 Mesh networks
典型嵌入式硬體
        Small microcontroller (microprocessor + I/O)
●



            8- and 16-bit processors
    ●



            Typical memory size
    ●



             1 – 100 k Flash ROM for code
        ●



             0.1 – 10 k RAM for data
        ●



            Typical speed
    ●



             1 – 10 MHz
        ●



        8051, AVR, MSP430, Z80, 6502, ARM, ...
●
設計自己的 RTOS
Jamei = Just Another Microprocessor Embedded
  Infrastructure
     輕巧並可調整組態
     仿造 Linux kernel 部份設計
       arch( 平台相依實做 )
       device driver model
       vfs
     部份 POSIX Thread
     部份 Realtime API (IEEE 1003.1b)
     New BSD License 與 GNU GPLv2( 部份 )
     支援 i386 與 ARM9
RTOS 結構

• Introduction
• Structure         Applications
                                     POSIX
• RTOS Kernel                       Subsystem


• Tasks                                         Use r Mo de

• Memory                                        Ke rne l Mo de

• Timers
                                            Security
                                    Object
• I/O                               Manager Reference
                                            Monitor

                    RTOS-kernel
• IPCs
                                      HAL : Hardware Abstraction Layer
                    Driver/BSP
• Device Driver
• In an Action


                  Custom-Hardware
RTOS Kernel

• Introduction
• Structure
• RTOS Kernel
• Tasks
• Memory
• Timers
• I/O
• IPCs
• Device Driver
• In an Action
ThreadC
RealMain                                     Stack
                                             RealMain
                                             ThreadC
Scheduler                                     Timer
                                              Alarm
               Timer
                                           Task Queue

              Alarm
                                  Action
     serial
                                      Interrupt table
              H/W timer   A/D conv.
    receive
ThreadC
RealMain                                     Stack
                                              Alarm
                                              Timer
Scheduler                                    Scheduler


               Timer
                                           Task Queue
                                             timer task
              Alarm
                                  Action
     serial
                                      Interrupt table
              H/W timer   A/D conv.
    receive
ThreadC
RealMain                                     Stack
                                             Scheduler
                                              Timer
Scheduler                                    ThreadC
                                              Action
               Timer
                                           Task Queue
                                             timer task
              Alarm
                                  Action
     serial
                                      Interrupt table
              H/W timer   A/D conv.
    receive
RTOS Kernel::Tasks
    Task 是 RTOS 最重要的項目
                  RTOS scheduler 必須 determinstic
• Introduction

                    O(1) or O(n)
• Structure
                                             笨蛋,問題在
• RTOS Kernel                                scheduling !
                  Scheduling policy
• Tasks
                    Clock driven
• Memory
• Timers
                    Priority driven (RMS & EDF)
• I/O
                                     new      ready
• IPCs                                                  scheduler
                                     task
• Device Driver
• In an Action
                                                        running
                                                              terminatin
                                              waiting
                                     signal
                                                                 tasks
                                     events
RTOS Kernel::Tasks
         Task 的狀態移轉
• Introduction
• Structure
                                                       Terminate
                                   sleep
• RTOS Kernel
• Tasks
• Memory
                                Start Terminate
• Timers
                                            Get something
• I/O
                  Terminate                                   waiting
                                   ready
• IPCs
• Device Driver
                                               Wait something
• In an Action
                              Context switch

                                                  Interrupt
                                  running                               ISR
                                                  Return
RTOS Kernel::Tasks
         TCB (Task Control Block)
                                                         rt_thread_struct
• Introduction
                                   stack               SAVED_TASK_STATE
                   stack
• Structure
                                                              signals
• RTOS Kernel
• Tasks                                                       events
                   TCB             TCB
• Memory                                                 current_deadline,
                     priority        priority
                     status          status
• Timers                                                       policy
                      stack           stack
• I/O              CPU register    CPU register
                                                            context_tid
• IPCs
                                                                 .
                   The other ...   The other ...
                                                         System Variables
• Device Driver
• In an Action
                          CPU registers            context
RTOS Kernel::Tasks
    Jamei 中 thread 是 Task 的單元
                  typedef struct rt_thread_struct *pthread_t;
• Introduction
                  pthread_create
• Structure
• RTOS Kernel
                  pthread_exit
• Tasks
                  pthread_kill
• Memory

                  pthread_wakeup_np
• Timers
• I/O
                  pthread_suspend_np
• IPCs

                  pthread_wait_np
• Device Driver
• In an Action
                  ...            試圖滿足 POSIX Thread 語意
                                   ●


                                       _np]non-POSIX
                                   ●
RTOS Kernel::Tasks
    Jamei 中 thread 是 Task 的單元
                                                                    preempt
                       Task A                  Task A
• Introduction
                                 isr                        isr
• Structure
                                             Call the Scheduler
• RTOS Kernel
                       Task A                                       Task B
• Tasks
• Memory                        Task B         Task A
              non-preempt
• Timers
                                                                    preemptive      scheduling
                                   int rt_schedule(void)
• I/O
                                   {
                                     struct rt_thread_struct *preemptor = 0;
• IPCs
                                     ...
• Device Driver
                                    if ((s->clock->mode == RT_CLOCK_MODE_ONESHOT)) {
• In an Action                        if ((preemptor = find_preemptor(s,new_task)))

                                        {
                                          (s->clock)->settimer(s->clock, preemptor->resume_time - now);
                                        } else {
                                          (s->clock)->settimer(s->clock, (HRTICKS_PER_SEC / HZ) / 2 );
                                        }
優先權 Task A < Task B                     set_bit (RT_SCHED_TIMER_OK, &s->sched_flags);
                                    }
RTOS Kernel::Memory

                        在 i386 硬體架構下, Jamei 可支援
• Introduction
                        MMU (virtual memory) 與 MPU
• Structure

                        (memory protection)
• RTOS Kernel
• Tasks
                        區分 user-space 與 kernel-space
• Memory
                                    void start_kernel(void)
                        memory
• Timers                            {
                                                  /* architecture-dependent */
• I/O
                                                   init_arch();
• IPCs                                            /* NOTE:
                                                     - Mask all interrupts.
• Device Driver                                      - Interrupts are mapped in 0x20-0x30 IDT entries
                                                  */
• In an Action
                                                  #if CONFIG_KERNEL_MEMORYPROT
                       User Space memory           init_page();
                  P1                         P2
                                                  #endif

                                                  #if CONFIG_CONTEXT_MEMORYPROT
                                                   init_context();
                  M1                         M2
                                                  #endif
                       Kernel Space Memory
                                                  ...
RTOS Kernel::Memory
    Jamei 仿效 POSIX/Linux 的處理
                  APIs
• Introduction
                    kmalloc / kfree
• Structure
• RTOS Kernel
                    mmap
• Tasks
                    shm (shared memory area)
• Memory
• Timers
                  有彈性的記憶體管理機制
• I/O
                    放任 (no protected memory)
• IPCs
• Device Driver
                    最低限度記憶體保護機制
• In an Action
                       不可寫入 RT executive 記憶體
                    保護 context 執行單元記憶體
RTOS Kernel::Timer
    Timer 本質上是硬體時鐘的軟體呈現
                  型態                #define HRT_FROM_NS(x) (x)
• Introduction
                                    #define HRTICKS_PER_SEC 1000000000
                   watchdog timer
• Structure
                                    #ifndef HRT_FROM_8254
• RTOS Kernel
                   programmable     #ifndef HRT_FROM_8254
• Tasks                             #define HRT_FROM_8254(x) ((x) * 838)
                   timer            #endif
• Memory
                                    #ifndef HRT_TO_8254
• Timers
                                    #define HRT_TO_8254(x) ((x) / 838)
• I/O                               #endif
• IPCs
• Device Driver
• In an Action
RTOS Kernel::Timer
                                                                       struct rt_clock {
    萬惡 HZ                                                                   ...
                                                                            int (*sethrtime)(
                                                                                  struct rt_clock *,
                            實做 HRT (High                                          hrtime_t t);
• Introduction
                            Resolution Timer)                               int (*settimer)(
• Structure
                                                                                  struct rt_clock *,
• RTOS Kernel
                            用於 sched, sync 等
                                                                                  hrtime_t interval);
                                                                            ...
• Tasks                                                                     hrtime_t resolution;
                            系統實作                                            hrtime_t value;
• Memory
                                                                            hrtime_t delta;
• Timers                                                                    pthread_spinlock_t lock;
                                                                            struct rt_clock_arch arch;
• I/O                                                                  };
• IPCs
                  int rt_schedule(void)
• Device Driver   {
                  ...
• In an Action      if ((s->clock->mode == RT_CLOCK_MODE_ONESHOT)) {
                      if ((preemptor = find_preemptor(s,new_task)))

                        {
                          (s->clock)->settimer(s->clock, preemptor->resume_time - now);
                        } else {
                          (s->clock)->settimer(s->clock, (HRTICKS_PER_SEC / HZ) / 2 );
                        }
                  ...
RTOS Kernel::I/O
 everything is file
                  Interrupt-driven
• Introduction
                     polling / DMA
• Structure
• RTOS Kernel
                  I/O mapping
• Tasks
                     memory space 與 I/O 操作的對應
• Memory
• Timers
                  APIs
• I/O
                     open / close
• IPCs
• Device Driver
                     read / write
• In an Action
                     mmap
                     register_rtdev / unregister_rtdev
RTOS Kernel::IPC
  其實是 Inter-Task Communications
                  可配置的組態
• Introduction
                   Signals
• Structure
• RTOS Kernel
                   Semaphore
• Tasks
• Memory
• Timers
• I/O
• IPCs                            signals
• Device Driver
• In an Action




                  semaphore
RTOS Kernel::Device Driver
                                            static struct rt_file_operations
                                            rt_mem_fops = {
                                                  rt_mem_llseek,
                                                  rt_mem_read,
• Introduction                                    rt_mem_write,
                                                  NULL,
• Structure                                       rt_mem_mmap,
                      Client Drivers              rt_mem_open,
• RTOS Kernel
                                                  rt_mem_release
• Tasks                                     };
• Memory
• Timers
                     Protocol Layers
• I/O
• IPCs
• Device Driver
• In an Action
                  Host Controller Drivers



                        Hardware
In an Action

• Introduction
• Structure
• RTOS Kernel
• Tasks
• Memory
• Timers
• I/O
• IPCs
• Device Driver
• In an Action
機器人硬體機構概況
硬體:就是電腦系統中,可以讓你踢一腳的地方
控制系統

軌跡產生器                         控制             反應行為
 trajectory


                                                    決策邏輯
                          sensor
              Network


              RT task
                                              控制與軌跡生成
                        Robot Interpration



                                             低階控制系統
gdb stub
 考慮在 emulation/target 模式下,該如何喚起 gdb ?
 Remote Debugging :透過 serial 或 TCP/IP 進行遠端除錯
Show me the Robot
實現 TCP/IP 的
難題
IP Network
    UDP – best­effort datagrams
➢


    TCP – connection oriented, reliable byte­stream, 
➢


    full­duplex
                                                Application
        Flow control, congestion control, etc
    ➢


    IP – best­effort packet delivery
➢                                               UDP     TCP

        Forwarding, fragmentation
    ➢
                                                        ICMP
                                                 IP
    並未對資源消耗作優化
    相對來說,是可行的解決方案                                Network

    共通性
TCP/IP stack design
                                           Application


          lwIP – lightweight IP            UDP     TCP
  ●


           “Application driven” : larger           ICMP
      ●
                                            IP

          µIP – micro IP
  ●
                                            Network

           “Network driven” : smaller
      ●
TCP/IP stack design
                                                Application
           Application driven
                                                UDP     TCP


                                                        ICMP
                                                 IP
                                      Network
                         Stack
   Application

                                                 Network
                                      lwip

            Network driven


                                 Application
                 Stack
 Network



                                      uIP
資源有限、慾望無窮

 成本、實體空間
 Memory
   ~10 k RAM, ~100 k ROM
 Energy, power consumption
   Batteries, ~10 mW
 Bandwidth
   ~100 kbits/second
資源限制


 memory
 energy
 bandwidth
資源限制: Memory+TCP/IP

  RAM vs throughput
  基本上是兩難



                      More memory




                        Less memory
資源限制

 memory

 energy
 bandwidth
資源限制:功耗




     listening 與 receiving 一樣耗電
資源限制:功耗
    listening 與 receiving 一樣耗電,需透過軟體解決
➢

    Solution 1: don’t listen (ZigBee)
➢


       Listening nodes have a lot of energy (mains powered)
     ➢


       Problem: makes mesh networking difficult
     ➢


    Solution 2: be smart about listening and energy
➢


       Power-saving radio mechanisms
     ➢
資源限制

 memory
 energy

 bandwidth
資源限制: TCP/IP bandwidth

  ~100 kbit/second
  Messages are small
                                  Header
    802.15.4 max size 128 bytes
  TCP/IP headers are large


                                   Data
TCP/IP header is too long

   TCP/IP headers 40 bytes
   UDP/IP headers 28 bytes
   802.15.4 frame size 128 bytes
     27% – 36% overhead
   IPv6 adds 20 bytes
     42% – 52% overhead
Header compression
                     僅傳遞重要資訊


  48 bytes


     IP
                         1-4 bytes
    UDP
                     Compressed header

                           Data
    Data
回歸現實:剪裁
與調適
TCP/IP stack design
                                                Application
           Application driven
                                                UDP     TCP


                                                        ICMP
                                                 IP
                                      Network
                         Stack
   Application

                                                 Network
                                      lwip

            Network driven


                                 Application
                 Stack
 Network



                                      uIP
lwIP – Application driven
                                                              Application
          http://savannah.nongnu.org/projects/lwip/
  ●




          lwIP – lightweight IP
  ●                                                           UDP     TCP

          First release late 2000
  ●
                                                                      ICMP
                                                               IP

          40k code, 40k RAM
  ●
                                                               Network

          Application driven design
  ●


            Similar to Linux, BSD stacks
      ●



          Middle­end                 Application driven
  ●




                                                                     Network
                                                      Stack
                                 Application
µIP – smallest “full” TCP/IP stack
                                        Application

     http://www.sics.se/~adam/uip/
 ●
                                                   TCP
                                        UDP

     First release 2001
 ●
                                                    ICMP
                                         IP
     3 ­ 5k code, 100 bytes ­ 2k RAM
 ●
                                         Network
     “Full” TCP/IP (RFC compliant)
 ●



     Used in Contiki OS
 ●




                            Network driven

                                              Application
                                Stack
                      Network
 µIP 技巧


      Shared packet buffer
  ●



      Lower throughput
  ●



      Event­driven APIs
  ●
Shared packet buffer


          所有封包 (outbound + inbound ) 使用同一份
  ●


          緩衝區
           緩衝區的大小決定 throughput
      ●



                                    Outbound packet
      Incoming packet



                        Packet buffer
Shared packet buffer


      Implicit locking: single­threaded access
  ●


      1) Grab packet from network – put into buffer
      2) Process packet
           Put reply packet in the same buffer
       ●



      3) Send reply packet into network


                           Packet buffer
Lower Throughput


          µIP trades throughput for RAM
  ●


           Low RAM usage = low throughput
      ●



          小的系統通常不會有太多資料
  ●



          「具通訊的能力」會比 throughput 多寡
  ●


          來得重要
Event­driven APIs

          µIP 沒有 BSD sockets
  ●



           BSD sockets 建構於 threads 之上
      ●



           Threads 引來 overhead (RAM)
      ●



          因此,透過特製的 event­driven API
  ●



          co­routine
  ●


           Applications are called by µIP, call must return
      ●



          Protosockets – BSD socket­like API based 
  ●


          on protothreads
Protothread

int a_protothread(struct pt *pt) {
  PT_BEGIN(pt);
    /* … */
    PT_WAIT_UNTIL(pt, condition1);
    /* … */
    if(something) {
        /* … */
        PT_WAIT_UNTIL(pt, condition2);
        /* … */
    }

    PT_END(pt);
}
Hierarchical Protothreads
int a_protothread(struct pt *pt) {
  static struct pt child_pt;

    PT_BEGIN(pt);

    PT_INIT(&child_pt);
    PT_WAIT_UNTIL(pt2(&child_pt) != 0);

    PT_END(pt);
}

                      int pt2(struct pt *pt) {
                        PT_BEGIN(pt);

                          PT_WAIT_UNTIL(pt, condition);

                          PT_END(pt);
                      }
Threads vs. Events
Threads: sequential code flow   Events: unstructured code flow




          No blocking wait!
Events require one stack
 Threads require per­thread stack memory


                                                              Four event handlers, one 
      Four threads, each with its own stack
                                                         ●


                                                              stack

                                              Thread 4
  Thread 1       Thread 2       Thread 3




Stack is reused for 
every event handler
                                                             Eventhandler 1
                                                             Eventhandler 2
                                                             Eventhandler 3
                                                             Eventhandler 4
Protothreads require one stack
 Threads require per­thread stack memory


                                                             Four protothreads, one 
      Four threads, each with its own stack
                                                         ●


                                                             stack

                                              Thread 4

                                         Just like events
  Thread 1       Thread 2       Thread 3




             Events require one stack

                  Four event handlers, one 
         ●

                  stack




                                                         Protothread 1
                                                         Protothread 2
                                                         Protothread 3
                                                         Protothread 4
Event­driven APIs
void example2_app(void) {
   struct example2_state *s = 
     (struct example2_state *)uip_conn­>appstate;

   if(uip_connected()) {
      s­>state = WELCOME_SENT;
      uip_send(quot;Welcome!nquot;, 9);
      return;
                                    if(uip_rexmit()) {
   }
                                       switch(s­>state) {
                                       case WELCOME_SENT:
   if(uip_acked() && 
      s­>state == WELCOME_SENT) {         uip_send(quot;Welcome!nquot;, 9);
      s­>state = WELCOME_ACKED;          break;
                                       case WELCOME_ACKED:
   }
                                          uip_send(quot;oknquot;, 3);
                                          break;
   if(uip_newdata()) {
                                       }
      uip_send(quot;oknquot;, 3);
                                    }
   }
                                 }
Event­driven APIs

        Event­driven API 不見得適用所有程式
●



        Protosockets: sockets­like API using protothreads
●


         Extremely lightweight stackless threads
    ●



         2 bytes per­thread state, no stack
    ●



        Protothreads 允許“ blocking” ,本質是循序的
●



        overhead 遠小於真實的 thread
●
Event­driven APIs
      PT_THREAD(smtp_protothread(void))
      {
        PSOCK_BEGIN(s);

        PSOCK_READTO(s, 'n');

        if(strncmp(inputbuffer, “220”, 3) != 0) {
          PSOCK_CLOSE(s);
          PSOCK_EXIT(s);
        }

        PSOCK_SEND(s, “HELO ”, 5);
        PSOCK_SEND(s, hostname, strlen(hostname));
        PSOCK_SEND(s, “rn”, 2);

        PSOCK_READTO(s, 'n');

        if(inputbuffer[0] != '2') {
          PSOCK_CLOSE(s);
          PSOCK_EXIT(s);
        }
Proof-of-concept TCP/IP stacks


     phpstack – TCP/IP stack, webserver written in PHP
 ●

     http://www.sics.se/~adam/phpstack/
     miniweb – TCP/IP stack, webserver using 30 bytes of
 ●

     RAM
     http://www.sics.se/~adam/miniweb/
技術討論
討論
     µIP 適用於低階的環境
➢


    中階或網路需求較高者,應用 lwIP 或 BSD
➢


    socket
    Thread preemption
➢
情境: Process 正等待 Device I/O( 由中斷觸發 ) 的結束,
方可繼續執行
Waiting
                                                                            Running task
 task                                      Makes the
                                         task runnable

                                  Interrupt
                      interrupt                                Scheduler
                                   handler
                       latency
          Interrupt

                                                                scheduler
                                   handler         scheduler
                                                                 duration
                                   duration         latency



kernel latency = interrupt latency +
                 handler duration +
                 scheduler latency +
                 scheduler duration
Waiting
                                                                           Running task
    task                                  Makes the
                                        task runnable

                     interrupt   Interrupt
                                                              Scheduler
                                  handler
                      latency
             Interrupt

                                                               scheduler
                                  handler         scheduler
                                                                duration
                                  duration         latency

來源
 Interrupts disabled by kernel code: Interrupt context, managed by the CPU
                                                       handler with greater 
 spinlocks, driver code...                             priority
 Bad driver using the fast interrupt
                                                    handler
 mode (should be reserved to timer
 interrupts).                                                 processes

 Other interrupts processed before.
                                       Process context, managed by the scheduler
Waiting
                                                                              Running task
   task                                      Makes the
                                           task runnable

                                    Interrupt
                        interrupt
                                                                 Scheduler
                                     handler
                         latency
            Interrupt

                                                                  scheduler
                                    handler          scheduler
                                                                   duration
                                                      latency
                                    duration

執行 interrupt handler 的時間,在以下情況會更嚴重:
 Preemption by other interrupts.
 Interrupt handler with a softirq component
 Interrupts disabled by kernel code
 Bad driver using the fast interrupt mode
 Other interrupts processed before.
Waiting
                                                                         Running task
  task                                      Makes the
                                          task runnable

                                   Interrupt
                       interrupt
                                                            Scheduler
                                    handler
                        latency
           Interrupt

                                                             scheduler
                                                scheduler
                                    handler
                                                              duration
                                    duration
                                                 latency

用於 scheduler 的時間,原因:
 Kernel code not preemptible.
     Need to wait for returning
     from interrupts or from system calls.
 Interrupts disabled for a long time in driver code.
     Can cause a timer interrupt to be missed.
Waiting
                                                                             Running task
  task                                      Makes the
                                          task runnable

                                   Interrupt
                       interrupt
                                                                 Scheduler
                                    handler
                        latency
           Interrupt

                                                                scheduler
                                    handler         scheduler
                                    duration         latency
                                                                 duration

執行 scheduler 並切換到新的 task 所耗費的時間
 執行 scheduler 的時間為常數
 context switching time
    Restoring processor registers and stack for the new process.
    Restoring the address space of the new process
    (except for threads sharing the same address space).
結論
無所不在的嵌入式系統
 Invisible Computer
機電整合與自由軟體的機會
作中學

Mais conteúdo relacionado

Mais procurados

Overview of Android binder IPC implementation
Overview of Android binder IPC implementationOverview of Android binder IPC implementation
Overview of Android binder IPC implementationChethan Pchethan
 
Linux Ethernet device driver
Linux Ethernet device driverLinux Ethernet device driver
Linux Ethernet device driver艾鍗科技
 
BPF / XDP 8월 세미나 KossLab
BPF / XDP 8월 세미나 KossLabBPF / XDP 8월 세미나 KossLab
BPF / XDP 8월 세미나 KossLabTaeung Song
 
JVM JIT compilation overview by Vladimir Ivanov
JVM JIT compilation overview by Vladimir IvanovJVM JIT compilation overview by Vladimir Ivanov
JVM JIT compilation overview by Vladimir IvanovZeroTurnaround
 
簡介 Linux 的 Network Namespace 功能
簡介 Linux 的 Network Namespace 功能簡介 Linux 的 Network Namespace 功能
簡介 Linux 的 Network Namespace 功能John L Chen
 
Access Network Evolution
Access Network Evolution Access Network Evolution
Access Network Evolution Cisco Canada
 
Power optimization for Android apps
Power optimization for Android appsPower optimization for Android apps
Power optimization for Android appsXavier Hallade
 
Developing rich SIP applications with SIPSIMPLE SDK
Developing rich SIP applications with SIPSIMPLE SDKDeveloping rich SIP applications with SIPSIMPLE SDK
Developing rich SIP applications with SIPSIMPLE SDKSaúl Ibarra Corretgé
 
The linux networking architecture
The linux networking architectureThe linux networking architecture
The linux networking architecturehugo lu
 
Linux Performance Analysis: New Tools and Old Secrets
Linux Performance Analysis: New Tools and Old SecretsLinux Performance Analysis: New Tools and Old Secrets
Linux Performance Analysis: New Tools and Old SecretsBrendan Gregg
 
Virtualized network with openvswitch
Virtualized network with openvswitchVirtualized network with openvswitch
Virtualized network with openvswitchSim Janghoon
 
The TCP/IP Stack in the Linux Kernel
The TCP/IP Stack in the Linux KernelThe TCP/IP Stack in the Linux Kernel
The TCP/IP Stack in the Linux KernelDivye Kapoor
 
High-Performance Networking Using eBPF, XDP, and io_uring
High-Performance Networking Using eBPF, XDP, and io_uringHigh-Performance Networking Using eBPF, XDP, and io_uring
High-Performance Networking Using eBPF, XDP, and io_uringScyllaDB
 
Inline and lambda function
Inline and lambda functionInline and lambda function
Inline and lambda functionJawad Khan
 
Cisco ACI & F5 Integrate to Transform the Data Center
Cisco ACI & F5 Integrate to Transform the Data CenterCisco ACI & F5 Integrate to Transform the Data Center
Cisco ACI & F5 Integrate to Transform the Data CenterF5NetworksAPJ
 

Mais procurados (20)

Android IPC Mechanism
Android IPC MechanismAndroid IPC Mechanism
Android IPC Mechanism
 
Overview of Android binder IPC implementation
Overview of Android binder IPC implementationOverview of Android binder IPC implementation
Overview of Android binder IPC implementation
 
Linux Network Stack
Linux Network StackLinux Network Stack
Linux Network Stack
 
Linux Ethernet device driver
Linux Ethernet device driverLinux Ethernet device driver
Linux Ethernet device driver
 
BPF / XDP 8월 세미나 KossLab
BPF / XDP 8월 세미나 KossLabBPF / XDP 8월 세미나 KossLab
BPF / XDP 8월 세미나 KossLab
 
BGP Update Source
BGP Update Source BGP Update Source
BGP Update Source
 
JVM JIT compilation overview by Vladimir Ivanov
JVM JIT compilation overview by Vladimir IvanovJVM JIT compilation overview by Vladimir Ivanov
JVM JIT compilation overview by Vladimir Ivanov
 
Explore Android Internals
Explore Android InternalsExplore Android Internals
Explore Android Internals
 
簡介 Linux 的 Network Namespace 功能
簡介 Linux 的 Network Namespace 功能簡介 Linux 的 Network Namespace 功能
簡介 Linux 的 Network Namespace 功能
 
Linux Kernel Live Patching
Linux Kernel Live PatchingLinux Kernel Live Patching
Linux Kernel Live Patching
 
Access Network Evolution
Access Network Evolution Access Network Evolution
Access Network Evolution
 
Power optimization for Android apps
Power optimization for Android appsPower optimization for Android apps
Power optimization for Android apps
 
Developing rich SIP applications with SIPSIMPLE SDK
Developing rich SIP applications with SIPSIMPLE SDKDeveloping rich SIP applications with SIPSIMPLE SDK
Developing rich SIP applications with SIPSIMPLE SDK
 
The linux networking architecture
The linux networking architectureThe linux networking architecture
The linux networking architecture
 
Linux Performance Analysis: New Tools and Old Secrets
Linux Performance Analysis: New Tools and Old SecretsLinux Performance Analysis: New Tools and Old Secrets
Linux Performance Analysis: New Tools and Old Secrets
 
Virtualized network with openvswitch
Virtualized network with openvswitchVirtualized network with openvswitch
Virtualized network with openvswitch
 
The TCP/IP Stack in the Linux Kernel
The TCP/IP Stack in the Linux KernelThe TCP/IP Stack in the Linux Kernel
The TCP/IP Stack in the Linux Kernel
 
High-Performance Networking Using eBPF, XDP, and io_uring
High-Performance Networking Using eBPF, XDP, and io_uringHigh-Performance Networking Using eBPF, XDP, and io_uring
High-Performance Networking Using eBPF, XDP, and io_uring
 
Inline and lambda function
Inline and lambda functionInline and lambda function
Inline and lambda function
 
Cisco ACI & F5 Integrate to Transform the Data Center
Cisco ACI & F5 Integrate to Transform the Data CenterCisco ACI & F5 Integrate to Transform the Data Center
Cisco ACI & F5 Integrate to Transform the Data Center
 

Destaque

protothread and its usage in contiki OS
protothread and its usage in contiki OSprotothread and its usage in contiki OS
protothread and its usage in contiki OSSalah Amean
 
BeRTOS Embedded Survey Summary 2011
BeRTOS Embedded Survey Summary 2011BeRTOS Embedded Survey Summary 2011
BeRTOS Embedded Survey Summary 2011Develer S.r.l.
 
BeRTOS: Free Embedded RTOS
BeRTOS: Free Embedded RTOSBeRTOS: Free Embedded RTOS
BeRTOS: Free Embedded RTOSDeveler S.r.l.
 
Implementing Lightweight Networking
Implementing Lightweight NetworkingImplementing Lightweight Networking
Implementing Lightweight Networkingguest6972eaf
 
Qi -- Lightweight Boot Loader Applied in Mobile and Embedded Devices
Qi -- Lightweight Boot Loader Applied in Mobile and Embedded DevicesQi -- Lightweight Boot Loader Applied in Mobile and Embedded Devices
Qi -- Lightweight Boot Loader Applied in Mobile and Embedded DevicesNational Cheng Kung University
 
Advanced Internet of Things firmware engineering with Thingsquare and Contiki...
Advanced Internet of Things firmware engineering with Thingsquare and Contiki...Advanced Internet of Things firmware engineering with Thingsquare and Contiki...
Advanced Internet of Things firmware engineering with Thingsquare and Contiki...Adam Dunkels
 
WSN protocol 802.15.4 together with cc2420 seminars
WSN protocol 802.15.4 together with cc2420 seminars WSN protocol 802.15.4 together with cc2420 seminars
WSN protocol 802.15.4 together with cc2420 seminars Salah Amean
 
Building the Internet of Things with Thingsquare and Contiki - day 2 part 1
Building the Internet of Things with Thingsquare and Contiki - day 2 part 1Building the Internet of Things with Thingsquare and Contiki - day 2 part 1
Building the Internet of Things with Thingsquare and Contiki - day 2 part 1Adam Dunkels
 
Contiki introduction I.
Contiki introduction I.Contiki introduction I.
Contiki introduction I.Dingxin Xu
 
Introduction to Tiny OS
Introduction to Tiny OSIntroduction to Tiny OS
Introduction to Tiny OSSudharsan S
 
Contiki Operating system tutorial
Contiki Operating system tutorialContiki Operating system tutorial
Contiki Operating system tutorialSalah Amean
 

Destaque (14)

protothread and its usage in contiki OS
protothread and its usage in contiki OSprotothread and its usage in contiki OS
protothread and its usage in contiki OS
 
BeRTOS Embedded Survey Summary 2011
BeRTOS Embedded Survey Summary 2011BeRTOS Embedded Survey Summary 2011
BeRTOS Embedded Survey Summary 2011
 
BeRTOS: Free Embedded RTOS
BeRTOS: Free Embedded RTOSBeRTOS: Free Embedded RTOS
BeRTOS: Free Embedded RTOS
 
Implementing Lightweight Networking
Implementing Lightweight NetworkingImplementing Lightweight Networking
Implementing Lightweight Networking
 
Qi -- Lightweight Boot Loader Applied in Mobile and Embedded Devices
Qi -- Lightweight Boot Loader Applied in Mobile and Embedded DevicesQi -- Lightweight Boot Loader Applied in Mobile and Embedded Devices
Qi -- Lightweight Boot Loader Applied in Mobile and Embedded Devices
 
Advanced Internet of Things firmware engineering with Thingsquare and Contiki...
Advanced Internet of Things firmware engineering with Thingsquare and Contiki...Advanced Internet of Things firmware engineering with Thingsquare and Contiki...
Advanced Internet of Things firmware engineering with Thingsquare and Contiki...
 
Contiki Presentation
Contiki PresentationContiki Presentation
Contiki Presentation
 
WSN protocol 802.15.4 together with cc2420 seminars
WSN protocol 802.15.4 together with cc2420 seminars WSN protocol 802.15.4 together with cc2420 seminars
WSN protocol 802.15.4 together with cc2420 seminars
 
Building the Internet of Things with Thingsquare and Contiki - day 2 part 1
Building the Internet of Things with Thingsquare and Contiki - day 2 part 1Building the Internet of Things with Thingsquare and Contiki - day 2 part 1
Building the Internet of Things with Thingsquare and Contiki - day 2 part 1
 
Game Programming By J2me
Game Programming By J2meGame Programming By J2me
Game Programming By J2me
 
Contiki introduction I.
Contiki introduction I.Contiki introduction I.
Contiki introduction I.
 
Introduction to Tiny OS
Introduction to Tiny OSIntroduction to Tiny OS
Introduction to Tiny OS
 
J2ME
J2MEJ2ME
J2ME
 
Contiki Operating system tutorial
Contiki Operating system tutorialContiki Operating system tutorial
Contiki Operating system tutorial
 

Semelhante a Implementing Lightweight Networking

Real Time Operating System Concepts
Real Time Operating System ConceptsReal Time Operating System Concepts
Real Time Operating System ConceptsSanjiv Malik
 
Gerenciamento de Memória(2)
Gerenciamento de Memória(2)Gerenciamento de Memória(2)
Gerenciamento de Memória(2)elliando dias
 
Tips on High Performance Server Programming
Tips on High Performance Server ProgrammingTips on High Performance Server Programming
Tips on High Performance Server ProgrammingJoshua Zhu
 
Advanced Oracle Troubleshooting
Advanced Oracle TroubleshootingAdvanced Oracle Troubleshooting
Advanced Oracle TroubleshootingHector Martinez
 
Lightweight Grids With Terracotta
Lightweight Grids With TerracottaLightweight Grids With Terracotta
Lightweight Grids With TerracottaPT.JUG
 
Evergreen Sysadmin Survival Skills
Evergreen Sysadmin Survival SkillsEvergreen Sysadmin Survival Skills
Evergreen Sysadmin Survival SkillsEvergreen ILS
 
Don't Tell Joanna the Virtualized Rootkit is Dead (Blackhat 2007)
Don't Tell Joanna the Virtualized Rootkit is Dead (Blackhat 2007)Don't Tell Joanna the Virtualized Rootkit is Dead (Blackhat 2007)
Don't Tell Joanna the Virtualized Rootkit is Dead (Blackhat 2007)Nate Lawson
 
Application Profiling for Memory and Performance
Application Profiling for Memory and PerformanceApplication Profiling for Memory and Performance
Application Profiling for Memory and Performancepradeepfn
 
Me3D: A Model-driven Methodology Expediting Embedded Device Driver Development
Me3D: A Model-driven Methodology  Expediting Embedded Device  Driver DevelopmentMe3D: A Model-driven Methodology  Expediting Embedded Device  Driver Development
Me3D: A Model-driven Methodology Expediting Embedded Device Driver Developmenthuichenphd
 
Memory Management for High-Performance Applications
Memory Management for High-Performance ApplicationsMemory Management for High-Performance Applications
Memory Management for High-Performance ApplicationsEmery Berger
 
HeapStats: Troubleshooting with Serviceability and the New Runtime Monitoring...
HeapStats: Troubleshooting with Serviceability and the New Runtime Monitoring...HeapStats: Troubleshooting with Serviceability and the New Runtime Monitoring...
HeapStats: Troubleshooting with Serviceability and the New Runtime Monitoring...Yuji Kubota
 
How Many Ways Can I Manage Oracle GoldenGate?
How Many Ways Can I Manage Oracle GoldenGate?How Many Ways Can I Manage Oracle GoldenGate?
How Many Ways Can I Manage Oracle GoldenGate?Enkitec
 
DTrace Topics: Introduction
DTrace Topics: IntroductionDTrace Topics: Introduction
DTrace Topics: IntroductionBrendan Gregg
 
Dynamic Load-balancing On Graphics Processors
Dynamic Load-balancing On Graphics ProcessorsDynamic Load-balancing On Graphics Processors
Dynamic Load-balancing On Graphics Processorsdaced
 
AHMED JASSAT SOUTH ARICAN ORACLE USER GROUP PRESENTATION
AHMED JASSAT SOUTH ARICAN ORACLE USER GROUP PRESENTATIONAHMED JASSAT SOUTH ARICAN ORACLE USER GROUP PRESENTATION
AHMED JASSAT SOUTH ARICAN ORACLE USER GROUP PRESENTATIONZahid02
 
Experiences with Debugging Data Races
Experiences with Debugging Data RacesExperiences with Debugging Data Races
Experiences with Debugging Data RacesAzul Systems Inc.
 

Semelhante a Implementing Lightweight Networking (20)

Real Time Operating System Concepts
Real Time Operating System ConceptsReal Time Operating System Concepts
Real Time Operating System Concepts
 
Gerenciamento de Memória(2)
Gerenciamento de Memória(2)Gerenciamento de Memória(2)
Gerenciamento de Memória(2)
 
Tips on High Performance Server Programming
Tips on High Performance Server ProgrammingTips on High Performance Server Programming
Tips on High Performance Server Programming
 
YARN Under The Hood
YARN Under The HoodYARN Under The Hood
YARN Under The Hood
 
Advanced Oracle Troubleshooting
Advanced Oracle TroubleshootingAdvanced Oracle Troubleshooting
Advanced Oracle Troubleshooting
 
Lightweight Grids With Terracotta
Lightweight Grids With TerracottaLightweight Grids With Terracotta
Lightweight Grids With Terracotta
 
Evergreen Sysadmin Survival Skills
Evergreen Sysadmin Survival SkillsEvergreen Sysadmin Survival Skills
Evergreen Sysadmin Survival Skills
 
2. operating systems
2. operating systems2. operating systems
2. operating systems
 
Don't Tell Joanna the Virtualized Rootkit is Dead (Blackhat 2007)
Don't Tell Joanna the Virtualized Rootkit is Dead (Blackhat 2007)Don't Tell Joanna the Virtualized Rootkit is Dead (Blackhat 2007)
Don't Tell Joanna the Virtualized Rootkit is Dead (Blackhat 2007)
 
Application Profiling for Memory and Performance
Application Profiling for Memory and PerformanceApplication Profiling for Memory and Performance
Application Profiling for Memory and Performance
 
Me3D: A Model-driven Methodology Expediting Embedded Device Driver Development
Me3D: A Model-driven Methodology  Expediting Embedded Device  Driver DevelopmentMe3D: A Model-driven Methodology  Expediting Embedded Device  Driver Development
Me3D: A Model-driven Methodology Expediting Embedded Device Driver Development
 
Tremashark
TremasharkTremashark
Tremashark
 
Memory Management for High-Performance Applications
Memory Management for High-Performance ApplicationsMemory Management for High-Performance Applications
Memory Management for High-Performance Applications
 
HeapStats: Troubleshooting with Serviceability and the New Runtime Monitoring...
HeapStats: Troubleshooting with Serviceability and the New Runtime Monitoring...HeapStats: Troubleshooting with Serviceability and the New Runtime Monitoring...
HeapStats: Troubleshooting with Serviceability and the New Runtime Monitoring...
 
How Many Ways Can I Manage Oracle GoldenGate?
How Many Ways Can I Manage Oracle GoldenGate?How Many Ways Can I Manage Oracle GoldenGate?
How Many Ways Can I Manage Oracle GoldenGate?
 
DTrace Topics: Introduction
DTrace Topics: IntroductionDTrace Topics: Introduction
DTrace Topics: Introduction
 
No Heap Remote Objects for Distributed real-time Java
No Heap Remote Objects for Distributed real-time JavaNo Heap Remote Objects for Distributed real-time Java
No Heap Remote Objects for Distributed real-time Java
 
Dynamic Load-balancing On Graphics Processors
Dynamic Load-balancing On Graphics ProcessorsDynamic Load-balancing On Graphics Processors
Dynamic Load-balancing On Graphics Processors
 
AHMED JASSAT SOUTH ARICAN ORACLE USER GROUP PRESENTATION
AHMED JASSAT SOUTH ARICAN ORACLE USER GROUP PRESENTATIONAHMED JASSAT SOUTH ARICAN ORACLE USER GROUP PRESENTATION
AHMED JASSAT SOUTH ARICAN ORACLE USER GROUP PRESENTATION
 
Experiences with Debugging Data Races
Experiences with Debugging Data RacesExperiences with Debugging Data Races
Experiences with Debugging Data Races
 

Mais de National Cheng Kung University

PyPy's approach to construct domain-specific language runtime
PyPy's approach to construct domain-specific language runtimePyPy's approach to construct domain-specific language runtime
PyPy's approach to construct domain-specific language runtimeNational Cheng Kung University
 
進階嵌入式作業系統設計與實做 (2015 年秋季 ) 課程說明
進階嵌入式作業系統設計與實做 (2015 年秋季 ) 課程說明進階嵌入式作業系統設計與實做 (2015 年秋季 ) 課程說明
進階嵌入式作業系統設計與實做 (2015 年秋季 ) 課程說明National Cheng Kung University
 
給自己更好未來的 3 個練習:嵌入式作業系統設計、實做,與移植 (2015 年春季 ) 課程說明
給自己更好未來的 3 個練習:嵌入式作業系統設計、實做,與移植 (2015 年春季 ) 課程說明給自己更好未來的 3 個練習:嵌入式作業系統設計、實做,與移植 (2015 年春季 ) 課程說明
給自己更好未來的 3 個練習:嵌入式作業系統設計、實做,與移植 (2015 年春季 ) 課程說明National Cheng Kung University
 
進階嵌入式系統開發與實做 (2014 年秋季 ) 課程說明
進階嵌入式系統開發與實做 (2014 年秋季 ) 課程說明進階嵌入式系統開發與實做 (2014 年秋季 ) 課程說明
進階嵌入式系統開發與實做 (2014 年秋季 ) 課程說明National Cheng Kung University
 
Develop Your Own Operating Systems using Cheap ARM Boards
Develop Your Own Operating Systems using Cheap ARM BoardsDevelop Your Own Operating Systems using Cheap ARM Boards
Develop Your Own Operating Systems using Cheap ARM BoardsNational Cheng Kung University
 
Lecture notice about Embedded Operating System Design and Implementation
Lecture notice about Embedded Operating System Design and ImplementationLecture notice about Embedded Operating System Design and Implementation
Lecture notice about Embedded Operating System Design and ImplementationNational Cheng Kung University
 
中輟生談教育: 完全用開放原始碼軟體進行 嵌入式系統教學
中輟生談教育: 完全用開放原始碼軟體進行 嵌入式系統教學中輟生談教育: 完全用開放原始碼軟體進行 嵌入式系統教學
中輟生談教育: 完全用開放原始碼軟體進行 嵌入式系統教學National Cheng Kung University
 
F9: A Secure and Efficient Microkernel Built for Deeply Embedded Systems
F9: A Secure and Efficient Microkernel Built for Deeply Embedded SystemsF9: A Secure and Efficient Microkernel Built for Deeply Embedded Systems
F9: A Secure and Efficient Microkernel Built for Deeply Embedded SystemsNational Cheng Kung University
 

Mais de National Cheng Kung University (20)

PyPy's approach to construct domain-specific language runtime
PyPy's approach to construct domain-specific language runtimePyPy's approach to construct domain-specific language runtime
PyPy's approach to construct domain-specific language runtime
 
Making Linux do Hard Real-time
Making Linux do Hard Real-timeMaking Linux do Hard Real-time
Making Linux do Hard Real-time
 
2016 年春季嵌入式作業系統課程說明
2016 年春季嵌入式作業系統課程說明2016 年春季嵌入式作業系統課程說明
2016 年春季嵌入式作業系統課程說明
 
Interpreter, Compiler, JIT from scratch
Interpreter, Compiler, JIT from scratchInterpreter, Compiler, JIT from scratch
Interpreter, Compiler, JIT from scratch
 
進階嵌入式作業系統設計與實做 (2015 年秋季 ) 課程說明
進階嵌入式作業系統設計與實做 (2015 年秋季 ) 課程說明進階嵌入式作業系統設計與實做 (2015 年秋季 ) 課程說明
進階嵌入式作業系統設計與實做 (2015 年秋季 ) 課程說明
 
Construct an Efficient and Secure Microkernel for IoT
Construct an Efficient and Secure Microkernel for IoTConstruct an Efficient and Secure Microkernel for IoT
Construct an Efficient and Secure Microkernel for IoT
 
The Internals of "Hello World" Program
The Internals of "Hello World" ProgramThe Internals of "Hello World" Program
The Internals of "Hello World" Program
 
How A Compiler Works: GNU Toolchain
How A Compiler Works: GNU ToolchainHow A Compiler Works: GNU Toolchain
How A Compiler Works: GNU Toolchain
 
Virtual Machine Constructions for Dummies
Virtual Machine Constructions for DummiesVirtual Machine Constructions for Dummies
Virtual Machine Constructions for Dummies
 
給自己更好未來的 3 個練習:嵌入式作業系統設計、實做,與移植 (2015 年春季 ) 課程說明
給自己更好未來的 3 個練習:嵌入式作業系統設計、實做,與移植 (2015 年春季 ) 課程說明給自己更好未來的 3 個練習:嵌入式作業系統設計、實做,與移植 (2015 年春季 ) 課程說明
給自己更好未來的 3 個練習:嵌入式作業系統設計、實做,與移植 (2015 年春季 ) 課程說明
 
從線上售票看作業系統設計議題
從線上售票看作業系統設計議題從線上售票看作業系統設計議題
從線上售票看作業系統設計議題
 
進階嵌入式系統開發與實做 (2014 年秋季 ) 課程說明
進階嵌入式系統開發與實做 (2014 年秋季 ) 課程說明進階嵌入式系統開發與實做 (2014 年秋季 ) 課程說明
進階嵌入式系統開發與實做 (2014 年秋季 ) 課程說明
 
Xvisor: embedded and lightweight hypervisor
Xvisor: embedded and lightweight hypervisorXvisor: embedded and lightweight hypervisor
Xvisor: embedded and lightweight hypervisor
 
Making Linux do Hard Real-time
Making Linux do Hard Real-timeMaking Linux do Hard Real-time
Making Linux do Hard Real-time
 
Implement Runtime Environments for HSA using LLVM
Implement Runtime Environments for HSA using LLVMImplement Runtime Environments for HSA using LLVM
Implement Runtime Environments for HSA using LLVM
 
Priority Inversion on Mars
Priority Inversion on MarsPriority Inversion on Mars
Priority Inversion on Mars
 
Develop Your Own Operating Systems using Cheap ARM Boards
Develop Your Own Operating Systems using Cheap ARM BoardsDevelop Your Own Operating Systems using Cheap ARM Boards
Develop Your Own Operating Systems using Cheap ARM Boards
 
Lecture notice about Embedded Operating System Design and Implementation
Lecture notice about Embedded Operating System Design and ImplementationLecture notice about Embedded Operating System Design and Implementation
Lecture notice about Embedded Operating System Design and Implementation
 
中輟生談教育: 完全用開放原始碼軟體進行 嵌入式系統教學
中輟生談教育: 完全用開放原始碼軟體進行 嵌入式系統教學中輟生談教育: 完全用開放原始碼軟體進行 嵌入式系統教學
中輟生談教育: 完全用開放原始碼軟體進行 嵌入式系統教學
 
F9: A Secure and Efficient Microkernel Built for Deeply Embedded Systems
F9: A Secure and Efficient Microkernel Built for Deeply Embedded SystemsF9: A Secure and Efficient Microkernel Built for Deeply Embedded Systems
F9: A Secure and Efficient Microkernel Built for Deeply Embedded Systems
 

Último

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 

Último (20)

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

Implementing Lightweight Networking

  • 1. 實作輕量級 RTOS 網路堆疊 Apr 24, 2009 Jim Huang( 黃敬群 /jserv) Email: <jserv.tw@gmail.com> Blog: http://blog.linux.org.tw/jserv/
  • 2. 自我介紹 Phone/PDA, GPS, Mobile TV/Digital TV 代工設計 參與自由軟體開發 / 社群組織 新酷音輸入法 Xenomai Debian Taiwan Kaffe.org Orz Microkernel KDE Taiwan GNU Classpath pcmanx TOSSUG FreeDesktop LXDE 0xlab (4/27) OpenMoko OpenAVS ... ... 警告:本議程僅探討實務面,忽略理論部份
  • 4. 動機 每年寫一套作業系統 當作業 ( 對不起,遲交 ) JK (2001) Orz Microkernel (2006) RT nanokernel (2007) Jamei RTOS (2007) CuRT (2009) ??? (2009)
  • 5. 動機 (1) Everything can be Orz. Orz Microkernel
  • 6. 動機 (2) Orz Microkernel 的啟發 學習作業系統與相關的系統程 式該如何設計 建立自信:原來一個作業系統 只需幾 kb 的空間就實做出來
  • 7. 動機 (3) 設計作業系統也 可很有趣 以實體的機器人設計作為主軸 體驗如何親手打造嵌入式系統 並著手設計相關軟硬體建設
  • 8. 動機 (4) 從零到有,設計即時 作業系統 杜威博士:「作中學」 RT nanokernel (OSDC.tw 2007) Jamei (COSCUP 2007) 模仿 Linux 經典設計並建構具體而微的 RTOS
  • 9. 動機 (5) 滿足自動控制系 統需求 即時處理 建構嵌入式環境 網路通訊能力
  • 11. 動機 (6) 簡化設計,適用更廣 範圍的硬體 CuRT (2009) 硬體: Marvell/Intel PXA255 特徵 Preemptive Multi-threading Priority-base Round-Robin Scheduling Thread Management Semaphore Management Support IPC: mailbox, message queue
  • 12. Bell 定律:每十年運算 型態的移轉 1980 年代: PC revolution 1990 年代: Internet revolution 2000 年代: embedded revolution 2010 年代: embedded Internet revolution
  • 17. 典型嵌入式硬體 Small microcontroller (microprocessor + I/O) ● 8- and 16-bit processors ● Typical memory size ● 1 – 100 k Flash ROM for code ● 0.1 – 10 k RAM for data ● Typical speed ● 1 – 10 MHz ● 8051, AVR, MSP430, Z80, 6502, ARM, ... ●
  • 18. 設計自己的 RTOS Jamei = Just Another Microprocessor Embedded Infrastructure 輕巧並可調整組態 仿造 Linux kernel 部份設計 arch( 平台相依實做 ) device driver model vfs 部份 POSIX Thread 部份 Realtime API (IEEE 1003.1b) New BSD License 與 GNU GPLv2( 部份 ) 支援 i386 與 ARM9
  • 19. RTOS 結構 • Introduction • Structure Applications POSIX • RTOS Kernel Subsystem • Tasks Use r Mo de • Memory Ke rne l Mo de • Timers Security Object • I/O Manager Reference Monitor RTOS-kernel • IPCs HAL : Hardware Abstraction Layer Driver/BSP • Device Driver • In an Action Custom-Hardware
  • 20. RTOS Kernel • Introduction • Structure • RTOS Kernel • Tasks • Memory • Timers • I/O • IPCs • Device Driver • In an Action
  • 21. ThreadC RealMain Stack RealMain ThreadC Scheduler Timer Alarm Timer Task Queue Alarm Action serial Interrupt table H/W timer A/D conv. receive
  • 22. ThreadC RealMain Stack Alarm Timer Scheduler Scheduler Timer Task Queue timer task Alarm Action serial Interrupt table H/W timer A/D conv. receive
  • 23. ThreadC RealMain Stack Scheduler Timer Scheduler ThreadC Action Timer Task Queue timer task Alarm Action serial Interrupt table H/W timer A/D conv. receive
  • 24. RTOS Kernel::Tasks Task 是 RTOS 最重要的項目 RTOS scheduler 必須 determinstic • Introduction O(1) or O(n) • Structure 笨蛋,問題在 • RTOS Kernel scheduling ! Scheduling policy • Tasks Clock driven • Memory • Timers Priority driven (RMS & EDF) • I/O new ready • IPCs scheduler task • Device Driver • In an Action running terminatin waiting signal tasks events
  • 25. RTOS Kernel::Tasks Task 的狀態移轉 • Introduction • Structure Terminate sleep • RTOS Kernel • Tasks • Memory Start Terminate • Timers Get something • I/O Terminate waiting ready • IPCs • Device Driver Wait something • In an Action Context switch Interrupt running ISR Return
  • 26. RTOS Kernel::Tasks TCB (Task Control Block) rt_thread_struct • Introduction stack SAVED_TASK_STATE stack • Structure signals • RTOS Kernel • Tasks events TCB TCB • Memory current_deadline, priority priority status status • Timers policy stack stack • I/O CPU register CPU register context_tid • IPCs . The other ... The other ... System Variables • Device Driver • In an Action CPU registers context
  • 27. RTOS Kernel::Tasks Jamei 中 thread 是 Task 的單元 typedef struct rt_thread_struct *pthread_t; • Introduction pthread_create • Structure • RTOS Kernel pthread_exit • Tasks pthread_kill • Memory pthread_wakeup_np • Timers • I/O pthread_suspend_np • IPCs pthread_wait_np • Device Driver • In an Action ... 試圖滿足 POSIX Thread 語意 ● _np]non-POSIX ●
  • 28. RTOS Kernel::Tasks Jamei 中 thread 是 Task 的單元 preempt Task A Task A • Introduction isr isr • Structure Call the Scheduler • RTOS Kernel Task A Task B • Tasks • Memory Task B Task A non-preempt • Timers preemptive scheduling int rt_schedule(void) • I/O { struct rt_thread_struct *preemptor = 0; • IPCs ... • Device Driver if ((s->clock->mode == RT_CLOCK_MODE_ONESHOT)) { • In an Action if ((preemptor = find_preemptor(s,new_task))) { (s->clock)->settimer(s->clock, preemptor->resume_time - now); } else { (s->clock)->settimer(s->clock, (HRTICKS_PER_SEC / HZ) / 2 ); } 優先權 Task A < Task B set_bit (RT_SCHED_TIMER_OK, &s->sched_flags); }
  • 29. RTOS Kernel::Memory 在 i386 硬體架構下, Jamei 可支援 • Introduction MMU (virtual memory) 與 MPU • Structure (memory protection) • RTOS Kernel • Tasks 區分 user-space 與 kernel-space • Memory void start_kernel(void) memory • Timers { /* architecture-dependent */ • I/O init_arch(); • IPCs /* NOTE: - Mask all interrupts. • Device Driver - Interrupts are mapped in 0x20-0x30 IDT entries */ • In an Action #if CONFIG_KERNEL_MEMORYPROT User Space memory init_page(); P1 P2 #endif #if CONFIG_CONTEXT_MEMORYPROT init_context(); M1 M2 #endif Kernel Space Memory ...
  • 30. RTOS Kernel::Memory Jamei 仿效 POSIX/Linux 的處理 APIs • Introduction kmalloc / kfree • Structure • RTOS Kernel mmap • Tasks shm (shared memory area) • Memory • Timers 有彈性的記憶體管理機制 • I/O 放任 (no protected memory) • IPCs • Device Driver 最低限度記憶體保護機制 • In an Action 不可寫入 RT executive 記憶體 保護 context 執行單元記憶體
  • 31. RTOS Kernel::Timer Timer 本質上是硬體時鐘的軟體呈現 型態 #define HRT_FROM_NS(x) (x) • Introduction #define HRTICKS_PER_SEC 1000000000 watchdog timer • Structure #ifndef HRT_FROM_8254 • RTOS Kernel programmable #ifndef HRT_FROM_8254 • Tasks #define HRT_FROM_8254(x) ((x) * 838) timer #endif • Memory #ifndef HRT_TO_8254 • Timers #define HRT_TO_8254(x) ((x) / 838) • I/O #endif • IPCs • Device Driver • In an Action
  • 32. RTOS Kernel::Timer struct rt_clock { 萬惡 HZ ... int (*sethrtime)( struct rt_clock *, 實做 HRT (High hrtime_t t); • Introduction Resolution Timer) int (*settimer)( • Structure struct rt_clock *, • RTOS Kernel 用於 sched, sync 等 hrtime_t interval); ... • Tasks hrtime_t resolution; 系統實作 hrtime_t value; • Memory hrtime_t delta; • Timers pthread_spinlock_t lock; struct rt_clock_arch arch; • I/O }; • IPCs int rt_schedule(void) • Device Driver { ... • In an Action if ((s->clock->mode == RT_CLOCK_MODE_ONESHOT)) { if ((preemptor = find_preemptor(s,new_task))) { (s->clock)->settimer(s->clock, preemptor->resume_time - now); } else { (s->clock)->settimer(s->clock, (HRTICKS_PER_SEC / HZ) / 2 ); } ...
  • 33. RTOS Kernel::I/O everything is file Interrupt-driven • Introduction polling / DMA • Structure • RTOS Kernel I/O mapping • Tasks memory space 與 I/O 操作的對應 • Memory • Timers APIs • I/O open / close • IPCs • Device Driver read / write • In an Action mmap register_rtdev / unregister_rtdev
  • 34. RTOS Kernel::IPC 其實是 Inter-Task Communications 可配置的組態 • Introduction Signals • Structure • RTOS Kernel Semaphore • Tasks • Memory • Timers • I/O • IPCs signals • Device Driver • In an Action semaphore
  • 35. RTOS Kernel::Device Driver static struct rt_file_operations rt_mem_fops = { rt_mem_llseek, rt_mem_read, • Introduction rt_mem_write, NULL, • Structure rt_mem_mmap, Client Drivers rt_mem_open, • RTOS Kernel rt_mem_release • Tasks }; • Memory • Timers Protocol Layers • I/O • IPCs • Device Driver • In an Action Host Controller Drivers Hardware
  • 36. In an Action • Introduction • Structure • RTOS Kernel • Tasks • Memory • Timers • I/O • IPCs • Device Driver • In an Action
  • 38. 控制系統 軌跡產生器 控制 反應行為 trajectory 決策邏輯 sensor Network RT task 控制與軌跡生成 Robot Interpration 低階控制系統
  • 39. gdb stub 考慮在 emulation/target 模式下,該如何喚起 gdb ? Remote Debugging :透過 serial 或 TCP/IP 進行遠端除錯
  • 40. Show me the Robot
  • 41.
  • 42.
  • 44. IP Network UDP – best­effort datagrams ➢ TCP – connection oriented, reliable byte­stream,  ➢ full­duplex Application Flow control, congestion control, etc ➢ IP – best­effort packet delivery ➢ UDP TCP Forwarding, fragmentation ➢ ICMP IP 並未對資源消耗作優化 相對來說,是可行的解決方案 Network 共通性
  • 45. TCP/IP stack design Application lwIP – lightweight IP UDP TCP ● “Application driven” : larger ICMP ● IP µIP – micro IP ● Network “Network driven” : smaller ●
  • 46. TCP/IP stack design Application Application driven UDP TCP ICMP IP Network Stack Application Network lwip Network driven Application Stack Network uIP
  • 47. 資源有限、慾望無窮 成本、實體空間 Memory ~10 k RAM, ~100 k ROM Energy, power consumption Batteries, ~10 mW Bandwidth ~100 kbits/second
  • 49. 資源限制: Memory+TCP/IP RAM vs throughput 基本上是兩難 More memory Less memory
  • 51. 資源限制:功耗 listening 與 receiving 一樣耗電
  • 52. 資源限制:功耗 listening 與 receiving 一樣耗電,需透過軟體解決 ➢ Solution 1: don’t listen (ZigBee) ➢ Listening nodes have a lot of energy (mains powered) ➢ Problem: makes mesh networking difficult ➢ Solution 2: be smart about listening and energy ➢ Power-saving radio mechanisms ➢
  • 54. 資源限制: TCP/IP bandwidth ~100 kbit/second Messages are small Header 802.15.4 max size 128 bytes TCP/IP headers are large Data
  • 55. TCP/IP header is too long TCP/IP headers 40 bytes UDP/IP headers 28 bytes 802.15.4 frame size 128 bytes 27% – 36% overhead IPv6 adds 20 bytes 42% – 52% overhead
  • 56. Header compression 僅傳遞重要資訊 48 bytes IP 1-4 bytes UDP Compressed header Data Data
  • 58. TCP/IP stack design Application Application driven UDP TCP ICMP IP Network Stack Application Network lwip Network driven Application Stack Network uIP
  • 59. lwIP – Application driven Application http://savannah.nongnu.org/projects/lwip/ ● lwIP – lightweight IP ● UDP TCP First release late 2000 ● ICMP IP 40k code, 40k RAM ● Network Application driven design ● Similar to Linux, BSD stacks ● Middle­end Application driven ● Network Stack Application
  • 60. µIP – smallest “full” TCP/IP stack Application http://www.sics.se/~adam/uip/ ● TCP UDP First release 2001 ● ICMP IP 3 ­ 5k code, 100 bytes ­ 2k RAM ● Network “Full” TCP/IP (RFC compliant) ● Used in Contiki OS ● Network driven Application Stack Network
  • 61.  µIP 技巧 Shared packet buffer ● Lower throughput ● Event­driven APIs ●
  • 62. Shared packet buffer 所有封包 (outbound + inbound ) 使用同一份 ● 緩衝區 緩衝區的大小決定 throughput ● Outbound packet Incoming packet Packet buffer
  • 63. Shared packet buffer Implicit locking: single­threaded access ● 1) Grab packet from network – put into buffer 2) Process packet Put reply packet in the same buffer ● 3) Send reply packet into network Packet buffer
  • 64. Lower Throughput µIP trades throughput for RAM ● Low RAM usage = low throughput ● 小的系統通常不會有太多資料 ● 「具通訊的能力」會比 throughput 多寡 ● 來得重要
  • 65. Event­driven APIs µIP 沒有 BSD sockets ● BSD sockets 建構於 threads 之上 ● Threads 引來 overhead (RAM) ● 因此,透過特製的 event­driven API ● co­routine ● Applications are called by µIP, call must return ● Protosockets – BSD socket­like API based  ● on protothreads
  • 66. Protothread int a_protothread(struct pt *pt) { PT_BEGIN(pt); /* … */ PT_WAIT_UNTIL(pt, condition1); /* … */ if(something) { /* … */ PT_WAIT_UNTIL(pt, condition2); /* … */ } PT_END(pt); }
  • 67. Hierarchical Protothreads int a_protothread(struct pt *pt) { static struct pt child_pt; PT_BEGIN(pt); PT_INIT(&child_pt); PT_WAIT_UNTIL(pt2(&child_pt) != 0); PT_END(pt); } int pt2(struct pt *pt) { PT_BEGIN(pt); PT_WAIT_UNTIL(pt, condition); PT_END(pt); }
  • 68. Threads vs. Events Threads: sequential code flow Events: unstructured code flow No blocking wait!
  • 69. Events require one stack Threads require per­thread stack memory Four event handlers, one  Four threads, each with its own stack ● stack Thread 4 Thread 1 Thread 2 Thread 3 Stack is reused for  every event handler Eventhandler 1 Eventhandler 2 Eventhandler 3 Eventhandler 4
  • 70. Protothreads require one stack Threads require per­thread stack memory Four protothreads, one  Four threads, each with its own stack ● stack Thread 4 Just like events Thread 1 Thread 2 Thread 3 Events require one stack Four event handlers, one  ● stack Protothread 1 Protothread 2 Protothread 3 Protothread 4
  • 71. Event­driven APIs void example2_app(void) {    struct example2_state *s =       (struct example2_state *)uip_conn­>appstate;    if(uip_connected()) {       s­>state = WELCOME_SENT;       uip_send(quot;Welcome!nquot;, 9);       return;    if(uip_rexmit()) {    }       switch(s­>state) {       case WELCOME_SENT:    if(uip_acked() &&        s­>state == WELCOME_SENT) {         uip_send(quot;Welcome!nquot;, 9);       s­>state = WELCOME_ACKED;          break;       case WELCOME_ACKED:    }          uip_send(quot;oknquot;, 3);          break;    if(uip_newdata()) {       }       uip_send(quot;oknquot;, 3);    }    } }
  • 72. Event­driven APIs Event­driven API 不見得適用所有程式 ● Protosockets: sockets­like API using protothreads ● Extremely lightweight stackless threads ● 2 bytes per­thread state, no stack ● Protothreads 允許“ blocking” ,本質是循序的 ● overhead 遠小於真實的 thread ●
  • 73. Event­driven APIs PT_THREAD(smtp_protothread(void)) {   PSOCK_BEGIN(s);   PSOCK_READTO(s, 'n');   if(strncmp(inputbuffer, “220”, 3) != 0) {     PSOCK_CLOSE(s);     PSOCK_EXIT(s);   }   PSOCK_SEND(s, “HELO ”, 5);   PSOCK_SEND(s, hostname, strlen(hostname));   PSOCK_SEND(s, “rn”, 2);   PSOCK_READTO(s, 'n');   if(inputbuffer[0] != '2') {     PSOCK_CLOSE(s);     PSOCK_EXIT(s);   }
  • 74. Proof-of-concept TCP/IP stacks phpstack – TCP/IP stack, webserver written in PHP ● http://www.sics.se/~adam/phpstack/ miniweb – TCP/IP stack, webserver using 30 bytes of ● RAM http://www.sics.se/~adam/miniweb/
  • 76. 討論  µIP 適用於低階的環境 ➢ 中階或網路需求較高者,應用 lwIP 或 BSD ➢ socket Thread preemption ➢
  • 77. 情境: Process 正等待 Device I/O( 由中斷觸發 ) 的結束, 方可繼續執行 Waiting Running task task Makes the task runnable Interrupt interrupt Scheduler handler latency Interrupt scheduler handler scheduler duration duration latency kernel latency = interrupt latency + handler duration + scheduler latency + scheduler duration
  • 78. Waiting Running task task Makes the task runnable interrupt Interrupt Scheduler handler latency Interrupt scheduler handler scheduler duration duration latency 來源 Interrupts disabled by kernel code: Interrupt context, managed by the CPU handler with greater  spinlocks, driver code... priority Bad driver using the fast interrupt handler mode (should be reserved to timer interrupts). processes Other interrupts processed before. Process context, managed by the scheduler
  • 79. Waiting Running task task Makes the task runnable Interrupt interrupt Scheduler handler latency Interrupt scheduler handler scheduler duration latency duration 執行 interrupt handler 的時間,在以下情況會更嚴重: Preemption by other interrupts. Interrupt handler with a softirq component Interrupts disabled by kernel code Bad driver using the fast interrupt mode Other interrupts processed before.
  • 80. Waiting Running task task Makes the task runnable Interrupt interrupt Scheduler handler latency Interrupt scheduler scheduler handler duration duration latency 用於 scheduler 的時間,原因: Kernel code not preemptible. Need to wait for returning from interrupts or from system calls. Interrupts disabled for a long time in driver code. Can cause a timer interrupt to be missed.
  • 81. Waiting Running task task Makes the task runnable Interrupt interrupt Scheduler handler latency Interrupt scheduler handler scheduler duration latency duration 執行 scheduler 並切換到新的 task 所耗費的時間 執行 scheduler 的時間為常數 context switching time Restoring processor registers and stack for the new process. Restoring the address space of the new process (except for threads sharing the same address space).