From patchwork Thu Jun 4 06:25:42 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tang yuantian X-Patchwork-Id: 480549 X-Patchwork-Delegate: scottwood@freescale.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id DD699140271 for ; Thu, 4 Jun 2015 18:04:10 +1000 (AEST) Received: from ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id C1CC81A2B57 for ; Thu, 4 Jun 2015 18:04:10 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org X-Greylist: delayed 4685 seconds by postgrey-1.35 at bilbo; Thu, 04 Jun 2015 18:03:13 AEST Received: from na01-by2-obe.outbound.protection.outlook.com (mail-by2on0129.outbound.protection.outlook.com [207.46.100.129]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id CFEE41A0BC1 for ; Thu, 4 Jun 2015 18:03:13 +1000 (AEST) Received: from DM2PR03CA0008.namprd03.prod.outlook.com (10.141.96.18) by BY2PR03MB571.namprd03.prod.outlook.com (10.141.143.145) with Microsoft SMTP Server (TLS) id 15.1.172.22; Thu, 4 Jun 2015 06:29:51 +0000 Received: from BN1BFFO11FD035.protection.gbl (2a01:111:f400:7c10::1:158) by DM2PR03CA0008.outlook.office365.com (2a01:111:e400:2428::18) with Microsoft SMTP Server (TLS) id 15.1.184.17 via Frontend Transport; Thu, 4 Jun 2015 06:29:50 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=freescale.com; freescale.mail.onmicrosoft.com; dkim=none (message not signed) header.d=none; Received-SPF: Fail (protection.outlook.com: domain of freescale.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BN1BFFO11FD035.mail.protection.outlook.com (10.58.144.98) with Microsoft SMTP Server (TLS) id 15.1.184.11 via Frontend Transport; Thu, 4 Jun 2015 06:29:49 +0000 Received: from titan.ap.freescale.net ([10.192.208.233]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id t546TjxI032178; Wed, 3 Jun 2015 23:29:46 -0700 From: To: Subject: [PATCH] cpufreq: qoriq: optimize the CPU frequency switching time Date: Thu, 4 Jun 2015 14:25:42 +0800 Message-ID: <1433399142-18324-1-git-send-email-Yuantian.Tang@freescale.com> X-Mailer: git-send-email 2.1.0.27.g96db324 X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BN1BFFO11FD035; 1:cLTJjATZebgM6Q/VfLXiaajU/xWHcC7DsxGB9YoS2oWPyqFeXpwLSkaXS/g2BydZC/3Ab8naVghC6QJQwgwgDTW3RzYhj6mgs2dREKp0hj59Rsmyb0KOxuNzckfXCDo2DgcPDXcYz5dHCg/ccOX9k47HOqsYC66OswK/DvOgqZkngH6CQaQWYZ00S8fi1KuCjprPspM7jMap3bqTeYRXp5vdyzaABIuARNocHhI6TdGZN32gVUjyvD34Ka5TxL6sSJw31H85vdAbhJi6rPTssWWT3P0pA5tIdfdB8sxGn9QxzjrwCB/Hi4z1iKnKIJcPuURs0UdmEUqvSjpqDXs+mLiX1789J7Vinppdr+WGe6g= X-Forefront-Antispam-Report: CIP:192.88.168.50; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(339900001)(189002)(199003)(6806004)(110136002)(68736005)(77096005)(86362001)(107886002)(5001960100002)(77156002)(105606002)(92566002)(86152002)(19580405001)(87936001)(104016003)(48376002)(2351001)(229853001)(5001830100001)(46102003)(189998001)(50226001)(97736004)(50466002)(62966003)(47776003)(5001860100001)(85426001)(19580395003)(81156007)(36756003)(50986999)(64706001)(4001540100001)(106466001)(4001430100001); DIR:OUT; SFP:1102; SCL:1; SRVR:BY2PR03MB571; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Exchange-Diagnostics: 1; BY2PR03MB571; 2:ccQIbFHgoD+ZwChOsRUWODfpXQb6Vc5veIY9u78NNrIwRRrWa8yaTv7Ibu/tXTVr; 2:s5YtH956fpEQYM3KtD94LvhnlOcDlh/PBEJZjNQs9Urlwu5nxRXlInn/ArcYVqpJqcbVe/djBb4BMMooLTIbqozh54q7UYNqQKNu2bC3IWs0y62O4zbRgSl/FRWDoUqRimB+jzycZEpB4PeuUYB0KNM45DoRQmVzE1djtMiELlGdCe4D/T/g2yUaBu3aY0n0Gv6K7vtndkO19hEi9ko0I1CslKpmRvzrQF+TXAtaMko=; 6:9fnXstMcjyIVZX5QZ7BTenHnQLL2yhPNle62k6y0glxwPxdpu6gIYm+xYbku46pPh8hfIwONCTwjzc2sLr2v51OXdn1uXfaPjzrbEH2HpB7KGXG/eqeQwAVzm/jlNnYKPJFFFpd0krAGVd5btsOUopBwNsMGACJfHzuRxj+0jGIJcdC6b0EPSlfjGbYQAP8+yybrF8pwr8m07uKTBIJjGh/dxrf8EErGZL45cuVqsl9YtUVAbsxOnybqssftDyojmjw6VCx1Xe7rLLqe5jwGRx2LRWlOW8ELF0pAUQqmzoU3v4oBK0bDaTOoEoVktTDL8l6P8UdgCCgIne5tpMZ9/Q==; 3:t35Nd2lJeacNOAmSa4s4geTACO5Zr2Oq+4W9Hc4qt7miSh92tqYL9lXWz1Foi9ZCoIIzT93oRQ0xuhq4s9vBWP20533xKp0Q8jd0OvlKW4z7whSV4ZJvJKEi/+d2pke+6kCrM/zeEi5k56xdfaCK1ABWV9h27A7TtmcqRTTnYvDfR5oy7ZwNBkpXLCbmTuCA/l3amZ/RBhubtVN201uzJvll/6koso+uJ7T/0DqDTFCKVTTvDewvPCfELJDGtJ/yyTqNVdqKqFDkIxnx+Z4HKLRyvF8xcGQBDb/z8013CNSgmoU+xp44GZqF6AdL4ms0 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY2PR03MB571; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(5005006)(520003)(3002001); SRVR:BY2PR03MB571; BCL:0; PCL:0; RULEID:; SRVR:BY2PR03MB571; X-Forefront-PRVS: 0597911EE1 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BY2PR03MB571; 9:bZn8M92FxV0dHEM3P9dggPHiWPHvLVJ6FcwEotqmZ9x?= =?us-ascii?Q?Y7SEAMtIkZDdrMBelx0MausoVABb9FtR5In19Aug86SErr+T73wCgBMQgbBm?= =?us-ascii?Q?mBdOOnxt8ZbOJGQKEx8BXS6PRqzqy+JJfjvQgjtVya8fvctHA5qF2mMENd1l?= =?us-ascii?Q?5YmW8VnQ/4Vc6fB9PlO8Biv1bTRFVinOVoZtqCL0n6ilTIYR3OHn0S1nZDe5?= =?us-ascii?Q?WWGU8eBkiZiqGfCXEhNS0Jjhprbzq959z6wbQuvJIXUdco7XdZWrK8Fu9uvQ?= =?us-ascii?Q?B6YOeIWsxatE98dpFXQSfTf7Cw3Mu0QTFSvuVCWRjVnDuqmzLaXh+kn7N44u?= =?us-ascii?Q?Z9J1Ewo86oLZvA+B8lCSX8NExX7mFRCUsrfTI2WzYKgEBsbhp3I1nDI8XnL6?= =?us-ascii?Q?dyzQO230pmofrO2kzCFQOYHbHyygYLmrNajVdOoqdxY6IamXUnYnxDGSo8BW?= =?us-ascii?Q?MvadwnDgXXcaNxm8V5IrZ2nlaBpQxH9aP5U0Unsmjt2GZolOzTgbl9G2iz5u?= =?us-ascii?Q?Xs97V5NaykQFVp8nOwtT5knWViZVPqr3BrTud6Qkwh8ktVta+qpnAlNV3ESg?= =?us-ascii?Q?FubmiXKVnjdcAHqh4v3IoI51rIhKF5EarRNaRW+7IJQerc+9Y0ASkSVuUDxf?= =?us-ascii?Q?9VYlXelNWN6SWamKKKnpoC2Y/w3GlS9a5KmzN1lRVkwIdyj0wSNpFBEOpe+8?= =?us-ascii?Q?Gthga0DZ+d1C8PM0l29EGKxPl1mO5VUhZ2vmuUzIWaJD1MMddVo9LFH6fGXn?= =?us-ascii?Q?q78rzVCHbljH6BLQdbc56HbZMGNvisz2ayBwncNrjEl8juON5o/gzK0MYDtJ?= =?us-ascii?Q?/xo5y+mKXHkG81uXpBj+tqfhAU/jdPA/eyBOd5rhZZp2PzDJRBl4m/GKDupe?= =?us-ascii?Q?9/MecMhCywLl9Q+WtOGJx5gvHkhy3PJHhXRUBTBWmo6HMDeO5tV3++0xwqk+?= =?us-ascii?Q?WYSzZw0rk676ZAQZ5CXT258UEZR1kmfb109WNRi9cGHIEsoJYcmYFJjddjME?= =?us-ascii?Q?ynh9y6gWZWSGGglieUu9uOHMMa0t21e+A4h2akGN4VA=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; BY2PR03MB571; 3:MA02Zr41gJ6xxptqgA0bIcX5Ft9MAXCMu77JI6PL60dzh9Y4JHV/G3e9ox0wn3Nw6EE16f5heekFm4ANVqrWHgSYivHOT4CO/G3izAE1S5qtaSlDsard1VzYZpuPokivlSuYFV41+j6R8DMVBYunsw==; 10:hlCBMeJe0aSCZ6zBFeYhyv4A/R78kdvJ/9TWsayJiCj0ZhXjYEGijwF7ds8YVn+5ijLanXMUXxPmvfrST4jgF3aJ2/G0XcB5ZbEXgyZ3h2o=; 6:yaNF5/RzUsSdDN4Mr47nszLLtpx4O8nOd7OIoRwI2OE3FN+haFc2drByWGuc3qGg X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Jun 2015 06:29:49.4398 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d; Ip=[192.88.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR03MB571 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tang Yuantian , viresh.kumar@linaro.org, linuxppc-dev@lists.ozlabs.org, cpufreq@vger.kernel.org, linux-pm@vger.kernel.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" From: Tang Yuantian Each time the CPU switches its frequency, the clock nodes in DTS are walked through to find proper clock source. This is very time-consuming, for example, it is up to 500+ us on T4240. Besides, switching time varies from clock to clock. To optimize this, each input clock of CPU is buffered, so that it can be picked up instantly when needed. Since for each CPU each input clock is stored in a pointer which takes 4 or 8 bytes memory and normally there are several input clocks per CPU, that will not take much memory as well. Signed-off-by: Tang Yuantian --- drivers/cpufreq/qoriq-cpufreq.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/drivers/cpufreq/qoriq-cpufreq.c b/drivers/cpufreq/qoriq-cpufreq.c index 88b21ae..358f075 100644 --- a/drivers/cpufreq/qoriq-cpufreq.c +++ b/drivers/cpufreq/qoriq-cpufreq.c @@ -27,11 +27,11 @@ /** * struct cpu_data - * @parent: the parent node of cpu clock + * @pclk: the parent clock of cpu * @table: frequency table */ struct cpu_data { - struct device_node *parent; + struct clk **pclk; struct cpufreq_frequency_table *table; }; @@ -196,7 +196,7 @@ static void freq_table_sort(struct cpufreq_frequency_table *freq_table, static int qoriq_cpufreq_cpu_init(struct cpufreq_policy *policy) { - struct device_node *np; + struct device_node *np, *pnode; int i, count, ret; u32 freq, mask; struct clk *clk; @@ -219,17 +219,23 @@ static int qoriq_cpufreq_cpu_init(struct cpufreq_policy *policy) goto err_nomem2; } - data->parent = of_parse_phandle(np, "clocks", 0); - if (!data->parent) { + pnode = of_parse_phandle(np, "clocks", 0); + if (!pnode) { pr_err("%s: could not get clock information\n", __func__); goto err_nomem2; } - count = of_property_count_strings(data->parent, "clock-names"); + count = of_property_count_strings(pnode, "clock-names"); + data->pclk = kcalloc(count, sizeof(struct clk *), GFP_KERNEL); + if (!data->pclk) { + pr_err("%s: no memory\n", __func__); + goto err_node; + } + table = kcalloc(count + 1, sizeof(*table), GFP_KERNEL); if (!table) { pr_err("%s: no memory\n", __func__); - goto err_node; + goto err_pclk; } if (fmask) @@ -238,7 +244,8 @@ static int qoriq_cpufreq_cpu_init(struct cpufreq_policy *policy) mask = 0x0; for (i = 0; i < count; i++) { - clk = of_clk_get(data->parent, i); + clk = of_clk_get(pnode, i); + data->pclk[i] = clk; freq = clk_get_rate(clk); /* * the clock is valid if its frequency is not masked @@ -273,13 +280,16 @@ static int qoriq_cpufreq_cpu_init(struct cpufreq_policy *policy) policy->cpuinfo.transition_latency = u64temp + 1; of_node_put(np); + of_node_put(pnode); return 0; err_nomem1: kfree(table); +err_pclk: + kfree(data->pclk); err_node: - of_node_put(data->parent); + of_node_put(pnode); err_nomem2: policy->driver_data = NULL; kfree(data); @@ -293,7 +303,7 @@ static int __exit qoriq_cpufreq_cpu_exit(struct cpufreq_policy *policy) { struct cpu_data *data = policy->driver_data; - of_node_put(data->parent); + kfree(data->pclk); kfree(data->table); kfree(data); policy->driver_data = NULL; @@ -307,7 +317,7 @@ static int qoriq_cpufreq_target(struct cpufreq_policy *policy, struct clk *parent; struct cpu_data *data = policy->driver_data; - parent = of_clk_get(data->parent, data->table[index].driver_data); + parent = data->pclk[data->table[index].driver_data]; return clk_set_parent(policy->clk, parent); }