aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazunori Asayama <asayama@sm.sony.co.jp>2009-02-05 18:30:52 -0800
committerYuji Mano <yuji.mano@am.sony.com>2009-02-11 11:02:53 -0800
commit8076f490cd85ec2c7a17d05018e8c180fb5d1122 (patch)
treed417a57e53748e9b584c8a05ae034e75a0b75636
parentc5d91b1a18da4fbcb833809f163e9663c474cc9b (diff)
downloadmars-src-8076f490cd85ec2c7a17d05018e8c180fb5d1122.tar.gz
base: Cond wait hybrid
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@sm.sony.co.jp> Signed-off-by: Yuji Mano <yuji.mano@am.sony.com>
-rw-r--r--base/src/host/lib/cond_cell.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/base/src/host/lib/cond_cell.c b/base/src/host/lib/cond_cell.c
index fd9ede3..30015de 100644
--- a/base/src/host/lib/cond_cell.c
+++ b/base/src/host/lib/cond_cell.c
@@ -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_point_ea,
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_point_ea,
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;