This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Fix for PCH on many Linux platforms


Some Linux platforms (sparc, ARM, MIPS, etc.) have to deal with
virtual cache aliasing issues.  One way in which this is
handled is to force the alignment of mmap() requests to be on
certain cache coloring boundaries.

This causes PCH to fail miserably.

This is done in two cases, for file based mmaps (which is the
scenerio PCH cares about) and for shared mappings of anonymous
memory.

For the file based mmap case (as long as MAP_SHARED is not asked
for), you can force it to use exactly the passed in base address
by using MAP_FIXED.

Because the caller does not handle the relocation case at all,
and MAP_FIXED either gives you what you asked for or fails if
the area is not available, I thought it OK to specify MAP_FIXED
all the time.

The solaris code does some hocus-pocus-mumbo-jumbo with mincore()
which I think it totally unnecessary, at worst it should try
first without MAP_FIXED then with MAP_FIXED if the former fails.
Actually, I think it can specify MAP_FIXED all the time too.

Another strategy would be 1) Try MAP_FIXED 2) if it fails try
without.  Then when relocation support is written, it could
actually occur when address space usage is tight or we have
some other problem.

Thoughts?

2004-06-13  David S. Miller  <davem@nuts.davemloft.net>

	* config/host-linux.c (HOST_HOOKS_GR_PCH_USE_ADDRESS): Define.
	(linux_pt_pch_use_address): Implement in order to deal with
	Linux platforms that apply cache coloring offsets to requested
	bases unless MAP_FIXED is specified.

--- config/host-linux.c.~1.2.~	2004-06-09 11:24:58.000000000 -0700
+++ config/host-linux.c	2004-06-13 12:24:02.689342696 -0700
@@ -137,5 +137,35 @@
   return addr;
 }
 
+#undef HOST_HOOKS_GT_PCH_USE_ADDRESS
+#define HOST_HOOKS_GT_PCH_USE_ADDRESS linux_gt_pch_use_address
+
+/* Map SIZE bytes of FD+OFFSET at BASE.  Return 1 if we succeeded at 
+   mapping the data at BASE, -1 if we couldn't.  */
+
+static int
+linux_gt_pch_use_address (void *base, size_t size, int fd, size_t offset)
+{
+  void *addr;
+
+  /* We're called with size == 0 if we're not planning to load a PCH
+     file at all.  This allows the hook to free any static space that
+     we might have allocated at link time.  */
+  if (size == 0)
+    return -1;
+
+  /* On some Linux platforms, in order to deal with virtually indexed
+     cache issues, the passed in requested base might be aligned to
+     an appropriate cache color.  This is done for any file mapping,
+     and for anonymous mappings with MAP_SHARED.  Such cache coloring
+     enforcement is not done if MAP_FIXED is specified as long as
+     MAP_SHARED is not asked for too.  */
+
+  addr = mmap (base, size, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_PRIVATE,
+	       fd, offset);
+
+  return addr == base ? 1 : -1;
+}
+
 
 const struct host_hooks host_hooks = HOST_HOOKS_INITIALIZER;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]