ECE 1175 Embedded Systems Design

2y ago
59 Views
3 Downloads
785.22 KB
23 Pages
Last View : 12d ago
Last Download : 3m ago
Upload by : Ronan Garica
Transcription

ECE 1175Embedded Systems DesignLab 4 – RMS, EDF and PriorityInheritanceECE 1175 Embedded Systems Design1

ECE 1175 – Lab 4 Scheduling Algorithms Rate Monotonic Scheduling (RMS) Earliest Deadline First Scheduling (EDF or EDFS) Lab task 1: scheduling simulation Priority Inheritance Multithreading in C Lab task 2: demonstration of priority inheritanceECE 1175 Embedded Systems Design2

Recap RMS & EDF Rate Monotonic Scheduling (RMS) Higher rate (1/period) Higher priority U Ub n schedulable (sufficient) Low overhead but cannot guarantee schedulability Earliest Deadline First (EDF) Earlier absolute deadline Higher priority U 1 schedulable Ensure schedulability but high overheadECE 1175 Embedded Systems Design3

Lab Task 1 Simulate RMS and EDF Refer to rms.c (You can write your own!) Schedulability check Implement preemptionWhat is preemption?Priority: Task 1 Task 2Task 1Task 2interruptedresumeECE 1175 Embedded Systems Design4

Lab Task 1 Example – RMS, T1 (10, 25), T2 (15, 60)You can verify thecorrectness by manuallydrawing the flow chart.ECE 1175 Embedded Systems Design5

Lab Task 1 Example – RMS, T1 (10, 20), T2 (15, 30)Your program shouldbe aware if the taskset is schedulable.ECE 1175 Embedded Systems Design6

Lab Task 1 Example – RMS, T1 (20, 50), T2 (35, 100)Your program shouldbe able to handlepreemption.ECE 1175 Embedded Systems Design7

Lab Task 1 Check-off Correctness and preemption Show your results with the configurations in the table. Schedulability check Demonstrate with your own example. Code submission Email your code to the TA.ECE 1175 Embedded Systems Design8

Recap priority Inheritance Priority InheritanceJob 1 is running critical section (hold lock)Job 3Priority: highJob 2Priority: mediumJob 1Priority: lowTemporarily elevatedHighECE 1175 Embedded Systems DesignJob 2 cannotpreempt me now!I inherited Job 3’spriority9

Multithreading in C Thread creation – pthread.h pthread.h : POSIX threads Specifies a set of interfaces (functions, header files) for threadedprogramming commonly known as POSIX threads, or Pthreads Data type pthread t: thread variable, a type similar to int. pthread mutex t: mutex variable, a type similar to int. pthread mutexattr t: attribute of mutex variable, a type similar toint Function pthread create(); pthread mutex init(); pthread mutex lock();pthread mutex unlock(); pthread mutexattr setprotocol()ECE 1175 Embedded Systems Design10

Multithreading in C – thread creation Thread creation Data: pthread t Funciton: pthread create()int pthread create(pthread t *thread, const pthread attr t *attr, void *(*start routine) (void *), void *arg);include pthread.h pthread t thread1;// declare pthread t type variable named thread1void *thread1handler() // thread handler{//do some work;}pthread create(&thread1, NULL, thread1handler, NULL); //create athread named thread1ECE 1175 Embedded Systems Design11

Multithreading in C – mutex mutex (mutual exclusion) Data type: pthread mutex t; Function: pthread mutex init(); pthread mutex lock();pthread mutex unlock();include pthread.h pthread mutex t mutex; /*declare pthread mutex t type variablename mutex*/pthread mutex init(&mutex, NULL);//mutex initializepthread mutex lock(&mutex); //lock mutexPthread mutex unlock(&mutex); //unlock mutexECE 1175 Embedded Systems Design12

Multithreading in C – Exampleinclude pthread.h pthread mutex t mutex;pthread t thread1, thread2;void *threadhandler1(){//do some work herepthread mutex unlock(&mutex);}void *threadhandler2(){pthread mutex lock(&mutex);// do some work here}int main(){pthread mutex init(&mutex, NULL);pthread mutex lock(&mutex, NULL);pthread create(&thread1, NULL, thread1handler, NULL);pthread create(&thread2, NULL, thread2handler, NULL);pthread join(thread1, NULL);// wait for thread1 to completepthread join(thread2, NULL);// wait for thread2 to completeReturn 0;ECE 1175 Embedded Systems Design}13

Enable Priority Inheritance mutex Data type: pthread mutexattr t Function: pthread mutexattr setprotocol()int pthread mutexattr setprotocol(pthread mutexattr t*attr, int protocol)include pthread.h pthread mutex t mutexpthread mutexattr t mutexattr;pthread mutexattr setprotocol(&mutexattr, PTHREAD PRIO INHERIT);//setting protocol for mutex attributepthread mutex init(&mutex, &mutexattr); //initialize mutex withattribute*Other protocol: PTHREAD PRIO PROTECT and PTHREAD PRIO NONEECE 1175 Embedded Systems Design14

Multithreading in C – scheduling Thread scheduling – sched.h sched.h : execution scheduling (REALTIME) Defines the sched param structure, which contains the schedulingparameters such as scheduling priority and policy. sched param This structure contains at least the following member: int sched priorityinclude sched.h struct sched param param; //declare structure variableint priority 10;// set an integer number for priorityparam.sched priority priority; //assign priority to structure variableECE 1175 Embedded Systems Design15

Multithreading in C – scheduling Thread scheduling – sched.h Scheduling policy SCHED FIFO SCHED RR SCHED OTHERinclude sched.h int policy;// policy is an int variable;policy SCHED RR;// assign SCHED RR to declared policy variableECE 1175 Embedded Systems Design16

Multithreading in C – set scheduling priority Thread scheduling – sched.h Priority range of scheduling policy sched get priority max(): get max priority of scheduling policy int sched get priority max(int policy); sched get priority min(): get min priority of scheduling policyinclude sched.h int policy;policy SCHED RR;// policy is an int variable;// assign SCHED RR to declared policy variableint maxpriority sched get priority max(policy); // get max priorityint minpriority sched get priority min(policy); // get min priorityECE 1175 Embedded Systems Design17

Multithreading in C – set scheduling priority Thread scheduling – sched.h Set & get policy and priority for a thread pthread setschedparam(): set scheduling policy and parameters ofa thread named thread pthread setschedparam(pthread tthread, int policy, const struct sched param *param); pthread getschedparam(): return scheduling policy and paramtersof a thread named threadpthread getschedparam(pthread t thread, int *policy, struct sched param *param);include sched.h int policy SCHED RR;struct sched param param;int priority 10;param.sched priority priority; //assign priority to structure variablepthread setschedparam(thread1,policy,¶m); /* set & get policy forpthread getschedparam(thread1,&policy,¶m); thread1*/ECE 1175 Embedded Systems Design18

Multithreading in C – Example#include stdio.h #include stdlib.h #include unistd.h #include pthread.h #include sched.h pthread t thread1;pthread mutex t mutex;pthread mutexattr t mutexattr;int policy SCHED RR;int priority 10;struct sched param param;void *thread1handler() {pthread mutex lock(&mutex);//do some work;pthread mutex unlock(&mutex)}int main(){pthread mutexattr setprotocol(&mutexattr, PTHREAD PRIO INHERIT);pthread mutex init(&mutex, &mutexattr);priority sched get priority max(policy);param.sched priority priority;pthread create(&thread1, NULL, thread1handler, NULL);pthread setschedparam(thread1,policy,¶m);pthread join(thread1, NULL);return 0;}ECE 1175 Embedded Systems Design19

Lab Task 2 Write multithreading C code to demonstrate priority inheritancethread 2Priority: mediumthread 1Priority: highThread 3 is runningcritical sectionthread 3Priority: lowIf enable priority inheritance, the execution order will beThread 3Thread 1ECE 1175 Embedded Systems DesignThread 220

Lab Task 2 ExampleInitial priority: thread 1 thread 2 thread 3Thread 2 failed to preempt thread 1 becauseof priority inheritance.Thread 2 preempted thread 1 after thread 3released the lock.ECE 1175 Embedded Systems Design21

Lab Task 2 Important notes Ensure your main() has the highest priority E.g., Priority: main() thread 1 thread 2 thread 3 pthread setschedparam(pthread self(), policy, ¶m main); Ensure the thread with the lowest priority starts first. Add some delay before creating other threads. To compile your code link to pthread lib and disable optimization gcc ./program.c –O0 –lpthread To run your program (on single core) sudo taskset –c 1 ./program For debugging and check-off Use long loop to slow down your program. Print out sufficient information to show priority inheritance does happen.ECE 1175 Embedded Systems Design22

Thank you!ECE 1175 Embedded Systems Design23

resume. Priority: Task 1 Task 2. . ECE 1175 Embedded Systems Design 22. ECE 1175 Embedded Systems Design 23. Thank you! Title: ECE 1175 Embedded Systems Design Lab 2 – Sense HAT & Interrupt Au

Related Documents:

Electrical & Computer Engineering Student Affairs Office ece.ucsd.edu . ECE 174. ECE 175A: ECE 175B* Year 4: ECE 171B* ECE 172A* DESIGN. PROF. ELECTIVE: PROF. ELECTIVE. TECH. ELECTIVE: TECH. ELECTIVE. MACHINE LEARNING & CONTROLS DEPTH *Pick one of ECE 171B, 172A or 175B to complete the 4th Depth course requirement.

ECE 429: Audio Electronics ECE 461: Introduction to VLSI ECE 466: RF and Microwave Integrated Circuits ECE 468: Advanced Analog CMOS Circuits and Systems ECE 469: High Speed Integrated Electronics . Computer Design and Computer Engineering Concentration Requirements . ECE 401: Advanced Computer Architecture Two of the following .

ECE 332 Embedded Systems Laboratory 21. RLE State in detail WAIT_OUTPUT 1 cycle stall is needed De-assert wr_req by setting wr_reg RESET_COUNT Reset bit counting register after passing encoded data to output side FIFO ECE 332 Embedded Systems Laboratory 22. Race Condition

3.ECE 821: Advanced Power Electronics and Applications 4.ECE 835: Advanced Electromagnetic Fields and Waves I 5.ECE 851: Linear Control Systems 6.ECE 863: Analysis of Stochastic Systems 7.ECE 874: Physical Electronics A minimum of six (6) credits in supporting classes from outside the College of Engineering.

11. ECE 6020 Multirate Systems 2 0 0 4 3 12. ECE 6021 Adaptive Signal Processing 2 0 0 4 3 13. ECE 6022 Optical Broadband Access Networks 2 0 0 4 3 14. ECE 6023 RF MEMS 3 0 0 0 3 15. CSE 6051 Information and Network Security 3 0 0 0 3 3. ECE 5011 Advance

ECE 406 - Introduction to Wireless Communication Systems ECE 407 / ECE 408 - Introduction to Computer Networks . measures and protecting customers' digital assets are covered. A broad spectrum of security . Electrodynamics ECE 311 - Engineering Electronics ECE 312 - Electronic Circuits

2. Embedded systems Vs General Computing system Page 4 Sec 1.2 ; 3. History of embedded systems , classification of embedded system Page 5,6 Sec 1.3 , Sec 1,4 . 4. Major application area of embedded sys Page 7 Sec 1.5 5. Purpose of embeded system Page 8 Sec 1.6 6. Typical Embedded sys: Core of embedded system Page 15 Chap 2 : 7. Memory Page 28

to AGMA 9 standard, improved the quality and performance of the QE range. Today, the QE Vibrator not only meets industry expectations, but will out-perform competitive models when correctly selected and operated in line with the information given in this brochure. When a QE Vibrator is directly attached to a trough it is referred to as a “Brute Force” design. It is very simple to calculate .