qduino a multithreaded arduino system for embedded
play

Qduino: A Multithreaded Arduino System for Embedded Computing - PowerPoint PPT Presentation

Qduino: A Multithreaded Arduino System for Embedded Computing Zhuoqun Cheng, Ye Li, Richard West Computer Science Background Many Robotics, Internet of Things, Home Automation applications have been developed recently Perform complicated


  1. Qduino: A Multithreaded Arduino System for Embedded Computing Zhuoqun Cheng, Ye Li, Richard West Computer Science

  2. Background Many Robotics, Internet of Things, Home Automation applications have been developed recently Perform complicated computing tasks Interact with the physical world Need an easy-to-use platform to develop applications High processing capabilities Straightforward hardware and software interface 2

  3. Background Arduino Digital and analog GPIOs Simple API Low processing capabilities Arduino Uno: 16MHz 8-bit ATmega328P

  4. Background More powerful Arduino-compatible boards emerge to meet the demands Intel Galileo: 400MHz Intel Quark X1000 Intel Edison: 500MHz dual-core Atom Arduino-compatible: the same GPIO layout with the standard Arduino boards

  5. Background The standard Arduino runs sketches (Arduino program) on the bare metal New boards are shipped with Linux Able to afford the overhead of operating systems To cope with the complexity of the hardware Run sketches as Linux processes 6

  6. Motivation Linux lacks predictability Many embedded applications have real-time requirements RTOS is needed T he standard Arduino API designed for a single thread of execution No multithreading or concurrency Fails to utilize computing resources and hardware parallelism

  7. Contributions Qduino: a programming environment that provides support for preemptive multithreading Arduino API that guarantees timing predictability of different control flows in a sketch Multithreaded sketches, and synchronization and communication between control flows Temporal isolation between different control flows and asynchronous system events, e.g., interrupts Predictable event delivery for I/O handling in sketches

  8. Qduino Architecture Sketch ... loop1 loopN Quest Quest ... Native Native App App Qduino Libs User Kernel GPIO Driver SPI Driver I2C Driver x86 SoC Galileo Edison Minnowboard

  9. Arduino vs Qduino APIs Category Standard APIs New APIs (backward compatible) Structure setup(), loop() loop(id, C, T) Digital and pinMode(), Analog I/Os digitalWrite(),digitalRead(), anlogWrite(), anlogRead() Interrupts Interrupts(), noInterrupts(), interruptsVcpu(C, T), attachInterrupt(pin, ISR, mode), attachInterruptVcpu(pin, ISR, detachInterrupt(pin) mode, C, T) Synchronization spinlock, four-slot channel, & ringbuffer Communication Other Utility micros(), delay(), min(), sqrt(), sin(), Functions isLowerCase(), random(), bitset(), ...

  10. Contributions Qduino: Multithreaded sketches, and synchronization and communication between control flows Temporal isolation between different control flows and asynchronous system events, e.g., interrupts Predictable event delivery for I/O handling in sketch

  11. Multithreaded Sketch Structure loop(), setup() loop(id, C, T) Standard API Sketch ... Only one loop() is allowed loop1 loopN Quest Quest ... Native Native App App Qduino Libs Blocking I/Os block the sketch User Kernel Qduino: GPIO Driver SPI Driver Up to 32 loop() in one sketch I2C Driver Each loop() function is assigned to x86 SoC a Quest thread Galileo Edison Minnowboard

  12. Multithreaded Sketch Benefits Loop interleaving Blocking I/Os won't block the entire sketch increase CPU utilization Easy to write sketches with parallel tasks Example: toggle pin 9 every 2s, pin 10 every 3s

  13. Multithreaded Sketch //Sketch 1: toggle pin 9 every 2s //Sketch 2: toggle pin 10 every 3s int val9 = 0; int val10 = 0; void setup() { void setup() { pinMode(9, OUTPUT); pinMode(10, OUTPUT); } } void loop() { void loop() { val9 = !val9; //flip the output value val10 = !val10; //flip the output value digitalWrite(9, val9); digitalWrite(10, val10); delay(2000); //delay 2s delay(3000); //delay 3s delay(2000); delay(3000); } } Delay(?) No way to merge them!

  14. Multithreaded Sketch int val9, val10 = 0; Inefficient int next_flip9, next_flip10 = 0; void setup() { Do scheduling by hand pinMode(9, OUTPUT); pinMode(10, OUTPUT); } Hard to scale void loop() { if (millis() >= next_flip9) if (millis() >= next_flip9) { val9 = !val9; //flip the output value digitalWrite(9, val9); next_flip9 += 2000; } if (millis() >= next_flip10) { if (millis() >= next_flip10) val10 = !val10; //flip the output value digitalWrite(10, val10); next_flip10 += 3000; } }

  15. Multithreaded Sketch int val9, val10 = 0; int C = 500, T = 1000; Multithreaded Sketch in Qduino void setup() { pinMode(9, OUTPUT); pinMode(10, OUTPUT); } void loop(1, 5, 10) { loop(1, C, T) val9 = !val9; //flip the output value digitalWrite(9, val9); delay(2000); } void loop(2, 5, 10) { loop(2, C, T) val10 = !val10; //flip the output value digitalWrite(10, val10); delay(3000); }

  16. Communication & Synchronization Loops – threads Function Signatures Category Communication via global ● spinlockInit(lock) Spinlock variables ● spinlockLock(lock) ● spinlockUnlock(lock) Serialized global variable access ● channelWrite(channel,item) Four-slot ● item channelRead(channel) Explicit: spinlock ● ringbufInit(buffer,size) Ring buffer Implicit: channel, ring buffer ● ringbufWrite(buffer,item) ● ringbufRead(buffer,item)

  17. Contributions Qduino: Multithreaded sketches, and synchronization and communication between control flows Temporal isolation between different control flows and asynchronous system events, e.g., interrupts Predictable event delivery for I/O handling in sketch

  18. Temporal Isolation Address Real-time Virtual CPU (VCPU) Space Scheduling Threads VCPU: kernel objects for time accounting and scheduling Main VCPUs Two classes: I/O VCPUs Main VCPU – conventional thread I/O VCPU – threaded interrupt handler PCPUs (Cores)

  19. Temporal Isolation Address Real-time Virtual CPU (VCPU) Space Scheduling Threads Each VCPU has a max budget C, a period T and a utilization U = C / T Main VCPUs Integrate the scheduling of tasks & I/O VCPUs I/O interrupts Extension to rate-monotonic scheduling Ensure temporal isolation if the Liu- Layland utilization bound is satisfied PCPUs (Cores)

  20. Temporal Isolation Structure loop(), setup() loop(id, C, T) Interrupts interrupts() interruptsVcpu(C, T) Sketch ... Quest Quest loop1 loopN ... Native Native Loop – thread – Main VCPU App App Qduino Libs Specify loop timing requirements User Kernel GPIO interrupt handler – I/O VCPU GPIO Driver Control # of interrupts to handle SPI Driver I2C Driver Balance CPU time between tasks, as well as tasks and interrupts x86 SoC Galileo Edison Minnowboard

  21. Contributions Qduino: Multithreaded sketches, and synchronization and communication between control flows Temporal isolation between different control flows and asynchronous system events, e.g., interrupts Predictable event delivery for I/O handling in sketch

  22. Predictable Events Category Standard APIs Newly added APIs Interrupts Interrupts(), noInterrupts(), interruptsVcpu(C, T), attachInterrupt(pin, ISR, attachInterruptVcpu(pin, ISR, mode), detachInterrupt(pin) mode, C, T) Sketch User Interrupt Thread Handler Event delivery time: the time interval attachInterruptVcpu between the invocation of the ISR User interrupt return and the invocation of the user-level Kernel Wakeup interrupt handler GPIO Driver Main Main VCPU VCPU Predictable end-to-end event delivery Interrupt I/O Bottom VCPU Half attachInterruptVcpu(..., C, T), Hardware interruptsVcpu(C, T) Scheduler Interrupt CPU Core(s) GPIO Expander

  23. Predictable Events I/O VCPU ( C io , T io ) – threaded interrupt bottom half Main VCPU (C h , T h ) – threaded user interrupt handler Worst Case Event Delivery Time : Interrupt bottom half execution time I/O VCPU used up budget Main VCPU used up budget Δ WCD =Δ bh +( T h − C h )=( T io − C io )+ ⌈ − 1 ⌉ ⋅ T io +δ bh modC io +( T h − C h ) δ bh C io

  24. Evaluation Experiment Setup Intel Galileo board Gen 1 Qduino vs. Clanton Clanton Linux 3.8.7 is shipped with the Galileo board

  25. Evaluation 12 11.2 10.8 Multithreaded Sketch Clanton 10 Qduino 8 7.7 7.6 7.6 8 Computation-intensive: find CPU Cycles (x10^9) all prime numbers smaller 6 than 80000 3.8 3.7 4 I/O-intensive: 2000 digital 2 write 0 Case 1 Case 2 Case 3 Case 4 Reduce 30% CPU Cycles Case # Description Case 1 Single-loop digitalWrite() Case 2 Single-loop findPrime Case 3 Single-loop digitalWrite() + findPrime Case 4 Multi-loop digitalWrite() + findPrime

  26. Evaluation Predictable loop execution 60 (50,100),2 (70,100),2 (90,100),2 Linux,2 (50,100),4 (70,100),4 (90,100),4 Linux,4 50 1 Foreground loop increments a counter during 40 Counter (x10 4 ) its loop period 30 2/4 background loops act as potential interference 20 10 Result interpretation Overlapped – temporal isolation 0 Straight line – timing guarantee 500T 100T 200T 300T 400T Time (Periods)

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend