David Hunt 59287933a0 examples/vm_power: add options to guest app
Add new command line arguments to the guest app to make
    testing and validation of the policy usage easier.
    These arguments are mainly around setting up the power
    management policy that is sent from the guest vm to
    to the vm_power_manager in the host

    New command line parameters:
    -n or --vm-name
       sets the name of the vm to be used by the host OS.
    -b or --busy-hours
       sets the list of hours that are predicted to be busy
    -q or --quiet-hours
       sets the list of hours that are predicted to be quiet
    -l or --vcpu-list
       sets the list of vcpus to monitor
    -p or --port-list
       sets the list of posts to monitor when using a
       workload policy.
    -o or --policy
       sets the default policy type
          TIME
          WORKLOAD
          TRAFFIC
          BRANCH_RATIO

    The format of the hours or list paramers is a comma-separated
    list of integers, which can take the form of
       a. x    e.g. --vcpu-list=1
       b. x,y  e.g. --quiet-hours=3,4
       c. x-y  e.g. --busy-hours=9-12
       d. combination of above (e.g. --busy-hours=4,5-7,9)

Signed-off-by: David Hunt <david.hunt@intel.com>
Acked-by: Radu Nicolau <radu.nicolau@intel.com>
2018-07-21 00:00:43 +02:00

83 lines
1.7 KiB
C

/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2010-2014 Intel Corporation.
* Copyright(c) 2014 6WIND S.A.
*/
#include <stdlib.h>
#include <string.h>
#include <rte_log.h>
#include "parse.h"
/*
* Parse elem, the elem could be single number/range or group
* 1) A single number elem, it's just a simple digit. e.g. 9
* 2) A single range elem, two digits with a '-' between. e.g. 2-6
* 3) A group elem, combines multiple 1) or 2) e.g 0,2-4,6
* Within group, '-' used for a range separator;
* ',' used for a single number.
*/
int
parse_set(const char *input, uint16_t set[], unsigned int num)
{
unsigned int idx;
const char *str = input;
char *end = NULL;
unsigned int min, max;
memset(set, 0, num * sizeof(uint16_t));
while (isblank(*str))
str++;
/* only digit or left bracket is qualify for start point */
if (!isdigit(*str) || *str == '\0')
return -1;
while (isblank(*str))
str++;
if (*str == '\0')
return -1;
min = num;
do {
/* go ahead to the first digit */
while (isblank(*str))
str++;
if (!isdigit(*str))
return -1;
/* get the digit value */
errno = 0;
idx = strtoul(str, &end, 10);
if (errno || end == NULL || idx >= num)
return -1;
/* go ahead to separator '-' and ',' */
while (isblank(*end))
end++;
if (*end == '-') {
if (min == num)
min = idx;
else /* avoid continuous '-' */
return -1;
} else if ((*end == ',') || (*end == '\0')) {
max = idx;
if (min == num)
min = idx;
for (idx = RTE_MIN(min, max);
idx <= RTE_MAX(min, max); idx++) {
set[idx] = 1;
}
min = num;
} else
return -1;
str = end + 1;
} while (*end != '\0');
return str - input;
}