Skip to content

Commit

Permalink
[cleanup] move threads_timer_res api to threads_common.c
Browse files Browse the repository at this point in the history
Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
  • Loading branch information
fabbione committed Jul 15, 2020
1 parent 72682b7 commit dfa3f44
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 69 deletions.
69 changes: 0 additions & 69 deletions libknet/handle.c
Expand Up @@ -1845,72 +1845,3 @@ int knet_handle_clear_stats(knet_handle_t knet_h, int clear_option)
pthread_rwlock_unlock(&knet_h->global_rwlock);
return 0;
}

int knet_handle_set_threads_timer_res(knet_handle_t knet_h,
useconds_t timeres)
{
int savederrno = 0;

if (!knet_h) {
errno = EINVAL;
return -1;
}

/*
* most threads use timeres / 1000 as timeout on epoll.
* anything below 1000 would generate a result of 0, making
* the threads spin at 100% cpu
*/
if ((timeres > 0) && (timeres < 1000)) {
errno = EINVAL;
return -1;
}

savederrno = get_global_wrlock(knet_h);
if (savederrno) {
log_err(knet_h, KNET_SUB_HANDLE, "Unable to get write lock: %s",
strerror(savederrno));
errno = savederrno;
return -1;
}

if (timeres) {
knet_h->threads_timer_res = timeres;
log_debug(knet_h, KNET_SUB_HANDLE, "Setting new threads timer resolution to %u usecs", knet_h->threads_timer_res);
} else {
knet_h->threads_timer_res = KNET_THREADS_TIMER_RES;
log_debug(knet_h, KNET_SUB_HANDLE, "Setting new threads timer resolution to default %u usecs", knet_h->threads_timer_res);
}

pthread_rwlock_unlock(&knet_h->global_rwlock);
return 0;
}

int knet_handle_get_threads_timer_res(knet_handle_t knet_h,
useconds_t *timeres)
{
int savederrno = 0;

if (!knet_h) {
errno = EINVAL;
return -1;
}

if (!timeres) {
errno = EINVAL;
return -1;
}

savederrno = pthread_rwlock_rdlock(&knet_h->global_rwlock);
if (savederrno) {
log_err(knet_h, KNET_SUB_HANDLE, "Unable to get read lock: %s",
strerror(savederrno));
errno = savederrno;
return -1;
}

*timeres = knet_h->threads_timer_res;

pthread_rwlock_unlock(&knet_h->global_rwlock);
return 0;
}
69 changes: 69 additions & 0 deletions libknet/threads_common.c
Expand Up @@ -247,3 +247,72 @@ void force_pmtud_run(knet_handle_t knet_h, uint8_t subsystem, uint8_t reset_mtu)
pthread_mutex_unlock(&knet_h->pmtud_mutex);
}
}

int knet_handle_set_threads_timer_res(knet_handle_t knet_h,
useconds_t timeres)
{
int savederrno = 0;

if (!knet_h) {
errno = EINVAL;
return -1;
}

/*
* most threads use timeres / 1000 as timeout on epoll.
* anything below 1000 would generate a result of 0, making
* the threads spin at 100% cpu
*/
if ((timeres > 0) && (timeres < 1000)) {
errno = EINVAL;
return -1;
}

savederrno = get_global_wrlock(knet_h);
if (savederrno) {
log_err(knet_h, KNET_SUB_HANDLE, "Unable to get write lock: %s",
strerror(savederrno));
errno = savederrno;
return -1;
}

if (timeres) {
knet_h->threads_timer_res = timeres;
log_debug(knet_h, KNET_SUB_HANDLE, "Setting new threads timer resolution to %u usecs", knet_h->threads_timer_res);
} else {
knet_h->threads_timer_res = KNET_THREADS_TIMER_RES;
log_debug(knet_h, KNET_SUB_HANDLE, "Setting new threads timer resolution to default %u usecs", knet_h->threads_timer_res);
}

pthread_rwlock_unlock(&knet_h->global_rwlock);
return 0;
}

int knet_handle_get_threads_timer_res(knet_handle_t knet_h,
useconds_t *timeres)
{
int savederrno = 0;

if (!knet_h) {
errno = EINVAL;
return -1;
}

if (!timeres) {
errno = EINVAL;
return -1;
}

savederrno = pthread_rwlock_rdlock(&knet_h->global_rwlock);
if (savederrno) {
log_err(knet_h, KNET_SUB_HANDLE, "Unable to get read lock: %s",
strerror(savederrno));
errno = savederrno;
return -1;
}

*timeres = knet_h->threads_timer_res;

pthread_rwlock_unlock(&knet_h->global_rwlock);
return 0;
}

0 comments on commit dfa3f44

Please sign in to comment.