- 快召唤伙伴们来围观吧
- 微博 QQ QQ空间 贴吧
- 文档嵌入链接
- 复制
- 微信扫一扫分享
- 已成功复制到剪贴板
22_Course_Review
展开查看详情
1 .CPEN333 – Course Review What is System Software Engineering? Whirlwind tour through all material Mutual exclusion Inter-Process Communication UML Synchronization & Deadlock Priority and Scheduling Advanced Patterns (Producer-Consumer, Readers-Writers, RCU) A few example problems Learning Goals © Paul Davies, C. Antonio Sanchez. Not to be copied, used, or revised without explicit written permission from the copyright owner.
2 .Intro to System Software Engineering 2 Lecture 1: Introduction to System Software Engineering Learning Goals Define a system , system software , and system software engineering Distinguish between hard and soft time constraints Distinguish between event-driven and time-driven systems, and give examples Describe the difference between interrupts and polling for detecting and handling events List advantages and disadvantages of both interrupts and polling Discuss why testing real-time systems can be challenging
3 .Examples of Systems Course Review 3
4 .Intro to Concurrency 4 Lecture 2: Introduction to Concurrency Learning Goals Describe the differences between single-tasking and multi-tasking Identify challenges introduced by adding concurrency Describe an example of a multitasking system (perhaps with a diagram) Identify whether or not a program will benefit from concurrency, either in terms of efficiency or scalability Describe various methods of implementing multitasking , and list some advantages/disadvantages of each Define and describe time-slicing and how it differs from pseudo-multitasking
5 .Multi-Tasking Example Intro to Concurrency 5 60k searches per second 0.5 s to process each search
6 .Pseudo Multitasking Intro to Concurrency 6 Simply switch between a bunch of sequential tasks fast enough that it looks like they are running in parallel. int main () { // continuously cycle through set of monitors // to give appearance of parallel operation while ( deviceIsOn () ) { monitorTemperature (); monitorHumidity (); monitorAtmosphericPressure (); updateDisplays (); } return 0 ; }
7 .Multiple Dedicated Processors/Cores Intro to Concurrency 7 Each processor/core is given one task to run on its own, synchronizes with others. (2015) 8 Core I7 CPU with shared Cache and Memory controller Custom server with shared backplane, communicate over a VMEbus
8 .Distributed Systems Intro to Concurrency 8 Microsoft’s data center in San Antonio, Texas
9 .Time-Slicing Intro to Concurrency 9 Real Time Clock Operating System Kernel Operating System Kernel CPU 5 4 3 2 1 Real Time Clock OS Kernel called to deal with Interrupt Kernel directs CPU to swap/resume task 10ms interrupt Repeat Forever Interrupt Cleared Save State of Current Task Restore State of Next Task List of Tasks Descriptors (1 per Process) Active Process Queue
10 .Threads 10 Lecture 3: Threads Learning Goals Describe what a thread is in your own words Describe the role of the Operating System kernel in thread creation Create and use threads in C++ using the C++11 standard std::thread class Describe two methods of thread communication and give a code example Define a race condition and give an example Given code that runs in parallel, identify all possible sequences and outputs Given an application, identify where it might be useful to use separate threads List potential drawbacks or limitations of multiple threads
11 .Communication and Synchronization Problems Threads 11 11 Thread Thread Thread Thread Thread Thread Process/Thread Process/Thread Process/Thread Process/Thread Process/Thread Process/Thread Communication Problems Synchronisation Problems More threads more problems. Communication and synchronization issues grow exponentially, scattering data leads to more data dependencies , slowing the system down, leading to data management challenges.
12 .Processes 12 Lecture 4: Processes Learning Goals Describe what a process is in your own words Describe the role of the Operating System kernel in process creation Describe the differences between processes and threads, and list some advantages/disadvantages of each Understand that there are differences in process creation between different operating systems (you don’t need to know how to create them on each platform) Create a child process with the help of the course library
13 .Processes 13 Monolithic System Process Process Process Thread Thread Thread Process Process Process Thread Thread Thread Monolithic System Process Process Process Thread Thread Thread Process Process Process Thread Thread Thread System broken down into processes : Coarse grained or Process Granularity Processes broken down into threads : Fine grained or Thread Granularity No Granularity High Granularity Tending towards highly parallel programming with increasing data dependencies Towards Crude, single tasking systems running on 1 CPU/Core Multi-tasking systems Multi-threaded systems Application/Process/Thread Decomposition System broken down into processes Processes broken down into smaller processes Smaller Processes broken down into threads Threads broken down into smaller threads
14 .Exceptions, Specifications, and Testing 14 Lecture 5: Exceptions, Specifications, and Testing Learning Goals Understand what an exception is, and what they are useful for Use exceptions in combination with a try — catch block Create and use a custom exception class Define and give examples of preconditions and postconditions Write complete and correct method specifications Partition inputs to design tests for a method that cover all expected behaviours Write unit tests against a method
15 .Specifications Exceptions, Specifications, and Testing 15 // REQUIRES: data is a non-empty vector // EFFECTS: returns the index of the last occurrence // of val in data, or -1 if not found int find( std :: vector < int >& data, int val); int a0 = find({ 0 , 1 , 2 , 3 , 4 , 5 }, 2 ); int a1 = find({ 0 , 1 , 2 , 3 , 4 , 5 }, 6 ); int a2 = find({ 0 , 1 , 1 , 1 , 4 , 5 }, 1 ); int a3 = find({}, 1 ); // fails precondition, output indeterminate Preconditions Postconditions
16 .Testing Exceptions, Specifications, and Testing 16 Unit Testing: testing each method/class (i.e. a unit ) in isolation . Each partition of inputs is usually separated into a separate test so that a failed test will indicate exactly what type of bug to search for. Integration Testing: testing the system as a whole to ensure the various components of the software function properly in combination. If all unit tests pass, then you know the issue is somewhere in the interfacing or timings. Regression Testing: testing the system to ensure it performs exactly as it did in a previous functional version. Often important when adding new features or optimizing parts of code, making sure you don’t break any part that works.
17 .Mutual Exclusion 17 Lecture 6: Mutual Exclusion Learning Goals Define mutual exclusion and describe its use Define and differentiate between an atomic operation and a critical section Create your own mutual exclusion class from scratch using atomic operations Create your own lock class that uses RAII principles to guarantee exception safety Use a mutex and lock to prevent inter-thread race conditions in a code example Use an inter-process mutex to prevent race conditions between multiple processes Identify critical sections in a provided task or code
18 .Race Conditions Mutual Exclusion 18 Miscellaneous Read value of a ( 0 ) Add 1 to value ( 1 ) Store back a ( 1 ) Miscellaneous Miscellaneous Read value ( 0 ) Add 1 to value ( 1 ) Store back ( 1 ) Miscellaneous CPU/Core P1 Miscellaneous Read value of a ( 0 ) Add 1 to value ( 1 ) Store back a ( 1 ) Miscellaneous Miscellaneous Read value ( 0 ) Add 1 to value ( 1 ) Store back ( 1 ) Miscellaneous CPU/Core P2 0 1 0 Actual ‘counter’ Error: ‘a’ has only been incremented once instead of twice Data Data Data Data
19 .Mutex: Exception Safety Mutual Exclusion 19 Solution: use RAII principles, destructors guaranteed to be called!! #include <mutex> class lock { std::mutex& mutex_; // reference to a mutex public : lock(std::mutex& mutex) : mutex_(mutex) { mutex_.lock(); // lock in constructor } ~lock() { mutex_.unlock(); // unlock in destructor } }; void threadinc(std::mutex& mutex, size_t& counter) { for (size_t i= 0 ; i< 5000000 ; ++i) { { lock mylock(mutex); // locks mutex counter += 1 ; } // mutex guaranteed to be unlocked } }
20 .Shared Memory 20 Lecture 7: Inter-Process Communication Shared Memory Learning Goals Explain why processes cannot share local memory as easily as threads Describe a possible mechanism of how processes can share blocks of memory List and describe three levels of persistence of resources Use the CPEN 333 library to create and apply named shared memory objects for inter-process communication List some advantages and drawbacks of shared memory objects Identify which accesses of shared memory need protection or synchronization via a mutex and which don’t, arguing your case
21 .IPC: How would YOU do it? Shared Memory 21 Let’s say two processes on the same machine DO want to share memory. How would you do it?
22 .Shared Memory 22 A Structure template used by each process can create a ‘plan’ or ‘blue print’ of the data which can be mapped or overlaid onto a blank block of memory that forms the datapool. Of course all processes must use the same template typically maintained within a header file Process B maintains a pointer to the datapool struct Pool { int joe ; char fred ; char array[256] ; float result ; } ; struct Pool *my_ptr; Data Pool Stored in Memory Shared Memory Process A maintains a pointer to the datapool struct Pool { int joe ; char fred ; char array[256] ; float result ; } ; Structure Template mapping/overlaying data for Process A onto datapool struct Pool *my_ptr; Structure Template mapping/overlaying data for Process B onto datapool
23 .Lecture 10 – Pipes and Sockets Learning Goals Understand the basic workings of a simple pipe using a circular buffer Describe the properties of uni-directional pipes and relation to synchronization Provide a brief overview of the client-server model Set up a pipe_server for multiple simultaneous connections Describe what sockets are used for, and how they connect Set up a socket_server for multiple simultaneous connections Describe why an explicit socket communication protocol is necessary Create an example communication protocol and API for an application
24 .Pipes Pipes and Sockets 24 Buffer Top Buffer Bottom Pointer to Reading Position Pointer to Writing Position Pipes are usually implemented using circular buffers : the “beginning” of the buffer advances and wraps around as you read from the buffer. The end also wraps around. Care must be taken not to write so much as to wrap around and overwrite unread data. The pipe implementation generally handles this synchronization internally, blocking writes while the pipe is full.
25 .Socket Server The server opens the port, listens for incoming requests, accepts a client connection, and then communicates with the client using low-level read/write operations. During and after the connection process, the original port is still free to listen for new clients. Pipes and Sockets 25 Server :52001 Client Client Client
26 .Socket Communication Protocol Pipes and Sockets 26 There is a need to establish an explicit protocol for your application Most web-based communication is text-based (e.g. HTML or JSON) For raw numbers, byte order and size needs to be explicitly stated. E.g. Messages are sent with a 2-byte message-type identifier , followed by a 4-byte little-endian integer indicating the remainder of the message size, followed by UTF-8 text-based content in JSON format that ends with a terminating zero. 0x6a 0x73 0x10 0x00 0x00 0x00 0x7b 0x22 0x6d 0x73 0x67 0x22 0x3a 0x22 0x68 0x65 0x6c 0x6c 0x6f 0x22 0x7d 0x00 type = ‘j’ ‘s’ size = 16 content = {“msg”:“hello”}
27 .Application Program Interface (API) Pipes and Sockets 27 { "results" : [ { "formatted_address" : "1600 Amphitheatre Parkway, Mountain View, CA 94043, USA" , "geometry" : { "location" : { "lat" : 37.4224764 , "lng" : - 122.0842499 }, "location_type" : "ROOFTOP" , "viewport" : { "northeast" : { "lat" : 37.4238253802915 , "lng" : - 122.0829009197085 }, "southwest" : { "lat" : 37.4211274197085 , "lng" : - 122.0855988802915 } } }, "place_id" : "ChIJ2eUgeAK6j4ARbn5u_wAGqWA" , "types" : [ "street_address" ] } ], "status" : "OK" } https://developers.google.com/maps/documentation/geocoding/start e.g. Google Maps has an API for finding locations. HTTP requests are made of the form https://maps.googleapis.com/maps/api/geocode/json? address=1600+Amphitheatre+Parkway,+Mountain+View,+CA & key=YOUR_API_KEY Google will then respond to your request with a JSON-formatted string according to the API specification.
28 .Intro to UML 28 Lecture 8: Introduction to UML Learning Goals Describe the purpose of the Unified Modelling Language (UML) Argue why modelling is important in System Software Engineering List several types of diagrams , and give a short description of their purpose Outline instances where and how UML is used in practice
29 .Why Model at All? Intro to UML 29 If you are hammering together a simple bookcase with a few pieces of wood and a handful of nails, you may not need to spend much time on design. Imagine building this one without a plan. The Leistler Bookcase took over a year to build, and was shown off at the Great Exhibition in London (1851) as a demonstration of the “wonders of industry”. By Gryffindor (Own work) [CC BY-SA 3.0]