~ubuntu-branches/ubuntu/precise/torque/precise-updates

« back to all changes in this revision

Viewing changes to src/resmom/netbsd/mom_mach.c

  • Committer: Bazaar Package Importer
  • Author(s): Dominique Belhachemi
  • Date: 2010-05-17 20:56:46 UTC
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: james.westby@ubuntu.com-20100517205646-yjsoqs5r1s9xpnu9
Tags: upstream-2.4.8+dfsg
ImportĀ upstreamĀ versionĀ 2.4.8+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
133
133
#include "server_limits.h"
134
134
#include "attribute.h"
135
135
#include "resource.h"
136
 
#include "job.h"
 
136
#include "pbs_job.h"
137
137
#include "mom_mach.h"
138
138
#include "resmon.h"
139
139
#include "../rm_dep.h"
140
140
 
141
 
static char ident[] = "@(#) netbsd/$RCSfile$ $Revision: 2628 $";
 
141
static char ident[] = "@(#) netbsd/$RCSfile$ $Revision: 3151 $";
142
142
 
143
143
#ifndef TRUE
144
144
#define FALSE 0
158
158
extern double wallfactor;
159
159
/* wow, no ncpus on netbsd - extern  long    system_ncpus; */
160
160
extern  int     ignwalltime;
 
161
extern  int     igncput;
161
162
extern  int     ignvmem;
 
163
extern  int     ignmem;
162
164
 
163
165
/*
164
166
** local functions
237
239
  /* Don't need any periodic processing. */
238
240
  }
239
241
 
240
 
extern struct pbs_err_to_txt pbs_err_to_txt[];
241
242
extern time_t   time_now;
242
243
 
243
244
/*
259
260
 *  sizeof(word) = sizeof(int)
260
261
 */
261
262
 
262
 
static int getsize(pres, ret)
263
 
resource  *pres;
264
 
unsigned long *ret;
 
263
static int
 
264
getsize(resource *pres, unsigned long *ret)
265
265
  {
266
266
  unsigned long value;
267
267
 
296
296
 * decoded value of time in milliseconds in the unsigned long integer.
297
297
 */
298
298
 
299
 
static int gettime(pres, ret)
300
 
resource  *pres;
301
 
unsigned long *ret;
 
299
static int
 
300
gettime(resource *pres, unsigned long *ret)
302
301
  {
303
302
 
304
303
  if (pres->rs_value.at_type != ATR_TYPE_LONG)
347
346
 * Accepts a job id.  Returns the sum of all cpu time consumed for all
348
347
 * tasks executed by the job, in seconds, adjusted by "cputfactor".
349
348
 */
350
 
static unsigned long cput_sum(pjob)
351
 
job  *pjob;
 
349
static unsigned long
 
350
cput_sum(job *pjob)
352
351
  {
353
352
  char   *id = "cput_sum";
354
353
  int   i;
424
423
 * Accepts a job ID.  Returns the total number of bytes of address
425
424
 * space consumed by all current tasks within the job.
426
425
 */
427
 
static unsigned long mem_sum(pjob)
428
 
job  *pjob;
 
426
static unsigned long
 
427
mem_sum(job *pjob)
429
428
  {
430
429
  char  *id = "mem_sum";
431
430
  int  i;
455
454
/*
456
455
 * Internal session mem (workingset) size function.
457
456
 */
458
 
static unsigned long resi_sum(pjob)
459
 
job  *pjob;
 
457
static unsigned long
 
458
resi_sum(job *pjob)
460
459
  {
461
460
  char  *id = "resi_sum";
462
461
  int  i;
485
484
/*
486
485
 * Return TRUE if any task in the job is over limit for memory usage.
487
486
 */
488
 
static int overmem_proc(pjob, limit)
489
 
job   *pjob;
490
 
unsigned long limit;
 
487
static int
 
488
overmem_proc(job *pjob, unsigned long limit)
491
489
  {
492
490
  int   i;
493
491
 
516
514
int
517
515
error(char *string, int value)
518
516
  {
519
 
  int  i = 0;
520
517
  char  *message;
521
518
 
522
519
  assert(string != NULL);
523
520
  assert(*string != '\0');
524
 
  assert(value > PBSE_);   /* minimum PBS error number */
525
 
  assert(value <= PBSE_NOSYNCMSTR); /* maximum PBS error number */
526
 
  assert(pbs_err_to_txt[i].err_no != 0);
527
 
 
528
 
  do
529
 
    {
530
 
    if (pbs_err_to_txt[i].err_no == value)
531
 
      break;
532
 
    }
533
 
  while (pbs_err_to_txt[++i].err_no != 0);
534
 
 
535
 
  assert(pbs_err_to_txt[i].err_txt != NULL);
536
 
 
537
 
  message = *pbs_err_to_txt[i].err_txt;
 
521
 
 
522
  message = pbse_to_txt(value);
538
523
 
539
524
  assert(message != NULL);
540
 
 
541
525
  assert(*message != '\0');
542
526
 
543
527
  (void)fprintf(stderr, msg_momsetlim, string, message);
568
552
 * existing limits.  Cannot alter those set by setrlimit (kernel)
569
553
 * because we are the wrong process.
570
554
 */
571
 
int mom_set_limits(pjob, set_mode)
572
 
job   *pjob;
573
 
int    set_mode; /* SET_LIMIT_SET or SET_LIMIT_ALTER */
 
555
int
 
556
mom_set_limits(
 
557
  job *pjob,
 
558
  int set_mode /* SET_LIMIT_SET or SET_LIMIT_ALTER */
 
559
)
574
560
  {
575
561
  char  *id = "mom_set_limits";
576
562
  char  *pname;
603
589
 
604
590
    if (strcmp(pname, "cput") == 0)
605
591
      {
606
 
      /* cpu time - check, if less than pcput use it */
607
 
      retval = gettime(pres, &value);
 
592
      if (igncput == FALSE)
 
593
        {
 
594
        /* cpu time - check, if less than pcput use it */
 
595
        retval = gettime(pres, &value);
608
596
 
609
 
      if (retval != PBSE_NONE)
610
 
        return (error(pname, retval));
 
597
        if (retval != PBSE_NONE)
 
598
          return (error(pname, retval));
 
599
        }
611
600
      }
612
601
    else if (strcmp(pname, "pcput") == 0)
613
602
      {
614
 
      /* process cpu time - set */
615
 
      retval = gettime(pres, &value);
616
 
 
617
 
      if (retval != PBSE_NONE)
618
 
        return (error(pname, retval));
619
 
 
620
 
      reslim.rlim_cur = reslim.rlim_max =
621
 
                          (unsigned long)((double)value / cputfactor);
622
 
 
623
 
      if (setrlimit(RLIMIT_CPU, &reslim) < 0)
624
 
        return (error("RLIMIT_CPU", PBSE_SYSTEM));
 
603
      if (igncput == FALSE)
 
604
        {
 
605
        /* process cpu time - set */
 
606
        retval = gettime(pres, &value);
 
607
 
 
608
        if (retval != PBSE_NONE)
 
609
          return (error(pname, retval));
 
610
 
 
611
        reslim.rlim_cur = reslim.rlim_max =
 
612
          (unsigned long)((double)value / cputfactor);
 
613
 
 
614
        if (setrlimit(RLIMIT_CPU, &reslim) < 0)
 
615
          return (error("RLIMIT_CPU", PBSE_SYSTEM));
 
616
        }
625
617
      }
626
618
    else if (strcmp(pname, "file") == 0)   /* set */
627
619
      {
643
635
      }
644
636
    else if (strcmp(pname, "vmem") == 0)   /* check */
645
637
      {
646
 
      retval = getsize(pres, &value);
647
 
 
648
 
      if (retval != PBSE_NONE)
649
 
        return (error(pname, retval));
650
 
 
651
 
      if ((mem_limit == 0) || (value < mem_limit))
652
 
        mem_limit = value;
 
638
      if (ignvmem == FALSE)
 
639
        {
 
640
        retval = getsize(pres, &value);
 
641
 
 
642
        if (retval != PBSE_NONE)
 
643
          return (error(pname, retval));
 
644
 
 
645
        if ((mem_limit == 0) || (value < mem_limit))
 
646
          mem_limit = value;
 
647
        }
653
648
      }
654
649
    else if (strcmp(pname, "pvmem") == 0)   /* set */
655
650
      {
656
 
      retval = getsize(pres, &value);
657
 
 
658
 
      if (retval != PBSE_NONE)
659
 
        return (error(pname, retval));
660
 
 
661
 
      if (value > INT_MAX)
662
 
        return (error(pname, PBSE_BADATVAL));
663
 
 
664
 
      if ((mem_limit == 0) || (value < mem_limit))
665
 
        mem_limit = value;
 
651
      if (ignvmem == FALSE)
 
652
        {
 
653
        retval = getsize(pres, &value);
 
654
 
 
655
        if (retval != PBSE_NONE)
 
656
          return (error(pname, retval));
 
657
 
 
658
        if (value > INT_MAX)
 
659
          return (error(pname, PBSE_BADATVAL));
 
660
 
 
661
        if ((mem_limit == 0) || (value < mem_limit))
 
662
          mem_limit = value;
 
663
        }
666
664
      }
667
665
    else if (strcmp(pname, "mem") == 0)    /* ignore */
668
666
      {
669
667
      }
670
668
    else if (strcmp(pname, "pmem") == 0)   /* set */
671
669
      {
672
 
      if (set_mode == SET_LIMIT_SET)
 
670
      if (ignmem == FALSE)
673
671
        {
674
 
        retval = getsize(pres, &value);
675
 
 
676
 
        if (retval != PBSE_NONE)
677
 
          return (error(pname, retval));
678
 
 
679
 
        reslim.rlim_cur = reslim.rlim_max = value;
680
 
 
681
 
        if (setrlimit(RLIMIT_RSS, &reslim) < 0)
682
 
          return (error("RLIMIT_RSS", PBSE_SYSTEM));
 
672
        if (set_mode == SET_LIMIT_SET)
 
673
          {
 
674
          retval = getsize(pres, &value);
 
675
 
 
676
          if (retval != PBSE_NONE)
 
677
            return (error(pname, retval));
 
678
 
 
679
          reslim.rlim_cur = reslim.rlim_max = value;
 
680
 
 
681
          if (setrlimit(RLIMIT_RSS, &reslim) < 0)
 
682
            return (error("RLIMIT_RSS", PBSE_SYSTEM));
 
683
          }
683
684
        }
684
685
      }
685
686
    else if (strcmp(pname, "walltime") == 0)   /* Check */
733
734
 * polling is done using the mom_over_limit machine-dependent function.
734
735
 */
735
736
 
736
 
int mom_do_poll(pjob)
737
 
job   *pjob;
 
737
int
 
738
mom_do_poll(job *pjob)
738
739
  {
739
740
  char  *id = "mom_do_poll";
740
741
  char  *pname;
898
899
 * Otherwise, return FALSE.
899
900
 */
900
901
 
901
 
int mom_over_limit(pjob)
902
 
job   *pjob;
 
902
int
 
903
mom_over_limit(job *pjob)
903
904
  {
904
905
  char  *id = "mom_over_limit";
905
906
  char  *pname;
921
922
    assert(pname != NULL);
922
923
    assert(*pname != '\0');
923
924
 
924
 
    if (strcmp(pname, "cput") == 0)
 
925
    if ((igncput == FALSE) && (strcmp(pname, "cput") == 0))
925
926
      {
926
927
      retval = gettime(pres, &value);
927
928
 
965
966
        return (TRUE);
966
967
        }
967
968
      }
968
 
    else if (strcmp(pname, "walltime") == 0)
 
969
    else if (ignwalltime == 0 && strcmp(pname, "walltime") == 0)
969
970
      {
970
971
      if ((pjob->ji_qs.ji_svrflags & JOB_SVFLG_HERE) == 0)
971
972
        continue;
982
983
        sprintf(log_buffer,
983
984
                "walltime %lu exceeded limit %lu",
984
985
                num, value);
985
 
 
986
 
        if (ignwalltime == 0)
987
 
          return (TRUE);
 
986
        return (TRUE);
988
987
        }
989
988
      }
990
989
    }
1001
1000
 *
1002
1001
 * Assumes that the session ID attribute has already been set.
1003
1002
 */
1004
 
int mom_set_use(pjob)
1005
 
job  *pjob;
 
1003
int
 
1004
mom_set_use(job *pjob)
1006
1005
  {
1007
1006
  char  *id = "mom_set_use";
1008
1007
  resource *pres;
1096
1095
 * Kill a job task.
1097
1096
 * Call with the job and a signal number.
1098
1097
 */
1099
 
int kill_task(ptask, sig, pg)
1100
 
task *ptask;
1101
 
int  sig;
1102
 
int         pg;
 
1098
int
 
1099
kill_task(task *ptask, int sig, int pg)
1103
1100
  {
1104
1101
  char *id = "kill_task";
1105
1102
  int ct = 0;
1159
1156
  }
1160
1157
 
1161
1158
/*
1162
 
 * mom_does_chkpnt - return 1 if mom supports checkpoint
1163
 
 *       0 if not
 
1159
 * mom_does_checkpoint
1164
1160
 */
1165
1161
 
1166
1162
int
1167
 
mom_does_chkpnt(void)
 
1163
mom_does_checkpoint(void)
1168
1164
  {
1169
 
  return (0);
 
1165
  return(CST_NONE);
1170
1166
  }
1171
1167
 
1172
1168
/*
1175
1171
 * If abort is true, kill it too.
1176
1172
 */
1177
1173
 
1178
 
int mach_checkpoint(ptask, file, abort)
1179
 
task *ptask;
1180
 
char *file;
1181
 
int  abort;
 
1174
int
 
1175
mach_checkpoint(task *ptask, char *file, int abort)
1182
1176
  {
1183
1177
  return (-1);
1184
1178
  }
1189
1183
 * Return -1 on error or sid if okay.
1190
1184
 */
1191
1185
 
1192
 
long mach_restart(ptask, file)
1193
 
task *ptask;
1194
 
char *file;
 
1186
long
 
1187
mach_restart(task *ptask, char *file)
1195
1188
  {
1196
1189
  return (-1);
1197
1190
  }