radv: anv: Use the new vk_clock_gettime and vk_time_max_deviation
functions Removes the duplicated code and start using the new common code. v2: split anv/radv parts to separate commits Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com> (v1) Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com> (v1) Signed-off-by: Igor Torrente <igor.torrente@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18281>
This commit is contained in:
@@ -7147,23 +7147,6 @@ radv_GetPhysicalDeviceCalibrateableTimeDomainsEXT(VkPhysicalDevice physicalDevic
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
static uint64_t
|
|
||||||
radv_clock_gettime(clockid_t clock_id)
|
|
||||||
{
|
|
||||||
struct timespec current;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
ret = clock_gettime(clock_id, ¤t);
|
|
||||||
#ifdef CLOCK_MONOTONIC_RAW
|
|
||||||
if (ret < 0 && clock_id == CLOCK_MONOTONIC_RAW)
|
|
||||||
ret = clock_gettime(CLOCK_MONOTONIC, ¤t);
|
|
||||||
#endif
|
|
||||||
if (ret < 0)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
return (uint64_t)current.tv_sec * 1000000000ULL + current.tv_nsec;
|
|
||||||
}
|
|
||||||
|
|
||||||
VKAPI_ATTR VkResult VKAPI_CALL
|
VKAPI_ATTR VkResult VKAPI_CALL
|
||||||
radv_GetCalibratedTimestampsEXT(VkDevice _device, uint32_t timestampCount,
|
radv_GetCalibratedTimestampsEXT(VkDevice _device, uint32_t timestampCount,
|
||||||
const VkCalibratedTimestampInfoEXT *pTimestampInfos,
|
const VkCalibratedTimestampInfoEXT *pTimestampInfos,
|
||||||
@@ -7176,9 +7159,9 @@ radv_GetCalibratedTimestampsEXT(VkDevice _device, uint32_t timestampCount,
|
|||||||
uint64_t max_clock_period = 0;
|
uint64_t max_clock_period = 0;
|
||||||
|
|
||||||
#ifdef CLOCK_MONOTONIC_RAW
|
#ifdef CLOCK_MONOTONIC_RAW
|
||||||
begin = radv_clock_gettime(CLOCK_MONOTONIC_RAW);
|
begin = vk_clock_gettime(CLOCK_MONOTONIC_RAW);
|
||||||
#else
|
#else
|
||||||
begin = radv_clock_gettime(CLOCK_MONOTONIC);
|
begin = vk_clock_gettime(CLOCK_MONOTONIC);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (d = 0; d < timestampCount; d++) {
|
for (d = 0; d < timestampCount; d++) {
|
||||||
@@ -7189,7 +7172,7 @@ radv_GetCalibratedTimestampsEXT(VkDevice _device, uint32_t timestampCount,
|
|||||||
max_clock_period = MAX2(max_clock_period, device_period);
|
max_clock_period = MAX2(max_clock_period, device_period);
|
||||||
break;
|
break;
|
||||||
case VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT:
|
case VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT:
|
||||||
pTimestamps[d] = radv_clock_gettime(CLOCK_MONOTONIC);
|
pTimestamps[d] = vk_clock_gettime(CLOCK_MONOTONIC);
|
||||||
max_clock_period = MAX2(max_clock_period, 1);
|
max_clock_period = MAX2(max_clock_period, 1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -7205,49 +7188,12 @@ radv_GetCalibratedTimestampsEXT(VkDevice _device, uint32_t timestampCount,
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CLOCK_MONOTONIC_RAW
|
#ifdef CLOCK_MONOTONIC_RAW
|
||||||
end = radv_clock_gettime(CLOCK_MONOTONIC_RAW);
|
end = vk_clock_gettime(CLOCK_MONOTONIC_RAW);
|
||||||
#else
|
#else
|
||||||
end = radv_clock_gettime(CLOCK_MONOTONIC);
|
end = vk_clock_gettime(CLOCK_MONOTONIC);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
*pMaxDeviation = vk_time_max_deviation(begin, end, max_clock_period);
|
||||||
* The maximum deviation is the sum of the interval over which we
|
|
||||||
* perform the sampling and the maximum period of any sampled
|
|
||||||
* clock. That's because the maximum skew between any two sampled
|
|
||||||
* clock edges is when the sampled clock with the largest period is
|
|
||||||
* sampled at the end of that period but right at the beginning of the
|
|
||||||
* sampling interval and some other clock is sampled right at the
|
|
||||||
* begining of its sampling period and right at the end of the
|
|
||||||
* sampling interval. Let's assume the GPU has the longest clock
|
|
||||||
* period and that the application is sampling GPU and monotonic:
|
|
||||||
*
|
|
||||||
* s e
|
|
||||||
* w x y z 0 1 2 3 4 5 6 7 8 9 a b c d e f
|
|
||||||
* Raw -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
|
|
||||||
*
|
|
||||||
* g
|
|
||||||
* 0 1 2 3
|
|
||||||
* GPU -----_____-----_____-----_____-----_____
|
|
||||||
*
|
|
||||||
* m
|
|
||||||
* x y z 0 1 2 3 4 5 6 7 8 9 a b c
|
|
||||||
* Monotonic -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
|
|
||||||
*
|
|
||||||
* Interval <----------------->
|
|
||||||
* Deviation <-------------------------->
|
|
||||||
*
|
|
||||||
* s = read(raw) 2
|
|
||||||
* g = read(GPU) 1
|
|
||||||
* m = read(monotonic) 2
|
|
||||||
* e = read(raw) b
|
|
||||||
*
|
|
||||||
* We round the sample interval up by one tick to cover sampling error
|
|
||||||
* in the interval clock
|
|
||||||
*/
|
|
||||||
|
|
||||||
uint64_t sample_interval = end - begin + 1;
|
|
||||||
|
|
||||||
*pMaxDeviation = sample_interval + max_clock_period;
|
|
||||||
|
|
||||||
return VK_SUCCESS;
|
return VK_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@@ -4573,23 +4573,6 @@ VkResult anv_GetPhysicalDeviceCalibrateableTimeDomainsEXT(
|
|||||||
return vk_outarray_status(&out);
|
return vk_outarray_status(&out);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint64_t
|
|
||||||
anv_clock_gettime(clockid_t clock_id)
|
|
||||||
{
|
|
||||||
struct timespec current;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
ret = clock_gettime(clock_id, ¤t);
|
|
||||||
#ifdef CLOCK_MONOTONIC_RAW
|
|
||||||
if (ret < 0 && clock_id == CLOCK_MONOTONIC_RAW)
|
|
||||||
ret = clock_gettime(CLOCK_MONOTONIC, ¤t);
|
|
||||||
#endif
|
|
||||||
if (ret < 0)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
return (uint64_t) current.tv_sec * 1000000000ULL + current.tv_nsec;
|
|
||||||
}
|
|
||||||
|
|
||||||
VkResult anv_GetCalibratedTimestampsEXT(
|
VkResult anv_GetCalibratedTimestampsEXT(
|
||||||
VkDevice _device,
|
VkDevice _device,
|
||||||
uint32_t timestampCount,
|
uint32_t timestampCount,
|
||||||
@@ -4605,9 +4588,9 @@ VkResult anv_GetCalibratedTimestampsEXT(
|
|||||||
uint64_t max_clock_period = 0;
|
uint64_t max_clock_period = 0;
|
||||||
|
|
||||||
#ifdef CLOCK_MONOTONIC_RAW
|
#ifdef CLOCK_MONOTONIC_RAW
|
||||||
begin = anv_clock_gettime(CLOCK_MONOTONIC_RAW);
|
begin = vk_clock_gettime(CLOCK_MONOTONIC_RAW);
|
||||||
#else
|
#else
|
||||||
begin = anv_clock_gettime(CLOCK_MONOTONIC);
|
begin = vk_clock_gettime(CLOCK_MONOTONIC);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (d = 0; d < timestampCount; d++) {
|
for (d = 0; d < timestampCount; d++) {
|
||||||
@@ -4624,7 +4607,7 @@ VkResult anv_GetCalibratedTimestampsEXT(
|
|||||||
max_clock_period = MAX2(max_clock_period, device_period);
|
max_clock_period = MAX2(max_clock_period, device_period);
|
||||||
break;
|
break;
|
||||||
case VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT:
|
case VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT:
|
||||||
pTimestamps[d] = anv_clock_gettime(CLOCK_MONOTONIC);
|
pTimestamps[d] = vk_clock_gettime(CLOCK_MONOTONIC);
|
||||||
max_clock_period = MAX2(max_clock_period, 1);
|
max_clock_period = MAX2(max_clock_period, 1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -4640,49 +4623,12 @@ VkResult anv_GetCalibratedTimestampsEXT(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CLOCK_MONOTONIC_RAW
|
#ifdef CLOCK_MONOTONIC_RAW
|
||||||
end = anv_clock_gettime(CLOCK_MONOTONIC_RAW);
|
end = vk_clock_gettime(CLOCK_MONOTONIC_RAW);
|
||||||
#else
|
#else
|
||||||
end = anv_clock_gettime(CLOCK_MONOTONIC);
|
end = vk_clock_gettime(CLOCK_MONOTONIC);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
*pMaxDeviation = vk_time_max_deviation(begin, end, max_clock_period);
|
||||||
* The maximum deviation is the sum of the interval over which we
|
|
||||||
* perform the sampling and the maximum period of any sampled
|
|
||||||
* clock. That's because the maximum skew between any two sampled
|
|
||||||
* clock edges is when the sampled clock with the largest period is
|
|
||||||
* sampled at the end of that period but right at the beginning of the
|
|
||||||
* sampling interval and some other clock is sampled right at the
|
|
||||||
* beginning of its sampling period and right at the end of the
|
|
||||||
* sampling interval. Let's assume the GPU has the longest clock
|
|
||||||
* period and that the application is sampling GPU and monotonic:
|
|
||||||
*
|
|
||||||
* s e
|
|
||||||
* w x y z 0 1 2 3 4 5 6 7 8 9 a b c d e f
|
|
||||||
* Raw -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
|
|
||||||
*
|
|
||||||
* g
|
|
||||||
* 0 1 2 3
|
|
||||||
* GPU -----_____-----_____-----_____-----_____
|
|
||||||
*
|
|
||||||
* m
|
|
||||||
* x y z 0 1 2 3 4 5 6 7 8 9 a b c
|
|
||||||
* Monotonic -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
|
|
||||||
*
|
|
||||||
* Interval <----------------->
|
|
||||||
* Deviation <-------------------------->
|
|
||||||
*
|
|
||||||
* s = read(raw) 2
|
|
||||||
* g = read(GPU) 1
|
|
||||||
* m = read(monotonic) 2
|
|
||||||
* e = read(raw) b
|
|
||||||
*
|
|
||||||
* We round the sample interval up by one tick to cover sampling error
|
|
||||||
* in the interval clock
|
|
||||||
*/
|
|
||||||
|
|
||||||
uint64_t sample_interval = end - begin + 1;
|
|
||||||
|
|
||||||
*pMaxDeviation = sample_interval + max_clock_period;
|
|
||||||
|
|
||||||
return VK_SUCCESS;
|
return VK_SUCCESS;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user