Skip to content

Commit

Permalink
drm-ffi: Call GETPROPERTY ioctl only once if no values or enums
Browse files Browse the repository at this point in the history
When we call this ioctl first, we obtain the amount of values and enum
blobs available for this property, so that we can allocate the memory
and pass it in a second call.  But when there are zero values and zero
enum blobs, there is no need for any allocation or second call.

This further reduces the amount of DRM_IOCTL_MODE_GETPROPERTY ioctls
from 84 to 77 in the atomic_modeset example.
  • Loading branch information
linkmauve committed Sep 24, 2023
1 parent 7503d13 commit 81e8d1c
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions drm-ffi/src/mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,26 +554,25 @@ pub fn get_property(
mut values: Option<&mut Vec<u64>>,
mut enums: Option<&mut Vec<drm_mode_property_enum>>,
) -> Result<drm_mode_get_property, Error> {
let mut sizes = drm_mode_get_property {
let mut prop = drm_mode_get_property {
prop_id,
..Default::default()
};

unsafe {
ioctl::mode::get_property(fd, &mut sizes)?;
ioctl::mode::get_property(fd, &mut prop)?;
}

map_reserve!(values, sizes.count_values as usize);
map_reserve!(enums, sizes.count_enum_blobs as usize);
// There is no need to call get_property() twice if there is nothing else to retrieve.
if prop.count_values == 0 && prop.count_enum_blobs == 0 {
return Ok(prop);
}

let mut prop = drm_mode_get_property {
prop_id,
values_ptr: map_ptr!(&values),
enum_blob_ptr: map_ptr!(&enums),
count_values: map_len!(&values),
count_enum_blobs: map_len!(&enums),
..Default::default()
};
map_reserve!(values, prop.count_values as usize);
map_reserve!(enums, prop.count_enum_blobs as usize);

prop.values_ptr = map_ptr!(&values);
prop.enum_blob_ptr = map_ptr!(&enums);

unsafe {
ioctl::mode::get_property(fd, &mut prop)?;
Expand Down

0 comments on commit 81e8d1c

Please sign in to comment.