You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Aug 23, 2024. It is now read-only.
I wrote a program as follows, and found that some threads exited abnormally when executing mpt_beginmpt_end.
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <mpt/mpt.h>
#include <climits>
#include <fcntl.h>
#include <sys/mman.h>
#define DOM_NUM 1024
#define MAX_THREAD 12
char *iso_data[DOM_NUM];
void (*funcs[DOM_NUM])(int);
int vpkeys[DOM_NUM];
void chain_func(int i) {
mpt_begin(vpkeys[i], PROT_READ | PROT_WRITE);
mpt_end(vpkeys[i]);
funcs[i+1](i+1);
}
void end_func(int i) {
mpt_begin(vpkeys[i], PROT_READ | PROT_WRITE);
mpt_end(vpkeys[i]);
}
void init_domain(int num) {
mpt_init(-1);
for (int i = 0; i < num; i++) {
vpkeys[i] = mpt_mmap((void **)&iso_data[i], 0x1000, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE);
funcs[i] = chain_func;
}
funcs[num - 1] = end_func;
}
typedef struct thread_info {
pthread_t pid;
unsigned long long res;
} info_t;
info_t threads_info[MAX_THREAD];
void *worker_func(void *arg) {
int count = 10000;
unsigned long long start = rdtsc();
for (int i = 0; i < count; i++) {
funcs[0](0);
}
unsigned long long end = rdtsc();
((info_t *)arg)->res = (end - start) / count;
printf("thread with res %llu\n", (end - start)/ count);
return NULL;
}
int main(int argc, char *argv[]) {
int num = 30;
int threads = 2;
init_domain(num);
for (int i = 0; i < threads; i++) {
int ret = pthread_create(&threads_info[i].pid, NULL, &worker_func, &threads_info[i]);
if (ret < 0) {
printf("pthread_create failed\n");
return -1;
}
}
unsigned long long total = 0;
for (int i = 0; i < threads; i++) {
int ret = pthread_join(threads_info[i].pid, NULL);
if (ret < 0) {
printf("pthread_join failed\n");
return -1;
}
total += threads_info[i].res;
printf("thread %d time %llu\n", i, threads_info[i].res);
}
unsigned long long avg = total / threads;
printf("%d,%llu,\n", num, avg);
return 0;
}
The program chained num functions, inside each function it switches domain. When there is only one thread (threads = 1 in main()), the program works well. However, if threads = 2, some of threads may corrupt and exit early than return NULL in worker_func, as the res field turned out to be 0 for these threads.
Do I use the interfaces provided by libmpk correctly? I am worried about that the problem is caused by coding incorrectly.
Does libmpk support multi-threaded programming? If so, can you provide a runnable version of multi-threaded benchmark? Or if there are some bugs, can you fix them?
The text was updated successfully, but these errors were encountered:
I guess that's the issue you're reaching in this case. The codebase has not been updated for more than 2 years, so I suppose the authors won't address it.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I wrote a program as follows, and found that some threads exited abnormally when executing
mpt_begin
mpt_end
.The program chained
num
functions, inside each function it switches domain. When there is only one thread (threads = 1
inmain()
), the program works well. However, ifthreads = 2
, some of threads may corrupt and exit early thanreturn NULL
inworker_func
, as theres
field turned out to be 0 for these threads.And I found error messages thrown by kernel:
I have the following questions:
The text was updated successfully, but these errors were encountered: