From patchwork Tue Nov 8 05:09:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Valentin X-Patchwork-Id: 9416595 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 3CAEF60459 for ; Tue, 8 Nov 2016 05:27:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2CB6F28B9E for ; Tue, 8 Nov 2016 05:27:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1F35228BA6; Tue, 8 Nov 2016 05:27: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.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID 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 3DE2828B9D for ; Tue, 8 Nov 2016 05:27:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752478AbcKHF1X (ORCPT ); Tue, 8 Nov 2016 00:27:23 -0500 Received: from mail-pf0-f195.google.com ([209.85.192.195]:33489 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751062AbcKHF1W (ORCPT ); Tue, 8 Nov 2016 00:27:22 -0500 Received: by mail-pf0-f195.google.com with SMTP id 144so9735401pfv.0; Mon, 07 Nov 2016 21:27:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=q1r5prAxgPYTWAlujgVitFcZpqWZSW07ja/bRphlM7g=; b=ds7oqPSKbah36Q6rnA3tgPML7wPH+ML1jV7isuzf/iQXHMBUGi116nZNfuwR6C1Iye kBOJDlUBMJduQbSE/sRhOu1m6jqbgTSuHXNvQkdIoLuVCuA2A1X7/3YXhb+a3gIns5sT 8gSvXeJ7kScpvM0WWhW9LFDE/9+gIQr3RVLxaOYBfNbm7LdctzQVVFiFkXEk0/nfrsGr rj80M7+gOUpZOVljyFD8RMLisEy79tUoSDyKyGQBCXqsnl02wjf7ai3h8usqC44b5BY4 9AX8vCe7Gqf7vvh+F8vclu4ZsnXxQpyhi4SCHn48JtR/TqmrWe5k1Ax+YqpzcXBkwxZv 66Tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=q1r5prAxgPYTWAlujgVitFcZpqWZSW07ja/bRphlM7g=; b=H4W477pzTX+Nm3bAsLRxAsqh37aC52lOOyVFCS1//fl/UypUTqpKlrCXba//wbXGZQ w5PiVY3ViiEL6plpnKVFpj8dUW5T8vf+gTNy2DlhZOirpsXFUe4ryzj72rXIwgdW+Vtj 8v9fIqMGYNoB0A8swsVgSzbcOLBVIyXhdDefBufYhwF2byWRxLvNXKf52E7m6MaMyofg Lj/eSRsWyesX1jJPbOC1nGklgL7LYiiese1CxAA91RTaYxVguLg/aj7Y0+aKFFXTHxis ODsw5rYC38p4aJgFBE8g39rRddAWqrZ5joU8C7/Thiot0sVgOKfIt2tehj5Qxs4V5bVs PCDg== X-Gm-Message-State: ABUngvehHfy0kp2RyW87TmowortoqHHMgfFzdYTGZlkULBb95SCxgrAoVgMVfRaatilVeQ== X-Received: by 10.98.201.196 with SMTP id l65mr20080518pfk.116.1478581841980; Mon, 07 Nov 2016 21:10:41 -0800 (PST) Received: from localhost ([2601:647:4401:a2f0:7256:81ff:febd:926d]) by smtp.gmail.com with ESMTPSA id qy2sm44506220pab.27.2016.11.07.21.10.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Nov 2016 21:10:41 -0800 (PST) From: Eduardo Valentin To: Rui Zhang Cc: LKML , Linux PM , Eduardo Valentin Subject: [PATCHv2 27/49] thermal: core: group functions related to governor handling Date: Mon, 7 Nov 2016 21:09:05 -0800 Message-Id: <1478581767-7009-28-git-send-email-edubezval@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1478581767-7009-1-git-send-email-edubezval@gmail.com> References: <1478581767-7009-1-git-send-email-edubezval@gmail.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 Organize thermal core code to group the functions handling with governor manipulation in one single section. Cc: Zhang Rui Cc: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Eduardo Valentin --- drivers/thermal/thermal_core.c | 153 +++++++++++++++++++++-------------------- 1 file changed, 80 insertions(+), 73 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 519aa94..e36a6a6 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -64,6 +64,13 @@ static atomic_t in_suspend; static struct thermal_governor *def_governor; +/* + * Governor section: set of functions to handle thermal governors + * + * Functions to help in the life cycle of thermal governors within + * the thermal core and by the thermal governor code. + */ + static struct thermal_governor *__find_governor(const char *name) { struct thermal_governor *pos; @@ -206,6 +213,79 @@ void thermal_unregister_governor(struct thermal_governor *governor) return; } +int thermal_zone_device_set_policy(struct thermal_zone_device *tz, + char *policy) +{ + struct thermal_governor *gov; + int ret = -EINVAL; + + mutex_lock(&thermal_governor_lock); + mutex_lock(&tz->lock); + + gov = __find_governor(strim(policy)); + if (!gov) + goto exit; + + ret = thermal_set_governor(tz, gov); + +exit: + mutex_unlock(&tz->lock); + mutex_unlock(&thermal_governor_lock); + + return ret; +} + +int thermal_build_list_of_policies(char *buf) +{ + struct thermal_governor *pos; + ssize_t count = 0; + ssize_t size = PAGE_SIZE; + + mutex_lock(&thermal_governor_lock); + + list_for_each_entry(pos, &thermal_governor_list, governor_list) { + size = PAGE_SIZE - count; + count += scnprintf(buf + count, size, "%s ", pos->name); + } + count += scnprintf(buf + count, size, "\n"); + + mutex_unlock(&thermal_governor_lock); + + return count; +} + +static int __init thermal_register_governors(void) +{ + int result; + + result = thermal_gov_step_wise_register(); + if (result) + return result; + + result = thermal_gov_fair_share_register(); + if (result) + return result; + + result = thermal_gov_bang_bang_register(); + if (result) + return result; + + result = thermal_gov_user_space_register(); + if (result) + return result; + + return thermal_gov_power_allocator_register(); +} + +static void thermal_unregister_governors(void) +{ + thermal_gov_step_wise_unregister(); + thermal_gov_fair_share_unregister(); + thermal_gov_bang_bang_unregister(); + thermal_gov_user_space_unregister(); + thermal_gov_power_allocator_unregister(); +} + static int get_idr(struct idr *idr, struct mutex *lock, int *id) { int ret; @@ -617,47 +697,6 @@ void thermal_zone_device_unbind_exception(struct thermal_zone_device *tz, mutex_unlock(&thermal_list_lock); } -int thermal_zone_device_set_policy(struct thermal_zone_device *tz, - char *policy) -{ - struct thermal_governor *gov; - int ret = -EINVAL; - - mutex_lock(&thermal_governor_lock); - mutex_lock(&tz->lock); - - gov = __find_governor(strim(policy)); - if (!gov) - goto exit; - - ret = thermal_set_governor(tz, gov); - -exit: - mutex_unlock(&tz->lock); - mutex_unlock(&thermal_governor_lock); - - return ret; -} - -int thermal_build_list_of_policies(char *buf) -{ - struct thermal_governor *pos; - ssize_t count = 0; - ssize_t size = PAGE_SIZE; - - mutex_lock(&thermal_governor_lock); - - list_for_each_entry(pos, &thermal_governor_list, governor_list) { - size = PAGE_SIZE - count; - count += scnprintf(buf + count, size, "%s ", pos->name); - } - count += scnprintf(buf + count, size, "\n"); - - mutex_unlock(&thermal_governor_lock); - - return count; -} - /* Device management */ /** @@ -1424,38 +1463,6 @@ static inline int genetlink_init(void) { return 0; } static inline void genetlink_exit(void) {} #endif /* !CONFIG_NET */ -static int __init thermal_register_governors(void) -{ - int result; - - result = thermal_gov_step_wise_register(); - if (result) - return result; - - result = thermal_gov_fair_share_register(); - if (result) - return result; - - result = thermal_gov_bang_bang_register(); - if (result) - return result; - - result = thermal_gov_user_space_register(); - if (result) - return result; - - return thermal_gov_power_allocator_register(); -} - -static void thermal_unregister_governors(void) -{ - thermal_gov_step_wise_unregister(); - thermal_gov_fair_share_unregister(); - thermal_gov_bang_bang_unregister(); - thermal_gov_user_space_unregister(); - thermal_gov_power_allocator_unregister(); -} - static int thermal_pm_notify(struct notifier_block *nb, unsigned long mode, void *_unused) {