source: mainline/uspace/lib/c/generic/taskman.c@ 4667b5c

Last change on this file since 4667b5c was 4667b5c, checked in by Matthieu Riolo <matthieu.riolo@…>, 6 years ago

taskman: Add method to dump events of already running tasks

It's crafted for early startup of sysman.

  • Property mode set to 100644
File size: 4.5 KB
RevLine 
[40313e4]1/*
[0a8f070]2 * Copyright (c) 2015 Michal Koutny
[40313e4]3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
[0a8f070]29/** @addtogroup libc
[40313e4]30 * @{
31 */
[0a8f070]32/** @file
33 */
34
[012dd8e]35
36#include <async.h>
[0a8f070]37#include <errno.h>
[012dd8e]38#include <ipc/common.h>
[0a8f070]39#include <ipc/taskman.h>
[012dd8e]40#include <task.h>
[0a8f070]41#include <taskman.h>
42
[012dd8e]43#include "private/async.h"
44#include "private/taskman.h"
[0a8f070]45
[012dd8e]46async_sess_t *session_taskman = NULL;
[0a8f070]47
[4667b5c]48/*
49 * Private functions
50 */
51
[012dd8e]52void __task_init(async_sess_t *sess)
53{
54 assert(session_taskman == NULL);
55 session_taskman = sess;
56}
57
58async_exch_t *taskman_exchange_begin(void)
59{
60 assert(session_taskman);
61
62 async_exch_t *exch = async_exchange_begin(session_taskman);
63 return exch;
64}
65
66void taskman_exchange_end(async_exch_t *exch)
[0a8f070]67{
68 async_exchange_end(exch);
[012dd8e]69}
[0a8f070]70
[012dd8e]71/** Wrap PHONE_INITIAL with session and introduce to taskman
72 */
73async_sess_t *taskman_connect(void)
74{
75 /*
76 * EXCHANGE_ATOMIC would require single calls only,
77 * EXCHANGE_PARALLEL not sure about implementation via multiple phones,
78 * >EXCHANGE_SERIALIZE perhaphs no harm, except the client serialization
79 */
80 const exch_mgmt_t mgmt = EXCHANGE_SERIALIZE;
81 async_sess_t *sess = create_session(PHONE_INITIAL, mgmt, 0, 0, 0);
82
83 if (sess != NULL) {
84 /* Introduce ourselves and ignore answer */
85 async_exch_t *exch = async_exchange_begin(sess);
86 aid_t req = async_send_0(exch, TASKMAN_NEW_TASK, NULL);
87 async_exchange_end(exch);
88
89 if (req) {
90 async_forget(req);
91 }
92 }
93
94 return sess;
[0a8f070]95}
[40313e4]96
[012dd8e]97/** Ask taskman to pass/share its NS */
98async_sess_t *taskman_session_ns(void)
[0a8f070]99{
[012dd8e]100 assert(session_taskman);
101
102 async_exch_t *exch = async_exchange_begin(session_taskman);
103 assert(exch);
104
105 async_sess_t *sess = async_connect_me_to(EXCHANGE_ATOMIC,
106 exch, TASKMAN_CONNECT_TO_NS, 0, 0);
[0a8f070]107 async_exchange_end(exch);
[40313e4]108
[012dd8e]109 return sess;
[0a8f070]110}
111
[012dd8e]112/** Ask taskman to connect to (a new) loader instance */
113async_sess_t *taskman_session_loader(void)
114{
115 assert(session_taskman);
116
117 async_exch_t *exch = async_exchange_begin(session_taskman);
118 async_sess_t *sess = async_connect_me_to(EXCHANGE_SERIALIZE,
119 exch, TASKMAN_CONNECT_TO_LOADER, 0, 0);
120 async_exchange_end(exch);
121
122 return sess;
123}
124
[4667b5c]125/*
126 * Public functions
127 */
128
129int taskman_dump_events(void)
130{
131 assert(session_taskman);
132
133 async_exch_t *exch = async_exchange_begin(session_taskman);
134 int rc = async_req_0_0(exch, TASKMAN_DUMP_EVENTS);
135 taskman_exchange_end(exch);
136
137 return rc;
138}
139
140async_sess_t *taskman_get_session(void)
141{
142 return session_taskman;
143}
144
[012dd8e]145/** Introduce as loader to taskman
[0a8f070]146 *
[012dd8e]147 * @return EOK on success, otherwise propagated error code
148 */
149int taskman_intro_loader(void)
150{
151 assert(session_taskman);
152
153 async_exch_t *exch = async_exchange_begin(session_taskman);
154 int rc = async_connect_to_me(
155 exch, TASKMAN_LOADER_CALLBACK, 0, 0, NULL, NULL);
156 async_exchange_end(exch);
157
158 return rc;
159}
160
161/** Tell taskman we are his NS
[0a8f070]162 *
[012dd8e]163 * @return EOK on success, otherwise propagated error code
[0a8f070]164 */
[012dd8e]165int taskman_intro_ns(void)
[0a8f070]166{
[012dd8e]167 assert(session_taskman);
168
169 async_exch_t *exch = async_exchange_begin(session_taskman);
170 aid_t req = async_send_0(exch, TASKMAN_I_AM_NS, NULL);
171
172 int rc = async_connect_to_me(exch, 0, 0, 0, NULL, NULL);
173 taskman_exchange_end(exch);
174
[0a8f070]175 if (rc != EOK) {
[012dd8e]176 return rc;
[0a8f070]177 }
[40313e4]178
[012dd8e]179 sysarg_t retval;
180 async_wait_for(req, &retval);
181 return retval;
182}
[40313e4]183
[012dd8e]184
185
[0a8f070]186/** @}
[40313e4]187 */
Note: See TracBrowser for help on using the repository browser.