From patchwork Mon Jul 9 10:10:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Cherian, George" X-Patchwork-Id: 10514163 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CA37D6032A for ; Mon, 9 Jul 2018 10:11:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD6352899C for ; Mon, 9 Jul 2018 10:11:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A08AF28A7C; Mon, 9 Jul 2018 10:11:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E58962899C for ; Mon, 9 Jul 2018 10:11:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932435AbeGIKLE (ORCPT ); Mon, 9 Jul 2018 06:11:04 -0400 Received: from mail-dm3nam03on0048.outbound.protection.outlook.com ([104.47.41.48]:26701 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932427AbeGIKLD (ORCPT ); Mon, 9 Jul 2018 06:11:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BoF27DPDGOhLxtqHt/Iw+B05KVYyhxROoRK7uzMuljQ=; b=MviMoSBUyNYuEQleBAg5kb1r5zGzhe8ganjyMBICkbfhJYqEwTEkxvGsjBttaxiCCIS7browdTOp4ILU5E0W0DCCeXzyLB8Bab8p7lK9xEMfW7oUAx3+FyT1BU3ilExHy7sE1XCGvAfgo65C4XPiRu4Y8UDEUPrGdowkye1NIec= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=George.Cherian@cavium.com; Received: from sbr2s-28.caveonetworks.com (50.233.148.155) by DM6PR07MB4922.namprd07.prod.outlook.com (2603:10b6:5:2b::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.930.20; Mon, 9 Jul 2018 10:11:00 +0000 From: George Cherian To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Cc: viresh.kumar@linaro.org, rjw@rjwysocki.net, pprakash@codeaurora.org, George Cherian Subject: [PATCH v3] cpufreq / CPPC: Add cpuinfo_cur_freq support for CPPC Date: Mon, 9 Jul 2018 03:10:48 -0700 Message-Id: <1531131048-60762-1-git-send-email-george.cherian@cavium.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Originating-IP: [50.233.148.155] X-ClientProxiedBy: MWHPR1201CA0018.namprd12.prod.outlook.com (2603:10b6:301:4a::28) To DM6PR07MB4922.namprd07.prod.outlook.com (2603:10b6:5:2b::27) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4ce6bf50-8427-4465-b038-08d5e5844573 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989117)(5600053)(711020)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(2017052603328)(7153060)(7193020); SRVR:DM6PR07MB4922; X-Microsoft-Exchange-Diagnostics: 1; DM6PR07MB4922; 3:toyRikxwFamCj+XhGs1pgkWNQjPml69VKGhtw0FU1XmsJC9eJv8YFtrTHkVoZITeuEf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R4Tqba04CgSTXeJXnwbfEGgG0BorSlDLBGCQld+pxMUXHK9d5T3BFbXw7tZ7RkPgqCXcDotb04aTM4nJXopsNVjefrlyChOzIXJmQLVjJRqzSA9c56iBVpoe90qKSWCPuMhjztNjFwiaUBrlCQxZpWRAj0nR5rzOSew2qUoppQr/PB2saXCHnpJCk/mmM8GNpv0V5h9wuMnAPnHou8Jirx/a7aYvHzZ6ICJTUDEPgqeKo3g3end4bH0jN9eVWFGuwHP/QTM/nZMbRG+9+m55ndg6OY7Yl3l5dq; 4:eDzL5HlVx8BpKz6RGpOc2tFfOIYjRKEWeeWuBcpjdGWy6H6qI/YkU9HcmpSjtPxikW2qaBHHiegf1ee5Z4kmlyELZB4RJKaSVlhr7ov3ysSzFHg1bNC6fzOmGIX7xorzHVb2yUnR3drxIN0GKtNOH2y3suWXsOYD7ozjPY8BBA5HQWsWfds+U/3qMaGbOLRwSFOTO6noc5hviCK4WJv9KIQz+AILG2N5U4bu/YJAQWAyKZhDs3URmgpHHLOGhXOnnB37Wf3AdCue/67fjDL7Bg== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231311)(944501410)(52105095)(3002001)(10201501046)(149027)(150027)(6041310)(20161123560045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123558120)(6072148)(201708071742011)(7699016); SRVR:DM6PR07MB4922; BCL:0; PCL:0; RULEID:; SRVR:DM6PR07MB4922; X-Forefront-PRVS: 07283408BE X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(396003)(136003)(39850400004)(346002)(376002)(366004)(189003)(199004)(386003)(6506007)(26005)(81166006)(6512007)(4720700003)(3846002)(6116002)(8676002)(8936002)(81156014)(36756003)(52116002)(6666003)(305945005)(51416003)(53416004)(106356001)(105586002)(25786009)(53936002)(7736002)(2906002)(14444005)(50226002)(68736007)(5660300001)(16526019)(50466002)(107886003)(6486002)(476003)(2616005)(956004)(72206003)(48376002)(478600001)(86362001)(486006)(44832011)(69596002)(16586007)(97736004)(316002)(47776003)(66066001)(4326008)(186003); DIR:OUT; SFP:1101; SCL:1; SRVR:DM6PR07MB4922; H:sbr2s-28.caveonetworks.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM6PR07MB4922; 23:mM5EonxxkMBv171ed1jTpX6xWeB/RM/pQFQFUYz0K?= =?us-ascii?Q?3S8DyrlL9mcC68HFC/IqgiiUETFfA0LbcFNT8R8RrW21MMFKZXRkaIlBtYMr?= =?us-ascii?Q?xvHSgp+TSutrzbyTSH7JREhr40o8JtbUz4XLiuVgQfHCF0zxmvshvQPLArgO?= =?us-ascii?Q?R+UpeExEuiYSsijX9O96ivka32JPOKsvzMmxqEgbl/FrM/YdDEVBs9Tpu9J8?= =?us-ascii?Q?HGwND7T8bcYr3tfiHt3d9c+9xVZw8F7KhU86np4f+uW7kWiLOO6lUaHM6Otj?= =?us-ascii?Q?bZJGq/cRRY0giMjzw2CYf4BJsyQoRd1S53OmUZyzHRwT3pA36KG8C9I/6zr1?= =?us-ascii?Q?a7+gM0AdiupODKKYUs4zOlG+8GY/Mg45r2TR9DhYwYnA3TrAUJ752U7N04Q+?= =?us-ascii?Q?+paUdXX8hc0Jxay8pJEf0/ptMHze2WW3hPzLfIPZuakiyFDp5vS7CxZ1Jav5?= =?us-ascii?Q?bzGIkmEsiwyQNTj2EOU4RJc7ZMiLvtmh4t0ORzgxMb5o+zDY6vtnuZB4HXC4?= =?us-ascii?Q?Akf3xTGWWwpk8WzIlf/gDaBIBh1m52KVGOubcVnKmvUzc6cacbjTORlPERa/?= =?us-ascii?Q?EyuN7oAdxUeA3s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HqanC1SScRgqVRbrzBds9TjiX81DBh6mywXgMxZkKCU8ZgVEUOjbMC2HoOvkc0c/m9wo0JM8ppxJDguo1CY2G+3hidKLvAR2iF+ge4Zvt7L6w6NaacmQP8aVSzhKYGoaairuMwQtHUK19ZnWLbKzI/NcuV1ryozY8uPQlfpH49gPdbKCyVe4VTYaC5bMBJ6Kd X-OriginatorOrg: cavium.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jul 2018 10:11:00.1442 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4ce6bf50-8427-4465-b038-08d5e5844573 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR07MB4922 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Per Section 8.4.7.1.3 of ACPI 6.2, The platform provides performance feedback via set of performance counters. To determine the actual performance level delivered over time, OSPM may read a set of performance counters from the Reference Performance Counter Register and the Delivered Performance Counter Register. OSPM calculates the delivered performance over a given time period by taking a beginning and ending snapshot of both the reference and delivered performance counters, and calculating: delivered_perf = reference_perf X (delta of delivered_perf counter / delta of reference_perf counter). Implement the above and hook this to the cpufreq->get method. Signed-off-by: George Cherian Acked-by: Viresh Kumar --- drivers/cpufreq/cppc_cpufreq.c | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c index a9d3eec..61132e8 100644 --- a/drivers/cpufreq/cppc_cpufreq.c +++ b/drivers/cpufreq/cppc_cpufreq.c @@ -296,10 +296,54 @@ static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) return ret; } +static int cppc_get_rate_from_fbctrs(struct cppc_cpudata *cpu, + struct cppc_perf_fb_ctrs fb_ctrs_t0, + struct cppc_perf_fb_ctrs fb_ctrs_t1) +{ + u64 delta_reference, delta_delivered; + u64 reference_perf, delivered_perf; + + reference_perf = fb_ctrs_t0.reference_perf; + + delta_reference = (u32)fb_ctrs_t1.reference - + (u32)fb_ctrs_t0.reference; + delta_delivered = (u32)fb_ctrs_t1.delivered - + (u32)fb_ctrs_t0.delivered; + + /* Check to avoid divide-by zero */ + if (delta_reference || delta_delivered) + delivered_perf = (reference_perf * delta_delivered) / + delta_reference; + else + delivered_perf = cpu->perf_ctrls.desired_perf; + + return cppc_cpufreq_perf_to_khz(cpu, delivered_perf); +} + +static unsigned int cppc_cpufreq_get_rate(unsigned int cpunum) +{ + struct cppc_perf_fb_ctrs fb_ctrs_t0 = {0}, fb_ctrs_t1 = {0}; + struct cppc_cpudata *cpu = all_cpu_data[cpunum]; + int ret; + + ret = cppc_get_perf_ctrs(cpunum, &fb_ctrs_t0); + if (ret) + return ret; + + udelay(2); /* 2usec delay between sampling */ + + ret = cppc_get_perf_ctrs(cpunum, &fb_ctrs_t1); + if (ret) + return ret; + + return cppc_get_rate_from_fbctrs(cpu, fb_ctrs_t0, fb_ctrs_t1); +} + static struct cpufreq_driver cppc_cpufreq_driver = { .flags = CPUFREQ_CONST_LOOPS, .verify = cppc_verify_policy, .target = cppc_cpufreq_set_target, + .get = cppc_cpufreq_get_rate, .init = cppc_cpufreq_cpu_init, .stop_cpu = cppc_cpufreq_stop_cpu, .name = "cppc_cpufreq",