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

Input: Batched reads & batched table allocations #1346

Merged
merged 27 commits into from Apr 2, 2021

Conversation

NiLuJe
Copy link
Member

@NiLuJe NiLuJe commented Apr 2, 2021

Okay, turns out, reading the full batch of events at once (or at least in as few read as possible) isn't too gnarly, and allows us to do nifty things with Lua table allocations, by telling Lua exactly how many elements we're going to insert.


This change is Reviewable

@NiLuJe
Copy link
Member Author

NiLuJe commented Apr 2, 2021

(I'll punt the debug printfs after dinner ;)).

Not terribly useful logic-wise, unlike in waitForEvent, but at least it
makes stuff consistent.
return 2; // false, errno
}
if (len == 0) {
// Should never happen
Copy link
Member

Choose a reason for hiding this comment

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

lol

ffi/posix_h.lua Outdated
Comment on lines 163 to 165
pcall(ffi.load, "/lib/librt.so.1", true)
-- NOTE: There's no librt.so symlink, so, specify the SOVER, but not the full path,
-- in order to let the dynamic loader figure it out on its own.
pcall(ffi.load, "rt.so.1", true)
Copy link
Contributor

Choose a reason for hiding this comment

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

(Just letting you know this keeps working on my GloHD.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Cool, thanks ;).

I'd checked with a dummy library and a strace that it was indeed following all the crazy stock paths, but glad to have a confirmation ;).

@NiLuJe
Copy link
Member Author

NiLuJe commented Apr 2, 2021

Wheeee \o/

[pid 25222] 23:24:57.828218 [2ac7ae90] _newselect(8, [5</dev/input/event0> 6</dev/input/event1> 7<pipe:[72753]>], NULL, NULL, {tv_sec=1697, tv_usec=236071}) = 1 (in [6], left {tv_sec=1692, tv_usec=250573}) <4.985557>
[pid 25222] 23:25:02.814233 [2ac72e2c] read(6</dev/input/event1>, "\256\213g`\211k\f\0\3\09\0\1\0\0\0\256\213g`\217k\f\0\3\0000\0\1\0\0\0"..., 4096) = 112 <0.000036>
[pid 25222] 23:25:02.814570 [2ac72e2c] read(6</dev/input/event1>, 0x7ec627d8, 3984) = -1 EAGAIN (Resource temporarily unavailable) <0.000028>
[pid 25222] 23:25:02.815060 [2ac828dc] timerfd_create(CLOCK_REALTIME, TFD_CLOEXEC|TFD_NONBLOCK) = 11<anon_inode:[timerfd]> <0.000049>
[pid 25222] 23:25:02.815320 [2ac828fc] timerfd_settime(11<anon_inode:[timerfd]>, TFD_TIMER_ABSTIME, {it_interval={tv_sec=0, tv_nsec=0}, it_value={tv_sec=1617398703, tv_nsec=313977000}}, NULL) = 0 <0.000034>
[pid 25222] 23:25:02.816864 [2ac9031c] clock_gettime(CLOCK_MONOTONIC, {tv_sec=611936, tv_nsec=507595863}) = 0 <0.000034>
[pid 25222] 23:25:02.817232 [2ac7ae90] _newselect(12, [5</dev/input/event0> 6</dev/input/event1> 7<pipe:[72753]> 11<anon_inode:[timerfd]>], NULL, NULL, {tv_sec=1692, tv_usec=247057}) = 1 (in [6], left {tv_sec=1692, tv_usec=239888}) <0.007219>
[pid 25222] 23:25:02.824909 [2ac72e2c] read(6</dev/input/event1>, "\256\213g`\\\225\f\0\3\09\0\1\0\0\0\256\213g`b\225\f\0\3\0000\0\0\0\0\0"..., 4096) = 112 <0.000037>
[pid 25222] 23:25:02.825231 [2ac72e2c] read(6</dev/input/event1>, 0x7ec627d8, 3984) = -1 EAGAIN (Resource temporarily unavailable) <0.000026>
[pid 25222] 23:25:02.828375 [2ac9031c] clock_gettime(CLOCK_MONOTONIC, {tv_sec=611936, tv_nsec=519117922}) = 0 <0.000033>
[pid 25222] 23:25:02.828884 [2ac7ae90] _newselect(8, [5</dev/input/event0> 6</dev/input/event1> 7<pipe:[72753]>], NULL, NULL, {tv_sec=1692, tv_usec=235535}

Copy link
Member Author

@NiLuJe NiLuJe left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 3 files at r1, 3 of 3 files at r3.
Dismissed @poire-z from a discussion.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @NiLuJe)


ffi/posix_h.lua, line 165 at r2 (raw file):

Previously, NiLuJe (NiLuJe) wrote…

Cool, thanks ;).

I'd checked with a dummy library and a strace that it was indeed following all the crazy stock paths, but glad to have a confirmation ;).

Done.

@NiLuJe NiLuJe merged commit b3337e5 into koreader:master Apr 2, 2021
NiLuJe added a commit to koreader/koreader that referenced this pull request Apr 2, 2021
Requires koreader/koreader-base#1344 & koreader/koreader-base#1346 (fix #7485)

Assorted input fixes:

* Actually handle errors in the "there's a callback timer" input polling loop.
* Don't break timerfd when the clock probe was inconclusive.

Not directly related, but noticed because of duplicate onInputEvent handlers:

* HookContainer: Fix deregistration to actually deregister properly. "Regression" extant since its inception in #2933 (!).
* Made sure the three plugins (basically the trio of AutoThingies ;p) that were using HookContainer actually unschedule their task on teardown.
roygbyte pushed a commit to roygbyte/koreader-base that referenced this pull request Mar 3, 2022
Okay, turns out, reading the full batch of events at once (or at least in as few `read` as possible) isn't too gnarly, and allows us to do nifty things with Lua table allocations, by telling Lua exactly how many elements we're going to insert.

Also, fix loading librt on multilib systems.
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.

None yet

3 participants