From patchwork Thu Nov 9 17:09:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Tyshchenko X-Patchwork-Id: 10051389 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C96E660632 for ; Thu, 9 Nov 2017 17:13:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B01712B04E for ; Thu, 9 Nov 2017 17:13:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A501C2B052; Thu, 9 Nov 2017 17:13:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 059402B054 for ; Thu, 9 Nov 2017 17:13:37 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eCqLh-00041B-80; Thu, 09 Nov 2017 17:10:41 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eCqLg-0003xk-5C for xen-devel@lists.xenproject.org; Thu, 09 Nov 2017 17:10:40 +0000 Received: from [85.158.143.35] by server-6.bemta-6.messagelabs.com id 57/B4-08608-F0C840A5; Thu, 09 Nov 2017 17:10:39 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrIIsWRWlGSWpSXmKPExsVyMfS6oy5/D0u UQcdDXovvWyYzOTB6HP5whSWAMYo1My8pvyKBNaPtYj9bwXmHikl3GlgaGPuNuxg5OYQEZjJK LOyQ6GLk4mAReMkisf//RzYQR0Kgn1Xi/6H/bCBVEgJZEk/nPGCBsNMkXl2YxwxhV0h83HOcG WKSksTrnZuZQJqFBGYzSTxqgWhgEzCQ2P/uCTuILQJUdG/VZLAiZpCi+3s+giWEBbwkfj3dBb aNRUBV4saGaYwgNq+As8Sbn5OgNstJ3DzXCbaNU8BF4s3H62wQm50lLr4+zjaBUXABI8MqRo3 i1KKy1CJdI3O9pKLM9IyS3MTMHF1DAzO93NTi4sT01JzEpGK95PzcTYzAoGMAgh2Mi9cGHmKU 5GBSEuWVsmSJEuJLyk+pzEgszogvKs1JLT7EKMPBoSTB29INlBMsSk1PrUjLzAGGP0xagoNHS YT3XRdQmre4IDG3ODMdInWKMZDjwp1Lf5g4jm26DCQP7LkFJDfdvAskN3x/ACSfzXzdwMwx7W prE7MQS15+XqqUOK8VyB4BkEEZpXlwa2AxfYlRVkqYlxHocCGegtSi3MwSVPlXjOIcjErCvNt BzuHJzCuBu+YV0KFMQIdGs4MdWpKIkJJqYORcmTvrTbmxQ0/+pOdX5Te21joq1Cimp172v7Cd Y+Oznnz1rXOZ/Rrmegh731E83RygHKzDdHxB0n5BW6v2w+fvPdIQeTPjVFQ816HpJVfmH+PQz +VfoNTP90/iQLhZ4CVjv8aD4VFXEr1ncxwUDuOa/5Gp6ya3iIzG3f+nuJaeNubXl9P6osRSnJ FoqMVcVJwIAOO23GTkAgAA X-Env-Sender: olekstysh@gmail.com X-Msg-Ref: server-7.tower-21.messagelabs.com!1510247438!81338349!1 X-Originating-IP: [209.85.215.65] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 64374 invoked from network); 9 Nov 2017 17:10:39 -0000 Received: from mail-lf0-f65.google.com (HELO mail-lf0-f65.google.com) (209.85.215.65) by server-7.tower-21.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 9 Nov 2017 17:10:39 -0000 Received: by mail-lf0-f65.google.com with SMTP id e143so8033822lfg.12 for ; Thu, 09 Nov 2017 09:10:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=9MzhsIO4UlYZdR4PhAJ/BaPATTHyJ/Ot7I6T5bDJnKk=; b=CW/43UjYXeT3D40SbNwRFM1Ud6AU7ltry6tCvBA3J0P0+8k1WUZePuCIETXMW7stAn xseuHt2JBZVpp1yFy4kBwPm0SWDb7kGjFz02XX3lPc0SXYi5pTI7HzglYPUfGrfghqbg KxeSiuV2ltx1gJBFdFbTTvRPm9ShkGAezbASq7zTay+G+E1PUh29HFzhNCTNskLda6lF piMlp+F4Guw+v+5NYNq7WV8EQbIu+eMSxqflR7c2m5Thjm/twK75rDygaYIDEZ6xmKWQ pY7h8Hyq5jtR/C0LaNuVNyaHIGctqiFNXo5R1Lx1B+SX/gnhCVZw72ceYkV0uT6CcZ6S 1UZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=9MzhsIO4UlYZdR4PhAJ/BaPATTHyJ/Ot7I6T5bDJnKk=; b=CTcncY63++IDkWpgJ6vp/ml5WdAmCFOnIl1GXdg/ECzL8HHk/WWTOfSqKrID8qi4YF lqaQBlDnUqMI0jYpOVdVMgFgbpoInWnj8CXWLTNVWO4s+pGXA6pG+/oavGITdIKnguKp ey1wjEmbdkS6Z5GP/d6xTwi8w0gyi3ZSyYUf99Abpou7ma6n/psDNprQeeMR9wk4DWdR 70XAcmoj6EQn3VJg17Tp5hAOOGzBc2DabXq3fiQTTYwsCby0nzVuOZ56EM5ehpS21Vr4 Y1tK+p9aaEILeakErR8fdjXhtWP5UXhkGnxTrecMi5DpZ1eCk1r0Zy7AgA9sB0sA+iLQ hj8A== X-Gm-Message-State: AJaThX7jWw17evL33HoEOncJPKPK6rO6puLGQpg3MG0DuW7sevRLi29O egybOBP+/T4oHmBGiQD50Ru9Kg== X-Google-Smtp-Source: AGs4zMbttrkxmEMRL7DO4kHnWRLB9TaKM8BJ1bFxO8liECIVF78pwPLgSYlum6S1P9JMNo2o4NK3xw== X-Received: by 10.25.143.194 with SMTP id s63mr82805lfk.143.1510247438118; Thu, 09 Nov 2017 09:10:38 -0800 (PST) Received: from otyshchenko.kyiv.epam.com (ll-53.209.223.85.sovam.net.ua. [85.223.209.53]) by smtp.gmail.com with ESMTPSA id x90sm1394299ljb.86.2017.11.09.09.10.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 09 Nov 2017 09:10:37 -0800 (PST) From: Oleksandr Tyshchenko To: xen-devel@lists.xenproject.org Date: Thu, 9 Nov 2017 19:09:56 +0200 Message-Id: <1510247421-24094-7-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1510247421-24094-1-git-send-email-olekstysh@gmail.com> References: <1510247421-24094-1-git-send-email-olekstysh@gmail.com> Cc: Stefano Stabellini , Andrew Cooper , Oleksandr Dmytryshyn , Julien Grall , Oleksandr Tyshchenko , Jan Beulich Subject: [Xen-devel] [RFC PATCH 06/31] cpufreq: make cpufreq driver more generalizable X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Oleksandr Dmytryshyn First implementation of the cpufreq driver has been written with x86 in mind. This patch makes possible the cpufreq driver be working on both x86 and arm architectures. This is a rebased version of the original patch: https://lists.xen.org/archives/html/xen-devel/2014-11/msg00932.html Signed-off-by: Oleksandr Dmytryshyn Signed-off-by: Oleksandr Tyshchenko CC: Jan Beulich CC: Andrew Cooper CC: Stefano Stabellini CC: Julien Grall --- xen/drivers/cpufreq/cpufreq.c | 81 +++++++++++++++++++++++++++++++++++++--- xen/include/public/platform.h | 1 + xen/include/xen/processor_perf.h | 6 +++ 3 files changed, 82 insertions(+), 6 deletions(-) diff --git a/xen/drivers/cpufreq/cpufreq.c b/xen/drivers/cpufreq/cpufreq.c index ab909e2..64e1ae7 100644 --- a/xen/drivers/cpufreq/cpufreq.c +++ b/xen/drivers/cpufreq/cpufreq.c @@ -42,7 +42,6 @@ #include #include #include -#include #include static unsigned int __read_mostly usr_min_freq; @@ -206,6 +205,7 @@ int cpufreq_add_cpu(unsigned int cpu) } else { /* domain sanity check under whatever coordination type */ firstcpu = cpumask_first(cpufreq_dom->map); +#ifdef CONFIG_ACPI if ((perf->domain_info.coord_type != processor_pminfo[firstcpu]->perf.domain_info.coord_type) || (perf->domain_info.num_processors != @@ -221,6 +221,19 @@ int cpufreq_add_cpu(unsigned int cpu) ); return -EINVAL; } +#else /* !CONFIG_ACPI */ + if ((perf->domain_info.num_processors != + processor_pminfo[firstcpu]->perf.domain_info.num_processors)) { + + printk(KERN_WARNING "cpufreq fail to add CPU%d:" + "incorrect num processors (%"PRIu64"), " + "expect(%"PRIu64")\n", + cpu, perf->domain_info.num_processors, + processor_pminfo[firstcpu]->perf.domain_info.num_processors + ); + return -EINVAL; + } +#endif /* CONFIG_ACPI */ } if (!domexist || hw_all) { @@ -380,6 +393,7 @@ int cpufreq_del_cpu(unsigned int cpu) return 0; } +#ifdef CONFIG_ACPI static void print_PCT(struct xen_pct_register *ptr) { printk("\t_PCT: descriptor=%d, length=%d, space_id=%d, " @@ -387,12 +401,14 @@ static void print_PCT(struct xen_pct_register *ptr) ptr->descriptor, ptr->length, ptr->space_id, ptr->bit_width, ptr->bit_offset, ptr->reserved, ptr->address); } +#endif /* CONFIG_ACPI */ static void print_PSS(struct xen_processor_px *ptr, int count) { int i; printk("\t_PSS: state_count=%d\n", count); for (i=0; inum_entries, ptr->revision, ptr->domain, ptr->coord_type, ptr->num_processors); +#else /* !CONFIG_ACPI */ + printk("\t_PSD: domain=%"PRId64" num_processors=%"PRId64"\n", + ptr->domain, ptr->num_processors); +#endif /* CONFIG_ACPI */ } static void print_PPC(unsigned int platform_limit) @@ -418,13 +445,53 @@ static void print_PPC(unsigned int platform_limit) printk("\t_PPC: %d\n", platform_limit); } +static inline bool is_pss_data(struct xen_processor_performance *px) +{ +#ifdef CONFIG_ACPI + return px->flags & XEN_PX_PSS; +#else + return px->flags == XEN_PX_DATA; +#endif +} + +static inline bool is_psd_data(struct xen_processor_performance *px) +{ +#ifdef CONFIG_ACPI + return px->flags & XEN_PX_PSD; +#else + return px->flags == XEN_PX_DATA; +#endif +} + +static inline bool is_ppc_data(struct xen_processor_performance *px) +{ +#ifdef CONFIG_ACPI + return px->flags & XEN_PX_PPC; +#else + return px->flags == XEN_PX_DATA; +#endif +} + +static inline bool is_all_data(struct xen_processor_performance *px) +{ +#ifdef CONFIG_ACPI + return px->flags == ( XEN_PX_PCT | XEN_PX_PSS | XEN_PX_PSD | XEN_PX_PPC ); +#else + return px->flags == XEN_PX_DATA; +#endif +} + int set_px_pminfo(uint32_t acpi_id, struct xen_processor_performance *dom0_px_info) { int ret=0, cpuid; struct processor_pminfo *pmpt; struct processor_performance *pxpt; +#ifdef CONFIG_ACPI cpuid = get_cpu_id(acpi_id); +#else + cpuid = acpi_id; +#endif if ( cpuid < 0 || !dom0_px_info) { ret = -EINVAL; @@ -446,6 +513,8 @@ int set_px_pminfo(uint32_t acpi_id, struct xen_processor_performance *dom0_px_in processor_pminfo[cpuid] = pmpt; } pxpt = &pmpt->perf; + +#ifdef CONFIG_ACPI pmpt->acpi_id = acpi_id; pmpt->id = cpuid; @@ -472,8 +541,9 @@ int set_px_pminfo(uint32_t acpi_id, struct xen_processor_performance *dom0_px_in print_PCT(&pxpt->status_register); } } +#endif /* CONFIG_ACPI */ - if ( dom0_px_info->flags & XEN_PX_PSS ) + if ( is_pss_data(dom0_px_info) ) { /* capability check */ if (dom0_px_info->state_count <= 1) @@ -500,7 +570,7 @@ int set_px_pminfo(uint32_t acpi_id, struct xen_processor_performance *dom0_px_in print_PSS(pxpt->states,pxpt->state_count); } - if ( dom0_px_info->flags & XEN_PX_PSD ) + if ( is_psd_data(dom0_px_info) ) { /* check domain coordination */ if (dom0_px_info->shared_type != CPUFREQ_SHARED_TYPE_ALL && @@ -520,7 +590,7 @@ int set_px_pminfo(uint32_t acpi_id, struct xen_processor_performance *dom0_px_in print_PSD(&pxpt->domain_info); } - if ( dom0_px_info->flags & XEN_PX_PPC ) + if ( is_ppc_data(dom0_px_info) ) { pxpt->platform_limit = dom0_px_info->platform_limit; @@ -534,8 +604,7 @@ int set_px_pminfo(uint32_t acpi_id, struct xen_processor_performance *dom0_px_in } } - if ( dom0_px_info->flags == ( XEN_PX_PCT | XEN_PX_PSS | - XEN_PX_PSD | XEN_PX_PPC ) ) + if ( is_all_data(dom0_px_info) ) { pxpt->init = XEN_PX_INIT; diff --git a/xen/include/public/platform.h b/xen/include/public/platform.h index 94dbc3f..328579c 100644 --- a/xen/include/public/platform.h +++ b/xen/include/public/platform.h @@ -384,6 +384,7 @@ DEFINE_XEN_GUEST_HANDLE(xenpf_getidletime_t); #define XEN_PX_PSS 2 #define XEN_PX_PPC 4 #define XEN_PX_PSD 8 +#define XEN_PX_DATA 16 struct xen_power_register { uint32_t space_id; diff --git a/xen/include/xen/processor_perf.h b/xen/include/xen/processor_perf.h index d8a1ba6..afdccf2 100644 --- a/xen/include/xen/processor_perf.h +++ b/xen/include/xen/processor_perf.h @@ -3,7 +3,9 @@ #include #include +#ifdef CONFIG_ACPI #include +#endif #define XEN_PX_INIT 0x80000000 @@ -24,8 +26,10 @@ int cpufreq_del_cpu(unsigned int); struct processor_performance { uint32_t state; uint32_t platform_limit; +#ifdef CONFIG_ACPI struct xen_pct_register control_register; struct xen_pct_register status_register; +#endif uint32_t state_count; struct xen_processor_px *states; struct xen_psd_package domain_info; @@ -35,8 +39,10 @@ struct processor_performance { }; struct processor_pminfo { +#ifdef CONFIG_ACPI uint32_t acpi_id; uint32_t id; +#endif struct processor_performance perf; };