From patchwork Mon Jul 27 09:57:54 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Qiang X-Patchwork-Id: 500317 X-Patchwork-Delegate: scottwood@freescale.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 7AB281402B7 for ; Mon, 27 Jul 2015 20:20:35 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 5D2BA1A2D30 for ; Mon, 27 Jul 2015 20:20:35 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from na01-bn1-obe.outbound.protection.outlook.com (mail-bn1on0113.outbound.protection.outlook.com [157.56.110.113]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 5AC211A4472 for ; Mon, 27 Jul 2015 20:03:04 +1000 (AEST) Received: from BLUPR0301CA0016.namprd03.prod.outlook.com (10.162.113.154) by BY2PR0301MB1542.namprd03.prod.outlook.com (10.163.27.156) with Microsoft SMTP Server (TLS) id 15.1.219.17; Mon, 27 Jul 2015 10:02:57 +0000 Received: from BL2FFO11OLC005.protection.gbl (2a01:111:f400:7c09::126) by BLUPR0301CA0016.outlook.office365.com (2a01:111:e400:5259::26) with Microsoft SMTP Server (TLS) id 15.1.225.19 via Frontend Transport; Mon, 27 Jul 2015 10:02:57 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=freescale.com; freescale.mail.onmicrosoft.com; dkim=none (message not signed) header.d=none; Received-SPF: Fail (protection.outlook.com: domain of freescale.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BL2FFO11OLC005.mail.protection.outlook.com (10.173.160.91) with Microsoft SMTP Server (TLS) id 15.1.231.11 via Frontend Transport; Mon, 27 Jul 2015 10:02:57 +0000 Received: from titan.ap.freescale.net ([10.192.208.233]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id t6RA2pCR006879; Mon, 27 Jul 2015 03:02:52 -0700 From: Zhao Qiang To: Subject: [RFC v2] genalloc:add an gen_pool_first_fit_align algo to genalloc Date: Mon, 27 Jul 2015 17:57:54 +0800 Message-ID: <1437991074-35377-1-git-send-email-qiang.zhao@freescale.com> X-Mailer: git-send-email 2.1.0.27.g96db324 X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11OLC005; 1:vXtwG1pJGt2PNJCha7/k5y3nmvyDQLYVwywKhWmNFFkoR4YFdUvy9M8Ni6s0mdunrsISv18Oa+XK87DUurVEcOftYCGpQCLwY4/zjHogEMw+vB2eVlyztE6wM1xtjjHAH7LtmBsUqXcF4os/+59mirSCHikzX7yuO/hSsXxxk5PRg3813JmgJUZgFcoxxBo49BGdtAxmhq16tfDITZkx8C80fsuKcYROl6BrsHmaD/nA5hIii4RMV3twODhs/3JwxNoPN1B4+CjJog49wxhS0J+cIqYynjT0DKD6Hmr150kj+RrhypFQD6R6t/Hl4mfAHlXK2bm1/wAHeKjkibe/NA== X-Forefront-Antispam-Report: CIP:192.88.168.50; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(2980300002)(339900001)(199003)(189002)(46102003)(36756003)(48376002)(575784001)(87936001)(50466002)(47776003)(92566002)(15975445007)(86362001)(85426001)(77096005)(19580395003)(6806004)(19580405001)(105606002)(77156002)(104016003)(33646002)(106466001)(50226001)(5003940100001)(5001960100002)(2351001)(62966003)(189998001)(229853001)(107886002)(110136002)(50986999)(4001430100001); DIR:OUT; SFP:1102; SCL:1; SRVR:BY2PR0301MB1542; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; MLV:sfv; A:1; MX:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Exchange-Diagnostics: 1; BY2PR0301MB1542; 2:+Lr7snECz5lmeqE4QqJvLUnFN8e37gqDDv0277BNl5HDOud/J+QIvklXUtWqD18S; 3:FcNvR9H5/cC4xM5YaaSoL3AjGhxqOKO9NAii7d+gdIZoKdnJsBSLlgqikgZek4m6My8ZadPCThZBlnl2SkIDYnili1bm8LX5zMnuKHhNDWz0ubYB2Hx5QtS2ZiqzHb5Rwvape67K/LKhT+Kgdj1lPNVma+IhpQ6Oo9aiRSFZqv0iD1zK1a33ZSdhVX7fJpMAvXGxH9MQHRy3jcWttubKywj1D2Mpp+C+R6sH2IigeDo=; 25:TJHIWcIWpsKTI6zXLyBLHBuEDXd1f+jIU1yKFlH2PlYuOJ3rggW7jyzQZwhUQSZsP5aQW9GM23LH1LGOV1Ohso7AXaMTaiz48+BeePl5Gv0U4GtDZglcR+84xp5HuxO+7LszQpsFW6OxJa1XPJMHcubog17mzfOLtl+iNJQ96FnaKnU/mxDyszAuLoybCemWP0kaOdMt7LRFTHD80e+5ubo7OacuFEMyx5RVokewH76PQZzNq5IddF0qstBkxqWyKIShKlosZVHJ9fdiAsladA==; 20:FMRil83gLhdJfS+fFi81G9wsEVFltAvsIoGd894wI/j1ihgbm3Uk2wOKChYz2twGrqbOXLPWIs63Ngdt27yzZNBF6ydJos93Oup7nGZIb3bbM+C11F0ptVGRLVR3pDIT6tap4KEKLVzKtz6p5X4AR3/RAvYbMWNJV5sapX82ZhvUxeWTKk97w/mMzVuWEABIiFk1QoyCjxG8S1tZPJVGhPeKJHbbrWBzgYWnJ6Dx5y9HDLGCrUaexdo0lF0WRAkb11sC16Q7eqcGJZbTJMM9KTMX3BvIzwfnrno6oZWLaKyfC2HaIGJFGYdFDJaYccftO3H+5kRbX3QEyUnLf13pC8iozKxrRo/B4H1jDJjvTho= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY2PR0301MB1542; BY2PR0301MB1542: X-MS-Exchange-Organization-RulesExecuted X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(5005006)(3002001); SRVR:BY2PR0301MB1542; BCL:0; PCL:0; RULEID:; SRVR:BY2PR0301MB1542; X-Microsoft-Exchange-Diagnostics: 1; BY2PR0301MB1542; 4:2G+2VM4seFa3OVJaRHZzj/5h/PG0/T0+uy4sFTxiXzJ5PrK+IQGlYwZjgEuQw78hGpyVFLssjM4fwzgLnkHSVttfD+Mu5L8p0wVz3rIqYAwfZdrSfKmh4l37RhBX29ocgPGDbQv9z/+3GbvIwmcZBENU6JtjpshqMTwDixe/hvYovvkhlp61H/SvyLihhTvNVIBz90wQKKuOeY63rRV8GLIwOwxI7wHxu2D1SZTsHHlZXNQ1Ws0aQqjBaI9fzMOl3OmAbXW6OPGrmgwp2BUkAwcUOVxmOGcT0+v/3mLqkqs= X-Forefront-PRVS: 0650714AAA X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BY2PR0301MB1542; 23:EzguCQuANrzva4oN1ELoM+dje4u2uyxYjpGF+6B?= =?us-ascii?Q?WWw1TrIm/8DesUQM908Hx3u2Cp7Ed34zAkmUWsbaYw9T3JKurxszKrtfNQ02?= =?us-ascii?Q?02xe7hYRcaLsljg+4Fi5t5m13N3tcuJjjBRPtc98iH6TbVqwaR3tXI4bzGM+?= =?us-ascii?Q?UnX3RwEAyRlOiPJ2H6XGE0ywxOvvX88AvGWLLrd+AlO+EEo/pVGH1+Zlvj4l?= =?us-ascii?Q?OBcMva/IhVmAKvYEAf0o0MKeKWVcZW8rVylkU2vENSqQc9ulcgXF4vmINGy0?= =?us-ascii?Q?rI2O74g6YmjX5stOF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pF5jAF0kqOmOrvRhztTn46fZNgA8n6mMrittvkkdoj9LzznS2a+SPkmBbK56uyZRAxqgI=; 20:u5hRNX7nHxBcEVF3MkXfyONoGFUbcEw3tt50+gvhYrWEfFdHWB5BSvDCGX66s0+Z2Sb7pZrE5VmOPDo0p9qFLQ== X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2015 10:02:57.0530 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d; Ip=[192.88.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR0301MB1542 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zhao Qiang , catalin.marinas@arm.com, linux-kernel@vger.kernel.org, scottwood@freescale.com, olof@lixom.net, akpm@linux-foundation.org, linuxppc-dev@lists.ozlabs.org, X.xie@freescale.com Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Bytes alignment is required to manage some special ram, so add gen_pool_first_fit_align to genalloc. User should define data structure struct data { int align; struct gen_pool *pool; } align is the number of bytes alignment, pool points to gen_pool which include data. Signed-off-by: Zhao Qiang --- *v2: changes: title has been modified, original patch link: http://patchwork.ozlabs.org/patch/493297/ original patch add a func gen_pool_alloc_align, then pass alignment to it as an parameter. after discussing with lauraa and scott, they recommend to pass alignment as part of data based on commit message for ca279cf1065fb689abea1dc7d8c11787729bb185 which adds "data": "As I can't predict all the possible requirements/needs for all allocation uses cases, I add a "free" field 'void *data' to pass any needed information to the allocation function. For example 'data' could be used to handle a structure where you store the alignment, the expected memory bank, the requester device, or any information that could influence the allocation algorithm." include/linux/genalloc.h | 4 ++++ lib/genalloc.c | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/include/linux/genalloc.h b/include/linux/genalloc.h index 1ccaab4..b85d0f8 100644 --- a/include/linux/genalloc.h +++ b/include/linux/genalloc.h @@ -110,6 +110,10 @@ extern void gen_pool_set_algo(struct gen_pool *pool, genpool_algo_t algo, extern unsigned long gen_pool_first_fit(unsigned long *map, unsigned long size, unsigned long start, unsigned int nr, void *data); +extern unsigned long gen_pool_first_fit_align(unsigned long *map, + unsigned long size, unsigned long start, unsigned int nr, + void *data); + extern unsigned long gen_pool_first_fit_order_align(unsigned long *map, unsigned long size, unsigned long start, unsigned int nr, void *data); diff --git a/lib/genalloc.c b/lib/genalloc.c index d214866..e6608cd 100644 --- a/lib/genalloc.c +++ b/lib/genalloc.c @@ -509,6 +509,31 @@ unsigned long gen_pool_first_fit(unsigned long *map, unsigned long size, EXPORT_SYMBOL(gen_pool_first_fit); /** + * gen_pool_first_fit_align - find the first available region + * of memory matching the size requirement (no alignment constraint) + * @map: The address to base the search on + * @size: The bitmap size in bits + * @start: The bitnumber to start searching at + * @nr: The number of zeroed bits we're looking for + * @data: additional data - unused + */ +unsigned long gen_pool_first_fit_align(unsigned long *map, unsigned long size, + unsigned long start, unsigned int nr, void *data) +{ + unsigned long align_mask; + int order; + + if (data && data->pool) { + order = data->pool->min_alloc_order; + align_mask = ((data->align + (1UL << order) - 1) >> order) - 1; + } else { + pr_err("no data or data->pool\n"); + } + return bitmap_find_next_zero_area(map, size, start, nr, align_mask); +} +EXPORT_SYMBOL(gen_pool_first_fit_algin); + +/** * gen_pool_first_fit_order_align - find the first available region * of memory matching the size requirement. The region will be aligned * to the order of the size specified.