Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 19 Mar 2012 07:15:42 +0000 (UTC)
From:      Alexander Motin <mav@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org
Subject:   svn commit: r233163 - in stable/9/sys: kern sys
Message-ID:  <201203190715.q2J7Fgun056439@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mav
Date: Mon Mar 19 07:15:42 2012
New Revision: 233163
URL: http://svn.freebsd.org/changeset/base/233163

Log:
  MFC r232783:
  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.

Modified:
  stable/9/sys/kern/kern_clock.c
  stable/9/sys/kern/kern_clocksource.c
  stable/9/sys/sys/systm.h
Directory Properties:
  stable/9/sys/   (props changed)

Modified: stable/9/sys/kern/kern_clock.c
==============================================================================
--- stable/9/sys/kern/kern_clock.c	Mon Mar 19 07:13:30 2012	(r233162)
+++ stable/9/sys/kern/kern_clock.c	Mon Mar 19 07:15:42 2012	(r233163)
@@ -482,7 +482,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;
 	struct thread *td;
@@ -702,11 +709,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:
@@ -722,15 +729,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;
 		}
 	}
 
@@ -738,22 +745,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;
@@ -769,7 +784,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 {
@@ -780,7 +795,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: stable/9/sys/kern/kern_clocksource.c
==============================================================================
--- stable/9/sys/kern/kern_clocksource.c	Mon Mar 19 07:13:30 2012	(r233162)
+++ stable/9/sys/kern/kern_clocksource.c	Mon Mar 19 07:15:42 2012	(r233163)
@@ -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: stable/9/sys/sys/systm.h
==============================================================================
--- stable/9/sys/sys/systm.h	Mon Mar 19 07:13:30 2012	(r233162)
+++ stable/9/sys/sys/systm.h	Mon Mar 19 07:15:42 2012	(r233163)
@@ -238,12 +238,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?201203190715.q2J7Fgun056439>