From owner-svn-src-all@FreeBSD.ORG Mon Apr 20 11:54:03 2015 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id D8DB0E7B; Mon, 20 Apr 2015 11:54:02 +0000 (UTC) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id D6D91697; Mon, 20 Apr 2015 11:54:01 +0000 (UTC) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.14.9/8.14.9) with ESMTP id t3KBrsOO001847 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Mon, 20 Apr 2015 14:53:54 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.9.2 kib.kiev.ua t3KBrsOO001847 Received: (from kostik@localhost) by tom.home (8.14.9/8.14.9/Submit) id t3KBrpjT001845; Mon, 20 Apr 2015 14:53:51 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Mon, 20 Apr 2015 14:53:51 +0300 From: Konstantin Belousov To: Jung-uk Kim Cc: Alan Cox , John Baldwin , Bruce Evans , src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r280279 - head/sys/sys Message-ID: <20150420115351.GD2390@kib.kiev.ua> References: <201503201027.t2KAR6Ze053047@svn.freebsd.org> <550DA656.5060004@FreeBSD.org> <20150322080015.O955@besplex.bde.org> <17035816.lxyzYKiOWV@ralph.baldwin.cx> <552BFEB2.8040407@rice.edu> <552C215D.8020107@FreeBSD.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <552C215D.8020107@FreeBSD.org> User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on tom.home X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 20 Apr 2015 11:54:03 -0000 On Mon, Apr 13, 2015 at 04:04:45PM -0400, Jung-uk Kim wrote: > Please try the attached patch. > > Jung-uk Kim > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v2 > > iQEcBAEBCAAGBQJVLCFZAAoJEHyflib82/FGOp0H/1+Jr+cKUn/MnV5O5SghPw9f > XzTM4+BV9BcWabLRjFe1LR065SfLDXqKLuU4h5lmVSlXQaxElAXxaMeyO3mrMzR4 > Sb1xr0rf+ZfUARJeEJWI65Wpn+gEH+7XxXAIAetYGMwwclBOBgbZIoDXITnCaUFa > /pi3zQIey8EzbvlzhQcffLDV8oF4f8HNEMoSxMRtOiZNNPu/8ECnyGeHZhOd++kh > pwZNsSbcCw3RXMheuErTpKPrJSEXgMNmWG3G00aP7L8IjcObgOqMUQt+8eT8Ge8B > tEv40kgm2G/OG2akONh4/6bX3hyodW3IHcb6AYhqZogiDIqd/eXD4jDup/kkVxU= > =1Ca9 > -----END PGP SIGNATURE----- > Index: sys/amd64/amd64/pmap.c > =================================================================== > --- sys/amd64/amd64/pmap.c (revision 281496) > +++ sys/amd64/amd64/pmap.c (working copy) > @@ -412,7 +412,7 @@ static caddr_t crashdumpmap; > static void free_pv_chunk(struct pv_chunk *pc); > static void free_pv_entry(pmap_t pmap, pv_entry_t pv); > static pv_entry_t get_pv_entry(pmap_t pmap, struct rwlock **lockp); > -static int popcnt_pc_map_elem_pq(uint64_t elem); > +static int popcnt_pc_map(uint64_t *pc_map); > static vm_page_t reclaim_pv_chunk(pmap_t locked_pmap, struct rwlock **lockp); > static void reserve_pv_entries(pmap_t pmap, int needed, > struct rwlock **lockp); > @@ -2979,7 +2979,7 @@ retry: > } > > /* > - * Returns the number of one bits within the given PV chunk map element. > + * Returns the number of one bits within the given PV chunk map. > * > * The erratas for Intel processors state that "POPCNT Instruction May > * Take Longer to Execute Than Expected". It is believed that the > @@ -2994,12 +2994,21 @@ retry: > * 5th Gen Core: BDM85 > */ > static int > -popcnt_pc_map_elem_pq(uint64_t elem) > +popcnt_pc_map(uint64_t *pc_map) > { > - u_long result; > + u_long count, result; > + int field; > > - __asm __volatile("xorl %k0,%k0;popcntq %1,%0" > - : "=&r" (result) : "rm" (elem)); > + result = 0; > + if ((cpu_feature2 & CPUID2_POPCNT) != 0) > + for (field = 0; field < _NPCM; field++) { > + __asm __volatile("xorl %k0, %k0; popcntq %1, %0" > + : "=r" (count) : "m" (pc_map[field])); > + result += count; > + } > + else > + for (field = 0; field < _NPCM; field++) > + result += bitcount64(pc_map[field]); > return (result); > } > > @@ -3031,15 +3040,7 @@ reserve_pv_entries(pmap_t pmap, int needed, struct > retry: > avail = 0; > TAILQ_FOREACH(pc, &pmap->pm_pvchunk, pc_list) { > - if ((cpu_feature2 & CPUID2_POPCNT) == 0) { > - free = bitcount64(pc->pc_map[0]); > - free += bitcount64(pc->pc_map[1]); > - free += bitcount64(pc->pc_map[2]); > - } else { > - free = popcnt_pc_map_elem_pq(pc->pc_map[0]); > - free += popcnt_pc_map_elem_pq(pc->pc_map[1]); > - free += popcnt_pc_map_elem_pq(pc->pc_map[2]); > - } > + free = popcnt_pc_map(pc->pc_map); > if (free == 0) > break; > avail += free; Yes, this worked for me the same way as for you, the argument is taken directly from memory, without temporary spill. Is this due to silly inliner ? Whatever the reason is, I think a comment should be added noting the subtlety. Otherwise, looks fine.