Lecture 9 Scheduling. Scheduling Policies Preemptive Priority Scheduling.

Slides:



Advertisements
Similar presentations
Copyright © 2000, Daniel W. Lewis. All Rights Reserved. CHAPTER 10 SHARED MEMORY.
Advertisements

ECE 454 Computer Systems Programming Compiler and Optimization (I) Ding Yuan ECE Dept., University of Toronto
CPSC Compiler Tutorial 9 Review of Compiler.
Chapter 1 Computer System Overview Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and Design Principles,
Improving code generation. Better code generation requires greater context Over expressions: optimal ordering of subtrees Over basic blocks: Common subexpression.
Computer System Overview
Chapter 6. 2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single Value Pass by Reference Variable Scope.
Programming with CUDA WS 08/09 Lecture 9 Thu, 20 Nov, 2008.
Improving Code Generation Honors Compilers April 16 th 2002.
Improving code generation. Better code generation requires greater context Over expressions: optimal ordering of subtrees Over basic blocks: Common subexpression.
Mehmet Can Vuran, Instructor University of Nebraska-Lincoln Acknowledgement: Overheads adapted from those provided by the authors of the textbook.
C Programming for Embedded Systems. fig_06_00 Computer Layers Low-level hardware to high-level software (4GL: “domain-specific”, report-driven, e.g.)
Embedded ‘C’.  It is a ‘mid-level’, with ‘high-level’ features (such as support for functions and modules), and ‘low-level’ features (such as good access.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 15 Slide 1 Real-time Systems 1.
© 2008, Renesas Technology America, Inc., All Rights Reserved 1 Purpose  This training course describes how to configure the the C/C++ compiler options.
Chapter 1 Computer System Overview Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and Design Principles,
Chapter 1 Computer System Overview Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E William.
Copyright 2001 Oxford Consulting, Ltd1 January Storage Classes, Scope and Linkage Overview Focus is on the structure of a C++ program with –Multiple.
A First Book of C++: From Here To There, Third Edition2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single.
Scheduling Basic scheduling policies, for OS schedulers (threads, tasks, processes) or thread library schedulers Review of Context Switching overheads.
Scalable Web Server on Heterogeneous Cluster CHEN Ge.
Reference: Ian Sommerville, Chap 15  Systems which monitor and control their environment.  Sometimes associated with hardware devices ◦ Sensors: Collect.
Week 1 Algorithmization and Programming Languages.
C.E. Goutis V.I.Kelefouras University of Patras Department of Electrical and Computer Engineering VLSI lab Date: 31/01/2014 Compilers for Embedded Systems.
COMPUTER ORGANIZATION AND ASSEMBLY LANGUAGE Lecture 19 & 20 Instruction Formats PDP-8,PDP-10,PDP-11 & VAX Course Instructor: Engr. Aisha Danish.
Operating System Isfahan University of Technology Note: most of the slides used in this course are derived from those of the textbook (see slide 4)
A FIRST BOOK OF C++ CHAPTER 6 MODULARITY USING FUNCTIONS.
Function Overloading and References
Optimization of C Code The C for Speed
Compiler Directives. The C Preprocessor u The C preprocessor (cpp) changes your source code based on instructions, or preprocessor directives, embedded.
Programming Fundamentals. Topics to be covered Today Recursion Inline Functions Scope and Storage Class A simple class Constructor Destructor.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 4.
Real-time Software Design
Advanced Computer Systems
Component 1.6.
EGR 2261 Unit 11 Pointers and Dynamic Variables
Course Contents KIIT UNIVERSITY Sr # Major and Detailed Coverage Area
Lecture 2 Interrupts.
Chapter 1 Computer System Overview
EEE Embedded Systems Design Process in Operating Systems 서강대학교 전자공학과
MODULAR PROGRAMMING Many programs are too large to be developed by one person. programs are routinely developed by teams of programmers The linker program.
Advanced OS Concepts (For OCR)
Computer Architecture
ACOE301: Computer Architecture II Labs
Process Description and Control
Chapter7 Structure & C++
Run-time organization
Chapter 5 Conclusion CIS 61.
A Closer Look at Instruction Set Architectures
C-language Lecture By B.S.S.Tejesh, S.Neeraja Asst.Prof.
Chapter 2.2 : Process Scheduling
Real-time Software Design
Baremetal C Programming for Embedded Systems
Compiler Construction
Optimizing Malloc and Free
Lecture 22 Inheritance Richard Gesick.
Chapter 2: The Linux System Part 3
Operating systems Process scheduling.
CPU SCHEDULING.
Tim Ehrlich Growing Arrays in C.
Explaining issues with DCremoval( )
Embedded System Development Lecture 7 2/21/2007
A QUICK START TO OPL IBM ILOG OPL V6.3 > Starting Kit >
Focus of the Course Object-Oriented Software Development
An Embedded Software Primer
Chapter 1 Computer System Overview
Tonga Institute of Higher Education IT 141: Information Systems
Tonga Institute of Higher Education IT 141: Information Systems
Programming with Shared Memory Specifying parallelism
Storage classes in C In C language, each variable has a storage class which decides the following things: scope i.e where the value of the variable would.
Presentation transcript:

Lecture 9 Scheduling

Scheduling Policies

Preemptive Priority Scheduling

Round Robin Scheduling

than fixed-priority case.

Because LL algorithm (and ED )assume that all the deadlines are hard.

Minimizing Maximum Lateness Scheduling Sometimes one task cannot start until another completes. In addition, the completion of each action j is associated with a cost function h j. An optimal scheduling minimizing cost can be constructed using the following off-line static algorithm:

Minimizing Maximum Lateness Scheduling J –ordered set of tasks already scheduled J c –set of task still to be scheduled(complement of J) J’ –set of task that can be scheduled immediately before J(J can’t start before J’ completes) 1. J empty, J c =all the tasks, J’=all tasks with no successors 2. Select j* from J c with minimum h j* that has no predecessor in J c (so j* must be in J’) 3. Add j* to J and remove from J c 4. Adjust J’ 5. If J c is empty stop, otherwise go to step 2

Our project There is no OS Every group should implement a scheduler in the project and can use any of the above scheduling algorithms The main loop is the scheduling loop You should state in the code and the design document which scheduling algorithm you are using. Alternatively, you can upload any operating system from the Web to the microcontrollers.

Example Task1 should be performed every 100 ms (high priority) Task2 should be performed every 150 ms (low priority) There are simple Interrupt 1 and Interrupt 2 (short exe time) There is Interrupt3 that creates a new med priority task in the system.

Example Tasks = {Task1,Task2}; Last_call_task1 = 0; Last_call_task2 = 0; Simple Interrupt 1 handler; Simple Interrupt 2 handler; Interrupt 3 handler {Add Task3 to the Tasks} main() { while(1){} } Timer interrupt every 10 ms {ReadyTasks=Tasks; IF (current_time - Last_call_task1 ) < 100 ms THEN remove Task1 from ReadyTasks; IF (current_time - Last_call_task2 ) < 150 ms THEN remove Task2 from ReadyTasks; // apply here the scheduling algorithm. For example: Choose task from ReadyTasks with maximal priority; //Emulate context change: move PC register to run the chosen task } Task 1(or 2 or 3) function {interrupt disable; … interrupt enable; set PC to while(1) }

More comments on MPC430 working environment and general concepts of embedded programming

Using efficient data types The data types you use should be considered carefully, because this can have a large impact on code size and code speed: ● Use small data types. ● Try to avoid 64-bit data types, such as double and long long. ● Bitfields with sizes other than 1 bit should be avoided because they will result in inefficient code compared to bit operations. ● Using floating-point types is very inefficient, both in terms of code size and execution speed. If possible, consider using integer operations instead. ● Declaring a pointer to const data tells the calling function that the data pointed to will not change, which opens for better optimizations

Alignment on the MSP430 Can access memory using 8- or 16-bit operations. However, when a 16-bit access is performed, the data must be located at an even address. The MSP430 IAR C/C++ Compiler ensures this by assigning an alignment to every data type, ensuring that the MSP430 microcontroller will be able to read the data.

Rearranging elements in a structure The MSP430 microcontroller requires that data in memory must be aligned. Each element in a structure needs to be aligned according to its specified type requirements. This means that the compiler must insert pad bytes if the alignment is not correct.

Alignment – cont. Be careful about padding: ● Network communication protocols are usually specified in terms of data types with no padding in between ● It “wastes” data memory. There are two ways to solve the problem: 1. Use the #pragma pack directive. +Easy and fast solution -Each access to an unaligned element in the structure will use more code. 2. Write your own customized functions for packing and unpacking structures. +Will not produce any more code apart from your functions - You will need two views on the structure data—packed and unpacked.

#pragma pack Example: struct First { char alpha; short beta; }; #pragma pack(1) struct FirstPacked { char alpha; short beta; }; #pragma pack() struct Second { struct FirstPacked first; Short Empty; short gamma; };

Compiler optimization: common subexpression elimination Redundant re-evaluation of common subexpressions is by default eliminated at optimization levels Medium and High. This optimization normally reduces both code size and execution time. However, the resulting code might be difficult to debug.

Loop unrolling It is possible to duplicate the loop body of a small loop, whose number of iterations can be determined at compile time, to reduce the loop overhead. This optimization, which can be performed at optimization level High, normally reduces execution time, but increases code size. The resulting code might be difficult to debug. The compiler heuristically decides which loops to unroll. Different heuristics are used when optimizing for speed, size, or when balancing between size and speed.

Mixing C and Assembler There are several ways to mix C or C++ and assembler: ● Modules written entirely in assembler ● Intrinsic functions (the C alternative) ● Inline assembler

Intrinsic functions A small number of predefined functions that allow direct access to low-level processor operations without having to use the assembler language. They can be very useful in, for example, time- critical routines.

Intrinsic function – cont. An intrinsic function looks like a normal function call, but it is really a built-in function that the compiler recognizes. The intrinsic functions compile into inline code, either as a single instruction, or as a short sequence of instructions. The advantage of an intrinsic function compared to using inline assembler is that the compiler has all necessary information to interface the sequence properly with register allocation and variables. The compiler also knows how to optimize functions with such sequences; something the compiler is unable to do with inline assembler sequences. The result is that you get the desired sequence properly integrated in your code, and that the compiler can optimize the result. To use intrinsic functions in an application, include the header file intrinsics.h. Note that the intrinsic function names start with double underscores

Intrinsic functions – cont.

Writing efficient code Local variables—auto variables and parameters—are preferred over static or global variables. The reason is that the optimizer must assume, for example, that called functions may modify non- local variables. When the life spans for local variables end, the previously occupied memory can then be reused. Globally declared variables will occupy data memory during the whole program execution. Avoid taking the address of local variables using the & operator, because: 1. The variable must be placed in memory, and thus cannot be placed in a processor register. This results in larger and slower code. 2. The optimizer can no longer assume that the local variable is unaffected over function calls. Module-local variables—variables that are declared static—are preferred over global variables. Also avoid taking the address of frequently accessed static variables. The compiler is capable of inlining functions. instead of calling a function, the compiler inserts the content of the function at the location where the function was called. The result is a faster, but often larger, application. Inlining may enable further optimizations. The compiler often inlines small functions declared static. The use of the #pragma inline directive and the C++ keyword inline gives you fine-grained control, and it is the preferred method compared to the traditional way of using preprocessor macros. Avoid using inline assembler. Instead, try writing the code in C or C++, use intrinsic functions, or write a separate module in assembler language.