From patchwork Sun Mar 28 18:16:07 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pauli Nieminen X-Patchwork-Id: 88799 Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o2SIHWuN016895 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Sun, 28 Mar 2010 18:18:12 GMT Received: from localhost ([127.0.0.1] helo=sfs-ml-1.v29.ch3.sourceforge.com) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.69) (envelope-from ) id 1Nvx2E-0005yU-6g; Sun, 28 Mar 2010 18:16:30 +0000 Received: from sfi-mx-1.v28.ch3.sourceforge.com ([172.29.28.121] helo=mx.sourceforge.net) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.69) (envelope-from ) id 1Nvx2C-0005yN-80 for dri-devel@lists.sourceforge.net; Sun, 28 Mar 2010 18:16:28 +0000 Received-SPF: neutral (sfi-mx-1.v28.ch3.sourceforge.com: 213.243.153.185 is neither permitted nor denied by domain of gmail.com) client-ip=213.243.153.185; envelope-from=suokkos@gmail.com; helo=filtteri2.pp.htv.fi; Received: from filtteri2.pp.htv.fi ([213.243.153.185]) by sfi-mx-1.v28.ch3.sourceforge.com with esmtp (Exim 4.69) id 1Nvx29-0004AR-Nl for dri-devel@lists.sourceforge.net; Sun, 28 Mar 2010 18:16:28 +0000 Received: from localhost (localhost [127.0.0.1]) by filtteri2.pp.htv.fi (Postfix) with ESMTP id 54BAABFB5; Sun, 28 Mar 2010 21:16:11 +0300 (EEST) X-Virus-Scanned: Debian amavisd-new at pp.htv.fi Received: from smtp5.welho.com ([213.243.153.39]) by localhost (filtteri2.pp.htv.fi [213.243.153.185]) (amavisd-new, port 10024) with ESMTP id hx02DUpMoCAT; Sun, 28 Mar 2010 21:16:11 +0300 (EEST) Received: from localhost.localdomain (cs181130083.pp.htv.fi [82.181.130.83]) by smtp5.welho.com (Postfix) with ESMTP id E65A95BC005; Sun, 28 Mar 2010 21:16:10 +0300 (EEST) From: Pauli Nieminen To: dri-devel@lists.sourceforge.net Subject: [PATCH 7/7] drm/ttm: Add sysfs interface to control pool allocator. Date: Sun, 28 Mar 2010 21:16:07 +0300 Message-Id: <1269800167-5291-7-git-send-email-suokkos@gmail.com> X-Mailer: git-send-email 1.7.0 In-Reply-To: <1269800167-5291-1-git-send-email-suokkos@gmail.com> References: <1269800167-5291-1-git-send-email-suokkos@gmail.com> X-Spam-Score: 1.1 (+) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. 1.2 SPF_NEUTRAL SPF: sender does not match SPF record (neutral) -0.1 AWL AWL: From: address is in the auto white-list X-Headers-End: 1Nvx29-0004AR-Nl X-BeenThere: dri-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.sourceforge.net X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Sun, 28 Mar 2010 18:18:12 +0000 (UTC) diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c index 72f31aa..7c0309f 100644 --- a/drivers/gpu/drm/ttm/ttm_memory.c +++ b/drivers/gpu/drm/ttm/ttm_memory.c @@ -395,7 +395,7 @@ int ttm_mem_global_init(struct ttm_mem_global *glob) "Zone %7s: Available graphics memory: %llu kiB.\n", zone->name, (unsigned long long) zone->max_mem >> 10); } - ttm_page_alloc_init(glob->zone_kernel->max_mem/(2*PAGE_SIZE)); + ttm_page_alloc_init(glob, glob->zone_kernel->max_mem/(2*PAGE_SIZE)); return 0; out_no_zone: ttm_mem_global_release(glob); diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c index 716b400..9bfe513 100644 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c @@ -72,6 +72,12 @@ struct ttm_page_pool { unsigned long nrefills; }; +/** + * Limits for the pool. They are handled without locks because only place where + * they may change is in sysfs store. They won't have immediate effect anyway + * so forcing serialiazation to access them is pointless. + */ + struct ttm_pool_opts { unsigned alloc_size; unsigned max_size; @@ -94,6 +100,7 @@ struct ttm_pool_opts { * @pools: All pool objects in use. **/ struct ttm_pool_manager { + struct kobject kobj; struct shrinker mm_shrink; atomic_t page_alloc_inited; struct ttm_pool_opts options; @@ -109,6 +116,100 @@ struct ttm_pool_manager { }; }; +static struct attribute ttm_page_pool_max = { + .name = "pool_max_size", + .mode = S_IRUGO | S_IWUSR +}; +static struct attribute ttm_page_pool_small = { + .name = "pool_small_allocation", + .mode = S_IRUGO | S_IWUSR +}; +static struct attribute ttm_page_pool_alloc_size = { + .name = "pool_allocation_size", + .mode = S_IRUGO | S_IWUSR +}; + +static struct attribute *ttm_pool_attrs[] = { + &ttm_page_pool_max, + &ttm_page_pool_small, + &ttm_page_pool_alloc_size, + NULL +}; + +static void ttm_pool_kobj_release(struct kobject *kobj) +{ + struct ttm_pool_manager *m = + container_of(kobj, struct ttm_pool_manager, kobj); + (void)m; +} + +static ssize_t ttm_pool_store(struct kobject *kobj, + struct attribute *attr, const char *buffer, size_t size) +{ + struct ttm_pool_manager *m = + container_of(kobj, struct ttm_pool_manager, kobj); + int chars; + unsigned val; + chars = sscanf(buffer, "%u", &val); + if (chars == 0) + return size; + + /* Convert kb to number of pages */ + val = val / (PAGE_SIZE >> 10); + + if (attr == &ttm_page_pool_max) + m->options.max_size = val; + else if (attr == &ttm_page_pool_small) + m->options.small = val; + else if (attr == &ttm_page_pool_alloc_size) { + if (val > NUM_PAGES_TO_ALLOC*8) { + printk(KERN_ERR "[ttm] Setting allocation size to %lu " + "is not allowed. Recomended size is " + "%lu\n", + NUM_PAGES_TO_ALLOC*(PAGE_SIZE >> 7), + NUM_PAGES_TO_ALLOC*(PAGE_SIZE >> 10)); + return size; + } else if (val > NUM_PAGES_TO_ALLOC) { + printk(KERN_WARNING "[ttm] Setting allocation size to " + "larger than %lu is not recomended.\n", + NUM_PAGES_TO_ALLOC*(PAGE_SIZE >> 10)); + } + m->options.alloc_size = val; + } + + return size; +} + +static ssize_t ttm_pool_show(struct kobject *kobj, + struct attribute *attr, char *buffer) +{ + struct ttm_pool_manager *m = + container_of(kobj, struct ttm_pool_manager, kobj); + unsigned val = 0; + + if (attr == &ttm_page_pool_max) + val = m->options.max_size; + else if (attr == &ttm_page_pool_small) + val = m->options.small; + else if (attr == &ttm_page_pool_alloc_size) + val = m->options.alloc_size; + + val = val * (PAGE_SIZE >> 10); + + return snprintf(buffer, PAGE_SIZE, "%u\n", val); +} + +static const struct sysfs_ops ttm_pool_sysfs_ops = { + .show = &ttm_pool_show, + .store = &ttm_pool_store, +}; + +static struct kobj_type ttm_pool_kobj_type = { + .release = &ttm_pool_kobj_release, + .sysfs_ops = &ttm_pool_sysfs_ops, + .default_attrs = ttm_pool_attrs, +}; + static struct ttm_pool_manager _manager = { .page_alloc_inited = ATOMIC_INIT(0) }; @@ -663,8 +764,9 @@ static void ttm_page_pool_init_locked(struct ttm_page_pool *pool, int flags, pool->name = name; } -int ttm_page_alloc_init(unsigned max_pages) +int ttm_page_alloc_init(struct ttm_mem_global *glob, unsigned max_pages) { + int ret; if (atomic_add_return(1, &_manager.page_alloc_inited) > 1) return 0; @@ -684,6 +786,13 @@ int ttm_page_alloc_init(unsigned max_pages) _manager.options.small = SMALL_ALLOCATION; _manager.options.alloc_size = NUM_PAGES_TO_ALLOC; + kobject_init(&_manager.kobj, &ttm_pool_kobj_type); + ret = kobject_add(&_manager.kobj, &glob->kobj, "pool"); + if (unlikely(ret != 0)) { + kobject_put(&_manager.kobj); + return ret; + } + ttm_pool_mm_shrink_init(&_manager); return 0; @@ -701,6 +810,8 @@ void ttm_page_alloc_fini() for (i = 0; i < NUM_POOLS; ++i) ttm_page_pool_free(&_manager.pools[i], FREE_ALL_PAGES); + + kobject_put(&_manager.kobj); } int ttm_page_alloc_debugfs(struct seq_file *m, void *data) diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h index 99bbe03..432ac02 100644 --- a/include/drm/ttm/ttm_page_alloc.h +++ b/include/drm/ttm/ttm_page_alloc.h @@ -61,7 +61,7 @@ void ttm_put_pages(struct list_head *pages, * multiple times but ttm_page_alloc_fini has to be called same number of * times. */ -int ttm_page_alloc_init(unsigned max_pages); +int ttm_page_alloc_init(struct ttm_mem_global *glob, unsigned max_pages); /** * Free pool allocator. */