Ejemplo n.º 1
0
Archivo: manager.c Proyecto: ertesh/SO
void make_loop(int n, int* last_pipe, char* grammar) {
    /* last_pipe[0] = input of the recently created pipe    *
     * last_pipe[1] = output of the first pipe              */
	pid_t pid;
	if (n == 1) {
		prepare_input(last_pipe);
        prepare_output(last_pipe);
        close_pipe(last_pipe);
        return;
	}
	int next_pipe[2];
    create_pipe(next_pipe);
	switch (pid = fork()) {
		case -1:
			syserr("Error in fork()\n");
		case 0:
			prepare_input(last_pipe);
            close_pipe(last_pipe);
            prepare_output(next_pipe);
            close_pipe(next_pipe);
			execl("./worker", "./worker", grammar, NULL);
			syserr("Error in execl()\n");
		default:
            last_pipe[0] = next_pipe[0];
            make_loop(n - 1, last_pipe, grammar);
            return;
	}
}
Ejemplo n.º 2
0
/*===========================================================================*
 *				output_done				     *
 *===========================================================================*/
static void output_done()
{
/* Previous chunk of printing is finished.  Continue if OK and more.
 * Otherwise, reply to caller (FS).
 */
  int status;

  if (!writing) return;	  	/* probably leftover interrupt */
  if (done_status != OK) {      	/* printer error occurred */
	status = EIO;
	if ((done_status & ON_LINE) == 0) { 
	    printf("Printer is not on line\n");
	} else if ((done_status & NO_PAPER)) { 
	    printf("Printer is out of paper\n");
	    status = EAGAIN;	
	} else {
	    printf("Printer error, status is 0x%02X\n", done_status);
	}
	/* Some characters have been printed, tell how many. */
	if (status == EAGAIN && user_left < orig_count) {
		status = orig_count - user_left;
	}
	oleft = 0;			/* cancel further output */
  } else if (user_left != 0) {		/* not yet done, continue! */
	prepare_output();
	return;
  } else {				/* done! report back to FS */
	status = orig_count;
  }

  chardriver_reply_task(caller, write_id, status);

  writing = FALSE;			/* unmark event */
}
static gboolean
read_light (gpointer user_data)
{
	DrvData *data = user_data;

	prepare_output (data, data->buffer_data->dev_dir_name, data->buffer_data->trigger_name);

	return G_SOURCE_CONTINUE;
}
Ejemplo n.º 4
0
// ------------------------------------------------------------------ process --
void SpectacleBase::process(const float *buf, const int)
{
	DPRINT("SpectacleBase::process");

   if (_reading_input) {
      prepare_input(buf);
      _fft->r2c();
   }
	modify_analysis(_reading_input);
	_fft->c2r();
	prepare_output();
}
Ejemplo n.º 5
0
// ------------------------------------------------------------------ process --
void SPECTACLE2_BASE::process(const float *buf, const int)
{
	DPRINT("SPECTACLE2_BASE::process\n");

	const bool reading_input = (currentFrame() < _input_end_frame);
	if (reading_input) {
		DPRINT1("taking input...currentFrame()=%d\n", currentFrame());
		prepare_input(buf);
		_fft->r2c();
		cartesian_to_polar();
	}
	modify_analysis(reading_input);
	polar_to_cartesian();
	_fft->c2r();
	prepare_output();
}
Ejemplo n.º 6
0
/*===========================================================================*
 *				do_write				     *
 *===========================================================================*/
static ssize_t printer_write(devminor_t UNUSED(minor), u64_t UNUSED(position),
	endpoint_t endpt, cp_grant_id_t grant, size_t size, int flags,
	cdev_id_t id)
{
/* The printer is used by sending write requests to it. Process one. */
  int retries;
  u32_t status;

  /* Reject command if last write is not yet finished, the count is not
   * positive, or we're asked not to block.
   */
  if (writing)			return EIO;
  if (size <= 0)		return EINVAL;
  if (flags & CDEV_NONBLOCK)	return EAGAIN;	/* not supported */

  /* If no errors occurred, continue printing with the caller.
   * First wait until the printer is online to prevent stupid errors.
   */
  caller = endpt;
  user_left = size;
  orig_count = size;
  user_vir_d = 0;	/* Offset. */
  writing = TRUE;
  grant_nr = grant;
  write_id = id;

  retries = MAX_ONLINE_RETRIES + 1;
  while (--retries > 0) {
        if (sys_inb(port_base + 1, &status) != OK) {
		printf("printer: sys_inb of %x failed\n", port_base+1);
		panic("sys_inb failed");
	}
	if (status & ON_LINE) {		/* printer online! */
		prepare_output();
		printer_intr(0);
		return EDONTREPLY;	/* we may already have sent a reply */
	}
	micro_delay(500000);		/* wait before retry */
  }
  /* If we reach this point, the printer was not online in time. */
  done_status = status;
  output_done();
  return EDONTREPLY;
}
Ejemplo n.º 7
0
int
mxc_v4l_tvin_test(void)
{
	struct v4l2_buffer capture_buf, output_buf;
	v4l2_std_id id;
	int i, j;
	enum v4l2_buf_type type;
	int total_time;
	struct timeval tv_start, tv_current;

	unsigned char *buf_test;
	buf_test = (unsigned char *) malloc (g_frame_size);


	if (prepare_output() < 0)
	{
		printf("prepare_output failed\n");
		return TFAIL;
	}

	if (start_capturing() < 0)
	{
		printf("start_capturing failed\n");
		return TFAIL;
	}

	for (i = 0; ; i++) {
		
		memset(&capture_buf, 0, sizeof(capture_buf));
		capture_buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
		capture_buf.memory = V4L2_MEMORY_MMAP;
		if (ioctl(fd_capture_v4l, VIDIOC_DQBUF, &capture_buf) < 0) {
			printf("VIDIOC_DQBUF failed.\n");
			return TFAIL;
		}

		memset(&output_buf, 0, sizeof(output_buf));
		output_buf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
		output_buf.memory = V4L2_MEMORY_MMAP;
		if (i < g_output_num_buffers) {
			output_buf.index = i;
			if (ioctl(fd_output_v4l, VIDIOC_QUERYBUF, &output_buf) < 0)
			{
				printf("VIDIOC_QUERYBUF failed\n");
				return TFAIL;
			}
		} else {
			output_buf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
			output_buf.memory = V4L2_MEMORY_MMAP;
			if (ioctl(fd_output_v4l, VIDIOC_DQBUF, &output_buf) < 0)
			{
				printf("VIDIOC_DQBUF failed !!!\n");
				return TFAIL;
			}
		}

		memcpy(buf_test, capture_buffers[capture_buf.index].start, g_frame_size);

		memcpy(output_buffers[output_buf.index].start, buf_test, g_frame_size);



		if (ioctl(fd_capture_v4l, VIDIOC_QBUF, &capture_buf) < 0) {
			printf("VIDIOC_QBUF failed\n");
			return TFAIL;
		}

		output_buf.timestamp.tv_sec = tv_start.tv_sec;
		output_buf.timestamp.tv_usec = tv_start.tv_usec + (g_frame_period * i);
		if (ioctl(fd_output_v4l, VIDIOC_QBUF, &output_buf) < 0)
		{
			printf("VIDIOC_QBUF failed\n");
			return TFAIL;
		}
		if (i == 1) {
			type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
			if (ioctl(fd_output_v4l, VIDIOC_STREAMON, &type) < 0) {
				printf("Could not start stream\n");
				return TFAIL;
			}
		}
	}

	gettimeofday(&tv_current, 0);
	total_time = (tv_current.tv_sec - tv_start.tv_sec) * 1000000L;
	total_time += tv_current.tv_usec - tv_start.tv_usec;
	printf("total time for %u frames = %u us =  %lld fps\n", i, total_time, (i * 1000000ULL) / total_time);

	free (buf_test);
	return 0;
}
Ejemplo n.º 8
0
Archivo: main.c Proyecto: 020gzh/linux
int main(int argc, char **argv)
{
	int c;
	int option_index = 0;
	struct config *config = NULL;

	config = prepare_default_config();

	if (config == NULL)
		return EXIT_FAILURE;

	while (1) {
		c = getopt_long (argc, argv, "hg:o:s:l:vc:p:f:n:r:x:y:",
				long_options, &option_index);
		if (c == -1)
			break;

		switch (c) {
		case 'o':
			if (config->output != NULL)
				fclose(config->output);

			config->output = prepare_output(optarg);

			if (config->output == NULL)
				return EXIT_FAILURE;

			dprintf("user output path -> %s\n", optarg);
			break;
		case 's':
			sscanf(optarg, "%li", &config->sleep);
			dprintf("user sleep time -> %s\n", optarg);
			break;
		case 'l':
			sscanf(optarg, "%li", &config->load);
			dprintf("user load time -> %s\n", optarg);
			break;
		case 'c':
			sscanf(optarg, "%u", &config->cpu);
			dprintf("user cpu -> %s\n", optarg);
			break;
		case 'g':
			strncpy(config->governor, optarg, 14);
			dprintf("user governor -> %s\n", optarg);
			break;
		case 'p':
			if (string_to_prio(optarg) != SCHED_ERR) {
				config->prio = string_to_prio(optarg);
				dprintf("user prio -> %s\n", optarg);
			} else {
				if (config != NULL) {
					if (config->output != NULL)
						fclose(config->output);
					free(config);
				}
				usage();
			}
			break;
		case 'n':
			sscanf(optarg, "%u", &config->cycles);
			dprintf("user cycles -> %s\n", optarg);
			break;
		case 'r':
			sscanf(optarg, "%u", &config->rounds);
			dprintf("user rounds -> %s\n", optarg);
			break;
		case 'x':
			sscanf(optarg, "%li", &config->load_step);
			dprintf("user load_step -> %s\n", optarg);
			break;
		case 'y':
			sscanf(optarg, "%li", &config->sleep_step);
			dprintf("user sleep_step -> %s\n", optarg);
			break;
		case 'f':
			if (prepare_config(optarg, config))
				return EXIT_FAILURE;
			break;
		case 'v':
			config->verbose = 1;
			dprintf("verbose output enabled\n");
			break;
		case 'h':
		case '?':
		default:
			if (config != NULL) {
				if (config->output != NULL)
					fclose(config->output);
				free(config);
			}
			usage();
		}
	}

	if (config->verbose) {
		printf("starting benchmark with parameters:\n");
		printf("config:\n\t"
		       "sleep=%li\n\t"
		       "load=%li\n\t"
		       "sleep_step=%li\n\t"
		       "load_step=%li\n\t"
		       "cpu=%u\n\t"
		       "cycles=%u\n\t"
		       "rounds=%u\n\t"
		       "governor=%s\n\n",
		       config->sleep,
		       config->load,
		       config->sleep_step,
		       config->load_step,
		       config->cpu,
		       config->cycles,
		       config->rounds,
		       config->governor);
	}

	prepare_user(config);
	prepare_system(config);
	start_benchmark(config);

	if (config->output != stdout)
		fclose(config->output);

	free(config);

	return EXIT_SUCCESS;
}
Ejemplo n.º 9
0
void streamClose(struct stream *s) {
  prepare_output(s);
  output(s);
  json_object_put(s->json);
}