EPICS Multi-Core Utilities  1.2.2-SNAPSHOT
Real-Time Utilities for EPICS IOCs on Multi-Core Linux
 All Files Functions Variables Typedefs Macros Groups Pages
shellCommands.c
Go to the documentation of this file.
1 /********************************************/
12 #include <unistd.h>
13 #include <stdlib.h>
14 
15 #include <iocsh.h>
16 #include <epicsExport.h>
17 #include <epicsThread.h>
18 
19 #include "mcoreutils.h"
20 
26 static epicsThreadId getThreadIdFor(const char* thread) {
27  const char *cp;
28  epicsThreadId tid;
29  unsigned long ltmp;
30  char *endp;
31 
32  if (!thread) return 0;
33  cp = thread;
34  ltmp = strtoul(cp, &endp, 0);
35  if (*endp) {
36  tid = epicsThreadGetId(cp);
37  if (!tid) {
38  printf("*** %s is not a valid thread name ***\n", cp);
39  }
40  }
41  else {
42  tid = (epicsThreadId) ltmp;
43  }
44  return tid;
45 }
46 
47 static const iocshArg mcoreThreadShowArg0 = {"thread", iocshArgString};
48 static const iocshArg mcoreThreadShowArg1 = {"level", iocshArgInt};
49 static const iocshArg *const mcoreThreadShowArgs[] = {
50  &mcoreThreadShowArg0,
51  &mcoreThreadShowArg1,
52 };
53 static const iocshFuncDef mcoreThreadShowDef =
54  {"mcoreThreadShow", 2, mcoreThreadShowArgs};
55 static void mcoreThreadShowCall(const iocshArgBuf * args) {
56  epicsThreadId tid;
57  unsigned int level = args[1].ival;
58  if (!args[0].sval) {
59  printf("Missing argument\nUsage: mcoreThreadShow thread [level]\n");
60  return;
61  }
62  tid = getThreadIdFor(args[0].sval);
63  if (tid) {
64  mcoreThreadShow( 0, level);
65  mcoreThreadShow(tid, level);
66  }
67 }
68 
69 static const iocshArg mcoreThreadShowAllArg0 = {"level", iocshArgInt};
70 static const iocshArg *const mcoreThreadShowAllArgs[] = {
71  &mcoreThreadShowAllArg0,
72 };
73 static const iocshFuncDef mcoreThreadShowAllDef =
74  {"mcoreThreadShowAll", 1, mcoreThreadShowAllArgs};
75 static void mcoreThreadShowAllCall(const iocshArgBuf * args) {
76  unsigned int level = args[0].ival;
77  mcoreThreadShowAll(level);
78 }
79 
80 static const iocshArg mcoreThreadRuleAddArg0 = {"name", iocshArgString};
81 static const iocshArg mcoreThreadRuleAddArg1 = {"policy", iocshArgString};
82 static const iocshArg mcoreThreadRuleAddArg2 = {"priority", iocshArgString};
83 static const iocshArg mcoreThreadRuleAddArg3 = {"cpuset", iocshArgString};
84 static const iocshArg mcoreThreadRuleAddArg4 = {"pattern", iocshArgString};
85 static const iocshArg *const mcoreThreadRuleAddArgs[] = {
86  &mcoreThreadRuleAddArg0,
87  &mcoreThreadRuleAddArg1,
88  &mcoreThreadRuleAddArg2,
89  &mcoreThreadRuleAddArg3,
90  &mcoreThreadRuleAddArg4,
91 };
92 static const iocshFuncDef mcoreThreadRuleAddDef =
93  {"mcoreThreadRuleAdd", 5, mcoreThreadRuleAddArgs};
94 static void mcoreThreadRuleAddCall(const iocshArgBuf * args) {
95  int i;
96  char missing = 0;
97  for (i=0; i<5; i++) {
98  if (NULL == args[i].sval) missing |= 1;
99  }
100  if (missing) {
101  printf("Missing argument\nUsage: mcoreThreadRuleAdd name policy priority cpuset pattern\n");
102  return;
103  }
104  mcoreThreadRuleAdd(args[0].sval, args[1].sval, args[2].sval, args[3].sval, args[4].sval);
105 }
106 
107 static const iocshArg mcoreThreadRuleDeleteArg0 = {"name", iocshArgString};
108 static const iocshArg *const mcoreThreadRuleDeleteArgs[] = {
109  &mcoreThreadRuleDeleteArg0,
110 };
111 static const iocshFuncDef mcoreThreadRuleDeleteDef =
112  {"mcoreThreadRuleDelete", 1, mcoreThreadRuleDeleteArgs};
113 static void mcoreThreadRuleDeleteCall(const iocshArgBuf * args) {
114  if (NULL == args[0].sval) {
115  printf("Missing argument\nUsage: mcoreThreadRuleDelete name\n");
116  return;
117  }
118  mcoreThreadRuleDelete(args[0].sval);
119 }
120 
121 static const iocshFuncDef mcoreThreadRulesShowDef =
122  {"mcoreThreadRulesShow", 0, NULL};
123 static void mcoreThreadRulesShowCall(const iocshArgBuf * args) {
125 }
126 
127 static const iocshArg mcoreThreadModifyArg0 = {"thread", iocshArgString};
128 static const iocshArg mcoreThreadModifyArg1 = {"policy", iocshArgString};
129 static const iocshArg mcoreThreadModifyArg2 = {"priority", iocshArgString};
130 static const iocshArg mcoreThreadModifyArg3 = {"cpuset", iocshArgString};
131 static const iocshArg *const mcoreThreadModifyArgs[] = {
132  &mcoreThreadModifyArg0,
133  &mcoreThreadModifyArg1,
134  &mcoreThreadModifyArg2,
135  &mcoreThreadModifyArg3,
136 };
137 static const iocshFuncDef mcoreThreadModifyDef =
138  {"mcoreThreadModify", 4, mcoreThreadModifyArgs};
139 static void mcoreThreadModifyCall(const iocshArgBuf * args) {
140  epicsThreadId tid;
141  int i;
142  char missing = 0;
143 
144  for (i = 0; i < 4; i++) {
145  if (NULL == args[i].sval) missing |= 1;
146  }
147  if (missing) {
148  printf("Missing argument\nUsage: mcoreThreadModify thread policy priority cpuset\n");
149  return;
150  }
151  tid = getThreadIdFor(args[0].sval);
152  if (tid)
153  mcoreThreadModify(tid, args[1].sval, args[2].sval, args[3].sval);
154 }
155 
156 static const iocshFuncDef mcoreMLockDef =
157  {"mcoreMLock", 0, NULL};
158 static void mcoreMLockCall(const iocshArgBuf * args) {
159  mcoreMLock();
160 }
161 
162 static const iocshFuncDef mcoreMUnlockDef =
163  {"mcoreMUnlock", 0, NULL};
164 static void mcoreMUnlockCall(const iocshArgBuf * args) {
165  mcoreMUnlock();
166 }
167 
168 static void mcoreRegister(void)
169 {
170  static int firstTime = 1;
171  if(!firstTime) return;
172  firstTime = 0;
173 
176  iocshRegister(&mcoreThreadShowDef, mcoreThreadShowCall);
177  iocshRegister(&mcoreThreadShowAllDef, mcoreThreadShowAllCall);
178  iocshRegister(&mcoreThreadRuleAddDef, mcoreThreadRuleAddCall);
179  iocshRegister(&mcoreThreadRuleDeleteDef, mcoreThreadRuleDeleteCall);
180  iocshRegister(&mcoreThreadRulesShowDef, mcoreThreadRulesShowCall);
181  iocshRegister(&mcoreThreadModifyDef, mcoreThreadModifyCall);
182  iocshRegister(&mcoreMLockDef, mcoreMLockCall);
183  iocshRegister(&mcoreMUnlockDef, mcoreMUnlockCall);
184 }
186 epicsExportRegistrar(mcoreRegister);