All of lore.kernel.org
 help / color / mirror / Atom feed
From: Benjamin LaHaise <bcrl@redhat.com>
To: Linus Torvalds <torvalds@transmeta.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: Using %cr2 to reference "current"
Date: Tue, 6 Nov 2001 13:42:34 -0500	[thread overview]
Message-ID: <20011106134234.A27718@redhat.com> (raw)
In-Reply-To: <20011106121313.B16245@redhat.com> <Pine.LNX.4.33.0111060918380.2194-100000@penguin.transmeta.com>
In-Reply-To: <Pine.LNX.4.33.0111060918380.2194-100000@penguin.transmeta.com>; from torvalds@transmeta.com on Tue, Nov 06, 2001 at 09:49:15AM -0800

On Tue, Nov 06, 2001 at 09:49:15AM -0800, Linus Torvalds wrote:
> That said, how expensive is loading %cr2 anyway? We can do all the same
> tricks with a 16kB stack and just playing games with using the higher bits
> as the "offset", ie things like

Here are some numbers:

read cr2 best: 11  av: 11.12
write cr2 cr2 best: 61  av: 64.42
read cr2 best: 11  av: 11.12
write cr2 cr2 best: 61  av: 65.01
read stk best: 10  av: 11.03
write cr2 stk best: 61  av: 64.95
read stk best: 10  av: 11.03
write cr2 stk best: 61  av: 65.23

Which come from insmod of the below two modules.  I didn't test writing to 
the stack register, but I expect it's similarly expensive as it affects the 
call return stack and other behind the scenes dependancies.  Suffice it to 
say that reading %cr2 is essentially free on my box (athlon mp).  Maybe 
we should use it as a pointer into a per-cpu area to avoid writing it?

		-ben

----teststk_k.c----
#define USE_STK 1
#include "testcr2_k.c"
----testcr2_k.c----
#include <linux/module.h>
#include <linux/kernel.h>
#include <asm/errno.h>
#include <linux/init.h>

static inline long long rdtsc(void)
{
        unsigned int low,high;
        __asm__ __volatile__("rdtsc" : "=a" (low), "=d" (high));
        return low + (((long long)high)<<32);
}

long dummy;

long doit(void)
{
	long long start, end;
	long val;

	start = rdtsc();
#ifdef USE_STK
#define WHICH	"stk"
	__asm__ __volatile__(
                "movl $0x0003c000,%%eax  \n" // 4 bits at bit 14
                "movl $-16384,%%edx      \n" // remove low 14 bits
                "andl %%esp,%%eax		\n"
                "andl %%esp,%%edx		\n"
                "shrl $7,%%eax           \n" // color it by 128 bytes
                "addl %%edx,%%eax		\n"
		: "=a" (val) :: "edx");
#else
#define WHICH "cr2"
        __asm__ __volatile__("movl %%cr2,%0" : "=r" (val));
#endif
	val += 100;
	dummy = val;
	end = rdtsc();

	return end - start;
}

long doit2(void)
{
	long long start, end;
	long val;

	start = rdtsc();
	val = dummy;
        __asm__ __volatile__("movl %0,%%cr2" : "=r" (val));
	end = rdtsc();

	return end - start;
}

int test_init (void)
{
	long min = 1000000000, av = 0;
	int i;
	for (i=0; i<100; i++) {
		long dur = doit();
		if (dur < min)
			min = dur;
		av += dur;
	}
	printk("read " WHICH " best: %ld  av: %ld.%02ld\n", min, av / 100, av % 100);

	min = 10000000;
	av = 0;
	for (i=0; i<100; i++) {
		long dur = doit2();
		if (dur < min)
			min = dur;
		av += dur;
	}
	printk("write cr2 " WHICH " best: %ld  av: %ld.%02ld\n", min, av / 100, av % 100);
	return -ENODEV;
}

void test_exit(void)
{
	return;
}

module_init(test_init);
module_exit(test_exit);
MODULE_LICENSE("GPL");
---snip---

  parent reply	other threads:[~2001-11-06 18:43 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-11-06  7:18 Using %cr2 to reference "current" H. Peter Anvin
2001-11-06  8:01 ` Robert Love
2001-11-06 10:55   ` Alan Cox
2001-11-06 17:31     ` Michael Barabanov
2001-11-06 14:14   ` Manfred Spraul
2001-11-06 10:58 ` Alan Cox
2001-11-06 17:04   ` Linus Torvalds
2001-11-06 17:46     ` Alan Cox
2001-11-06 17:59       ` Linus Torvalds
2001-11-06 18:14         ` Alan Cox
2001-11-06 16:55           ` Marcelo Tosatti
2001-11-06 18:14           ` Linus Torvalds
2001-11-06 18:31             ` Alan Cox
2001-11-06 22:38               ` Linus Torvalds
2001-11-07  0:00           ` Martin Dalecki
2001-11-06 23:19             ` Alan Cox
2001-11-07  0:43               ` Martin Dalecki
2001-11-07  0:27                 ` Alan Cox
2001-11-07  0:35                 ` Jeff Garzik
2001-11-07 14:00               ` Martin Dalecki
2001-11-07 13:38                 ` Alan Cox
2001-11-07 14:59                   ` Martin Dalecki
2001-11-07 14:17                     ` Alan Cox
2001-11-07 14:34                       ` Dirk Moerenhout
2001-11-07 14:54                         ` Alan Cox
2001-11-07 15:32                           ` David Howells
2001-11-07 14:39                       ` Intel compiler [Re: Using %cr2 to reference "current"] Sebastian Heidl
2001-11-07 22:05                         ` lists
2001-11-07 15:36                       ` Using %cr2 to reference "current" Martin Dalecki
2001-11-08 14:08                       ` Martin Dalecki
2001-11-13 16:49                       ` Merge BUG in 2.4.15-pre4 serial.c Martin Dalecki
2001-11-13 16:21                         ` Russell King
2001-11-13 17:37                           ` Martin Dalecki
2001-11-13 16:53                             ` Russell King
2001-11-13 18:05                               ` Martin Dalecki
2001-11-13 17:11                             ` Alan Cox
2001-11-13 18:23                               ` Martin Dalecki
2001-11-07 20:04                   ` Using %cr2 to reference "current" Andrew Morton
2001-11-11 13:16                   ` Martin Dalecki
2001-11-11 13:06                     ` Keith Owens
2001-11-12 11:28                     ` PATCH 2.4.14 mregparm=3 compilation fixes Martin Dalecki
2001-11-12 16:10                       ` Keith Owens
2001-11-12 16:25                         ` Christoph Hellwig
2001-11-12 17:56                         ` Martin Dalecki
2001-11-12 16:42                       ` Linus Torvalds
2001-11-12 18:51                         ` Martin Dalecki
2001-11-12 20:05                           ` Corsspatch patch-2.4.15-pre2 patch-2.4.15-pre3 Martin Dalecki
2001-11-12 20:13                             ` BUG BUG hunt the bugs!!! patch-2.4.15-pre5 Martin Dalecki
2001-11-06 17:02 ` Using %cr2 to reference "current" Linus Torvalds
2001-11-06 17:13   ` Benjamin LaHaise
2001-11-06 17:49     ` Linus Torvalds
2001-11-06 18:19       ` Alan Cox
2001-11-09 21:52         ` Jamie Lokier
2001-11-06 18:42       ` Benjamin LaHaise [this message]
2001-11-06 19:09         ` H. Peter Anvin
2001-11-06 19:16         ` Dave Jones
2001-11-06 20:10           ` Ricky Beam
2001-11-06 23:09           ` Alan Cox
2001-11-06 23:15             ` Dave Jones
  -- strict thread matches above, loose matches on Subject: below --
2001-11-06 22:05 Mikael Pettersson
2002-11-10 21:23 Igor Levicki

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=20011106134234.A27718@redhat.com \
    --to=bcrl@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.