mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: David Daney <ddaney@caviumnetworks.com>
Cc: Jason Baron <jbaron@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>,
	hpa@zytor.com, mingo@elte.hu, tglx@linutronix.de,
	andi@firstfloor.org, roland@redhat.com, rth@redhat.com,
	masami.hiramatsu.pt@hitachi.com, fweisbec@gmail.com,
	avi@redhat.com, davem@davemloft.net, sam@ravnborg.org,
	michael@ellerman.id.au, linux-kernel@vger.kernel.org
Subject: Re: [PATCH/RFC 1/2] jump label: make enable/disable o(1)
Date: Fri, 17 Dec 2010 16:12:21 -0500	[thread overview]
Message-ID: <1292620341.22905.17.camel@gandalf.stny.rr.com> (raw)
In-Reply-To: <4D0BCD60.3030007@caviumnetworks.com>

On Fri, 2010-12-17 at 12:51 -0800, David Daney wrote:
> On 12/17/2010 12:07 PM, Jason Baron wrote:

> Not acceptable I would think.
> 
> How about:
> 
> union fubar {
>     int key_as_non_atomic;
>     atomic_t key_as_atomic;
> };

I don't even like this union.

> 
> Now explain the exact semantics of this thing including how you 
> guarantee no conflicting accesses *ever* occur.

I don't like the mixed semantics at all.

> 
> 
> > So for when jump labels are disabled case we could have
> > one struct:
> >
> > struct jump_label_key {

	atomic_t state;

> > }
> >
> > and then we could then have (rough c code):
> >
> > jump_label_enable(struct jump_label_key *key)
> > {

	if (atomic_read(&key->state))
		return;
	atomic_inc(&key->state);

> > }
> >
> > jump_label_disable(struct jump_label_key *key)
> > {

	if (!atomic_read(&key->state))
		return;
	atomic_dec(&key->state);
	WARN_ON(atomic_read(&key->state);

> > }
> >
> > jump_label_inc(struct jump_label_key *key)
> > {

 	atomic_inc(&key->state)

> > }
> >
> > jump_label_dec(struct jump_label_key *key)
> > {

 	atomic_dec((&key->state)

> > }
> >
> > bool unlikely_switch(struct jump_label_key *key)
> > {

 	if (atomic_read(&key->state))

> > 		return true;
> > 	return false;
> > }
> >

There, now you are guaranteed that you have proper semantics.

> >
> > can we agree on something like this?
> 
> I get a sick feeling whenever casting is used to give types with well 
> defined semantics (atomic_t) poorly defined semantics (your usage).

Exactly, I like to avoid (void*) anything or even worse, casting one
type to another for some strange semantics. This is guaranteed nightmare
of maintenance.

-- Steve



  reply	other threads:[~2010-12-17 21:12 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-16 18:25 [PATCH/RFC 0/2] jump label: simplify API Jason Baron
2010-12-16 18:25 ` [PATCH/RFC 1/2] jump label: make enable/disable o(1) Jason Baron
2010-12-16 19:10   ` Peter Zijlstra
2010-12-16 19:23     ` Jason Baron
2010-12-16 19:33       ` Peter Zijlstra
2010-12-16 19:36         ` Jason Baron
2010-12-16 19:41           ` Peter Zijlstra
2010-12-16 19:48             ` Jason Baron
2010-12-16 20:09               ` Steven Rostedt
2010-12-16 20:36               ` Mathieu Desnoyers
2010-12-16 20:43                 ` Peter Zijlstra
2010-12-16 20:50                   ` Mathieu Desnoyers
2010-12-16 20:56                     ` Peter Zijlstra
2010-12-17 20:07                       ` Jason Baron
2010-12-17 20:51                         ` David Daney
2010-12-17 21:12                           ` Steven Rostedt [this message]
2010-12-17 21:32                             ` Jason Baron
2010-12-16 20:45               ` Mathieu Desnoyers
2010-12-16 18:25 ` [PATCH/RFC 2/2] jump label: introduce unlikely_switch() Jason Baron
2010-12-16 19:22 ` [PATCH/RFC 0/2] jump label: simplify API Mathieu Desnoyers
2010-12-16 20:18   ` Steven Rostedt

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=1292620341.22905.17.camel@gandalf.stny.rr.com \
    --to=rostedt@goodmis.org \
    --cc=andi@firstfloor.org \
    --cc=avi@redhat.com \
    --cc=davem@davemloft.net \
    --cc=ddaney@caviumnetworks.com \
    --cc=fweisbec@gmail.com \
    --cc=hpa@zytor.com \
    --cc=jbaron@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masami.hiramatsu.pt@hitachi.com \
    --cc=mathieu.desnoyers@polymtl.ca \
    --cc=michael@ellerman.id.au \
    --cc=mingo@elte.hu \
    --cc=peterz@infradead.org \
    --cc=roland@redhat.com \
    --cc=rth@redhat.com \
    --cc=sam@ravnborg.org \
    --cc=tglx@linutronix.de \
    /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

all inboxes | Powered by JetHome®