svn commit: r237855 - in head/sys/amd64: amd64 include
Alan Cox
alc at FreeBSD.org
Sat Jun 30 20:25:13 UTC 2012
Author: alc
Date: Sat Jun 30 20:25:12 2012
New Revision: 237855
URL: http://svn.freebsd.org/changeset/base/237855
Log:
Optimize reserve_pv_entries() using the popcnt instruction.
Modified:
head/sys/amd64/amd64/pmap.c
head/sys/amd64/include/cpufunc.h
Modified: head/sys/amd64/amd64/pmap.c
==============================================================================
--- head/sys/amd64/amd64/pmap.c Sat Jun 30 20:23:59 2012 (r237854)
+++ head/sys/amd64/amd64/pmap.c Sat Jun 30 20:25:12 2012 (r237855)
@@ -2408,9 +2408,15 @@ reserve_pv_entries(pmap_t pmap, int need
retry:
avail = 0;
TAILQ_FOREACH(pc, &pmap->pm_pvchunk, pc_list) {
- free = popcnt_pc_map_elem(pc->pc_map[0]);
- free += popcnt_pc_map_elem(pc->pc_map[1]);
- free += popcnt_pc_map_elem(pc->pc_map[2]);
+ if ((cpu_feature2 & CPUID2_POPCNT) == 0) {
+ free = popcnt_pc_map_elem(pc->pc_map[0]);
+ free += popcnt_pc_map_elem(pc->pc_map[1]);
+ free += popcnt_pc_map_elem(pc->pc_map[2]);
+ } else {
+ free = popcntq(pc->pc_map[0]);
+ free += popcntq(pc->pc_map[1]);
+ free += popcntq(pc->pc_map[2]);
+ }
if (free == 0)
break;
avail += free;
Modified: head/sys/amd64/include/cpufunc.h
==============================================================================
--- head/sys/amd64/include/cpufunc.h Sat Jun 30 20:23:59 2012 (r237854)
+++ head/sys/amd64/include/cpufunc.h Sat Jun 30 20:25:12 2012 (r237855)
@@ -273,6 +273,15 @@ outw(u_int port, u_short data)
__asm __volatile("outw %0, %w1" : : "a" (data), "Nd" (port));
}
+static __inline u_long
+popcntq(u_long mask)
+{
+ u_long result;
+
+ __asm __volatile("popcntq %1,%0" : "=r" (result) : "rm" (mask));
+ return (result);
+}
+
static __inline void
mfence(void)
{
More information about the svn-src-all
mailing list