Commit 94aacc1c authored by Maria Matejka's avatar Maria Matejka
Browse files

Worker: The task-local linpool

parent 8a65b607
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ extern _Thread_local u64 worker_id;

#define SPIN_INIT(_sp) atomic_store_explicit(&(_sp), NOWORKER, memory_order_relaxed);

/* Locked typed linked list */

#define LOCKED_LIST(_type) struct { \
  TLIST(_type) _llist; \
+2 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

struct config;

extern _Thread_local linpool *task_pool;

struct semaphore *semaphore_new(pool *p, uint n);
void semaphore_wait(struct semaphore *s);
void semaphore_post(struct semaphore *s);
+79 −71
Original line number Diff line number Diff line
@@ -1009,6 +1009,9 @@ extern _Thread_local struct timeloop *timeloop_current;
/* There has been a tail-task queued without trying the available semaphore. */
_Thread_local _Bool tail_task = 1;

/* Pool for allocating data during task run. */
_Thread_local linpool *task_pool;

static void *
worker_loop(void *_data UNUSED)
{
@@ -1024,6 +1027,9 @@ worker_loop(void *_data UNUSED)
  cpu_stat_init();
#endif

  /* Initialize the task-local linpool */
  task_pool = lp_new_default(&root_pool);

  /* Obtain the yield-semaphore before being available */
  WORKER_CONTINUE();

@@ -1090,8 +1096,9 @@ worker_loop(void *_data UNUSED)
    WQ_LOCK();

    /* Is there a pending task? */
    if (!EMPTY_LIST(wq->pending))
    {
    if (EMPTY_LIST(wq->pending))
      break;

    /* Retrieve that task */
    struct task *t = HEAD(wq->pending);
    rem_node(&t->n);
@@ -1145,15 +1152,17 @@ worker_loop(void *_data UNUSED)

    else
    {
	WQ_STATELOG_TASK_EXPLICIT(WQS_TASK_BLOCKED, tf, d, te);
      }

      /* Else: Unavailable. The task has been stored
       * into the blocked list and will be released
       * when the lock is available. */
      WQ_STATELOG_TASK_EXPLICIT(WQS_TASK_BLOCKED, tf, d, te);
    }
    else
    {

    /* Cleanup after executing the task */
    lp_flush(task_pool);
  }

  /* There is no task in queue */
  WQ_UNLOCK();

  /* There must be a request to stop then */
@@ -1175,13 +1184,12 @@ worker_loop(void *_data UNUSED)
  /* Notify the stop requestor */
  SEM_POST(&wq->stopped);

  /* Free the task-local linpool */
  rfree(task_pool);

  /* Finished */
  return NULL;
}
  }
 
  wimpossible(); 
}

static int
worker_start(void)