コード例 #1
0
int read_acpi_info_sysfs(int battery)
{
	DIR *sysfs;
	struct dirent *propety;
	char *name;

	sysfs = opendir(batteries[battery]);
	if (sysfs == 0)
	{
	#ifdef DEBUG
		  printf("DBG:Can't open %s!\n", batteries[battery]);
	#endif
	    return 0;
	}
	/* malloc.. might explain the random battery level values on 2.6.24 
	systems (energe_full is called charge_full so the value isn't initialised
	and some random data from the heap is displayed..) 
	if (!acpiinfo) acpiinfo=(ACPIinfo *)malloc(sizeof(ACPIinfo)); 
	*/
	if (!acpiinfo) acpiinfo=(ACPIinfo *)calloc(1, sizeof(ACPIinfo));
	
	while ((propety = readdir(sysfs)))
	{
		name = propety->d_name;
		if (!strncmp(".", name, 1) || !strncmp("..", name, 2)) continue;
		/* at least on my system this is called charge_full */
		if ((strcmp(name,"energy_full") == 0) || (strcmp(name,"charge_full") == 0))
		{
			sprintf(buf,"%s/%s",batteries[battery], name);
			acpiinfo->last_full_capacity = read_sysfs_int(buf);
		}
		if ((strcmp(name,"energy_full_design") == 0) || (strcmp(name,"charge_full_design") == 0))
		{
			sprintf(buf,"%s/%s",batteries[battery], name);
			acpiinfo->design_capacity = read_sysfs_int(buf);
		}
		if (strcmp(name,"technology") == 0)
		{
			char *tmp;
			sprintf(buf,"%s/%s",batteries[battery], name);
			tmp = read_sysfs_string(buf);
			if (tmp != NULL)
			{
				if (strcmp(tmp,"Li-ion") == 0)
					acpiinfo->battery_technology = 1;
				else
					acpiinfo->battery_technology = 0;
			}
		}
		if (strcmp(name,"present") == 0)
		{
			sprintf(buf,"%s/%s",batteries[battery], name);
			acpiinfo->present = read_sysfs_int(buf);
		}
	}
	closedir(sysfs);
	return acpiinfo->present;
}
コード例 #2
0
int dmp_fw_loaded(void)
{
    int fw_loaded;
    if (read_sysfs_int(mpu.firmware_loaded, &fw_loaded) < 0)
        fw_loaded= 0;
    return fw_loaded;
}
コード例 #3
0
int save_n_write_sysfs_int(char *filename, int data, int *old_value)
{
    int res;
    res = read_sysfs_int(filename, old_value);
    if (res < 0) {
        return res;
    }
    //printf("saved %s = %d\n", filename, *old_value);
    res = write_sysfs_int(filename, data);
    if (res < 0) {
        return res;
    }
    return 0;
}
コード例 #4
0
static int is_complete(struct loopback_test *t)
{
	int iteration_count;
	int i;

	for (i = 0; i < t->device_count; i++) {
		if (!device_enabled(t, i))
			continue;

		iteration_count = read_sysfs_int(t->devices[i].sysfs_entry,
						 "iteration_count");

		/* at least one device did not finish yet */
		if (iteration_count != t->iteration_max)
			return 0;
	}

	return 1;
}
コード例 #5
0
int read_acad_state_sysfs(void)
{
	DIR *sysfs;
	struct dirent *propety;
	char *name;
	char onlinefilepath[128];
	
	sysfs = opendir(sysfsacdir);
	if (sysfs == 0)
	{
	#ifdef DEBUG
		printf("DBG:Can't open %s",sysfsacdir);
	#endif
		return 0;
	}
	closedir(sysfs);
	
	if (!acadstate) acadstate=(ACADstate *)malloc(sizeof(ACADstate));
	/* this code doesn't make much sense.. why look at the whole directory?!
	while ((propety = readdir(sysfs)))
	{
		name = propety->d_name;
		if (!strncmp(".", name, 1) || !strncmp("..", name, 2)) continue;
		
		if (strcmp(name,"online") == 0)
		{
			acadstate->state = ( read_sysfs_int("/sys/class/power_supply/AC/online") == 1 ) ;
		}
	} 
	*/
	sprintf(onlinefilepath, "%s/online", sysfsacdir);
	/* if onlinefilepath doesn't exist read_sysfs_int() will return 0
	so acadstate->state will be 0, that should be ok */
	acadstate->state = ( read_sysfs_int(onlinefilepath) == 1 );
	
	return acadstate->state;
}
コード例 #6
0
ファイル: loopback_test.c プロジェクト: bryanodonoghue/gbsim
void loopback_run(const char *test_name, int size, int iteration_max,
		  const char *sys_prefix, const char *dbgfs_prefix,
		  uint32_t mask)
{
	char buf[MAX_SYSFS_PATH];
	char inotify_buf[0x800];
	char *sys_pfx = (char*)sys_prefix;
	extern int errno;
	fd_set fds;
	int test_id = 0;
	int i;
	int previous, err, iteration_count;
	int fd, wd, ret;
	struct timeval tv;

	if (construct_paths(sys_prefix, dbgfs_prefix)) {
		fprintf(stderr, "unable to construct sysfs/dbgfs path names\n");
		usage();
		return;
	}
	sys_pfx = ctrl_path;

	for (i = 0; i < sizeof(dict) / sizeof(struct dict); i++) {
		if (strstr(dict[i].name, test_name))
			test_id = dict[i].type;
	}
	if (!test_id) {
		fprintf(stderr, "invalid test %s\n", test_name);
		usage();
		return;
	}

	/* Terminate any currently running test */
	write_sysfs_val(sys_pfx, NULL, "type", 0);

	/* Set parameter for no wait between messages */
	write_sysfs_val(sys_pfx, NULL, "ms_wait", 0);

	/* Set operation size */
	write_sysfs_val(sys_pfx, NULL, "size", size);

	/* Set iterations */
	write_sysfs_val(sys_pfx, NULL, "iteration_max", iteration_max);

	/* Set mask of connections to include */
	write_sysfs_val(sys_pfx, NULL, "mask", mask);

	/* Initiate by setting loopback operation type */
	write_sysfs_val(sys_pfx, NULL, "type", test_id);
	sleep(1);

	if (iteration_max == 0) {
		printf("Infinite test initiated CSV won't be logged\n");
		return;
	}

	/* Setup for inotify on the sysfs entry */
	fd = inotify_init();
	if (fd < 0) {
		fprintf(stderr, "inotify_init fail %s\n", strerror(errno));
		abort();
	}
	snprintf(buf, sizeof(buf), "%s%s", sys_pfx, "iteration_count");
	wd = inotify_add_watch(fd, buf, IN_MODIFY);
	if (wd < 0) {
		fprintf(stderr, "inotify_add_watch %s fail %s\n",
			buf, strerror(errno));
		close(fd);
		abort();
	}

	previous = 0;
	err = 0;
	while (1) {
		/* Wait for change */
		tv.tv_sec = 1;
		tv.tv_usec = 0;
		FD_ZERO(&fds);
		FD_SET(fd, &fds);
		ret = select(fd + 1, &fds, NULL, NULL, &tv);

		if (ret > 0) {
			if (!FD_ISSET(fd, &fds)) {
				fprintf(stderr, "error - FD_ISSET fd=%d flase!\n",
					fd);
				break;
			}
			/* Read to clear the event */
			ret = read(fd, inotify_buf, sizeof(inotify_buf));
		}

		/* Grab the data */
		iteration_count = read_sysfs_int(sys_pfx, NULL, "iteration_count");

		/* Validate data value is different */
		if (previous == iteration_count) {
			err = 1;
			break;
		} else if (iteration_count == iteration_max) {
			break;
		}
		previous = iteration_count;
		if (verbose) {
			printf("%02d%% complete %d of %d\r",
				100 * iteration_count / iteration_max,
				iteration_count, iteration_max);
			fflush(stdout);
		}
	}
	inotify_rm_watch(fd, wd);
	close(fd);

	if (err)
		printf("\nError executing test\n");
	else
		log_csv(test_name, size, iteration_max, sys_pfx, mask);
}
コード例 #7
0
ファイル: loopback_test.c プロジェクト: bryanodonoghue/gbsim
void __log_csv(const char *test_name, int size, int iteration_max,
	       int fd, struct tm *tm, const char *dbgfs_entry,
	       const char *sys_pfx, const char *postfix)
{
	char buf[CSV_MAX_LINE];
	extern int errno;
	int error, fd_dev, len;
	float request_avg, latency_avg, latency_gb_avg, throughput_avg;
	int request_min, request_max, request_jitter;
	int latency_min, latency_max, latency_jitter;
	int throughput_min, throughput_max, throughput_jitter;
	unsigned int i;
	char rx_buf[SYSFS_MAX_INT];

	fd_dev = open(dbgfs_entry, O_RDONLY);
	if (fd_dev < 0) {
		fprintf(stderr, "unable to open specified device %s\n",
			dbgfs_entry);
		return;
	}

	/* gather data set */
	error = read_sysfs_int(sys_pfx, postfix, "error");
	request_min = read_sysfs_int(sys_pfx, postfix, "requests_per_second_min");
	request_max = read_sysfs_int(sys_pfx, postfix, "requests_per_second_max");
	request_avg = read_sysfs_float(sys_pfx, postfix, "requests_per_second_avg");
	latency_min = read_sysfs_int(sys_pfx, postfix, "latency_min");
	latency_max = read_sysfs_int(sys_pfx, postfix, "latency_max");
	latency_avg = read_sysfs_float(sys_pfx, postfix, "latency_avg");
	throughput_min = read_sysfs_int(sys_pfx, postfix, "throughput_min");
	throughput_max = read_sysfs_int(sys_pfx, postfix, "throughput_max");
	throughput_avg = read_sysfs_float(sys_pfx, postfix, "throughput_avg");

	/* derive jitter */
	request_jitter = request_max - request_min;
	latency_jitter = latency_max - latency_min;
	throughput_jitter = throughput_max - throughput_min;

	/* append calculated metrics to file */
	memset(buf, 0x00, sizeof(buf));
	len = snprintf(buf, sizeof(buf), "%u-%u-%u %u:%u:%u,",
		       tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
		       tm->tm_hour, tm->tm_min, tm->tm_sec);
	len += snprintf(&buf[len], sizeof(buf) - len,
			"%s,%s,%u,%u,%u,%u,%u,%f,%u,%u,%u,%f,%u,%u,%u,%f,%u",
			test_name, sys_pfx, size, iteration_max, error,
			request_min, request_max, request_avg, request_jitter,
			latency_min, latency_max, latency_avg, latency_jitter,
			throughput_min, throughput_max, throughput_avg,
			throughput_jitter);
	write(fd, buf, len);

	/* print basic metrics to stdout - requested feature add */
	printf("\n%s\n", buf);

	/* Write raw latency times to CSV  */
	for (i = 0; i < iteration_max; i++) {
		memset(&rx_buf, 0x00, sizeof(rx_buf));
		len = read(fd_dev, rx_buf, sizeof(rx_buf));
		if (len < 0) {
			fprintf(stderr, "error reading %s %s\n",
				dbgfs_entry, strerror(errno));
			break;
		}
		lseek(fd_dev, SEEK_SET, 0);
		len = snprintf(buf, sizeof(buf), ",%s", rx_buf);
		if (write(fd, buf, len) != len) {
			log_csv_error(0, errno);
			break;
		}
	}
	if (write(fd, "\n", 1) < 1)
		log_csv_error(1, errno);

	/* skip printing large set to stdout just close open handles */
	close(fd_dev);

}
コード例 #8
0
int read_acpi_state_sysfs(int battery)
{
	DIR *sysfs;
	struct dirent *propety;
	char *name;

	sysfs = opendir(batteries[battery]);
	if (sysfs == 0)
	{
	#ifdef DEBUG
	  printf("DBG:Can't open %s!\n", batteries[battery]);
	#endif
	return 0;
	}
  
	/* again it might be better to use calloc 
	if (!acpistate) acpistate=(ACPIstate *)malloc(sizeof(ACPIstate));
	*/
	if (!acpistate) acpistate=(ACPIstate *)calloc(1, sizeof(ACPIstate));

	while ((propety = readdir(sysfs)))
	{
		name = propety->d_name;
		if (!strncmp(".", name, 1) || !strncmp("..", name, 2)) continue;
		
		if (strcmp(name,"status") == 0)
		{
			char *tmp;
			sprintf(buf,"%s/%s",batteries[battery], name);
			tmp = read_sysfs_string(buf);
			if ( tmp != NULL )
			{
				if (strcmp(tmp,"Charging") == 0)
					acpistate->state = CHARGING;
				else if (strcmp(tmp,"Discharging") == 0)
					acpistate->state = DISCHARGING;
				else if (strcmp(tmp,"Full") == 0)
					acpistate->state = POWER;
				else
					acpistate->state = UNKNOW;
			}
		}
		/* on my system this is called charge_now */
		if ((strcmp(name,"energy_now") == 0) || (strcmp(name,"charge_now") == 0))
		{
			sprintf(buf,"%s/%s",batteries[battery], name);
			acpistate->rcapacity = read_sysfs_int(buf);
			acpistate->percentage = (((float) acpistate->rcapacity)/acpiinfo->last_full_capacity) * 100;
		}
		if ((strcmp(name,"current_now") == 0) || (strcmp(name,"power_now") == 0))
		{
			sprintf(buf,"%s/%s",batteries[battery], name);
			acpistate->prate = read_sysfs_int(buf);
			if ( acpistate->prate < 0 )
				acpistate->prate = 0;
			if ( acpistate->prate > 0 )
				acpistate->rtime = (((float) acpistate->rcapacity) / acpistate->prate) * 60;
		}
		if (strcmp(name,"voltage_now") == 0)
		{
			sprintf(buf,"%s/%s",batteries[battery], name);
			acpistate->pvoltage = read_sysfs_int(buf);
		}
	}
	closedir(sysfs);
	return acpiinfo->present;
}
コード例 #9
0
int DmpFWloaded()
{
    int res;
    read_sysfs_int(mpu.firmware_loaded, &res);
    return res;
}
コード例 #10
0
static int get_results(struct loopback_test *t)
{
	struct loopback_device *d;
	struct loopback_results *r;
	int i;

	for (i = 0; i < t->device_count; i++) {
		if (!device_enabled(t, i))
			continue;

		d = &t->devices[i];
		r = &d->results;

		r->error = read_sysfs_int(d->sysfs_entry, "error");
		r->request_min = read_sysfs_int(d->sysfs_entry, "requests_per_second_min");
		r->request_max = read_sysfs_int(d->sysfs_entry, "requests_per_second_max");
		r->request_avg = read_sysfs_float(d->sysfs_entry, "requests_per_second_avg");

		r->latency_min = read_sysfs_int(d->sysfs_entry, "latency_min");
		r->latency_max = read_sysfs_int(d->sysfs_entry, "latency_max");
		r->latency_avg = read_sysfs_float(d->sysfs_entry, "latency_avg");

		r->throughput_min = read_sysfs_int(d->sysfs_entry, "throughput_min");
		r->throughput_max = read_sysfs_int(d->sysfs_entry, "throughput_max");
		r->throughput_avg = read_sysfs_float(d->sysfs_entry, "throughput_avg");

		r->apbridge_unipro_latency_min =
			read_sysfs_int(d->sysfs_entry, "apbridge_unipro_latency_min");
		r->apbridge_unipro_latency_max =
			read_sysfs_int(d->sysfs_entry, "apbridge_unipro_latency_max");
		r->apbridge_unipro_latency_avg =
			read_sysfs_float(d->sysfs_entry, "apbridge_unipro_latency_avg");

		r->gbphy_firmware_latency_min =
			read_sysfs_int(d->sysfs_entry, "gbphy_firmware_latency_min");
		r->gbphy_firmware_latency_max =
			read_sysfs_int(d->sysfs_entry, "gbphy_firmware_latency_max");
		r->gbphy_firmware_latency_avg =
			read_sysfs_float(d->sysfs_entry, "gbphy_firmware_latency_avg");

		r->request_jitter = r->request_max - r->request_min;
		r->latency_jitter = r->latency_max - r->latency_min;
		r->throughput_jitter = r->throughput_max - r->throughput_min;
		r->apbridge_unipro_latency_jitter =
			r->apbridge_unipro_latency_max - r->apbridge_unipro_latency_min;
		r->gbphy_firmware_latency_jitter =
			r->gbphy_firmware_latency_max - r->gbphy_firmware_latency_min;

	}

	/*calculate the aggregate results of all enabled devices */
	if (t->aggregate_output) {
		r = &t->aggregate_results;

		r->request_min = get_request_min_aggregate(t);
		r->request_max = get_request_max_aggregate(t);
		r->request_avg = get_request_avg_aggregate(t);

		r->latency_min = get_latency_min_aggregate(t);
		r->latency_max = get_latency_max_aggregate(t);
		r->latency_avg = get_latency_avg_aggregate(t);

		r->throughput_min = get_throughput_min_aggregate(t);
		r->throughput_max = get_throughput_max_aggregate(t);
		r->throughput_avg = get_throughput_avg_aggregate(t);

		r->apbridge_unipro_latency_min =
			get_apbridge_unipro_latency_min_aggregate(t);
		r->apbridge_unipro_latency_max =
			get_apbridge_unipro_latency_max_aggregate(t);
		r->apbridge_unipro_latency_avg =
			get_apbridge_unipro_latency_avg_aggregate(t);

		r->gbphy_firmware_latency_min =
			get_gbphy_firmware_latency_min_aggregate(t);
		r->gbphy_firmware_latency_max =
			get_gbphy_firmware_latency_max_aggregate(t);
		r->gbphy_firmware_latency_avg =
			get_gbphy_firmware_latency_avg_aggregate(t);

		r->request_jitter = r->request_max - r->request_min;
		r->latency_jitter = r->latency_max - r->latency_min;
		r->throughput_jitter = r->throughput_max - r->throughput_min;
		r->apbridge_unipro_latency_jitter =
			r->apbridge_unipro_latency_max - r->apbridge_unipro_latency_min;
		r->gbphy_firmware_latency_jitter =
			r->gbphy_firmware_latency_max - r->gbphy_firmware_latency_min;

	}

	return 0;
}