Module Name: src Committed By: riastradh Date: Sun Dec 19 11:55:47 UTC 2021
Modified Files: src/sys/external/bsd/drm2/dist/drm: drm_vblank.c src/sys/external/bsd/drm2/dist/drm/amd/amdgpu: amdgpu_fence.c src/sys/external/bsd/drm2/dist/drm/i915: intel_uncore.c src/sys/external/bsd/drm2/include/linux: hrtimer.h timer.h src/sys/external/bsd/drm2/linux: linux_hrtimer.c Log Message: drm: Eliminate hrtimer_destroy and teardown_timer. These are non-Linux shims added to the Linux API to pair with hrtimer_setup and setup_timer, but they really only serve to call callout_destroy, which is not strictly necessary in the NetBSD API. So although we lose a little bit of diagnostic help this way, we also reduce diffs a bit and save some trouble that bit us last week. To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/sys/external/bsd/drm2/dist/drm/drm_vblank.c cvs rdiff -u -r1.8 -r1.9 \ src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_fence.c cvs rdiff -u -r1.18 -r1.19 \ src/sys/external/bsd/drm2/dist/drm/i915/intel_uncore.c cvs rdiff -u -r1.6 -r1.7 src/sys/external/bsd/drm2/include/linux/hrtimer.h cvs rdiff -u -r1.13 -r1.14 src/sys/external/bsd/drm2/include/linux/timer.h cvs rdiff -u -r1.2 -r1.3 src/sys/external/bsd/drm2/linux/linux_hrtimer.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/external/bsd/drm2/dist/drm/drm_vblank.c diff -u src/sys/external/bsd/drm2/dist/drm/drm_vblank.c:1.10 src/sys/external/bsd/drm2/dist/drm/drm_vblank.c:1.11 --- src/sys/external/bsd/drm2/dist/drm/drm_vblank.c:1.10 Sun Dec 19 11:52:25 2021 +++ src/sys/external/bsd/drm2/dist/drm/drm_vblank.c Sun Dec 19 11:55:47 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: drm_vblank.c,v 1.10 2021/12/19 11:52:25 riastradh Exp $ */ +/* $NetBSD: drm_vblank.c,v 1.11 2021/12/19 11:55:47 riastradh Exp $ */ /* * drm_irq.c IRQ and vblank support @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: drm_vblank.c,v 1.10 2021/12/19 11:52:25 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: drm_vblank.c,v 1.11 2021/12/19 11:55:47 riastradh Exp $"); #include <linux/export.h> #include <linux/moduleparam.h> @@ -463,7 +463,6 @@ void drm_vblank_cleanup(struct drm_devic drm_core_check_feature(dev, DRIVER_MODESET)); del_timer_sync(&vblank->disable_timer); - teardown_timer(&vblank->disable_timer); seqlock_destroy(&vblank->seqlock); } Index: src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_fence.c diff -u src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_fence.c:1.8 src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_fence.c:1.9 --- src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_fence.c:1.8 Sun Dec 19 09:59:30 2021 +++ src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_fence.c Sun Dec 19 11:55:47 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: amdgpu_fence.c,v 1.8 2021/12/19 09:59:30 riastradh Exp $ */ +/* $NetBSD: amdgpu_fence.c,v 1.9 2021/12/19 11:55:47 riastradh Exp $ */ /* * Copyright 2009 Jerome Glisse. @@ -31,7 +31,7 @@ * Dave Airlie */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: amdgpu_fence.c,v 1.8 2021/12/19 09:59:30 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: amdgpu_fence.c,v 1.9 2021/12/19 11:55:47 riastradh Exp $"); #include <linux/seq_file.h> #include <linux/atomic.h> @@ -549,7 +549,6 @@ void amdgpu_fence_driver_fini(struct amd ring->fence_drv.fences = NULL; ring->fence_drv.initialized = false; spin_lock_destroy(&ring->fence_drv.lock); - timer_teardown(&ring->fence_drv.fallback_timer); } } Index: src/sys/external/bsd/drm2/dist/drm/i915/intel_uncore.c diff -u src/sys/external/bsd/drm2/dist/drm/i915/intel_uncore.c:1.18 src/sys/external/bsd/drm2/dist/drm/i915/intel_uncore.c:1.19 --- src/sys/external/bsd/drm2/dist/drm/i915/intel_uncore.c:1.18 Sun Dec 19 11:53:18 2021 +++ src/sys/external/bsd/drm2/dist/drm/i915/intel_uncore.c Sun Dec 19 11:55:47 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: intel_uncore.c,v 1.18 2021/12/19 11:53:18 riastradh Exp $ */ +/* $NetBSD: intel_uncore.c,v 1.19 2021/12/19 11:55:47 riastradh Exp $ */ /* * Copyright © 2013 Intel Corporation @@ -24,7 +24,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: intel_uncore.c,v 1.18 2021/12/19 11:53:18 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: intel_uncore.c,v 1.19 2021/12/19 11:55:47 riastradh Exp $"); #include <linux/pm_runtime.h> #include <asm/iosf_mbi.h> @@ -1519,7 +1519,6 @@ static void fw_domain_fini(struct intel_ uncore->fw_domains &= ~BIT(domain_id); WARN_ON(d->wake_count); WARN_ON(hrtimer_cancel(&d->timer)); - hrtimer_destroy(&d->timer); kfree(d); } Index: src/sys/external/bsd/drm2/include/linux/hrtimer.h diff -u src/sys/external/bsd/drm2/include/linux/hrtimer.h:1.6 src/sys/external/bsd/drm2/include/linux/hrtimer.h:1.7 --- src/sys/external/bsd/drm2/include/linux/hrtimer.h:1.6 Sun Dec 19 11:53:09 2021 +++ src/sys/external/bsd/drm2/include/linux/hrtimer.h Sun Dec 19 11:55:47 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: hrtimer.h,v 1.6 2021/12/19 11:53:09 riastradh Exp $ */ +/* $NetBSD: hrtimer.h,v 1.7 2021/12/19 11:55:47 riastradh Exp $ */ /*- * Copyright (c) 2014 The NetBSD Foundation, Inc. @@ -39,18 +39,20 @@ #include <linux/ktime.h> #include <linux/timer.h> -struct hrtimer { - enum hrtimer_restart (*function)(struct hrtimer *); - - struct hrtimer_private *hrt_private; -}; - enum hrtimer_mode { HRTIMER_MODE_ABS, HRTIMER_MODE_REL, HRTIMER_MODE_REL_PINNED, }; +struct hrtimer { + enum hrtimer_restart (*function)(struct hrtimer *); + + struct callout hrt_ch; + enum hrtimer_mode hrt_mode; + ktime_t hrt_expires; +}; + enum hrtimer_restart { HRTIMER_NORESTART, HRTIMER_RESTART, @@ -59,7 +61,6 @@ enum hrtimer_restart { #define hrtimer_active linux_hrtimer_active #define hrtimer_add_expires_ns linux_hrtimer_add_expires_ns #define hrtimer_cancel linux_hrtimer_cancel -#define hrtimer_destroy linux_hrtimer_destroy #define hrtimer_forward linux_hrtimer_forward #define hrtimer_forward_now linux_hrtimer_forward_now #define hrtimer_init linux_hrtimer_init @@ -74,7 +75,6 @@ void hrtimer_start(struct hrtimer *, kti void hrtimer_start_range_ns(struct hrtimer *, ktime_t, uint64_t, enum hrtimer_mode); int hrtimer_cancel(struct hrtimer *); -void hrtimer_destroy(struct hrtimer *); bool hrtimer_active(struct hrtimer *); uint64_t hrtimer_forward(struct hrtimer *, ktime_t, ktime_t); uint64_t hrtimer_forward_now(struct hrtimer *, ktime_t); Index: src/sys/external/bsd/drm2/include/linux/timer.h diff -u src/sys/external/bsd/drm2/include/linux/timer.h:1.13 src/sys/external/bsd/drm2/include/linux/timer.h:1.14 --- src/sys/external/bsd/drm2/include/linux/timer.h:1.13 Sun Dec 19 11:49:12 2021 +++ src/sys/external/bsd/drm2/include/linux/timer.h Sun Dec 19 11:55:47 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: timer.h,v 1.13 2021/12/19 11:49:12 riastradh Exp $ */ +/* $NetBSD: timer.h,v 1.14 2021/12/19 11:55:47 riastradh Exp $ */ /*- * Copyright (c) 2013 The NetBSD Foundation, Inc. @@ -29,13 +29,6 @@ * POSSIBILITY OF SUCH DAMAGE. */ -/* - * Notes on porting: - * - * - Linux does not have teardown_timer. You must add it yourself in - * the appropriate place. - */ - #ifndef _LINUX_TIMER_H_ #define _LINUX_TIMER_H_ @@ -64,13 +57,6 @@ timer_setup(struct timer_list *timer, vo (void *)timer); } -static inline void -teardown_timer(struct timer_list *timer) -{ - - callout_destroy(&timer->tl_callout); -} - static inline int mod_timer(struct timer_list *timer, unsigned long then) { Index: src/sys/external/bsd/drm2/linux/linux_hrtimer.c diff -u src/sys/external/bsd/drm2/linux/linux_hrtimer.c:1.2 src/sys/external/bsd/drm2/linux/linux_hrtimer.c:1.3 --- src/sys/external/bsd/drm2/linux/linux_hrtimer.c:1.2 Sun Dec 19 11:53:09 2021 +++ src/sys/external/bsd/drm2/linux/linux_hrtimer.c Sun Dec 19 11:55:47 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: linux_hrtimer.c,v 1.2 2021/12/19 11:53:09 riastradh Exp $ */ +/* $NetBSD: linux_hrtimer.c,v 1.3 2021/12/19 11:55:47 riastradh Exp $ */ /*- * Copyright (c) 2021 The NetBSD Foundation, Inc. @@ -27,61 +27,49 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: linux_hrtimer.c,v 1.2 2021/12/19 11:53:09 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: linux_hrtimer.c,v 1.3 2021/12/19 11:55:47 riastradh Exp $"); #include <sys/types.h> #include <sys/callout.h> -#include <sys/kmem.h> #include <linux/hrtimer.h> #include <linux/ktime.h> -struct hrtimer_private { - struct callout ch; - enum hrtimer_mode mode; - ktime_t expires; -}; - static void hrtimer_fire(void *); void hrtimer_init(struct hrtimer *hrt, clockid_t clkid, enum hrtimer_mode mode) { - struct hrtimer_private *H; KASSERTMSG(clkid == CLOCK_MONOTONIC, "clkid %d", clkid); - H = hrt->hrt_private = kmem_zalloc(sizeof(*H), KM_SLEEP); - - callout_init(&H->ch, CALLOUT_MPSAFE); - callout_setfunc(&H->ch, hrtimer_fire, H); - H->mode = mode; + callout_init(&hrt->hrt_ch, CALLOUT_MPSAFE); + callout_setfunc(&hrt->hrt_ch, hrtimer_fire, hrt); + hrt->hrt_mode = mode; } static void _hrtimer_schedule(struct hrtimer *hrt) { - struct hrtimer_private *H = hrt->hrt_private; int delta; - switch (H->mode) { + switch (hrt->hrt_mode) { case HRTIMER_MODE_ABS: panic("absolute hrtimer NYI"); break; case HRTIMER_MODE_REL: - delta = ktime_to_ms(H->expires); + delta = ktime_to_ms(hrt->hrt_expires); break; default: - panic("invalid hrtimer mode %d", H->mode); + panic("invalid hrtimer mode %d", hrt->hrt_mode); } - callout_schedule(&H->ch, delta); + callout_schedule(&hrt->hrt_ch, delta); } static void hrtimer_fire(void *cookie) { struct hrtimer *hrt = cookie; - struct hrtimer_private *H = hrt->hrt_private; switch ((*hrt->function)(hrt)) { case HRTIMER_RESTART: @@ -91,23 +79,21 @@ hrtimer_fire(void *cookie) break; } - callout_ack(&H->ch); + callout_ack(&hrt->hrt_ch); } void hrtimer_set_expires(struct hrtimer *hrt, ktime_t expires) { - struct hrtimer_private *H = hrt->hrt_private; - H->expires = expires; + hrt->hrt_expires = expires; } void hrtimer_add_expires_ns(struct hrtimer *hrt, uint64_t ns) { - struct hrtimer_private *H = hrt->hrt_private; - H->expires = ktime_add_ns(H->expires, ns); + hrt->hrt_expires = ktime_add_ns(hrt->hrt_expires, ns); } void @@ -121,25 +107,23 @@ void hrtimer_start_range_ns(struct hrtimer *hrt, ktime_t expires, uint64_t range_ns, enum hrtimer_mode mode) { - struct hrtimer_private *H = hrt->hrt_private; - H->expires = expires; + hrt->hrt_expires = expires; (void)range_ns; - H->mode = mode; + hrt->hrt_mode = mode; _hrtimer_schedule(hrt); } int hrtimer_cancel(struct hrtimer *hrt) { - struct hrtimer_private *H = hrt->hrt_private; bool active; /* * Halt the callout and ascertain whether the hrtimer was * active when we invoked hrtimer_cancel. */ - if (callout_halt(&H->ch, NULL)) { + if (callout_halt(&hrt->hrt_ch, NULL)) { /* Callout expired, meaning it was active. */ active = true; } else { @@ -149,26 +133,14 @@ hrtimer_cancel(struct hrtimer *hrt) * corresponds with whether the hrtimer was active or * not. */ - active = callout_pending(&H->ch); + active = callout_pending(&hrt->hrt_ch); } return active; } -void -hrtimer_destroy(struct hrtimer *hrt) -{ - struct hrtimer_private *H = hrt->hrt_private; - - callout_destroy(&H->ch); - kmem_free(H, sizeof(*H)); - - explicit_memset(hrt, 0, sizeof(*hrt)); /* paranoia */ -} - bool hrtimer_active(struct hrtimer *hrt) { - struct hrtimer_private *H = hrt->hrt_private; /* * If the callout has been scheduled, but has not yet fired, @@ -177,16 +149,15 @@ hrtimer_active(struct hrtimer *hrt) * If the callout has fired, but has not yet reached * callout_ack, then it is invoking. */ - return callout_pending(&H->ch) || callout_invoking(&H->ch); + return callout_pending(&hrt->hrt_ch) || callout_invoking(&hrt->hrt_ch); } uint64_t hrtimer_forward(struct hrtimer *hrt, ktime_t now, ktime_t period) { - struct hrtimer_private *H = hrt->hrt_private; uint64_t now_ms, period_ms, expires_ms, nperiods; - KASSERT(!callout_pending(&H->ch)); + KASSERT(!callout_pending(&hrt->hrt_ch)); /* * Can't get better than 10ms precision (or ~1ms if you set @@ -195,7 +166,7 @@ hrtimer_forward(struct hrtimer *hrt, kti */ now_ms = ktime_to_ms(now); period_ms = ktime_to_ms(period); - expires_ms = ktime_to_ms(H->expires); + expires_ms = ktime_to_ms(hrt->hrt_expires); /* If it hasn't yet expired, no overruns. */ if (now_ms < expires_ms) @@ -204,7 +175,8 @@ hrtimer_forward(struct hrtimer *hrt, kti /* Advance it by as many periods as it should have fired. */ /* XXX fenceposts */ nperiods = howmany(now_ms - expires_ms, period_ms); - H->expires = ktime_add_ns(H->expires, 1000000*nperiods*period_ms); + hrt->hrt_expires = ktime_add_ns(hrt->hrt_expires, + 1000000*nperiods*period_ms); return nperiods; }