Re: what is static inline void tvec_base

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Aug 28, 2010 at 12:06 PM, James Bond <jamesbond.2k.g@xxxxxxxxx> wrote:

> No not yet clear.
>

To make a function call CPU has to save registers and pass on ret
instructions when ever the function call ends
if we have a small fucntion which is used in a file and a function
call via CPU then over head of saving flag registers ,saving stack and
making the called function return to the location where the call was
made is so much that it is preferred to replace that call via the
actual function itself hence if some one has such a function which has
is of very less number of lines and has been called once or twice then
it is good to declare it inline.

The overhead that  CPU has to undergo if the function is not inline is
saving the current context ,flag,stack,heap ,(what ever is)the state
of code in execution and then load the called function from a specific
memory location.
Doing this for small subroutines is resource consuming.So it is a good
practise among  kernel developers do declare functions inline when it
is used once or twice and saves the CPU the over head involved in
saving the stack,program counter flag registers and other registers
which are being related to the program in execution.

By using the word in laymans language I will say that part of code
(function ) is actually written where ever the function call is made.

For example following program

example1.c

#include<stdio.h>
inline function ingen (X1,X2)
{
does some thing some thing
return c;
}

function b( )
{
 step = function ingen ();
}
main()
{
b ();
}

If you were to execute above code

call to function ingen ()  via function b()  would replace the
function ingen() by the code inside  function ingen().



If you would not have declared  function ingen as inline function then
the CPU would jumped to some memory location where function ingen() is
actually residing and then executed.

In this case CPU just have to insert that code what ever function
ingen() does when ever a call to function ingen() is made via function
b().

Or which ever function in the  code calls function ingen().

If the keyword static is added so that if the same function has been
used at any other place then it should not affect the other
files.Meaning the word static before a function makes its scope
limited to that file only.

If you have another program example2.c and compile

 cc example1.c example2.c
then functions in exampl1.c would be available to example2.c and vice
versa but use of word static restricts the function in their
respective files.
i.e. if example1.c has a static function then it will not be available
to example2.c

Since Linux kernel is made up of C and to make sure functions with
similar names(if any) exist then they are not conflicting it is a good
practice to declare a function  as static.

Declaring it inline reduces the overhead that CPU would have to do in
actually calling a function.


To have more digging about this you need to understand mechanism of
function call as what does
processor do when a function call is made.

Clearly  if you have a large code to execute the
instruction is in memory and it has to come to cache so if you have
large code and you declare that as inline it has disadvantage that
cache miss will more.

What I wanted to
say is if you have a function is used at 10 places and you declare it
inline 10 times then there would be cache miss more (because that
inline part of code would not be in cache) and this  will
have disadvantage.

static and inline functions is

To make a function call CPU has to save registers and pass on ret
instructions when ever the function call ends
if we have a small fucntion which is used in a file and a function
call via CPU then over head of saving flag registers ,saving stack and
making the called function return to the location where the call was
made is so much that it is preferred to replace that call via the
actual function itself hence if some one has such a function which has
is of very less number of lines and has been called once or twice then
it is good to declare it inline.

The overhead that  CPU has to undergo if the function is not inline is
saving the current context ,flag,stack,heap ,(what ever is)the state
of code in execution and then load the called function from a specific
memory location.
Doing this for small subroutines is resource consuming.So it is a good
practise among  kernel developers do declare functions inline when it
is used once or twice and saves the CPU the over head involved in
saving the stack,program counter flag registers and other registers
which are being related to the program in execution.

By using the word in laymans language I will say that part of code
(function ) is actually written where ever the function call is made.

For example following program

example1.c

#include<stdio.h>
inline function ingen (X1,X2)
{
does some thing some thing
return c;
}

function b( )
{
 step = function ingen ();
}
main()
{
b ();
}

If you were to execute above code

call to function ingen ()  via function b()  would replace the
function ingen() by the code inside  function ingen().



If you would not have declared  function ingen as inline function then
the CPU would jumped to some memory location where function ingen() is
actually residing and then executed.

In this case CPU just have to insert that code what ever function
ingen() does when ever a call to function ingen() is made via function
b().

Or which ever function in the  code calls function ingen().

If the keyword static is added so that if the same function has been
used at any other place then it should not affect the other
files.Meaning the word static before a function makes its scope
limited to that file only.

If you have another program example2.c and compile

 cc example1.c example2.c
then functions in exampl1.c would be available to example2.c and vice
versa but use of word static restricts the function in their
respective files.
i.e. if example1.c has a static function then it will not be available
to example2.c

Since Linux kernel is made up of C and to make sure functions with
similar names(if any) exist then they are not conflicting it is a good
practice to declare a function  as static.

Declaring it inline reduces the overhead that CPU would have to do in
actually calling a function.


To have more digging about this you need to understand mechanism of
function call as what does
processor do when a function call is made.

Clearly  if you have a large code to execute the
instruction is in memory and it has to come to cache so if you have
large code and you declare that as inline it has disadvantage that
cache miss will more.

What I wanted to
say is if you have a function is used at 10 places and you declare it
inline 10 times then there would be cache miss more (because that
inline part of code would not be in cache) and this  will
have disadvantage.

Some good links worth mentioning are if you want to dig into

http://www.tenouk.com/cncplusplusbufferoverflow.html
http://www.tenouk.com/Bufferoverflowc/Bufferoverflow1.html
http://www.intel.com/products/processor/manuals/index.htm
http://www.tenouk.com/cnlinuxsockettutorials.html
http://www.drpaulcarter.com/pcasm/
http://asm.sourceforge.net/

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux