Example #1
0
/*
 * Return number of online cpus
 */
int get_num_online_cpus()
{
	FILE *filp;
	int i;
	char path[PATH_MAX];
	int status = 0;
	int value_of_onlinefile, rc;

	for (i = 0; i <= get_numcpus(); i++) {
		/* check wether file exists and is readable */
		sprintf(path, "/sys/devices/system/cpu/cpu%d/online", i);
		if (access(path, R_OK) != 0)
			continue;
		filp = fopen(path, "r");
		if (!filp)
			cpuplugd_exit("Cannot open cpu online file: "
				      "%s\n", strerror(errno));
		else {
			rc = fscanf(filp, "%d", &value_of_onlinefile);
			if (rc != 1)
				cpuplugd_exit("Cannot read cpu online file: "
					      "%s\n", strerror(errno));
			if (value_of_onlinefile == 1)
				status++;
		}
		fclose(filp);
	}
	return status;
}
Example #2
0
ri_option_t *
ri_option_new()
{
    int              ret;
	ri_option_t     *p    = NULL;
	ri_display_t    *disp = NULL;

	p = (ri_option_t *)ri_mem_alloc(sizeof(ri_option_t));


	p->camera                    = ri_camera_new();
    p->display_list              = ri_list_new();

    disp                         = ri_display_new();
    ret = ri_list_append(p->display_list, (void *)disp);
    assert(ret == 0);

    
	p->hider                     = "hidden";
	p->searchpath                = ri_ptr_array_new();
	p->relative_detail           = 1.0;
	p->orientation               = RI_LH;
	p->nfinalgather_rays         = 5;
	p->narealight_rays           = 16;
	p->max_ray_depth             = 5;

	p->irradcache_find_tolerance = 5.0;
	p->irradcache_max_radius     = 1.0;

	p->bssrdf_nsamples           = 100;
	p->bssrdf_scatter            = 2.19;
	p->bssrdf_absorb             = 0.0021;
	p->bssrdf_scale              = 1.0;
	p->bssrdf_tree_level         = 3;
	p->bssrdf_cache_file         = NULL;

	p->enable_direct_lighting    = 1;
	p->enable_indirect_lighting  = 0;
	p->enable_caustics_lighting  = 0;
	p->irradcache_file           = NULL;

	p->accel_method              = RI_ACCEL_BVH;

	p->compute_prt               = 0;
	p->prt_is_glossy             = 0;
	p->prt_nsamples              = 64;
	p->prt_samplinglevel         = 3;
	p->prt_do_distscale          = 0;
	p->prt_scale                 = 1.0;

	ri_vector_setzero( p->bgcolor );
	ri_vector_setzero( p->ambcolor );

#if defined(WITH_PTHREAD) || (!defined(NOTHREAD) && defined(WIN32))
	/*
	 * default: automatically determine the number of threads to use, 
	 * from the number of cpus installed in the system.
	 */

	p->nthreads = get_numcpus();
#else	/* compiled with no thread support */
	p->nthreads = 0;
#endif

	p->use_qmc = 0;
	p->render_method = TRANSPORT_MCRAYTRACE;

	p->pt_nsamples = 4;

	p->mlt_nsamples = 10000;
	p->bsp_tree_depth = 6;
	p->kd_tree_depth = 16;

	p->gather_nsamples = 64;

	//p->pixel_filter = RiBoxFilter;
	p->pixel_filter_widthx = 1.0;
	p->pixel_filter_widthy = 1.0;

	p->do_adaptive_supersampling = 1;

	return p;
}
Example #3
0
static void eval_cpu_rules(void)
{
	double diffs[CPUSTATS], diffs_total, percent_factor;
	char *procinfo_current, *procinfo_prev;
	int cpu, nr_cpus, on_off;

	nr_cpus = get_numcpus();
	procinfo_current = cpustat + history_current * cpustat_size;
	procinfo_prev = cpustat + history_prev * cpustat_size;

	diffs[0] = get_proc_value(procinfo_current, "user", ' ') -
		   get_proc_value(procinfo_prev, "user", ' ');
	diffs[1] = get_proc_value(procinfo_current, "nice", ' ') -
		   get_proc_value(procinfo_prev, "nice", ' ');
	diffs[2] = get_proc_value(procinfo_current, "system", ' ') -
		   get_proc_value(procinfo_prev, "system", ' ');
	diffs[3] = get_proc_value(procinfo_current, "idle", ' ') -
		   get_proc_value(procinfo_prev, "idle", ' ');
	diffs[4] = get_proc_value(procinfo_current, "iowait", ' ') -
		   get_proc_value(procinfo_prev, "iowait", ' ');
	diffs[5] = get_proc_value(procinfo_current, "irq", ' ') -
		   get_proc_value(procinfo_prev, "irq", ' ');
	diffs[6] = get_proc_value(procinfo_current, "softirq", ' ') -
		   get_proc_value(procinfo_prev, "softirq", ' ');
	diffs[7] = get_proc_value(procinfo_current, "steal", ' ') -
		   get_proc_value(procinfo_prev, "steal", ' ');
	diffs[8] = get_proc_value(procinfo_current, "guest", ' ') -
		   get_proc_value(procinfo_prev, "guest", ' ');
	diffs[9] = get_proc_value(procinfo_current, "guest_nice", ' ') -
		   get_proc_value(procinfo_prev, "guest_nice", ' ');

	diffs_total = get_proc_value(procinfo_current, "total_ticks", ' ') -
		      get_proc_value(procinfo_prev, "total_ticks", ' ');
	if (diffs_total == 0)
		diffs_total = 1;

	symbols.loadavg = get_proc_value(procinfo_current, "loadavg", ' ');
	symbols.runnable_proc = get_proc_value(procinfo_current,
					       "runnable_proc", ' ');
	symbols.onumcpus = get_proc_value(procinfo_current, "onumcpus", ' ');

	percent_factor = 100 * symbols.onumcpus;
	symbols.user = (diffs[0] / diffs_total) * percent_factor;
	symbols.nice = (diffs[1] / diffs_total) * percent_factor;
	symbols.system = (diffs[2] / diffs_total) * percent_factor;
	symbols.idle = (diffs[3] / diffs_total) * percent_factor;
	symbols.iowait = (diffs[4] / diffs_total) * percent_factor;
	symbols.irq = (diffs[5] / diffs_total) * percent_factor;
	symbols.softirq = (diffs[6] / diffs_total) * percent_factor;
	symbols.steal = (diffs[7] / diffs_total) * percent_factor;
	symbols.guest = (diffs[8] / diffs_total) * percent_factor;
	symbols.guest_nice = (diffs[9] / diffs_total) * percent_factor;

	/* only use this for development and testing */
	cpuplugd_debug("cpustat values:\n%s", cpustat + history_current *
		       cpustat_size);
	if (debug && foreground == 1) {
		printf("-------------------- CPU --------------------\n");
		printf("cpu_min: %ld\n", cfg.cpu_min);
		printf("cpu_max: %ld\n", cfg.cpu_max);
		printf("loadavg: %f \n", symbols.loadavg);
		printf("user percent = %f\n", symbols.user);
		printf("nice percent = %f\n", symbols.nice);
		printf("system percent = %f\n", symbols.system);
		printf("idle percent = %f\n", symbols.idle);
		printf("iowait percent = %f\n", symbols.iowait);
		printf("irq percent = %f\n", symbols.irq);
		printf("softirq percent = %f\n", symbols.softirq);
		printf("steal percent = %f\n", symbols.steal);
		printf("guest percent = %f\n", symbols.guest);
		printf("guest_nice percent = %f\n", symbols.guest_nice);
		printf("numcpus %d\n", nr_cpus);
		printf("runnable_proc: %d\n", (int) symbols.runnable_proc);
		printf("---------------------------------------------\n");
		printf("onumcpus:   %d\n", (int) symbols.onumcpus);
		printf("---------------------------------------------\n");
		printf("hotplug: ");
		print_term(cfg.hotplug);
		printf("\n");
		printf("hotunplug: ");
		print_term(cfg.hotunplug);
		printf("\n");
		printf("---------------------------------------------\n");
	}

	on_off = 0;
	/* Evaluate the hotplug rule */
	if (eval_term(cfg.hotplug, &symbols))
		on_off++;
	/* Evaluate the hotunplug rule only if hotplug did not match */
	else if (eval_term(cfg.hotunplug, &symbols))
		on_off--;
	if (on_off > 0) {
		/* check the cpu nr limit */
		if (symbols.onumcpus + 1 > cfg.cpu_max) {
			/* cpu limit reached */
			cpuplugd_debug("maximum cpu limit is reached\n");
			return;
		}
		/* try to find a offline cpu */
		for (cpu = 0; cpu < nr_cpus; cpu++)
			if (is_online(cpu) == 0 && cpu_is_configured(cpu) != 0)
				break;
		if (cpu < nr_cpus) {
			cpuplugd_debug("cpu with id %d is currently offline "
				       "and will be enabled\n", cpu);
			if (hotplug(cpu) == -1)
				cpuplugd_debug("unable to find a cpu which "
					       "can be enabled\n");
		} else {
			/*
			 * In case we tried to enable a cpu but this failed.
			 * This is the case if a cpu is deconfigured
			 */
			cpuplugd_debug("unable to find a cpu which can "
				       "be enabled\n");
		}
	} else if (on_off < 0) {
		/* check cpu nr limit */
		if (symbols.onumcpus <= cfg.cpu_min) {
			cpuplugd_debug("minimum cpu limit is reached\n");
			return;
		}
		/* try to find a online cpu */
		for (cpu = get_numcpus() - 1; cpu >= 0; cpu--) {
			if (is_online(cpu) != 0)
				break;
		}
		if (cpu > 0) {
			cpuplugd_debug("cpu with id %d is currently online "
				       "and will be disabled\n", cpu);
			hotunplug(cpu);
		}
	}
}