Re: [PATCH 1/1] mutex: prevent optimistic spinning from spinninglonger than neccessary (Repost)

From: Tim Chen
Date: Fri Aug 20 2010 - 13:03:08 EST


On Fri, 2010-08-20 at 15:19 +0200, Ingo Molnar wrote:

>
> Thanks! The performance results you've posted so far IMO more than justifies
> its inclusion.
>
> Ingo

Thanks to everyone for your review. I've updated the patch to add
comments explaining the change per suggestion from Andrew.

Signed-off-by: Tim Chen <tim.c.chen@xxxxxxxxxxxxxxx>
diff --git a/kernel/sched.c b/kernel/sched.c
index 41541d7..3747d04 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -3865,8 +3865,15 @@ int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner)
/*
* Owner changed, break to re-assess state.
*/
- if (lock->owner != owner)
+ if (lock->owner != owner) {
+ /* if lock has switched to a different owner,
+ * we have heavy contention. Return 0 to
+ * quit optimistic spinning and not contend further.
+ */
+ if (lock->owner)
+ return 0;
break;
+ }

/*
* Is that owner really running on that cpu?


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/