struct percpu_list_entry c[CPU_SETSIZE];
};
+static bool is_rseq_available;
+
/* A simple percpu spinlock. */
void rseq_percpu_lock(struct percpu_lock *lock, int cpu)
{
struct spinlock_test_data *data = arg;
int i;
- if (rseq_register_current_thread()) {
+ if (is_rseq_available && rseq_register_current_thread()) {
fprintf(stderr, "Error: rseq_register_current_thread(...) failed(%d): %s\n",
errno, strerror(errno));
abort();
data->c[cpu].count++;
rseq_percpu_unlock(&data->lock, cpu);
}
- if (rseq_unregister_current_thread()) {
+ if (is_rseq_available && rseq_unregister_current_thread()) {
fprintf(stderr, "Error: rseq_unregister_current_thread(...) failed(%d): %s\n",
errno, strerror(errno));
abort();
int i;
struct percpu_list *list = (struct percpu_list *)arg;
- if (rseq_register_current_thread()) {
+ if (is_rseq_available && rseq_register_current_thread()) {
fprintf(stderr, "Error: rseq_register_current_thread(...) failed(%d): %s\n",
errno, strerror(errno));
abort();
percpu_list_push(list, node, percpu_current_cpu());
}
- if (rseq_unregister_current_thread()) {
+ if (is_rseq_available && rseq_unregister_current_thread()) {
fprintf(stderr, "Error: rseq_unregister_current_thread(...) failed(%d): %s\n",
errno, strerror(errno));
abort();
int main(int argc, char **argv)
{
- if (rseq_register_current_thread()) {
+ is_rseq_available = rseq_available();
+ if (!is_rseq_available)
+ fprintf(stderr, "Warning: rseq is not available\n");
+ if (!cpu_op_available()) {
+ fprintf(stderr, "Error: cpu_opv is not available\n");
+ goto error;
+ }
+
+ if (is_rseq_available && rseq_register_current_thread()) {
fprintf(stderr, "Error: rseq_register_current_thread(...) failed(%d): %s\n",
errno, strerror(errno));
goto error;
test_percpu_spinlock();
printf("percpu_list\n");
test_percpu_list();
- if (rseq_unregister_current_thread()) {
+ if (is_rseq_available && rseq_unregister_current_thread()) {
fprintf(stderr, "Error: rseq_unregister_current_thread(...) failed(%d): %s\n",
errno, strerror(errno));
goto error;