Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/rasops Stop allocating ri_buf and ri_stamp dynamical...



details:   https://anonhg.NetBSD.org/src/rev/26d02b08d113
branches:  trunk
changeset: 964562:26d02b08d113
user:      rin <rin%NetBSD.org@localhost>
date:      Wed Aug 07 11:47:33 2019 +0000

description:
Stop allocating ri_buf and ri_stamp dynamically. As commented in
rasops.h, it is not safe to use kmem_alloc(9) in rasops_init();
rasops routines can be used for early putchar, which means that
UVM is not fully initialized.

Should fix a problem reported by macallan:
http://mail-index.netbsd.org/tech-kern/2019/08/02/msg025327.html

Instead of using ri_buf, inline function rasops_memcpy32() is
introduced to fill 32bit data efficiently.

Instead of using ri_stamp (per device stamp), stamp_ri is
introduced to distinguish for which device stamp is calculated.

diffstat:

 sys/dev/rasops/rasops.c               |   64 ++------------
 sys/dev/rasops/rasops.h               |   43 +++++++++-
 sys/dev/rasops/rasops15.c             |   23 ++++-
 sys/dev/rasops/rasops2.c              |   21 +++-
 sys/dev/rasops/rasops24.c             |  142 ++++++++++++++++++++-------------
 sys/dev/rasops/rasops32.c             |   19 +++-
 sys/dev/rasops/rasops4.c              |   19 +++-
 sys/dev/rasops/rasops8.c              |   19 +++-
 sys/dev/rasops/rasops_putchar_width.h |    5 +-
 9 files changed, 212 insertions(+), 143 deletions(-)

diffs (truncated from 804 to 300 lines):

diff -r 600aefaa255c -r 26d02b08d113 sys/dev/rasops/rasops.c
--- a/sys/dev/rasops/rasops.c   Wed Aug 07 11:13:20 2019 +0000
+++ b/sys/dev/rasops/rasops.c   Wed Aug 07 11:47:33 2019 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: rasops.c,v 1.114 2019/08/07 11:08:44 rin Exp $        */
+/*      $NetBSD: rasops.c,v 1.115 2019/08/07 11:47:33 rin Exp $        */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rasops.c,v 1.114 2019/08/07 11:08:44 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rasops.c,v 1.115 2019/08/07 11:47:33 rin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_rasops.h"
@@ -509,21 +509,6 @@
                    WSSCREEN_WSCOLORS | WSSCREEN_REVERSE;
        }
 
-       if (ri->ri_buf != NULL) {
-               kmem_free(ri->ri_buf, ri->ri_buflen);
-               ri->ri_buf = NULL;
-       }
-       len = (ri->ri_flg & RI_FULLCLEAR) ? ri->ri_stride : ri->ri_emustride;
-       ri->ri_buflen = len;
-       ri->ri_buf = kmem_alloc(len, KM_SLEEP);
-
-#ifndef RASOPS_SMALL
-       if (ri->ri_stamp != NULL) {
-               kmem_free(ri->ri_stamp, ri->ri_stamp_len);
-               ri->ri_stamp = NULL;
-       }
-#endif
-
        switch (ri->ri_depth) {
 #if NRASOPS1 > 0
        case 1:
@@ -1004,9 +989,8 @@
 rasops_eraserows(void *cookie, int row, int num, long attr)
 {
        struct rasops_info *ri = (struct rasops_info *)cookie;
-       uint32_t *buf = (uint32_t *)ri->ri_buf;
        uint32_t *rp, *hp, clr;
-       int stride, cnt;
+       int stride;
 
        hp = NULL;      /* XXX GCC */
 
@@ -1045,13 +1029,10 @@
                        hp = (uint32_t *)(ri->ri_hwbits + row * ri->ri_yscale);
        }
 
-       for (cnt = 0; cnt < stride >> 2; cnt++)
-               buf[cnt] = clr;
-
        while (num--) {
-               memcpy(rp, buf, stride);
+               rasops_memset32(rp, clr, stride);
                if (ri->ri_hwbits) {
-                       memcpy(hp, buf, stride);
+                       memcpy(hp, rp, stride);
                        DELTA(hp, ri->ri_stride, uint32_t *);
                }
                DELTA(rp, ri->ri_stride, uint32_t *);
@@ -1166,9 +1147,8 @@
 rasops_erasecols(void *cookie, int row, int col, int num, long attr)
 {
        struct rasops_info *ri = (struct rasops_info *)cookie;
-       uint32_t *buf = ri->ri_buf;
-       int height, cnt, clr;
-       uint32_t *dp, *rp, *hp;
+       int height, clr;
+       uint32_t *rp, *hp;
 
        hp = NULL;      /* XXX GCC */
 
@@ -1196,25 +1176,13 @@
        height = ri->ri_font->fontheight;
        clr = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf];
 
-       dp = buf;
-
-       /* Write 4 bytes per loop */
-       for (cnt = num >> 2; cnt; cnt--)
-               *dp++ = clr;
-
-       /* Write unaligned trailing slop */
-       for (cnt = num & 3; cnt; cnt--) {
-               *(uint8_t *)dp = clr;
-               DELTA(dp, 1, uint32_t *);
-       }
-
        while (height--) {
-               memcpy(rp, buf, num);
-               DELTA(rp, ri->ri_stride, uint32_t *);
+               rasops_memset32(rp, clr, num);
                if (ri->ri_hwbits) {
-                       memcpy(hp, buf, num);
+                       memcpy(hp, rp, num);
                        DELTA(hp, ri->ri_stride, uint32_t *);
                }
+               DELTA(rp, ri->ri_stride, uint32_t *);
        }
 }
 
@@ -1689,15 +1657,3 @@
                memcpy(palette, rasops_cmap, uimin(bytes, sizeof(rasops_cmap)));
        return 0;
 }
-
-#ifndef RASOPS_SMALL
-void
-rasops_allocstamp(struct rasops_info *ri, size_t len)
-{
-
-       KASSERT(ri->ri_stamp == NULL);
-       ri->ri_stamp_len = len;
-       ri->ri_stamp = kmem_zalloc(len, KM_SLEEP);
-       ri->ri_stamp_attr = 0;
-}
-#endif
diff -r 600aefaa255c -r 26d02b08d113 sys/dev/rasops/rasops.h
--- a/sys/dev/rasops/rasops.h   Wed Aug 07 11:13:20 2019 +0000
+++ b/sys/dev/rasops/rasops.h   Wed Aug 07 11:47:33 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rasops.h,v 1.43 2019/08/03 06:29:52 rin Exp $ */
+/*     $NetBSD: rasops.h,v 1.44 2019/08/07 11:47:33 rin Exp $ */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -191,14 +191,51 @@
 void   rasops24_init(struct rasops_info *);
 void   rasops32_init(struct rasops_info *);
 
-void   rasops_allocstamp(struct rasops_info *, size_t);
-
 #define        DELTA(p, d, cast) ((p) = (cast)((uint8_t *)(p) + (d)))
 
 #define        FONT_GLYPH(uc, font, ri)                                        \
        ((uint8_t *)(font)->data + ((uc) - ((font)->firstchar)) *       \
            (ri)->ri_fontscale)
 
+static __inline void
+rasops_memset32(void *p, uint32_t val, size_t bytes)
+{
+       int slop1, slop2, full;
+       uint8_t *dp = (uint8_t *)p;
+
+       if (bytes == 1) {
+               *dp = val;
+               return;
+       }
+
+       slop1 = (4 - ((uintptr_t)dp & 3)) & 3;
+       slop2 = (bytes - slop1) & 3;
+       full = (bytes - slop1 /* - slop2 */) >> 2;
+
+       if (slop1 & 1)
+               *dp++ = val;
+
+       if (slop1 & 2) {
+               *(uint16_t *)dp = val;
+               dp += 2;
+       }
+
+       for (; full; full--) {
+               *(uint32_t *)dp = val;
+               dp += 4;
+       }
+
+       if (slop2 & 2) {
+               *(uint16_t *)dp = val;
+               dp += 2;
+       }
+
+       if (slop2 & 1)
+               *dp = val;
+
+       return;
+}
+
 static __inline uint32_t
 be32uatoh(uint8_t *p)
 {
diff -r 600aefaa255c -r 26d02b08d113 sys/dev/rasops/rasops15.c
--- a/sys/dev/rasops/rasops15.c Wed Aug 07 11:13:20 2019 +0000
+++ b/sys/dev/rasops/rasops15.c Wed Aug 07 11:47:33 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rasops15.c,v 1.34 2019/08/02 04:40:53 rin Exp $        */
+/*     $NetBSD: rasops15.c,v 1.35 2019/08/07 11:47:33 rin Exp $        */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rasops15.c,v 1.34 2019/08/02 04:40:53 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rasops15.c,v 1.35 2019/08/07 11:47:33 rin Exp $");
 
 #include "opt_rasops.h"
 
@@ -55,6 +55,11 @@
 #endif
 
 #ifndef RASOPS_SMALL
+/* 4x1 stamp for optimized character blitting */
+static uint32_t                        stamp[32];
+static long                    stamp_attr;
+static struct rasops_info      *stamp_ri;
+
 /*
  * offset = STAMP_SHIFT(fontbits, nibble #) & STAMP_MASK
  * destination uint32_t[0] = STAMP_READ(offset)
@@ -104,12 +109,17 @@
        }
 
 #ifndef RASOPS_SMALL
-       rasops_allocstamp(ri, sizeof(uint32_t) * 32);
+       stamp_attr = 0;
+       stamp_ri = NULL;
 #endif
 }
 
+#undef RASOPS_AA
 #include "rasops_putchar.h"
-#include "rasops_putchar_aa.h"
+
+#define        RASOPS_AA
+#include "rasops_putchar.h"
+#undef RASOPS_AA
 
 #ifndef RASOPS_SMALL
 /*
@@ -118,13 +128,14 @@
 static void
 rasops15_makestamp(struct rasops_info *ri, long attr)
 {
-       uint32_t *stamp = (uint32_t *)ri->ri_stamp;
        uint32_t fg, bg;
        int i;
 
+       stamp_attr = attr;
+       stamp_ri = ri;
+
        fg = ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf] & 0xffff;
        bg = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf] & 0xffff;
-       ri->ri_stamp_attr = attr;
 
        for (i = 0; i < 32; i += 2) {
 #if BYTE_ORDER == LITTLE_ENDIAN
diff -r 600aefaa255c -r 26d02b08d113 sys/dev/rasops/rasops2.c
--- a/sys/dev/rasops/rasops2.c  Wed Aug 07 11:13:20 2019 +0000
+++ b/sys/dev/rasops/rasops2.c  Wed Aug 07 11:47:33 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rasops2.c,v 1.29 2019/08/02 04:39:09 rin Exp $ */
+/*     $NetBSD: rasops2.c,v 1.30 2019/08/07 11:47:33 rin Exp $ */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rasops2.c,v 1.29 2019/08/02 04:39:09 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rasops2.c,v 1.30 2019/08/07 11:47:33 rin Exp $");
 
 #include "opt_rasops.h"
 
@@ -58,6 +58,12 @@
 static void    rasops2_makestamp(struct rasops_info *, long);
 #endif
 
+#ifndef RASOPS_SMALL
+/* 4x1 stamp for optimized character blitting */
+static uint8_t                 stamp[16];
+static long                    stamp_attr;
+static struct rasops_info      *stamp_ri;
+
 /*
  * offset = STAMP_SHIFT(fontbits, nibble #) & STAMP_MASK
  * destination = STAMP_READ(offset)
@@ -65,6 +71,7 @@
 #define        STAMP_SHIFT(fb, n)      ((n) ? (fb) >> 4 : (fb))
 #define        STAMP_MASK              0xf
 #define        STAMP_READ(o)           stamp[o]
+#endif
 
 /*
  * Initialize rasops_info struct for this colordepth.
@@ -90,14 +97,15 @@
        case 16:
                ri->ri_ops.putchar = rasops2_putchar16;
                break;
-#endif /* !RASOPS_SMALL */
+#endif
        default:



Home | Main Index | Thread Index | Old Index