Skip to contentSkip to conversation

xen/mcelog: simplify MCE_GETCLEAR_FLAGS using xchg()

PATCH In review Uros Bizjak 3 participants 4 messages Jan 22 Xen hypervisor interface

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/mcelog: simplify MCE_GETCLEAR_FLAGS using xchg()

The MCE_GETCLEAR_FLAGS ioctl retrieves xen_mcelog.flags while atomically clearing it. This was previously implemented using a cmpxchg() loop.

Replace the cmpxchg() loop with a single xchg(), which provides the same atomic get-and-clear semantics, avoids retry spinning under contention, and simplifies the code.

The code on x86_64 improves from:

    186:	8b 15 00 00 00 00    	mov    0x0(%rip),%edx
    18c:	89 d0                	mov    %edx,%eax
    18e:	f0 0f b1 0d 00 00 00 	lock cmpxchg %ecx,0x0(%rip)
    195:	00
    196:	39 c2                	cmp    %eax,%edx
    198:	75 ec                	jne    186 <...>

to just:

    186:	87 05 00 00 00 00    	xchg   %eax,0x0(%rip)

No functional change intended.

Cc Juergen Gross <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Oleksandr Tyshchenko <[email protected]>
---
 drivers/xen/mcelog.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/xen/mcelog.c +1 -3
index 4f65b641c054..abe658c73b7b 100644
@@ -165,9 +165,7 @@ static long xen_mce_chrdev_ioctl(struct file *f, unsigned int cmd,
 	case MCE_GETCLEAR_FLAGS: {
 		unsigned flags;
 
-		do {
-			flags = xen_mcelog.flags;
-		} while (cmpxchg(&xen_mcelog.flags, flags, 0) != flags);
+		flags = xchg(&xen_mcelog.flags, 0);
 
 		return put_user(flags, p);
 	}
Signature · 1 line
2.52.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 17 lines · Uros Bizjak

The MCE_GETCLEAR_FLAGS ioctl retrieves xen_mcelog.flags while atomically clearing it. This was previously implemented using a cmpxchg() loop.

Replace the cmpxchg() loop with a single xchg(), which provides the same atomic get-and-clear semantics, avoids retry spinning under contention, and simplifies the code.

The code on x86_64 improves from:

    186:	8b 15 00 00 00 00    	mov    0x0(%rip),%edx
    18c:	89 d0                	mov    %edx,%eax
    18e:	f0 0f b1 0d 00 00 00 	lock cmpxchg %ecx,0x0(%rip)
    195:	00
    196:	39 c2                	cmp    %eax,%edx
    198:	75 ec                	jne    186 <...>
Quoted 7 lines

to just:

    186:	87 05 00 00 00 00    	xchg   %eax,0x0(%rip)

No functional change intended.

Reviewed-by on v1 1/1
#2 lore raw
In reply to Uros Bizjak
Quoted 17 lines · Uros Bizjak

The MCE_GETCLEAR_FLAGS ioctl retrieves xen_mcelog.flags while atomically clearing it. This was previously implemented using a cmpxchg() loop.

Replace the cmpxchg() loop with a single xchg(), which provides the same atomic get-and-clear semantics, avoids retry spinning under contention, and simplifies the code.

The code on x86_64 improves from:

    186:	8b 15 00 00 00 00    	mov    0x0(%rip),%edx
    18c:	89 d0                	mov    %edx,%eax
    18e:	f0 0f b1 0d 00 00 00 	lock cmpxchg %ecx,0x0(%rip)
    195:	00
    196:	39 c2                	cmp    %eax,%edx
    198:	75 ec                	jne    186 <...>
Quoted 7 lines

to just:

    186:	87 05 00 00 00 00    	xchg   %eax,0x0(%rip)

No functional change intended.

Reviewed-by on v1 1/1
#3 lore raw
In reply to Uros Bizjak
Quoted 36 lines · Uros Bizjak

The MCE_GETCLEAR_FLAGS ioctl retrieves xen_mcelog.flags while atomically clearing it. This was previously implemented using a cmpxchg() loop.

Replace the cmpxchg() loop with a single xchg(), which provides the same atomic get-and-clear semantics, avoids retry spinning under contention, and simplifies the code.

The code on x86_64 improves from:

    186:	8b 15 00 00 00 00    	mov    0x0(%rip),%edx
    18c:	89 d0                	mov    %edx,%eax
    18e:	f0 0f b1 0d 00 00 00 	lock cmpxchg %ecx,0x0(%rip)
    195:	00
    196:	39 c2                	cmp    %eax,%edx
    198:	75 ec                	jne    186 <...>

to just:

    186:	87 05 00 00 00 00    	xchg   %eax,0x0(%rip)

No functional change intended.

Cc Juergen Gross <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Oleksandr Tyshchenko <[email protected]>
---
 drivers/xen/mcelog.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/xen/mcelog.c +0 -0
index 4f65b641c054..abe658c73b7b 100644

drivers/xen/mcelog.c static long xen_mce_chrdev_ioctl(struct file *f, unsigned int cmd, · line 171

Quoted 10 lines
drivers/xen/mcelog.c +1 -3
@@ -165,9 +165,7 @@ static long xen_mce_chrdev_ioctl(struct file *f, unsigned int cmd,
 	case MCE_GETCLEAR_FLAGS: {
 		unsigned flags;
 
-		do {
-			flags = xen_mcelog.flags;
-		} while (cmpxchg(&xen_mcelog.flags, flags, 0) != flags);
+		flags = xchg(&xen_mcelog.flags, 0);
 
 		return put_user(flags, p);
 	}

Oh yeah, that was very daft beforehand.