Received: by 10.223.176.5 with SMTP id f5csp2540711wra; Mon, 5 Feb 2018 05:55:53 -0800 (PST) X-Google-Smtp-Source: AH8x226U/JnsVHb4oGo48mrskH7FQVTXlcM5hnKSQgGClXVZ4CZpj1vT7AK/ehfe13XrTKhdgDBj X-Received: by 2002:a17:902:74c9:: with SMTP id f9-v6mr13256985plt.89.1517838953302; Mon, 05 Feb 2018 05:55:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517838953; cv=none; d=google.com; s=arc-20160816; b=E9gMUlMKgwIL5zXDh2NfvdByhU83Fg8RumCN2R7UFIfV7vyFqasjasHf+qr/Km/8rS fjJylNI0yy1udKFKKnCOqB7lfROzHKU9ouAeKOrSBJxnvoE87GvedjljX+/ARm356f/i utpLWroiFyrk5wxUiWmJTAWByVTca+HBOrOZySozx8+qh7baCfKP24sTSd2xgVHrjdXQ BCrxHRFYBlBSxqXm6ccxSWy0r0eQLfE+rYtDB0LR+z7ibIvbn99r1oYIHJ+qAVd62Ho8 GAC0qYEC22o4D2ZOw0omGMr9OmjZMZYFA8IeJ9YKHW6PXA+QvTgw++ua5IY+l5JIbF+X Lw4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=vnSEk5I6cVSxRc9oUGspD9zqSlFDYmT2ApYOYV1/ZxU=; b=DGsP9Gd8AK9hGUPILwHDJUoi1E4huCc1qL1JhEGsi58ySO1u2okfgpvWQKMo/ijGW5 mr026J/0dAn73ITlRG7Ck+ffXnnwhu5n0dje2o1dCb3tCMLjUqEfCIIp8/6EtFuWQe+4 z2hPGwvPG8YRvkFcFpMuM4iP0swXBfcAcxRnwG/dhEaQ/yauwwo3Ecpb28dsFn/ZF7y6 Q14T4nKGvx/75tpmU99yuaz7esfjbPOR7TEkJr1+bqEakoTuEX4CJVNYaVrjB1aAO+T6 s3uNzhMifcmh+dKsEQOLMY7chEEJmC89Mwl4CLAMb1uIcpiL42XrbKWEehKBxJJNRAv8 ms/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Q3cyU6kl; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m7si1961493pgs.489.2018.02.05.05.55.38; Mon, 05 Feb 2018 05:55:53 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Q3cyU6kl; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753137AbeBENyw (ORCPT + 99 others); Mon, 5 Feb 2018 08:54:52 -0500 Received: from mail-wr0-f194.google.com ([209.85.128.194]:38461 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752925AbeBENyr (ORCPT ); Mon, 5 Feb 2018 08:54:47 -0500 Received: by mail-wr0-f194.google.com with SMTP id t94so18147759wrc.5 for ; Mon, 05 Feb 2018 05:54:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=vnSEk5I6cVSxRc9oUGspD9zqSlFDYmT2ApYOYV1/ZxU=; b=Q3cyU6klGnSRApC3OA01P1htRDrej0UklVHLL26tswlC+JVExJDPIdnggfKjk4H2gy 28ghHUE87lE9wc8qVMRVIKMf4SDqEK6v3l1JGt+uUzD7xaoTJjoequp2jJgVn6UuD6qP fM5/QDWDZZDBAkyheQnOhs+1KDip/bc4KS4cU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=vnSEk5I6cVSxRc9oUGspD9zqSlFDYmT2ApYOYV1/ZxU=; b=pP+v0LgrDwIRP8LRHa4B8vNurwRaa2m87lL31L3b7U6reRVL5sbzx0aioXvw+MI08M JwkbGa1e7hS3D6+hYKix37It5iVEONnRsfEXtENq6ZSlbC8hAH5g6auu4IYEKBondKfR u/ti/XpaVP907RnlJJX7gwmLi2nXFrW7HA+YoTFMfTwBZTPwld/xmc3BJEHho8uBBzHu i6HMF4aFCNgBfV4RBrOEwQypGfTB3yQxdzythmXZjcML11+GZwBuOd1fhCH1vTTQVYKT qCBIIwEE2uD1bCQqPIOpkjO/PfHwSRdHv8X2S9PzbMcP/duxdF1TSI/yoS8d/blGtmO+ cwpw== X-Gm-Message-State: AKwxytfxMelfOTSU52d7IapVVtJk7R8d9QPFXx405mxM4Pxawd2MYdWn TpVg46pY+rhY0HBLO+iBwCfiKw== X-Received: by 10.223.141.139 with SMTP id o11mr38853595wrb.0.1517838886448; Mon, 05 Feb 2018 05:54:46 -0800 (PST) Received: from [192.168.1.24] (cpc141214-aztw34-2-0-cust773.18-1.cable.virginm.net. [86.9.19.6]) by smtp.gmail.com with ESMTPSA id 42sm15589476wrw.15.2018.02.05.05.54.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Feb 2018 05:54:45 -0800 (PST) Subject: Re: [PATCH 5/8] thermal/drivers/cpu_cooling: Introduce the cpu idle cooling driver To: Daniel Lezcano , edubezval@gmail.com Cc: kevin.wangtao@linaro.org, leo.yan@linaro.org, vincent.guittot@linaro.org, amit.kachhap@gmail.com, viresh.kumar@linaro.org, linux-kernel@vger.kernel.org, Zhang Rui , Javi Merino , "open list:THERMAL" References: <1516721671-16360-1-git-send-email-daniel.lezcano@linaro.org> <1516721671-16360-6-git-send-email-daniel.lezcano@linaro.org> From: Daniel Thompson Message-ID: Date: Mon, 5 Feb 2018 13:54:43 +0000 User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <1516721671-16360-6-git-send-email-daniel.lezcano@linaro.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 23/01/18 15:34, Daniel Lezcano wrote: > +/** > + * cpuidle_cooling_get_max_state - Get the maximum state > + * @cdev : the thermal cooling device > + * @state : a pointer to the state variable to be filled > + * > + * The function gives always 100 as the injection ratio is percentile > + * based for consistency accros different platforms. > + * > + * The function can not fail, it returns always zero. > + */ > +static int cpuidle_cooling_get_max_state(struct thermal_cooling_device *cdev, > + unsigned long *state) > +{ > + /* > + * Depending on the configuration or the hardware, the running > + * cycle and the idle cycle could be different. We want unify > + * that to an 0..100 interval, so the set state interface will > + * be the same whatever the platform is. > + * > + * The state 100% will make the cluster 100% ... idle. A 0% > + * injection ratio means no idle injection at all and 50% > + * means for 10ms of idle injection, we have 10ms of running > + * time. > + */ > + *state = 100; Doesn't this requires DTs to be changed? Basically the existing bindings for cpu cooling dictate that cooling-max-levels == num OPPs - 1 . Likewise I think cooling-max-levels *defines* the scale used by the cooling maps in the DT. Introducing an alternative scale means that the OPP limits in the cooling-map will be misinterpreted when we bind the cooling device. Note that we get away with this on Hikey because its mainline cooling map is, AFAICT, deeply sub-optimal and doesn't set any cooling limits. If its cooling map has been tuned (as the Exynos ones are) then I suspect there could be overheating problems when the cpuidle (or combo) CPU coolers are enabled. Daniel. > + > + return 0; > +} > + > +/** > + * cpuidle_cooling_get_cur_state - Get the current cooling state > + * @cdev: the thermal cooling device > + * @state: a pointer to the state > + * > + * The function just copy the state value from the private thermal > + * cooling device structure, the mapping is 1 <-> 1. > + * > + * The function can not fail, it returns always zero. > + */ > +static int cpuidle_cooling_get_cur_state(struct thermal_cooling_device *cdev, > + unsigned long *state) > +{ > + struct cpuidle_cooling_device *idle_cdev = cdev->devdata; > + > + *state = idle_cdev->state; > + > + return 0; > +} > + > +/** > + * cpuidle_cooling_set_cur_state - Set the current cooling state > + * @cdev: the thermal cooling device > + * @state: the target state > + * > + * The function checks first if we are initiating the mitigation which > + * in turn wakes up all the idle injection tasks belonging to the idle > + * cooling device. In any case, it updates the internal state for the > + * cooling device. > + * > + * The function can not fail, it returns always zero. > + */ > +static int cpuidle_cooling_set_cur_state(struct thermal_cooling_device *cdev, > + unsigned long state) > +{ > + struct cpuidle_cooling_device *idle_cdev = cdev->devdata; > + unsigned long current_state = idle_cdev->state; > + > + idle_cdev->state = state; > + > + if (current_state == 0 && state > 0) { > + pr_debug("Starting cooling cpus '%*pbl'\n", > + cpumask_pr_args(idle_cdev->cpumask)); > + cpuidle_cooling_wakeup(idle_cdev); > + } else if (current_state > 0 && !state) { > + pr_debug("Stopping cooling cpus '%*pbl'\n", > + cpumask_pr_args(idle_cdev->cpumask)); > + } > + > + return 0; > +} > + > +/** > + * cpuidle_cooling_ops - thermal cooling device ops > + */ > +static struct thermal_cooling_device_ops cpuidle_cooling_ops = { > + .get_max_state = cpuidle_cooling_get_max_state, > + .get_cur_state = cpuidle_cooling_get_cur_state, > + .set_cur_state = cpuidle_cooling_set_cur_state, > +}; > + > +/** > + * cpuidle_cooling_release - Kref based release helper > + * @kref: a pointer to the kref structure > + * > + * This function is automatically called by the kref_put function when > + * the idle cooling device refcount reaches zero. At this point, we > + * have the guarantee the structure is no longer in use and we can > + * safely release all the ressources. > + */ > +static void __init cpuidle_cooling_release(struct kref *kref) > +{ > + struct cpuidle_cooling_device *idle_cdev = > + container_of(kref, struct cpuidle_cooling_device, kref); > + > + thermal_cooling_device_unregister(idle_cdev->cdev); > + kfree(idle_cdev->waitq); > + kfree(idle_cdev->tsk); > + kfree(idle_cdev); > +} > + > +/** > + * cpuidle_cooling_register - Idle cooling device initialization function > + * > + * This function is in charge of creating a cooling device per cluster > + * and register it to thermal framework. For this we rely on the > + * topology as there is nothing yet describing better the idle state > + * power domains. > + * > + * For each first CPU of the cluster's cpumask, we allocate the idle > + * cooling device, initialize the general fields and then we initialze > + * the rest in a per cpu basis. > + * > + * Returns zero on success, < 0 otherwise. > + */ > +int cpuidle_cooling_register(void) > +{ > + struct cpuidle_cooling_device *idle_cdev = NULL; > + struct thermal_cooling_device *cdev; > + struct task_struct *tsk; > + struct device_node *np; > + cpumask_t *cpumask; > + char dev_name[THERMAL_NAME_LENGTH]; > + int weight; > + int ret = -ENOMEM, cpu; > + int index = 0; > + > + for_each_possible_cpu(cpu) { > + > + cpumask = topology_core_cpumask(cpu); > + weight = cpumask_weight(cpumask); > + > + /* > + * This condition makes the first cpu belonging to the > + * cluster to create a cooling device and allocates > + * the structure. Others CPUs belonging to the same > + * cluster will just increment the refcount on the > + * cooling device structure and initialize it. > + */ > + if (cpu == cpumask_first(cpumask)) { > + > + np = of_cpu_device_node_get(cpu); > + > + idle_cdev = kzalloc(sizeof(*idle_cdev), GFP_KERNEL); > + if (!idle_cdev) > + goto out_fail; > + > + idle_cdev->tsk = kzalloc(sizeof(*idle_cdev->tsk) * > + weight, GFP_KERNEL); > + if (!idle_cdev->tsk) > + goto out_fail; > + > + idle_cdev->waitq = kzalloc(sizeof(*idle_cdev->waitq) * > + weight, GFP_KERNEL); > + if (!idle_cdev->waitq) > + goto out_fail; > + > + idle_cdev->idle_cycle = DEFAULT_IDLE_TIME_US; > + > + atomic_set(&idle_cdev->count, 0); > + > + kref_init(&idle_cdev->kref); > + > + /* > + * Initialize the timer to wakeup all the idle > + * injection tasks > + */ > + hrtimer_init(&idle_cdev->timer, > + CLOCK_MONOTONIC, HRTIMER_MODE_REL); > + > + /* > + * The wakeup function callback which is in > + * charge of waking up all CPUs belonging to > + * the same cluster > + */ > + idle_cdev->timer.function = cpuidle_cooling_wakeup_fn; > + > + /* > + * The thermal cooling device name > + */ > + snprintf(dev_name, sizeof(dev_name), "thermal-idle-%d", index++); > + cdev = thermal_of_cooling_device_register(np, dev_name, > + idle_cdev, > + &cpuidle_cooling_ops); > + if (IS_ERR(cdev)) { > + ret = PTR_ERR(cdev); > + goto out_fail; > + } > + > + idle_cdev->cdev = cdev; > + > + idle_cdev->cpumask = cpumask; > + > + list_add(&idle_cdev->node, &cpuidle_cdev_list); > + > + pr_info("Created idle cooling device for cpus '%*pbl'\n", > + cpumask_pr_args(cpumask)); > + } > + > + kref_get(&idle_cdev->kref); > + > + /* > + * Each cooling device is per package. Each package > + * has a set of cpus where the physical number is > + * duplicate in the kernel namespace. We need a way to > + * address the waitq[] and tsk[] arrays with index > + * which are not Linux cpu numbered. > + * > + * One solution is to use the > + * topology_core_id(cpu). Other solution is to use the > + * modulo. > + * > + * eg. 2 x cluster - 4 cores. > + * > + * Physical numbering -> Linux numbering -> % nr_cpus > + * > + * Pkg0 - Cpu0 -> 0 -> 0 > + * Pkg0 - Cpu1 -> 1 -> 1 > + * Pkg0 - Cpu2 -> 2 -> 2 > + * Pkg0 - Cpu3 -> 3 -> 3 > + * > + * Pkg1 - Cpu0 -> 4 -> 0 > + * Pkg1 - Cpu1 -> 5 -> 1 > + * Pkg1 - Cpu2 -> 6 -> 2 > + * Pkg1 - Cpu3 -> 7 -> 3 > + */ > + init_waitqueue_head(&idle_cdev->waitq[cpu % weight]); > + > + tsk = kthread_create_on_cpu(cpuidle_cooling_injection_thread, > + idle_cdev, cpu, "kidle_inject/%u"); > + if (IS_ERR(tsk)) { > + ret = PTR_ERR(tsk); > + goto out_fail; > + } > + > + idle_cdev->tsk[cpu % weight] = tsk; > + > + wake_up_process(tsk); > + } > + > + return 0; > + > +out_fail: > + list_for_each_entry(idle_cdev, &cpuidle_cdev_list, node) { > + > + for_each_cpu(cpu, idle_cdev->cpumask) { > + > + if (idle_cdev->tsk[cpu]) > + kthread_stop(idle_cdev->tsk[cpu]); > + > + kref_put(&idle_cdev->kref, cpuidle_cooling_release); > + } > + } > + > + pr_err("Failed to create idle cooling device (%d)\n", ret); > + > + return ret; > +} > +#endif > diff --git a/include/linux/cpu_cooling.h b/include/linux/cpu_cooling.h > index d4292eb..2b5950b 100644 > --- a/include/linux/cpu_cooling.h > +++ b/include/linux/cpu_cooling.h > @@ -45,6 +45,7 @@ struct thermal_cooling_device * > cpufreq_power_cooling_register(struct cpufreq_policy *policy, > u32 capacitance, get_static_t plat_static_func); > > +extern int cpuidle_cooling_register(void); > /** > * of_cpufreq_cooling_register - create cpufreq cooling device based on DT. > * @np: a valid struct device_node to the cooling device device tree node. > @@ -118,6 +119,11 @@ void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev) > { > return; > } > + > +static inline int cpuidle_cooling_register(void) > +{ > + return 0; > +} > #endif /* CONFIG_CPU_THERMAL */ > > #endif /* __CPU_COOLING_H__ */ >