Exemple #1
0
bool zmq::connect_session_t::attached (const blob_t &peer_identity_)
{
    //  If there was no previous connection...
    if (!connected) {

        //  Peer has transient identity.
        if (peer_identity_.empty () || peer_identity_ [0] == 0) {
            connected = true;
            return true;
        }

        //  Peer has strong identity. Let's register it and check whether noone
        //  else is using the same identity.
        if (!register_session (peer_identity_, this)) {
            log ("DPID: duplicate peer identity - disconnecting peer");
            return false;
        }
        connected = true;
        peer_identity = peer_identity_;
        return true;
    }

    //  New engine from listener can conflict with existing engine.
    //  Alternatively, new engine created by reconnection process can
    //  conflict with engine supplied by listener in the meantime.
    if (has_engine ()) {
        log ("DPID: duplicate peer identity - disconnecting peer");
        return false;
    }

    //  If there have been a connection before, we have to check whether
    //  peer's identity haven't changed in the meantime.
    if ((peer_identity_.empty () || peer_identity_ [0] == 0) &&
          peer_identity.empty ())
        return true;
    if (peer_identity != peer_identity_) {
        log ("CHID: peer have changed identity - disconnecting peer");
        return false;
    }
    return true;
}
static void processes(void)
{
	const struct intel_execution_engine *e;
	unsigned engines[16];
	int num_engines;
	struct rlimit rlim;
	unsigned num_ctx;
	uint32_t name;
	int fd, *fds;

	fd = drm_open_driver(DRIVER_INTEL);
	num_ctx = get_num_contexts(fd);

	num_engines = 0;
	for (e = intel_execution_engines; e->name; e++) {
		if (e->exec_id == 0)
			continue;

		if (!has_engine(fd, e))
			continue;

		if (e->exec_id == I915_EXEC_BSD) {
			int is_bsd2 = e->flags != 0;
			if (gem_has_bsd2(fd) != is_bsd2)
				continue;
		}

		engines[num_engines++] = e->exec_id | e->flags;
		if (num_engines == ARRAY_SIZE(engines))
			break;
	}

	/* tweak rlimits to allow us to create this many files */
	igt_assert(getrlimit(RLIMIT_NOFILE, &rlim) == 0);
	if (rlim.rlim_cur < ALIGN(num_ctx + 1024, 1024)) {
		rlim.rlim_cur = ALIGN(num_ctx + 1024, 1024);
		if (rlim.rlim_cur > rlim.rlim_max)
			rlim.rlim_max = rlim.rlim_cur;
		igt_assert(setrlimit(RLIMIT_NOFILE, &rlim) == 0);
	}

	fds = malloc(num_ctx * sizeof(int));
	igt_assert(fds);
	for (unsigned n = 0; n < num_ctx; n++) {
		fds[n] = drm_open_driver(DRIVER_INTEL);
		if (fds[n] == -1) {
			int err = errno;
			for (unsigned i = n; i--; )
				close(fds[i]);
			free(fds);
			errno = err;
			igt_assert_f(0, "failed to create context %lld/%lld\n", (long long)n, (long long)num_ctx);
		}
	}

	if (1) {
		uint32_t bbe = MI_BATCH_BUFFER_END;
		name = gem_create(fd, 4096);
		gem_write(fd, name, 0, &bbe, sizeof(bbe));
		name = gem_flink(fd, name);
	}

	igt_fork(child, NUM_THREADS) {
		struct drm_i915_gem_execbuffer2 execbuf;
		struct drm_i915_gem_exec_object2 obj;

		memset(&obj, 0, sizeof(obj));
		memset(&execbuf, 0, sizeof(execbuf));
		execbuf.buffers_ptr = (uintptr_t)&obj;
		execbuf.buffer_count = 1;

		igt_permute_array(fds, num_ctx, xchg_int);
		for (unsigned n = 0; n < num_ctx; n++) {
			obj.handle = gem_open(fds[n], name);
			execbuf.flags = engines[n % num_engines];
			gem_execbuf(fds[n], &execbuf);
			gem_close(fds[n], obj.handle);
		}
	}
	igt_waitchildren();

	for (unsigned n = 0; n < num_ctx; n++)
		close(fds[n]);
	free(fds);
	close(fd);
}