]> mj.ucw.cz Git - libucw.git/commitdiff
CPU_PAGE_SIZE ported from mainline.
authorMartin Mares <mj@ucw.cz>
Fri, 12 Jan 2007 11:20:55 +0000 (12:20 +0100)
committerMartin Mares <mj@ucw.cz>
Fri, 12 Jan 2007 11:20:55 +0000 (12:20 +0100)
lib/autoconf.cfg
lib/fb-mmap.c
lib/lizard-safe.c
lib/lizard-test.c
lib/partmap.c
lib/qache.c

index 2cbb1efaf5fa1e88221b4652f75ed7b9757a988e..66c4056cd079c14799bf648ae2983641f569fd63 100644 (file)
@@ -1,5 +1,5 @@
 # Automatic configuration of the UCW Library
-# (c) 2005 Martin Mares <mj@ucw.cz>
+# (c) 2005--2007 Martin Mares <mj@ucw.cz>
 # (c) 2006 Robert Spalek <robert@ucw.cz>
 
 ### OS ###
@@ -221,10 +221,23 @@ if (IsSet("CONFIG_DARWIN")) {
        Append("LIBS" => "-L/sw/lib");
        Append("COPT" => "-I/sw/include");
        # Fill in some constants not found in the system header files
-       Set("PAGE_SIZE" => `sysctl -n hw.pagesize`);
-       Set("SOL_TCP" => 6);            #missing in /usr/include/netinet/tcp.h
+       Set("SOL_TCP" => 6);            # missing in /usr/include/netinet/tcp.h
 }
 
+# Determine page size
+Test("CPU_PAGE_SIZE", "Determining page size", sub {
+       my $p;
+       if (IsSet("CONFIG_DARWIN")) {
+               $p = `sysctl -n hw.pagesize`;
+               defined $p or Fail "sysctl hw.pagesize failed";
+       } elsif (IsSet("CONFIG_LINUX")) {
+               $p = `getconf PAGE_SIZE`;
+               defined $p or Fail "getconf PAGE_SIZE failed";
+       }
+       chomp $p;
+       return $p;
+});
+
 if (IsSet("CONFIG_LARGE_FILES") && IsSet("CONFIG_LINUX")) {
        # Use 64-bit versions of file functions
        Set("CONFIG_LFS");
index 67b7f910d94d4cc9284f37ef8a1ec7434b1dd0ba..85dc27ee2c10566e4d77d222acad39e87d495a4c 100644 (file)
 #include <fcntl.h>
 #include <unistd.h>
 #include <sys/mman.h>
-#include <sys/user.h>
 
-static uns mmap_window_size = 16*PAGE_SIZE;
-static uns mmap_extend_size = 4*PAGE_SIZE;
+static uns mmap_window_size = 16*CPU_PAGE_SIZE;
+static uns mmap_extend_size = 4*CPU_PAGE_SIZE;
 
 static struct cf_section fbmm_config = {
   CF_ITEMS {
@@ -49,10 +48,10 @@ static void
 bfmm_map_window(struct fastbuf *f)
 {
   struct fb_mmap *F = FB_MMAP(f);
-  sh_off_t pos0 = f->pos & ~(sh_off_t)(PAGE_SIZE-1);
+  sh_off_t pos0 = f->pos & ~(sh_off_t)(CPU_PAGE_SIZE-1);
   int l = MIN((sh_off_t)mmap_window_size, F->file_extend - pos0);
-  uns ll = ALIGN_TO(l, PAGE_SIZE);
-  uns oll = ALIGN_TO(f->bufend - f->buffer, PAGE_SIZE);
+  uns ll = ALIGN_TO(l, CPU_PAGE_SIZE);
+  uns oll = ALIGN_TO(f->bufend - f->buffer, CPU_PAGE_SIZE);
   int prot = ((F->mode & O_ACCMODE) == O_RDONLY) ? PROT_READ : (PROT_READ | PROT_WRITE);
 
   DBG(" ... Mapping %x(%x)+%x(%x) len=%x extend=%x", (int)pos0, (int)f->pos, ll, l, (int)F->file_size, (int)F->file_extend);
@@ -68,7 +67,7 @@ bfmm_map_window(struct fastbuf *f)
   if (f->buffer == (byte *) MAP_FAILED)
     die("mmap(%s): %m", f->name);
 #ifdef MADV_SEQUENTIAL
-  if (ll > PAGE_SIZE)
+  if (ll > CPU_PAGE_SIZE)
     madvise(f->buffer, ll, MADV_SEQUENTIAL);
 #endif
   f->bufend = f->buffer + l;
@@ -109,7 +108,7 @@ bfmm_spout(struct fastbuf *f)
   f->pos = end;
   if (f->pos >= F->file_extend)
     {
-      F->file_extend = ALIGN_TO(F->file_extend + mmap_extend_size, (sh_off_t)PAGE_SIZE);
+      F->file_extend = ALIGN_TO(F->file_extend + mmap_extend_size, (sh_off_t)CPU_PAGE_SIZE);
       if (sh_ftruncate(F->fd, F->file_extend))
        die("ftruncate(%s): %m", f->name);
     }
@@ -137,7 +136,7 @@ bfmm_close(struct fastbuf *f)
   struct fb_mmap *F = FB_MMAP(f);
 
   if (f->buffer)
-    munmap(f->buffer, ALIGN_TO(f->bufend-f->buffer, PAGE_SIZE));
+    munmap(f->buffer, ALIGN_TO(f->bufend-f->buffer, CPU_PAGE_SIZE));
   if (F->file_extend > F->file_size &&
       sh_ftruncate(F->fd, F->file_size))
     die("ftruncate(%s): %m", f->name);
index 7553b45944e04269a73b6dfbb1be0ea48853829b..0473e34ae7270215267adb6b59e342eb43140485 100644 (file)
@@ -12,7 +12,6 @@
 #include "lib/lizard.h"
 
 #include <sys/mman.h>
-#include <sys/user.h>
 #include <fcntl.h>
 #include <signal.h>
 #include <setjmp.h>
@@ -38,13 +37,13 @@ lizard_free(struct lizard_buffer *buf)
 {
   unhandle_signal(SIGSEGV);
   if (buf->ptr)
-    munmap(buf->ptr, buf->len + PAGE_SIZE);
+    munmap(buf->ptr, buf->len + CPU_PAGE_SIZE);
   xfree(buf);
 }
 
 static void
 lizard_realloc(struct lizard_buffer *buf, uns max_len)
-  /* max_len needs to be aligned to PAGE_SIZE */
+  /* max_len needs to be aligned to CPU_PAGE_SIZE */
 {
   if (max_len <= buf->len)
     return;
@@ -52,12 +51,12 @@ lizard_realloc(struct lizard_buffer *buf, uns max_len)
     max_len = 2*buf->len;
 
   if (buf->ptr)
-    munmap(buf->ptr, buf->len + PAGE_SIZE);
+    munmap(buf->ptr, buf->len + CPU_PAGE_SIZE);
   buf->len = max_len;
-  buf->ptr = mmap(NULL, buf->len + PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
+  buf->ptr = mmap(NULL, buf->len + CPU_PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
   if (buf->ptr == MAP_FAILED)
-    die("mmap(anonymous, %d bytes): %m", (uns)(buf->len + PAGE_SIZE));
-  if (mprotect(buf->ptr + buf->len, PAGE_SIZE, PROT_NONE) < 0)
+    die("mmap(anonymous, %d bytes): %m", (uns)(buf->len + CPU_PAGE_SIZE));
+  if (mprotect(buf->ptr + buf->len, CPU_PAGE_SIZE, PROT_NONE) < 0)
     die("mprotect: %m");
 }
 
@@ -77,7 +76,7 @@ lizard_decompress_safe(byte *in, struct lizard_buffer *buf, uns expected_length)
    * case of buffer-overflow.  The function is not re-entrant because of a
    * static longjmp handler.  */
 {
-  uns lock_offset = ALIGN_TO(expected_length + 3, PAGE_SIZE);  // +3 due to the unaligned access
+  uns lock_offset = ALIGN_TO(expected_length + 3, CPU_PAGE_SIZE);      // +3 due to the unaligned access
   if (lock_offset > buf->len)
     lizard_realloc(buf, lock_offset);
   volatile sh_sighandler_t old_handler = set_signal_handler(SIGSEGV, sigsegv_handler);
index 3973cfcd8d4197701b46a3bf026976505dc1f45f..dd9c62c4c4888a890d18ec79089f05214db513f4 100644 (file)
@@ -6,7 +6,6 @@
 #include <stdlib.h>
 #include <fcntl.h>
 #include <unistd.h>
-#include <sys/user.h>
 
 static char *options = CF_SHORT_OPTS "cdtx";
 static char *help = "\
@@ -105,8 +104,8 @@ main(int argc, char **argv)
   else
   {
     int smaller_li;
-    if (li >= (int) PAGE_SIZE)
-      smaller_li = li - PAGE_SIZE;
+    if (li >= (int) CPU_PAGE_SIZE)
+      smaller_li = li - CPU_PAGE_SIZE;
     else
       smaller_li = 0;
     struct lizard_buffer *buf = lizard_alloc();
index 8dba8f8fcffe6ec891978d919db7430acf934cbd..3b32bc9094ff04225c766d92e87b9c9730c478d9 100644 (file)
@@ -18,7 +18,6 @@
 #include <unistd.h>
 #include <sys/stat.h>
 #include <sys/mman.h>
-#include <sys/user.h>
 
 #ifdef CONFIG_PARTMAP_IS_MMAP
 #define PARTMAP_WINDOW ~(size_t)0
@@ -68,10 +67,10 @@ partmap_load(struct partmap *p, sh_off_t start, uns size)
   if (p->start_map)
     munmap(p->start_map, p->end_off - p->start_off);
   sh_off_t end = start + size;
-  sh_off_t win_start = start/PAGE_SIZE * PAGE_SIZE;
+  sh_off_t win_start = start/CPU_PAGE_SIZE * CPU_PAGE_SIZE;
   size_t win_len = PARTMAP_WINDOW;
   if ((sh_off_t) (win_start+win_len) > p->file_size)
-    win_len = ALIGN_TO(p->file_size - win_start, PAGE_SIZE);
+    win_len = ALIGN_TO(p->file_size - win_start, CPU_PAGE_SIZE);
   if ((sh_off_t) (win_start+win_len) < end)
     die("partmap_map: Window is too small for mapping %d bytes", size);
   p->start_map = sh_mmap(NULL, win_len, p->writeable ? (PROT_READ | PROT_WRITE) : PROT_READ, MAP_SHARED, p->fd, win_start);
index 3c4be273ab1c1bd0b24d100cc4439781da75a61c..5a832bb76d19063fad33bc7c26a0a354b2b34ad9 100644 (file)
@@ -15,7 +15,6 @@
 #include <fcntl.h>
 #include <sys/stat.h>
 #include <sys/mman.h>
-#include <sys/user.h>
 
 /*
  *  The cache lives in a mmapped file of the following format:
@@ -81,9 +80,9 @@ qache_msync(struct qache *q UNUSED, uns start UNUSED, uns len UNUSED)
 {
 #ifndef CONFIG_LINUX
   /* We don't need msyncing on Linux, since the mappings are guaranteed to be coherent */
-  len += (start % PAGE_SIZE);
-  start -= start % PAGE_SIZE;
-  len = ALIGN_TO(len, PAGE_SIZE);
+  len += (start % CPU_PAGE_SIZE);
+  start -= start % CPU_PAGE_SIZE;
+  len = ALIGN_TO(len, CPU_PAGE_SIZE);
   if (msync(q->mmap_data + start, len, MS_ASYNC | MS_INVALIDATE) < 0)
     log(L_ERROR, "Cache %s: msync failed: %m", q->file_name);
 #endif