01: //
02: // Copyright (C) 2005 United States Government as represented by the
03: // Administrator of the National Aeronautics and Space Administration
04: // (NASA). All Rights Reserved.
05: //
06: // This software is distributed under the NASA Open Source Agreement
07: // (NOSA), version 1.3. The NOSA has been approved by the Open Source
08: // Initiative. See the file NOSA-1.3-JPF at the top of the distribution
09: // directory tree for the complete NOSA document.
10: //
11: // THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
12: // KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
13: // LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
14: // SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
15: // A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
16: // THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
17: // DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
18: //
19: package DEOS;
20:
21: /**
22: * DOCUMENT ME!
23: */
24: class DEOSProcess {
25: static ProcessConstraint itsProcessConstraint;
26: static Thread itsMainThread;
27: int cpuUtilization = Registry.uSecsInFastestPeriod;
28:
29: public DEOSProcess() {
30: //System.out.println("Process Constructor");
31: itsMainThread = new Thread("main");
32: itsMainThread.setCPUBudget(Registry.uSecsInFastestPeriod);
33: itsMainThread.ConceptualObjectConstructor(0);
34: itsProcessConstraint = new ProcessConstraint(cpuUtilization);
35: }
36:
37: // note - had to change this code because you can't pass an integer
38: // by reference in Java - so not, it returns -1 where it used to
39: // return false. the code in DEOSKernel.java (schedk.cpp) has also
40: // been changed to reflect this. -jp
41: public static int allocateCPUBudgetForThread(Thread theThread,
42: int requestedBudget, int periodIndex) {
43: //System.out.println("Process.allocateCPUBudgetForThread");
44: int grantedCPU;
45:
46: if (theThread == itsMainThread) {
47: return itsMainThread.cpuBudget();
48: }
49:
50: boolean result = itsProcessConstraint.allocateCPUForThread(
51: requestedBudget, periodIndex, false/*SPIN isAssociatedWithInterrupt*/
52: );
53:
54: if (result) {
55: itsMainThread.setCPUBudget(itsMainThread.cpuBudget()
56: - ProcessConstraint.CPUTimeToNormalizedUtilization(
57: requestedBudget, periodIndex));
58: grantedCPU = requestedBudget;
59: } else {
60: grantedCPU = -1;
61: }
62:
63: return grantedCPU;
64: }
65:
66: public static void deallocateCPUBudgetForThread(Thread theThread) {
67: int budget = theThread.cpuBudget();
68: int periodIndex = theThread.periodIndex();
69: itsProcessConstraint
70: .deallocateCPUForThread(budget, periodIndex);
71: itsMainThread.setCPUBudget(itsMainThread.cpuBudget()
72: + ProcessConstraint.CPUTimeToNormalizedUtilization(
73: budget, periodIndex));
74: }
75:
76: public static Thread mainThread() {
77: return itsMainThread;
78: }
79: }
|