From: Wei Liu Subject: Re: [PATCH v2 5/5] tools: add total/local memory bandwith monitoring Date: Wed, 7 Jan 2015 12:23:05 +0000 Message-ID: <20150107122305.GM28680@zion.uk.xensource.com> References: <1420629125-17725-1-git-send-email-chao.p.peng@linux.intel.com> <1420629125-17725-6-git-send-email-chao.p.peng@linux.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: <1420629125-17725-6-git-send-email-chao.p.peng@linux.intel.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Chao Peng Cc: keir@xen.org, Ian.Campbell@citrix.com, stefano.stabellini@eu.citrix.com, Ian.Jackson@eu.citrix.com, xen-devel@lists.xen.org, JBeulich@suse.com, wei.liu2@citrix.com List-Id: xen-devel@lists.xenproject.org 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.