From patchwork Thu Jun 1 11:39:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 100901 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp759193qge; Thu, 1 Jun 2017 04:40:51 -0700 (PDT) X-Received: by 10.98.202.68 with SMTP id n65mr706016pfg.158.1496317251295; Thu, 01 Jun 2017 04:40:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496317251; cv=none; d=google.com; s=arc-20160816; b=ddyf/Nmzok9MYs+rZM33vl0r6kuh2+nwYlDddJux/PRKs8qhrq7D9GLEI7yGFHZOPr uhLu6bJCeBnv0468TF4tC5R0fMVY/LMWjoQHCYgF1+z4m57+pt+PF0EamrUIjYedoNzt 9owHg68gq3WG5nMlUgYDOOssRZBJJRRR7HaPKgKeF7oSo88q8OO984XlysblbJVIynGD D15EokfkoVq0m8S+LdDCb7LtYW6LgFQITOTpUTTGgM3zRHxzSEb21ZO9xYIml4TUhRil hx7YzrnrDkqa0rjzsetx9DuSvnoMnvQqWgMcpA2zNTvAUpmbmqYzmNWbsZ5IsNxK5B5P UC+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=dXut3XsfbF4NJwUFnduoLzccyX3wVnNL3Ut9KAXe+k4=; b=bvUsLnNwtYJEcN8tDIkYZAN5njABsMtT94v1Dm/PYsa+6dw3GWBG1f7rWer3G/yX5X vSgBIp23QDczkFducvCuKZ9Am3pireSaPvKzzfuv8+dbrt1+L1Hr+85tEg79LEO9X+X0 133hjcF1HiLOp/AlqJGtyvlSVimlK8M9TNi8VjtcnhjCEPOyyvY+0YZHlvH/dAgJJLg6 1hTRgbQXXqzLh4AK2X62FKtjHp4dILJXe2gLM2DpMxkzaCqHVu9lJN53oxeuUIoU6arZ S8Oxez1TT2CHUZuR1jtVOFyWqUv3yveS8U/K8VuLVy3/nslHBdyrzBe/f4iSv5hQyO9h bW2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 q15si989032pli.169.2017.06.01.04.40.51; Thu, 01 Jun 2017 04:40:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S1751161AbdFALku (ORCPT + 14 others); Thu, 1 Jun 2017 07:40:50 -0400 Received: from mail-wm0-f45.google.com ([74.125.82.45]:35893 "EHLO mail-wm0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751159AbdFALkt (ORCPT ); Thu, 1 Jun 2017 07:40:49 -0400 Received: by mail-wm0-f45.google.com with SMTP id 7so154408012wmo.1 for ; Thu, 01 Jun 2017 04:40:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=dXut3XsfbF4NJwUFnduoLzccyX3wVnNL3Ut9KAXe+k4=; b=G+VZ4p4FJDqDYYvGA9VumIBB4AB60dEoxxOt1IR9hsXbK/hApSaHIdgjuusAE8JtpR evw+C4buK+0UnVAxcSKPn0CSk7Y3gI11m7tv6KmjtNcfr/XuC7JlOO+rV6oKsgN8UCDc fLG9OaUMtN2L0txGMsvW1ERMj3WqSz7XSmoE0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=dXut3XsfbF4NJwUFnduoLzccyX3wVnNL3Ut9KAXe+k4=; b=oBIYRF5Si0jS5+1+wwQ2Rx9iagpGFyIMH8cVTQHAQ31WKHECwtT4/ae75gmnP5VLjh mse7VMyQG7YmRLbsSOkCANtlmdsKT6+3Q34r9RGBiNWuk03+6jQYUT35Mw0LLTWpcNZ+ kO1IGhozvJP1zdaOSW0QeZn8GR5Pu8auaAOwqLcSrg7ykH5+ugwbYojhGWwWWAJqzW/8 iVk1dXrNAZ12fpp+am7SsgB+7ea2uld/JZLhaeRjmgvwn9X+lia2WpIbj2uoDRv48oyD F6cbC7RUVgzKZnggfC89rnUrBEUKKz8yznaqUjLu4guKypRDVlYSadsCOXV23BIhzoWW PqhQ== X-Gm-Message-State: AODbwcD3RYNiTcameQp5t3tZDlTBUL+DHmqehP/KjC7oqBzfeOqzbIOB 4F5WXnzP4w8EGvplLweSOQ== X-Received: by 10.223.164.23 with SMTP id d23mr982355wra.54.1496317247632; Thu, 01 Jun 2017 04:40:47 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:879a:6cd0:f90e:b7d2:e646:ce75]) by smtp.gmail.com with ESMTPSA id d8sm3282478wrc.60.2017.06.01.04.40.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 01 Jun 2017 04:40:46 -0700 (PDT) From: Daniel Lezcano To: rjw@rjwysocki.net, lorenzo.pieralisi@arm.com Cc: sudeep.holla@arm.com, leo.yan@linaro.org, linux-pm@vger.kernel.org (open list:CPUIDLE DRIVERS), linux-kernel@vger.kernel.org (open list) Subject: [PATCH V2] ARM: cpuidle: Support asymmetric idle definition Date: Thu, 1 Jun 2017 13:39:48 +0200 Message-Id: <1496317188-15272-1-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Some hardware have clusters with different idle states. The current code does not support this and fails as it expects all the idle states to be identical. Because of this, the Mediatek mtk8173 had to create the same idle state for a big.Little system and now the Hisilicon 960 is facing the same situation. Solve this by simply assuming the multiple driver will be needed for all the platforms using the ARM generic cpuidle driver which makes sense because of the different topologies we can support with a single kernel for ARM32 or ARM64. Every CPU has its own driver, so every single CPU can specify in the DT the idle states. This simple approach allows to support the future dynamIQ system, current SMP and HMP. It is unoptimal from a memory point of view for a system with a large number of CPUs but nowadays there is no such system with a cpuidle driver on ARM. Tested on: - 96boards: Hikey 620 - 96boards: Hikey 960 - 96boards: dragonboard410c - Mediatek 8173 Tested-by: Leo Yan Signed-off-by: Daniel Lezcano --- drivers/cpuidle/Kconfig.arm | 1 + drivers/cpuidle/cpuidle-arm.c | 62 ++++++++++++++++++++++++++----------------- 2 files changed, 39 insertions(+), 24 deletions(-) -- 2.7.4 diff --git a/drivers/cpuidle/Kconfig.arm b/drivers/cpuidle/Kconfig.arm index 21340e0..f521448 100644 --- a/drivers/cpuidle/Kconfig.arm +++ b/drivers/cpuidle/Kconfig.arm @@ -4,6 +4,7 @@ config ARM_CPUIDLE bool "Generic ARM/ARM64 CPU idle Driver" select DT_IDLE_STATES + select CPU_IDLE_MULTIPLE_DRIVERS help Select this to enable generic cpuidle driver for ARM. It provides a generic idle driver whose idle states are configured diff --git a/drivers/cpuidle/cpuidle-arm.c b/drivers/cpuidle/cpuidle-arm.c index f440d38..7080c38 100644 --- a/drivers/cpuidle/cpuidle-arm.c +++ b/drivers/cpuidle/cpuidle-arm.c @@ -18,6 +18,7 @@ #include #include #include +#include #include @@ -44,7 +45,7 @@ static int arm_enter_idle_state(struct cpuidle_device *dev, return CPU_PM_CPU_IDLE_ENTER(arm_cpuidle_suspend, idx); } -static struct cpuidle_driver arm_idle_driver = { +static struct cpuidle_driver arm_idle_driver __initdata = { .name = "arm_idle", .owner = THIS_MODULE, /* @@ -80,30 +81,42 @@ static const struct of_device_id arm_idle_state_match[] __initconst = { static int __init arm_idle_init(void) { int cpu, ret; - struct cpuidle_driver *drv = &arm_idle_driver; + struct cpuidle_driver *drv; struct cpuidle_device *dev; - /* - * Initialize idle states data, starting at index 1. - * This driver is DT only, if no DT idle states are detected (ret == 0) - * let the driver initialization fail accordingly since there is no - * reason to initialize the idle driver if only wfi is supported. - */ - ret = dt_init_idle_driver(drv, arm_idle_state_match, 1); - if (ret <= 0) - return ret ? : -ENODEV; - - ret = cpuidle_register_driver(drv); - if (ret) { - pr_err("Failed to register cpuidle driver\n"); - return ret; - } - - /* - * Call arch CPU operations in order to initialize - * idle states suspend back-end specific data - */ for_each_possible_cpu(cpu) { + + drv = kmemdup(&arm_idle_driver, sizeof(*drv), GFP_KERNEL); + if (!drv) { + ret = -ENOMEM; + goto out_fail; + } + + drv->cpumask = (struct cpumask *)cpumask_of(cpu); + + /* + * Initialize idle states data, starting at index 1. This + * driver is DT only, if no DT idle states are detected (ret + * == 0) let the driver initialization fail accordingly since + * there is no reason to initialize the idle driver if only + * wfi is supported. + */ + ret = dt_init_idle_driver(drv, arm_idle_state_match, 1); + if (ret <= 0) { + ret = ret ? : -ENODEV; + goto out_fail; + } + + ret = cpuidle_register_driver(drv); + if (ret) { + pr_err("Failed to register cpuidle driver\n"); + goto out_fail; + } + + /* + * Call arch CPU operations in order to initialize + * idle states suspend back-end specific data + */ ret = arm_cpuidle_init(cpu); /* @@ -141,10 +154,11 @@ static int __init arm_idle_init(void) dev = per_cpu(cpuidle_devices, cpu); cpuidle_unregister_device(dev); kfree(dev); + drv = cpuidle_get_driver(); + cpuidle_unregister_driver(drv); + kfree(drv); } - cpuidle_unregister_driver(drv); - return ret; } device_initcall(arm_idle_init);