This patch implements get HW info flow for CDP including L3 CDP callback
function. The flow is almost same as L3 CAT.

With this patch, 'psr-hwinfo' can work for L3 CDP.

Signed-off-by: Yi Sun <yi.y....@linux.intel.com>
---
v11:
    - modify 'psr_get_info' flow to make it simple to cover CDP case.
v10:
    - update renamed macros used by psr_get_info.
      (suggested by Jan Beulich)
    - change 'psr_get_info' flow to cover CDP case to make codes in sysctl
      more simple.
      (suggested by Jan Beulich)
    - remove sysctl redundant codes after applying above changes.
      (suggested by Jan Beulich)
v9:
    - modify commit message to explain flow more clearly.
    - reuse 'cat_get_feat_info' for CDP to reduce redundant codes.
      (suggested by Roger Pau)
    - fix coding style issues.
      (suggested by Wei Liu and Roger Pau)
    - rename macros used by psr_get_info to make them meaningful.
      (suggested by Jan Beulich)
v5:
    - rename 'dat[]' to 'data[]'.
      (suggested by Jan Beulich)
    - remove type check in callback function.
      (suggested by Jan Beulich)
v4:
    - create this patch to make codes easier to understand.
      (suggested by Jan Beulich)
---
 xen/arch/x86/psr.c | 31 ++++++++++++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)

diff --git a/xen/arch/x86/psr.c b/xen/arch/x86/psr.c
index 7000d95..55ac221 100644
--- a/xen/arch/x86/psr.c
+++ b/xen/arch/x86/psr.c
@@ -207,7 +207,9 @@ static void free_socket_resources(unsigned int socket)
     memset(info->dom_ids, 0, ((DOMID_IDLE + 1) + 7) / 8);
 }
 
-static enum psr_feat_type psr_cbm_type_to_feat_type(enum cbm_type type)
+static enum psr_feat_type psr_cbm_type_to_feat_type(
+                                    const struct psr_socket_info *info,
+                                    enum cbm_type type)
 {
     enum psr_feat_type feat_type = PSR_SOCKET_FEAT_UNKNOWN;
 
@@ -215,7 +217,18 @@ static enum psr_feat_type psr_cbm_type_to_feat_type(enum 
cbm_type type)
     {
     case PSR_CBM_TYPE_L3:
         feat_type = PSR_SOCKET_L3_CAT;
+
+        /* If type is L3 CAT but we cannot find it in feature array, try CDP. 
*/
+        if ( !info->features[feat_type] )
+            feat_type = PSR_SOCKET_L3_CDP;
+
+        break;
+
+    case PSR_CBM_TYPE_L3_DATA:
+    case PSR_CBM_TYPE_L3_CODE:
+        feat_type = PSR_SOCKET_L3_CDP;
         break;
+
     default:
         ASSERT_UNREACHABLE();
     }
@@ -328,8 +341,20 @@ static struct feat_props l3_cat_props = {
 };
 
 /* L3 CDP props */
+static bool l3_cdp_get_feat_info(const struct feat_node *feat,
+                                 uint32_t data[], uint32_t array_len)
+{
+    if ( !cat_get_feat_info(feat, data, array_len) )
+        return false;
+
+    data[PSR_INFO_IDX_CAT_FLAG] |= XEN_SYSCTL_PSR_CAT_L3_CDP;
+
+    return true;
+}
+
 static struct feat_props l3_cdp_props = {
     .cos_num = 2,
+    .get_feat_info = l3_cdp_get_feat_info,
 };
 
 static void __init parse_psr_bool(char *s, char *value, char *feature,
@@ -574,7 +599,7 @@ static struct feat_node *psr_get_feat_and_type(unsigned int 
socket,
     if ( IS_ERR(info) )
         return ERR_PTR(PTR_ERR(info));
 
-    *feat_type = psr_cbm_type_to_feat_type(type);
+    *feat_type = psr_cbm_type_to_feat_type(info, type);
     if ( *feat_type >= ARRAY_SIZE(info->features) )
         return NULL;
 
@@ -1040,7 +1065,7 @@ int psr_set_val(struct domain *d, unsigned int socket,
 
     val = new_val;
 
-    feat_type = psr_cbm_type_to_feat_type(type);
+    feat_type = psr_cbm_type_to_feat_type(info, type);
     if ( feat_type >= ARRAY_SIZE(info->features) ||
          !info->features[feat_type] )
         return -ENOENT;
-- 
1.9.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

Reply via email to