From patchwork Mon Nov 27 13:16:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Rui" X-Patchwork-Id: 170132 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp3100757vqx; Mon, 27 Nov 2023 05:17:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IEUR1gq6ia0pPI7mAEerSnmgcbRbAVFcwqf6stvAjS79HFLhwoW3jg9LsjpbNmHPijAUjQU X-Received: by 2002:a05:6a20:7352:b0:18c:2d7:b84c with SMTP id v18-20020a056a20735200b0018c02d7b84cmr12490668pzc.61.1701091045704; Mon, 27 Nov 2023 05:17:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701091045; cv=none; d=google.com; s=arc-20160816; b=bTet2tRy+0xdKGmHZLg0u59vsv3eWsIwbrDZRKxofVKpgTP1PsccSb+i7KxiY39gPo Ptww1RTmj0W+QZ2gylz+DJ+aqPrEIiAapHVddnwRDy2ler20xDuu+2oYz/wJ9hUKT/J+ nw3ovC5oDxOe4JdvG544QXILAFl3ktgcuhHUa6m8q9i47kR0sA0u3SpUo5VKW8R5AT73 J9k2yG5B6LE9lAXqWAa8asM4x1X4ZmqHhIP2pKqZ1iby8Wu17lb32E90DkktW9iMdjl/ g13U0+hzC244pcHVysVO2t5HH4v3jom65LajA+iNzYATu/DgKYyjX6gIFmaCCdsnIXX+ ufOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vRl1X0Rf1dPzOU9VSHobheD51u0XuuU1TA43Mn33vBE=; fh=Mbam0pR9JWUnI2UheCn8N0H+ykbrnMeiPzCxF+zJmn8=; b=bEP0k7Og5jchFauC0c35+DdL28WKS3hgiVPlZfx3SJdwhxms3cWiQD3ZFValmEhKH5 YTLt+D/pZO2TfPd8/paP4tLD9BJZ4N3V30Agbb6yQLrAM8eimYHnpP8vO0m3MNwrNXb+ ghiaPBgFAxjJygYOCcWpooprjL15IFpggr9qcuT3HIksmQR+P3x0Dw/MSDpuGqAUs7b+ oW24niI8orRf9gSylm1eGjMPsTNlQk2LnutecF+BA+BHNNEfSh1Yqo5XSf9KTlu39UTT ep81QYdRRY3wyBBpsXTkF7Wv+0nd86Wrt5r0q2gxwBzqq3lREhU1V4XN9RJESG1cdXmr yioA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Arx0+kEC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id s14-20020a056a00178e00b006cba6b43d88si10074567pfg.265.2023.11.27.05.17.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 05:17:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Arx0+kEC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id ED8E0805E441; Mon, 27 Nov 2023 05:17:20 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233434AbjK0NRF (ORCPT + 99 others); Mon, 27 Nov 2023 08:17:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233371AbjK0NRD (ORCPT ); Mon, 27 Nov 2023 08:17:03 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 693821A1; Mon, 27 Nov 2023 05:17:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701091030; x=1732627030; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hlesYW8rOy1XULs0ORzCaeEOdp4ntoGv7wHs6RrOTq4=; b=Arx0+kECHD7iU2ss0hRNKmOwUZNDhXuYU7O6+Arq95nIwECR5753Loiu jUJIHz3uBBrnlFytOYeyWLxjIT/dNiwFaSsmsWX02nY1PEjVbRQmjPg5a hFDyDZwrSX/IibocZxRF2hds0lvmU1yffwiQWonijwm/I0lMLnEfSoObz Hl0qjbMoVDG6M9YgyFfp1/f2oHMxj6xE930mAWLgyzORyl0TOHEqmzVCL hffvMvFSKG3bWwGm9dztS3p2u+UR4dVUdc/3iEDMHrYHpOLfTQKbb/Mdv Rfj/ao0Snuf+1is6mUBHFBQCBizNRmEc4EftyFulQhRCyMW9dI91j4hRP Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10906"; a="423833674" X-IronPort-AV: E=Sophos;i="6.04,230,1695711600"; d="scan'208";a="423833674" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Nov 2023 05:17:10 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10906"; a="718031609" X-IronPort-AV: E=Sophos;i="6.04,230,1695711600"; d="scan'208";a="718031609" Received: from zhipengw-mobl1.ccr.corp.intel.com (HELO rzhang1-mobl7.ccr.corp.intel.com) ([10.255.29.237]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Nov 2023 05:17:07 -0800 From: Zhang Rui To: linux@roeck-us.net, jdelvare@suse.com Cc: fenghua.yu@intel.com, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] hwmon: (coretemp) Introduce enum for attr index Date: Mon, 27 Nov 2023 21:16:49 +0800 Message-Id: <20231127131651.476795-2-rui.zhang@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231127131651.476795-1-rui.zhang@intel.com> References: <20231127131651.476795-1-rui.zhang@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 27 Nov 2023 05:17:21 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783723244523574275 X-GMAIL-MSGID: 1783723244523574275 Introduce enum coretemp_attr_index to better describe the index of each sensor attribute and the maximum number of basic/possible attributes. No functional change. Signed-off-by: Zhang Rui --- drivers/hwmon/coretemp.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c index ba82d1e79c13..6053ed3761c2 100644 --- a/drivers/hwmon/coretemp.c +++ b/drivers/hwmon/coretemp.c @@ -43,10 +43,18 @@ MODULE_PARM_DESC(tjmax, "TjMax value in degrees Celsius"); #define BASE_SYSFS_ATTR_NO 2 /* Sysfs Base attr no for coretemp */ #define NUM_REAL_CORES 128 /* Number of Real cores per cpu */ #define CORETEMP_NAME_LENGTH 28 /* String Length of attrs */ -#define MAX_CORE_ATTRS 4 /* Maximum no of basic attrs */ -#define TOTAL_ATTRS (MAX_CORE_ATTRS + 1) #define MAX_CORE_DATA (NUM_REAL_CORES + BASE_SYSFS_ATTR_NO) +enum coretemp_attr_index { + ATTR_LABEL, + ATTR_CRIT_ALARM, + ATTR_TEMP, + ATTR_TJMAX, + ATTR_TTARGET, + TOTAL_ATTRS, /* Maximum no of possible attrs */ + MAX_CORE_ATTRS = ATTR_TJMAX + 1 /* Maximum no of basic attrs */ +}; + #ifdef CONFIG_SMP #define for_each_sibling(i, cpu) \ for_each_cpu(i, topology_sibling_cpumask(cpu)) From patchwork Mon Nov 27 13:16:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Rui" X-Patchwork-Id: 170135 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp3101364vqx; Mon, 27 Nov 2023 05:18:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IE1AdokoozXlt1i6VepSIzGZdFmuTnXSYJ4hAwIoURIJTQRIR5jC+nymm6BUpmovY8P1nNg X-Received: by 2002:a92:c26b:0:b0:35c:d832:5d58 with SMTP id h11-20020a92c26b000000b0035cd8325d58mr3331446ild.17.1701091090763; Mon, 27 Nov 2023 05:18:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701091090; cv=none; d=google.com; s=arc-20160816; b=gcgsLY3heNBG1IQEQs0bS/JXytPfPN4w+pWuvKAsriJOhDOXTfX/bCL5kWBBVUhHJB 7rlYaC4MRXctVikLZLBVjukKhRcINb9/eniZRF3C/d3bScwiAbL1q2Az0izq/r3bWlwD r/k5Sf1RM5ueIpY8zmwNRHT9hR8Kx6m8NWMc2lC21O3cUCBQxYS7AA/pGYeqzCFbaGDe VnWeODXf+TTzxRTRx1xQlokR1gN+EG9n26ZMLzOTHwXDLs63pD2AENEFC+du7yvRTect 9spWiaX153nbvsP7Mjn8ZlLfLepPzeBJ4g++5L7T3KGDi62wd2LDnVhM4jeZLO15KRxS z+kA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=t+1cdv5TxpBJ1GjKW4zpovfXCpAiFX2g6v/ZIrPq+00=; fh=Mbam0pR9JWUnI2UheCn8N0H+ykbrnMeiPzCxF+zJmn8=; b=z+p3+fpwf2PGMKHEEgMoNIsUKZDT/14sKaZpPI5C/4CxPO2m6TmnE2ubtC0Y78YKeq P+4p2pZeBdcqtKDkql8GFdYVBN9XXg9sdp6IcczkqHMjjF9O3D6ng1tJdkEWGzhXqwRs J/SJJwmv5CqmAoLeQuQdVXhSXTD5C7OcrVOeh82/MOkdqOGcVLQ9ZTqWU2TWWZUtG0Uw ghn2z7h+JHNCvmFmci+fUlZWptIcOzQmgtRzi59aq8dqA09486lLSNkBqNonXslldWwr 4NusqtDbl5q1nm6Dc5eMG7dawhzNZLT4vaGctqyMDcxVYhtzx4uFqOxUAb/5kq02lYx9 GvvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=W8biN+dx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id l68-20020a632547000000b005b9066580d1si9478755pgl.754.2023.11.27.05.18.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 05:18:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=W8biN+dx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 1DF7E804C6D0; Mon, 27 Nov 2023 05:17:42 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233476AbjK0NRJ (ORCPT + 99 others); Mon, 27 Nov 2023 08:17:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233468AbjK0NRH (ORCPT ); Mon, 27 Nov 2023 08:17:07 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F9A4189; Mon, 27 Nov 2023 05:17:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701091033; x=1732627033; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jPe+mAbPpnyNZkTqYzOt88Czcd9OZNWfQMy+IPturg4=; b=W8biN+dxmHzU878PhrqG2u/pYVqA3uzFhkBUaZRzyGeR5Wo5SPARnJLN HCjaWZja8lgHG0+4RKIzXQuGLTwNXKG2Ozqv6OQKzHqC8EnD/az1GxvMR OpRIb162rf6/+lB+dUktHVzlPMVxC1kgJyE5MoTie5Dap0X2RL52Imp2E APC/UIKWs/Wg5xi3kdmCivnsHXenpAT6ESGZ+7iTx/Ewc63WF/EMbteMJ vkE1/O9HVTF8g7goE2w2kMF+oQ5XRkbIvku8+hsAtAGhyWrVpIMSKTgkT xDW8Lwyi/kPSneplcISsL7C5WNS0qfOfu0/MQiDq8yKV2KZfIPmyIbfCv Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10906"; a="423833679" X-IronPort-AV: E=Sophos;i="6.04,230,1695711600"; d="scan'208";a="423833679" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Nov 2023 05:17:12 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10906"; a="718031612" X-IronPort-AV: E=Sophos;i="6.04,230,1695711600"; d="scan'208";a="718031612" Received: from zhipengw-mobl1.ccr.corp.intel.com (HELO rzhang1-mobl7.ccr.corp.intel.com) ([10.255.29.237]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Nov 2023 05:17:10 -0800 From: Zhang Rui To: linux@roeck-us.net, jdelvare@suse.com Cc: fenghua.yu@intel.com, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] hwmon: (coretemp) Remove unnecessary dependency of array index Date: Mon, 27 Nov 2023 21:16:50 +0800 Message-Id: <20231127131651.476795-3-rui.zhang@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231127131651.476795-1-rui.zhang@intel.com> References: <20231127131651.476795-1-rui.zhang@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Mon, 27 Nov 2023 05:17:42 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783723291605533988 X-GMAIL-MSGID: 1783723291605533988 When sensor_device_attribute pointer is available, use container_of() to get the temp_data address. This removes the unnecessary dependency of cached index in pdata->core_data[]. Signed-off-by: Zhang Rui --- drivers/hwmon/coretemp.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c index 6053ed3761c2..cef43fedbd58 100644 --- a/drivers/hwmon/coretemp.c +++ b/drivers/hwmon/coretemp.c @@ -342,7 +342,7 @@ static ssize_t show_label(struct device *dev, { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct platform_data *pdata = dev_get_drvdata(dev); - struct temp_data *tdata = pdata->core_data[attr->index]; + struct temp_data *tdata = container_of(attr, struct temp_data, sd_attrs[ATTR_LABEL]); if (tdata->is_pkg_data) return sprintf(buf, "Package id %u\n", pdata->pkg_id); @@ -355,8 +355,7 @@ static ssize_t show_crit_alarm(struct device *dev, { u32 eax, edx; struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); - struct platform_data *pdata = dev_get_drvdata(dev); - struct temp_data *tdata = pdata->core_data[attr->index]; + struct temp_data *tdata = container_of(attr, struct temp_data, sd_attrs[ATTR_CRIT_ALARM]); mutex_lock(&tdata->update_lock); rdmsr_on_cpu(tdata->cpu, tdata->status_reg, &eax, &edx); @@ -369,8 +368,7 @@ static ssize_t show_tjmax(struct device *dev, struct device_attribute *devattr, char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); - struct platform_data *pdata = dev_get_drvdata(dev); - struct temp_data *tdata = pdata->core_data[attr->index]; + struct temp_data *tdata = container_of(attr, struct temp_data, sd_attrs[ATTR_TJMAX]); int tjmax; mutex_lock(&tdata->update_lock); @@ -384,8 +382,7 @@ static ssize_t show_ttarget(struct device *dev, struct device_attribute *devattr, char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); - struct platform_data *pdata = dev_get_drvdata(dev); - struct temp_data *tdata = pdata->core_data[attr->index]; + struct temp_data *tdata = container_of(attr, struct temp_data, sd_attrs[ATTR_TTARGET]); int ttarget; mutex_lock(&tdata->update_lock); @@ -402,8 +399,7 @@ static ssize_t show_temp(struct device *dev, { u32 eax, edx; struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); - struct platform_data *pdata = dev_get_drvdata(dev); - struct temp_data *tdata = pdata->core_data[attr->index]; + struct temp_data *tdata = container_of(attr, struct temp_data, sd_attrs[ATTR_TEMP]); int tjmax; mutex_lock(&tdata->update_lock); @@ -445,7 +441,6 @@ static int create_core_attrs(struct temp_data *tdata, struct device *dev, tdata->sd_attrs[i].dev_attr.attr.name = tdata->attr_name[i]; tdata->sd_attrs[i].dev_attr.attr.mode = 0444; tdata->sd_attrs[i].dev_attr.show = rd_ptr[i]; - tdata->sd_attrs[i].index = attr_no; tdata->attrs[i] = &tdata->sd_attrs[i].dev_attr.attr; } tdata->attr_group.attrs = tdata->attrs; From patchwork Mon Nov 27 13:16:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Rui" X-Patchwork-Id: 170133 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp3100959vqx; Mon, 27 Nov 2023 05:17:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IGKu8KMQnklSz2WQj/I9LcfrUVLGBXpY3mya8tlUZ4EOJ1M9ZJg42WtDzLNR/qgxIhmuriI X-Received: by 2002:a17:90b:38d2:b0:285:b99a:a92d with SMTP id nn18-20020a17090b38d200b00285b99aa92dmr4219372pjb.32.1701091061982; Mon, 27 Nov 2023 05:17:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701091061; cv=none; d=google.com; s=arc-20160816; b=FLaw974rmUc1GfXOsmzlEFoialLGoHXDf6Shr4+ilwxMfxsEdivGF7XMROlmS5XKXR eJ9aIGKkQx60Zi1rTyWjouY0pAuvKkQQQi2n2SBJ8yxoTfyQpYfmDoA/WRhEjm6iq8HT Opc6tCtf7Rjnm0mjvKf+oPBSEaX/i0g2K6vM05Ffvv2h6NAqtGva1UvneSIV038CL6mK c+ekSJc8A0U3PDBoRTQ+O2wOAxMG9m2dQNziapQr3a0KiCNntvRWiz2bTHbxaUty/iwg 0nlcoJHRmHV1qWZDM5YcQSfHhTUefVN8Hect0Y6VXhg7DgXVh3ppXhd3e9aLIwBHdIuM q7+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=jbK+XImTAD2WvaMA4Nc3lXBrb4/VPS8LwyFuAyF4bCk=; fh=Mbam0pR9JWUnI2UheCn8N0H+ykbrnMeiPzCxF+zJmn8=; b=SosQY4c2XQzzYZejtJMBOpaSHjTFGboTJpiDgxHqtQcTOxUc56vRYL+cbu2o3hyfDs uoPZbDzeZLH7r+WM0NzwLAUsA1XMMJ6JNaUMNLAOPC3WLf+7lyFwN8s5rk2iIVULD7eV VScF9A7inaJErW5wjt+WgtYyjYvUjZF9n66hpqv/3bv1bHbfgMpMQq7/6cesXN56aDWX W5AtxCdKbBBs4ACtM+6ThZ0RvVgJaNvDzgGGk2QOUwKz2YvqwNiXNtjD8Nn0toH/JjyR 4pAibn9pV87EHzrNZ6eOt9FYZAFhBi/R3c0hrBuYfIckUdA+5bn41o1F5vAOXCsxkDSF SeDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hT1Rg1Kx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id om8-20020a17090b3a8800b00285d58914ddsi1957989pjb.51.2023.11.27.05.17.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 05:17:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hT1Rg1Kx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 4F60F8061143; Mon, 27 Nov 2023 05:17:36 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233426AbjK0NRQ (ORCPT + 99 others); Mon, 27 Nov 2023 08:17:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233485AbjK0NRL (ORCPT ); Mon, 27 Nov 2023 08:17:11 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99F821B4; Mon, 27 Nov 2023 05:17:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701091036; x=1732627036; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wpYM9lkUhA7Ume69eMZFogv/ktPexXBBfq5eJqiJgJQ=; b=hT1Rg1Kx+yyyALD20R2mwYQ58N3oXMMN1rdRxFkCHTIfnNMl0YVQWqb5 C+gZKp/70iAuMo0AXuYnzrXD5XgXTd11Cc3SE3IY0rsfV4T8kEwebyQ3y /Oy4nBk3u3wCuolAwxoU8bfDp6oGsDkhcp9MgCi1b/AVD5ADarIDMsgGl tSLR94ERMxsMnxPeFY5Wpjlb3zvrYTWvUE+W6e4Hdq8gTOAc9XqlFcBwy uTWzXDZ+sZED2mWT74Pdw0Ug2j2cxJPxeCAqZE6Mha1SUazl+idr9YqX8 fXxW51nWaNCkZ3pD3YEDpJThIe7H7n8YuLugJ3TQZzDNPI7bsUZ8/GBu3 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10906"; a="423833689" X-IronPort-AV: E=Sophos;i="6.04,230,1695711600"; d="scan'208";a="423833689" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Nov 2023 05:17:15 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10906"; a="718031617" X-IronPort-AV: E=Sophos;i="6.04,230,1695711600"; d="scan'208";a="718031617" Received: from zhipengw-mobl1.ccr.corp.intel.com (HELO rzhang1-mobl7.ccr.corp.intel.com) ([10.255.29.237]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Nov 2023 05:17:13 -0800 From: Zhang Rui To: linux@roeck-us.net, jdelvare@suse.com Cc: fenghua.yu@intel.com, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] hwmon: (coretemp) Fix core count limitation Date: Mon, 27 Nov 2023 21:16:51 +0800 Message-Id: <20231127131651.476795-4-rui.zhang@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231127131651.476795-1-rui.zhang@intel.com> References: <20231127131651.476795-1-rui.zhang@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 27 Nov 2023 05:17:36 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783723236111876499 X-GMAIL-MSGID: 1783723261509595170 Currently, coretemp driver only supports 128 cores per package. This loses some core temperation information on systems that have more than 128 cores per package. [ 58.685033] coretemp coretemp.0: Adding Core 128 failed [ 58.692009] coretemp coretemp.0: Adding Core 129 failed Fix the problem by using a per package list to maintain the per core temp_data instead of the fixed length pdata->core_data[] array. Signed-off-by: Zhang Rui --- drivers/hwmon/coretemp.c | 110 ++++++++++++++++++--------------------- 1 file changed, 52 insertions(+), 58 deletions(-) diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c index cef43fedbd58..1bb1a6e4b07b 100644 --- a/drivers/hwmon/coretemp.c +++ b/drivers/hwmon/coretemp.c @@ -39,11 +39,7 @@ static int force_tjmax; module_param_named(tjmax, force_tjmax, int, 0444); MODULE_PARM_DESC(tjmax, "TjMax value in degrees Celsius"); -#define PKG_SYSFS_ATTR_NO 1 /* Sysfs attribute for package temp */ -#define BASE_SYSFS_ATTR_NO 2 /* Sysfs Base attr no for coretemp */ -#define NUM_REAL_CORES 128 /* Number of Real cores per cpu */ #define CORETEMP_NAME_LENGTH 28 /* String Length of attrs */ -#define MAX_CORE_DATA (NUM_REAL_CORES + BASE_SYSFS_ATTR_NO) enum coretemp_attr_index { ATTR_LABEL, @@ -90,17 +86,17 @@ struct temp_data { struct attribute *attrs[TOTAL_ATTRS + 1]; struct attribute_group attr_group; struct mutex update_lock; + struct list_head node; }; /* Platform Data per Physical CPU */ struct platform_data { struct device *hwmon_dev; u16 pkg_id; - u16 cpu_map[NUM_REAL_CORES]; - struct ida ida; struct cpumask cpumask; - struct temp_data *core_data[MAX_CORE_DATA]; struct device_attribute name_attr; + struct mutex core_data_lock; + struct list_head core_data_list; }; struct tjmax_pci { @@ -491,6 +487,23 @@ static struct temp_data *init_temp_data(unsigned int cpu, int pkg_flag) return tdata; } +static struct temp_data *get_tdata(struct platform_data *pdata, int cpu) +{ + struct temp_data *tdata; + + mutex_lock(&pdata->core_data_lock); + list_for_each_entry(tdata, &pdata->core_data_list, node) { + if (cpu >= 0 && !tdata->is_pkg_data && tdata->cpu_core_id == topology_core_id(cpu)) + goto found; + if (cpu < 0 && tdata->is_pkg_data) + goto found; + } + tdata = NULL; +found: + mutex_unlock(&pdata->core_data_lock); + return tdata; +} + static int create_core_data(struct platform_device *pdev, unsigned int cpu, int pkg_flag) { @@ -498,37 +511,29 @@ static int create_core_data(struct platform_device *pdev, unsigned int cpu, struct platform_data *pdata = platform_get_drvdata(pdev); struct cpuinfo_x86 *c = &cpu_data(cpu); u32 eax, edx; - int err, index, attr_no; + int err, attr_no; if (!housekeeping_cpu(cpu, HK_TYPE_MISC)) return 0; + tdata = get_tdata(pdata, pkg_flag ? -1 : cpu); + if (tdata) + return -EEXIST; + + tdata = init_temp_data(cpu, pkg_flag); + if (!tdata) + return -ENOMEM; + /* * Find attr number for sysfs: * We map the attr number to core id of the CPU * The attr number is always core id + 2 * The Pkgtemp will always show up as temp1_*, if available */ - if (pkg_flag) { - attr_no = PKG_SYSFS_ATTR_NO; - } else { - index = ida_alloc(&pdata->ida, GFP_KERNEL); - if (index < 0) - return index; - pdata->cpu_map[index] = topology_core_id(cpu); - attr_no = index + BASE_SYSFS_ATTR_NO; - } - - if (attr_no > MAX_CORE_DATA - 1) { - err = -ERANGE; - goto ida_free; - } - - tdata = init_temp_data(cpu, pkg_flag); - if (!tdata) { - err = -ENOMEM; - goto ida_free; - } + if (pkg_flag) + attr_no = 1; + else + attr_no = tdata->cpu_core_id + 2; /* Test if we can access the status register */ err = rdmsr_safe_on_cpu(cpu, tdata->status_reg, &eax, &edx); @@ -547,20 +552,18 @@ static int create_core_data(struct platform_device *pdev, unsigned int cpu, if (get_ttarget(tdata, &pdev->dev) >= 0) tdata->attr_size++; - pdata->core_data[attr_no] = tdata; - /* Create sysfs interfaces */ err = create_core_attrs(tdata, pdata->hwmon_dev, attr_no); if (err) goto exit_free; + mutex_lock(&pdata->core_data_lock); + list_add(&tdata->node, &pdata->core_data_list); + mutex_unlock(&pdata->core_data_lock); + return 0; exit_free: - pdata->core_data[attr_no] = NULL; kfree(tdata); -ida_free: - if (!pkg_flag) - ida_free(&pdata->ida, index); return err; } @@ -571,9 +574,9 @@ coretemp_add_core(struct platform_device *pdev, unsigned int cpu, int pkg_flag) dev_err(&pdev->dev, "Adding Core %u failed\n", cpu); } -static void coretemp_remove_core(struct platform_data *pdata, int indx) +static void coretemp_remove_core(struct platform_data *pdata, int cpu) { - struct temp_data *tdata = pdata->core_data[indx]; + struct temp_data *tdata = get_tdata(pdata, cpu); /* if we errored on add then this is already gone */ if (!tdata) @@ -582,11 +585,11 @@ static void coretemp_remove_core(struct platform_data *pdata, int indx) /* Remove the sysfs attributes */ sysfs_remove_group(&pdata->hwmon_dev->kobj, &tdata->attr_group); - kfree(pdata->core_data[indx]); - pdata->core_data[indx] = NULL; + mutex_lock(&pdata->core_data_lock); + list_del(&tdata->node); + mutex_unlock(&pdata->core_data_lock); - if (indx >= BASE_SYSFS_ATTR_NO) - ida_free(&pdata->ida, indx - BASE_SYSFS_ATTR_NO); + kfree(tdata); } static int coretemp_device_add(int zoneid) @@ -601,7 +604,8 @@ static int coretemp_device_add(int zoneid) return -ENOMEM; pdata->pkg_id = zoneid; - ida_init(&pdata->ida); + mutex_init(&pdata->core_data_lock); + INIT_LIST_HEAD(&pdata->core_data_list); pdev = platform_device_alloc(DRVNAME, zoneid); if (!pdev) { @@ -629,7 +633,6 @@ static void coretemp_device_remove(int zoneid) struct platform_device *pdev = zone_devices[zoneid]; struct platform_data *pdata = platform_get_drvdata(pdev); - ida_destroy(&pdata->ida); kfree(pdata); platform_device_unregister(pdev); } @@ -699,7 +702,7 @@ static int coretemp_cpu_offline(unsigned int cpu) struct platform_device *pdev = coretemp_get_pdev(cpu); struct platform_data *pd; struct temp_data *tdata; - int i, indx = -1, target; + int target; /* No need to tear down any interfaces for suspend */ if (cpuhp_tasks_frozen) @@ -710,19 +713,10 @@ static int coretemp_cpu_offline(unsigned int cpu) if (!pd->hwmon_dev) return 0; - for (i = 0; i < NUM_REAL_CORES; i++) { - if (pd->cpu_map[i] == topology_core_id(cpu)) { - indx = i + BASE_SYSFS_ATTR_NO; - break; - } - } - - /* Too many cores and this core is not populated, just return */ - if (indx < 0) + tdata = get_tdata(pd, cpu); + if (!tdata) return 0; - tdata = pd->core_data[indx]; - cpumask_clear_cpu(cpu, &pd->cpumask); /* @@ -732,20 +726,20 @@ static int coretemp_cpu_offline(unsigned int cpu) */ target = cpumask_any_and(&pd->cpumask, topology_sibling_cpumask(cpu)); if (target >= nr_cpu_ids) { - coretemp_remove_core(pd, indx); - } else if (tdata && tdata->cpu == cpu) { + coretemp_remove_core(pd, cpu); + } else if (tdata->cpu == cpu) { mutex_lock(&tdata->update_lock); tdata->cpu = target; mutex_unlock(&tdata->update_lock); } + tdata = get_tdata(pd, -1); /* * If all cores in this pkg are offline, remove the interface. */ - tdata = pd->core_data[PKG_SYSFS_ATTR_NO]; if (cpumask_empty(&pd->cpumask)) { if (tdata) - coretemp_remove_core(pd, PKG_SYSFS_ATTR_NO); + coretemp_remove_core(pd, -1); hwmon_device_unregister(pd->hwmon_dev); pd->hwmon_dev = NULL; return 0;