mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-02-16 17:01:53 +00:00
[util] Ensure hunk allocs are cache alligned
This doesn't seem to make much difference in the vulkan renderer, but it certainly doesn't hurt.
This commit is contained in:
parent
bc7858bb87
commit
0bfb60775e
15 changed files with 32 additions and 19 deletions
|
@ -122,7 +122,8 @@ void Sys_Init_Cvars (void);
|
|||
// memory protection
|
||||
//
|
||||
void Sys_MakeCodeWriteable (uintptr_t startaddr, size_t length);
|
||||
void Sys_PageIn (void *ptr, int size);
|
||||
void Sys_PageIn (void *ptr, size_t size);
|
||||
void *Sys_Alloc (size_t size);
|
||||
|
||||
//
|
||||
// system IO
|
||||
|
|
|
@ -68,7 +68,7 @@ init (void)
|
|||
COM_ParseConfig ();
|
||||
Cvar_Get ("cmd_warncmd", "1", CVAR_NONE, NULL, NULL);
|
||||
|
||||
Memory_Init (malloc (MEMSIZE), MEMSIZE);
|
||||
Memory_Init (Sys_Alloc (MEMSIZE), MEMSIZE);
|
||||
|
||||
QFS_Init ("qw");
|
||||
PI_Init ();
|
||||
|
|
|
@ -612,11 +612,11 @@ Sys_TimeID (void) //FIXME I need a new name, one that doesn't make me feel 3 fee
|
|||
}
|
||||
|
||||
VISIBLE void
|
||||
Sys_PageIn (void *ptr, int size)
|
||||
Sys_PageIn (void *ptr, size_t size)
|
||||
{
|
||||
//may or may not be useful in linux #ifdef _WIN32
|
||||
byte *x;
|
||||
int m, n;
|
||||
size_t m, n;
|
||||
|
||||
// touch all the memory to make sure it's there. The 16-page skip is to
|
||||
// keep Win 95 from thinking we're trying to page ourselves in (we are
|
||||
|
@ -632,6 +632,16 @@ Sys_PageIn (void *ptr, int size)
|
|||
//#endif
|
||||
}
|
||||
|
||||
VISIBLE void *
|
||||
Sys_Alloc (size_t size)
|
||||
{
|
||||
size_t page_size = sysconf (_SC_PAGESIZE);
|
||||
size_t page_mask = page_size - 1;
|
||||
size = (size + page_mask) & ~page_mask;
|
||||
return mmap (0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS,
|
||||
-1, 0);
|
||||
}
|
||||
|
||||
VISIBLE void
|
||||
Sys_DebugLog (const char *file, const char *fmt, ...)
|
||||
{
|
||||
|
|
|
@ -56,6 +56,7 @@ static qboolean Cache_FreeLRU (void);
|
|||
#define HUNK_SENTINAL 0x1df001ed
|
||||
|
||||
#define MINFRAGMENT 64
|
||||
#define HUNK_ALIGN 64
|
||||
|
||||
/*
|
||||
ZONE MEMORY ALLOCATION
|
||||
|
@ -413,6 +414,7 @@ typedef struct {
|
|||
int sentinal;
|
||||
int size; // including sizeof(hunk_t), -1 = not allocated
|
||||
char name[8];
|
||||
char fill[48]; // pad out to 64 bytes
|
||||
} hunk_t;
|
||||
|
||||
byte *hunk_base;
|
||||
|
@ -551,7 +553,7 @@ Hunk_AllocName (int size, const char *name)
|
|||
if (size < 0)
|
||||
Sys_Error ("Hunk_Alloc: bad size: %i", size);
|
||||
|
||||
size = sizeof (hunk_t) + ((size + 15) & ~15);
|
||||
size = sizeof (hunk_t) + ((size + HUNK_ALIGN - 1) & ~(HUNK_ALIGN - 1));
|
||||
|
||||
if (hunk_size - hunk_low_used - hunk_high_used < size) {
|
||||
Hunk_HighMark();
|
||||
|
@ -618,7 +620,7 @@ Hunk_HighAlloc (int size)
|
|||
Hunk_Check ();
|
||||
#endif
|
||||
|
||||
size = ((size + 15) & ~15);
|
||||
size = ((size + HUNK_ALIGN - 1) & ~(HUNK_ALIGN - 1));
|
||||
|
||||
if (hunk_size - hunk_low_used - hunk_high_used < size) {
|
||||
Sys_Printf ("Hunk_HighAlloc: failed on %i bytes\n", size);
|
||||
|
@ -640,7 +642,7 @@ Hunk_TempAlloc (int size)
|
|||
{
|
||||
void *buf;
|
||||
|
||||
size = (size + 15) & ~15;
|
||||
size = (size + HUNK_ALIGN - 1) & ~(HUNK_ALIGN - 1);
|
||||
|
||||
if (hunk_tempactive) {
|
||||
if (hunk_high_used - hunk_tempmark >= size + (int) sizeof (hunk_t)) {
|
||||
|
@ -1009,7 +1011,7 @@ Cache_Alloc (cache_user_t *c, int size, const char *name)
|
|||
if (size <= 0)
|
||||
Sys_Error ("Cache_Alloc: size %i", size);
|
||||
|
||||
size = (size + sizeof (cache_system_t) + 15) & ~15;
|
||||
size = (size + sizeof (cache_system_t) + HUNK_ALIGN - 1) & ~(HUNK_ALIGN-1);
|
||||
|
||||
// find memory for it
|
||||
while (1) {
|
||||
|
|
|
@ -859,7 +859,7 @@ Host_Init_Memory (void)
|
|||
Sys_Error ("Only %4.1f megs of memory reported, can't execute game",
|
||||
mem_size / (float) 0x100000);
|
||||
|
||||
mem_base = malloc (mem_size);
|
||||
mem_base = Sys_Alloc (mem_size);
|
||||
|
||||
if (!mem_base)
|
||||
Sys_Error ("Can't allocate %d", mem_size);
|
||||
|
|
|
@ -214,7 +214,7 @@ qtv_memory_init (void)
|
|||
|
||||
Cvar_SetFlags (qtv_mem_size, qtv_mem_size->flags | CVAR_ROM);
|
||||
mem_size = (int) (qtv_mem_size->value * 1024 * 1024);
|
||||
mem_base = malloc (mem_size);
|
||||
mem_base = Sys_Alloc (mem_size);
|
||||
if (!mem_base)
|
||||
Sys_Error ("Can't allocate %d", mem_size);
|
||||
Memory_Init (mem_base, mem_size);
|
||||
|
|
|
@ -1756,7 +1756,7 @@ CL_Init_Memory (void)
|
|||
Sys_Error ("Only %4.1f megs of memory reported, can't execute game",
|
||||
mem_size / (float) 0x100000);
|
||||
|
||||
mem_base = malloc (mem_size);
|
||||
mem_base = Sys_Alloc (mem_size);
|
||||
|
||||
if (!mem_base)
|
||||
Sys_Error ("Can't allocate %d", mem_size);
|
||||
|
|
|
@ -774,7 +774,7 @@ Demo_Init (void)
|
|||
if (p < com_argc - 1)
|
||||
size = atoi (com_argv[p + 1]) * 1024;
|
||||
else
|
||||
Sys_Error ("Memory_Init: you must specify a size in KB after "
|
||||
Sys_Error ("Demo_Init: you must specify a size in KB after "
|
||||
"-democache");
|
||||
}
|
||||
|
||||
|
|
|
@ -2470,7 +2470,7 @@ SV_Init_Memory (void)
|
|||
Sys_Error ("Only %4.1f megs of memory reported, can't execute game",
|
||||
mem_size / (float) 0x100000);
|
||||
|
||||
mem_base = malloc (mem_size);
|
||||
mem_base = Sys_Alloc (mem_size);
|
||||
|
||||
if (!mem_base)
|
||||
Sys_Error ("Can't allocate %d", mem_size);
|
||||
|
|
|
@ -136,7 +136,7 @@ init_qf (void)
|
|||
|
||||
//Cvar_Set (developer, "1");
|
||||
|
||||
Memory_Init (malloc (8 * 1024 * 1024), 8 * 1024 * 1024);
|
||||
Memory_Init (Sys_Alloc (8 * 1024 * 1024), 8 * 1024 * 1024);
|
||||
|
||||
Cvar_Get ("pr_debug", "2", 0, 0, 0);
|
||||
Cvar_Get ("pr_boundscheck", "0", 0, 0, 0);
|
||||
|
|
|
@ -114,7 +114,7 @@ init_qf (void)
|
|||
|
||||
//Cvar_Set (developer, "1");
|
||||
|
||||
Memory_Init (malloc (8 * 1024 * 1024), 8 * 1024 * 1024);
|
||||
Memory_Init (Sys_Alloc (8 * 1024 * 1024), 8 * 1024 * 1024);
|
||||
|
||||
Cvar_Get ("pr_debug", "2", 0, 0, 0);
|
||||
Cvar_Get ("pr_boundscheck", "0", 0, 0, 0);
|
||||
|
|
|
@ -925,7 +925,7 @@ write_pcx (image_t *image)
|
|||
|
||||
Sys_Init ();
|
||||
|
||||
Memory_Init (malloc (MEMSIZE), MEMSIZE);
|
||||
Memory_Init (Sys_Alloc (MEMSIZE), MEMSIZE);
|
||||
pcx = EncodePCX (image->image, image->width, image->height,
|
||||
image->width, palette, false, &pcx_len);
|
||||
if (Qwrite (outfile, pcx, pcx_len) != pcx_len) {
|
||||
|
|
|
@ -134,7 +134,7 @@ init_qf (void)
|
|||
Sys_Init ();
|
||||
Cvar_Get ("developer", va ("%d", options.developer), 0, 0, 0);
|
||||
|
||||
Memory_Init (malloc (1024 * 1024), 1024 * 1024);
|
||||
Memory_Init (Sys_Alloc (1024 * 1024), 1024 * 1024);
|
||||
|
||||
cvar_t *debug = Cvar_Get ("pr_debug", "2", 0, 0, 0);
|
||||
Cvar_Get ("pr_boundscheck", "2", 0, 0, 0);
|
||||
|
|
|
@ -334,7 +334,7 @@ main (int argc, char **argv)
|
|||
this_program = argv[0];
|
||||
|
||||
Sys_Init ();
|
||||
Memory_Init (malloc (MEMSIZE), MEMSIZE);
|
||||
Memory_Init (Sys_Alloc (MEMSIZE), MEMSIZE);
|
||||
|
||||
decode_args (argc, argv);
|
||||
|
||||
|
|
|
@ -396,7 +396,7 @@ main (int argc, char **argv)
|
|||
lumpinfo_t *pf;
|
||||
|
||||
Sys_Init ();
|
||||
Memory_Init (malloc (MEMSIZE), MEMSIZE);
|
||||
Memory_Init (Sys_Alloc (MEMSIZE), MEMSIZE);
|
||||
|
||||
this_program = argv[0];
|
||||
|
||||
|
|
Loading…
Reference in a new issue