int main(int argc, char **argv) {
  grpc_test_init(argc, argv);

  grpc_init();
  gpr_mu_init(&g_mu);
  grpc_blocking_resolve_address = my_resolve_address;

  grpc_resolver *resolver = create_resolver("dns:test");

  grpc_resolver_result *result = (grpc_resolver_result *)1;

  grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
  gpr_event ev1;
  gpr_event_init(&ev1);
  grpc_resolver_next(&exec_ctx, resolver, &result,
                     grpc_closure_create(on_done, &ev1));
  grpc_exec_ctx_flush(&exec_ctx);
  GPR_ASSERT(wait_loop(5, &ev1));
  GPR_ASSERT(result == NULL);

  gpr_event ev2;
  gpr_event_init(&ev2);
  grpc_resolver_next(&exec_ctx, resolver, &result,
                     grpc_closure_create(on_done, &ev2));
  grpc_exec_ctx_flush(&exec_ctx);
  GPR_ASSERT(wait_loop(30, &ev2));
  GPR_ASSERT(result != NULL);

  grpc_resolver_result_unref(&exec_ctx, result);
  GRPC_RESOLVER_UNREF(&exec_ctx, resolver, "test");
  grpc_exec_ctx_finish(&exec_ctx);

  grpc_shutdown();
  gpr_mu_destroy(&g_mu);
}
Beispiel #2
0
int main(int argc, char *argv[])
{	
	co_rc_t rc;
	HANDLE daemon_handle = 0;
	int exit_code = 0;
	co_daemon_handle_t daemon_handle_;
	start_parameters_t start_parameters;

	co_debug_start();

	co_set_terminal_print_hook(terminal_print_hook_func);

	rc = handle_paramters(&start_parameters, argc, argv);
	if (!CO_OK(rc)) {
		exit_code = -1;
		goto out;
	}

	daemon_parameters = &start_parameters;

	rc = co_os_daemon_pipe_open(daemon_parameters->instance, 
				    CO_MODULE_SERIAL0 + daemon_parameters->index, &daemon_handle_);
	if (!CO_OK(rc)) {
		co_terminal_print("Error opening a pipe to the daemon\n");
		goto out;
	}

	daemon_handle = daemon_handle_->handle;
	exit_code = wait_loop(daemon_handle);
	co_os_daemon_pipe_close(daemon_handle_);

out:
	co_debug_end();
	return exit_code;
}
Beispiel #3
0
co_rc_t daemon_mode(int unit, int instance)
{
	co_daemon_handle_t daemon_handle_;
	co_rc_t rc = CO_RC(ERROR);
	struct termios term;

	rc = co_os_daemon_pipe_open(instance, CO_MODULE_SERIAL0 + unit, &daemon_handle_);
	if (!CO_OK(rc)) {
		co_terminal_print("coserial: error opening a pipe to the daemon\n");
		goto out;
	}

	tcgetattr(0, &term);
	cfmakeraw(&term);
	tcsetattr(0, 0, &term);

	tcgetattr(1, &term);
	cfmakeraw(&term);
	tcsetattr(1, 0, &term);

	rc = wait_loop(daemon_handle_, unit, 0, 1);

	co_os_daemon_pipe_close(daemon_handle_);
out:
	return rc;
}
Beispiel #4
0
/********************************************************************************
 * main...
 */
int
main(int argc, char *argv[])
{
	co_rc_t rc;
	HANDLE daemon_handle = 0;
	HANDLE pcap_thread;
	start_parameters_t start_parameters;
	int exit_code = 0;
	co_daemon_handle_t daemon_handle_;

	rc = handle_paramters(&start_parameters, argc, argv);
	if (!CO_OK(rc)) 
		return -1;

	if (start_parameters.show_help) {
		co_net_syntax();
		return 0;
	}

	if (!start_parameters.mac_specified) {
		printf("Error, MAC address not specified\n");
		return CO_RC(ERROR);
	}

	if (start_parameters.index == -1) {
		printf("Error, index not specified\n");
		return CO_RC(ERROR);
	}

	daemon_parameters = &start_parameters;

	exit_code = pcap_init();
	if (exit_code) {
		co_debug("Error initializing winPCap\n");
		goto out;
	}

	rc = co_os_open_daemon_pipe(daemon_parameters->instance, 
				    CO_MODULE_CONET0 + daemon_parameters->index, &daemon_handle_);
	if (!CO_OK(rc)) {
		co_debug("Error opening a pipe to the daemon\n");
		goto out;
	}

	pcap_thread = CreateThread(NULL, 0, pcap2Daemon, NULL, 0, NULL);

	if (pcap_thread == NULL) {
		co_debug("Failed to spawn pcap_thread\n");
		goto out;
	}

	daemon_handle = daemon_handle_->handle;
	exit_code = wait_loop(daemon_handle);
	co_os_daemon_close(daemon_handle_);

      out:
	ExitProcess(exit_code);
	return exit_code;
}
int main(int argc, char **argv) {
  grpc_test_init(argc, argv);

  grpc_init();
  gpr_mu_init(&g_mu);
  g_combiner = grpc_combiner_create();
  grpc_resolve_address = my_resolve_address;
  grpc_dns_lookup_ares = my_dns_lookup_ares;
  grpc_channel_args *result = (grpc_channel_args *)1;

  grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
  grpc_resolver *resolver = create_resolver(&exec_ctx, "dns:test");
  gpr_event ev1;
  gpr_event_init(&ev1);
  call_resolver_next_after_locking(
      &exec_ctx, resolver, &result,
      GRPC_CLOSURE_CREATE(on_done, &ev1, grpc_schedule_on_exec_ctx));
  grpc_exec_ctx_flush(&exec_ctx);
  GPR_ASSERT(wait_loop(5, &ev1));
  GPR_ASSERT(result == NULL);

  gpr_event ev2;
  gpr_event_init(&ev2);
  call_resolver_next_after_locking(
      &exec_ctx, resolver, &result,
      GRPC_CLOSURE_CREATE(on_done, &ev2, grpc_schedule_on_exec_ctx));
  grpc_exec_ctx_flush(&exec_ctx);
  GPR_ASSERT(wait_loop(30, &ev2));
  GPR_ASSERT(result != NULL);

  grpc_channel_args_destroy(&exec_ctx, result);
  GRPC_RESOLVER_UNREF(&exec_ctx, resolver, "test");
  GRPC_COMBINER_UNREF(&exec_ctx, g_combiner, "test");
  grpc_exec_ctx_finish(&exec_ctx);

  grpc_shutdown();
  gpr_mu_destroy(&g_mu);
}
Beispiel #6
0
int main(int argc, char *argv[])
{	
	co_rc_t rc;
	HANDLE daemon_handle = 0;
	int exit_code = 0;
	co_daemon_handle_t daemon_handle_;
	start_parameters_t start_parameters;
	WSADATA wsad;

	co_debug_start();
	WSAStartup(MAKEWORD(2, 0), &wsad);
	slirp_init();

	rc = handle_paramters(&start_parameters, argc, argv);
	if (!CO_OK(rc)) {
		exit_code = -1;
		goto out;
	}

	co_terminal_print("Slirp initialized\n");

	daemon_parameters = &start_parameters;
	rc = co_os_daemon_pipe_open(daemon_parameters->instance, 
				    CO_MODULE_CONET0 + daemon_parameters->index, &daemon_handle_);
	if (!CO_OK(rc)) {
		co_terminal_print("Error opening a pipe to the daemon\n");
		goto out;
	}

	slirp_mutex = CreateMutex(NULL, FALSE, NULL);
	if (slirp_mutex == NULL) 
		goto out_close;

	co_set_terminal_print_hook(terminal_print_hook_func);

	co_terminal_print("Slirp loop running\n");

	daemon_handle = daemon_handle_->handle;
	exit_code = wait_loop(daemon_handle);

	CloseHandle(slirp_mutex);

out_close:
	co_os_daemon_pipe_close(daemon_handle_);

out:
	co_debug_end();
	return exit_code;
}
/*
 * On a 5-minute timeout, wait for all devices currently configured.  We need
 * to do this to guarantee that the filesystems and / or network devices
 * needed for boot are available, before we can allow the boot to proceed.
 *
 * This needs to be on a late_initcall, to happen after the frontend device
 * drivers have been initialised, but before the root fs is mounted.
 *
 * A possible improvement here would be to have the tools add a per-device
 * flag to the store entry, indicating whether it is needed at boot time.
 * This would allow people who knew what they were doing to accelerate their
 * boot slightly, but of course needs tools or manual intervention to set up
 * those flags correctly.
 */
static void wait_for_devices(struct xenbus_driver *xendrv)
{
	unsigned long start = jiffies;
	struct device_driver *drv = xendrv ? &xendrv->driver : NULL;
	unsigned int seconds_waited = 0;

	if (!ready_to_wait_for_devices || !xen_domain())
		return;

	while (exists_non_essential_connecting_device(drv))
		if (wait_loop(start, 30, &seconds_waited))
			break;

	/* Skips PVKB and PVFB check.*/
	while (exists_essential_connecting_device(drv))
		if (wait_loop(start, 270, &seconds_waited))
			break;

	if (seconds_waited)
		printk("\n");

	bus_for_each_dev(&xenbus_frontend.bus, NULL, drv,
			 print_device_status);
}
Beispiel #8
0
int main(int argc, char *argv[])
{	
	co_rc_t rc;
	int exit_code = 0;
	co_daemon_handle_t daemon_handle_;
	int tap_fd;
	char tap_name[0x30];
	int unit = 0;
	int colinux_instance = 0;

	co_terminal_print("Cooperative Linux TAP network daemon\n");
	if (argc < 3) {
		syntax();
		return -1;
	}

	snprintf(tap_name, sizeof(tap_name), "conet-host-%d-%d", colinux_instance, unit);

	co_terminal_print("creating network %s\n", tap_name);

	tap_fd = tap_alloc(tap_name);
	if (tap_fd < 0) {
		co_terminal_print("Error opening TAP\nn");
		exit_code = -1;		
		goto out;
	}

	co_terminal_print("TAP interface %s created\n", tap_name);

	rc = co_os_open_daemon_pipe(0, CO_MODULE_CONET0, &daemon_handle_);
	if (!CO_OK(rc)) {
		co_terminal_print("Error opening a pipe to the daemon\n");
		goto out_close;
	}

	wait_loop(daemon_handle_, tap_fd);
	co_os_daemon_close(daemon_handle_);

out_close:
	close(tap_fd);

out:
	return exit_code;
}
Beispiel #9
0
int Mathilda::create_worker_processes() {
	if(instructions.empty()) {
		return ERR;
	}

	uint32_t num_cores = mf->cores;

	if(instructions.size() < num_cores) {
		num_cores = instructions.size()-1;
	}

	pid_t p = 0;

	if((safe_to_fork == true || getenv("MATHILDA_FORK")) && slow_parallel == false) {
		for(uint32_t proc_num = 0; proc_num <= num_cores; proc_num++) {
			p = mf->fork_child(false, use_shm, shm_sz, process_timeout);

			if(p == ERR) {
#ifdef DEBUG
				fprintf(stdout, "[Mathilda] Failed to fork!\n");
#endif
			} else if(mf->parent == false) {
				if(use_shm) {
					this->shm_ptr = mf->get_shm_ptr();
					this->shm_id = mf->get_shm_id();
				}

				// Child process
				uint32_t start = 0;
				uint32_t end = 0;
				uint32_t sz_of_work = instructions.size();

				if(num_cores > 0) {
					sz_of_work = instructions.size() / num_cores;
				}

				start = sz_of_work * proc_num;
				end = start + sz_of_work;

				if(set_cpu == true) {
					mf->set_affinity(proc_num);
				}

				mathilda_proc_init(proc_num, start, end, sz_of_work);
				exit(OK);
			}
		}

		wait_loop();
	} else if(slow_parallel == true && safe_to_fork == true) {
		// This mode means only 1 Instruction per core
		// which translates to a fork() per Instruction.
		// Its slower but more reliable because you don't
		// lose Instructions if the child receives SIGALRM.
		// If this mode is used then the timeout should
		// be relatively short
		uint32_t count = 0;

		slow:
		for(uint32_t proc_num = 0; proc_num <= num_cores; proc_num++) {
			count+=1;

			p = mf->fork_child(false, use_shm, shm_sz, process_timeout);

			if(p == ERR) {
#ifdef DEBUG
				fprintf(stdout, "[Mathilda] Failed to fork!\n");
#endif
			} else if(mf->parent == false) {
				if(use_shm) {
					this->shm_ptr = mf->get_shm_ptr();
					this->shm_id = mf->get_shm_id();
				}

				if(set_cpu == true) {
					mf->set_affinity(proc_num);
				}

				Instruction *i = instructions[count];
				instructions.clear();
				instructions.push_back(i);
				mathilda_proc_init(0, 0, 1, 1);
				exit(OK);
			}
		}

		wait_loop();

		if(count <= instructions.size()) {
			goto slow;
		}
	} else {
		// No children were forked
		mathilda_proc_init(0, 0, instructions.size(), instructions.size());

		if(finish) {
			finish(NULL);
		}
	}

	return OK;
}
Beispiel #10
0
int main(int argc, char *argv[])
{
	void *addr;
	size_t length;
	struct stat sb;
	struct tms tms;
	struct rusage r1, r2;
	int fd, next_opt;
	long hz, tvali, tvalf;
	double elapsed, us_time, sy_time;
	int fault_mode = PG_FAULT_NONE, mmap_mode = MMAP_MODE_NONE;
	int exit_wait = 0;
	int print_stats = 0;

	signal(SIGINT, signal_handler);
	signal(SIGTERM, signal_handler);

	prg_name = argv[0];
	do {
		next_opt = getopt_long(argc, argv, short_opts, long_opts, NULL);
		switch (next_opt) {
		case 'p':
			fault_mode = PG_FAULT_NONE;
			if (optarg) {
			        if (strcmp(optarg, "write") == 0)
					fault_mode = PG_FAULT_WRITE;

			        if (strcmp(optarg, "read") == 0)
					fault_mode = PG_FAULT_READ;

			        if (strcmp(optarg, "loop") == 0)
					fault_mode = PG_FAULT_RWLOOP;
			}
			break;

		case 'a':
			mmap_mode = MMAP_MODE_ANON;
			length = atol(optarg) * MB;
			fd = -1;
			break;

		case 'f':
			mmap_mode = MMAP_MODE_FILE;
			fd = open (optarg, O_RDWR);
			if (fd == -1) {
				perror ("open");
				return 1;
			}

			if (fstat (fd, &sb) == -1) {
				perror ("fstat");
				return 1;
			}

			length = sb.st_size;
			break;

		case 's':
			print_stats = 1;
			break;

		case 'w':
			exit_wait = 1;
			break;

		case 'h':
			print_usage(stdout, 0);

		case '?':
			print_usage(stderr, 1);

		case -1:
			break;

		default:
			abort();
		}
	} while (next_opt != -1);

	if (argc == 1 || mmap_mode == MMAP_MODE_NONE)
		print_usage(stderr, 2);

	addr = do_mmap(fd, length);
	if (mmap_mode == MMAP_MODE_FILE)
		close(fd);

	if (addr == MAP_FAILED) {
		perror("mmap");
		return 1;
	}

	if (print_stats) {
		hz = sysconf(_SC_CLK_TCK);
		if (hz == -1) {
			perror("sysconf");
			return 1;
		}

		tvali = times(&tms);

		if (getrusage(RUSAGE_SELF, &r1)) {
			perror("getrusage");
			return 1;
		}
	}

	do_page_fault(addr, length, fault_mode);

	if (print_stats) {
		if (getrusage(RUSAGE_SELF, &r2)) {
			perror("getrusage");
			return 1;
		}

		tvalf = times(&tms);

		elapsed = (double) (tvalf - tvali) / hz;
		us_time = (double) tms.tms_utime / hz;
		sy_time = (double) tms.tms_stime / hz;

		fprintf(stderr, "page faults: %lu minor; %lu major\n",
			r2.ru_minflt - r1.ru_minflt,
			r2.ru_majflt - r1.ru_majflt);

		fprintf(stderr, "time (secs): %0.3lf wall; "
			"%0.3lf user; %0.3lf system\n",
			elapsed, us_time, sy_time);

		fprintf(stderr, "throughput : %0.3lf kB/s \n",
			length / KB / elapsed);
	}

	if (exit_wait)
		wait_loop();

	return 0;
}