Krishna iResearch Intelligent Cloud Platform - VIRtual Generic Os - VIRGO - Linux kernel extensions for cloud
 All Classes
virgo_queue.c
1 /***************************************************************************************
2 VIRGO - a linux module extension with CPU and Memory pooling with cloud capabilities
3 
4 
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18 --------------------------------------------------------------------------------------------------
19 Copyright (C):
20 Srinivasan Kannan (alias) Ka.Shrinivaasan (alias) Shrinivas Kannan
21 Independent Open Source Developer, Researcher and Consultant
22 Ph: 9789346927, 9003082186, 9791165980
23 Open Source Products Profile(Krishna iResearch):
24 http://sourceforge.net/users/ka_shrinivaasan,
25 https://www.ohloh.net/accounts/ka_shrinivaasan
26 Personal website(research): https://sites.google.com/site/kuja27/
27 emails: ka.shrinivaasan@gmail.com, shrinivas.kannan@gmail.com, kashrinivaasan@live.com
28 --------------------------------------------------------------------------------------------------
29 
30 *****************************************************************************************/
31 
32 /*
33  A standalone Queueing Driver implementation which either uses a kernel workqueue or a naive local queue
34  that can be used for VIRGO CPU and Memory pooling Drivers requests and
35  KingCobra byzantine request servicing pub-sub model
36 */
37 
38 #include <linux/virgo_queue.h>
39 
40 
41 static int __init virgo_queue_init()
42 {
43  /* native queue initialization */
44  virgo_request_queue=kmalloc(VIRGO_QUEUE_SZ, GFP_ATOMIC);
45 
46  /* Linux workqueue has to be differently queued-in and there need not be any explicit push and pop */
47  if(use_workqueue)
48  {
49  printk(KERN_INFO "virgo_queue_init(): use_workqueue=1");
50  if(virgo_kernel_wq==NULL)
51  {
52  printk(KERN_INFO "virgo_queue_init(): use_workqueue=1, virgo_kernel_wq=NULL, creating a kernel workqueue\n");
53  virgo_kernel_wq = create_workqueue("virgo_kernel_workqueue");
54  }
55  /*
56  printk(KERN_INFO "virgo_queue_init(): use_workqueue=1, enqueueing work %p to kernel workqueue\n",&virgo_work);
57  queue_work(virgo_kernel_wq, &virgo_work);
58  */
59  }
60 
61  /*
62  struct virgo_request r1;
63  r1.data=kstrdup("example virgo queue element 1",GFP_ATOMIC);
64  r1.next=NULL;
65  push_request(&r1);
66  */
67 
68  /*
69  / Simple push-pop test /
70  printk(KERN_INFO "virgo_queue_init(): pushed element to native virgo_queue: %s\n",r1.data);
71  struct virgo_request *r2=pop_request();
72  printk(KERN_INFO "virgo_queue_init(): popped element from native virgo_queue: %s\n",r2->data);
73  */
74 
75  /* Example KingCobra ServiceRequest /
76  struct virgo_request r3;
77  r3.data=kstrdup("KingCobra: example service request",GFP_ATOMIC);
78  r3.next=NULL;
79  push_request(&r3);
80  */
81 
82  return 0;
83 }
84 
85 void push_request(struct virgo_request* req)
86 {
87  if(use_workqueue)
88  {
89  struct virgo_workqueue_request *vwqreq=kmalloc(sizeof(struct virgo_workqueue_request),GFP_ATOMIC);
90  vwqreq->data=kstrdup(req->data,GFP_ATOMIC);
91  printk(KERN_INFO "push_request(): use_workqueue=1, enqueueing req in the kernel workqueue which will invoke handler, req->data = %s, vwqreq->work=%p, vwqreq->data = %s\n",req->data, &(vwqreq->work), vwqreq->data);
92  INIT_WORK(&(vwqreq->work),virgo_workqueue_handler);
93  queue_work(virgo_kernel_wq,&(vwqreq->work));
94  }
95  else
96  {
97  virgo_request_queue[queue_end].data=kstrdup(req->data,GFP_ATOMIC);
98  virgo_request_queue[queue_end].next=req->next;
99  queue_end++;
100  }
101 }
102 EXPORT_SYMBOL(push_request);
103 
104 struct virgo_request* pop_request()
105 {
106  return &virgo_request_queue[queue_front];
107  queue_front++;
108 }
109 EXPORT_SYMBOL(pop_request);
110 
111 static void __exit virgo_queue_exit()
112 {
113  do_exit(1);
114 }
115 
116 MODULE_LICENSE("GPL");
117 module_init(virgo_queue_init);
118 module_exit(virgo_queue_exit);