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

Re: [Xen-devel] [PATCH v2 5/5] tools: add total/local memory bandwith monitoring



On Wed, Jan 07, 2015 at 07:12:05PM +0800, Chao Peng wrote:
[...]
> +static int libxl__psr_cmt_get_mem_bandwidth(libxl__gc *gc,
> +                                            uint32_t domid,
> +                                            xc_psr_cmt_type type,
> +                                            uint32_t socketid,
> +                                            uint32_t *bandwidth)
> +{
> +    uint64_t sample1, sample2;
> +    uint32_t upscaling_factor;
> +    int retry_attempts = 0;
> +    int rc;
> +
> +retry:
> +    rc = libxl__psr_cmt_get_l3_monitoring_data(gc, domid, type, socketid,
> +                                               &sample1);
> +    if (rc < 0)
> +        return ERROR_FAIL;
> +
> +    usleep(10000);
> +
> +    rc = libxl__psr_cmt_get_l3_monitoring_data(gc, domid, type, socketid,
> +                                               &sample2);
> +    if (rc < 0)
> +       return ERROR_FAIL;
> +
> +    if (sample2 < sample1) {
> +         if (retry_attempts < MBM_SAMPLE_RETRY_MAX) {
> +             retry_attempts++;
> +             goto retry;
> +         } else {
> +             LOGE(ERROR, "event counter overflowed");
> +             return ERROR_FAIL;
> +         }
> +    }
> +

Two things:

1. Use for/while for retry loop, don't use goto.
2. Use "goto out" idiom for error handling.

The "goto out" idiom is part of documented libxl error handling section
in tools/libxl/CODING_STYLE. You might find that document useful
reference.

Wei.

_______________________________________________
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®.