Skip to content

Commit

Permalink
Add diffwait judge to force order
Browse files Browse the repository at this point in the history
  • Loading branch information
Youpen-y committed Dec 3, 2024
1 parent d0ec10f commit 39cd0ed
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 26 deletions.
21 changes: 21 additions & 0 deletions apps/hello/src/hello.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,26 @@ int main(int argc, char **argv) {
if (jiapid == 0) {
printf("Hello from master, Number of processes is: %d\n", jiahosts);
}
int *arr = (int *)jia_alloc(2000*sizeof(int));
if (jiapid == 0){
for(int i = 0; i < 2000; ++i) {
arr[i] = 0;
}
}

jia_lock(0);
for(int i = 0; i < 2000; i++) {
arr[i]++;
}
jia_unlock(0);

jia_barrier();

if (jiapid == 0) {
for(int i = 0; i < 2000; i++) {
printf("arr[%d] = %d\n", i, arr[i]);
}
}

jia_exit();
}
9 changes: 3 additions & 6 deletions apps/pi/src/pi.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,16 @@ int main(int argc,char *argv[])
}
mypi = h * sum;

if(system_setting.jia_pid == 0){
sleep(3);
}
jia_lock(1);
*pa= *pa+mypi;
jia_unlock(1);
jia_barrier();
endt = jia_clock();

if (jiapid==0) {
printf("pi is approximately %.16f, Error is %.16f\n",
*pa, fabs(*pa - PI25DT));
printf("Elapsed time = %f\n", endt-startt);
printf("pi is approximately %.16f, Error is %.16f\n",
*pa, fabs(*pa - PI25DT));
printf("Elapsed time = %f\n", endt-startt);
}

jia_exit();
Expand Down
2 changes: 1 addition & 1 deletion lib/lib.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ FC = gfortran # gfortran is more common
# define dirs
SRCDIR = ../../src
INCLUDEDIR = $(SRCDIR)/include
CFLAGS += -I./${INCLUDEDIR} $(ARCH_FLAGS) -DDOSTAT -g -fdebug-prefix-map=${PWD}=..
CFLAGS += -I./${INCLUDEDIR} $(ARCH_FLAGS) -DDOSTAT -g

# define files
SRCS := $(wildcard $(SRCDIR)/*/*.c)
Expand Down
11 changes: 6 additions & 5 deletions src/include/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ static char *mainstr = "[Thread main ]";
"[\033[31mERROR\033[0m] %s (%s:%d:%s: errno: %s) " STR "\n", \
str, __FILE__, __LINE__, __func__, show_errno(), \
##__VA_ARGS__); \
} while (0)
} while (0)

// fprintf(logfile, \
// fprintf(logfile, \
// "[ERROR] %s (%s:%d:%s: errno: %s) " STR "\n", \
// str, __FILE__, __LINE__, __func__, show_errno(), \
// ##__VA_ARGS__); \
Expand All @@ -61,8 +61,9 @@ static char *mainstr = "[Thread main ]";
} else { \
str = mainstr; \
} \
fprintf(logfile, "[TIME: %lu] [INFO] %s (%s:%d:%s) " STR "\n", jia_current_time(), str, __FILE__, \
__LINE__, __func__, ##__VA_ARGS__); \
fprintf(logfile, "[TIME: %lu] [INFO] %s (%s:%d:%s) " STR "\n", \
jia_current_time(), str, __FILE__, __LINE__, __func__, \
##__VA_ARGS__); \
}

#define log_out(level, STR, ...) \
Expand All @@ -84,5 +85,5 @@ static char *mainstr = "[Thread main ]";
* @return int
*/
int open_logfile(char *filename);
char* op2name(int op);
char *op2name(int op);
#endif
12 changes: 6 additions & 6 deletions src/mem/mmsyn.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,10 @@ void sigsegv_handler(int signo, siginfo_t *sip, ucontext_t *uap)

log_info(3, "Enter sigsegv ");
log_info(3,
"Shared memory range from %p to %p!, faultaddr=%p, "
"writefault=%d\n",
"Shared memory range from %p to %p!, faultaddr=%p(%d), "
"writefault=%d",
(void *)system_setting.global_start_addr,
(void *)(system_setting.global_start_addr + globaladdr), faultaddr,
(void *)(system_setting.global_start_addr + globaladdr), faultaddr, homehost(faultaddr),
writefault);

log_info(3,
Expand Down Expand Up @@ -329,6 +329,7 @@ void sigsegv_handler(int signo, siginfo_t *sip, ucontext_t *uap)
* writefault later. first writable permission is for getpgrantserver's
* copy(to faultaddr)
*/

if (cachei < Cachepages) {
memprotect((caddr_t)faultaddr, Pagesize, PROT_READ | PROT_WRITE);
if (!((writefault) && (cache[cachei].state == RO))) {
Expand Down Expand Up @@ -491,9 +492,8 @@ void savediff(int cachei) {
move_msg_to_outqueue(&msg_buffer, index, &outqueue);
diffmsg[hosti]->size = 0;
appendmsg(diffmsg[hosti], diff, diffsize);
// while (diffwait)
// ;
// TODO: wait condition variable
while (diffwait)
;
} else {
appendmsg(diffmsg[hosti], diff, diffsize);
}
Expand Down
2 changes: 1 addition & 1 deletion src/syn/syn.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ void endinterval(int synop) {
register int hpages;
log_info(3, "Enter endinterval!");

// step 1: send all cache diffs
/*/ step 1: save all cache diff */
for (cachei = 0; cachei < Cachepages; cachei++) {
// cachepage's wtnt == 1 means RW permission
if (cache[cachei].wtnt == 1) {
Expand Down
4 changes: 0 additions & 4 deletions src/syn/synlockbarr.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ void acquire(int lock) {
jia_msg_t *req;
int index;

// req = newmsg();
index = freemsg_lock(&msg_buffer);
req = &msg_buffer.buffer[index].msg;
req->op = ACQ;
Expand All @@ -88,9 +87,6 @@ void acquire(int lock) {
req->size = 0;
appendmsg(req, ltos(lock), Intbytes);

// asendmsg(req); // send the ACQ msg the lock owner
// freemsg(req);

move_msg_to_outqueue(&msg_buffer, index, &outqueue);
freemsg_unlock(&msg_buffer, index);
while (atomic_load(&acqwait))
Expand Down
4 changes: 3 additions & 1 deletion src/syn/synserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ void barrserver(jia_msg_t *req) {
lock = (int)stol(req->data);

jia_assert((lock % system_setting.hostc == system_setting.jia_pid), "Incorrect home of lock!");
jia_assert((lock == hidelock), "This should not have happened! 8");
jia_assert((lock == hidelock), "This should not have happened! 8"); // barrier is hidelock

recordwtnts(req); // record write notices in msg barr's data

Expand All @@ -322,6 +322,7 @@ void barrserver(jia_msg_t *req) {
void barrgrantserver(jia_msg_t *req) {
int lock;

log_info(3, "Enter barrgrantserver");
jia_assert((req->op == BARRGRANT) && (req->topid == system_setting.jia_pid),
"Incorrect BARRGRANT Message!");

Expand All @@ -338,6 +339,7 @@ void barrgrantserver(jia_msg_t *req) {
//barrwait = 0;
atomic_store(&barrwait, 0);
noclearlocks = 0;
log_info(3, "Out of barrgrantserver");
}


Expand Down
4 changes: 3 additions & 1 deletion src/syn/synwtnts.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,12 @@ wtnt_t *appendlockwtnts(jia_msg_t *msg, wtnt_t *ptr, int acqscope) {

full = 0;
wnptr = ptr;

/* wnptr is not NULL and a msg is not full */
while ((wnptr != WNULL) && (full == 0)) {
if ((msg->size + (wnptr->wtntc * (sizeof(unsigned char *)))) <
Maxmsgsize) {
for (wtnti = 0; wtnti < wnptr->wtntc; wtnti++)
for (wtnti = 0; wtnti < wnptr->wtntc; wtnti++)
if ((wnptr->from[wtnti] > acqscope) &&
// if homehost(wnptr->wtnts[wtnti]) == msg->topid), not
// send(remote host is the owner of this copy)
Expand Down
2 changes: 1 addition & 1 deletion src/thread/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void *server_thread(void *args)
* @note msg_handle called by server_thread
*/
static void msg_handle(jia_msg_t *msg) {
log_info(3, "In servermsg!\n");
log_info(3, "In servermsg!");

switch (msg->op) {
case DIFF:
Expand Down

0 comments on commit 39cd0ed

Please sign in to comment.