mirror of https://github.com/F-Stack/f-stack.git
1. Fixed some issue that sem_timewait and sem_post.
2. Modify timeout of epoll_wait/kevent from 100us to 100ms by default. 3. set cpu affinity in main_stack_epoll_thread socket.
This commit is contained in:
parent
d3fabc9cef
commit
4af5a643fb
|
@ -1351,20 +1351,30 @@ ff_hook_epoll_wait(int epfd, struct epoll_event *events,
|
||||||
sc->ops = FF_SO_EPOLL_WAIT;
|
sc->ops = FF_SO_EPOLL_WAIT;
|
||||||
sc->args = args;
|
sc->args = args;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* sc->result, sc->error must reset in epoll_wait and kevent.
|
||||||
|
* Otherwise can access last sc call's result.
|
||||||
|
*
|
||||||
|
* Because if sem_timedwait timeouted, but fstack instance still
|
||||||
|
* call sem_post later, and next or next's next sem_timedwait will
|
||||||
|
* return 0 directly, then get invalid result and error.
|
||||||
|
*/
|
||||||
|
sc->result = 0;
|
||||||
|
sc->error = 0;
|
||||||
|
errno = 0;
|
||||||
if (timeout == 0) {
|
if (timeout == 0) {
|
||||||
need_alarm_sem = 1;
|
need_alarm_sem = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
RELEASE_ZONE_LOCK(FF_SC_REQ);
|
RELEASE_ZONE_LOCK(FF_SC_REQ);
|
||||||
|
|
||||||
errno = 0;
|
|
||||||
if (timeout > 0) {
|
if (timeout > 0) {
|
||||||
struct timespec abs_timeout;
|
struct timespec abs_timeout;
|
||||||
|
|
||||||
clock_gettime(CLOCK_REALTIME, &abs_timeout);
|
clock_gettime(CLOCK_REALTIME, &abs_timeout);
|
||||||
DEBUG_LOG("before wait, sec:%ld, nsec:%ld\n", abs_timeout.tv_sec, abs_timeout.tv_nsec);
|
DEBUG_LOG("before wait, sec:%ld, nsec:%ld\n", abs_timeout.tv_sec, abs_timeout.tv_nsec);
|
||||||
abs_timeout.tv_sec += timeout / 1000;
|
abs_timeout.tv_sec += timeout / 1000;
|
||||||
abs_timeout.tv_nsec += timeout * 1000;
|
abs_timeout.tv_nsec += timeout * 1000 * 1000;
|
||||||
if (abs_timeout.tv_nsec > NS_PER_SECOND) {
|
if (abs_timeout.tv_nsec > NS_PER_SECOND) {
|
||||||
abs_timeout.tv_nsec -= NS_PER_SECOND;
|
abs_timeout.tv_nsec -= NS_PER_SECOND;
|
||||||
abs_timeout.tv_sec += 1;
|
abs_timeout.tv_sec += 1;
|
||||||
|
@ -1535,16 +1545,27 @@ kevent(int kq, const struct kevent *changelist, int nchanges,
|
||||||
args->kq = kq;
|
args->kq = kq;
|
||||||
args->timeout = (struct timespec *)timeout;
|
args->timeout = (struct timespec *)timeout;
|
||||||
|
|
||||||
if (timeout == NULL) {
|
|
||||||
need_alarm_sem = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
rte_spinlock_lock(&sc->lock);
|
rte_spinlock_lock(&sc->lock);
|
||||||
|
|
||||||
sc->ops = FF_SO_KEVENT;
|
sc->ops = FF_SO_KEVENT;
|
||||||
sc->args = args;
|
sc->args = args;
|
||||||
sc->status = FF_SC_REQ;
|
sc->status = FF_SC_REQ;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* sc->result, sc->error must reset in epoll_wait and kevent.
|
||||||
|
* Otherwise can access last sc call's result.
|
||||||
|
*
|
||||||
|
* Because if sem_timedwait timeouted, but fstack instance still
|
||||||
|
* call sem_post later, and next or next's next sem_timedwait will
|
||||||
|
* return 0 directly, then get invalid result and error.
|
||||||
|
*/
|
||||||
|
sc->result = 0;
|
||||||
|
sc->error = 0;
|
||||||
|
errno = 0;
|
||||||
|
if (timeout == NULL) {
|
||||||
|
need_alarm_sem = 1;
|
||||||
|
}
|
||||||
|
|
||||||
rte_spinlock_unlock(&sc->lock);
|
rte_spinlock_unlock(&sc->lock);
|
||||||
|
|
||||||
if (timeout != NULL) {
|
if (timeout != NULL) {
|
||||||
|
|
|
@ -32,7 +32,8 @@ struct kevent events[MAX_EVENTS];
|
||||||
int kq;
|
int kq;
|
||||||
int sockfd;
|
int sockfd;
|
||||||
|
|
||||||
struct timespec timeout = {0, 100000};
|
/* 100 ms */
|
||||||
|
struct timespec timeout = {0, 100000000};
|
||||||
|
|
||||||
static int exit_flag = 0;
|
static int exit_flag = 0;
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,8 @@ pthread_t hworker[MAX_WORKERS];
|
||||||
pthread_spinlock_t worker_lock;
|
pthread_spinlock_t worker_lock;
|
||||||
#define MAX_EVENTS 512
|
#define MAX_EVENTS 512
|
||||||
|
|
||||||
struct timespec timeout = {0, 100000};
|
/* 100 ms */
|
||||||
|
struct timespec timeout = {0, 100000000};
|
||||||
|
|
||||||
static int exit_flag = 0;
|
static int exit_flag = 0;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue