1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
|
/*-
* BSD LICENSE
*
* Copyright(c) 2015 Intel Corporation. All rights reserved.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <errno.h>
#define __USE_GNU
#include <sched.h>
#include <dlfcn.h>
#include <rte_log.h>
#include "lthread_api.h"
#include "pthread_shim.h"
#define RTE_LOGTYPE_PTHREAD_SHIM RTE_LOGTYPE_USER3
#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
* or of we call the standard pthread function
*/
static __thread int override;
/*
* this structures contains function pointers that will be
* initialised to the loaded address of the real
* pthread library API functions
*/
struct pthread_lib_funcs {
int (*f_pthread_barrier_destroy)
(pthread_barrier_t *);
int (*f_pthread_barrier_init)
(pthread_barrier_t *, const pthread_barrierattr_t *, unsigned);
int (*f_pthread_barrier_wait)
(pthread_barrier_t *);
int (*f_pthread_cond_broadcast)
(pthread_cond_t *);
int (*f_pthread_cond_destroy)
(pthread_cond_t *);
int (*f_pthread_cond_init)
(pthread_cond_t *, const pthread_condattr_t *);
int (*f_pthread_cond_signal)
(pthread_cond_t *);
int (*f_pthread_cond_timedwait)
(pthread_cond_t *, pthread_mutex_t *, const struct timespec *);
int (*f_pthread_cond_wait)
(pthread_cond_t *, pthread_mutex_t *);
int (*f_pthread_create)
(pthread_t *, const pthread_attr_t *, void *(*)(void *), void *);
int (*f_pthread_detach)
(pthread_t);
int (*f_pthread_equal)
(pthread_t, pthread_t);
void (*f_pthread_exit)
(void *);
void * (*f_pthread_getspecific)
(pthread_key_t);
int (*f_pthread_getcpuclockid)
(pthread_t, clockid_t *);
int (*f_pthread_join)
(pthread_t, void **);
int (*f_pthread_key_create)
(pthread_key_t *, void (*) (void *));
int (*f_pthread_key_delete)
(pthread_key_t);
int (*f_pthread_mutex_destroy)
(pthread_mutex_t *__mutex);
int (*f_pthread_mutex_init)
(pthread_mutex_t *__mutex, const pthread_mutexattr_t *);
int (*f_pthread_mutex_lock)
(pthread_mutex_t *__mutex);
int (*f_pthread_mutex_trylock)
(pthread_mutex_t *__mutex);
int (*f_pthread_mutex_timedlock)
(pthread_mutex_t *__mutex, const struct timespec *);
int (*f_pthread_mutex_unlock)
(pthread_mutex_t *__mutex);
int (*f_pthread_once)
(pthread_once_t *, void (*) (void));
int (*f_pthread_rwlock_destroy)
(pthread_rwlock_t *__rwlock);
int (*f_pthread_rwlock_init)
(pthread_rwlock_t *__rwlock, const pthread_rwlockattr_t *);
int (*f_pthread_rwlock_rdlock)
(pthread_rwlock_t *__rwlock);
int (*f_pthread_rwlock_timedrdlock)
(pthread_rwlock_t *__rwlock, const struct timespec *);
int (*f_pthread_rwlock_timedwrlock)
(pthread_rwlock_t *__rwlock, const struct timespec *);
int (*f_pthread_rwlock_tryrdlock)
(pthread_rwlock_t *__rwlock);
int (*f_pthread_rwlock_trywrlock)
(pthread_rwlock_t *__rwlock);
int (*f_pthread_rwlock_unlock)
(pthread_rwlock_t *__rwlock);
int (*f_pthread_rwlock_wrlock)
(pthread_rwlock_t *__rwlock);
pthread_t (*f_pthread_self)
(void);
int (*f_pthread_setspecific)
(pthread_key_t, const void *);
int (*f_pthread_spin_init)
(pthread_spinlock_t *__spin, int);
int (*f_pthread_spin_destroy)
(pthread_spinlock_t *__spin);
int (*f_pthread_spin_lock)
(pthread_spinlock_t *__spin);
int (*f_pthread_spin_trylock)
(pthread_spinlock_t *__spin);
int (*f_pthread_spin_unlock)
(pthread_spinlock_t *__spin);
int (*f_pthread_cancel)
(pthread_t);
int (*f_pthread_setcancelstate)
(int, int *);
int (*f_pthread_setcanceltype)
(int, int *);
void (*f_pthread_testcancel)
(void);
int (*f_pthread_getschedparam)
(pthread_t pthread, int *, struct sched_param *);
int (*f_pthread_setschedparam)
(pthread_t, int, const struct sched_param *);
int (*f_pthread_yield)
(void);
int (*f_pthread_setaffinity_np)
(pthread_t thread, size_t cpusetsize, const rte_cpuset_t *cpuset);
int (*f_nanosleep)
(const struct timespec *req, struct timespec *rem);
} _sys_pthread_funcs = {
.f_pthread_barrier_destroy = NULL,
};
/*
* this macro obtains the loaded address of a library function
* and saves it.
*/
static void *__libc_dl_handle = RTLD_NEXT;
#define get_addr_of_loaded_symbol(name) do { \
char *error_str; \
_sys_pthread_funcs.f_##name = dlsym(__libc_dl_handle, (#name)); \
error_str = dlerror(); \
if (error_str != NULL) { \
fprintf(stderr, "%s\n", error_str); \
} \
} while (0)
/*
* The constructor function initialises the
* function pointers for pthread library functions
*/
RTE_INIT(pthread_intercept_ctor)
{
override = 0;
/*
* Get the original functions
*/
get_addr_of_loaded_symbol(pthread_barrier_destroy);
get_addr_of_loaded_symbol(pthread_barrier_init);
get_addr_of_loaded_symbol(pthread_barrier_wait);
get_addr_of_loaded_symbol(pthread_cond_broadcast);
get_addr_of_loaded_symbol(pthread_cond_destroy);
get_addr_of_loaded_symbol(pthread_cond_init);
get_addr_of_loaded_symbol(pthread_cond_signal);
get_addr_of_loaded_symbol(pthread_cond_timedwait);
get_addr_of_loaded_symbol(pthread_cond_wait);
get_addr_of_loaded_symbol(pthread_create);
get_addr_of_loaded_symbol(pthread_detach);
get_addr_of_loaded_symbol(pthread_equal);
get_addr_of_loaded_symbol(pthread_exit);
get_addr_of_loaded_symbol(pthread_getspecific);
get_addr_of_loaded_symbol(pthread_getcpuclockid);
get_addr_of_loaded_symbol(pthread_join);
get_addr_of_loaded_symbol(pthread_key_create);
get_addr_of_loaded_symbol(pthread_key_delete);
get_addr_of_loaded_symbol(pthread_mutex_destroy);
get_addr_of_loaded_symbol(pthread_mutex_init);
get_addr_of_loaded_symbol(pthread_mutex_lock);
get_addr_of_loaded_symbol(pthread_mutex_trylock);
get_addr_of_loaded_symbol(pthread_mutex_timedlock);
get_addr_of_loaded_symbol(pthread_mutex_unlock);
get_addr_of_loaded_symbol(pthread_once);
get_addr_of_loaded_symbol(pthread_rwlock_destroy);
get_addr_of_loaded_symbol(pthread_rwlock_init);
get_addr_of_loaded_symbol(pthread_rwlock_rdlock);
get_addr_of_loaded_symbol(pthread_rwlock_timedrdlock);
get_addr_of_loaded_symbol(pthread_rwlock_timedwrlock);
get_addr_of_loaded_symbol(pthread_rwlock_tryrdlock);
get_addr_of_loaded_symbol(pthread_rwlock_trywrlock);
get_addr_of_loaded_symbol(pthread_rwlock_unlock);
get_addr_of_loaded_symbol(pthread_rwlock_wrlock);
get_addr_of_loaded_symbol(pthread_self);
get_addr_of_loaded_symbol(pthread_setspecific);
get_addr_of_loaded_symbol(pthread_spin_init);
get_addr_of_loaded_symbol(pthread_spin_destroy);
get_addr_of_loaded_symbol(pthread_spin_lock);
get_addr_of_loaded_symbol(pthread_spin_trylock);
get_addr_of_loaded_symbol(pthread_spin_unlock);
get_addr_of_loaded_symbol(pthread_cancel);
get_addr_of_loaded_symbol(pthread_setcancelstate);
get_addr_of_loaded_symbol(pthread_setcanceltype);
get_addr_of_loaded_symbol(pthread_testcancel);
get_addr_of_loaded_symbol(pthread_getschedparam);
get_addr_of_loaded_symbol(pthread_setschedparam);
get_addr_of_loaded_symbol(pthread_yield);
get_addr_of_loaded_symbol(pthread_setaffinity_np);
get_addr_of_loaded_symbol(nanosleep);
}
/*
* Enable/Disable pthread override
* state
* 0 disable
* 1 enable
*/
void pthread_override_set(int state)
{
override = state;
}
/*
* Return pthread override state
* return
* 0 disable
* 1 enable
*/
int pthread_override_get(void)
{
return override;
}
/*
* This macro is used to catch and log
* invocation of stubs for unimplemented pthread
* API functions.
*/
#define NOT_IMPLEMENTED do { \
if (override) { \
RTE_LOG(WARNING, \
PTHREAD_SHIM, \
"WARNING %s NOT IMPLEMENTED\n", \
__func__); \
} \
} while (0)
/*
* pthread API override functions follow
* Note in this example code only a subset of functions are
* implemented.
*
* The stub functions provided will issue a warning log
* message if an unimplemented function is invoked
*
*/
int pthread_barrier_destroy(pthread_barrier_t *a)
{
NOT_IMPLEMENTED;
return _sys_pthread_funcs.f_pthread_barrier_destroy(a);
}
int
pthread_barrier_init(pthread_barrier_t *a,
const pthread_barrierattr_t *b, unsigned c)
{
NOT_IMPLEMENTED;
return _sys_pthread_funcs.f_pthread_barrier_init(a, b, c);
}
int pthread_barrier_wait(pthread_barrier_t *a)
{
NOT_IMPLEMENTED;
return _sys_pthread_funcs.f_pthread_barrier_wait(a);
}
int pthread_cond_broadcast(pthread_cond_t *cond)
{
if (override) {
lthread_cond_broadcast(*(struct lthread_cond **)cond);
return 0;
}
return _sys_pthread_funcs.f_pthread_cond_broadcast(cond);
}
int pthread_mutex_destroy(pthread_mutex_t *mutex)
{
if (override)
return lthread_mutex_destroy(*(struct lthread_mutex **)mutex);
return _sys_pthread_funcs.f_pthread_mutex_destroy(mutex);
}
int pthread_cond_destroy(pthread_cond_t *cond)
{
if (override)
return lthread_cond_destroy(*(struct lthread_cond **)cond);
return _sys_pthread_funcs.f_pthread_cond_destroy(cond);
}
int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
{
if (override)
return lthread_cond_init(NULL,
(struct lthread_cond **)cond,
(const struct lthread_condattr *) attr);
return _sys_pthread_funcs.f_pthread_cond_init(cond, attr);
}
int pthread_cond_signal(pthread_cond_t *cond)
{
if (override) {
lthread_cond_signal(*(struct lthread_cond **)cond);
return 0;
}
return _sys_pthread_funcs.f_pthread_cond_signal(cond);
}
int
pthread_cond_timedwait(pthread_cond_t *__restrict cond,
pthread_mutex_t *__restrict mutex,
const struct timespec *__restrict time)
{
NOT_IMPLEMENTED;
return _sys_pthread_funcs.f_pthread_cond_timedwait(cond, mutex, time);
}
int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
{
if (override) {
pthread_mutex_unlock(mutex);
int rv = lthread_cond_wait(*(struct lthread_cond **)cond, 0);
pthread_mutex_lock(mutex);
return rv;
}
return _sys_pthread_funcs.f_pthread_cond_wait(cond, mutex);
}
int
pthread_create(pthread_t *__restrict tid,
const pthread_attr_t *__restrict attr,
void *(func) (void *),
void *__restrict arg)
{
if (override) {
int lcore = -1;
if (attr != NULL) {
/* determine CPU being requested */
rte_cpuset_t cpuset;
CPU_ZERO(&cpuset);
pthread_attr_getaffinity_np(attr,
sizeof(rte_cpuset_t),
&cpuset);
if (CPU_COUNT(&cpuset) != 1)
return POSIX_ERRNO(EINVAL);
for (lcore = 0; lcore < LTHREAD_MAX_LCORES; lcore++) {
if (!CPU_ISSET(lcore, &cpuset))
continue;
break;
}
}
return lthread_create((struct lthread **)tid, lcore,
(void (*)(void *))func, arg);
}
return _sys_pthread_funcs.f_pthread_create(tid, attr, func, arg);
}
int pthread_detach(pthread_t tid)
{
if (override) {
struct lthread *lt = (struct lthread *)tid;
if (lt == lthread_current()) {
lthread_detach();
return 0;
}
NOT_IMPLEMENTED;
}
return _sys_pthread_funcs.f_pthread_detach(tid);
}
int pthread_equal(pthread_t a, pthread_t b)
{
NOT_IMPLEMENTED;
return _sys_pthread_funcs.f_pthread_equal(a, b);
}
void pthread_exit_override(void *v)
{
if (override) {
lthread_exit(v);
return;
}
_sys_pthread_funcs.f_pthread_exit(v);
}
void
*pthread_getspecific(pthread_key_t key)
{
if (override)
return lthread_getspecific((unsigned int) key);
return _sys_pthread_funcs.f_pthread_getspecific(key);
}
int pthread_getcpuclockid(pthread_t a, clockid_t *b)
{
NOT_IMPLEMENTED;
return _sys_pthread_funcs.f_pthread_getcpuclockid(a, b);
}
int pthread_join(pthread_t tid, void **val)
{
if (override)
return lthread_join((struct lthread *)tid, val);
return _sys_pthread_funcs.f_pthread_join(tid, val);
}
int pthread_key_create(pthread_key_t *keyptr, void (*dtor) (void *))
{
if (override)
return lthread_key_create((unsigned int *)keyptr, dtor);
return _sys_pthread_funcs.f_pthread_key_create(keyptr, dtor);
}
int pthread_key_delete(pthread_key_t key)
{
if (override) {
lthread_key_delete((unsigned int) key);
return 0;
}
return _sys_pthread_funcs.f_pthread_key_delete(key);
}
int
pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
{
if (override)
return lthread_mutex_init(NULL,
(struct lthread_mutex **)mutex,
(const struct lthread_mutexattr *)attr);
return _sys_pthread_funcs.f_pthread_mutex_init(mutex, attr);
}
int pthread_mutex_lock(pthread_mutex_t *mutex)
{
if (override)
return lthread_mutex_lock(*(struct lthread_mutex **)mutex);
return _sys_pthread_funcs.f_pthread_mutex_lock(mutex);
}
int pthread_mutex_trylock(pthread_mutex_t *mutex)
{
if (override)
return lthread_mutex_trylock(*(struct lthread_mutex **)mutex);
return _sys_pthread_funcs.f_pthread_mutex_trylock(mutex);
}
int pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *b)
{
NOT_IMPLEMENTED;
return _sys_pthread_funcs.f_pthread_mutex_timedlock(mutex, b);
}
int pthread_mutex_unlock(pthread_mutex_t *mutex)
{
if (override)
return lthread_mutex_unlock(*(struct lthread_mutex **)mutex);
return _sys_pthread_funcs.f_pthread_mutex_unlock(mutex);
}
int pthread_once(pthread_once_t *a, void (b) (void))
{
NOT_IMPLEMENTED;
return _sys_pthread_funcs.f_pthread_once(a, b);
}
int pthread_rwlock_destroy(pthread_rwlock_t *a)
{
NOT_IMPLEMENTED;
return _sys_pthread_funcs.f_pthread_rwlock_destroy(a);
}
int pthread_rwlock_init(pthread_rwlock_t *a, const pthread_rwlockattr_t *b)
{
NOT_IMPLEMENTED;
return _sys_pthread_funcs.f_pthread_rwlock_init(a, b);
}
int pthread_rwlock_rdlock(pthread_rwlock_t *a)
{
NOT_IMPLEMENTED;
return _sys_pthread_funcs.f_pthread_rwlock_rdlock(a);
}
int pthread_rwlock_timedrdlock(pthread_rwlock_t *a, const struct timespec *b)
{
NOT_IMPLEMENTED;
return _sys_pthread_funcs.f_pthread_rwlock_timedrdlock(a, b);
}
int pthread_rwlock_timedwrlock(pthread_rwlock_t *a, const struct timespec *b)
{
NOT_IMPLEMENTED;
return _sys_pthread_funcs.f_pthread_rwlock_timedwrlock(a, b);
}
int pthread_rwlock_tryrdlock(pthread_rwlock_t *a)
{
NOT_IMPLEMENTED;
return _sys_pthread_funcs.f_pthread_rwlock_tryrdlock(a);
}
int pthread_rwlock_trywrlock(pthread_rwlock_t *a)
{
NOT_IMPLEMENTED;
return _sys_pthread_funcs.f_pthread_rwlock_trywrlock(a);
}
int pthread_rwlock_unlock(pthread_rwlock_t *a)
{
NOT_IMPLEMENTED;
return _sys_pthread_funcs.f_pthread_rwlock_unlock(a);
}
int pthread_rwlock_wrlock(pthread_rwlock_t *a)
{
NOT_IMPLEMENTED;
return _sys_pthread_funcs.f_pthread_rwlock_wrlock(a);
}
#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)
{
if (override)
return (pthread_t) lthread_current();
return _sys_pthread_funcs.f_pthread_self();
}
int pthread_setspecific(pthread_key_t key, const void *data)
{
if (override) {
int rv = lthread_setspecific((unsigned int)key, data);
return rv;
}
return _sys_pthread_funcs.f_pthread_setspecific(key, data);
}
int pthread_spin_init(pthread_spinlock_t *a, int b)
{
NOT_IMPLEMENTED;
return _sys_pthread_funcs.f_pthread_spin_init(a, b);
}
int pthread_spin_destroy(pthread_spinlock_t *a)
{
NOT_IMPLEMENTED;
return _sys_pthread_funcs.f_pthread_spin_destroy(a);
}
int pthread_spin_lock(pthread_spinlock_t *a)
{
NOT_IMPLEMENTED;
return _sys_pthread_funcs.f_pthread_spin_lock(a);
}
int pthread_spin_trylock(pthread_spinlock_t *a)
{
NOT_IMPLEMENTED;
return _sys_pthread_funcs.f_pthread_spin_trylock(a);
}
int pthread_spin_unlock(pthread_spinlock_t *a)
{
NOT_IMPLEMENTED;
return _sys_pthread_funcs.f_pthread_spin_unlock(a);
}
int pthread_cancel(pthread_t tid)
{
if (override) {
lthread_cancel(*(struct lthread **)tid);
return 0;
}
return _sys_pthread_funcs.f_pthread_cancel(tid);
}
int pthread_setcancelstate(int a, int *b)
{
NOT_IMPLEMENTED;
return _sys_pthread_funcs.f_pthread_setcancelstate(a, b);
}
int pthread_setcanceltype(int a, int *b)
{
NOT_IMPLEMENTED;
return _sys_pthread_funcs.f_pthread_setcanceltype(a, b);
}
void pthread_testcancel(void)
{
NOT_IMPLEMENTED;
return _sys_pthread_funcs.f_pthread_testcancel();
}
int pthread_getschedparam(pthread_t tid, int *a, struct sched_param *b)
{
NOT_IMPLEMENTED;
return _sys_pthread_funcs.f_pthread_getschedparam(tid, a, b);
}
int pthread_setschedparam(pthread_t a, int b, const struct sched_param *c)
{
NOT_IMPLEMENTED;
return _sys_pthread_funcs.f_pthread_setschedparam(a, b, c);
}
int nanosleep(const struct timespec *req, struct timespec *rem)
{
if (override) {
uint64_t ns = req->tv_sec * 1000000000 + req->tv_nsec;
lthread_sleep(ns);
return 0;
}
return _sys_pthread_funcs.f_nanosleep(req, rem);
}
int
pthread_setaffinity_np(pthread_t thread, size_t cpusetsize,
const rte_cpuset_t *cpuset)
{
if (override) {
/* we only allow affinity with a single CPU */
if (CPU_COUNT(cpuset) != 1)
return POSIX_ERRNO(EINVAL);
/* we only allow the current thread to sets its own affinity */
struct lthread *lt = (struct lthread *)thread;
if (lthread_current() != lt)
return POSIX_ERRNO(EINVAL);
/* determine the CPU being requested */
int i;
for (i = 0; i < LTHREAD_MAX_LCORES; i++) {
if (!CPU_ISSET(i, cpuset))
continue;
break;
}
/* check requested core is allowed */
if (i == LTHREAD_MAX_LCORES)
return POSIX_ERRNO(EINVAL);
/* finally we can set affinity to the requested lcore */
lthread_set_affinity(i);
return 0;
}
return _sys_pthread_funcs.f_pthread_setaffinity_np(thread, cpusetsize,
cpuset);
}
|