Received: by 10.223.185.116 with SMTP id b49csp4241504wrg; Tue, 6 Mar 2018 12:13:36 -0800 (PST) X-Google-Smtp-Source: AG47ELtqLSlDX2HiZtESTm2AMB6IVN3LjXXMb53PZbRA1jWb/EyUhvN2jBjC+/CTYUbHhHdbKDrw X-Received: by 10.98.11.19 with SMTP id t19mr20165583pfi.70.1520367215933; Tue, 06 Mar 2018 12:13:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520367215; cv=none; d=google.com; s=arc-20160816; b=fdIck+i5jH92VbGGItm+OVywISVvaFfKS71xoMs43sc+ZFZ2g02xXdWZqFHHZK52nK Sy4CkEjQaS3phk4/sRCatf7FM60CDLc/w/0g2Oc2EimfjmYTOvo7UZQlbAS8mrrN+9ro a8Kx1VpptylUgAuJbXdh3d04LCtt/qotJn+qmVBF1vwrNeEQXIBX8626d8ZKbR2LFw4f uqHHGbFn42f1jlpVTdLkmB6IyhBduVjqAVZCULBMPiYBFo2RaOGEGFGacoJuKi87eoKM wkJbBIwAqB8CFhci+B3QW/ux+kemJZMsDoEzhe2t9GqFwIWEo6xoObFlLq0VlByVA2hy nkKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=9mzzYSZnq7nmKIh2BRC5x2kF1AUVHN9/X31nDQnVzkg=; b=dkPna9fQFpCCUUlSir7VpFQmc1gvHB64AP2zY2e2UrdqbCnPQvNWS8goW8Pt67TUUu Dqg45FxZ0hJPIQkQnVvcbBUXVTPblhl8yKzbmI7UoyvZmwtQ+3mLLKd6+4zhKBItwxH3 fKlV6WauiLApdSvM3esKi54bxnPIsONAkll9B5MO50t9bi5+dWQWiFD00/92A1R2Yj+e 1GjivRa1cpP2Zg/ToPnOCiZnKB+++zQS3v6xCUNuPVKUl49+ScY42AKSzYfXB7n1ytnW EM4K42mkwI+v3t3cZjVeibN4SD5NpqZG6IxDcY/fKj+RgGIEVRFbF7KUmVAORXnQR6tp lqWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=WVBrG01f; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n3si10288410pgp.102.2018.03.06.12.13.19; Tue, 06 Mar 2018 12:13:35 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=WVBrG01f; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753899AbeCFUM0 (ORCPT + 99 others); Tue, 6 Mar 2018 15:12:26 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:41112 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753466AbeCFUMZ (ORCPT ); Tue, 6 Mar 2018 15:12:25 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w26KBwQx168858; Tue, 6 Mar 2018 20:12:20 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2017-10-26; bh=9mzzYSZnq7nmKIh2BRC5x2kF1AUVHN9/X31nDQnVzkg=; b=WVBrG01fteEtB1ah3kluo+VnGbM8nsQmsU0tarY1F/xJcI/skfL8G8arglcrhcYD1GKK eWOWpqWOEKGJZLnD9nFIgJzJIjDNeVe+hGJBQuSISZmucozq+nT66AMHesYRojWGUHGP RY4EYb2YzqTaDU0BKMnWTYEzo0hMPoSMqtX/MYEDRaZHG3WF5KTuGynezzD2pusi3y4P loTvLvl60zcSqvIejQg7R4UTqQyWDBB19I+EUylEpV3EfROTFvunYWeOYGli6A3wg1Iz +nCJ+KIx7zRXSZPQ9UpDYH7hd47kB6fU+tJ9E0TaUTAck5uws8UWHVw7v8xvV8+E+lLt bw== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2120.oracle.com with ESMTP id 2gj1d1r4mx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 06 Mar 2018 20:12:20 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w26KCKQH032754 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 6 Mar 2018 20:12:20 GMT Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w26KCJCV018104; Tue, 6 Mar 2018 20:12:19 GMT Received: from paddy.uk.oracle.com (/10.175.222.67) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 06 Mar 2018 12:12:19 -0800 From: Joao Martins To: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Cc: Joao Martins , Boris Ostrovsky , Juergen Gross Subject: [PATCH v1] xen: acpi: upload _PSD info for offline CPUs too Date: Tue, 6 Mar 2018 20:12:09 +0000 Message-Id: <20180306201209.21890-1-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8824 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1803060218 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org All uploaded PM data from offline CPUs takes the info from vCPU 0 and changing only the acpi_id. For processors which P-state coordination type is HW_ALL (0xFD) it is OK to upload bogus P-state dependency information (_PSD), because Xen will ignore cpufreq domains existence. Albeit for hardware exposing Px coordination types as SW_ANY or SW_ALL, this will have some unintended side effects. Effectively, it will look at the P-state domain existence and *if it already exists* it will skip the acpi-cpufreq initialization and thus inherit the policy from the first CPU in the cpufreq domain. This will finally lead to the original cpu not changing target freq to P0 other than the first in the domain. Which will make turbo boost not getting enabled (e.g. for 'performance' governor) for all cpus. This patch fixes that, by also evaluating _PSD when enumerating all ACPI procesors (online and offline) and always uploading the correct P-State dependency up to Xen. Signed-off-by: Joao Martins --- xen_processor_get_psd() is taken from acpi_processor_get_psd() (drivers/acpi/processor_perflib.c) simply because only Xen Dom0 needs to handle vcpus != pcpus. If preferred I could try exporting that API instead and use it here. --- drivers/xen/xen-acpi-processor.c | 101 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/drivers/xen/xen-acpi-processor.c b/drivers/xen/xen-acpi-processor.c index 23e391d3ec01..63b3d005a1bb 100644 --- a/drivers/xen/xen-acpi-processor.c +++ b/drivers/xen/xen-acpi-processor.c @@ -53,6 +53,10 @@ static unsigned long *acpi_ids_done; static unsigned long *acpi_id_present; /* And if there is an _CST definition (or a PBLK) for the ACPI IDs */ static unsigned long *acpi_id_cst_present; +/* And if there is an _PSD definition for the ACPI IDs */ +static unsigned long *acpi_id_psd_present; +/* Which ACPI P-State dependencies for a enumerated processor */ +static struct acpi_psd_package *acpi_psd; static int push_cxx_to_hypervisor(struct acpi_processor *_pr) { @@ -319,6 +323,69 @@ static unsigned int __init get_max_acpi_id(void) pr_debug("Max ACPI ID: %u\n", max_acpi_id); return max_acpi_id; } + +static int xen_processor_get_psd(acpi_handle handle, + struct acpi_psd_package *pdomain) +{ + int result = 0; + acpi_status status = AE_OK; + struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL}; + struct acpi_buffer format = {sizeof("NNNNN"), "NNNNN"}; + struct acpi_buffer state = {0, NULL}; + union acpi_object *psd = NULL; + + status = acpi_evaluate_object(handle, "_PSD", NULL, &buffer); + if (ACPI_FAILURE(status)) + return -ENODEV; + + psd = buffer.pointer; + if (!psd || (psd->type != ACPI_TYPE_PACKAGE)) { + pr_err("Invalid _PSD data\n"); + result = -EFAULT; + goto end; + } + + if (psd->package.count != 1) { + pr_err("Invalid _PSD data\n"); + result = -EFAULT; + goto end; + } + + state.length = sizeof(struct acpi_psd_package); + state.pointer = pdomain; + + status = acpi_extract_package(&(psd->package.elements[0]), + &format, &state); + if (ACPI_FAILURE(status)) { + pr_err("Invalid _PSD data\n"); + result = -EFAULT; + goto end; + } + + if (pdomain->num_entries != ACPI_PSD_REV0_ENTRIES) { + pr_err("Unknown _PSD:num_entries\n"); + result = -EFAULT; + goto end; + } + + if (pdomain->revision != ACPI_PSD_REV0_REVISION) { + pr_err("Unknown _PSD:revision\n"); + result = -EFAULT; + goto end; + } + + if (pdomain->coord_type != DOMAIN_COORD_TYPE_SW_ALL && + pdomain->coord_type != DOMAIN_COORD_TYPE_SW_ANY && + pdomain->coord_type != DOMAIN_COORD_TYPE_HW_ALL) { + pr_err("Invalid _PSD:coord_type\n"); + result = -EFAULT; + goto end; + } +end: + kfree(buffer.pointer); + return result; +} + /* * The read_acpi_id and check_acpi_ids are there to support the Xen * oddity of virtual CPUs != physical CPUs in the initial domain. @@ -372,6 +439,15 @@ read_acpi_id(acpi_handle handle, u32 lvl, void *context, void **rv) pr_debug("ACPI CPU%u w/ PBLK:0x%lx\n", acpi_id, (unsigned long)pblk); + /* It has P-state dependencies */ + if (!xen_processor_get_psd(handle, &acpi_psd[acpi_id])) { + __set_bit(acpi_id, acpi_id_psd_present); + + pr_debug("ACPI CPU%u w/ PST:coord_type = %llu domain = %llu\n", + acpi_id, acpi_psd[acpi_id].coord_type, + acpi_psd[acpi_id].domain); + } + status = acpi_evaluate_object(handle, "_CST", NULL, &buffer); if (ACPI_FAILURE(status)) { if (!pblk) @@ -382,6 +458,7 @@ read_acpi_id(acpi_handle handle, u32 lvl, void *context, void **rv) return AE_OK; } + static int check_acpi_ids(struct acpi_processor *pr_backup) { @@ -405,6 +482,23 @@ static int check_acpi_ids(struct acpi_processor *pr_backup) return -ENOMEM; } + acpi_id_psd_present = kcalloc(BITS_TO_LONGS(nr_acpi_bits), + sizeof(unsigned long), GFP_KERNEL); + if (!acpi_id_psd_present) { + kfree(acpi_id_present); + kfree(acpi_id_cst_present); + return -ENOMEM; + } + + acpi_psd = kcalloc(nr_acpi_bits, sizeof(struct acpi_psd_package), + GFP_KERNEL); + if (!acpi_psd) { + kfree(acpi_id_present); + kfree(acpi_id_cst_present); + kfree(acpi_id_psd_present); + return -ENOMEM; + } + acpi_walk_namespace(ACPI_TYPE_PROCESSOR, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX, read_acpi_id, NULL, NULL, NULL); @@ -417,6 +511,11 @@ static int check_acpi_ids(struct acpi_processor *pr_backup) pr_backup->acpi_id = i; /* Mask out C-states if there are no _CST or PBLK */ pr_backup->flags.power = test_bit(i, acpi_id_cst_present); + if (test_bit(i, acpi_id_psd_present)) { + memcpy(&pr_backup->performance->domain_info, + &acpi_psd[i], + sizeof(struct acpi_psd_package)); + } (void)upload_pm_data(pr_backup); } } @@ -566,6 +665,8 @@ static void __exit xen_acpi_processor_exit(void) kfree(acpi_ids_done); kfree(acpi_id_present); kfree(acpi_id_cst_present); + kfree(acpi_id_psd_present); + kfree(acpi_psd); for_each_possible_cpu(i) acpi_processor_unregister_performance(i); -- 2.11.0