vulkan/anv: use vk_device_get_timestamp and drop vk_clock_gettime

vk_clock_gettime hasn't been used by other implementations ever since
venus and kk migrated over to the common implementation. It'd be better
to drop that helper (or move into anv) because it's not OS agnostic as
compare to the more comprehensive vk_device_get_timestamp.

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/40582>
This commit is contained in:
Yiwei Zhang 2026-03-23 10:55:09 -07:00 committed by Marge Bot
parent 8982056fa8
commit 8351c6070d
3 changed files with 22 additions and 38 deletions

View file

@ -2126,13 +2126,13 @@ void anv_GetDeviceMemoryCommitment(
*pCommittedMemoryInBytes = 0;
}
static inline clockid_t
anv_get_default_cpu_clock_id(void)
static inline VkTimeDomainKHR
anv_get_default_cpu_time_domain(void)
{
#ifdef CLOCK_MONOTONIC_RAW
return CLOCK_MONOTONIC_RAW;
return VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_KHR;
#else
return CLOCK_MONOTONIC;
return VK_TIME_DOMAIN_CLOCK_MONOTONIC_KHR;
#endif
}
@ -2192,9 +2192,15 @@ VkResult anv_GetCalibratedTimestampsKHR(
uint64_t max_clock_period = 0;
const enum intel_kmd_type kmd_type = device->physical->info.kmd_type;
const bool has_correlate_timestamp = kmd_type == INTEL_KMD_TYPE_XE;
const VkTimeDomainKHR default_cpu_time_domain = anv_get_default_cpu_time_domain();
const clockid_t default_cpu_clock_id = vk_time_domain_to_clockid(default_cpu_time_domain);
clockid_t cpu_clock_id = -1;
VkResult result;
begin = end = vk_clock_gettime(anv_get_default_cpu_clock_id());
result = vk_device_get_timestamp(&device->vk, default_cpu_time_domain, &end);
if (result != VK_SUCCESS)
return vk_error(device, result);
begin = end;
for (d = 0, increment = 1; d < timestampCount; d += increment) {
const VkTimeDomainKHR current = get_effective_time_domain(&pTimestampInfos[d]);
@ -2248,11 +2254,11 @@ VkResult anv_GetCalibratedTimestampsKHR(
}
/* If we're the first element, we can replace begin */
if (d == 0 && cpu_clock_id == anv_get_default_cpu_clock_id())
if (d == 0 && cpu_clock_id == default_cpu_clock_id)
begin = cpu_timestamp;
/* If we're in the same clock domain as begin/end. We can set the end. */
if (cpu_clock_id == anv_get_default_cpu_clock_id())
if (cpu_clock_id == default_cpu_clock_id)
end = cpu_end_timestamp;
continue;
@ -2272,7 +2278,10 @@ VkResult anv_GetCalibratedTimestampsKHR(
max_clock_period = MAX2(max_clock_period, device_period);
break;
case VK_TIME_DOMAIN_CLOCK_MONOTONIC_KHR:
pTimestamps[d] = vk_clock_gettime(CLOCK_MONOTONIC);
result = vk_device_get_timestamp(
&device->vk, VK_TIME_DOMAIN_CLOCK_MONOTONIC_KHR, &pTimestamps[d]);
if (result != VK_SUCCESS)
return vk_error(device, result);
max_clock_period = MAX2(max_clock_period, 1);
break;
@ -2307,8 +2316,11 @@ VkResult anv_GetCalibratedTimestampsKHR(
/* If last timestamp was not get with has_correlate_timestamp method or
* if it was but last cpu clock is not the default one, get time again
*/
if (increment == 1 || cpu_clock_id != anv_get_default_cpu_clock_id())
end = vk_clock_gettime(anv_get_default_cpu_clock_id());
if (increment == 1 || cpu_clock_id != default_cpu_clock_id) {
result = vk_device_get_timestamp(&device->vk, default_cpu_time_domain, &end);
if (result != VK_SUCCESS)
return vk_error(device, result);
}
*pMaxDeviation = vk_time_max_deviation(begin, end, max_clock_period);

View file

@ -916,24 +916,3 @@ vk_common_GetCalibratedTimestampsKHR(
return VK_SUCCESS;
}
#ifndef _WIN32
uint64_t
vk_clock_gettime(clockid_t clock_id)
{
struct timespec current;
int ret;
ret = clock_gettime(clock_id, &current);
#ifdef CLOCK_MONOTONIC_RAW
if (ret < 0 && clock_id == CLOCK_MONOTONIC_RAW)
ret = clock_gettime(CLOCK_MONOTONIC, &current);
#endif
if (ret < 0)
return 0;
return (uint64_t)current.tv_sec * 1000000000ULL + current.tv_nsec;
}
#endif //!_WIN32

View file

@ -443,13 +443,6 @@ VkResult
vk_device_get_timestamp(struct vk_device *device, VkTimeDomainKHR domain,
uint64_t *timestamp);
#ifndef _WIN32
uint64_t
vk_clock_gettime(clockid_t clock_id);
#endif //!_WIN32
static inline uint64_t
vk_time_max_deviation(uint64_t begin, uint64_t end, uint64_t max_clock_period)
{