Fri Aug 24 14:04:27 2018 UTC ()
Use __predict_false to optimize, and also replace panic->printf.


(maxv)
diff -r1.224 -r1.225 src/sys/kern/subr_pool.c

cvs diff -r1.224 -r1.225 src/sys/kern/subr_pool.c (expand / switch to unified diff)

--- src/sys/kern/subr_pool.c 2018/08/23 12:18:02 1.224
+++ src/sys/kern/subr_pool.c 2018/08/24 14:04:27 1.225
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: subr_pool.c,v 1.224 2018/08/23 12:18:02 maxv Exp $ */ 1/* $NetBSD: subr_pool.c,v 1.225 2018/08/24 14:04:27 maxv Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1997, 1999, 2000, 2002, 2007, 2008, 2010, 2014, 2015 4 * Copyright (c) 1997, 1999, 2000, 2002, 2007, 2008, 2010, 2014, 2015
5 * The NetBSD Foundation, Inc. 5 * The NetBSD Foundation, Inc.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * This code is derived from software contributed to The NetBSD Foundation 8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Paul Kranenburg; by Jason R. Thorpe of the Numerical Aerospace 9 * by Paul Kranenburg; by Jason R. Thorpe of the Numerical Aerospace
10 * Simulation Facility, NASA Ames Research Center; by Andrew Doran, and by 10 * Simulation Facility, NASA Ames Research Center; by Andrew Doran, and by
11 * Maxime Villard. 11 * Maxime Villard.
12 * 12 *
13 * Redistribution and use in source and binary forms, with or without 13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions 14 * modification, are permitted provided that the following conditions
@@ -23,27 +23,27 @@ @@ -23,27 +23,27 @@
23 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 23 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 24 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 25 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
26 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE. 32 * POSSIBILITY OF SUCH DAMAGE.
33 */ 33 */
34 34
35#include <sys/cdefs.h> 35#include <sys/cdefs.h>
36__KERNEL_RCSID(0, "$NetBSD: subr_pool.c,v 1.224 2018/08/23 12:18:02 maxv Exp $"); 36__KERNEL_RCSID(0, "$NetBSD: subr_pool.c,v 1.225 2018/08/24 14:04:27 maxv Exp $");
37 37
38#ifdef _KERNEL_OPT 38#ifdef _KERNEL_OPT
39#include "opt_ddb.h" 39#include "opt_ddb.h"
40#include "opt_lockdebug.h" 40#include "opt_lockdebug.h"
41#endif 41#endif
42 42
43#include <sys/param.h> 43#include <sys/param.h>
44#include <sys/systm.h> 44#include <sys/systm.h>
45#include <sys/sysctl.h> 45#include <sys/sysctl.h>
46#include <sys/bitops.h> 46#include <sys/bitops.h>
47#include <sys/proc.h> 47#include <sys/proc.h>
48#include <sys/errno.h> 48#include <sys/errno.h>
49#include <sys/kernel.h> 49#include <sys/kernel.h>
@@ -2820,36 +2820,36 @@ pool_redzone_check(struct pool *pp, void @@ -2820,36 +2820,36 @@ pool_redzone_check(struct pool *pp, void
2820 if (!pp->pr_redzone) 2820 if (!pp->pr_redzone)
2821 return; 2821 return;
2822#ifdef KASAN 2822#ifdef KASAN
2823 kasan_free(p, pp->pr_reqsize + POOL_REDZONE_SIZE); 2823 kasan_free(p, pp->pr_reqsize + POOL_REDZONE_SIZE);
2824#else 2824#else
2825 uint8_t *cp, pat, expected; 2825 uint8_t *cp, pat, expected;
2826 const uint8_t *ep; 2826 const uint8_t *ep;
2827 2827
2828 cp = (uint8_t *)p + pp->pr_reqsize; 2828 cp = (uint8_t *)p + pp->pr_reqsize;
2829 ep = cp + POOL_REDZONE_SIZE; 2829 ep = cp + POOL_REDZONE_SIZE;
2830 2830
2831 pat = pool_pattern_generate(cp); 2831 pat = pool_pattern_generate(cp);
2832 expected = (pat == '\0') ? STATIC_BYTE: pat; 2832 expected = (pat == '\0') ? STATIC_BYTE: pat;
2833 if (expected != *cp) { 2833 if (__predict_false(expected != *cp)) {
2834 panic("%s: %p: 0x%02x != 0x%02x\n", 2834 printf("%s: %p: 0x%02x != 0x%02x\n",
2835 __func__, cp, *cp, expected); 2835 __func__, cp, *cp, expected);
2836 } 2836 }
2837 cp++; 2837 cp++;
2838 2838
2839 while (cp < ep) { 2839 while (cp < ep) {
2840 expected = pool_pattern_generate(cp); 2840 expected = pool_pattern_generate(cp);
2841 if (*cp != expected) { 2841 if (__predict_false(*cp != expected)) {
2842 panic("%s: %p: 0x%02x != 0x%02x\n", 2842 printf("%s: %p: 0x%02x != 0x%02x\n",
2843 __func__, cp, *cp, expected); 2843 __func__, cp, *cp, expected);
2844 } 2844 }
2845 cp++; 2845 cp++;
2846 } 2846 }
2847#endif 2847#endif
2848} 2848}
2849 2849
2850#endif /* POOL_REDZONE */ 2850#endif /* POOL_REDZONE */
2851 2851
2852 2852
2853#ifdef POOL_SUBPAGE 2853#ifdef POOL_SUBPAGE
2854/* Sub-page allocator, for machines with large hardware pages. */ 2854/* Sub-page allocator, for machines with large hardware pages. */
2855void * 2855void *