* [patch 2.6.13-rc3] i386: clean up user_mode macros
@ 2005-07-25 22:59 Chuck Ebbert
2005-07-25 23:13 ` Linus Torvalds
0 siblings, 1 reply; 8+ messages in thread
From: Chuck Ebbert @ 2005-07-25 22:59 UTC (permalink / raw)
To: linux-kernel; +Cc: Andrew Morton, Linus Torvalds, Vincent Hanquez, Andi Kleen
Recent patches from the Xen group changed the X86 user_mode macros.
This patch does the following:
1. Makes the new user_mode() return 0 or 1 (same as x86_64)
2. Removes conditional jump from user_mode_vm()
(it's called every timer tick on each CPU on SMP)
I've been running this patch for a while now. Please apply.
Signed-off-by: Chuck Ebbert <76306.1226@compuserve.com>
Index: 2.6.13-rc3a/include/asm-i386/ptrace.h
===================================================================
--- 2.6.13-rc3a.orig/include/asm-i386/ptrace.h 2005-07-13 16:20:26.000000000 -0400
+++ 2.6.13-rc3a/include/asm-i386/ptrace.h 2005-07-14 02:47:51.000000000 -0400
@@ -57,8 +57,8 @@
#ifdef __KERNEL__
struct task_struct;
extern void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs, int error_code);
-#define user_mode(regs) (3 & (regs)->xcs)
-#define user_mode_vm(regs) ((VM_MASK & (regs)->eflags) || user_mode(regs))
+#define user_mode(regs) (!!(3 & (regs)->xcs))
+#define user_mode_vm(regs) (!!((VM_MASK & (regs)->eflags) | (3 & (regs)->xcs)))
#define instruction_pointer(regs) ((regs)->eip)
#if defined(CONFIG_SMP) && defined(CONFIG_FRAME_POINTER)
extern unsigned long profile_pc(struct pt_regs *regs);
__
Chuck
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [patch 2.6.13-rc3] i386: clean up user_mode macros
2005-07-25 22:59 [patch 2.6.13-rc3] i386: clean up user_mode macros Chuck Ebbert
@ 2005-07-25 23:13 ` Linus Torvalds
2005-07-26 0:20 ` Steven Rostedt
2005-07-26 1:28 ` Miles Bader
0 siblings, 2 replies; 8+ messages in thread
From: Linus Torvalds @ 2005-07-25 23:13 UTC (permalink / raw)
To: Chuck Ebbert; +Cc: linux-kernel, Andrew Morton, Vincent Hanquez, Andi Kleen
On Mon, 25 Jul 2005, Chuck Ebbert wrote:
>
> Recent patches from the Xen group changed the X86 user_mode macros.
>
> This patch does the following:
>
> 1. Makes the new user_mode() return 0 or 1 (same as x86_64)
I _really_ prefer
x != 0
over
!!x
since double negation is not only a bad habit in natural languages, it's a
bad habit in computer languages too, for exactly the same reason. It's
confusing.
Ask a hundred random C programmers what "!!x" means, versus what "x != 0"
means, and time their replies.
I will bet you $5 USD that even if they all give the right answer (and I
suspect you'll get a few wrogn answers in there too for the !! case),
they'll take a _lot_ longer answering the "!!x" version than they will the
"x != 0" question.
And guess what? That means that the "!!x" version is worse. It means that
people don't "see" what it means - they have to think about it. And you
shouldn't have to think about something like that, you should write it in
the obvious way in the first place.
Linus
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [patch 2.6.13-rc3] i386: clean up user_mode macros
2005-07-25 23:13 ` Linus Torvalds
@ 2005-07-26 0:20 ` Steven Rostedt
2005-07-26 2:45 ` Lee Revell
2005-07-26 1:28 ` Miles Bader
1 sibling, 1 reply; 8+ messages in thread
From: Steven Rostedt @ 2005-07-26 0:20 UTC (permalink / raw)
To: Linus Torvalds
Cc: Andi Kleen, Vincent Hanquez, Andrew Morton, linux-kernel, Chuck Ebbert
On Mon, 2005-07-25 at 16:13 -0700, Linus Torvalds wrote:
> I _really_ prefer
>
> x != 0
>
> over
>
> !!x
Good to hear. This means that you should have no problem accepting my
previous patch for signal.c that changed the x ^ y to x != y. And I
would also assume that you prefer x *= 2 over x <<= 1 (also since the
first person to show this example used x <<= 2. Right Lee? :-)
-- Steve
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [patch 2.6.13-rc3] i386: clean up user_mode macros
2005-07-26 0:20 ` Steven Rostedt
@ 2005-07-26 2:45 ` Lee Revell
0 siblings, 0 replies; 8+ messages in thread
From: Lee Revell @ 2005-07-26 2:45 UTC (permalink / raw)
To: Steven Rostedt
Cc: Linus Torvalds, Andi Kleen, Vincent Hanquez, Andrew Morton,
linux-kernel, Chuck Ebbert
On Mon, 2005-07-25 at 20:20 -0400, Steven Rostedt wrote:
> And I
> would also assume that you prefer x *= 2 over x <<= 1 (also since the
> first person to show this example used x <<= 2. Right Lee? :-)
Let us never speak of that again. These aren't the droids you're
looking for.
Lee
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [patch 2.6.13-rc3] i386: clean up user_mode macros
2005-07-25 23:13 ` Linus Torvalds
2005-07-26 0:20 ` Steven Rostedt
@ 2005-07-26 1:28 ` Miles Bader
2005-07-26 1:34 ` Andrew Morton
1 sibling, 1 reply; 8+ messages in thread
From: Miles Bader @ 2005-07-26 1:28 UTC (permalink / raw)
To: Linus Torvalds
Cc: Chuck Ebbert, linux-kernel, Andrew Morton, Vincent Hanquez, Andi Kleen
Linus Torvalds <torvalds@osdl.org> writes:
> Ask a hundred random C programmers what "!!x" means, versus what "x != 0"
> means, and time their replies.
I've always thought of "!!" as the "canonicalize boolean" operator...
Vaguely ugly, but I think it's actually _more clear_ than != 0 in
contexts where the value is already "boolean" in the C zero or not-zero
sense, but you want a "proper" boolean (0 or 1) for some reason.
-miles
--
Somebody has to do something, and it's just incredibly pathetic that it
has to be us. -- Jerry Garcia
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [patch 2.6.13-rc3] i386: clean up user_mode macros
2005-07-26 1:28 ` Miles Bader
@ 2005-07-26 1:34 ` Andrew Morton
2005-07-26 2:31 ` randy_dunlap
0 siblings, 1 reply; 8+ messages in thread
From: Andrew Morton @ 2005-07-26 1:34 UTC (permalink / raw)
To: Miles Bader
Cc: miles, torvalds, 76306.1226, linux-kernel, vincent.hanquez, ak
Miles Bader <miles@lsi.nec.co.jp> wrote:
>
> Linus Torvalds <torvalds@osdl.org> writes:
> > Ask a hundred random C programmers what "!!x" means, versus what "x != 0"
> > means, and time their replies.
>
> I've always thought of "!!" as the "canonicalize boolean" operator...
Me too. Once you get used to it, it's just the "convert non-zero to 1"
operator.
But whatever.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [patch 2.6.13-rc3] i386: clean up user_mode macros
2005-07-26 1:34 ` Andrew Morton
@ 2005-07-26 2:31 ` randy_dunlap
0 siblings, 0 replies; 8+ messages in thread
From: randy_dunlap @ 2005-07-26 2:31 UTC (permalink / raw)
To: Andrew Morton
Cc: miles, miles, torvalds, 76306.1226, linux-kernel, vincent.hanquez, ak
On Mon, 25 Jul 2005 18:34:13 -0700 Andrew Morton wrote:
> Miles Bader <miles@lsi.nec.co.jp> wrote:
> >
> > Linus Torvalds <torvalds@osdl.org> writes:
> > > Ask a hundred random C programmers what "!!x" means, versus what "x != 0"
> > > means, and time their replies.
> >
> > I've always thought of "!!" as the "canonicalize boolean" operator...
>
> Me too. Once you get used to it, it's just the "convert non-zero to 1"
> operator.
>
> But whatever.
I call it "truth value" (true or false), but once I got used to it,
I thought it was OK too.
---
~Randy
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [patch 2.6.13-rc3] i386: clean up user_mode macros
@ 2005-07-27 1:57 Chuck Ebbert
0 siblings, 0 replies; 8+ messages in thread
From: Chuck Ebbert @ 2005-07-27 1:57 UTC (permalink / raw)
To: Linus Torvalds; +Cc: Andi Kleen, Vincent Hanquez, Andrew Morton, linux-kernel
On Mon, 25 Jul 2005 at 16:13:13 -0700 (PDT), Linus Torvalds wrote:
> On Mon, 25 Jul 2005, Chuck Ebbert wrote:
> >
> > Recent patches from the Xen group changed the X86 user_mode macros.
> >
> > This patch does the following:
> >
> > 1. Makes the new user_mode() return 0 or 1 (same as x86_64)
>
> I _really_ prefer
>
> x != 0
>
> over
>
> !!x
Take 2: compile tested only.
Signed-off-by: Chuck Ebbert <76306.1226@compuserve.com>
===================================================================
--- 2.6.13-rc3.orig/include/asm-i386/ptrace.h
+++ 2.6.13-rc3/include/asm-i386/ptrace.h
@@ -57,14 +57,21 @@
#ifdef __KERNEL__
struct task_struct;
extern void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs, int error_code);
-#define user_mode(regs) (3 & (regs)->xcs)
-#define user_mode_vm(regs) ((VM_MASK & (regs)->eflags) || user_mode(regs))
+
+static inline int user_mode(struct pt_regs *regs)
+{
+ return (regs->xcs & 3) != 0;
+}
+static inline int user_mode_vm(struct pt_regs *regs)
+{
+ return ((regs->xcs & 3) | (regs->eflags & VM_MASK)) != 0;
+}
#define instruction_pointer(regs) ((regs)->eip)
#if defined(CONFIG_SMP) && defined(CONFIG_FRAME_POINTER)
extern unsigned long profile_pc(struct pt_regs *regs);
#else
#define profile_pc(regs) instruction_pointer(regs)
#endif
-#endif
+#endif /* __KERNEL__ */
#endif
__
Chuck
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2005-07-27 2:00 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-25 22:59 [patch 2.6.13-rc3] i386: clean up user_mode macros Chuck Ebbert
2005-07-25 23:13 ` Linus Torvalds
2005-07-26 0:20 ` Steven Rostedt
2005-07-26 2:45 ` Lee Revell
2005-07-26 1:28 ` Miles Bader
2005-07-26 1:34 ` Andrew Morton
2005-07-26 2:31 ` randy_dunlap
2005-07-27 1:57 Chuck Ebbert
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).