-
Notifications
You must be signed in to change notification settings - Fork 4
/
ktls.h
124 lines (107 loc) · 3.48 KB
/
ktls.h
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* KTLS - Kernel Thread-Level Speculation
*
* ktls.h - Definitions and documentation for the ktls user-space interface
*
* Authors: Clemens Hammacher <[email protected]>
* Janosch Graef <[email protected]>
*/
#ifndef _KTLS_H_
#define _KTLS_H_
#include "ktls_ioctl.h"
#include <cstdint>
#ifdef __cplusplus
extern "C" {
#endif
/**
* The all-in-one interface: take a TaskList and run all tasks contained in it.
* The file handle for connecting to the kernel module will be opened
* automatically on the first call to this function, and will remain open until
* the termination of the whole executing process (so basically forever).
* If any error occurs (e.g. because the kernel module is not available), then
* an error message is print to stderr, and the program is aborted.
*/
void ktls_run(void *taskList);
/**
* Open a connection to the KTLS kernel module.
* Return a file descriptor, or -1 if an error occured.
* In this case, errno is set appropriately.
*/
int ktls_open(void);
/**
* Close a KTLS connection which was previously opened by ktls_open.
* Returns 0 on success, -1 on error (and sets errno).
*/
int ktls_close(int fd);
/**
* The task-level-parallelism (a.k.a fork/join) interface.
*
* Spawn multiple threads with kernel transactional memory.
* `fd` is the file descriptor returned by ktls_open.
* `tasks` is a pointer to a TLS::TaskList.
* `tasks_end` is a pointer past the end of the TaskList (as returned by
* TaskList::getEnd()).
* `num_tasks` is the number of tasks in the list (as returned by
* TaskList::getNumTasks()).
*
* Returns 0 on success, 1 if an error occured (e.g. communication with kernel
* module failed).
* In case of error, errno is set accordingly.
*/
int ktls_spawn(int fd, void *tasks, void *tasks_end, uint32_t num_tasks);
/**
* The loop interface.
*
* Start a loop execution with dynamic number of tasks.
*
* Aborts on error, otherwise returns a private pointer to be passed to the
* other loop-related functions..
*/
void *ktls_start_loop();
/**
* The loop interface.
*
* Spawn the next task.
* `loopInfo` is the pointer returned by ktls_start_loop.
* `fd` is the file descriptor returned by ktls_open.
* `fun` is the function to execute with parameters (input_ptr, output_ptr).
* `input` is a pointer to the space where the input is written.
* `input_size` is the size in bytes of the input space.
*
* Aborts on error.
*/
void ktls_spawn_next(void *loopInfo, void (*fun)(void *, void *),
void *input, unsigned input_size);
/**
* Sync on all the spawned threads.
* This corresponds to the loop interface.
* `loopInfo` is the pointer returned by ktls_start_loop.
*
* Aborts on error.
*/
void ktls_finish_loop(void *loopInfo);
/**
* Reset KTLS statistics.
* Returns 0 on success, -1 on error (and sets errno).
*/
int ktls_reset_stats(int fd);
/**
* Retrieve KTLS statistics, and store them in `stats`.
* Returns 0 on success, -1 on error (and sets errno).
*/
int ktls_get_stats(int fd, struct ktls_stats *stats);
/**
* Reset the KTLS statistics for the global context used by previous ktls_run
* calls.
* Returns 0 on success, -1 on error (and sets errno).
*/
int ktls_reset_global_stats();
/**
* Retrieve KTLS statistics for the global context used by previous ktls_run
* calls, and store them in `stats`.
* Returns 0 on success, -1 on error (and sets errno).
*/
int ktls_get_global_stats(struct ktls_stats *stats);
#ifdef __cplusplus
}
#endif
#endif /* _KTLS_H_ */