2 * Copyright (C) 2012 GRNET S.A.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 * kernel driver for pthread peers
24 #include <linux/module.h>
25 #include <linux/moduleparam.h>
26 #include <linux/init.h>
27 #include <linux/sched.h>
28 #include <linux/kernel.h>
29 #include <linux/slab.h>
31 #include <linux/errno.h>
32 #include <linux/timer.h>
33 #include <linux/types.h>
34 #include <linux/vmalloc.h>
35 #include <linux/genhd.h>
36 #include <linux/blkdev.h>
37 #include <linux/bio.h>
38 #include <linux/device.h>
39 #include <linux/completion.h>
41 #include <xseg/xseg.h>
42 #include <sys/kernel/segdev.h>
44 #include <xtypes/xpool.h>
45 #include <drivers/xseg_pthread.h>
47 MODULE_DESCRIPTION("xseg_pthread");
48 MODULE_AUTHOR("XSEG");
49 MODULE_LICENSE("GPL");
51 static int pthread_remote_signal_init(void)
56 static void pthread_remote_signal_quit(void)
61 static int pthread_local_signal_init(struct xseg *xseg, xport portno)
66 static void pthread_local_signal_quit(struct xseg *xseg, xport portno)
71 static int pthread_prepare_wait(struct xseg *xseg, uint32_t portno)
76 static int pthread_cancel_wait(struct xseg *xseg, uint32_t portno)
81 static int pthread_wait_signal(struct xseg *xseg, uint32_t timeout)
86 static int pthread_signal(struct xseg *xseg, uint32_t portno)
91 struct task_struct *task;
93 struct pthread_signal_desc *psd;
94 struct xseg_port *port = xseg_get_port(xseg, portno);
97 psd = xseg_get_signal_desc(xseg, port);
102 /* XXX Security: xseg peers can kill anyone */
104 for (i = 0; i < MAX_WAITERS; i++) {
110 /* no waiters found */
116 pid = find_vpid(cue);
119 task = pid_task(pid, PIDTYPE_PID);
123 ret = send_sig(SIGIO, task, 1);
129 static void *pthread_malloc(uint64_t size)
134 static void *pthread_realloc(void *mem, uint64_t size)
139 static void pthread_mfree(void *mem) { }
141 int pthread_init_signal_desc(struct xseg *xseg, void *sd)
146 void pthread_quit_signal_desc(struct xseg *xseg, void *sd)
151 void * pthread_alloc_data(struct xseg *xseg)
156 void pthread_free_data(struct xseg *xseg, void *data)
161 void *pthread_alloc_signal_desc(struct xseg *xseg, void *data)
166 void pthread_free_signal_desc(struct xseg *xseg, void *data, void *sd)
172 static struct xseg_peer xseg_peer_pthread = {
173 /* xseg signal operations */
175 .init_signal_desc = pthread_init_signal_desc,
176 .quit_signal_desc = pthread_quit_signal_desc,
177 .alloc_data = pthread_alloc_data,
178 .free_data = pthread_free_data,
179 .alloc_signal_desc = pthread_alloc_signal_desc,
180 .free_signal_desc = pthread_free_signal_desc,
181 .local_signal_init = pthread_local_signal_init,
182 .local_signal_quit = pthread_local_signal_quit,
183 .remote_signal_init = pthread_remote_signal_init,
184 .remote_signal_quit = pthread_remote_signal_quit,
185 .prepare_wait = pthread_prepare_wait,
186 .cancel_wait = pthread_cancel_wait,
187 .prepare_wait = pthread_prepare_wait,
188 .wait_signal = pthread_wait_signal,
189 .signal = pthread_signal,
190 .malloc = pthread_malloc,
191 .realloc = pthread_realloc,
192 .mfree = pthread_mfree
198 static int pthread_init(void)
202 XSEGLOG("registering xseg types");
204 r = xseg_register_peer(&xseg_peer_pthread);
209 static int pthread_quit(void)
211 xseg_unregister_peer(xseg_peer_pthread.name);
215 /* *************************** */
216 /* ** Module Initialization ** */
217 /* *************************** */
219 static int __init xseg_pthread_init(void)
223 ret = pthread_init();
227 XSEGLOG("initialization complete");
232 static void __exit xseg_pthread_exit(void)
237 module_init(xseg_pthread_init);
238 module_exit(xseg_pthread_exit);