1
0
mirror of https://git.FreeBSD.org/src.git synced 2025-01-16 15:11:52 +00:00

Idle ticks optimization:

- Pass number of events to the statclock() and profclock() functions
   same as to hardclock() before to not call them many times in a loop.
 - Rename them into statclock_cnt() and profclock_cnt().
 - Turn statclock() and profclock() into compatibility wrappers,
   still needed for arm.
 - Rename hardclock_anycpu() into hardclock_cnt() for unification.

MFC after:	1 week
This commit is contained in:
Alexander Motin 2012-03-10 14:57:21 +00:00
parent 0a53cd5742
commit bcfd016cff
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=232783
3 changed files with 46 additions and 23 deletions

View File

@ -483,7 +483,7 @@ hardclock(int usermode, uintfptr_t pc)
} }
void void
hardclock_anycpu(int cnt, int usermode) hardclock_cnt(int cnt, int usermode)
{ {
struct pstats *pstats; struct pstats *pstats;
struct thread *td = curthread; struct thread *td = curthread;
@ -687,6 +687,13 @@ stopprofclock(p)
*/ */
void void
statclock(int usermode) statclock(int usermode)
{
statclock_cnt(1, usermode);
}
void
statclock_cnt(int cnt, int usermode)
{ {
struct rusage *ru; struct rusage *ru;
struct vmspace *vm; struct vmspace *vm;
@ -703,11 +710,11 @@ statclock(int usermode)
/* /*
* Charge the time as appropriate. * Charge the time as appropriate.
*/ */
td->td_uticks++; td->td_uticks += cnt;
if (p->p_nice > NZERO) if (p->p_nice > NZERO)
cp_time[CP_NICE]++; cp_time[CP_NICE] += cnt;
else else
cp_time[CP_USER]++; cp_time[CP_USER] += cnt;
} else { } else {
/* /*
* Came from kernel mode, so we were: * Came from kernel mode, so we were:
@ -723,15 +730,15 @@ statclock(int usermode)
*/ */
if ((td->td_pflags & TDP_ITHREAD) || if ((td->td_pflags & TDP_ITHREAD) ||
td->td_intr_nesting_level >= 2) { td->td_intr_nesting_level >= 2) {
td->td_iticks++; td->td_iticks += cnt;
cp_time[CP_INTR]++; cp_time[CP_INTR] += cnt;
} else { } else {
td->td_pticks++; td->td_pticks += cnt;
td->td_sticks++; td->td_sticks += cnt;
if (!TD_IS_IDLETHREAD(td)) if (!TD_IS_IDLETHREAD(td))
cp_time[CP_SYS]++; cp_time[CP_SYS] += cnt;
else else
cp_time[CP_IDLE]++; cp_time[CP_IDLE] += cnt;
} }
} }
@ -739,21 +746,29 @@ statclock(int usermode)
MPASS(p->p_vmspace != NULL); MPASS(p->p_vmspace != NULL);
vm = p->p_vmspace; vm = p->p_vmspace;
ru = &td->td_ru; ru = &td->td_ru;
ru->ru_ixrss += pgtok(vm->vm_tsize); ru->ru_ixrss += pgtok(vm->vm_tsize) * cnt;
ru->ru_idrss += pgtok(vm->vm_dsize); ru->ru_idrss += pgtok(vm->vm_dsize) * cnt;
ru->ru_isrss += pgtok(vm->vm_ssize); ru->ru_isrss += pgtok(vm->vm_ssize) * cnt;
rss = pgtok(vmspace_resident_count(vm)); rss = pgtok(vmspace_resident_count(vm));
if (ru->ru_maxrss < rss) if (ru->ru_maxrss < rss)
ru->ru_maxrss = rss; ru->ru_maxrss = rss;
KTR_POINT2(KTR_SCHED, "thread", sched_tdname(td), "statclock", KTR_POINT2(KTR_SCHED, "thread", sched_tdname(td), "statclock",
"prio:%d", td->td_priority, "stathz:%d", (stathz)?stathz:hz); "prio:%d", td->td_priority, "stathz:%d", (stathz)?stathz:hz);
thread_lock_flags(td, MTX_QUIET); thread_lock_flags(td, MTX_QUIET);
sched_clock(td); for ( ; cnt > 0; cnt--)
sched_clock(td);
thread_unlock(td); thread_unlock(td);
} }
void void
profclock(int usermode, uintfptr_t pc) profclock(int usermode, uintfptr_t pc)
{
profclock_cnt(1, usermode, pc);
}
void
profclock_cnt(int cnt, int usermode, uintfptr_t pc)
{ {
struct thread *td; struct thread *td;
#ifdef GPROF #ifdef GPROF
@ -770,7 +785,7 @@ profclock(int usermode, uintfptr_t pc)
* bother trying to count it. * bother trying to count it.
*/ */
if (td->td_proc->p_flag & P_PROFIL) if (td->td_proc->p_flag & P_PROFIL)
addupc_intr(td, pc, 1); addupc_intr(td, pc, cnt);
} }
#ifdef GPROF #ifdef GPROF
else { else {
@ -781,7 +796,7 @@ profclock(int usermode, uintfptr_t pc)
if (g->state == GMON_PROF_ON && pc >= g->lowpc) { if (g->state == GMON_PROF_ON && pc >= g->lowpc) {
i = PC_TO_I(g, pc); i = PC_TO_I(g, pc);
if (i < g->textsize) { if (i < g->textsize) {
KCOUNT(g, i)++; KCOUNT(g, i) += cnt;
} }
} }
} }

View File

@ -195,28 +195,34 @@ handleevents(struct bintime *now, int fake)
pc = TRAPF_PC(frame); pc = TRAPF_PC(frame);
} }
runs = 0;
state = DPCPU_PTR(timerstate); state = DPCPU_PTR(timerstate);
runs = 0;
while (bintime_cmp(now, &state->nexthard, >=)) { while (bintime_cmp(now, &state->nexthard, >=)) {
bintime_add(&state->nexthard, &hardperiod); bintime_add(&state->nexthard, &hardperiod);
runs++; runs++;
} }
if (runs && fake < 2) { if (runs && fake < 2) {
hardclock_anycpu(runs, usermode); hardclock_cnt(runs, usermode);
done = 1; done = 1;
} }
runs = 0;
while (bintime_cmp(now, &state->nextstat, >=)) { while (bintime_cmp(now, &state->nextstat, >=)) {
if (fake < 2)
statclock(usermode);
bintime_add(&state->nextstat, &statperiod); bintime_add(&state->nextstat, &statperiod);
runs++;
}
if (runs && fake < 2) {
statclock_cnt(runs, usermode);
done = 1; done = 1;
} }
if (profiling) { if (profiling) {
runs = 0;
while (bintime_cmp(now, &state->nextprof, >=)) { while (bintime_cmp(now, &state->nextprof, >=)) {
if (!fake)
profclock(usermode, pc);
bintime_add(&state->nextprof, &profperiod); bintime_add(&state->nextprof, &profperiod);
runs++;
}
if (runs && !fake) {
profclock_cnt(runs, usermode, pc);
done = 1; done = 1;
} }
} else } else

View File

@ -247,12 +247,14 @@ void realitexpire(void *);
int sysbeep(int hertz, int period); int sysbeep(int hertz, int period);
void hardclock(int usermode, uintfptr_t pc); void hardclock(int usermode, uintfptr_t pc);
void hardclock_anycpu(int cnt, int usermode); void hardclock_cnt(int cnt, int usermode);
void hardclock_cpu(int usermode); void hardclock_cpu(int usermode);
void hardclock_sync(int cpu); void hardclock_sync(int cpu);
void softclock(void *); void softclock(void *);
void statclock(int usermode); void statclock(int usermode);
void statclock_cnt(int cnt, int usermode);
void profclock(int usermode, uintfptr_t pc); void profclock(int usermode, uintfptr_t pc);
void profclock_cnt(int cnt, int usermode, uintfptr_t pc);
int hardclockintr(void); int hardclockintr(void);