commit-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

hurd-l4 physmem/physmem.c physmem/zalloc.c wort...


From: Marcus Brinkmann
Subject: hurd-l4 physmem/physmem.c physmem/zalloc.c wort...
Date: Tue, 16 Sep 2003 22:50:38 -0400

CVSROOT:        /cvsroot/hurd
Module name:    hurd-l4
Branch:         
Changes by:     Marcus Brinkmann <address@hidden>       03/09/16 22:50:38

Modified files:
        physmem        : physmem.c zalloc.c 
        wortel         : wortel.c 

Log message:
        Use different UTCB for physmem (to where wortel is, so physmem can take 
all
        the physmem, probably do more safety checks here).
        
        Fix fpages creation algorithm to use self-aligned pages.  physmem's 
zalloc
        now almost works (still a bug somewhere).

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/hurd/hurd-l4/physmem/physmem.c.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/hurd/hurd-l4/physmem/zalloc.c.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/hurd/hurd-l4/wortel/wortel.c.diff?tr1=1.11&tr2=1.12&r1=text&r2=text

Patches:
Index: hurd-l4/physmem/physmem.c
diff -u hurd-l4/physmem/physmem.c:1.3 hurd-l4/physmem/physmem.c:1.4
--- hurd-l4/physmem/physmem.c:1.3       Tue Sep 16 21:16:53 2003
+++ hurd-l4/physmem/physmem.c   Tue Sep 16 22:50:37 2003
@@ -68,11 +68,7 @@
       fpage = grant_item.send_fpage;
 
       if (fpage.raw != l4_nilpage.raw)
-       {
-         debug ("%s: Got fpage 0x%x/%u\n", program_name,
-                l4_address (fpage), l4_size_log2 (fpage));
-         zfree (l4_address (fpage), l4_size (fpage));
-       }
+       zfree (l4_address (fpage), l4_size (fpage));
     }
   while (fpage.raw != l4_nilpage.raw);
 }
@@ -81,11 +77,13 @@
 int
 main (int argc, char *argv[])
 {
-  output_debug = 1;
+  output_debug = 0;
 
   debug ("%s " PACKAGE_VERSION "\n", program_name);
 
   get_all_memory ();
+
+  zalloc_dump_zones (program_name);
 
   while (1)
     l4_sleep (l4_never);
Index: hurd-l4/physmem/zalloc.c
diff -u hurd-l4/physmem/zalloc.c:1.1 hurd-l4/physmem/zalloc.c:1.2
--- hurd-l4/physmem/zalloc.c:1.1        Tue Sep 16 21:16:53 2003
+++ hurd-l4/physmem/zalloc.c    Tue Sep 16 22:50:37 2003
@@ -111,7 +111,7 @@
 /* Find the first bit set.  The least significant bit is 1.  If no bit
    is set, return 0.  FIXME: This can be optimized a lot, in an
    archtecture dependent way.  Add to libl4, like __l4_msb().  */
-inline unsigned int
+static inline unsigned int
 wffs (l4_word_t nr)
 {
   unsigned int bit = 0;
Index: hurd-l4/wortel/wortel.c
diff -u hurd-l4/wortel/wortel.c:1.11 hurd-l4/wortel/wortel.c:1.12
--- hurd-l4/wortel/wortel.c:1.11        Tue Sep 16 21:16:53 2003
+++ hurd-l4/wortel/wortel.c     Tue Sep 16 22:50:38 2003
@@ -114,16 +114,39 @@
 /* The maximum number of fpages required to cover a page aligned range
    of memory.  This is k if the maximum memory range size to cover is
    2^(k + min_page_size_log2), which can be easily proved by
-   induction.  The minimum page size in L4 is at least 2^10.  */
+   induction.  The minimum page size in L4 is at least 2^10.  We also
+   need to have each fpage aligned to a multiple of its own size.
+   This makes the proof by induction a bit more convoluted, but does
+   not change the result.  */
 #define MAX_FPAGES (sizeof (l4_word_t) * 8 - 10)
 
 
+/* Find the first bit set.  The least significant bit is 1.  If no bit
+   is set, return 0.  FIXME: This can be optimized a lot, in an
+   archtecture dependent way.  Add to libl4, like __l4_msb().  */
+static inline unsigned int
+wffs (l4_word_t nr)
+{
+  unsigned int bit = 0;
+
+  while (bit < sizeof (l4_word_t) * 8)
+    {
+      if ((1ULL << bit) & nr)
+       {
+         return bit + 1;
+       }
+      bit++;
+    }
+}
+
+
 /* Determine the fpages required to cover the bytes from START to END
    (exclusive).  START must be aligned to the minimal page size
    supported by the system.  Returns the number of fpages required to
    cover the range, and returns that many fpages (with maximum
    accessibility) in FPAGES.  At most MAX_FPAGES fpages will be
-   returned.  */
+   returned.  Each fpage will also be aligned to a multiple of its own
+   size.  */
 static unsigned int
 make_fpages (l4_word_t start, l4_word_t end, l4_fpage_t *fpages)
 {
@@ -141,8 +164,12 @@
   nr_fpages = 0;
   while (start < end)
     {
-      fpages[nr_fpages] = l4_fpage_add_rights (l4_fpage (start, end - start),
-                                              l4_fully_accessible);
+      /* Each fpage must be self-aligned.  */
+      unsigned int fpsize_log2 = wffs (start | (end - start)) - 1;
+
+      fpages[nr_fpages]
+       = l4_fpage_add_rights (l4_fpage_log2 (start, fpsize_log2),
+                              l4_fully_accessible);
       start += l4_size (fpages[nr_fpages]);
       nr_fpages++;
     }
@@ -264,21 +291,24 @@
      This can also be used to actually create these threads up
      front.  */
   ret = l4_thread_control (physmem_server, physmem_server, l4_myself (),
-                          l4_nilthread, (void *) 0x2000000);
+                          l4_nilthread, (void *) -1);
   if (!ret)
     panic ("Creation of initial physmem thread failed");
 
   /* The UTCB area must be controllable in some way, see above.  Same
      for KIP area.  */
   ret = l4_space_control (physmem_server, 0,
-                         l4_fpage_log2 (0x2400000, l4_kip_area_size_log2 ()),
-                         l4_fpage_log2 (0x2000000, 14),
+                         l4_fpage_log2 (wortel_start,
+                                        l4_kip_area_size_log2 ()),
+                         l4_fpage_log2 (wortel_start + l4_kip_area_size (),
+                                        l4_utcb_area_size_log2 ()),
                          l4_anythread, &control);
   if (!ret)
     panic ("Creation of physmem address space failed");
 
   ret = l4_thread_control (physmem_server, physmem_server, l4_nilthread,
-                          l4_myself (), (void *) -1);
+                          l4_myself (),
+                          (void *) (wortel_start + l4_kip_area_size ()));
   if (!ret)
     panic ("Activation of initial physmem thread failed");
 
@@ -444,6 +474,13 @@
          l4_msg_append_grant_item (&msg, grant_item);
          l4_msg_load (&msg);
          l4_reply (from);
+       }
+      else if ((label >> 4) == 0xffe)
+       {
+         if (l4_untyped_words (msg_tag) != 2 || l4_typed_words (msg_tag) != 0)
+           panic ("Invalid format of page fault message");
+         panic ("Unexpected page fault from 0x%xat address 0x%x (IP 0x%x)",
+                from.raw, l4_msg_word (&msg, 0), l4_msg_word (&msg, 1));
        }
       else
        panic ("Invalid message with tag 0x%x", msg_tag.raw);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]