Skip to content

Commit

Permalink
Replace deprecated timeout code with callout.
Browse files Browse the repository at this point in the history
  • Loading branch information
johalun committed Dec 14, 2019
1 parent 843ded0 commit b17900b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions drivers/gpu/drm/drm_os_freebsd.c
Expand Up @@ -32,7 +32,7 @@ int drm_always_interruptible;
SYSCTL_INT(_dev_drm, OID_AUTO, always_interruptible, CTLFLAG_RWTUN, &drm_always_interruptible, 0, "always allow a thread to be interrupted in driver wait");

static atomic_t reset_debug_log_armed = ATOMIC_INIT(0);
static struct callout_handle reset_debug_log_handle;
static struct callout reset_debug_log_handle;

static void
clear_debug_func(void *arg __unused)
Expand All @@ -44,7 +44,7 @@ void
cancel_reset_debug_log(void)
{
if (atomic_read(&reset_debug_log_armed))
untimeout(clear_debug_func, NULL, reset_debug_log_handle);
callout_stop(&reset_debug_log_handle);
}

static void
Expand All @@ -54,8 +54,7 @@ reset_debug_log(void)
return;

if (atomic_add_unless(&reset_debug_log_armed, 1, 1)) {
reset_debug_log_handle = timeout(clear_debug_func, NULL,
10*hz);
callout_reset(&reset_debug_log_handle, 10*hz, clear_debug_func, NULL);
}
}

Expand Down Expand Up @@ -315,6 +314,7 @@ drm_modevent(module_t mod, int type, void *data)
switch (type) {
case MOD_LOAD:
TUNABLE_INT_FETCH("drm.debug", &drm_debug);
callout_init(&reset_debug_log_handle, 1);
break;
}
return (0);
Expand Down

2 comments on commit b17900b

@bsdjhb
Copy link

@bsdjhb bsdjhb commented on b17900b Dec 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You want a callout_drain in MOD_UNLOAD to ensure the callout is not pending or racing with the unload.

I think the reset_debug_log_armed variable probably shouldn't exist with how callouts work in FreeBSD. Instead, you should probably just always call callout_stop() in cancel_reset_debug_log() (it's safe to call callout_stop() on a callout that isn't active). The callout_reset can also probably be unconditional, or at least you can have it do something like:

    if (!callout_pending())
        callout_reset();

I doubt that the race of duplicate scheduling of the callout matters for a debug log facility.

@johalun
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Thanks for the help!

Please sign in to comment.