Esempio n. 1
0
/**
 * Main loop of the cache process or thread.
 */
static void cache_mainloop(cache_vars_t *s) {
    int sleep_count = 0;
#if FORKED_CACHE
    struct sigaction sa = { 0 };
    sa.sa_handler = SIG_IGN;
    sigaction(SIGUSR1, &sa, NULL);
#endif
    do {
        if (!cache_fill(s)) {
#if FORKED_CACHE
            // Let signal wake us up, we cannot leave this
            // enabled since we do not handle EINTR in most places.
            // This might need extra code to work on BSD.
            sa.sa_handler = dummy_sighandler;
            sigaction(SIGUSR1, &sa, NULL);
#endif
            if (sleep_count < INITIAL_FILL_USLEEP_COUNT) {
                sleep_count++;
                usec_sleep(INITIAL_FILL_USLEEP_TIME);
            } else
                usec_sleep(FILL_USLEEP_TIME); // idle
#if FORKED_CACHE
            sa.sa_handler = SIG_IGN;
            sigaction(SIGUSR1, &sa, NULL);
#endif
        } else
            sleep_count = 0;
    } while (cache_execute_control(s));
}
Esempio n. 2
0
// close audio device
static void uninit(int immed) {
  if (!immed)
    usec_sleep(get_delay() * 1000 * 1000);
  // HACK, make sure jack doesn't loop-output dirty buffers
  reset();
  usec_sleep(100 * 1000);
  jack_client_close(client);
  av_fifo_free(buffer);
  buffer = NULL;
}
Esempio n. 3
0
/* Blink LED */
void *LEDMod(void *ptr) {
    int fd, led_pattern, i;
    char path[MAX_SYSFS_LEN];
    struct trigger_t *trigger = (struct trigger_t *)ptr;
    uint32_t *led_pattern_p;

#if 1
    snprintf(path, MAX_SYSFS_LEN, "/sys/class/gpio/gpio%d/value", trigger->led_pin);
    fd = open(path, O_WRONLY);
    if (fd < 0) {
	fprintf(stderr, "Failed to open gpio value for writing: %s\n", strerror(errno));
	exit(1);
    }

    while (1) {
	pthread_mutex_lock(&lock);
	led_pattern = trigger->led_pattern;
	pthread_mutex_unlock(&lock);

	switch (led_pattern) {
	case LED_ST_HB_SLOW:
	    led_pattern_p = LED_HB_SLOW;
	    break;
	case LED_ST_HB_FAST:
	    led_pattern_p = LED_HB_FAST;
	    break;
	case LED_ST_ERROR:
	    led_pattern_p = LED_ERROR;
	default:
	    led_pattern_p = LED_ERROR;
	}

	for (i = 0; i < LED_PATTERN_MAX; i++) {
	    write(fd, "0", 2);
	    usec_sleep(led_pattern_p[i++] * 1000);
	    write(fd, "1", 2);
	    usec_sleep(led_pattern_p[i] * 1000);
	}
    }
#else
    while (1) {
	usec_sleep(led_period);
	printf("*");
	usec_sleep(led_period);
	printf("-");
    }
#endif
}
Esempio n. 4
0
// close audio device
static void uninit(int immed){
	mp_msg(MSGT_AO,MSGL_V,"SDL: Audio Subsystem shutting down!\n");
	if (!immed)
	  usec_sleep(get_delay() * 1000 * 1000);
	SDL_CloseAudio();
	SDL_QuitSubSystem(SDL_INIT_AUDIO);
}
Esempio n. 5
0
static void uninit(sh_audio_t *sh)
{
    HRESULT ret;
    acm_context_t *priv = sh->context;

retry:
    ret = acmStreamClose(priv->handle, 0);

    if (ret)
    switch(ret)
    {
	case ACMERR_BUSY:
	case ACMERR_CANCELED:
	    mp_msg(MSGT_WIN32, MSGL_DBG2, "ACM_Decoder: stream busy, waiting..\n");
	    usec_sleep(100000000);
	    goto retry;
	case ACMERR_UNPREPARED:
	case ACMERR_NOTPOSSIBLE:
	    return;
	default:
	    mp_msg(MSGT_WIN32, MSGL_WARN, "ACM_Decoder: unknown error occurred: %ld\n", ret);
	    return;
    }

    MSACM_UnregisterAllDrivers();

    free(priv->o_wf);
    free(priv);
}
Esempio n. 6
0
static void mtt_reset(SkelDrvrModuleContext *mcon)
{
	InsLibIntrDesc *isr = mcon->Modld->Isr;
	struct udata	*udata = mcon->UserData;
	unsigned long	flags;

	cdcm_spin_lock_irqsave(&udata->iolock, flags);
	/* quiesce the module */
	__mtt_quiesce(mcon);

	/* reset the module */
	__mtt_cmd(mcon, MttDrvrCommandRESET, 1);
	cdcm_spin_unlock_irqrestore(&udata->iolock, flags);

	usec_sleep(100);

	/*
	 * re-configure the interrupt level
	 * Note that the vector and level share the register
	 */
	if (isr) {
		mtt_writew(mcon, MTT_INTR, isr->Vector |
			mtt_shift_intr_level(isr->Level));
	}
}
Esempio n. 7
0
int stream_check_interrupt(int time) {
    if(!stream_check_interrupt_cb) {
        usec_sleep(time * 1000);
        return 0;
    }
    return stream_check_interrupt_cb(stream_check_interrupt_ctx, time);
}
static void iolog_delay(struct thread_data *td, unsigned long delay)
{
	unsigned long usec = utime_since_now(&td->last_issue);
	unsigned long this_delay;

	if (delay < usec)
		return;

	delay -= usec;

	/*
	 * less than 100 usec delay, just regard it as noise
	 */
	if (delay < 100)
		return;

	while (delay && !td->terminate) {
		this_delay = delay;
		if (this_delay > 500000)
			this_delay = 500000;

		usec_sleep(td, this_delay);
		delay -= this_delay;
	}
}
Esempio n. 9
0
// close audio device
static void uninit(int immed){
        mp_msg(MSGT_AO,MSGL_V,"SDL: Audio Subsystem shutting down!\n");
        if (!immed)
        while(buf_free() < BUFFSIZE - CHUNK_SIZE)
                usec_sleep(50000);
        SDL_CloseAudio();
        SDL_QuitSubSystem(SDL_INIT_AUDIO);
}
Esempio n. 10
0
File: io_u.c Progetto: vsharma13/fio
static enum fio_ddir rate_ddir(struct thread_data *td, enum fio_ddir ddir)
{
	enum fio_ddir odir = ddir ^ 1;
	struct timeval t;
	long usec;

	assert(ddir_rw(ddir));

	if (td->rate_pending_usleep[ddir] <= 0)
		return ddir;

	/*
	 * We have too much pending sleep in this direction. See if we
	 * should switch.
	 */
	if (td_rw(td) && td->o.rwmix[odir]) {
		/*
		 * Other direction does not have too much pending, switch
		 */
		if (td->rate_pending_usleep[odir] < 100000)
			return odir;

		/*
		 * Both directions have pending sleep. Sleep the minimum time
		 * and deduct from both.
		 */
		if (td->rate_pending_usleep[ddir] <=
			td->rate_pending_usleep[odir]) {
			usec = td->rate_pending_usleep[ddir];
		} else {
			usec = td->rate_pending_usleep[odir];
			ddir = odir;
		}
	} else
		usec = td->rate_pending_usleep[ddir];

	io_u_quiesce(td);

	fio_gettime(&t, NULL);
	usec_sleep(td, usec);
	usec = utime_since_now(&t);

	td->rate_pending_usleep[ddir] -= usec;

	odir = ddir ^ 1;
	if (td_rw(td) && __should_check_rate(td, odir))
		td->rate_pending_usleep[odir] -= usec;

	if (ddir_trim(ddir))
		return ddir;

	return ddir;
}
Esempio n. 11
0
// close audio device
static void uninit(int immed){
	mp_msg(MSGT_AO,MSGL_V,"SDL: Audio Subsystem shutting down!\n");
	if (!immed)
	  usec_sleep(get_delay() * 1000 * 1000);
#ifdef _WIN32
    if (!hSDL) return;
#endif
	SDL_CloseAudio();
	SDL_QuitSubSystem(SDL_INIT_AUDIO);
	av_fifo_free(buffer);
#ifdef _WIN32
	FreeLibrary(hSDL);
#endif
}
Esempio n. 12
0
int cache_do_control(stream_t *stream, int cmd, void *arg) {
  cache_vars_t* s = stream->cache_data;
  switch (cmd) {
    case STREAM_CTRL_SEEK_TO_TIME:
      s->control_double_arg = *(double *)arg;
      s->control = cmd;
      break;
    case STREAM_CTRL_SEEK_TO_CHAPTER:
    case STREAM_CTRL_SET_ANGLE:
      s->control_uint_arg = *(unsigned *)arg;
      s->control = cmd;
      break;
// the core might call these every frame, they are too slow for this...
    case STREAM_CTRL_GET_TIME_LENGTH:
//    case STREAM_CTRL_GET_CURRENT_TIME:
      *(double *)arg = s->stream_time_length;
      return s->stream_time_length ? STREAM_OK : STREAM_UNSUPPORTED;
    case STREAM_CTRL_GET_NUM_CHAPTERS:
    case STREAM_CTRL_GET_CURRENT_CHAPTER:
    case STREAM_CTRL_GET_ASPECT_RATIO:
    case STREAM_CTRL_GET_NUM_ANGLES:
    case STREAM_CTRL_GET_ANGLE:
    case -2:
      s->control = cmd;
      break;
    default:
      return STREAM_UNSUPPORTED;
  }
  while (s->control != -1)
    usec_sleep(CONTROL_SLEEP_TIME);
  switch (cmd) {
    case STREAM_CTRL_GET_TIME_LENGTH:
    case STREAM_CTRL_GET_CURRENT_TIME:
    case STREAM_CTRL_GET_ASPECT_RATIO:
      *(double *)arg = s->control_double_arg;
      break;
    case STREAM_CTRL_GET_NUM_CHAPTERS:
    case STREAM_CTRL_GET_CURRENT_CHAPTER:
    case STREAM_CTRL_GET_NUM_ANGLES:
    case STREAM_CTRL_GET_ANGLE:
      *(unsigned *)arg = s->control_uint_arg;
      break;
    case STREAM_CTRL_SEEK_TO_CHAPTER:
    case STREAM_CTRL_SEEK_TO_TIME:
    case STREAM_CTRL_SET_ANGLE:
      stream->pos = s->read_filepos = s->control_new_pos;
      break;
  }
  return s->control_res;
}
Esempio n. 13
0
File: log.c Progetto: jeefke/fio
int read_iolog_get(struct thread_data *td, struct io_u *io_u)
{
	struct io_piece *ipo;
	unsigned long elapsed;
	
	while (!flist_empty(&td->io_log_list)) {
		int ret;

		ipo = flist_entry(td->io_log_list.next, struct io_piece, list);
		flist_del(&ipo->list);
		remove_trim_entry(td, ipo);

		ret = ipo_special(td, ipo);
		if (ret < 0) {
			free(ipo);
			break;
		} else if (ret > 0) {
			free(ipo);
			continue;
		}

		io_u->ddir = ipo->ddir;
		if (ipo->ddir != DDIR_WAIT) {
			io_u->offset = ipo->offset;
			io_u->buflen = ipo->len;
			io_u->file = td->files[ipo->fileno];
			get_file(io_u->file);
			dprint(FD_IO, "iolog: get %llu/%lu/%s\n", io_u->offset,
						io_u->buflen, io_u->file->file_name);
			if (ipo->delay)
				iolog_delay(td, ipo->delay);
		} else {
			elapsed = mtime_since_genesis();
			if (ipo->delay > elapsed)
				usec_sleep(td, (ipo->delay - elapsed) * 1000);
				
		}

		free(ipo);
		
		if (io_u->ddir != DDIR_WAIT)
			return 0;
	}

	td->done = 1;
	return 1;
}
Esempio n. 14
0
// close audio device
static void uninit(int immed) {
  ALCcontext *ctx = alcGetCurrentContext();
  ALCdevice *dev = alcGetContextsDevice(ctx);
  free(tmpbuf);
  if (!immed) {
    ALint state;
    alGetSourcei(sources[0], AL_SOURCE_STATE, &state);
    while (state == AL_PLAYING) {
      usec_sleep(10000);
      alGetSourcei(sources[0], AL_SOURCE_STATE, &state);
    }
  }
  reset();
  alcMakeContextCurrent(NULL);
  alcDestroyContext(ctx);
  alcCloseDevice(dev);
}
Esempio n. 15
0
static int cache_read(cache_vars_t *s, unsigned char *buf, int size)
{
  int total=0;
  while(size>0){
    int pos,newb,len;

  //printf("CACHE2_READ: 0x%X <= 0x%X <= 0x%X  \n",s->min_filepos,s->read_filepos,s->max_filepos);

    if(s->read_filepos>=s->max_filepos || s->read_filepos<s->min_filepos){
	// eof?
	if(s->eof) break;
	// waiting for buffer fill...
	usec_sleep(READ_USLEEP_TIME); // 10ms
	continue; // try again...
    }

    newb=s->max_filepos-s->read_filepos; // new bytes in the buffer
    if(newb<min_fill) min_fill=newb; // statistics...

//    printf("*** newb: %d bytes ***\n",newb);

    pos=s->read_filepos - s->offset;
    if(pos<0) pos+=s->buffer_size; else
    if(pos>=s->buffer_size) pos-=s->buffer_size;

    if(newb>s->buffer_size-pos) newb=s->buffer_size-pos; // handle wrap...
    if(newb>size) newb=size;

    // check:
    if(s->read_filepos<s->min_filepos) mp_msg(MSGT_CACHE,MSGL_ERR,"Ehh. s->read_filepos<s->min_filepos !!! Report bug...\n");

    // len=write(mem,newb)
    //printf("Buffer read: %d bytes\n",newb);
    memcpy(buf,&s->buffer[pos],newb);
    buf+=newb;
    len=newb;
    // ...

    s->read_filepos+=len;
    size-=len;
    total+=len;

  }
  cache_fill_status=(s->max_filepos-s->read_filepos)/(s->buffer_size / 100);
  return total;
}
Esempio n. 16
0
File: log.c Progetto: jeefke/fio
static void iolog_delay(struct thread_data *td, unsigned long delay)
{
	unsigned long usec = utime_since_now(&td->last_issue);

	if (delay < usec)
		return;

	delay -= usec;

	/*
	 * less than 100 usec delay, just regard it as noise
	 */
	if (delay < 100)
		return;

	usec_sleep(td, delay);
}
Esempio n. 17
0
static uint32_t clkgen_rval(struct cvorg *cvorg, unsigned int addr)
{
	uint32_t val;
	int i;

	cvorg_writew(cvorg, CVORG_CLKCTL, CVORG_AD9516_OP_READ | (addr << 8));

	/* try a few times, although normally 5us should be enough */
	for (i = 0; i < 3; i++) {
		/* delay to allow the serial transfer to happen */
		usec_sleep(CVORG_AD9516_SPI_SLEEP_US);
		val = cvorg_readw(cvorg, CVORG_CLKCTL);
		if (clkgen_ok(val, addr))
			goto out;
	}
 out:
	return val;
}
Esempio n. 18
0
static int stream_reconnect(stream_t *s)
{
#define MAX_RECONNECT_RETRIES 5
#define RECONNECT_SLEEP_MS 1000
    int retry = 0;
    int64_t pos = s->pos;
    // Seeking is used as a hack to make network streams
    // reopen the connection, ideally they would implement
    // e.g. a STREAM_CTRL_RECONNECT to do this
    do {
        if (retry >= MAX_RECONNECT_RETRIES)
            return 0;
        if (retry) usec_sleep(RECONNECT_SLEEP_MS * 1000);
        retry++;
        s->eof=1;
        stream_reset(s);
    } while (stream_seek_internal(s, pos) >= 0 || s->pos != pos); // seek failed
    return 1;
}
Esempio n. 19
0
int main() {
    int i,j, r, c = 200;
    long long t = 0;

    InitTimer();

    for (i = 0; i < c; i++) {
        const int delay = rand() / (RAND_MAX / 1e5);
        j = GetTimer();
#if 1
        r = usec_sleep(delay);
#else
        r = sleep_accurate(delay / 1e6) * 1e6;
#endif
        j = (GetTimer() - j) - delay;
        printf("sleep time:%8i %5i (%i)\n", delay, j, j - r);
        t += j - r;
    }
    fprintf(stderr, "average error:\t%lli\n", t / c);

    return 0;
}
Esempio n. 20
0
void ipu_image_stop()
{
	int lcd_level = 0;
	lcd_level = kernel_ioctl(&lcd_level,KERNEL_BACKLIGHT_CTRL);
	lcd_ioctl(0, IOCTL_IPU_TO_DMA1);
	SetVideoOutMode(NULL);
	FreeImage();
	
	int pmdata = -1;
	int curlevel = kernel_ioctl(&pmdata,KERNEL_PM_CONTROL);
	if(curlevel != init_pm_level)
	{
		
		int enablelcd = 0;
		kernel_ioctl(&enablelcd,KERNEL_LCD_CTRL);
		kernel_ioctl(&init_pm_level,KERNEL_PM_CONTROL);
		enablelcd = 1;
		kernel_ioctl(&enablelcd,KERNEL_LCD_CTRL);
		
	}	
	usec_sleep(150000);
	// kernel_ioctl(&lcd_level,KERNEL_BACKLIGHT_CTRL);

}
Esempio n. 21
0
void rate_throttle(struct thread_data *td, unsigned long time_spent,
		   unsigned int bytes)
{
	unsigned long usec_cycle;
	unsigned int bs;

	if (!td->o.rate && !td->o.rate_iops)
		return;

	if (td_rw(td))
		bs = td->o.rw_min_bs;
	else if (td_read(td))
		bs = td->o.min_bs[DDIR_READ];
	else
		bs = td->o.min_bs[DDIR_WRITE];

	usec_cycle = td->rate_usec_cycle * (bytes / bs);

	if (time_spent < usec_cycle) {
		unsigned long s = usec_cycle - time_spent;

		td->rate_pending_usleep += s;

		if (td->rate_pending_usleep >= 100000) {
			struct timeval t;

			fio_gettime(&t, NULL);
			usec_sleep(td, td->rate_pending_usleep);
			td->rate_pending_usleep -= utime_since_now(&t);
		}
	} else {
		long overtime = time_spent - usec_cycle;

		td->rate_pending_usleep -= overtime;
	}
}
Esempio n. 22
0
void Init_Direct_Mode(mp_image_t *mpi)
{
	if ((LCD_OUT & display_mode) == TV_OUT)
	{
		img_param.ipu_d_fmt |= (OUT_FMT_YUV422 | (1 << 16));
		img_param.in_bpp = 16;
	}
	else
	{
        if(get_screen_bpp()==32){
            img_param.ipu_d_fmt |= OUT_FMT_RGB888;
            img_param.in_bpp = 32;
        }else if(get_screen_bpp()==16){
            img_param.ipu_d_fmt |= OUT_FMT_RGB565;
            img_param.in_bpp = 16;
        }else{
            img_param.ipu_d_fmt |= OUT_FMT_RGB888;
            img_param.in_bpp = 32;
        }
            
		
	}
    
	if(display_mode & DECODE_BUFFER)
	{
  		img_param.y_buf = mpi->planes[0];
		img_param.u_buf = mpi->planes[1];
		img_param.v_buf = mpi->planes[2];
		stride.y = mpi->stride[0];
		stride.u = mpi->stride[1];
		stride.v = mpi->stride[2];
		__dcache_writeback_all();
  		jz47_put_image_with_ipu = jz47_put_image_with_direct_ipu_nobuffer;
		printf("direct buf\n");
	}else
	{

		CreateImage(mpi->width,mpi->height,mpi->chroma_width,mpi->chroma_height,mpi->bpp);
		mpi_copy(yuv_cur,mpi);
		img_param.y_buf = yuv_cur->y_framebuf;
		img_param.u_buf = yuv_cur->u_framebuf;
		img_param.v_buf = yuv_cur->v_framebuf;
		stride.y = yuv_cur->ystride;
		stride.u = yuv_cur->ustride;
		stride.v = yuv_cur->vstride;
		yuv_cur = yuv_cur->nextframe;
		jz47_put_image_with_ipu = jz47_put_image_with_direct_ipu_buffer;
		printf("create buf\n");
	}
 	printf("stride.y = %d\n",stride.y);
  	printf("stride.u = %d\n",stride.u);
  	printf("stride.v = %d\n",stride.v);
	printf("display_mode = %x\n",display_mode);
    
    
	if(init_pm_level == -1)
	{	
		init_pm_level = -1;
		init_pm_level = kernel_ioctl(&init_pm_level,KERNEL_PM_CONTROL);
	
		int lcd_level = 0;
		lcd_level = kernel_ioctl(&lcd_level,KERNEL_BACKLIGHT_CTRL);
        
        codecs_t *codec = mplayer_get_code_info(1);
        
        int isrun_fast = 0;
        isrun_fast = (mpi->width * mpi->height >= 1280*720);
        
           
       
        if (!isrun_fast) isrun_fast = Is_Fast_Codes(codec->dll,mpi,"vc1",1024*576);
        if (!isrun_fast) isrun_fast = Is_Fast_Codes(codec->dll,mpi,"wmv3",1024*576);
        if (!isrun_fast) isrun_fast = Is_Fast_Codes(codec->dll,mpi,"h264",720*480);
        
        F("mplayer enter fast mode codecs = %s width = %d height = %d isrun_fast =%d\n",codec->dll,mpi->width,mpi->height,isrun_fast);
		if(isrun_fast)
		{
			int enablelcd = 0;
			kernel_ioctl(&enablelcd,KERNEL_LCD_CTRL);
            
			int curlevel = 4;
			kernel_ioctl(&curlevel,KERNEL_PM_CONTROL); //5 = 432000000
			enablelcd = 1;
			kernel_ioctl(&enablelcd,KERNEL_LCD_CTRL);

		}	
		lcd_ioctl(&img_param, IOCTL_DMA1_TO_IPU);
		usec_sleep(20000);
		kernel_ioctl(&lcd_level,KERNEL_BACKLIGHT_CTRL);
	}else
	{
		lcd_ioctl(&img_param, IOCTL_DMA1_TO_IPU);
	}
}
Esempio n. 23
0
int main(int argc, char **argv) {
    pthread_t pth;
    int opt;
    struct ifreq ifr;
    struct trigger_t trigger_data;
    struct sockaddr_can caddr;
    fd_set readfds, exceptfds;
    struct can_frame frame;
    uint16_t member;
    uint8_t buffer[MAXLEN];

    memset(&trigger_data, 0, sizeof(trigger_data));
    memset(ifr.ifr_name, 0, sizeof(ifr.ifr_name));
    strcpy(ifr.ifr_name, "can0");

    trigger_data.led_pin = -1;
    trigger_data.pb_pin = -1;

    trigger_data.interval = DEF_INTERVAL;

    while ((opt = getopt(argc, argv, "i:l:p:t:fvh?")) != -1) {
	switch (opt) {
	case 'i':
	    strncpy(ifr.ifr_name, optarg, sizeof(ifr.ifr_name));
	    break;
	case 't':
	    trigger_data.interval = atoi(optarg);
	    break;
	case 'l':
	    trigger_data.led_pin = atoi(optarg);
	    break;
	case 'p':
	    trigger_data.pb_pin = atoi(optarg);
	    break;
	case 'v':
	    trigger_data.verbose = 1;
	    break;
	case 'f':
	    trigger_data.background = 0;
	    break;
	case 'h':
	case '?':
	    usage(basename(argv[0]));
	    exit(EXIT_SUCCESS);
	default:
	    usage(basename(argv[0]));
	    exit(EXIT_FAILURE);
	}
    }

    /* prepare CAN socket */
    if ((trigger_data.socket = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) {
	fprintf(stderr, "error creating CAN socket: %s\n", strerror(errno));
	exit(EXIT_FAILURE);
    }

    memset(&caddr, 0, sizeof(caddr));
    caddr.can_family = AF_CAN;
    if (ioctl(trigger_data.socket, SIOCGIFINDEX, &ifr) < 0) {
	fprintf(stderr, "setup CAN socket error: %s %s\n", strerror(errno), ifr.ifr_name);
	exit(EXIT_FAILURE);
    }
    caddr.can_ifindex = ifr.ifr_ifindex;

    if (bind(trigger_data.socket, (struct sockaddr *)&caddr, sizeof(caddr)) < 0) {
	fprintf(stderr, "error binding CAN socket: %s\n", strerror(errno));
	exit(EXIT_FAILURE);
    }

    trigger_data.caddr = caddr;

    /* Create thread if LED pin defined */
    if ((trigger_data.led_pin) > 0) {
	trigger_data.led_pattern = LED_ST_HB_SLOW;
	gpio_export(trigger_data.led_pin);
	gpio_direction(trigger_data.led_pin, 0);

	if (pthread_mutex_init(&lock, NULL)) {
	    fprintf(stderr, "can't init mutex %s\n", strerror(errno));
	    exit(EXIT_FAILURE);
	}

	if (pthread_create(&pth, NULL, LEDMod, &trigger_data)) {
	    fprintf(stderr, "can't create pthread %s\n", strerror(errno));
	    exit(EXIT_FAILURE);
	}
	if (!trigger_data.background && trigger_data.verbose)
	    printf("created LED thread\n");
    }

    if (trigger_data.background) {
	pid_t pid;

	/* fork off the parent process */
	pid = fork();
	if (pid < 0) {
	    exit(EXIT_FAILURE);
	}
	/* if we got a good PID, then we can exit the parent process. */
	if (pid > 0) {
	    if (trigger_data.verbose)
		printf("Going into background ...\n");
	    exit(EXIT_SUCCESS);
	}
    }

    /* initialize push button */
    if ((trigger_data.pb_pin) > 0) {
	/* first free pin */
	gpio_unexport(trigger_data.pb_pin);
	gpio_export(trigger_data.pb_pin);
	gpio_direction(trigger_data.pb_pin, 1);
	gpio_edge(trigger_data.pb_pin, EDGE_FALLING);
	trigger_data.pb_fd = gpio_open(trigger_data.pb_pin);
    }

    FD_ZERO(&readfds);
    FD_ZERO(&exceptfds);
    /* delete pending push button event */
    if ((trigger_data.pb_pin) > 0) {
	read(trigger_data.pb_fd, NULL, 100);
	lseek(trigger_data.pb_fd, 0, SEEK_SET);
    }
    /* loop forever TODO: if interval is set */
    while (1) {
	FD_SET(trigger_data.socket, &readfds);
	/* extend FD_SET only if push button pin is set */
	if (trigger_data.pb_pin > 0)
	    FD_SET(trigger_data.pb_fd, &exceptfds);
	if (select(MAX(trigger_data.socket, trigger_data.pb_fd) + 1, &readfds, NULL, &exceptfds, NULL) < 0) {
	    fprintf(stderr, "select error: %s\n", strerror(errno));
	    exit(EXIT_FAILURE);
	}
	/* CAN frame event */
	if (FD_ISSET(trigger_data.socket, &readfds)) {
	    if (read(trigger_data.socket, &frame, sizeof(struct can_frame)) < 0)
		fprintf(stderr, "error reading CAN frame: %s\n", strerror(errno));

	    if (frame.can_id & CAN_EFF_FLAG) {
		switch ((frame.can_id & 0x00FF0000UL) >> 16) {
		case 0x31:
		    if (trigger_data.verbose)
			print_can_frame(F_CAN_FORMAT_STRG, &frame);
		    memcpy(&member, frame.data, sizeof(member));
		    member = ntohs(member);
		    /* look for MS2 */
		    if ((member & 0xfff0) == 0x4d50)
			get_ms2_dbsize(&trigger_data);
		    break;
		case 0x41:
		    if (trigger_data.verbose)
			print_can_frame(F_CAN_FORMAT_STRG, &frame);
		    break;
		case 0x42:
		    get_data(&trigger_data, &frame);
		    /* if (trigger_data.verbose)
		       print_can_frame(F_CAN_FORMAT_STRG, &frame); */
		    break;
		default:
		    if (trigger_data.verbose)
			print_can_frame(F_CAN_FORMAT_STRG, &frame);
		    break;
		}
	    }
	}
	/* push button event */
	if (FD_ISSET(trigger_data.pb_fd, &exceptfds)) {
	    set_led_pattern(&trigger_data, LED_ST_HB_FAST);

	    /* wait some time for LED pattern change */
	    usec_sleep(1000 * 1000);
	    /* send CAN Member Ping */
	    frame.can_id = 0x00300300;
	    frame.can_dlc = 0;
	    memset(frame.data, 0, 8);
	    if (send_can_frame(trigger_data.socket, &frame, trigger_data.verbose) < 0)
		fprintf(stderr, "can't send CAN Member Ping: %s\n", strerror(errno));

	    lseek(trigger_data.pb_fd, 0, SEEK_SET);
	    if (read(trigger_data.pb_fd, buffer, sizeof(buffer)) < 0)
		fprintf(stderr, "error reading GPIO status: %s\n", strerror(errno));
	    printf("push button event\n");
	}
    }

    /* TODO : wait until copy is done */

    if ((trigger_data.pb_pin) > 0)
	gpio_unexport(trigger_data.pb_pin);
    if ((trigger_data.led_pin) > 0) {
	gpio_unexport(trigger_data.led_pin);
	pthread_join(pth, (void *)&trigger_data);
	pthread_mutex_unlock(&lock);
    }
    return 0;
}
Esempio n. 24
0
/**
 * @brief User entry point in driver/simulator ioctl routine.
 *
 * @param proceed -- if standard code execution should be proceed
 * @param sptr    -- statics table pointer
 * @param f       -- file pointer. Lynx/Linux specific.
 *                   See (sys/file.h) for Lynx and (linux/fs.h) for Linux.
 * @param lun     -- minor number (LUN)
 * @param com     -- ioctl number
 * @param arg     -- ioctl arguments
 *
 * It's up to user to set kernel-level errno (by means of @e pseterr call).
 * @e proceed parameter denotes if further standard actions should be proceed
 * after function returns. @b FALSE - means that user-desired operation done
 * all that user wants and there is no further necessaty to perfom any standard
 * operations that follow function call. @b TRUE - means that code that follows
 * function call will be executed.
 *
 * @return return value is the same as in entry point function\n
 *         OK     - if succeed.\n
 *         SYSERR - in case of failure.
 */
int CvorbUserIoctl(int *proceed, register CVORBStatics_t *sptr,
			 struct file *f, int lun, int com, char *arg)
{
	CVORBUserStatics_t *usp = sptr->usrst; /* user statistics table */
	ushort edp[3]; /* [select/get function] ioctl parameters
			  [0] -- module idx
			  [1] -- chan idx
			  [2] -- func idx */
	*proceed = FALSE;

	switch (com) {
	case CVORB_VHDL:
		return read_vhdl(usp, arg);
	case CVORB_PCB:
		return read_pcb(usp, arg);
	case CVORB_TEMP:
		return read_temp(usp, arg);
	case CVORB_MOD_CFG_RD:
		return read_mod_config_reg(usp, arg);
	case CVORB_MOD_CFG_WR:
		return write_mod_config_reg(usp, arg);
	case CVORB_CH_CFG_RD:
		return read_ch_config_reg(usp, arg);
	case CVORB_CH_CFG_WR:
		return write_ch_config_reg(usp, arg);
	case CVORB_MOD_STAT:
		return read_mod_stat(usp, arg);
	case CVORB_CH_STAT:
		return read_ch_stat(usp, arg);
	case CVORB_LOAD_SRAM:
		return load_sram(usp, arg);
	case CVORB_READ_SRAM:
		return read_sram(usp, arg);
	case CVORB_FEN: /* enable function in the function bitmask */
		return enable_function(usp, arg);
	case CVORB_FDIS: /* disable function in the function bitmask */
		return disable_function(usp, arg);
	case CVORB_FEN_RD: /* read Funciton Enable Mask */
		{
			uint m[2]; /* [0] -- bits[63-32]
				      [1] -- bits[31-0] */

			/* ioctl parameters */
			struct {
				ushort m; /* module idx */
				ushort c; /* channel idx */
				uint  *p; /* results goes here */
			} par;

			if (cdcm_copy_from_user(&par, arg, sizeof(par)))
				return SYSERR;

			m[0] = _rcr(par.m, par.c, FCT_EM_H);
			m[1] = _rcr(par.m, par.c, FCT_EM_L);
			return cdcm_copy_to_user(par.p, m, sizeof(m));
		}
	case CVORB_FEN_WR: /* write Function Enable Mask */
		return write_fem_regs(usp, arg);
	case CVORB_FUNC_SEL: /* select function to be played */
		if (cdcm_copy_from_user(&edp, arg, sizeof(edp)))
			return SYSERR;
		_wcr(edp[0], edp[1], FUNC_SEL, edp[2]);
		/* Should wait on Channel Status register bit[9] -- function
		   copy in progress, when data is copying into local SRAM. */
		while(_rcr(edp[0], edp[1], CH_STAT) & 1<<9)
			usec_sleep(1);
		return OK;
	case CVORB_FUNC_GET:	/* get currently selected function */
		if (cdcm_copy_from_user(&edp, arg, sizeof(edp)))
			return SYSERR;
		return _rcr(edp[0], edp[1], FUNC_SEL);
	case CVORB_WRSWP: /* action register.
			     Simulate front panel pulse inputs */
		return write_swp(usp, arg);
	case CVORB_RC_RD:
		return read_recurrent_cycles_reg(usp, arg);
	case CVORB_RC_WR:
		return write_recurrent_cycles_reg(usp, arg);
	case CVORB_DAC_ON:
		return dac_on(usp, arg);
	case CVORB_DAC_OFF:
		/* disable on-board clock generator */
		_wr(0, CLK_GEN_CNTL, AD9516_OFF);
		return OK;
	case AD9516_GET_PLL:
		return get_pll(usp, arg);
	case CVORB_WR_SAR:
		return write_sar(usp, arg);
	default:
		*proceed = TRUE; /* continue standard code execution */
	}

	return OK;
}
Esempio n. 25
0
int stream_enable_cache(stream_t *stream,int size,int min,int seek_limit){
  int ss=(stream->type==STREAMTYPE_VCD)?VCD_SECTOR_DATA:STREAM_BUFFER_SIZE;
  cache_vars_t* s;

  if (stream->type==STREAMTYPE_STREAM && stream->fd < 0) {
    // The stream has no 'fd' behind it, so is non-cacheable
    mp_msg(MSGT_CACHE,MSGL_STATUS,"\rThis stream is non-cacheable\n");
    return 1;
  }

  s=cache_init(size,ss);
  if(s == NULL) return 0;
  stream->cache_data=s;
  s->stream=stream; // callback
  s->seek_limit=seek_limit;


  //make sure that we won't wait from cache_fill
  //more data than it is alowed to fill
  if (s->seek_limit > s->buffer_size - s->fill_limit ){
     s->seek_limit = s->buffer_size - s->fill_limit;
  }
  if (min > s->buffer_size - s->fill_limit) {
     min = s->buffer_size - s->fill_limit;
  }
  
#ifndef WIN32  
  if((stream->cache_pid=fork())){
#else
  {
    DWORD threadId;
    stream_t* stream2=malloc(sizeof(stream_t));
    memcpy(stream2,s->stream,sizeof(stream_t));
    s->stream=stream2;
    stream->cache_pid = CreateThread(NULL,0,ThreadProc,s,0,&threadId);
#endif
    // wait until cache is filled at least prefill_init %
    mp_msg(MSGT_CACHE,MSGL_V,"CACHE_PRE_INIT: %"PRId64" [%"PRId64"] %"PRId64"  pre:%d  eof:%d  \n",
	(int64_t)s->min_filepos,(int64_t)s->read_filepos,(int64_t)s->max_filepos,min,s->eof);
    while(s->read_filepos<s->min_filepos || s->max_filepos-s->read_filepos<min){
	mp_msg(MSGT_CACHE,MSGL_STATUS,MSGTR_CacheFill,
	    100.0*(float)(s->max_filepos-s->read_filepos)/(float)(s->buffer_size),
	    (int64_t)s->max_filepos-s->read_filepos
	);
	if(s->eof) break; // file is smaller than prefill size
	if(mp_input_check_interrupt(PREFILL_SLEEP_TIME))
	  return 0;
    }
    mp_msg(MSGT_CACHE,MSGL_STATUS,"\n");
    return 1; // parent exits
  }
  
#ifdef WIN32
}
static DWORD WINAPI ThreadProc(void*s){
#endif
  
// cache thread mainloop:
  signal(SIGTERM,exit_sighandler); // kill
  while(1){
    if(!cache_fill((cache_vars_t*)s)){
	 usec_sleep(FILL_USLEEP_TIME); // idle
    }
//	 cache_stats(s->cache_data);
  }
}
Esempio n. 26
0
/* unload plugin and deregister from coreaudio */
static void uninit(int immed)
{
  OSStatus            err = noErr;

  if (!immed) {
    long long timeleft=(1000000LL*av_fifo_size(ao->buffer))/ao_data.bps;
    ao_msg(MSGT_AO,MSGL_DBG2, "%d bytes left @%d bps (%d usec)\n", av_fifo_size(ao->buffer), ao_data.bps, (int)timeleft);
    usec_sleep((int)timeleft);
  }

  if (!ao->b_digital) {
      AudioOutputUnitStop(ao->theOutputUnit);
      AudioUnitUninitialize(ao->theOutputUnit);
      CloseComponent(ao->theOutputUnit);
  }
  else {
      /* Stop device. */
      err = AudioDeviceStop(ao->i_selected_dev, ao->renderCallback);
      if (err != noErr)
          ao_msg(MSGT_AO, MSGL_WARN, "AudioDeviceStop failed: [%4.4s]\n", (char *)&err);

      /* Remove IOProc callback. */
      err = AudioDeviceDestroyIOProcID(ao->i_selected_dev, ao->renderCallback);
      if (err != noErr)
          ao_msg(MSGT_AO, MSGL_WARN, "AudioDeviceRemoveIOProc failed: [%4.4s]\n", (char *)&err);

      if (ao->b_revert)
          AudioStreamChangeFormat(ao->i_stream_id, ao->sfmt_revert);

      if (ao->b_changed_mixing && ao->sfmt_revert.mFormatID != kAudioFormat60958AC3)
      {
          UInt32 b_mix;
          Boolean b_writeable;
          /* Revert mixable to true if we are allowed to. */
          err = IsAudioPropertySettable(ao->i_selected_dev,
                                        kAudioDevicePropertySupportsMixing,
                                        &b_writeable);
          err = GetAudioProperty(ao->i_selected_dev,
                                 kAudioDevicePropertySupportsMixing,
                                 sizeof(UInt32), &b_mix);
          if (err != noErr && b_writeable)
          {
              b_mix = 1;
              err = SetAudioProperty(ao->i_selected_dev,
                                     kAudioDevicePropertySupportsMixing,
                                     sizeof(UInt32), &b_mix);
          }
          if (err != noErr)
              ao_msg(MSGT_AO, MSGL_WARN, "failed to set mixmode: [%4.4s]\n", (char *)&err);
      }
      if (ao->i_hog_pid == getpid())
      {
          ao->i_hog_pid = -1;
          err = SetAudioProperty(ao->i_selected_dev,
                                 kAudioDevicePropertyHogMode,
                                 sizeof(ao->i_hog_pid), &ao->i_hog_pid);
          if (err != noErr) ao_msg(MSGT_AO, MSGL_WARN, "Could not release hogmode: [%4.4s]\n", (char *)&err);
      }
  }

  av_fifo_free(ao->buffer);
  free(ao);
  ao = NULL;
}
Esempio n. 27
0
void *workload_replayer(void *arg)
{
    unsigned int tid = 0;
    readLine req;
    long long trace_sTime = -1;
    long long trace_wTime = 0;
    long long gio_sTime   = 0;
    long long gio_wTime   = 0;
    struct timeval now;
    int fd;
    char *buf;
    size_t ret;
    unsigned long mSize;
    unsigned long mAddr;
    OPERATION_TYPE op;

    desc = (wg_env *)arg;
    if( (fd = open(desc->file_path, O_CREAT|O_RDWR|O_DIRECT, 0666)) == -1 ){
    //if( (fd = open(desc->file_path, O_CREAT|O_RDWR, 0666)) == -1){
	PRINT("Error on opening the init_file of workload generator, file:%s, line:%d, fd=%d\n", __func__, __LINE__, fd);
	exit(1);
    }

#if !defined(BLOCKING_IO)
    aio_initialize(desc->max_queue_depth);
#endif

    mem_allocation(desc, &buf, REPLAYER_MAX_FILE_SIZE);
    if (NULL == buf) {
	PRINT("Error on memory allocation, file:%s, line:%d\n", __func__, __LINE__);
	exit(1);
    }

    while(1){
	//Dequeueing
	req = de_queue();
	//If a request is successfully dequeued.
	if(strcmp(req.rwbs, "EMPTY") != 0){
	    mSize = select_size(req.size);
	    mAddr = select_start_addr(req.sSector);
	    fill_data(desc, buf, mSize);

	    //Calculate wait time based on trace log
	    if(trace_sTime == -1){
		get_start_time(&trace_sTime, &gio_sTime); 
	    }
	    trace_wTime = MICRO_SECOND(req.sTime) - trace_sTime;
	    if(trace_wTime < 0){
		PRINT("trace_wTime : %lli\n", trace_wTime);
		PRINT("Issue time must be ordered. Check the issue time in trace file");
		exit(1);
	    }

	    //Caculate how much time should wait
	    get_current_time(&now);
	    gio_wTime = TIME_VALUE(&now) - gio_sTime;
	    PRINT("TIMEDEBUG trace_wTime:%10lli  \tgio_wTime:%10lli\n",
		    trace_wTime, gio_wTime);

	    //If we need to wait
	    if(trace_wTime > gio_wTime){
		PRINT("WAITING ....%lli us\n", trace_wTime - gio_wTime);
		usec_sleep(trace_wTime - gio_wTime);
	    }
	    op = strstr(req.rwbs,"R")!=NULL? WG_READ : WG_WRITE;
#if defined(BLOCKING_IO)
	    if(op == WG_READ){
		//PRINT("R\n");
		ret = pread(fd, buf , (size_t)mSize, mAddr);
	    }else{
		//PRINT("W\n");
		ret = pwrite(fd, buf , (size_t)mSize, mAddr);
		fsync(fd);
	    }
	    if (ret != mSize) {
		PRINT("Error on file I/O (error# : %zu), file:%s, line:%d\n", ret, __func__, __LINE__);
		break;
	    }
#else
    	    ret = aio_enqueue(fd, buf, mSize, mAddr, op);
	    if (ret != 1) {
		PRINT("Error on file I/O (error# : %zu), file:%s, line:%d\n", ret, __func__, __LINE__);
		break;
	    }
#endif //BLOCKING_IO
#if 0
	    PRINT("DEQUEUED REQ tid:%u sTime:%lf rwbs:%s Addr:%12li \t Size:%12lu\n\n", 
		    tid,
		    req.sTime,
		    req.rwbs,
		    mAddr,
		    mSize);	
#endif
		   
	}

	if( get_queue_status() == 1 ){
	    PRINT("END OF REPLAYER\n");
	    break;
	}
    }
    pthread_mutex_destroy(&thr_mutex);
}
Esempio n. 28
0
/*****************************************************************************
 * AudioStreamChangeFormat: Change i_stream_id to change_format
 *****************************************************************************/
static int AudioStreamChangeFormat( AudioStreamID i_stream_id, AudioStreamBasicDescription change_format )
{
    OSStatus err = noErr;
    int i;
    AudioObjectPropertyAddress property_address;

    static volatile int stream_format_changed;
    stream_format_changed = 0;

    print_format(MSGL_V, "setting stream format:", &change_format);

    /* Install the callback. */
    property_address.mSelector = kAudioStreamPropertyPhysicalFormat;
    property_address.mScope    = kAudioObjectPropertyScopeGlobal;
    property_address.mElement  = kAudioObjectPropertyElementMaster;

    err = AudioObjectAddPropertyListener(i_stream_id,
                                         &property_address,
                                         StreamListener,
                                         (void *)&stream_format_changed);
    if (err != noErr)
    {
        ao_msg(MSGT_AO, MSGL_WARN, "AudioStreamAddPropertyListener failed: [%4.4s]\n", (char *)&err);
        return CONTROL_FALSE;
    }

    /* Change the format. */
    err = SetAudioProperty(i_stream_id,
                           kAudioStreamPropertyPhysicalFormat,
                           sizeof(AudioStreamBasicDescription), &change_format);
    if (err != noErr)
    {
        ao_msg(MSGT_AO, MSGL_WARN, "could not set the stream format: [%4.4s]\n", (char *)&err);
        return CONTROL_FALSE;
    }

    /* The AudioStreamSetProperty is not only asynchronious,
     * it is also not Atomic, in its behaviour.
     * Therefore we check 5 times before we really give up.
     * FIXME: failing isn't actually implemented yet. */
    for (i = 0; i < 5; ++i)
    {
        AudioStreamBasicDescription actual_format;
        int j;
        for (j = 0; !stream_format_changed && j < 50; ++j)
            usec_sleep(10000);
        if (stream_format_changed)
            stream_format_changed = 0;
        else
            ao_msg(MSGT_AO, MSGL_V, "reached timeout\n" );

        err = GetAudioProperty(i_stream_id,
                               kAudioStreamPropertyPhysicalFormat,
                               sizeof(AudioStreamBasicDescription), &actual_format);

        print_format(MSGL_V, "actual format in use:", &actual_format);
        if (actual_format.mSampleRate == change_format.mSampleRate &&
            actual_format.mFormatID == change_format.mFormatID &&
            actual_format.mFramesPerPacket == change_format.mFramesPerPacket)
        {
            /* The right format is now active. */
            break;
        }
        /* We need to check again. */
    }

    /* Removing the property listener. */
    err = AudioObjectRemovePropertyListener(i_stream_id,
                                            &property_address,
                                            StreamListener,
                                            (void *)&stream_format_changed);
    if (err != noErr)
    {
        ao_msg(MSGT_AO, MSGL_WARN, "AudioStreamRemovePropertyListener failed: [%4.4s]\n", (char *)&err);
        return CONTROL_FALSE;
    }

    return CONTROL_TRUE;
}
Esempio n. 29
0
/**
 * \return 1 on success, 0 if the function was interrupted and -1 on error
 */
int stream_enable_cache(stream_t *stream,int size,int min,int seek_limit){
  int ss = stream->sector_size ? stream->sector_size : STREAM_BUFFER_SIZE;
  int res = -1;
  cache_vars_t* s;

  if (stream->flags & STREAM_NON_CACHEABLE) {
    mp_msg(MSGT_CACHE,MSGL_STATUS,"\rThis stream is non-cacheable\n");
    return 1;
  }

  s=cache_init(size,ss);
  if(s == NULL) return -1;
  stream->cache_data=s;
  s->stream=stream; // callback
  s->seek_limit=seek_limit;


  //make sure that we won't wait from cache_fill
  //more data than it is alowed to fill
  if (s->seek_limit > s->buffer_size - s->fill_limit ){
     s->seek_limit = s->buffer_size - s->fill_limit;
  }
  if (min > s->buffer_size - s->fill_limit) {
     min = s->buffer_size - s->fill_limit;
  }

#if !defined(__MINGW32__) && !defined(PTHREAD_CACHE) && !defined(__OS2__)
  if((stream->cache_pid=fork())){
    if ((pid_t)stream->cache_pid == -1)
      stream->cache_pid = 0;
#else
  {
    stream_t* stream2=malloc(sizeof(stream_t));
    memcpy(stream2,s->stream,sizeof(stream_t));
    s->stream=stream2;
#if defined(__MINGW32__)
    stream->cache_pid = _beginthread( ThreadProc, 0, s );
#elif defined(__OS2__)
    stream->cache_pid = _beginthread( ThreadProc, NULL, 256 * 1024, s );
#else
    {
    pthread_t tid;
    pthread_create(&tid, NULL, ThreadProc, s);
    stream->cache_pid = 1;
    }
#endif
#endif
    if (!stream->cache_pid) {
        mp_msg(MSGT_CACHE, MSGL_ERR,
               "Starting cache process/thread failed: %s.\n", strerror(errno));
        goto err_out;
    }
    // wait until cache is filled at least prefill_init %
    mp_msg(MSGT_CACHE,MSGL_V,"CACHE_PRE_INIT: %"PRId64" [%"PRId64"] %"PRId64"  pre:%d  eof:%d  \n",
	(int64_t)s->min_filepos,(int64_t)s->read_filepos,(int64_t)s->max_filepos,min,s->eof);
    while(s->read_filepos<s->min_filepos || s->max_filepos-s->read_filepos<min){
	mp_msg(MSGT_CACHE,MSGL_STATUS,MSGTR_CacheFill,
	    100.0*(float)(s->max_filepos-s->read_filepos)/(float)(s->buffer_size),
	    (int64_t)s->max_filepos-s->read_filepos
	);
	if(s->eof) break; // file is smaller than prefill size
	if(stream_check_interrupt(PREFILL_SLEEP_TIME)) {
	  res = 0;
	  goto err_out;
        }
    }
    mp_msg(MSGT_CACHE,MSGL_STATUS,"\n");
    return 1; // parent exits

err_out:
    cache_uninit(stream);
    return res;
  }

#if defined(__MINGW32__) || defined(PTHREAD_CACHE) || defined(__OS2__)
}
#ifdef PTHREAD_CACHE
static void *ThreadProc( void *s ){
#else
static void ThreadProc( void *s ){
#endif
#endif

#ifdef CONFIG_GUI
  use_gui = 0; // mp_msg may not use gui stuff in forked code
#endif
// cache thread mainloop:
  signal(SIGTERM,exit_sighandler); // kill
  do {
    if(!cache_fill(s)){
	 usec_sleep(FILL_USLEEP_TIME); // idle
    }
//	 cache_stats(s->cache_data);
  } while (cache_execute_control(s));
#if defined(__MINGW32__) || defined(__OS2__)
  _endthread();
#elif defined(PTHREAD_CACHE)
  return NULL;
#else
  // make sure forked code never leaves this function
  exit(0);
#endif
}

int cache_stream_fill_buffer(stream_t *s){
  int len;
  if(s->eof){ s->buf_pos=s->buf_len=0; return 0; }
  if(!s->cache_pid) return stream_fill_buffer(s);

//  cache_stats(s->cache_data);

  if(s->pos!=((cache_vars_t*)s->cache_data)->read_filepos) mp_msg(MSGT_CACHE,MSGL_ERR,"!!! read_filepos differs!!! report this bug...\n");

  len=cache_read(s->cache_data,s->buffer, ((cache_vars_t*)s->cache_data)->sector_size);
  //printf("cache_stream_fill_buffer->read -> %d\n",len);

  if(len<=0){ s->eof=1; s->buf_pos=s->buf_len=0; return 0; }
  s->buf_pos=0;
  s->buf_len=len;
  s->pos+=len;
//  printf("[%d]",len);fflush(stdout);
  return len;

}
Esempio n. 30
0
static enum fio_ddir rate_ddir(struct thread_data *td, enum fio_ddir ddir)
{
	enum fio_ddir odir = ddir ^ 1;
	struct timeval t;
	long usec;

	assert(ddir_rw(ddir));

	if (td->rate_pending_usleep[ddir] <= 0)
		return ddir;

	/*
	 * We have too much pending sleep in this direction. See if we
	 * should switch.
	 */
	if (td_rw(td)) {
		/*
		 * Other direction does not have too much pending, switch
		 */
		if (td->rate_pending_usleep[odir] < 100000)
			return odir;

		/*
		 * Both directions have pending sleep. Sleep the minimum time
		 * and deduct from both.
		 */
		if (td->rate_pending_usleep[ddir] <=
			td->rate_pending_usleep[odir]) {
			usec = td->rate_pending_usleep[ddir];
		} else {
			usec = td->rate_pending_usleep[odir];
			ddir = odir;
		}
	} else
		usec = td->rate_pending_usleep[ddir];

	/*
	 * We are going to sleep, ensure that we flush anything pending as
	 * not to skew our latency numbers.
	 *
	 * Changed to only monitor 'in flight' requests here instead of the
	 * td->cur_depth, b/c td->cur_depth does not accurately represent
	 * io's that have been actually submitted to an async engine,
	 * and cur_depth is meaningless for sync engines.
	 */
	if (td->io_u_in_flight) {
		int fio_unused ret;

		ret = io_u_queued_complete(td, td->io_u_in_flight, NULL);
	}

	fio_gettime(&t, NULL);
	usec_sleep(td, usec);
	usec = utime_since_now(&t);

	td->rate_pending_usleep[ddir] -= usec;

	odir = ddir ^ 1;
	if (td_rw(td) && __should_check_rate(td, odir))
		td->rate_pending_usleep[odir] -= usec;

	if (ddir_trim(ddir))
		return ddir;
	return ddir;
}