kernel is getting crashed when i tried to change the scheduling queue....... - Minix

This is a discussion on kernel is getting crashed when i tried to change the scheduling queue....... - Minix ; Hi I tried to change the scheduling queue for the user processes. For that I have defined a new Wrapping structure over proc structure in proc.c defined as struct uQ_node{ struct proc * rp; struct uQ_node * next; }; EXTERN ...

+ Reply to Thread
Results 1 to 9 of 9

Thread: kernel is getting crashed when i tried to change the scheduling queue.......

  1. kernel is getting crashed when i tried to change the scheduling queue.......

    Hi

    I tried to change the scheduling queue for the user processes. For
    that I have defined a new Wrapping structure over proc structure in
    proc.c defined as

    struct uQ_node{
    struct proc * rp;
    struct uQ_node * next;
    };

    EXTERN struct uQ_node * uQ_head=NIL_NODE;
    EXTERN struct uQ_node * uQ_tail=NIL_NODE; /* the head and
    tail of the user queue respectively*/


    Now in order to insert in the tail of the queue, i change the code in
    proc.c (/usr/src/kernel) in ready function as....
    {
    struct uQ_node * nodeptr=NIL_NODE;
    nodeptr = (struct uQ_node *)malloc(sizeof(struct uQ_node ));
    nodeptr->rp=rp;
    nodeptr->next=NIL_NODE;
    -----------------
    -------------- /* same as in original ready function */
    -------------

    if(uQ_head == NIL_NODE){ /* where
    NIL_NODE is #define NIL_NODE ((struct uQ_node *) 0)
    uQ_head = nodeptr;
    }
    else
    uQ_tail->next = nodeptr;

    uQ_tail=nodeptr;
    }

    I also made changes in unready function as
    nodeptr=uQ_head;
    if(uQ_head!=NIL_NODE)
    {
    uQ_head=uQ_head->next;
    free(nodeptr);
    }


    But when i recompile the kernel and boot the new image, the kernel is
    crashing................. could anyone figure out the reason????
    plz. help me....

    Thanks in advance.
    }


  2. Re: kernel is getting crashed when i tried to change the scheduling queue.......

    All,

    > Now in order to insert in the tail of the queue, i change the code in
    > proc.c (/usr/src/kernel) in ready function as....
    > {
    > struct uQ_node * nodeptr=NIL_NODE;
    > nodeptr = (struct uQ_node *)malloc(sizeof(struct uQ_node ));
    > nodeptr->rp=rp;
    > nodeptr->next=NIL_NODE;


    One definite no-no is calling standard malloc(). That will try to
    sendrec() a message to PM.

    If you must use dynamic memory allocation, include your own malloc()
    in the kernel or statically declare and manually allocate nodes.

    =Ben



  3. Re: kernel is getting crashed when i tried to change the scheduling queue.......

    On 10 Mar, 21:58, Ben Gras wrote:
    > All,
    >
    > > Now in order to insert in the tail of the queue, i change the code in
    > > proc.c (/usr/src/kernel) in ready function as....
    > > {
    > > struct uQ_node * nodeptr=NIL_NODE;
    > > nodeptr = (struct uQ_node *)malloc(sizeof(struct uQ_node ));
    > > nodeptr->rp=rp;
    > > nodeptr->next=NIL_NODE;

    >
    > One definite no-no is calling standard malloc(). That will try to
    > sendrec() a message to PM.
    >
    > If you must use dynamic memory allocation, include your own malloc()
    > in the kernel or statically declare and manually allocate nodes.
    >
    > =Ben



    Thanks for ur reply Ben. Instead of using malloc, i also tried the
    following code.

    struct uQ_node node;

    node.rp=rp;
    node.next=NIL_NODE;
    nodeptr=&node;

    but even this was not working.....


  4. Re: kernel is getting crashed when i tried to change the scheduling queue.......

    koundyc@gmail.com wrote:
    > On 10 Mar, 21:58, Ben Gras wrote:
    >> All,
    >>
    >> > Now in order to insert in the tail of the queue, i change the code in
    >> > proc.c (/usr/src/kernel) in ready function as....
    >> > {
    >> > struct uQ_node * nodeptr=NIL_NODE;
    >> > nodeptr = (struct uQ_node *)malloc(sizeof(struct uQ_node ));
    >> > nodeptr->rp=rp;
    >> > nodeptr->next=NIL_NODE;

    >>
    >> One definite no-no is calling standard malloc(). That will try to
    >> sendrec() a message to PM.
    >>
    >> If you must use dynamic memory allocation, include your own malloc()
    >> in the kernel or statically declare and manually allocate nodes.
    >>
    >> =Ben



    > Thanks for ur reply Ben. Instead of using malloc, i also tried the
    > following code.


    > struct uQ_node node;


    > node.rp=rp;
    > node.next=NIL_NODE;
    > nodeptr=&node;


    > but even this was not working.....


    Declaring node inside a function will cause the memory to be allocated
    on the stack. Once the function exits the memory is released and when some
    other function is called the memory area on the stack is overwritten and
    your queue gets corrupted. You need to find some way to allocate your
    struct uQ_node's on the heap without using standard malloc().

    Regards,

    Jens

    --
    Jens de Smit
    Student Computer Science | Vrije Universiteit Amsterdam
    jfdsmit@few.vu.nl | http://www.few.vu.nl/~jfdsmit
    "[In the end, people] get furious at IT that the goddamn magic isn't working"
    -- Stewart Dean

  5. Re: kernel is getting crashed when i tried to change the scheduling queue.......

    On 12 Mar, 14:36, Smit de JF wrote:
    > koun...@gmail.com wrote:
    > > On 10 Mar, 21:58, Ben Gras wrote:
    > >> All,

    >
    > >> > Now in order to insert in the tail of the queue, i change the code in
    > >> > proc.c (/usr/src/kernel) in ready function as....
    > >> > {
    > >> > struct uQ_node * nodeptr=NIL_NODE;
    > >> > nodeptr = (struct uQ_node *)malloc(sizeof(struct uQ_node ));
    > >> > nodeptr->rp=rp;
    > >> > nodeptr->next=NIL_NODE;

    >
    > >> One definite no-no is calling standard malloc(). That will try to
    > >> sendrec() a message to PM.

    >
    > >> If you must use dynamic memory allocation, include your own malloc()
    > >> in the kernel or statically declare and manually allocate nodes.

    >
    > >> =Ben

    > > Thanks for ur reply Ben. Instead of using malloc, i also tried the
    > > following code.
    > > struct uQ_node node;
    > > node.rp=rp;
    > > node.next=NIL_NODE;
    > > nodeptr=&node;
    > > but even this was not working.....

    >
    > Declaring node inside a function will cause the memory to be allocated
    > on the stack. Once the function exits the memory is released and when some
    > other function is called the memory area on the stack is overwritten and
    > your queue gets corrupted. You need to find some way to allocate your
    > struct uQ_node's on the heap without using standard malloc().
    >
    > Regards,
    >
    > Jens
    >
    > --
    > Jens de Smit
    > Student Computer Science | Vrije Universiteit Amsterdam
    > jfds...@few.vu.nl |http://www.few.vu.nl/~jfdsmit
    > "[In the end, people] get furious at IT that the goddamn magic isn't working"
    > -- Stewart Dean


    Thankyou Jen... could you plz. suggest a way to allocate on heap......


  6. Re: kernel is getting crashed when i tried to change the scheduling queue.......

    koundyc@gmail.com wrote:
    >> Declaring node inside a function will cause the memory to be allocated
    >> on the stack. Once the function exits the memory is released and when some
    >> other function is called the memory area on the stack is overwritten and
    >> your queue gets corrupted. You need to find some way to allocate your
    >> struct uQ_node's on the heap without using standard malloc().


    > Thankyou Jen... could you plz. suggest a way to allocate on heap......


    Probably easiest is to declare an array of uQ_node's globally or static
    locally like so:

    struct uQ_node node_pool[1024];

    Whenever you need a node, loop through the array:

    struct uQ_node *free_node = NIL_NODE;
    for (i = 0; i < 1024; i++) {
    if (node_pool[i].rp == NIL_NODE) {
    // this node is free
    free_node = &(node_pool[i]);
    break;
    }
    }
    if (free_node == NIL_NODE) {
    panic("No free nodes left\n");
    } else {
    // do what you need to do
    }

    Whenever you don't need a node anymore, make sure to set its rp value to
    NIL_NODE to indicate it is free, and do not forget to initialize all nodes
    in the pool to NIL_NODE, otherwise some nodes may be considered not-empty
    when in fact they are.

    Oh, btw, 1024 is a very basic guess, you might need to adjust this value.

    Regards,

    Jens

    --
    Jens de Smit
    Student Computer Science | Vrije Universiteit Amsterdam
    jfdsmit@few.vu.nl | http://www.few.vu.nl/~jfdsmit
    "[In the end, people] get furious at IT that the goddamn magic isn't working"
    -- Stewart Dean

  7. Re: kernel is getting crashed when i tried to change the scheduling queue.......

    On 12 Mar, 18:37, Smit de JF wrote:
    > koun...@gmail.com wrote:
    > >> Declaring node inside a function will cause the memory to be allocated
    > >> on the stack. Once the function exits the memory is released and when some
    > >> other function is called the memory area on the stack is overwritten and
    > >> your queue gets corrupted. You need to find some way to allocate your
    > >> struct uQ_node's on the heap without using standard malloc().

    > > Thankyou Jen... could you plz. suggest a way to allocate on heap......

    >
    > Probably easiest is to declare an array of uQ_node's globally or static
    > locally like so:
    >
    > struct uQ_node node_pool[1024];
    >
    > Whenever you need a node, loop through the array:
    >
    > struct uQ_node *free_node = NIL_NODE;
    > for (i = 0; i < 1024; i++) {
    > if (node_pool[i].rp == NIL_NODE) {
    > // this node is free
    > free_node = &(node_pool[i]);
    > break;
    > }}
    >
    > if (free_node == NIL_NODE) {
    > panic("No free nodes left\n");} else {
    >
    > // do what you need to do
    >
    > }
    >
    > Whenever you don't need a node anymore, make sure to set its rp value to
    > NIL_NODE to indicate it is free, and do not forget to initialize all nodes
    > in the pool to NIL_NODE, otherwise some nodes may be considered not-empty
    > when in fact they are.
    >
    > Oh, btw, 1024 is a very basic guess, you might need to adjust this value.
    >
    > Regards,
    >
    > Jens
    >
    > --
    > Jens de Smit
    > Student Computer Science | Vrije Universiteit Amsterdam
    > jfds...@few.vu.nl |http://www.few.vu.nl/~jfdsmit
    > "[In the end, people] get furious at IT that the goddamn magic isn't working"
    > -- Stewart Dean



    Thanks Jen... Initially I thought of the same solution.... but if
    we can do what ever malloc does in kernel without calling malloc, i
    think that would also solve the purpose...... what do u say.. which
    one is the better??


  8. Re: kernel is getting crashed when i tried to change the scheduling queue.......

    On 12 Mar, 18:37, Smit de JF wrote:
    > koun...@gmail.com wrote:
    > >> Declaring node inside a function will cause the memory to be allocated
    > >> on the stack. Once the function exits the memory is released and when some
    > >> other function is called the memory area on the stack is overwritten and
    > >> your queue gets corrupted. You need to find some way to allocate your
    > >> struct uQ_node's on the heap without using standard malloc().

    > > Thankyou Jen... could you plz. suggest a way to allocate on heap......

    >
    > Probably easiest is to declare an array of uQ_node's globally or static
    > locally like so:
    >
    > struct uQ_node node_pool[1024];
    >
    > Whenever you need a node, loop through the array:
    >
    > struct uQ_node *free_node = NIL_NODE;
    > for (i = 0; i < 1024; i++) {
    > if (node_pool[i].rp == NIL_NODE) {
    > // this node is free
    > free_node = &(node_pool[i]);
    > break;
    > }}
    >
    > if (free_node == NIL_NODE) {
    > panic("No free nodes left\n");} else {
    >
    > // do what you need to do
    >
    > }
    >
    > Whenever you don't need a node anymore, make sure to set its rp value to
    > NIL_NODE to indicate it is free, and do not forget to initialize all nodes
    > in the pool to NIL_NODE, otherwise some nodes may be considered not-empty
    > when in fact they are.
    >
    > Oh, btw, 1024 is a very basic guess, you might need to adjust this value.
    >
    > Regards,
    >
    > Jens
    >
    > --
    > Jens de Smit
    > Student Computer Science | Vrije Universiteit Amsterdam
    > jfds...@few.vu.nl |http://www.few.vu.nl/~jfdsmit
    > "[In the end, people] get furious at IT that the goddamn magic isn't working"
    > -- Stewart Dean


    The method which you suggested is working..... thankyou for your help
    Jen...


  9. Re: kernel is getting crashed when i tried to change the scheduling queue.......

    koundyc@gmail.com wrote:
    > Thanks Jen... Initially I thought of the same solution.... but if
    > we can do what ever malloc does in kernel without calling malloc, i
    > think that would also solve the purpose...... what do u say.. which
    > one is the better??


    Allocating memory inside the kernel is dangerous business. For starters,
    you have to do the work yourself instead of having the OS take care of it
    for you. Secondly, it introduces the risk of memory leaks. While memory
    leaks in user processes are annoying and hamper performance, memory leaks
    inside the kernel will invariably kill your system every once in a while.

    If you look at other parts of the kernel and servers, you will see that
    they all use static allocation of data structures. While this decreases
    flexibility (i.e. a limited number of processes) it eases design and
    implementation thus reducing the chance of critical bugs inside the
    kernel. Although "better" is a subjective term in this context (do you
    prefer reliability or flexibility?) I would say that the node pool
    approach is better than allocating and freeing memory as needed.

    Oh, if processes never appear twice in your queues, you can set the number
    of nodes in the node pool to be equal to the number of slots in the
    process table. This way you will always have exactly the number of nodes
    you need to serve your queueing purposes.

    Regards,

    Jens

    --
    Jens de Smit
    Student Computer Science | Vrije Universiteit Amsterdam
    jfdsmit@few.vu.nl | http://www.few.vu.nl/~jfdsmit
    "[In the end, people] get furious at IT that the goddamn magic isn't working"
    -- Stewart Dean

+ Reply to Thread