public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Tom Zanussi <tom.zanussi@linux.intel.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>,
	Namhyung Kim <namhyung@kernel.org>,
	Andi Kleen <andi@firstfloor.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v3 5/7] tracing: Add 'hist' event trigger command
Date: Sat, 04 Apr 2015 15:25:49 -0500	[thread overview]
Message-ID: <1428179149.2610.27.camel@picadillo> (raw)
In-Reply-To: <CAADnVQJfw7HOCjitz9jQX+VDQj7QjwSsCH0pP+JfoGUHpvetOQ@mail.gmail.com>

On Sat, 2015-04-04 at 08:36 -0700, Alexei Starovoitov wrote:
> On Fri, Apr 3, 2015 at 8:51 AM, Tom Zanussi <tom.zanussi@linux.intel.com> wrote:
> > +static struct hist_trigger_entry *
> > +tracing_map_insert(struct tracing_map *map, void *key)
> > +{
> > +       u32 idx, key_hash, test_key;
> > +
> > +       key_hash = jhash(key, map->key_size, 0);
> > +       idx = key_hash >> (32 - (map->map_bits + 1));
> > +
> > +       while (1) {
> > +               idx &= (map->map_size - 1);
> > +               test_key = map->map[idx].key;
> > +
> > +               if (test_key && test_key == key_hash &&
> > +                   keys_match(key, map->map[idx].val->key, map->key_size))
> > +                       return map->map[idx].val;
> > +
> > +               if (!test_key && !cmpxchg(&map->map[idx].key, 0, key_hash)) {
> > +                       struct hist_trigger_entry *entry;
> > +
> > +                       entry = hist_trigger_entry_create(map);
> > +                       if (!entry)
> > +                               break;
> > +                       memcpy(entry->key, key, map->key_size);
> > +                       map->map[idx].val = entry;
> > +
> > +                       return map->map[idx].val;
> > +               }
> 
> There is obvious race here, since algorithm is not implemented correctly.
> Partially inserted key/value is not handled.

You're right, thanks for pointing it out.

I guess adding '&& map->map[idx].val && keys_match(...' would fix the
problem, but would result in duplicate entries for the same key, which I
wanted to avoid.

My original code didn't even have that keys_match() check, which is only
there for the rare possibility of a key collision - I originally just
set a flag in that case, which was printed out with the run results.  In
all my testing I only ever saw it once, so I know it happens very
rarely, but it does happen, and the flag lets the user know and to maybe
try again (my second run of the same test didn't show a collision).  I
thought of actually tracking the collisions as well, since they're so
rare, but didn't see that it was worth the bother.  Using a 64-bit hash
would make it even more remote, but again, is it necessary in practice?

So I think there are several solutions - I'll probably just keep things
simple and go back to a collision flag..

Tom


  reply	other threads:[~2015-04-04 20:25 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-03 15:51 [PATCH v3 0/7] tracing: 'hist' triggers Tom Zanussi
2015-04-03 15:51 ` [PATCH v3 1/7] tracing: Make ftrace_event_field checking functions available Tom Zanussi
2015-04-03 15:51 ` [PATCH v3 2/7] tracing: Add event record param to trigger_ops.func() Tom Zanussi
2015-04-03 15:51 ` [PATCH v3 3/7] tracing: Add get_syscall_name() Tom Zanussi
2015-04-03 15:51 ` [PATCH v3 4/7] tracing: Add a per-event-trigger 'paused' field Tom Zanussi
2015-04-03 15:51 ` [PATCH v3 5/7] tracing: Add 'hist' event trigger command Tom Zanussi
2015-04-04 15:14   ` Paul Bolle
2015-04-04 20:09     ` Tom Zanussi
2015-04-04 20:56       ` Paul Bolle
2015-04-04 21:06         ` Tom Zanussi
2015-04-06 15:55       ` Steven Rostedt
2015-04-06 15:50     ` Steven Rostedt
2015-04-06 16:19       ` Paul Bolle
2015-04-06 16:25         ` Steven Rostedt
2015-04-06 18:07           ` Paul Bolle
2015-04-04 15:36   ` Alexei Starovoitov
2015-04-04 20:25     ` Tom Zanussi [this message]
2015-04-03 15:51 ` [PATCH v3 6/7] tracing: Add enable_hist/disable_hist triggers Tom Zanussi
2015-04-03 15:51 ` [PATCH v3 7/7] tracing: Add 'hist' trigger Documentation Tom Zanussi
2015-04-13 21:18 ` [PATCH v3 0/7] tracing: 'hist' triggers Steven Rostedt
2015-04-13 21:49   ` Tom Zanussi

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=1428179149.2610.27.camel@picadillo \
    --to=tom.zanussi@linux.intel.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andi@firstfloor.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masami.hiramatsu.pt@hitachi.com \
    --cc=namhyung@kernel.org \
    --cc=rostedt@goodmis.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox