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

« back to all changes in this revision

Viewing changes to src/resmom/freebsd5/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:
103
103
#include <limits.h>
104
104
#include <stdio.h>
105
105
#include <stdlib.h>
106
 
#include    <unistd.h>
107
106
#include <ctype.h>
108
107
#include <dirent.h>
109
108
#include <string.h>
129
128
#include <sys/vmmeter.h>
130
129
#include <ufs/ufs/quota.h>
131
130
#include <vm/vm_map.h>
132
 
#include    <signal.h>
133
131
 
134
132
 
135
133
#include "portability.h"
139
137
#include "server_limits.h"
140
138
#include "attribute.h"
141
139
#include "resource.h"
142
 
#include "job.h"
 
140
#include "pbs_job.h"
143
141
#include "mom_mach.h"
144
142
#include "mom_func.h"
145
143
#include "resmon.h"
163
161
extern double wallfactor;
164
162
extern  long    system_ncpus;
165
163
extern  int     ignwalltime;
 
164
extern  int     igncput;
166
165
extern  int     ignvmem;
 
166
extern  int     ignmem;
167
167
 
168
168
extern  int     LOGLEVEL;
169
169
extern void checkret(char **, int);
278
278
  /* No periodic functions. */
279
279
  }
280
280
 
281
 
extern struct pbs_err_to_txt pbs_err_to_txt[];
282
281
extern time_t   time_now;
283
282
 
284
283
/*
307
306
 *  sizeof(word) = sizeof(int)
308
307
 */
309
308
 
310
 
static int getsize(pres, ret)
311
 
resource  *pres;
312
 
unsigned long *ret;
 
309
static int
 
310
getsize(resource *pres, unsigned long *ret)
313
311
  {
314
312
  unsigned long value;
315
313
 
344
342
 * decoded value of time in seconds in the unsigned long integer.
345
343
 */
346
344
 
347
 
static int gettime(pres, ret)
348
 
resource  *pres;
349
 
unsigned long *ret;
 
345
static int
 
346
gettime(resource *pres, unsigned long *ret)
350
347
  {
351
348
 
352
349
  if (pres->rs_value.at_type != ATR_TYPE_LONG)
395
392
 * Accepts a job id.  Returns the sum of all cpu time consumed for all
396
393
 * tasks executed by the job, in seconds, adjusted by cputfactor.
397
394
 */
398
 
static unsigned long cput_sum(pjob)
399
 
job  *pjob;
 
395
static unsigned long
 
396
cput_sum(job *pjob)
400
397
  {
401
398
  static char  id[] = "cput_sum";
402
399
  int   i;
405
402
 
406
403
  cputime = 0;
407
404
 
 
405
  if (LOGLEVEL >= 7)
 
406
    {
 
407
    sprintf(log_buffer,"proc_array loop start - jobid = %s", 
 
408
      pjob->ji_qs.ji_jobid);
 
409
 
 
410
    log_record(PBSEVENT_DEBUG,0,id,log_buffer);
 
411
    }
 
412
 
408
413
  for (i = 0; i < nproc; i++)
409
414
    {
410
415
 
416
421
    nps++;
417
422
 
418
423
    cputime += pp->ki_runtime / 1000000;
 
424
    
 
425
    if (LOGLEVEL >= 7)
 
426
      {
 
427
      sprintf(log_buffer,"%s: session=%d pid=%d cputime=%llu",
 
428
        id, 
 
429
        sess_tbl[i], 
 
430
        pp->ki_pid, 
 
431
        (long long unsigned)pp->ki_runtime / 1000000);
 
432
 
 
433
      log_record(PBSEVENT_SYSTEM,0,id,log_buffer);
 
434
      }
419
435
 
420
436
    DBPRT(("%s: ses %d pid %d cputime %llu\n", id,
421
437
           sess_tbl[i], pp->ki_pid, (long long unsigned)pp->ki_runtime / 1000000))
435
451
 * Accepts a job ID.  Returns the total number of bytes of address
436
452
 * space consumed by all current tasks within the job.
437
453
 */
438
 
static unsigned long mem_sum(pjob)
439
 
job  *pjob;
 
454
static unsigned long
 
455
mem_sum(job *pjob)
440
456
  {
441
457
  char  *id = "mem_sum";
442
458
  int  i;
464
480
/*
465
481
 * Internal session mem (workingset) size function.
466
482
 */
467
 
static unsigned long resi_sum(pjob)
468
 
job  *pjob;
 
483
static unsigned long
 
484
resi_sum(job *pjob)
469
485
  {
470
486
  char  *id = "resi_sum";
471
487
  int  i;
494
510
/*
495
511
 * Return TRUE if any task in the job is over limit for memory usage.
496
512
 */
497
 
static int overmem_proc(pjob, limit)
498
 
job   *pjob;
499
 
unsigned long limit;
 
513
static int
 
514
overmem_proc(job *pjob, unsigned long limit)
500
515
  {
501
516
  int   i;
502
517
 
523
538
int
524
539
error(char *string, int value)
525
540
  {
526
 
  int  i = 0;
527
541
  char  *message;
528
542
 
529
543
  assert(string != NULL);
530
544
  assert(*string != '\0');
531
 
  assert(value > PBSE_);   /* minimum PBS error number */
532
 
  assert(value <= PBSE_NOSYNCMSTR); /* maximum PBS error number */
533
 
  assert(pbs_err_to_txt[i].err_no != 0);
534
 
 
535
 
  do
536
 
    {
537
 
    if (pbs_err_to_txt[i].err_no == value)
538
 
      break;
539
 
    }
540
 
  while (pbs_err_to_txt[++i].err_no != 0);
541
 
 
542
 
  assert(pbs_err_to_txt[i].err_txt != NULL);
543
 
 
544
 
  message = *pbs_err_to_txt[i].err_txt;
 
545
 
 
546
  message = pbse_to_txt(value);
545
547
 
546
548
  assert(message != NULL);
547
 
 
548
549
  assert(*message != '\0');
549
550
 
550
551
  (void)fprintf(stderr, msg_momsetlim, string, message);
575
576
 * existing limits.  Cannot alter those set by setrlimit (kernel)
576
577
 * because we are the wrong process.
577
578
 */
578
 
int mom_set_limits(pjob, set_mode)
579
 
job   *pjob;
580
 
int    set_mode; /* SET_LIMIT_SET or SET_LIMIT_ALTER */
 
579
int
 
580
mom_set_limits(
 
581
  job *pjob,
 
582
  int set_mode /* SET_LIMIT_SET or SET_LIMIT_ALTER */
 
583
)
581
584
  {
582
585
  char  *id = "mom_set_limits";
583
586
  char  *pname;
610
613
 
611
614
    if (strcmp(pname, "cput") == 0)
612
615
      {
613
 
      /* cpu time - check, if less than pcput use it */
614
 
      retval = gettime(pres, &value);
 
616
      if (igncput == FALSE)
 
617
        {
 
618
        /* cpu time - check, if less than pcput use it */
 
619
        retval = gettime(pres, &value);
615
620
 
616
 
      if (retval != PBSE_NONE)
617
 
        return (error(pname, retval));
 
621
        if (retval != PBSE_NONE)
 
622
          return (error(pname, retval));
 
623
        }
618
624
      }
619
625
    else if (strcmp(pname, "pcput") == 0)
620
626
      {
621
 
      /* process cpu time - set */
622
 
      retval = gettime(pres, &value);
623
 
 
624
 
      if (retval != PBSE_NONE)
625
 
        return (error(pname, retval));
626
 
 
627
 
      reslim.rlim_cur = reslim.rlim_max =
628
 
                          (unsigned long)((double)value / cputfactor);
629
 
 
630
 
      if (setrlimit(RLIMIT_CPU, &reslim) < 0)
631
 
        return (error("RLIMIT_CPU", PBSE_SYSTEM));
 
627
      if (igncput == FALSE)
 
628
        {
 
629
        /* process cpu time - set */
 
630
        retval = gettime(pres, &value);
 
631
 
 
632
        if (retval != PBSE_NONE)
 
633
          return (error(pname, retval));
 
634
 
 
635
        reslim.rlim_cur = reslim.rlim_max =
 
636
          (unsigned long)((double)value / cputfactor);
 
637
 
 
638
        if (setrlimit(RLIMIT_CPU, &reslim) < 0)
 
639
          return (error("RLIMIT_CPU", PBSE_SYSTEM));
 
640
        }
632
641
      }
633
642
    else if (strcmp(pname, "file") == 0)   /* set */
634
643
      {
650
659
      }
651
660
    else if (strcmp(pname, "vmem") == 0)   /* check */
652
661
      {
653
 
      retval = getsize(pres, &value);
654
 
 
655
 
      if (retval != PBSE_NONE)
656
 
        return (error(pname, retval));
657
 
 
658
 
      if ((mem_limit == 0) || (value < mem_limit))
659
 
        mem_limit = value;
660
 
      }
661
 
    else if (strcmp(pname, "pvmem") == 0)   /* set */
662
 
      {
663
 
      if (set_mode == SET_LIMIT_SET)
 
662
      if (ignvmem == FALSE)
664
663
        {
665
664
        retval = getsize(pres, &value);
666
665
 
667
666
        if (retval != PBSE_NONE)
668
667
          return (error(pname, retval));
669
668
 
670
 
        if (value > ULONG_MAX)
671
 
          return (error(pname, PBSE_BADATVAL));
672
 
 
673
669
        if ((mem_limit == 0) || (value < mem_limit))
674
670
          mem_limit = value;
675
671
        }
676
672
      }
 
673
    else if (strcmp(pname, "pvmem") == 0)   /* set */
 
674
      {
 
675
      if (ignvmem == FALSE)
 
676
        {
 
677
        if (set_mode == SET_LIMIT_SET)
 
678
          {
 
679
          retval = getsize(pres, &value);
 
680
 
 
681
          if (retval != PBSE_NONE)
 
682
            return (error(pname, retval));
 
683
 
 
684
          if (value > ULONG_MAX)
 
685
            return (error(pname, PBSE_BADATVAL));
 
686
 
 
687
          if ((mem_limit == 0) || (value < mem_limit))
 
688
            mem_limit = value;
 
689
          }
 
690
        }
 
691
      }
677
692
    else if (strcmp(pname, "mem") == 0)    /* ignore */
678
693
      {
679
694
      }
680
695
    else if (strcmp(pname, "pmem") == 0)   /* set */
681
696
      {
682
 
      if (set_mode == SET_LIMIT_SET)
 
697
      if (ignmem == FALSE)
683
698
        {
684
 
        retval = getsize(pres, &value);
685
 
 
686
 
        if (retval != PBSE_NONE)
687
 
          return (error(pname, retval));
688
 
 
689
 
        reslim.rlim_cur = reslim.rlim_max = value;
690
 
 
691
 
        if (setrlimit(RLIMIT_RSS, &reslim) < 0)
692
 
          return (error("RLIMIT_RSS", PBSE_SYSTEM));
 
699
        if (set_mode == SET_LIMIT_SET)
 
700
          {
 
701
          retval = getsize(pres, &value);
 
702
 
 
703
          if (retval != PBSE_NONE)
 
704
            return (error(pname, retval));
 
705
 
 
706
          reslim.rlim_cur = reslim.rlim_max = value;
 
707
 
 
708
          if (setrlimit(RLIMIT_RSS, &reslim) < 0)
 
709
            return (error("RLIMIT_RSS", PBSE_SYSTEM));
 
710
          }
693
711
        }
694
712
      }
695
713
    else if (strcmp(pname, "walltime") == 0)   /* Check */
743
761
 * polling is done using the mom_over_limit machine-dependent function.
744
762
 */
745
763
 
746
 
int mom_do_poll(pjob)
747
 
job   *pjob;
 
764
int
 
765
mom_do_poll(job *pjob)
748
766
  {
749
767
  char  *id = "mom_do_poll";
750
768
  char  *pname;
882
900
 * Otherwise, return FALSE.
883
901
 */
884
902
 
885
 
int mom_over_limit(pjob)
886
 
job   *pjob;
 
903
int
 
904
mom_over_limit(job *pjob)
887
905
  {
888
906
  char  *id = "mom_over_limit";
889
907
  char  *pname;
905
923
    assert(pname != NULL);
906
924
    assert(*pname != '\0');
907
925
 
908
 
    if (strcmp(pname, "cput") == 0)
 
926
    if ((igncput == FALSE) && (strcmp(pname, "cput") == 0))
909
927
      {
910
928
      retval = gettime(pres, &value);
911
929
 
949
967
        return (TRUE);
950
968
        }
951
969
      }
952
 
    else if (strcmp(pname, "walltime") == 0)
 
970
    else if (ignwalltime == 0 && strcmp(pname, "walltime") == 0)
953
971
      {
954
972
      if ((pjob->ji_qs.ji_svrflags & JOB_SVFLG_HERE) == 0)
955
973
        continue;
966
984
        sprintf(log_buffer,
967
985
                "walltime %lu exceeded limit %lu",
968
986
                num, value);
969
 
 
970
 
        if (ignwalltime == 0)
971
 
          return (TRUE);
 
987
        return (TRUE);
972
988
        }
973
989
      }
974
990
    }
985
1001
 *
986
1002
 * Assumes that the session ID attribute has already been set.
987
1003
 */
988
 
int mom_set_use(pjob)
989
 
job  *pjob;
 
1004
int
 
1005
mom_set_use(job *pjob)
990
1006
  {
991
1007
  resource *pres;
992
1008
  attribute *at;
1079
1095
 * Kill a job task.
1080
1096
 * Call with the job and a signal number.
1081
1097
 */
1082
 
int kill_task(ptask, sig, pg)
1083
 
task *ptask;
1084
 
int  sig;
1085
 
int         pg;
 
1098
int
 
1099
kill_task(task *ptask, int sig, int pg)
1086
1100
  {
1087
1101
  char *id = "kill_task";
1088
1102
  int ct = 0;
1094
1108
  sesid = ptask->ti_qs.ti_sid;
1095
1109
 
1096
1110
  if (sesid <= 1)
1097
 
    return 0;
 
1111
    {
 
1112
    if (LOGLEVEL >= 3)
 
1113
      {
 
1114
      sprintf(log_buffer,"cannot send signal %d to task (no session id)",
 
1115
        sig);
 
1116
 
 
1117
      log_record(
 
1118
        PBSEVENT_ERROR,
 
1119
        PBS_EVENTCLASS_JOB,
 
1120
        ptask->ti_job->ji_qs.ji_jobid,
 
1121
        log_buffer);
 
1122
      }
 
1123
 
 
1124
    /* FAILURE */
 
1125
 
 
1126
    return(0);
 
1127
    }
 
1128
 
 
1129
  if (LOGLEVEL >= 5)
 
1130
    {
 
1131
    sprintf(log_buffer,"sending signal %d to task",
 
1132
      sig);
 
1133
 
 
1134
    log_record(
 
1135
      PBSEVENT_JOB,
 
1136
      PBS_EVENTCLASS_JOB,
 
1137
      ptask->ti_job->ji_qs.ji_jobid,
 
1138
      log_buffer);
 
1139
    }
1098
1140
 
1099
1141
  if ((err = mom_get_sample()) != PBSE_NONE)
1100
1142
    return 0;
1107
1149
    if (sesid != sess_tbl[i])
1108
1150
      continue;
1109
1151
 
1110
 
    DBPRT(("%s: send signal %d to pid %d\n", id,
1111
 
           sig, pp->ki_pid))
 
1152
    if (LOGLEVEL >= 5)
 
1153
      {
 
1154
      sprintf(log_buffer,"%s: killing pid %d task %d with sig %d",
 
1155
        id, 
 
1156
        pp->ki_pid, 
 
1157
        ptask->ti_qs.ti_task, 
 
1158
        sig);
 
1159
 
 
1160
      log_record(
 
1161
        PBSEVENT_JOB,
 
1162
        PBS_EVENTCLASS_JOB,
 
1163
        ptask->ti_job->ji_qs.ji_jobid,
 
1164
        log_buffer);
 
1165
      }
 
1166
      
1112
1167
    (void)kill(pp->ki_pid, sig);
1113
1168
 
1114
1169
    ++ct;
1125
1180
int
1126
1181
mom_close_poll(void)
1127
1182
  {
1128
 
  DBPRT(("mom_close_poll entered\n"))
 
1183
  char  *id = "mom_close_poll";
 
1184
 
 
1185
  if (LOGLEVEL >= 6)
 
1186
    {
 
1187
    log_record(
 
1188
      PBSEVENT_SYSTEM,
 
1189
      0,
 
1190
      id,
 
1191
      "entered");
 
1192
    }
1129
1193
 
1130
1194
  if (kd)
1131
1195
    {
1142
1206
  }
1143
1207
 
1144
1208
/*
1145
 
 * mom_does_chkpnt - return 1 if mom supports checkpoint
1146
 
 *       0 if not
 
1209
 * mom_does_checkpoint
1147
1210
 */
1148
1211
 
1149
1212
int
1150
 
mom_does_chkpnt(void)
 
1213
mom_does_checkpoint(void)
1151
1214
  {
1152
 
  return (0);
 
1215
  return(CST_NONE);
1153
1216
  }
1154
1217
 
1155
1218
/*
1158
1221
 * If abort is true, kill it too.
1159
1222
 */
1160
1223
 
1161
 
int mach_checkpoint(ptask, file, abort)
1162
 
task *ptask;
1163
 
char *file;
1164
 
int  abort;
 
1224
int
 
1225
mach_checkpoint(task *ptask, char *file, int abort)
1165
1226
  {
1166
1227
  return (-1);
1167
1228
  }
1172
1233
 * Return -1 on error or sid if okay.
1173
1234
 */
1174
1235
 
1175
 
long mach_restart(ptask, file)
1176
 
task *ptask;
1177
 
char *file;
 
1236
long
 
1237
mach_restart(task *ptask, char *file)
1178
1238
  {
1179
1239
  return (-1);
1180
1240
  }
1187
1247
  {
1188
1248
  static unsigned int lastproc = 0;
1189
1249
 
 
1250
 
1190
1251
  if (lastproc == reqnum) /* don't need new proc table */
1191
1252
    return 1;
1192
1253
 
1214
1275
 
1215
1276
  cputime = 0;
1216
1277
 
 
1278
  if (LOGLEVEL >= 6)
 
1279
    {
 
1280
    sprintf(log_buffer,"proc_array loop start - jobid = %d", 
 
1281
      jobid);
 
1282
 
 
1283
    log_record(PBSEVENT_DEBUG,0,id,log_buffer);
 
1284
    }
 
1285
 
1217
1286
  for (i = 0; i < nproc; i++)
1218
1287
    {
1219
1288
 
1420
1489
resi_job(jobid)
1421
1490
pid_t jobid;
1422
1491
  {
 
1492
  char         *id = "resi_job";
1423
1493
  int   i, found;
1424
1494
  int   resisize;
1425
1495
 
1433
1503
 
1434
1504
  found = 0;
1435
1505
 
 
1506
  if (LOGLEVEL >= 6)
 
1507
    {
 
1508
    sprintf(log_buffer,"proc_array loop start - jobid = %d", 
 
1509
      jobid);
 
1510
 
 
1511
    log_record(PBSEVENT_DEBUG,0,id,log_buffer);
 
1512
    }
 
1513
 
1436
1514
  for (i = 0; i < nproc; i++)
1437
1515
    {
1438
1516