예제 #1
0
파일: sudoku.c 프로젝트: tayo/sudoku-simple
int restr(int i, int j, int num) {
	short root = (short)(sqrt((double)N));
	int k = 0, m = 0;

	/* neighboring cols in sqr */
	for (k = (j/root)*root; k < ((j/root)*root + root); k++) {
		//if ((k != j) && (puz[i][k] == 0))
		if ((k != j))
			if (!(col_find(k, num)))
				return 0;
	}

	/* neighboring rows in sqr */
	for (k = (i/root)*root; k < ((i/root)*root + root); k++) {
		//if ((k != i) && (puz[k][j] == 0))
		if ((k != i))
			if (!(row_find(k, num)))
				return 0;
	}

	return 1;
}
예제 #2
0
static int
read_stats(rcid_type_t stat_type)
{
	int fd;
	int proc_fd;
	char procfile[20];
	uint64_t pid;
	col_t *col, *col_next;
	lcollection_report_t report;
	struct stat st;

	if ((fd = open(STAT_FILE_DEFAULT, O_RDONLY)) < 0) {
		warn(gettext("rcapd is not active\n"));
		return (E_ERROR);
	}

	if (fstat(fd, &st) == 0)
		stat_mod = st.st_mtime;

	if (read(fd, &hdr, sizeof (hdr)) != sizeof (hdr)) {
		(void) fprintf(stderr,
		    gettext("rcapstat: can't read stat file header: %s\n"),
		    strerror(errno));
		(void) close(fd);
		return (E_ERROR);
	}

	/*
	 * Check if rcapd is running
	 */
	pid = hdr.rs_pid;
	(void) snprintf(procfile, 20, "/proc/%lld/psinfo", pid);
	if ((proc_fd = open(procfile, O_RDONLY)) < 0) {
		warn(gettext("rcapd is not active\n"));
		(void) close(fd);
		return (E_ERROR);
	}
	(void) close(proc_fd);

	(void) strncpy(mode, hdr.rs_mode, RC_MODE_LEN);
	for (col = col_head; col != NULL; col = col->col_next) {
		col->col_fresh = 0;
		col->col_paged_eff = 0;
		col->col_paged_att = 0;
	}

	while (read(fd, &report, sizeof (report)) == sizeof (report)) {
		if (report.lcol_id.rcid_type != stat_type)
			continue;

		col = col_find(report.lcol_id);
		if (col == NULL) {
			col = col_insert(report.lcol_id);
			col->col_paged_eff_old = col->col_paged_eff =
			    report.lcol_stat.lcols_pg_eff;
			col->col_paged_att_old = col->col_paged_att =
			    report.lcol_stat.lcols_pg_att;
			col->col_count = 0;
		}
		(void) strncpy(col->col_name, report.lcol_name, LC_NAME_LEN);
		col->col_vmsize = report.lcol_image_size;
		col->col_rsssize = report.lcol_rss;
		col->col_rsslimit = report.lcol_rss_cap;
		col->col_fresh = 1;
		if (report.lcol_stat.lcols_pg_eff > col->col_paged_eff_old) {
			col->col_paged_eff =
			    report.lcol_stat.lcols_pg_eff -
			    col->col_paged_eff_old;
			if (report.lcol_stat.lcols_scan_count > col->col_count)
				col->col_paged_eff_avg =
				    col->col_paged_eff /
				    (report.lcol_stat.lcols_scan_count -
				    col->col_count);
		} else {
			col->col_paged_eff_avg = 0;
		}
		if (report.lcol_stat.lcols_pg_att > col->col_paged_att_old) {
			col->col_paged_att =
			    report.lcol_stat.lcols_pg_att -
			    col->col_paged_att_old;
			if (report.lcol_stat.lcols_scan_count > col->col_count)
				col->col_paged_att_avg =
				    col->col_paged_att /
				    (report.lcol_stat.lcols_scan_count -
				    col->col_count);
		} else {
			col->col_paged_att_avg = 0;
		}
		col->col_paged_eff_old = report.lcol_stat.lcols_pg_eff;
		col->col_paged_att_old = report.lcol_stat.lcols_pg_att;
		col->col_nproc =
		    report.lcol_stat.lcols_proc_in -
		    report.lcol_stat.lcols_proc_out;
		col->col_count = report.lcol_stat.lcols_scan_count;
		col->col_src_stat = report.lcol_stat;
	}

	/*
	 * Remove stale data
	 */
	col = col_head;
	while (col != NULL) {
		col_next = col->col_next;
		if (col->col_fresh == 0)
			col_remove(col);
		col = col_next;
	}
	(void) close(fd);
	return (E_SUCCESS);
}