Closed Bug 1120471 Opened 5 years ago Closed 5 years ago

Support timers in libfdio

Categories

(Firefox OS Graveyard :: General, defect)

All
Gonk (Firefox OS)
defect
Not set

Tracking

(feature-b2g:2.2+, b2g-v2.2 fixed, b2g-master fixed)

RESOLVED FIXED
2.2 S4 (23jan)
feature-b2g 2.2+
Tracking Status
b2g-v2.2 --- fixed
b2g-master --- fixed

People

(Reporter: tzimmermann, Assigned: tzimmermann)

References

Details

Attachments

(1 file, 1 obsolete file)

We will need timers in bluetoothd for fixing bug 1119176. By implementing them in libfdio, we can safely integrate them into the main I/O loop and won't need ad-hoc solutions.
Attached file Github pull request (obsolete) —
This patch adds timers to libfdio. The code requires at least Kitkat, but that should not be a problem for now. We will need this feature for bluetoothd on Lollipop. Bug 1119176 has more information.
Attachment #8548193 - Flags: review?(mwu)
Attached file Github pull request
Updated Github pull request:

  - periodic timer bugfix from Bruce
Attachment #8548193 - Attachment is obsolete: true
Attachment #8548193 - Flags: review?(mwu)
Attachment #8548857 - Flags: review?(mwu)
Comment on attachment 8548857 [details]
Github pull request

Updated Github pull request:

  - added spaces around | operators
  - added separate API functions for absolute and relative timers
2.2?, because this bug is a dependency for bug 1119176, which already has 2.2+.
blocking-b2g: --- → 2.2?
Hmm this API is still confusing to me. In add_timer_to_epoll_loop, what the heck does frequency mean if it's not periodic?

Also, I wasn't asking for a fallback on kernels that don't support this syscall. I was asking to support this where the syscall is available, regardless of whether our libc directly supports it.
How about:
 - a. using the same parameter list of |add_absolute_timer_to_epoll_loop()| for |add_timer_to_epoll_loop()|; or
 - b. merging |add_absolute_timer_to_epoll_loop()| and |add_timer_to_epoll_loop()| into one function but adding one additional input parameter to distinguish between an absolute timer and an relative timer?
blocking-b2g: 2.2? → ---
feature-b2g: --- → 2.2+
Target Milestone: --- → 2.2 S4 (23jan)
(In reply to Michael Wu [:mwu] from comment #5)
> Hmm this API is still confusing to me. In add_timer_to_epoll_loop, what the
> heck does frequency mean if it's not periodic?

'frequency' is the duration from the current time until the timer fires. Maybe 'interval' is a better term. Non-periodic timers will fire once, periodic timers in regular intervals.

> Also, I wasn't asking for a fallback on kernels that don't support this
> syscall. I was asking to support this where the syscall is available,
> regardless of whether our libc directly supports it.

As I mentioned, yes it can be build with syscalls. The timerfd code was added in Linux 2.6.22, so all our kernels should support it.

The rest of my reply just meant that it might be better to emulate the API with something portable, than to use platform-specific syscalls.
Comment on attachment 8548857 [details]
Github pull request

Updated Github pull request

  - use 'interval' instead of 'frequency' throughout timer.{c,h}
  - moved setup of timespec structure to separate function
  - replaced plain numeric values by constants
(In reply to Thomas Zimmermann [:tzimmermann] [:tdz] from comment #7)
> > Also, I wasn't asking for a fallback on kernels that don't support this
> > syscall. I was asking to support this where the syscall is available,
> > regardless of whether our libc directly supports it.
> 
> As I mentioned, yes it can be build with syscalls. The timerfd code was
> added in Linux 2.6.22, so all our kernels should support it.
> 

I think this should be done instead of not supporting ANDROID_VERSION < 19. Basically, implement the calls ourselves via syscall when ANDROID_VERSION < 19. Not supporting timer functionality based on the bionic version seems too surprising.

> The rest of my reply just meant that it might be better to emulate the API
> with something portable, than to use platform-specific syscalls.

Oh, but isn't this API better? I don't think we should pretend to support anything but Linux, but if we do, we should support it using the best available API.

Back to the API being added to libfdio..

s/frequency/interval/ makes the API make more sense, but it still doesn't seem ideal. Some objections:
- periodic is being used as a bool. AFAICT bools aren't great in function args, since it's hard to easily determine what it means without referencing the docs. Wrapping the function in two wrapper functions that specifies the difference in the name is one way to avoid this, which is what I initially meant by splitting the function.
- The API is too different between add_timer_to_epoll_loop and add_absolute_timer_to_epoll_loop. At a glance, you would expect the only difference to be whether the time specified for the first timer firing is specified in relative or absolute time. Not true! They're different apis, and one of them doesn't allow the interval to be specified separately from first fire time. brsun's suggestion addresses this.
Comment on attachment 8548857 [details]
Github pull request

Updated Github pull request

  - added timerfd support for Android APIs 14 to 18
  - cleaned up API according to previous review

Timerfd support for older releases was a lot less work than I expected. These functions are just wrappers around the system calls and simply forward the arguments into the kernel. The |syscall| function does the same in a portable way. On x86, |syscall| loads 6 arguments into registers when doing the system call. So when I call |syscall| I use '0' for unused arguments.
Comment on attachment 8548857 [details]
Github pull request

Ok, that makes sense.

BTW, I think you can remove the ATTRIBS(UNUSED) on the add_timer and remove_timer functions since we just assume there's support now.

The makefile logic seems slightly verbose.. how about:

ifneq ($(filter 14 15 16 17,$(PLATFORM_SDK_VERSION)),)
    local_source_files := ports/timerfd.c
endif

Up to you though, I don't care about that too much.
Attachment #8548857 - Flags: review?(mwu) → review+
Comment on attachment 8548857 [details]
Github pull request

Updated Github pull request

  - removed unused ATTRIB statements in timer.c
Thanks Michael.
Keywords: checkin-needed
https://github.com/mozilla-b2g/platform_system_libfdio/commit/8fcd25d64f0f67d1a6f7037a4c83ce6d95466770
Status: ASSIGNED → RESOLVED
Closed: 5 years ago
Keywords: checkin-needed
Resolution: --- → FIXED
Hi Thomas, will you request for the approval to uplift this patch?
Flags: needinfo?(tzimmermann)
Comment on attachment 8548857 [details]
Github pull request

NOTE: Please see https://wiki.mozilla.org/Release_Management/B2G_Landing to better understand the B2G approval process and landings.

[Approval Request Comment]
Bug caused by (feature/regressing bug #): 

Bug 1119176. This patch set is part of the Lillopop port.

User impact if declined: 

Bluetooth on L might not work reliably

Testing completed: 

Manual testing on local machines by running Bluetooth.

Risk to taking this patch (and alternatives if risky): 

Low. We can roll-back this change and bug 1119176 easily.

String or UUID changes made by this patch:

None.
Flags: needinfo?(tzimmermann)
Attachment #8548857 - Flags: approval-mozilla-b2g37?
Attachment #8548857 - Flags: approval-mozilla-b2g37? → approval-mozilla-b2g37+
You need to log in before you can comment on or make changes to this bug.