public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Anton Blanchard <anton@samba.org>
To: Manfred Spraul <manfred@colorfullife.com>
Cc: "David S. Miller" <davem@redhat.com>,
	jakub@redhat.com, bcrl@redhat.com, torvalds@transmeta.com,
	alan@lxorguk.ukuu.org.uk, arjanv@redhat.com,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] take 2 of the tr-based current
Date: Sun, 11 Nov 2001 23:36:11 +1100	[thread overview]
Message-ID: <20011111233611.A7409@krispykreme> (raw)
In-Reply-To: <20011108211143.A4797@redhat.com> <20011109041327.T4087@devserv.devel.redhat.com> <3BEBEE0B.BA1FD7EE@colorfullife.com> <20011109.070312.88700201.davem@redhat.com> <3BEBF730.86CAE1CC@colorfullife.com> <20011111110107.A4064@krispykreme> <3BEE4C04.4040406@colorfullife.com>
In-Reply-To: <3BEE4C04.4040406@colorfullife.com>


Hi,

> But the function called schedule - mustn't gcc assume that schedule 
> writes into global variables?
> As far as I can see that sounds like a gcc bug.

Yes gcc knows we need to reload across a function call, but it also
knows that the get_cpu function uses no global variables.

> Could you try how many get_cpu calls are generated by the attached testapp?

I changed the code a bit so that get_cpu() is now inline - this
represents our situation better. I think it is valid for gcc to cache
get_cpu across a function call in the below example because it knows
that get_cpu does not refer to any global variables.

I brought it up in case gcc optimises your get_tr the same way (I cant
remember what the operand constraints on it were now, if it was only a
register then you might see it).

(The disassembly of the below has only one mfspr and it caches the
result across schedule).

Anton

int cpu;

static void schedule(void);

static inline int get_cpu(void) __attribute__((pure));
static inline int get_cpu(void)
{
	int ret;
	__asm__ ("mfspr %0, 0x113"
			: "=r" (ret)
			:);

	return ret;
}

int main(void)
{
	int cpu1, cpu2, cpu3, cpu4;
	cpu1 = get_cpu();
	cpu2 = get_cpu();
	schedule();
	cpu3 = get_cpu();
	cpu4 = get_cpu();
	printf("the cpu values were %d %d %d %d.\n",
		cpu1, cpu2, cpu3, cpu4);
	return 0;
}

static void schedule(void)
{
	cpu = 2;
	printf("schedule called .\n");
}

  reply	other threads:[~2001-11-11 12:41 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20011108190546.A29741@redhat.com>
2001-11-09  2:11 ` [PATCH] take 2 of the tr-based current Benjamin LaHaise
2001-11-09  9:13   ` Jakub Jelinek
2001-11-09 14:54     ` Manfred Spraul
2001-11-09 15:03       ` David S. Miller
2001-11-09 15:33         ` Manfred Spraul
2001-11-09 16:01           ` Richard B. Johnson
2001-11-11  0:01           ` Anton Blanchard
2001-11-11  1:01             ` Benjamin LaHaise
2001-11-11  2:27               ` Anton Blanchard
2001-11-11  9:59             ` Manfred Spraul
2001-11-11 12:36               ` Anton Blanchard [this message]
2001-11-11 14:02                 ` Manfred Spraul
2001-11-12  3:32                   ` Benjamin LaHaise

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=20011111233611.A7409@krispykreme \
    --to=anton@samba.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=arjanv@redhat.com \
    --cc=bcrl@redhat.com \
    --cc=davem@redhat.com \
    --cc=jakub@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=manfred@colorfullife.com \
    --cc=torvalds@transmeta.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