From owner-svn-src-all@freebsd.org Mon Dec 28 20:01:28 2015 Return-Path: Delivered-To: svn-src-all@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 790ACA54644 for ; Mon, 28 Dec 2015 20:01:28 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: from mail-qg0-x229.google.com (mail-qg0-x229.google.com [IPv6:2607:f8b0:400d:c04::229]) (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 2E1B11793 for ; Mon, 28 Dec 2015 20:01:28 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: by mail-qg0-x229.google.com with SMTP id 6so75087159qgy.1 for ; Mon, 28 Dec 2015 12:01:28 -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=Tcn1EMGjuiNnHIwrZt2E+gh9ACzP/sZIVGlfItEsRWjqgrNiwD4aNSQIsaDRN3vVs0 xHnq1EwEDi1T8iMbt7XBYR2WkkV7LWAltlyQx5zBC4AqldY4werLwrEXK08D13axWKcP uaXxjTLB8VPJHFZVge6Df0ODJ42Ra4B0r5l4JS/u5h+eAxbmG5SYk7eK2Lvqc6E0EPki ZAlqlq4Ds3KnAf3rjgXsyca85bXiRdSSO8gbgb4/I+MqfwKXeu1WC12FTeM0II8UvCVW 1PHHqxBT2eupg28j5761B6cu0x8RmAi/ptN4C9UyLqMWNQSoFwD3R+9u+2dZb6u6DAaM oG8Q== X-Gm-Message-State: ALoCoQl9mj9SyGxr7Qw4BEeOsdJqDYV+y9KaRhUi2SrKUXu0HYSBfu5Hnmvm9B0c2FVOdnWZGy7IV1ckwZvmoO2B2vEd3RqDCw== 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-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" 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 >