From: "Jan Beulich" Subject: Re: [PATCH v9 06/13] x86: dynamically get/set CBM for a domain Date: Tue, 16 Jun 2015 08:08:34 +0100 Message-ID: <557FE79202000078000853C4@mail.emea.novell.com> References: <1433307190-6381-1-git-send-email-chao.p.peng@linux.intel.com> <1433307190-6381-7-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: In-Reply-To: <1433307190-6381-7-git-send-email-chao.p.peng@linux.intel.com> Content-Disposition: inline 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: wei.liu2@citrix.com, Ian.Campbell@citrix.com, stefano.stabellini@eu.citrix.com, andrew.cooper3@citrix.com, dario.faggioli@citrix.com, Ian.Jackson@eu.citrix.com, xen-devel@lists.xen.org, will.auld@intel.com, keir@xen.org, dgdegra@tycho.nsa.gov List-Id: xen-devel@lists.xenproject.org >>> On 03.06.15 at 06:53, wrote: > +static bool_t psr_check_cbm(unsigned int cbm_len, uint64_t cbm) > +{ > + unsigned int first_bit, zero_bit; > + > + /* Set bits should only in the range of [0, cbm_len). */ > + if ( cbm & (~0ull << cbm_len) ) > + return 0; > + > + /* At least one bit need to be set. */ > + if ( hweight_long(cbm) < 1 ) Why hweight_long()? Afaict all you need is "cbm != 0". > +int psr_set_l3_cbm(struct domain *d, unsigned int socket, uint64_t cbm) > +{ > + unsigned int old_cos, cos; > + struct psr_cat_cbm *map, *found = NULL; > + struct psr_cat_socket_info *info = NULL; > + int ret = get_cat_socket_info(socket, &info); > + > + if ( ret ) > + return ret; > + > + if ( !psr_check_cbm(info->cbm_len, cbm) ) > + return -EINVAL; > + > + old_cos = d->arch.psr_cos_ids[socket]; > + map = info->cos_to_cbm; > + > + spin_lock(&info->cbm_lock); > + > + for ( cos = 0; cos <= info->cos_max; cos++ ) > + { > + /* If still not found, then keep unused one. */ > + if ( !found && cos != 0 && map[cos].ref == 0 ) > + found = map + cos; > + else if ( map[cos].cbm == cbm ) > + { > + if ( unlikely(cos == old_cos) ) > + { > + spin_unlock(&info->cbm_lock); > + return 0; Is this in particular, but also the surrounding "else if", correct when map[cos].ref == 0? I can't seem to see map[cos].cbm getting invalidated when an entry's refcount drops to zero... Jan