From patchwork Wed Apr 6 07:44:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huang Rui X-Patchwork-Id: 8759031 Return-Path: X-Original-To: patchwork-linux-hwmon@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 0A392C0553 for ; Wed, 6 Apr 2016 07:59:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 26FD320149 for ; Wed, 6 Apr 2016 07:59:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 146842013A for ; Wed, 6 Apr 2016 07:59:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754158AbcDFH74 (ORCPT ); Wed, 6 Apr 2016 03:59:56 -0400 Received: from mail-bn1on0063.outbound.protection.outlook.com ([157.56.110.63]:52640 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753843AbcDFH7z (ORCPT ); Wed, 6 Apr 2016 03:59:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:To:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=CptWto684eo/8Mm+HMJDHjinJsqG/FUYStSaxF/nFaA=; b=oBKt+Oyuf5kKpeuTRgnWZ44V/7bQkKz6eyk4Dqj2hBd5hMa5sMgV1M/CxYjqD3Q4KT5P1O9fnPZnk5g5geGFaMuf9DqPduDQblQ+LULGskOFT4lXoEdkVU8mO4ZTNoyJm9mrUrgdlOg5JcAAb6D4JqEvGx9mMC8unp7PdjkaokE= Received: from DM3PR12CA0031.namprd12.prod.outlook.com (10.164.12.169) by CY1PR12MB0714.namprd12.prod.outlook.com (10.163.238.20) with Microsoft SMTP Server (TLS) id 15.1.447.15; Wed, 6 Apr 2016 07:43:55 +0000 Received: from DM3NAM03FT026.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e49::208) by DM3PR12CA0031.outlook.office365.com (2a01:111:e400:599f::41) with Microsoft SMTP Server (TLS) id 15.1.447.15 via Frontend Transport; Wed, 6 Apr 2016 07:43:55 +0000 Authentication-Results: spf=none (sender IP is 165.204.84.222) smtp.mailfrom=amd.com; alien8.de; dkim=none (message not signed) header.d=none; alien8.de; dmarc=permerror action=none header.from=amd.com; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Received: from atltwp02.amd.com (165.204.84.222) by DM3NAM03FT026.mail.protection.outlook.com (10.152.82.185) with Microsoft SMTP Server id 15.1.453.6 via Frontend Transport; Wed, 6 Apr 2016 07:43:54 +0000 X-WSS-ID: 0O57C51-08-2FQ-02 X-M-MSG: Received: from satlvexedge02.amd.com (satlvexedge02.amd.com [10.177.96.29]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by atltwp02.amd.com (Axway MailGate 5.3.1) with ESMTPS id 26F43D1601C; Wed, 6 Apr 2016 03:43:48 -0400 (EDT) Received: from SATLEXDAG04.amd.com (10.181.40.9) by SATLVEXEDGE02.amd.com (10.177.96.29) with Microsoft SMTP Server (TLS) id 14.3.195.1; Wed, 6 Apr 2016 02:44:26 -0500 Received: from SCYBEXDAG03.amd.com (10.34.11.13) by satlexdag04.amd.com (10.181.40.9) with Microsoft SMTP Server (TLS) id 14.3.266.1; Wed, 6 Apr 2016 03:43:36 -0400 Received: from hr-ub.amd.com (10.237.74.43) by SCYBEXDAG03.amd.com (10.34.11.13) with Microsoft SMTP Server id 14.3.266.1; Wed, 6 Apr 2016 15:43:32 +0800 From: Huang Rui To: Guenter Roeck , Jean Delvare CC: , , "Borislav Petkov" , Sherry Hurwitz , Huang Rui Subject: [PATCH v6 2/6] hwmon: (fam15h_power) Add compute unit accumulated power Date: Wed, 6 Apr 2016 15:44:11 +0800 Message-ID: <1459928655-6071-3-git-send-email-ray.huang@amd.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1459928655-6071-1-git-send-email-ray.huang@amd.com> References: <1459928655-6071-1-git-send-email-ray.huang@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:165.204.84.222; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(2980300002)(428002)(199003)(189002)(5001770100001)(50226001)(586003)(50466002)(81166005)(1220700001)(36756003)(105586002)(2906002)(77096005)(48376002)(19580405001)(4326007)(53416004)(19580395003)(5003940100001)(2950100001)(1096002)(87936001)(86362001)(11100500001)(229853001)(101416001)(92566002)(76176999)(189998001)(5008740100001)(50986999)(5003600100002)(106466001)(33646002)(47776003); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR12MB0714; H:atltwp02.amd.com; FPR:; SPF:None; MLV:sfv; A:1; MX:1; LANG:en; X-MS-Office365-Filtering-Correlation-Id: ced3826b-f777-4883-a966-08d35def348c X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0714; 2:unCRsuRn7VFUPVKec3JkI0URgItoJlhzYHB0j+nbs4fH+1PLCQo8VHGF+sgwVRYgKjc3DD4VdPlTMYIg1t5Dyy1sKytXuMLB5FphWzjvhf6xGvKG21enYzEkJPbavp5cNmLOuA/IfXXIjb1Q+At3h2GC3nEwlWuajBuTfbr0jZy8r2xOrQBIpBNx7z4KQraQ; 3:j1T9tof/GONoZ2qWfQX/3r2ElcMT4MQNbHq9d8ZCGubf/bbzduGPQZ7Z4irlXq0dyi02UlR9FgTMacm6LOPpSIcRx/2IJzoCXEJhORL9QaKPxsR7Ii5ss587NCadJJh2KZqQvQ+btv3Q5hYWlfs2EmsI+vOZDHwGKK2Kz9NWSxq3u7zlKrI95PTh9rYQ1FITC4aJBrZeMDc0Ng4LYiJHd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rhZ4ichIIBwNEvlzdWR5Z0CUfE6MsUhKV67EKSMQ+ISm/mliE2RWGrNXyvpIKjONa2LOOi/c5x7imegaz6Tk9ZQXL7JJXkIAj3K7FuLYzPwixxkcw5aFWc3bh+b1XxdMNoq4YnqLI+GtgTqZMecUJN8YNhQR40mnIMlNiL3ygT1/MjrDKiqBAB/hOoQy9zwlsVh3PIH47zWLeHWXssq+ X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(13017025)(8121501046)(13024025)(13015025)(13023025)(5005006)(13018025)(10201501046)(3002001); SRVR:CY1PR12MB0714; BCL:0; PCL:0; RULEID:; SRVR:CY1PR12MB0714; X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0714; 4:7ELuei0k1sZFII265dvRV8LAWTYrAXzJz08cwJtjmbaYWh33WwoTj+QXfwAg3EqItf4x6wD+SjwcJvhEoJji4/z3gZJvXbM/znuq5OrR+CnAeKWUOsBbpRQ3PsMFikYysHhyDBgiAUufU99FMh5/JsJsiy5tJk10L7ZKBf3+YX3xpQeTh8xRQIMDy6GwhIMTi7zYLP0gNxVGBZm3Lnn4+P4wCjadGb+t0mNeaUag7zG1K+hQx8LiMy4GZoIfVODctSUbEgRKOaP1Qfv9+Whz3bcQBj/Uurh3a/h0ZKzT0vKxSsajDa1P406HMhsOVdMiDwBSZvoVWLEVkzgwU9zoJCpjcNQV3vG9LVGGHVCvYfxmruIV0H0ONpqhVacXDqqGyy1D7z6zG/17ZcHDdXiqw50e9lPWdnmLHV4wEcHRq9LHI3I7BnXZfQEVLEsGcI7Tq3m7fdDtUpndBeqnHH0Lfw== X-Forefront-PRVS: 0904004ECB X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY1PR12MB0714; 23:9mPVAWvb6/s4q5IhHyBZqKsIkvbzphX+w9s2hykCJ?= =?us-ascii?Q?LacQjEzjijNDf6+2N/rcXvP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?Q?oLNyy6tBKh2BppoSqOIKk9i2o3yJKnYgAQijvCAQAhEQB2o8qsn8qskuxHm8?= =?us-ascii?Q?7kRlQZiq1R4GB96cOvX12GN?= X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0714; 5:OOOOft7oUbZBCXupbhPJab0nqtLWd3O8bwDZnuH9IidnjE3kckQ/gxr/6B8ImwLjzTz6bExMVxkDHhMRxm3+s8XAgbxygcGtz/gB8ZKICT6jAYLh1gX9HB9q3C9V77ynd9bzsY3+kSzkPWAc4ncAtg==; 24:r472pSFvCIh27yryF9ZfsOQouq8shd84lIIe6YiKWRBcW/+WFmipKJuRxXAjD/8ErTCsNNTlbglIf20tnmCsFhF6JnidriYnX61I2xGmp2w=; 20:8QHJcrvDjzPlBb4vVDnpFlGyhBqSeMNkX6NCz3YIxTdO+DgfVZfn01Px47OLmZzYFYFP06L47hW42Bw3Sswg5OJmYgkX5lcE7hJ11Yfzv7Ko7YeU7AJY2Oxyd8osZfMcV1O73k+i92Hm7we7MyYc1320VFzBM61c3OZvhmDJgHC0KSlDVa1zYSCGYQnB0ugUX5DaCKkRQjJY1tKxUAeLyiMSB5daSQXkLmbgW+/zvLt1y74VvFwZrvlHlH+3LLDk SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Apr 2016 07:43:54.4719 (UTC) X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.222]; Helo=[atltwp02.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR12MB0714 Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds a member in fam15h_power_data which specifies the compute unit accumulated power. It adds do_read_registers_on_cu to do all the read to all MSRs and run it on one of the online cores on each compute unit with smp_call_function_many(). This behavior can decrease IPI numbers. Suggested-by: Borislav Petkov Signed-off-by: Huang Rui --- drivers/hwmon/fam15h_power.c | 72 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/fam15h_power.c b/drivers/hwmon/fam15h_power.c index 4f695d8..4edbaf0 100644 --- a/drivers/hwmon/fam15h_power.c +++ b/drivers/hwmon/fam15h_power.c @@ -25,6 +25,8 @@ #include #include #include +#include +#include #include #include @@ -44,7 +46,9 @@ MODULE_LICENSE("GPL"); #define FAM15H_MIN_NUM_ATTRS 2 #define FAM15H_NUM_GROUPS 2 +#define MAX_CUS 8 +#define MSR_F15H_CU_PWR_ACCUMULATOR 0xc001007a #define MSR_F15H_CU_MAX_PWR_ACCUMULATOR 0xc001007b #define PCI_DEVICE_ID_AMD_15H_M70H_NB_F4 0x15b4 @@ -59,6 +63,8 @@ struct fam15h_power_data { struct attribute_group group; /* maximum accumulated power of a compute unit */ u64 max_cu_acc_power; + /* accumulated power of the compute units */ + u64 cu_acc_power[MAX_CUS]; }; static ssize_t show_power(struct device *dev, @@ -125,6 +131,70 @@ static ssize_t show_power_crit(struct device *dev, } static DEVICE_ATTR(power1_crit, S_IRUGO, show_power_crit, NULL); +static void do_read_registers_on_cu(void *_data) +{ + struct fam15h_power_data *data = _data; + int cpu, cu; + + cpu = smp_processor_id(); + + /* + * With the new x86 topology modelling, cpu core id actually + * is compute unit id. + */ + cu = cpu_data(cpu).cpu_core_id; + + rdmsrl_safe(MSR_F15H_CU_PWR_ACCUMULATOR, &data->cu_acc_power[cu]); +} + +/* + * This function is only able to be called when CPUID + * Fn8000_0007:EDX[12] is set. + */ +static int read_registers(struct fam15h_power_data *data) +{ + int this_cpu, ret, cpu; + int core, this_core; + cpumask_var_t mask; + + ret = zalloc_cpumask_var(&mask, GFP_KERNEL); + if (!ret) + return -ENOMEM; + + get_online_cpus(); + this_cpu = smp_processor_id(); + + /* + * Choose the first online core of each compute unit, and then + * read their MSR value of power and ptsc in a single IPI, + * because the MSR value of CPU core represent the compute + * unit's. + */ + core = -1; + + for_each_online_cpu(cpu) { + this_core = topology_core_id(cpu); + + if (this_core == core) + continue; + + core = this_core; + + /* get any CPU on this compute unit */ + cpumask_set_cpu(cpumask_any(topology_sibling_cpumask(cpu)), mask); + } + + if (cpumask_test_cpu(this_cpu, mask)) + do_read_registers_on_cu(data); + + smp_call_function_many(mask, do_read_registers_on_cu, data, true); + put_online_cpus(); + + free_cpumask_var(mask); + + return 0; +} + static int fam15h_power_init_attrs(struct pci_dev *pdev, struct fam15h_power_data *data) { @@ -263,7 +333,7 @@ static int fam15h_power_init_data(struct pci_dev *f4, data->max_cu_acc_power = tmp; - return 0; + return read_registers(data); } static int fam15h_power_probe(struct pci_dev *pdev,