Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 10 Mar 2012 14:57:22 +0000 (UTC)
From:      Alexander Motin <mav@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r232783 - in head/sys: kern sys
Message-ID:  <201203101457.q2AEvM81061023@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mav
Date: Sat Mar 10 14:57:21 2012
New Revision: 232783
URL: http://svn.freebsd.org/changeset/base/232783

Log:
  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

Modified:
  head/sys/kern/kern_clock.c
  head/sys/kern/kern_clocksource.c
  head/sys/sys/systm.h

Modified: head/sys/kern/kern_clock.c
==============================================================================
--- head/sys/kern/kern_clock.c	Sat Mar 10 14:38:49 2012	(r232782)
+++ head/sys/kern/kern_clock.c	Sat Mar 10 14:57:21 2012	(r232783)
@@ -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;
@@ -688,6 +688,13 @@ stopprofclock(p)
 void
 statclock(int usermode)
 {
+
+	statclock_cnt(1, usermode);
+}
+
+void
+statclock_cnt(int cnt, int usermode)
+{
 	struct rusage *ru;
 	struct vmspace *vm;
 	struct thread *td;
@@ -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,22 +746,30 @@ 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
 	struct gmonparam *g;
@@ -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;
 			}
 		}
 	}

Modified: head/sys/kern/kern_clocksource.c
==============================================================================
--- head/sys/kern/kern_clocksource.c	Sat Mar 10 14:38:49 2012	(r232782)
+++ head/sys/kern/kern_clocksource.c	Sat Mar 10 14:57:21 2012	(r232783)
@@ -195,28 +195,34 @@ handleevents(struct bintime *now, int fa
 		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

Modified: head/sys/sys/systm.h
==============================================================================
--- head/sys/sys/systm.h	Sat Mar 10 14:38:49 2012	(r232782)
+++ head/sys/sys/systm.h	Sat Mar 10 14:57:21 2012	(r232783)
@@ -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);
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201203101457.q2AEvM81061023>