lkml.org 
[lkml]   [2012]   [Jul]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] x86/mce: Need to let kill_proc() send signal to doomed process
On Tue, Jul 10, 2012 at 10:12:17AM -0700, Tony Luck wrote:
> On Tue, Jul 10, 2012 at 8:44 AM, Borislav Petkov <bp@amd64.org> wrote:
> > Acked-by: Borislav Petkov <borislav.petkov@amd.com>
>
> Thanks for the Ack.
>
> + doit = !!PageDirty(ppage) || !!(flags & MF_MUST_KILL);
>
> Thinking about this some more, the "!!" are redundant
> and are an impediment to readability. We started with
> !!PageDirty(ppage) when we were passing an argument
> directly to kill_procs() and wanted to make sure we had a
> nice boolean value. But the result of the "||" is boolean,
> so we don't need to double negate.
>
> I'm going to change it to:
> doit = PageDirty(ppage) || (flags & MF_MUST_KILL);

Ok, so out of curiosity I took a look at compiler output and both
versions are identical:


> + doit = !!PageDirty(ppage) || !!(flags & MF_MUST_KILL);

.loc 1 974 0
movl $1, %edx #, doit
testb $16, %al #, D.28886
jne .L196 #,
movl -196(%rbp), %ecx # %sfp,
xorl %edx, %edx # doit
testl %ecx, %ecx #
setne %dl #, doit

> doit = PageDirty(ppage) || (flags & MF_MUST_KILL);

.loc 1 974 0
movl $1, %edx #, doit
testb $16, %al #, D.28886
jne .L196 #,
movl -196(%rbp), %ecx # %sfp,
xorl %edx, %edx # doit
testl %ecx, %ecx #
setne %dl #, doit

In both cases you get your standard shortcutting OR logic:

.loc 1 974 0
movl $1, %edx #, doit <--- preset doit
testb $16, %al #, D.28886 <--- PG_dirty
jne .L196 #, <--- ZF=0, shortcut out to kill_procs
movl -196(%rbp), %ecx # %sfp, <--- get value of (flags & MF_MUST_KILL) which we computed earlier in the function and saved on stack
xorl %edx, %edx # doit <--- clear doit
testl %ecx, %ecx # <--- check above (flags & MF_MUST_KILL) is not 0
setne %dl #, doit <--- prep doit for kill_procs

so the compiler is pretty smart already.

You could go another step further by declaring

bool doit;

and changing kill_procs() argument to bool too so that the booleanness
is really explicit.

This saves you the xor:

.loc 1 975 0
movl $1, %edx #, prephitmp.124
testb $16, %al #, D.28891
jne .L196 #,
movl -196(%rbp), %ecx # %sfp,
testl %ecx, %ecx #
setne %dl #, prephitmp.124

because we're using explicitly bools which are u8s, apparently, in this
case and we're reusing the 1 we wrote into edx at the beginning of the
block.

Oh well, enough fun.

--
Regards/Gruss,
Boris.

Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach
GM: Alberto Bozzo
Reg: Dornach, Landkreis Muenchen
HRB Nr. 43632 WEEE Registernr: 129 19551


\
 
 \ /
  Last update: 2012-07-10 21:21    [W:0.088 / U:0.084 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site