what is the relation between atomic operations and memory alignment ? I read from UTLK that "an unaligned memory access is not atomic" please explain me , I am not able to get the relationship between memory alignment and atomicity of the operation.
On Sun, Feb 24, 2013 at 10:42 AM, Shraddha Kamat <sh2008ka@gmail.com> wrote:
what is the relation between atomic operations and memory alignment ?
I read from UTLK that "an unaligned memory access is not atomic"
please explain me , I am not able to get the relationship between memory alignment and atomicity of the operation.
Not all CPUs support unaligned memory access, such an access may cause a fault which needs to be fixed by the kernel... -- Thanks, //richard
On Sun, 24 Feb 2013 11:50:14 +0100, richard -rw- weinberger said:
On Sun, Feb 24, 2013 at 10:42 AM, Shraddha Kamat <sh2008ka@gmail.com> wrote:
what is the relation between atomic operations and memory alignment ?
I read from UTLK that "an unaligned memory access is not atomic"
please explain me , I am not able to get the relationship between memory alignment and atomicity of the operation.
Not all CPUs support unaligned memory access, such an access may cause a fault which needs to be fixed by the kernel...
There's a more subtle issue - an unaligned access can be split across a cache line boundary, requiring 2 separate memory accesses to do the read or write. This can result in CPU A fetching the first half of the variable, CPU B updating both halves, and then A fetching the second half of the now updated variable.. This can bite you even on CPUs that support unaligned accesses.
in simple terms, any operation, in terms assembly instructions, which can be executed in ONE instruction, is "atomic", because, just like an atom, it cannot be broken up into parts. any instructions that is longer than one, for eg, TWO instruction, is NOT atomic, because in BETWEEN the first and 2nd instruction, something like an interrupt can come in, and affect the values of the operand when it is passed from instruction one to second instruction. To save me from reiteration: http://www.ibm.com/developerworks/library/pa-dalign/ (search for "atomicity"). http://stackoverflow.com/questions/381244/purpose-of-memory-alignment http://lwn.net/Articles/260832/ http://www.songho.ca/misc/alignment/dataalign.html http://www.cis.upenn.edu/~palsetia/cit595s08/Lectures08/alignmentOrdering.pd... Essentially, atomicity and non-alignment become problematic when u tried to to read using non-byte addressing mode with non-aligned address. On Sun, Feb 24, 2013 at 5:42 PM, Shraddha Kamat <sh2008ka@gmail.com> wrote:
what is the relation between atomic operations and memory alignment ?
I read from UTLK that "an unaligned memory access is not atomic"
please explain me , I am not able to get the relationship between memory alignment and atomicity of the operation.
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
-- Regards, Peter Teoh
Hi Peter, On Sun, Feb 24, 2013 at 6:20 PM, Peter Teoh <htmldeveloper@gmail.com> wrote:
in simple terms, any operation, in terms assembly instructions, which can be executed in ONE instruction, is "atomic", because, just like an atom, it cannot be broken up into parts. any instructions that is longer than one, for eg, TWO instruction, is NOT atomic, because in BETWEEN the first and 2nd instruction, something like an interrupt can come in, and affect the values of the operand when it is passed from instruction one to second instruction.
Nice explanation. Thanks, Arun
To save me from reiteration:
http://www.ibm.com/developerworks/library/pa-dalign/ (search for "atomicity").
http://stackoverflow.com/questions/381244/purpose-of-memory-alignment
http://lwn.net/Articles/260832/
http://www.songho.ca/misc/alignment/dataalign.html
http://www.cis.upenn.edu/~palsetia/cit595s08/Lectures08/alignmentOrdering.pd...
Essentially, atomicity and non-alignment become problematic when u tried to to read using non-byte addressing mode with non-aligned address.
On Sun, Feb 24, 2013 at 5:42 PM, Shraddha Kamat <sh2008ka@gmail.com> wrote:
what is the relation between atomic operations and memory alignment ?
I read from UTLK that "an unaligned memory access is not atomic"
please explain me , I am not able to get the relationship between memory alignment and atomicity of the operation.
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
-- Regards, Peter Teoh
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
participants (5)
-
Arun KS -
Peter Teoh -
richard -rw- weinberger -
Shraddha Kamat -
Valdis.Kletnieks@vt.edu