Lesson-6: Signal Related OS Functions

Lesson-6: Signal Related OS Functions

INTER-PROCESS COMMUNICATION AND SYNCHRONISATION: Lesson-6: Signal Related OS Functions Chapter-9 L06: "Embedded Systems - Architecture, Programming and Design", 2015 1 Raj Kamal, Publs.: McGraw-Hill EducationInc. 1. Signal Chapter-9 L06: "Embedded Systems - Architecture, Programming and Design", 2015 2 Raj Kamal, Publs.: McGraw-Hill EducationInc. Signal One way for messaging is to use an OS function signal ( ). Provided in Unix, Linux and several RTOSes. Unix and Linux OSes use signals profusely and have thirty-one different types of signals for the various events. Chapter-9 L06: "Embedded Systems - Architecture, Programming and Design", 2015 3 Raj Kamal, Publs.: McGraw-Hill EducationInc. Signal A signal is the software equivalent of the flag at a register that sets on a hardware interrupt Unless masked by a signal mask, the signal allows the execution of the signal handling function and allows the handler to run just as a hardware interrupt allows the execution of an ISR Chapter-9 L06: "Embedded Systems - Architecture, Programming and Design", 2015 4 Raj Kamal, Publs.: McGraw-Hill EducationInc. Signal… Signal is an IPC used for signaling from a process A to OS to enable start of another process B Signal is a one or two byte IPC from a process to the OS. Chapter-9 L06: "Embedded Systems - Architecture, Programming and Design", 2015 5 Raj Kamal, Publs.: McGraw-Hill EducationInc. Signal … Signal provides the shortest communication. The signal ( ) sends a one-bit output for a process, which unmasks a signal mask of a process or task (called signal handler) The handler has coding similar to ones in an ISR runs in a way similar to a highest priority ISR. Chapter-9 L06: "Embedded Systems - Architecture, Programming and Design", 2015 6 Raj Kamal, Publs.: McGraw-Hill EducationInc. Signal … An ISR runs on an hardware interrupt provided that interrupt is no masked. The signal handler also runs on signal provided that signal is no masked Chapter-9 L06: "Embedded Systems - Architecture, Programming and Design", 2015 7 Raj Kamal, Publs.: McGraw-Hill EducationInc. Signal … Signal ( ) forces a signaled process or task called signal handler to run. When there is return from the signaled or forced task or process, the process, which sent the signal, runs the codes as happens on a return from the ISR. Chapter-9 L06: "Embedded Systems - Architecture, Programming and Design", 2015 8 Raj Kamal, Publs.: McGraw-Hill EducationInc. Signal ... OS connects a signal to a process or ISR j (called signal handler function), and resets the signal mask of j. Then the j runs after all higher than j priority processes (or ISRs) finish. Chapter-9 L06: "Embedded Systems - Architecture, Programming and Design", 2015 9 Raj Kamal, Publs.: McGraw-Hill EducationInc. Signal ... An OS provision for signal as an IPC function means a provision for interrupt-message from a process or task to another process or task Chapter-9 L06: "Embedded Systems - Architecture, Programming and Design", 2015 10 Raj Kamal, Publs.: McGraw-Hill EducationInc. Signal ( ) IPC function SigHandler ( ) to create a signal handler corresponding to a signal identified by the signal number and define a pointer to signal context The signal context saves the registers on signal. Chapter-9 L06: "Embedded Systems - Architecture, Programming and Design", 2015 11 Raj Kamal, Publs.: McGraw-Hill EducationInc. Signal ( ) Connect function Connect an interrupt vector to a signal number, with signaled handler function and signal handler arguments The interrupt vector provides the program counter value for address of signal handler function Chapter-9 L06: "Embedded Systems - Architecture, Programming and Design", 2015 12 Raj Kamal, Publs.: McGraw-Hill EducationInc. Signal ( ) IPC functions signal ( ) to send a signal identified by a number to a signal handler task Mask the signal Unmask the signal Ignore the signal Chapter-9 L06: "Embedded Systems - Architecture, Programming and Design", 2015 13 Raj Kamal, Publs.: McGraw-Hill EducationInc. 2. Comparison between signal and semaphore Chapter-9 L06: "Embedded Systems - Architecture, Programming and Design", 2015 14 Raj Kamal, Publs.: McGraw-Hill EducationInc. Signal and Semaphore Some OSes provide the signal and semaphore both IPC functions Every OS provides semaphore IPC functions. When the IPC functions for signal are not provided by an OS, then the OS employs semaphore for the same purpose. Chapter-9 L06: "Embedded Systems - Architecture, Programming and Design", 2015 15 Raj Kamal, Publs.: McGraw-Hill EducationInc. Task A sending signal sB to initiate Task B (signal handler) to run OS Task B signal Task A mask B start B Send sB Chapter-9 L06: "Embedded Systems - Architecture, Programming and Design", 2015 16 Raj Kamal, Publs.: McGraw-Hill EducationInc. Task A sending semaphore as event flag semi to initiate a task section waiting to take semi before it could run OS Task B signal Task A mask B Wait semi Change semi = 1 Take semi = 0 Release semi Start semi Chapter-9 L06: "Embedded Systems - Architecture, Programming and Design", 2015 17 Raj Kamal, Publs.: McGraw-Hill EducationInc. 3. Example of using signal ( ) Chapter-9 L06: "Embedded Systems - Architecture, Programming and Design", 2015 18 Raj Kamal, Publs.: McGraw-Hill EducationInc. Signal ( ) Example Handling of exception. An exception is a process that is executed on a specific reported run-time condition. Chapter-9 L06: "Embedded Systems - Architecture, Programming and Design", 2015 19 Raj Kamal, Publs.: McGraw-Hill EducationInc. Signal ( ) Example A signal reports an error (called 'Exception') during the running of a task and then lets the scheduler initiate an error-handling process or ISR, for example, initiate error-login task. - Handling of signal is similar to an ISR handling function using an interrupt vector. Chapter-9 L06: "Embedded Systems - Architecture, Programming and Design", 2015 20 Raj Kamal, Publs.: McGraw-Hill EducationInc. 4. Advantage of using a Signal Chapter-9 L06: "Embedded Systems - Architecture, Programming and Design", 2015 21 Raj Kamal, Publs.: McGraw-Hill EducationInc. Advantage of using a Signal Unlike semaphores, it takes the shortest possible CPU time. The signals are the flag or one or two byte message used as the IPC functions for synchronizing the concurrent processing of the tasks. Chapter-9 L06: "Embedded Systems - Architecture, Programming and Design", 2015 22 Raj Kamal, Publs.: McGraw-Hill EducationInc. Signal handler Tasks B, C, and D Synchronizing their execution by signals s1, s2 and s3 Task A Task B Task C Task D Start B Start C Start D Send s2 Send s3 Send s1 Chapter-9 L06: "Embedded Systems - Architecture, Programming and Design", 2015 23 Raj Kamal, Publs.: McGraw-Hill EducationInc. Task i sending signal s to initiate signal handler ISR j Execute signal ( ) OS ISR j signal Task i mask j start j Send sj Return Chapter-9 L06: "Embedded Systems - Architecture, Programming and Design", 2015 24 Raj Kamal, Publs.: McGraw-Hill EducationInc. Advantage of using a Signal 1. A signal is the software equivalent of the flag at a register that sets on a hardware interrupt. 2. It is sent on some exception or on some condition, which can set during running of a process or task or thread. 3. Sending a signal is software equivalent of throwing exception in C/C++ or Java program Chapter-9 L06: "Embedded Systems - Architecture, Programming and Design", 2015 25 Raj Kamal, Publs.: McGraw-Hill EducationInc. Advantage of using a Signal 4. Unless process is masked by a signal mask, the signal allows the execution of the signal handling process, just as a hardware interrupt allows the execution of an ISR Chapter-9 L06: "Embedded Systems - Architecture, Programming and Design", 2015 26 Raj Kamal, Publs.: McGraw-Hill EducationInc. Advantage of using a Signal 5. A signal is identical to setting a flag that is shared and used by another interrupt servicing process. 6. A signal raised by one process forces another process to interrupt and to catch that signal provided the signal is not masked at that process. Chapter-9 L06: "Embedded Systems - Architecture, Programming and Design", 2015 27 Raj Kamal, Publs.: McGraw-Hill EducationInc. 5. Drawbacks of using a Signal Chapter-9 L06: "Embedded Systems - Architecture, Programming and Design", 2015 28 Raj Kamal, Publs.: McGraw-Hill EducationInc. Drawbacks of using a Signal 1. Signal should be handled only in a very high priority process (service routine), else that may disrupt the usual schedule and usual priority inheritance mechanism. 2. Signal may cause reentrancy problem [process not retuning to state identical to the one before signal handler process executed]. Chapter-9 L06: "Embedded Systems - Architecture, Programming and Design", 2015 29 Raj Kamal, Publs.: McGraw-Hill EducationInc. Summary Chapter-9 L06: "Embedded Systems - Architecture, Programming and Design", 2015 30 Raj Kamal, Publs.: McGraw-Hill EducationInc. We learnt Signal, the simplest IPC for messaging and synchronizing processes is signal Signal, the shortest message. Uses: Initiating another ISR or task and error handling process called signal handler. Signal is equivalent throwing exception in Java/C/C++ or setting of an interrupt flag Chapter-9 L06: "Embedded Systems - Architecture, Programming and Design", 2015 31 Raj Kamal, Publs.: McGraw-Hill EducationInc. End of Chapter 9 Lesson-06 on Signal Related OS Functions Chapter-9 L06: "Embedded Systems - Architecture, Programming and Design", 2015 32 Raj Kamal, Publs.: McGraw-Hill EducationInc. .

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    32 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us