Skip to content

Commit

Permalink
lkl: Warn if lkl_create_syscall_thread seems unproperly used
Browse files Browse the repository at this point in the history
  • Loading branch information
phhusson committed Feb 25, 2016
1 parent 853beba commit e7c521a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
2 changes: 2 additions & 0 deletions arch/lkl/include/uapi/asm/host_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ struct lkl_sem_t;
* @sem_free - free a host semaphore
* @sem_up - perform an up operation on the semaphore
* @sem_down - perform a down operation on the semaphore
* @sem_get - return the current value of semahpore. To be used only for sanity checking
*
* @mutex_alloc - allocate and initialize a host mutex
* @mutex_free - free a host mutex
Expand Down Expand Up @@ -66,6 +67,7 @@ struct lkl_host_operations {
void (*sem_free)(struct lkl_sem_t *sem);
void (*sem_up)(struct lkl_sem_t *sem);
void (*sem_down)(struct lkl_sem_t *sem);
int (*sem_get)(struct lkl_sem_t *sem);

struct lkl_mutex_t *(*mutex_alloc)(void);
void (*mutex_free)(struct lkl_mutex_t *mutex);
Expand Down
24 changes: 21 additions & 3 deletions arch/lkl/kernel/syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,31 @@ static int syscall_thread_data_init(struct syscall_thread_data *data,
return 0;
}

long lkl_syscall(long no, long *params)
{
static struct syscall_thread_data *lkl_syscall_data(void) {
struct syscall_thread_data *data = NULL;
struct syscall s;

if (lkl_ops->tls_get)
data = lkl_ops->tls_get(syscall_thread_data_key);
if (!data)
data = &default_syscall_thread_data;

return data;
}

static int lkl_syscall_wouldblock(void) {
struct syscall_thread_data *data = lkl_syscall_data();

if(!lkl_ops->sem_get)
return 0;

return !lkl_ops->sem_get(data->mutex);
}

long lkl_syscall(long no, long *params)
{
struct syscall_thread_data *data = lkl_syscall_data();
struct syscall s;

s.no = no;
s.params = params;

Expand Down Expand Up @@ -196,6 +211,9 @@ int lkl_create_syscall_thread(void)
return ret;
}

if(lkl_syscall_wouldblock())
pr_warn("lkl: Calling lkl_create_syscall_thread will block\n");

params[0] = (long)data;
ret = lkl_syscall(__NR_create_syscall_thread, params);
if (ret < 0) {
Expand Down
12 changes: 12 additions & 0 deletions tools/lkl/lib/posix-host.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,17 @@ static void sem_down(struct lkl_sem_t *sem)
#endif /* _POSIX_SEMAPHORES */
}

static int sem_get(struct lkl_sem_t *sem) {
int v = 0;
#ifdef _POSIX_SEMAPHORES
WARN_UNLESS(sem_getvalue(&sem->sem, &v));
#else
WARN_PTHREAD(pthread_mutex_lock(&sem->lock));
v = sem->count;
WARN_PTHREAD(pthread_mutex_unlock(&sem->lock));
#endif /* _POSIX_SEMAPHORES */
return v;
}

static struct lkl_mutex_t *mutex_alloc(void)
{
Expand Down Expand Up @@ -268,6 +279,7 @@ struct lkl_host_operations lkl_host_ops = {
.sem_free = sem_free,
.sem_up = sem_up,
.sem_down = sem_down,
.sem_get = sem_get,
.mutex_alloc = mutex_alloc,
.mutex_free = mutex_free,
.mutex_lock = mutex_lock,
Expand Down

0 comments on commit e7c521a

Please sign in to comment.