static void read_rc6_residency( int value[], const char *name_of_rc6_residency)
{
	unsigned int i;
	const int device = drm_get_card();
	char *path ;
	int  ret;
	FILE *file;

	/* For some reason my ivb isn't idle even after syncing up with the gpu.
	 * Let's add a sleept just to make it happy. */
	sleep(5);

	ret = asprintf(&path, "/sys/class/drm/card%d/power/rc6_enable", device);
	igt_assert_neq(ret, -1);

	file = fopen(path, "r");
	igt_require(file);

	/* claim success if no rc6 enabled. */
	if (readit(path) == 0)
		igt_success();

	for(i = 0; i < 2; i++)
	{
		sleep(SLEEP_DURATION / 1000);
		ret = asprintf(&path, "/sys/class/drm/card%d/power/%s_residency_ms",device,name_of_rc6_residency);
		igt_assert_neq(ret, -1);
		value[i] = readit(path);
	}
	free(path);
}
int main(int argc, char *argv[])
{
	const int device = drm_get_card(0);
	char *path, *pathp, *pathpp;
	int fd, ret;
	unsigned int value1, value1p, value1pp, value2, value2p, value2pp;
	FILE *file;
	int diff;

	/* Use drm_open_any to verify device existence */
	fd = drm_open_any();
	close(fd);

	ret = asprintf(&path, "/sys/class/drm/card%d/power/rc6_enable", device);
	assert(ret != -1);

	/* For some reason my ivb isn't idle even after syncing up with the gpu.
	 * Let's add a sleept just to make it happy. */
	sleep(5);

	file = fopen(path, "r");
	if (!file) {
		printf("kernel too old or rc6 not supported on this platform.\n");
		exit(77);
	}

	/* claim success if no rc6 enabled. */
	if (readit(path) == 0)
		exit(EXIT_SUCCESS);

	ret = asprintf(&path, "/sys/class/drm/card%d/power/rc6_residency_ms", device);
	assert(ret != -1);
	ret = asprintf(&pathp, "/sys/class/drm/card%d/power/rc6p_residency_ms", device);
	assert(ret != -1);
	ret = asprintf(&pathpp, "/sys/class/drm/card%d/power/rc6pp_residency_ms", device);
	assert(ret != -1);

	value1 = readit(path);
	value1p = readit(pathp);
	value1pp = readit(pathpp);
	sleep(SLEEP_DURATION / 1000);
	value2 = readit(path);
	value2p = readit(pathp);
	value2pp = readit(pathpp);

	free(pathpp);
	free(pathp);
	free(path);

	diff = (value2pp - value1pp) +
		(value2p - value1p) +
		(value2 - value1);

	if (diff > (SLEEP_DURATION + RC6_FUDGE)) {
		fprintf(stderr, "Diff was too high. That is unpossible\n");
		exit(EXIT_FAILURE);
	}
	if (diff < (SLEEP_DURATION - RC6_FUDGE)) {
		fprintf(stderr, "GPU was not in RC6 long enough. Check that "
				"the GPU is as idle as possible (ie. no X, "
				"running and running no other tests)\n");
		exit(EXIT_FAILURE);
	}

	exit(EXIT_SUCCESS);
}