Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix set gain exception Linux #9845

Merged
merged 11 commits into from
Oct 13, 2021

Conversation

Nir-Az
Copy link
Collaborator

@Nir-Az Nir-Az commented Oct 12, 2021

  • Use Status Interrupt Endpoint Vl42 implementation for verifying set_pu command was executed before the function call returns
  • Add set_pu stress UT

The test pass on Linux with the fix and fail on Windows.
Tracked on [DSO-17185]

@Nir-Az Nir-Az requested review from ev-mp and maloel October 12, 2021 10:52
@@ -1280,6 +1280,12 @@ namespace librealsense
{
struct v4l2_control control = {get_cid(opt), value};
if (RS2_OPTION_ENABLE_AUTO_EXPOSURE==opt) { control.value = value ? V4L2_EXPOSURE_APERTURE_PRIORITY : V4L2_EXPOSURE_MANUAL; }

std::lock_guard<std::mutex> lock(_set_ctrl_event_mutex);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather not have this mutex - in worst case we're going to stall the main thread for 30msec, which is not acceptable

Copy link
Collaborator Author

@Nir-Az Nir-Az Oct 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The worst cast I saw on 50 set command was:

subscribe_to_ctrl_event took :0.011617 [ms]
pend_for_ctrl_status_event took :8.54738 [ms]
unsubscribe_from_ctrl_event took :0.006908 [ms]

if (!pend_for_ctrl_status_event())
return false;

unsubscribe_from_ctrl_event(control.id);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • What is the impact of subscribe/unsubscribe ? How much penalty it adds?
  • Note that in case of return false the unsubscribe will not be executed.
    Please restructure subscribe/unsubscribe it into RAII scheme (class or unique_ptr with custom dtor) to ensure that if an exception is raised in-between, the unsubscribe call will be enforced

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RAII added

src/linux/backend-v4l2.cpp Show resolved Hide resolved
memset(event_subscription.reserved,0, sizeof(event_subscription.reserved));
if (xioctl(_fd, VIDIOC_SUBSCRIBE_EVENT, &event_subscription) < 0)
{
throw linux_backend_exception("xioctl(VIDIOC_SUBSCRIBE_EVENT) failed");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls add the control id to the exception message here and below

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

struct v4l2_event event;
memset(&event, 0 , sizeof(event));

// Poll registered events and verify that set control event raised (wait max of 6 * 5 = 30 [ms])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the impact of making it 10 X 2 msec ? (2msec is the min interval for control calls we have in UVC pipe) . Imo - 5 msec intervals are not optimized.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The min time I tried was 15 [ms], and I got cases of no event raised yet (first iteration it failed was > 1000)
I will try with 10 X 2

Copy link
Collaborator Author

@Nir-Az Nir-Az Oct 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Timing constants updated .

depth_ir_sensor = dev.first_depth_sensor()

for i in range(test_iterations):
log.d("{} Itearion {} {}".format("=" * 50, i, "=" * 50))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines 29 to 31
depth_ir_sensor.set_option(rs.option.enable_auto_exposure, 0)
depth_ir_sensor.set_option(rs.option.exposure, 1)
depth_ir_sensor.set_option(rs.option.gain, 248)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add check for sensor.supports(... for generality

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@Nir-Az Nir-Az force-pushed the fix_set_gain_exception_linux branch from daf2e9a to a394031 Compare October 12, 2021 11:27
// RAII to handle unsubscribe in case of exceptions
std::unique_ptr<uint32_t, std::function<void(uint32_t*)> > unsubscriber(
new uint32_t(control.id),
[this](uint32_t* id){ if (id) unsubscribe_from_ctrl_event(*id); });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also add delete id; to avoid memleak

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

test.check(val == get_val)
log.d("Gain Set To: {}".format(get_val))

time.sleep(0.1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sleep may mask the issue (if it still exist).
also pls repeat the loop several time so the total num of iteration will be 20+

Copy link
Collaborator Author

@Nir-Az Nir-Az Oct 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sleep was there cause that's validation script, this exact test failed on their side.
The loop occurs 200 times, each time sets 5 values (total of 1000 sets), I didn't understand your request..

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sleep removed

@Nir-Az Nir-Az force-pushed the fix_set_gain_exception_linux branch from 5dda755 to b23614d Compare October 13, 2021 15:17
@ev-mp ev-mp merged commit 7319014 into IntelRealSense:development Oct 13, 2021
@Nir-Az Nir-Az deleted the fix_set_gain_exception_linux branch June 7, 2022 06:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants