linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Maksym Planeta <mcsim.planeta@gmail.com>
To: tglx@linutronix.de
Cc: kernel-janitors@vger.kernel.org, mingo@redhat.com,
	linux-kernel@vger.kernel.org,
	Maksym Planeta <mcsim.planeta@gmail.com>
Subject: [PATCH] x86: page: get_order() optimization
Date: Sat, 19 Mar 2011 18:25:47 +0200	[thread overview]
Message-ID: <1300551947-22279-1-git-send-email-mcsim.planeta@gmail.com> (raw)

For x86 architecture get_order function can be optimized due to
assembler instruction bsr.

I'm sorry. I've forgot about Signed-off, so the same, but with the sign.

Signed-off-by: Maksym Planeta <mcsim.planeta@gmail.com>
---
 arch/x86/include/asm/page.h |   20 +++++++++++++++++++-
 1 files changed, 19 insertions(+), 1 deletions(-)

diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
index 8ca8283..339ae26 100644
--- a/arch/x86/include/asm/page.h
+++ b/arch/x86/include/asm/page.h
@@ -60,10 +60,28 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
 extern bool __virt_addr_valid(unsigned long kaddr);
 #define virt_addr_valid(kaddr)	__virt_addr_valid((unsigned long) (kaddr))
 
+/* Pure 2^n version of get_order */
+static inline __attribute_const__ int get_order(unsigned long size)
+{
+	int order;
+
+	size = (size - 1) >> (PAGE_SHIFT - 1);
+#ifdef CONFIG_X86_CMOV
+	asm("bsr %1,%0\n\t"
+	    "cmovzl %2,%0"
+	    : "=&r" (order) : "rm" (size), "rm" (0));
+#else
+	asm("bsr %1,%0\n\t"
+	    "jnz 1f\n\t"
+	    "movl $0,%0\n"
+	    "1:" : "=r" (order) : "rm" (size));
+#endif
+	return order;
+}
+
 #endif	/* __ASSEMBLY__ */
 
 #include <asm-generic/memory_model.h>
-#include <asm-generic/getorder.h>
 
 #define __HAVE_ARCH_GATE_AREA 1
 
-- 
1.7.2.3


             reply	other threads:[~2011-03-19 16:32 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-19 16:25 Maksym Planeta [this message]
2011-03-23 10:07 ` [PATCH] x86: page: get_order() optimization Ingo Molnar
2011-03-27  8:57   ` Maksym Planeta
  -- strict thread matches above, loose matches on Subject: below --
2011-03-19 16:08 Maksym Planeta

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=1300551947-22279-1-git-send-email-mcsim.planeta@gmail.com \
    --to=mcsim.planeta@gmail.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --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;
as well as URLs for NNTP newsgroup(s).