Repository navigation
Expand file tree
/
Copy pathtailslayer_example.cpp
More file actions
68 lines (55 loc) · 2.3 KB
/
Copy pathtailslayer_example.cpp
File metadata and controls
68 lines (55 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <tailslayer/hedged_reader.hpp>
#include <iostream>
/*
Example user functions that could be passed to tailslayer
*/
// Example with arguments
[[gnu::always_inline]] inline std::size_t dummy_read_signal2(int arg1, int arg2) {
std::cout << "Hi with args: " << arg1 << " " << arg2 << "\n";
return 0; // Index to read
}
template <typename T>
[[gnu::always_inline]] inline void dummy_final_work2(T val, int arg2) {
std::cout << "Hi with args: " << val << " " << arg2 << "\n";
}
// Example with no arguments
[[gnu::always_inline]] inline std::size_t dummy_read_signal() {
// UPDATE HERE - signal
// This is the signal that the worker will wait for
// Once this loop completes, the read will be triggered
#if defined(__x86_64__) || defined(__i386__) // Avoid compilation errors for testers on non-x86 platforms. Read happens immediately though :)
uint64_t starting_time_dumb = tailslayer::detail::rdtsc_lfence();
tailslayer::detail::rdtsc_lfence();
uint64_t num_cycles{0};
do {
num_cycles = tailslayer::detail::rdtsc_lfence() - starting_time_dumb;
} while (num_cycles < 2000000000);
#endif // x86
// UPDATE HERE - index
std::size_t index_to_read = 1; // Desired index to read (example reading the second value 0x44)
return index_to_read;
}
template <typename T>
[[gnu::always_inline]] inline void dummy_final_work(T val) {
// UPDATE HERE - final work
// This is the function that will be executed with the value as soon as the signal function finishes
asm volatile("" :: "r"(val)); // Dummy using value
std::cout << "Val: " << val << "\n";
}
int main() {
using target_size_t = uint8_t;
tailslayer::pin_to_core(tailslayer::CORE_MAIN);
std::cout << "Start tailslayer demo.\n";
// Example with arguments
// tailslayer::HedgedReader<target_size_t, dummy_read_signal2, dummy_final_work2<target_size_t>, tailslayer::ArgList<1, 2>, tailslayer::ArgList<2>> reader_args{};
// reader_args.insert(0x43);
// reader_args.insert(0x44);
// reader_args.start_workers();
// Example with no arguments
tailslayer::HedgedReader<target_size_t, dummy_read_signal, dummy_final_work<target_size_t>> reader{};
reader.insert(0x43);
reader.insert(0x44);
reader.start_workers();
std::cout << "End tailslayer demo.\n";
return 0;
}