int main()
{
	printf("Expected result: Program should print \"deadlock prevented!\" and exit.\n");
	printf("... valgrind won't run clean if exit() is called without calls to _destroy(). This is fine.\n");
	printf("... this program should print right away and exit. If it takes longer than a second, it likely deadlocked.\n");

	drm_setmode(DEADLOCK_PREVENTION);

	drm_init(&m1);
	drm_init(&m2);

	pthread_t t1, t2;
	pthread_create(&t1, NULL, count_up, NULL);
	pthread_create(&t2, NULL, count_down, NULL);

	pthread_join(t1, NULL);
	pthread_join(t2, NULL);

	drm_destroy(&m1);
	drm_destroy(&m2);
	drm_cleanup();

	printf("%d\n", x);
	return 0;
}
Example #2
0
int main()
{
	printf("Expected result: Program should print \"Deadlock detected! Edges: 1 -> 2, 2 -> 1\", where 1 and 2 will be specific thread_ids.\n");
	printf("... after that, the program should output a non-zero number (usually a number close to 100000 or -100000).\n");
	printf("... as you run your program multiple times, the number should vary between positive and negative.\n");
	printf("    ...remember, the thread you send the signal to should be random, so you will be switching between killing the\n");
	printf("       count_up() and the count_down() threads.\n");
	printf("\n");
	printf("... this program should exit within a second or two and exit. If it takes longer than 5 seconds, it likely deadlocked.\n");
	printf("... due to how valgrind handles signals, the tester may not work under valgrind.\n");
	printf("\n");

	drm_setmode(DEADLOCK_DETECTION);

	drm_init(&m1);
	drm_init(&m2);

	pthread_t t1, t2;
	pthread_create(&t1, NULL, count_up, NULL);
	pthread_create(&t2, NULL, count_down, NULL);

	pthread_join(t1, NULL);
	pthread_join(t2, NULL);

	drm_destroy(&m1);
	drm_destroy(&m2);
	drm_cleanup();

	printf("%d\n", x);
	return 0;

}
Example #3
0
File: drm.c Project: tizbac/Mesa-3D
static HRESULT WINAPI
drm_create_adapter( int fd,
                    ID3DAdapter9 **ppAdapter )
{
    struct d3dadapter9drm_context *ctx = CALLOC_STRUCT(d3dadapter9drm_context);
    HRESULT hr;
    int i, different_device;
    const struct drm_conf_ret *throttle_ret = NULL;
    const struct drm_conf_ret *dmabuf_ret = NULL;
    driOptionCache defaultInitOptions;
    driOptionCache userInitOptions;
    int throttling_value_user = -2;

#if !GALLIUM_STATIC_TARGETS
    const char *paths[] = {
        getenv("D3D9_DRIVERS_PATH"),
        getenv("D3D9_DRIVERS_DIR"),
        PIPE_SEARCH_DIR
    };
#endif

    if (!ctx) { return E_OUTOFMEMORY; }

    ctx->base.destroy = drm_destroy;

    fd = loader_get_user_preferred_fd(fd, &different_device);
    ctx->fd = fd;
    ctx->base.linear_framebuffer = !!different_device;

#if GALLIUM_STATIC_TARGETS
    ctx->base.hal = dd_create_screen(fd);
#else
    /* use pipe-loader to dlopen appropriate drm driver */
    if (!pipe_loader_drm_probe_fd(&ctx->dev, fd, FALSE)) {
        ERR("Failed to probe drm fd %d.\n", fd);
        FREE(ctx);
        close(fd);
        return D3DERR_DRIVERINTERNALERROR;
    }

    /* use pipe-loader to create a drm screen (hal) */
    ctx->base.hal = NULL;
    for (i = 0; !ctx->base.hal && i < Elements(paths); ++i) {
        if (!paths[i]) { continue; }
        ctx->base.hal = pipe_loader_create_screen(ctx->dev, paths[i]);
    }
#endif
    if (!ctx->base.hal) {
        ERR("Unable to load requested driver.\n");
        drm_destroy(&ctx->base);
        return D3DERR_DRIVERINTERNALERROR;
    }

#if GALLIUM_STATIC_TARGETS
    dmabuf_ret = dd_configuration(DRM_CONF_SHARE_FD);
    throttle_ret = dd_configuration(DRM_CONF_THROTTLE);
#else
    dmabuf_ret = pipe_loader_configuration(ctx->dev, DRM_CONF_SHARE_FD);
    throttle_ret = pipe_loader_configuration(ctx->dev, DRM_CONF_THROTTLE);
#endif // GALLIUM_STATIC_TARGETS
    if (!dmabuf_ret || !dmabuf_ret->val.val_bool) {
        ERR("The driver is not capable of dma-buf sharing."
            "Abandon to load nine state tracker\n");
        drm_destroy(&ctx->base);
        return D3DERR_DRIVERINTERNALERROR;
    }

    if (throttle_ret && throttle_ret->val.val_int != -1) {
        ctx->base.throttling = TRUE;
        ctx->base.throttling_value = throttle_ret->val.val_int;
    } else
        ctx->base.throttling = FALSE;

    driParseOptionInfo(&defaultInitOptions, __driConfigOptionsNine);
    driParseConfigFiles(&userInitOptions, &defaultInitOptions, 0, "nine");
    if (driCheckOption(&userInitOptions, "throttle_value", DRI_INT)) {
        throttling_value_user = driQueryOptioni(&userInitOptions, "throttle_value");
        if (throttling_value_user == -1)
            ctx->base.throttling = FALSE;
        else if (throttling_value_user >= 0) {
            ctx->base.throttling = TRUE;
            ctx->base.throttling_value = throttling_value_user;
        }
    }

    if (driCheckOption(&userInitOptions, "vblank_mode", DRI_ENUM))
        ctx->base.vblank_mode = driQueryOptioni(&userInitOptions, "vblank_mode");
    else
        ctx->base.vblank_mode = 1;

    if (driCheckOption(&userInitOptions, "thread_submit", DRI_BOOL)) {
        ctx->base.thread_submit = driQueryOptionb(&userInitOptions, "thread_submit");
        if (ctx->base.thread_submit && (throttling_value_user == -2 || throttling_value_user == 0)) {
            ctx->base.throttling_value = 0;
        } else if (ctx->base.thread_submit) {
            DBG("You have set a non standard throttling value in combination with thread_submit."
                "We advise to use a throttling value of -2/0");
        }
        if (ctx->base.thread_submit && !different_device)
            DBG("You have set thread_submit but do not use a different device than the server."
                "You should not expect any benefit.");
    }

    driDestroyOptionCache(&userInitOptions);
    driDestroyOptionInfo(&defaultInitOptions);

#if GALLIUM_STATIC_TARGETS
    ctx->base.ref = ninesw_create_screen(ctx->base.hal);
#else
    /* wrap it to create a software screen that can share resources */
    if (pipe_loader_sw_probe_wrapped(&ctx->swdev, ctx->base.hal)) {
        ctx->base.ref = NULL;
        for (i = 0; !ctx->base.ref && i < Elements(paths); ++i) {
            if (!paths[i]) { continue; }
            ctx->base.ref = pipe_loader_create_screen(ctx->swdev, paths[i]);
        }
    }
#endif
    if (!ctx->base.ref) {
        ERR("Couldn't wrap drm screen to swrast screen. Software devices "
            "will be unavailable.\n");
    }

    /* read out PCI info */
    read_descriptor(&ctx->base, fd);

    /* create and return new ID3DAdapter9 */
    hr = NineAdapter9_new(&ctx->base, (struct NineAdapter9 **)ppAdapter);
    if (FAILED(hr)) {
        drm_destroy(&ctx->base);
        return hr;
    }

    return D3D_OK;
}
Example #4
0
File: drm.c Project: iXit/Mesa-3D
static HRESULT WINAPI
drm_create_adapter( int fd,
                    ID3DAdapter9 **ppAdapter )
{
    struct d3dadapter9drm_context *ctx = CALLOC_STRUCT(d3dadapter9drm_context);
    HRESULT hr;
    bool different_device;
    driOptionCache defaultInitOptions;
    driOptionCache userInitOptions;
    int throttling_value_user = -2;
    int override_vendorid = -1;

    if (!ctx) { return E_OUTOFMEMORY; }

    ctx->base.destroy = drm_destroy;

    /* Although the fd is provided from external source, mesa/nine
     * takes ownership of it. */
    fd = loader_get_user_preferred_fd(fd, &different_device);
    ctx->fd = fd;
    ctx->base.linear_framebuffer = different_device;

    if (!pipe_loader_drm_probe_fd(&ctx->dev, fd)) {
        ERR("Failed to probe drm fd %d.\n", fd);
        FREE(ctx);
        close(fd);
        return D3DERR_DRIVERINTERNALERROR;
    }

    ctx->base.hal = pipe_loader_create_screen(ctx->dev);
    if (!ctx->base.hal) {
        ERR("Unable to load requested driver.\n");
        drm_destroy(&ctx->base);
        return D3DERR_DRIVERINTERNALERROR;
    }

    if (!ctx->base.hal->get_param(ctx->base.hal, PIPE_CAP_DMABUF)) {
        ERR("The driver is not capable of dma-buf sharing."
            "Abandon to load nine state tracker\n");
        drm_destroy(&ctx->base);
        return D3DERR_DRIVERINTERNALERROR;
    }

    /* Previously was set to PIPE_CAP_MAX_FRAMES_IN_FLIGHT,
     * but the change of value of this cap to 1 seems to cause
     * regressions. */
    ctx->base.throttling_value = 2;
    ctx->base.throttling = ctx->base.throttling_value > 0;

    driParseOptionInfo(&defaultInitOptions, __driConfigOptionsNine);
    driParseConfigFiles(&userInitOptions, &defaultInitOptions, 0, "nine", NULL);
    if (driCheckOption(&userInitOptions, "throttle_value", DRI_INT)) {
        throttling_value_user = driQueryOptioni(&userInitOptions, "throttle_value");
        if (throttling_value_user == -1)
            ctx->base.throttling = FALSE;
        else if (throttling_value_user >= 0) {
            ctx->base.throttling = TRUE;
            ctx->base.throttling_value = throttling_value_user;
        }
    }

    if (driCheckOption(&userInitOptions, "vblank_mode", DRI_ENUM))
        ctx->base.vblank_mode = driQueryOptioni(&userInitOptions, "vblank_mode");
    else
        ctx->base.vblank_mode = 1;

    if (driCheckOption(&userInitOptions, "thread_submit", DRI_BOOL))
        ctx->base.thread_submit = driQueryOptionb(&userInitOptions, "thread_submit");
    else
        ctx->base.thread_submit = different_device;

    if (driCheckOption(&userInitOptions, "override_vendorid", DRI_INT)) {
        override_vendorid = driQueryOptioni(&userInitOptions, "override_vendorid");
    }

    if (driCheckOption(&userInitOptions, "discard_delayed_release", DRI_BOOL))
        ctx->base.discard_delayed_release = driQueryOptionb(&userInitOptions, "discard_delayed_release");
    else
        ctx->base.discard_delayed_release = TRUE;

    if (driCheckOption(&userInitOptions, "tearfree_discard", DRI_BOOL))
        ctx->base.tearfree_discard = driQueryOptionb(&userInitOptions, "tearfree_discard");
    else
        ctx->base.tearfree_discard = FALSE;

    if (ctx->base.tearfree_discard && !ctx->base.discard_delayed_release) {
        ERR("tearfree_discard requires discard_delayed_release\n");
        ctx->base.tearfree_discard = FALSE;
    }

    if (driCheckOption(&userInitOptions, "csmt_force", DRI_INT))
        ctx->base.csmt_force = driQueryOptioni(&userInitOptions, "csmt_force");
    else
        ctx->base.csmt_force = -1;

    if (driCheckOption(&userInitOptions, "dynamic_texture_workaround", DRI_BOOL))
        ctx->base.dynamic_texture_workaround = driQueryOptionb(&userInitOptions, "dynamic_texture_workaround");
    else
        ctx->base.dynamic_texture_workaround = FALSE;

    if (driCheckOption(&userInitOptions, "shader_inline_constants", DRI_BOOL))
        ctx->base.shader_inline_constants = driQueryOptionb(&userInitOptions, "shader_inline_constants");
    else
        ctx->base.shader_inline_constants = FALSE;

    driDestroyOptionCache(&userInitOptions);
    driDestroyOptionInfo(&defaultInitOptions);

    /* wrap it to create a software screen that can share resources */
    if (pipe_loader_sw_probe_wrapped(&ctx->swdev, ctx->base.hal))
        ctx->base.ref = pipe_loader_create_screen(ctx->swdev);

    if (!ctx->base.ref) {
        ERR("Couldn't wrap drm screen to swrast screen. Software devices "
            "will be unavailable.\n");
    }

    /* read out PCI info */
    read_descriptor(&ctx->base, fd, override_vendorid);

    /* create and return new ID3DAdapter9 */
    hr = NineAdapter9_new(&ctx->base, (struct NineAdapter9 **)ppAdapter);
    if (FAILED(hr)) {
        drm_destroy(&ctx->base);
        return hr;
    }

    return D3D_OK;
}