aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2001-10-13 20:54:20 +0000
committerH. Peter Anvin <hpa@zytor.com>2001-10-13 20:54:20 +0000
commita0c984c1b205b01cfe5849080b116022a0cdebe6 (patch)
treebcbc46ea738fc5c3174ac5c93ce015b5968755ab
parentd8eff73f38cec27e9090f040a457d51adf9e959b (diff)
downloadlpsm-a0c984c1b205b01cfe5849080b116022a0cdebe6.tar.gz
lpsm-a0c984c1b205b01cfe5849080b116022a0cdebe6.tar.xz
lpsm-a0c984c1b205b01cfe5849080b116022a0cdebe6.zip
Replace debugging printf()'s with DPRINTF()
-rw-r--r--alloc.c43
1 files changed, 24 insertions, 19 deletions
diff --git a/alloc.c b/alloc.c
index 81d0250..2baac0c 100644
--- a/alloc.c
+++ b/alloc.c
@@ -27,7 +27,13 @@
#include <stdlib.h>
#include <inttypes.h>
#include <limits.h>
+
+#ifndef NDEBUG
#include <stdio.h> /* For debugging printf() */
+#define DPRINTF(X) printf X
+#else
+#define DPRINTF(X)
+#endif
#include "objstore.h"
#include "internals.h"
@@ -312,14 +318,14 @@ static int objstore_find_free_chunk(int rorder)
xbit = objstore_find_free_chunk(rorder-1);
if ( !xbit )
return 0; /* All out of those, sir */
- printf("buddy: splitting rorder %2d %8d -> %d %d\n", rorder-1, xbit, xbit << 1, (xbit << 1)+1);
+ DPRINTF(("buddy: splitting rorder %2d %8d -> %d %d\n", rorder-1, xbit, xbit << 1, (xbit << 1)+1));
xbit <<= 1; /* Convert to address of fragments */
set_bit(ah->free_bitmap, xbit+1); /* Upper buddy is available */
/* Return the lower buddy */
} else {
clr_bit(ah->free_bitmap, xbit); /* No longer available */
}
- printf("buddy: allocated rorder %2d %8d\n", rorder, xbit);
+ DPRINTF(("buddy: allocated rorder %2d %8d\n", rorder, xbit));
return xbit;
}
@@ -343,7 +349,7 @@ static void *objstore_malloc_buddy(size_t size)
rorder = ah->arena_size_lg2 - order;
obit = 1 << rorder;
- printf("buddy: trying to allocate %d bytes, rorder = %d\n", size, rorder);
+ DPRINTF(("buddy: trying to allocate %d bytes, rorder = %d\n", size, rorder));
xbit = objstore_find_free_chunk(rorder);
if ( !xbit ) {
@@ -356,7 +362,7 @@ static void *objstore_malloc_buddy(size_t size)
p = (void *)((char *)ah->data_start + ((uintptr_t)(xbit-obit) << order));
- printf("buddy: allocated %u/%u bytes at %p\n", size, 1U << order, p);
+ DPRINTF(("buddy: allocated %u/%u bytes at %p\n", size, 1U << order, p));
return p;
}
@@ -372,7 +378,7 @@ static struct slab_header *objstore_make_new_slab(struct slab_info *si, int inde
if ( !sh )
return NULL;
- printf("slab: allocating new page for size %d at %p\n", si->size, sh);
+ DPRINTF(("slab: allocating new page for size %d at %p\n", si->size, sh));
sh->magic = SLAB_MAGIC;
sh->free_count = si->count;
@@ -415,9 +421,8 @@ static void *objstore_malloc_slab(size_t size)
}
/* Now si points to the slab_info header we want to allocate from */
-
- printf("slab: trying to allocate %d bytes, slab size %d bytes\n",
- size, si->size);
+ DPRINTF(("slab: trying to allocate %d bytes, slab size %d bytes\n",
+ size, si->size));
sh = si->list;
if ( !sh ) {
@@ -441,8 +446,8 @@ static void *objstore_malloc_slab(size_t size)
}
p = (void *)((char *)sh + si->data_offset + which*si->size);
- printf("slab: allocated %d/%d bytes at %p, %d/%d slabs in use\n",
- size, si->size, p, si->count-sh->free_count, si->count);
+ DPRINTF(("slab: allocated %d/%d bytes at %p, %d/%d slabs in use\n",
+ size, si->size, p, si->count-sh->free_count, si->count));
return p;
}
@@ -461,8 +466,8 @@ static void objstore_free_chunk(int xbit, int rorder)
if ( test_bit(ah->free_bitmap, bxbit) ) {
/* Buddy is free. */
clr_bit(ah->free_bitmap, bxbit);
- printf("buddy: coalescing rorder %2d %d %d -> %2d %d\n",
- rorder, xbit, bxbit, rorder-1, (xbit >> 1));
+ DPRINTF(("buddy: coalescing rorder %2d %d %d -> %2d %d\n",
+ rorder, xbit, bxbit, rorder-1, (xbit >> 1)));
objstore_free_chunk((xbit >> 1), rorder-1);
return;
}
@@ -476,7 +481,7 @@ static void objstore_free_buddy(void *ptr)
int order, rorder;
int xbit, obit;
- printf("buddy: freeing allocation at %p\n", ptr);
+ DPRINTF(("buddy: freeing allocation at %p\n", ptr));
assert(offset < (1UL << ah->arena_size_lg2)); /* Not inside the arena?? */
@@ -491,7 +496,7 @@ static void objstore_free_buddy(void *ptr)
if ( test_bit(ah->alloc_bitmap, xbit) ) {
/* We're this order... */
- printf("buddy: freeing rorder %2d %8d\n", rorder, xbit);
+ DPRINTF(("buddy: freeing rorder %2d %8d\n", rorder, xbit));
clr_bit(ah->alloc_bitmap, xbit);
objstore_free_chunk(xbit, rorder);
return;
@@ -515,8 +520,8 @@ static void objstore_free_slab(void *ptr)
slab_bitmap = (unsigned char *)sh +
((sizeof(struct slab_header)+MINIMUM_ALIGN-1) & ~MINIMUM_ALIGN_MASK);
- printf("slab: Freeing size %d slab at %p, %d/%d allocated\n",
- si->size, ptr, si->count-sh->free_count, si->count);
+ DPRINTF(("slab: Freeing size %d slab at %p, %d/%d allocated\n",
+ si->size, ptr, si->count-sh->free_count, si->count));
offset = ((uintptr_t)ptr & (BUDDY_SIZE_MIN-1)) - si->data_offset;
assert(offset >= 0);
@@ -527,7 +532,7 @@ static void objstore_free_slab(void *ptr)
if ( free_count == si->count-1 ) {
/* Deallocated the entire page; give back to buddy system */
- printf("slab: Returning page %p back to the buddy system\n", sh);
+ DPRINTF(("slab: Returning page %p back to the buddy system\n", sh));
*(sh->rev) = sh->next; /* Remove from free list */
objstore_free_buddy(sh);
} else {
@@ -535,8 +540,8 @@ static void objstore_free_slab(void *ptr)
sh->free_count = free_count+1;
if ( free_count == 0 ) {
/* Page with newly available slabs */
- printf("slab: Adding page %p back onto free list for slab size %d\n",
- sh, si->size);
+ DPRINTF(("slab: Adding page %p back onto free list for slab size %d\n",
+ sh, si->size));
sh->rev = &(si->list);
sh->next = si->list;
if ( si->list )