Exemplo n.º 1
0
static int do_site(void)
{
	int fd;
	int rv = -1;

	if (!cl.debug) {
		if (daemon(0, 0) < 0) {
			perror("daemon error");
			exit(EXIT_FAILURE);
		}
	}

	setup_logging();
	fd = lockfile();
	if (fd < 0)
		return fd;

	log_info("BOOTH cluster site daemon started");
	set_scheduler();
	set_oom_adj(-16);

	rv = loop(SITE);
	if (rv < 0)
		goto fail;

	unlink_lockfile(fd);
	close_logging();

	return 0;

fail:
	return -1;
}
Exemplo n.º 2
0
//------------------------------------------------
// Config for JNA 
//
bool configJNA(char* device_name, uint32_t size, uint32_t num_of_sub_sector){
	g_ref_tab_columns = num_of_sub_sector;

	if (! config_parse_device_name(device_name)){
    	printf("=> ERROR: Couldn't parse device name: %s\n", device_name);
		return false;
    }else
    {g_record_bytes = size;}

    if (! discover_num_blocks(g_device)){
		printf("=> ERROR: Couldn't discover number of blocks.\n");
		return false;
	}

	set_scheduler();

	return true;
}
Exemplo n.º 3
0
int main(int argc, char* argv[])
{
	unsigned long mask = -1;
	int r = 0, fd = open("/proc/sys/chronos/clear_on_sched_set", O_RDWR);
	char on = '1', buff;

	if(fd == -1) {
		perror("Cannot open proc file: are you sudo?\n"); exit(1);
	}

	r = read(fd, &buff, 1);
	write(fd, &on, 1);

	set_scheduler(SCHED_RT_FIFO, -1, mask);
	write(fd, &buff, r);

	close(fd);
	return 0;
}
Exemplo n.º 4
0
Controller::Controller( active::scheduler & tp, int seed )
{
	remaining_iterations=500;
	srand(seed);
	set_scheduler(tp);
	display.set_scheduler(tp);
	for(int x=0; x<num_cols; ++x)
		for(int y=0; y<num_rows; ++y)
		{
			cell[x][y].x = x;
			cell[x][y].y = y;
			cell[x][y].display = &display;
			cell[x][y].controller = this;
			cell[x][y].set_scheduler(tp);

			// Set up cell neighbours.
			Cell::add_neighbour an;
			int x0=(x-1)%num_cols, x1=(x+1)%num_cols, y0=(y-1)%num_rows, y1=(y+1)%num_rows;

			if( x0<0 ) x0+=num_cols;	// Thank you % for not being intuituive...
			if( y0<0 ) y0+=num_rows;

			an.neighbour = &cell[x0][y0];
			cell[x][y](an);
			an.neighbour = &cell[x0][y];
			cell[x][y](an);
			an.neighbour = &cell[x0][y1];
			cell[x][y](an);
			an.neighbour = &cell[x][y0];
			cell[x][y](an);
			an.neighbour = &cell[x][y1];
			cell[x][y](an);
			an.neighbour = &cell[x1][y0];
			cell[x][y](an);
			an.neighbour = &cell[x1][y];
			cell[x][y](an);
			an.neighbour = &cell[x1][y1];
			cell[x][y](an);

			cell[x][y].is_alive = (bool)(rand()/(RAND_MAX/2));
		}
}
Exemplo n.º 5
0
static void set_priority(void)
{
	const char *ptr;

	ptr = getenv("CTDB_NOSETSCHED");
	if (ptr != NULL) {
		realtime = false;
	}

	if (! realtime) {
		return;
	}

	realtime = set_scheduler();
	if (! realtime) {
		fprintf(stderr,
			"%s: Unable to set real-time scheduler priority\n",
			progname);
	}
}
Exemplo n.º 6
0
Arquivo: main.c Projeto: aspiers/booth
static int do_server(int type)
{
	int fd = -1;
	int rv = -1;

	rv = setup(type);
	if (rv < 0)
		goto out;

	if (!daemonize) {
		if (daemon(0, 0) < 0) {
			perror("daemon error");
			exit(EXIT_FAILURE);
		}
	}

	/*
	  The lock cannot be obtained before the call to daemon(), otherwise
	  the lockfile would contain the pid of the parent, not the daemon.
	*/
	fd = lockfile();
	if (fd < 0)
		return fd;

	if (type == ARBITRATOR)
		log_info("BOOTH arbitrator daemon started");
	else if (type == SITE)
		log_info("BOOTH cluster site daemon started");

	set_scheduler();
	set_oom_adj(-16);

	rv = loop();

out:
	if (fd >= 0)
		unlink_lockfile(fd);

	return rv;
}
Exemplo n.º 7
0
void set_scheduler(size_t nw = std::thread::hardware_concurrency()) {
  set_scheduler(new scheduler::coordinator<StealPolicy, JobQueuePolicy>(nw));
}
Exemplo n.º 8
0
Arquivo: edf-wm.c Projeto: Aand1/ROSCH
/**
 * assign the given task to a particular CPU.
 * if no CPUs can accept the task, it is just assigned the lowest priority.
 * note that the task has not yet been inserted into the global list.
 */
static void task_run(resch_task_t *rt)
{
	int cpu_dst;

	/* aperiodic tasks are just skipped. */
	if (!rt->period) {
		return;
	}

	/* first clear the EDF-WM properties. */
	clear_split_task(rt);

	/* this is going to be a big lock! */
	global_list_down();

	/* try partitioning. */
	if ((cpu_dst = partition(rt)) != RESCH_CPU_UNDEFINED) {
		/* schedulable. */
		goto out; 
	}

	/* try splitting. */
	cpu_dst = split(rt);

 out:
	rt->cpu_id = cpu_dst; /* this is safe. */
	global_list_up();

	/* if partitioning succeeded, migrate @p to the cpu. 
	   otherwise, do the default fair scheduling. */
	if (cpu_dst != RESCH_CPU_UNDEFINED) {
		if (task_is_split(rt)) {
			edf_wm_task_t *et = &edf_wm_task[rt->rid];
			unsigned long runtime_save = et->rt->runtime;
			et->sched_deadline = et->rt->task->dl.sched_deadline;
			et->rt->deadline = et->deadline;
			et->rt->runtime = jiffies_to_usecs(et->runtime[et->first_cpu]);
			/* change the deadline. */
			set_scheduler(et->rt, RESCH_SCHED_EDF, rt->prio);
			et->sched_split_deadline = et->rt->task->dl.sched_deadline;
			et->rt->runtime = runtime_save;

			printk(KERN_INFO "EDF-WM: task#%d is split across to CPU#%d-%d.\n", 
				   rt->rid, et->first_cpu, et->last_cpu);
		}
		else {
			if (rt->policy != RESCH_SCHED_EDF) {
				set_scheduler(rt, RESCH_SCHED_EDF, RESCH_PRIO_EDF);
			}
			printk(KERN_INFO "EDF-WM: task#%d is assigned to CPU#%d.\n", 
				   rt->rid, cpu_dst);
		}
		rt->migratory = false;
		migrate_task(rt, cpu_dst);
	}
	else {
		printk(KERN_INFO "EDF-WM: task#%d is not schedulable.\n", rt->rid);
		/* it is actually the designer's choice how the tasks not 
		   successfully partitioned are scheduled. */
		set_scheduler(rt, RESCH_SCHED_FAIR, 0);
	}
}
Exemplo n.º 9
0
int
main(int argc, char* argv[])
{
	signal_setup();

	fprintf(stdout, "\nACT version %s\n", VERSION);
	fprintf(stdout, "Storage device IO test\n");
	fprintf(stdout, "Copyright 2018 by Aerospike. All rights reserved.\n\n");

	if (! storage_configure(argc, argv)) {
		exit(-1);
	}

	device devices[g_scfg.num_devices];
	queue* trans_qs[g_scfg.num_queues];

	g_devices = devices;
	g_trans_qs = trans_qs;

	histogram_scale scale =
			g_scfg.us_histograms ? HIST_MICROSECONDS : HIST_MILLISECONDS;

	if (! (g_large_block_read_hist = histogram_create(scale)) ||
		! (g_large_block_write_hist = histogram_create(scale)) ||
		! (g_raw_read_hist = histogram_create(scale)) ||
		! (g_read_hist = histogram_create(scale)) ||
		! (g_raw_write_hist = histogram_create(scale)) ||
		! (g_write_hist = histogram_create(scale))) {
		exit(-1);
	}

	for (uint32_t n = 0; n < g_scfg.num_devices; n++) {
		device* dev = &g_devices[n];

		dev->name = (const char*)g_scfg.device_names[n];

		if (g_scfg.file_size == 0) { // normally 0
			set_scheduler(dev->name, g_scfg.scheduler_mode);
		}

		if (! (dev->fd_q = queue_create(sizeof(int), true)) ||
			! discover_device(dev) ||
			! (dev->raw_read_hist = histogram_create(scale)) ||
			! (dev->raw_write_hist = histogram_create(scale))) {
			exit(-1);
		}

		sprintf(dev->read_hist_tag, "%s-reads", dev->name);
		sprintf(dev->write_hist_tag, "%s-writes", dev->name);
	}

	rand_seed();

	g_run_start_us = get_us();

	uint64_t run_stop_us = g_run_start_us + g_scfg.run_us;

	g_running = true;

	if (g_scfg.write_reqs_per_sec != 0) {
		for (uint32_t n = 0; n < g_scfg.num_devices; n++) {
			device* dev = &g_devices[n];

			if (pthread_create(&dev->large_block_read_thread, NULL,
					run_large_block_reads, (void*)dev) != 0) {
				fprintf(stdout, "ERROR: create large op read thread\n");
				exit(-1);
			}

			if (pthread_create(&dev->large_block_write_thread, NULL,
					run_large_block_writes, (void*)dev) != 0) {
				fprintf(stdout, "ERROR: create large op write thread\n");
				exit(-1);
			}
		}
	}

	if (g_scfg.tomb_raider) {
		for (uint32_t n = 0; n < g_scfg.num_devices; n++) {
			device* dev = &g_devices[n];

			if (pthread_create(&dev->tomb_raider_thread, NULL,
					run_tomb_raider, (void*)dev) != 0) {
				fprintf(stdout, "ERROR: create tomb raider thread\n");
				exit(-1);
			}
		}
	}

	uint32_t n_trans_tids = g_scfg.num_queues * g_scfg.threads_per_queue;
	pthread_t trans_tids[n_trans_tids];

	for (uint32_t i = 0; i < g_scfg.num_queues; i++) {
		if (! (g_trans_qs[i] = queue_create(sizeof(trans_req), true))) {
			exit(-1);
		}

		for (uint32_t j = 0; j < g_scfg.threads_per_queue; j++) {
			if (pthread_create(&trans_tids[(i * g_scfg.threads_per_queue) + j],
					NULL, run_transactions, (void*)g_trans_qs[i]) != 0) {
				fprintf(stdout, "ERROR: create transaction thread\n");
				exit(-1);
			}
		}
	}

	// Equivalent: g_scfg.internal_read_reqs_per_sec != 0.
	bool do_reads = g_scfg.read_reqs_per_sec != 0;

	pthread_t read_req_tids[g_scfg.read_req_threads];

	if (do_reads) {
		for (uint32_t k = 0; k < g_scfg.read_req_threads; k++) {
			if (pthread_create(&read_req_tids[k], NULL, run_generate_read_reqs,
					NULL) != 0) {
				fprintf(stdout, "ERROR: create read request thread\n");
				exit(-1);
			}
		}
	}

	// Equivalent: g_scfg.internal_write_reqs_per_sec != 0.
	bool do_commits = g_scfg.commit_to_device && g_scfg.write_reqs_per_sec != 0;

	pthread_t write_req_tids[g_scfg.write_req_threads];

	if (do_commits) {
		for (uint32_t k = 0; k < g_scfg.write_req_threads; k++) {
			if (pthread_create(&write_req_tids[k], NULL,
					run_generate_write_reqs, NULL) != 0) {
				fprintf(stdout, "ERROR: create write request thread\n");
				exit(-1);
			}
		}
	}

	fprintf(stdout, "\nHISTOGRAM NAMES\n");

	if (do_reads) {
		fprintf(stdout, "reads\n");
		fprintf(stdout, "device-reads\n");

		for (uint32_t d = 0; d < g_scfg.num_devices; d++) {
			fprintf(stdout, "%s\n", g_devices[d].read_hist_tag);
		}
	}

	if (g_scfg.write_reqs_per_sec != 0) {
		fprintf(stdout, "large-block-reads\n");
		fprintf(stdout, "large-block-writes\n");
	}

	if (do_commits) {
		fprintf(stdout, "writes\n");
		fprintf(stdout, "device-writes\n");

		for (uint32_t d = 0; d < g_scfg.num_devices; d++) {
			fprintf(stdout, "%s\n", g_devices[d].write_hist_tag);
		}
	}

	fprintf(stdout, "\n");

	uint64_t now_us = 0;
	uint64_t count = 0;

	while (g_running && (now_us = get_us()) < run_stop_us) {
		count++;

		int64_t sleep_us = (int64_t)
				((count * g_scfg.report_interval_us) -
						(now_us - g_run_start_us));

		if (sleep_us > 0) {
			usleep((uint32_t)sleep_us);
		}

		fprintf(stdout, "after %" PRIu64 " sec:\n",
				(count * g_scfg.report_interval_us) / 1000000);

		fprintf(stdout, "requests-queued: %" PRIu32 "\n",
				atomic32_get(g_reqs_queued));

		if (do_reads) {
			histogram_dump(g_read_hist, "reads");
			histogram_dump(g_raw_read_hist, "device-reads");

			for (uint32_t d = 0; d < g_scfg.num_devices; d++) {
				histogram_dump(g_devices[d].raw_read_hist,
						g_devices[d].read_hist_tag);
			}
		}

		if (g_scfg.write_reqs_per_sec != 0) {
			histogram_dump(g_large_block_read_hist, "large-block-reads");
			histogram_dump(g_large_block_write_hist, "large-block-writes");
		}

		if (do_commits) {
			histogram_dump(g_write_hist, "writes");
			histogram_dump(g_raw_write_hist, "device-writes");

			for (uint32_t d = 0; d < g_scfg.num_devices; d++) {
				histogram_dump(g_devices[d].raw_write_hist,
						g_devices[d].write_hist_tag);
			}
		}

		fprintf(stdout, "\n");
		fflush(stdout);
	}

	g_running = false;

	if (do_reads) {
		for (uint32_t k = 0; k < g_scfg.read_req_threads; k++) {
			pthread_join(read_req_tids[k], NULL);
		}
	}

	if (do_commits) {
		for (uint32_t k = 0; k < g_scfg.write_req_threads; k++) {
			pthread_join(write_req_tids[k], NULL);
		}
	}

	for (uint32_t j = 0; j < n_trans_tids; j++) {
		pthread_join(trans_tids[j], NULL);
	}

	for (uint32_t i = 0; i < g_scfg.num_queues; i++) {
		queue_destroy(g_trans_qs[i]);
	}

	for (uint32_t d = 0; d < g_scfg.num_devices; d++) {
		device* dev = &g_devices[d];

		if (g_scfg.tomb_raider) {
			pthread_join(dev->tomb_raider_thread, NULL);
		}

		if (g_scfg.write_reqs_per_sec != 0) {
			pthread_join(dev->large_block_read_thread, NULL);
			pthread_join(dev->large_block_write_thread, NULL);
		}

		fd_close_all(dev);
		queue_destroy(dev->fd_q);
		free(dev->raw_read_hist);
		free(dev->raw_write_hist);
	}

	free(g_large_block_read_hist);
	free(g_large_block_write_hist);
	free(g_raw_read_hist);
	free(g_read_hist);
	free(g_raw_write_hist);
	free(g_write_hist);

	return 0;
}
Exemplo n.º 10
0
static int do_server(int type)
{
	int rv = -1;
	static char log_ent[128] = DAEMON_NAME "-";

	rv = setup_config(type);
	if (rv < 0)
		return rv;

	if (!local) {
		log_error("Cannot find myself in the configuration.");
		exit(EXIT_FAILURE);
	}

	if (daemonize) {
		if (daemon(0, 0) < 0) {
			perror("daemon error");
			exit(EXIT_FAILURE);
		}
	}

	/* The lockfile must be written to _after_ the call to daemon(), so
	 * that the lockfile contains the pid of the daemon, not the parent. */
	lock_fd = create_lockfile();
	if (lock_fd < 0)
		return lock_fd;

	atexit(server_exit);

	strcat(log_ent, type_to_string(local->type));
	cl_log_set_entity(log_ent);
	cl_log_enable_stderr(enable_stderr ? TRUE : FALSE);
	cl_log_set_facility(HA_LOG_FACILITY);
	cl_inherit_logging_environment(0);

	log_info("BOOTH %s %s daemon is starting",
			type_to_string(local->type), RELEASE_STR);

	signal(SIGUSR1, (__sighandler_t)tickets_log_info);
	signal(SIGTERM, (__sighandler_t)sig_exit_handler);
	signal(SIGINT, (__sighandler_t)sig_exit_handler);
	/* we'll handle errors there and then */
	signal(SIGPIPE, SIG_IGN);

	set_scheduler();
	/* we don't want to be killed by the OOM-killer */
	if (set_procfs_val("/proc/self/oom_score_adj", "-999"))
		(void)set_procfs_val("/proc/self/oom_adj", "-16");
	set_proc_title("%s %s %s for [%s]:%d",
			DAEMON_NAME,
			cl.configfile,
			type_to_string(local->type),
			local->addr_string,
			booth_conf->port);

	rv = limit_this_process();
	if (rv)
		return rv;

#ifdef COREDUMP_NURSING
	if (cl_enable_coredumps(TRUE) < 0){
		log_error("enabling core dump failed");
	}
	cl_cdtocoredir();
	prctl(PR_SET_DUMPABLE, (unsigned long)TRUE, 0UL, 0UL, 0UL);
#else
	if (chdir(BOOTH_CORE_DIR) < 0) {
		log_error("cannot change working directory to %s", BOOTH_CORE_DIR);
	}
#endif

	signal(SIGCHLD, (__sighandler_t)wait_child);
	rv = loop(lock_fd);

	return rv;
}
Exemplo n.º 11
0
static int do_server(int type)
{
	int rv = -1;
	static char log_ent[128] = DAEMON_NAME "-";

	rv = setup_config(type);
	if (rv < 0)
		return rv;


	if (!local) {
		log_error("Cannot find myself in the configuration.");
		exit(EXIT_FAILURE);
	}

	if (!daemonize) {
		if (daemon(0, 0) < 0) {
			perror("daemon error");
			exit(EXIT_FAILURE);
		}
	}

	/* The lockfile must be written to _after_ the call to daemon(), so
	 * that the lockfile contains the pid of the daemon, not the parent. */
	lock_fd = create_lockfile();
	if (lock_fd < 0)
		return lock_fd;

	atexit(server_exit);

	strcat(log_ent, type_to_string(local->type));
	cl_log_set_entity(log_ent);
	cl_log_enable_stderr(enable_stderr ? TRUE : FALSE);
	cl_log_set_facility(HA_LOG_FACILITY);
	cl_inherit_logging_environment(0);

	log_info("BOOTH %s %s daemon is starting",
			type_to_string(local->type), RELEASE_STR);

	signal(SIGUSR1, (__sighandler_t)tickets_log_info);
	signal(SIGTERM, (__sighandler_t)sig_exit_handler);
	signal(SIGINT, (__sighandler_t)sig_exit_handler);

	set_scheduler();
	set_oom_adj(-16);
	set_proc_title("%s %s %s for [%s]:%d",
			DAEMON_NAME,
			cl.configfile,
			type_to_string(local->type),
			local->addr_string,
			booth_conf->port);

	rv = limit_this_process();
	if (rv)
		return rv;

	if (cl_enable_coredumps(TRUE) < 0){
		cl_log(LOG_ERR, "enabling core dump failed");
	}
	cl_cdtocoredir();
	prctl(PR_SET_DUMPABLE, (unsigned long)TRUE, 0UL, 0UL, 0UL);

	rv = loop(lock_fd);

	return rv;
}
Exemplo n.º 12
0
int main(int argc, char *argv[])
{
	int write_fd, log_fd;
	char result = 0;
	int ppid;
	const char *lock_type;

	progname = argv[0];

	if (argc < 5) {
		usage();
		exit(1);
	}

	if (!set_scheduler()) {
		fprintf(stderr, "%s: Unable to set real-time scheduler priority\n",
			progname);
	}

	log_fd = atoi(argv[1]);
	close(STDOUT_FILENO);
	close(STDERR_FILENO);
	dup2(log_fd, STDOUT_FILENO);
	dup2(log_fd, STDERR_FILENO);
	close(log_fd);

	ppid = atoi(argv[2]);
	write_fd = atoi(argv[3]);
	lock_type = argv[4];

	if (strcmp(lock_type, "RECORD") == 0) {
		if (argc != 8) {
			fprintf(stderr, "%s: Invalid number of arguments (%d)\n",
				progname, argc);
			usage();
			exit(1);
		}
		result = lock_record(argv[5], argv[6], argv[7]);

	} else if (strcmp(lock_type, "DB") == 0) {
		int n;

		/* If there are no databases specified, no need for lock */
		if (argc > 5) {
			for (n=5; n+1<argc; n+=2) {
				result = lock_db(argv[n], argv[n+1]);
				if (result != 0) {
					break;
				}
			}
		}

	} else {
		fprintf(stderr, "%s: Invalid lock-type '%s'\n", progname, lock_type);
		usage();
		exit(1);
	}

	send_result(write_fd, result);

	ctdb_wait_for_process_to_exit(ppid);
	return 0;
}