From patchwork Tue Jan 10 07:42:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Sun X-Patchwork-Id: 9506649 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 10B45606E1 for ; Tue, 10 Jan 2017 07:46:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0471628156 for ; Tue, 10 Jan 2017 07:46:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ED36E28485; Tue, 10 Jan 2017 07:46: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 5D6FB28156 for ; Tue, 10 Jan 2017 07:46:00 +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 1cQr5z-00047f-9q; Tue, 10 Jan 2017 07:43:51 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cQr5x-00044Y-TJ for xen-devel@lists.xenproject.org; Tue, 10 Jan 2017 07:43:50 +0000 Received: from [85.158.137.68] by server-6.bemta-3.messagelabs.com id A4/57-02804-5B094785; Tue, 10 Jan 2017 07:43:49 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrPLMWRWlGSWpSXmKPExsVywNykWHfLhJI Ig1f31Cy+b5nM5MDocfjDFZYAxijWzLyk/IoE1owrR5sYCxZbVXw58pSxgXG2VhcjJ4eQQKXE j02T2EBsCQFeiSPLZrBC2P4SHd+msncxcgHVNDBKHLjbAlbEJqAu8fhrDxOILSKgJHFv1WQmk CJmgf2MEvOPH2cGSQgLeEu0fjgINolFQFXix7IFLCA2r4CHxML3t5ggNshJnDw2GayGEyjecn UdI8RF7hLNb+8zTmDkXcDIsIpRozi1qCy1SNfYQC+pKDM9oyQ3MTNH19DAWC83tbg4MT01JzG pWC85P3cTIzAg6hkYGHcwdp7wO8QoycGkJMqbolsSIcSXlJ9SmZFYnBFfVJqTWnyIUYaDQ0mC t6ofKCdYlJqeWpGWmQMMTZi0BAePkggvC0iat7ggMbc4Mx0idYpRUUqcNxAkIQCSyCjNg2uDx cMlRlkpYV5GBgYGIZ6C1KLczBJU+VeM4hyMSsK8riBTeDLzSuCmvwJazAS0ONKuGGRxSSJCSg oYYcwFMvKmi6w7dGKOmmhdOKa30EpcQWCu+4wYka2+RcG/Nbe2LLnH1nJ/yrW3P5ZL3d7X2DX N8qNKYebzGf89ZivtzDRuqr5/3rfCMuZx6wRmO2OhEmWf1xqKdnmhglG6GdVNfzXq1ews4gps 1Kt6j3V93SHFJ8Q9R/Neiy2Le5TzPSXPKCWW4oxEQy3mouJEAJEU9F+CAgAA X-Env-Sender: yi.y.sun@linux.intel.com X-Msg-Ref: server-12.tower-31.messagelabs.com!1484034224!62972679!2 X-Originating-IP: [192.55.52.115] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 32496 invoked from network); 10 Jan 2017 07:43:48 -0000 Received: from mga14.intel.com (HELO mga14.intel.com) (192.55.52.115) by server-12.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 10 Jan 2017 07:43:48 -0000 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP; 09 Jan 2017 23:43:45 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,343,1477983600"; d="scan'208";a="211583204" Received: from vmmmba-s2600wft.bj.intel.com ([10.240.193.63]) by fmsmga004.fm.intel.com with ESMTP; 09 Jan 2017 23:43:43 -0800 From: Yi Sun To: xen-devel@lists.xenproject.org Date: Tue, 10 Jan 2017 15:42:30 +0800 Message-Id: <1484034155-4521-12-git-send-email-yi.y.sun@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1484034155-4521-1-git-send-email-yi.y.sun@linux.intel.com> References: <1484034155-4521-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] [RFC 11/16] tools: refactor codes to make get val be more general. 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 This patch refactors some codes in tools/ to make get value be more general. Signed-off-by: Yi Sun --- tools/libxc/include/xenctrl.h | 12 +++---- tools/libxc/xc_psr.c | 8 ++--- tools/libxl/libxl_psr.c | 80 +++++++++++++++++++++++++++++++++++-------- 3 files changed, 75 insertions(+), 25 deletions(-) diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h index fa62e2a..69f9343 100644 --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -2598,13 +2598,13 @@ enum xc_psr_cmt_type { }; typedef enum xc_psr_cmt_type xc_psr_cmt_type; -enum xc_psr_cat_type { +enum xc_psr_val_type { XC_PSR_CAT_L3_CBM = 1, XC_PSR_CAT_L3_CBM_CODE = 2, XC_PSR_CAT_L3_CBM_DATA = 3, XC_PSR_CAT_L2_CBM = 4, }; -typedef enum xc_psr_cat_type xc_psr_cat_type; +typedef enum xc_psr_val_type xc_psr_val_type; enum xc_psr_feat_type { XC_PSR_FEAT_UNKNOWN = 0, @@ -2640,11 +2640,11 @@ int xc_psr_cmt_get_data(xc_interface *xch, uint32_t rmid, uint32_t cpu, int xc_psr_cmt_enabled(xc_interface *xch); int xc_psr_cat_set_domain_data(xc_interface *xch, uint32_t domid, - xc_psr_cat_type type, uint32_t target, + xc_psr_val_type type, uint32_t target, uint64_t data); -int xc_psr_cat_get_domain_data(xc_interface *xch, uint32_t domid, - xc_psr_cat_type type, uint32_t target, - uint64_t *data); +int xc_psr_get_domain_data(xc_interface *xch, uint32_t domid, + xc_psr_val_type type, uint32_t target, + uint64_t *data); int xc_psr_get_hw_info(xc_interface *xch, uint32_t socket, xc_psr_feat_type type, xc_psr_hw_info *hw_info); diff --git a/tools/libxc/xc_psr.c b/tools/libxc/xc_psr.c index af648eb..4dbb7c6 100644 --- a/tools/libxc/xc_psr.c +++ b/tools/libxc/xc_psr.c @@ -249,7 +249,7 @@ int xc_psr_cmt_enabled(xc_interface *xch) return 0; } int xc_psr_cat_set_domain_data(xc_interface *xch, uint32_t domid, - xc_psr_cat_type type, uint32_t target, + xc_psr_val_type type, uint32_t target, uint64_t data) { DECLARE_DOMCTL; @@ -283,9 +283,9 @@ int xc_psr_cat_set_domain_data(xc_interface *xch, uint32_t domid, return do_domctl(xch, &domctl); } -int xc_psr_cat_get_domain_data(xc_interface *xch, uint32_t domid, - xc_psr_cat_type type, uint32_t target, - uint64_t *data) +int xc_psr_get_domain_data(xc_interface *xch, uint32_t domid, + xc_psr_val_type type, uint32_t target, + uint64_t *data) { int rc; DECLARE_DOMCTL; diff --git a/tools/libxl/libxl_psr.c b/tools/libxl/libxl_psr.c index 2fe42b7..07c4bc4 100644 --- a/tools/libxl/libxl_psr.c +++ b/tools/libxl/libxl_psr.c @@ -71,16 +71,35 @@ static void libxl__psr_cmt_log_err_msg(libxl__gc *gc, int err) LOGE(ERROR, "%s", msg); } -static void libxl__psr_cat_log_err_msg(libxl__gc *gc, int err) +static void libxl__psr_alloc_log_err_msg(libxl__gc *gc, + libxl_psr_cbm_type type, int err) { char *msg; + char *feat; + + switch (type) { + case LIBXL_PSR_CBM_TYPE_L3_CBM: + feat = "L3 CAT"; + break; + case LIBXL_PSR_CBM_TYPE_L3_CBM_CODE: + case LIBXL_PSR_CBM_TYPE_L3_CBM_DATA: + feat = "L3 CDP"; + break; + case LIBXL_PSR_CBM_TYPE_L2_CBM: + feat = "L2 CAT"; + break; + default: + LOGE(ERROR, "Input type %d is wrong!\n", type); + libxl__psr_log_err_msg(gc, err); + return; + } switch (err) { case ENODEV: - msg = "CAT is not supported in this system"; + msg = "is not supported in this system"; break; case ENOENT: - msg = "CAT is not enabled on the socket"; + msg = "is not enabled on the socket"; break; case EOVERFLOW: msg = "no free COS available"; @@ -97,7 +116,38 @@ static void libxl__psr_cat_log_err_msg(libxl__gc *gc, int err) return; } - LOGE(ERROR, "%s", msg); + LOGE(ERROR, "%s: %s", feat, msg); +} + +static void libxl__psr_hw_info_log_err_msg(libxl__gc *gc, int lvl, + libxl_psr_feat_type type, int err) +{ + char *msg; + char *feat; + + switch (type) { + case LIBXL_PSR_FEAT_TYPE_CAT_INFO: + if (lvl == 3) + feat = "L3 CAT"; + else + feat = "L2 CAT"; + break; + default: + LOGE(ERROR, "Input type %d is wrong!\n", type); + libxl__psr_log_err_msg(gc, err); + return; + } + + switch (err) { + case ENOENT: + msg = "is not enabled on the socket"; + break; + default: + libxl__psr_log_err_msg(gc, err); + return; + } + + LOGE(ERROR, "%s: %s", feat, msg); } static int libxl__pick_socket_cpu(libxl__gc *gc, uint32_t socketid) @@ -294,11 +344,11 @@ out: return rc; } -static inline xc_psr_cat_type libxl__psr_cbm_type_to_libxc_psr_cat_type( +static inline xc_psr_val_type libxl__psr_cbm_type_to_libxc_psr_val_type( libxl_psr_cbm_type type) { - BUILD_BUG_ON(sizeof(libxl_psr_cbm_type) != sizeof(xc_psr_cat_type)); - return (xc_psr_cat_type)type; + BUILD_BUG_ON(sizeof(libxl_psr_cbm_type) != sizeof(xc_psr_val_type)); + return (xc_psr_val_type)type; } int libxl_psr_cat_set_cbm(libxl_ctx *ctx, uint32_t domid, @@ -316,15 +366,15 @@ int libxl_psr_cat_set_cbm(libxl_ctx *ctx, uint32_t domid, } libxl_for_each_set_bit(socketid, *target_map) { - xc_psr_cat_type xc_type; + xc_psr_val_type xc_type; if (socketid >= nr_sockets) break; - xc_type = libxl__psr_cbm_type_to_libxc_psr_cat_type(type); + xc_type = libxl__psr_cbm_type_to_libxc_psr_val_type(type); if (xc_psr_cat_set_domain_data(ctx->xch, domid, xc_type, socketid, cbm)) { - libxl__psr_cat_log_err_msg(gc, errno); + libxl__psr_alloc_log_err_msg(gc, type, errno); rc = ERROR_FAIL; } } @@ -340,11 +390,11 @@ int libxl_psr_cat_get_cbm(libxl_ctx *ctx, uint32_t domid, { GC_INIT(ctx); int rc = 0; - xc_psr_cat_type xc_type = libxl__psr_cbm_type_to_libxc_psr_cat_type(type); + xc_psr_val_type xc_type = libxl__psr_cbm_type_to_libxc_psr_val_type(type); - if (xc_psr_cat_get_domain_data(ctx->xch, domid, xc_type, - target, cbm_r)) { - libxl__psr_cat_log_err_msg(gc, errno); + if (xc_psr_get_domain_data(ctx->xch, domid, xc_type, + target, cbm_r)) { + libxl__psr_alloc_log_err_msg(gc, type, errno); rc = ERROR_FAIL; } @@ -428,7 +478,7 @@ int libxl_psr_get_hw_info(libxl_ctx *ctx, libxl_psr_hw_info **info, libxl_for_each_set_bit(socketid, socketmap) { ptr[i].id = socketid; if (xc_psr_get_hw_info(ctx->xch, socketid, xc_type, &hw_info)) { - libxl__psr_cat_log_err_msg(gc, errno); + libxl__psr_hw_info_log_err_msg(gc, lvl, type, errno); rc = ERROR_FAIL; free(ptr); goto out;