From: miod Date: Thu, 26 Dec 2013 21:02:37 +0000 (+0000) Subject: When running the ll/sc version of the mutex code (for MULTIPROCESSOR kernels), X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=25b8a2fa4c529245454d4dc801b24c234aa8730b;p=openbsd When running the ll/sc version of the mutex code (for MULTIPROCESSOR kernels), correctly handle sc failures. All other ll/sc constructs were doing this correctly but apparently noone had noticed mutex did not. --- diff --git a/sys/arch/octeon/octeon/mutex.c b/sys/arch/octeon/octeon/mutex.c index 2026a6088e3..8876a5edd66 100644 --- a/sys/arch/octeon/octeon/mutex.c +++ b/sys/arch/octeon/octeon/mutex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mutex.c,v 1.5 2011/04/21 04:34:12 miod Exp $ */ +/* $OpenBSD: mutex.c,v 1.6 2013/12/26 21:02:37 miod Exp $ */ /* * Copyright (c) 2004 Artur Grabowski @@ -39,12 +39,15 @@ try_lock(struct mutex *mtx) asm volatile ( ".set noreorder\n" - "ll %0, %2\n" - "bnez %0, 1f\n" - "nop\n" - "li %1, 1\n" - "sc %1, %2\n" "1:\n" + "ll %0, %2\n" /* tmp = mtx->mtx_lock */ + "bnez %0, 2f\n" + " li %1, 0\n" /* ret = 0 */ + "li %1, 1\n" /* ret = 1 */ + "sc %1, %2\n" /* mtx->mtx_lock = 1 */ + "beqz %1, 1b\n" /* update failed */ + " nop\n" + "2:\n" ".set reorder\n" : "+r"(tmp), "+r"(ret) : "m"(mtx->mtx_lock)); diff --git a/sys/arch/sgi/sgi/mutex.c b/sys/arch/sgi/sgi/mutex.c index 2c85fa89e19..3fa43dac71c 100644 --- a/sys/arch/sgi/sgi/mutex.c +++ b/sys/arch/sgi/sgi/mutex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mutex.c,v 1.12 2011/04/21 04:34:12 miod Exp $ */ +/* $OpenBSD: mutex.c,v 1.13 2013/12/26 21:02:37 miod Exp $ */ /* * Copyright (c) 2004 Artur Grabowski @@ -39,12 +39,15 @@ try_lock(struct mutex *mtx) asm volatile ( ".set noreorder\n" - "ll %0, %2\n" - "bnez %0, 1f\n" - "nop\n" - "li %1, 1\n" - "sc %1, %2\n" "1:\n" + "ll %0, %2\n" /* tmp = mtx->mtx_lock */ + "bnez %0, 2f\n" + " li %1, 0\n" /* ret = 0 */ + "li %1, 1\n" /* ret = 1 */ + "sc %1, %2\n" /* mtx->mtx_lock = 1 */ + "beqz %1, 1b\n" /* update failed */ + " nop\n" + "2:\n" ".set reorder\n" : "+r"(tmp), "+r"(ret) : "m"(mtx->mtx_lock));