X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=examples%2Fperformance-thread%2Fpthread_shim%2Fpthread_shim.c;h=7e6d7230e0e2f02475d6ec218312f8753fd92258;hb=ba78d0104e4ce61135ffb26a39dac0d57b00824b;hp=93c3216d23a7879e1cd07ba0c1c63cc237e39caa;hpb=b5cdd645c9fc62341d55aebbfc93a1b648415512;p=deb_dpdk.git diff --git a/examples/performance-thread/pthread_shim/pthread_shim.c b/examples/performance-thread/pthread_shim/pthread_shim.c index 93c3216d..7e6d7230 100644 --- a/examples/performance-thread/pthread_shim/pthread_shim.c +++ b/examples/performance-thread/pthread_shim/pthread_shim.c @@ -48,6 +48,21 @@ #define POSIX_ERRNO(x) (x) +/* some releases of FreeBSD 10, e.g. 10.0, don't have CPU_COUNT macro */ +#ifndef CPU_COUNT +#define CPU_COUNT(x) __cpu_count(x) + +static inline unsigned int +__cpu_count(const rte_cpuset_t *cpuset) +{ + unsigned int i, count = 0; + for (i = 0; i < RTE_MAX_LCORE; i++) + if (CPU_ISSET(i, cpuset)) + count++; + return count; +} +#endif + /* * this flag determines at run time if we override pthread * calls and map then to equivalent lthread calls @@ -159,7 +174,7 @@ int (*f_pthread_setschedparam) int (*f_pthread_yield) (void); int (*f_pthread_setaffinity_np) - (pthread_t thread, size_t cpusetsize, const cpu_set_t *cpuset); + (pthread_t thread, size_t cpusetsize, const rte_cpuset_t *cpuset); int (*f_nanosleep) (const struct timespec *req, struct timespec *rem); } _sys_pthread_funcs = { @@ -382,7 +397,7 @@ int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) int pthread_create(pthread_t *__restrict tid, const pthread_attr_t *__restrict attr, - void *(func) (void *), + lthread_func_t func, void *__restrict arg) { if (override) { @@ -390,11 +405,11 @@ pthread_create(pthread_t *__restrict tid, if (attr != NULL) { /* determine CPU being requested */ - cpu_set_t cpuset; + rte_cpuset_t cpuset; CPU_ZERO(&cpuset); pthread_attr_getaffinity_np(attr, - sizeof(cpu_set_t), + sizeof(rte_cpuset_t), &cpuset); if (CPU_COUNT(&cpuset) != 1) @@ -407,7 +422,7 @@ pthread_create(pthread_t *__restrict tid, } } return lthread_create((struct lthread **)tid, lcore, - (void (*)(void *))func, arg); + func, arg); } return _sys_pthread_funcs.f_pthread_create(tid, attr, func, arg); } @@ -417,9 +432,10 @@ int pthread_detach(pthread_t tid) if (override) { struct lthread *lt = (struct lthread *)tid; - if (lt == lthread_current()) + if (lt == lthread_current()) { lthread_detach(); return 0; + } NOT_IMPLEMENTED; } return _sys_pthread_funcs.f_pthread_detach(tid); @@ -575,15 +591,26 @@ int pthread_rwlock_wrlock(pthread_rwlock_t *a) return _sys_pthread_funcs.f_pthread_rwlock_wrlock(a); } -int pthread_yield(void) +#ifdef RTE_EXEC_ENV_LINUXAPP +int +pthread_yield(void) { if (override) { lthread_yield(); return 0; } return _sys_pthread_funcs.f_pthread_yield(); - } +#else +void +pthread_yield(void) +{ + if (override) + lthread_yield(); + else + _sys_pthread_funcs.f_pthread_yield(); +} +#endif pthread_t pthread_self(void) { @@ -685,7 +712,7 @@ int nanosleep(const struct timespec *req, struct timespec *rem) int pthread_setaffinity_np(pthread_t thread, size_t cpusetsize, - const cpu_set_t *cpuset) + const rte_cpuset_t *cpuset) { if (override) { /* we only allow affinity with a single CPU */