l4-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Task server thread and task allocation/deallocation interfaces proposal


From: Matthieu Lemerre
Subject: Task server thread and task allocation/deallocation interfaces proposal
Date: Fri, 04 Mar 2005 17:18:16 +0000
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

Hi,

I wrote some new RPC for the task server to implement task and thread
allocation and deletion. For the moment, I've written some code which
functionnaly works, but not always ideally (I didn't wrote a
cap_class_alloc function for instance).

I managed to create a new task, map memory in it and execute code, so
basically it works. Now we have to think about proper interfaces, so
that I can polish and finish it. Neal just told me that you already
had some ideas about it, so I write this as a beginning for finding
the good interfaces.

For basic operations we need the following operations:

***task_create(hurd_cap_handle_t current_task_handle,
             hurd_cap_handle_t *new_task_handle)

This create a new task, with just one thread, and creates an handle
associated with it so you can act on the task.

Task creation requires the following steps:
-creating a new inactive thread
-calling space_control on it
-Activating the thread, that is to say setting a pager for this thread.

Setting the pager can be done:
-By a separate RPC, task_set_pager(hurd_cap_handle_t task_handle,
                                   l4_thread_id_t pager,
                                   l4_thread_id_t thread).
                                   
(Eventually we could pass several thread to that RPC, although this is
not necessary because once the task is started, you can use a local
thread call the exchange_register system call to do this.
                                   
-In the task_create RPC.

-In the task_thread_alloc RPC, adding one argument to it.

I'm personnally in favor of the latest: currently task_thread_alloc
creates active thread with itself as its pager, which is not very
useful.

***task_terminate(hurd_cap_handle_t task_handle)

This RPC sends task death notification to each task which hold a task
info capability, and destroy all threads in the task, thus destroying
the address space.
It also record somewhere that the task_id is not used anymore.

*** task_thread_alloc(hurd_cap_handle_t task_handle,
                      l4_thread_id_t pager,
                      l4_word_t number_requested,
                      l4_word_t all_or_nothing,
                      l4_word_t *number_allocated,
                      l4_thread_id_t *thread_ids)

Neal wanted to alloc several threads at one time, so:

This allocates NUMBER threads, or less if the server cannot or does
not want (unless all_or_nothing is set, in which case no thread is
allocated). Every created thread has its pager set to PAGER.


THREAD_IDS will contain all the returned thread ids (passed in the
message register from task to the client).

*** task_thread_dealloc(hurd_cap_handle_t task_handle,
                        l4_word_t number,
                        l4_thread_id_t *thread_ids)

This destroy the threads and put the thread ids back in the free
thread ids list.
When there is only one thread left, the thread is not destroyed but
just inactivated. (And in thread_alloc, if there is nr_threads is 0,
the first thread is activated and the other allocated).




*On the implementation side, I suppose that we should use the
task_alloc, ... functions used in the cap_class.

So we should rename the task_alloc function currently written in
task_alloc_bootstrap or something like that. 

*Here is already some patches which are independant of the interface,
but needed for the task server:

-This one implements wortel_space_control in wortel:

2005-03-04  Matthieu Lemerre <address@hidden>

        * wortel.c (serve_bootstrap_requests): Implement reply to
        WORTEL_MSG_SPACE_CONTROL.
        
--- mainline/hurd-l4/wortel/wortel.c    2005-02-14 01:22:16.000000000 +0000
+++ hurd-l4/wortel/wortel.c     2005-02-27 22:54:37.000000000 +0000
@@ -1231,6 +1231,27 @@ serve_bootstrap_requests (void)
          l4_msg_load (msg);
          l4_reply (from);
        }
+      else if (label == WORTEL_MSG_SPACE_CONTROL)
+       {
+         if (l4_untyped_words (tag) != 5 || l4_typed_words (tag) != 0)
+           panic ("Invalid format of thread control msg");
+
+         l4_thread_id_t space = l4_msg_word (msg, 0);
+         l4_word_t control = l4_msg_word (msg, 1);
+         l4_fpage_t kip = l4_msg_word (msg, 2);
+         l4_fpage_t utcb = l4_msg_word (msg, 3);
+         l4_thread_id_t redirector = l4_msg_word (msg, 4);
+         l4_word_t ret;
+         l4_word_t old_control;
+
+         ret = l4_space_control (space, control, kip, utcb,
+                                 redirector, &old_control);
+         l4_msg_clear (msg);
+         l4_msg_append_word (msg, ret ? 0 : l4_error_code ());
+         l4_msg_append_word (msg, old_control);
+         l4_msg_load (msg);
+         l4_reply (from);
+       }
       else if (label == WORTEL_MSG_GET_TASK_CAP_REQUEST)
        {
          if (cur_task == (unsigned int) -1)

-This one puts more explicit descriptions in wortel.h (I have been
 confused, because it does not follow the manual, and I had to read
 the code to find out what ret was).

2005-03-04  Matthieu Lemerre <address@hidden>

        * wortel.h (wortel_thread_control, wortel_space_control): Changed
        to a more accurate description.
        
--- mainline/hurd-l4/wortel/wortel.h    2005-02-14 01:22:16.000000000 +0000
+++ hurd-l4/wortel/wortel.h     2005-02-26 22:11:01.000000000 +0000
@@ -70,7 +70,8 @@ extern wortel_cap_id_t wortel_cap_id;
 
 /* Privileged system calls.  */
 
-/* Like l4_thread_control.  */
+/* Like l4_thread_control, except that return value holds 0 if the
+   operation succeeded, the error code otherwise.  */
 static inline l4_word_t
 __attribute__((always_inline))
 wortel_thread_control (l4_thread_id_t dest, l4_thread_id_t space,
@@ -99,7 +100,8 @@ wortel_thread_control (l4_thread_id_t de
 }
 
 
-/* Like l4_space_control.  */
+/* Like l4_space_control, except that return value holds 0 if the
+   operation succeeded, the error code otherwise.  */
 static inline l4_word_t
 __attribute__((always_inline))
 wortel_space_control (l4_thread_id_t space, l4_word_t control,
-This one corrects a bug in the current thread_alloc function.

2005-03-04  Matthieu Lemerre <address@hidden>

        * task-class.c (task_alloc): Fix a bug when setting
        R_TASK->nr_threads

--- bak/hurd-l4/task/task-class.c       2005-03-04 17:11:11.000000000 +0000
+++ hurd-l4/task/task-class.c   2005-03-04 17:11:49.000000000 +0000
@@ -151,7 +151,8 @@ task_alloc (l4_word_t task_id, unsigned 
 
   /* Add the threads from back to front.  */
   task->threads = NULL;
-
+  task->nr_threads = nr_threads;
+  
   while (nr_threads--)
     {
       thread_t thread;
@@ -180,8 +181,7 @@ task_alloc (l4_word_t task_id, unsigned 
       thread->next = task->threads;
       task->threads = thread;
     }
-  task->nr_threads = nr_threads;
-
+  
   *r_task = task;
   return 0;
 }
Thanks,
Matthieu

reply via email to

[Prev in Thread] Current Thread [Next in Thread]