From patchwork Wed Dec 21 02:04:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Rui X-Patchwork-Id: 9482449 X-Patchwork-Delegate: rui.zhang@intel.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7DCD760772 for ; Wed, 21 Dec 2016 02:04:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7291828138 for ; Wed, 21 Dec 2016 02:04:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 67A7B281C3; Wed, 21 Dec 2016 02:04:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 11E2928138 for ; Wed, 21 Dec 2016 02:04:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933519AbcLUCEY (ORCPT ); Tue, 20 Dec 2016 21:04:24 -0500 Received: from mga02.intel.com ([134.134.136.20]:65334 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932778AbcLUCEX (ORCPT ); Tue, 20 Dec 2016 21:04:23 -0500 Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga101.jf.intel.com with ESMTP; 20 Dec 2016 18:04:23 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,381,1477983600"; d="scan'208";a="45169082" Received: from gxu24-mobl1.ccr.corp.intel.com (HELO rzhang1-surface.ccr.corp.intel.com) ([10.255.28.231]) by fmsmga005.fm.intel.com with ESMTP; 20 Dec 2016 18:04:22 -0800 From: Zhang Rui To: linux-pm@vger.kernel.org Cc: Matthew Wilcox , Zhang Rui Subject: [PATCH 4/5] thermal: devfreq cooling: convert ID allocation to IDA Date: Wed, 21 Dec 2016 10:04:14 +0800 Message-Id: <1482285855-2974-5-git-send-email-rui.zhang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1482285855-2974-1-git-send-email-rui.zhang@intel.com> References: <1482285855-2974-1-git-send-email-rui.zhang@intel.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP thermal devfreq cooling currently uses IDRs to allocate IDs, but it only needs to know whether IDs are in use or not; the ID to pointer functionality of the IDR is unused. That means it can use the more space-efficient IDA. CC: Matthew Wilcox Signed-off-by: Zhang Rui --- drivers/thermal/devfreq_cooling.c | 49 ++++++--------------------------------- 1 file changed, 7 insertions(+), 42 deletions(-) diff --git a/drivers/thermal/devfreq_cooling.c b/drivers/thermal/devfreq_cooling.c index 5a737fd..00832bb 100644 --- a/drivers/thermal/devfreq_cooling.c +++ b/drivers/thermal/devfreq_cooling.c @@ -26,9 +26,10 @@ #include #include +#include static DEFINE_MUTEX(devfreq_lock); -static DEFINE_IDR(devfreq_idr); +static DEFINE_IDA(devfreq_ida); /** * struct devfreq_cooling_device - Devfreq cooling device @@ -58,42 +59,6 @@ struct devfreq_cooling_device { }; /** - * get_idr - function to get a unique id. - * @idr: struct idr * handle used to create a id. - * @id: int * value generated by this function. - * - * This function will populate @id with an unique - * id, using the idr API. - * - * Return: 0 on success, an error code on failure. - */ -static int get_idr(struct idr *idr, int *id) -{ - int ret; - - mutex_lock(&devfreq_lock); - ret = idr_alloc(idr, NULL, 0, 0, GFP_KERNEL); - mutex_unlock(&devfreq_lock); - if (unlikely(ret < 0)) - return ret; - *id = ret; - - return 0; -} - -/** - * release_idr - function to free the unique id. - * @idr: struct idr * handle used for creating the id. - * @id: int value representing the unique id. - */ -static void release_idr(struct idr *idr, int id) -{ - mutex_lock(&devfreq_lock); - idr_remove(idr, id); - mutex_unlock(&devfreq_lock); -} - -/** * partition_enable_opps() - disable all opps above a given state * @dfc: Pointer to devfreq we are operating on * @cdev_state: cooling device state we're setting @@ -496,7 +461,7 @@ of_devfreq_cooling_register_power(struct device_node *np, struct devfreq *df, if (err) goto free_dfc; - err = get_idr(&devfreq_idr, &dfc->id); + err = get_ida(&devfreq_ida, &devfreq_lock, &dfc->id); if (err) goto free_tables; @@ -509,15 +474,15 @@ of_devfreq_cooling_register_power(struct device_node *np, struct devfreq *df, dev_err(df->dev.parent, "Failed to register devfreq cooling device (%d)\n", err); - goto release_idr; + goto release_ida; } dfc->cdev = cdev; return cdev; -release_idr: - release_idr(&devfreq_idr, dfc->id); +release_ida: + release_ida(&devfreq_ida, &devfreq_lock, dfc->id); free_tables: kfree(dfc->power_table); kfree(dfc->freq_table); @@ -565,7 +530,7 @@ void devfreq_cooling_unregister(struct thermal_cooling_device *cdev) dfc = cdev->devdata; thermal_cooling_device_unregister(dfc->cdev); - release_idr(&devfreq_idr, dfc->id); + release_ida(&devfreq_ida, &devfreq_lock, dfc->id); kfree(dfc->power_table); kfree(dfc->freq_table);