earlephilhower / bearssl-esp8266

Port of https://bearssl.org BearSSL to ESP8266

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

External symbol definition sidelining Arduino.h include conflicts with inlining work in ESP8266

dok-net opened this issue · comments

I am speeding up optimistic_yield() in ESP8266 master from idle 80 cycles to 32 cyles by inlining the usually constexpr parameter conversion from µs to cycles.
Writing directly inlined code in Arduino.h, This conflicts with src/inner.h line 2598:

extern void optimistic_yield(uint32_t); 

requiring an external symbol.
In PR esp8266/Arduino#6804 I'm working around this by using the preprocessor. Cleaning this up would be better for typesafety etc.

@earlephilhower Grep'ing for use of optimistic_yield in bearssl, I would believe that the PR speeds up bearssl noticeably? Both the idle cycle reduction, and the corrected behavior of not yielding on every optimistic_yield after 10000us in the same loop iteration, but only each 10000µs between yields, should make a difference. Could you please review and comment in the PR log, maybe providing rationale from your POV there, what the expected behavior of optimistic_yield was anyway? Thank you.

@dok-net what would your suggestion for fixing the problem? I'm not sure I can repro it, as I tried checking out Arduino/6804 and running the simple validation example. The results weren't very stable, but I didn't see a great deviation vs. w/o the (corrected) optimistic_yield. Maybe 100ms shorted in the shortest reported handshake time (but total connect time about 1300ms so it's not that dramatic).

The reason, I believe, is because in most cases the optimistic_yield is a no-op when I call it. The SSL protocol is 1-way until the handshake is done, so while I'm doing EC work no new packets will be arriving from the website. W/o wifi servicing, the ROM doesn't really have much to do other than some beacons and stuff. I'm also doing a lot of work in the EC math calls, so the small overhead of the call/return aren't really noticeable.