From patchwork Sat Apr 1 13:53:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Sun X-Patchwork-Id: 9657967 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 E5C6760349 for ; Sat, 1 Apr 2017 13:56:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DCB52285C2 for ; Sat, 1 Apr 2017 13:56:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CFE8628610; Sat, 1 Apr 2017 13:56:26 +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.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,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 69B1C285C2 for ; Sat, 1 Apr 2017 13:56:26 +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 1cuJTq-0005sK-0v; Sat, 01 Apr 2017 13:54:14 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cuJTp-0005oy-8O for xen-devel@lists.xenproject.org; Sat, 01 Apr 2017 13:54:13 +0000 Received: from [85.158.137.68] by server-7.bemta-3.messagelabs.com id FD/D0-23854-501BFD85; Sat, 01 Apr 2017 13:54:13 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrNLMWRWlGSWpSXmKPExsXS1tYhosuy8X6 EwYT7Qhbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8af9VNYCyaqVrxuy25g/CTdxcjFwSJwi0li +vUZ7CCOkMA0RomOu1+AHE4OCQFeiSPLZrBC2P4Sp/tOgdlCAvUSf1Z2gNlsAuoSj7/2MIHYI gJKEvdWTWYCGcQssJNJYt3p78wgCWGBKIlJ98+CNbAIqEqc2rQNLM4r4Clx++8ZJogFchInj0 0Gq+EEil95sY8FYpmHxKpJl5gnMPItYGRYxahRnFpUllqka2ihl1SUmZ5RkpuYmaNraGCsl5t aXJyYnpqTmFSsl5yfu4kRGCj1DAyMOxh/n/Y8xCjJwaQkyvu9+F6EEF9SfkplRmJxRnxRaU5q 8SFGGQ4OJQlehQ33I4QEi1LTUyvSMnOAIQuTluDgURLhPbYeKM1bXJCYW5yZDpE6xagoJc6bC tInAJLIKM2Da4PFySVGWSlhXkYGBgYhnoLUotzMElT5V4ziHIxKwrzyION5MvNK4Ka/AlrMBL TY4utdkMUliQgpqQbGVWvW3rc4v5F9xZMf3b3769nc7j1bIftn9ab6dZ2t3a9nHX1fWxB2hJ9 xftpJ+b1H1hc9KD4fuEcmK8tcnGEmr/3ygsDD8ULcW/xrGn1bVq8NftGz33xZ4obPLMtOzC4/ Fup3ec73becELTJ0++f85N3QYONyV7njn1/YaXHFrEIFxTMFSzX1lFiKMxINtZiLihMBRzypx I4CAAA= X-Env-Sender: yi.y.sun@linux.intel.com X-Msg-Ref: server-9.tower-31.messagelabs.com!1491054811!37933881!14 X-Originating-IP: [134.134.136.20] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTM0LjEzNC4xMzYuMjAgPT4gMzU1MzU4\n X-StarScan-Received: X-StarScan-Version: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 53083 invoked from network); 1 Apr 2017 13:54:11 -0000 Received: from mga02.intel.com (HELO mga02.intel.com) (134.134.136.20) by server-9.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 1 Apr 2017 13:54:11 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=intel; t=1491054851; x=1522590851; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=J0Pcm94rA3LOHaojkNlWhLrnXTRHW9hWFAgamvdC4jo=; b=IDvrU91gfHfz45ws0DN5DukSVa/2Yrhe283J7C9XJFUP1GnFDhjBEoQ0 mj0XpAEiADoWt9Qh8iLimj2poojfEQ==; Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Apr 2017 06:54:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,258,1486454400"; d="scan'208";a="950544947" Received: from yisun1-ubuntu.bj.intel.com ([10.238.156.112]) by orsmga003.jf.intel.com with ESMTP; 01 Apr 2017 06:54:07 -0700 From: Yi Sun To: xen-devel@lists.xenproject.org Date: Sat, 1 Apr 2017 21:53:44 +0800 Message-Id: <1491054836-30488-14-git-send-email-yi.y.sun@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1491054836-30488-1-git-send-email-yi.y.sun@linux.intel.com> References: <1491054836-30488-1-git-send-email-yi.y.sun@linux.intel.com> Cc: kevin.tian@intel.com, wei.liu2@citrix.com, andrew.cooper3@citrix.com, dario.faggioli@citrix.com, he.chen@linux.intel.com, ian.jackson@eu.citrix.com, Yi Sun , mengxu@cis.upenn.edu, jbeulich@suse.com, chao.p.peng@linux.intel.com, roger.pau@citrix.com Subject: [Xen-devel] [PATCH v10 13/25] x86: refactor psr: L3 CAT: set value: implement write msr flow. 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 Continue from previous patch: 'x86: refactor psr: L3 CAT: set value: implement cos id picking flow.' We have got the feature value and COS ID to set. Then, we write MSR of the designated feature. Till now, set value process is completed. Signed-off-by: Yi Sun --- v10: - remove 'type' from 'write_msr' parameter list. Will add it back when implementing CDP. (suggested by Jan Beulich) - remove unnecessary casts. (suggested by Jan Beulich) - changes about 'props'. (suggested by Jan Beulich) v9: - replace feature list handling to feature array handling. (suggested by Roger Pau) - add 'array_len' in 'struct cos_write_info' and check if val array exceeds it. - modify 'write_psr_msr' flow only to set one value a time. No need to set whole feature array values. - modify patch title to indicate 'L3 CAT'. (suggested by Jan Beulich) - changes about 'uint64_t' to 'uint32_t'. (suggested by Jan Beulich) v8: - modify 'write_msr' callback function to 'void' because we have to set all features' cbm. When input cos exceeds some features' cos_max, just skip them but not break the iteration. v5: - modify commit message to provide exact patch name to continue from. (suggested by Jan Beulich) - modify return value of callback functions because we do not need them to return number of entries the feature uses. In caller, we call 'get_cos_num' to get the number of entries the feature uses. (suggested by Jan Beulich) - move type check out from callback functions to caller. (suggested by Jan Beulich) - modify variables names to make them better, e.g. 'feat_tmp' to 'feat'. (suggested by Jan Beulich) - correct code format. (suggested by Jan Beulich) v4: - create this patch to make codes easier understand. (suggested by Jan Beulich) --- xen/arch/x86/psr.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/psr.c b/xen/arch/x86/psr.c index 44c9313..0f57676 100644 --- a/xen/arch/x86/psr.c +++ b/xen/arch/x86/psr.c @@ -101,6 +101,10 @@ struct feat_node { /* get_val is used to get feature COS register value. */ void (*get_val)(const struct feat_node *feat, unsigned int cos, uint32_t *val); + + /* write_msr is used to write out feature MSR register. */ + void (*write_msr)(unsigned int cos, uint32_t val, + struct feat_node *feat); } *props; uint32_t cos_reg_val[MAX_COS_REG_CNT]; @@ -315,10 +319,21 @@ static void cat_get_val(const struct feat_node *feat, unsigned int cos, } /* L3 CAT ops */ +static void l3_cat_write_msr(unsigned int cos, uint32_t val, + struct feat_node *feat) +{ + if ( feat->cos_reg_val[cos] != val ) + { + feat->cos_reg_val[cos] = val; + wrmsrl(MSR_IA32_PSR_L3_MASK(cos), val); + } +} + static struct feat_props l3_cat_props = { .cos_num = 1, .get_feat_info = cat_get_feat_info, .get_val = cat_get_val, + .write_msr = l3_cat_write_msr, }; static void __init parse_psr_bool(char *s, char *value, char *feature, @@ -878,10 +893,56 @@ static int pick_avail_cos(const struct psr_socket_info *info, return -EOVERFLOW; } +static unsigned int get_socket_cpu(unsigned int socket) +{ + if ( likely(socket < nr_sockets) ) + return cpumask_any(socket_cpumask[socket]); + + return nr_cpu_ids; +} + +struct cos_write_info +{ + unsigned int cos; + struct feat_node *feature; + uint32_t val; +}; + +static void do_write_psr_msr(void *data) +{ + struct cos_write_info *info = data; + unsigned int cos = info->cos; + struct feat_node *feat = info->feature; + + if ( cos > feat->props->cos_max ) + return; + + feat->props->write_msr(cos, info->val, feat); +} + static int write_psr_msr(unsigned int socket, unsigned int cos, uint32_t val, enum psr_feat_type feat_type) { - return -ENOENT; + struct psr_socket_info *info = get_socket_info(socket); + struct cos_write_info data = + { + .cos = cos, + .feature = info->features[feat_type], + .val = val, + }; + + if ( socket == cpu_to_socket(smp_processor_id()) ) + do_write_psr_msr(&data); + else + { + unsigned int cpu = get_socket_cpu(socket); + + if ( cpu >= nr_cpu_ids ) + return -ENOTSOCK; + on_selected_cpus(cpumask_of(cpu), do_write_psr_msr, &data, 1); + } + + return 0; } /* The whole set process is protected by domctl_lock. */