Changeset 0a8f070 in mainline for uspace/lib/c


Ignore:
Timestamp:
2019-08-07T02:33:03Z (6 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
Children:
fe86d9d
Parents:
103939e
git-author:
Michal Koutný <xm.koutny+hos@…> (2015-08-16 16:04:14)
git-committer:
Matthieu Riolo <matthieu.riolo@…> (2019-08-07 02:33:03)
Message:

Create taskman server (extracts task-related operations from naming service)

  • Exploits initial phones connected to spawn parent instead of NS.
  • session_ns changed to session_primary (setup during taskman-loader handshake).
  • Task creation moved from NS to taskman (no clonable services anymore).
  • Other task-related operations implementation is to come (task_retval is temporarily dummy).
  • Async framework: implicit connections — create fibrils for calls that arrived through initial phone.

Conflicts:

abi/include/abi/ipc/methods.h
boot/Makefile.common
uspace/Makefile
uspace/app/trace/ipcp.c
uspace/lib/c/generic/async.c
uspace/lib/c/generic/libc.c
uspace/lib/c/generic/loader.c
uspace/lib/c/generic/ns.c
uspace/lib/c/generic/private/async.h
uspace/lib/c/generic/private/ns.h
uspace/lib/c/generic/task.c
uspace/lib/c/include/async.h
uspace/lib/c/include/ipc/services.h
uspace/lib/c/include/ipc/taskman.h
uspace/lib/c/include/loader/pcb.h
uspace/lib/c/include/ns.h
uspace/srv/loader/main.c
uspace/srv/ns/clonable.c
uspace/srv/ns/ns.c

Location:
uspace/lib/c
Files:
2 added
13 edited
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/Makefile

    r103939e r0a8f070  
    165165        generic/arg_parse.c \
    166166        generic/stats.c \
     167        generic/taskman.c \
    167168        generic/assert.c \
    168169        generic/bsearch.c \
  • uspace/lib/c/generic/async/client.c

    r103939e r0a8f070  
    124124static fibril_rmutex_t message_mutex;
    125125
    126 /** Naming service session */
    127 async_sess_t session_ns;
     126/** Primary session (spawn parent, later naming service) */
     127async_sess_t *session_primary = NULL;
    128128
    129129/** Message data */
     
    168168static FIBRIL_CONDVAR_INITIALIZE(avail_phone_cv);
    169169
     170
     171static async_sess_t *create_session_primary(void)
     172{
     173        async_sess_t *session = (async_sess_t *) malloc(sizeof(async_sess_t));
     174
     175        if (session != NULL) {
     176                session_ns->iface = 0;
     177                session->mgmt = EXCHANGE_ATOMIC;
     178                session->phone = PHONE_INITIAL;
     179                session->arg1 = 0;
     180                session->arg2 = 0;
     181                session->arg3 = 0;
     182               
     183                fibril_mutex_initialize(&session->remote_state_mtx);
     184                session->remote_state_data = NULL;
     185               
     186                list_initialize(&session->exch_list);
     187                fibril_mutex_initialize(&session->mutex);
     188                atomic_set(&session->refcnt, 0);
     189                &session.exchanges = 0;
     190        }
     191
     192        return session;
     193}
     194
     195
    170196/** Initialize the async framework.
    171197 *
    172198 */
    173 void __async_client_init(void)
     199void __async_client_init(async_sess_t *session)
    174200{
    175201        if (fibril_rmutex_initialize(&message_mutex) != EOK)
    176202                abort();
    177203
    178         session_ns.iface = 0;
    179         session_ns.mgmt = EXCHANGE_ATOMIC;
    180         session_ns.phone = PHONE_NS;
    181         session_ns.arg1 = 0;
    182         session_ns.arg2 = 0;
    183         session_ns.arg3 = 0;
    184 
    185         fibril_mutex_initialize(&session_ns.remote_state_mtx);
    186         session_ns.remote_state_data = NULL;
    187 
    188         list_initialize(&session_ns.exch_list);
    189         fibril_mutex_initialize(&session_ns.mutex);
    190         session_ns.exchanges = 0;
     204        if (session == NULL) {
     205                session_primary = create_session_primary();
     206        } else {
     207                session_primary = session;
     208        }
     209
     210        if (session_primary == NULL)
     211                abort();
    191212}
    192213
     
    807828        *out_phone = (cap_phone_handle_t) ipc_get_arg5(&result);
    808829        return EOK;
     830}
     831
     832/** Injects another session instead of original primary session
     833 *
     834 * @param  session  Session to naming service.
     835 *
     836 * @return old primary session (to spawn parent)
     837 */
     838async_sess_t *async_session_primary_swap(async_sess_t *session)
     839{
     840        assert(session_primary->phone == PHONE_INITIAL);
     841
     842        async_sess_t *old_primary = session_primary;
     843        session_primary = session;
     844        return old_primary;
    809845}
    810846
  • uspace/lib/c/generic/async/server.c

    r103939e r0a8f070  
    216216}
    217217
     218static async_client_conn_t implicit_connection = NULL;
    218219static fibril_rmutex_t client_mutex;
    219220static hash_table_t client_hash_table;
     
    964965        /* Route the call according to its request label */
    965966        errno_t rc = route_call(call);
    966         if (rc == EOK)
     967        if (rc == EOK) {
    967968                return;
     969        } else if (implicit_connection != NULL) {
     970                async_new_connection(call->in_task_id, call->in_phone_hash,
     971                    callid, call, implicit_connection, NULL);
     972                return;
     973        }
    968974
    969975        // TODO: Log the error.
  • uspace/lib/c/generic/libc.c

    r103939e r0a8f070  
    103103        }
    104104#endif
    105 
     105       
     106        /* Setup async framework */
    106107        __async_server_init();
    107         __async_client_init();
     108        if (__pcb == NULL) {
     109                __async_client_init(NULL);
     110        } else {
     111                __async_client_init(__pcb->session_primary);
     112        }
    108113        __async_ports_init();
    109114
  • uspace/lib/c/generic/loader.c

    r103939e r0a8f070  
    3333 */
    3434
     35#include <async.h>
     36#include <errno.h>
    3537#include <ipc/loader.h>
    3638#include <ipc/services.h>
     39#include <ipc/taskman.h>
     40#include <libc.h>
     41#include <loader/loader.h>
    3742#include <ns.h>
    38 #include <libc.h>
     43#include <stdlib.h>
     44#include <str.h>
    3945#include <task.h>
    40 #include <str.h>
    41 #include <stdlib.h>
    42 #include <async.h>
    43 #include <errno.h>
    4446#include <vfs/vfs.h>
    45 #include <loader/loader.h>
    4647#include "private/loader.h"
    4748
     
    6768
    6869        async_sess_t *sess =
    69             service_connect_blocking(SERVICE_LOADER, INTERFACE_LOADER, 0);
     70            service_connect_blocking(SERVICE_TASKMAN, TASKMAN_CONNECT_TO_LOADER, 0);
    7071        if (sess == NULL) {
    7172                free(ldr);
  • uspace/lib/c/generic/ns.c

    r103939e r0a8f070  
    4141
    4242/*
    43  * XXX ns does not know about session_ns, so we create an extra session for
     43 * XXX ns does not know about session_primary, so we create an extra session for
    4444 * actual communicaton
    4545 */
    46 static async_sess_t *sess_ns = NULL;
     46static async_sess_t *sess_primary = NULL;
    4747
    4848errno_t service_register(service_t service, iface_t iface,
    4949    async_port_handler_t handler, void *data)
    5050{
    51         async_sess_t *sess = ns_session_get();
     51        async_sess_t *sess = get_session_primary();
    5252        if (sess == NULL)
    5353                return EIO;
     
    8181        async_set_fallback_port_handler(handler, data);
    8282
    83         async_sess_t *sess = ns_session_get();
     83        async_sess_t *sess = get_session_primary();
    8484        if (sess == NULL)
    8585                return EIO;
     
    105105async_sess_t *service_connect(service_t service, iface_t iface, sysarg_t arg3)
    106106{
    107         async_sess_t *sess = ns_session_get();
     107        async_sess_t *sess = get_session_primary();
    108108        if (sess == NULL)
    109109                return NULL;
     
    133133    sysarg_t arg3)
    134134{
    135         async_sess_t *sess = ns_session_get();
     135        async_sess_t *sess = get_session_primary();
    136136        if (sess == NULL)
    137137                return NULL;
     
    157157errno_t ns_ping(void)
    158158{
    159         async_sess_t *sess = ns_session_get();
     159        async_sess_t *sess = get_session_primary();
    160160        if (sess == NULL)
    161161                return EIO;
     
    168168}
    169169
    170 errno_t ns_intro(task_id_t id)
    171 {
    172         async_exch_t *exch;
    173         async_sess_t *sess = ns_session_get();
    174         if (sess == NULL)
    175                 return EIO;
    176170
    177         exch = async_exchange_begin(sess);
    178         errno_t rc = async_req_2_0(exch, NS_ID_INTRO, LOWER32(id), UPPER32(id));
    179         async_exchange_end(exch);
    180 
    181         return rc;
    182 }
    183 
    184 async_sess_t *ns_session_get(void)
     171async_sess_t *get_session_primary(void)
    185172{
    186173        async_exch_t *exch;
    187174
    188         if (sess_ns == NULL) {
    189                 exch = async_exchange_begin(&session_ns);
    190                 sess_ns = async_connect_me_to(exch, 0, 0, 0);
     175        if (sess_primary == NULL) {
     176                exch = async_exchange_begin(&session_primary);
     177                sess_primary = async_connect_me_to(exch, 0, 0, 0);
    191178                async_exchange_end(exch);
    192                 if (sess_ns == NULL)
     179                if (sess_primary == NULL)
    193180                        return NULL;
    194181        }
    195182
    196         return sess_ns;
     183        return sess_primary;
    197184}
    198185
  • uspace/lib/c/generic/private/async.h

    r103939e r0a8f070  
    9696extern void __async_server_init(void);
    9797extern void __async_server_fini(void);
    98 extern void __async_client_init(void);
     98extern void __async_client_init(async_sess_t *);
    9999extern void __async_client_fini(void);
    100100extern void __async_ports_init(void);
  • uspace/lib/c/generic/private/ns.h

    r103939e r0a8f070  
    3838#include <async.h>
    3939
    40 extern async_sess_t session_ns;
     40extern async_sess_t *session_primary;
    4141
    4242#endif
  • uspace/lib/c/generic/task.c

    r103939e r0a8f070  
    325325errno_t task_setup_wait(task_id_t id, task_wait_t *wait)
    326326{
    327         async_sess_t *sess_ns = ns_session_get();
     327        async_sess_t *sess_ns = get_session_primary();
    328328        if (sess_ns == NULL)
    329329                return EIO;
    330330
    331331        async_exch_t *exch = async_exchange_begin(sess_ns);
     332
    332333        wait->aid = async_send_2(exch, NS_TASK_WAIT, LOWER32(id), UPPER32(id),
    333334            &wait->result);
     
    407408errno_t task_retval(int val)
    408409{
    409         async_sess_t *sess_ns = ns_session_get();
     410        async_sess_t *sess_ns = get_session_primary();
    410411        if (sess_ns == NULL)
    411412                return EIO;
  • uspace/lib/c/include/async.h

    r103939e r0a8f070  
    131131extern void *async_get_client_data_by_id(task_id_t);
    132132extern void async_put_client_data_by_id(task_id_t);
     133
     134extern void async_set_implicit_connection(async_client_conn_t);
    133135
    134136extern errno_t async_create_port(iface_t, async_port_handler_t, void *,
     
    274276extern sysarg_t async_get_label(void);
    275277
     278extern async_sess_t *async_session_primary_swap(async_sess_t *);
    276279extern async_sess_t *async_connect_me_to(async_exch_t *, iface_t, sysarg_t,
    277280    sysarg_t);
  • uspace/lib/c/include/ipc/services.h

    r103939e r0a8f070  
    4343typedef enum {
    4444        SERVICE_NONE       = 0,
    45         SERVICE_LOADER     = FOURCC('l', 'o', 'a', 'd'),
    4645        SERVICE_VFS        = FOURCC('v', 'f', 's', ' '),
    4746        SERVICE_LOC        = FOURCC('l', 'o', 'c', ' '),
    4847        SERVICE_SYSMAN     = FOURCC('s', 'y', 's', 'm'),
     48        SERVICE_TASKMAN    = FOURCC('t', 's', 'k', 'm'),
    4949        SERVICE_LOGGER     = FOURCC('l', 'o', 'g', 'g'),
    5050        SERVICE_DEVMAN     = FOURCC('d', 'e', 'v', 'n'),
  • uspace/lib/c/include/ipc/taskman.h

    r103939e r0a8f070  
    11/*
    2  * Copyright (c) 2009 Martin Decky
     2 * Copyright (c) 2015 Michal Koutny
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup ns
     29/** @addtogroup libcipc
    3030 * @{
    3131 */
     32/** @file
     33 */
    3234
    33 #ifndef NS_CLONABLE_H__
    34 #define NS_CLONABLE_H__
     35#ifndef LIBC_IPC_TASKMAN_H_
     36#define LIBC_IPC_TASKMAN_H_
    3537
    3638#include <ipc/common.h>
    37 #include <ipc/services.h>
    38 #include <abi/ipc/interfaces.h>
    39 #include <stdbool.h>
    4039
    41 extern errno_t ns_clonable_init(void);
    4240
    43 extern bool ns_service_is_clonable(service_t, iface_t);
    44 extern void ns_clonable_register(ipc_call_t *);
    45 extern void ns_clonable_forward(service_t, iface_t, ipc_call_t *);
     41typedef enum {
     42        TASKMAN_HELLO = IPC_FIRST_USER_METHOD,
     43} taskman_request_t;
     44
     45typedef enum {
     46        TASKMAN_CONNECT_TO_LOADER = 0,
     47        TASKMAN_LOADER_TO_NS,
     48        TASKMAN_LOADER_CALLBACK,
     49        TASKMAN_CONTROL
     50} taskman_interface_t;
    4651
    4752#endif
    4853
    49 /**
    50  * @}
     54/** @}
    5155 */
  • uspace/lib/c/include/loader/pcb.h

    r103939e r0a8f070  
    4646};
    4747
     48/* Forward declaration */
     49struct async_sess;
     50typedef struct async_sess async_sess_t;
     51
    4852/** Program Control Block.
    4953 *
     
    5761        entry_point_t entry;
    5862
     63        /** Primary session to broker. */
     64        async_sess_t *session_primary;
     65       
    5966        /** Current working directory. */
    6067        char *cwd;
  • uspace/lib/c/include/ns.h

    r103939e r0a8f070  
    4747
    4848extern errno_t ns_ping(void);
    49 extern errno_t ns_intro(task_id_t);
    5049extern async_sess_t *ns_session_get(void);
    5150
Note: See TracChangeset for help on using the changeset viewer.