-
Notifications
You must be signed in to change notification settings - Fork 106
Optimize timestamps with per-CPU caching #2349
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
base: master
Are you sure you want to change the base?
Optimize timestamps with per-CPU caching #2349
Conversation
@MorganaFuture we'be been lacking resources to implement this feature, so thank you! This is draft, we shouldn't review it yet, right? |
This PR is not ready yet. I'm having some difficulties running tests for Tempesta. Once I make sure everything works as expected, I will update the PR status |
BTW, why not simply update a per-CPU variable in a timer SoftIRQ? Then each |
cf97fdd
to
81600a9
Compare
@keshonok could you please take a look at changes? |
dc7f740
to
32f83f5
Compare
|
||
/* Update the timestamp on all CPUs */ | ||
for_each_online_cpu(cpu) { | ||
per_cpu(tfw_ts_cache, cpu) = ts.tv_sec; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks not good, however we do it only once per second. But I have doubts about current solution anyway. Suggested in the task approach seems more elegant. We can conditionally update per-cpu cached time relying on jiffies inside softirq handler. @krizhanovsky What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MorganaFuture In this solution we do check/update timer on each call of tfw_current_timestamp
, but we can improve it doing check/update only once per softirq handler, and then in tfw_current_timestamp
only receive the value. Solution with timer also not bad, but I would prefer to minimize cache bouncing even once per second. However, maybe I'm trying to over optimize, therefore I would like to hear also your @MorganaFuture opinion as well as @krizhanovsky.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @const-t and think that the problem can be fixed easier on the kernel level. We do our best to minimize the kernel patch, but this case seems should be done on the kernel side.
I think it makes sense to do this on https://github.com/tempesta-tech/linux-6.12.12-tfw/ . @const-t please guide how it'd be more convenient to do: as a branch from your https://github.com/tempesta-tech/linux-6.12.12-tfw/tree/kt-apply-tempesta-patch or will you just add the @MorganaFuture patch to your patch preserving his authorship.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MorganaFuture Patch to https://github.com/tempesta-tech/linux-6.12.12-tfw/ looks better for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd propose to path the kernel to cache the timestamp value, export it from the kernel, probably with a function, and use it from tfw_current_timestamp()
@@ -20,6 +20,8 @@ | |||
#include <linux/module.h> | |||
#include <linux/string.h> | |||
|
|||
#include "common.h" | |||
|
|||
MODULE_AUTHOR("Tempesta Technologies, INC"); | |||
MODULE_VERSION("0.1.1"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a new feature, so let's advance the version to 0.2.0
|
||
/* Update the timestamp on all CPUs */ | ||
for_each_online_cpu(cpu) { | ||
per_cpu(tfw_ts_cache, cpu) = ts.tv_sec; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @const-t and think that the problem can be fixed easier on the kernel level. We do our best to minimize the kernel patch, but this case seems should be done on the kernel side.
I think it makes sense to do this on https://github.com/tempesta-tech/linux-6.12.12-tfw/ . @const-t please guide how it'd be more convenient to do: as a branch from your https://github.com/tempesta-tech/linux-6.12.12-tfw/tree/kt-apply-tempesta-patch or will you just add the @MorganaFuture patch to your patch preserving his authorship.
What
Implement per-CPU cached timestamp mechanism for tfw_current_timestamp()
Add automatic refresh when cached timestamp becomes stale
Only cache timestamps in softirq context
Why
ktime_get_real_ts64() is a heavyweight kernel function
Links
2275