From owner-svn-src-head@freebsd.org Mon Dec 28 20:01:28 2015 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 769F6A54643 for ; Mon, 28 Dec 2015 20:01:28 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: from mail-qg0-x22f.google.com (mail-qg0-x22f.google.com [IPv6:2607:f8b0:400d:c04::22f]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 2E2861795 for ; Mon, 28 Dec 2015 20:01:27 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: by mail-qg0-x22f.google.com with SMTP id e32so61818396qgf.3 for ; Mon, 28 Dec 2015 12:01:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=kOfT2RuXtm7sfTBFx9X0pQQgYTDbRADZFle+IarMY5I=; b=Nnp2iLR6j3LEjMrCswkeH5iwygr8izdD4Kk3V56nSoY8sWKVRyfhEpe1or+HvjoToO j9ljNUcrrUF3zDk5jA6XRF2serFM6BORJK5AqxOvdyAC45qAWJ8RoRam9L1MmxfEejp2 U8psF6owDVkmKr7pbhFMEO0VUm2ERlG7Cq//6JHODUOKaE9fjwqmg4hncKd7k5xUbga+ m9PefrnWGmODcRKZ9xQbk1TJ3JDpJOAgyRAEDbdR+LacxiCA23b+JWRRSPgTwEQgIiGQ 8ag7USMLp71L3pxaXvGzyG26pRDBxw6r0NCyMrNWAUtRvQJA18O1ETtVwH7ce5ApUNtL xGNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=kOfT2RuXtm7sfTBFx9X0pQQgYTDbRADZFle+IarMY5I=; b=TkHYTc8yehNgv++PAJ2+jDrV6EiywIWSgxPuRSuJCkZNAiwVGD3ikpYTp/DCNuuYcF Pc8pn0iuw6E5vnpkjh1ArIppcQ1UVcJHw+v9eebaXxchAUBKkBMHMCHaf6T7DsxDxqXr 9aX65lDastDDaa9w6QBtLQGWsxM08QnayD5EW4lIfoBxDB5uCtQjo4B+zZ/KRxdv9Z5F 2bA+Gt5MxHuxpMnYJzrGA9g383Z0EZ5mllDfRhTRGj3JbPIhivfh8RLNtcDWjqHXt7EA i8VcRDHyDPiHbGDPTQ20a7PytI2eH/OzBsATYoGkPOX7K6wRQV5qkbuyd5uAUeGkl9vg rduQ== X-Gm-Message-State: ALoCoQmWYz8MRGhyNFf/8g6IVPH0ECaf0qzhY+F39LEhw+qZSP2teJRtd4gpYCm8C4BiS6bHrNXYX789AQahxVmc5DP9oyi2Mw== MIME-Version: 1.0 X-Received: by 10.140.30.197 with SMTP id d63mr72607489qgd.81.1451332887021; Mon, 28 Dec 2015 12:01:27 -0800 (PST) Sender: wlosh@bsdimp.com Received: by 10.140.27.181 with HTTP; Mon, 28 Dec 2015 12:01:26 -0800 (PST) X-Originating-IP: [2607:fb90:1908:5378:0:46:97bd:7401] Received: by 10.140.27.181 with HTTP; Mon, 28 Dec 2015 12:01:26 -0800 (PST) In-Reply-To: <41508412.yspAtSoPCD@ralph.baldwin.cx> References: <201512272304.tBRN4C5D034464@repo.freebsd.org> <41508412.yspAtSoPCD@ralph.baldwin.cx> Date: Mon, 28 Dec 2015 13:01:26 -0700 X-Google-Sender-Auth: VYwPxta0azBLs76t7XqmM_ne0i8 Message-ID: Subject: Re: svn commit: r292809 - head/lib/libc/stdio From: Warner Losh To: John Baldwin Cc: src-committers , svn-src-head@freebsd.org, svn-src-all@freebsd.org, Warner Losh Content-Type: text/plain; charset=UTF-8 X-Content-Filtered-By: Mailman/MimeDel 2.1.20 X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Dec 2015 20:01:28 -0000 I'll look at that, but I don't think posix_memalign is the right way to go. The alignment of FILE is more strict than posix_memalign will return. Ian's idea of __alignof__ is the way to go. We allocate them in one block on purpose for performance, and posix_memalign would be a one at a time affair. Warner On Dec 28, 2015 12:42 PM, "John Baldwin" wrote: > On Sunday, December 27, 2015 11:04:12 PM Warner Losh wrote: > > Author: imp > > Date: Sun Dec 27 23:04:11 2015 > > New Revision: 292809 > > URL: https://svnweb.freebsd.org/changeset/base/292809 > > > > Log: > > The FILE structure has a mbstate_t in it. This structure needs to be > > aligned on a int64_t boundary. However, when we allocate the array of > > these structures, we use ALIGNBYTES which defaults to sizeof(int) on > > arm, i386 and others. The i386 stuff can handle unaligned accesses > > seemlessly. However, arm cannot. Take this into account when creating > > the array of FILEs, and add some comments about why. > > > > Differential Revision: https://reviews.freebsd.org/D4708 > > > > Modified: > > head/lib/libc/stdio/findfp.c > > > > Modified: head/lib/libc/stdio/findfp.c > > > ============================================================================== > > --- head/lib/libc/stdio/findfp.c Sun Dec 27 23:04:10 2015 > (r292808) > > +++ head/lib/libc/stdio/findfp.c Sun Dec 27 23:04:11 2015 > (r292809) > > @@ -41,6 +41,7 @@ __FBSDID("$FreeBSD$"); > > #include > > #include > > #include > > +#include > > #include > > > > #include > > @@ -96,11 +97,22 @@ moreglue(int n) > > struct glue *g; > > static FILE empty = { ._fl_mutex = PTHREAD_MUTEX_INITIALIZER }; > > FILE *p; > > + size_t align; > > > > - g = (struct glue *)malloc(sizeof(*g) + ALIGNBYTES + n * > sizeof(FILE)); > > + /* > > + * FILE has a mbstate_t variable. This variable tries to be int64_t > > + * aligned through its definition. int64_t may be larger than void > *, > > + * which is the size traditionally used for ALIGNBYTES. So, use > our own > > + * rounding instead of the MI ALIGN macros. If for some reason > > + * ALIGNBYTES is larger than int64_t, respect that too. There > appears to > > + * be no portable way to ask for FILE's alignment requirements > other > > + * than just knowing here. > > + */ > > + align = MAX(ALIGNBYTES, sizeof(int64_t)); > > + g = (struct glue *)malloc(sizeof(*g) + align + n * sizeof(FILE)); > > if (g == NULL) > > return (NULL); > > - p = (FILE *)ALIGN(g + 1); > > + p = (FILE *)roundup((uintptr_t)(g + 1), align); > > Can this use posix_memalign() rather than doing the alignment by hand? > > -- > John Baldwin >