-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for waitpkg and reporting count in clock and stats
- Loading branch information
1 parent
5cdeb57
commit d9f56cb
Showing
3 changed files
with
38 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include <immintrin.h> | ||
#include <x86intrin.h> | ||
|
||
#pragma once | ||
|
||
namespace nvsl { | ||
enum class TpauseType { | ||
DeepSleep = 0, // C0.2 | ||
LightSleep = 1, // C0.1 | ||
}; | ||
|
||
static inline void tpause(size_t wait_cycles, TpauseType type) { | ||
const uint64_t current_tsc = _rdtsc(); | ||
const uint64_t final_tsc = current_tsc + wait_cycles; | ||
|
||
_tpause(static_cast<int>(type), final_tsc); | ||
} | ||
|
||
static inline void wait(void *addr, size_t wait_cycles, TpauseType type) { | ||
_umonitor(addr); | ||
|
||
while (true) { | ||
const uint64_t current_tsc = _rdtsc(); | ||
const uint64_t final_tsc = current_tsc + wait_cycles; | ||
|
||
const auto expired = _umwait(static_cast<int>(type), final_tsc); | ||
|
||
if (!expired) break; | ||
}; | ||
} | ||
} // namespace nvsl |