Beispiel #1
0
void	Flip_token_body( char *buf, token_header *token_ptr )
{
/*
 * This routine can not be called twice for the same buffer because
 * of ring_rtr_ptr->num_seq.
 */
	ring_rtr	*ring_rtr_ptr;
	int32		*req_seq;
	char		*rtr;
	int		ptr;
	int		i;

	if( token_ptr->rtr_len <= 0 ) return;

	rtr = buf;
	ptr = 0;
	while( ptr < token_ptr->rtr_len )
	{
	    ring_rtr_ptr = (ring_rtr *)&rtr[ptr];

	    ring_rtr_ptr->memb_id.proc_id = Flip_int32( ring_rtr_ptr->memb_id.proc_id );
	    ring_rtr_ptr->memb_id.time    = Flip_int32( ring_rtr_ptr->memb_id.time );
	    ring_rtr_ptr->proc_id	  = Flip_int32( ring_rtr_ptr->proc_id );
	    ring_rtr_ptr->seg_index	  = Flip_int16( ring_rtr_ptr->seg_index );
	    ring_rtr_ptr->num_seq	  = Flip_int16( ring_rtr_ptr->num_seq );

	    ptr += sizeof(ring_rtr);
	    for( i=0; i < ring_rtr_ptr->num_seq; i++ )
	    {
		req_seq = (int32 *)&rtr[ptr];
		*req_seq = Flip_int32( *req_seq );
		ptr += sizeof(int32);
	    }	
	}
}
Beispiel #2
0
inline void CSwapBlock::ConvertIndianness()
{
	register int TempVal;
	for(unsigned int i=0;i<m_UsedCount;i++)
	{
		TempVal = m_Block[i];
		m_Block[i] = Flip_int32(TempVal);	
	}
	if (m_NextBlock)
		m_NextBlock->ConvertIndianness();
}
Beispiel #3
0
/*************************************************************************
* Let the game begin
**************************************************************************/
int main(int argc, char *argv[])
{
  idxtype i, j, istep, options[10], nn, ne, fstep, lstep, nparts, nboxes, u[3], dim, nchanges, ncomm;
  char filename[256];
  idxtype *mien, *mrng, *part, *oldpart, *sflag, *bestdims, *fepart;
  double *mxyz, *bxyz;
  idxtype *xadj, *adjncy, *cntptr, *cntind;
  idxtype numflag = 0, wgtflag = 0, edgecut, etype=2;
  void *cinfo;
  FILE *fpin;
  long long int *ltmp;

  if (argc != 6) {
    mfprintf(stderr, "Usage: %s <nn> <ne> <fstep> <lstep> <nparts>\n", argv[0]);
    exit(0);
  }

  nn     = atoi(argv[1]);
  ne     = atoi(argv[2]);
  fstep  = atoi(argv[3]);
  lstep  = atoi(argv[4]);
  nparts = atoi(argv[5]);

  mprintf("Reading %s, nn: %D, ne: %D, fstep: %D, lstep: %D, nparts: %D\n", filename, nn, ne, fstep, lstep, nparts);

  mien = idxmalloc(4*ne, "main: mien");
  mxyz = gk_dmalloc(3*nn, "main: mxyz");
  mrng = idxmalloc(4*ne, "main: mrng");
  bxyz = gk_dmalloc(6*ne*4, "main: bxyz");

  fepart  = idxmalloc(nn, "main: fepart");
  part    = idxmalloc(nn, "main: part");
  oldpart = idxmalloc(nn, "main: oldpart");
  sflag   = idxmalloc(nn, "main: sflag");

  bestdims  = idxsmalloc(2*nparts, -1, "main: bestdims");

  xadj   = idxmalloc(nn+1, "main: xadj");
  adjncy = idxmalloc(50*nn, "main: adjncy");


  /*========================================================================
   * Read the initial mesh and setup the graph and contact information
   *========================================================================*/
  msprintf(filename, "mien.%04D", fstep);
  fpin = GKfopen(filename, "rb", "main: mien");
  fread(mien, sizeof(int), 4*ne, fpin);
  for (i=0; i<4*ne; i++)
    mien[i] = Flip_int32(mien[i]);
  GKfclose(fpin);

  msprintf(filename, "mxyz.%04D", fstep);
  fpin = GKfopen(filename, "rb", "main: mxyz");
  fread(mxyz, sizeof(double), 3*nn, fpin);
  for (i=0; i<3*nn; i++) {
    ltmp = (long long int *)(mxyz+i);
    *ltmp = Flip_int64(*ltmp);
  }
  GKfclose(fpin);
  mprintf("%e %e %e\n", mxyz[3*0+0], mxyz[3*0+1], mxyz[3*0+2]);

  msprintf(filename, "mrng.%04D", fstep);
  fpin = GKfopen(filename, "rb", "main: mrng");
  fread(mrng, sizeof(int), 4*ne, fpin);
  for (i=0; i<4*ne; i++)
    mrng[i] = Flip_int32(mrng[i]);
  GKfclose(fpin);


  /*========================================================================
   * Determine which nodes are in the surface
   *========================================================================*/
  iset(nn, 0, sflag);
  for (i=0; i<ne; i++) {
    if (mrng[4*i+0] > 0) { /* 1, 2, 3 */
      sflag[mien[4*i+0]-1] = 1;
      sflag[mien[4*i+1]-1] = 1;
      sflag[mien[4*i+2]-1] = 1;
    }
    if (mrng[4*i+1] > 0) { /* 1, 2, 4 */
      sflag[mien[4*i+0]-1] = 1;
      sflag[mien[4*i+1]-1] = 1;
      sflag[mien[4*i+3]-1] = 1;
    }
    if (mrng[4*i+2] > 0) { /* 2, 3, 4 */
      sflag[mien[4*i+1]-1] = 1;
      sflag[mien[4*i+2]-1] = 1;
      sflag[mien[4*i+3]-1] = 1;
    }
    if (mrng[4*i+3] > 0) { /* 1, 3, 4 */
      sflag[mien[4*i+0]-1] = 1;
      sflag[mien[4*i+2]-1] = 1;
      sflag[mien[4*i+3]-1] = 1;
    }
  }

  mprintf("Contact Nodes: %D of %D\n", isum(nn, sflag), nn);


  /*========================================================================
   * Compute the FE partition
   *========================================================================*/
  numflag = mien[idxargmin(4*ne, mien)];
  METIS_MeshToNodal(&ne, &nn, mien, &etype, &numflag, xadj, adjncy);

  options[0] = 0;
  METIS_PartGraphVKway(&nn, xadj, adjncy, NULL, NULL, &wgtflag, &numflag, &nparts,
        options, &edgecut, fepart);

  mprintf("K-way partitioning Volume: %D\n", edgecut);


  /*========================================================================
   * Get into the loop in which you go over the different configurations
   *========================================================================*/
  for (istep=fstep; istep<=lstep; istep++) {
    msprintf(filename, "mxyz.%04D", istep);
    mprintf("Reading %s...............................................................\n", filename);
    fpin = GKfopen(filename, "rb", "main: mxyz");
    fread(mxyz, sizeof(double), 3*nn, fpin);
    for (i=0; i<3*nn; i++) {
      ltmp = (long long int *)(mxyz+i);
      *ltmp = Flip_int64(*ltmp);
    }
    GKfclose(fpin);

    msprintf(filename, "mrng.%04D", istep);
    fpin = GKfopen(filename, "rb", "main: mrng");
    fread(mrng, sizeof(int), 4*ne, fpin);
    for (i=0; i<4*ne; i++)
      mrng[i] = Flip_int32(mrng[i]);
    GKfclose(fpin);

    /* Determine which nodes are in the surface */
    iset(nn, 0, sflag);
    for (i=0; i<ne; i++) {
      if (mrng[4*i+0] > 0) { /* 1, 2, 3 */
        sflag[mien[4*i+0]-1] = 1;
        sflag[mien[4*i+1]-1] = 1;
        sflag[mien[4*i+2]-1] = 1;
      }
      if (mrng[4*i+1] > 0) { /* 1, 2, 4 */
        sflag[mien[4*i+0]-1] = 1;
        sflag[mien[4*i+1]-1] = 1;
        sflag[mien[4*i+3]-1] = 1;
      }
      if (mrng[4*i+2] > 0) { /* 2, 3, 4 */
        sflag[mien[4*i+1]-1] = 1;
        sflag[mien[4*i+2]-1] = 1;
        sflag[mien[4*i+3]-1] = 1;
      }
      if (mrng[4*i+3] > 0) { /* 1, 3, 4 */
        sflag[mien[4*i+0]-1] = 1;
        sflag[mien[4*i+2]-1] = 1;
        sflag[mien[4*i+3]-1] = 1;
      }
    }

    mprintf("Contact Nodes: %D of %D\n", isum(nn, sflag), nn);

    /* Determine the bounding boxes of the surface elements */
    for (nboxes=0, i=0; i<ne; i++) {
      if (mrng[4*i+0] > 0) { /* 1, 2, 3 */
        u[0] = mien[4*i+0]-1;
        u[1] = mien[4*i+1]-1;
        u[2] = mien[4*i+2]-1;
        bxyz[6*nboxes+0] = bxyz[6*nboxes+3] = mxyz[3*u[0]+0];
        bxyz[6*nboxes+1] = bxyz[6*nboxes+4] = mxyz[3*u[0]+1];
        bxyz[6*nboxes+2] = bxyz[6*nboxes+5] = mxyz[3*u[0]+2];
        for (j=1; j<3; j++) {
          for (dim=0; dim<3; dim++) {
            bxyz[6*nboxes+dim] = (bxyz[6*nboxes+dim] > mxyz[3*u[j]+dim] ? mxyz[3*u[j]+dim] : bxyz[6*nboxes+dim]);
            bxyz[6*nboxes+3+dim] = (bxyz[6*nboxes+3+dim] < mxyz[3*u[j]+dim] ? mxyz[3*u[j]+dim] : bxyz[6*nboxes+3+dim]);
          }
        }
        nboxes++;
      }
      if (mrng[4*i+1] > 0) { /* 1, 2, 4 */
        u[0] = mien[4*i+0]-1;
        u[1] = mien[4*i+1]-1;
        u[2] = mien[4*i+3]-1;
        bxyz[6*nboxes+0] = bxyz[6*nboxes+3] = mxyz[3*u[0]+0];
        bxyz[6*nboxes+1] = bxyz[6*nboxes+4] = mxyz[3*u[0]+1];
        bxyz[6*nboxes+2] = bxyz[6*nboxes+5] = mxyz[3*u[0]+2];
        for (j=1; j<3; j++) {
          for (dim=0; dim<3; dim++) {
            bxyz[6*nboxes+dim] = (bxyz[6*nboxes+dim] > mxyz[3*u[j]+dim] ? mxyz[3*u[j]+dim] : bxyz[6*nboxes+dim]);
            bxyz[6*nboxes+3+dim] = (bxyz[6*nboxes+3+dim] < mxyz[3*u[j]+dim] ? mxyz[3*u[j]+dim] : bxyz[6*nboxes+3+dim]);
          }
        }
        nboxes++;
      }
      if (mrng[4*i+2] > 0) { /* 2, 3, 4 */
        u[0] = mien[4*i+1]-1;
        u[1] = mien[4*i+2]-1;
        u[2] = mien[4*i+3]-1;
        bxyz[6*nboxes+0] = bxyz[6*nboxes+3] = mxyz[3*u[0]+0];
        bxyz[6*nboxes+1] = bxyz[6*nboxes+4] = mxyz[3*u[0]+1];
        bxyz[6*nboxes+2] = bxyz[6*nboxes+5] = mxyz[3*u[0]+2];
        for (j=1; j<3; j++) {
          for (dim=0; dim<3; dim++) {
            bxyz[6*nboxes+dim] = (bxyz[6*nboxes+dim] > mxyz[3*u[j]+dim] ? mxyz[3*u[j]+dim] : bxyz[6*nboxes+dim]);
            bxyz[6*nboxes+3+dim] = (bxyz[6*nboxes+3+dim] < mxyz[3*u[j]+dim] ? mxyz[3*u[j]+dim] : bxyz[6*nboxes+3+dim]);
          }
        }
        nboxes++;
      }
      if (mrng[4*i+3] > 0) { /* 1, 3, 4 */
        u[0] = mien[4*i+0]-1;
        u[1] = mien[4*i+2]-1;
        u[2] = mien[4*i+3]-1;
        bxyz[6*nboxes+0] = bxyz[6*nboxes+3] = mxyz[3*u[0]+0];
        bxyz[6*nboxes+1] = bxyz[6*nboxes+4] = mxyz[3*u[0]+1];
        bxyz[6*nboxes+2] = bxyz[6*nboxes+5] = mxyz[3*u[0]+2];
        for (j=1; j<3; j++) {
          for (dim=0; dim<3; dim++) {
            bxyz[6*nboxes+dim] = (bxyz[6*nboxes+dim] > mxyz[3*u[j]+dim] ? mxyz[3*u[j]+dim] : bxyz[6*nboxes+dim]);
            bxyz[6*nboxes+3+dim] = (bxyz[6*nboxes+3+dim] < mxyz[3*u[j]+dim] ? mxyz[3*u[j]+dim] : bxyz[6*nboxes+3+dim]);
          }
        }
        nboxes++;
      }
    }

    cinfo = METIS_PartSurfForContactRCB(&nn, mxyz, sflag, &nparts, part, bestdims);

    METIS_FindContacts(cinfo, &nboxes, bxyz, &nparts, &cntptr, &cntind);

    METIS_FreeContactInfo(cinfo);

    nchanges = 0;
    if (istep > fstep) {
      for (i=0; i<nn; i++)
        nchanges += (part[i] != oldpart[i] ? 1 : 0);
    }
    idxcopy(nn, part, oldpart);

    ncomm = ComputeMapCost(nn, nparts, fepart, part);

    mprintf("Contacting Elements: %D  Indices: %D  Nchanges: %D  MapCost: %D\n", nboxes, cntptr[nboxes]-nboxes, nchanges, ncomm);

    gk_free((void **)&cntptr, &cntind, LTERM);
  }

}  
Beispiel #4
0
static	void	Report_message(mailbox fd, int dummy, void *dummy_p)
{
	proc	p;
	proc	leader_p;
	int	ret;
	int	ret1,ret2;
static	int32	last_mes;
static	int32	last_aru;
static	int32	last_sec;

	last_mes = GlobalStatus.message_delivered;
	last_aru = GlobalStatus.aru;
	last_sec = GlobalStatus.sec;

	ret = DL_recv( fd, &Report_scat );
	if( ret <= 0 ) {
            Alarm( DEBUG, "Report_messsage: DL_recv failed with ret %d, errno %d\n", ret, sock_errno);
            return;
        }

	if( !Same_endian( Report_pack.type ) )
	{
		GlobalStatus.sec		= Flip_int32( GlobalStatus.sec );
		GlobalStatus.state		= Flip_int32( GlobalStatus.state );
		GlobalStatus.gstate		= Flip_int32( GlobalStatus.gstate );
		GlobalStatus.packet_sent	= Flip_int32( GlobalStatus.packet_sent );
		GlobalStatus.packet_recv	= Flip_int32( GlobalStatus.packet_recv );
		GlobalStatus.packet_delivered   = Flip_int32( GlobalStatus.packet_delivered );
		GlobalStatus.retrans		= Flip_int32( GlobalStatus.retrans );
		GlobalStatus.u_retrans	        = Flip_int32( GlobalStatus.u_retrans );
		GlobalStatus.s_retrans	        = Flip_int32( GlobalStatus.s_retrans );
		GlobalStatus.b_retrans	        = Flip_int32( GlobalStatus.b_retrans );
		GlobalStatus.aru		= Flip_int32( GlobalStatus.aru );
		GlobalStatus.my_aru		= Flip_int32( GlobalStatus.my_aru );
		GlobalStatus.highest_seq	= Flip_int32( GlobalStatus.highest_seq );
		GlobalStatus.token_hurry	= Flip_int32( GlobalStatus.token_hurry );
		GlobalStatus.token_rounds	= Flip_int32( GlobalStatus.token_rounds );
		GlobalStatus.my_id		= Flip_int32( GlobalStatus.my_id );
		GlobalStatus.leader_id	        = Flip_int32( GlobalStatus.leader_id );
		GlobalStatus.message_delivered  = Flip_int32( GlobalStatus.message_delivered );
		GlobalStatus.membership_changes = Flip_int16( GlobalStatus.membership_changes);
		GlobalStatus.num_procs	        = Flip_int16( GlobalStatus.num_procs );
		GlobalStatus.num_segments	= Flip_int16( GlobalStatus.num_segments );
		GlobalStatus.window		= Flip_int16( GlobalStatus.window );
		GlobalStatus.personal_window	= Flip_int16( GlobalStatus.personal_window );
		GlobalStatus.accelerated_ring	= Flip_int16( GlobalStatus.accelerated_ring );
		GlobalStatus.accelerated_window	= Flip_int16( GlobalStatus.accelerated_window );
		GlobalStatus.num_sessions	= Flip_int16( GlobalStatus.num_sessions );
		GlobalStatus.num_groups	        = Flip_int16( GlobalStatus.num_groups );
		GlobalStatus.major_version		= Flip_int16( GlobalStatus.major_version );
		GlobalStatus.minor_version		= Flip_int16( GlobalStatus.minor_version );
		GlobalStatus.patch_version		= Flip_int16( GlobalStatus.patch_version );
	}
	printf("\n============================\n");
	ret1 = Conf_proc_by_id( GlobalStatus.my_id, &p );
	ret2 = Conf_proc_by_id( GlobalStatus.leader_id, &leader_p );
	if( ret1 < 0 )
	{
		printf("Report_message: Skiping illegal status \n");
		printf("==================================\n");
		return;
	}
	printf("Status at %s V%2d.%02d.%2d (state %d, gstate %d) after %d seconds :\n",p.name, 
               GlobalStatus.major_version,GlobalStatus.minor_version,GlobalStatus.patch_version, 
               GlobalStatus.state, GlobalStatus.gstate, GlobalStatus.sec);
	if( ret2 < 0 )
	     printf("Membership  :  %d  procs in %d segments, leader is %d, ",
			GlobalStatus.num_procs,GlobalStatus.num_segments,GlobalStatus.leader_id);
	else printf("Membership  :  %d  procs in %d segments, leader is %s, ",
		GlobalStatus.num_procs,GlobalStatus.num_segments,leader_p.name);
        if (GlobalStatus.accelerated_ring == 0)
            printf("regular protocol\n");
        else
            printf("accelerated protocol\n");

	printf("rounds   : %7d\ttok_hurry : %7d\tmemb change: %7d\n",GlobalStatus.token_rounds,GlobalStatus.token_hurry,GlobalStatus.membership_changes);
	printf("sent pack: %7d\trecv pack : %7d\tretrans    : %7d\n",GlobalStatus.packet_sent,GlobalStatus.packet_recv,GlobalStatus.retrans);
	printf("u retrans: %7d\ts retrans : %7d\tb retrans  : %7d\n",GlobalStatus.u_retrans,GlobalStatus.s_retrans,GlobalStatus.b_retrans);
	printf("My_aru   : %7d\tAru       : %7d\tHighest seq: %7d\n",GlobalStatus.my_aru,GlobalStatus.aru, GlobalStatus.highest_seq);
	printf("Sessions : %7d\tGroups    : %7d\tWindow     : %7d\n",GlobalStatus.num_sessions,GlobalStatus.num_groups,GlobalStatus.window);
	printf("Deliver M: %7d\tDeliver Pk: %7d\tP/A Window : %7d/%d\n",GlobalStatus.message_delivered,GlobalStatus.packet_delivered,GlobalStatus.personal_window,GlobalStatus.accelerated_window);
	printf("Delta Mes: %7d\tDelta Pk  : %7d\tDelta sec  : %7d\n",GlobalStatus.message_delivered - last_mes,GlobalStatus.aru - last_aru,GlobalStatus.sec - last_sec);
	printf("==================================\n");

	printf("\n");
	printf("Monitor> ");
	fflush(stdout);

}
Beispiel #5
0
static	void	Handle_state()
{
  group_id	*curr_gid_ptr;
  address	*curr_real_address_ptr;
  int		num_bytes;
  int		num_released;
  int           *curr_index_ptr;
  int           *curr_maturity_ptr;
  int           *curr_num_allocated_ptr;  
  address       *curr_pseudo_addr_ptr;
  int           *curr_claim_priority_ptr;
  int           *curr_num_prefer_ptr;
  address       *curr_prefer_address;
  int           i, j, k;

  wack_alarm(LOGIC,  "Handle state" );

  num_bytes = 0;
  curr_gid_ptr = (group_id *)&Mess[num_bytes];
  num_bytes += sizeof( group_id );
  
  /* ### wackamole stuff */
  curr_real_address_ptr = (address *)&Mess[num_bytes];
  num_bytes += sizeof( address );
  curr_index_ptr = (int *)&Mess[num_bytes];
  num_bytes += sizeof( int );
  curr_maturity_ptr = (int *)&Mess[num_bytes];
  num_bytes += sizeof( int );
  curr_num_allocated_ptr = (int *)&Mess[num_bytes];
  num_bytes += sizeof( int );

  if( Endian_mismatch )
    {
      curr_gid_ptr->id[0] = Flip_int32( curr_gid_ptr->id[0] );
      curr_gid_ptr->id[1] = Flip_int32( curr_gid_ptr->id[1] );
      curr_gid_ptr->id[2] = Flip_int32( curr_gid_ptr->id[2] );
      
      /* ### wackamole stuff */
      *curr_real_address_ptr = Flip_int32( *curr_real_address_ptr );
      *curr_index_ptr = Flip_int32( *curr_index_ptr );
      *curr_maturity_ptr = Flip_int32( *curr_maturity_ptr );
      *curr_num_allocated_ptr = Flip_int32( *curr_num_allocated_ptr );
    }

  /* Check this here, don't process extra stuff if we don't need to. */
  if( Gid.id[0] != curr_gid_ptr->id[0] ||
      Gid.id[1] != curr_gid_ptr->id[1] ||
      Gid.id[2] != curr_gid_ptr->id[2] ) return;
  
  _rif_ip_s(Members[*curr_index_ptr]) = *curr_real_address_ptr;
  Members[*curr_index_ptr].num_allocated = *curr_num_allocated_ptr;
  Members[*curr_index_ptr].got_state_from = 1;

  num_released = 0;
  /* Rip addresses and compute stuff */
  for ( i = 0; i < *curr_num_allocated_ptr; i++ )
    {
      curr_pseudo_addr_ptr = (address *)&Mess[num_bytes];
      num_bytes += sizeof( address );
      curr_claim_priority_ptr = (int *)&Mess[num_bytes];
      num_bytes += sizeof( int );
      if( Endian_mismatch )
	{
	  *curr_pseudo_addr_ptr = Flip_int32( *curr_pseudo_addr_ptr );
	  *curr_claim_priority_ptr = Flip_int32( *curr_claim_priority_ptr );
	}
      for ( j = 0; j < Num_pseudo; j++)
	{
	  if ( *curr_pseudo_addr_ptr == _pif_ip_s(Allocation_table[j]) )
	    {
	      if( _rif_ip_s(Allocation_table[j]) == 0 )
		{
		  _rif_ip_s(Allocation_table[j]) = *curr_real_address_ptr;
		  Allocation_table[j].claim_priority = *curr_claim_priority_ptr;
		}
	      else
		{/*conflict in ip address case*/
		  if( Allocation_table[j].claim_priority == PREFER_CLAIMED ||
		      Allocation_table[j].claim_priority ==  *curr_claim_priority_ptr )
		    {
		      Members[*curr_index_ptr].num_allocated--;
		      if( _rif_ip_s(My) == *curr_real_address_ptr )
			{
                          num_released++;
			  ReleaseAddress(*curr_pseudo_addr_ptr);
			}
		      Old_table[j].claim_priority = Allocation_table[j].claim_priority;
		      _rif_ip_s(Old_table[j]) = _rif_ip_s(Allocation_table[j]);
		    }
		  else if( Allocation_table[j].claim_priority == CLAIMED &&
			   *curr_claim_priority_ptr > PREFER )
		    {
		      if( _rif_ip_s(My) == _rif_ip_s(Allocation_table[j]) )
                        {
                          num_released++;
			  ReleaseAddress( *curr_pseudo_addr_ptr );
                        }
		      for(k = 0; k < Num_members; ++k)
			{
			  if( _rif_ip_s(Members[k]) == _rif_ip_s(Allocation_table[j]) )
			    Members[k].num_allocated--;
			}
		      _rif_ip_s(Allocation_table[j]) = *curr_real_address_ptr;
		      Allocation_table[j].claim_priority = *curr_claim_priority_ptr;
		      Old_table[j].claim_priority = Allocation_table[j].claim_priority;
		      _rif_ip_s(Old_table[j]) = _rif_ip_s(Allocation_table[j]);
		    }
		}
	      j = Num_pseudo;
	    }
	}
    }
 
  if(num_released) {
    Handle_Post_Release();
  } 
  curr_num_prefer_ptr = (int *)&Mess[num_bytes];
  num_bytes += sizeof( int );
  if( Endian_mismatch ) *curr_num_prefer_ptr = Flip_int32( *curr_num_prefer_ptr );
  
  for ( i = 0; i < *curr_num_prefer_ptr; i++ )
    {
      curr_prefer_address = (address *)&Mess[num_bytes];
      num_bytes += sizeof( address );
      if( Endian_mismatch )
	*curr_prefer_address = Flip_int32( *curr_prefer_address );
      for ( j = 0; j < Num_pseudo; j++)
	if ( *curr_prefer_address == _pif_ip_s(Allocation_table[j]) )
	  {
	    if ( Allocation_table[j].claim_priority < PREFER )
	      {
		_rif_ip_s(Allocation_table[j]) = *curr_real_address_ptr;
		Allocation_table[j].claim_priority = PREFER;
	      }
	    j = Num_pseudo;
	  }
    }

  /* ### wackamole compute stuff */
  if ( Maturity == 0 && *curr_maturity_ptr == 1 )
    Handle_mature();
				   
  wack_alarm(LOGIC, "handle state:  got state from %d", *curr_real_address_ptr );
  Num_pending_states--;
  if( Num_pending_states == 0 )
    {
      wack_alarm(LOGIC,  "handle state: Finished getting states, maturity is %d.", Maturity );
      if ( Maturity ) 
	{
	  /* wackamole calculate, drop and aquire */
	  /* Do we do Priority_claim or Claim_unclaimed first? ... each has advantages. */
	  Priority_claim();
	  Claim_unclaimed();

	  State = RUN;
	  E_queue( Balance, 0, 0, Balance_timer );
	  wack_alarm(LOGIC,  "handle state: shifting to RUN");
	}
      else
	{
	  State = BOOT;
	  wack_alarm(LOGIC,  "handle state: shifting back to BOOT");
	}
      Print_alloc();
    }
}
Beispiel #6
0
static	void	Handle_balance()
{
  int        i, j, k;
  int        num_bytes;
  int        *num_balanced;
  int	     num_released;
  int	     num_acquired;
  address    *curr_real_ptr;
  address    *curr_pseudo_ptr;

  wack_alarm(LOGIC,"Handle_balance");
  if( State != RUN ) return;
  Print_alloc();

  num_bytes = 0;
  num_balanced = (int *)&Mess[num_bytes];
  num_bytes += sizeof( int );
  if( Endian_mismatch ) *num_balanced = Flip_int32( *num_balanced );

  num_released = 0;
  num_acquired = 0;
  for ( k = 0; k < *num_balanced; k++ )
    {
      curr_real_ptr = (address *)&Mess[num_bytes];
      num_bytes += sizeof( address );
      curr_pseudo_ptr = (address *)&Mess[num_bytes];
      num_bytes += sizeof( address );

      if( Endian_mismatch )
	{
	  *curr_real_ptr = Flip_int32( *curr_real_ptr );
	  *curr_pseudo_ptr = Flip_int32( *curr_pseudo_ptr );
	}
        
      for ( i = 0; i < Num_pseudo; i++ )
	{
	  if( *curr_pseudo_ptr == _pif_ip_s(Allocation_table[i]) )
	    {
	      if ( _rif_ip_s(My) == *curr_real_ptr ) {
                num_acquired++;
		Acquire( &Allocation_table[i] );
              }
	      if ( _rif_ip_s(My) == _rif_ip_s(Allocation_table[i]) ) {
                num_released++;
		Release( &Allocation_table[i] );
              }
	      for ( j = 0; j < Num_members; j++ )
		{
		  if ( _rif_ip_s(Members[j]) == _rif_ip_s(Allocation_table[i]) )
      		    Members[j].num_allocated--;
		  if ( _rif_ip_s(Members[j]) == *curr_real_ptr )
		    Members[j].num_allocated++;
		}
	      _rif_ip_s(Allocation_table[i]) = *curr_real_ptr;
	      i = Num_pseudo;
	    }  
	}
    }
  if(num_acquired) {
    Handle_Post_Acquire();
  }
  if(num_released) {
    Handle_Post_Release();
  }
  wack_alarm(LOGIC,  "Finished Handle_balance." );
  Print_alloc();
}
Beispiel #7
0
int	DL_recvfrom( channel chan, sys_scatter *scat, int *src_address, unsigned short *src_port )
{
#ifndef ARCH_SCATTER_NONE
static	struct	msghdr	msg;
#else	/* ARCH_SCATTER_NONE */
static	char		pseudo_scat[MAX_PACKET_SIZE];
	int		bytes_to_copy;
	int		total_len;
	int		start;
	int		i;
#endif	/* ARCH_SCATTER_NONE */
        struct  sockaddr_in     source_address;
        int             sip;
        unsigned short  sport;
        socklen_t       sa_len;
	int		ret;

        /* check the scat is small enough to be a sys_scatter */
        assert(scat->num_elements <= ARCH_SCATTER_SIZE);

#ifndef ARCH_SCATTER_NONE
	msg.msg_name 	= (caddr_t) &source_address;
	msg.msg_namelen = sizeof(source_address);
	msg.msg_iov	= (struct iovec *)scat->elements;
	msg.msg_iovlen	= scat->num_elements;
#endif	/* ARCH_SCATTER_NONE */

#ifdef ARCH_SCATTER_CONTROL
	msg.msg_control = (caddr_t) 0;
	msg.msg_controllen = 0;
#endif /* ARCH_SCATTER_CONTROL */
#ifdef ARCH_SCATTER_ACCRIGHTS
	msg.msg_accrights = (caddr_t) 0;
	msg.msg_accrightslen = 0;
#endif /* ARCH_SCATTER_ACCRIGHTS */

#ifndef ARCH_SCATTER_NONE
	ret = recvmsg( chan, &msg, 0 ); 
        sa_len = msg.msg_namelen;
#else	/* ARCH_SCATTER_NONE */
        
	total_len = 0;                             /*This is for TCP, to not receive*/
	for(i=0; i<scat->num_elements; i++)     /*more than one packet.          */
	   total_len += scat->elements[i].len;
        
        if(total_len>MAX_PACKET_SIZE)
           total_len = MAX_PACKET_SIZE;

        sa_len = sizeof(source_address);
	ret = recvfrom( chan, pseudo_scat, total_len, 0, &source_address, &sa_len);
	
	for( i=0, total_len = ret, start =0; total_len > 0; i++)
	{
		bytes_to_copy = scat->elements[i].len;
		if( bytes_to_copy > total_len ) bytes_to_copy = total_len;
		memcpy( scat->elements[i].buf, &pseudo_scat[start], 
                        bytes_to_copy );
		total_len-= scat->elements[i].len;
		start    += scat->elements[i].len;
	}
#endif	/* ARCH_SCATTER_NONE */
	if (ret < 0)
	{
		Alarm( DATA_LINK, "DL_recv: error %d receiving on channel %d\n", ret, chan );
		return( -1 );
	} 
#ifdef ARCH_SCATTER_CONTROL
        else if (ret == 0)
        {
                char    *sptr;
                unsigned short port;
                Alarm( DATA_LINK, "DL_recv: received zero length packet on channel %d flags 0x%x msg_len %d\n", chan, msg.msg_flags, msg.msg_namelen);
                if (msg.msg_namelen >= sizeof(struct sockaddr_in) ) {
                    sptr = (char *) inet_ntoa(source_address.sin_addr);
                    port = Flip_int16(source_address.sin_port);
                    Alarm( DATA_LINK, "\tfrom %s with family %d port %d\n", sptr, source_address.sin_family, port );
                }
#ifdef  MSG_BCAST
                if ( msg.msg_flags & MSG_BCAST )
                {
                        Alarm( DATA_LINK, "\t(BROADCAST)");
                }
#endif
#ifdef  MSG_MCAST
                if ( msg.msg_flags & MSG_MCAST )
                {
                        Alarm( DATA_LINK, "\t(MULTICAST)");
                }
#endif
#ifdef  MSG_TRUNC
                if ( msg.msg_flags & MSG_TRUNC )
                {
                        Alarm( DATA_LINK, "\t(Data TRUNCATED)");
                }
#endif
#ifdef  MSG_CTRUNC
                if ( msg.msg_flags & MSG_CTRUNC )
                {
                        Alarm( DATA_LINK, "\t(Control TRUNCATED)");
                }
#endif
                Alarm( DATA_LINK, "\n");
        }
#endif
        /* Report the source address and port if requested by caller */
        if (sa_len >= sizeof(struct sockaddr_in) ) {
            memcpy(&sip, &source_address.sin_addr, sizeof(int32) );
            sip =  Flip_int32(sip);
            if (src_address != NULL)
                *src_address = sip;
            sport = Flip_int16(source_address.sin_port);
            if (src_port != NULL)
                *src_port = sport;
            Alarm( DATA_LINK, "\tfrom (" IPF ") with family %d port %d\n", IP(sip), source_address.sin_family, sport );
        }
	Alarm( DATA_LINK, "DL_recv: received %d bytes on channel %d\n",
			ret, chan );

	return(ret);
}