Subversion Repositories shark

Rev

Rev 235 | Rev 293 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
235 giacomo 1
/*
2
 * Project: S.Ha.R.K.
3
 *
4
 * Coordinators:
5
 *   Giorgio Buttazzo    <giorgio@sssup.it>
6
 *   Paolo Gai           <pj@gandalf.sssup.it>
7
 *
8
 * Authors     :
9
 *   Paolo Gai           <pj@gandalf.sssup.it>
10
 *   (see the web pages for full authors list)
11
 *
12
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
13
 *
14
 * http://www.sssup.it
15
 * http://retis.sssup.it
16
 * http://shark.sssup.it
17
 */
18
 
19
/*
20
 * Copyright (C) 2001 Paolo Gai
21
 *
22
 * This program is free software; you can redistribute it and/or modify
23
 * it under the terms of the GNU General Public License as published by
24
 * the Free Software Foundation; either version 2 of the License, or
25
 * (at your option) any later version.
26
 *
27
 * This program is distributed in the hope that it will be useful,
28
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
30
 * GNU General Public License for more details.
31
 *
32
 * You should have received a copy of the GNU General Public License
33
 * along with this program; if not, write to the Free Software
34
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
35
 *
36
 */
37
 
38
#include "rmstar.h"
39
#include <ll/stdio.h>
40
#include <ll/string.h>
41
#include <kernel/model.h>
42
#include <kernel/descr.h>
43
#include <kernel/var.h>
44
#include <kernel/func.h>
45
#include <kernel/trace.h>
46
 
47
 
48
#define RMSTAR_CHANGE_LEVEL 1
49
 
50
/* for iqueues */
51
/* #include "iqueue.h" Now iqueues are the only queue type into the kernel */
52
 
53
/* for BUDGET_TASK_MODEL */
241 giacomo 54
#include "fsf_server.h"
235 giacomo 55
 
56
/*
57
 * DEBUG stuffs begin
58
 */
59
 
60
//#define RMSTAR_DEBUG
61
 
62
#ifdef RMSTAR_DEBUG
63
 
64
static __inline__ fake_printf(char *fmt, ...) {}
65
 
66
#define rmstar_printf fake_printf
67
#define rmstar_printf2 fake_printf
68
#define rmstar_printf3 fake_printf
69
 
70
//#define rmstar_printf kern_printf
71
//#define rmstar_printf2 kern_printf
72
//#define rmstar_printf3 kern_printf
73
#endif
74
 
75
/*
76
 * DEBUG stuffs end
77
 */
78
 
79
/* Status used in the level */
80
#define RMSTAR_READY         MODULE_STATUS_BASE    /* - Ready status        */
81
#define RMSTAR_IDLE          MODULE_STATUS_BASE+4  /* to wait the deadline  */
82
 
83
/* flags */
84
#define RMSTAR_FLAG_NORAISEEXC  2
85
 
86
/* the level redefinition for the Earliest Deadline First level */
87
typedef struct {
88
  level_des l;     /* the standard level descriptor          */
89
 
90
  TIME period[MAX_PROC]; /* The task periods; the deadlines are
91
                       stored in the priority field           */
92
  int deadline_timer[MAX_PROC];
93
                   /* The task deadline timers               */
94
 
95
  struct timespec deadline_timespec[MAX_PROC];
96
 
97
  int dline_miss[MAX_PROC]; /* Deadline miss counter */
98
  int wcet_miss[MAX_PROC];  /* Wcet miss counter */
99
 
100
  int nact[MAX_PROC];       /* Wcet miss counter */
101
 
102
  int flag[MAX_PROC];
103
                   /* used to manage the JOB_TASK_MODEL and the
104
                       periodicity                            */
105
 
106
  IQUEUE ready;     /* the ready queue                        */
107
 
108
  PID activated;   /* the task that has been inserted into the
109
                       master module */
110
 
111
  int budget[MAX_PROC];
112
 
113
  int new_level[MAX_PROC];
114
  int wcet[MAX_PROC]; /* save the wcet fields */
115
 
116
  int scheduling_level;
117
 
118
} RMSTAR_level_des;
119
 
120
static void RMSTAR_check_preemption(RMSTAR_level_des *lev)
121
{
122
  PID first;
123
 
124
#ifdef RMSTAR_DEBUG
125
  rmstar_printf("(E:chk)");
126
#endif
127
 
128
  if ((first = iq_query_first(&lev->ready)) != lev->activated) {
129
    if (lev->activated != NIL)
130
      level_table[ lev->scheduling_level ]->
131
        private_extract(lev->scheduling_level, lev->activated);
132
 
133
    lev->activated = first;
134
 
135
    if (first != NIL) {
136
      BUDGET_TASK_MODEL b;
137
      budget_task_default_model(b, lev->budget[first]);
138
 
139
      level_table[ lev->scheduling_level ]->
140
        private_insert(lev->scheduling_level, first, (TASK_MODEL *)&b);
141
    }
142
  }
143
}
144
 
145
static void RMSTAR_timer_deadline(void *par);
146
 
147
static void RMSTAR_internal_activate(RMSTAR_level_des *lev, PID p,
148
                                     struct timespec *t)
149
{
150
#ifdef RMSTAR_DEBUG
151
  rmstar_printf("(E:iact)");
152
#endif
153
 
154
  ADDUSEC2TIMESPEC(lev->period[p], t);
155
 
156
  *iq_query_timespec(p, &lev->ready) = *t;
157
  lev->deadline_timespec[p] = *t;
158
 
159
  /* Insert task in the correct position */
160
  proc_table[p].status = RMSTAR_READY;
161
  iq_priority_insert(p,&lev->ready);
162
 
163
  /* needed because when there is a wcet miss I disable CONTROL_CAP */
164
  proc_table[p].control |= CONTROL_CAP;
165
 
166
  /* check for preemption */
167
  RMSTAR_check_preemption(lev);
168
}
169
 
170
static void RMSTAR_timer_deadline(void *par)
171
{
172
  PID p = (PID) par;
173
  RMSTAR_level_des *lev;
174
 
175
#ifdef RMSTAR_DEBUG
176
//  rmstar_printf("(E:tdl ");
177
#endif
178
 
179
  lev = (RMSTAR_level_des *)level_table[proc_table[p].task_level];
180
 
181
  switch (proc_table[p].status) {
182
    case RMSTAR_IDLE:
183
#ifdef RMSTAR_DEBUG
184
//      rmstar_printf2("I%d",p);
185
#endif
186
      /* set the request time */
187
      RMSTAR_internal_activate(lev,p,iq_query_timespec(p, &lev->ready));
188
 
189
      event_need_reschedule();
190
      break;
191
 
192
    default:
193
#ifdef RMSTAR_DEBUG
194
//      rmstar_printf2("D%d",p);
195
#endif
196
      /* else, a deadline miss occurred!!! */
197
      lev->dline_miss[p]++;
198
 
199
      /* the task is into another state */
200
      lev->nact[p]++;
201
 
202
      /* Set the deadline timer */
203
      ADDUSEC2TIMESPEC(lev->period[p], &lev->deadline_timespec[p]);
204
  }
205
 
206
  /* Set the deadline timer */
207
  lev->deadline_timer[p] = kern_event_post(&lev->deadline_timespec[p],
208
                                           RMSTAR_timer_deadline,
209
                                           (void *)p);
210
 
211
#ifdef RMSTAR_DEBUG
212
//  rmstar_printf(")");
213
#endif
214
}
215
 
216
static void RMSTAR_timer_guest_deadline(void *par)
217
{
218
  PID p = (PID) par;
219
 
220
#ifdef RMSTAR_DEBUG
221
  rmstar_printf("(E:gdl)");
222
#endif
223
 
224
  kern_raise(XDEADLINE_MISS,p);
225
}
226
 
227
static int RMSTAR_public_create(LEVEL l, PID p, TASK_MODEL *m)
228
{
229
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
230
 
231
  /* if the RMSTAR_task_create is called, then the pclass must be a
232
     valid pclass. */
233
  HARD_TASK_MODEL *h;
234
 
235
  if (m->pclass != HARD_PCLASS) return -1;
236
  if (m->level != 0 && m->level != l) return -1;
237
  h = (HARD_TASK_MODEL *)m;
238
  if (!h->wcet || !h->mit || h->periodicity != PERIODIC) return -1;
239
  /* now we know that m is a valid model */
240
 
241
#ifdef RMSTAR_DEBUG
242
  rmstar_printf("(E:tcr)");
243
#endif
244
 
245
  lev->period[p] = h->mit;
246
  *iq_query_priority(p, &lev->ready) = h->mit;
247
 
248
  lev->flag[p] = 0;
249
  lev->deadline_timer[p] = -1;
250
  lev->dline_miss[p]     = 0;
251
  lev->wcet_miss[p]      = 0;
252
  lev->nact[p]           = 0;
253
 
254
  /* Enable wcet check */
255
  proc_table[p].avail_time = h->wcet;
256
  proc_table[p].wcet       = h->wcet;
257
  proc_table[p].control |= CONTROL_CAP;
258
 
259
  return 0; /* OK, also if the task cannot be guaranteed... */
260
}
261
 
262
static void RMSTAR_public_dispatch(LEVEL l, PID p, int nostop)
263
{
264
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
265
 
266
#ifdef RMSTAR_DEBUG
267
  rmstar_printf("(E:dis)");
268
 
269
  rmstar_printf3("(%d %d)",
270
                  iq_query_timespec(p, &lev->ready)->tv_nsec/1000000,
271
                  schedule_time.tv_nsec/1000000);
272
#endif
273
 
274
  level_table[ lev->scheduling_level ]->
275
    private_dispatch(lev->scheduling_level,p,nostop);
276
}
277
 
278
static void RMSTAR_public_epilogue(LEVEL l, PID p)
279
{
280
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
281
 
282
#ifdef RMSTAR_DEBUG
283
  rmstar_printf("(E:epi ");
284
#endif
285
 
286
  /* check if the wcet is finished... */
287
  if (proc_table[p].avail_time <= 0 && proc_table[p].control&CONTROL_CAP) {
288
    /* wcet finished: disable wcet event and count wcet miss */
289
#ifdef RMSTAR_DEBUG
290
    rmstar_printf2("W%d",p);
291
#endif
292
    proc_table[p].control &= ~CONTROL_CAP;
293
    lev->wcet_miss[p]++;
294
  }
295
#ifdef RMSTAR_DEBUG
296
  rmstar_printf(")");
297
#endif
298
 
299
  level_table[ lev->scheduling_level ]->
300
    private_epilogue(lev->scheduling_level,p);
301
 
302
  proc_table[p].status = RMSTAR_READY;
303
}
304
 
305
static void RMSTAR_public_activate(LEVEL l, PID p)
306
{
307
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
308
  struct timespec t;
309
 
310
#ifdef RMSTAR_DEBUG
311
  rmstar_printf("(E:act)");
312
#endif
313
 
314
  /* Test if we are trying to activate a non sleeping task    */
315
  /* save activation (only if needed... */
316
  if (proc_table[p].status != SLEEP) {
317
    /* a periodic task cannot be activated when it is already active */
318
    kern_raise(XACTIVATION,p);
319
    return;
320
  }
321
 
322
  kern_gettime(&t);
323
 
324
  RMSTAR_internal_activate(lev,p, &t);
325
 
326
  /* Set the deadline timer */
327
  lev->deadline_timer[p] = kern_event_post(&lev->deadline_timespec[p],
328
                                           RMSTAR_timer_deadline,
329
                                           (void *)p);
330
 
331
}
332
 
333
static void RMSTAR_public_unblock(LEVEL l, PID p)
334
{
335
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
336
 
337
#ifdef RMSTAR_DEBUG
338
  rmstar_printf("(E:ins)");
339
#endif
340
 
341
  /* Insert task in the correct position */
342
  proc_table[p].status = RMSTAR_READY;
343
  iq_priority_insert(p,&lev->ready);
344
 
345
  /* and check for preemption! */
346
  RMSTAR_check_preemption(lev);
347
}
348
 
349
static void RMSTAR_public_block(LEVEL l, PID p)
350
{
351
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
352
 
353
#ifdef RMSTAR_DEBUG
354
  rmstar_printf("(E:ext)");
355
#endif
356
 
357
  /* the task is blocked on a synchronization primitive. we have to
358
     remove it from the master module -and- from the local queue! */
359
  iq_extract(p,&lev->ready);
360
 
361
  /* and finally, a preemption check! (it will also call guest_end) */
362
  RMSTAR_check_preemption(lev);
363
}
364
 
365
static int RMSTAR_public_message(LEVEL l, PID p, void *m)
366
{
367
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
368
  struct timespec temp;
369
 
370
#ifdef RMSTAR_DEBUG
371
  rmstar_printf("(E:ecy ");
372
#endif
373
 
374
  switch ((long)(m))
375
    {
376
 
377
      /* Task EndCycle */
378
    case (long)(NULL):
379
 
380
      /* we call guest_end directly here because the same task may
381
         be reinserted in the queue before calling the preemption check! */
382
      level_table[ lev->scheduling_level ]->
383
        private_extract(lev->scheduling_level,p);  lev->activated = NIL;
384
 
385
      iq_extract(p,&lev->ready);
386
 
387
      /* we reset the capacity counters... */
388
      proc_table[p].avail_time = proc_table[p].wcet;
389
 
390
      if (lev->nact[p] > 0) {
391
#ifdef RMSTAR_DEBUG
392
        rmstar_printf2("E%d",p);
393
#endif
394
 
395
        /* Pending activation: reactivate the thread!!! */
396
        lev->nact[p]--;
397
 
398
        /* see also RMSTAR_timer_deadline */
399
        kern_gettime(&temp);
400
 
401
        RMSTAR_internal_activate(lev,p,&temp);
402
 
403
        /* check if the deadline has already expired */
404
        temp = *iq_query_timespec(p, &lev->ready);
405
        if (TIMESPEC_A_LT_B(&temp, &schedule_time)) {
406
          /* count the deadline miss */
407
          lev->dline_miss[p]++;
408
          kern_event_delete(lev->deadline_timer[p]);
409
        }
410
 
411
      }
412
      else {
413
#ifdef RMSTAR_DEBUG
414
        rmstar_printf("e%d",p);
415
#endif
416
 
417
        /* the task has terminated his job before it consume the wcet. All OK! */
418
        proc_table[p].status = RMSTAR_IDLE;
419
 
420
        /* and finally, a preemption check! */
421
        RMSTAR_check_preemption(lev);
422
 
423
        /* when the deadline timer fire, it recognize the situation and set
424
           correctly all the stuffs (like reactivation, etc... ) */
425
      }
426
#ifdef RMSTAR_DEBUG
427
      rmstar_printf(")");
428
#endif
429
 
430
      jet_update_endcycle(); /* Update the Jet data... */
431
      trc_logevent(TRC_ENDCYCLE,&exec_shadow); /* tracer stuff */
432
      break;
433
    default:
434
 
435
      break;
436
 
437
    }
438
  return 0;
439
}
440
 
441
static void RMSTAR_public_end(LEVEL l, PID p)
442
{
443
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
444
 
445
#ifdef RMSTAR_DEBUG
446
  rmstar_printf("(E:end)");
447
#endif
448
 
449
  iq_extract(p,&lev->ready);
450
 
451
  /* we finally put the task in the ready queue */
452
  proc_table[p].status = FREE;
453
 
454
  iq_insertfirst(p,&freedesc);
455
 
456
  if (lev->deadline_timer[p] != -1) {
457
    kern_event_delete(lev->deadline_timer[p]);
458
  }
459
 
460
  /* and finally, a preemption check! (it will also call guest_end) */
461
  RMSTAR_check_preemption(lev);
462
}
463
 
464
 
465
/* Guest Functions
466
   These functions manages a JOB_TASK_MODEL, that is used to put
467
   a guest task in the RMSTAR ready queue. */
468
 
469
static void RMSTAR_private_insert(LEVEL l, PID p, TASK_MODEL *m)
470
{
471
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
472
  JOB_TASK_MODEL *job;
473
 
474
  if (m->pclass != JOB_PCLASS || (m->level != 0 && m->level != l) ) {
475
    kern_raise(XINVALID_TASK, p);
476
    return;
477
  }
478
 
479
  job = (JOB_TASK_MODEL *)m;
480
 
481
  *iq_query_timespec(p, &lev->ready) = job->deadline;
482
 
483
  lev->deadline_timer[p] = -1;
484
  lev->dline_miss[p]     = 0;
485
  lev->wcet_miss[p]      = 0;
486
  lev->nact[p]           = 0;
487
 
488
  if (job->noraiseexc)
489
    lev->flag[p] = RMSTAR_FLAG_NORAISEEXC;
490
  else {
491
    lev->flag[p] = 0;
492
    lev->deadline_timer[p] = kern_event_post(iq_query_timespec(p, &lev->ready),
493
                                             RMSTAR_timer_guest_deadline,
494
                                             (void *)p);
495
   }
496
 
497
  lev->period[p] = job->period;
498
  *iq_query_priority(p, &lev->ready) = job->period;
499
 
500
  /* there is no bandwidth guarantee at this level, it is performed
501
     by the level that inserts guest tasks... */
502
 
503
  /* Insert task in the correct position */
504
  iq_priority_insert(p,&lev->ready);
505
  proc_table[p].status = RMSTAR_READY;
506
 
507
  /* check for preemption */
508
  RMSTAR_check_preemption(lev);
509
}
510
 
511
 
512
static void RMSTAR_private_dispatch(LEVEL l, PID p, int nostop)
513
{
514
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
515
 
516
  level_table[ lev->scheduling_level ]->
517
    private_dispatch(lev->scheduling_level,p,nostop);
518
}
519
 
520
static void RMSTAR_private_epilogue(LEVEL l, PID p)
521
{
522
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
523
 
524
  /* the task has been preempted. it returns into the ready queue... */
525
  level_table[ lev->scheduling_level ]->
526
    private_epilogue(lev->scheduling_level,p);
527
 
528
  proc_table[p].status = RMSTAR_READY;
529
}
530
 
531
static void RMSTAR_private_extract(LEVEL l, PID p)
532
{
533
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
534
 
535
#ifdef RMSTAR_DEBUG
536
  //kern_printf("RMSTAR_guest_end: dline timer %d\n",lev->deadline_timer[p]);
537
#endif
538
 
539
  iq_extract(p, &lev->ready);
540
 
541
  /* we remove the deadline timer, because the slice is finished */
542
  if (lev->deadline_timer[p] != NIL) {
543
#ifdef RMSTAR_DEBUG
544
//    kern_printf("RMSTAR_guest_end: dline timer %d\n",lev->deadline_timer[p]);
545
#endif
546
    kern_event_delete(lev->deadline_timer[p]);
547
    lev->deadline_timer[p] = NIL;
548
  }
549
 
550
  /* and finally, a preemption check! (it will also call guest_end() */
551
  RMSTAR_check_preemption(lev);
552
}
553
 
554
/* Registration functions */
555
 
556
/* Registration function:
557
    int flags                 the init flags ... see RMSTAR.h */
558
LEVEL RMSTAR_register_level(int master)
559
{
560
  LEVEL l;            /* the level that we register */
561
  RMSTAR_level_des *lev;  /* for readableness only */
562
  PID i;              /* a counter */
563
 
564
#ifdef RMSTAR_DEBUG
565
  printk("RMSTAR_register_level\n");
566
#endif
567
 
568
  /* request an entry in the level_table */
569
  l = level_alloc_descriptor(sizeof(RMSTAR_level_des));
570
 
571
  lev = (RMSTAR_level_des *)level_table[l];
572
 
573
  printk("    lev=%d\n",(int)lev);
574
 
575
  /* fill the standard descriptor */
576
  lev->l.private_insert   = RMSTAR_private_insert;
577
  lev->l.private_extract  = RMSTAR_private_extract;
578
  lev->l.private_dispatch = RMSTAR_private_dispatch;
579
  lev->l.private_epilogue = RMSTAR_private_epilogue;
580
 
581
  lev->l.public_guarantee = NULL;
582
  lev->l.public_create    = RMSTAR_public_create;
583
  lev->l.public_end       = RMSTAR_public_end;
584
  lev->l.public_dispatch  = RMSTAR_public_dispatch;
585
  lev->l.public_epilogue  = RMSTAR_public_epilogue;
586
  lev->l.public_activate  = RMSTAR_public_activate;
587
  lev->l.public_unblock   = RMSTAR_public_unblock;
588
  lev->l.public_block     = RMSTAR_public_block;
589
  lev->l.public_message   = RMSTAR_public_message;
590
 
591
  /* fill the RMSTAR descriptor part */
592
  for(i=0; i<MAX_PROC; i++) {
593
    lev->period[i]         = 0;
594
    lev->deadline_timer[i] = -1;
595
    lev->flag[i]           = 0;
596
    lev->dline_miss[i]     = 0;
597
    lev->wcet_miss[i]      = 0;
598
    lev->nact[i]           = 0;
599
    lev->budget[i]         = NIL;
600
    lev->wcet[i]           = 0;
601
  }
602
 
603
  iq_init(&lev->ready, NULL, 0);
604
  lev->activated = NIL;
605
 
606
  lev->scheduling_level = master;
607
 
608
  return l;
609
}
610
 
611
int RMSTAR_get_dline_miss(PID p)
612
{
613
  LEVEL l = proc_table[p].task_level;
614
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
615
 
616
  return lev->dline_miss[p];
617
}
618
 
619
int RMSTAR_get_wcet_miss(PID p)
620
{
621
  LEVEL l = proc_table[p].task_level;
622
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
623
 
624
  return lev->wcet_miss[p];
625
}
626
 
627
int RMSTAR_get_nact(PID p)
628
{
629
  LEVEL l = proc_table[p].task_level;
630
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
631
 
632
  return lev->nact[p];
633
}
634
 
635
int RMSTAR_reset_dline_miss(PID p)
636
{
637
  LEVEL l = proc_table[p].task_level;
638
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
639
 
640
  lev->dline_miss[p] = 0;
641
  return 0;
642
}
643
 
644
int RMSTAR_reset_wcet_miss(PID p)
645
{
646
  LEVEL l = proc_table[p].task_level;
647
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
648
 
649
  lev->wcet_miss[p] = 0;
650
  return 0;
651
}
652
 
653
 
654
int RMSTAR_setbudget(LEVEL l, PID p, int budget)
655
{
656
 
657
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
658
 
659
  lev->budget[p] = budget;
660
 
661
  return 0;
662
 
663
}
664
 
665
int RMSTAR_getbudget(LEVEL l, PID p)
666
{
667
 
668
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
669
 
670
  return lev->budget[p];
671
 
672
}
673
 
674
int RMSTAR_budget_has_thread(LEVEL l, int budget)
675
{
676
 
677
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
678
  int i;
679
 
680
  for(i = 0; i< MAX_PROC; i++)
681
    if (lev->budget[i] == budget) return 1;
682
 
683
  return 0;
684
 
685
}