source: mainline/uspace/lib/c/generic/taskman.c@ bb57a00

Last change on this file since bb57a00 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
Line 
1/*
2 * Copyright (c) 2015 Michal Koutny
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
29/** @addtogroup libc
30 * @{
31 */
32/** @file
33 */
34
35
36#include <async.h>
37#include <errno.h>
38#include <ipc/common.h>
39#include <ipc/taskman.h>
40#include <task.h>
41#include <taskman.h>
42
43#include "private/async.h"
44#include "private/taskman.h"
45
46async_sess_t *session_taskman = NULL;
47
48/*
49 * Private functions
50 */
51
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)
67{
68 async_exchange_end(exch);
69}
70
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;
95}
96
97/** Ask taskman to pass/share its NS */
98async_sess_t *taskman_session_ns(void)
99{
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);
107 async_exchange_end(exch);
108
109 return sess;
110}
111
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
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
145/** Introduce as loader to taskman
146 *
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
162 *
163 * @return EOK on success, otherwise propagated error code
164 */
165int taskman_intro_ns(void)
166{
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
175 if (rc != EOK) {
176 return rc;
177 }
178
179 sysarg_t retval;
180 async_wait_for(req, &retval);
181 return retval;
182}
183
184
185
186/** @}
187 */
Note: See TracBrowser for help on using the repository browser.