read-modify-write command -> how does it work?

Status
Not open for further replies.

ivlsi

Advanced Member level 3
Joined
Feb 17, 2012
Messages
883
Helped
17
Reputation
32
Reaction score
16
Trophy points
1,298
Visit site
Activity points
6,868
Hi All,

The read-modify-write command in micro-processors -> how does it work? Why needed?

Thank you!
 

The idea behind a read-modify-write command is it's atomic (meaning it can't be interrupted). In some multi-processor designs I've seen this type of command is used to update semaphores so one process can't interrupt a second process while it's updating the semaphore.
 

Thanks.

Could you please provide more details about semaphore arbitration - when might be used, pros & cons, etc...
 

Semaphores are typically used when there is a shared resource like memory that needs to be accessed by two masters the semaphore is used to lock out the second device while it's being updated by the first, therefore to set/clear the semaphore you need to have an atomic access so only one of the devices can set/clear at a time.
 

Is the read-modify-write command a dedicated SW command or HW mechanism? Should a programmer write this command explicitly in his/her code?
 

I've seen it done both ways. Depends on the hardware (uP) that's used. If the uP doesn't support it but it's still needed for the system to operate external HW has to support it.

BTW. Things might have changed since the time I worked on processor based designs. >10 years ago. Not sure what all the new processors features are for this type of application. Some of the DSP processors I worked with had special read-modify-write semaphore reading/setting instructions. So you could share memory between processors.
 

Why is it so important to hold an access to the memory while modifying one of its entry (in case of the read-modify-write command)?
What would happen if a programmer would use the regular read and write commands instead of an atomic read-modify-write one? Could you provide a scenario when this would not work?
 

Why is it so important to hold an access to the memory while modifying one of its entry (in case of the read-modify-write command)?
What would happen if a programmer would use the regular read and write commands instead of an atomic read-modify-write one? Could you provide a scenario when this would not work?
 

A & B want to access the same memory location at the same time.

A reads the location first and gets 0x12345678.
B reads the location second and gets 0x12345678.

A modifies the location and writes 0x32345678 first.
B modifies the location and writes 0x12345679 second.

The end result is 0x12345679 instead of 0x32345679.
 
Reactions: ivlsi

    ivlsi

    Points: 2
    Helpful Answer Positive Rating
Thanks! Indeed an increment operation by two sources needs RMW command!
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…