All of lore.kernel.org
 help / color / mirror / Atom feed
From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: xen-devel@lists.xenproject.org,
	Doug Goldstein <cardoe@cardoe.com>, Wei Liu <wei.liu2@citrix.com>,
	Jan Beulich <jbeulich@suse.com>
Subject: Re: [PATCH v1 2/4] tmem: Wrap atomic_t in struct tmem_statistics as well.
Date: Thu, 2 Jun 2016 11:26:52 -0400	[thread overview]
Message-ID: <20160602152652.GA1099@char.us.oracle.com> (raw)
In-Reply-To: <57504DE3.9070805@citrix.com>

On Thu, Jun 02, 2016 at 04:16:51PM +0100, Andrew Cooper wrote:
> On 02/06/16 16:04, Konrad Rzeszutek Wilk wrote:
> > diff --git a/xen/common/tmem.c b/xen/common/tmem.c
> > index d362eae..b58ab4d 100644
> > --- a/xen/common/tmem.c
> > +++ b/xen/common/tmem.c
> > @@ -51,9 +51,32 @@ struct tmem_statistics {
> >      unsigned long failed_copies;
> >      unsigned long pcd_tot_tze_size;
> >      unsigned long pcd_tot_csize;
> > +    /* Global counters (should use long_atomic_t access). */
> > +    atomic_t global_obj_count;
> > +    atomic_t global_pgp_count;
> > +    atomic_t global_pcd_count;
> > +    atomic_t global_page_count;
> > +    atomic_t global_rtree_node_count;
> >  };
> >  
> > -static struct tmem_statistics tmem_stats;
> > +#define atomic_inc_and_max(_c) do { \
> > +    atomic_inc(&tmem_stats._c); \
> > +    if ( _atomic_read(tmem_stats._c) > tmem_stats._c##_max ) \
> > +        tmem_stats._c##_max = _atomic_read(tmem_stats._c); \
> > +} while (0)
> > +
> > +#define atomic_dec_and_assert(_c) do { \
> > +    atomic_dec(&tmem_stats._c); \
> > +    ASSERT(_atomic_read(tmem_stats._c) >= 0); \
> > +} while (0)
> 
> I know you are just modifying existing code (thus this complain doesn't
> count against the patch), but these constructs are racy and broken.

Yes.
> 
> You need to use atomic_{inc,dec}_and_test() for these to function as
> intended.
> 
> Up to you whether you want to fix that in this patch, or a subsequent
> non-cleanup patch.

Subsequent. There were sooo many things I itched to do - but for right
now just want to do this simple cleanup.
> 
> ~Andrew

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

  reply	other threads:[~2016-06-02 15:27 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-02 15:04 [PATCH v1 for 4.7] Tmem cleanups Konrad Rzeszutek Wilk
2016-06-02 15:04 ` [PATCH v1 1/4] tmem: Move global stats in a tmem_statistics structure Konrad Rzeszutek Wilk
2016-06-02 15:04 ` [PATCH v1 2/4] tmem: Wrap atomic_t in struct tmem_statistics as well Konrad Rzeszutek Wilk
2016-06-02 15:16   ` Andrew Cooper
2016-06-02 15:26     ` Konrad Rzeszutek Wilk [this message]
2016-06-02 15:04 ` [PATCH v1 3/4] tmem: Move global_ individual variables in a global structure Konrad Rzeszutek Wilk
2016-06-02 15:04 ` [PATCH v1 4/4] tmem: Move bulk of tmem control functions in its own file Konrad Rzeszutek Wilk
2016-06-02 15:17 ` [PATCH v1 for 4.7] Tmem cleanups Jan Beulich
2016-06-02 15:27   ` Konrad Rzeszutek Wilk
2016-06-02 15:42 ` Wei Liu
2016-06-02 15:46   ` Konrad Rzeszutek Wilk
2016-06-02 20:09     ` Konrad Rzeszutek Wilk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160602152652.GA1099@char.us.oracle.com \
    --to=konrad.wilk@oracle.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=cardoe@cardoe.com \
    --cc=jbeulich@suse.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.