/[rtmk]/rtmk/init-main.c
ViewVC logotype

Diff of /rtmk/init-main.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by jrydberg, Mon Dec 17 22:02:16 2001 UTC revision 1.4 by jrydberg, Thu Jan 3 01:32:43 2002 UTC
# Line 22  Foundation, Inc., 59 Temple Place - Suit Line 22  Foundation, Inc., 59 Temple Place - Suit
22  #include "processor.h"  #include "processor.h"
23  #include "bootstrap.h"  #include "bootstrap.h"
24    
25    #include "i386/i386-io.h"
26    
27  /* From version.c  */  /* From version.c  */
28  extern char version_string [];  extern char version_string [];
29    
# Line 45  launch_the_system (void *arg) Line 47  launch_the_system (void *arg)
47      ;      ;
48  }  }
49    
50    static struct thread_lock simple_lock;
51    
52    static void
53    tm_fn (void *arg)
54    {
55      extern unsigned int timestamp_count;
56    
57      trace_printf ("tm fn arg %p %d", arg, timestamp_count);
58    }
59    
60    static void
61    test_fn (void *aux)
62    {
63    #if 0
64      extern unsigned int timestamp_count;
65      struct thread *thread = THREAD_CURRENT ();
66      bool err;
67      int i;
68      unsigned int now;
69    
70      trace_printf ("starting thread %d", (int) thread->scratch_area [3]);
71    
72      for (;;)
73        {
74          trace_printf ("thread %d trying lock", (int) thread->scratch_area [3]);
75    
76          now = timestamp_count;
77          thread_lock_write (&simple_lock);
78    
79          trace_printf ("thread %d got lock (%d)", (int) thread->scratch_area [3],
80                        (timestamp_count - now));
81    
82          for (i = 0; i < 6000000; i++)
83            ;
84    
85    
86          trace_printf ("thread %d unlock", (int) thread->scratch_area [3]);
87          thread_lock_unlock (&simple_lock);
88    
89          for (i = 0; i < 600000; i++)
90            ;
91    
92    
93    #if 0
94          thread_lock_read (&simple_lock);
95    
96          for (i = 0; i < 600000; i++)
97            ;
98    
99          err = thread_lock_read_to_write (&simple_lock);
100          if (err == true)
101            trace_printf ("thread %d failed upgrading lock", (int) thread->scratch_area [3]);
102          else
103            trace_printf ("thread %d upgraded lock", (int) thread->scratch_area [3]);
104    
105          for (i = 0; i < 600000; i++)
106            ;
107    
108          if (err == false)
109            {
110              trace_printf ("thread %d downgrading lock", (int) thread->scratch_area [3]);
111              thread_lock_write_to_read (&simple_lock);
112    
113              for (i = 0; i < 60000; i++)
114                ;
115            }
116    
117          thread_lock_unlock (&simple_lock);
118    
119          for (i = 0; i < 600000; i++)
120            ;
121    #endif
122        }
123    #else
124      timeout (10*2000, tm_fn, 0xdeadbeef);
125      for (;;)
126        ;
127    #endif
128    }
129    
130    struct thread_lock lock_a, lock_b;
131    struct thread_lock mutex;
132    
133    volatile int mid_test = 0;
134    
135    void
136    low_prio_thread (void *arg)
137    {
138      int i;
139    
140      for (i = 0; i < 11000; i++)
141        {
142          mid_test = 1;
143    
144          thread_lock_write (&mutex);
145          thread_lock_unlock (&lock_b);
146    
147          outb (0x9000, 0);
148    
149          thread_lock_unlock (&mutex);
150        }
151    }
152    
153    void
154    middle_prio_thread (void *arg)
155    {
156      for (;;)
157        {
158          thread_lock_write (&lock_b);
159          thread_lock_unlock (&lock_a);
160    
161          while (mid_test)
162            ;
163        }
164    }
165    
166    void
167    high_prio_thread (void *arg)
168    {
169      for (;;)
170        {
171          thread_lock_write (&lock_a);
172          outb (0x9000, 1);
173    
174          thread_lock_write (&mutex);
175    
176          outb (0x9000, 2);
177    
178          mid_test = 0;
179          thread_lock_unlock (&mutex);
180        }
181    }
182    
183    
184    
185    
186  /* Copyright string.  */  /* Copyright string.  */
187    
188  static char copyright_string [] =  static char copyright_string [] =
# Line 52  static char copyright_string [] = Line 190  static char copyright_string [] =
190    "rtmk is free software, covered by the GNU General Public License, and you are\n"    "rtmk is free software, covered by the GNU General Public License, and you are\n"
191    "welcome to change it and/or distribute copies of it under certain conditions.\n\n";    "welcome to change it and/or distribute copies of it under certain conditions.\n\n";
192    
   
193  /* ... */  /* ... */
194    
195  void  void
196  init_main (void)  init_main (void)
197  {  {
198    struct thread *launch_thread;    struct thread *launch_thread, *threads[5];
199    int err;    int err, i;
200    
201    /* Print version information and copyright string.  */    /* Print version information and copyright string.  */
202    
# Line 69  init_main (void) Line 206  init_main (void)
206    callout_init ();    callout_init ();
207    
208    /* Initialize bootstrap.  */    /* Initialize bootstrap.  */
209    #if 0
210    bootstrap_init ();    bootstrap_init ();
211    
212    /* Create the launch thread and start it.  */    /* Create the launch thread and start it.  */
# Line 79  init_main (void) Line 216  init_main (void)
216    thread_start (launch_thread, launch_the_system, 0);    thread_start (launch_thread, launch_the_system, 0);
217    
218    LOAD_CONTEXT (launch_thread);    LOAD_CONTEXT (launch_thread);
219    #else
220      thread_lock_init (&simple_lock, true, false);
221    
222      thread_lock_init (&mutex, true, true);
223      thread_lock_init (&lock_a, true, false);
224      thread_lock_init (&lock_b, true, false);
225    
226      err = thread_create (TASK_KERNEL (), &launch_thread);
227      assert (err == KERN_SUCCESS);
228      launch_thread->scratch_area[3] = 777;
229      thread_start (launch_thread, launch_the_system, 0);
230    
231      for (i = 0; i < 3; i++)
232        {
233          err = thread_create (TASK_KERNEL (), &threads [i]);
234          assert (err == KERN_SUCCESS);
235    
236          threads[i]->scratch_area[3] = (void *) i + 10;
237    
238          thread_set_priority (threads[i], THREAD_POLICY_FIFO, 20+i*20);
239    
240          if (i == 0)
241            thread_start (threads[i], low_prio_thread, 0);
242          else if (i == 1)
243            thread_start (threads[i], middle_prio_thread, 0);
244          else if (i == 2)
245            thread_start (threads[i], high_prio_thread, 0);
246    
247          thread_setrun (threads[i], false);
248        }
249    
250      thread_lock_write (&lock_a);
251      thread_lock_write (&lock_b);
252    #endif
253    
254      thread_system_running = true;
255      LOAD_CONTEXT (launch_thread);
256  }  }

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26