📄 p4_utils.c
字号:
if ( !p4_global->local_communication_only ) p4_free(listener_info); /* only allocated in this case */ if (p4_local->procgroup) p4_free(p4_local->procgroup); p4_free(p4_local->conntab); p4_shfree((P4VOID *)(p4_local->queued_messages->m.qs)); p4_free(p4_local->queued_messages);#ifdef CAN_DO_XDR p4_free(p4_local->xdr_buff);#endif p4_free(p4_local); free_avail_quels(); /* (in p4_global) */ for (i = 0; i < P4_MAX_MSG_QUEUES; i++) p4_shfree((P4VOID *)(p4_global->shmem_msg_queues[i].m.qs)); p4_shfree((P4VOID *)(p4_global->cluster_barrier.m.qs)); p4_shfree((P4VOID *)(p4_global));# if defined(SYSV_IPC) p4_dprintfl(90, "removing SYS V IPCs\n"); remove_sysv_ipc();# endif# if defined(SGI) && defined(VENDOR_IPC) unlink(p4_sgi_shared_arena_filename);# endif return (0);}/* static variables private to fork_p4 and zap_p4_processes */static int n_pids = 0;static int pid_list[P4_MAXPROCS];int fork_p4()/* Wrapper round fork for sole purpose of keeping track of pids so that can signal error conditions. See zap_p4_processes.*/{ int pid;# if defined(IPSC860) || defined(CM5) || defined(NCUBE) || defined(SP1_EUI) || defined(SP1_EIUH) p4_error("fork_p4: nodes cannot fork processes",0); # else if (p4_global->n_forked_pids >= P4_MAXPROCS) p4_error("forking too many local processes; max = ", P4_MAXPROCS); p4_global->n_forked_pids++; fflush(stdout); pid = fork(); if (pid > 0) { /* Parent process */ pid_list[n_pids++] = pid;#if defined(SUN_SOLARIS)/***** { processorid_t proc = 0; if(p_online(proc,P_STATUS) != P_ONLINE) printf("Could not bind parent to processor 0\n"); else { processor_bind(P_PID,P_MYID,proc, &proc); printf("Bound parent to processor 0 , previous binding was %d\n", proc); } }*****/#endif } else if (pid == 0) { /* Child process */ pid_list[n_pids++] = getppid(); } else p4_error("fork_p4: fork failed", pid);# endif return pid;}P4VOID zap_p4_processes(){ int n; if (p4_global == NULL) return; n = p4_global->n_forked_pids; while (n--) { p4_dprintfl(30, "killing local process pid %d (pidlist[%d]) of %d\n", pid_list[n], n, p4_global->n_forked_pids ); if ( pid_list[n] > 0 ) kill(pid_list[n], SIGINT); }}P4VOID zap_remote_p4_processes(){ int i; int my_id, num_tries; struct proc_info *dest_pi; char *dest_host; int dest_listener; int dest_listener_con_fd;/* struct slave_listener_msg msg; int connection_fd; int new_listener_port, new_listener_fd; */ p4_dprintfl(30,"killing remote processes\n"); my_id = p4_get_my_id(); for (i = 0; i < p4_global->num_in_proctable; i++) { if (i != my_id) { dest_pi = get_proc_info(i); dest_host = dest_pi->host_name; dest_listener = dest_pi->port; p4_dprintfl(30, "zap: my_id=%d dest_id=%d dest_host=%s dest_listener=%d\n", my_id, i, dest_host, dest_listener); p4_dprintfl(30, "zap: enter loop to connect to dest listener %s\n",dest_host); /* Connect to dest listener */ num_tries = 1; p4_has_timedout( 0 ); while((dest_listener_con_fd = net_conn_to_listener(dest_host,dest_listener,1)) == -1) { num_tries++; if (p4_has_timedout( 1 )) { p4_error( "Timeout in establishing connection to remote process", 0 ); } } p4_dprintfl(30, "conn_to_proc_contd: connected after %d tries, dest_listener_con_fd=%d\n", num_tries, dest_listener_con_fd);/* send it kill-clients-and-die message*/ } }/* kill own listener*/}P4VOID get_qualified_hostname(char *str, int maxlen){ str[maxlen-1] = 0;# if (defined(IPSC860) && !defined(IPSC860_SOCKETS)) || \ (defined(CM5) && !defined(CM5_SOCKETS)) || \ (defined(NCUBE) && !defined(NCUBE_SOCKETS)) || \ (defined(SP1_EUI)) || \ (defined(SP1_EUIH)) strncpy(str,"cube_node",maxlen-1);# else# if defined(SUN_SOLARIS) || defined(MEIKO_CS2) if (*str == '\0') { if (p4_global) strncpy(str,p4_global->my_host_name,maxlen-1); else if (sysinfo(SI_HOSTNAME, str, maxlen-1) == -1) p4_error("could not get qualified hostname", getpid()); }# else if (*str == '\0') { if (p4_global) strncpy(str,p4_global->my_host_name,maxlen-1); else gethostname_p4(str, maxlen); }# endif if (*local_domain != '\0' && !index(str,'.')) { strncat(str,".",maxlen-1); strncat(str,local_domain,maxlen-1); }#endif}int getswport(hostname)char *hostname;{#ifdef CAN_DO_SWITCH_MSGS char local_host[MAXHOSTNAMELEN]; if (strcmp(hostname, "local") == 0) { local_host[0] = '\0'; get_qualified_hostname(local_host); return getswport(local_host); } if (strcmp(hostname, "hurley") == 0) return 1; if (strcmp(hostname, "hurley.tcg.anl.gov") == 0) return 1; if (strcmp(hostname, "hurley.mcs.anl.gov") == 0) return 1; if (strcmp(hostname, "campus.mcs.anl.gov") == 0) return 2; if (strcmp(hostname,"mpp1") == 0) return 3; if (strcmp(hostname,"mpp2") == 0) return 28; if (strcmp(hostname,"mpp3") == 0) return 6; if (strcmp(hostname,"mpp4") == 0) return 7; if (strcmp(hostname,"mpp7") == 0) return 14; if (strcmp(hostname,"mpp8") == 0) return 25; if (strcmp(hostname,"mpp9") == 0) return 20; if (strcmp(hostname,"mpp10") == 0) return 11;#endif return -1;}P4BOOL same_data_representation(id1,id2)int id1, id2;{ struct proc_info *p1 = &(p4_global->proctable[id1]); struct proc_info *p2 = &(p4_global->proctable[id2]); return (data_representation(p1->machine_type) == data_representation(p2->machine_type));}/* Given rank and places to put the hostname and image names, returns * the pid, and fills in the host and image names of the process with * the given rank. Returns 0 if the rank is invalid. */int p4_proc_info(i, hostname, exename)int i;char **hostname;char **exename;{ if (((unsigned) i) >= p4_global->num_in_proctable) { *hostname = 0; return(0); } else { struct proc_info *p1 = &(p4_global->proctable[i]); *hostname = p1->host_name; /* Get the executable name from the procgroup */ *exename = p4_local->procgroup->entries[i].slave_full_pathname; return (p1->unix_id); }} #ifdef OLD_EXECERP4VOID put_execer_port(int port){ int fd; char job_filename[64]; char port_c[16]; sprintf(port_c,"%d",port); strcpy(job_filename,"/tmp/p4_"); strcat(job_filename,execer_jobname); if ((fd = open(job_filename, O_WRONLY | O_CREAT | O_TRUNC, 0600)) < 0) { p4_error("put_execer_port: open failed ",fd); } if ((write(fd,port_c,strlen(port_c)+1)) != strlen(port_c)+1) { p4_error("put_execer_port: write failed ",(-1)); } close(fd);}int get_execer_port( char *master_hostname){ int port, num_read, sleep_time, status; FILE *fp; char cmd[P4_MAX_PGM_LEN]; sprintf(cmd,"rsh %s cat /tmp/p4_%s",master_hostname,execer_jobname); num_read = 0; sleep_time = 4; while (num_read != 1 && sleep_time < 128) { if ((fp = (FILE *) popen(cmd,"r")) == NULL) { wait(&status); /* for the rsh started by popen */ sleep(sleep_time); sleep_time *= 2; } else { num_read = fscanf(fp,"%d",&port); pclose(fp); } } if (num_read != 1) { p4_error("get_execer_port: never got good port",(-1)); } return(port);}void clean_execer_port( void ){ char job_filename[64]; if (execer_starting_remotes && execer_mynodenum == 0) { strncpy(job_filename,"/tmp/p4_",64); strncat(job_filename,execer_jobname,64); unlink(job_filename); }}#elsevoid put_execer_port( int port ){}void clean_execer_port( void ){}#endif/* high-resolution clock, made out of p4_clock and p4_ustimer */static int clock_start_ms;static usc_time_t ustimer_start;static usc_time_t usrollover;P4VOID init_usclock(){ clock_start_ms = p4_clock(); ustimer_start = p4_ustimer(); usrollover = usc_rollover_val();}double p4_usclock(){ int elapsed_ms, q; usc_time_t ustimer_end; double rc, roll, beginning, end; if (usrollover == 0) return( .001*p4_clock() ); elapsed_ms = p4_clock() - clock_start_ms; /* milliseconds */ ustimer_end = p4_ustimer(); /* terminal segment */ q = elapsed_ms / (int)(usrollover/1000);/* num rollover-sized intervals*/ /* q+1 is the maximum number of rollovers that could have occurred */ if (ustimer_start <= ustimer_end) q = q - 1; /* now q+1 is the number of rollovers that did occur */ beginning = (double)(usrollover - ustimer_start); /* initial segment */ end = ustimer_end; /* terminal segment */ roll = (double)(usrollover * 0.000001); /* rollover in seconds */ rc = (double) (((beginning + end ) * 0.000001) + (q * roll)); return(rc);}#ifndef p4_CheckSighandlerP4VOID p4_CheckSighandler( sigf )int (*sigf)();{ if (sigf != SIG_IGN && sigf != SIG_DFL && sigf != SIG_ERR) { printf( "Replaced a non-default signal in P4\n" ); }}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -