From patchwork Fri May 19 16:45:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 100200 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp405849qge; Fri, 19 May 2017 09:47:05 -0700 (PDT) X-Received: by 10.84.141.36 with SMTP id 33mr12190003plu.99.1495212425087; Fri, 19 May 2017 09:47:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1495212425; cv=none; d=google.com; s=arc-20160816; b=o3jz7BfT+kgBv4qYRolzUx70YvhUHj78y5I5ARwUwuF+KytF2GFEhWhezeSh1HZY9f pffINhdx9DFhp5L9yxudpNdRiAeJN24ZFZNwl/H3gXGKnqbG+O4EOraAaCMHDl0poKgc 2V9AMmFvEQoQOQ/mGJ1IGYAEFFitkotaKmpPiPtdRDgrPOB1EtslKs7+q1CYUtxVTGCO /1pXN4f36L4MuvLQ8Td6nRKukbdnaLhYtqLWvHd9wsg2kDXjUAksae37aVEvBxijjbC3 shVPfivpa3bBldk1BGnstYczLx7xEZM7E+dWF8xYD9/YQytZElXx5fxk1Q8s0XYIypHt R/pg== 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=hTxcRklfQislMapiCf3f7XlWSHdL3SpAzFbZfPoiqZw=; b=DJ28xtS7/N09rIqirhbSqJjxhUCAGaFJG0V0G769wkwSxZu1iEFL0t/bDO0plBM4bh Bm7uYNSeepzRmabakEdJf7HvZrS9yYYkfrQHpZZ9cL3+hpoxj8xforu3D6vC9lFNNBvb n/s+iJ46A6MN+h8m86YBAdAD7uBkrbzFNzPXSqZ47J6zVz7QnX5r1+9puGTzOzutMDeQ VjwxXpL375wVDrwADjSR7a91mVDG+dXdPBMEz63hnwvylr2Cv0Wz3LgQ5WbeYmIMY1/9 jvDqDTVd4o/I7ALgYubXkG3eITORipPTzagyKTc05x+h6FFXMHnqFjeHfHoyJe6N9lPF AWQw== 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 p15si8726763pli.166.2017.05.19.09.47.04; Fri, 19 May 2017 09:47:05 -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 S1751260AbdESQrD (ORCPT + 14 others); Fri, 19 May 2017 12:47:03 -0400 Received: from mail-wr0-f174.google.com ([209.85.128.174]:34198 "EHLO mail-wr0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751731AbdESQrA (ORCPT ); Fri, 19 May 2017 12:47:00 -0400 Received: by mail-wr0-f174.google.com with SMTP id l9so20334162wre.1 for ; Fri, 19 May 2017 09:46:38 -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=hTxcRklfQislMapiCf3f7XlWSHdL3SpAzFbZfPoiqZw=; b=ZGlg5DhEjsC2wYADZkP4Am9EW64buxHy+i+yi7zlOLiSKJJYfQxTfA0imatqsvg/St PJxM+gYcLmnyI0n5yGXkx5ftI+V1gnZi/gQxZ0AYWB42j2YLGInBc6SF6gB+yEh3AeQC ASXrnUQQJaZv6artRFtoaWMmndwaqjtXLW33o= 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=hTxcRklfQislMapiCf3f7XlWSHdL3SpAzFbZfPoiqZw=; b=tILL0dOJStnktwGD7ZkMZbJhQc203mv0w/sqdm572imnaSQzdX0tbayjNlT6UXgVW3 mv/Q4cJaL5iglzS7QgAk9unA9GmowffmoPrv9IRUIH6tkAkounLvnJ62z1acqEWwErYi HNZy2KLx3e4qqlUyYYbKStXSGfHMTKH30jh0/JUtoj4Z5BVRl5W83ueytvJNdMGFd+Uu VUKNLLPbJK1qWt8Jt4e2XLX3wZtBAiWvNWpRxeLKIcZn0dNwKsZOV+l8yFNmmAVOixQ6 m8rpRlkhU/1h2efWND6far4janrzC4YYZTiFdCBmo1FUmd+eCvk0i+VmB/qFyJmZaNhm 9y4w== X-Gm-Message-State: AODbwcDrUjlDutCS6BfFfgEu+6Pihs4dgoqnCTzEA8NG8CLrVvz7xCIL /+G4p4VLt5PyK9mc X-Received: by 10.223.138.237 with SMTP id z42mr4228896wrz.66.1495212397728; Fri, 19 May 2017 09:46:37 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:879a:6cd0:b16d:8c6c:5be6:8e7f]) by smtp.gmail.com with ESMTPSA id 25sm2370408wrz.8.2017.05.19.09.46.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 19 May 2017 09:46:36 -0700 (PDT) From: Daniel Lezcano To: rjw@rjwysocki.net, lorenzo.pieralisi@arm.com Cc: leo.yan@linaro.org, linux-pm@vger.kernel.org (open list:CPUIDLE DRIVERS), linux-kernel@vger.kernel.org (open list) Subject: [PATCH] ARM: cpuidle: Support asymmetric idle definition Date: Fri, 19 May 2017 18:45:43 +0200 Message-Id: <1495212343-24873-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. 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 | 55 +++++++++++++++++++++++++++++-------------- 2 files changed, 38 insertions(+), 18 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..bec31d5 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,23 +81,40 @@ 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 = NULL; 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; + for_each_possible_cpu(cpu) { + + if (drv && cpumask_test_cpu(cpu, drv->cpumask)) + continue; + + ret = -ENOMEM; + + drv = kmemdup(&arm_idle_driver, sizeof(*drv), GFP_KERNEL); + if (!drv) + goto out_fail; + + drv->cpumask = &cpu_topology[cpu].core_sibling; + + /* + * 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; + } } /* @@ -141,10 +159,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);