[Ur] Collecting Ur/Web examples

Evan Danaher ur at edanaher.net
Wed May 7 23:52:49 EDT 2014


Preprocessor magic?  No, I just made a very simple change to get it to
work for me.  And it's simple enough that I'm just going to paste the diff
inline here instead of trying to figure out the proper way to submit it.

I also have no idea of the performance/memory usage implications; it might
be interesting to run some benchmarks on x86 and see how it goes.  All I
know is that it fails quickly on ARM without this change, and succeeds as
far as I've tested with it.

Also, incidentally, I was compiling this on the ARM machine itself rather
than cross-compiling, so needed to cut memory usage of MLton and gcc to get
it to compile in a meager gigabyte of RAM; I'm including the Makefile
change I made as well in case it might be worth incorporating somehow.


diff -purN urweb-20131231/src/c/urweb.c urweb-20131231-mine/src/c/urweb.c
--- urweb-20131231/src/c/urweb.c  2013-12-31 07:49:04.000000000 -0800
+++ urweb-20131231-mine/src/c/urweb.c 2014-03-26 15:21:42.121568001 -0700
@@ -1257,12 +1257,13 @@ void *uw_malloc(uw_context ctx, size_t l
   void *result;

   if (ctx->amInitializing) {
-    result = malloc(len);
+    int error = posix_memalign(&result, 4, len);
+    //result = malloc(len);

-    if (result)
+    if (!error)
       return result;
     else
-      uw_error(ctx, FATAL, "uw_malloc: malloc() returns 0");
+      uw_error(ctx, FATAL, "uw_malloc: posix_memalign() returns %d", error);
   } else {
     uw_check_heap(ctx, len);
diff -purN urweb-20131231/Makefile urweb-20131231-mine/Makefile
--- urweb-20131231/Makefile 2014-05-07 20:46:24.006358000 -0700
+++ urweb-20131231-mine/Makefile  2014-05-07 20:10:57.933014881 -0700
@@ -151,7 +151,7 @@ MAKEINFO = ${SHELL} /home/ubuntu/bin/src
 MKDIR_P = /bin/mkdir -p
 MLLEX = yes
 MLTON = mlton
-MLTONARGS =
+MLTONARGS = @MLton -ram-slop 0.6 -- -cc-opt -O0
 MLYACC = yes
 MSHEADER = mysql/mysql.h
 NM = /usr/bin/nm -B


On Wed, May 07, 2014 at 03:45:45PM -0400, Adam Chlipala wrote:
> Right, we can tell it's a requirement for ARM, because Evan had to change
> the Ur/Web implementation to maintain alignment, to get it working on ARM.
> :)
> 
> I think it's best to apply Evan's alignment patch unconditionally, for all
> architectures, and I'm hoping he can just send what he already implemented.
> 
> On 05/07/2014 02:34 PM, Austin Seipp wrote:
> >FWIW, alignment is probably not only good for most non-Nehalem*
> >platforms, it is also a requirement for certain platforms like 32-bit
> >ARM, if I'm not mistaken. I believe AArch64 (64bit ARM) has also
> >lifted this restruction, but in general it's probably a decent one to
> >follow for portability I think.
> >
> >* Intel Nehalem was the first Intel arch to allow very cheap unaligned
> >load/stores from what I remember, these days I'm not even sure how
> >much slower they are than aligned ones...
> >
> >On Wed, May 7, 2014 at 1:25 PM, Adam Chlipala <adamc at csail.mit.edu> wrote:
> >>Neat!  Would you mind contributing a patch to address this ARM issue?
> >>(Presumably this is just the code you already tweaked, perhaps ideally using
> >>some kind of preprocessor magic to decide if the alignment is necessary, or
> >>maybe alignment is also good for performance on all platforms that should be
> >>supported.)
> >>
> >>
> >>On 05/07/2014 12:36 PM, Evan Danaher wrote:
> >>>On Wed, May 07, 2014 at 08:37:58AM -0400, Adam Chlipala wrote:
> >>>>[snip]
> >>>>
> >>>>I don't know if anyone has built Ur/Web servers for ARM, but I can't
> >>>>think
> >>>>of any reason why it wouldn't work right away.  If there are issues,
> >>>>they're
> >>>>probably easy to fix.  Certainly Ur/Web is used regularly with both
> >>>>32-bit
> >>>>and 64-bit x86.
> >>>>
> >>>I haven't finished any projects, but some of my playing around was on an
> >>>ARM machine running Ubuntu.  IIRC, I had to tweak uw_malloc to always be
> >>>4-byte aligned, but aside from that I didn't run into any issues.  (I
> >>>also didn't do anything particularly exciting, but the basics at least
> >>>worked without issue.)
> >>
> >>_______________________________________________
> >>Ur mailing list
> >>Ur at impredicative.com
> >>http://www.impredicative.com/cgi-bin/mailman/listinfo/ur
> >
> >
> 
> 
> _______________________________________________
> Ur mailing list
> Ur at impredicative.com
> http://www.impredicative.com/cgi-bin/mailman/listinfo/ur
> 



More information about the Ur mailing list