CSE 451: Introduction to Operating Systems

 

Section 3, April/12/2001

Jochen Jäger

 

 

 

 

 

 

1.    Project 1 turn in

2.    Project 2 hand out

3.    Questions about lecture, project, etc

4.    Scheduler, processes & context switching


Errata:

 

http://lxr.linux.no

find . –ctime -1

 

 

Scheduler:

 

in kernel/sched.c#L67:

 

#define NICE_TO_TICKS(nice)     (TICK_SCALE(20-(nice))+1)

 

Scheduling quanta.

·       NOTE! The unix "nice" value influences how long a process gets.

·       The nice value ranges from -20 to +19, where a -20 is a "high-priority" task, and a "+10" is a low-priority task.

·       We want the time-slice to be around 50ms or so, so this calculation depends on the value of HZ.

 

#define HZ 100   // in /include/asm-i386/param.h#L5

 

#if HZ < 200

#define TICK_SCALE(x)   ((x) >> 2)

#elif HZ < 400

#define TICK_SCALE(x)   ((x) >> 1)

#elif HZ < 800

#define TICK_SCALE(x)   (x)

#elif HZ < 1600

#define TICK_SCALE(x)   ((x) << 1)

#else

#define TICK_SCALE(x)   ((x) << 2)

#endif

 

 

/*

 * This is the function that decides how desirable a process is..

 * You can weigh different processes against each other depending

 * on what CPU they've run on lately etc to try to handle cache

 * and TLB miss penalties.

 *

 * Return values:

 *       -1000: never select this

 *           0: out of time, recalculate counters (but it might still be

 *              selected)

 *         +ve: "goodness" value (the larger, the better)

 *       +1000: realtime process, select this.

 */

 

static inline int goodness(struct task_struct * p, int this_cpu, struct mm_struct *this_mm)

{

        int weight;

 

        /* select the current process after every other runnable process, but before the idle thread. Also, dont trigger a counter recalculation.    */

        weight = -1;

        if (p->policy & SCHED_YIELD)

                goto out;

 

        /* Non-RT process - normal case first.      */

        if (p->policy == SCHED_OTHER) {

                /* Give the process a first-approximation goodness value according to the number of clock-ticks it has left.

 Don't do any other calculations if the time slice is over..        */

                weight = p->counter;

                if (!weight)

                        goto out;

#ifdef CONFIG_SMP

                /* Give a largish advantage to the same processor...   */

                /* (this is equivalent to penalizing other processors) */

                if (p->processor == this_cpu)

                        weight += PROC_CHANGE_PENALTY;

#endif

 

                /* .. and a slight advantage to the current MM */

                if (p->mm == this_mm || !p->mm)

                        weight += 1;

                weight += 20 - p->nice;

                goto out;

        }

 

        /* Realtime process, select the first one on the runqueue (taking priorities within processes into account).     */

        weight = 1000 + p->rt_priority;

out:

        return weight;

}

 

 

 

 

Thread vs Process:

http://www.byte.com/column/BYT19991122S0002