From patchwork Sat Sep 5 14:32:25 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: 11759129 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 597E2112E for ; Sat, 5 Sep 2020 14:32:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2B18420760 for ; Sat, 5 Sep 2020 14:32:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="TyIUJJct" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728314AbgIEOcy (ORCPT ); Sat, 5 Sep 2020 10:32:54 -0400 Received: from mail-bn8nam11on2087.outbound.protection.outlook.com ([40.107.236.87]:9185 "EHLO NAM11-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728206AbgIEOcx (ORCPT ); Sat, 5 Sep 2020 10:32:53 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ts7k/g9KmWY7jMY2ypL2vS3ajfA3YaD0nJZYPJrawNbfvycCW27zFb4lw1UvSYNuaPVrS5D/hhB/noCRE4KEinAAscQkcgRf2S4RF4dwK+mzHTULPuZZjBZUWcAPxPooSJvqUMx1so5kEbdfuGQr/F7Dix8cEanE/ITV8cP92kOZCDYMV1HQZV2KLuZxVn83P25rNKRhi2aNVKJTeG8gxhQQ36aGh2q6rZ+eH96x0PyrtHtxje4tymy0zr5K7b9JU9nJXyoXO9R1Itv3KALAfRZVFC/FLjo4fTTgGntlhNdJ/TEOk/U8Pa11RqgBgDNM2LdHDDr1jqO4AkBZ1DYsBQ== 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=QFh4S3JU5H900LMduFCoKGDACjoNGmqN1Edal7hH74g=; b=k9PmOQTXxY6Gnt+xINOXXsJ+ZnB5z9EYGH1Lpg9CKpCWR7gD0ODwFpmdq9k4HqpiF5xxFwGdJR7qj4I/EALAsswzMWEGfZxXjCcqeFPkkO86LLyZfpBTqwa04YJjhiuinwMPI/bPZFrlJD4tIBYZ4ILKW4CG3eyhLg2hPbdxCNZbHrWMQKvdb4AQioRyLp6iTSTj1xjo5IGblXzAl67Krs74aXvUwpIYhn125klLzRWtlJmavtGA/lFxrRlfaEiIFbHaF7/HQuJYBvIbxekEqvmmMYGnqMC0pVbcHoKVldpHzOQk0YrvzfV7mWwy42T2vLmMdZSbpGpdRd+FBSgBLQ== 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=QFh4S3JU5H900LMduFCoKGDACjoNGmqN1Edal7hH74g=; b=TyIUJJctJzUgix2xX+T98qennQjt+t0TfF6H9/E0OxQYEnqcPX7JAiw3icjzR4akg7E+w4uwqGCT+myUeTmr28336moRjzZnbxI46OIPD9Vl7cP8LVlB4mKjMOaR9rx3B08HrD7ddhkMD3iFF5vOHq/BTZjfZwDbM1T2h1gcP5E= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=amd.com; Received: from DM6PR12MB4388.namprd12.prod.outlook.com (2603:10b6:5:2a9::10) by DM6PR12MB3114.namprd12.prod.outlook.com (2603:10b6:5:11e::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3348.16; Sat, 5 Sep 2020 14:32:50 +0000 Received: from DM6PR12MB4388.namprd12.prod.outlook.com ([fe80::311f:8c73:8d31:7839]) by DM6PR12MB4388.namprd12.prod.outlook.com ([fe80::311f:8c73:8d31:7839%5]) with mapi id 15.20.3348.018; Sat, 5 Sep 2020 14:32:50 +0000 From: Naveen Krishna Chatradhi To: linux-hwmon@vger.kernel.org Cc: linux@roeck-us.net, Akshay Gupta Subject: [PATCH 1/6] hwmon: amd_energy: Move label out of accumulation structure Date: Sat, 5 Sep 2020 20:02:25 +0530 Message-Id: <20200905143230.195049-2-nchatrad@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200905143230.195049-1-nchatrad@amd.com> References: <20200905143230.195049-1-nchatrad@amd.com> X-ClientProxiedBy: MAXPR0101CA0063.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:e::25) To DM6PR12MB4388.namprd12.prod.outlook.com (2603:10b6:5:2a9::10) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from milan-ETHANOL-X.amd.com (165.204.156.251) by MAXPR0101CA0063.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:e::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3348.15 via Frontend Transport; Sat, 5 Sep 2020 14:32:49 +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: 853003c0-e1db-4c01-a822-08d851a8911b X-MS-TrafficTypeDiagnostic: DM6PR12MB3114: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:276; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IcV7r0+5UvRMJYuS6gKqowWG5psElgCuXEpvAS73ZIYSYh9Sc6P9u2UviXf5JFcPUdwUeFv/1GQhYPv14HRT3Diwr1aC8oPU3MyQNpjJyBKP4RQ2iTkUxCP3PH4LG9arRekefU5TYLyHk4ndJW3JuyYS01WvlC8SVoRQ7Z5lc8cHbNX9rLvy/Fs7WdQmQBgstMY5CIoXAdqVcAskRpCz4u/378W5bJyZwxuEB1OHbYrObWLRyLVc2M3V+AUHjmCtFPcpC+frm+7kNSTHLuKgGW4Z6EBePHvxfdCJORWGZI9Iwukr/oc0b40x8uF4FmG9 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4388.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(136003)(396003)(346002)(39860400002)(366004)(376002)(52116002)(316002)(478600001)(66946007)(8676002)(7696005)(66476007)(6916009)(66556008)(26005)(6666004)(4326008)(2616005)(6486002)(83380400001)(5660300002)(956004)(16526019)(36756003)(2906002)(186003)(1076003)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: h4JPk8fPpM567uIUevLkL09KoIi0uiJUYNIqPIMVAq7G8W0TAHlXtk5TtDO4jEImQtkklNRsNyClUcPvuFhXoVoJxhGu2wWdJvA4qeANyPVUhOqZTx1rVqliVC9v/nq05WwCYqGfk7AcNydFEMcsk1boUKGs5E4KvaQJQEEcU89RhppW/U1SLSHkM7ft9YWWS1H2fFX0mWgEHZ6ZrhIBNtvkrnTTxioE9MfjuBU5c2GC5RmC89x73gcK0epD0NBZb0uL2mYAa20opQVCkKupGaGeEXaLkqEhSSrDUpchMRT9SEEFnlYHVN55qH0kE3ZBh5EEML/X7wvde/0g8v8aYjNawkTfbkXKRwni1pwB82iBgoNQp7SUuXhqHM1MJiq6RbTog49yhutdQbE9uGFk5Pcr4NvlEx4kAmQ/gKns7Z5BOUu35NGy3FArMBxTo9q12ezC+r2P+oHFslvlzqEKIjH1vMJdxANc52NInJBDXPGCidmhn9XRPPyji27CQw2lH8/MTZ7dOOby9nvTnqp5OAwm3mOkhaYdnBo/+8EjF+qEVVDd8X9i1Coqs8+uomFFnyuaAI540gZ9UGrfe7G0POixZykXNHGfDIWqXTMtSYat/9dKihpj224JXBbkj7jR6kO46QuDH9uRlfHDIBoEJQ== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 853003c0-e1db-4c01-a822-08d851a8911b X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4388.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Sep 2020 14:32:50.5054 (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: o/NSGJtyz14aQxKt6QJl9BUKsofHhAEFq1+lCgnfRfHjA3j7RFyGWv48lvQk7ez62JgptnAP3nSlv0gWoIFbNA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3114 Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org From: Akshay Gupta At present, core & socket labels are defined in struct sensor_accumulator This patch moves it to the amd_energy_data structure, which will help in calling memset on struct sensor_accumulator to optimize the code. Signed-off-by: Akshay Gupta --- drivers/hwmon/amd_energy.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/drivers/hwmon/amd_energy.c b/drivers/hwmon/amd_energy.c index 29603742c858..9580a16185b8 100644 --- a/drivers/hwmon/amd_energy.c +++ b/drivers/hwmon/amd_energy.c @@ -35,7 +35,6 @@ struct sensor_accumulator { u64 energy_ctr; u64 prev_value; - char label[10]; }; struct amd_energy_data { @@ -52,6 +51,7 @@ struct amd_energy_data { int nr_cpus; int nr_socks; int core_id; + char (*label)[10]; }; static int amd_energy_read_labels(struct device *dev, @@ -61,7 +61,7 @@ static int amd_energy_read_labels(struct device *dev, { struct amd_energy_data *data = dev_get_drvdata(dev); - *str = data->accums[channel].label; + *str = data->label[channel]; return 0; } @@ -253,6 +253,7 @@ static int amd_create_sensor(struct device *dev, struct sensor_accumulator *accums; int i, num_siblings, cpus, sockets; u32 *s_config; + char (*label_l)[10]; /* Identify the number of siblings per core */ num_siblings = ((cpuid_ebx(0x8000001e) >> 8) & 0xff) + 1; @@ -276,21 +277,25 @@ static int amd_create_sensor(struct device *dev, if (!accums) return -ENOMEM; + label_l = devm_kcalloc(dev, cpus + sockets, + sizeof(*label_l), GFP_KERNEL); + if (!label_l) + return -ENOMEM; + info->type = type; info->config = s_config; data->nr_cpus = cpus; data->nr_socks = sockets; data->accums = accums; + data->label = label_l; for (i = 0; i < cpus + sockets; i++) { s_config[i] = config; if (i < cpus) - scnprintf(accums[i].label, 10, - "Ecore%03u", i); + scnprintf(label_l[i], 10, "Ecore%03u", i); else - scnprintf(accums[i].label, 10, - "Esocket%u", (i - cpus)); + scnprintf(label_l[i], 10, "Esocket%u", (i - cpus)); } return 0; From patchwork Sat Sep 5 14:32:26 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: 11759131 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 845D9112E for ; Sat, 5 Sep 2020 14:32:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5B007206B8 for ; Sat, 5 Sep 2020 14:32:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="RM1mqePD" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728206AbgIEOc4 (ORCPT ); Sat, 5 Sep 2020 10:32:56 -0400 Received: from mail-bn8nam11on2087.outbound.protection.outlook.com ([40.107.236.87]:9185 "EHLO NAM11-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728297AbgIEOc4 (ORCPT ); Sat, 5 Sep 2020 10:32:56 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OYYqEHXUQdROoye6cqZxQku0QfAoVNghnQCc0meUCyuSRcyrs4MAj8r7TMVaTpAqbss5JTt7v+u2io1ZOx/y/NRiOwdiBEyWYE353fZfLxk6IsI2tLsgnT5bYf8y6kmxTZ2zQMfRMbLLgk7OWdNk9NH1Ez21PcEobkgZKzXl7CRsep1e2LSE5Psbbk7bqVHcDxrOZCFDwIjs2PMlFWLHcy5mwwIWrFIiWv0SFKMM/AtWc4cORQofiMyXcyvp/SlBA6aON/XoWhp7HjGaoFRcGCZKDlnwyXOeQARwlxXMVJVu6fA1gNM2Kgsjr5sj5ATLraGxLmsXIWt/uGM5goVp0A== 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=YhA0rc9aIjCpwVkq9etUI7rgso6opunEg0XYPrOuXCE=; b=E3j2pKWau6mAVSr07jtt6cUkPJCwLYoPjAlKJZKGlEJXawIYsfKjjGA0kzTdBAXLtt0Xw3cuViRtKjAITIEAXlP000N5Bua7BbF5SLuUjS1ZEc9POiFYmDhsYYJTC3WD17nJaALTcmxBWB6uwNAWG8VGo0LvyWAgb2IxP9VTV+5OpxB7WmjS7lbJrv+Y9wHWpw52yPxRfuILRd8oGdYJGB/BVzkarsaxYmKNyHEyk0LIKKERwpWKQOkP7XcBbrBCkqrfXPMSDleSZDB4M0jmEEsISdqp9n5Fqpmk/nuHlZMbSnpCgOnQonhV5do+A3qY+6GJc7qvQZKaZsCq+13PcQ== 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=YhA0rc9aIjCpwVkq9etUI7rgso6opunEg0XYPrOuXCE=; b=RM1mqePDqIkACu0NJWQfwLAHa7Xa5l93Gq4JqjkSXIOesBl12Ax6rNODEJc/NTeKpP4aAX9yqfDDZ9HPzI0Vl0jurYzJ7zIR537fuV6Mq0kRVlYNkWyMSG43UBdYvzKQ+PwB9AhKgWiqfC3GkrVQvqqemEGWplJTq/j77R12mfY= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=amd.com; Received: from DM6PR12MB4388.namprd12.prod.outlook.com (2603:10b6:5:2a9::10) by DM6PR12MB3114.namprd12.prod.outlook.com (2603:10b6:5:11e::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3348.16; Sat, 5 Sep 2020 14:32:53 +0000 Received: from DM6PR12MB4388.namprd12.prod.outlook.com ([fe80::311f:8c73:8d31:7839]) by DM6PR12MB4388.namprd12.prod.outlook.com ([fe80::311f:8c73:8d31:7839%5]) with mapi id 15.20.3348.018; Sat, 5 Sep 2020 14:32:53 +0000 From: Naveen Krishna Chatradhi To: linux-hwmon@vger.kernel.org Cc: linux@roeck-us.net, Naveen Krishna Chatradhi Subject: [PATCH 2/6] hwmon: amd_energy: optimize accumulation interval Date: Sat, 5 Sep 2020 20:02:26 +0530 Message-Id: <20200905143230.195049-3-nchatrad@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200905143230.195049-1-nchatrad@amd.com> References: <20200905143230.195049-1-nchatrad@amd.com> X-ClientProxiedBy: MAXPR0101CA0063.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:e::25) To DM6PR12MB4388.namprd12.prod.outlook.com (2603:10b6:5:2a9::10) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from milan-ETHANOL-X.amd.com (165.204.156.251) by MAXPR0101CA0063.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:e::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3348.15 via Frontend Transport; Sat, 5 Sep 2020 14:32:51 +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: 23b9d74c-e2d9-40e5-751e-08d851a892bb X-MS-TrafficTypeDiagnostic: DM6PR12MB3114: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4502; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SYpGTuvgPwliNJzCFBJ981boLRNfP+noMxSqtafU7K5GZ8+yyEb/1lUigrNJnAo7WQYyF//UYfwlZaXuOvgJBOARrfHmYr/swOg4yFsqByJ2dI/W13mZrHRzGIbsvOu/BQDucr9+IbEdwrE9C26inJktzITUigor4I9sFm240p97RdGFdedCJBtt/FVh8LLmM1txoJOcdsw4JzwK1r5mpWlYzEfpccOSwnOcD7SCDiSP03cH4iHELMR+yUeHqP5lWxZ9FoOUz79FT2x8gphjZYXrYv2avGxXpHdaJNkUkwk0Z6XQ3alyvpp4lV7qXt0ZWHWp3E2aIR4S5BlsuUk95g== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4388.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(136003)(396003)(346002)(39860400002)(366004)(376002)(52116002)(316002)(478600001)(66946007)(8676002)(7696005)(66476007)(6916009)(66556008)(26005)(6666004)(4326008)(2616005)(6486002)(83380400001)(5660300002)(956004)(16526019)(36756003)(2906002)(186003)(1076003)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 0HHGNn5NMUQ3t5Fau3WNOcBnIXQEw51Gz7qVv3atobcq3Z7ch3KzzjSV6znOUS0wYQ+cgrPo1u0HNXve14Zh5iZrv/NnG1H/j71v/kA5SOvLV4HBLCU5H12jqMgUwA3F8F28sWlOOQYFMxu7IkZD9HKQzMBq1QkzEdB6zyCf+w6trpxTLS6Z+7O6Cv+rwAxoJneqygFRDNMrKHrBUi0bDW3bivi3NlQhhdJfFhIrzbh+JmltVnQ8dy0VaTxm4e+8hgRXyu8cOI7GxtbFQrzBN5FSB78ZvYcW/jz/2lN/W9Gsj6Jbi38DwpOwPTLf6CIfMbDGgQFKQFW4hY1YhWyXchgPd7m/MjvekZS8OOrcFK2+/I1XQkJmuJ/wXS6KkY6x/a9ybqW3ThuxEpRCxR2tVcmscUj69WnFYVN4yYZQRfLg5+8NFoIoDJlyAX6eI//SyxI3QeI+Jg4K571X2au376iIEVVQ8HoT3kslcUXzSfPFmysfdog8fioPoYaxFo8K4fJs0VA7pQQTIWlhl4puwa9PEJFUPiszmlrn7vEM0cL594AVO2iJTkW2VZfZxdVxvvscJ0YrCdisEM2RYdAV8BiGAwVI9fI/UfoM2PCfTnIi822PM9AsWCoZqk3I/1V/h2YY6+j7b0sWYo4y0fquPg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 23b9d74c-e2d9-40e5-751e-08d851a892bb X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4388.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Sep 2020 14:32:53.2532 (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: 8MvVN5Yc2bl939kkq2oyrJq5/EZySMGOf0upW8vBYsMkBEidKc8ignH8yOoBqCj0mmFxsWlj21feRBQrAWdVDA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3114 Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org On a system with course grain resolution of energy unit (milli J) the accumulation thread can be executed less frequently than on the system with fine grain resolution(micro J). This patch sets the accumulation thread interval to an optimum value calculated based on the (energy unit) resolution supported by the hardware (assuming a peak wattage of 240W). Signed-off-by: Naveen Krishna Chatradhi --- drivers/hwmon/amd_energy.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/amd_energy.c b/drivers/hwmon/amd_energy.c index 9580a16185b8..f0a13d6cc419 100644 --- a/drivers/hwmon/amd_energy.c +++ b/drivers/hwmon/amd_energy.c @@ -48,6 +48,7 @@ struct amd_energy_data { struct sensor_accumulator *accums; /* Energy Status Units */ u64 energy_units; + unsigned int timeout; int nr_cpus; int nr_socks; int core_id; @@ -215,6 +216,7 @@ static umode_t amd_energy_is_visible(const void *_data, static int energy_accumulator(void *p) { struct amd_energy_data *data = (struct amd_energy_data *)p; + unsigned int timeout = data->timeout; while (!kthread_should_stop()) { /* @@ -234,7 +236,7 @@ static int energy_accumulator(void *p) * * let us accumulate for every 100secs */ - schedule_timeout(msecs_to_jiffies(100000)); + schedule_timeout(msecs_to_jiffies(timeout)); } return 0; } @@ -331,6 +333,14 @@ static int amd_energy_probe(struct platform_device *pdev) if (IS_ERR(hwmon_dev)) return PTR_ERR(hwmon_dev); + /* Once in 3 minutes for a resolution of 1/2*16 */ + if (data->energy_units == 0x10) + data->timeout = 3 * 60; + + /* Once in 3 days for a resolution of 1/2^6 */ + if (data->energy_units == 0x6) + data->timeout = 3 * 24 * 60 * 60; + data->wrap_accumulate = kthread_run(energy_accumulator, data, "%s", dev_name(hwmon_dev)); if (IS_ERR(data->wrap_accumulate)) From patchwork Sat Sep 5 14:32:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Naveen Krishna Chatradhi X-Patchwork-Id: 11759133 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 684B913B6 for ; Sat, 5 Sep 2020 14:33:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4173A206B8 for ; Sat, 5 Sep 2020 14:33:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="cSrS9KXb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728412AbgIEOdA (ORCPT ); Sat, 5 Sep 2020 10:33:00 -0400 Received: from mail-bn8nam11on2063.outbound.protection.outlook.com ([40.107.236.63]:2133 "EHLO NAM11-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728364AbgIEOc7 (ORCPT ); Sat, 5 Sep 2020 10:32:59 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jl+fGalg6hp2fOG7kiP4wJa3fxN8szbj/IGjaSHmY42fExFdD19k5fMAgc7nv+XwBbwsajanjbQadIit9A4k6tVywJIeU9znLVNvvcssSY6SOg31LP6OUfKrA4IVPxohSVdiRsgMLLXv45sbwRpabCQ+YCYEgUYEjtlnLL3bVFq5oFIS/GlL5PmRieC/mGetUZj3QX8nZ4sskiAA67ekTj9BzoyfgHbzvywexAwRuvELeL9Z8E1YwCwC0sBLNzn8yAkZCXZYpUNCuH3degcDlOqG7DaHCO+Pryk9vgtPnsqtPucL/vBLjhYHXG/VpuGGeIimKd205WDdeHublqNLSA== 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=dW4OKpuI0vAUXLtunRkn5QcoQInc/2TI2+JTMrRHwMA=; b=QIC1cAefvCtHhBnRzjZUTb889JV81SwAX8jeIa7Fy2wMEsfspcYJf/owLDDahMfAKFqb8fQ2oknEJyh/bkFrjHlpPa4MYrJ36HSLETXL+Y5J4GAlr5A9f22QDaVztiuSbuigebW2dMP7T+lVmWaDLfwLFrBzITdP5OdlApX2HzjUat99qAN85VfxWk91SlPTWzCuDTqdr8E5HQm+0KEMzTieq3q3GC+YyrN8hdLKsBWxLpskLCxBsQUHNxDf/9EcjjJ8qLsJ/slhjGBgbSpHBJXUpI71UMYmgoE4iqaoNcJuqkYPD8A7bcSzaMS1vgEdLMyky0Bnc1E+Mqa4pzcrRQ== 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=dW4OKpuI0vAUXLtunRkn5QcoQInc/2TI2+JTMrRHwMA=; b=cSrS9KXbFD7vFLP4CKnprAo3fwdAj41Bhmplvr/+BZxoCEpaWIsbLjS2hsEE2GZJV19/DHEI1MDqePUBwUMofDeBDpQPopngRB/dqnnayXu25nU3T5f4LczQ1Xd3Wh2MSf09IBybr9xY75/A9p4uKQqkvGysWSxZNhUls1GHipE= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=amd.com; Received: from DM6PR12MB4388.namprd12.prod.outlook.com (2603:10b6:5:2a9::10) by DM6PR12MB3114.namprd12.prod.outlook.com (2603:10b6:5:11e::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3348.16; Sat, 5 Sep 2020 14:32:56 +0000 Received: from DM6PR12MB4388.namprd12.prod.outlook.com ([fe80::311f:8c73:8d31:7839]) by DM6PR12MB4388.namprd12.prod.outlook.com ([fe80::311f:8c73:8d31:7839%5]) with mapi id 15.20.3348.018; Sat, 5 Sep 2020 14:32:56 +0000 From: Naveen Krishna Chatradhi To: linux-hwmon@vger.kernel.org Cc: linux@roeck-us.net, Naveen Krishna Chatradhi Subject: [PATCH 3/6] hwmon: amd_energy: Improve the accumulation logic Date: Sat, 5 Sep 2020 20:02:27 +0530 Message-Id: <20200905143230.195049-4-nchatrad@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200905143230.195049-1-nchatrad@amd.com> References: <20200905143230.195049-1-nchatrad@amd.com> X-ClientProxiedBy: MAXPR0101CA0063.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:e::25) To DM6PR12MB4388.namprd12.prod.outlook.com (2603:10b6:5:2a9::10) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from milan-ETHANOL-X.amd.com (165.204.156.251) by MAXPR0101CA0063.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:e::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3348.15 via Frontend Transport; Sat, 5 Sep 2020 14:32:54 +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: 325d4b30-0529-4387-487b-08d851a89459 X-MS-TrafficTypeDiagnostic: DM6PR12MB3114: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:220; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: CElCDBCGy7M9VxCIsWe+QS6YGSc6N1ZL5XSnzyGYKWK53EthHJe2wwIguABucyEn1c97XzCJjOvqQbmWYx2H1eVxE+Ha3woomxYtmpQkFJxiKwD4NxnyOCk9O5JnkW8zY5DJ7oKWq9UtYWWmVE//PW48zufOZb1zysb8gaFb6VWADjf7Lh0BWieo8mT1BRDJO+xxNbuPVqy5xPCvkn+l+HLbSIb4Tk1cnM1bz0bvk4tZiVo4oWpSiWDx6LL2Sao7+jV5afrw/7QOLZiUQt/SI1nYrK6eNJDZXNOKlmzgawg9zZ+zed2XRGtotU5jHCWSvATLbmziMh13bbEuzDY79A== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4388.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(136003)(396003)(346002)(39860400002)(366004)(376002)(52116002)(316002)(478600001)(66946007)(8676002)(7696005)(66476007)(6916009)(66556008)(26005)(6666004)(4326008)(2616005)(6486002)(83380400001)(5660300002)(956004)(16526019)(36756003)(2906002)(186003)(1076003)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: bnoFL7gFaWAjYnIqRYyM2zEbo7agiYj6bLlnDCgLnu3pqelZqGFyu25ZdYrWGGd30WuqbwuhUhWq3eB1RPdF11qnOnMr10YAMxoMQu4sgYeRBCNUpWxb4sOS3v7n07DACJpzaKUbnLtarlgM5UVUpI9piMHPFeqxqU5Z+pq5QUjGSAckWO1ksMtCaG1KUhmhsXJuLgw2eBCdJwJMCod7cMBmIQcuecGmpMS+u3wlNsgLPSAsJ1FZTFP6C9E/a+pINAn/2c74iY3EJU/EqKz3v8GuwoNN0jQUHOxHrzCuDFSrKYeLZHwzWEsuoZhfxD+1SI2NFndtqSHVsSNmhRYJBoTIdjvQoSxXeQ1cfST3qibZHmOVaaUG2Ol/H/Ingq+VAizx4ovG+0g2E08FEasqWAEH0TVpCTw5QrHGk2eqm//GDVZw5H79fi7tVymVE6Z+3zch1RoQG85nNdVYc7UkYzAEGvggL6KQT1Z/0POyBaoZApkEWPdRJG82lTIuCX3SXO7fLMqBU5nT6s2saO8Ka5blKNvipQ+Wb3sTygqzwRHuzUWx5USAlAbWO52bFkhn4ovUmkEede/T0A3x8rPtJq1+YLHzjWMV7rTjVQBb6l8PyBUEDdXJr0qGOIirFwk62zyEIMxyy1wnCllJ5oUKzQ== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 325d4b30-0529-4387-487b-08d851a89459 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4388.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Sep 2020 14:32:55.9384 (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: dZVkcroh/GWlosWI9STVRiq1KLum7mWzNboKWdP2VkPPdGxdaH+Jx84zLpdlkUzZHo/Oi0DjKCBgXTLKC+szXw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3114 Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Factor out the common code in the accumulation functions for core and socket accumulation. While at it, handle the return value of the amd_create_sensor() function. Signed-off-by: Naveen Krishna Chatradhi --- drivers/hwmon/amd_energy.c | 126 +++++++++++++------------------------ 1 file changed, 45 insertions(+), 81 deletions(-) diff --git a/drivers/hwmon/amd_energy.c b/drivers/hwmon/amd_energy.c index f0a13d6cc419..96c61784d05c 100644 --- a/drivers/hwmon/amd_energy.c +++ b/drivers/hwmon/amd_energy.c @@ -74,108 +74,67 @@ static void get_energy_units(struct amd_energy_data *data) data->energy_units = (rapl_units & AMD_ENERGY_UNIT_MASK) >> 8; } -static void accumulate_socket_delta(struct amd_energy_data *data, - int sock, int cpu) +static void accumulate_delta(struct amd_energy_data *data, + int channel, int cpu, u32 reg) { - struct sensor_accumulator *s_accum; + struct sensor_accumulator *accum; u64 input; mutex_lock(&data->lock); - rdmsrl_safe_on_cpu(cpu, ENERGY_PKG_MSR, &input); + rdmsrl_safe_on_cpu(cpu, reg, &input); input &= AMD_ENERGY_MASK; - s_accum = &data->accums[data->nr_cpus + sock]; - if (input >= s_accum->prev_value) - s_accum->energy_ctr += - input - s_accum->prev_value; + accum = &data->accums[channel]; + if (input >= accum->prev_value) + accum->energy_ctr += + input - accum->prev_value; else - s_accum->energy_ctr += UINT_MAX - - s_accum->prev_value + input; + accum->energy_ctr += UINT_MAX - + accum->prev_value + input; - s_accum->prev_value = input; + accum->prev_value = input; mutex_unlock(&data->lock); } -static void accumulate_core_delta(struct amd_energy_data *data) +static void read_accumulate(struct amd_energy_data *data) { - struct sensor_accumulator *c_accum; - u64 input; - int cpu; + int sock, scpu, cpu; + + for (sock = 0; sock < data->nr_socks; sock++) { + scpu = cpumask_first_and(cpu_online_mask, + cpumask_of_node(sock)); + + accumulate_delta(data, data->nr_cpus + sock, + scpu, ENERGY_PKG_MSR); + } - mutex_lock(&data->lock); if (data->core_id >= data->nr_cpus) data->core_id = 0; cpu = data->core_id; + if (cpu_online(cpu)) + accumulate_delta(data, cpu, cpu, ENERGY_CORE_MSR); - if (!cpu_online(cpu)) - goto out; - - rdmsrl_safe_on_cpu(cpu, ENERGY_CORE_MSR, &input); - input &= AMD_ENERGY_MASK; - - c_accum = &data->accums[cpu]; - - if (input >= c_accum->prev_value) - c_accum->energy_ctr += - input - c_accum->prev_value; - else - c_accum->energy_ctr += UINT_MAX - - c_accum->prev_value + input; - - c_accum->prev_value = input; - -out: data->core_id++; - mutex_unlock(&data->lock); -} - -static void read_accumulate(struct amd_energy_data *data) -{ - int sock; - - for (sock = 0; sock < data->nr_socks; sock++) { - int cpu; - - cpu = cpumask_first_and(cpu_online_mask, - cpumask_of_node(sock)); - - accumulate_socket_delta(data, sock, cpu); - } - - accumulate_core_delta(data); } static void amd_add_delta(struct amd_energy_data *data, int ch, - int cpu, long *val, bool is_core) + int cpu, long *val, u32 reg) { - struct sensor_accumulator *s_accum, *c_accum; + struct sensor_accumulator *accum; u64 input; mutex_lock(&data->lock); - if (!is_core) { - rdmsrl_safe_on_cpu(cpu, ENERGY_PKG_MSR, &input); - input &= AMD_ENERGY_MASK; - - s_accum = &data->accums[ch]; - if (input >= s_accum->prev_value) - input += s_accum->energy_ctr - - s_accum->prev_value; - else - input += UINT_MAX - s_accum->prev_value + - s_accum->energy_ctr; - } else { - rdmsrl_safe_on_cpu(cpu, ENERGY_CORE_MSR, &input); - input &= AMD_ENERGY_MASK; + rdmsrl_safe_on_cpu(cpu, reg, &input); + input &= AMD_ENERGY_MASK; - c_accum = &data->accums[ch]; - if (input >= c_accum->prev_value) - input += c_accum->energy_ctr - - c_accum->prev_value; - else - input += UINT_MAX - c_accum->prev_value + - c_accum->energy_ctr; - } + accum = &data->accums[ch]; + if (input >= accum->prev_value) + input += accum->energy_ctr - + accum->prev_value; + else + input += UINT_MAX - accum->prev_value + + accum->energy_ctr; /* Energy consumed = (1/(2^ESU) * RAW * 1000000UL) μJoules */ *val = div64_ul(input * 1000000UL, BIT(data->energy_units)); @@ -188,20 +147,22 @@ static int amd_energy_read(struct device *dev, u32 attr, int channel, long *val) { struct amd_energy_data *data = dev_get_drvdata(dev); + u32 reg; int cpu; if (channel >= data->nr_cpus) { cpu = cpumask_first_and(cpu_online_mask, cpumask_of_node (channel - data->nr_cpus)); - amd_add_delta(data, channel, cpu, val, false); + reg = ENERGY_PKG_MSR; } else { cpu = channel; if (!cpu_online(cpu)) return -ENODEV; - amd_add_delta(data, channel, cpu, val, true); + reg = ENERGY_CORE_MSR; } + amd_add_delta(data, channel, cpu, val, reg); return 0; } @@ -249,7 +210,7 @@ static const struct hwmon_ops amd_energy_ops = { static int amd_create_sensor(struct device *dev, struct amd_energy_data *data, - u8 type, u32 config) + enum hwmon_sensor_types type, u32 config) { struct hwmon_channel_info *info = &data->energy_info; struct sensor_accumulator *accums; @@ -308,6 +269,7 @@ 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; data = devm_kzalloc(dev, sizeof(struct amd_energy_data), GFP_KERNEL); @@ -320,8 +282,10 @@ static int amd_energy_probe(struct platform_device *pdev) dev_set_drvdata(dev, data); /* Populate per-core energy reporting */ data->info[0] = &data->energy_info; - amd_create_sensor(dev, data, hwmon_energy, - HWMON_E_INPUT | HWMON_E_LABEL); + ret = amd_create_sensor(dev, data, hwmon_energy, + HWMON_E_INPUT | HWMON_E_LABEL); + if (ret) + return ret; mutex_init(&data->lock); get_energy_units(data); @@ -346,7 +310,7 @@ static int amd_energy_probe(struct platform_device *pdev) if (IS_ERR(data->wrap_accumulate)) return PTR_ERR(data->wrap_accumulate); - return PTR_ERR_OR_ZERO(data->wrap_accumulate); + return 0; } static int amd_energy_remove(struct platform_device *pdev) From patchwork Sat Sep 5 14:32:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Naveen Krishna Chatradhi X-Patchwork-Id: 11759135 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 9D55813B6 for ; Sat, 5 Sep 2020 14:33:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7A698206B8 for ; Sat, 5 Sep 2020 14:33:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="dbDZCJix" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728473AbgIEOdD (ORCPT ); Sat, 5 Sep 2020 10:33:03 -0400 Received: from mail-bn8nam11on2063.outbound.protection.outlook.com ([40.107.236.63]:2133 "EHLO NAM11-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728297AbgIEOdC (ORCPT ); Sat, 5 Sep 2020 10:33:02 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hEF0Q638qHlruAwLn3fZVVijWGsPiJDS8yF3hnjBGiSGxsrZBV9f5hqneg9Ucv83gIlwMk6igbVVXzZXYjeRIJavOPTwIC+4Ho/1Bzua4p39ssxBuTtHPtDksgpHTLI1OFljnV7Ck5CLXtn8uVLdzj5wEoi247a08uuazHzrwivGQpj21IYtg/TV2rIoLC91T5aO1g6ASDqHdROeL/5O/uFaax9O74ZraAJDnZfGsuMJRfVGMQN27muSVtqeOujIYYb9NPg48X5DgcT9k6jRp47/lZE2NdFqhiWcJE5wPoWPos1ylrcafcg6YLj9fAS1e3oiWetRPKpZqdd5+p8/lg== 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=o8Hqp0jthVOH+uRtBvPl401ym36PQbrYoGhvH+kIKSE=; b=NCyO688bkx0NzOifw8X6wNGn7feU91iA0ODGu/oO5RT3i3ZVN+hFWj2igeJHy3OTfskUL6C9XvboEDEF38+WHhYUhvpkBUpwQGScQ8Q51BjvANMDDM1P6T1Bn0ek+z3FJgm8DgWqrG8+m0vgnr1gNsyWs01912v6W+bj5mX6KnYv4q3SuZArEDns6BHf1FGaNNcH8Kk1UyBsv7vpndrNcwCA2pRk2aFyVq/uDIhCc9UgcTUy7MRdTeU+ReaFarQlRCsRq+H5i1u1JVwYDGY7YXJ8ZbmNp60bFdAa67qAHYaAUgSgbrWv/4NvDZaEu9F+249JWt+22iP9WuMenQbe5Q== 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=o8Hqp0jthVOH+uRtBvPl401ym36PQbrYoGhvH+kIKSE=; b=dbDZCJixlTscei25H0XR/vhfmDoJFHiG9T3BvSdnGmEf0KFEYBivnq9dtE64rmS+2ry0M2J6IGuuJAxWFMhwlQouS69Guxc9v9BP/l0J3MEaYuApc1V63PFP6AviWpMDXIbrQ05tBRLXsoHZPDo2hP5pP8J+Gllt1qmy/6fyLUo= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=amd.com; Received: from DM6PR12MB4388.namprd12.prod.outlook.com (2603:10b6:5:2a9::10) by DM6PR12MB3114.namprd12.prod.outlook.com (2603:10b6:5:11e::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3348.16; Sat, 5 Sep 2020 14:32:58 +0000 Received: from DM6PR12MB4388.namprd12.prod.outlook.com ([fe80::311f:8c73:8d31:7839]) by DM6PR12MB4388.namprd12.prod.outlook.com ([fe80::311f:8c73:8d31:7839%5]) with mapi id 15.20.3348.018; Sat, 5 Sep 2020 14:32:58 +0000 From: Naveen Krishna Chatradhi To: linux-hwmon@vger.kernel.org Cc: linux@roeck-us.net, Naveen Krishna Chatradhi Subject: [PATCH 4/6] hwmon: amd_energy: let user enable/disable the sw accumulation Date: Sat, 5 Sep 2020 20:02:28 +0530 Message-Id: <20200905143230.195049-5-nchatrad@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200905143230.195049-1-nchatrad@amd.com> References: <20200905143230.195049-1-nchatrad@amd.com> X-ClientProxiedBy: MAXPR0101CA0063.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:e::25) To DM6PR12MB4388.namprd12.prod.outlook.com (2603:10b6:5:2a9::10) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from milan-ETHANOL-X.amd.com (165.204.156.251) by MAXPR0101CA0063.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:e::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3348.15 via Frontend Transport; Sat, 5 Sep 2020 14:32:57 +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: 007faadc-a267-4937-65e7-08d851a895e6 X-MS-TrafficTypeDiagnostic: DM6PR12MB3114: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:270; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BQ5X0U1gqtpOHHR7DFdHiZryDjbD8Fw292Ot1NoWGYVZerlAmAJ0weWitM+bvlUdDwOx6XuJLS70IDhsVauX1kPImf7rpx5RklS4EkORaGf4sQEFlY80T4pU69U95aD6ZvlwMB2nJLB/R0IOqw7cKfPl8fdLZ4KrliqAPtQSetgwHrfgtMPJXt3NB3ncBhTNiUSRpZkWo6WdmzDCB6+w1GgnMEKacyhRZirkR6EiGnvBpyyXtmjXdmzc+soOClokVP1rrLJ7SxdlKu+XNCOX6/UBgxVjAN5dxFq1qwpLbutFBabXvqSWOkvNnDsdCQG5 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4388.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(136003)(396003)(346002)(39860400002)(366004)(376002)(52116002)(316002)(478600001)(66946007)(8676002)(7696005)(66476007)(6916009)(66556008)(26005)(6666004)(4326008)(2616005)(6486002)(83380400001)(5660300002)(956004)(16526019)(36756003)(2906002)(186003)(1076003)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: MHu2BoK1aChqqzJoBZT/ge3sHsHxdxx0d3MNbyRxKP/3sFl6jyKzkJDXsj54q7lWSZL9vWk4uVvsi+VJ/qIkUOT8TB2E4vuY7ExyXGiH5rv55YhVkOkC4EOyktUJEDU/QFLrx6OWlw9a4tlQCNICiLAYkdxdTJkAg7//Qh19UftikNP3lPQxf6gRKuQGG1pgLcIbaAnt78DdrzCHGUdOeR5MCI+dsauhRU3MkQSWlUcwA9S4wZ8r9ShfYtXQtLzrV3sjzepSly1knEXddqm9F7NoaSgydHow6cGw/DTTRlUi+Ylb52C83iQl7Y8rlOAD6XBZ/dhl6JjhEbcqXidqYal/BDRWhwzzvLJ0d2+9mN8hMXtIb4OjXreEBflFhMFyewnNwmkD9lOsiOzHWMysY8DzFooVW2ZH89PYkBQMoEjkMNloiZKAkFK6Bi4ADjWICQq4HuiAUCf5T65lBgLB3e8uOv6uUHWeCuubwWhJb9jZ3TDDMLB0nCFBHjyqsS7tpwzZabNAj/ghu3UtQKq59YeefR2EGUNCv7dOg5VZbmDWqKdOlJgHn8RnDmRIBxyXlFM2MW67Sd4hG6Pa4PvKJVoxNKlsqJfSxsfJbjLjeOHvTnjGF0Y6gLTOB0jBhkZCQa9eo+uMCF2/j2AokmmKrg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 007faadc-a267-4937-65e7-08d851a895e6 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4388.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Sep 2020 14:32:58.6037 (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: zYIxbK5Kl08NsrwiweN2bZD+g7LPwHnH0wGwHNzQdCBI6xey9HGKi6Dc0ShifKHr3vC6PraJqFqKlkJEEYd3tg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3114 Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Provide an option "accumulator_status" via sysfs to enable/disable the software accumulation of energy counters. Signed-off-by: Naveen Krishna Chatradhi --- drivers/hwmon/amd_energy.c | 104 ++++++++++++++++++++++++++++++------- 1 file changed, 86 insertions(+), 18 deletions(-) diff --git a/drivers/hwmon/amd_energy.c b/drivers/hwmon/amd_energy.c index 96c61784d05c..c294bea56c02 100644 --- a/drivers/hwmon/amd_energy.c +++ b/drivers/hwmon/amd_energy.c @@ -32,6 +32,8 @@ #define AMD_ENERGY_UNIT_MASK 0x01F00 #define AMD_ENERGY_MASK 0xFFFFFFFF +static struct device_attribute accumulate_attr; + struct sensor_accumulator { u64 energy_ctr; u64 prev_value; @@ -42,10 +44,12 @@ struct amd_energy_data { const struct hwmon_channel_info *info[2]; struct hwmon_chip_info chip; struct task_struct *wrap_accumulate; + struct device *hwmon_dev; /* Lock around the accumulator */ struct mutex lock; /* An accumulator for each core and socket */ struct sensor_accumulator *accums; + bool accumulator_status; /* Energy Status Units */ u64 energy_units; unsigned int timeout; @@ -128,13 +132,15 @@ static void amd_add_delta(struct amd_energy_data *data, int ch, rdmsrl_safe_on_cpu(cpu, reg, &input); input &= AMD_ENERGY_MASK; - accum = &data->accums[ch]; - if (input >= accum->prev_value) - input += accum->energy_ctr - - accum->prev_value; - else - input += UINT_MAX - accum->prev_value + - accum->energy_ctr; + if (data->accumulator_status) { + accum = &data->accums[ch]; + if (input >= accum->prev_value) + input += accum->energy_ctr - + accum->prev_value; + else + input += UINT_MAX - accum->prev_value + + accum->energy_ctr; + } /* Energy consumed = (1/(2^ESU) * RAW * 1000000UL) μJoules */ *val = div64_ul(input * 1000000UL, BIT(data->energy_units)); @@ -264,9 +270,67 @@ static int amd_create_sensor(struct device *dev, return 0; } +static ssize_t amd_energy_accumulate_show(struct device *dev, + struct device_attribute *dev_attr, + char *buf) +{ + struct amd_energy_data *data = dev_get_drvdata(dev); + + return sprintf(buf, "%d\n", data->accumulator_status); +} + +static ssize_t amd_energy_accumulate_store(struct device *dev, + struct device_attribute *dev_attr, + const char *buf, size_t count) +{ + struct amd_energy_data *data = dev_get_drvdata(dev); + bool input; + int ret; + + ret = kstrtobool(buf, &input); + if (ret) + return ret; + + if (data->accumulator_status == input) + return count; + + if (input) { + memset(data->accums, 0, (data->nr_cpus + data->nr_socks) * + sizeof(struct sensor_accumulator)); + + if (!data->wrap_accumulate) { + data->wrap_accumulate = + kthread_run(energy_accumulator, + data, "%s", dev_name(dev)); + if (IS_ERR(data->wrap_accumulate)) + return PTR_ERR(data->wrap_accumulate); + } + } else { + if (data && data->wrap_accumulate) { + ret = kthread_stop(data->wrap_accumulate); + if (ret) + return ret; + data->wrap_accumulate = NULL; + } + } + data->accumulator_status = input; + + return count; +} + +static int create_accumulate_status_file(struct amd_energy_data *data) +{ + accumulate_attr.attr.name = "accumulator_status"; + accumulate_attr.attr.mode = 0664; + accumulate_attr.show = amd_energy_accumulate_show; + accumulate_attr.store = amd_energy_accumulate_store; + + return sysfs_create_file(&data->hwmon_dev->kobj, + &accumulate_attr.attr); +} + 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; @@ -290,12 +354,12 @@ static int amd_energy_probe(struct platform_device *pdev) mutex_init(&data->lock); get_energy_units(data); - hwmon_dev = devm_hwmon_device_register_with_info(dev, DRVNAME, - data, - &data->chip, - NULL); - if (IS_ERR(hwmon_dev)) - return PTR_ERR(hwmon_dev); + data->hwmon_dev = devm_hwmon_device_register_with_info(dev, DRVNAME, + data, + &data->chip, + NULL); + if (IS_ERR(data->hwmon_dev)) + return PTR_ERR(data->hwmon_dev); /* Once in 3 minutes for a resolution of 1/2*16 */ if (data->energy_units == 0x10) @@ -305,10 +369,12 @@ static int amd_energy_probe(struct platform_device *pdev) if (data->energy_units == 0x6) data->timeout = 3 * 24 * 60 * 60; - data->wrap_accumulate = kthread_run(energy_accumulator, data, - "%s", dev_name(hwmon_dev)); - if (IS_ERR(data->wrap_accumulate)) - return PTR_ERR(data->wrap_accumulate); + /* Disabling the energy accumulation by default */ + data->accumulator_status = 0; + + ret = create_accumulate_status_file(data); + if (ret) + return ret; return 0; } @@ -317,6 +383,8 @@ static int amd_energy_remove(struct platform_device *pdev) { struct amd_energy_data *data = dev_get_drvdata(&pdev->dev); + sysfs_remove_file(&data->hwmon_dev->kobj, &accumulate_attr.attr); + if (data && data->wrap_accumulate) kthread_stop(data->wrap_accumulate); From patchwork Sat Sep 5 14:32:29 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: 11759137 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 6F49C112E for ; Sat, 5 Sep 2020 14:33:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 51BFB20760 for ; Sat, 5 Sep 2020 14:33:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="YNHYgWDp" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728297AbgIEOdH (ORCPT ); Sat, 5 Sep 2020 10:33:07 -0400 Received: from mail-bn8nam11on2063.outbound.protection.outlook.com ([40.107.236.63]:2133 "EHLO NAM11-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728364AbgIEOdF (ORCPT ); Sat, 5 Sep 2020 10:33:05 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gVuwV3fe9N2VxOoXIuBb7OWSwtVfbxsuqFqIPemrzCyVormzbsrqD0tju2HQuNhPAZ3G2xd7NIXNTmCRUn8RE6irjJplKU/hA+ugvewvn8grtUq0XUOYQN/aSRJLgHam3cS+fnn4YigtGeH7v0fnhqD+oWeekx3hG6R+b0HmGJnIX0S2HZ2rXG36XXc/DQm/6MxYaT0W457IRAp5vn/ETyYezCyRvUH8ifELDHQZjHUM9bw3qEnfD3jf4COowIPukgq3yYPhqyELeG8zRPc6kLajyfwnunrnNdcp6ZERa2jWrJQLAB6O9kleW38iNH7mXVAqy+CYqC/DDZNYP1SIoQ== 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=CZE8mEpZOc0DoZa4M97ogv4hgr03c4OIKFWY0MTHNyo=; b=jkWNq2ea9SklaSquOVAMAnjJ+h2PSj3GPTOnK16ngBbwz01PAPXJMgEUXmmBEZYGLWY41V733xRyGX8HpSErhwDXNV0jXWO1klYdrgKOUG8RX8Zq/DjMAw2N+E0YV96MTSKVs9XLRrxV5AGn+N2CI+9rVFeMh+x11G5iwbiyfj3e0LjQRqGyoG4oWnxjQgn4k9mFGOD8aVelMqBiW761YA8wKd34eQoLIDIaXW+lK+tvak6I8gBFfS61Gxt72zdHQLL93N9Dvr5D3TusaVLWbjX4rJpI22qucptXq4KgT5FjCP0miUdpPUaAkYTxj6DvGtqmFHWGt856VffQFRoshA== 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=CZE8mEpZOc0DoZa4M97ogv4hgr03c4OIKFWY0MTHNyo=; b=YNHYgWDpagzCrmrrOf1Oi8NTyHf1dE3bUGU6bQvt1abIv03BeOOt0fbKkk5HR1y+L/TonbclTs51oetQiYFMw+Cna4BaqMWnMrppy+03ow8pI2u71dSi4Jee/K0g3lsyER7TCQ9y0uIm1WlUkT7CPg2R4L5ZstRM7q+aubQeeX4= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=amd.com; Received: from DM6PR12MB4388.namprd12.prod.outlook.com (2603:10b6:5:2a9::10) by DM6PR12MB3114.namprd12.prod.outlook.com (2603:10b6:5:11e::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3348.16; Sat, 5 Sep 2020 14:33:01 +0000 Received: from DM6PR12MB4388.namprd12.prod.outlook.com ([fe80::311f:8c73:8d31:7839]) by DM6PR12MB4388.namprd12.prod.outlook.com ([fe80::311f:8c73:8d31:7839%5]) with mapi id 15.20.3348.018; Sat, 5 Sep 2020 14:33:01 +0000 From: Naveen Krishna Chatradhi To: linux-hwmon@vger.kernel.org Cc: linux@roeck-us.net, Naveen Krishna Chatradhi Subject: [PATCH 5/6] hwmon: amd_energy: dump energy counters via debugfs Date: Sat, 5 Sep 2020 20:02:29 +0530 Message-Id: <20200905143230.195049-6-nchatrad@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200905143230.195049-1-nchatrad@amd.com> References: <20200905143230.195049-1-nchatrad@amd.com> X-ClientProxiedBy: MAXPR0101CA0063.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:e::25) To DM6PR12MB4388.namprd12.prod.outlook.com (2603:10b6:5:2a9::10) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from milan-ETHANOL-X.amd.com (165.204.156.251) by MAXPR0101CA0063.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:e::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3348.15 via Frontend Transport; Sat, 5 Sep 2020 14:32:59 +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: e46f72d3-7056-4b95-cdae-08d851a8976e X-MS-TrafficTypeDiagnostic: DM6PR12MB3114: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:393; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nD8eTb8WvOSZ3XyeYjCgqPVUE9aBfTr7SF/hMfIJsYevi9gkUOQoYguedM7zefgbtCuMIhF+2dQ3mmpI955QXdQC+ROWeP2gMTzJyaQ0b/RJT8tN+PLNSO4HQHKZ2gNnyGC295uMDa5Cr4XHi8/X+HxqbmxJFuB5UJQInl/EIanNIBaU78orRW8T0x4ymXr5DY+3LY87Kd0etL3IEttq0CyHgo8XEBNfDSnOp6WC9PoUYQeIMb4u2+kyQVZuQ05Np3sjlARowLLi14hznzL18EAIeBWcsyT+KaIJ0AtFleeEwwAJXqrRE2utqg2a3nAfMtyRktC32OVYws6Zj+o2lA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4388.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(136003)(396003)(346002)(39860400002)(366004)(376002)(52116002)(316002)(478600001)(66946007)(8676002)(7696005)(66476007)(6916009)(66556008)(26005)(6666004)(4326008)(2616005)(6486002)(83380400001)(5660300002)(956004)(16526019)(36756003)(2906002)(186003)(1076003)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: xcJG8uUrHu0v9RJ+Dc5L369sMPmBO2Inh6BCU3w1xJjJDOELb5/D5VJ6dSu3+rrkTY51ed1LFhC85hPQH83oZcEjvx9F7IKlcNdcTIUvZXW/MD0pwILri00jOGmHo139PgZuv9zSsmiy2KT87wH+eYaWgqyBaglrckCMd4fkfVcSLemuc0jnoVvc3R1DRtj/htnmcQSkwu9jdyesumXFdqLpdP912Df/FqF6lG41i9COkuL3KM1CjVZWkZPQ4TyNX8fzgIIJzML2dcurYzrvbNQMEEd6VzsTx6Mj89yrBVQDWPkLRZXlsXZ+9g54ubDVwKqYePgApx4CVO+s1EVGrt9RUBGvvh6aOtpruhckcHCOSdESn1FXSRDYVgQvTOcnRf3+Fg/zdWmmfWgeJJ7kjT9xushDPBrwFMZAHdaiGDoe5jgFt4sLnDgEmhvL+tkdwk648Ht4cvZcPJ6Xq/TDSltfCET88YT1zkd2uGIs0BEMMTUmvk2e4YXTEt8hlq6VWgiDuME3oia9vXvUKneGlcV5LMwBRlf6kzPkK9jycEhQ9AmQlzUzaFlsA/qkm33r8xPMiqAHC3G0AhKniM11n50rfacjD6XLCoWILkWhT4TnDTkbFJXBn+7IYVLg/RS3BLwWqcl+ABsahxfRwUAtKg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: e46f72d3-7056-4b95-cdae-08d851a8976e X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4388.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Sep 2020 14:33:01.1236 (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: 4rGFRhc16+MtbiC2EcJPjG8bjnvuA574jWzdcFQ6I0ZxYiDkxCLyPRJW8w856ENCIpJGVAjXn2V1Mxk3Q4cwTQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3114 Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Use seq_printf to capture the core and socket energies under debugfs path in '/sys/kernel/debug/amd_energy/' file cenergy_dump: To print out the core energy counters file senergy_dump: To print out the socket energy counters Signed-off-by: Naveen Krishna Chatradhi --- drivers/hwmon/amd_energy.c | 110 +++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/drivers/hwmon/amd_energy.c b/drivers/hwmon/amd_energy.c index c294bea56c02..2184bd4510ed 100644 --- a/drivers/hwmon/amd_energy.c +++ b/drivers/hwmon/amd_energy.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -20,6 +21,7 @@ #include #include #include +#include #include #include @@ -57,6 +59,8 @@ struct amd_energy_data { int nr_socks; int core_id; char (*label)[10]; + u64 *cdump; + u64 *sdump; }; static int amd_energy_read_labels(struct device *dev, @@ -329,6 +333,108 @@ static int create_accumulate_status_file(struct amd_energy_data *data) &accumulate_attr.attr); } +#ifdef CONFIG_DEBUG_FS +static void dump_on_each_cpu(void *info) +{ + struct amd_energy_data *data = info; + int cpu = smp_processor_id(); + + amd_add_delta(data, cpu, cpu, (long *)&data->cdump[cpu], + ENERGY_CORE_MSR); +} + +static int cenergy_dump_show(struct seq_file *s, void *unused) +{ + struct amd_energy_data *data = s->private; + struct cpumask *cpus_mask; + int i; + + cpus_mask = kmalloc(sizeof(*cpus_mask), GFP_KERNEL); + memset(data->cdump, 0, (data->nr_cpus) * sizeof(u64)); + cpumask_clear(cpus_mask); + for (i = 0; i < data->nr_cpus; i++) { + if (cpu_online(i)) + cpumask_set_cpu(i, cpus_mask); + } + + on_each_cpu_mask(cpus_mask, dump_on_each_cpu, data, true); + + for (i = 0; i < data->nr_cpus; i++) { + if (!(i & 3)) + seq_printf(s, "Core %3d: ", i); + + seq_printf(s, "%16llu ", data->cdump[i]); + if ((i & 3) == 3) + seq_puts(s, "\n"); + } + seq_puts(s, "\n"); + + kfree(cpus_mask); + return 0; +} +DEFINE_SHOW_ATTRIBUTE(cenergy_dump); + +static int senergy_dump_show(struct seq_file *s, void *unused) +{ + struct amd_energy_data *data = s->private; + int i, cpu; + + for (i = 0; i < data->nr_socks; i++) { + cpu = cpumask_first_and(cpu_online_mask, + cpumask_of_node(i)); + amd_add_delta(data, data->nr_cpus + i, cpu, + (long *)&data->sdump[i], ENERGY_PKG_MSR); + seq_printf(s, "Socket %1d: %16llu\n", + i, data->sdump[i]); + } + + return 0; +} +DEFINE_SHOW_ATTRIBUTE(senergy_dump); + +static void dump_debugfs_cleanup(void *ddir) +{ + debugfs_remove_recursive(ddir); +} + +static int create_dump_file(struct device *dev, + struct amd_energy_data *data) +{ + struct dentry *debugfs; + char name[] = "amd_energy"; + + data->cdump = devm_kcalloc(dev, data->nr_cpus, + sizeof(u64), GFP_KERNEL); + if (!data->cdump) + return -ENOMEM; + + data->sdump = devm_kcalloc(dev, data->nr_socks, + sizeof(u64), GFP_KERNEL); + if (!data->sdump) + return -ENOMEM; + + debugfs = debugfs_create_dir(name, NULL); + if (debugfs) { + debugfs_create_file("cenergy_dump", 0440, + debugfs, data, &cenergy_dump_fops); + debugfs_create_file("senergy_dump", 0440, + debugfs, data, &senergy_dump_fops); + devm_add_action_or_reset(data->hwmon_dev, + dump_debugfs_cleanup, debugfs); + } + + return 0; +} +#else + +static int create_dump_file(struct device *dev, + struct amd_energy_data *data) +{ + return 0; +} + +#endif //CONFIG_DEBUG_FS + static int amd_energy_probe(struct platform_device *pdev) { struct amd_energy_data *data; @@ -376,6 +482,10 @@ static int amd_energy_probe(struct platform_device *pdev) if (ret) return ret; + ret = create_dump_file(dev, data); + if (ret) + return ret; + return 0; } From patchwork Sat Sep 5 14:32:30 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: 11759139 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 2E8AA112E for ; Sat, 5 Sep 2020 14:33:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1373620760 for ; Sat, 5 Sep 2020 14:33:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="syPiew0g" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728566AbgIEOdJ (ORCPT ); Sat, 5 Sep 2020 10:33:09 -0400 Received: from mail-bn8nam11on2063.outbound.protection.outlook.com ([40.107.236.63]:2133 "EHLO NAM11-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727875AbgIEOdI (ORCPT ); Sat, 5 Sep 2020 10:33:08 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kX0Et7EfSgl5tP1R4urhBg5o6fHAH/6sEc9XV7lwZmlwUpVeBeEuLZJG/9760gao99BvyKcah0zOV+7NSEd0670ei8UTJmW3G0oxL85h6HLsreo3tQ/Lo59QEy6pSPWu+Zz9A22pbOnlqvKfLlvaVaZhVWrwa7OTjwce2Zz7ntvqe+91Rt10GRpciYY2yfWXsudSBAFonULUtEUlp5e/LoqmvbtDUJ+q04MT4LcTkG0IgPXGZSHXU/kHkCI4GCKjHd59rnEa0zA21bFteY4/qZc5xoS5N5pFBnFpEZnrX95usVL6aqFrpJp0Zhxp63mtfHSTczPX+7XjCCLc4/kzfQ== 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=o1N5bqHEI4+U4XXo7nsGPe15+jKaFLEC+w6COsL/I60=; b=IeXfAS7sVP67r7ZLTlGy6v9ZXR1Si29GCjnNYIh9PesAJ17p7E+11RqxCTxsmKUAcsxWCc3ptuN7aQgnjnAbojdAbUu7cQcqr6/MtOKrIScC3PjojFoStWFCthobDDF7Z15LZeX1jFcXjrKCofIEtQxPT0x2Bqp88vKMT9VDbqrp9ADeHBd5Too5Pr/mTo1E0JFoaSGOVHmHXoAh2NWwxvI8/DHNOPkb1Af929RWjPd0V6pvIwT9b5FX5frL3gUwR0Dg92B114vhWqEIvihu1xc/ycdR6WHLEnoNerluCb1DbaYV3Wa3v7IBSV0/HGp2TcNE9vUowh+y3bKJQB4YYA== 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=o1N5bqHEI4+U4XXo7nsGPe15+jKaFLEC+w6COsL/I60=; b=syPiew0gUrEVou9DqIz8mGLtRJVokZdfYL/l70gx9w1GCh5tv1VuFoRdKgp/1EsCQuWVps4iXn9ZJXgQMqZC2zJ/j5dR1g1oLeGHj1u1qGkHTILYN5Hs0ojFYwpzkdLAAufKPIJymtVnlgYRZu+fYKQXIKoERVm9r56cfQE4gbs= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=amd.com; Received: from DM6PR12MB4388.namprd12.prod.outlook.com (2603:10b6:5:2a9::10) by DM6PR12MB3114.namprd12.prod.outlook.com (2603:10b6:5:11e::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3348.16; Sat, 5 Sep 2020 14:33:03 +0000 Received: from DM6PR12MB4388.namprd12.prod.outlook.com ([fe80::311f:8c73:8d31:7839]) by DM6PR12MB4388.namprd12.prod.outlook.com ([fe80::311f:8c73:8d31:7839%5]) with mapi id 15.20.3348.018; Sat, 5 Sep 2020 14:33:03 +0000 From: Naveen Krishna Chatradhi To: linux-hwmon@vger.kernel.org Cc: linux@roeck-us.net, Naveen Krishna Chatradhi Subject: [PATCH 6/6] hwmon: (amd_energy) Update driver documentation Date: Sat, 5 Sep 2020 20:02:30 +0530 Message-Id: <20200905143230.195049-7-nchatrad@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200905143230.195049-1-nchatrad@amd.com> References: <20200905143230.195049-1-nchatrad@amd.com> X-ClientProxiedBy: MAXPR0101CA0063.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:e::25) To DM6PR12MB4388.namprd12.prod.outlook.com (2603:10b6:5:2a9::10) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from milan-ETHANOL-X.amd.com (165.204.156.251) by MAXPR0101CA0063.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:e::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3348.15 via Frontend Transport; Sat, 5 Sep 2020 14:33:02 +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: 0bfc8acb-d2af-492a-51b1-08d851a898dc X-MS-TrafficTypeDiagnostic: DM6PR12MB3114: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gi5P8ugyZNKcgVYVgqA/m4uMfqkTCnSpJ/pC+bSYixC991mu8am63utWfXZdPqo/oGSJPe6SeZCKGSSEMWusWQuX5PvvKLU4ak+M6TOJ0/e3UN8LV2hdzsTybV8sg/kMwn5z9pfpCILYPNsY99kExzOz8TFSYeotC3bH+VQY4E2Wo8T6tghd9uZJ3OWBI6hhunU1B20jGlu+xvoBwjrfKyNdjkjZInK640xnFOqlax2ODzOpsl25litVmojV+FwjC8mKtJ1Z4ctcuvBTD0YRs2EF18Gy0w3yfJ0sTCx59CocCU9FmJJLkL+NZZzeY7Sf X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4388.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(136003)(396003)(346002)(39860400002)(366004)(376002)(15650500001)(52116002)(316002)(478600001)(66946007)(8676002)(7696005)(66476007)(6916009)(66556008)(26005)(6666004)(4326008)(2616005)(6486002)(83380400001)(5660300002)(956004)(16526019)(36756003)(2906002)(186003)(1076003)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: S1/k3EN26Cq4xQaxsatiX9nMYoBrIGgOaxAxW2jLan/2kr5YBgmMjxcoitLwqoQiwIUNqS9i40ROwZesnD4gqdDJdED56hFOVyVSpdoXz6ECuJDTPAre8GPPFHYu3a1/G0UyAljFJmojQBnQD1rDHGbIIzVMu9WrXpMHIjMUnGzOAXZOKzT4z/dnegU2LSVOLeEUn4a9CFOCzlSAPKnZFLqAN+mgN3p5v3PuB1GxZyY0idg9+wL1izHW92yEBfviak+GfPSaZQu4IsoBe1BDLNc9OtzFvKREy14eWcnIBaYWLfjGyiO89E8IUzBojYkzFvFQ/xvM7C19hXjafp18BXmrqK6tSQWmt1qspYuIzZyLuPgOh7Dy5MlaHgUlgpZaWH598nrBzIhuI+s+taDzlam/53qQm0ZS2PQAo+V1uT6AlrCm0PvWNFoORp1d1Rwlornbndqkn9/klWSwGvtKhuP3r89XQijNI4XZJBjtM9yDh5kYBmGt/YzcBcORxP38eFka4rL6ibwhSA/ylsg431miSHUbRHkibwAuFjY8/xFvpzjaR9UsMJ6pcTEPYXpcMqPGEIJDn8yNLIDMv3GqnWX6baam2kxL0Zwca6eprIn0uIK4Yc3cc9+B7NFnNGYFW0B+ICAArN9dXSgtKyW6QA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0bfc8acb-d2af-492a-51b1-08d851a898dc X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4388.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Sep 2020 14:33:03.5230 (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: gQEd18z5nQkFSDoQbYBoCXWjI4N9f0QcxmtHBffEa5bn0uUuyJcrNcULA55DZ6HJ6t2NU7ELvyqLeXb4GWMWgw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3114 Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Update the documentation of the newly added features 1. Set the accumulation interval based on resolution 2. Debugfs entries to capture the counters of all the cores and sockets 3. Control the software accumulation Signed-off-by: Naveen Krishna Chatradhi --- Documentation/hwmon/amd_energy.rst | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Documentation/hwmon/amd_energy.rst b/Documentation/hwmon/amd_energy.rst index f8288edff664..fe145ad158dd 100644 --- a/Documentation/hwmon/amd_energy.rst +++ b/Documentation/hwmon/amd_energy.rst @@ -84,9 +84,28 @@ per run to a respective 64-bit counter. The kernel thread starts running during probe, wakes up every 100secs and stops running when driver is removed. +Frequency of the accumulator thread is set during the probe +based on the chosen energy unit resolution. +A. fine grain (1.625 micro J) +B. course grain (0.125 milli J) + A socket and core energy read would return the current register value added to the respective energy accumulator. +The energy counters of all the core and sockets are available +under debugfs path in '/sys/kernel/debug/amd_energy/' + +file cenergy_dump: To print out the core energy counters +file senergy_dump: To print out the socket energy counters + +Control the Energy accumulation +--------------------------------- + +The software accumulation of energy counters is disabled by default. + +A sysfs entry "accumulator_status" is provided to enable/disable +the same. + Sysfs attributes ----------------