mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@osdl.org>
To: kaigai@ak.jp.nec.com (Kaigai Kohei)
Cc: hugh@veritas.com, ak@muc.de, wli@holomorphy.com,
	takata.hirokazu@renesas.com, kaigai@ak.jp.nec.com,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] atomic_inc_return() for i386[1/5] (Re: atomic_inc_return)
Date: Sat, 11 Sep 2004 16:05:32 -0700	[thread overview]
Message-ID: <20040911160532.07216174.akpm@osdl.org> (raw)
In-Reply-To: <200409100326.i8A3QsYV007096@mailsv.bs1.fc.nec.co.jp>

kaigai@ak.jp.nec.com (Kaigai Kohei) wrote:
>
> 
> [1/5] atomic_inc_return-linux-2.6.9-rc1.i386.patch
>   This patch implements atomic_inc_return() and so on for i386,
>   and includes runtime check whether CPU is legacy 386.
>   It is same as I posted to LKML and Andi Kleen at '04/09/01.
> 

Can we not use the `alternative instruction' stuff to eliminate the runtime
test?


> 
> diff -rNU4 linux-2.6.9-rc1/include/asm-i386/atomic.h linux-2.6.9-rc1.atomic_inc_return/include/asm-i386/atomic.h
> --- linux-2.6.9-rc1/include/asm-i386/atomic.h	2004-08-24 16:02:24.000000000 +0900
> +++ linux-2.6.9-rc1.atomic_inc_return/include/asm-i386/atomic.h	2004-09-10 10:15:18.000000000 +0900
> @@ -1,8 +1,10 @@
>  #ifndef __ARCH_I386_ATOMIC__
>  #define __ARCH_I386_ATOMIC__
>  
>  #include <linux/config.h>
> +#include <linux/compiler.h>
> +#include <asm/processor.h>
>  
>  /*
>   * Atomic operations that C can't guarantee us.  Useful for
>   * resource counting etc..
> @@ -175,8 +177,48 @@
>  		:"ir" (i), "m" (v->counter) : "memory");
>  	return c;
>  }
>  
> +/**
> + * atomic_add_return - add and return
> + * @v: pointer of type atomic_t
> + * @i: integer value to add
> + *
> + * Atomically adds @i to @v and returns @i + @v
> + */
> +static __inline__ int atomic_add_return(int i, atomic_t *v)
> +{
> +	int __i;
> +#ifdef CONFIG_M386
> +	if(unlikely(boot_cpu_data.x86==3))
> +		goto no_xadd;
> +#endif
> +	/* Modern 486+ processor */
> +	__i = i;
> +	__asm__ __volatile__(
> +		LOCK "xaddl %0, %1;"
> +		:"=r"(i)
> +		:"m"(v->counter), "0"(i));
> +	return i + __i;
> +
> +#ifdef CONFIG_M386
> +no_xadd: /* Legacy 386 processor */
> +	local_irq_disable();
> +	__i = atomic_read(v);
> +	atomic_set(v, i + __i);
> +	local_irq_enable();
> +	return i + __i;
> +#endif
> +}
> +
> +static __inline__ int atomic_sub_return(int i, atomic_t *v)
> +{
> +	return atomic_add_return(-i,v);
> +}
> +
> +#define atomic_inc_return(v)  (atomic_add_return(1,v))
> +#define atomic_dec_return(v)  (atomic_sub_return(1,v))
> +
>  /* These are x86-specific, used by some header files */
>  #define atomic_clear_mask(mask, addr) \
>  __asm__ __volatile__(LOCK "andl %0,%1" \
>  : : "r" (~(mask)),"m" (*addr) : "memory")

  parent reply	other threads:[~2004-09-11 23:07 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <Pine.LNX.4.44.0409092005430.14004-100000@localhost.localdomain>
2004-09-10  3:26 ` Kaigai Kohei
2004-09-10  5:34   ` Chris Wedgwood
2004-09-11 23:05   ` Andrew Morton [this message]
2004-09-12  8:25     ` Andi Kleen
2004-09-12  9:06       ` Andrew Morton
2004-09-10  3:27 ` [PATCH] atomic_inc_return() for x86_64[2/5] " Kaigai Kohei
2004-09-10  3:29 ` [PATCH] atomic_inc_return() for arm[3/5] " Kaigai Kohei
2004-09-10  3:30 ` [PATCH] atomic_inc_return() for arm26[1/5] " Kaigai Kohei
2004-09-10  3:32 ` [PATCH] atomic_inc_return() for sparc64[5/5] " Kaigai Kohei
2004-09-10  5:26   ` David S. Miller
2004-09-10  4:05 ` PATCH] atomic_inc_return() [0/5] " Kaigai Kohei
2004-09-10  6:37   ` Hugh Dickins

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=20040911160532.07216174.akpm@osdl.org \
    --to=akpm@osdl.org \
    --cc=ak@muc.de \
    --cc=hugh@veritas.com \
    --cc=kaigai@ak.jp.nec.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=takata.hirokazu@renesas.com \
    --cc=wli@holomorphy.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

all inboxes | Powered by JetHome®