Embedded Programming for IoT. John Light, Intel OTC OpenIoT Summit, San Diego 6 April 2016

Size: px
Start display at page:

Download "Embedded Programming for IoT. John Light, Intel OTC OpenIoT Summit, San Diego 6 April 2016"

Transcription

1 Embedded Programming for IoT John Light, Intel OTC OpenIoT Summit, San Diego 6 April 2016

2 Embedded programming is a lost art Fewer and fewer engineers understand embedded programming. Embedded software engineers are retiring and otherwise moving on. Most new engineers assume malloc, threads, and powerful CPUs. This decline in numbers matched the declining need until IoT appeared. IoT leaf nodes are proliferating radically, and many are very small devices. Small devices cost less and consume less power. Many leaf nodes can t run Linux, instead use RTOS. With so few resources, standard application methods shouldn t be used. 2

3 Embedded programming is critical to IoT Most IoT devices need careful embedded programming practices: Leaf nodes will proliferate in the millions, so they must be really inexpensive. Many leaf nodes will be highly power-constrained, some running on scavenged power, so they will have highly constrained resources. Many leaf nodes will need to run for months and years (decades?) without maintenance or replacement. Gateways will need to meet strict uptime requirements. Many gateways will be resource-constrained because of size, power, and cost constraints. 3

4 What I m going to talk about Why resources will remain constrained: cost, power, peripherals. General techniques of embedded programming: Memory handling Coroutines Myths about embedded memory management. What I m not going to talk about: RTOS choices and development environments. 4

5 Example processor for IoT Intel Quark SE (processor in the Intel Curie button SOC) 32 MHz processor (1992 i486 equivalent) 192 Kbytes code memory (late 80s PC equivalent) 80 Kbytes RAM (late 80s PC equivalent) Modern peripherals: Extremely low power sleep modes. Sensor hub, runs independently of processor. Accelerometer with 128 neuron net for pattern matching ADC with 19 analog comparators Battery charging circuit (in Curie) Bluetooth LE (in Curie) 5

6 Myth: IoT devices will use the latest technology IoT devices are extremely price sensitive. (Because so many!) They are invariable designed for trailing-edge processes to reduce cost. Older process nodes (65nm vs. 22nm) are much cheaper. 1-5 process nodes behind for many ARM IoT chips. 2-3 process nodes behind for Intel chips. This limits performance and other resources. 6

7 Myth: Moore s Law will solve the resource shortage Process improvements (e.g., 22nm -> 14nm) bring architectural tradeoffs. A new semiconductor node can be used several ways for an SOC: a. Make the die smaller to reduce cost. (Limitation: external interconnect) b. Leave the die the same size and put more computing resources on it. c. Leave the die the same size and add/improve peripheral features. d. Some combination of the above. I believe new processes will be used for two primary purposes: a. Reduce cost. The huge numbers of IoT devices will make them extremely price sensitive. b. Add/improve features. The IoT has a voracious appetite for new networking and specialized processing. c. Computing resources may grow, but not much. 7

8 Memory shortage Memory is always short in embedded systems. (See previous slides.) Even if there s enough of one kind of memory, another will be short. Which kind runs out first depends on application. This leads to trading one off for another. Normal heap usage (malloc/free) leads to fragmentation. Fragmentation is more likely as memory is more constrained. In machines with Virtual Memory, the effect is increased memory usage. In embedded systems, the effect is erratic behavior or system termination. In embedded programming, memory usage design is critical. An RTOS will support good memory design, but it won t hide the need. 8

9 Heap failure Heap failure is the inability of the heap to supply a required allocation in spite of having enough memory. Heap failure results from leaks (easily fixable) and fragmentation (not so much). Result of heap failure: program stops working. Whether you test return code from malloc() or not. Often unreported because report path or recovery code also has heap failure. Common story: It mysteriously stopped running but worked fine after restart. Most heap failures occur over time, and IoT nodes are often long-lived. 9

10 Fragmentation In this example, the heap is unable to provide 600 even though 1011 is available. This may seem contrived, but it happens all the time. Fragmentation is hidden by virtual memory, resulting in heap bloat. Malloc algorithms help a little bit, but only for specific usage patterns. Fragmentation occurs over time, often as a result of unexpected behavior. Testing is useful, but no amount of testing insures it won t happen. Checking for malloc failure doesn t keep it from happening. When malloc failure is found, others are likely going to happen right away. Reporting a malloc failure is hard because the reporting path may fail as well. 10

11 What are the symptoms of heap failure? Most programmers outside embedded programming have never seen and recognized a heap failure. Modern computers have amazing amounts of memory. Most applications don t run very long. We re all inured to random failures that clear up after restart. Heap failure reporting is often non-existent or weak. Many applications are built with sophisticated memory handling. 11

12 Myth: memory fragmentation results from leaks Memory fragmentation can occur when all memory leaks are eliminated. Fragmentation results from emergent behavior in an allocation algorithm relative to a specific usage pattern. Not all usage patterns result in fragmentation. Most don t. It s very hard to predict when fragmentation will occur. It s better to assume fragmentation will occur and avoid malloc/free. Of course, handling leaks is critical on embedded systems. Eliminate them! 12

13 Myth: fragmentation results from calling malloc() All fragmentation results from calling free(). If free is never called, there will be no fragmentation. This means you can use available malloc() calls to populate buffer pools. Just never free those pool buffers, and you ll be ok. This also give you a tool for analyzing existing software: look for the free() calls. 13

14 Myth: memory management hardware helps Since fragmentation occurs in highly constrained systems and highly constrained systems often lack memory management hardware, it is easy to assume: 1. The lack of memory management hardware is the source of the problem, and 2. Upgrading to an MMU will solve the problem. Neither is true. Eliminating this magical thinking will make it easier to solve the real problem. Fragmentation occurs with or without memory management hardware. 14

15 Bonus Myth: VM doesn t help, either. This Myth doesn t usually apply to embedded programming since few IoT leaf nodes will have Virtual Memory. To be pedantic, for many application memory usage patterns that result in heap failure due to fragmentation, adding more memory can result in a system that doesn t experience heap failure, but that s due to providing more memory, and has nothing to do with whether Virtual Memory is used to provide it. This myth applies to IoT gateways. (As do the others.) 15

16 The limitations of testing It s necessary to test IoT programs but not sufficient to ensure that they won t suffer from memory failures in normal heap management. Memory failures typically result from specific usage patterns, and the great variety of usage patterns is not predictable. If a failure usage pattern is not applied during testing, then that failure will not be seen during testing. Some memory failures result from long term usage, and there s no way to know how long that is, and it may be longer than any practical testing. Embedded programming of memory usage attempts to minimize the stochastic sources of memory failure. 16

17 Eliminate fragmentation Never call free()! How? Drastically minimize number of allocated buffers. (One per transaction?) Declare temporary buffers in other buffers or on stack. Be willing to waste memory by allocating maximum sized struct elements. Declare a small number of different buffer sizes (<10, even better: <5) Allocate these sizes from pools of fixed size buffers. Allocate fewer and bigger (more wasteful) buffers. 17

18 Think in terms of transactions IoT leaf node processing often consists of a series of largely independent transactions. Allocate one buffer to handle an entire transaction. If transaction buffer can be allocated, you are assured that the transaction can complete. If you can t allocate the one buffer, you can make an explicit decision about how to respond. Different types of transactions may require different size buffers. If the difference is less than a factor of 2, waste space by allocating the larger buffer size. If the difference is more than a factor of 2, allocate a small number of different buffers sizes. Transaction may leave traces, which may require their own buffers. The traces may require their own buffer size. 18

19 Barriers to transactional thinking Traditional software design encourages functional encapsulation. A transaction may consist of multiple protocol levels. (think socket, UDP, IP, link) Encapsulated design suggests a structure (or more) per level. (so far, so good) Traditional design suggests allocating a buffer for each structure, and linking them together. (this is where we get in trouble) Embedded design suggests allocating a single composite structure. A single buffer allocation is required for the composite structure of the transaction. Pointer handling is largely eliminated (and it s a major source of programming errors.) Some parts of the composite structure may not be needed. (Waste!) 19

20 Myth: wasting scarce memory must be avoided Embedded programming declares that predictability is more important than waste. Allocating the largest needed memory means that: The typical case will consume more memory than required. (waste!) The largest case can be handled. The logic, tests, and errors associated with different case sizes is eliminated. Waste is your friend. Consume away! 20

21 Waste example: string allocation struct foo {... char *name;... } struct foo {... char name[max_name_size];... } The left side requires a malloc for the string length. The right side doesn t. Predictability suggests using the right side all the time. Strings always have a maximum length. If you don t know what it is, you haven t done your homework. Secret: for smaller buffers, the heap overhead for an allocation is often larger than the amount of memory you think you are saving. 21

22 Waste example: temporary buffers struct foo {... struct bar *temp1;... } struct foo {... struct bar temp1;... } For most of a transaction temp1 will be unused. If struct bar is large, right side wastes much more than left side. In general, the left side doesn t reduce the maximum heap usage required during the transaction. Maximum usage determines heap failure. In all cases, after allocating foo, the right side ensures that the transaction will complete. Temporaries can can also be declared (and allocated) on the stack. 22

23 Transaction traces Transaction traces are side effects of a transaction that must be retained after the transaction completes and its transaction buffer is deleted. Trace example: a transaction may start persistent ongoing processing (observation/reporting?) that continues until stopped. Trace buffers need to be allocated independently of transaction buffers, and their size may be much different than that of a transaction buffer. A trace buffer typically holds a single (composite?) structure that holds all context needed for the purpose of the trace. 23

24 Buffer pools Once the total number of allocations has been reduced to a small number, you can create a memory pool for each size. Example: 3 pools, 24 bytes, 65 bytes, 1264 bytes. 1264b buffer is used for each transaction, two trace types are managed (24b and 65b). Guess how many of each size will be needed, and allocate those at startup. Each buffer type is allocated out of its respective memory pool only. When a buffer is no longer needed, it is returned to the memory pool whence it came. Run and analyze the number of each pool type that is needed. Study available memory and increase pool sizes to provide margin. 24

25 Benefits of memory pools Benefits aside from eliminating memory fragmentation. You can characterize and guarantee the behavior of your program: It will handle three transactions at a time. (3 transaction buffers) It will handle 5 observation requests. (5 observation traces) You can monitor the program and easily adjust parameters. It often runs low on observation trace buffers, so I will add a few. It informed me via network, that it is running short on observation trace buffers. You can implement fall-back strategies. If it runs out of observation trace buffers, cannibalize a transaction to add trace buffers and notify me that retuning is needed. 25

26 Exception handling IoT nodes need to report exceptions, most notably Out of Memory exceptions. The exception reporting path must be free of buffer allocations that can fail. This can be accomplished by pre-allocating buffers needed for reporting. Static allocation can also be used for the report buffers. Another case of predictability being more important than waste. IoT nodes can use tuning information such as buffer pool usage to report information that might predict future problems. 26

27 Embedded memory summary IoT leaf node software (and some gateways) will continue to be highly resourceconstrained due to requirements for minimizing cost, power, and maintenance. Embedded software requires explicit and careful memory handling to reliably run for long periods of time with limited memory resources. Techniques for careful embedded software memory handling are well known in the embedded application community, but they need wider visibility in the growing IoT community. 27

28 Coroutines Coroutines are a method for decomposing complex designs into manageable processes. Think of them as threads when you don t have threads. "Subroutines are special cases of... coroutines." Donald Knuth, Fundamental Algorithms Coroutines have been largely forgotten with the advent of object-oriented programming and the availability of thread libraries. Because highly constrained computing environments often lack threads, embedded programming uses coroutines in place of them to provide much the same benefit. 28

29 Threads Threading is used in conventional programming for two primary purposes: Decomposing complex systems. Providing concurrent processing on machines with CPU threads. Constrained computers often have a single thread or a limited number. When two threads are available in constrained environments, one thread is often dedicated to a particular purpose, such as the OS or sensor response. Threads remain a valuable tool for decomposing designs (meaning making software maintainable ). Coroutines fill that gap when hardware threads are not available. 29

30 Process decomposition Input Process Output There s usually some sort of processing in the Input and Output sections (checking peripherals, qualifying and transforming input, formatting output). Threading allows writing these processes independently and connecting them. 30

31 Process implementation with threads Input Process Output queue queue The queues allow separation of function and activity. In an environment with threads, you might apply a thread to each process block. Without threads, this might be written as a single logical process, so the implementation would be completely different. 31

32 Process implementation with coroutines Input Process Output queue queue Notice that the implementations with threads and coroutines look similar. That s the point. By thinking with coroutines, you can make the same code work with and without a threading library and hardware threads. 32

33 Threads and coroutines coexist (flow) threads Input Process Output queue queue in q1 (see next page) q2 out coroutines Input Process Output queue queue 33

34 Example coroutine code for previous slide void function input { while (inhasdata() && q1hasroom()) { d = infetch(); filterdata(&d, &f);... q1send(&f); } } void function process() { while (1) { input(); output(); if (q1hasdata() && q2hasroom()) { d = q1fetch(); processdata(&d, &r); q2send(&r); } } } void function output() { while (q2hasdata() && outhasroom()) { d = q2fetch(); formatdata(&d, &f);... outsend(&f); } } 34

35 Comments on code on previous slide The code is one example of the myriad ways coroutines can be written. No coroutine library is needed. To switch between threads and coroutines, a small amount of conditional code would be needed. The operation of the coroutines can be modified by changing the conditionals in the example. By using coroutines we can decompose processes without having threads. 35

36 Summary The characteristics of many IoT system means that embedded programming skills and techniques will be needed in a wide arena. Two aspects of embedded programming were discussed: Raising memory handling to a first-order design criterion, and Using coroutines to allow functional decomposition in the absence of threads. I intend this presentation to be part of a larger conversation between these fields. 36

37 References I have written two white papers on this subject. This one describes the memory issues in some detail. This one is a case study on using these techniques on real software. They should be active by conference start. 37

The Art and Science of Memory Allocation

The Art and Science of Memory Allocation Logical Diagram The Art and Science of Memory Allocation Don Porter CSE 506 Binary Formats RCU Memory Management Memory Allocators CPU Scheduler User System Calls Kernel Today s Lecture File System Networking

More information

o Code, executable, and process o Main memory vs. virtual memory

o Code, executable, and process o Main memory vs. virtual memory Goals for Today s Lecture Memory Allocation Prof. David August COS 217 Behind the scenes of running a program o Code, executable, and process o Main memory vs. virtual memory Memory layout for UNIX processes,

More information

QUIZ. What is wrong with this code that uses default arguments?

QUIZ. What is wrong with this code that uses default arguments? QUIZ What is wrong with this code that uses default arguments? Solution The value of the default argument should be placed in either declaration or definition, not both! QUIZ What is wrong with this code

More information

CSC 1600 Memory Layout for Unix Processes"

CSC 1600 Memory Layout for Unix Processes CSC 16 Memory Layout for Unix Processes" 1 Lecture Goals" Behind the scenes of running a program" Code, executable, and process" Memory layout for UNIX processes, and relationship to C" : code and constant

More information

Memory Management. q Basic memory management q Swapping q Kernel memory allocation q Next Time: Virtual memory

Memory Management. q Basic memory management q Swapping q Kernel memory allocation q Next Time: Virtual memory Memory Management q Basic memory management q Swapping q Kernel memory allocation q Next Time: Virtual memory Memory management Ideal memory for a programmer large, fast, nonvolatile and cheap not an option

More information

ECE 598 Advanced Operating Systems Lecture 14

ECE 598 Advanced Operating Systems Lecture 14 ECE 598 Advanced Operating Systems Lecture 14 Vince Weaver http://web.eece.maine.edu/~vweaver vincent.weaver@maine.edu 22 March 2018 HW#6 was due. Announcements HW#7 will be posted eventually. Project

More information

2018/10/29 22:25 1/5 Linux Processes vs NuttX Tasks

2018/10/29 22:25 1/5 Linux Processes vs NuttX Tasks 2018/10/29 22:25 1/5 Linux Processes vs NuttX Tasks Linux Processes vs NuttX Tasks You may be used to running programs that are stored in files on Linux or Windows. If you transition to using NuttX tasks

More information

Operating System Principles: Memory Management Swapping, Paging, and Virtual Memory CS 111. Operating Systems Peter Reiher

Operating System Principles: Memory Management Swapping, Paging, and Virtual Memory CS 111. Operating Systems Peter Reiher Operating System Principles: Memory Management Swapping, Paging, and Virtual Memory Operating Systems Peter Reiher Page 1 Outline Swapping Paging Virtual memory Page 2 Swapping What if we don t have enough

More information

ECE 550D Fundamentals of Computer Systems and Engineering. Fall 2017

ECE 550D Fundamentals of Computer Systems and Engineering. Fall 2017 ECE 550D Fundamentals of Computer Systems and Engineering Fall 2017 The Operating System (OS) Prof. John Board Duke University Slides are derived from work by Profs. Tyler Bletsch and Andrew Hilton (Duke)

More information

Memory Management. To do. q Basic memory management q Swapping q Kernel memory allocation q Next Time: Virtual memory

Memory Management. To do. q Basic memory management q Swapping q Kernel memory allocation q Next Time: Virtual memory Memory Management To do q Basic memory management q Swapping q Kernel memory allocation q Next Time: Virtual memory Memory management Ideal memory for a programmer large, fast, nonvolatile and cheap not

More information

CS370 Operating Systems

CS370 Operating Systems CS370 Operating Systems Colorado State University Yashwant K Malaiya Spring 2018 L17 Main Memory Slides based on Text by Silberschatz, Galvin, Gagne Various sources 1 1 FAQ Was Great Dijkstra a magician?

More information

CS162 Operating Systems and Systems Programming Lecture 11 Page Allocation and Replacement"

CS162 Operating Systems and Systems Programming Lecture 11 Page Allocation and Replacement CS162 Operating Systems and Systems Programming Lecture 11 Page Allocation and Replacement" October 3, 2012 Ion Stoica http://inst.eecs.berkeley.edu/~cs162 Lecture 9 Followup: Inverted Page Table" With

More information

Chapter 3 Memory Management: Virtual Memory

Chapter 3 Memory Management: Virtual Memory Memory Management Where we re going Chapter 3 Memory Management: Virtual Memory Understanding Operating Systems, Fourth Edition Disadvantages of early schemes: Required storing entire program in memory

More information

15 Sharing Main Memory Segmentation and Paging

15 Sharing Main Memory Segmentation and Paging Operating Systems 58 15 Sharing Main Memory Segmentation and Paging Readings for this topic: Anderson/Dahlin Chapter 8 9; Siberschatz/Galvin Chapter 8 9 Simple uniprogramming with a single segment per

More information

Anne Bracy CS 3410 Computer Science Cornell University

Anne Bracy CS 3410 Computer Science Cornell University Anne Bracy CS 3410 Computer Science Cornell University The slides were originally created by Deniz ALTINBUKEN. P&H Chapter 4.9, pages 445 452, appendix A.7 Manages all of the software and hardware on the

More information

ECE 598 Advanced Operating Systems Lecture 10

ECE 598 Advanced Operating Systems Lecture 10 ECE 598 Advanced Operating Systems Lecture 10 Vince Weaver http://www.eece.maine.edu/~vweaver vincent.weaver@maine.edu 17 February 2015 Announcements Homework #1 and #2 grades, HW#3 Coming soon 1 Various

More information

Memory Management: Virtual Memory and Paging CS 111. Operating Systems Peter Reiher

Memory Management: Virtual Memory and Paging CS 111. Operating Systems Peter Reiher Memory Management: Virtual Memory and Paging Operating Systems Peter Reiher Page 1 Outline Paging Swapping and demand paging Virtual memory Page 2 Paging What is paging? What problem does it solve? How

More information

Dynamic Memory Allocation

Dynamic Memory Allocation 1 Dynamic Memory Allocation Anne Bracy CS 3410 Computer Science Cornell University Note: these slides derive from those by Markus Püschel at CMU 2 Recommended Approach while (TRUE) { code a little; test

More information

Lectures 13 & 14. memory management

Lectures 13 & 14. memory management Lectures 13 & 14 Linked lists and memory management Courtesy of Prof. Garcia (UCB) CS61C L05 Introduction to C (pt 3) (1) Review Pointers and arrays are virtually same C knows how to increment pointers

More information

System Architecture Directions for Networked Sensors. Jason Hill et. al. A Presentation by Dhyanesh Narayanan MS, CS (Systems)

System Architecture Directions for Networked Sensors. Jason Hill et. al. A Presentation by Dhyanesh Narayanan MS, CS (Systems) System Architecture Directions for Networked Sensors Jason Hill et. al. A Presentation by Dhyanesh Narayanan MS, CS (Systems) Sensor Networks Key Enablers Moore s s Law: More CPU Less Size Less Cost Systems

More information

Memory Allocation. Copyright : University of Illinois CS 241 Staff 1

Memory Allocation. Copyright : University of Illinois CS 241 Staff 1 Memory Allocation Copyright : University of Illinois CS 241 Staff 1 Recap: Virtual Addresses A virtual address is a memory address that a process uses to access its own memory Virtual address actual physical

More information

Dynamic Memory: Alignment and Fragmentation

Dynamic Memory: Alignment and Fragmentation Dynamic Memory: Alignment and Fragmentation Learning Objectives Explain the purpose of dynamic memory Define the terms arena, heap Identify common errors involving dynamic memory Explain how dynamic memory

More information

Three OPTIMIZING. Your System for Photoshop. Tuning for Performance

Three OPTIMIZING. Your System for Photoshop. Tuning for Performance Three OPTIMIZING Your System for Photoshop Tuning for Performance 72 Power, Speed & Automation with Adobe Photoshop This chapter goes beyond speeding up how you can work faster in Photoshop to how to make

More information

Engine Support System. asyrani.com

Engine Support System. asyrani.com Engine Support System asyrani.com A game engine is a complex piece of software consisting of many interacting subsystems. When the engine first starts up, each subsystem must be configured and initialized

More information

Chapter 9: Virtual-Memory

Chapter 9: Virtual-Memory Chapter 9: Virtual-Memory Management Chapter 9: Virtual-Memory Management Background Demand Paging Page Replacement Allocation of Frames Thrashing Other Considerations Silberschatz, Galvin and Gagne 2013

More information

Habanero Extreme Scale Software Research Project

Habanero Extreme Scale Software Research Project Habanero Extreme Scale Software Research Project Comp215: Garbage Collection Zoran Budimlić (Rice University) Adapted from Keith Cooper s 2014 lecture in COMP 215. Garbage Collection In Beverly Hills...

More information

Kernels & Processes The Structure of the Operating System

Kernels & Processes The Structure of the Operating System COMP 111: Operating Systems (Fall 2013) Kernels & Processes The Structure of the Operating System Noah Mendelsohn Tufts University Email: noah@cs.tufts.edu Web: http://www.cs.tufts.edu/~noah Based on a

More information

! What is main memory? ! What is static and dynamic allocation? ! What is segmentation? Maria Hybinette, UGA. High Address (0x7fffffff) !

! What is main memory? ! What is static and dynamic allocation? ! What is segmentation? Maria Hybinette, UGA. High Address (0x7fffffff) ! Memory Questions? CSCI [4 6]730 Operating Systems Main Memory! What is main memory?! How does multiple processes share memory space?» Key is how do they refer to memory addresses?! What is static and dynamic

More information

Addresses in the source program are generally symbolic. A compiler will typically bind these symbolic addresses to re-locatable addresses.

Addresses in the source program are generally symbolic. A compiler will typically bind these symbolic addresses to re-locatable addresses. 1 Memory Management Address Binding The normal procedures is to select one of the processes in the input queue and to load that process into memory. As the process executed, it accesses instructions and

More information

16 Sharing Main Memory Segmentation and Paging

16 Sharing Main Memory Segmentation and Paging Operating Systems 64 16 Sharing Main Memory Segmentation and Paging Readings for this topic: Anderson/Dahlin Chapter 8 9; Siberschatz/Galvin Chapter 8 9 Simple uniprogramming with a single segment per

More information

Dynamic Memory Allocation

Dynamic Memory Allocation Dynamic Memory Allocation CS61, Lecture 10 Prof. Stephen Chong October 4, 2011 Announcements 1/2 Assignment 4: Malloc Will be released today May work in groups of one or two Please go to website and enter

More information

The Art and Science of Memory Alloca4on

The Art and Science of Memory Alloca4on The Art and Science of Memory Alloca4on Don Porter 1 Binary Formats RCU Logical Diagram Memory Allocators Threads User System Calls Kernel Today s Lecture File System Networking Sync Memory Management

More information

Classifying Information Stored in Memory! Memory Management in a Uniprogrammed System! Segments of a Process! Processing a User Program!

Classifying Information Stored in Memory! Memory Management in a Uniprogrammed System! Segments of a Process! Processing a User Program! Memory Management in a Uniprogrammed System! A! gets a fixed segment of (usually highest )"! One process executes at a time in a single segment"! Process is always loaded at "! Compiler and linker generate

More information

Parallelism: The Real Y2K Crisis. Darek Mihocka August 14, 2008

Parallelism: The Real Y2K Crisis. Darek Mihocka August 14, 2008 Parallelism: The Real Y2K Crisis Darek Mihocka August 14, 2008 The Free Ride For decades, Moore's Law allowed CPU vendors to rely on steady clock speed increases: late 1970's: 1 MHz (6502) mid 1980's:

More information

Computer Architecture. Lecture 8: Virtual Memory

Computer Architecture. Lecture 8: Virtual Memory Computer Architecture Lecture 8: Virtual Memory Dr. Ahmed Sallam Suez Canal University Spring 2015 Based on original slides by Prof. Onur Mutlu Memory (Programmer s View) 2 Ideal Memory Zero access time

More information

CSE 4/521 Introduction to Operating Systems. Lecture 15 Virtual Memory I (Background, Demand Paging) Summer 2018

CSE 4/521 Introduction to Operating Systems. Lecture 15 Virtual Memory I (Background, Demand Paging) Summer 2018 CSE 4/521 Introduction to Operating Systems Lecture 15 Virtual Memory I (Background, Demand Paging) Summer 2018 Overview Objective: To describe the benefits of a virtual memory system. To explain the concept

More information

CS399 New Beginnings. Jonathan Walpole

CS399 New Beginnings. Jonathan Walpole CS399 New Beginnings Jonathan Walpole Memory Management Memory Management Memory a linear array of bytes - Holds O.S. and programs (processes) - Each cell (byte) is named by a unique memory address Recall,

More information

Chapter 5: ASICs Vs. PLDs

Chapter 5: ASICs Vs. PLDs Chapter 5: ASICs Vs. PLDs 5.1 Introduction A general definition of the term Application Specific Integrated Circuit (ASIC) is virtually every type of chip that is designed to perform a dedicated task.

More information

CHAPTER 8 - MEMORY MANAGEMENT STRATEGIES

CHAPTER 8 - MEMORY MANAGEMENT STRATEGIES CHAPTER 8 - MEMORY MANAGEMENT STRATEGIES OBJECTIVES Detailed description of various ways of organizing memory hardware Various memory-management techniques, including paging and segmentation To provide

More information

Review! Lecture 5 C Memory Management !

Review! Lecture 5 C Memory Management ! CS61C L05 C Memory Management (1)! inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 5 C Memory Management 2010-06-28!!! Instructor Paul Pearce! Symmetric multiprocessor! MIPS support for

More information

CS61C : Machine Structures

CS61C : Machine Structures inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 5 C Memory Management 2010-06-28!!! Instructor Paul Pearce! Symmetric multiprocessor! MIPS support for Android MIPS Technologies (founded

More information

19 File Structure, Disk Scheduling

19 File Structure, Disk Scheduling 88 19 File Structure, Disk Scheduling Readings for this topic: Silberschatz et al., Chapters 10 11. File: a named collection of bytes stored on disk. From the OS standpoint, the file consists of a bunch

More information

Memory. From Chapter 3 of High Performance Computing. c R. Leduc

Memory. From Chapter 3 of High Performance Computing. c R. Leduc Memory From Chapter 3 of High Performance Computing c 2002-2004 R. Leduc Memory Even if CPU is infinitely fast, still need to read/write data to memory. Speed of memory increasing much slower than processor

More information

Operating Systems. Operating Systems

Operating Systems. Operating Systems The operating system defines our computing experience. It is the first software we see when we turn on the computer, and the last software we see when the computer is turned off. It's the software that

More information

ECEN 449 Microprocessor System Design. Hardware-Software Communication. Texas A&M University

ECEN 449 Microprocessor System Design. Hardware-Software Communication. Texas A&M University ECEN 449 Microprocessor System Design Hardware-Software Communication 1 Objectives of this Lecture Unit Learn basics of Hardware-Software communication Memory Mapped I/O Polling/Interrupts 2 Motivation

More information

Lecture 4: Threads; weaving control flow

Lecture 4: Threads; weaving control flow Lecture 4: Threads; weaving control flow CSE 120: Principles of Operating Systems Alex C. Snoeren HW 1 Due NOW Announcements Homework #1 due now Project 0 due tonight Project groups Please send project

More information

Linux multi-core scalability

Linux multi-core scalability Linux multi-core scalability Oct 2009 Andi Kleen Intel Corporation andi@firstfloor.org Overview Scalability theory Linux history Some common scalability trouble-spots Application workarounds Motivation

More information

Chapter 8 & Chapter 9 Main Memory & Virtual Memory

Chapter 8 & Chapter 9 Main Memory & Virtual Memory Chapter 8 & Chapter 9 Main Memory & Virtual Memory 1. Various ways of organizing memory hardware. 2. Memory-management techniques: 1. Paging 2. Segmentation. Introduction Memory consists of a large array

More information

THE TROUBLE WITH MEMORY

THE TROUBLE WITH MEMORY THE TROUBLE WITH MEMORY OUR MARKETING SLIDE Kirk Pepperdine Authors of jpdm, a performance diagnostic model Co-founded Building the smart generation of performance diagnostic tooling Bring predictability

More information

THINK LIKE CREATIVE PROBLEM SOLVING V. ANTON SPRAUL

THINK LIKE CREATIVE PROBLEM SOLVING V. ANTON SPRAUL THINK LIKE A PROGRAMMERA A N I N T R O D U C T I O N T O CREATIVE PROBLEM SOLVING V. ANTON SPRAUL CODE EAT SLEEP INDEX Numbers and Symbols && operator (logical and), 48 short-circuit evaluation of, 129,

More information

Memory Management Topics. CS 537 Lecture 11 Memory. Virtualizing Resources

Memory Management Topics. CS 537 Lecture 11 Memory. Virtualizing Resources Memory Management Topics CS 537 Lecture Memory Michael Swift Goals of memory management convenient abstraction for programming isolation between processes allocate scarce memory resources between competing

More information

CS61C Midterm Review on C & Memory Management

CS61C Midterm Review on C & Memory Management CS61C Midterm Review on C & Memory Management Fall 2006 Aaron Staley Some material taken from slides by: Michael Le Navtej Sadhal Overview C Array and Pointer Goodness! Memory Management The Three Three

More information

System Architecture Directions for Networked Sensors[1]

System Architecture Directions for Networked Sensors[1] System Architecture Directions for Networked Sensors[1] Secure Sensor Networks Seminar presentation Eric Anderson System Architecture Directions for Networked Sensors[1] p. 1 Outline Sensor Network Characteristics

More information

Today. Dynamic Memory Allocation: Basic Concepts. Dynamic Memory Allocation. Dynamic Memory Allocation. malloc Example. The malloc Package

Today. Dynamic Memory Allocation: Basic Concepts. Dynamic Memory Allocation. Dynamic Memory Allocation. malloc Example. The malloc Package Today Dynamic Memory Allocation: Basic Concepts Basic concepts Performance concerns Approach 1: implicit free lists CSci 01: Machine Architecture and Organization Lecture #9, April th, 016 Your instructor:

More information

OpenACC Course. Office Hour #2 Q&A

OpenACC Course. Office Hour #2 Q&A OpenACC Course Office Hour #2 Q&A Q1: How many threads does each GPU core have? A: GPU cores execute arithmetic instructions. Each core can execute one single precision floating point instruction per cycle

More information

Heap Management. Heap Allocation

Heap Management. Heap Allocation Heap Management Heap Allocation A very flexible storage allocation mechanism is heap allocation. Any number of data objects can be allocated and freed in a memory pool, called a heap. Heap allocation is

More information

Chapter 9: Virtual Memory. Operating System Concepts 9 th Edition

Chapter 9: Virtual Memory. Operating System Concepts 9 th Edition Chapter 9: Virtual Memory Silberschatz, Galvin and Gagne 2013 Chapter 9: Virtual Memory Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped Files Allocating

More information

Memory Hierarchy. Mehran Rezaei

Memory Hierarchy. Mehran Rezaei Memory Hierarchy Mehran Rezaei What types of memory do we have? Registers Cache (Static RAM) Main Memory (Dynamic RAM) Disk (Magnetic Disk) Option : Build It Out of Fast SRAM About 5- ns access Decoders

More information

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages CMSC 330: Organization of Programming Languages Multithreading Multiprocessors Description Multiple processing units (multiprocessor) From single microprocessor to large compute clusters Can perform multiple

More information

Java Without the Jitter

Java Without the Jitter TECHNOLOGY WHITE PAPER Achieving Ultra-Low Latency Table of Contents Executive Summary... 3 Introduction... 4 Why Java Pauses Can t Be Tuned Away.... 5 Modern Servers Have Huge Capacities Why Hasn t Latency

More information

Moore s Law. Computer architect goal Software developer assumption

Moore s Law. Computer architect goal Software developer assumption Moore s Law The number of transistors that can be placed inexpensively on an integrated circuit will double approximately every 18 months. Self-fulfilling prophecy Computer architect goal Software developer

More information

Operating Systems. Week 9 Recitation: Exam 2 Preview Review of Exam 2, Spring Paul Krzyzanowski. Rutgers University.

Operating Systems. Week 9 Recitation: Exam 2 Preview Review of Exam 2, Spring Paul Krzyzanowski. Rutgers University. Operating Systems Week 9 Recitation: Exam 2 Preview Review of Exam 2, Spring 2014 Paul Krzyzanowski Rutgers University Spring 2015 March 27, 2015 2015 Paul Krzyzanowski 1 Exam 2 2012 Question 2a One of

More information

Operating Systems. IV. Memory Management

Operating Systems. IV. Memory Management Operating Systems IV. Memory Management Ludovic Apvrille ludovic.apvrille@telecom-paristech.fr Eurecom, office 470 http://soc.eurecom.fr/os/ @OS Eurecom Outline Basics of Memory Management Hardware Architecture

More information

Chapter 8: Memory- Management Strategies. Operating System Concepts 9 th Edition

Chapter 8: Memory- Management Strategies. Operating System Concepts 9 th Edition Chapter 8: Memory- Management Strategies Operating System Concepts 9 th Edition Silberschatz, Galvin and Gagne 2013 Chapter 8: Memory Management Strategies Background Swapping Contiguous Memory Allocation

More information

The Return of Innovation. David May. David May 1 Cambridge December 2005

The Return of Innovation. David May. David May 1 Cambridge December 2005 The Return of Innovation David May David May 1 Cambridge December 2005 Long term trends Computer performance/cost has followed an exponential path since the 1940s, doubling about every 18 months This has

More information

Contents. Slide Set 1. About these slides. Outline of Slide Set 1. Typographical conventions: Italics. Typographical conventions. About these slides

Contents. Slide Set 1. About these slides. Outline of Slide Set 1. Typographical conventions: Italics. Typographical conventions. About these slides Slide Set 1 for ENCM 369 Winter 2014 Lecture Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary Winter Term, 2014 ENCM 369 W14 Section

More information

Lecture 7: Binding Time and Storage

Lecture 7: Binding Time and Storage Lecture 7: Binding Time and Storage COMP 524 Programming Language Concepts Stephen Olivier February 5, 2009 Based on notes by A. Block, N. Fisher, F. Hernandez-Campos, and D. Stotts Goal of Lecture The

More information

ECE 471 Embedded Systems Lecture 2

ECE 471 Embedded Systems Lecture 2 ECE 471 Embedded Systems Lecture 2 Vince Weaver http://web.eece.maine.edu/~vweaver vincent.weaver@maine.edu 7 September 2018 Announcements Reminder: The class notes are posted to the website. HW#1 will

More information

CS61C : Machine Structures

CS61C : Machine Structures inst.eecs.berkeley.edu/~cs61c/su06 CS61C : Machine Structures Lecture #6: Memory Management CS 61C L06 Memory Management (1) 2006-07-05 Andy Carle Memory Management (1/2) Variable declaration allocates

More information

ECE 598 Advanced Operating Systems Lecture 12

ECE 598 Advanced Operating Systems Lecture 12 ECE 598 Advanced Operating Systems Lecture 12 Vince Weaver http://web.eece.maine.edu/~vweaver vincent.weaver@maine.edu 1 March 2018 Announcements Next homework will be due after break. Midterm next Thursday

More information

Operating Systems. Memory Management. Lecture 9 Michael O Boyle

Operating Systems. Memory Management. Lecture 9 Michael O Boyle Operating Systems Memory Management Lecture 9 Michael O Boyle 1 Memory Management Background Logical/Virtual Address Space vs Physical Address Space Swapping Contiguous Memory Allocation Segmentation Goals

More information

Dynamic Memory Allocation

Dynamic Memory Allocation Dynamic Memory Allocation Computer Systems Organization (Spring 2017) CSCI-UA 201, Section 3 Instructor: Joanna Klukowska Slides adapted from Randal E. Bryant and David R. O Hallaron (CMU) Mohamed Zahran

More information

Chapter 8 Memory Management

Chapter 8 Memory Management 1 Chapter 8 Memory Management The technique we will describe are: 1. Single continuous memory management 2. Partitioned memory management 3. Relocatable partitioned memory management 4. Paged memory management

More information

Chapter 8: Main Memory

Chapter 8: Main Memory Chapter 8: Main Memory Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Segmentation Paging Structure of the Page Table Example: The Intel 32 and 64-bit Architectures Example:

More information

Advanced Programming & C++ Language

Advanced Programming & C++ Language Advanced Programming & C++ Language ~6~ Introduction to Memory Management Ariel University 2018 Dr. Miri (Kopel) Ben-Nissan Stack & Heap 2 The memory a program uses is typically divided into four different

More information

Memory Management Basics

Memory Management Basics Memory Management Basics 1 Basic Memory Management Concepts Address spaces! Physical address space The address space supported by the hardware Ø Starting at address 0, going to address MAX sys! MAX sys!!

More information

Memory Hierarchy, Fully Associative Caches. Instructor: Nick Riasanovsky

Memory Hierarchy, Fully Associative Caches. Instructor: Nick Riasanovsky Memory Hierarchy, Fully Associative Caches Instructor: Nick Riasanovsky Review Hazards reduce effectiveness of pipelining Cause stalls/bubbles Structural Hazards Conflict in use of datapath component Data

More information

ELEC 377 Operating Systems. Week 1 Class 2

ELEC 377 Operating Systems. Week 1 Class 2 Operating Systems Week 1 Class 2 Labs vs. Assignments The only work to turn in are the labs. In some of the handouts I refer to the labs as assignments. There are no assignments separate from the labs.

More information

Real-Time and Embedded Systems (M) Lecture 19

Real-Time and Embedded Systems (M) Lecture 19 Low-Level/Embedded Programming Real-Time and Embedded Systems (M) Lecture 19 Lecture Outline Hardware developments Implications on system design Low-level programming Automatic memory management Timing

More information

Even coarse architectural trends impact tremendously the design of systems

Even coarse architectural trends impact tremendously the design of systems CSE 451: Operating Systems Spring 2006 Module 2 Architectural Support for Operating Systems John Zahorjan zahorjan@cs.washington.edu 534 Allen Center Even coarse architectural trends impact tremendously

More information

Operating Systems and Computer Networks. Memory Management. Dr.-Ing. Pascal A. Klein

Operating Systems and Computer Networks. Memory Management. Dr.-Ing. Pascal A. Klein Operating Systems and Computer Networks Memory Management pascal.klein@uni-due.de Alexander Maxeiner, M.Sc. Faculty of Engineering Agenda 1 Swapping 2 Segmentation Algorithms 3 Memory Allocation 4 Virtual

More information

Memory management has always involved tradeoffs between numerous optimization possibilities: Schemes to manage problem fall into roughly two camps

Memory management has always involved tradeoffs between numerous optimization possibilities: Schemes to manage problem fall into roughly two camps Garbage Collection Garbage collection makes memory management easier for programmers by automatically reclaiming unused memory. The garbage collector in the CLR makes tradeoffs to assure reasonable performance

More information

Why do we care about parallel?

Why do we care about parallel? Threads 11/15/16 CS31 teaches you How a computer runs a program. How the hardware performs computations How the compiler translates your code How the operating system connects hardware and software The

More information

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring Lecture 13: Address Translation

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring Lecture 13: Address Translation CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring 2004 Lecture 13: Address Translation 13.0 Main Points 13.1 Hardware Translation Overview CPU Virtual Address Translation

More information

Older geometric based addressing is called CHS for cylinder-head-sector. This triple value uniquely identifies every sector.

Older geometric based addressing is called CHS for cylinder-head-sector. This triple value uniquely identifies every sector. Review: On Disk Structures At the most basic level, a HDD is a collection of individually addressable sectors or blocks that are physically distributed across the surface of the platters. Older geometric

More information

Parallel Programming Principle and Practice. Lecture 9 Introduction to GPGPUs and CUDA Programming Model

Parallel Programming Principle and Practice. Lecture 9 Introduction to GPGPUs and CUDA Programming Model Parallel Programming Principle and Practice Lecture 9 Introduction to GPGPUs and CUDA Programming Model Outline Introduction to GPGPUs and Cuda Programming Model The Cuda Thread Hierarchy / Memory Hierarchy

More information

Sustainable Memory Use Allocation & (Implicit) Deallocation (mostly in Java)

Sustainable Memory Use Allocation & (Implicit) Deallocation (mostly in Java) COMP 412 FALL 2017 Sustainable Memory Use Allocation & (Implicit) Deallocation (mostly in Java) Copyright 2017, Keith D. Cooper & Zoran Budimlić, all rights reserved. Students enrolled in Comp 412 at Rice

More information

High Performance Computing and Programming, Lecture 3

High Performance Computing and Programming, Lecture 3 High Performance Computing and Programming, Lecture 3 Memory usage and some other things Ali Dorostkar Division of Scientific Computing, Department of Information Technology, Uppsala University, Sweden

More information

OPERATING SYSTEM. Chapter 9: Virtual Memory

OPERATING SYSTEM. Chapter 9: Virtual Memory OPERATING SYSTEM Chapter 9: Virtual Memory Chapter 9: Virtual Memory Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped Files Allocating Kernel Memory

More information

D Programming Language

D Programming Language Group 14 Muazam Ali Anil Ozdemir D Programming Language Introduction and Why D? It doesn t come with a religion this is written somewhere along the overview of D programming language. If you actually take

More information

ADRIAN PERRIG & TORSTEN HOEFLER Networks and Operating Systems ( ) Chapter 6: Demand Paging

ADRIAN PERRIG & TORSTEN HOEFLER Networks and Operating Systems ( ) Chapter 6: Demand Paging ADRIAN PERRIG & TORSTEN HOEFLER Networks and Operating Systems (5-006-00) Chapter 6: Demand Paging http://redmine.replicant.us/projects/replicant/wiki/samsunggalaxybackdoor (0) # Inverted page table One

More information

CS370 Operating Systems

CS370 Operating Systems CS370 Operating Systems Colorado State University Yashwant K Malaiya Fall 2017 Lecture 20 Main Memory Slides based on Text by Silberschatz, Galvin, Gagne Various sources 1 1 Pages Pages and frames Page

More information

Data Structure. Measuring Input size. Composite Data Structures. Linear data structures. Data Structure is: Abstract Data Type 1/9/2014

Data Structure. Measuring Input size. Composite Data Structures. Linear data structures. Data Structure is: Abstract Data Type 1/9/2014 Data Structure Measuring Input size Last lecture recap. A Data Structure is an aggregation of atomic and composite data into a set with defined relationships. Structure means a set of rules that holds

More information

Chapter 8: Memory-Management Strategies

Chapter 8: Memory-Management Strategies Chapter 8: Memory-Management Strategies Chapter 8: Memory Management Strategies Background Swapping Contiguous Memory Allocation Segmentation Paging Structure of the Page Table Example: The Intel 32 and

More information

Memory: Overview. CS439: Principles of Computer Systems February 26, 2018

Memory: Overview. CS439: Principles of Computer Systems February 26, 2018 Memory: Overview CS439: Principles of Computer Systems February 26, 2018 Where We Are In the Course Just finished: Processes & Threads CPU Scheduling Synchronization Next: Memory Management Virtual Memory

More information

Changelog. Corrections made in this version not in first posting: 1 April 2017: slide 13: a few more %c s would be needed to skip format string part

Changelog. Corrections made in this version not in first posting: 1 April 2017: slide 13: a few more %c s would be needed to skip format string part 1 Changelog 1 Corrections made in this version not in first posting: 1 April 2017: slide 13: a few more %c s would be needed to skip format string part OVER questions? 2 last time 3 memory management problems

More information

QUIZ on Ch.5. Why is it sometimes not a good idea to place the private part of the interface in a header file?

QUIZ on Ch.5. Why is it sometimes not a good idea to place the private part of the interface in a header file? QUIZ on Ch.5 Why is it sometimes not a good idea to place the private part of the interface in a header file? Example projects where we don t want the implementation visible to the client programmer: The

More information

A JVM Does What? Eva Andreasson Product Manager, Azul Systems

A JVM Does What? Eva Andreasson Product Manager, Azul Systems A JVM Does What? Eva Andreasson Product Manager, Azul Systems Presenter Eva Andreasson Innovator & Problem solver Implemented the Deterministic GC of JRockit Real Time Awarded patents on GC heuristics

More information

Today. Dynamic Memory Allocation: Basic Concepts. Dynamic Memory Allocation. Dynamic Memory Allocation. malloc Example. The malloc Package

Today. Dynamic Memory Allocation: Basic Concepts. Dynamic Memory Allocation. Dynamic Memory Allocation. malloc Example. The malloc Package Today Dynamic Memory Allocation: Basic Concepts Basic concepts Performance concerns Approach 1: implicit free lists CSci 01: Machine Architecture and Organization October 17th-nd, 018 Your instructor:

More information

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages CMSC 330: Organization of Programming Languages Memory Management and Garbage Collection CMSC 330 - Spring 2013 1 Memory Attributes! Memory to store data in programming languages has the following lifecycle

More information