Skip to content

Various nit picks - #225

Closed
kerolasa wants to merge 7 commits into
iputils:masterfrom
kerolasa:various-nit-picks
Closed

kerolasa wants to merge 7 commits into
iputils:masterfrom
kerolasa:various-nit-picks

Conversation

@kerolasa

@kerolasa kerolasa commented Nov 2, 2019

Copy link
Copy Markdown
Collaborator

Couple commits I wrote while back that have sit in my local branch. I though to combine these with ping timing work, but that change has become so big that it's better to get small commits reviewed separately. Also, the ping time stuff is taking lots of time to get done (pun intended), and being busy with that I could concurrently wait feedback.

@pevik

pevik commented Nov 2, 2019

Copy link
Copy Markdown
Contributor

Reviewed-by: Petr Vorel <[email protected]>. LGTM (first 3 commits are obviously correct and could be merged straight away), @metan-ucw @nmeyerhans @jsynacek @pavlix, could you please have a look?

@nmeyerhans

Copy link
Copy Markdown
Contributor

Agreed with @pevik, the first 3 changes are no problem. I'd like to review the next 3 in a little more depth. I'm a bit skeptical that they'll improve things in the way they're intended to, so I want a little more time to either convince myself that they're good or come up with convincing evidence that they don't...

Convert int types to long before multiplicatio.  Notice that ntokens that is
used to store the value is already long.

Reference: https://lgtm.com/projects/g/iputils/iputils/?mode=list
Signed-off-by: Sami Kerola <[email protected]>
The cmsgbuf is 4096 bytes of stack, that is wasted when pinging IPv4
addresses.  The rcvd_tbl is always needed, but 8192 is enough stack size
that it is better to use proper allocation function so that possible
allocation failure can be detected.

Secondly making the whole of run time struct to fit into a single memory
page should maximize probability of it to be in cache.

Signed-off-by: Sami Kerola <[email protected]>
Inlining functions is more often cache bloat than performance gain.  While
checking where ping is most expensive pr_addr() turned out stall the most,
and with a simple stack variable scoping that function is lighter.

Signed-off-by: Sami Kerola <[email protected]>
arping.c:692:33: warning: ISO C forbids empty initializer braces [-Wpedantic]
ping.c:1620:43: warning: ISO C forbids empty initializer braces [-Wpedantic]

Signed-off-by: Sami Kerola <[email protected]>
@nmeyerhans

Copy link
Copy Markdown
Contributor

Hi @kerolasa. I had hoped to provide something more definitive to express my skeptecism about the removal of the inline keywords and the use of heap space for memory, but I haven't been able to devote the time to do so. So please feel free to merge.

A couple of thoughts on the topic: When running with any optimization flags, as is done in the iputils build configuration, gcc doesn't actually inline any functions marked with the inline keyword anyway. When any -O flag is passed to gcc, then inlined functions may be generated inline. So in some sense, you haven't been inlining these functions for a while. (In Debian, we compile with -O2 and have thus been generating inline code.) This is detailed in the gcc documentation

For very small functions, inlining is almost certainly going to result in more efficient code. That's even more the case when the function is only called once within a given C file, as is the case, for example with the rcvd_set() function in ping.c. In fact, inlining such functions is so often beneficial that gcc has a inline-functions-called-once optimization setting, enabled at all optimization levels, that considers any function, whether explicitly marked inline or not, to be a candidate for inlining. But that hasn't caused any problems yet, given my comments above about -O so I think it's not a big deal.

Regarding the use of malloc() for memory allocation, it certainly doesn't hurt to avoid allocating memory that you never use. I'm not sure that dynamic memory allocation is a win otherwise, but in this context I don't think it's an issue.

@kerolasa

Copy link
Copy Markdown
Collaborator Author

Hello @nmeyerhans and @pevik. Let me merge the first three changes, and abandon the rest.

What comes inlining sometimes you win, other times not. http://www.cs.technion.ac.il/users/yechiel/c++-faq/inline-and-perf.html is pretty good short explanation how complicated this stuff is. My understanding benefit of having functions in cache is often better than inlining them. Anyway this is not so important that I want to push removal hard.

Reason why I want to malloc() rather than use stack is pretty simple. I want to fit the runtime configuration to a single memory page so that it is very effectively cached. As a minor thing catching allocation failure is possible with malloc(), while stack allocations are more nasty but since we are talking about couple hundred bytes this is pretty theoretical note.

@kerolasa kerolasa closed this Nov 19, 2019
@kerolasa
kerolasa deleted the various-nit-picks branch November 19, 2019 19:07
@pevik

pevik commented Nov 20, 2019

Copy link
Copy Markdown
Contributor

@kerolasa IMHO commit "arping / ping: fix couple warnings" is also obviously correct (backwards compatibility). Feel free to merge it with my ack.

@pevik

pevik commented Nov 23, 2019 •

Copy link
Copy Markdown
Contributor

I dared to push your fix arping / ping: fix couple warnings as 7c4049b. Thanks!

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.

3 participants