Re: [PATCH 5/6] node_memory: Expose the APIs to virsh

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

 



On Fri, Sep 14, 2012 at 02:42:19PM +0800, Osier Yang wrote:
> New command node-memory-tune to get/set the node memory parameters,
> only two parameters are allowed to set (pages_to_scan, and sleep_millisecs,
> see documents in this patch for more details).
> 
> Example of node-memory-tune's output:
> 
> Shared memory:
> 	pages_to_scan   100
> 	sleep_millisecs 20
> 	pages_shared    0
> 	pages_sharing   0
> 	pages_unshared  0
> 	pages_volatile  0
> 	full_scans      0
> ---
>  tools/virsh-host.c |  116 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>  tools/virsh.pod    |    8 ++++
>  2 files changed, 124 insertions(+), 0 deletions(-)
> 
> diff --git a/tools/virsh-host.c b/tools/virsh-host.c
> index c46288b..22292c8 100644
> --- a/tools/virsh-host.c
> +++ b/tools/virsh-host.c
> @@ -37,6 +37,7 @@
>  #include "util.h"
>  #include "virsh-domain.h"
>  #include "xml.h"
> +#include "virtypedparam.h"
>  
>  /*
>   * "capabilities" command
> @@ -884,12 +885,127 @@ cmdVersion(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
>      return true;
>  }
>  
> +static const vshCmdInfo info_node_memory_tune[] = {
> +    {"help", N_("Get or set node memory parameters")},
> +    {"desc", N_("Get or set node memory parameters"
> +                "    To get the memory parameters, use following command: \n\n"
> +                "    virsh # node-memory-tune")},
> +    {NULL, NULL}
> +};
> +
> +static const vshCmdOptDef opts_node_memory_tune[] = {
> +    {"shared-pages-to-scan", VSH_OT_INT, VSH_OFLAG_NONE,
> +      N_("number of pages to scan before the shared memory service "
> +         "goes to sleep")},
> +    {"shared-sleep-millisecs", VSH_OT_INT, VSH_OFLAG_NONE,
> +      N_("number of millisecs the shared memory service should "
> +         "sleep before next scan")},

  I would add "shm_" prefix again for the paremeters

> +    {NULL, 0, 0, NULL}
> +};
> +
> +static bool
> +cmdNodeMemoryTune(vshControl *ctl, const vshCmd *cmd)
> +{
> +    virTypedParameterPtr params = NULL;
> +    int nparams = 0;
> +    unsigned int flags = 0;
> +    unsigned int shared_pages_to_scan = 0;
> +    unsigned int shared_sleep_millisecs = 0;
> +    bool ret = false;
> +    int i = 0;
> +
> +    if (vshCommandOptUInt(cmd, "shared-pages-to-scan",
> +                          &shared_pages_to_scan) < 0) {
> +        vshError(ctl, "%s", _("invalid shared-pages-to-scan number"));
> +        return false;
> +    }
> +
> +    if (vshCommandOptUInt(cmd, "shared-sleep-millisecs",
> +                          &shared_sleep_millisecs) < 0) {
> +        vshError(ctl, "%s", _("invalid shared-sleep-millisecs number"));
> +        return false;
> +    }
> +

  same

> +    if (shared_pages_to_scan)
> +        nparams++;
> +
> +    if (shared_sleep_millisecs)
> +        nparams++;
> +
> +    if (nparams == 0) {
> +        /* Get the number of memory parameters */
> +        if (virNodeGetMemoryParameters(ctl->conn, NULL, &nparams, flags) != 0) {
> +            vshError(ctl, "%s",
> +                     _("Unable to get number of memory parameters"));
> +            goto cleanup;
> +        }
> +
> +        if (nparams == 0) {
> +            ret = true;
> +            goto cleanup;
> +        }
> +
> +        /* Now go get all the memory parameters */
> +        params = vshCalloc(ctl, nparams, sizeof(*params));
> +        if (virNodeGetMemoryParameters(ctl->conn, params, &nparams, flags) != 0) {
> +            vshError(ctl, "%s", _("Unable to get memory parameters"));
> +            goto cleanup;
> +        }
> +
> +        /* XXX: Need to sort the returned params once new parameter
> +         * fields not of shared memory are added.
> +         */
> +        vshPrint(ctl, _("Shared memory:\n"));
> +        for (i = 0; i < nparams; i++) {
> +            char *str = vshGetTypedParamValue(ctl, &params[i]);
> +            vshPrint(ctl, "\t%-15s %s\n", params[i].field, str);
> +            VIR_FREE(str);
> +        }
> +
> +        ret = true;
> +    } else {
> +        /* Set the memory parameters */
> +        params = vshCalloc(ctl, nparams, sizeof(*params));
> +
> +        if (i < nparams && shared_pages_to_scan) {
> +            if (virTypedParameterAssign(&params[i++],
> +                                        VIR_NODE_MEMORY_SHARED_PAGES_TO_SCAN,
> +                                        VIR_TYPED_PARAM_UINT,
> +                                        shared_pages_to_scan) < 0)
> +                goto error;
> +        }
> +
> +        if (i < nparams && shared_sleep_millisecs) {
> +            if (virTypedParameterAssign(&params[i++],
> +                                        VIR_NODE_MEMORY_SHARED_SLEEP_MILLISECS,
> +                                        VIR_TYPED_PARAM_UINT,
> +                                        shared_sleep_millisecs) < 0)
> +                goto error;
> +        }
> +
> +        if (virNodeSetMemoryParameters(ctl->conn, params, nparams, flags) != 0)
> +            goto error;
> +        else
> +            ret = true;
> +    }
> +
> +cleanup:
> +    VIR_FREE(params);
> +    return ret;
> +
> +error:
> +    vshError(ctl, "%s", _("Unable to change memory parameters"));
> +    goto cleanup;
> +}
> +
>  const vshCmdDef hostAndHypervisorCmds[] = {
>      {"capabilities", cmdCapabilities, NULL, info_capabilities, 0},
>      {"connect", cmdConnect, opts_connect, info_connect,
>       VSH_CMD_FLAG_NOCONNECT},
>      {"freecell", cmdFreecell, opts_freecell, info_freecell, 0},
>      {"hostname", cmdHostname, NULL, info_hostname, 0},
> +    {"node-memory-tune", cmdNodeMemoryTune,
> +     opts_node_memory_tune, info_node_memory_tune, 0},
>      {"nodecpustats", cmdNodeCpuStats, opts_node_cpustats, info_nodecpustats, 0},
>      {"nodeinfo", cmdNodeinfo, NULL, info_nodeinfo, 0},
>      {"nodememstats", cmdNodeMemStats, opts_node_memstats, info_nodememstats, 0},
> diff --git a/tools/virsh.pod b/tools/virsh.pod
> index 559e64d..7795822 100644
> --- a/tools/virsh.pod
> +++ b/tools/virsh.pod
> @@ -293,6 +293,14 @@ Real-Time-Clock interrupt to fire (to wake up the node) after a time delay
>  specified by the 'duration' parameter. The duration time should be
>  at least 60 seconds.
>  
> +=item B<node-memory-tune> [I<shared-pages-to-scan>] [I<shared-sleep-millisecs>]
> +
> +Allows you to display or set the node memory parameters.
> +I<shared-pages-to-scan> can be used to set the number of pages to scan
> +before the shared memory service goes to sleep; I<shared-sleep-millisecs>

 idem

> +can be used to set the number of millisecs the shared memory service should
> +sleep before next scan.
> +
>  =item B<capabilities>
>  
>  Print an XML document describing the capabilities of the hypervisor

  Otherwise, looks fine,

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel@xxxxxxxxxxxx  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]