panfrost: avoid potential divide by 0 calculating timer_resolution

On armhf integer divide by 0 can raise SIGFPE, whereas on aarch64
it just returns 0. This has become an issue because the recently
added panfrost_init_screen_caps always calls pan_gpu_time_to_ns to
calculate caps->timer_resolution, whereas before we only called it
when PIPE_CAP_TIMER_RESOLUTION was queried, and only OpenCL
does that (and not always).

Fixes: 205669e3a9 ("panfrost: add panfrost_init_screen_caps")
Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33435>
This commit is contained in:
Eric R. Smith
2025-02-06 17:21:36 -04:00
committed by Marge Bot
parent 2ae97a4eb6
commit e550a3cab0
2 changed files with 3 additions and 1 deletions
@@ -229,6 +229,7 @@ pan_is_bifrost(const struct panfrost_device *dev)
static inline uint64_t
pan_gpu_time_to_ns(struct panfrost_device *dev, uint64_t gpu_time)
{
assert(dev->kmod.props.timestamp_frequency > 0);
return (gpu_time * NSEC_PER_SEC) / dev->kmod.props.timestamp_frequency;
}
+2 -1
View File
@@ -576,7 +576,8 @@ panfrost_init_screen_caps(struct panfrost_screen *screen)
dev->kmod.props.gpu_can_query_timestamp &&
dev->kmod.props.timestamp_frequency != 0;
caps->timer_resolution = pan_gpu_time_to_ns(dev, 1);
if (caps->query_timestamp)
caps->timer_resolution = pan_gpu_time_to_ns(dev, 1);
/* The hardware requires element alignment for data conversion to work
* as expected. If data conversion is not required, this restriction is