Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp360559imm; Mon, 9 Jul 2018 03:12:13 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe4BPO80w3v9K3ddZvpE1J0MGhOuU4X79TnpZZp1Zy24BhFijtl5iP5QNL8s1+4zUPvgke5 X-Received: by 2002:a62:2983:: with SMTP id p125-v6mr6553458pfp.128.1531131133239; Mon, 09 Jul 2018 03:12:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531131133; cv=none; d=google.com; s=arc-20160816; b=1CNBYIqQzvTC512NfArQ1AlO8en0ip8EXaUlkdI5LQTUdUWlhv5tFjmewI53CPmvAS EaJdAUzKSIm5KKYjbbxEomnl9LpeZ4aFllwWl+pNrZGNTvstbHXMBrAF2dvOVpR48gwm CG20L+3QqH1VkOFf331P1/FphpiF46m3vVBEPUJ7ETie8gnjXotypkQypu9a4+jt5HGg /NKb/1xFKQTh4CsAOfUFkOZN5BXIGbsKW95EU40+0RGU9yO21Xxel5nys5Yd7VYMWqtk wShNQ2o+d5WJKDSFUXkdSOAeHUCwkv3/T1efIpJrZtw/xkpivhh2FEKZIT6tblM6AB9O 3S/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:mime-version:message-id:date:subject:cc:to :from:dkim-signature:arc-authentication-results; bh=BoF27DPDGOhLxtqHt/Iw+B05KVYyhxROoRK7uzMuljQ=; b=OhF5Pzgnb3e6WjcizuvjCyPbLJema3AFHH8svRqGtvbVp+Bt8+pAfIxUb8DArTdNEz 3YWaUetzPjvOUIZvdhZvqJP/O+0RmS33aEy+4b+9thAY+fRJof+zsk3X6W3ZywzNIwtH Ir5qdJuJ3/P+plXfTrvaTb3JP+4oUQAcA7bvLnZrdxuFtH9/SN7MBaxeOwUvDgeTj4W2 dA1tiT54enADRCxFBeNqgdSSqA7dKW291HLIT8TOMMIIv4OR1NgOLioKJsHhMaPGmFUq DIuMGMm4LdVB7b9AcPA/5A40E6lDeB5ZxXFH4aq0VZrl6CuvXvh1hZYhZ22+AfQR7MKW Uk0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@CAVIUMNETWORKS.onmicrosoft.com header.s=selector1-cavium-com header.b=MviMoSBU; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j30-v6si7884255pgm.26.2018.07.09.03.11.58; Mon, 09 Jul 2018 03:12:13 -0700 (PDT) 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=@CAVIUMNETWORKS.onmicrosoft.com header.s=selector1-cavium-com header.b=MviMoSBU; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932670AbeGIKLF (ORCPT + 99 others); Mon, 9 Jul 2018 06:11:05 -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 Content-Type: text/plain 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+XhGs1pgkWNQjPml69VKGhtw0FU1XmsJC9eJv8YFtrTHkVoZITeuEfb8lJDeMl/TncWsx1yDkuLQE5KuTyAhU7e5p1a0DeuOY0K3w7D+XUu0w5L34W83+vG6n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otb04aTM4nJXopsNVjefrlyChOzIXJmQLVjJRqzSA9c56iBVpoe90qKSWCPuMhjztNjFwiaUBrlCQxZpWRAj0nR5rzOSew2qUoppQr/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?EyuN7oAdxUeA3sNSua0/jEDZw5vMXjV+NW3/AoP6sdh3x3yt57QmnDFgc8N6?= =?us-ascii?Q?RYaDbBPMbj2D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guo1CY2G+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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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", -- 1.8.3.1