230 Doname res = distribute_process(commands, line);
231 if (res == build_running) {
232 parallel_process_cnt++;
233 }
234
235 /*
236 * Return only those memory that were specially allocated
237 * for part of commands.
238 */
239 for (int i = 0; commands[i] != NULL; i++) {
240 if ((commands[i][0] == (int) at_char) ||
241 (commands[i][0] == (int) hyphen_char)) {
242 retmem_mb(commands[i]);
243 }
244 }
245 return res;
246 }
247 }
248
249
250 #define MAXJOBS_ADJUST_RFE4694000
251
252 #ifdef MAXJOBS_ADJUST_RFE4694000
253
254 #include <unistd.h> /* sysconf(_SC_NPROCESSORS_ONLN) */
255 #include <sys/ipc.h> /* ftok() */
256 #include <sys/shm.h> /* shmget(), shmat(), shmdt(), shmctl() */
257 #include <semaphore.h> /* sem_init(), sem_trywait(), sem_post(), sem_destroy() */
258 #include <sys/loadavg.h> /* getloadavg() */
259
260 /*
261 * adjust_pmake_max_jobs (int pmake_max_jobs)
262 *
263 * Parameters:
264 * pmake_max_jobs - max jobs limit set by user
265 *
266 * External functions used:
267 * sysconf()
268 * getloadavg()
269 */
270 static int
271 adjust_pmake_max_jobs (int pmake_max_jobs)
272 {
518 job_adjust_mode = ADJUST_M1;
519
520 /* determine adjust mode */
521 if (char *var = getenv("DMAKE_ADJUST_MAX_JOBS")) {
522 if (strcasecmp(var, "NO") == 0) {
523 job_adjust_mode = ADJUST_NONE;
524 } else if (strcasecmp(var, "M2") == 0) {
525 job_adjust_mode = ADJUST_M2;
526 }
527 }
528
529 /* M2 specific initialization */
530 if (job_adjust_mode == ADJUST_M2) {
531 if (m2_init()) {
532 job_adjust_error();
533 }
534 }
535 }
536 }
537
538 #endif /* MAXJOBS_ADJUST_RFE4694000 */
539
540 /*
541 * distribute_process(char **commands, Property line)
542 *
543 * Parameters:
544 * commands argv vector of commands to execute
545 *
546 * Return value:
547 * The result of the execution
548 *
549 * Static variables used:
550 * process_running Set to the pid of the process set running
551 * #if defined (TEAMWARE_MAKE_CMN) && defined (MAXJOBS_ADJUST_RFE4694000)
552 * job_adjust_mode Current job adjust mode
553 * #endif
554 */
555 static Doname
556 distribute_process(char **commands, Property line)
557 {
558 static unsigned file_number = 0;
559 wchar_t string[MAXPATHLEN];
560 char mbstring[MAXPATHLEN];
561 int filed;
562 int res;
563 int tmp_index;
564 char *tmp_index_str_ptr;
565
566 #if !defined (TEAMWARE_MAKE_CMN) || !defined (MAXJOBS_ADJUST_RFE4694000)
567 while (parallel_process_cnt >= pmake_max_jobs) {
568 await_parallel(false);
569 finish_children(true);
570 }
571 #else /* TEAMWARE_MAKE_CMN && MAXJOBS_ADJUST_RFE4694000 */
572 /* initialize adjust mode, if not initialized */
573 if (job_adjust_mode == ADJUST_UNKNOWN) {
574 job_adjust_init();
575 }
576
577 /* actions depend on adjust mode */
578 switch (job_adjust_mode) {
579 case ADJUST_M1:
580 while (parallel_process_cnt >= adjust_pmake_max_jobs (pmake_max_jobs)) {
581 await_parallel(false);
582 finish_children(true);
583 }
584 break;
585 case ADJUST_M2:
586 if ((res = m2_acquire_job()) == 0) {
587 if (parallel_process_cnt > 0) {
588 await_parallel(false);
589 finish_children(true);
590
591 if ((res = m2_acquire_job()) == 0) {
595 return build_serial;
596 }
597 }
598 if (res < 0) {
599 /* job adjustment error */
600 job_adjust_error();
601
602 /* no adjustment */
603 while (parallel_process_cnt >= pmake_max_jobs) {
604 await_parallel(false);
605 finish_children(true);
606 }
607 }
608 break;
609 default:
610 while (parallel_process_cnt >= pmake_max_jobs) {
611 await_parallel(false);
612 finish_children(true);
613 }
614 }
615 #endif /* TEAMWARE_MAKE_CMN && MAXJOBS_ADJUST_RFE4694000 */
616 setvar_envvar();
617 /*
618 * Tell the user what DMake is doing.
619 */
620 if (!silent && output_mode != txt2_mode) {
621 /*
622 * Print local_host --> x job(s).
623 */
624 (void) fprintf(stdout,
625 gettext("%s --> %d %s\n"),
626 local_host,
627 parallel_process_cnt + 1,
628 (parallel_process_cnt == 0) ? gettext("job") : gettext("jobs"));
629
630 /* Print command line(s). */
631 tmp_index = 0;
632 while (commands[tmp_index] != NULL) {
633 /* No @ char. */
634 /* XXX - need to add [2] when + prefix is added */
635 if ((commands[tmp_index][0] != (int) at_char) &&
1135 } else {
1136 return;
1137 }
1138 } else {
1139 return;
1140 }
1141 }
1142 for (rp = running_list;
1143 (rp != NULL) && (rp->pid != pid);
1144 rp = rp->next) {
1145 ;
1146 }
1147 if (rp == NULL) {
1148 fatal(gettext("Internal error: returned child pid not in running_list"));
1149 } else {
1150 rp->state = (WIFEXITED(status) && WEXITSTATUS(status) == 0) ? build_ok : build_failed;
1151 }
1152 nohang = true;
1153 parallel_process_cnt--;
1154
1155 #if defined (TEAMWARE_MAKE_CMN) && defined (MAXJOBS_ADJUST_RFE4694000)
1156 if (job_adjust_mode == ADJUST_M2) {
1157 if (m2_release_job()) {
1158 job_adjust_error();
1159 }
1160 }
1161 #endif
1162 }
1163 }
1164
1165 /*
1166 * finish_children(docheck)
1167 *
1168 * Finishes the processing for all targets which were running
1169 * and have now completed.
1170 *
1171 * Parameters:
1172 * docheck Completely check the finished target
1173 *
1174 * Static variables used:
1175 * running_tail The tail of the running list
1176 *
1177 * Global variables used:
1178 * continue_after_error -k flag
1179 * fatal_in_progress True if we are finishing up after fatal err
1180 * running_list List of running processes
1181 */
|
230 Doname res = distribute_process(commands, line);
231 if (res == build_running) {
232 parallel_process_cnt++;
233 }
234
235 /*
236 * Return only those memory that were specially allocated
237 * for part of commands.
238 */
239 for (int i = 0; commands[i] != NULL; i++) {
240 if ((commands[i][0] == (int) at_char) ||
241 (commands[i][0] == (int) hyphen_char)) {
242 retmem_mb(commands[i]);
243 }
244 }
245 return res;
246 }
247 }
248
249
250
251 #include <unistd.h> /* sysconf(_SC_NPROCESSORS_ONLN) */
252 #include <sys/ipc.h> /* ftok() */
253 #include <sys/shm.h> /* shmget(), shmat(), shmdt(), shmctl() */
254 #include <semaphore.h> /* sem_init(), sem_trywait(), sem_post(), sem_destroy() */
255 #include <sys/loadavg.h> /* getloadavg() */
256
257 /*
258 * adjust_pmake_max_jobs (int pmake_max_jobs)
259 *
260 * Parameters:
261 * pmake_max_jobs - max jobs limit set by user
262 *
263 * External functions used:
264 * sysconf()
265 * getloadavg()
266 */
267 static int
268 adjust_pmake_max_jobs (int pmake_max_jobs)
269 {
515 job_adjust_mode = ADJUST_M1;
516
517 /* determine adjust mode */
518 if (char *var = getenv("DMAKE_ADJUST_MAX_JOBS")) {
519 if (strcasecmp(var, "NO") == 0) {
520 job_adjust_mode = ADJUST_NONE;
521 } else if (strcasecmp(var, "M2") == 0) {
522 job_adjust_mode = ADJUST_M2;
523 }
524 }
525
526 /* M2 specific initialization */
527 if (job_adjust_mode == ADJUST_M2) {
528 if (m2_init()) {
529 job_adjust_error();
530 }
531 }
532 }
533 }
534
535
536 /*
537 * distribute_process(char **commands, Property line)
538 *
539 * Parameters:
540 * commands argv vector of commands to execute
541 *
542 * Return value:
543 * The result of the execution
544 *
545 * Static variables used:
546 * process_running Set to the pid of the process set running
547 * job_adjust_mode Current job adjust mode
548 */
549 static Doname
550 distribute_process(char **commands, Property line)
551 {
552 static unsigned file_number = 0;
553 wchar_t string[MAXPATHLEN];
554 char mbstring[MAXPATHLEN];
555 int filed;
556 int res;
557 int tmp_index;
558 char *tmp_index_str_ptr;
559
560 /* initialize adjust mode, if not initialized */
561 if (job_adjust_mode == ADJUST_UNKNOWN) {
562 job_adjust_init();
563 }
564
565 /* actions depend on adjust mode */
566 switch (job_adjust_mode) {
567 case ADJUST_M1:
568 while (parallel_process_cnt >= adjust_pmake_max_jobs (pmake_max_jobs)) {
569 await_parallel(false);
570 finish_children(true);
571 }
572 break;
573 case ADJUST_M2:
574 if ((res = m2_acquire_job()) == 0) {
575 if (parallel_process_cnt > 0) {
576 await_parallel(false);
577 finish_children(true);
578
579 if ((res = m2_acquire_job()) == 0) {
583 return build_serial;
584 }
585 }
586 if (res < 0) {
587 /* job adjustment error */
588 job_adjust_error();
589
590 /* no adjustment */
591 while (parallel_process_cnt >= pmake_max_jobs) {
592 await_parallel(false);
593 finish_children(true);
594 }
595 }
596 break;
597 default:
598 while (parallel_process_cnt >= pmake_max_jobs) {
599 await_parallel(false);
600 finish_children(true);
601 }
602 }
603
604 setvar_envvar();
605 /*
606 * Tell the user what DMake is doing.
607 */
608 if (!silent && output_mode != txt2_mode) {
609 /*
610 * Print local_host --> x job(s).
611 */
612 (void) fprintf(stdout,
613 gettext("%s --> %d %s\n"),
614 local_host,
615 parallel_process_cnt + 1,
616 (parallel_process_cnt == 0) ? gettext("job") : gettext("jobs"));
617
618 /* Print command line(s). */
619 tmp_index = 0;
620 while (commands[tmp_index] != NULL) {
621 /* No @ char. */
622 /* XXX - need to add [2] when + prefix is added */
623 if ((commands[tmp_index][0] != (int) at_char) &&
1123 } else {
1124 return;
1125 }
1126 } else {
1127 return;
1128 }
1129 }
1130 for (rp = running_list;
1131 (rp != NULL) && (rp->pid != pid);
1132 rp = rp->next) {
1133 ;
1134 }
1135 if (rp == NULL) {
1136 fatal(gettext("Internal error: returned child pid not in running_list"));
1137 } else {
1138 rp->state = (WIFEXITED(status) && WEXITSTATUS(status) == 0) ? build_ok : build_failed;
1139 }
1140 nohang = true;
1141 parallel_process_cnt--;
1142
1143 if (job_adjust_mode == ADJUST_M2) {
1144 if (m2_release_job()) {
1145 job_adjust_error();
1146 }
1147 }
1148 }
1149 }
1150
1151 /*
1152 * finish_children(docheck)
1153 *
1154 * Finishes the processing for all targets which were running
1155 * and have now completed.
1156 *
1157 * Parameters:
1158 * docheck Completely check the finished target
1159 *
1160 * Static variables used:
1161 * running_tail The tail of the running list
1162 *
1163 * Global variables used:
1164 * continue_after_error -k flag
1165 * fatal_in_progress True if we are finishing up after fatal err
1166 * running_list List of running processes
1167 */
|