Plan 9 from Bell Labs’s /usr/web/sources/extra/9hist/pc/bbmalloc.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


## diffname pc/bbmalloc.c 1991/0730
## diff -e /dev/null /n/bootesdump/1991/0730/sys/src/9/safari/bbmalloc.c
0a
#include	"u.h"
#include	"lib.h"
#include	"mem.h"
#include	"dat.h"
#include	"fns.h"
#include	"io.h"

/*
 * Allocate memory for use in kernel bitblts.
 * The allocated memory must have a flushed instruction
 * cache, and the data cache must be flushed by bbdflush().
 * To avoid the need for frequent cache flushes, the memory
 * is allocated out of an arena, and the i-cache is only
 * flushed when it has to be reused.  By returning an
 * address in non-cached space, the need for flushing the
 * d-cache is avoided.
 *
 * Currently, the only kernel users of bitblt are devbit,
 * print, and the cursor stuff in devbit.  The cursor
 * can get drawn at clock interrupt time, so it might need
 * to bbmalloc while another bitblt is going on.
 *
 * This code will have to be interlocked if we ever get
 * a multiprocessor with a bitmapped display.
 */

/* a 0->3 bitblt can take 900 words */
enum {
	nbbarena=8192	/* number of words in an arena */
};

static ulong	bbarena[nbbarena];
static ulong	*bbcur = bbarena;
static ulong	*bblast = 0;

void *
bbmalloc(int nbytes)
{
	int nw;
	int s;
	ulong *ans;

	nw = nbytes/sizeof(long);
	s = splhi();
	if(bbcur + nw > &bbarena[nbbarena])
		ans = bbarena;
	else
		ans = bbcur;
	bbcur = ans + nw;
	splx(s);
/*
	if(ans == bbarena)
		icflush(ans, sizeof(bbarena));
*/
	bblast = ans;
	ans = (void *)ans;
	return ans;
}

void
bbfree(void *p, int n)
{
	ulong *up;

	if(p == bblast)
		bbcur = (ulong *)(((char *)bblast) + n);
}

void *
bbdflush(void *p, int n)
{
	return p;
}
.
## diffname pc/bbmalloc.c 1991/0802
## diff -e /n/bootesdump/1991/0730/sys/src/9/safari/bbmalloc.c /n/bootesdump/1991/0802/sys/src/9/safari/bbmalloc.c
66a
	splx(s);
.
64a
	s = splhi();
.
63a
	int s;
.
17a
 * On the safari, all this is unnecessary, since the
 * only icache is a miniscule prefetch buffer.
 *
.
## diffname pc/bbmalloc.c 1991/0904
## diff -e /n/bootesdump/1991/0802/sys/src/9/safari/bbmalloc.c /n/bootesdump/1991/0904/sys/src/9/safari/bbmalloc.c
79a

.
75c
void*
.
72a
	print("sanity bbfree\n");
.
70,71c
	i = ((char*)va - bbarena) /n;
	if(i >= 0 && i < sizeof(bbused) && bbused[i]){
		bbused[i] = 0;
		splx(s);
		return;
	}
.
66,67c
	int s, i;
.
64c
bbfree(void *va, int n)
.
54,60c
	print("too many bbmallocs\n");
	return bbarena;
.
48,52c
	a = memchr(bbused, 0, sizeof(bbused));
	if(a) {
		i = a - bbused;
		a = bbarena + i*n;
		if(a+n <= bbarena+sizeof(bbarena)) {
			bbused[i] = 1;
			splx(s);
			return a;
		}
	}
.
46d
42,44c
	char *a;
	int s, i;
.
30,40c
void*
bbmalloc(int n)
.
8,28c
static	char	bbarena[10000];
static	char	bbused[10];
.
6d
## diffname pc/bbmalloc.c 1992/0117
## diff -e /n/bootesdump/1991/0904/sys/src/9/safari/bbmalloc.c /n/bootesdump/1992/0117/sys/src/9/safari/bbmalloc.c
53d
51c
	if(u)
		return 1;
	return 0;
.
48,49c
int
bbonstack(void)
.
## diffname pc/bbmalloc.c 1992/0321
## diff -e /n/bootesdump/1992/0117/sys/src/9/safari/bbmalloc.c /n/bootesdump/1992/0321/sys/src/9/safari/bbmalloc.c
2c
#include	"../port/lib.h"
.
## diffname pc/bbmalloc.c 1992/1113
## diff -e /n/bootesdump/1992/0808/sys/src/9/safari/bbmalloc.c /n/bootesdump/1992/1113/sys/src/9/pc/bbmalloc.c
51,52d
47a
void
bbdflush(void *p, int n)
{
	USED(p, n);
}

.
45d
38,43c
	a = INTENABLED(s) ? 0 : 1;
	if(p == bblast[a])
		bbcur[a] = (ulong *)(((char *)bblast[a]) + n);
.
35c
	int a, s;
.
33c
bbfree(void *p, int n)
.
28,29c
	bblast[a] = ans;
	return ans;
.
17,26c
	a = INTENABLED(s) ? 0 : 1;
	if(bbcur[a] + nw > &bbarena[a][nbbarena])
		ans = bbarena[a];
	else
		ans = bbcur[a];
	bbcur[a] = ans + nw;
.
15a
	nw = nbytes/sizeof(long);
.
13,14c
	int nw, a;
	int s;
	ulong *ans;
.
10,11c
/* a 0->3 bitblt can take 800 longs */
enum {
	narena=2,	/* put interrupt time stuff in separate arena */
	nbbarena=4096	/* number of words in an arena */
};

static ulong	bbarena[narena][nbbarena];
static ulong	*bbcur[narena] = {&bbarena[0][0], &bbarena[1][0]};
static ulong	*bblast[narena] = {0, 0};

#define INTENABLED(v)	((v)&(1<<9))
void *
bbmalloc(int nbytes)
.
7,8c
/*
 * Allocate memory for use in kernel bitblts.
 *
 * This code will have to be interlocked if we ever get
 * a multiprocessor with a bitmapped display.
 */
.
5a
#include	"io.h"
.
## diffname pc/bbmalloc.c 1993/0402
## diff -e /n/bootesdump/1992/1113/sys/src/9/pc/bbmalloc.c /n/bootesdump/1993/0402/sys/src/9/pc/bbmalloc.c
44a

void
bbinit(void)
{
	int i;

	if(bbarena[0])
		return;
	for(i = 0; i < narena; i++)
		bbarena[i] = xalloc(nbbarena);
}

.
21c
static ulong	*bbarena[narena];
.
## diffname pc/bbmalloc.c 1993/0409
## diff -e /n/bootesdump/1993/0402/sys/src/9/pc/bbmalloc.c /n/bootesdump/1993/0409/sys/src/9/pc/bbmalloc.c
53,54c
	for(i = 0; i < narena; i++){
		bbarena[i] = xalloc(nbbarena * sizeof(long));
		bbcur[i] = bbarena[i];
		bblast[i] = 0;
	}
.
42a
	splx(s);
.
41d
36c
	if(bbcur[a] + nw > bbarena[a] + nbbarena)
.
22,23c
static ulong	*bbcur[narena];
static ulong	*bblast[narena];
.
## diffname pc/bbmalloc.c 1993/1113
## diff -e /n/bootesdump/1993/0409/sys/src/9/pc/bbmalloc.c /n/fornaxdump/1993/1113/sys/src/brazil/pc/bbmalloc.c
82a
}

void
bbexec(void (*memstart)(void), int len, int onstack)
{
	memstart();
	if(onstack)
		return;
	bbfree(memstart, len);
.
81a
	/*if(u)
		return 1;*/
.
73,78d
69c
		bbcur[a] = (ulong *)(((char *)bblast[a]) + n + LINEWORDS*sizeof(long));
.
67c
	a = INTLEVEL(s)? 1 : 0;
.
47,61d
42a

	bblast[a] = ans;
.
40,41c
	bbcur[a] = ans + nw + (LINEWORDS);
.
35,36c
	a = INTLEVEL(s)? 1 : 0;
	if(bbcur[a] + nw > &bbarena[a][nbbarena])
.
25c
#define INTLEVEL(v)	(((v)&(1<<9)) == 0)
.
21,23c
static ulong	bbarena[narena][nbbarena+LINEWORDS];
static ulong	*bbcur[narena] = {&bbarena[0][0], &bbarena[1][0]};
static ulong	*bblast[narena] = {0, 0};
.
15c
/* a 0->3 bitblt can take 900 words */
.
9a
 * The allocated memory must have a flushed instruction
 * cache, and the data cache must be flushed by bbdflush().
 * To avoid the need for frequent cache flushes, the memory
 * is allocated out of an arena, and the i-cache is only
 * flushed when it has to be reused
.
7a
#define LINEWORDS	(0)

.
## diffname pc/bbmalloc.c 1994/0413 # deleted
## diff -e /n/fornaxdump/1993/1113/sys/src/brazil/pc/bbmalloc.c /n/fornaxdump/1994/0413/sys/src/brazil/pc/bbmalloc.c
1,81d

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.