All of lore.kernel.org
 help / color / mirror / Atom feed
* Questions regarding BUG macro.
@ 2017-02-24 12:10 Varsha Rao
  2017-02-24 14:48 ` [Outreachy kernel] " Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: Varsha Rao @ 2017-02-24 12:10 UTC (permalink / raw)
  To: outreachy-kernel


[-- Attachment #1.1: Type: text/plain, Size: 441 bytes --]


What is the functionality of unreachable() ?
Isn't the do while loop unnecessary in the given definition ?

#define BUG()                                
    do {                                
        _BUG_OR_WARN(0);                    
        unreachable();                        
    } while (0)

Found the above definition at staging/arch/avr32/include/asm/bug.h 
Also what is the difference between unreachable() and unlikely()?



[-- Attachment #1.2: Type: text/html, Size: 607 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Outreachy kernel] Questions regarding BUG macro.
  2017-02-24 12:10 Questions regarding BUG macro Varsha Rao
@ 2017-02-24 14:48 ` Greg KH
  2017-02-24 18:24   ` Varsha Rao
  0 siblings, 1 reply; 4+ messages in thread
From: Greg KH @ 2017-02-24 14:48 UTC (permalink / raw)
  To: Varsha Rao; +Cc: outreachy-kernel

On Fri, Feb 24, 2017 at 04:10:30AM -0800, Varsha Rao wrote:
> 
> What is the functionality of unreachable() ?

It tells the compiler that it will never execute this.

> Isn't the do while loop unnecessary in the given definition ?

Not at all, why do you think it would be?

> #define BUG()��� ��� ��� ��� ��� ��� ��� ���
> ��� do {��� ��� ��� ��� ��� ��� ��� ���
> ��� ��� _BUG_OR_WARN(0);��� ��� ��� ��� ���
> ��� ��� unreachable();��� ��� ��� ��� ��� ���
> ��� } while (0)
> 
> Found the above definition at staging/arch/avr32/include/asm/bug.h
> Also what is the difference between unreachable() and unlikely()?

unlikely is a hint to the compiler that the statement vare rarely
happens.  unreachable tells the compiler that this code will never be
run, due to something stopping the CPU before it can happen.

Never use either of these in your code unless you really know what you
are doing.  Never use unlikely() unless you can measure the difference
of it being used and not being used, because almost always humans get it
wrong, CPUs are very good at guessing what should happen.

hope this helps,

greg k-h


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Outreachy kernel] Questions regarding BUG macro.
  2017-02-24 14:48 ` [Outreachy kernel] " Greg KH
@ 2017-02-24 18:24   ` Varsha Rao
  2017-02-24 18:29     ` Julia Lawall
  0 siblings, 1 reply; 4+ messages in thread
From: Varsha Rao @ 2017-02-24 18:24 UTC (permalink / raw)
  To: outreachy-kernel; +Cc: rvarsha016


[-- Attachment #1.1: Type: text/plain, Size: 1535 bytes --]



On Friday, February 24, 2017 at 8:18:17 PM UTC+5:30, gregkh wrote:
>
> On Fri, Feb 24, 2017 at 04:10:30AM -0800, Varsha Rao wrote: 
> > 
> > What is the functionality of unreachable() ? 
>
> It tells the compiler that it will never execute this. 
>
> > Isn't the do while loop unnecessary in the given definition ? 
>
> Not at all, why do you think it would be? 
>

   Since there are only two macro calls and no local variables are used, 
can't it be like this:
  
   #define BUG() (_BUG_OR_WARN(0), unreachable())

  I understand that  do while is used, when there are multiple statements. 
 

> > #define BUG()                                
> >     do {                                
> >         _BUG_OR_WARN(0);                    
> >         unreachable();                        
> >     } while (0) 
> > 
> > Found the above definition at staging/arch/avr32/include/asm/bug.h 
> > Also what is the difference between unreachable() and unlikely()? 
>
> unlikely is a hint to the compiler that the statement vare rarely 
> happens.  unreachable tells the compiler that this code will never be 
> run, due to something stopping the CPU before it can happen. 
>
> Never use either of these in your code unless you really know what you 
> are doing.  Never use unlikely() unless you can measure the difference 
> of it being used and not being used, because almost always humans get it 
> wrong, CPUs are very good at guessing what should happen. 
>
>     Thank you for the explanation.
 

> hope this helps, 
>
> greg k-h 
>

[-- Attachment #1.2: Type: text/html, Size: 2213 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Outreachy kernel] Questions regarding BUG macro.
  2017-02-24 18:24   ` Varsha Rao
@ 2017-02-24 18:29     ` Julia Lawall
  0 siblings, 0 replies; 4+ messages in thread
From: Julia Lawall @ 2017-02-24 18:29 UTC (permalink / raw)
  To: Varsha Rao; +Cc: outreachy-kernel

[-- Attachment #1: Type: text/plain, Size: 2604 bytes --]



On Fri, 24 Feb 2017, Varsha Rao wrote:

>
>
> On Friday, February 24, 2017 at 8:18:17 PM UTC+5:30, gregkh wrote:
>       On Fri, Feb 24, 2017 at 04:10:30AM -0800, Varsha Rao wrote:
>       >
>       > What is the functionality of unreachable() ?
>
>       It tells the compiler that it will never execute this.
>
>       > Isn't the do while loop unnecessary in the given definition ?
>
>       Not at all, why do you think it would be?
>
>
>    Since there are only two macro calls and no local variables are used,
> can't it be like this:
>  
>    #define BUG() (_BUG_OR_WARN(0), unreachable())

I think that this form of code is not common (or not used at all) in the
kernel.  It does not make the purpose very clear - it looks like it is
probably intended to be an argument list.

julia

>
>   I understand that  do while is used, when there are multiple statements.
>  
>       > #define BUG()                               
>       >     do {                               
>       >         _BUG_OR_WARN(0);                   
>       >         unreachable();                       
>       >     } while (0)
>       >
>       > Found the above definition at
>       staging/arch/avr32/include/asm/bug.h
>       > Also what is the difference between unreachable() and
>       unlikely()?
>
>       unlikely is a hint to the compiler that the statement vare
>       rarely
>       happens.  unreachable tells the compiler that this code will
>       never be
>       run, due to something stopping the CPU before it can happen.
>
>       Never use either of these in your code unless you really know
>       what you
>       are doing.  Never use unlikely() unless you can measure the
>       difference
>       of it being used and not being used, because almost always
>       humans get it
>       wrong, CPUs are very good at guessing what should happen.
>
>     Thank you for the explanation.
>  
>       hope this helps,
>
>       greg k-h
>
> --
> You received this message because you are subscribed to the Google Groups
> "outreachy-kernel" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to outreachy-kernel+unsubscribe@googlegroups.com.
> To post to this group, send email to outreachy-kernel@googlegroups.com.
> To view this discussion on the web visithttps://groups.google.com/d/msgid/outreachy-kernel/32dfda0b-6ce2-40f2-bf35-
> 789c0c31b4cc%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-02-24 18:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-02-24 12:10 Questions regarding BUG macro Varsha Rao
2017-02-24 14:48 ` [Outreachy kernel] " Greg KH
2017-02-24 18:24   ` Varsha Rao
2017-02-24 18:29     ` Julia Lawall

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.