From patchwork Wed May 4 06:02:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Valentin X-Patchwork-Id: 9010351 X-Patchwork-Delegate: rui.zhang@intel.com Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 12C13BF29F for ; Wed, 4 May 2016 06:06:04 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 272D7202B8 for ; Wed, 4 May 2016 06:06:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 73A6E2027D for ; Wed, 4 May 2016 06:05:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757304AbcEDGD2 (ORCPT ); Wed, 4 May 2016 02:03:28 -0400 Received: from mail-pf0-f174.google.com ([209.85.192.174]:35028 "EHLO mail-pf0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757295AbcEDGDZ (ORCPT ); Wed, 4 May 2016 02:03:25 -0400 Received: by mail-pf0-f174.google.com with SMTP id 77so20991011pfv.2; Tue, 03 May 2016 23:03:25 -0700 (PDT) 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=L/f3sVKnypWH2PEZ6mcdBX9WoE092HgQ+OIVNj1NcxI=; b=Llp5vysMkLArl0xOthU9M7IA1kH1CWYkfmgrDqIUBnOgjD91jx++WvureDtL5x2Qr9 zSVsYXuu/bn+4HVymhGHIabyRxYRAX6EIjZcyDcg6Xw7htOwd1Z6rdcr3KB5hvG/ZDsf O3siqMvjQcecVY5TTPl6eglq+0pHzwDMEsg20qz/PFtxuEUmNAGh47r+s50aUq5hIYxx wC2DRBqg4BNnEy0jVCAcdqwWr3tkD/fm3B1ptIq51V7AGORvTlOdadUJLEggZL42zUXq XuYi3Mv/1+7SRuDFhAI4vLXU9+uPNS3QxburwtJkuBKQwskSumw7q255Xf2ATp5GV9SC hIUA== 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=L/f3sVKnypWH2PEZ6mcdBX9WoE092HgQ+OIVNj1NcxI=; b=j8ZOA4t7Mv8wO5CZwOYp5epNFWusvNBP7sc0N7T2WE4hUuE9j6YUK+aI3VbCibGaug rqGtIICj+ZTTqQoDs06CS9euNHzGLBWUm1j4hIWcsS+AFiJJ+ulGqf9JhL0Iu3AdWFsM OQ3ofQVahUK0QICtECoJ5nQd4qgOUeW5yn74lt0LVtmMbn3EmArPeMDcmm6JDWbip8o4 qzS08g+x4FBRxzld0RPiKDLGHNgXGuavjzSJPbMhxZDmQ1n5MkEr5YYTBZknhP1g/VVv UzKQKH63bBXxy9QwYqWgIDL3kzcHHZUPqRP2xcqP0P+hlntd1X0vu5Y0XjmNLqihIm/k R7dA== X-Gm-Message-State: AOPr4FW+fZkxHScUKgSNByJ+14T5NrZUU0MoIH6f+L7KTvkqRgzFzIaGbby9A/l4AFEExA== X-Received: by 10.98.85.194 with SMTP id j185mr9628460pfb.68.1462341805100; Tue, 03 May 2016 23:03:25 -0700 (PDT) Received: from localhost ([2601:647:4203:c8e0:7256:81ff:febd:926d]) by smtp.gmail.com with ESMTPSA id r73sm2660736pfi.4.2016.05.03.23.03.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 May 2016 23:03:24 -0700 (PDT) From: Eduardo Valentin To: Rui Zhang Cc: Linux PM , LKML , Eduardo Valentin Subject: [PATCH 21/31] thermal: core: group functions related to governor handling Date: Tue, 3 May 2016 23:02:35 -0700 Message-Id: <1462341765-13268-22-git-send-email-edubezval@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1462341765-13268-1-git-send-email-edubezval@gmail.com> References: <1462341765-13268-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-Spam-Status: No, score=-8.9 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.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 aa2edec..09b4b42 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 @@ exit: 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; @@ -609,47 +689,6 @@ void thermal_zone_device_passive_update(struct thermal_zone_device *tz, thermal_zone_device_update(tz); } -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 */ /** @@ -1385,38 +1424,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) {