you need to submit one Zipped Folder (.zip) that contains: 1. .pdf files that contains answers to any required questions and modified codes showing the modification (such as yellow highlight) 2. .c/.h...

1 answer below »

you need to submit one Zipped Folder (.zip) that contains:


1. .pdf files that contains answers to any required questions and modified codes showing the modification (such as yellow highlight)


2. .c/.h files that you have changed


3. Video file (shows you explaining the code and showing results/output). There is no need to capture make clean,make, sudo and upload steps, and the opening of the back end. The video file should be maximum five minutes.


4. A tar file of the updated xinu folder (if you want).




Lab 5 Design and implement versions of send() and receive() that record up to K messages per process. As we discussed before, the low level messaging system in xinu has two important functions send and receive. One main issue with the low level messaging in xinu is there is only one message and if another message is sent to a process, this message will be ignored. In this lab, you are required to change the original send and receive functions to allow sending and receiving up to K messages. Help instructions (You do not have to follow the following instructions). 1. Edit the original send and receive functions or create new send and receive functions and call them sendk and receivek. 2. In your main function, you can call the new send and receive functions or you can create new shell commands to be able to call the new send and receive functions from the shell as you did in the midterm exam. 3. To show that your new xinu messaging system can now accept up to K messages. Assume K in your program as 5. Then, send 10 messages. So, if your system is working, you should fill a buffer of the first five messages and then show an error for the other five messages. 4. To receive the five messages sent before, you can get them from the buffer in FIFO or in LIFO. Your call! 5. prhasmsg flag should be updated to handle more situations (not only true and false) since a process can have more than one message i.e. up to k messages. Submission To submit, create a ZIP file of the following items and submit on the course website: · A pdf file with all the codes of any file you edited or modified. [Highlighting modifications, showing the full path of each file, and fully commented code] · A compiled and tested (xinu) folder that includes all the subdirectories even files you did not change. You can “tar” this folder if you want. · A video demo. You should start with a short introduction of your modified codes followed by the backend open and finally, showing the results. If the video is too long, kindly, divide it into two or three videos.
Answered Same DayMar 05, 2021

Answer To: you need to submit one Zipped Folder (.zip) that contains: 1. .pdf files that contains answers to...

Vidhi answered on Mar 07 2021
134 Votes
xinu_implementation/main.c
#include
#include
#include
#include
syscall sendMsg(pid32 pid, umsg32 msg);
uint32 sendMsgs(pid32 pid, umsg32* msgs, uint32 total_mess);
umsg32 receiveMsg(void);
syscall receiveMsgs(umsg32* msgs, uint32 msgs_count);
uint32 sendnMsg(uint32 pid_count, pid32* pids, umsg32 msg);
void insertItem (pid32 pid, umsg32 msg);
umsg32 getItem (pid32 pid);
void messageSender (void);
void singleMessageReceiver (void);
void multipleMessageReceiver (uint32 total_mess);
# define QUEUE_SIZE 10
# define QUEUE_HEAD queuePointer[pid][0]
# define QUEUE_TAIL queuePointer[pid][1]
# define
SIZE (QUEUE_SIZE - (queuePointer[pid][0] - queuePointer[pid][1])) % QUEUE_SIZE
umsg32 messageBuffer[10][QUEUE_SIZE] = {{0}};    // Message buffer initialized for storing the messages of each process
uint32 queuePointer[10][2] = {{0}};        // Pointer initialized for head and tail of circular queue of each process
pid32 rec1, rec2, rec3;
int main(int argc, char **argv)
{
// creating multiple receivers
    rec1 = create(multipleMessageReceiver, 4096, 50, "Receiver1", 1, 2);
    rec2 = create(singleMessageReceiver, 4096, 50, "Receiver2", 0, 0);
    rec3 = create(multipleMessageReceiver, 4096, 50, "Receiver3", 1, 3);
    
    resume(rec1);
    resume(rec2);
    resume(rec3);
    resume(create(messageSender, 4096, 50, "Sender1", 0, 0));
    while(TRUE)
    {
        
    }
    
    return OK;
}
/* Process created for sending messages to k processes which are in queue*/
void messageSender(void) {
    umsg32 singleReceiverMessages = 0;
    umsg32 multipleReceiverMessages = 1000;
    uint32 testCount;
    for(testCount = 0; testCount<3; testCount++)
    {
        /* Test case for sending single message to single process (Receiver1) */
        if(sendMsg(rec1, singleReceiverMessages++) == SYSERR)
        {
            kprintf("Message not sent.\n");
        }
        /* Test case for sending multiple messages to single process (Receiver3) */
        umsg32 msgs[8] = {1, 1, 2, 3, 5, 8, 13, 21};
        if(sendMsgs(rec3, msgs, 8) == SYSERR)
        {
            kprintf("Multiple message send failed and it is finely catched .\n");
        }
        /* Test case for sending single message to multiple processes (Receiver1, Receiver2, Receiver3) */
        pid32 receivers[3] = {rec1, rec2, rec3};
        if (sendnMsg(3, receivers, multipleReceiverMessages++) != 3)
        {
            kprintf("Multiple receiver send failed.\n");
        }
    }
    
}
/* Process created for receiving single message */
void singleMessageReceiver(void) {
    while (TRUE)
    {
        umsg32 msg = receiveMsg();
        if (msg == SYSERR)
        {
            kprintf("Message not received.\n");
        }
    }    
}
/*Process created for receiving multiple messages at a time*/
void multipleMessageReceiver(uint32 total_mess) {
    while (TRUE)
    {
        umsg32 msgs[total_mess];
        if (receiveMsgs(msgs, total_mess) == SYSERR)
        {
            kprintf("%d messages not received.\n", total_mess);
        }
    }    
}
void insertItem (pid32 pid, umsg32 msg) // inserting the information in queue
{
    messageBuffer[pid][QUEUE_TAIL] = msg;
    QUEUE_TAIL++;
    QUEUE_TAIL = QUEUE_TAIL % 8;
}
umsg32 getItem (pid32 pid)
{
    uint32 tempValue = messageBuffer[pid][QUEUE_HEAD];
    messageBuffer[pid][QUEUE_HEAD] = 0;     // Remove the contents from the location
    QUEUE_HEAD++;
    QUEUE_HEAD = QUEUE_HEAD % 8;
    return tempValue;
}
syscall    sendMsg (pid32 pid, umsg32 msg)
{
    intmask    mask;                // saved interrupt mask
    struct    procent *prptr;            // ptr to process' table entry
    mask = disable();
    if (isbadpid(pid)) {
        restore(mask);
        kprintf("Bad PID for process %d\t", pid);
        return SYSERR;
    }
    prptr = &proctab[pid];
    if (prptr->prstate == PR_FREE) {
        restore(mask);
        kprintf("Free Process\t");
        return SYSERR;
    }
    if (messageBuffer[pid][QUEUE_TAIL] != 0) //Queue of receiver is full
    {
        restore(mask);
        kprintf("Queue is Full\t");
        return SYSERR;
    }
    else
    {
        insertItem(pid, msg);
        kprintf("Message ""%d"" sent to process %d.\n", msg, pid);
    }
    /* If recipient waiting or in timed-wait make it ready */
    if (prptr->prstate == PR_RECV) {
        ready(pid);
    } else if (prptr->prstate == PR_RECTIM) {
        unsleep(pid);
        ready(pid);
    }
    restore(mask);                // Restore interrupts
    return OK;
}
umsg32    receiveMsg(void)
{
    intmask    mask;                // saved interrupt mask        
    struct    procent *prptr;            // ptr to process' table entry    
    umsg32    msg;                // message to return
    pid32 pid = getpid();            //Get current process pid
    mask = disable();
    prptr = &proctab[currpid];
    if (QUEUE_HEAD == QUEUE_TAIL)         //Queue is empty, No message waiting
    {
        prptr->prstate = PR_RECV;
        resched();            // Block until message arrives
    }
    msg = getItem (pid);            // Retrieve the message
    kprintf("Message ""%d"" received by process %d.\n", msg, pid);
    restore(mask);
    return msg;
}
uint32 sendMsgs (pid32 pid, umsg32* msgs, uint32 total_mess)
{
    uint32 count = 0;            // Count initialized for keeping track of how many messages were sent correctly
    uint32 ret, i;
    for (i=0;i    {
        ret = sendMsg(pid,msgs[i]);
        if (ret == OK)
            count++;
    }
    if (count > 0)                // Return number of correctly sent messages
    {
        kprintf("%d of %d messages sent correctly.\n", count, total_mess);
        return count;
    }    
    else
        return SYSERR;
}
uint32 sendnMsg (uint32 pid_count, pid32* pids, umsg32 msg)
{
    uint32 count = 0;             // Count initialized for keeping track of how many messages were sent correctly
    uint32 ret, i;
    for (i=0;i    {
        ret = sendMsg(pids[i],msg);
        if (ret == OK)
            count++;
    }
    if (count > 0)             // Return number of correctly sent messages
    {
        kprintf("Message sent correctly to %d of %d processes.\n", count, pid_count);
        return count;
    }
    else
        return SYSERR;
}
syscall    receiveMsgs (umsg32* msgs, uint32 total_mess)
{
    intmask    mask;                // saved interrupt mask
    struct    procent *prptr;            // ptr to process' table entry
    pid32 pid = getpid();             //Get current process pid
    mask = disable();
    prptr = &proctab[currpid];
    if (total_mess > 11)            //Check if total_mess is larger than the queue size
        return SYSERR;
    else if (QUEUE_HEAD == QUEUE_TAIL)     //Queue is empty, No message waiting
    {
        prptr->prstate = PR_RECV;
        resched();            // block until messages arrives
    }
    while (SIZE < total_mess)
    {
        prptr->prstate = PR_RECV;
        resched();            // block until messages arrives
    }
    int i;
    for(i=0;i    {
        msgs[i] = receiveMsg();
    }
    kprintf("%d messages received by processes %d.\n", total_mess, pid);
    restore(mask);
    return...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here