From owner-svn-src-all@FreeBSD.ORG Fri Jul 25 23:12:23 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 5EEE1C4D; Fri, 25 Jul 2014 23:12:23 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4B87B2929; Fri, 25 Jul 2014 23:12:23 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s6PNCNCg031202; Fri, 25 Jul 2014 23:12:23 GMT (envelope-from ian@svn.freebsd.org) Received: (from ian@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s6PNCMPd031198; Fri, 25 Jul 2014 23:12:22 GMT (envelope-from ian@svn.freebsd.org) Message-Id: <201407252312.s6PNCMPd031198@svn.freebsd.org> From: Ian Lepore Date: Fri, 25 Jul 2014 23:12:22 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r269101 - stable/10/lib/libstand X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18 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: Fri, 25 Jul 2014 23:12:23 -0000 Author: ian Date: Fri Jul 25 23:12:22 2014 New Revision: 269101 URL: http://svnweb.freebsd.org/changeset/base/269101 Log: MFC r261530 Set the malloc alignment to 64 bytes on platforms that use the U-Boot API device drivers. Recent versions of u-boot run with the MMU enabled, and require DMA-based I/O to be aligned to cache line boundaries. Modified: stable/10/lib/libstand/sbrk.c stable/10/lib/libstand/zalloc.c stable/10/lib/libstand/zalloc_defs.h stable/10/lib/libstand/zalloc_mem.h Directory Properties: stable/10/ (props changed) Modified: stable/10/lib/libstand/sbrk.c ============================================================================== --- stable/10/lib/libstand/sbrk.c Fri Jul 25 22:58:55 2014 (r269100) +++ stable/10/lib/libstand/sbrk.c Fri Jul 25 23:12:22 2014 (r269101) @@ -33,6 +33,7 @@ __FBSDID("$FreeBSD$"); #include #include "stand.h" +#include "zalloc_defs.h" static size_t maxheap, heapsize = 0; static void *heapbase; @@ -40,8 +41,9 @@ static void *heapbase; void setheap(void *base, void *top) { - /* Align start address to 16 bytes for the malloc code. Sigh. */ - heapbase = (void *)(((uintptr_t)base + 15) & ~15); + /* Align start address for the malloc code. Sigh. */ + heapbase = (void *)(((uintptr_t)base + MALLOCALIGN_MASK) & + ~MALLOCALIGN_MASK); maxheap = (char *)top - (char *)heapbase; } Modified: stable/10/lib/libstand/zalloc.c ============================================================================== --- stable/10/lib/libstand/zalloc.c Fri Jul 25 22:58:55 2014 (r269100) +++ stable/10/lib/libstand/zalloc.c Fri Jul 25 23:12:22 2014 (r269101) @@ -71,6 +71,15 @@ __FBSDID("$FreeBSD$"); #include "zalloc_defs.h" /* + * Objects in the pool must be aligned to at least the size of struct MemNode. + * They must also be aligned to MALLOCALIGN, which should normally be larger + * than the struct, so assert that to be so at compile time. + */ +typedef char assert_align[(sizeof(struct MemNode) <= MALLOCALIGN) ? 1 : -1]; + +#define MEMNODE_SIZE_MASK MALLOCALIGN_MASK + +/* * znalloc() - allocate memory (without zeroing) from pool. Call reclaim * and retry if appropriate, return NULL if unable to allocate * memory. Modified: stable/10/lib/libstand/zalloc_defs.h ============================================================================== --- stable/10/lib/libstand/zalloc_defs.h Fri Jul 25 22:58:55 2014 (r269100) +++ stable/10/lib/libstand/zalloc_defs.h Fri Jul 25 23:12:22 2014 (r269101) @@ -52,18 +52,26 @@ #define BLKEXTENDMASK (BLKEXTEND - 1) /* - * required malloc alignment. Just hardwire to 16. + * Required malloc alignment. * - * Note: if we implement a more sophisticated realloc, we should ensure that - * MALLOCALIGN is at least as large as MemNode. + * Embedded platforms using the u-boot API drivers require that all I/O buffers + * be on a cache line sized boundary. The worst case size for that is 64 bytes. + * For other platforms, 16 bytes works fine. The alignment also must be at + * least sizeof(struct MemNode); this is asserted in zalloc.c. */ +#if defined(__arm__) || defined(__mips__) || defined(__powerpc__) +#define MALLOCALIGN 64 +#else +#define MALLOCALIGN 16 +#endif +#define MALLOCALIGN_MASK (MALLOCALIGN - 1) + typedef struct Guard { size_t ga_Bytes; size_t ga_Magic; /* must be at least 32 bits */ } Guard; -#define MALLOCALIGN 16 #define GAMAGIC 0x55FF44FD #define GAFREE 0x5F54F4DF Modified: stable/10/lib/libstand/zalloc_mem.h ============================================================================== --- stable/10/lib/libstand/zalloc_mem.h Fri Jul 25 22:58:55 2014 (r269100) +++ stable/10/lib/libstand/zalloc_mem.h Fri Jul 25 23:12:22 2014 (r269101) @@ -48,8 +48,6 @@ typedef struct MemPool { uintptr_t mp_Used; } MemPool; -#define MEMNODE_SIZE_MASK ((sizeof(MemNode) <= 8) ? 7 : 15) - #define ZNOTE_FREE 0 #define ZNOTE_REUSE 1