Print this page
make: unifdef for TEAMWARE_MAKE_CMN (defined)


   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 
  26 #ifdef TEAMWARE_MAKE_CMN
  27 
  28 /*
  29  *      parallel.cc
  30  *
  31  *      Deal with the parallel processing
  32  */
  33 
  34 /*
  35  * Included files
  36  */
  37 #include <errno.h>                /* errno */
  38 #include <fcntl.h>
  39 #include <mk/defs.h>
  40 #include <mksh/dosys.h>           /* redirect_io() */
  41 #include <mksh/macro.h>           /* expand_value() */
  42 #include <mksh/misc.h>            /* getmem() */
  43 #include <sys/signal.h>
  44 #include <sys/stat.h>
  45 #include <sys/types.h>
  46 #include <sys/utsname.h>


  52 
  53 /*
  54  * Defined macros
  55  */
  56 #define MAXRULES                100
  57 
  58 /*
  59  * This const should be in avo_dms/include/AvoDmakeCommand.h
  60  */
  61 const int local_host_mask = 0x20;
  62 
  63 
  64 /*
  65  * typedefs & structs
  66  */
  67 
  68 
  69 /*
  70  * Static variables
  71  */
  72 #ifdef TEAMWARE_MAKE_CMN
  73 static  Boolean         just_did_subtree = false;
  74 static  char            local_host[MAXNAMELEN] = "";
  75 static  char            user_name[MAXNAMELEN] = "";
  76 #endif
  77 static  int             pmake_max_jobs = 0;
  78 static  pid_t           process_running = -1;
  79 static  Running         *running_tail = &running_list;
  80 static  Name            subtree_conflict;
  81 static  Name            subtree_conflict2;
  82 
  83 
  84 /*
  85  * File table of contents
  86  */
  87 static  void            delete_running_struct(Running rp);
  88 static  Boolean         dependency_conflict(Name target);
  89 static  Doname          distribute_process(char **commands, Property line);
  90 static  void            doname_subtree(Name target, Boolean do_get, Boolean implicit);
  91 static  void            dump_out_file(char *filename, Boolean err);
  92 static  void            finish_doname(Running rp);
  93 static  void            maybe_reread_make_state(void);
  94 static  void            process_next(void);
  95 static  void            reset_conditionals(int cnt, Name *targets, Property *locals);
  96 static  pid_t           run_rule_commands(char *host, char **commands);


 244                 Doname res = distribute_process(commands, line);
 245                 if (res == build_running) {
 246                         parallel_process_cnt++;
 247                 }
 248 
 249                 /*
 250                  * Return only those memory that were specially allocated
 251                  * for part of commands.
 252                  */
 253                 for (int i = 0; commands[i] != NULL; i++) {
 254                         if ((commands[i][0] == (int) at_char) ||
 255                             (commands[i][0] == (int) hyphen_char)) {
 256                                 retmem_mb(commands[i]);
 257                         }
 258                 }
 259                 return res;
 260         }
 261 }
 262 
 263 
 264 #ifdef TEAMWARE_MAKE_CMN
 265 #define MAXJOBS_ADJUST_RFE4694000
 266 
 267 #ifdef MAXJOBS_ADJUST_RFE4694000
 268 
 269 #include <unistd.h>       /* sysconf(_SC_NPROCESSORS_ONLN) */
 270 #include <sys/ipc.h>              /* ftok() */
 271 #include <sys/shm.h>              /* shmget(), shmat(), shmdt(), shmctl() */
 272 #include <semaphore.h>            /* sem_init(), sem_trywait(), sem_post(), sem_destroy() */
 273 #include <sys/loadavg.h>  /* getloadavg() */
 274 
 275 /*
 276  *      adjust_pmake_max_jobs (int pmake_max_jobs)
 277  *
 278  *      Parameters:
 279  *              pmake_max_jobs  - max jobs limit set by user
 280  *
 281  *      External functions used:
 282  *              sysconf()
 283  *              getloadavg()
 284  */


 534 
 535                 /* determine adjust mode */
 536                 if (char *var = getenv(NOCATGETS("DMAKE_ADJUST_MAX_JOBS"))) {
 537                         if (strcasecmp(var, NOCATGETS("NO")) == 0) {
 538                                 job_adjust_mode = ADJUST_NONE;
 539                         } else if (strcasecmp(var, NOCATGETS("M2")) == 0) {
 540                                 job_adjust_mode = ADJUST_M2;
 541                         }
 542                 }
 543 
 544                 /* M2 specific initialization */
 545                 if (job_adjust_mode == ADJUST_M2) {
 546                         if (m2_init()) {
 547                                 job_adjust_error();
 548                         }
 549                 }
 550         }
 551 }
 552 
 553 #endif /* MAXJOBS_ADJUST_RFE4694000 */
 554 #endif /* TEAMWARE_MAKE_CMN */
 555 
 556 /*
 557  *      distribute_process(char **commands, Property line)
 558  *
 559  *      Parameters:
 560  *              commands        argv vector of commands to execute
 561  *
 562  *      Return value:
 563  *                              The result of the execution
 564  *
 565  *      Static variables used:
 566  *              process_running Set to the pid of the process set running
 567  * #if defined (TEAMWARE_MAKE_CMN) && defined (MAXJOBS_ADJUST_RFE4694000)
 568  *              job_adjust_mode Current job adjust mode
 569  * #endif
 570  */
 571 static Doname
 572 distribute_process(char **commands, Property line)
 573 {
 574         static unsigned file_number = 0;


 654                         if (*tmp_index_str_ptr == (int) hyphen_char) {
 655                                 tmp_index_str_ptr++;
 656                         }
 657                         (void) fprintf(stdout, "%s\n", tmp_index_str_ptr);
 658                     }
 659                     tmp_index++;
 660                 }
 661                 (void) fflush(stdout);
 662         }
 663 
 664         (void) sprintf(mbstring,
 665                         NOCATGETS("%s/dmake.stdout.%d.%d.XXXXXX"),
 666                         tmpdir,
 667                         getpid(),
 668                         file_number++);
 669 
 670         mktemp(mbstring);
 671 
 672         stdout_file = strdup(mbstring);
 673         stderr_file = NULL;
 674 #if defined (TEAMWARE_MAKE_CMN)
 675         if (!out_err_same) {
 676                 (void) sprintf(mbstring,
 677                                 NOCATGETS("%s/dmake.stderr.%d.%d.XXXXXX"),
 678                                 tmpdir,
 679                                 getpid(),
 680                                 file_number++);
 681 
 682                 mktemp(mbstring);
 683 
 684                 stderr_file = strdup(mbstring);
 685         }
 686 #endif
 687 
 688         process_running = run_rule_commands(local_host, commands);
 689 
 690         return build_running;
 691 }
 692 
 693 /*
 694  *      doname_parallel(target, do_get, implicit)
 695  *
 696  *      Processes the given target and finishes up any parallel
 697  *      processes left running.
 698  *
 699  *      Return value:
 700  *                              Result of target build
 701  *
 702  *      Parameters:
 703  *              target          Target to build
 704  *              do_get          True if sccs get to be done
 705  *              implicit        True if this is an implicit target
 706  */


1910         if ((rp->conditional_cnt > 0) &&
1911             (rp->conditional_targets != NULL)) {
1912                 retmem_mb((char *) rp->conditional_targets);
1913         }
1914 /**/
1915         if ((rp->auto_count > 0) &&
1916             (rp->automatics != NULL)) {
1917                 retmem_mb((char *) rp->automatics);
1918         }
1919 /**/
1920         if(rp->sprodep_value) {
1921                 free_name(rp->sprodep_value);
1922         }
1923         if(rp->sprodep_env) {
1924                 retmem_mb(rp->sprodep_env);
1925         }
1926         retmem_mb((char *) rp);
1927 
1928 }
1929 
1930 #endif
1931 


   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 

  26 
  27 /*
  28  *      parallel.cc
  29  *
  30  *      Deal with the parallel processing
  31  */
  32 
  33 /*
  34  * Included files
  35  */
  36 #include <errno.h>                /* errno */
  37 #include <fcntl.h>
  38 #include <mk/defs.h>
  39 #include <mksh/dosys.h>           /* redirect_io() */
  40 #include <mksh/macro.h>           /* expand_value() */
  41 #include <mksh/misc.h>            /* getmem() */
  42 #include <sys/signal.h>
  43 #include <sys/stat.h>
  44 #include <sys/types.h>
  45 #include <sys/utsname.h>


  51 
  52 /*
  53  * Defined macros
  54  */
  55 #define MAXRULES                100
  56 
  57 /*
  58  * This const should be in avo_dms/include/AvoDmakeCommand.h
  59  */
  60 const int local_host_mask = 0x20;
  61 
  62 
  63 /*
  64  * typedefs & structs
  65  */
  66 
  67 
  68 /*
  69  * Static variables
  70  */

  71 static  Boolean         just_did_subtree = false;
  72 static  char            local_host[MAXNAMELEN] = "";
  73 static  char            user_name[MAXNAMELEN] = "";

  74 static  int             pmake_max_jobs = 0;
  75 static  pid_t           process_running = -1;
  76 static  Running         *running_tail = &running_list;
  77 static  Name            subtree_conflict;
  78 static  Name            subtree_conflict2;
  79 
  80 
  81 /*
  82  * File table of contents
  83  */
  84 static  void            delete_running_struct(Running rp);
  85 static  Boolean         dependency_conflict(Name target);
  86 static  Doname          distribute_process(char **commands, Property line);
  87 static  void            doname_subtree(Name target, Boolean do_get, Boolean implicit);
  88 static  void            dump_out_file(char *filename, Boolean err);
  89 static  void            finish_doname(Running rp);
  90 static  void            maybe_reread_make_state(void);
  91 static  void            process_next(void);
  92 static  void            reset_conditionals(int cnt, Name *targets, Property *locals);
  93 static  pid_t           run_rule_commands(char *host, char **commands);


 241                 Doname res = distribute_process(commands, line);
 242                 if (res == build_running) {
 243                         parallel_process_cnt++;
 244                 }
 245 
 246                 /*
 247                  * Return only those memory that were specially allocated
 248                  * for part of commands.
 249                  */
 250                 for (int i = 0; commands[i] != NULL; i++) {
 251                         if ((commands[i][0] == (int) at_char) ||
 252                             (commands[i][0] == (int) hyphen_char)) {
 253                                 retmem_mb(commands[i]);
 254                         }
 255                 }
 256                 return res;
 257         }
 258 }
 259 
 260 

 261 #define MAXJOBS_ADJUST_RFE4694000
 262 
 263 #ifdef MAXJOBS_ADJUST_RFE4694000
 264 
 265 #include <unistd.h>       /* sysconf(_SC_NPROCESSORS_ONLN) */
 266 #include <sys/ipc.h>              /* ftok() */
 267 #include <sys/shm.h>              /* shmget(), shmat(), shmdt(), shmctl() */
 268 #include <semaphore.h>            /* sem_init(), sem_trywait(), sem_post(), sem_destroy() */
 269 #include <sys/loadavg.h>  /* getloadavg() */
 270 
 271 /*
 272  *      adjust_pmake_max_jobs (int pmake_max_jobs)
 273  *
 274  *      Parameters:
 275  *              pmake_max_jobs  - max jobs limit set by user
 276  *
 277  *      External functions used:
 278  *              sysconf()
 279  *              getloadavg()
 280  */


 530 
 531                 /* determine adjust mode */
 532                 if (char *var = getenv(NOCATGETS("DMAKE_ADJUST_MAX_JOBS"))) {
 533                         if (strcasecmp(var, NOCATGETS("NO")) == 0) {
 534                                 job_adjust_mode = ADJUST_NONE;
 535                         } else if (strcasecmp(var, NOCATGETS("M2")) == 0) {
 536                                 job_adjust_mode = ADJUST_M2;
 537                         }
 538                 }
 539 
 540                 /* M2 specific initialization */
 541                 if (job_adjust_mode == ADJUST_M2) {
 542                         if (m2_init()) {
 543                                 job_adjust_error();
 544                         }
 545                 }
 546         }
 547 }
 548 
 549 #endif /* MAXJOBS_ADJUST_RFE4694000 */

 550 
 551 /*
 552  *      distribute_process(char **commands, Property line)
 553  *
 554  *      Parameters:
 555  *              commands        argv vector of commands to execute
 556  *
 557  *      Return value:
 558  *                              The result of the execution
 559  *
 560  *      Static variables used:
 561  *              process_running Set to the pid of the process set running
 562  * #if defined (TEAMWARE_MAKE_CMN) && defined (MAXJOBS_ADJUST_RFE4694000)
 563  *              job_adjust_mode Current job adjust mode
 564  * #endif
 565  */
 566 static Doname
 567 distribute_process(char **commands, Property line)
 568 {
 569         static unsigned file_number = 0;


 649                         if (*tmp_index_str_ptr == (int) hyphen_char) {
 650                                 tmp_index_str_ptr++;
 651                         }
 652                         (void) fprintf(stdout, "%s\n", tmp_index_str_ptr);
 653                     }
 654                     tmp_index++;
 655                 }
 656                 (void) fflush(stdout);
 657         }
 658 
 659         (void) sprintf(mbstring,
 660                         NOCATGETS("%s/dmake.stdout.%d.%d.XXXXXX"),
 661                         tmpdir,
 662                         getpid(),
 663                         file_number++);
 664 
 665         mktemp(mbstring);
 666 
 667         stdout_file = strdup(mbstring);
 668         stderr_file = NULL;
 669 
 670         if (!out_err_same) {
 671                 (void) sprintf(mbstring,
 672                                 NOCATGETS("%s/dmake.stderr.%d.%d.XXXXXX"),
 673                                 tmpdir,
 674                                 getpid(),
 675                                 file_number++);
 676 
 677                 mktemp(mbstring);
 678 
 679                 stderr_file = strdup(mbstring);
 680         }

 681 
 682         process_running = run_rule_commands(local_host, commands);
 683 
 684         return build_running;
 685 }
 686 
 687 /*
 688  *      doname_parallel(target, do_get, implicit)
 689  *
 690  *      Processes the given target and finishes up any parallel
 691  *      processes left running.
 692  *
 693  *      Return value:
 694  *                              Result of target build
 695  *
 696  *      Parameters:
 697  *              target          Target to build
 698  *              do_get          True if sccs get to be done
 699  *              implicit        True if this is an implicit target
 700  */


1904         if ((rp->conditional_cnt > 0) &&
1905             (rp->conditional_targets != NULL)) {
1906                 retmem_mb((char *) rp->conditional_targets);
1907         }
1908 /**/
1909         if ((rp->auto_count > 0) &&
1910             (rp->automatics != NULL)) {
1911                 retmem_mb((char *) rp->automatics);
1912         }
1913 /**/
1914         if(rp->sprodep_value) {
1915                 free_name(rp->sprodep_value);
1916         }
1917         if(rp->sprodep_env) {
1918                 retmem_mb(rp->sprodep_env);
1919         }
1920         retmem_mb((char *) rp);
1921 
1922 }
1923 

1924