qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Kevin Wolf <kwolf@redhat.com>, "Richard W.M. Jones" <rjones@redhat.com>
Cc: qemu-devel@nongnu.org, agraf@suse.de, qemu-block@nongnu.org,
	armbru@redhat.com
Subject: Re: [Qemu-devel] [PATCH v3 1/2] Add a simple mechanism to protect against error message floods.
Date: Wed, 8 Jul 2015 15:38:30 +0200	[thread overview]
Message-ID: <559D27D6.4090309@redhat.com> (raw)
In-Reply-To: <20150708132642.GL4117@noname.redhat.com>



On 08/07/2015 15:26, Kevin Wolf wrote:
>> +/* Suggested initial value is 100 */
>> +#define FLOOD_COUNTER(counter_name, initial) \
>> +  static int counter_name = (initial)

No "static" here.

>> +#define NO_FLOOD(counter_name, code, suppress_message)         \
>> +  do {                                                         \
>> +    int t_##counter_name = atomic_fetch_add(&counter_name, 0); \
>> +    if (t_##counter_name > 0) {                                \
>> +        code;                                                  \
>> +        if (t_##counter_name == 1) {                           \
>> +            suppress_message;                                  \
>> +        }                                                      \
>> +        atomic_dec(&counter_name);                             \
>> +    }                                                          \
>> +} while (0)

What you want is a cmpxchg loop like:

   int old;
   do
       old = atomic_read(&counter_name);
   while (old > 0 && atomic_cmpxchg(&counter_name, old, old - 1) != old);
   if (old > 0) {
       code;
       if (old == 1) {
           suppress_message;
       }
   }

but I would wrap it with a simple API like

   void error_report_limited(int *counter, const char *s, ...);
   void error_report_err_limited(int *counter, Error *err);

instead of your complex NO_FLOOD macro.

Paolo

  reply	other threads:[~2015-07-08 13:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-08 12:50 [Qemu-devel] [PATCH v3 0/2] block/curl: Don't lose original error when a connection fails Richard W.M. Jones
2015-07-08 12:50 ` [Qemu-devel] [PATCH v3 1/2] Add a simple mechanism to protect against error message floods Richard W.M. Jones
2015-07-08 13:26   ` Kevin Wolf
2015-07-08 13:38     ` Paolo Bonzini [this message]
2015-07-08 12:50 ` [Qemu-devel] [PATCH v3 2/2] block/curl: Don't lose original error when a connection fails Richard W.M. Jones

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=559D27D6.4090309@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=agraf@suse.de \
    --cc=armbru@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=rjones@redhat.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).