-
Notifications
You must be signed in to change notification settings - Fork 6.1k
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
Enhance x86 apic timer driver #72839
Enhance x86 apic timer driver #72839
Conversation
kwd-doodling
commented
May 16, 2024
•
edited
edited
- Add 64bit cycle counter support.
- Improve accuracy of last_announcement assignment.
- Improve TSC mode accuracy by using TSC count
e89c02f
to
4705d80
Compare
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.
A few nits, and maybe a modest concern given the math was already being done this way previously
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.
Commit 56392b8 wording could use a little cleanup
I'd suggest
"Change last_announcement to track the tick aligned cycle count of the last announcement rather than the absolute cycle count. This ensures the the number of ticks that have elapsed since last_announcement, provided by sys_clock_elapsed(), are accurate. Without this change the number of elapsed ticks may show up as one more than have actually elapsed."
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 driver is a legacy thing. It exists to support platforms that have the old APIC countdown hardware and not TSC deadline support, which basically means "qemu" (which IIRC is using HPET in all our CI platforms anyway, I think?). Post-Quark, I don't think any such hardware exists or is envisioned?
Is there a reason you're trying to evolve this one instead of using apic_tsc? Honestly if you're going to be spending effort here I think I'd prefer to just see it removed.
Is there a reason you're trying to evolve this one instead of using apic_tsc? Honestly if you're going to be spending effort here I think I'd prefer to just see it removed.
Agreed. The only way this driver may provide a reliable time source is by
_only_ using the periodic mode not the one-shot one, and therefore making
it available only if CONFIG_TICKLESS_KERNEL=n.
|
ISH is a legacy CPU in fact :) Run apic_tsc on ISH already, ASSERT on "__ASSERT((ecx & BIT(24)) != 0, "No TSC Deadline support");" |
In this patch for TSC mode, TSC count is used to make it good for one-shot mode. |
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.
Sigh. Well, OK then. :) I'll remove the -1, clearly you're stuck with this one.
4705d80
to
4187b68
Compare
thanks Tom. accept you suggestion. Add more, this change also make the next announcement calculation more accurate. |
I still stand by my assertion that this driver is not accurate. In the non-TSC case you have:
Between the The ISR contributes to this as well:
The "Restart the timer as early as possible to minimize drift" comment is And then this roundabout computation via So I'm saying it again: without |
@npitre completely agree you on "So I'm saying it again: without CONFIG_APIC_TIMER_TSC this driver should none-TSC mode is just a thing for playing, not for production, maybe just for CPU has no TSC at all. Just leave it as it is, and ISH won't use it at least. |
4187b68
to
aadfdc1
Compare
Even with
You could end up overflowing the announced tick count if the next event
This is wrong of course. You should limit the timeout range to the But while at it, I think it would make sense to split this in two:
|
"You could end up overflowing the announced tick count if the next event |
INT_MAX ticks = 0x7fffffff/TICKS_PER_SEC(100 for example)/60/60/24 = 248 days. This is long enough for a timer of embedded system. |
In fact apic_tsc.c already exists. Can't you use that one already?
|
As noted above by @kwd-doodling this x86 core doesn't have all the tsc features to use it as a timer. It has the functionality to read a counter but not setup a compare from what I understand. |
Ah... If that is indeed the case, I think it would be much cleaner to I'm proposing 2 PRs: |
Make k_cycle_get_64() call available for both TSC and none-TSC mode. Signed-off-by: Dong Wang <dong.d.wang@intel.com>
Change last_announcement to track the tick aligned cycle count of the last announcement rather than the absolute cycle count. This ensures the the number of ticks that have elapsed since last_announcement, provided by sys_clock_elapsed(), are accurate. This also makes annoucement calculation more accurate. Signed-off-by: Dong Wang <dong.d.wang@intel.com>
Now the cycle count calculated from TSC is utilized for total_cycles. It's more accurate than the old value calculated out from previous total cycles saved plus APIC cycles passed since then, which has the interrrupt generation time missed. Additionally, stop the APIC timer when setting timeout as "forever" after TSC count is utilized. Signed-off-by: Dong Wang <dong.d.wang@intel.com>
aadfdc1
to
1765352
Compare
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.
Please consider adding ICR-based fallback to apic_tsc on top of PR #73183 instead. This will most likely be much cleaner.
|
Legacy or not, we still have to maintain the code if we're to keep supporting
Please have a look at #73185. I don't think it is that bad. |
let's go with #73185. |