[Cbe-oss-dev] [PATCH 06/28]MARS/base: cond wait hybrid
Yuji Mano
yuji.mano at am.sony.com
Fri Feb 6 13:30:52 EST 2009
From: Kazunori Asayama <asayama at sm.sony.co.jp>
Add hybrid method to wait for condition on host side
The current implementation to wait for condition on host side has
significant performance loss and unexpected load of host CPU because
of frequent use of futex.
This patch adds short sched_yield loop before futex_wait to improve
performance and to reduce extra load in case that the condition
becomes satisfied soon after condition test fails.
Signed-off-by: Kazunori Asayama <asayama at sm.sony.co.jp>
---
base/src/host/lib/cond_cell.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
Index: b/base/src/host/lib/cond_cell.c
===================================================================
--- a/base/src/host/lib/cond_cell.c 2009-01-23 16:31:55.000000000 +0900
+++ b/base/src/host/lib/cond_cell.c 2009-01-23 17:24:13.000000000 +0900
@@ -44,6 +44,8 @@
#include "mars/base.h"
#include "mars/error.h"
+#define SPIN_MAX 50
+
#ifdef ENABLE_COND_WAIT_FUTEX
#include <unistd.h>
@@ -79,6 +81,7 @@ int mars_ea_cond_wait(uint64_t watch_poi
void *test_cond_param)
{
int ret;
+ int spin = 0;
while (1) {
uint32_t val = mars_ea_get_uint32(watch_point_ea);
@@ -88,12 +91,17 @@ int mars_ea_cond_wait(uint64_t watch_poi
break;
#ifdef ENABLE_COND_WAIT_FUTEX
- ret = futex_wait(mars_ea_to_ptr(watch_point_ea), val);
- if (ret != MARS_SUCCESS)
- break;
-#else
- sched_yield();
+ if (spin >= SPIN_MAX) {
+ ret = futex_wait(mars_ea_to_ptr(watch_point_ea), val);
+ if (ret != MARS_SUCCESS)
+ break;
+ }
+ else
#endif
+ {
+ sched_yield();
+ spin++;
+ }
}
return ret;
More information about the cbe-oss-dev
mailing list