Linux Kernel Architecture

(Jacob Rumans) #1
Mauerer app04.tex V1 - 09/04/2008 6:12pm Page 1231

Appendix D: System Startup


ticks = jiffies;
while (ticks == jiffies)
/* nothing */;
/* Go .. */
ticks = jiffies;
__delay(loops_per_jiffy);
ticks = jiffies - ticks;
if (ticks)
break;
}

/*
* Do a binary approximation to get loops_per_jiffy set to
* equal one clock (up to lps_precision bits)
*/
loops_per_jiffy >>= 1;
loopbit = loops_per_jiffy;
while ( lps_precision-- && (loopbit >>= 1) ) {
loops_per_jiffy |= loopbit;
ticks = jiffies;
while (ticks == jiffies)
/* nothing */;
ticks = jiffies;
__delay(loops_per_jiffy);
if (jiffies != ticks) /* longer than 1 tick */
loops_per_jiffy &= ~loopbit;
}

/* Round the value and print it */
printk("%lu.%02lu BogoMIPS (lpj=%lu)\n",
loops_per_jiffy/(500000/HZ),
(loops_per_jiffy/(5000/HZ)) % 100,
loops_per_jiffy);
}
}

The following construction is particularly interesting (although in C, it would not normally make
sense or would produce an endless loop):
init/main.c
ticks = jiffies;
while (ticks == jiffies)
/* nothing */;
However, the loop does terminate at some point because the value ofjiffiesis incremented
by 1 in the interrupt handler routine at each tick of the system clock (which sleeps with the
frequencyHZ). As a result, the condition in thewhileloops produces an incorrect value after a
certain time, thus causing the loop to terminate.

❑ pidmap_initallocates the array in which the free positions of the PID allocator are saved. It also
reserves the (unused) PID 0 for all PID types.


❑ fork_initallocates thetask_structslab cache (providing there is no architecture-specific
mechanism to generate and cachetask_structinstances) and calculates the maximum number
of threads that can be generated.

Free download pdf