diff mbox

[v4,21/24] tools: L2 CAT: support get HW info for L2 CAT.

Message ID 1481688484-5093-22-git-send-email-yi.y.sun@linux.intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Yi Sun Dec. 14, 2016, 4:08 a.m. UTC
This patch implements xl/xc changes to support get HW info
for L2 CAT.

'xl psr-hwinfo' is updated to show both L3 CAT and L2 CAT
info.

Example(on machine which only supports L2 CAT):
Cache Monitoring Technology (CMT):
Enabled         : 0
Cache Allocation Technology (CAT): L3
libxl: error: libxl_psr.c:100:libxl__psr_cat_log_err_msg: CAT is not enabled on the socket: No such file or directory
Failed to get l3 cat info
Cache Allocation Technology (CAT): L2
Socket ID       : 0
Maximum COS     : 3
CBM length      : 8
Default CBM     : 0xff

Signed-off-by: He Chen <he.chen@linux.intel.com>
Signed-off-by: Yi Sun <yi.y.sun@linux.intel.com>
---
 tools/libxc/include/xenctrl.h |  6 +++---
 tools/libxc/xc_psr.c          | 40 +++++++++++++++++++++++-----------
 tools/libxl/libxl.h           | 11 ++++++++--
 tools/libxl/libxl_psr.c       |  8 +++----
 tools/libxl/xl_cmdimpl.c      | 50 +++++++++++++++++++++++++++++++++++--------
 5 files changed, 85 insertions(+), 30 deletions(-)

Comments

Wei Liu Jan. 6, 2017, 12:04 p.m. UTC | #1
On Wed, Dec 14, 2016 at 12:08:01PM +0800, Yi Sun wrote:
> This patch implements xl/xc changes to support get HW info
> for L2 CAT.
> 
> 'xl psr-hwinfo' is updated to show both L3 CAT and L2 CAT
> info.
> 
> Example(on machine which only supports L2 CAT):
> Cache Monitoring Technology (CMT):
> Enabled         : 0
> Cache Allocation Technology (CAT): L3
> libxl: error: libxl_psr.c:100:libxl__psr_cat_log_err_msg: CAT is not enabled on the socket: No such file or directory
> Failed to get l3 cat info

What is this?

> Cache Allocation Technology (CAT): L2
> Socket ID       : 0
> Maximum COS     : 3
> CBM length      : 8
> Default CBM     : 0xff
> 
> Signed-off-by: He Chen <he.chen@linux.intel.com>
> Signed-off-by: Yi Sun <yi.y.sun@linux.intel.com>
> ---
>  tools/libxc/include/xenctrl.h |  6 +++---
>  tools/libxc/xc_psr.c          | 40 +++++++++++++++++++++++-----------
>  tools/libxl/libxl.h           | 11 ++++++++--
>  tools/libxl/libxl_psr.c       |  8 +++----
>  tools/libxl/xl_cmdimpl.c      | 50 +++++++++++++++++++++++++++++++++++--------
>  5 files changed, 85 insertions(+), 30 deletions(-)
> 
> diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h
> index 2c83544..5b7df22 100644
> --- a/tools/libxc/include/xenctrl.h
> +++ b/tools/libxc/include/xenctrl.h
> @@ -2626,9 +2626,9 @@ int xc_psr_cat_set_domain_data(xc_interface *xch, uint32_t domid,
>  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_cat_get_l3_info(xc_interface *xch, uint32_t socket,
> -                           uint32_t *cos_max, uint32_t *cbm_len,
> -                           bool *cdp_enabled);
> +int xc_psr_cat_get_info(xc_interface *xch, uint32_t socket, unsigned int lvl,
> +                        uint32_t *cos_max, uint32_t *cbm_len,
> +                        bool *cdp_enabled);
>  
>  int xc_get_cpu_levelling_caps(xc_interface *xch, uint32_t *caps);
>  int xc_get_cpu_featureset(xc_interface *xch, uint32_t index,
> diff --git a/tools/libxc/xc_psr.c b/tools/libxc/xc_psr.c
> index 43b3286..7af17d9 100644
> --- a/tools/libxc/xc_psr.c
> +++ b/tools/libxc/xc_psr.c
> @@ -317,24 +317,40 @@ int xc_psr_cat_get_domain_data(xc_interface *xch, uint32_t domid,
>      return rc;
>  }
>  
> -int xc_psr_cat_get_l3_info(xc_interface *xch, uint32_t socket,
> -                           uint32_t *cos_max, uint32_t *cbm_len,
> -                           bool *cdp_enabled)
> +int xc_psr_cat_get_info(xc_interface *xch, uint32_t socket, unsigned int lvl,
> +                        uint32_t *cos_max, uint32_t *cbm_len, bool *cdp_enabled)
>  {
> -    int rc;
> +    int rc = -1;
>      DECLARE_SYSCTL;
>  
>      sysctl.cmd = XEN_SYSCTL_psr_cat_op;
> -    sysctl.u.psr_cat_op.cmd = XEN_SYSCTL_PSR_CAT_get_l3_info;
>      sysctl.u.psr_cat_op.target = socket;
>  
> -    rc = xc_sysctl(xch, &sysctl);
> -    if ( !rc )
> -    {
> -        *cos_max = sysctl.u.psr_cat_op.u.l3_info.cos_max;
> -        *cbm_len = sysctl.u.psr_cat_op.u.l3_info.cbm_len;
> -        *cdp_enabled = sysctl.u.psr_cat_op.u.l3_info.flags &
> -                       XEN_SYSCTL_PSR_CAT_L3_CDP;
> +    switch ( lvl ) {
> +    case 2:
> +        sysctl.u.psr_cat_op.cmd = XEN_SYSCTL_PSR_CAT_get_l2_info;
> +        rc = xc_sysctl(xch, &sysctl);
> +        if ( !rc )
> +        {
> +            *cos_max = sysctl.u.psr_cat_op.u.l2_info.cos_max;
> +            *cbm_len = sysctl.u.psr_cat_op.u.l2_info.cbm_len;
> +            *cdp_enabled = false;
> +        }
> +        break;
> +    case 3:
> +        sysctl.u.psr_cat_op.cmd = XEN_SYSCTL_PSR_CAT_get_l3_info;
> +        rc = xc_sysctl(xch, &sysctl);
> +        if ( !rc )
> +        {
> +            *cos_max = sysctl.u.psr_cat_op.u.l3_info.cos_max;
> +            *cbm_len = sysctl.u.psr_cat_op.u.l3_info.cbm_len;
> +            *cdp_enabled = sysctl.u.psr_cat_op.u.l3_info.flags &
> +                           XEN_SYSCTL_PSR_CAT_L3_CDP;
> +        }
> +        break;
> +    default:
> +        errno = EOPNOTSUPP;
> +        return rc;

There is no need for "return rc".

>      }
>  
>      return rc;
> diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h
> index acbf476..9233b0f 100644
> --- a/tools/libxl/libxl.h
> +++ b/tools/libxl/libxl.h
> @@ -904,6 +904,13 @@ void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, const libxl_mac *src);
>   * If this is defined, the Code and Data Prioritization feature is supported.
>   */
>  #define LIBXL_HAVE_PSR_CDP 1
> +
> +/*
> + * LIBXL_HAVE_PSR_L2_CAT
> + *
> + * If this is defined, the L2 Cache Allocation Technology feature is supported.
> + */
> +#define LIBXL_HAVE_PSR_L2_CAT 1
>  #endif
>  
>  /*
> @@ -2159,8 +2166,8 @@ int libxl_psr_cat_get_cbm(libxl_ctx *ctx, uint32_t domid,
>   * On success, the function returns an array of elements in 'info',
>   * and the length in 'nr'.
>   */
> -int libxl_psr_cat_get_l3_info(libxl_ctx *ctx, libxl_psr_cat_info **info,
> -                              int *nr);
> +int libxl_psr_cat_get_info(libxl_ctx *ctx, libxl_psr_cat_info **info,
> +                           int *nr, unsigned int lvl);

You can't delete old public functions. They will basically stay there
forever.

Please refactor the code to support both the new functions and the old.
In this particular case, it would be easy to implement _get_l3_info with
_get_info.

Wei.
Yi Sun Jan. 9, 2017, 1:19 a.m. UTC | #2
On 17-01-06 12:04:36, Wei Liu wrote:
> On Wed, Dec 14, 2016 at 12:08:01PM +0800, Yi Sun wrote:
> > This patch implements xl/xc changes to support get HW info
> > for L2 CAT.
> > 
> > 'xl psr-hwinfo' is updated to show both L3 CAT and L2 CAT
> > info.
> > 
> > Example(on machine which only supports L2 CAT):
> > Cache Monitoring Technology (CMT):
> > Enabled         : 0
> > Cache Allocation Technology (CAT): L3
> > libxl: error: libxl_psr.c:100:libxl__psr_cat_log_err_msg: CAT is not enabled on the socket: No such file or directory
> > Failed to get l3 cat info
> 
> What is this?
> 
The psr-hwinfo prints all features out by design. This test was executed on a
machine which only supports L2 CAT. So, the L3 CAT not supported info will be
printed out.

> > Signed-off-by: He Chen <he.chen@linux.intel.com>
> > Signed-off-by: Yi Sun <yi.y.sun@linux.intel.com>
> > ---
> >  tools/libxc/include/xenctrl.h |  6 +++---
> >  tools/libxc/xc_psr.c          | 40 +++++++++++++++++++++++-----------
> >  tools/libxl/libxl.h           | 11 ++++++++--
> >  tools/libxl/libxl_psr.c       |  8 +++----
> >  tools/libxl/xl_cmdimpl.c      | 50 +++++++++++++++++++++++++++++++++++--------
> >  5 files changed, 85 insertions(+), 30 deletions(-)
> > 
> > diff --git a/tools/libxc/xc_psr.c b/tools/libxc/xc_psr.c
> > index 43b3286..7af17d9 100644
> > --- a/tools/libxc/xc_psr.c
> > +++ b/tools/libxc/xc_psr.c
> > +        if ( !rc )
> > +        {
> > +            *cos_max = sysctl.u.psr_cat_op.u.l3_info.cos_max;
> > +            *cbm_len = sysctl.u.psr_cat_op.u.l3_info.cbm_len;
> > +            *cdp_enabled = sysctl.u.psr_cat_op.u.l3_info.flags &
> > +                           XEN_SYSCTL_PSR_CAT_L3_CDP;
> > +        }
> > +        break;
> > +    default:
> > +        errno = EOPNOTSUPP;
> > +        return rc;
> 
> There is no need for "return rc".
> 
Thanks!

> >      }
> >  
> >      return rc;
> > diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h
> > index acbf476..9233b0f 100644
> > --- a/tools/libxl/libxl.h
> > +++ b/tools/libxl/libxl.h
> > @@ -904,6 +904,13 @@ void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, const libxl_mac *src);
> >   * If this is defined, the Code and Data Prioritization feature is supported.
> >   */
> >  #define LIBXL_HAVE_PSR_CDP 1
> > +
> > +/*
> > + * LIBXL_HAVE_PSR_L2_CAT
> > + *
> > + * If this is defined, the L2 Cache Allocation Technology feature is supported.
> > + */
> > +#define LIBXL_HAVE_PSR_L2_CAT 1
> >  #endif
> >  
> >  /*
> > @@ -2159,8 +2166,8 @@ int libxl_psr_cat_get_cbm(libxl_ctx *ctx, uint32_t domid,
> >   * On success, the function returns an array of elements in 'info',
> >   * and the length in 'nr'.
> >   */
> > -int libxl_psr_cat_get_l3_info(libxl_ctx *ctx, libxl_psr_cat_info **info,
> > -                              int *nr);
> > +int libxl_psr_cat_get_info(libxl_ctx *ctx, libxl_psr_cat_info **info,
> > +                           int *nr, unsigned int lvl);
> 
> You can't delete old public functions. They will basically stay there
> forever.
> 
> Please refactor the code to support both the new functions and the old.
> In this particular case, it would be easy to implement _get_l3_info with
> _get_info.
> 
> Wei.

Got it. I will refactor codes to keep the old interfaces. Thank you!

Sun Yi
Jan Beulich Jan. 9, 2017, 8:31 a.m. UTC | #3
>>> On 09.01.17 at 02:19, <yi.y.sun@linux.intel.com> wrote:
> On 17-01-06 12:04:36, Wei Liu wrote:
>> On Wed, Dec 14, 2016 at 12:08:01PM +0800, Yi Sun wrote:
>> > This patch implements xl/xc changes to support get HW info
>> > for L2 CAT.
>> > 
>> > 'xl psr-hwinfo' is updated to show both L3 CAT and L2 CAT
>> > info.
>> > 
>> > Example(on machine which only supports L2 CAT):
>> > Cache Monitoring Technology (CMT):
>> > Enabled         : 0
>> > Cache Allocation Technology (CAT): L3
>> > libxl: error: libxl_psr.c:100:libxl__psr_cat_log_err_msg: CAT is not enabled on the socket: No such file or directory
>> > Failed to get l3 cat info
>> 
>> What is this?
>> 
> The psr-hwinfo prints all features out by design. This test was executed on a
> machine which only supports L2 CAT. So, the L3 CAT not supported info will be
> printed out.

But there is an indication of error(s), which shouldn't be the case just
because of non-present hardware. The hypercall may return failure
in such a case of course, but this shouldn't propagate to error/failure
messages being printed (but at the same time you need to make sure
you don't hide actual errors). Perhaps there's a call missing querying
host capabilities (based on the result of which further info queries
would be issued)?

Jan
Wei Liu Jan. 9, 2017, 9:26 a.m. UTC | #4
On Mon, Jan 09, 2017 at 01:31:35AM -0700, Jan Beulich wrote:
> >>> On 09.01.17 at 02:19, <yi.y.sun@linux.intel.com> wrote:
> > On 17-01-06 12:04:36, Wei Liu wrote:
> >> On Wed, Dec 14, 2016 at 12:08:01PM +0800, Yi Sun wrote:
> >> > This patch implements xl/xc changes to support get HW info
> >> > for L2 CAT.
> >> > 
> >> > 'xl psr-hwinfo' is updated to show both L3 CAT and L2 CAT
> >> > info.
> >> > 
> >> > Example(on machine which only supports L2 CAT):
> >> > Cache Monitoring Technology (CMT):
> >> > Enabled         : 0
> >> > Cache Allocation Technology (CAT): L3
> >> > libxl: error: libxl_psr.c:100:libxl__psr_cat_log_err_msg: CAT is not enabled on the socket: No such file or directory
> >> > Failed to get l3 cat info
> >> 
> >> What is this?
> >> 
> > The psr-hwinfo prints all features out by design. This test was executed on a
> > machine which only supports L2 CAT. So, the L3 CAT not supported info will be
> > printed out.
> 
> But there is an indication of error(s), which shouldn't be the case just
> because of non-present hardware. The hypercall may return failure
> in such a case of course, but this shouldn't propagate to error/failure
> messages being printed (but at the same time you need to make sure
> you don't hide actual errors). Perhaps there's a call missing querying
> host capabilities (based on the result of which further info queries
> would be issued)?
> 

This is what I thought as well.

> Jan
>
Yi Sun Jan. 10, 2017, 8 a.m. UTC | #5
On 17-01-09 09:26:17, Wei Liu wrote:
> On Mon, Jan 09, 2017 at 01:31:35AM -0700, Jan Beulich wrote:
> > >>> On 09.01.17 at 02:19, <yi.y.sun@linux.intel.com> wrote:
> > > On 17-01-06 12:04:36, Wei Liu wrote:
> > >> On Wed, Dec 14, 2016 at 12:08:01PM +0800, Yi Sun wrote:
> > >> > This patch implements xl/xc changes to support get HW info
> > >> > for L2 CAT.
> > >> > 
> > >> > 'xl psr-hwinfo' is updated to show both L3 CAT and L2 CAT
> > >> > info.
> > >> > 
> > >> > Example(on machine which only supports L2 CAT):
> > >> > Cache Monitoring Technology (CMT):
> > >> > Enabled         : 0
> > >> > Cache Allocation Technology (CAT): L3
> > >> > libxl: error: libxl_psr.c:100:libxl__psr_cat_log_err_msg: CAT is not enabled on the socket: No such file or directory
> > >> > Failed to get l3 cat info
> > >> 
> > >> What is this?
> > >> 
> > > The psr-hwinfo prints all features out by design. This test was executed on a
> > > machine which only supports L2 CAT. So, the L3 CAT not supported info will be
> > > printed out.
> > 
> > But there is an indication of error(s), which shouldn't be the case just
> > because of non-present hardware. The hypercall may return failure
> > in such a case of course, but this shouldn't propagate to error/failure
> > messages being printed (but at the same time you need to make sure
> > you don't hide actual errors). Perhaps there's a call missing querying
> > host capabilities (based on the result of which further info queries
> > would be issued)?
> > 
> 
> This is what I thought as well.
> 
> > Jan
> > 
I considered to add a sysctl interface to get feature mask back before.
Then, the application can print enabled feature list out in psr-hwinfo.

But current psr-hwinfo command implementation can have same effect. It
gets all features HW info back. For not enabled feature, such error info
is printed. Although it is not user friendly, it reduces one hypercall.

So, I have below two options:
1) Create a new sysctl interface to get feature mask and get HW info
   according to it.
2) Modify current psr-hwinfo codes only to show enabled feature HW info
   but not show error logs. Of course the libxl library interface still
   returns error to application.

Which one do you prefer? Thanks!
Jan Beulich Jan. 10, 2017, 8:46 a.m. UTC | #6
>>> On 10.01.17 at 09:00, <yi.y.sun@linux.intel.com> wrote:
> On 17-01-09 09:26:17, Wei Liu wrote:
>> On Mon, Jan 09, 2017 at 01:31:35AM -0700, Jan Beulich wrote:
>> > >>> On 09.01.17 at 02:19, <yi.y.sun@linux.intel.com> wrote:
>> > > On 17-01-06 12:04:36, Wei Liu wrote:
>> > >> On Wed, Dec 14, 2016 at 12:08:01PM +0800, Yi Sun wrote:
>> > >> > This patch implements xl/xc changes to support get HW info
>> > >> > for L2 CAT.
>> > >> > 
>> > >> > 'xl psr-hwinfo' is updated to show both L3 CAT and L2 CAT
>> > >> > info.
>> > >> > 
>> > >> > Example(on machine which only supports L2 CAT):
>> > >> > Cache Monitoring Technology (CMT):
>> > >> > Enabled         : 0
>> > >> > Cache Allocation Technology (CAT): L3
>> > >> > libxl: error: libxl_psr.c:100:libxl__psr_cat_log_err_msg: CAT is not enabled on the socket: No such file or directory
>> > >> > Failed to get l3 cat info
>> > >> 
>> > >> What is this?
>> > >> 
>> > > The psr-hwinfo prints all features out by design. This test was executed on a
>> > > machine which only supports L2 CAT. So, the L3 CAT not supported info will be
>> > > printed out.
>> > 
>> > But there is an indication of error(s), which shouldn't be the case just
>> > because of non-present hardware. The hypercall may return failure
>> > in such a case of course, but this shouldn't propagate to error/failure
>> > messages being printed (but at the same time you need to make sure
>> > you don't hide actual errors). Perhaps there's a call missing querying
>> > host capabilities (based on the result of which further info queries
>> > would be issued)?
>> > 
>> 
>> This is what I thought as well.
>> 
> I considered to add a sysctl interface to get feature mask back before.
> Then, the application can print enabled feature list out in psr-hwinfo.
> 
> But current psr-hwinfo command implementation can have same effect. It
> gets all features HW info back. For not enabled feature, such error info
> is printed. Although it is not user friendly, it reduces one hypercall.
> 
> So, I have below two options:
> 1) Create a new sysctl interface to get feature mask and get HW info
>    according to it.
> 2) Modify current psr-hwinfo codes only to show enabled feature HW info
>    but not show error logs. Of course the libxl library interface still
>    returns error to application.
> 
> Which one do you prefer? Thanks!

Well, afaic I'd prefer any variant without new hypercall, as long as
the bogus error messages go away without hiding any actual errors.

Jan
Yi Sun Jan. 10, 2017, 9:01 a.m. UTC | #7
On 17-01-10 01:46:17, Jan Beulich wrote:
> >>> On 10.01.17 at 09:00, <yi.y.sun@linux.intel.com> wrote:
> > On 17-01-09 09:26:17, Wei Liu wrote:
> >> On Mon, Jan 09, 2017 at 01:31:35AM -0700, Jan Beulich wrote:
> >> > >>> On 09.01.17 at 02:19, <yi.y.sun@linux.intel.com> wrote:
> >> > > On 17-01-06 12:04:36, Wei Liu wrote:
> >> > >> On Wed, Dec 14, 2016 at 12:08:01PM +0800, Yi Sun wrote:
> >> > >> > This patch implements xl/xc changes to support get HW info
> >> > >> > for L2 CAT.
> >> > >> > 
> >> > >> > 'xl psr-hwinfo' is updated to show both L3 CAT and L2 CAT
> >> > >> > info.
> >> > >> > 
> >> > >> > Example(on machine which only supports L2 CAT):
> >> > >> > Cache Monitoring Technology (CMT):
> >> > >> > Enabled         : 0
> >> > >> > Cache Allocation Technology (CAT): L3
> >> > >> > libxl: error: libxl_psr.c:100:libxl__psr_cat_log_err_msg: CAT is not enabled on the socket: No such file or directory
> >> > >> > Failed to get l3 cat info
> >> > >> 
> >> > >> What is this?
> >> > >> 
> >> > > The psr-hwinfo prints all features out by design. This test was executed on a
> >> > > machine which only supports L2 CAT. So, the L3 CAT not supported info will be
> >> > > printed out.
> >> > 
> >> > But there is an indication of error(s), which shouldn't be the case just
> >> > because of non-present hardware. The hypercall may return failure
> >> > in such a case of course, but this shouldn't propagate to error/failure
> >> > messages being printed (but at the same time you need to make sure
> >> > you don't hide actual errors). Perhaps there's a call missing querying
> >> > host capabilities (based on the result of which further info queries
> >> > would be issued)?
> >> > 
> >> 
> >> This is what I thought as well.
> >> 
> > I considered to add a sysctl interface to get feature mask back before.
> > Then, the application can print enabled feature list out in psr-hwinfo.
> > 
> > But current psr-hwinfo command implementation can have same effect. It
> > gets all features HW info back. For not enabled feature, such error info
> > is printed. Although it is not user friendly, it reduces one hypercall.
> > 
> > So, I have below two options:
> > 1) Create a new sysctl interface to get feature mask and get HW info
> >    according to it.
> > 2) Modify current psr-hwinfo codes only to show enabled feature HW info
> >    but not show error logs. Of course the libxl library interface still
> >    returns error to application.
> > 
> > Which one do you prefer? Thanks!
> 
> Well, afaic I'd prefer any variant without new hypercall, as long as
> the bogus error messages go away without hiding any actual errors.
> 
> Jan

Ok, thank you!

Sun Yi
diff mbox

Patch

diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h
index 2c83544..5b7df22 100644
--- a/tools/libxc/include/xenctrl.h
+++ b/tools/libxc/include/xenctrl.h
@@ -2626,9 +2626,9 @@  int xc_psr_cat_set_domain_data(xc_interface *xch, uint32_t domid,
 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_cat_get_l3_info(xc_interface *xch, uint32_t socket,
-                           uint32_t *cos_max, uint32_t *cbm_len,
-                           bool *cdp_enabled);
+int xc_psr_cat_get_info(xc_interface *xch, uint32_t socket, unsigned int lvl,
+                        uint32_t *cos_max, uint32_t *cbm_len,
+                        bool *cdp_enabled);
 
 int xc_get_cpu_levelling_caps(xc_interface *xch, uint32_t *caps);
 int xc_get_cpu_featureset(xc_interface *xch, uint32_t index,
diff --git a/tools/libxc/xc_psr.c b/tools/libxc/xc_psr.c
index 43b3286..7af17d9 100644
--- a/tools/libxc/xc_psr.c
+++ b/tools/libxc/xc_psr.c
@@ -317,24 +317,40 @@  int xc_psr_cat_get_domain_data(xc_interface *xch, uint32_t domid,
     return rc;
 }
 
-int xc_psr_cat_get_l3_info(xc_interface *xch, uint32_t socket,
-                           uint32_t *cos_max, uint32_t *cbm_len,
-                           bool *cdp_enabled)
+int xc_psr_cat_get_info(xc_interface *xch, uint32_t socket, unsigned int lvl,
+                        uint32_t *cos_max, uint32_t *cbm_len, bool *cdp_enabled)
 {
-    int rc;
+    int rc = -1;
     DECLARE_SYSCTL;
 
     sysctl.cmd = XEN_SYSCTL_psr_cat_op;
-    sysctl.u.psr_cat_op.cmd = XEN_SYSCTL_PSR_CAT_get_l3_info;
     sysctl.u.psr_cat_op.target = socket;
 
-    rc = xc_sysctl(xch, &sysctl);
-    if ( !rc )
-    {
-        *cos_max = sysctl.u.psr_cat_op.u.l3_info.cos_max;
-        *cbm_len = sysctl.u.psr_cat_op.u.l3_info.cbm_len;
-        *cdp_enabled = sysctl.u.psr_cat_op.u.l3_info.flags &
-                       XEN_SYSCTL_PSR_CAT_L3_CDP;
+    switch ( lvl ) {
+    case 2:
+        sysctl.u.psr_cat_op.cmd = XEN_SYSCTL_PSR_CAT_get_l2_info;
+        rc = xc_sysctl(xch, &sysctl);
+        if ( !rc )
+        {
+            *cos_max = sysctl.u.psr_cat_op.u.l2_info.cos_max;
+            *cbm_len = sysctl.u.psr_cat_op.u.l2_info.cbm_len;
+            *cdp_enabled = false;
+        }
+        break;
+    case 3:
+        sysctl.u.psr_cat_op.cmd = XEN_SYSCTL_PSR_CAT_get_l3_info;
+        rc = xc_sysctl(xch, &sysctl);
+        if ( !rc )
+        {
+            *cos_max = sysctl.u.psr_cat_op.u.l3_info.cos_max;
+            *cbm_len = sysctl.u.psr_cat_op.u.l3_info.cbm_len;
+            *cdp_enabled = sysctl.u.psr_cat_op.u.l3_info.flags &
+                           XEN_SYSCTL_PSR_CAT_L3_CDP;
+        }
+        break;
+    default:
+        errno = EOPNOTSUPP;
+        return rc;
     }
 
     return rc;
diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h
index acbf476..9233b0f 100644
--- a/tools/libxl/libxl.h
+++ b/tools/libxl/libxl.h
@@ -904,6 +904,13 @@  void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, const libxl_mac *src);
  * If this is defined, the Code and Data Prioritization feature is supported.
  */
 #define LIBXL_HAVE_PSR_CDP 1
+
+/*
+ * LIBXL_HAVE_PSR_L2_CAT
+ *
+ * If this is defined, the L2 Cache Allocation Technology feature is supported.
+ */
+#define LIBXL_HAVE_PSR_L2_CAT 1
 #endif
 
 /*
@@ -2159,8 +2166,8 @@  int libxl_psr_cat_get_cbm(libxl_ctx *ctx, uint32_t domid,
  * On success, the function returns an array of elements in 'info',
  * and the length in 'nr'.
  */
-int libxl_psr_cat_get_l3_info(libxl_ctx *ctx, libxl_psr_cat_info **info,
-                              int *nr);
+int libxl_psr_cat_get_info(libxl_ctx *ctx, libxl_psr_cat_info **info,
+                           int *nr, unsigned int lvl);
 void libxl_psr_cat_info_list_free(libxl_psr_cat_info *list, int nr);
 #endif
 
diff --git a/tools/libxl/libxl_psr.c b/tools/libxl/libxl_psr.c
index 786183c..f238f71 100644
--- a/tools/libxl/libxl_psr.c
+++ b/tools/libxl/libxl_psr.c
@@ -352,8 +352,8 @@  int libxl_psr_cat_get_cbm(libxl_ctx *ctx, uint32_t domid,
     return rc;
 }
 
-int libxl_psr_cat_get_l3_info(libxl_ctx *ctx, libxl_psr_cat_info **info,
-                              int *nr)
+int libxl_psr_cat_get_info(libxl_ctx *ctx, libxl_psr_cat_info **info,
+                           int *nr, unsigned int lvl)
 {
     GC_INIT(ctx);
     int rc;
@@ -380,8 +380,8 @@  int libxl_psr_cat_get_l3_info(libxl_ctx *ctx, libxl_psr_cat_info **info,
 
     libxl_for_each_set_bit(socketid, socketmap) {
         ptr[i].id = socketid;
-        if (xc_psr_cat_get_l3_info(ctx->xch, socketid, &ptr[i].cos_max,
-                                   &ptr[i].cbm_len, &ptr[i].cdp_enabled)) {
+        if (xc_psr_cat_get_info(ctx->xch, socketid, lvl, &ptr[i].cos_max,
+                                &ptr[i].cbm_len, &ptr[i].cdp_enabled)) {
             libxl__psr_cat_log_err_msg(gc, errno);
             rc = ERROR_FAIL;
             free(ptr);
diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index 7e8a8ae..c210b05 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -9331,19 +9331,19 @@  int main_psr_cmt_show(int argc, char **argv)
 }
 #endif
 
-#ifdef LIBXL_HAVE_PSR_CAT
-static int psr_cat_hwinfo(void)
+#if defined(LIBXL_HAVE_PSR_CAT) || defined(LIBXL_HAVE_PSR_L2_CAT)
+static int psr_l3_cat_hwinfo(void)
 {
-    int rc;
-    int i, nr;
+    int rc, nr;
+    unsigned int i;
     uint32_t l3_cache_size;
     libxl_psr_cat_info *info;
 
-    printf("Cache Allocation Technology (CAT):\n");
+    printf("Cache Allocation Technology (CAT): L3\n");
 
-    rc = libxl_psr_cat_get_l3_info(ctx, &info, &nr);
+    rc = libxl_psr_cat_get_info(ctx, &info, &nr, 3);
     if (rc) {
-        fprintf(stderr, "Failed to get cat info\n");
+        fprintf(stderr, "Failed to get l3 cat info\n");
         return rc;
     }
 
@@ -9454,7 +9454,7 @@  static int psr_cat_show(uint32_t domid)
     int rc;
     libxl_psr_cat_info *info;
 
-    rc = libxl_psr_cat_get_l3_info(ctx, &info, &nr);
+    rc = libxl_psr_cat_get_info(ctx, &info, &nr, 3);
     if (rc) {
         fprintf(stderr, "Failed to get cat info\n");
         return rc;
@@ -9471,6 +9471,34 @@  out:
     return rc;
 }
 
+static int psr_l2_cat_hwinfo(void)
+{
+    int rc;
+    unsigned int i;
+    int nr;
+    libxl_psr_cat_info *info;
+
+    printf("Cache Allocation Technology (CAT): L2\n");
+
+    rc = libxl_psr_cat_get_info(ctx, &info, &nr, 2);
+    if (rc) {
+        fprintf(stderr, "Failed to get l2 cat info\n");
+        return rc;
+    }
+
+    for (i = 0; i < nr; i++) {
+        /* There is no CMT on L2 cache so far. */
+        printf("%-16s: %u\n", "Socket ID", info[i].id);
+        printf("%-16s: %u\n", "Maximum COS", info[i].cos_max);
+        printf("%-16s: %u\n", "CBM length", info[i].cbm_len);
+        printf("%-16s: %#llx\n", "Default CBM",
+               (1ull << info[i].cbm_len) - 1);
+    }
+
+    libxl_psr_cat_info_list_free(info, nr);
+    return rc;
+}
+
 int main_psr_cat_cbm_set(int argc, char **argv)
 {
     uint32_t domid;
@@ -9588,7 +9616,11 @@  int main_psr_hwinfo(int argc, char **argv)
         ret = psr_cmt_hwinfo();
 
     if (!ret && (all || cat))
-        ret = psr_cat_hwinfo();
+        ret = psr_l3_cat_hwinfo();
+
+    /* L2 CAT is independent of CMT and L3 CAT */
+    if (all || cat)
+        ret = psr_l2_cat_hwinfo();
 
     return ret;
 }