Ejemplo n.º 1
0
/**
 * intel_register_access_init:
 * @pci_dev: intel graphics pci device
 * @safe: use safe register access tables
 *
 * This initializes the new register access library, which supports forcewake
 * handling and also allows register access to be checked with an explicit
 * whitelist.
 *
 * It also initializes #igt_global_mmio like intel_mmio_use_pci_bar().
 *
 * @pci_dev can be obtained from intel_get_pci_device().
 */
int
intel_register_access_init(struct pci_device *pci_dev, int safe)
{
	int ret;

	/* after old API is deprecated, remove this */
	if (igt_global_mmio == NULL)
		intel_mmio_use_pci_bar(pci_dev);

	igt_assert(igt_global_mmio != NULL);

	if (mmio_data.inited)
		return -1;

	mmio_data.safe = (safe != 0 &&
			intel_gen(pci_dev->device_id) >= 4) ? true : false;
	mmio_data.i915_devid = pci_dev->device_id;
	if (mmio_data.safe)
		mmio_data.map = intel_get_register_map(mmio_data.i915_devid);

	/* Find where the forcewake lock is. Forcewake doesn't exist
	 * gen < 6, but the debugfs should do the right things for us.
	 */
	ret = igt_open_forcewake_handle();
	if (ret == -1)
		mmio_data.key = FAKEKEY;
	else
		mmio_data.key = ret;

	mmio_data.inited++;
	return 0;
}
Ejemplo n.º 2
0
int main(int argc, char **argv)
{
    pid_t child;
    uint64_t ring_idle = 0, ring_time = 0;
    struct timeval start, end;
    static struct rusage rusage;
    int status;

    intel_mmio_use_pci_bar(intel_get_pci_device());

    if (argc == 1) {
        fprintf(stderr, "usage: %s cmd [args...]\n", argv[0]);
        return 1;
    }

    signal(SIGCHLD, sighandler);
    signal(SIGINT, SIG_IGN);
    signal(SIGQUIT, SIG_IGN);

    gettimeofday(&start, NULL);
    child = spawn(argv+1);
    if (child < 0)
        return 127;

    while (!goddo) {
        uint32_t ring_head, ring_tail;

        ring_head = INREG(LP_RING + RING_HEAD) & HEAD_ADDR;
        ring_tail = INREG(LP_RING + RING_TAIL) & TAIL_ADDR;

        if (ring_tail == ring_head)
            ring_idle++;
        ring_time++;

        usleep(1000000 / SAMPLES_PER_SEC);
    }
    gettimeofday(&end, NULL);
    timersub(&end, &start, &end);

    waitpid(child, &status, 0);

    getrusage(RUSAGE_CHILDREN, &rusage);
    printf("user: %ld.%06lds, sys: %ld.%06lds, elapsed: %ld.%06lds, CPU: %.1f%%, GPU: %.1f%%\n",
           rusage.ru_utime.tv_sec, rusage.ru_utime.tv_usec,
           rusage.ru_stime.tv_sec, rusage.ru_stime.tv_usec,
           end.tv_sec, end.tv_usec,
           100*(rusage.ru_utime.tv_sec + 1e-6*rusage.ru_utime.tv_usec + rusage.ru_stime.tv_sec + 1e-6*rusage.ru_stime.tv_usec) / (end.tv_sec + 1e-6*end.tv_usec),
           100 - ring_idle * 100. / ring_time);

    return WEXITSTATUS(status);
}