changeset 265:f9169495d476

order log calc
author tobaru
date Sun, 26 Jan 2020 18:20:40 +0900
parents 00224d119299
children 597c79dd5851
files src/buddy.c src/ln.h
diffstat 2 files changed, 11 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/buddy.c	Sun Jan 26 17:11:52 2020 +0900
+++ b/src/buddy.c	Sun Jan 26 18:20:40 2020 +0900
@@ -6,6 +6,7 @@
 #include "mmu.h"
 #include "spinlock.h"
 #include "arm.h"
+#include "ln.h"
 
 
 // this file implement the buddy memory allocator. Each order divides
@@ -246,6 +247,7 @@
 {
     uint8         *up;
 
+    ln(order);
     if ((order > MAX_ORD) || (order < MIN_ORD)) {
         panic("kmalloc: order out of range\n");
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ln.h	Sun Jan 26 18:20:40 2020 +0900
@@ -0,0 +1,9 @@
+static inline int ln(int sz) {
+    int j = 1 << 6;
+    for (int i = 6; i < 12; i++) {
+        if (sz < j) return i;
+        j <<= 1;
+    }
+    return 12;
+} 
+