simulation of scheduling algo

Upload: kanika-kapoor

Post on 10-Apr-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/8/2019 Simulation of Scheduling Algo

    1/13

    Scheduling algorithm

    Scheduling algorithm is the method by which threads, processes or data flows are

    given access to system resources (e.g. processor time, communications bandwidth).

    This is usually done to load balance a system effectively or achieve a target quality ofservice. The need for a scheduling algorithm arises from the requirement for most

    modern systems to perform multitasking(execute more than one process at a time)

    and multiplexing (transmit multiple flows simultaneously).

    In Computing And Multitasking

    The algorithm used may be as simple as round-robin in which each process is given

    equal time in a cycling list. So, process A executes for 1 ms, then process B, then

    process C, then back to process A. More advanced algorithms take into accountprocess priority, or the importance of the process. This allows some processes to use

    more time than other processes. It should be noted that the kernel always uses

    whatever resources it needs to ensure proper functioning of the system, and so can be

    said to have infinite priority. In SMP (symmetric multiprocessing) systems, processor

    affinity is considered to increase overall system performance, even if it may cause a

    process itself to run more slowly. This generally improves performance by

    reducing cache thrashing.

    In Computer Networks And Multiplexing

    In computer networks and multiplexing, the notion of a scheduling algorithm is usedas an alternative to first-come first-served queuing of data packets. In advanced packetradio wireless networks such as HSDPA (High-Speed Downlink PacketAccess ) 3.5G cellular system, channel-dependent scheduling may be used to takeadvantage of favourable channel conditions to increase the throughput and systemspectral efficiency. The simplest best-effort scheduling algorithms are round-robin, fairqueuing (a max-min fairscheduling algorithm), proportionally fairschedulingand maximum throughput. If differentiated or guaranteed quality of service is offered, as

    opposed to best-effort communication, weighted fair queuing may be utilized. .Thenotion of a scheduling algorithm is used as an alternative to first-come first-servedqueuing of data packets. LIFO and FIFO refer to how requests or intermediate resultsare stored and dealt with. If requests are handled on a first-come-first-served basis, thedate store is called a 'queue'. If requests are handled Last-In-First-Out, the structure iscalled a 'stack'. Different operations require different data handling.

    WHY SCHEDULING ALGORITHMS?????

    http://en.wikipedia.org/wiki/Thread_(computer_science)http://en.wikipedia.org/wiki/Process_(computing)http://en.wikipedia.org/wiki/Flow_(computer_networking)http://en.wikipedia.org/wiki/Load_balancing_(computing)http://en.wikipedia.org/wiki/Quality_of_servicehttp://en.wikipedia.org/wiki/Quality_of_servicehttp://en.wikipedia.org/wiki/Computer_multitaskinghttp://en.wikipedia.org/wiki/Multiplexinghttp://en.wikipedia.org/wiki/Round-robin_schedulinghttp://en.wikipedia.org/wiki/Symmetric_multiprocessinghttp://en.wikipedia.org/wiki/Processor_affinityhttp://en.wikipedia.org/wiki/Processor_affinityhttp://en.wikipedia.org/wiki/Cache_thrashinghttp://en.wikipedia.org/wiki/Computer_networkshttp://en.wikipedia.org/wiki/Statistical_multiplexinghttp://en.wikipedia.org/wiki/FIFO_(computing)http://en.wikipedia.org/wiki/HSDPAhttp://en.wikipedia.org/wiki/3.5Ghttp://en.wikipedia.org/wiki/Throughputhttp://en.wikipedia.org/wiki/System_spectral_efficiencyhttp://en.wikipedia.org/wiki/System_spectral_efficiencyhttp://en.wikipedia.org/wiki/Round-robin_schedulinghttp://en.wikipedia.org/wiki/Fair_queuinghttp://en.wikipedia.org/wiki/Fair_queuinghttp://en.wikipedia.org/wiki/Max-min_fairhttp://en.wikipedia.org/wiki/Proportionally_fairhttp://en.wikipedia.org/wiki/Maximum_throughput_schedulinghttp://en.wikipedia.org/wiki/Quality_of_servicehttp://en.wikipedia.org/wiki/Weighted_fair_queuinghttp://en.wikipedia.org/wiki/Process_(computing)http://en.wikipedia.org/wiki/Flow_(computer_networking)http://en.wikipedia.org/wiki/Load_balancing_(computing)http://en.wikipedia.org/wiki/Quality_of_servicehttp://en.wikipedia.org/wiki/Quality_of_servicehttp://en.wikipedia.org/wiki/Computer_multitaskinghttp://en.wikipedia.org/wiki/Multiplexinghttp://en.wikipedia.org/wiki/Round-robin_schedulinghttp://en.wikipedia.org/wiki/Symmetric_multiprocessinghttp://en.wikipedia.org/wiki/Processor_affinityhttp://en.wikipedia.org/wiki/Processor_affinityhttp://en.wikipedia.org/wiki/Cache_thrashinghttp://en.wikipedia.org/wiki/Computer_networkshttp://en.wikipedia.org/wiki/Statistical_multiplexinghttp://en.wikipedia.org/wiki/FIFO_(computing)http://en.wikipedia.org/wiki/HSDPAhttp://en.wikipedia.org/wiki/3.5Ghttp://en.wikipedia.org/wiki/Throughputhttp://en.wikipedia.org/wiki/System_spectral_efficiencyhttp://en.wikipedia.org/wiki/System_spectral_efficiencyhttp://en.wikipedia.org/wiki/Round-robin_schedulinghttp://en.wikipedia.org/wiki/Fair_queuinghttp://en.wikipedia.org/wiki/Fair_queuinghttp://en.wikipedia.org/wiki/Max-min_fairhttp://en.wikipedia.org/wiki/Proportionally_fairhttp://en.wikipedia.org/wiki/Maximum_throughput_schedulinghttp://en.wikipedia.org/wiki/Quality_of_servicehttp://en.wikipedia.org/wiki/Weighted_fair_queuinghttp://en.wikipedia.org/wiki/Thread_(computer_science)
  • 8/8/2019 Simulation of Scheduling Algo

    2/13

    Scheduling algorithms are used to decide when and for how long each process runsand also make choices about Preemptibility, Priority, Running time, Run-time-to-completion, fairness.

    FIFO

    In computer science this term refers to the way data stored in a queue is processed asfirst in first out(FIFO). Each item in the queue is stored in a queue (simpliciter) datastructure. The first data to be added to the queue will be the first data to be removed,then processing proceeds sequentially in the same order. This is typical behavior for aqueue.Disk controllers can use the FIFO as a disk scheduling algorithm to determine the orderto service disk I/O requests.

    In hardware FIFO is used for synchronization purposes. It is often implemented as a

    circular queue, and thus has two pointers:

    1. Read Pointer/Read Address Register2. Write Pointer/Write Address Register

    Read and write addresses are initially both at the first memory location and the FIFOqueue is Empty.FIFO EmptyWhen read address register reaches to write address register, the FIFOtriggers the Empty signal.FIFO FULLWhen write address register reaches to readaddress register, the FIFO triggers the FULL signal.

    FIFO is used in queues. And a queue is a particular kind ofcollection in which the

    entities in the collection are kept in order and the principal (or only) operations on the

    collection are the addition of entities to the rear terminal position and removal of entities

    from the front terminal position. This makes the queue a First-In-First-Out (FIFO) data

    structure. In a FIFO data structure, the first element added to the queue will be the first

    one to be removed. This is equivalent to the requirement that whenever an element is

    added, all elements that were added before have to be removed before the new element can

    be invoked. A queue is an example of a linear data structure.

    http://en.wikipedia.org/wiki/Collection_(computing)http://en.wikipedia.org/wiki/FIFO_(computing)http://en.wikipedia.org/wiki/FIFO_(computing)http://en.wikipedia.org/wiki/Collection_(computing)http://en.wikipedia.org/wiki/FIFO_(computing)http://en.wikipedia.org/wiki/FIFO_(computing)
  • 8/8/2019 Simulation of Scheduling Algo

    3/13

    Queues provide services in computer science, transport and operations research where various

    entities such as data, objects, persons, or events are stored and held to be processed later. In

    these contexts, the queue performs the function of a buffer.

    Queues are common in computer programs, where they are implemented as data structurescoupled with access routines, as an abstract data structure or in object-oriented languages as

    classes. Common implementations are circular buffers and linked lists.

    Rear: A variable stores the index number in the array at which the new data will be

    added (in the queue).

    Front: It is a variable storing the index number in the array where the data will be

    retrieved.

    http://en.wikipedia.org/wiki/Computer_sciencehttp://en.wikipedia.org/wiki/Transporthttp://en.wikipedia.org/wiki/Operations_researchhttp://en.wikipedia.org/wiki/Buffer_(computer_science)http://en.wikipedia.org/wiki/Abstract_data_structurehttp://en.wikipedia.org/wiki/Circular_bufferhttp://en.wikipedia.org/wiki/Linked_listhttp://en.wikipedia.org/wiki/Computer_sciencehttp://en.wikipedia.org/wiki/Transporthttp://en.wikipedia.org/wiki/Operations_researchhttp://en.wikipedia.org/wiki/Buffer_(computer_science)http://en.wikipedia.org/wiki/Abstract_data_structurehttp://en.wikipedia.org/wiki/Circular_bufferhttp://en.wikipedia.org/wiki/Linked_list
  • 8/8/2019 Simulation of Scheduling Algo

    4/13

    Algorithum for queues

    This algo inserts an element ITEM into a queue.

    INSERTION(QUEUE, N, FRONT, REAR, ITEM)

    1. If FRONT=1 and REAR=N, or if FRONT=REAR+1, then:

    Write: OVERFLOW, and Return.

    2.If FRONT:=NULL, then:

    Set FRONT:=1 and REAR:=1

    Else if REAR=N, then:

    Set REAR:=1

    Else:

    Set REAR:=REAR+1

    [End of If structure]

    3.Set QUEUE[REAR]:=ITEM

    4.Return

    This algo deletes an element from queue and assigns it to the variable ITEM.

    DELETE(QUEUE, N, FRONT, REAR, ITEM)1. If FRONT=NULL then: Write : UNDERFLOW, and Return.

    2.Set ITEM:=QUEUE[FRONT]

    3. If FRONT= REAR, then

    Set FRONT:=NULL and REAR:=NULL

    Else if FRONT=N , then:

    Set FRONT:=1

    Else:

    Set FRONT:=FRONT+1[End of if structure]

    4. Return

  • 8/8/2019 Simulation of Scheduling Algo

    5/13

    SOURCE CODE FOR NSERTION AND DELETION IN QUEUES

    #include#include#incldue

    Typedef struct node

    {

    Int data;

    Struct node *next;

    }

    Node;

    Void main()

    {

    Node *head *p;

    Clrscr();

    Int n;

    Printf(enter no. of elements);

    Scanf(%d&n);

    Head=(node*)malloc(sizeof(node));

    Head->next=NULL;

    Printf(enter the elements);

    Scanf(%d,&(head->data));

    P=head;

    For(int i=1;inext=(node*)malloc(sizeof(node));

    p=p->next;

  • 8/8/2019 Simulation of Scheduling Algo

    6/13

    p->next=NULL;

    scanf(%d,&p->data);

    }

    Int ch=0;

    While(ch!=4)

    {

    Printf(enter your choice \n 1. insert);

    Printf(:\n 2. delete\n 3. display \n 4. quit);

    Scanf(%d,&ch);

    Switch(ch)

    {

    Case1: p->next=(node*)malloc(sizeof(node));

    P=p->next=NULL;

    Printf(enter elements to insert);

    Scanf(%d,&(p->data));

    Break;

    Case2:

    Printf(enter elements to delete %d,head->data);

    Head=head->next;

    Break;

    Case3:

    P=head;

    Printf(\n)

    While(n!=Null)

    {

  • 8/8/2019 Simulation of Scheduling Algo

    7/13

    Printf(%d,p->data);

    P=p->next;

    }

    Break;

    Case4:

    Printf(\n quit);

    Break;

    }

    }

    Getch();

    }

    LIFO

    In computer science, a stack is a last in, first out (LIFO) abstract data type and datastructure. A stack can have any abstract data type as an element, but is characterizedby only two fundamental operations: push and pop. The push operation adds to the top

    of the list, hiding any items already on the stack, or initializing the stack if it is empty.The pop operation removes an item from the top of the list, and returns this value to thecaller. A pop either reveals previously concealed items, or results in an empty list.A stack is a restricted data structure, because only a small number of operations areperformed on it. The nature of the pop and push operations also means that stackelements have a natural order. Elements are removed from the stack in the reverseorder to the order of their addition: therefore, the lower elements are typically those thathave been in the list the longest. Operations used in stack that is push and pop are:

    a push operation, in which a data item is placed at the location pointed to by the

    stack pointer, and the address in the stack pointer is adjusted by the size of the data

    item;

    a pop or pull operation: a data item at the current location pointed to by the stack

    pointer is removed, and the stack pointer is adjusted by the size of the data item.

  • 8/8/2019 Simulation of Scheduling Algo

    8/13

    Algorithum for traversing a stack is as follows:

    Algo(traversing linear array)here LA is a linear array with lower bound LB and upperbound UB.this algo traverses LA applying an operation. PROCESS to each element ofLA

    1.[initialize counter] set k=LB

    2.Repeat Steps3 and 4 while k

  • 8/8/2019 Simulation of Scheduling Algo

    9/13

    Cin>>n;Cout

  • 8/8/2019 Simulation of Scheduling Algo

    10/13

    typedef struct node

    {

    int data;

    struct node *next;

    }

    node;

    void main()

    {

    node *head,*p;

    clrscr();

    int n;

    printf("enter the number of elements in stack:");

    scanf("%d",&n);

    head=(node*)malloc(sizeof(node));

    head->next=NULL;

    printf("enter the elements:");

    scanf("%d",&(head->data));

    p=head;

    for(int i=1;inext=(node*)malloc(sizeof(node));

    p=p->next;

    p->next=NULL;

    scanf("%d",&(p->data));

  • 8/8/2019 Simulation of Scheduling Algo

    11/13

    }

    int ch;

    printf("enter ur choice 1 push 2 pop 3 display 4 quit :);

    scanf("%d",&ch);

    if(ch==1)

    {

    node *newn;

    newn=(node*)malloc(sizeof(node));

    newn->next=NULL;

    printf("enter the info of elementto b inserted: ");

    scanf("%d",&(newn->data));

    newn->next=head;

    head=newn;

    }

    else if(ch==2)

    {

    int item;

    item=head->data;

    head=head->next;

    printf("item is deleted,so poped element is %d",&item);

    }

    else if(ch==3)

    {

    p=head;

    printf("displaying");

  • 8/8/2019 Simulation of Scheduling Algo

    12/13

    while(p!=NULL)

    {

    printf("%d",p->data);

    p=p->next;

    }

    }

    else if(ch==4)

    {

    printf("quit");

    getch();

    }

    else

    {

    printf("wrong choice");

    }

    goto n;

    }

  • 8/8/2019 Simulation of Scheduling Algo

    13/13

    REFERENCES

    http://learning-computer-programming.blogspot.com/2007/06/data-structures-introduction-to-stacks.html

    http://www.cs.princeton.edu/introcs/43stack/

    http://learning-computer-programming.blogspot.com/2007/06/data-structures-introduction-to-stacks.htmlhttp://learning-computer-programming.blogspot.com/2007/06/data-structures-introduction-to-stacks.htmlhttp://www.cs.princeton.edu/introcs/43stack/http://learning-computer-programming.blogspot.com/2007/06/data-structures-introduction-to-stacks.htmlhttp://learning-computer-programming.blogspot.com/2007/06/data-structures-introduction-to-stacks.htmlhttp://www.cs.princeton.edu/introcs/43stack/