Rtos
Rtos
-
Re entrant code is code which does not rely on being executed without inte
rruption before completion. Reentrant code can be used by multiple, simult
aneous tasks. Reentrant code generally
does not access global data. Variables within a reentrant function are alloc
ated on the stack, so each instance of the function has its own private data
. Nonreentrant code, to be used safely by multiple
processes, should have access controlled via some synchronization metho
d such as a semaphore.
-
We can use thr fork system call to create a process in UNIX and in OSE th
e system call create_process is used.
8. what is a flat memory model and a shared memory model?
-
in a flatmemory model the code and data segment occupies single address
space.
-
in a shared model the large memory is divided into different segments and
needs a qualifier to identify each segment
-
in a flat memory model the programmer doesnt need to switch for data and
code
Paging
-
Paging is a techinque where in the OS makes available the data required a
s quickly as possible. It stores some pages from the aux device to main me
mory and when a prog needs a page that is not on the main memory it fetch
es it from aux memory and replaces it in main memory. It uses specialised
algorithms to choose which page to replace from in main memory.
Caching
-
It deals with a concept where the data is temperorarily stored in a high spee
d memory for faster access. This data is duplicated in cache and the original
data is stored in some aux memory. This concepts brings the average acce
ss time lower.
Segmentation
-
Segmentation is a memory management scheme. This is the technique use
d for memory protection. Any accesses outside premitted area would result
in segmentation fault.
Virtual Memory
This technique enables non-
contiguous memory to be accessed as if it were contiguous. Same as
paging.
int i=2;
int j=3;
define 2 local variables one after other and try to print the address
12. write a small piece of code protecting a shared memory variable with a se
maphore?
int global_i;
void increment_shared_memory
{
wait(semaphore);
global_i++;
signal(semaphore);
}
13. what are the different types of semaphores and where they are used?
16. what are the different segments of a program (code, data,stack,heap etc)
data segment
-
This is one of the sections of a program in an object file or in memory, whi
ch contains the global variables that are initialized by the programmer. It ha
s a fixed size, since all of the data in this section is set by the programmer
before the program is loaded. However, it is not read-
only, since the values of the variables can be altered at runtime.
.bss
This segment of memory is part of data segment that contains uninitialized
data (static variables). These are initialized to 0 and later assigned values d
uring runtime.
stack segment
-
This segment of memory is a special stack which stores information about
the active subroutines of
a task. It contains the return address to be branched to after a sub-
routine has finished execution. It contains local variables of the sub-
routines and the parameters that are passed to those sub routines.
heap segment
-
The segment of memory which is used for dynamic memory allocation is k
nown as heap. It is the responsibility of the programmer to deallocate it afte
r its use. Or alternatively it will be garbage collected by the OS.
17. what is OS scheduling mechanism in our OSE?
18. how and wher the context related information is stored PCB i guess
19. what is a make command and what are al its uses?
20. what if no process responding how it is handled (watch dog timeout me
chanism)
THREAD POOLING
Modern RTOSs simply make sure that a) no interrupt is ever lost, and b) no
interrupt can be blocked by a lower priority process.
If stack overflow occurs, the program can crash or you can say that segmentation fault
that is the result of the stack overflow.
What is the cause of the stack overflow?
In the embedded application we have a little amount of stack memory as compare to
the desktop application. So we have to work on embedded applications very carefully
either we can face the stack overflow issues that can be a cause of the application
crash.
What is ISR?
An ISR refers to the Interrupt Service Routines. These are procedures stored at
specific memory addresses which are called when a certain type of interrupt occurs.
The Cortex-M processors family has the NVIC that manages the execution of the
interrupt.
What is semaphore?
Semaphore is simply a variable that is non-negative and shared between threads. This
variable is used to solve the critical section problem and to achieve process
synchronization in the multiprocessing environment. A semaphore is a signaling
mechanism, and a thread that is waiting on a semaphore can be signaled by another
thread.
What is mutex?
A Mutex is a mutually exclusive object which protects the shared resources from
simultaneous access by multiple threads or processes. It acts as a gatekeeper to a
section of code allowing one thread in and blocking access to all others. This ensures
that the code being controlled will only be hit by a single thread at a time.
Mutex work on the locking mechanism, the thread which locks the mutex can only
unlock it. So you must release the mutex after its use either it causes serious issues.
Don’t pass the structure variable in a function. Use the pointer or reference to
passing it in a function.
Instead of A() calling B() which calls C() which calls D(), have A() call B(), C(),
and D() itself.
If a function is only referenced once, mark it inline (assuming your compiler
supports this).
Turn on your compiler optimization.
Increase your compiler optimization level.
When the interrupt occurs, the CPU saves its context and jumps to the ISR. The way
the context is saved varies among CPU families. When the ISR is complete, it should
call a special RTOS routine that allows for a context switch after an ISR. If there is a
higher priority task ready to run then this routine will perform a context switch. It will
take the pre-interrupt context saved by the CPU and save it with TASK_1. Then it will
get the saved context of TASK_2 and restore it into the CPU such that when the end-
of-interrupt instruction is called, execution returns to the context of TASK_2.
Note: The details of all of this are very CPU and RTOS-dependent.
What is PendSV?
PendSV is an interrupt-driven request for system-level service. In an OS environment,
use PendSV for context switching when no other exception is active.
What is SVCall?
A supervisor call (SVC) is an exception that is triggered by the SVC instruction. In an
OS environment, applications can use SVC instructions to access OS kernel functions
and device drivers.
What is SysTick?
A SysTick exception is an exception the system timer generates when it reaches zero.
The software can also generate a SysTick exception. In an OS environment, the
processor can use this exception as a system tick.
1. An undefined instruction
2. An illegal unaligned access
3. Invalid state on instruction execution
4. An error on exception return.
The following can cause a UsageFault when the core is configured to report them: