* [PATCH] x86-64: reduce SMP locks table size
@ 2010-04-21 15:08 Jan Beulich
2010-04-29 0:17 ` H. Peter Anvin
2010-04-29 0:55 ` [tip:x86/asm] x86-64: Reduce " tip-bot for Jan Beulich
0 siblings, 2 replies; 3+ messages in thread
From: Jan Beulich @ 2010-04-21 15:08 UTC (permalink / raw)
To: mingo, tglx, hpa; +Cc: linux-kernel
... by using relative pointers instead of absolute ones, thus cutting
the table size by half.
Signed-off-by: Jan Beulich <jbeulich@novell.com>
---
arch/x86/include/asm/alternative-asm.h | 4 +-
arch/x86/include/asm/alternative.h | 4 +-
arch/x86/kernel/alternative.c | 45 ++++++++++++++++++---------------
3 files changed, 29 insertions(+), 24 deletions(-)
--- linux-2.6.34-rc5/arch/x86/include/asm/alternative-asm.h 2010-02-24 19:52:17.000000000 +0100
+++ 2.6.34-rc5-x86_64-smp-locks-reduce-size/arch/x86/include/asm/alternative-asm.h 2010-04-15 11:58:18.000000000 +0200
@@ -6,8 +6,8 @@
.macro LOCK_PREFIX
1: lock
.section .smp_locks,"a"
- _ASM_ALIGN
- _ASM_PTR 1b
+ .balign 4
+ .long 1b - .
.previous
.endm
#else
--- linux-2.6.34-rc5/arch/x86/include/asm/alternative.h 2010-04-20 16:07:30.000000000 +0200
+++ 2.6.34-rc5-x86_64-smp-locks-reduce-size/arch/x86/include/asm/alternative.h 2010-04-15 11:58:18.000000000 +0200
@@ -30,8 +30,8 @@
#ifdef CONFIG_SMP
#define LOCK_PREFIX \
".section .smp_locks,\"a\"\n" \
- _ASM_ALIGN "\n" \
- _ASM_PTR "661f\n" /* address */ \
+ ".balign 4\n" \
+ ".long 661f - .\n" /* offset */ \
".previous\n" \
"661:\n\tlock; "
--- linux-2.6.34-rc5/arch/x86/kernel/alternative.c 2010-04-20 16:07:31.000000000 +0200
+++ 2.6.34-rc5-x86_64-smp-locks-reduce-size/arch/x86/kernel/alternative.c 2010-04-15 11:58:18.000000000 +0200
@@ -194,7 +194,7 @@ static void __init_or_module add_nops(vo
}
extern struct alt_instr __alt_instructions[], __alt_instructions_end[];
-extern u8 *__smp_locks[], *__smp_locks_end[];
+extern s32 __smp_locks[], __smp_locks_end[];
static void *text_poke_early(void *addr, const void *opcode, size_t len);
/* Replace instructions with better alternatives for this CPU type.
@@ -235,37 +235,39 @@ void __init_or_module apply_alternatives
#ifdef CONFIG_SMP
-static void alternatives_smp_lock(u8 **start, u8 **end, u8 *text, u8 *text_end)
+static void alternatives_smp_lock(const s32 *start, const s32 *end,
+ u8 *text, u8 *text_end)
{
- u8 **ptr;
+ const s32 *poff;
mutex_lock(&text_mutex);
- for (ptr = start; ptr < end; ptr++) {
- if (*ptr < text)
- continue;
- if (*ptr > text_end)
+ for (poff = start; poff < end; poff++) {
+ u8 *ptr = (u8 *)poff + *poff;
+
+ if (!*poff || ptr < text || ptr >= text_end)
continue;
/* turn DS segment override prefix into lock prefix */
- text_poke(*ptr, ((unsigned char []){0xf0}), 1);
+ text_poke(ptr, ((unsigned char []){0xf0}), 1);
};
mutex_unlock(&text_mutex);
}
-static void alternatives_smp_unlock(u8 **start, u8 **end, u8 *text, u8 *text_end)
+static void alternatives_smp_unlock(const s32 *start, const s32 *end,
+ u8 *text, u8 *text_end)
{
- u8 **ptr;
+ const s32 *poff;
if (noreplace_smp)
return;
mutex_lock(&text_mutex);
- for (ptr = start; ptr < end; ptr++) {
- if (*ptr < text)
- continue;
- if (*ptr > text_end)
+ for (poff = start; poff < end; poff++) {
+ u8 *ptr = (u8 *)poff + *poff;
+
+ if (!*poff || ptr < text || ptr >= text_end)
continue;
/* turn lock prefix into DS segment override prefix */
- text_poke(*ptr, ((unsigned char []){0x3E}), 1);
+ text_poke(ptr, ((unsigned char []){0x3E}), 1);
};
mutex_unlock(&text_mutex);
}
@@ -276,8 +278,8 @@ struct smp_alt_module {
char *name;
/* ptrs to lock prefixes */
- u8 **locks;
- u8 **locks_end;
+ const s32 *locks;
+ const s32 *locks_end;
/* .text segment, needed to avoid patching init code ;) */
u8 *text;
@@ -398,16 +400,19 @@ void alternatives_smp_switch(int smp)
int alternatives_text_reserved(void *start, void *end)
{
struct smp_alt_module *mod;
- u8 **ptr;
+ const s32 *poff;
u8 *text_start = start;
u8 *text_end = end;
list_for_each_entry(mod, &smp_alt_modules, next) {
if (mod->text > text_end || mod->text_end < text_start)
continue;
- for (ptr = mod->locks; ptr < mod->locks_end; ptr++)
- if (text_start <= *ptr && text_end >= *ptr)
+ for (poff = mod->locks; poff < mod->locks_end; poff++) {
+ const u8 *ptr = (const u8 *)poff + *poff;
+
+ if (text_start <= ptr && text_end > ptr)
return 1;
+ }
}
return 0;
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] x86-64: reduce SMP locks table size
2010-04-21 15:08 [PATCH] x86-64: reduce SMP locks table size Jan Beulich
@ 2010-04-29 0:17 ` H. Peter Anvin
2010-04-29 0:55 ` [tip:x86/asm] x86-64: Reduce " tip-bot for Jan Beulich
1 sibling, 0 replies; 3+ messages in thread
From: H. Peter Anvin @ 2010-04-29 0:17 UTC (permalink / raw)
To: Jan Beulich; +Cc: mingo, tglx, linux-kernel
On 04/21/2010 08:08 AM, Jan Beulich wrote:
> ... by using relative pointers instead of absolute ones, thus cutting
> the table size by half.
>
> Signed-off-by: Jan Beulich <jbeulich@novell.com>
We probably could use something like this for the alternatives and
exceptions tables, too...
-hpa
^ permalink raw reply [flat|nested] 3+ messages in thread
* [tip:x86/asm] x86-64: Reduce SMP locks table size
2010-04-21 15:08 [PATCH] x86-64: reduce SMP locks table size Jan Beulich
2010-04-29 0:17 ` H. Peter Anvin
@ 2010-04-29 0:55 ` tip-bot for Jan Beulich
1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Jan Beulich @ 2010-04-29 0:55 UTC (permalink / raw)
To: linux-tip-commits; +Cc: linux-kernel, hpa, mingo, jbeulich, JBeulich, tglx
Commit-ID: 5967ed87ade85a421ef814296c3c7f182b08c225
Gitweb: http://git.kernel.org/tip/5967ed87ade85a421ef814296c3c7f182b08c225
Author: Jan Beulich <JBeulich@novell.com>
AuthorDate: Wed, 21 Apr 2010 16:08:14 +0100
Committer: H. Peter Anvin <hpa@zytor.com>
CommitDate: Wed, 28 Apr 2010 17:15:47 -0700
x86-64: Reduce SMP locks table size
Reduce the SMP locks table size by using relative pointers instead of
absolute ones, thus cutting the table size by half.
Signed-off-by: Jan Beulich <jbeulich@novell.com>
LKML-Reference: <4BCF30FE020000780003B3B6@vpn.id2.novell.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
---
arch/x86/include/asm/alternative-asm.h | 4 +-
arch/x86/include/asm/alternative.h | 4 +-
arch/x86/kernel/alternative.c | 45 +++++++++++++++++--------------
3 files changed, 29 insertions(+), 24 deletions(-)
diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
index b97f786..a63a68b 100644
--- a/arch/x86/include/asm/alternative-asm.h
+++ b/arch/x86/include/asm/alternative-asm.h
@@ -6,8 +6,8 @@
.macro LOCK_PREFIX
1: lock
.section .smp_locks,"a"
- _ASM_ALIGN
- _ASM_PTR 1b
+ .balign 4
+ .long 1b - .
.previous
.endm
#else
diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
index b09ec55..714bf24 100644
--- a/arch/x86/include/asm/alternative.h
+++ b/arch/x86/include/asm/alternative.h
@@ -30,8 +30,8 @@
#ifdef CONFIG_SMP
#define LOCK_PREFIX \
".section .smp_locks,\"a\"\n" \
- _ASM_ALIGN "\n" \
- _ASM_PTR "661f\n" /* address */ \
+ ".balign 4\n" \
+ ".long 661f - .\n" /* offset */ \
".previous\n" \
"661:\n\tlock; "
diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
index 1a160d5..9367384 100644
--- a/arch/x86/kernel/alternative.c
+++ b/arch/x86/kernel/alternative.c
@@ -194,7 +194,7 @@ static void __init_or_module add_nops(void *insns, unsigned int len)
}
extern struct alt_instr __alt_instructions[], __alt_instructions_end[];
-extern u8 *__smp_locks[], *__smp_locks_end[];
+extern s32 __smp_locks[], __smp_locks_end[];
static void *text_poke_early(void *addr, const void *opcode, size_t len);
/* Replace instructions with better alternatives for this CPU type.
@@ -235,37 +235,39 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
#ifdef CONFIG_SMP
-static void alternatives_smp_lock(u8 **start, u8 **end, u8 *text, u8 *text_end)
+static void alternatives_smp_lock(const s32 *start, const s32 *end,
+ u8 *text, u8 *text_end)
{
- u8 **ptr;
+ const s32 *poff;
mutex_lock(&text_mutex);
- for (ptr = start; ptr < end; ptr++) {
- if (*ptr < text)
- continue;
- if (*ptr > text_end)
+ for (poff = start; poff < end; poff++) {
+ u8 *ptr = (u8 *)poff + *poff;
+
+ if (!*poff || ptr < text || ptr >= text_end)
continue;
/* turn DS segment override prefix into lock prefix */
- text_poke(*ptr, ((unsigned char []){0xf0}), 1);
+ text_poke(ptr, ((unsigned char []){0xf0}), 1);
};
mutex_unlock(&text_mutex);
}
-static void alternatives_smp_unlock(u8 **start, u8 **end, u8 *text, u8 *text_end)
+static void alternatives_smp_unlock(const s32 *start, const s32 *end,
+ u8 *text, u8 *text_end)
{
- u8 **ptr;
+ const s32 *poff;
if (noreplace_smp)
return;
mutex_lock(&text_mutex);
- for (ptr = start; ptr < end; ptr++) {
- if (*ptr < text)
- continue;
- if (*ptr > text_end)
+ for (poff = start; poff < end; poff++) {
+ u8 *ptr = (u8 *)poff + *poff;
+
+ if (!*poff || ptr < text || ptr >= text_end)
continue;
/* turn lock prefix into DS segment override prefix */
- text_poke(*ptr, ((unsigned char []){0x3E}), 1);
+ text_poke(ptr, ((unsigned char []){0x3E}), 1);
};
mutex_unlock(&text_mutex);
}
@@ -276,8 +278,8 @@ struct smp_alt_module {
char *name;
/* ptrs to lock prefixes */
- u8 **locks;
- u8 **locks_end;
+ const s32 *locks;
+ const s32 *locks_end;
/* .text segment, needed to avoid patching init code ;) */
u8 *text;
@@ -398,16 +400,19 @@ void alternatives_smp_switch(int smp)
int alternatives_text_reserved(void *start, void *end)
{
struct smp_alt_module *mod;
- u8 **ptr;
+ const s32 *poff;
u8 *text_start = start;
u8 *text_end = end;
list_for_each_entry(mod, &smp_alt_modules, next) {
if (mod->text > text_end || mod->text_end < text_start)
continue;
- for (ptr = mod->locks; ptr < mod->locks_end; ptr++)
- if (text_start <= *ptr && text_end >= *ptr)
+ for (poff = mod->locks; poff < mod->locks_end; poff++) {
+ const u8 *ptr = (const u8 *)poff + *poff;
+
+ if (text_start <= ptr && text_end > ptr)
return 1;
+ }
}
return 0;
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-04-29 0:55 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-21 15:08 [PATCH] x86-64: reduce SMP locks table size Jan Beulich
2010-04-29 0:17 ` H. Peter Anvin
2010-04-29 0:55 ` [tip:x86/asm] x86-64: Reduce " tip-bot for Jan Beulich
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox