From patchwork Tue Oct 25 03:40:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Sun X-Patchwork-Id: 9393905 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 B00D360762 for ; Tue, 25 Oct 2016 02:37:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A20A42927D for ; Tue, 25 Oct 2016 02:37:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 963A029296; Tue, 25 Oct 2016 02:37:00 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED 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 749F82927D for ; Tue, 25 Oct 2016 02:36:59 +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 1byrZ0-0004Up-QO; Tue, 25 Oct 2016 02:34:06 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1byrZ0-0004U0-82 for xen-devel@lists.xenproject.org; Tue, 25 Oct 2016 02:34:06 +0000 Received: from [193.109.254.147] by server-9.bemta-6.messagelabs.com id 6D/E5-28857-D94CE085; Tue, 25 Oct 2016 02:34:05 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrPLMWRWlGSWpSXmKPExsVywNykWHfOEb4 Ig1frLS2+b5nM5MDocfjDFZYAxijWzLyk/IoE1oxvUzexFiwwqFh14RdrA+NlxS5GTg4hgQqJ iU92soDYEgK8EkeWzWCFsAMkHiy+ydTFyAVU08Ao0TrhLCNIgk1AXeLx1x4mEFtEQEni3qrJY EXMAvsZJX69fAw2SVggWGLhykvsIDaLgKrEt8VLwKbyCnhIrFmwiQlig5zEyWOTweKcQPE7e4 +zQ1zkLtHX0MQ4gZF3ASPDKkaN4tSistQiXUNzvaSizPSMktzEzBxdQwMzvdzU4uLE9NScxKR iveT83E2MwIBgAIIdjLc3BhxilORgUhLlnbmJL0KILyk/pTIjsTgjvqg0J7X4EKMMB4eSBO/6 w0A5waLU9NSKtMwcYGjCpCU4eJREeJ+ApHmLCxJzizPTIVKnGBWlxHkXgSQEQBIZpXlwbbB4u MQoKyXMywh0iBBPQWpRbmYJqvwrRnEORiVh3hcgU3gy80rgpr8CWswEtFgwngdkcUkiQkqqgd E11u2WY4uCbdW0EtNdNc3+qbJFzQ++5N/a+Wa+2/Vw7zupAaITHy6Vf/leKrTC19I3Ibj3oXN zjWnpovAbSq9r5/s/upvXsqVDumfboqn+trF7mf6EWUa/3rkkPed7UPijtL4HIaJOzi/VD8dv ns0WvGRxX+eSH/vZ5XZ7HF+bNScgb1dduRJLcUaioRZzUXEiAFqocqGCAgAA X-Env-Sender: yi.y.sun@linux.intel.com X-Msg-Ref: server-14.tower-27.messagelabs.com!1477362814!54875270!10 X-Originating-IP: [192.55.52.115] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.0.13; banners=-,-,- X-VirusChecked: Checked Received: (qmail 50556 invoked from network); 25 Oct 2016 02:34:04 -0000 Received: from mga14.intel.com (HELO mga14.intel.com) (192.55.52.115) by server-14.tower-27.messagelabs.com with DHE-RSA-CAMELLIA256-SHA encrypted SMTP; 25 Oct 2016 02:34:04 -0000 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP; 24 Oct 2016 19:34:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.31,544,1473145200"; d="scan'208"; a="1049570198" Received: from vmmmba-s2600wft.bj.intel.com ([10.240.193.60]) by orsmga001.jf.intel.com with ESMTP; 24 Oct 2016 19:34:02 -0700 From: Yi Sun To: xen-devel@lists.xenproject.org Date: Tue, 25 Oct 2016 11:40:57 +0800 Message-Id: <1477366863-5246-10-git-send-email-yi.y.sun@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1477366863-5246-1-git-send-email-yi.y.sun@linux.intel.com> References: <1477366863-5246-1-git-send-email-yi.y.sun@linux.intel.com> Cc: wei.liu2@citrix.com, he.chen@linux.intel.com, andrew.cooper3@citrix.com, ian.jackson@eu.citrix.com, Yi Sun , jbeulich@suse.com, chao.p.peng@linux.intel.com Subject: [Xen-devel] [PATCH v3 09/15] x86: refactor psr: Implement get value callback function. 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 Get feature COS register value is an interface provided by psr.c. It can be abstracted as another operation. This patch adds 'get_val' callback function to get the COS register value of the feature and implement the callback function for L3 CAT/CDP. It also modifies the domctl interface to make it general. Signed-off-by: Yi Sun --- xen/arch/x86/domctl.c | 18 +++++------ xen/arch/x86/psr.c | 79 ++++++++++++++++++++++++++++------------------- xen/include/asm-x86/psr.h | 4 +-- 3 files changed, 59 insertions(+), 42 deletions(-) diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c index 2a2fe04..3d7fc34 100644 --- a/xen/arch/x86/domctl.c +++ b/xen/arch/x86/domctl.c @@ -1404,23 +1404,23 @@ long arch_do_domctl( break; case XEN_DOMCTL_PSR_CAT_OP_GET_L3_CBM: - ret = psr_get_l3_cbm(d, domctl->u.psr_cat_op.target, - &domctl->u.psr_cat_op.data, - PSR_CBM_TYPE_L3); + ret = psr_get_val(d, domctl->u.psr_cat_op.target, + &domctl->u.psr_cat_op.data, + PSR_CBM_TYPE_L3); copyback = 1; break; case XEN_DOMCTL_PSR_CAT_OP_GET_L3_CODE: - ret = psr_get_l3_cbm(d, domctl->u.psr_cat_op.target, - &domctl->u.psr_cat_op.data, - PSR_CBM_TYPE_L3_CODE); + ret = psr_get_val(d, domctl->u.psr_cat_op.target, + &domctl->u.psr_cat_op.data, + PSR_CBM_TYPE_L3_CODE); copyback = 1; break; case XEN_DOMCTL_PSR_CAT_OP_GET_L3_DATA: - ret = psr_get_l3_cbm(d, domctl->u.psr_cat_op.target, - &domctl->u.psr_cat_op.data, - PSR_CBM_TYPE_L3_DATA); + ret = psr_get_val(d, domctl->u.psr_cat_op.target, + &domctl->u.psr_cat_op.data, + PSR_CBM_TYPE_L3_DATA); copyback = 1; break; diff --git a/xen/arch/x86/psr.c b/xen/arch/x86/psr.c index acd180c..b8bb09b 100644 --- a/xen/arch/x86/psr.c +++ b/xen/arch/x86/psr.c @@ -52,6 +52,9 @@ struct feat_ops { /* get_feat_info is used to get feature HW info. */ bool (*get_feat_info)(const struct feat_node *feat, enum cbm_type type, uint32_t dat[], uint32_t array_len); + /* get_val is used to get feature COS register value. */ + int (*get_val)(const struct feat_node *feat, unsigned int cos, + enum cbm_type type, uint64_t *val); }; /* CAT/CDP HW info data structure. */ @@ -244,9 +247,42 @@ static bool l3_cat_get_feat_info(const struct feat_node *feat, return true; } +static int l3_cat_get_val(const struct feat_node *feat, unsigned int cos, + enum cbm_type type, uint64_t *val) +{ + if ( cos > feat->info.cos_max ) + /* Use default value. */ + cos = 0; + + switch ( type ) { + /* CDP */ + case PSR_CBM_TYPE_L3_DATA: + case PSR_CBM_TYPE_L3_CODE: + if ( feat->feature != PSR_SOCKET_L3_CDP ) + return -ENXIO; + + if ( type == PSR_CBM_TYPE_L3_DATA ) + *val = get_cdp_data(feat, cos); + else + *val = get_cdp_code(feat, cos); + break; + + /* CAT */ + case PSR_CBM_TYPE_L3: + *val = feat->cos_reg_val[cos]; + break; + + default: + return 0; + } + + return 1; +} + struct feat_ops l3_cat_ops = { .init_feature = l3_cat_init_feature, .get_feat_info = l3_cat_get_feat_info, + .get_val = l3_cat_get_val, }; static unsigned int get_socket_cpu(unsigned int socket) @@ -486,45 +522,26 @@ int psr_get_info(unsigned int socket, enum cbm_type type, return -ENOENT; } -int psr_get_l3_cbm(struct domain *d, unsigned int socket, - uint64_t *cbm, enum cbm_type type) +int psr_get_val(struct domain *d, unsigned int socket, + uint64_t *val, enum cbm_type type) { - struct psr_cat_socket_info *info = get_cat_socket_info(socket); - bool_t cdp_enabled = cdp_is_enabled(socket); + const struct psr_cat_socket_info *info = get_cat_socket_info(socket); unsigned int cos = d->arch.psr_cos_ids[socket]; - struct feat_node *feat_tmp; + const struct feat_node *feat_tmp; + int ret; if ( IS_ERR(info) ) return PTR_ERR(info); - feat_tmp = get_feat_l3(info); - if ( !feat_tmp ) - return -ENOENT; - - switch ( type ) + list_for_each_entry(feat_tmp, &info->feat_list, list) { - case PSR_CBM_TYPE_L3: - if ( cdp_enabled ) - return -EXDEV; - *cbm = feat_tmp->cos_reg_val[cos]; - break; + ret = feat_tmp->ops.get_val(feat_tmp, cos, type, val); + if ( ret < 0 ) + return ret; - case PSR_CBM_TYPE_L3_CODE: - if ( !cdp_enabled ) - *cbm = feat_tmp->cos_reg_val[cos]; - else - *cbm = get_cdp_code(feat_tmp, cos); - break; - - case PSR_CBM_TYPE_L3_DATA: - if ( !cdp_enabled ) - *cbm = feat_tmp->cos_reg_val[cos]; - else - *cbm = get_cdp_data(feat_tmp, cos); - break; - - default: - ASSERT_UNREACHABLE(); + if ( ret > 0 ) + /* Found */ + break; } return 0; diff --git a/xen/include/asm-x86/psr.h b/xen/include/asm-x86/psr.h index eccfa75..f2872a2 100644 --- a/xen/include/asm-x86/psr.h +++ b/xen/include/asm-x86/psr.h @@ -65,8 +65,8 @@ void psr_ctxt_switch_to(struct domain *d); int psr_get_info(unsigned int socket, enum cbm_type type, uint32_t dat[], uint32_t array_len); -int psr_get_l3_cbm(struct domain *d, unsigned int socket, - uint64_t *cbm, enum cbm_type type); +int psr_get_val(struct domain *d, unsigned int socket, + uint64_t *val, enum cbm_type type); int psr_set_l3_cbm(struct domain *d, unsigned int socket, uint64_t cbm, enum cbm_type type);