vivid, vivid-kthread-touch.c migration to hrtimer

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi All,
I try to handle "V4L2: vivid: improve timestamping" task in
https://www.linuxtv.org/wiki/index.php/Media_Open_Source_Projects:_Looking_for_Volunteers

I do a first try on using hrtimer on vivi-kthread-touch.c
I have some doubt on my things :'(

In particular on the following formulas:

buffers_since_start =
                 denominator * time_since_start / NSEC_PER_SEC;


next_time_buf_start =
                 time_since_start / buffers_since_start;


I post also the entire hrtimer func:

static enum hrtimer_restart vivid_hrtimer_touch_cap(struct hrtimer *hrtimer)
{
	struct vivid_dev *dev = container_of(hrtimer,
							struct vivid_dev, hrtimer_touch_cap);
	unsigned int numerator, denominator;
	ktime_t now;
	s64 time_since_start, next_time_buf_start;
	u64 buffers_since_start, numerators_since_start;
	int dropped_bufs;

	/* Resets frame counters first time */
	if (!dev->hrtimer_touch_cap_started) {

		dprintk(dev, 1, "Touch Capture Thread Start\n");

		dev->touch_cap_seq_offset = 0;
		dev->touch_cap_seq_count = 0;
		dev->touch_cap_seq_resync = false;
		dev->time_touch_cap = hrtimer_cb_get_time(hrtimer);

		if (dev->time_wrap)
			dev->time_wrap_offset = dev->time_wrap - ktime_get_ns();
		else
			dev->time_wrap_offset = 0;

		dev->hrtimer_touch_cap_started = true;
	}

	now = hrtimer_cb_get_time(hrtimer);

	if (dev->touch_cap_seq_resync) {
		dev->time_touch_cap = hrtimer_cb_get_time(hrtimer);
		dev->touch_cap_seq_offset = dev->touch_cap_seq_count + 1;
		dev->touch_cap_seq_count = 0;
		dev->cap_seq_resync = false;
	}

	denominator = dev->timeperframe_tch_cap.denominator;
	numerator = dev->timeperframe_tch_cap.numerator;

	time_since_start =
		ktime_to_ns(now) - ktime_to_ns(dev->time_touch_cap);

	// printk("ktime_to_ms(now) = %lld", ktime_to_ms(now));
	// printk("ktime_to_ms(dev->time_touch_cap) = %lld", ktime_to_ms(dev->time_touch_cap));
	// printk("time_since_start = %lld\n",time_since_start);

	buffers_since_start =
		denominator * time_since_start / NSEC_PER_SEC;

	// printk("buffer_since_start = %lld\n",buffers_since_start);

	dropped_bufs =
		buffers_since_start + dev->touch_cap_seq_offset - dev->touch_cap_seq_count;
	dev->touch_cap_seq_count =
		buffers_since_start + dev->touch_cap_seq_offset;
	dev->touch_cap_with_seq_wrap_count =
		dev->touch_cap_seq_count - dev->touch_cap_seq_start;

	vivid_thread_tch_cap_tick(dev, dropped_bufs);

	numerators_since_start = ++buffers_since_start * numerator;

	now = hrtimer_cb_get_time(hrtimer);
	time_since_start =
		ktime_to_ns(now) - ktime_to_ns(dev->time_touch_cap);

	// printk("time_since_start = %lld\n",time_since_start);
	mutex_unlock(&dev->mutex);

	next_time_buf_start =
		time_since_start / buffers_since_start;

	// printk("next_time_buf_start = %lld", next_time_buf_start);

	hrtimer_forward_now(hrtimer, ns_to_ktime(next_time_buf_start));
	return HRTIMER_RESTART;
}

References:
 - https://github.com/Scott31393/linux/commit/b0e7b7eea1921ab3faad46c8ad8538c083cac2b4

During test I got the following result, delta is quite costant but
sometimes I got some delay of 2 time the, let me say "nice to have
delay". 

/usr/bin/v4l2-ctl -d /dev/v4l-touch0 --stream-mmap --verbose

cap dqbuf: 1 seq:   3839 bytesused: 504 ts: 628.527612 delta: 99.995 ms fps: 10.00 (ts-monotonic, ts-src-eof)
TD16:    0   1   0   0   0   0   0   0   0   0   0   0  -3  -1   0   0   0   0   0   0   0
TD16:    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1   0
TD16:    0   3   0   0   0   0   0   0   0   0   0   0   0   0   3   0   0   0   0   0   0
TD16:    0   0   0   1   0   0   0   0   0   0   0   0   3   0   0   0   0   0   0  -1   0
TD16:    0   0   0   0  -1   0   0   0   0   2   0   0   0   0   0   0   0   0   0   0   0
TD16:    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
TD16:    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
TD16:    0   0   0   0   0   0   0   0   0   0   1   0   0   0   0   0   0   0   0   0   0
TD16:    0   0   0   0   0   0   0   0   0   0   0   0   0   3   0   2   0   0   0   0   0
TD16:    3   0  -1   0   0   0   0   0   0   0   0   0   0   0   0   0   3   0   0   3   0
TD16:    0   0   1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
TD16:    0   0   0   0   0   0   0   3   0   0   0   0   0   0   0   0   0   0   0   0   3
cap dqbuf: 2 seq:   3840 bytesused: 504 ts: 628.627602 delta: 99.990 ms fps: 10.00 (ts-monotonic, ts-src-eof)
TD16:    0   0   0   0   0   0   0   0   0   0   0   1   0   0   0   0   0   0   2   0   0
TD16:    0   0   0   0   0   0   0   0   1   0   0   0   0   0   0   0   0   0   0   0   0
TD16:    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   3   0   0   0
TD16:    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
TD16:    0  -2   0   2   0   0   0   0   0   0   0   0   0   0   2   0   0   0   0   0   0
TD16:    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
TD16:    0   0   0   0   0   2   0   0   0   0   0   3   0   0   0   0   0   0   0   0   0
TD16:    0   0   0  -2   0   0   0  -3   0   0   0  -1   0   0   0   1   0   0   0   0   0
TD16:   -1   0   0   0   0   0   0   0   0   0   0   0   0   0   0  -3   0   0   0   0   0
TD16:    0   3   0  -3   1   0   0  -3   0   0   0   0   0   0   0   0   0   0   0   0   0
TD16:    1   0   0   0   0   0   0  -3   0   0   0   0   0   0   0   0   0   0   0   0   3
TD16:    0   1   0   0   0   2   0   0   0   0   0   0   0   0  -1   0   0   0   0   0   0
cap dqbuf: 3 seq:   3841 bytesused: 504 ts: 628.727597 delta: 99.995 ms fps: 10.00 (ts-monotonic, ts-src-eof)
TD16:    0   1   0   0  -1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
TD16:    0   0   0   0   0   0   0   0   0  -1   0  -1  -3   0   0  -1   0   0  -3   0   0
TD16:    0   0   0   0  -1   3   0   0   0   0   0   0   0  -1   0   0   0   0  -2   0   0
TD16:    0   0   0  -1   0   0   0   0   1   0   0   0   0   0   0   0   0   0   0   0   0
TD16:    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0  -2   0   0   0   0   0
TD16:    0   0   0   0   0   0   2   0   0   0   2   0   0   0   0   0   0   0   0   0   0
TD16:    0   0   0   0   0  -3   0   0   0   0   1   0   0   0   0   0   0  -3   0   0   0
TD16:    0   0   0   0   0   0   0   0   0  -2   0   0   0   0   3   0  -3   0   0   0   0
TD16:    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0  -2   0   0
TD16:    0   0   0   0   0   0   0   0  -1   0   3   0   0   0   0   2   0   0   0   1   0
TD16:    0   0   0   0   0   0   0   0  -1   0   0   0   0   0  -1   0   0   0   0   0   0
TD16:    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
cap dqbuf: 0 seq:   3843 bytesused: 504 ts: 628.927577 delta: 199.980 ms fps: 10.00 dropped: 1 (ts-monotonic, ts-src-eof)

This is just a work in progress. For this reason I don't post the entire patch.
But if we need I can post it too :)

Let me know. What do you think about.
Thanks in advance.

Tommaso
-- 
Tommaso Merciai
Embedded Linux Engineer
tommaso.merciai@xxxxxxxxxxxxxxxxxxxx
__________________________________

Amarula Solutions SRL
Via Le Canevare 30, 31100 Treviso, Veneto, IT
T. +39 042 243 5310
info@xxxxxxxxxxxxxxxxxxxx
www.amarulasolutions.com



[Index of Archives]     [Linux Input]     [Video for Linux]     [Gstreamer Embedded]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux