Exemplo n.º 1
0
/**
 * Print the final statistics for the given file
 */
void print_status(const struct finfo_t *finfo, struct timeval start_time)
{
    struct timeval done_time;
    double elapsed_time;
    int i;

    if (sync_mode) {
        print_sync_status(finfo, start_time);
        return;
    }

    if (finfo->file_id == 0) {
        log0(0, 0, "Group complete");
        return;
    }

    log0(0, 0, "Transfer status:");
    for (done_time = start_time, i = 0; i < destcount; i++) {
        if (destlist[i].clientcnt >= 0) {
            continue;
        }
        clog0(0, 0, "Host: %-15s  Status: ", destlist[i].name);
        switch (destlist[i].status) {
        case DEST_MUTE:
            slog0("Mute");
            break;
        case DEST_LOST:
            slog0("Lost connection");
            break;
        case DEST_ABORT:
            slog0("Aborted");
            break;
        case DEST_DONE:
            if (destlist[i].comp_status == COMP_STAT_REJECTED) {
                slog0("Rejected");
                break;
            }
            if (diff_usec(finfo->deststate[i].time, done_time) > 0) {
                done_time = finfo->deststate[i].time;
            }
            elapsed_time = (double)diff_usec(finfo->deststate[i].time,
                                             start_time) / 1000000;
            slog0("Completed   time: %7.3f seconds    NAKs: %d",
                 elapsed_time, finfo->deststate[i].naks);
            break;
        default:
            slog0("Unknown  code: %d", destlist[i].status);
            break;
        }
    }
    elapsed_time = (double)diff_usec(done_time, start_time) / 1000000;
    log1(0, 0, "Total elapsed time: %.3f seconds", elapsed_time);
    log1(0, 0, "Overall throughput: %.2f KB/s",
               (elapsed_time != 0) ? (finfo->size / elapsed_time / 1024) : 0);
}
Exemplo n.º 2
0
bool GuiTrigger::Down()
{
	u32 wiibtn = GCSettings.WiimoteOrientation ? WPAD_BUTTON_LEFT : WPAD_BUTTON_DOWN;

	if(((wpad->btns_d | wpad->btns_h) & (wiibtn | WPAD_CLASSIC_BUTTON_DOWN))
			|| ((wupcdata.btns_d | wupcdata.btns_h) & (wiibtn | WPAD_CLASSIC_BUTTON_DOWN))
			|| (pad.btns_d | pad.btns_h) & PAD_BUTTON_DOWN
			|| pad.stickY < -PADCAL
			|| WPAD_StickY(0) < -PADCAL
			|| wupcdata.stickY < -WUPCCAL)
	{
	if((wpad->btns_d & (wiibtn | WPAD_CLASSIC_BUTTON_DOWN))
			|| wupcdata.btns_d & (wiibtn | WPAD_CLASSIC_BUTTON_DOWN)
			|| pad.btns_d & PAD_BUTTON_DOWN)
		{
			prev[chan] = gettime();
			delay[chan] = SCROLL_DELAY_INITIAL; // reset scroll delay
			return true;
		}

		now[chan] = gettime();

		if(diff_usec(prev[chan], now[chan]) > delay[chan])
		{
			prev[chan] = now[chan];
			
			if(delay[chan] == SCROLL_DELAY_INITIAL)
				delay[chan] = SCROLL_DELAY_LOOP;
			else if(delay[chan] > SCROLL_DELAY_DECREASE)
				delay[chan] -= SCROLL_DELAY_DECREASE;
			return true;
		}
	}
	return false;
}
Exemplo n.º 3
0
long long dbg_time_usec()
{
	long long t = gettime();
	long long d = diff_usec(dbg_t, t);
	dbg_t = t;
	return d;
}
Exemplo n.º 4
0
/**
 * Returns the current congestion control rate in bytes / second.
 * As specified in RFC 4654
 */
unsigned current_cc_rate(struct group_list_t *group)
{
    double p, rtt;
    int i, bytes, thresh;

    if (group->rtt != 0.0) {
        rtt = group->rtt;
    } else {
        rtt = group->grtt;
    }
    p = loss_event_rate(group);

    if (p == 0.0) {
        thresh = (int)(group->grtt * 1000000 * 4);
        bytes = 0;
        i = group->max_txseq;
        while ((i != group->start_txseq) &&
                (diff_usec(group->loss_history[group->max_txseq].t,
                   group->loss_history[i].t) < thresh)) {
            bytes += group->loss_history[i--].size;
        }
        return (unsigned)(2.0 * bytes / (4.0 * group->grtt));
    } else {
        glog5(group, "getting cc rate, p=%f, rtt=%f", p, rtt);
        return (unsigned)(group->datapacketsize /
                (rtt * (sqrt(p * 2.0 / 3.0) +
                        (12 * sqrt(p * 3.0 / 8.0) * p * (1 + (32 * p * p))))));
    }
}
Exemplo n.º 5
0
bool GuiTrigger::Up()
{
    u32 wiibtn = WPAD_BUTTON_UP;

    if((wpad->btns_d | wpad->btns_h) & (wiibtn | WPAD_CLASSIC_BUTTON_UP)
            || (pad.btns_d | pad.btns_h) & PAD_BUTTON_UP
            || pad.stickY > PADCAL
            || WPAD_StickY(0) > PADCAL)
    {
        if(wpad->btns_d & (wiibtn | WPAD_CLASSIC_BUTTON_UP)
                || pad.btns_d & PAD_BUTTON_UP)
        {
            prev[chan] = gettime();
            delay[chan] = SCROLL_DELAY_INITIAL; // reset scroll delay
            return true;
        }

        now[chan] = gettime();

        if(diff_usec(prev[chan], now[chan]) > delay[chan])
        {
            prev[chan] = now[chan];

            if(delay[chan] == SCROLL_DELAY_INITIAL)
                delay[chan] = SCROLL_DELAY_LOOP;
            else if(delay[chan] > SCROLL_DELAY_DECREASE)
                delay[chan] -= SCROLL_DELAY_DECREASE;
            return true;
        }
    }
    return false;
}
Exemplo n.º 6
0
void S9xSyncSpeed ()
{
	unsigned int timediffallowed = Settings.TurboMode ? 0 : Settings.FrameTime;

	while (!S9xSyncSound())
		usleep(10);

	uint32 skipFrms = Settings.SkipFrames;

	if (Settings.TurboMode)
		skipFrms = Settings.TurboSkipFrames;

	now = gettime();

	if (diff_usec(prev, now) > timediffallowed)
	{
		/* Timer has already expired */
		if (IPPU.SkippedFrames < skipFrms)
		{
			IPPU.SkippedFrames++;
			IPPU.RenderThisFrame = FALSE;
		}
		else
		{
			IPPU.SkippedFrames = 0;
			IPPU.RenderThisFrame = TRUE;
		}
	}
	else
	{
		/*** Ahead - so hold up ***/
		while (diff_usec(prev, now) < timediffallowed)
		{
			now = gettime();
			usleep(50);
		}
		IPPU.RenderThisFrame = TRUE;
		IPPU.SkippedFrames = 0;
	}

	prev = now;

	return;
}
Exemplo n.º 7
0
void DoRumble(int i)
{
	if(rumbleOn[i])
	{
		now[i] = gettime();

		if(diff_usec(prev[i], now[i]) > RUMBLE_MAX)
			ShutoffRumble(i, RUMBLE_COOLOFF);
	}
}
Exemplo n.º 8
0
static void run() {
	solutions = alist_new();
	
	gettimeofday(&startTime, NULL);
	
	gamestate_t *gs = gamestate_new(5, coord_new(3, 2));
	search(gs, alist_new());
	
	gettimeofday(&endTime, NULL);
	
	printf("Games played:    %6ld\n", gamesPlayed);
	printf("Solutions found: %6d\n", solutions->size);
	printf("Time elapsed:    %6ldms\n", diff_usec(startTime, endTime) / 1000);
}
Exemplo n.º 9
0
void system10Frames(int rate)
{
	u32 time = gettime();
	u32 diff = diff_usec(lastTime, time);

	// expected diff - actual diff
	u32 timeOff = RATE60HZ - diff;

	if(timeOff > 0 && timeOff < 100000) // we're running ahead!
		usleep(timeOff); // let's take a nap
	else
		timeOff = 0; // timeoff was not valid

	int speed = (RATE60HZ/diff)*100;

	if (cartridgeType == 2) // GBA games require frameskipping
	{
		if (!GCSettings.gbaFrameskip)
		{
			systemFrameSkip = 0;
		}
		else
		{
			// consider increasing skip
			if(speed < 60)
				systemFrameSkip += 4;
			else if(speed < 70)
				systemFrameSkip += 3;
			else if(speed < 80)
				systemFrameSkip += 2;
			else if(speed < 98)
				++systemFrameSkip;

			// consider decreasing skip
			else if(speed > 185)
				systemFrameSkip -= 3;
			else if(speed > 145)
				systemFrameSkip -= 2;
			else if(speed > 125)
				systemFrameSkip -= 1;

			// correct invalid frame skip values
			if(systemFrameSkip > 20)
				systemFrameSkip = 20;
			else if(systemFrameSkip < 0)
				systemFrameSkip = 0;
		}
	}
	lastTime = gettime();
}
Exemplo n.º 10
0
void RequestRumble(int i)
{
	if(CONF_GetPadMotorMode() == 0 || rumbleDisabled || i < 0) // !WiiSettings.rumble
		return;

	now[i] = gettime();

	if(prev[i] > now[i])
		return;

	if(diff_usec(prev[i], now[i]) > RUMBLE_MAX)
	{
		rumbleOn[i] = 1;
		WPAD_Rumble(i, 1); // rumble on
		prev[i] = now[i];
	}
}
Exemplo n.º 11
0
Arquivo: exi.c Projeto: comex/libogc
static s32 __exi_probe(s32 nChn)
{
	u64 time;
	s32 ret = 1;
	u32 level;
	u32 val;
	exibus_priv *exi = &eximap[nChn];
#ifdef _EXI_DEBUG
	printf("__exi_probe(%d)\n",nChn);
#endif
	_CPU_ISR_Disable(level);
	val = _exiReg[nChn*5];
	if(!(exi->flags&EXI_FLAG_ATTACH)) {
		if(val&EXI_EXT_IRQ) {
			__exi_clearirqs(nChn,0,0,1);
			exi->exi_idtime = 0;
			last_exi_idtime[nChn] = 0;
		}
		if(_exiReg[nChn*5]&EXI_EXT_BIT) {
			time = gettime();
			if(last_exi_idtime[nChn]==0) last_exi_idtime[nChn] = time;
			if((val=diff_usec(last_exi_idtime[nChn],time)+10)<30) ret = 0;
			else ret = 1;
#ifdef _EXI_DEBUG
			printf("val = %u, ret = %d, last_exi_idtime[chn] = %llu\n",val,ret,last_exi_idtime[nChn]);
#endif
			_CPU_ISR_Restore(level);
			return ret;
		} else {
			exi->exi_idtime = 0;
			last_exi_idtime[nChn] = 0;
			_CPU_ISR_Restore(level);
			return 0;
		}
	}

	if(!(_exiReg[nChn*5]&EXI_EXT_BIT) || (_exiReg[nChn*5]&EXI_EXT_IRQ)) {
		exi->exi_idtime = 0;
		last_exi_idtime[nChn] = 0;
		ret = 0;
	}
	_CPU_ISR_Restore(level);
	return ret;
}
Exemplo n.º 12
0
/**
 * Gets the current timeout value to use for the main loop
 *
 * First check to see if any active groups have an expired timeout, and
 * handle that timeout.  Once all expired timeouts have been handled, find
 * the active group with the earliest timeout and return the time until that
 * timeout.  If there are no active groups, return NULL.
 */
struct timeval *getrecenttimeout()
{
    static struct timeval tv = {0,0};
    struct timeval current_timestamp, min_timestamp;
    int i, j, found_timeout, recheck, pending;
    int32_t usecs;

    gettimeofday(&current_timestamp, NULL);

    recheck = 1;
    while (recheck) {
        found_timeout = 0;
        recheck = 0;
        // First check group timeouts
        for (i = 0; i < MAXLIST; i++) {
            if (group_list[i].group_id != 0) {
                if ((group_list[i].phase == PR_PHASE_REGISTERED) ||
                        (group_list[i].phase == PR_PHASE_READY)) {
                    if ((group_list[i].phase == PR_PHASE_READY) &&
                            (cmptimestamp(current_timestamp,
                                    group_list[i].phase_timeout_time) >= 0)) {
                        send_keyinfo(i, NULL, 0);
                        recheck = 1;
                    }
                    if (cmptimestamp(current_timestamp,
                            group_list[i].phase_expire_time) >= 0) {
                        group_list[i].phase = PR_PHASE_RECEIVING;
                        check_unfinished_clients(i, 1);
                    }
                }
                if (cmptimestamp(current_timestamp,
                        group_list[i].timeout_time) >= 0) {
                    // If at least one message is pending, timeout_time is
                    // time to next send of the specified message.
                    // Otherwise it's the overall timeout.
                    for (pending = 0, j = 0; (j < MAX_PEND) && !pending; j++) {
                        if (group_list[i].pending[j].msg != 0) {
                            pending = 1;
                        }
                    }
                    if (pending) {
                        send_all_pending(i);
                    } else {
                        log(group_list[i].group_id, 0, "Group timed out");
                        group_cleanup(i);
                    }
                    recheck = 1;
                }
                if (!recheck && ((!found_timeout) ||
                                 (cmptimestamp(group_list[i].timeout_time,
                                               min_timestamp) < 0))) {
                    min_timestamp = group_list[i].timeout_time;
                    found_timeout = 1;
                }
            }
        }
        // Then check timeout for sending heartbeat
        if (hbhost_count) {
            if (cmptimestamp(current_timestamp, next_hb_time) >= 0) {
                send_hb_request(listener, hb_hosts, hbhost_count,
                                &next_hb_time, hb_interval);
                recheck = 1;
            } else if ((!found_timeout) ||
                       (cmptimestamp(next_hb_time, min_timestamp) < 0)) {
                min_timestamp = next_hb_time;
                found_timeout = 1;
            }
        }
    }
    if (found_timeout) {
        usecs = (int32_t)diff_usec(min_timestamp, current_timestamp);
        tv.tv_sec = usecs / 1000000;
        tv.tv_usec = usecs % 1000000;
        return &tv;
    } else {
        return NULL;
    }
}
Exemplo n.º 13
0
/**
 * Gets the current timeout value to use for the main loop
 *
 * First check to see if any active groups have an expired timeout, and
 * handle that timeout.  Once all expired timeouts have been handled, find
 * the active group with the earliest timeout and return the time until that
 * timeout.  If there are no active groups, return NULL.
 */
struct timeval *getrecenttimeout()
{
    static struct timeval tv = {0,0};
    struct timeval current_timestamp, min_timestamp;
    int i, found_timeout, done;
    int32_t usecs;

    gettimeofday(&current_timestamp, NULL);
    done = 0;
    while (!done) {
        found_timeout = 0;
        done = 1;
        for (i = 0; i < MAXLIST; i++) {
            if (group_list[i].group_id != 0) {
                if (cmptimestamp(current_timestamp,
                                 group_list[i].timeout_time) >= 0) {
                    switch (group_list[i].phase) {
                    case PHASE_REGISTERED:
                        send_register(i);
                        break;
                    case PHASE_RECEIVING:
                    case PHASE_MIDGROUP:
                        log1(group_list[i].group_id, group_list[i].file_id,
                            "Transfer timed out");
                        send_abort(i, "Transfer timed out");
                        break;
                    case PHASE_COMPLETE:
                        send_complete(i);
                        break;
                    }
                    done = 0;
                } else if (!found_timeout) {
                    min_timestamp = group_list[i].timeout_time;
                    found_timeout = 1;
                } else if (cmptimestamp(group_list[i].timeout_time,
                                        min_timestamp) < 0) {
                    min_timestamp = group_list[i].timeout_time;
                }
            }
        }
        // Check timeout for proxy key request
        if (has_proxy && (proxy_key == (RSA_key_t)NULL)) {
            if (cmptimestamp(current_timestamp, next_keyreq_time) >= 0) {
                send_key_req();
                done = 0;
            } else if ((!found_timeout) ||
                       (cmptimestamp(next_keyreq_time, min_timestamp) < 0)) {
                min_timestamp = next_keyreq_time;
                found_timeout = 1;
            }
        }
        // Check timeout for sending heartbeat
        if (hbhost_count) {
            if (cmptimestamp(current_timestamp, next_hb_time) >= 0) {
                send_hb_request(listener, hb_hosts, hbhost_count,
                                &next_hb_time, hb_interval);
                done = 0;
            } else if ((!found_timeout) ||
                       (cmptimestamp(next_hb_time, min_timestamp) < 0)) {
                min_timestamp = next_hb_time;
                found_timeout = 1;
            }
        }

    }
    if (found_timeout) {
        usecs = (int32_t)diff_usec(min_timestamp, current_timestamp);
        tv.tv_sec = usecs / 1000000;
        tv.tv_usec = usecs % 1000000;
        return &tv;
    } else {
        return NULL;
    }
}
Exemplo n.º 14
0
/**
 * Updates the group's loss history
 *
 * Packets older than MAXMISORDER sequence numbers don't change the loss
 * history, and packets aren't considered lost unless the sequence number is
 * more than MAXMISORDER sequence numbers old.  Works under the assumption
 * that no more than 32K packets in a row get lost.
 */
void update_loss_history(struct group_list_t *group, uint16_t txseq, int size,
                         int ecn)
{
    uint16_t i;
    int tdiff, grtt_usec;
    struct timeval tvdiff;

    group->loss_history[txseq].found = 1;
    gettimeofday(&group->loss_history[txseq].t, NULL);
    if (group->multi.ss.ss_family == AF_INET6) {
        group->loss_history[txseq].size = size + 8 + 40;
    } else {
        group->loss_history[txseq].size = size + 8 + 20;
    }
    
    if ((int16_t)(txseq - group->max_txseq) > 0) {
        glog4(group, "Got seq %d, max was %d", txseq, group->max_txseq);
        grtt_usec = (int)(group->grtt * 1000000);
        if (txseq < group->max_txseq) {
            glog5(group, "increasing seq_wrap, txseq=%u, maxseq=%u",
                         txseq, group->max_txseq);
            group->seq_wrap++;
        }
        // First set nominal arrival times of missed packets
        for (i = group->max_txseq + 1; i != txseq; i++) {
            tdiff = (int)diff_usec(group->loss_history[txseq].t,
                                   group->loss_history[group->max_txseq].t) *
                ((i - group->max_txseq) / (txseq - group->max_txseq));
            tvdiff.tv_sec = 0;
            tvdiff.tv_usec = tdiff;
            while (tvdiff.tv_usec >= 1000000) {
                tvdiff.tv_usec -= 1000000;
                tvdiff.tv_sec++;
            }
            group->loss_history[i].found = 0;
            group->loss_history[i].t =
                    add_timeval(group->loss_history[group->max_txseq].t,tvdiff);
        }
        // Then check for missed packets up to MAXMISORDER less than the current
        // Don't do this part unless we have at least MAXMISORDER packets
        // TODO: address issue of start_txseq being within MAXMISORDER sequence
        // numbers from the maximum
        if (group->seq_wrap ||((uint16_t)(group->max_txseq -
                                    group->start_txseq) >= MAXMISORDER)) {
            for (i = group->max_txseq - MAXMISORDER;
                    i != (uint16_t)(txseq - MAXMISORDER); i++) {
                if (!group->loss_history[i].found &&
                        ((diff_usec(group->loss_history[i].t,
                                    group->loss_events[0].t) > grtt_usec) ||
                            group->slowstart)) {
                    new_loss_event(group, i);
                }
            }
        }
        group->max_txseq = txseq;
        if (ecn) {
            glog4(group, "Seq %d marked by ECN", txseq);
            if ((diff_usec(group->loss_history[txseq].t,
                    group->loss_events[0].t) > grtt_usec) || group->slowstart) {
                new_loss_event(group, txseq);
            }
        }
    }
    group->loss_events[0].len = ((group->seq_wrap << 16) | group->max_txseq) -
                                group->loss_events[0].start_seq;
    glog5(group, "current cc len = %d", group->loss_events[0].len);
    glog5(group, "seq_wrap=%d, max_txseq=%u, start_seq=%u",
            group->seq_wrap, group->max_txseq, group->loss_events[0].start_seq);
}
Exemplo n.º 15
0
int main (int argc, char *argv[])
{
#ifdef HW_RVL
  /* initialize DVD device */
  DI_Init();
#endif

  u16 usBetweenFrames;
  long long now, prev;
  
  /* Initialize OGC subsystems */
  ogc_video__init();
  ogc_input__init();
  ogc_audio__init();

#ifdef HW_DOL
  /* Initialize GC DVD interface */
  DVD_Init ();
  dvd_drive_detect();
#endif

#ifdef HW_RVL
  /* Power Button callback */
  SYS_SetPowerCallback(Power_Off);
#endif

  /* Initialize FAT Interface */
  if (fatInitDefault() == true)
  {
    fat_enabled = 1;
  }

  /* Default Config */
  legal();
  set_option_defaults ();
  config_load();
#ifdef HW_RVL
  /* Load SMB Settings */
  loadSettings();
#endif

  /* Restore Recent Files list */
  set_history_defaults();
  history_load();

  /* Initialize Virtual Machine */
  init_machine ();

  /* Show Menu */
  MainMenu();
  ConfigRequested = 0;

  /* Initialize Frame timings */
  frameticker = 0;
  usBetweenFrames = sms.display ? 20000 : 16666;
  prev = gettime();

  /* Emulation Loop */
  while (1)
  {
    /* update inputs */
    ogc_input__update();

    /* Frame synchronization */
    if (gc_pal != sms.display)
    {
      /* use timers */
      now = gettime();
      if (diff_usec(prev, now) > usBetweenFrames)
      {
        /* Frame skipping */
        prev = now;
        system_frame(1);
      }
      else
      {
        /* Delay */
        while (diff_usec(prev, now) < usBetweenFrames) now = gettime();

        /* Render Frame */
        prev = now;
        system_frame(0);
      }
    }
    else
    {
      /* use VSync */
      if (frameticker > 1)
      {
        /* Frame skipping */
        frameticker--;
        system_frame (1);
      }
      else
      {
        /* Delay */
        while (!frameticker) usleep(10);  
        
        system_frame (0);
      }

      frameticker--;
    }

    /* update video & audio */
    ogc_video__update();
    ogc_audio__update();

    /* Check for Menu request */
    if (ConfigRequested)
    {
      /* reset AUDIO */
      ogc_audio__reset();

      /* go to menu */
      MainMenu ();
      ConfigRequested = 0;
      ogc_video__reset();

      /* reset frame timings */
      frameticker = 0;
      usBetweenFrames = sms.display ? 20000 : 16666;
      prev = gettime();
    }
  }
  return 0;
}
Exemplo n.º 16
0
static void
compute_difference(pmytime pt) {
  pt->interval+= diff_usec(pt->start, pt->stop);
}
Exemplo n.º 17
0
/****************************************************************************
* systemGetClock
*
* Returns number of milliseconds since program start
****************************************************************************/
u32 systemGetClock( void )
{
	u32 now = gettime();
	return diff_usec(start, now) / 1000;
}
inline bool
nubot::Time::operator> (const nubot::Time& src) const throw () {
  return (diff_usec (src)>0);
}
Exemplo n.º 19
0
void MPlayerInput()
{
	bool ir = false;
	bool inDVDMenu = wiiInDVDMenu();
	static bool volumeUpdated = false;

	if(userInput[0].wpad->ir.valid)
		ir = true;

	if(userInput[0].wpad->btns_d & WPAD_BUTTON_1)
		osdLevel ^= 1;
	else if(ExitRequested || userInput[0].wpad->btns_d & WPAD_BUTTON_HOME)
		wiiGotoGui();

	if(!inDVDMenu)
	{
		if(userInput[0].wpad->btns_d & WPAD_BUTTON_A)
		{
			// Hack to allow people to unpause while the OSD GUI is visible by
			// pointing above the button bar and pressing A. We also need to be outside
			// the boundaries of the volume bar area, when it is visible
			int x = userInput[0].wpad->ir.x;
			int y = userInput[0].wpad->ir.y;

			int xoffset = 20;

			if(screenwidth == 768)
				xoffset = 80;

			if(!drawGui || (y < 360 && 
				(!VideoVolumeLevelBarVisible() || !(x > xoffset && x < xoffset+100 && y > 180))))
			{
				wiiPause();
			}
		}
		else if(userInput[0].wpad->btns_h & WPAD_BUTTON_PLUS)
		{
			volnow = gettime();
	
			if(diff_usec(volprev, volnow) > VOL_DELAY)
			{
				volprev = volnow;
				WiiSettings.volume++;
				if(WiiSettings.volume > 100) WiiSettings.volume = 100;
				wiiSetVolume(WiiSettings.volume);
				volumeUpdated = true;
				ShowVideoVolumeLevelBar();
			}
		}
		else if(userInput[0].wpad->btns_h & WPAD_BUTTON_MINUS)
		{
			volnow = gettime();
	
			if(diff_usec(volprev, volnow) > VOL_DELAY)
			{
				volprev = volnow;
				WiiSettings.volume--;
				if(WiiSettings.volume < 0) WiiSettings.volume = 0;
				wiiSetVolume(WiiSettings.volume);
				volumeUpdated = true;
				ShowVideoVolumeLevelBar();
			}
		}
		else if (userInput[0].wpad->btns_h & WPAD_BUTTON_B)
		{
			unsigned int delay = (resizeinitial == 1) ? RESIZE_INITIAL_DELAY : RESIZE_DELAY;
			int resizenow = gettime();

			if(userInput[0].wpad->btns_h & WPAD_BUTTON_RIGHT)
			{
				if(diff_usec(resizeprev, resizenow) > delay)
				{
					resizeinitial++;
					resizeprev = resizenow;
					MPlayerResize(+0.003F, 0.00F);
				}
			}
			else if(userInput[0].wpad->btns_h & WPAD_BUTTON_LEFT)
			{
				if(diff_usec(resizeprev, resizenow) > delay)
				{
					resizeinitial++;
					resizeprev = resizenow;
					MPlayerResize(-0.003F, 0.00F);
				}
			}
			else if(userInput[0].wpad->btns_h & WPAD_BUTTON_UP)
			{
				if(diff_usec(resizeprev, resizenow) > delay)
				{
					resizeinitial++;
					resizeprev = resizenow;
					MPlayerResize(0.00F, +0.003F);
				}
			}
			else if(userInput[0].wpad->btns_h & WPAD_BUTTON_DOWN)
			{
				if(diff_usec(resizeprev, resizenow) > delay)
				{
					resizeinitial++;
					resizeprev = resizenow;
					MPlayerResize(0.00F, -0.003F);
				}
			}

			if(userInput[0].wpad->btns_d & (WPAD_BUTTON_RIGHT | WPAD_BUTTON_LEFT |
											WPAD_BUTTON_UP | WPAD_BUTTON_DOWN))
			{
				resizeinitial = 0;
			}
		}
		else if(userInput[0].wpad->btns_d & WPAD_BUTTON_RIGHT)
		{
			wiiFastForward();
		}
		else if(userInput[0].wpad->btns_d & WPAD_BUTTON_LEFT)
		{
			wiiRewind();
		}
		else if(userInput[0].wpad->btns_d & WPAD_BUTTON_UP)
		{
			if(!wiiIsPaused())
				wiiSetProperty(MP_CMD_SUB_SELECT, 0);
		}
		else if(userInput[0].wpad->btns_d & WPAD_BUTTON_DOWN)
		{
			if(!wiiIsPaused())
				wiiSetProperty(MP_CMD_SWITCH_AUDIO, 0);
		}
		else if(userInput[0].wpad->btns_d & WPAD_BUTTON_2)
		{
			wiiDVDNav(MP_CMD_DVDNAV_MENU);
		}
	}
	else
	{
		if(userInput[0].wpad->ir.valid)
			wiiUpdatePointer((int)userInput[0].wpad->ir.x, (int)userInput[0].wpad->ir.y);

		if(userInput[0].wpad->btns_d & WPAD_BUTTON_A)
		{
			if(userInput[0].wpad->ir.valid)
				wiiDVDNav(MP_CMD_DVDNAV_MOUSECLICK);
			else
				wiiDVDNav(MP_CMD_DVDNAV_SELECT);
		}
		else if (userInput[0].wpad->btns_h & WPAD_BUTTON_B)
		{
			unsigned int delay = (resizeinitial == 1) ? RESIZE_INITIAL_DELAY : RESIZE_DELAY;
			int resizenow = gettime();

			if(userInput[0].wpad->btns_h & WPAD_BUTTON_RIGHT)
			{
				if(diff_usec(resizeprev, resizenow) > delay)
				{
					resizeinitial++;
					resizeprev = resizenow;
					MPlayerResize(+0.003F, 0.00F);
				}
			}
			else if(userInput[0].wpad->btns_h & WPAD_BUTTON_LEFT)
			{
				if(diff_usec(resizeprev, resizenow) > delay)
				{
					resizeinitial++;
					resizeprev = resizenow;
					MPlayerResize(-0.003F, 0.00F);
				}
			}
			else if(userInput[0].wpad->btns_h & WPAD_BUTTON_UP)
			{
				if(diff_usec(resizeprev, resizenow) > delay)
				{
					resizeinitial++;
					resizeprev = resizenow;
					MPlayerResize(0.00F, +0.003F);
				}
			}
			else if(userInput[0].wpad->btns_h & WPAD_BUTTON_DOWN)
			{
				if(diff_usec(resizeprev, resizenow) > delay)
				{
					resizeinitial++;
					resizeprev = resizenow;
					MPlayerResize(0.00F, -0.003F);
				}
			}

			if(userInput[0].wpad->btns_d & (WPAD_BUTTON_RIGHT | WPAD_BUTTON_LEFT |
			                                WPAD_BUTTON_UP | WPAD_BUTTON_DOWN))
			{
				resizeinitial = 0;
			}
		}
		else if(userInput[0].wpad->btns_d & WPAD_BUTTON_UP)
		{
			wiiDVDNav(MP_CMD_DVDNAV_UP);
		}
		else if(userInput[0].wpad->btns_d & WPAD_BUTTON_DOWN)
		{
			wiiDVDNav(MP_CMD_DVDNAV_DOWN);
		}
		else if(userInput[0].wpad->btns_d & WPAD_BUTTON_RIGHT)
		{
			wiiDVDNav(MP_CMD_DVDNAV_RIGHT);
		}
		else if(userInput[0].wpad->btns_d & WPAD_BUTTON_LEFT)
		{
			wiiDVDNav(MP_CMD_DVDNAV_LEFT);
		}
	}

	if(volumeUpdated)
	{
		volnow = gettime();

		if(volnow > volprev && diff_usec(volprev, volnow) > VOLDISP_MAX)
			volumeUpdated = false;
		else
			ir = true; // trigger display
	}

	if(ir || BufferingStatusSet() || osdLevel)
	{
		drawGui = true;
	}
	else if(drawGui)
	{
		drawGui = false;
		HideVideoVolumeLevelBar();
		ShutoffRumble();
	}
}
Exemplo n.º 20
0
/**
 * Performs the Transfer phase for a particular file
 * Returns 1 if at least one client finished, 0 if all are dropped or aborted
 */
int transfer_phase(struct finfo_t *finfo)
{
    unsigned char *packet, *encpacket, *data;
    char path[MAXPATHNAME];
    struct uftp_h *header;
    struct fileseg_h *fileseg;
    int max_time, alldone, numbytes, sent_blocks, current_naks;
    unsigned int pass, section, numnaks, block;
    struct timeval start_time, last_sent, current_sent;
    int64_t avgwait, waitcnt, overage, tdiff;
    f_offset_t offset, curr_offset;
    int file, i;

    if (finfo->file_id != 0) {
        // First check to see if all clients are already done for this file.
        // This can happen on a restart when the file finished on the
        // last attempt and responded to the FILEINFO with a COMPLETE
        for (i = 0, alldone = 1; (i < destcount) && alldone; i++) {
            alldone = alldone && ((destlist[i].status == DEST_DONE) ||
                        (client_error(i)) || (destlist[i].clientcnt != -1));
        }
        if (alldone) {
            gettimeofday(&start_time, NULL);
            print_status(finfo, start_time);
            return 1;
        }
    }

    // If rate is -1, use 100Mbps for purpose of calculating max time
    max_time = (int)floor(((double)weight / 100) *
           ((double)finfo->size / (((rate == -1) ? 100000 : rate) / 8) / 1024));
    if (max_time < min_time) {
        max_time = min_time;
    }

    if ((finfo->file_id != 0) && (finfo->ftype == FTYPE_REG)) {
        log(0, 0, "Maximum file transfer time: %d seconds", max_time);
        snprintf(path, sizeof(path), "%s%c%s", finfo->basedir, PATH_SEP,
                                               finfo->filename);
        if ((file = open(path, OPENREAD, 0)) == -1) {
            syserror(0, 0, "Error opening file");
            return 1;
        }
    } else {
        // At end of group, all non-errored client are DEST_DONE from the
        // last file, so reset them to DEST_ACTIVE to get the final COMPLETE.
        for (i = 0; i < destcount; i++) {
            if (!client_error(i)) {
                destlist[i].status = DEST_ACTIVE;
            }
        }
    }

    packet = calloc(mtu, 1);
    encpacket = calloc(mtu, 1);
    if ((packet == NULL) || (encpacket == NULL)) {
        syserror(0, 0, "calloc failed!");
        exit(1);
    }
    header = (struct uftp_h *)packet;
    fileseg = (struct fileseg_h *)(packet + sizeof(struct uftp_h));
    data = (unsigned char *)fileseg + sizeof(struct fileseg_h);
    set_uftp_header(header, FILESEG, finfo, &receive_dest);    

    pass = 1;
    alldone = 0;
    gettimeofday(&start_time, NULL);
    do {
        avgwait = 0;
        waitcnt = 0;
        numnaks = 0;
        overage = 0;
        section = 1;
        curr_offset = 0;
        sent_blocks = 0;

        gettimeofday(&last_sent, NULL);
        if (finfo->file_id != 0) {
            log(0, 0, "Sending file...pass %d", pass);
            lseek_func(file, 0, SEEK_SET);
        } else {
            log(0, 0, "Finishing group");
        }
        fileseg->func = FILESEG;
        fileseg->file_id = htons(finfo->file_id);
        fileseg->pass = pass;
        fileseg->section = htons(section);
        for (block = 0; block < finfo->blocks; block++) {
            // If all clients received this file partially on a prior attempt
            // and it's the first pass, request NAKs for all sections
            // right away and don't send any data packets.
            if (((pass == 1) || finfo->naklist[block]) &&
                    !((pass == 1) && finfo->partial)) {
                if (diff_sec(last_sent, start_time) > max_time) {
                    log0(0, 0, "Max file transfer time exceeded");
                    send_abort(finfo, "Max file transfer time exceeded",
                            &receive_dest, NULL, (keytype != KEY_NONE),
                            !quit_on_error);
                    alldone = 1;
                    for (i = 0; i < destcount; i++) {
                        if (quit_on_error || ((destlist[i].status == DEST_ACTIVE) &&
                                               destlist[i].clientcnt == -1 )) {
                            destlist[i].status = DEST_ABORT;
                        }
                    }
                    break;
                }
                // On the first pass, go straight through the file.
                // On later passes, seek to the next packet.
                if (pass != 1) {
                    log4(0, 0, "Resending %d", block);
                    if (!seek_block(file, block, &offset, curr_offset)) {
                        continue;
                    }
                }
                if ((numbytes = read(file, data, blocksize)) == -1) {
                    syserror(0, 0, "read failed");
                    continue;
                }
                if (pass != 1) {
                    curr_offset = offset + numbytes;
                }

                // Keep track of how long we really slept compared to how
                // long we expected to sleep.  If we went over, subtract the
                // time over from the next sleep time.  This way we maintain
                // the proper average sleep time.  This can result in multiple
                // packets going out at once, potentially losing packets.
                if (packet_wait > overage) {
                    usleep(packet_wait - (int32_t)overage);
                }
                gettimeofday(&current_sent, NULL);
                tdiff = diff_usec(current_sent, last_sent);
                avgwait += tdiff;
                waitcnt++;
                if (packet_wait) overage += tdiff - packet_wait;
                last_sent = current_sent;

                fileseg->seq_num = htonl(block);
                send_data(finfo, packet, numbytes, encpacket);
                sent_blocks++;
            }
            if ((block % (blocksize * 8) == (blocksize * 8) - 1) ||
                    (block == finfo->blocks - 1)) {
                if ((pass == 1) || sent_blocks) {
                    current_naks = get_naks(finfo, pass, section, &alldone);
                    numnaks += current_naks;
                    if ((rate != -1) && (cc_count > 0)) {
                        if (!read_cc_config(cc_config)) {
                            log1(0, 0, "Error rereading congestion control "
                                       "config, using prior values");
                        }
                        adjust_rate(current_naks, sent_blocks);
                    }
                    overage = 0;
                    if (alldone) break;
                }
                sent_blocks = 0;
                gettimeofday(&last_sent, NULL);
                fileseg->section = htons(++section);
            }
        }
        if ((finfo->size == 0) && !alldone) {
            // If it's the end of the group, or an empty file, a DONE was
            // never sent, so send it now
            numnaks += get_naks(finfo, pass, section, &alldone);
        }
        if (finfo->file_id != 0) {
            log(0, 0, "Average wait time = %.2f us",
                       (waitcnt == 0) ? 0 : (float)avgwait / waitcnt);
            log(0, 0, "Received %d distinct NAKs for pass %d", numnaks, pass);
        }
        pass++;
    } while (!alldone);

    if ((finfo->file_id != 0) && (finfo->ftype == FTYPE_REG)) {
        close(file);
    }
    print_status(finfo, start_time);

    free(packet);
    free(encpacket);

    for (i = 0; i < destcount; i++) {
        if (quit_on_error) {
            // Check to see that all finished
            if ((destlist[i].status != DEST_DONE) &&
                    (destlist[i].clientcnt == -1)) {
                return 0;
            }
        } else {
            // Check to see if at least one finished
            if (destlist[i].status == DEST_DONE) {
                return 1;
            }
        }
    }
    if (quit_on_error) {
        return 1;
    } else {
        return 0;
    }
}
Exemplo n.º 21
0
      //end of game, check to see if we have won
      ++games;
      if(won(games_state[curr_iteration]))
      {
        //use backtrack to create solution list
        prev=backtrack[curr_iteration];
        i=12;
        while(i>=0)
        {
          solutions_data[(solutions*13)+i]=prev>>24;
          prev=backtrack[prev%524288];
          --i;
        }
        ++solutions;
      }
    }
    ++curr_iteration;
  }

  free(games_state);
  free(backtrack);
  free(solutions_data);

  gettimeofday(&endTime, NULL);

  printf("Games played:    %6u \n", (unsigned int)games);
  printf("Solutions found: %6u\n", (unsigned int)solutions);
  printf("Time elapsed:    %6ldms\n", diff_usec(startTime, endTime) / 1000);
}

Exemplo n.º 22
0
/**
 * Print the final statistics for the given file while in sync mode
 */
void print_sync_status(const struct finfo_t *finfo, struct timeval start_time)
{
    double elapsed_time, throughput;
    int i;

    if (finfo->file_id == 0) {
        log0(0, 0, "- Status -");
        log0(0, 0, "HSTATS;target;copy;overwrite;"
                   "skip;totalMB;time;speedKB/s");
        for (i = 0; i < destcount; i++) {
            if (destlist[i].clientcnt >= 0) {
                continue;
            }
            if (destlist[i].total_time > 0) {
                throughput = destlist[i].total_size /
                             destlist[i].total_time / 1024;
            } else {
                throughput = 0;
            }
            log0(0, 0, "STATS;%s;%d;%d;%d;%sMB;%.3f;%.2fKB/s",
                    destlist[i].name, destlist[i].num_copy,
                    destlist[i].num_overwrite, destlist[i].num_skip,
                    printll(destlist[i].total_size / 1048576),
                    destlist[i].total_time,
                    throughput);
        }
        return;
    }

    for (i = 0; i < destcount; i++) {
        if (destlist[i].clientcnt >= 0) {
            continue;
        }
        clog0(0, 0, "RESULT;%s;%s;%sKB;", destlist[i].name,
                finfo->destfname, printll(finfo->size / 1024));
        switch (destlist[i].status) {
        case DEST_MUTE:
            slog0("mute;");
            break;
        case DEST_LOST:
            slog0("lost;");
            break;
        case DEST_ABORT:
            slog0("aborted;");
            break;
        case DEST_DONE:
            if (sync_preview) {
                throughput = rate / 8;
                elapsed_time = finfo->size / (throughput * 1024);
            } else {
                elapsed_time = (double)diff_usec(finfo->deststate[i].time,
                                                 start_time) / 1000000;
                if (elapsed_time > 0) {
                    throughput = finfo->size / elapsed_time / 1024;
                } else {
                    throughput = 0;
                }
            }
            switch (destlist[i].comp_status) {
            case COMP_STAT_NORMAL:
                slog0("copy;%.2fKB/s", throughput);
                destlist[i].num_copy++;
                destlist[i].total_time += elapsed_time;
                destlist[i].total_size += finfo->size;
                break;
            case COMP_STAT_SKIPPED:
                slog0("skipped;");
                destlist[i].num_skip++;
                break;
            case COMP_STAT_OVERWRITE:
                slog0("overwritten;%.2fKB/s", throughput);
                destlist[i].num_overwrite++;
                destlist[i].total_time += elapsed_time;
                destlist[i].total_size += finfo->size;
                break;
            case COMP_STAT_REJECTED:
                slog0("rejected;");
                break;
            default:
                slog0("Unknown;");
                break;
            }
            break;
        default:
            slog0("Unknown;");
            break;
        }
    }
}
Exemplo n.º 23
0
/**
 * Creates all directories in the given file's path, removing existing files.
 * Returns 1 on success, 0 on failure
 */
int create_path_to_file(struct group_list_t *group, const char *filename)
{
    char *dir, *base;
    stat_struct statbuf;
    int rval;

    split_path(filename, &dir, &base);
    if (!dir) {
        glog1(group, "Invalid path element %s", filename);
        rval = 0;
        goto end;
    }
#ifdef WINDOWS
    if ((base == NULL) || ((strlen(dir) == 2) && (dir[1] == ':'))) {
#else
    if ((!strcmp(dir, ".")) || (!strcmp(dir, "/"))) {
#endif
        // At top level directory, so stop recursion
        rval = 1;
        goto end;
    }

    if (lstat_func(dir, &statbuf) != -1) {
        if (!S_ISDIR(statbuf.st_mode)) {
            if (unlink(dir) == -1) {
                gsyserror(group, "Failed to delete path element %s", dir);
                rval = 0;
                goto end;
            }
            if (mkdir(dir, 0755) == -1) {
                gsyserror(group, "Failed to create path element %s", dir);
                rval = 0;
                goto end;
            }
        }
    } else {
        // If the file's directory does not exist, recurse first to make sure
        // all parent directories exist
        if (!create_path_to_file(group, dir)) {
            rval = 0;
            goto end;
        }
        if (mkdir(dir, 0755) == -1) {
            gsyserror(group, "Failed to create path element %s", dir);
            rval = 0;
            goto end;
        }
    }

    rval = 1;

end:
    free(dir);
    free(base);
    return rval;
}

void new_loss_event(struct group_list_t *group, uint16_t txseq)
{
    uint32_t seq_long;
    uint16_t count;
    int bytes, avgbytes, rate, grtt_usec;

    glog4(group, "Seq %d starts new loss event", txseq);
    // Found a new loss event
    if (txseq < group->max_txseq - MAXMISORDER) {
        glog5(group, "wrap check, i=%u, maxseq=%u", txseq, group->max_txseq);
        seq_long = ((group->seq_wrap - 1) << 16) | txseq;
    } else {
        seq_long = (group->seq_wrap << 16) | txseq;
    }
    if (group->slowstart) {
        group->slowstart = 0;
        // Initialize loss history 
        count = group->max_txseq;
        bytes = 0;
        grtt_usec = (int)(group->grtt * 1000000);
        while ((count != group->start_txseq) &&
                (diff_usec(group->loss_history[txseq].t,
                   group->loss_history[count].t) < grtt_usec)) {
            bytes += group->loss_history[count--].size;
        }
        rate = (int)(bytes / group->grtt);
        glog4(group, "End slowstart, calculated rate = %d", rate);
        avgbytes= bytes / ((int16_t)(group->max_txseq - count));
        group->loss_events[0].len = (int)(0 + pow(
                (rate * ((group->rtt != 0) ? group->rtt : group->grtt)) / 
                (sqrt(1.5) * 8 * avgbytes), 2));
        glog4(group, "Calculated prior event len = %d (rtt=%f, avgbytes=%d)",
                     group->loss_events[0].len, group->rtt,avgbytes);
    } else {
        group->loss_events[0].len = seq_long - group->loss_events[0].start_seq;
        glog4(group, "Prior event length = %d (i=%u, start=%u)",
                     group->loss_events[0].len,
                     seq_long, group->loss_events[0].start_seq);
    }
    memmove(&group->loss_events[1], &group->loss_events[0],
            sizeof(struct loss_event_t) * 8);
    group->loss_events[0].start_seq = seq_long;
    group->loss_events[0].len = 0;
    group->loss_events[0].t = group->loss_history[txseq].t;
}