This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

volatile variable using in making application.

Hi,   

      I am new in this field. Previously i was doing microcontroller programming. where i used in volatile variable to avoid compiler optimization. But i never saw such volatile declaration before variable declaration.Does it mean compilation is done without any optimization in build. Here i have two doubts.   

1. How can i enable different types of optimization during compilation like speed and space optimization in angstrom build?   

2. If it already optimization compilation, why do not we need volatile declaration?   

Regards.   

Learner   

  • Hi Learner,

    My understanding is, your questions are about general Linux kernel (device driver) programming, correct?

    If you are new to Linux kernel programming, my recommendation is to read http://lwn.net/Kernel/LDD3/ though it is a bit outdated.

    > 1. How can i enable different types of optimization during compilation like speed and space optimization in angstrom build?

    My understanding is, general Linux kernel build procedure takes care of GCC optimization level.  Usually I don't take care of the optimization options for Linux kernel build.

    > 2. If it already optimization compilation, why do not we need volatile declaration?

    For example, when we access hardware registers, we use predefined functions or macros e.g. iowrite32() or ioread32() which Linux kernel provides.  In the case, the macros or functions take care of any underlying hardware issues, so we don't need to take care of them very much regardless the CPU is x86 or ARM.

    The "Linux Device Drivers" are provided by PDF.  You can search the keyword "cache coherency" in the entire book.  You will see the topics are not so much explained except for the Chapter 15 for DMA topics.  The keyword "volatile" is also covered in some sections for some kernel variables (e.g. jiffies).  I hope it helps.

    Regards,
    Atsushi