[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [RFC][PATCH v1 1/3] Add xen-hvm-param



On 02/09/14 13:07, Don Slutz wrote:
> A tool to get and set hvm param.
>
> Signed-off-by: Don Slutz <dslutz@xxxxxxxxxxx>
> ---
>  .gitignore                 |   1 +
>  tools/misc/Makefile        |   7 ++-
>  tools/misc/xen-hvm-param.c | 154 
> +++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 160 insertions(+), 2 deletions(-)
>  create mode 100644 tools/misc/xen-hvm-param.c
>
> diff --git a/.gitignore b/.gitignore
> index 6d725aa..ad52162 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -179,6 +179,7 @@ tools/misc/xen-tmem-list-parse
>  tools/misc/xenperf
>  tools/misc/xenpm
>  tools/misc/xen-hvmctx
> +tools/misc/xen-hvm-param
>  tools/misc/gtraceview
>  tools/misc/gtracestat
>  tools/misc/xenlockprof
> diff --git a/tools/misc/Makefile b/tools/misc/Makefile
> index 69b1817..b8d4579 100644
> --- a/tools/misc/Makefile
> +++ b/tools/misc/Makefile
> @@ -10,7 +10,7 @@ CFLAGS += $(CFLAGS_libxenstore)
>  HDRS     = $(wildcard *.h)
>  
>  TARGETS-y := xenperf xenpm xen-tmem-list-parse gtraceview gtracestat 
> xenlockprof xenwatchdogd xencov
> -TARGETS-$(CONFIG_X86) += xen-detect xen-hvmctx xen-hvmcrash xen-lowmemd 
> xen-mfndump
> +TARGETS-$(CONFIG_X86) += xen-detect xen-hvmctx xen-hvm-param xen-hvmcrash 
> xen-lowmemd xen-mfndump
>  TARGETS-$(CONFIG_MIGRATE) += xen-hptool
>  TARGETS := $(TARGETS-y)
>  
> @@ -22,7 +22,7 @@ INSTALL_BIN := $(INSTALL_BIN-y)
>  
>  INSTALL_SBIN-y := xen-bugtool xen-python-path xenperf xenpm 
> xen-tmem-list-parse gtraceview \
>       gtracestat xenlockprof xenwatchdogd xen-ringwatch xencov
> -INSTALL_SBIN-$(CONFIG_X86) += xen-hvmctx xen-hvmcrash xen-lowmemd xen-mfndump
> +INSTALL_SBIN-$(CONFIG_X86) += xen-hvmctx xen-hvm-param xen-hvmcrash 
> xen-lowmemd xen-mfndump
>  INSTALL_SBIN-$(CONFIG_MIGRATE) += xen-hptool
>  INSTALL_SBIN := $(INSTALL_SBIN-y)
>  
> @@ -57,6 +57,9 @@ clean:
>  xen-hvmctx: xen-hvmctx.o
>       $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS)
>  
> +xen-hvm-param: xen-hvm-param.o
> +     $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS)
> +
>  xen-hvmcrash: xen-hvmcrash.o
>       $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS)
>  
> diff --git a/tools/misc/xen-hvm-param.c b/tools/misc/xen-hvm-param.c
> new file mode 100644
> index 0000000..df6ba12
> --- /dev/null
> +++ b/tools/misc/xen-hvm-param.c
> @@ -0,0 +1,154 @@
> +/*
> + * tools/misc/xen-hvm-param.c
> + *
> + * Copyright (C) 2014 Verizon Corporation
> + *
> + * This file is free software; you can redistribute it and/or modify it
> + * under the terms of the GNU General Public License Version 2 (GPLv2)
> + * as published by the Free Software Foundation.
> + *
> + * This file is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * General Public License for more details. <http://www.gnu.org/licenses/>.
> + */
> +
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <err.h>
> +
> +#include <xenctrl.h>
> +
> +
> +int
> +main(int argc, char **argv)
> +{
> +    xc_interface *xch;
> +    int domid;
> +    int param;
> +    int ret = 0;
> +    int i;
> +    char hvm_param_name[HVM_NR_PARAMS][80];
> +
> +    unsigned long hvm_param = -1;
> +
> +    if ( (argc < 3) || (argc > 4) )
> +        errx(1, "usage: %s domid param [new]", argv[0]);
> +
> +    for (i = 0; i < HVM_NR_PARAMS; i++)
> +        snprintf(hvm_param_name[i], sizeof(hvm_param_name[i]), "Unknown %d", 
> i);
> +    snprintf(hvm_param_name[HVM_PARAM_CALLBACK_IRQ],
> +             sizeof(hvm_param_name[HVM_PARAM_CALLBACK_IRQ]), "Callback_Irq");
> +    snprintf(hvm_param_name[HVM_PARAM_STORE_PFN],
> +             sizeof(hvm_param_name[HVM_PARAM_STORE_PFN]), "Store_Pfn");
> +    snprintf(hvm_param_name[HVM_PARAM_STORE_EVTCHN],
> +             sizeof(hvm_param_name[HVM_PARAM_STORE_EVTCHN]), "Store_Evtchn");
> +    snprintf(hvm_param_name[HVM_PARAM_PAE_ENABLED],
> +             sizeof(hvm_param_name[HVM_PARAM_PAE_ENABLED]), "Pae_Enabled");
> +    snprintf(hvm_param_name[HVM_PARAM_IOREQ_PFN],
> +             sizeof(hvm_param_name[HVM_PARAM_IOREQ_PFN]), "Ioreq_Pfn");
> +    snprintf(hvm_param_name[HVM_PARAM_BUFIOREQ_PFN],
> +             sizeof(hvm_param_name[HVM_PARAM_BUFIOREQ_PFN]), "Bufioreq_Pfn");
> +    snprintf(hvm_param_name[HVM_PARAM_VIRIDIAN],
> +             sizeof(hvm_param_name[HVM_PARAM_VIRIDIAN]), "Viridian");
> +    snprintf(hvm_param_name[HVM_PARAM_TIMER_MODE],
> +             sizeof(hvm_param_name[HVM_PARAM_TIMER_MODE]), "Timer_Mode");
> +    snprintf(hvm_param_name[HVM_PARAM_HPET_ENABLED],
> +             sizeof(hvm_param_name[HVM_PARAM_HPET_ENABLED]), "Hpet_Enabled");
> +    snprintf(hvm_param_name[HVM_PARAM_IDENT_PT],
> +             sizeof(hvm_param_name[HVM_PARAM_IDENT_PT]), "Ident_Pt");
> +    snprintf(hvm_param_name[HVM_PARAM_DM_DOMAIN],
> +             sizeof(hvm_param_name[HVM_PARAM_DM_DOMAIN]), "Dm_Domain");
> +    snprintf(hvm_param_name[HVM_PARAM_ACPI_S_STATE],
> +             sizeof(hvm_param_name[HVM_PARAM_ACPI_S_STATE]), "Acpi_S_State");
> +    snprintf(hvm_param_name[HVM_PARAM_VM86_TSS],
> +             sizeof(hvm_param_name[HVM_PARAM_VM86_TSS]), "Vm86_Tss");
> +    snprintf(hvm_param_name[HVM_PARAM_VPT_ALIGN],
> +             sizeof(hvm_param_name[HVM_PARAM_VPT_ALIGN]), "Vpt_Align");
> +    snprintf(hvm_param_name[HVM_PARAM_CONSOLE_PFN],
> +             sizeof(hvm_param_name[HVM_PARAM_CONSOLE_PFN]), "Console_Pfn");
> +    snprintf(hvm_param_name[HVM_PARAM_CONSOLE_EVTCHN],
> +             sizeof(hvm_param_name[HVM_PARAM_CONSOLE_EVTCHN]), 
> "Console_Evtchn");
> +    snprintf(hvm_param_name[HVM_PARAM_ACPI_IOPORTS_LOCATION],
> +             sizeof(hvm_param_name[HVM_PARAM_ACPI_IOPORTS_LOCATION]),
> +             "Acpi_Ioports_Location");
> +    snprintf(hvm_param_name[HVM_PARAM_MEMORY_EVENT_CR0],
> +             sizeof(hvm_param_name[HVM_PARAM_MEMORY_EVENT_CR0]), 
> "Memory_Event_Cr0");
> +    snprintf(hvm_param_name[HVM_PARAM_MEMORY_EVENT_CR3],
> +             sizeof(hvm_param_name[HVM_PARAM_MEMORY_EVENT_CR3]), 
> "Memory_Event_Cr3");
> +    snprintf(hvm_param_name[HVM_PARAM_MEMORY_EVENT_CR4],
> +             sizeof(hvm_param_name[HVM_PARAM_MEMORY_EVENT_CR4]), 
> "Memory_Event_Cr4");
> +    snprintf(hvm_param_name[HVM_PARAM_MEMORY_EVENT_INT3],
> +             sizeof(hvm_param_name[HVM_PARAM_MEMORY_EVENT_INT3]), 
> "Memory_Event_Int3");
> +    snprintf(hvm_param_name[HVM_PARAM_NESTEDHVM],
> +             sizeof(hvm_param_name[HVM_PARAM_NESTEDHVM]), "Nestedhvm");
> +    snprintf(hvm_param_name[HVM_PARAM_MEMORY_EVENT_SINGLE_STEP],
> +             sizeof(hvm_param_name[HVM_PARAM_MEMORY_EVENT_SINGLE_STEP]),
> +             "Memory_Event_Single_Step");
> +    snprintf(hvm_param_name[HVM_PARAM_BUFIOREQ_EVTCHN],
> +             sizeof(hvm_param_name[HVM_PARAM_BUFIOREQ_EVTCHN]), 
> "Bufioreq_Evtchn");
> +    snprintf(hvm_param_name[HVM_PARAM_PAGING_RING_PFN],
> +             sizeof(hvm_param_name[HVM_PARAM_PAGING_RING_PFN]), 
> "Paging_Ring_Pfn");
> +    snprintf(hvm_param_name[HVM_PARAM_ACCESS_RING_PFN],
> +             sizeof(hvm_param_name[HVM_PARAM_ACCESS_RING_PFN]), 
> "Access_Ring_Pfn");
> +    snprintf(hvm_param_name[HVM_PARAM_SHARING_RING_PFN],
> +             sizeof(hvm_param_name[HVM_PARAM_SHARING_RING_PFN]), 
> "Sharing_Ring_Pfn");
> +    snprintf(hvm_param_name[HVM_PARAM_VMWARE_HW],
> +             sizeof(hvm_param_name[HVM_PARAM_VMWARE_HW]), "Vmware_Hw");
> +    snprintf(hvm_param_name[HVM_PARAM_VMPORT_BUILD_NUMBER_TIME],
> +             sizeof(hvm_param_name[HVM_PARAM_VMPORT_BUILD_NUMBER_TIME]),
> +             "Vmport_Build_Number_Time");
> +    snprintf(hvm_param_name[HVM_PARAM_VMPORT_BUILD_NUMBER_VALUE],
> +             sizeof(hvm_param_name[HVM_PARAM_VMPORT_BUILD_NUMBER_VALUE]),
> +             "Vmport_Build_Number_Value");
> +    snprintf(hvm_param_name[HVM_PARAM_VMPORT_RESET_TIME],
> +             sizeof(hvm_param_name[HVM_PARAM_VMPORT_RESET_TIME]), 
> "Vmport_Reset_Time");

Surely all these snprintfs can be replaced with some compiler magic, to
vastly reduce its complexity.

static const char * hvm_param_names[] =
{
    "Callback_Irq",
    "Store_Pfn",
    ...
};

static const char *hvm_param_name(unsigned int param)
{
     return param < ARRAY_SIZE(hvm_param_names) ? hvm_param_names[param]
: "Unknown";
}

It might also be nice to have a "dump all" option.

~Andrew

> +
> +    xch = xc_interface_open(0, 0, 0);
> +    if ( !xch )
> +        err(1, "failed to open control interface");
> +
> +    domid = atoi(argv[1]);
> +    param = atoi(argv[2]);
> +
> +    ret = xc_get_hvm_param(xch, domid, param, &hvm_param);
> +    if ( ret )
> +        err(1, "failed to get hvm param %d for domid %d", param, domid);
> +    else
> +    {
> +        if ( argc == 4 )
> +        {
> +            long new = strtol(argv[3], NULL, 0);
> +
> +            ret = xc_set_hvm_param(xch, domid, param, new);
> +            if ( ret )
> +                err(1, "failed to set hvm param %d for domid %d", param, 
> domid);
> +            else if ( (param >= 0) && (param < HVM_NR_PARAMS) )
> +                printf("hvm_param(%s)=0x%lx(%ld) was 0x%lx(%ld)\n",
> +                       hvm_param_name[param], new, new, hvm_param, 
> hvm_param);
> +            else
> +                printf("hvm_param(%d)=0x%lx(%ld) was 0x%lx(%ld)\n",
> +                       param, new, new, hvm_param, hvm_param);
> +        }
> +        else
> +        {
> +            if ( (param >= 0) && (param < HVM_NR_PARAMS) )
> +                printf("hvm_param(%s)=0x%lx(%ld)\n", hvm_param_name[param], 
> hvm_param,
> +                       hvm_param);
> +            else
> +                printf("hvm_param(%d)=0x%lx(%ld)\n", param, hvm_param, 
> hvm_param);
> +        }
> +    }
> +    xc_interface_close(xch);
> +
> +    return ret;
> +}
> +
> +/*
> + * Local variables:
> + * mode: C
> + * c-file-style: "BSD"
> + * c-basic-offset: 4
> + * indent-tabs-mode: nil
> + * End:
> + */


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


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.