History

[PATCH] Optimize calc_load()

calc_load() is called by timer interrupt to update avenrun[]. It currently calls nr_active() at each timer tick (HZ per second), while the update of avenrun[] is done only once every 5 seconds. (LOAD_FREQ=5 Hz) nr_active() is quite expensive on SMP machines, since it has to sum up nr_running and nr_uninterruptible of all online CPUS, bringing foreign dirty cache lines. This patch is an optimization of calc_load() so that nr_active() is called only if we need it. The use of unlikely() is welcome since the condition is true only once every 5*HZ time.

Eric Dumazet committed 19 years ago

Commit cd7175e1 parent f9884431 file · +9 −5Browse files

Unified · Split

kernel/timer.c+9−5
@@ -1146,11 +1146,15 @@ static inline void calc_load(unsigned long ticks) · 1145 unmodified lines
11461146 unsigned long active_tasks; /* fixed-point */
11471147 static int count = LOAD_FREQ;
11481148
1149− active_tasks = count_active_tasks();
1150− for (count -= ticks; count < 0; count += LOAD_FREQ) {
1151− CALC_LOAD(avenrun[0], EXP_1, active_tasks);
1152− CALC_LOAD(avenrun[1], EXP_5, active_tasks);
1153− CALC_LOAD(avenrun[2], EXP_15, active_tasks);
1149+ count -= ticks;
1150+ if (unlikely(count < 0)) {
1151+ active_tasks = count_active_tasks();
1152+ do {
1153+ CALC_LOAD(avenrun[0], EXP_1, active_tasks);
1154+ CALC_LOAD(avenrun[1], EXP_5, active_tasks);
1155+ CALC_LOAD(avenrun[2], EXP_15, active_tasks);
1156+ count += LOAD_FREQ;
1157+ } while (count < 0);
11541158 }
11551159 }
11561160

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t