From patchwork Fri Apr 24 03:20:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naveen Krishna Chatradhi X-Patchwork-Id: 11506973 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3F179159A for ; Fri, 24 Apr 2020 03:21:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 12E702076C for ; Fri, 24 Apr 2020 03:21:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="sTfXuk4Y" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726008AbgDXDVT (ORCPT ); Thu, 23 Apr 2020 23:21:19 -0400 Received: from mail-dm6nam11on2071.outbound.protection.outlook.com ([40.107.223.71]:20801 "EHLO NAM11-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725884AbgDXDVT (ORCPT ); Thu, 23 Apr 2020 23:21:19 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OKKFs59VCJnkMHGvuVLnPrrU5PgTJLvvFLjrfHbO9fmhpbENvNCy8DuoPmZ6MfZarrF8XBDQoG1KdiImz1Kz0mmZ6xFL3pkY3DuzeeihOoY+qBA1aJpvIgR6pAh3r9QpJPp+xuLL1FeZFxCgr3/INsPDk+39IPGHk8zNaBoEVIKktO1uUMjRPWzDor7mokJ3UJEP4Uy6HJom3JkZhQ1c2zVuBySgBA6pTH0JpY0GDcf1YvwAPFJ7M8NLlpqrJ2SrmiSxyIcAVOO/qSHBA1dx1T71pdkUnrvh+55j5HE0i2iYHUkynE6y8mdgE8DVfpZpqCurygwiZXwEeR0C1IgLmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JnNkfG0kuMTAV8XgMDs+7CtU/KT8ovce5K50uBKz1f0=; b=Z7E8I+LhdjfQDxktSFZjuu9vUsSKFZ5KBG3n2saWCrJ4p1ze+gtfDAC33aFWpxZIh67fthA/qj9fKMDIahcBa47teJcxiOPR/IKxpTwuwi+SF+KkrxwdvCXzwBvTz+JBsSk7a5fdNCXZ1ujbISxHihZl5kSdeKlQKjrk8gGtPn31Ry0X4Zn5ZctB5CLb6k7MkG6dPGsPgdDz0hH7QEFuByHtS9CMUeJQGMTcGLnTKXCGV8xAUTlNMiECCP/p7IVxEpNDcVPRNu/hvU1i9lSweGcKfEXCwc0bSHSbppdqJFCY8VxBXXtrZFTkkbsGnbXHSeyMXOnGaVbryM49hROahQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JnNkfG0kuMTAV8XgMDs+7CtU/KT8ovce5K50uBKz1f0=; b=sTfXuk4YV0tL7iKj8MXWSL75EanSwJpQnZTHVzmizpP4dJj8P9XrvgsVqrNvvY2l2z+gli72DSxrL9VJ85If2hKpbLEwxiDQ6gfdL1L9rxaTS3sOyQLAHwGrRL5X4cp93qbZGxm85G5Cg2KTVGtQ0pWW+k5lw1gI65foJCSX6/c= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=NaveenKrishna.Chatradhi@amd.com; Received: from BY5PR12MB4212.namprd12.prod.outlook.com (2603:10b6:a03:202::8) by BY5PR12MB3955.namprd12.prod.outlook.com (2603:10b6:a03:1a2::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2921.29; Fri, 24 Apr 2020 03:21:15 +0000 Received: from BY5PR12MB4212.namprd12.prod.outlook.com ([fe80::9ce:3ab2:f0ee:47b2]) by BY5PR12MB4212.namprd12.prod.outlook.com ([fe80::9ce:3ab2:f0ee:47b2%5]) with mapi id 15.20.2921.030; Fri, 24 Apr 2020 03:21:15 +0000 From: Naveen Krishna Chatradhi To: linux-hwmon@vger.kernel.org Cc: naveenkrishna.ch@gmail.com, Naveen Krishna Chatradhi , Guenter Roeck Subject: [PATCH v4 1/3] hwmon: Add amd_energy driver to report energy counters Date: Fri, 24 Apr 2020 08:50:54 +0530 Message-Id: <20200424032056.16287-1-nchatrad@amd.com> X-Mailer: git-send-email 2.17.1 X-ClientProxiedBy: MA1PR01CA0107.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::23) To BY5PR12MB4212.namprd12.prod.outlook.com (2603:10b6:a03:202::8) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from milan-ETHANOL-X.amd.com (165.204.156.251) by MA1PR01CA0107.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.13 via Frontend Transport; Fri, 24 Apr 2020 03:21:13 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [165.204.156.251] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 0828a835-307f-4963-e019-08d7e7fe8bbf X-MS-TrafficTypeDiagnostic: BY5PR12MB3955:|BY5PR12MB3955: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:352; X-Forefront-PRVS: 03838E948C X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR12MB4212.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(10009020)(4636009)(376002)(396003)(346002)(39860400002)(366004)(136003)(81156014)(956004)(6916009)(66476007)(16526019)(66556008)(1076003)(66946007)(8936002)(8676002)(4326008)(5660300002)(54906003)(2616005)(186003)(26005)(2906002)(36756003)(7696005)(316002)(6666004)(6486002)(52116002)(478600001)(6606295002);DIR:OUT;SFP:1101; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: D97G1zdYjv52den3hmvt0sx3hKP7TLBTHzdoE9Tkmt6crC1+h/g0U6ZPKmBPjHRs5z8lvNRLu2occPIvDCCCZa16Eyy57GEHCOF9s57d/9rh4LVwes1PqkijZLrZXVY7Gd9RE4o2T1vwHLOwypH1l/ED03+64DeXE8X3dE1Gvad9y+lQnCrjri5G94g5izcZVrBnxjU0xCjqVNk2t00Kl7mTwG8rrIjxMDBFBHSYsJzelLA8ZG0uoLrFh3c/n7AfFgkpU9JcXham7tBeo+ZoMx4TOmcbu1eNqoE8v8anpcThxEbRD5WAJYXoQzuiQCgKsAyDBSDytwxj3JFjSOQ0xcodIt7Kon/C9tRV7Ob+GDV6BjIfrXv5AeYXDBkLwEOvsUZ7hkxuIygvjO3uZ98n+j/pxBsxaupbcK+F2rh3FmUwWC9ByuVIjrWF9ko/KM+TxmN5lCu27gFfv3X65fUpTRe1gqgaNX8kpcTvfVxRG+bHAI/mY2GXgvYErg+ZunFh X-MS-Exchange-AntiSpam-MessageData: JTU+neMD4vP/jMHny5xqyOtO5oN/prViMz7pLb0dDLbqFzqJPYlguFZaRrnOATOQWcd2liEhGl4YlA9ZFf1wH/V4Lz4efpsqcryG8bKhYuAcZB7ITY+AqXy6zUaQAGc0N8huMCkGjmNM7fgkUedyKQ== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0828a835-307f-4963-e019-08d7e7fe8bbf X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Apr 2020 03:21:15.0831 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: hQu25WpPIV8bkcy9uSx0nPY3lKXP6pog/PxBtMqpaak4yLwDk+sf2t7cVN4WM50urwRyWfFcROjAD9qR2fsrpQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB3955 Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org This patch adds hwmon based amd_energy driver support for family 17h processors from AMD. The driver provides following interface to the userspace 1. Reports the per core consumption * file: "energy%d_input", label: "Ecore%03d" 2. Reports per socket energy consumption * file: "energy%d_input", label: "Esocket%d" 2. Reports scaled energy value in Joules. Cc: Guenter Roeck Signed-off-by: Naveen Krishna Chatradhi --- Changes in v4: 1. Use num_present_cpus() instead num_online_cpu(), as the latter does not take offline cpus into account. 2. run checkpatch.pl --strict and fix alignment issues 3. Fixed other comments from Guenter Roeck drivers/hwmon/Kconfig | 10 ++ drivers/hwmon/Makefile | 1 + drivers/hwmon/amd_energy.c | 250 +++++++++++++++++++++++++++++++++++++ 3 files changed, 261 insertions(+) create mode 100644 drivers/hwmon/amd_energy.c diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index 4c62f900bf7e..e165e10c49ef 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -324,6 +324,16 @@ config SENSORS_FAM15H_POWER This driver can also be built as a module. If so, the module will be called fam15h_power. +config SENSORS_AMD_ENERGY + tristate "AMD RAPL MSR based Energy driver" + depends on X86 + help + If you say yes here you get support for core and package energy + sensors, based on RAPL MSR for AMD family 17h and above CPUs. + + This driver can also be built as a module. If so, the module + will be called as amd_energy. + config SENSORS_APPLESMC tristate "Apple SMC (Motion sensor, light sensor, keyboard backlight)" depends on INPUT && X86 diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile index b0b9c8e57176..318f89dc7133 100644 --- a/drivers/hwmon/Makefile +++ b/drivers/hwmon/Makefile @@ -45,6 +45,7 @@ obj-$(CONFIG_SENSORS_ADT7411) += adt7411.o obj-$(CONFIG_SENSORS_ADT7462) += adt7462.o obj-$(CONFIG_SENSORS_ADT7470) += adt7470.o obj-$(CONFIG_SENSORS_ADT7475) += adt7475.o +obj-$(CONFIG_SENSORS_AMD_ENERGY) += amd_energy.o obj-$(CONFIG_SENSORS_APPLESMC) += applesmc.o obj-$(CONFIG_SENSORS_ARM_SCMI) += scmi-hwmon.o obj-$(CONFIG_SENSORS_ARM_SCPI) += scpi-hwmon.o diff --git a/drivers/hwmon/amd_energy.c b/drivers/hwmon/amd_energy.c new file mode 100644 index 000000000000..7162c80edd10 --- /dev/null +++ b/drivers/hwmon/amd_energy.c @@ -0,0 +1,250 @@ +// SPDX-License-Identifier: GPL-2.0-only + +/* + * Copyright (C) 2020 Advanced Micro Devices, Inc. + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define DRVNAME "amd_energy" + +#define ENERGY_PWR_UNIT_MSR 0xC0010299 +#define ENERGY_CORE_MSR 0xC001029A +#define ENERGY_PKG_MSR 0xC001029B + +#define AMD_TIME_UNIT_MASK 0xF0000 +#define AMD_ENERGY_UNIT_MASK 0x01F00 +#define AMD_POWER_UNIT_MASK 0x0000F + +#define ENERGY_STATUS_MASK 0xffffffff + +#define AMD_FAM_17 0x17 /* ZP, SSP */ + +/* Useful macros */ +#define AMD_CPU_FAM_ANY(_family, _model) \ +{ \ + .vendor = X86_VENDOR_AMD, \ + .family = _family, \ + .model = _model, \ + .feature = X86_FEATURE_ANY, \ +} + +#define AMD_CPU_FAM(_model) \ + AMD_CPU_FAM_ANY(AMD_FAM_##_model, X86_MODEL_ANY) + +struct amd_energy_data { + struct hwmon_channel_info energy_info; + const struct hwmon_channel_info *info[2]; + struct hwmon_chip_info chip; +}; + +static int nr_cpus, nr_socks; +static u64 energy_units; + +static int amd_energy_read_labels(struct device *dev, + enum hwmon_sensor_types type, + u32 attr, int channel, + const char **str) +{ + char *buf = devm_kcalloc(dev, 10, sizeof(char), GFP_KERNEL); + + if (channel >= nr_cpus) + scnprintf(buf, 9, "Esocket%u", channel - nr_cpus); + else + scnprintf(buf, 9, "Ecore%03u", channel); + + *str = buf; + + return 0; +} + +static int get_energy_units(void) +{ + u64 rapl_units; + int ret; + + ret = rdmsrl_safe(ENERGY_PWR_UNIT_MSR, &rapl_units); + if (ret) + return -EAGAIN; + + energy_units = (rapl_units & AMD_ENERGY_UNIT_MASK) >> 8; + return 0; +} + +static int amd_energy_read(struct device *dev, + enum hwmon_sensor_types type, + u32 attr, int channel, long *val) +{ + u64 value; + int cpu, ret; + u32 reg; + + if (channel >= nr_cpus) { + reg = ENERGY_PKG_MSR; + cpu = cpumask_first_and(cpu_online_mask, + cpumask_of_node + (channel - nr_cpus)); + } else { + reg = ENERGY_CORE_MSR; + cpu = channel; + } + + if (!cpu_online(cpu)) + return -ENODEV; + + ret = rdmsrl_safe_on_cpu(cpu, reg, &value); + if (ret) + return -EAGAIN; + + if (energy_units == 0 && get_energy_units()) + return -EAGAIN; + + /* Energy consumed = (1/(2^ESU) * RAW * 1000000UL) Joules */ + *val = (long)value * div64_ul(1000000UL, BIT(energy_units)); + + return 0; +} + +static umode_t amd_energy_is_visible(const void *_data, + enum hwmon_sensor_types type, + u32 attr, int channel) +{ + return 0444; +} + +static const struct hwmon_ops amd_energy_ops = { + .is_visible = amd_energy_is_visible, + .read = amd_energy_read, + .read_string = amd_energy_read_labels, +}; + +static int amd_create_sensor(struct device *dev, + struct amd_energy_data *data, + u8 type, u32 config) +{ + int i; + u32 *s_config; + struct hwmon_channel_info *info = &data->energy_info; + + nr_socks = num_possible_nodes(); + nr_cpus = num_present_cpus(); + + s_config = devm_kcalloc(dev, nr_cpus + nr_socks, + sizeof(u32), GFP_KERNEL); + if (!s_config) + return -ENOMEM; + + info->type = type; + info->config = s_config; + + for (i = 0; i < nr_cpus + nr_socks; i++) + s_config[i] = config; + + return 0; +} + +static int amd_energy_probe(struct platform_device *pdev) +{ + struct device *hwmon_dev; + struct amd_energy_data *data; + struct device *dev = &pdev->dev; + int ret; + + ret = get_energy_units(); + + data = devm_kzalloc(dev, sizeof(struct amd_energy_data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + data->chip.ops = &amd_energy_ops; + data->chip.info = data->info; + + /* Populate per-core energy reporting */ + data->info[0] = &data->energy_info; + amd_create_sensor(dev, data, hwmon_energy, + HWMON_E_INPUT | HWMON_E_LABEL); + + hwmon_dev = devm_hwmon_device_register_with_info(dev, DRVNAME, + data, + &data->chip, + NULL); + return PTR_ERR_OR_ZERO(hwmon_dev); +} + +static int amd_energy_remove(struct platform_device *pdev) +{ + return 0; +} + +static const struct platform_device_id amd_energy_ids[] = { + { .name = DRVNAME, }, + {} +}; +MODULE_DEVICE_TABLE(platform, amd_energy_ids); + +static struct platform_driver amd_energy_driver = { + .probe = amd_energy_probe, + .remove = amd_energy_remove, + .id_table = amd_energy_ids, + .driver = { + .name = DRVNAME, + }, +}; + +static struct platform_device *amd_energy_platdev; + +static const struct x86_cpu_id cpu_ids[] __initconst = { + AMD_CPU_FAM(17), + {} +}; +MODULE_DEVICE_TABLE(x86cpu, cpu_ids); + +static int __init amd_energy_init(void) +{ + int ret; + + if (!x86_match_cpu(cpu_ids)) + return -ENODEV; + + ret = platform_driver_register(&amd_energy_driver); + if (ret < 0) + return ret; + + amd_energy_platdev = platform_device_alloc(DRVNAME, 0); + if (!amd_energy_platdev) + return -ENOMEM; + + ret = platform_device_add(amd_energy_platdev); + if (ret) { + platform_device_unregister(amd_energy_platdev); + return ret; + } + + return ret; +} + +static void __exit amd_energy_exit(void) +{ + platform_device_unregister(amd_energy_platdev); + platform_driver_unregister(&amd_energy_driver); +} + +module_init(amd_energy_init); +module_exit(amd_energy_exit); + +MODULE_DESCRIPTION("Driver for AMD Energy reporting from RAPL MSR via HWMON interface"); +MODULE_AUTHOR("Naveen Krishna Chatradhi "); +MODULE_LICENSE("GPL"); From patchwork Fri Apr 24 03:20:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naveen Krishna Chatradhi X-Patchwork-Id: 11506975 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 870ED159A for ; Fri, 24 Apr 2020 03:21:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6AB8B2076C for ; Fri, 24 Apr 2020 03:21:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="p4U4ORt8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726021AbgDXDVX (ORCPT ); Thu, 23 Apr 2020 23:21:23 -0400 Received: from mail-dm6nam11on2050.outbound.protection.outlook.com ([40.107.223.50]:31073 "EHLO NAM11-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725884AbgDXDVW (ORCPT ); Thu, 23 Apr 2020 23:21:22 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LCRPWQORj6WRMQwYvya1f3Ywc4xD1E7syV3Gt3++Cg2cQVnmNg4NSwbja9tetdNSD/cywSWatZi967BCDU27ZZq2i5L0yCKXwV8d2xQ+FCLJAFeEO/pogHhe5434aHfnfCHtsehcQXY9ViUBQ1sIpGtTBa5dVpzqVjnQm6hBMCxJZ8k1RGf/4X0tS2Md1eKDN+0mSsk5/HS7FAS/Ni7pvKW4aARHFKHJVolu7tkPSvKsndwQsK0SQm1DiXhEtdZZ8JP7u+3+2fpNK4Ds8XJicrvHjOpySC04UXdMi/fpGcKFMLCz8gQ/vDcLLQ0ZZbKroSg9V+zJJCHkk02KZZHi+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lSR22TUukp1gpG9OuAAIOnzx4NQnGtXa/dd87ozyB5g=; b=ATyL2w22j5vLBjq4erVwfNcgsylnI8a8nyRcTp0Wdr5bzQluSpb+VRuiburAWlqmmzKj50F/kCcFRC/PwDoxxzNwc48+vO510MFTH7ZDOvGqSxX+njVZwTytEdCOi7ZTZlJquKxm/zP7FZRzeltY0X6V4j0uqzVJxOlLemOc2owea7Eff13/XP+UfQZ9kooRxcEPTqNMyDMrP35BDpkwGaKuu4TrYEKwbGuW0gRaInzPyhWCvp05k2bf8+6rJhnGhOxW/wbDE1YBD45pIlrJsWqLgy8TYnHN8W9mGdOAK1cxXTvHUErIoB4fECqkxGtAxzXYd8cnOon9E0WFcIOqHA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lSR22TUukp1gpG9OuAAIOnzx4NQnGtXa/dd87ozyB5g=; b=p4U4ORt8/k+nRfPY1nrmSI9MajHVOeQSq3oNssZ93YnmokCGuy8sPE700KwlPi9KMhBvirihSOvdEh7GCT/8jPrHghVL6B75dJcLaX/waxNFqQ28yre3sRIKW/XHveNWclSrBzTtNu4nNnwA6OtKhaITa4YMGqFzRExHLnbH9KI= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=NaveenKrishna.Chatradhi@amd.com; Received: from BY5PR12MB4212.namprd12.prod.outlook.com (2603:10b6:a03:202::8) by BY5PR12MB3955.namprd12.prod.outlook.com (2603:10b6:a03:1a2::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2921.29; Fri, 24 Apr 2020 03:21:20 +0000 Received: from BY5PR12MB4212.namprd12.prod.outlook.com ([fe80::9ce:3ab2:f0ee:47b2]) by BY5PR12MB4212.namprd12.prod.outlook.com ([fe80::9ce:3ab2:f0ee:47b2%5]) with mapi id 15.20.2921.030; Fri, 24 Apr 2020 03:21:20 +0000 From: Naveen Krishna Chatradhi To: linux-hwmon@vger.kernel.org Cc: naveenkrishna.ch@gmail.com, Naveen Krishna Chatradhi , Guenter Roeck Subject: [PATCH v4 2/3] hwmon: (amd_energy) Add documentation Date: Fri, 24 Apr 2020 08:50:55 +0530 Message-Id: <20200424032056.16287-2-nchatrad@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200424032056.16287-1-nchatrad@amd.com> References: <20200424032056.16287-1-nchatrad@amd.com> X-ClientProxiedBy: MA1PR01CA0107.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::23) To BY5PR12MB4212.namprd12.prod.outlook.com (2603:10b6:a03:202::8) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from milan-ETHANOL-X.amd.com (165.204.156.251) by MA1PR01CA0107.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.13 via Frontend Transport; Fri, 24 Apr 2020 03:21:18 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [165.204.156.251] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: dfa6377a-47fe-4c0f-c88e-08d7e7fe8ea4 X-MS-TrafficTypeDiagnostic: BY5PR12MB3955:|BY5PR12MB3955: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-Forefront-PRVS: 03838E948C X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR12MB4212.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(10009020)(4636009)(376002)(396003)(346002)(39860400002)(366004)(136003)(81156014)(956004)(6916009)(66476007)(16526019)(66556008)(1076003)(66946007)(8936002)(8676002)(4326008)(5660300002)(54906003)(2616005)(186003)(26005)(2906002)(36756003)(7696005)(316002)(6666004)(6486002)(52116002)(478600001)(966005)(24770200002)(43620500001);DIR:OUT;SFP:1101; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SuhEHeqrLf6gN2eq4r1FjsmpP9P4VtRHFZn7n3kiG7HAaMthU1gyO/ctJ3EzMsi5TpHddZHd4sD51YNhkjDvh9IEd2bfcZy9+aBvAQb/RZLlqcO/kLLf9I1YcO4WnjjC/CaDDspCu8b6IrM1H8davUfxih4jqo8VRDxKuBzmR2EK02+o9lOeuaSZGx2R7xWIEKBj2yd11PMvMTqusMWHddLjEoNasL6AjM00Jb3q5fVVm66OujXsRUEQEjhVsURF9qKtWNPmwHx6auTLBCYmvAI7W6ippuFn8PUtytyZqMAaoIstiMp23MIQwsStXIDgf7rWxXHMXlAjIpEbb5m+9v0cG5wiBrO6pCpledBSUYAoH1ZvOr6ZCI7fLQDQopKxZXHd1qNmFxPrL4NIoTB+rV5mYHbGvvSx+hg8lllxXSYFYTYJQ0Mz/TO3M6wkMJmsGoJ9GE6PnQAfTIjRMC1YTllfgK1Y4izXUVaL54ETzY9VaugzbxEpYkAaFR3WY0zYw+3sc9eHDdNF2sZEePBQMG8n04Q1IXx+1YbBICAGeJL7f7JItFT4l2FF40R9AfyGPwWGNeYmIxgUmRYPPCLzk0Ga6BMfBqC6nt8VXrVwhPsGIbtZruh0guNB8uZp9XD6 X-MS-Exchange-AntiSpam-MessageData: p5CaETY+XmpB56wLNbMIRS87bymYO5H2T3ldk+YZ2VPUbPb4hun9iSAx1ePfa0LNh3sfi1ag7pWan1z6702HKZ/QR3bfkteWFhO9yoaOaP/c6LpZj+Z9uBqx96KvSEUdVBsiu18AWC3RiAQlf2hFhQ== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: dfa6377a-47fe-4c0f-c88e-08d7e7fe8ea4 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Apr 2020 03:21:19.9337 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 1VVI0zPoVXkwk2cY/PE2kTpaOUmAJpIeFi0Z7OSLVzotOLlBMy2D0poBL6H/ll68yibMWK65G2rQKnJAnkbU1w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB3955 Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Document amd_energy driver with all chips supported by it. Cc: Guenter Roeck Signed-off-by: Naveen Krishna Chatradhi --- Changes in v4: None Documentation/hwmon/amd_energy.rst | 84 ++++++++++++++++++++++++++++++ Documentation/hwmon/index.rst | 1 + 2 files changed, 85 insertions(+) create mode 100644 Documentation/hwmon/amd_energy.rst diff --git a/Documentation/hwmon/amd_energy.rst b/Documentation/hwmon/amd_energy.rst new file mode 100644 index 000000000000..b5d176deec1d --- /dev/null +++ b/Documentation/hwmon/amd_energy.rst @@ -0,0 +1,84 @@ +.. SPDX-License-Identifier: GPL-2.0 + +Kernel driver amd_energy +========================== + +Supported chips: + +* AMD Family 17h Processors + + Prefix: 'amd_energy' + + Addresses used: RAPL MSRs + + Datasheets: + + - Processor Programming Reference (PPR) for AMD Family 17h Model 01h, Revision B1 Processors + + https://developer.amd.com/wp-content/resources/55570-B1_PUB.zip + + - Preliminary Processor Programming Reference (PPR) for AMD Family 17h Model 31h, Revision B0 Processors + + https://developer.amd.com/wp-content/resources/56176_ppr_Family_17h_Model_71h_B0_pub_Rev_3.06.zip + +Author: Naveen Krishna Chatradhi + +Description +----------- + +The Energy driver exposes the energy counters that are +reported via the Running Average Power Limit (RAPL) +Model-specific Registers (MSRs) via the hardware monitor +(HWMON) sysfs interface. + +1. Power, Energy and Time Units + MSR_RAPL_POWER_UNIT/ C001_0299: + shared with all cores in the socket + +2. Energy consumed by each Core + MSR_CORE_ENERGY_STATUS/ C001_029A: + 32-bitRO, Accumulator, core-level power reporting + +3. Energy consumed by Socket + MSR_PACKAGE_ENERGY_STATUS/ C001_029B: + 32-bitRO, Accumulator, socket-level power reporting, + shared with all cores in socket + +These registers are updated every 1ms and cleared on +reset of the system. + +Energy Caluclation +------------------ + +Energy information (in Joules) is based on the multiplier, +1/2^ESU; where ESU is an unsigned integer read from +MSR_RAPL_POWER_UNIT register. Default value is 10000b, +indicating energy status unit is 15.3 micro-Joules increment. + +Reported values are scaled as per the formula + +scaled value = ((1/2^ESU) * (Raw value) * 1000000UL) in Joules + +Users calculate power for a given domain by calculating + dEnergy/dTime for that domain. + +Sysfs attributes +---------------- + +=============== ======== ===================================== +Attribute Label Description +=============== ======== ===================================== + +* For index N between [1] and [nr_cpus] + +=============== ======== ====================================== +energy[N]_input EcoreX Core Energy X = [0] to [nr_cpus - 1] + Measured input core energy +=============== ======== ====================================== + +* For N between [nr_cpus] and [nr_cpus + nr_socks] + +=============== ======== ====================================== +energy[N]_input EsocketX Socket Energy X = [0] to [nr_socks -1] + Measured input socket energy +=============== ======== ====================================== diff --git a/Documentation/hwmon/index.rst b/Documentation/hwmon/index.rst index 8ef62fd39787..fc4b89810e67 100644 --- a/Documentation/hwmon/index.rst +++ b/Documentation/hwmon/index.rst @@ -39,6 +39,7 @@ Hardware Monitoring Kernel Drivers adt7470 adt7475 amc6821 + amd_energy asb100 asc7621 aspeed-pwm-tacho From patchwork Fri Apr 24 03:20:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naveen Krishna Chatradhi X-Patchwork-Id: 11506977 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 71EB592C for ; Fri, 24 Apr 2020 03:21:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5A8C42076C for ; Fri, 24 Apr 2020 03:21:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="skWc1iR8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726027AbgDXDV1 (ORCPT ); Thu, 23 Apr 2020 23:21:27 -0400 Received: from mail-eopbgr680056.outbound.protection.outlook.com ([40.107.68.56]:10979 "EHLO NAM04-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725884AbgDXDV0 (ORCPT ); Thu, 23 Apr 2020 23:21:26 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UTQd4Qqldl+0xT8fD1qbJ5Duz9Y54Y4NfhvqJaZes8dW4+GM2VzdXHRqE+vkCpddSEMl5Dc7hXlXWU3bYBHkamSwATADMu9EgsKD6n8DMD+z1+CB6H0VjfyIpLmq9rR5A5lCdg5RKdF8tmoUciL9aeveQRnvPuVBTsw0McZv1EFK56tFxz/VC2dSA5n6wLlMi3wGsmPothi9QGjELAcsRrjvRQPwb66pEqtIKjswrc0/X6fa0jzbGlqiz24J6AvRU/aDJtfUQlJyiwBj8ecY5ZWpIjkQ4iDriBmX1ZZcFM+0D0aHu0PCYpwuAckr6I7FFPn4gXDC0Z1H2CN/zqBDTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WQu+yqJA0IuYA0rOk+WOVsOYlL/zuXxW1+McOfixBzI=; b=LeJ6Qno3vSlcviFiDTD9MIYHD4ug0T/DZ9kYREwjIy006XibelcDeXeCwSieuUp9P5UJUe0J/eyvvY2+/b4QejsC3T2agaTPtnoRJjR5RTupvQMBwJxM774lI6YgAYfFFmBBHC02YELIG9o5l+vDY+nIl1uZmRYRI+DG2TAM86WnEt0ZjwWSnYU8JaUjHRJGOxHW7tNybxAIBNRK/sH8cKAAIznC5cC3DOLxgV3w4T3/eU0oiu8SyyT+edop/M4yLWjjHBWFZslb2i3jQnJbdAqKDb67ZwNegKu0SDiU1d5PCRCpDIltGUMZOgKk1nmSDcQkOLBuTHUf48jA69WQAQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WQu+yqJA0IuYA0rOk+WOVsOYlL/zuXxW1+McOfixBzI=; b=skWc1iR8z+AM2FnQxTGgoaWBGg3xz0joUuz4shim2T1B94E6pk84SBBybIYzROPLTwgw0gKTuORWhdT8Vp31cPwsk1mw4yvxlIVHCsFm4wLGrK4+uLmDriukPacvSP+KCq8A9hiH3MpojgtZ7YZbZzY5Qla48W2vx1bZOLHR160= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=NaveenKrishna.Chatradhi@amd.com; Received: from BY5PR12MB4212.namprd12.prod.outlook.com (2603:10b6:a03:202::8) by BY5PR12MB3826.namprd12.prod.outlook.com (2603:10b6:a03:1a1::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2921.29; Fri, 24 Apr 2020 03:21:24 +0000 Received: from BY5PR12MB4212.namprd12.prod.outlook.com ([fe80::9ce:3ab2:f0ee:47b2]) by BY5PR12MB4212.namprd12.prod.outlook.com ([fe80::9ce:3ab2:f0ee:47b2%5]) with mapi id 15.20.2921.030; Fri, 24 Apr 2020 03:21:24 +0000 From: Naveen Krishna Chatradhi To: linux-hwmon@vger.kernel.org Cc: naveenkrishna.ch@gmail.com, Naveen Krishna Chatradhi , Guenter Roeck Subject: [PATCH v4 3/3] MAINTAINERS: add entry for AMD energy driver Date: Fri, 24 Apr 2020 08:50:56 +0530 Message-Id: <20200424032056.16287-3-nchatrad@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200424032056.16287-1-nchatrad@amd.com> References: <20200424032056.16287-1-nchatrad@amd.com> X-ClientProxiedBy: MA1PR01CA0107.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::23) To BY5PR12MB4212.namprd12.prod.outlook.com (2603:10b6:a03:202::8) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from milan-ETHANOL-X.amd.com (165.204.156.251) by MA1PR01CA0107.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.13 via Frontend Transport; Fri, 24 Apr 2020 03:21:22 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [165.204.156.251] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: e0a926a6-29ac-460b-c4c7-08d7e7fe9134 X-MS-TrafficTypeDiagnostic: BY5PR12MB3826:|BY5PR12MB3826: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1227; X-Forefront-PRVS: 03838E948C X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR12MB4212.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(10009020)(4636009)(396003)(376002)(39860400002)(346002)(136003)(366004)(1076003)(6916009)(4326008)(54906003)(2906002)(2616005)(316002)(26005)(8676002)(6666004)(52116002)(478600001)(81156014)(66476007)(186003)(66556008)(7696005)(956004)(5660300002)(36756003)(16526019)(66946007)(4744005)(8936002)(6486002);DIR:OUT;SFP:1101; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: h4Vx2U4xLiR1K3UyHY6ootk+7RyLIlNR/0pC0Bylxo4RPCUNxg2RM9b7dN2cqcrFPbiHpkcy3ho1m1/kxlc5a7LqqUOtKnqzN62DZhpnDMmhLlLPvk625jSl9EwAETNRBiN9jCZwRp9AC4SgtlseWElcKlYrWAecV54Aw9ZuiMn9S4dZxQoTDxe9tRAYRWK5WRTh4/TbOId30oLo4FCQaKi9VQ4vH30tlv/YkSXA95yigxoTnfVUMvCrr7E8ccrtqizt0krZpFb5ARysSxNuOj+i8R5TELC8kt281zUHvsxmyEr7xbh4eyEDRZDglYnvEIxx/+wlKEwtKI5KMGq+6Ap+a4nzSIY+DkoVS1WIL2sDxHPFlJgwbO1DIYpvsLc4yfPXe/QTU9ydrybIW62G4/215WqE7tLPEUPGx1Na+xIYhRdY11KNZrDxutQXOC1r X-MS-Exchange-AntiSpam-MessageData: yhdzSmkKY7pF836TFPhtIhRi5QDVa2P2xKKRMdjRql73kSzcr9grOOuWrDettf+PdXMb0oJ+/vLP7T04vHocWFSv8pfL0Xpq5YCBQZ0cw0QPhIZqvwNfr79IbdxkGR5cf9CNqDN+efBUgAaE7tQXxw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: e0a926a6-29ac-460b-c4c7-08d7e7fe9134 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Apr 2020 03:21:24.4329 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Ax7cwJ66ihVfAgonqUVgzFqgOiZEtmms9AcepEBlpXu+kwI/YgpgUv6Gp2nzkMk8LDJqyy5vBVMavJX8kQqmEA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB3826 Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org The kernel driver is part of HWMON subsystem. Cc: Guenter Roeck Signed-off-by: Naveen Krishna Chatradhi --- Changes in v4: None MAINTAINERS | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index c1175fc0aadb..112ffd7742aa 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -842,6 +842,13 @@ S: Supported T: git git://people.freedesktop.org/~agd5f/linux F: drivers/gpu/drm/amd/display/ +AMD ENERGY DRIVER +M: Naveen Krishna Chatradhi +L: linux-hwmon@vger.kernel.org +S: Maintained +F: Documentation/hwmon/amd_energy.rst +F: drivers/hwmon/amd_energy.c + AMD FAM15H PROCESSOR POWER MONITORING DRIVER M: Huang Rui L: linux-hwmon@vger.kernel.org