Skip to content

Commit

Permalink
register backend is not thread safe
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubuntu committed May 17, 2024
1 parent dee8ec6 commit ac7f7f5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
2 changes: 1 addition & 1 deletion apps/self-test/stress-init.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ int main(int argc, char **argv)
exit(1);
}

err = WooFCreate(Oname,sizeof(ST_EL),woof_size);
err = WooFCreate(Oname,payload_size,woof_size);
if(err < 0) {
fprintf(stderr,"stress-init: can't init %s\n",Oname);
fflush(stderr);
Expand Down
44 changes: 35 additions & 9 deletions apps/self-test/stress-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <sys/time.h>
#include <pthread.h>

#include "woofc.h"
Expand Down Expand Up @@ -43,29 +44,44 @@ int Verbose;

void *PutThread(void *arg)
{
ST_EL *st;
char Iname[4096];
ST_EL *st;
unsigned long seq_no;
char *payload;
int i;
int size;

MAKE_EXTENDED_NAME(Iname,Wname,"input");
/*
* register backend is not thread safe?
* do this to prime the pump
*/
pthread_mutex_lock(&Plock);
seq_no = WooFGetLatestSeqno(Iname);
pthread_mutex_unlock(&Plock);

payload = (char *)malloc(Payload_size);
if(payload == NULL) {
exit(1);
}
for(i=0; i < Payload_size; i++) {
payload[i] = 75;
}
memset(payload,0,Payload_size);
st = (ST_EL *)payload;
memset(st,0,sizeof(ST_EL));
strcpy(st->woof_name,Wname);
// memset(st,0,sizeof(ST_EL));
strncpy(st->woof_name,Wname,sizeof(st->woof_name));
//printf("Put: %ld with %s %s %d\n",
//pthread_self(),
//Iname,
//Wname,
//Payload_size);
//fflush(stdout);
pthread_mutex_lock(&Plock);
while(PutRemaining > 0) {
PutRemaining--;
pthread_mutex_unlock(&Plock);
gettimeofday(&st->posted,NULL);
//printf("Put: pr: %d\n",PutRemaining);
pthread_mutex_unlock(&Plock);
seq_no = WooFPut(Iname,"stress_handler",st);
//printf("Put: seq_no: %ld\n",seq_no);
if(WooFInvalid(seq_no)) {
fprintf(stderr,"put thread failed\n");
fflush(stderr);
Expand Down Expand Up @@ -98,6 +114,7 @@ void *GetThread(void *arg)
DlistNode *dn;
int retries;
struct timespec ts;
int started = 0;



Expand All @@ -106,7 +123,10 @@ void *GetThread(void *arg)
ts.tv_nsec = 1000000; /* 2 ms wait time on get */
}
MAKE_EXTENDED_NAME(Oname,Wname,"output");
while((Done == 0) || (Pending->first != NULL)) {
//printf("Get: %ld starting with %s\n",pthread_self(), Oname);
//fflush(stdout);
while((Done == 0) || (Pending->first != NULL) ||
(started == 0)) {
if(IsLatency == 0) {
nanosleep(&ts,NULL);
}
Expand All @@ -115,6 +135,7 @@ void *GetThread(void *arg)
if(dn != NULL) {
DlistDelete(Pending,dn);
pthread_mutex_unlock(&Glock);
started = 1;
retries = 0;
seq_no = dn->value.l;
while(retries < 30) {
Expand Down Expand Up @@ -272,6 +293,7 @@ int main(int argc, char **argv)
for(i=0; i < pt; i++) {
pthread_join(ptids[i],NULL);
}
//printf("Joined with put threads\n");

if(IsLatency == 0) {
sleep(1);
Expand All @@ -294,7 +316,11 @@ int main(int argc, char **argv)
if(IsLatency == 1) {
printf("avg latency: %f ms\n",Total/Count);
} else {
printf("avg throughput: %f puts/s\n",Count / (Total/1000.0));
if(Total > 0) {
printf("avg throughput: %f puts/s\n",Count / (Total/1000.0));
} else {
printf("No timing taken\n");
}
}

return(1);
Expand Down

0 comments on commit ac7f7f5

Please sign in to comment.