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

View File

@ -247,12 +247,14 @@ void realitexpire(void *);
int sysbeep(int hertz, int period);
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_sync(int cpu);
void softclock(void *);
void statclock(int usermode);
void statclock_cnt(int cnt, int usermode);
void profclock(int usermode, uintfptr_t pc);
void profclock_cnt(int cnt, int usermode, uintfptr_t pc);
int hardclockintr(void);