Tuesday, November 19, 2013

Data Queue Vs Mailbox: Deletion

① Difference between deletion of Data Queue and Mailbox

Both processings are almost same except that in Data Queue both the send-wait and receive-wait queues need to be checked.

② ITRON implementation of delete Data Queue

ER del_dtq(ID dtqid)
{
        If (called from ISR)
                return E_CTX;
        Sanity check on arguments;
        enter critical section;
        if (data queue is full) {
                for (each task waiting in the send-wait queue) {
                        Get the task control block from the task ID
                        Assign E_DLT in the return error code of the task's context;
                        if task is waiting in Timeout
                                remove from timer queue
                        Set task status as Ready
                        if the task is NOT suspended {
                                Change the task to the Ready Queue of priority
                                If (the task priority is higher than the current)
                                        set the flag to call scheduler
                        } else {
                                Just delete the task from the send wait queue
                        }
                }
        }
        if (data queue is empty) {
                for (each task waiting in the receive-wait queue) {
                        Get the task control block from the task ID
                        Assign E_DLT in the return error code of the task's context;
                        if task is waiting in Timeout
                                remove from timer queue
                        Set task status as Ready
                        if the task is NOT suspended {
                                Change the task to the Ready Queue of priority
                                If (the task priority is higher than the current)
                                        set the flag to call scheduler
                        } else {
                                Just delete the task from the send wait queue
                        }
                }
        }
        Free all the memory allocated for the data queue;
        if (the flag to call scheduler is set) {
                call scheduler;
        } else {
                exit critical section and return E_OK;
        }
}
③ITRON implementation of delete Mailbox

ER del_mbx(ID mbxid)
{
        If (called from ISR)
                return E_CTX;
        Sanity check on arguments;
        enter critical section;
        for (each task waiting in the receive-wait queue) {
                Get the task control block from the task ID
                Assign E_DLT in the return error code of the task's context;
                if task is waiting in Timeout
                        remove from timer queue
                Set task status as Ready
                if the task is NOT suspended {
                        Change the task to the Ready Queue of priority
                        If (the task priority is higher than the current)
                                set the flag to call scheduler
                } else {
                        Just delete the task from the send wait queue
                }
        }
        Free all the memory allocated for the mailbox;
        if (the flag to call scheduler is set) {
                call scheduler;
        } else {
                exit critical section and return E_OK;
        }
}

Deletion - Wake up sleeping men and tell them the building no more exists, before burning the building.

Things that matters in Debugging problems

1) Do not believe on assumptions. Do check on assumptions. Problems hide on assumptions.
 
2) Explicit speaking. Explicit speaking will bring out other possibilities of problem. (I hope Indians do well because of what they do get business)
 

Things that matters in Business

1) Chasing... Hesitation is crime.

2) Call for meeting. Discuss things openly.

3) Quote. How much they Quote?
 

Sunday, November 17, 2013

Data Queue Vs MailBox: Refer status

① Difference between referring Data Queue and Mailbox

ref_dtq() returns the task id for waiting receive and send tasks and number of data elements in the data queue.
ref_mbx() has to return either the pointer to the message at the top of the message queue or the task ID which is waiting at the receive waiting queue.

② ITRON implementation of referring data queue

ER ref_dtq(ID dtqid, T_RDTQ *pk_rdtq)
{
        Sanity check on arguments;
        enter critical section;
        store the number of data elements in the data queue into the pk_rdtq->sdtqcnt;
        check the receive waiting task queue;
        if (any task exists) {
                store the task id into the pk_rdtq->stsk_id;
        }
        else {
                pk_rdtq->stsk_id = TSK_NONE;
        }
        check the send waiting task queue;
        if (any task exists) {
                store the task id into the pk_rdtq->rtsk_id;
        }
        else {
                pk_rdtq->rtsk_id = TSK_NONE;
        }
        exit critical section;
        return E_OK;
}

③ ITRON implementation of referring Mailbox

ER ref_mbx(ID mbxid, T_RMBX *pk_rmbx)
{
        Sanity check on arguments;
        enter critical section;
        /* Check for the pending message first */
        get the head of message queue;
        for (each priority level of the messages) {
                get the head pointer to the message queue for the particular level;
                if (there is message) {
                        store the pointer to the message into the pk_rmbx->pk_msg;
                        make pk_rmbx->wtskid = TSK_NONE;
                        return E_OK;
                }
        }
        /* No message; So, check for any waiting task */
        make the pk_rmbx->pk_msg =NULL;
        check for any waiting receive task over the queue;
        if (there is any task) {
                store the task id into the pk_rmbx->wtskid;
                return E_OK;
        }
        /* No task either */
        pk_rmbx->wtskid = TSK_NONE;
        return E_OK;
}
Enjoy embedded RTOS...

Saturday, November 16, 2013

Data Queue Vs MailBox: Receive data

① Difference between receiving data from Data Queue and Mailbox

Data Queue not only should receive the data at the head, but also if there is sending tasks queued, wake up one to place the data at the tail.

② ITRON implementation of receiving data over data queue

ER rcv_dtq(ID dtqid, VP_INT *p_datat)
{
        Sanity check on arguments
        Enter critical section (Interrupt Disable)
        if (data count in queue == 0) {
                /* synchronous message passing */
                Check send task waiting queue;
                if (No task is sleeping) {
                        /* No data, no sending, so got to waiting */
                        If (polling mode)
                                 Exit critical section and return E_TMOUT;
                         If (this function is called from interrupt context) or
                         If (called from task independent state ex: timer handlers) or
                         If (called from dispatch disabled state)
                                 Return E_CTX;
                         If (Timeout value is specified) {
                                 Add task into timer queue;
                                 Set TCB flags that 'Waiting for receive wait queue, Check for Timeout'
                         } else (Wait forever) {
                                 Set TCB flags that 'Waiting forever for receive wait queue'
                         }
                         Set data queue ID in TCB
                         Store the data in context
                         Change the task from ReadyQueue to the Data queue's receive wait Queue
                         Schedule the tasks, since this task is going to sleep
                         (Once the task is released, execution will return here)
                         Return the value set by scheduler(Scheduler directly set return value before return here)
                }
                else { /* some task is sleeping */
                        /* need to wake up with the data */
                        Get the data from task's context and store it in the pointer argument;
                         if task is waiting in Timeout
                                 remove from timer queue
                         Set task status as Ready
                         if the task is NOT suspended {
                                 Change the task to the Ready Queue of priority
                                 If (the task priority is higher than the current){
                                         call scheduler
                                         return error code from scheduler
                                 } else {
                                         Exit critical section and return error code from it (E_OK)
                                         (return E_OK)
                                 }
                         } else {
                                 Just delete the task from the send wait queue
                                 Exit critical section and return the error code from it (E_OK)
                                 (return E_OK)
                         }
                }
        }
        /* Some data is in the data queue. Just receive it */
        Get the data from the read pointer and store it in the pointer argument;
        Update the read pointer;
        decrement the data count;
        /* check for send tasks waiting for to get free space in queue */
        Check send task waiting queue;
        if (any task is waiting) {
                take the data from the task's context;
                add the data at the write pointer of data queue and update the pointer;
                increment the data count of data queue;
                if task is waiting in Timeout
                         remove from timer queue
                Set task status as Ready
                if the task is NOT suspended {
                        Change the task to the Ready Queue of priority
                        If (the task priority is higher than the current){
                                call scheduler
                                return error code from scheduler
                        } else {
                                Exit critical section and return error code from it (E_OK)
                                (return E_OK)
                        }
                } else {
                        Just delete the task from the send wait queue
                        Exit critical section and return the error code from it (E_OK)
                        (return E_OK)
                }
        }
        Exit critical section and return the error code from it (E_OK)
}

② ITRON implementation of receiving data over data queue

ER rcv_mbx(ID mbxid, T_MSG **ppk_msg)
{
        Sanity check on arguments
        Enter critical section (Interrupt Disable)
        /* Reception of message. First, just checking the message queue for each
           message priority level. If message, just take the pointer and return E_OK */
        for (each message priority level, get message queue pointer) {
                if (there is valid message) {
                        Unlink the message on top from the message list;
                        assign the message to the pointer received as argument;
                        Exit critical section and return the error code from it (E_OK)
                }
        }
        /* No message. What to do? */
        if (polling) {
                return E_TMOUT;
        }
        if (called from ISR, Dispatch disabled state or Timer Handlers) {
            return E_CTX;
        }
        /* Make the task waiting */
        If (Timeout value is specified) {
                Add task into timer queue;
                Set TCB flags that 'Waiting for receive wait queue, Check for Timeout'
        } else (Wait forever) {
                Set TCB flags that 'Waiting forever for receive wait queue'
        }
        Store the pointer to the message in the task's context;
        Store the mail box ID in the task's context;
        Select Queue according to queueing order
        If (Tasks should be granted in FIFO order)
                Select receive wait queue->Queue[0] as Queue
        Else (Should be granted in Priority order)
                Select receive wait queue->Queue[Current Tasks Priority]
        Change the task from ReadyQueue to the mail box's receive wait Queue
        Schedule the tasks, since this task is going to sleep
        (Once the task is released, execution will return here)
        Return the value set by scheduler(Scheduler directly set return value before return here)
}
 

Friday, November 08, 2013

Recall Linux

Howto print partition names or partition lables in Linux?
To list all partitions with partition names or partition lables in Linux
$blkid
To just list all mounted ones
#mount -l
To just list all partitions without much details
#fdisk -l
To flush a file which is redirected using redirect symbol:
                        setlinebuf(stdout);



To install ARM cross compiler gcc-arm-linux-gnueabi:

sudo apt-get install gcc-arm-linux-gnueabihf

Thursday, November 07, 2013

cgroup structures

Cgroup includes many css_set, and in the same way, one css_set can be included in many Cgroups. cg_cgroup_link is used to build this relationship. For example, the following 4 cg_cgroup_links are used to make all combinations with in cgroup1, cgroup2, css_sets1 and css_sets2. And, cgroup1 maintains list of all css_sets it includes and css_set maintains list of all cgroups it has been included using the same cg_cgroup_links structures.
 
 
/* Link structure for associating css_set objects with cgroups */
struct cg_cgroup_link {
        /*
         * List running through cg_cgroup_links associated with a
         * cgroup, anchored on cgroup->css_sets
         */
        struct list_head cgrp_link_list;
        struct cgroup *cgrp;
        /*
         * List running through cg_cgroup_links pointing at a
         * single css_set object, anchored on css_set->cg_links
         */
        struct list_head cg_link_list;
        struct css_set *cg;
};

container_of

#first give me member variable you have (whose parent structure is wanted)
#second give me prototype of parent structure
#third give me the exact name of the #first one inside the #second one
 
* container_of - cast a member of a structure out to the containing structure
* @ptr:    the pointer to the member.
* @type:   the type of the container struct this is embedded in.
* @member: the name of the member within the struct.
 

Monday, November 04, 2013

"I see" Facts: ITRON

ITRON: Only two of the kernel objects can be manipulated forcefully. What are they?
 
1) Data Queue (fsnd_dtq, ifsnd_dtq - In case of data queue full, it overwrites the first element of the queue by own)
2) Resume function (frsm_tsk - Cancels even multiple suspend requests and moves task to ready state)
 
Which object will have both send and receive tasks will go waiting?
 
Data Queue - Since the size of data queue is fixed, if it is full even the sending task will go waiting. If the data queue
is empty the receive task will go waiting. So, it will have two wait queues.

What is synchronous message passing in Data Queue?

By making the size of Data Queue as Zero, the send and receive tasks are made to wait for the other to call the complimentary service call and at that timing the data is passed directly. Synchronous message passing is possible only at Data Queue.